1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 3, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING3. If not see
22 <http://www.gnu.org/licenses/>. */
24 /* TODO: Emit .debug_line header even when there are no functions, since
25 the file numbers are used by .debug_info. Alternately, leave
26 out locations for types and decls.
27 Avoid talking about ctors and op= for PODs.
28 Factor out common prologue sequences into multiple CIEs. */
30 /* The first part of this file deals with the DWARF 2 frame unwind
31 information, which is also used by the GCC efficient exception handling
32 mechanism. The second part, controlled only by an #ifdef
33 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 /* DWARF2 Abbreviation Glossary:
38 CFA = Canonical Frame Address
39 a fixed address on the stack which identifies a call frame.
40 We define it to be the value of SP just before the call insn.
41 The CFA register and offset, which may change during the course
42 of the function, are used to calculate its value at runtime.
44 CFI = Call Frame Instruction
45 an instruction for the DWARF2 abstract machine
47 CIE = Common Information Entry
48 information describing information common to one or more FDEs
50 DIE = Debugging Information Entry
52 FDE = Frame Description Entry
53 information describing the stack call frame, in particular,
54 how to restore registers
56 DW_CFA_... = DWARF2 CFA call frame instruction
57 DW_TAG_... = DWARF2 DIE tag */
61 #include "coretypes.h"
68 #include "hard-reg-set.h"
70 #include "insn-config.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
85 #include "diagnostic.h"
88 #include "langhooks.h"
93 #ifdef DWARF2_DEBUGGING_INFO
94 static void dwarf2out_source_line (unsigned int, const char *);
97 #ifndef DWARF2_FRAME_INFO
98 # ifdef DWARF2_DEBUGGING_INFO
99 # define DWARF2_FRAME_INFO \
100 (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
102 # define DWARF2_FRAME_INFO 0
106 /* Map register numbers held in the call frame info that gcc has
107 collected using DWARF_FRAME_REGNUM to those that should be output in
108 .debug_frame and .eh_frame. */
109 #ifndef DWARF2_FRAME_REG_OUT
110 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
113 /* Decide whether we want to emit frame unwind information for the current
117 dwarf2out_do_frame (void)
119 /* We want to emit correct CFA location expressions or lists, so we
120 have to return true if we're going to output debug info, even if
121 we're not going to output frame or unwind info. */
122 return (write_symbols
== DWARF2_DEBUG
123 || write_symbols
== VMS_AND_DWARF2_DEBUG
125 #ifdef DWARF2_UNWIND_INFO
126 || (DWARF2_UNWIND_INFO
127 && (flag_unwind_tables
128 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)))
133 /* The size of the target's pointer type. */
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
138 /* Array of RTXes referenced by the debugging information, which therefore
139 must be kept around forever. */
140 static GTY(()) VEC(rtx
,gc
) *used_rtx_array
;
142 /* A pointer to the base of a list of incomplete types which might be
143 completed at some later time. incomplete_types_list needs to be a
144 VEC(tree,gc) because we want to tell the garbage collector about
146 static GTY(()) VEC(tree
,gc
) *incomplete_types
;
148 /* A pointer to the base of a table of references to declaration
149 scopes. This table is a display which tracks the nesting
150 of declaration scopes at the current scope and containing
151 scopes. This table is used to find the proper place to
152 define type declaration DIE's. */
153 static GTY(()) VEC(tree
,gc
) *decl_scope_table
;
155 /* Pointers to various DWARF2 sections. */
156 static GTY(()) section
*debug_info_section
;
157 static GTY(()) section
*debug_abbrev_section
;
158 static GTY(()) section
*debug_aranges_section
;
159 static GTY(()) section
*debug_macinfo_section
;
160 static GTY(()) section
*debug_line_section
;
161 static GTY(()) section
*debug_loc_section
;
162 static GTY(()) section
*debug_pubnames_section
;
163 static GTY(()) section
*debug_pubtypes_section
;
164 static GTY(()) section
*debug_str_section
;
165 static GTY(()) section
*debug_ranges_section
;
166 static GTY(()) section
*debug_frame_section
;
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct
*dw_cfi_ref
;
174 typedef struct dw_fde_struct
*dw_fde_ref
;
175 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 enum dw_cfi_oprnd_type
{
184 dw_cfi_oprnd_reg_num
,
190 typedef union dw_cfi_oprnd_struct
GTY(())
192 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
193 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
194 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
195 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
199 typedef struct dw_cfi_struct
GTY(())
201 dw_cfi_ref dw_cfi_next
;
202 enum dwarf_call_frame_info dw_cfi_opc
;
203 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
205 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
210 /* This is how we define the location of the CFA. We use to handle it
211 as REG + OFFSET all the time, but now it can be more complex.
212 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
213 Instead of passing around REG and OFFSET, we pass a copy
214 of this structure. */
215 typedef struct cfa_loc
GTY(())
217 HOST_WIDE_INT offset
;
218 HOST_WIDE_INT base_offset
;
220 int indirect
; /* 1 if CFA is accessed via a dereference. */
223 /* All call frame descriptions (FDE's) in the GCC generated DWARF
224 refer to a single Common Information Entry (CIE), defined at
225 the beginning of the .debug_frame section. This use of a single
226 CIE obviates the need to keep track of multiple CIE's
227 in the DWARF generation routines below. */
229 typedef struct dw_fde_struct
GTY(())
232 const char *dw_fde_begin
;
233 const char *dw_fde_current_label
;
234 const char *dw_fde_end
;
235 const char *dw_fde_hot_section_label
;
236 const char *dw_fde_hot_section_end_label
;
237 const char *dw_fde_unlikely_section_label
;
238 const char *dw_fde_unlikely_section_end_label
;
239 bool dw_fde_switched_sections
;
240 dw_cfi_ref dw_fde_cfi
;
241 unsigned funcdef_number
;
242 HOST_WIDE_INT stack_realignment
;
243 /* Dynamic realign argument pointer register. */
244 unsigned int drap_reg
;
245 /* Virtual dynamic realign argument pointer register. */
246 unsigned int vdrap_reg
;
247 unsigned all_throwers_are_sibcalls
: 1;
248 unsigned nothrow
: 1;
249 unsigned uses_eh_lsda
: 1;
250 /* Whether we did stack realign in this call frame. */
251 unsigned stack_realign
: 1;
252 /* Whether dynamic realign argument pointer register has been saved. */
253 unsigned drap_reg_saved
: 1;
257 /* Maximum size (in bytes) of an artificially generated label. */
258 #define MAX_ARTIFICIAL_LABEL_BYTES 30
260 /* The size of addresses as they appear in the Dwarf 2 data.
261 Some architectures use word addresses to refer to code locations,
262 but Dwarf 2 info always uses byte addresses. On such machines,
263 Dwarf 2 addresses need to be larger than the architecture's
265 #ifndef DWARF2_ADDR_SIZE
266 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
269 /* The size in bytes of a DWARF field indicating an offset or length
270 relative to a debug info section, specified to be 4 bytes in the
271 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
274 #ifndef DWARF_OFFSET_SIZE
275 #define DWARF_OFFSET_SIZE 4
278 /* According to the (draft) DWARF 3 specification, the initial length
279 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
280 bytes are 0xffffffff, followed by the length stored in the next 8
283 However, the SGI/MIPS ABI uses an initial length which is equal to
284 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
286 #ifndef DWARF_INITIAL_LENGTH_SIZE
287 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
290 #define DWARF_VERSION 2
292 /* Round SIZE up to the nearest BOUNDARY. */
293 #define DWARF_ROUND(SIZE,BOUNDARY) \
294 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
296 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
297 #ifndef DWARF_CIE_DATA_ALIGNMENT
298 #ifdef STACK_GROWS_DOWNWARD
299 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
301 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
305 /* CIE identifier. */
306 #if HOST_BITS_PER_WIDE_INT >= 64
307 #define DWARF_CIE_ID \
308 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
310 #define DWARF_CIE_ID DW_CIE_ID
313 /* A pointer to the base of a table that contains frame description
314 information for each routine. */
315 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
317 /* Number of elements currently allocated for fde_table. */
318 static GTY(()) unsigned fde_table_allocated
;
320 /* Number of elements in fde_table currently in use. */
321 static GTY(()) unsigned fde_table_in_use
;
323 /* Size (in elements) of increments by which we may expand the
325 #define FDE_TABLE_INCREMENT 256
327 /* Get the current fde_table entry we should use. */
329 static inline dw_fde_ref
332 return fde_table_in_use
? &fde_table
[fde_table_in_use
- 1] : NULL
;
335 /* A list of call frame insns for the CIE. */
336 static GTY(()) dw_cfi_ref cie_cfi_head
;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
340 attribute that accelerates the lookup of the FDE associated
341 with the subprogram. This variable holds the table index of the FDE
342 associated with the current function (body) definition. */
343 static unsigned current_funcdef_fde
;
346 struct indirect_string_node
GTY(())
349 unsigned int refcount
;
354 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
356 static GTY(()) int dw2_string_counter
;
357 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
359 /* True if the compilation unit places functions in more than one section. */
360 static GTY(()) bool have_multiple_function_sections
= false;
362 /* Whether the default text and cold text sections have been used at all. */
364 static GTY(()) bool text_section_used
= false;
365 static GTY(()) bool cold_text_section_used
= false;
367 /* The default cold text section. */
368 static GTY(()) section
*cold_text_section
;
370 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
372 /* Forward declarations for functions defined in this file. */
374 static char *stripattributes (const char *);
375 static const char *dwarf_cfi_name (unsigned);
376 static dw_cfi_ref
new_cfi (void);
377 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
378 static void add_fde_cfi (const char *, dw_cfi_ref
);
379 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
380 static void lookup_cfa (dw_cfa_location
*);
381 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
382 #ifdef DWARF2_UNWIND_INFO
383 static void initial_return_save (rtx
);
385 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
);
386 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
387 static void output_call_frame_info (int);
388 static void dwarf2out_note_section_used (void);
389 static void dwarf2out_stack_adjust (rtx
, bool);
390 static void dwarf2out_args_size_adjust (HOST_WIDE_INT
, const char *);
391 static void flush_queued_reg_saves (void);
392 static bool clobbers_queued_reg_save (const_rtx
);
393 static void dwarf2out_frame_debug_expr (rtx
, const char *);
395 /* Support for complex CFA locations. */
396 static void output_cfa_loc (dw_cfi_ref
);
397 static void get_cfa_from_loc_descr (dw_cfa_location
*,
398 struct dw_loc_descr_struct
*);
399 static struct dw_loc_descr_struct
*build_cfa_loc
400 (dw_cfa_location
*, HOST_WIDE_INT
);
401 static struct dw_loc_descr_struct
*build_cfa_aligned_loc
402 (HOST_WIDE_INT
, HOST_WIDE_INT
);
403 static void def_cfa_1 (const char *, dw_cfa_location
*);
405 /* How to start an assembler comment. */
406 #ifndef ASM_COMMENT_START
407 #define ASM_COMMENT_START ";#"
410 /* Data and reference forms for relocatable data. */
411 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
412 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
414 #ifndef DEBUG_FRAME_SECTION
415 #define DEBUG_FRAME_SECTION ".debug_frame"
418 #ifndef FUNC_BEGIN_LABEL
419 #define FUNC_BEGIN_LABEL "LFB"
422 #ifndef FUNC_END_LABEL
423 #define FUNC_END_LABEL "LFE"
426 #ifndef FRAME_BEGIN_LABEL
427 #define FRAME_BEGIN_LABEL "Lframe"
429 #define CIE_AFTER_SIZE_LABEL "LSCIE"
430 #define CIE_END_LABEL "LECIE"
431 #define FDE_LABEL "LSFDE"
432 #define FDE_AFTER_SIZE_LABEL "LASFDE"
433 #define FDE_END_LABEL "LEFDE"
434 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
435 #define LINE_NUMBER_END_LABEL "LELT"
436 #define LN_PROLOG_AS_LABEL "LASLTP"
437 #define LN_PROLOG_END_LABEL "LELTP"
438 #define DIE_LABEL_PREFIX "DW"
440 /* The DWARF 2 CFA column which tracks the return address. Normally this
441 is the column for PC, or the first column after all of the hard
443 #ifndef DWARF_FRAME_RETURN_COLUMN
445 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
447 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
451 /* The mapping from gcc register number to DWARF 2 CFA column number. By
452 default, we just provide columns for all registers. */
453 #ifndef DWARF_FRAME_REGNUM
454 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
457 /* Hook used by __throw. */
460 expand_builtin_dwarf_sp_column (void)
462 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
463 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
466 /* Return a pointer to a copy of the section string name S with all
467 attributes stripped off, and an asterisk prepended (for assemble_name). */
470 stripattributes (const char *s
)
472 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
477 while (*s
&& *s
!= ',')
484 /* MEM is a memory reference for the register size table, each element of
485 which has mode MODE. Initialize column C as a return address column. */
488 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
490 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
491 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
492 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
495 /* Generate code to initialize the register size table. */
498 expand_builtin_init_dwarf_reg_sizes (tree address
)
501 enum machine_mode mode
= TYPE_MODE (char_type_node
);
502 rtx addr
= expand_normal (address
);
503 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
504 bool wrote_return_column
= false;
506 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
508 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
510 if (rnum
< DWARF_FRAME_REGISTERS
)
512 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
513 enum machine_mode save_mode
= reg_raw_mode
[i
];
516 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
517 save_mode
= choose_hard_reg_mode (i
, 1, true);
518 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
520 if (save_mode
== VOIDmode
)
522 wrote_return_column
= true;
524 size
= GET_MODE_SIZE (save_mode
);
528 emit_move_insn (adjust_address (mem
, mode
, offset
),
529 gen_int_mode (size
, mode
));
533 if (!wrote_return_column
)
534 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
536 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
537 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
540 targetm
.init_dwarf_reg_sizes_extra (address
);
543 /* Convert a DWARF call frame info. operation to its string name */
546 dwarf_cfi_name (unsigned int cfi_opc
)
550 case DW_CFA_advance_loc
:
551 return "DW_CFA_advance_loc";
553 return "DW_CFA_offset";
555 return "DW_CFA_restore";
559 return "DW_CFA_set_loc";
560 case DW_CFA_advance_loc1
:
561 return "DW_CFA_advance_loc1";
562 case DW_CFA_advance_loc2
:
563 return "DW_CFA_advance_loc2";
564 case DW_CFA_advance_loc4
:
565 return "DW_CFA_advance_loc4";
566 case DW_CFA_offset_extended
:
567 return "DW_CFA_offset_extended";
568 case DW_CFA_restore_extended
:
569 return "DW_CFA_restore_extended";
570 case DW_CFA_undefined
:
571 return "DW_CFA_undefined";
572 case DW_CFA_same_value
:
573 return "DW_CFA_same_value";
574 case DW_CFA_register
:
575 return "DW_CFA_register";
576 case DW_CFA_remember_state
:
577 return "DW_CFA_remember_state";
578 case DW_CFA_restore_state
:
579 return "DW_CFA_restore_state";
581 return "DW_CFA_def_cfa";
582 case DW_CFA_def_cfa_register
:
583 return "DW_CFA_def_cfa_register";
584 case DW_CFA_def_cfa_offset
:
585 return "DW_CFA_def_cfa_offset";
588 case DW_CFA_def_cfa_expression
:
589 return "DW_CFA_def_cfa_expression";
590 case DW_CFA_expression
:
591 return "DW_CFA_expression";
592 case DW_CFA_offset_extended_sf
:
593 return "DW_CFA_offset_extended_sf";
594 case DW_CFA_def_cfa_sf
:
595 return "DW_CFA_def_cfa_sf";
596 case DW_CFA_def_cfa_offset_sf
:
597 return "DW_CFA_def_cfa_offset_sf";
599 /* SGI/MIPS specific */
600 case DW_CFA_MIPS_advance_loc8
:
601 return "DW_CFA_MIPS_advance_loc8";
604 case DW_CFA_GNU_window_save
:
605 return "DW_CFA_GNU_window_save";
606 case DW_CFA_GNU_args_size
:
607 return "DW_CFA_GNU_args_size";
608 case DW_CFA_GNU_negative_offset_extended
:
609 return "DW_CFA_GNU_negative_offset_extended";
612 return "DW_CFA_<unknown>";
616 /* Return a pointer to a newly allocated Call Frame Instruction. */
618 static inline dw_cfi_ref
621 dw_cfi_ref cfi
= GGC_NEW (dw_cfi_node
);
623 cfi
->dw_cfi_next
= NULL
;
624 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
625 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
630 /* Add a Call Frame Instruction to list of instructions. */
633 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
636 dw_fde_ref fde
= current_fde ();
638 /* When DRAP is used, CFA is defined with an expression. Redefine
639 CFA may lead to a different CFA value. */
640 if (fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
641 switch (cfi
->dw_cfi_opc
)
643 case DW_CFA_def_cfa_register
:
644 case DW_CFA_def_cfa_offset
:
645 case DW_CFA_def_cfa_offset_sf
:
647 case DW_CFA_def_cfa_sf
:
654 /* Find the end of the chain. */
655 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
661 /* Generate a new label for the CFI info to refer to. */
664 dwarf2out_cfi_label (void)
666 static char label
[20];
668 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
669 ASM_OUTPUT_LABEL (asm_out_file
, label
);
673 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
674 or to the CIE if LABEL is NULL. */
677 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
681 dw_fde_ref fde
= current_fde ();
683 gcc_assert (fde
!= NULL
);
686 label
= dwarf2out_cfi_label ();
688 if (fde
->dw_fde_current_label
== NULL
689 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
693 label
= xstrdup (label
);
695 /* Set the location counter to the new label. */
697 /* If we have a current label, advance from there, otherwise
698 set the location directly using set_loc. */
699 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
700 ? DW_CFA_advance_loc4
702 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
703 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
705 fde
->dw_fde_current_label
= label
;
708 add_cfi (&fde
->dw_fde_cfi
, cfi
);
712 add_cfi (&cie_cfi_head
, cfi
);
715 /* Subroutine of lookup_cfa. */
718 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
720 switch (cfi
->dw_cfi_opc
)
722 case DW_CFA_def_cfa_offset
:
723 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
725 case DW_CFA_def_cfa_offset_sf
:
727 = cfi
->dw_cfi_oprnd1
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
729 case DW_CFA_def_cfa_register
:
730 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
733 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
734 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
736 case DW_CFA_def_cfa_sf
:
737 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
739 = cfi
->dw_cfi_oprnd2
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
741 case DW_CFA_def_cfa_expression
:
742 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
749 /* Find the previous value for the CFA. */
752 lookup_cfa (dw_cfa_location
*loc
)
757 loc
->reg
= INVALID_REGNUM
;
760 loc
->base_offset
= 0;
762 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
763 lookup_cfa_1 (cfi
, loc
);
765 fde
= current_fde ();
767 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
768 lookup_cfa_1 (cfi
, loc
);
771 /* The current rule for calculating the DWARF2 canonical frame address. */
772 static dw_cfa_location cfa
;
774 /* The register used for saving registers to the stack, and its offset
776 static dw_cfa_location cfa_store
;
778 /* The running total of the size of arguments pushed onto the stack. */
779 static HOST_WIDE_INT args_size
;
781 /* The last args_size we actually output. */
782 static HOST_WIDE_INT old_args_size
;
784 /* Entry point to update the canonical frame address (CFA).
785 LABEL is passed to add_fde_cfi. The value of CFA is now to be
786 calculated from REG+OFFSET. */
789 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
796 def_cfa_1 (label
, &loc
);
799 /* Determine if two dw_cfa_location structures define the same data. */
802 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
804 return (loc1
->reg
== loc2
->reg
805 && loc1
->offset
== loc2
->offset
806 && loc1
->indirect
== loc2
->indirect
807 && (loc1
->indirect
== 0
808 || loc1
->base_offset
== loc2
->base_offset
));
811 /* This routine does the actual work. The CFA is now calculated from
812 the dw_cfa_location structure. */
815 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
818 dw_cfa_location old_cfa
, loc
;
823 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
824 cfa_store
.offset
= loc
.offset
;
826 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
827 lookup_cfa (&old_cfa
);
829 /* If nothing changed, no need to issue any call frame instructions. */
830 if (cfa_equal_p (&loc
, &old_cfa
))
835 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
837 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
838 the CFA register did not change but the offset did. */
841 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
842 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
844 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
845 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= f_offset
;
849 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
850 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
854 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
855 else if (loc
.offset
== old_cfa
.offset
856 && old_cfa
.reg
!= INVALID_REGNUM
859 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
860 indicating the CFA register has changed to <register> but the
861 offset has not changed. */
862 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
863 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
867 else if (loc
.indirect
== 0)
869 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
870 indicating the CFA register has changed to <register> with
871 the specified offset. */
874 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
875 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
877 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
878 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
879 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= f_offset
;
883 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
884 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
885 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
890 /* Construct a DW_CFA_def_cfa_expression instruction to
891 calculate the CFA using a full location expression since no
892 register-offset pair is available. */
893 struct dw_loc_descr_struct
*loc_list
;
895 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
896 loc_list
= build_cfa_loc (&loc
, 0);
897 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
900 add_fde_cfi (label
, cfi
);
903 /* Add the CFI for saving a register. REG is the CFA column number.
904 LABEL is passed to add_fde_cfi.
905 If SREG is -1, the register is saved at OFFSET from the CFA;
906 otherwise it is saved in SREG. */
909 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
911 dw_cfi_ref cfi
= new_cfi ();
912 dw_fde_ref fde
= current_fde ();
914 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
916 /* When stack is aligned, store REG using DW_CFA_expression with
919 && fde
->stack_realign
920 && sreg
== INVALID_REGNUM
)
922 cfi
->dw_cfi_opc
= DW_CFA_expression
;
923 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= reg
;
924 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
925 = build_cfa_aligned_loc (offset
, fde
->stack_realignment
);
927 else if (sreg
== INVALID_REGNUM
)
930 /* The register number won't fit in 6 bits, so we have to use
932 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
934 cfi
->dw_cfi_opc
= DW_CFA_offset
;
936 #ifdef ENABLE_CHECKING
938 /* If we get an offset that is not a multiple of
939 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
940 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
942 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
944 gcc_assert (check_offset
* DWARF_CIE_DATA_ALIGNMENT
== offset
);
947 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
949 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
951 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
953 else if (sreg
== reg
)
954 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
957 cfi
->dw_cfi_opc
= DW_CFA_register
;
958 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
961 add_fde_cfi (label
, cfi
);
964 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
965 This CFI tells the unwinder that it needs to restore the window registers
966 from the previous frame's window save area.
968 ??? Perhaps we should note in the CIE where windows are saved (instead of
969 assuming 0(cfa)) and what registers are in the window. */
972 dwarf2out_window_save (const char *label
)
974 dw_cfi_ref cfi
= new_cfi ();
976 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
977 add_fde_cfi (label
, cfi
);
980 /* Add a CFI to update the running total of the size of arguments
981 pushed onto the stack. */
984 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
988 if (size
== old_args_size
)
991 old_args_size
= size
;
994 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
995 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
996 add_fde_cfi (label
, cfi
);
999 /* Entry point for saving a register to the stack. REG is the GCC register
1000 number. LABEL and OFFSET are passed to reg_save. */
1003 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
1005 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
1008 /* Entry point for saving the return address in the stack.
1009 LABEL and OFFSET are passed to reg_save. */
1012 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
1014 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
1017 /* Entry point for saving the return address in a register.
1018 LABEL and SREG are passed to reg_save. */
1021 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
1023 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
1026 #ifdef DWARF2_UNWIND_INFO
1027 /* Record the initial position of the return address. RTL is
1028 INCOMING_RETURN_ADDR_RTX. */
1031 initial_return_save (rtx rtl
)
1033 unsigned int reg
= INVALID_REGNUM
;
1034 HOST_WIDE_INT offset
= 0;
1036 switch (GET_CODE (rtl
))
1039 /* RA is in a register. */
1040 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
1044 /* RA is on the stack. */
1045 rtl
= XEXP (rtl
, 0);
1046 switch (GET_CODE (rtl
))
1049 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1054 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1055 offset
= INTVAL (XEXP (rtl
, 1));
1059 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1060 offset
= -INTVAL (XEXP (rtl
, 1));
1070 /* The return address is at some offset from any value we can
1071 actually load. For instance, on the SPARC it is in %i7+8. Just
1072 ignore the offset for now; it doesn't matter for unwinding frames. */
1073 gcc_assert (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
);
1074 initial_return_save (XEXP (rtl
, 0));
1081 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1082 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1086 /* Given a SET, calculate the amount of stack adjustment it
1089 static HOST_WIDE_INT
1090 stack_adjust_offset (const_rtx pattern
)
1092 const_rtx src
= SET_SRC (pattern
);
1093 const_rtx dest
= SET_DEST (pattern
);
1094 HOST_WIDE_INT offset
= 0;
1097 if (dest
== stack_pointer_rtx
)
1099 /* (set (reg sp) (plus (reg sp) (const_int))) */
1100 code
= GET_CODE (src
);
1101 if (! (code
== PLUS
|| code
== MINUS
)
1102 || XEXP (src
, 0) != stack_pointer_rtx
1103 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1106 offset
= INTVAL (XEXP (src
, 1));
1110 else if (MEM_P (dest
))
1112 /* (set (mem (pre_dec (reg sp))) (foo)) */
1113 src
= XEXP (dest
, 0);
1114 code
= GET_CODE (src
);
1120 if (XEXP (src
, 0) == stack_pointer_rtx
)
1122 rtx val
= XEXP (XEXP (src
, 1), 1);
1123 /* We handle only adjustments by constant amount. */
1124 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1125 && GET_CODE (val
) == CONST_INT
);
1126 offset
= -INTVAL (val
);
1133 if (XEXP (src
, 0) == stack_pointer_rtx
)
1135 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1142 if (XEXP (src
, 0) == stack_pointer_rtx
)
1144 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1159 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1160 indexed by INSN_UID. */
1162 static HOST_WIDE_INT
*barrier_args_size
;
1164 /* Helper function for compute_barrier_args_size. Handle one insn. */
1166 static HOST_WIDE_INT
1167 compute_barrier_args_size_1 (rtx insn
, HOST_WIDE_INT cur_args_size
,
1168 VEC (rtx
, heap
) **next
)
1170 HOST_WIDE_INT offset
= 0;
1173 if (! RTX_FRAME_RELATED_P (insn
))
1175 if (prologue_epilogue_contains (insn
)
1176 || sibcall_epilogue_contains (insn
))
1178 else if (GET_CODE (PATTERN (insn
)) == SET
)
1179 offset
= stack_adjust_offset (PATTERN (insn
));
1180 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1181 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1183 /* There may be stack adjustments inside compound insns. Search
1185 for (i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1186 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1187 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1192 rtx expr
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1196 expr
= XEXP (expr
, 0);
1197 if (GET_CODE (expr
) == PARALLEL
1198 || GET_CODE (expr
) == SEQUENCE
)
1199 for (i
= 1; i
< XVECLEN (expr
, 0); i
++)
1201 rtx elem
= XVECEXP (expr
, 0, i
);
1203 if (GET_CODE (elem
) == SET
&& !RTX_FRAME_RELATED_P (elem
))
1204 offset
+= stack_adjust_offset (elem
);
1209 #ifndef STACK_GROWS_DOWNWARD
1213 cur_args_size
+= offset
;
1214 if (cur_args_size
< 0)
1219 rtx dest
= JUMP_LABEL (insn
);
1223 if (barrier_args_size
[INSN_UID (dest
)] < 0)
1225 barrier_args_size
[INSN_UID (dest
)] = cur_args_size
;
1226 VEC_safe_push (rtx
, heap
, *next
, dest
);
1229 gcc_assert (barrier_args_size
[INSN_UID (dest
)]
1234 return cur_args_size
;
1237 /* Walk the whole function and compute args_size on BARRIERs. */
1240 compute_barrier_args_size (void)
1242 int max_uid
= get_max_uid (), i
;
1244 VEC (rtx
, heap
) *worklist
, *next
, *tmp
;
1246 barrier_args_size
= XNEWVEC (HOST_WIDE_INT
, max_uid
);
1247 for (i
= 0; i
< max_uid
; i
++)
1248 barrier_args_size
[i
] = -1;
1250 worklist
= VEC_alloc (rtx
, heap
, 20);
1251 next
= VEC_alloc (rtx
, heap
, 20);
1252 insn
= get_insns ();
1253 barrier_args_size
[INSN_UID (insn
)] = 0;
1254 VEC_quick_push (rtx
, worklist
, insn
);
1257 while (!VEC_empty (rtx
, worklist
))
1260 HOST_WIDE_INT cur_args_size
;
1262 insn
= VEC_pop (rtx
, worklist
);
1263 cur_args_size
= barrier_args_size
[INSN_UID (insn
)];
1264 prev
= prev_nonnote_insn (insn
);
1265 if (prev
&& BARRIER_P (prev
))
1266 barrier_args_size
[INSN_UID (prev
)] = cur_args_size
;
1268 for (; insn
; insn
= NEXT_INSN (insn
))
1270 if (INSN_DELETED_P (insn
) || NOTE_P (insn
))
1272 if (BARRIER_P (insn
))
1277 gcc_assert (barrier_args_size
[INSN_UID (insn
)] < 0
1278 || barrier_args_size
[INSN_UID (insn
)]
1283 body
= PATTERN (insn
);
1284 if (GET_CODE (body
) == SEQUENCE
)
1286 for (i
= 1; i
< XVECLEN (body
, 0); i
++)
1288 = compute_barrier_args_size_1 (XVECEXP (body
, 0, i
),
1289 cur_args_size
, &next
);
1291 = compute_barrier_args_size_1 (XVECEXP (body
, 0, 0),
1292 cur_args_size
, &next
);
1296 = compute_barrier_args_size_1 (insn
, cur_args_size
, &next
);
1300 if (VEC_empty (rtx
, next
))
1303 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1307 VEC_truncate (rtx
, next
, 0);
1310 VEC_free (rtx
, heap
, worklist
);
1311 VEC_free (rtx
, heap
, next
);
1315 /* Check INSN to see if it looks like a push or a stack adjustment, and
1316 make a note of it if it does. EH uses this information to find out how
1317 much extra space it needs to pop off the stack. */
1320 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1322 HOST_WIDE_INT offset
;
1326 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1327 with this function. Proper support would require all frame-related
1328 insns to be marked, and to be able to handle saving state around
1329 epilogues textually in the middle of the function. */
1330 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1333 /* If only calls can throw, and we have a frame pointer,
1334 save up adjustments until we see the CALL_INSN. */
1335 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1337 if (CALL_P (insn
) && !after_p
)
1339 /* Extract the size of the args from the CALL rtx itself. */
1340 insn
= PATTERN (insn
);
1341 if (GET_CODE (insn
) == PARALLEL
)
1342 insn
= XVECEXP (insn
, 0, 0);
1343 if (GET_CODE (insn
) == SET
)
1344 insn
= SET_SRC (insn
);
1345 gcc_assert (GET_CODE (insn
) == CALL
);
1346 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1351 if (CALL_P (insn
) && !after_p
)
1353 if (!flag_asynchronous_unwind_tables
)
1354 dwarf2out_args_size ("", args_size
);
1357 else if (BARRIER_P (insn
))
1359 if (barrier_args_size
== NULL
)
1360 compute_barrier_args_size ();
1361 offset
= barrier_args_size
[INSN_UID (insn
)];
1365 offset
-= args_size
;
1366 #ifndef STACK_GROWS_DOWNWARD
1370 else if (GET_CODE (PATTERN (insn
)) == SET
)
1371 offset
= stack_adjust_offset (PATTERN (insn
));
1372 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1373 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1375 /* There may be stack adjustments inside compound insns. Search
1377 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1378 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1379 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1387 label
= dwarf2out_cfi_label ();
1388 dwarf2out_args_size_adjust (offset
, label
);
1391 /* Adjust args_size based on stack adjustment OFFSET. */
1394 dwarf2out_args_size_adjust (HOST_WIDE_INT offset
, const char *label
)
1396 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1397 cfa
.offset
+= offset
;
1399 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1400 cfa_store
.offset
+= offset
;
1402 #ifndef STACK_GROWS_DOWNWARD
1406 args_size
+= offset
;
1410 def_cfa_1 (label
, &cfa
);
1411 if (flag_asynchronous_unwind_tables
)
1412 dwarf2out_args_size (label
, args_size
);
1417 /* We delay emitting a register save until either (a) we reach the end
1418 of the prologue or (b) the register is clobbered. This clusters
1419 register saves so that there are fewer pc advances. */
1421 struct queued_reg_save
GTY(())
1423 struct queued_reg_save
*next
;
1425 HOST_WIDE_INT cfa_offset
;
1429 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1431 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1432 struct reg_saved_in_data
GTY(()) {
1437 /* A list of registers saved in other registers.
1438 The list intentionally has a small maximum capacity of 4; if your
1439 port needs more than that, you might consider implementing a
1440 more efficient data structure. */
1441 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1442 static GTY(()) size_t num_regs_saved_in_regs
;
1444 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1445 static const char *last_reg_save_label
;
1447 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1448 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1451 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1453 struct queued_reg_save
*q
;
1455 /* Duplicates waste space, but it's also necessary to remove them
1456 for correctness, since the queue gets output in reverse
1458 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1459 if (REGNO (q
->reg
) == REGNO (reg
))
1464 q
= GGC_NEW (struct queued_reg_save
);
1465 q
->next
= queued_reg_saves
;
1466 queued_reg_saves
= q
;
1470 q
->cfa_offset
= offset
;
1471 q
->saved_reg
= sreg
;
1473 last_reg_save_label
= label
;
1476 /* Output all the entries in QUEUED_REG_SAVES. */
1479 flush_queued_reg_saves (void)
1481 struct queued_reg_save
*q
;
1483 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1486 unsigned int reg
, sreg
;
1488 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1489 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1491 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1493 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1494 num_regs_saved_in_regs
++;
1496 if (i
!= num_regs_saved_in_regs
)
1498 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1499 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1502 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1504 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1506 sreg
= INVALID_REGNUM
;
1507 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1510 queued_reg_saves
= NULL
;
1511 last_reg_save_label
= NULL
;
1514 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1515 location for? Or, does it clobber a register which we've previously
1516 said that some other register is saved in, and for which we now
1517 have a new location for? */
1520 clobbers_queued_reg_save (const_rtx insn
)
1522 struct queued_reg_save
*q
;
1524 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1527 if (modified_in_p (q
->reg
, insn
))
1529 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1530 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1531 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1538 /* Entry point for saving the first register into the second. */
1541 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1544 unsigned int regno
, sregno
;
1546 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1547 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1549 if (i
== num_regs_saved_in_regs
)
1551 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1552 num_regs_saved_in_regs
++;
1554 regs_saved_in_regs
[i
].orig_reg
= reg
;
1555 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1557 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1558 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1559 reg_save (label
, regno
, sregno
, 0);
1562 /* What register, if any, is currently saved in REG? */
1565 reg_saved_in (rtx reg
)
1567 unsigned int regn
= REGNO (reg
);
1569 struct queued_reg_save
*q
;
1571 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1572 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1575 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1576 if (regs_saved_in_regs
[i
].saved_in_reg
1577 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1578 return regs_saved_in_regs
[i
].orig_reg
;
1584 /* A temporary register holding an integral value used in adjusting SP
1585 or setting up the store_reg. The "offset" field holds the integer
1586 value, not an offset. */
1587 static dw_cfa_location cfa_temp
;
1589 /* Record call frame debugging information for an expression EXPR,
1590 which either sets SP or FP (adjusting how we calculate the frame
1591 address) or saves a register to the stack or another register.
1592 LABEL indicates the address of EXPR.
1594 This function encodes a state machine mapping rtxes to actions on
1595 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1596 users need not read the source code.
1598 The High-Level Picture
1600 Changes in the register we use to calculate the CFA: Currently we
1601 assume that if you copy the CFA register into another register, we
1602 should take the other one as the new CFA register; this seems to
1603 work pretty well. If it's wrong for some target, it's simple
1604 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1606 Changes in the register we use for saving registers to the stack:
1607 This is usually SP, but not always. Again, we deduce that if you
1608 copy SP into another register (and SP is not the CFA register),
1609 then the new register is the one we will be using for register
1610 saves. This also seems to work.
1612 Register saves: There's not much guesswork about this one; if
1613 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1614 register save, and the register used to calculate the destination
1615 had better be the one we think we're using for this purpose.
1616 It's also assumed that a copy from a call-saved register to another
1617 register is saving that register if RTX_FRAME_RELATED_P is set on
1618 that instruction. If the copy is from a call-saved register to
1619 the *same* register, that means that the register is now the same
1620 value as in the caller.
1622 Except: If the register being saved is the CFA register, and the
1623 offset is nonzero, we are saving the CFA, so we assume we have to
1624 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1625 the intent is to save the value of SP from the previous frame.
1627 In addition, if a register has previously been saved to a different
1630 Invariants / Summaries of Rules
1632 cfa current rule for calculating the CFA. It usually
1633 consists of a register and an offset.
1634 cfa_store register used by prologue code to save things to the stack
1635 cfa_store.offset is the offset from the value of
1636 cfa_store.reg to the actual CFA
1637 cfa_temp register holding an integral value. cfa_temp.offset
1638 stores the value, which will be used to adjust the
1639 stack pointer. cfa_temp is also used like cfa_store,
1640 to track stores to the stack via fp or a temp reg.
1642 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1643 with cfa.reg as the first operand changes the cfa.reg and its
1644 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1647 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1648 expression yielding a constant. This sets cfa_temp.reg
1649 and cfa_temp.offset.
1651 Rule 5: Create a new register cfa_store used to save items to the
1654 Rules 10-14: Save a register to the stack. Define offset as the
1655 difference of the original location and cfa_store's
1656 location (or cfa_temp's location if cfa_temp is used).
1658 Rules 16-20: If AND operation happens on sp in prologue, we assume
1659 stack is realigned. We will use a group of DW_OP_XXX
1660 expressions to represent the location of the stored
1661 register instead of CFA+offset.
1665 "{a,b}" indicates a choice of a xor b.
1666 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1669 (set <reg1> <reg2>:cfa.reg)
1670 effects: cfa.reg = <reg1>
1671 cfa.offset unchanged
1672 cfa_temp.reg = <reg1>
1673 cfa_temp.offset = cfa.offset
1676 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1677 {<const_int>,<reg>:cfa_temp.reg}))
1678 effects: cfa.reg = sp if fp used
1679 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1680 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1681 if cfa_store.reg==sp
1684 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1685 effects: cfa.reg = fp
1686 cfa_offset += +/- <const_int>
1689 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1690 constraints: <reg1> != fp
1692 effects: cfa.reg = <reg1>
1693 cfa_temp.reg = <reg1>
1694 cfa_temp.offset = cfa.offset
1697 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1698 constraints: <reg1> != fp
1700 effects: cfa_store.reg = <reg1>
1701 cfa_store.offset = cfa.offset - cfa_temp.offset
1704 (set <reg> <const_int>)
1705 effects: cfa_temp.reg = <reg>
1706 cfa_temp.offset = <const_int>
1709 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1710 effects: cfa_temp.reg = <reg1>
1711 cfa_temp.offset |= <const_int>
1714 (set <reg> (high <exp>))
1718 (set <reg> (lo_sum <exp> <const_int>))
1719 effects: cfa_temp.reg = <reg>
1720 cfa_temp.offset = <const_int>
1723 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1724 effects: cfa_store.offset -= <const_int>
1725 cfa.offset = cfa_store.offset if cfa.reg == sp
1727 cfa.base_offset = -cfa_store.offset
1730 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1731 effects: cfa_store.offset += -/+ mode_size(mem)
1732 cfa.offset = cfa_store.offset if cfa.reg == sp
1734 cfa.base_offset = -cfa_store.offset
1737 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1740 effects: cfa.reg = <reg1>
1741 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1744 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1745 effects: cfa.reg = <reg1>
1746 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1749 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1750 effects: cfa.reg = <reg1>
1751 cfa.base_offset = -cfa_temp.offset
1752 cfa_temp.offset -= mode_size(mem)
1755 (set <reg> {unspec, unspec_volatile})
1756 effects: target-dependent
1759 (set sp (and: sp <const_int>))
1760 constraints: cfa_store.reg == sp
1761 effects: current_fde.stack_realign = 1
1762 cfa_store.offset = 0
1763 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
1766 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
1767 effects: cfa_store.offset += -/+ mode_size(mem)
1770 (set (mem ({pre_inc, pre_dec} sp)) fp)
1771 constraints: fde->stack_realign == 1
1772 effects: cfa_store.offset = 0
1773 cfa.reg != HARD_FRAME_POINTER_REGNUM
1776 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
1777 constraints: fde->stack_realign == 1
1779 && cfa.indirect == 0
1780 && cfa.reg != HARD_FRAME_POINTER_REGNUM
1781 effects: Use DW_CFA_def_cfa_expression to define cfa
1782 cfa.reg == fde->drap_reg
1785 (set reg fde->drap_reg)
1786 constraints: fde->vdrap_reg == INVALID_REGNUM
1787 effects: fde->vdrap_reg = reg.
1788 (set mem fde->drap_reg)
1789 constraints: fde->drap_reg_saved == 1
1793 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1795 rtx src
, dest
, span
;
1796 HOST_WIDE_INT offset
;
1799 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1800 the PARALLEL independently. The first element is always processed if
1801 it is a SET. This is for backward compatibility. Other elements
1802 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1803 flag is set in them. */
1804 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1807 int limit
= XVECLEN (expr
, 0);
1810 /* PARALLELs have strict read-modify-write semantics, so we
1811 ought to evaluate every rvalue before changing any lvalue.
1812 It's cumbersome to do that in general, but there's an
1813 easy approximation that is enough for all current users:
1814 handle register saves before register assignments. */
1815 if (GET_CODE (expr
) == PARALLEL
)
1816 for (par_index
= 0; par_index
< limit
; par_index
++)
1818 elem
= XVECEXP (expr
, 0, par_index
);
1819 if (GET_CODE (elem
) == SET
1820 && MEM_P (SET_DEST (elem
))
1821 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1822 dwarf2out_frame_debug_expr (elem
, label
);
1825 for (par_index
= 0; par_index
< limit
; par_index
++)
1827 elem
= XVECEXP (expr
, 0, par_index
);
1828 if (GET_CODE (elem
) == SET
1829 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
1830 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1831 dwarf2out_frame_debug_expr (elem
, label
);
1832 else if (GET_CODE (elem
) == SET
1834 && !RTX_FRAME_RELATED_P (elem
))
1836 /* Stack adjustment combining might combine some post-prologue
1837 stack adjustment into a prologue stack adjustment. */
1838 HOST_WIDE_INT offset
= stack_adjust_offset (elem
);
1841 dwarf2out_args_size_adjust (offset
, label
);
1847 gcc_assert (GET_CODE (expr
) == SET
);
1849 src
= SET_SRC (expr
);
1850 dest
= SET_DEST (expr
);
1854 rtx rsi
= reg_saved_in (src
);
1859 fde
= current_fde ();
1861 if (GET_CODE (src
) == REG
1863 && fde
->drap_reg
== REGNO (src
)
1864 && (fde
->drap_reg_saved
1865 || GET_CODE (dest
) == REG
))
1868 /* If we are saving dynamic realign argument pointer to a
1869 register, the destination is virtual dynamic realign
1870 argument pointer. It may be used to access argument. */
1871 if (GET_CODE (dest
) == REG
)
1873 gcc_assert (fde
->vdrap_reg
== INVALID_REGNUM
);
1874 fde
->vdrap_reg
= REGNO (dest
);
1879 switch (GET_CODE (dest
))
1882 switch (GET_CODE (src
))
1884 /* Setting FP from SP. */
1886 if (cfa
.reg
== (unsigned) REGNO (src
))
1889 /* Update the CFA rule wrt SP or FP. Make sure src is
1890 relative to the current CFA register.
1892 We used to require that dest be either SP or FP, but the
1893 ARM copies SP to a temporary register, and from there to
1894 FP. So we just rely on the backends to only set
1895 RTX_FRAME_RELATED_P on appropriate insns. */
1896 cfa
.reg
= REGNO (dest
);
1897 cfa_temp
.reg
= cfa
.reg
;
1898 cfa_temp
.offset
= cfa
.offset
;
1902 /* Saving a register in a register. */
1903 gcc_assert (!fixed_regs
[REGNO (dest
)]
1904 /* For the SPARC and its register window. */
1905 || (DWARF_FRAME_REGNUM (REGNO (src
))
1906 == DWARF_FRAME_RETURN_COLUMN
));
1908 /* After stack is aligned, we can only save SP in FP
1909 if drap register is used. In this case, we have
1910 to restore stack pointer with the CFA value and we
1911 don't generate this DWARF information. */
1913 && fde
->stack_realign
1914 && REGNO (src
) == STACK_POINTER_REGNUM
)
1915 gcc_assert (REGNO (dest
) == HARD_FRAME_POINTER_REGNUM
1916 && fde
->drap_reg
!= INVALID_REGNUM
1917 && cfa
.reg
!= REGNO (src
));
1919 queue_reg_save (label
, src
, dest
, 0);
1926 if (dest
== stack_pointer_rtx
)
1930 switch (GET_CODE (XEXP (src
, 1)))
1933 offset
= INTVAL (XEXP (src
, 1));
1936 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
1938 offset
= cfa_temp
.offset
;
1944 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1946 /* Restoring SP from FP in the epilogue. */
1947 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
1948 cfa
.reg
= STACK_POINTER_REGNUM
;
1950 else if (GET_CODE (src
) == LO_SUM
)
1951 /* Assume we've set the source reg of the LO_SUM from sp. */
1954 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1956 if (GET_CODE (src
) != MINUS
)
1958 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1959 cfa
.offset
+= offset
;
1960 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1961 cfa_store
.offset
+= offset
;
1963 else if (dest
== hard_frame_pointer_rtx
)
1966 /* Either setting the FP from an offset of the SP,
1967 or adjusting the FP */
1968 gcc_assert (frame_pointer_needed
);
1970 gcc_assert (REG_P (XEXP (src
, 0))
1971 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1972 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1973 offset
= INTVAL (XEXP (src
, 1));
1974 if (GET_CODE (src
) != MINUS
)
1976 cfa
.offset
+= offset
;
1977 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1981 gcc_assert (GET_CODE (src
) != MINUS
);
1984 if (REG_P (XEXP (src
, 0))
1985 && REGNO (XEXP (src
, 0)) == cfa
.reg
1986 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1988 /* Setting a temporary CFA register that will be copied
1989 into the FP later on. */
1990 offset
= - INTVAL (XEXP (src
, 1));
1991 cfa
.offset
+= offset
;
1992 cfa
.reg
= REGNO (dest
);
1993 /* Or used to save regs to the stack. */
1994 cfa_temp
.reg
= cfa
.reg
;
1995 cfa_temp
.offset
= cfa
.offset
;
1999 else if (REG_P (XEXP (src
, 0))
2000 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2001 && XEXP (src
, 1) == stack_pointer_rtx
)
2003 /* Setting a scratch register that we will use instead
2004 of SP for saving registers to the stack. */
2005 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
2006 cfa_store
.reg
= REGNO (dest
);
2007 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
2011 else if (GET_CODE (src
) == LO_SUM
2012 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
2014 cfa_temp
.reg
= REGNO (dest
);
2015 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
2024 cfa_temp
.reg
= REGNO (dest
);
2025 cfa_temp
.offset
= INTVAL (src
);
2030 gcc_assert (REG_P (XEXP (src
, 0))
2031 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
2032 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
2034 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
2035 cfa_temp
.reg
= REGNO (dest
);
2036 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
2039 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2040 which will fill in all of the bits. */
2047 case UNSPEC_VOLATILE
:
2048 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
2049 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
2054 /* If this AND operation happens on stack pointer in prologue,
2055 we assume the stack is realigned and we extract the
2057 if (fde
&& XEXP (src
, 0) == stack_pointer_rtx
)
2059 gcc_assert (cfa_store
.reg
== REGNO (XEXP (src
, 0)));
2060 fde
->stack_realign
= 1;
2061 fde
->stack_realignment
= INTVAL (XEXP (src
, 1));
2062 cfa_store
.offset
= 0;
2064 if (cfa
.reg
!= STACK_POINTER_REGNUM
2065 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2066 fde
->drap_reg
= cfa
.reg
;
2074 def_cfa_1 (label
, &cfa
);
2079 /* Saving a register to the stack. Make sure dest is relative to the
2081 switch (GET_CODE (XEXP (dest
, 0)))
2086 /* We can't handle variable size modifications. */
2087 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
2089 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
2091 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
2092 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2094 cfa_store
.offset
+= offset
;
2095 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2096 cfa
.offset
= cfa_store
.offset
;
2098 offset
= -cfa_store
.offset
;
2104 offset
= GET_MODE_SIZE (GET_MODE (dest
));
2105 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
2108 gcc_assert ((REGNO (XEXP (XEXP (dest
, 0), 0))
2109 == STACK_POINTER_REGNUM
)
2110 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
2112 cfa_store
.offset
+= offset
;
2114 /* Rule 18: If stack is aligned, we will use FP as a
2115 reference to represent the address of the stored
2118 && fde
->stack_realign
2119 && src
== hard_frame_pointer_rtx
)
2121 gcc_assert (cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
);
2122 cfa_store
.offset
= 0;
2125 if (cfa
.reg
== STACK_POINTER_REGNUM
)
2126 cfa
.offset
= cfa_store
.offset
;
2128 offset
= -cfa_store
.offset
;
2132 /* With an offset. */
2139 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
2140 && REG_P (XEXP (XEXP (dest
, 0), 0)));
2141 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
2142 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
2145 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
2147 if (cfa_store
.reg
== (unsigned) regno
)
2148 offset
-= cfa_store
.offset
;
2151 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2152 offset
-= cfa_temp
.offset
;
2158 /* Without an offset. */
2161 int regno
= REGNO (XEXP (dest
, 0));
2163 if (cfa_store
.reg
== (unsigned) regno
)
2164 offset
= -cfa_store
.offset
;
2167 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
2168 offset
= -cfa_temp
.offset
;
2175 gcc_assert (cfa_temp
.reg
2176 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
2177 offset
= -cfa_temp
.offset
;
2178 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
2186 /* If the source operand of this MEM operation is not a
2187 register, basically the source is return address. Here
2188 we only care how much stack grew and we don't save it. */
2192 if (REGNO (src
) != STACK_POINTER_REGNUM
2193 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
2194 && (unsigned) REGNO (src
) == cfa
.reg
)
2196 /* We're storing the current CFA reg into the stack. */
2198 if (cfa
.offset
== 0)
2201 /* If stack is aligned, putting CFA reg into stack means
2202 we can no longer use reg + offset to represent CFA.
2203 Here we use DW_CFA_def_cfa_expression instead. The
2204 result of this expression equals to the original CFA
2207 && fde
->stack_realign
2208 && cfa
.indirect
== 0
2209 && cfa
.reg
!= HARD_FRAME_POINTER_REGNUM
)
2211 dw_cfa_location cfa_exp
;
2213 gcc_assert (fde
->drap_reg
== cfa
.reg
);
2215 cfa_exp
.indirect
= 1;
2216 cfa_exp
.reg
= HARD_FRAME_POINTER_REGNUM
;
2217 cfa_exp
.base_offset
= offset
;
2220 fde
->drap_reg_saved
= 1;
2222 def_cfa_1 (label
, &cfa_exp
);
2226 /* If the source register is exactly the CFA, assume
2227 we're saving SP like any other register; this happens
2229 def_cfa_1 (label
, &cfa
);
2230 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
2235 /* Otherwise, we'll need to look in the stack to
2236 calculate the CFA. */
2237 rtx x
= XEXP (dest
, 0);
2241 gcc_assert (REG_P (x
));
2243 cfa
.reg
= REGNO (x
);
2244 cfa
.base_offset
= offset
;
2246 def_cfa_1 (label
, &cfa
);
2251 def_cfa_1 (label
, &cfa
);
2253 span
= targetm
.dwarf_register_span (src
);
2256 queue_reg_save (label
, src
, NULL_RTX
, offset
);
2259 /* We have a PARALLEL describing where the contents of SRC
2260 live. Queue register saves for each piece of the
2264 HOST_WIDE_INT span_offset
= offset
;
2266 gcc_assert (GET_CODE (span
) == PARALLEL
);
2268 limit
= XVECLEN (span
, 0);
2269 for (par_index
= 0; par_index
< limit
; par_index
++)
2271 rtx elem
= XVECEXP (span
, 0, par_index
);
2273 queue_reg_save (label
, elem
, NULL_RTX
, span_offset
);
2274 span_offset
+= GET_MODE_SIZE (GET_MODE (elem
));
2285 /* Record call frame debugging information for INSN, which either
2286 sets SP or FP (adjusting how we calculate the frame address) or saves a
2287 register to the stack. If INSN is NULL_RTX, initialize our state.
2289 If AFTER_P is false, we're being called before the insn is emitted,
2290 otherwise after. Call instructions get invoked twice. */
2293 dwarf2out_frame_debug (rtx insn
, bool after_p
)
2298 if (insn
== NULL_RTX
)
2302 /* Flush any queued register saves. */
2303 flush_queued_reg_saves ();
2305 /* Set up state for generating call frame debug info. */
2308 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
2310 cfa
.reg
= STACK_POINTER_REGNUM
;
2313 cfa_temp
.offset
= 0;
2315 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
2317 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
2318 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
2320 num_regs_saved_in_regs
= 0;
2322 if (barrier_args_size
)
2324 XDELETEVEC (barrier_args_size
);
2325 barrier_args_size
= NULL
;
2330 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
2331 flush_queued_reg_saves ();
2333 if (! RTX_FRAME_RELATED_P (insn
))
2335 if (!ACCUMULATE_OUTGOING_ARGS
)
2336 dwarf2out_stack_adjust (insn
, after_p
);
2340 label
= dwarf2out_cfi_label ();
2341 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
2343 insn
= XEXP (src
, 0);
2345 insn
= PATTERN (insn
);
2347 dwarf2out_frame_debug_expr (insn
, label
);
2352 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
2353 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
2354 (enum dwarf_call_frame_info cfi
);
2356 static enum dw_cfi_oprnd_type
2357 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
2362 case DW_CFA_GNU_window_save
:
2363 return dw_cfi_oprnd_unused
;
2365 case DW_CFA_set_loc
:
2366 case DW_CFA_advance_loc1
:
2367 case DW_CFA_advance_loc2
:
2368 case DW_CFA_advance_loc4
:
2369 case DW_CFA_MIPS_advance_loc8
:
2370 return dw_cfi_oprnd_addr
;
2373 case DW_CFA_offset_extended
:
2374 case DW_CFA_def_cfa
:
2375 case DW_CFA_offset_extended_sf
:
2376 case DW_CFA_def_cfa_sf
:
2377 case DW_CFA_restore_extended
:
2378 case DW_CFA_undefined
:
2379 case DW_CFA_same_value
:
2380 case DW_CFA_def_cfa_register
:
2381 case DW_CFA_register
:
2382 return dw_cfi_oprnd_reg_num
;
2384 case DW_CFA_def_cfa_offset
:
2385 case DW_CFA_GNU_args_size
:
2386 case DW_CFA_def_cfa_offset_sf
:
2387 return dw_cfi_oprnd_offset
;
2389 case DW_CFA_def_cfa_expression
:
2390 case DW_CFA_expression
:
2391 return dw_cfi_oprnd_loc
;
2398 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2399 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2400 (enum dwarf_call_frame_info cfi
);
2402 static enum dw_cfi_oprnd_type
2403 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
2407 case DW_CFA_def_cfa
:
2408 case DW_CFA_def_cfa_sf
:
2410 case DW_CFA_offset_extended_sf
:
2411 case DW_CFA_offset_extended
:
2412 return dw_cfi_oprnd_offset
;
2414 case DW_CFA_register
:
2415 return dw_cfi_oprnd_reg_num
;
2418 return dw_cfi_oprnd_unused
;
2422 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2424 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2425 switch to the data section instead, and write out a synthetic label
2429 switch_to_eh_frame_section (void)
2433 #ifdef EH_FRAME_SECTION_NAME
2434 if (eh_frame_section
== 0)
2438 if (EH_TABLES_CAN_BE_READ_ONLY
)
2444 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2446 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2448 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2450 flags
= ((! flag_pic
2451 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2452 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2453 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2454 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2455 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2456 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2457 ? 0 : SECTION_WRITE
);
2460 flags
= SECTION_WRITE
;
2461 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2465 if (eh_frame_section
)
2466 switch_to_section (eh_frame_section
);
2469 /* We have no special eh_frame section. Put the information in
2470 the data section and emit special labels to guide collect2. */
2471 switch_to_section (data_section
);
2472 label
= get_file_function_name ("F");
2473 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2474 targetm
.asm_out
.globalize_label (asm_out_file
,
2475 IDENTIFIER_POINTER (label
));
2476 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2480 /* Output a Call Frame Information opcode and its operand(s). */
2483 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2486 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2487 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2488 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2489 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2490 ((unsigned HOST_WIDE_INT
)
2491 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
));
2492 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2494 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2495 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2496 "DW_CFA_offset, column 0x%lx", r
);
2497 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2499 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2501 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2502 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2503 "DW_CFA_restore, column 0x%lx", r
);
2507 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2508 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2510 switch (cfi
->dw_cfi_opc
)
2512 case DW_CFA_set_loc
:
2514 dw2_asm_output_encoded_addr_rtx (
2515 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2516 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2519 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2520 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2521 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2524 case DW_CFA_advance_loc1
:
2525 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2526 fde
->dw_fde_current_label
, NULL
);
2527 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2530 case DW_CFA_advance_loc2
:
2531 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2532 fde
->dw_fde_current_label
, NULL
);
2533 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2536 case DW_CFA_advance_loc4
:
2537 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2538 fde
->dw_fde_current_label
, NULL
);
2539 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2542 case DW_CFA_MIPS_advance_loc8
:
2543 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2544 fde
->dw_fde_current_label
, NULL
);
2545 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2548 case DW_CFA_offset_extended
:
2549 case DW_CFA_def_cfa
:
2550 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2551 dw2_asm_output_data_uleb128 (r
, NULL
);
2552 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2555 case DW_CFA_offset_extended_sf
:
2556 case DW_CFA_def_cfa_sf
:
2557 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2558 dw2_asm_output_data_uleb128 (r
, NULL
);
2559 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2562 case DW_CFA_restore_extended
:
2563 case DW_CFA_undefined
:
2564 case DW_CFA_same_value
:
2565 case DW_CFA_def_cfa_register
:
2566 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2567 dw2_asm_output_data_uleb128 (r
, NULL
);
2570 case DW_CFA_register
:
2571 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2572 dw2_asm_output_data_uleb128 (r
, NULL
);
2573 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2574 dw2_asm_output_data_uleb128 (r
, NULL
);
2577 case DW_CFA_def_cfa_offset
:
2578 case DW_CFA_GNU_args_size
:
2579 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2582 case DW_CFA_def_cfa_offset_sf
:
2583 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2586 case DW_CFA_GNU_window_save
:
2589 case DW_CFA_def_cfa_expression
:
2590 case DW_CFA_expression
:
2591 output_cfa_loc (cfi
);
2594 case DW_CFA_GNU_negative_offset_extended
:
2595 /* Obsoleted by DW_CFA_offset_extended_sf. */
2604 /* Output the call frame information used to record information
2605 that relates to calculating the frame pointer, and records the
2606 location of saved registers. */
2609 output_call_frame_info (int for_eh
)
2614 char l1
[20], l2
[20], section_start_label
[20];
2615 bool any_lsda_needed
= false;
2616 char augmentation
[6];
2617 int augmentation_size
;
2618 int fde_encoding
= DW_EH_PE_absptr
;
2619 int per_encoding
= DW_EH_PE_absptr
;
2620 int lsda_encoding
= DW_EH_PE_absptr
;
2623 /* Don't emit a CIE if there won't be any FDEs. */
2624 if (fde_table_in_use
== 0)
2627 /* If we make FDEs linkonce, we may have to emit an empty label for
2628 an FDE that wouldn't otherwise be emitted. We want to avoid
2629 having an FDE kept around when the function it refers to is
2630 discarded. Example where this matters: a primary function
2631 template in C++ requires EH information, but an explicit
2632 specialization doesn't. */
2633 if (TARGET_USES_WEAK_UNWIND_INFO
2634 && ! flag_asynchronous_unwind_tables
2637 for (i
= 0; i
< fde_table_in_use
; i
++)
2638 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2639 && !fde_table
[i
].uses_eh_lsda
2640 && ! DECL_WEAK (fde_table
[i
].decl
))
2641 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2642 for_eh
, /* empty */ 1);
2644 /* If we don't have any functions we'll want to unwind out of, don't
2645 emit any EH unwind information. Note that if exceptions aren't
2646 enabled, we won't have collected nothrow information, and if we
2647 asked for asynchronous tables, we always want this info. */
2650 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2652 for (i
= 0; i
< fde_table_in_use
; i
++)
2653 if (fde_table
[i
].uses_eh_lsda
)
2654 any_eh_needed
= any_lsda_needed
= true;
2655 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2656 any_eh_needed
= true;
2657 else if (! fde_table
[i
].nothrow
2658 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2659 any_eh_needed
= true;
2661 if (! any_eh_needed
)
2665 /* We're going to be generating comments, so turn on app. */
2670 switch_to_eh_frame_section ();
2673 if (!debug_frame_section
)
2674 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
2675 SECTION_DEBUG
, NULL
);
2676 switch_to_section (debug_frame_section
);
2679 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2680 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2682 /* Output the CIE. */
2683 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2684 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2685 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2686 dw2_asm_output_data (4, 0xffffffff,
2687 "Initial length escape value indicating 64-bit DWARF extension");
2688 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2689 "Length of Common Information Entry");
2690 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2692 /* Now that the CIE pointer is PC-relative for EH,
2693 use 0 to identify the CIE. */
2694 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2695 (for_eh
? 0 : DWARF_CIE_ID
),
2696 "CIE Identifier Tag");
2698 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2700 augmentation
[0] = 0;
2701 augmentation_size
= 0;
2707 z Indicates that a uleb128 is present to size the
2708 augmentation section.
2709 L Indicates the encoding (and thus presence) of
2710 an LSDA pointer in the FDE augmentation.
2711 R Indicates a non-default pointer encoding for
2713 P Indicates the presence of an encoding + language
2714 personality routine in the CIE augmentation. */
2716 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2717 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2718 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2720 p
= augmentation
+ 1;
2721 if (eh_personality_libfunc
)
2724 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2725 assemble_external_libcall (eh_personality_libfunc
);
2727 if (any_lsda_needed
)
2730 augmentation_size
+= 1;
2732 if (fde_encoding
!= DW_EH_PE_absptr
)
2735 augmentation_size
+= 1;
2737 if (p
> augmentation
+ 1)
2739 augmentation
[0] = 'z';
2743 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2744 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2746 int offset
= ( 4 /* Length */
2748 + 1 /* CIE version */
2749 + strlen (augmentation
) + 1 /* Augmentation */
2750 + size_of_uleb128 (1) /* Code alignment */
2751 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2753 + 1 /* Augmentation size */
2754 + 1 /* Personality encoding */ );
2755 int pad
= -offset
& (PTR_SIZE
- 1);
2757 augmentation_size
+= pad
;
2759 /* Augmentations should be small, so there's scarce need to
2760 iterate for a solution. Die if we exceed one uleb128 byte. */
2761 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2765 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2766 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2767 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2768 "CIE Data Alignment Factor");
2770 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2771 if (DW_CIE_VERSION
== 1)
2772 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2774 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2776 if (augmentation
[0])
2778 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2779 if (eh_personality_libfunc
)
2781 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2782 eh_data_format_name (per_encoding
));
2783 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2784 eh_personality_libfunc
,
2788 if (any_lsda_needed
)
2789 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2790 eh_data_format_name (lsda_encoding
));
2792 if (fde_encoding
!= DW_EH_PE_absptr
)
2793 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2794 eh_data_format_name (fde_encoding
));
2797 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2798 output_cfi (cfi
, NULL
, for_eh
);
2800 /* Pad the CIE out to an address sized boundary. */
2801 ASM_OUTPUT_ALIGN (asm_out_file
,
2802 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2803 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2805 /* Loop through all of the FDE's. */
2806 for (i
= 0; i
< fde_table_in_use
; i
++)
2808 fde
= &fde_table
[i
];
2810 /* Don't emit EH unwind info for leaf functions that don't need it. */
2811 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2812 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2813 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2814 && !fde
->uses_eh_lsda
)
2817 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2818 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2819 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2820 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2821 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2822 dw2_asm_output_data (4, 0xffffffff,
2823 "Initial length escape value indicating 64-bit DWARF extension");
2824 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2826 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2829 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2831 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2832 debug_frame_section
, "FDE CIE offset");
2836 if (fde
->dw_fde_switched_sections
)
2838 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
2839 fde
->dw_fde_unlikely_section_label
);
2840 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
2841 fde
->dw_fde_hot_section_label
);
2842 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
2843 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
2844 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
2845 "FDE initial location");
2846 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2847 fde
->dw_fde_hot_section_end_label
,
2848 fde
->dw_fde_hot_section_label
,
2849 "FDE address range");
2850 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
2851 "FDE initial location");
2852 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2853 fde
->dw_fde_unlikely_section_end_label
,
2854 fde
->dw_fde_unlikely_section_label
,
2855 "FDE address range");
2859 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
2860 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
2861 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2864 "FDE initial location");
2865 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2866 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2867 "FDE address range");
2872 if (fde
->dw_fde_switched_sections
)
2874 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2875 fde
->dw_fde_hot_section_label
,
2876 "FDE initial location");
2877 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2878 fde
->dw_fde_hot_section_end_label
,
2879 fde
->dw_fde_hot_section_label
,
2880 "FDE address range");
2881 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2882 fde
->dw_fde_unlikely_section_label
,
2883 "FDE initial location");
2884 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2885 fde
->dw_fde_unlikely_section_end_label
,
2886 fde
->dw_fde_unlikely_section_label
,
2887 "FDE address range");
2891 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2892 "FDE initial location");
2893 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2894 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2895 "FDE address range");
2899 if (augmentation
[0])
2901 if (any_lsda_needed
)
2903 int size
= size_of_encoded_value (lsda_encoding
);
2905 if (lsda_encoding
== DW_EH_PE_aligned
)
2907 int offset
= ( 4 /* Length */
2908 + 4 /* CIE offset */
2909 + 2 * size_of_encoded_value (fde_encoding
)
2910 + 1 /* Augmentation size */ );
2911 int pad
= -offset
& (PTR_SIZE
- 1);
2914 gcc_assert (size_of_uleb128 (size
) == 1);
2917 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2919 if (fde
->uses_eh_lsda
)
2921 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2922 fde
->funcdef_number
);
2923 dw2_asm_output_encoded_addr_rtx (
2924 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2925 false, "Language Specific Data Area");
2929 if (lsda_encoding
== DW_EH_PE_aligned
)
2930 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2932 (size_of_encoded_value (lsda_encoding
), 0,
2933 "Language Specific Data Area (none)");
2937 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2940 /* Loop through the Call Frame Instructions associated with
2942 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2943 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2944 output_cfi (cfi
, fde
, for_eh
);
2946 /* Pad the FDE out to an address sized boundary. */
2947 ASM_OUTPUT_ALIGN (asm_out_file
,
2948 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2949 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2952 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2953 dw2_asm_output_data (4, 0, "End of Table");
2954 #ifdef MIPS_DEBUGGING_INFO
2955 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2956 get a value of 0. Putting .align 0 after the label fixes it. */
2957 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2960 /* Turn off app to make assembly quicker. */
2965 /* Output a marker (i.e. a label) for the beginning of a function, before
2969 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2970 const char *file ATTRIBUTE_UNUSED
)
2972 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2976 current_function_func_begin_label
= NULL
;
2978 #ifdef TARGET_UNWIND_INFO
2979 /* ??? current_function_func_begin_label is also used by except.c
2980 for call-site information. We must emit this label if it might
2982 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2983 && ! dwarf2out_do_frame ())
2986 if (! dwarf2out_do_frame ())
2990 switch_to_section (function_section (current_function_decl
));
2991 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2992 current_function_funcdef_no
);
2993 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2994 current_function_funcdef_no
);
2995 dup_label
= xstrdup (label
);
2996 current_function_func_begin_label
= dup_label
;
2998 #ifdef TARGET_UNWIND_INFO
2999 /* We can elide the fde allocation if we're not emitting debug info. */
3000 if (! dwarf2out_do_frame ())
3004 /* Expand the fde table if necessary. */
3005 if (fde_table_in_use
== fde_table_allocated
)
3007 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
3008 fde_table
= GGC_RESIZEVEC (dw_fde_node
, fde_table
, fde_table_allocated
);
3009 memset (fde_table
+ fde_table_in_use
, 0,
3010 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
3013 /* Record the FDE associated with this function. */
3014 current_funcdef_fde
= fde_table_in_use
;
3016 /* Add the new FDE at the end of the fde_table. */
3017 fde
= &fde_table
[fde_table_in_use
++];
3018 fde
->decl
= current_function_decl
;
3019 fde
->dw_fde_begin
= dup_label
;
3020 fde
->dw_fde_current_label
= dup_label
;
3021 fde
->dw_fde_hot_section_label
= NULL
;
3022 fde
->dw_fde_hot_section_end_label
= NULL
;
3023 fde
->dw_fde_unlikely_section_label
= NULL
;
3024 fde
->dw_fde_unlikely_section_end_label
= NULL
;
3025 fde
->dw_fde_switched_sections
= false;
3026 fde
->dw_fde_end
= NULL
;
3027 fde
->dw_fde_cfi
= NULL
;
3028 fde
->funcdef_number
= current_function_funcdef_no
;
3029 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
3030 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
3031 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
3032 fde
->drap_reg
= INVALID_REGNUM
;
3033 fde
->vdrap_reg
= INVALID_REGNUM
;
3035 args_size
= old_args_size
= 0;
3037 /* We only want to output line number information for the genuine dwarf2
3038 prologue case, not the eh frame case. */
3039 #ifdef DWARF2_DEBUGGING_INFO
3041 dwarf2out_source_line (line
, file
);
3045 /* Output a marker (i.e. a label) for the absolute end of the generated code
3046 for a function definition. This gets called *after* the epilogue code has
3050 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
3051 const char *file ATTRIBUTE_UNUSED
)
3054 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3056 /* Output a label to mark the endpoint of the code generated for this
3058 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
3059 current_function_funcdef_no
);
3060 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3061 fde
= current_fde ();
3062 gcc_assert (fde
!= NULL
);
3063 fde
->dw_fde_end
= xstrdup (label
);
3067 dwarf2out_frame_init (void)
3069 /* Allocate the initial hunk of the fde_table. */
3070 fde_table
= GGC_CNEWVEC (dw_fde_node
, FDE_TABLE_INCREMENT
);
3071 fde_table_allocated
= FDE_TABLE_INCREMENT
;
3072 fde_table_in_use
= 0;
3074 /* Generate the CFA instructions common to all FDE's. Do it now for the
3075 sake of lookup_cfa. */
3077 /* On entry, the Canonical Frame Address is at SP. */
3078 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
3080 #ifdef DWARF2_UNWIND_INFO
3081 if (DWARF2_UNWIND_INFO
|| DWARF2_FRAME_INFO
)
3082 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
3087 dwarf2out_frame_finish (void)
3089 /* Output call frame information. */
3090 if (DWARF2_FRAME_INFO
)
3091 output_call_frame_info (0);
3093 #ifndef TARGET_UNWIND_INFO
3094 /* Output another copy for the unwinder. */
3095 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
3096 output_call_frame_info (1);
3100 /* Note that the current function section is being used for code. */
3103 dwarf2out_note_section_used (void)
3105 section
*sec
= current_function_section ();
3106 if (sec
== text_section
)
3107 text_section_used
= true;
3108 else if (sec
== cold_text_section
)
3109 cold_text_section_used
= true;
3113 dwarf2out_switch_text_section (void)
3115 dw_fde_ref fde
= current_fde ();
3117 gcc_assert (cfun
&& fde
);
3119 fde
->dw_fde_switched_sections
= true;
3120 fde
->dw_fde_hot_section_label
= crtl
->subsections
.hot_section_label
;
3121 fde
->dw_fde_hot_section_end_label
= crtl
->subsections
.hot_section_end_label
;
3122 fde
->dw_fde_unlikely_section_label
= crtl
->subsections
.cold_section_label
;
3123 fde
->dw_fde_unlikely_section_end_label
= crtl
->subsections
.cold_section_end_label
;
3124 have_multiple_function_sections
= true;
3126 /* Reset the current label on switching text sections, so that we
3127 don't attempt to advance_loc4 between labels in different sections. */
3128 fde
->dw_fde_current_label
= NULL
;
3130 /* There is no need to mark used sections when not debugging. */
3131 if (cold_text_section
!= NULL
)
3132 dwarf2out_note_section_used ();
3136 /* And now, the subset of the debugging information support code necessary
3137 for emitting location expressions. */
3139 /* Data about a single source file. */
3140 struct dwarf_file_data
GTY(())
3142 const char * filename
;
3146 /* We need some way to distinguish DW_OP_addr with a direct symbol
3147 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
3148 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
3151 typedef struct dw_val_struct
*dw_val_ref
;
3152 typedef struct die_struct
*dw_die_ref
;
3153 typedef const struct die_struct
*const_dw_die_ref
;
3154 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
3155 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
3157 /* Each DIE may have a series of attribute/value pairs. Values
3158 can take on several forms. The forms that are used in this
3159 implementation are listed below. */
3164 dw_val_class_offset
,
3166 dw_val_class_loc_list
,
3167 dw_val_class_range_list
,
3169 dw_val_class_unsigned_const
,
3170 dw_val_class_long_long
,
3173 dw_val_class_die_ref
,
3174 dw_val_class_fde_ref
,
3175 dw_val_class_lbl_id
,
3176 dw_val_class_lineptr
,
3178 dw_val_class_macptr
,
3182 /* Describe a double word constant value. */
3183 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
3185 typedef struct dw_long_long_struct
GTY(())
3192 /* Describe a floating point constant value, or a vector constant value. */
3194 typedef struct dw_vec_struct
GTY(())
3196 unsigned char * GTY((length ("%h.length"))) array
;
3202 /* The dw_val_node describes an attribute's value, as it is
3203 represented internally. */
3205 typedef struct dw_val_struct
GTY(())
3207 enum dw_val_class val_class
;
3208 union dw_val_struct_union
3210 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
3211 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
3212 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
3213 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
3214 HOST_WIDE_INT
GTY ((default)) val_int
;
3215 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
3216 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
3217 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
3218 struct dw_val_die_union
3222 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
3223 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
3224 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
3225 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
3226 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
3227 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
3229 GTY ((desc ("%1.val_class"))) v
;
3233 /* Locations in memory are described using a sequence of stack machine
3236 typedef struct dw_loc_descr_struct
GTY(())
3238 dw_loc_descr_ref dw_loc_next
;
3239 enum dwarf_location_atom dw_loc_opc
;
3240 dw_val_node dw_loc_oprnd1
;
3241 dw_val_node dw_loc_oprnd2
;
3246 /* Location lists are ranges + location descriptions for that range,
3247 so you can track variables that are in different places over
3248 their entire life. */
3249 typedef struct dw_loc_list_struct
GTY(())
3251 dw_loc_list_ref dw_loc_next
;
3252 const char *begin
; /* Label for begin address of range */
3253 const char *end
; /* Label for end address of range */
3254 char *ll_symbol
; /* Label for beginning of location list.
3255 Only on head of list */
3256 const char *section
; /* Section this loclist is relative to */
3257 dw_loc_descr_ref expr
;
3260 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
3262 static const char *dwarf_stack_op_name (unsigned);
3263 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
3264 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3265 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3266 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
3267 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
3268 static unsigned long size_of_locs (dw_loc_descr_ref
);
3269 static void output_loc_operands (dw_loc_descr_ref
);
3270 static void output_loc_sequence (dw_loc_descr_ref
);
3272 /* Convert a DWARF stack opcode into its string name. */
3275 dwarf_stack_op_name (unsigned int op
)
3280 case INTERNAL_DW_OP_tls_addr
:
3281 return "DW_OP_addr";
3283 return "DW_OP_deref";
3285 return "DW_OP_const1u";
3287 return "DW_OP_const1s";
3289 return "DW_OP_const2u";
3291 return "DW_OP_const2s";
3293 return "DW_OP_const4u";
3295 return "DW_OP_const4s";
3297 return "DW_OP_const8u";
3299 return "DW_OP_const8s";
3301 return "DW_OP_constu";
3303 return "DW_OP_consts";
3307 return "DW_OP_drop";
3309 return "DW_OP_over";
3311 return "DW_OP_pick";
3313 return "DW_OP_swap";
3317 return "DW_OP_xderef";
3325 return "DW_OP_minus";
3337 return "DW_OP_plus";
3338 case DW_OP_plus_uconst
:
3339 return "DW_OP_plus_uconst";
3345 return "DW_OP_shra";
3363 return "DW_OP_skip";
3365 return "DW_OP_lit0";
3367 return "DW_OP_lit1";
3369 return "DW_OP_lit2";
3371 return "DW_OP_lit3";
3373 return "DW_OP_lit4";
3375 return "DW_OP_lit5";
3377 return "DW_OP_lit6";
3379 return "DW_OP_lit7";
3381 return "DW_OP_lit8";
3383 return "DW_OP_lit9";
3385 return "DW_OP_lit10";
3387 return "DW_OP_lit11";
3389 return "DW_OP_lit12";
3391 return "DW_OP_lit13";
3393 return "DW_OP_lit14";
3395 return "DW_OP_lit15";
3397 return "DW_OP_lit16";
3399 return "DW_OP_lit17";
3401 return "DW_OP_lit18";
3403 return "DW_OP_lit19";
3405 return "DW_OP_lit20";
3407 return "DW_OP_lit21";
3409 return "DW_OP_lit22";
3411 return "DW_OP_lit23";
3413 return "DW_OP_lit24";
3415 return "DW_OP_lit25";
3417 return "DW_OP_lit26";
3419 return "DW_OP_lit27";
3421 return "DW_OP_lit28";
3423 return "DW_OP_lit29";
3425 return "DW_OP_lit30";
3427 return "DW_OP_lit31";
3429 return "DW_OP_reg0";
3431 return "DW_OP_reg1";
3433 return "DW_OP_reg2";
3435 return "DW_OP_reg3";
3437 return "DW_OP_reg4";
3439 return "DW_OP_reg5";
3441 return "DW_OP_reg6";
3443 return "DW_OP_reg7";
3445 return "DW_OP_reg8";
3447 return "DW_OP_reg9";
3449 return "DW_OP_reg10";
3451 return "DW_OP_reg11";
3453 return "DW_OP_reg12";
3455 return "DW_OP_reg13";
3457 return "DW_OP_reg14";
3459 return "DW_OP_reg15";
3461 return "DW_OP_reg16";
3463 return "DW_OP_reg17";
3465 return "DW_OP_reg18";
3467 return "DW_OP_reg19";
3469 return "DW_OP_reg20";
3471 return "DW_OP_reg21";
3473 return "DW_OP_reg22";
3475 return "DW_OP_reg23";
3477 return "DW_OP_reg24";
3479 return "DW_OP_reg25";
3481 return "DW_OP_reg26";
3483 return "DW_OP_reg27";
3485 return "DW_OP_reg28";
3487 return "DW_OP_reg29";
3489 return "DW_OP_reg30";
3491 return "DW_OP_reg31";
3493 return "DW_OP_breg0";
3495 return "DW_OP_breg1";
3497 return "DW_OP_breg2";
3499 return "DW_OP_breg3";
3501 return "DW_OP_breg4";
3503 return "DW_OP_breg5";
3505 return "DW_OP_breg6";
3507 return "DW_OP_breg7";
3509 return "DW_OP_breg8";
3511 return "DW_OP_breg9";
3513 return "DW_OP_breg10";
3515 return "DW_OP_breg11";
3517 return "DW_OP_breg12";
3519 return "DW_OP_breg13";
3521 return "DW_OP_breg14";
3523 return "DW_OP_breg15";
3525 return "DW_OP_breg16";
3527 return "DW_OP_breg17";
3529 return "DW_OP_breg18";
3531 return "DW_OP_breg19";
3533 return "DW_OP_breg20";
3535 return "DW_OP_breg21";
3537 return "DW_OP_breg22";
3539 return "DW_OP_breg23";
3541 return "DW_OP_breg24";
3543 return "DW_OP_breg25";
3545 return "DW_OP_breg26";
3547 return "DW_OP_breg27";
3549 return "DW_OP_breg28";
3551 return "DW_OP_breg29";
3553 return "DW_OP_breg30";
3555 return "DW_OP_breg31";
3557 return "DW_OP_regx";
3559 return "DW_OP_fbreg";
3561 return "DW_OP_bregx";
3563 return "DW_OP_piece";
3564 case DW_OP_deref_size
:
3565 return "DW_OP_deref_size";
3566 case DW_OP_xderef_size
:
3567 return "DW_OP_xderef_size";
3570 case DW_OP_push_object_address
:
3571 return "DW_OP_push_object_address";
3573 return "DW_OP_call2";
3575 return "DW_OP_call4";
3576 case DW_OP_call_ref
:
3577 return "DW_OP_call_ref";
3578 case DW_OP_GNU_push_tls_address
:
3579 return "DW_OP_GNU_push_tls_address";
3580 case DW_OP_GNU_uninit
:
3581 return "DW_OP_GNU_uninit";
3583 return "OP_<unknown>";
3587 /* Return a pointer to a newly allocated location description. Location
3588 descriptions are simple expression terms that can be strung
3589 together to form more complicated location (address) descriptions. */
3591 static inline dw_loc_descr_ref
3592 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3593 unsigned HOST_WIDE_INT oprnd2
)
3595 dw_loc_descr_ref descr
= GGC_CNEW (dw_loc_descr_node
);
3597 descr
->dw_loc_opc
= op
;
3598 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3599 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3600 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3601 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3606 /* Add a location description term to a location description expression. */
3609 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3611 dw_loc_descr_ref
*d
;
3613 /* Find the end of the chain. */
3614 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3620 /* Return the size of a location descriptor. */
3622 static unsigned long
3623 size_of_loc_descr (dw_loc_descr_ref loc
)
3625 unsigned long size
= 1;
3627 switch (loc
->dw_loc_opc
)
3630 case INTERNAL_DW_OP_tls_addr
:
3631 size
+= DWARF2_ADDR_SIZE
;
3650 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3653 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3658 case DW_OP_plus_uconst
:
3659 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3697 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3700 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3703 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3706 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3707 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3710 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3712 case DW_OP_deref_size
:
3713 case DW_OP_xderef_size
:
3722 case DW_OP_call_ref
:
3723 size
+= DWARF2_ADDR_SIZE
;
3732 /* Return the size of a series of location descriptors. */
3734 static unsigned long
3735 size_of_locs (dw_loc_descr_ref loc
)
3740 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3741 field, to avoid writing to a PCH file. */
3742 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3744 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
3746 size
+= size_of_loc_descr (l
);
3751 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3753 l
->dw_loc_addr
= size
;
3754 size
+= size_of_loc_descr (l
);
3760 /* Output location description stack opcode's operands (if any). */
3763 output_loc_operands (dw_loc_descr_ref loc
)
3765 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3766 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3768 switch (loc
->dw_loc_opc
)
3770 #ifdef DWARF2_DEBUGGING_INFO
3772 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3776 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3780 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3784 gcc_assert (HOST_BITS_PER_LONG
>= 64);
3785 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3792 gcc_assert (val1
->val_class
== dw_val_class_loc
);
3793 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3795 dw2_asm_output_data (2, offset
, NULL
);
3808 /* We currently don't make any attempt to make sure these are
3809 aligned properly like we do for the main unwind info, so
3810 don't support emitting things larger than a byte if we're
3811 only doing unwinding. */
3816 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3819 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3822 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3825 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3827 case DW_OP_plus_uconst
:
3828 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3862 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3865 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3868 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3871 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3872 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3875 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3877 case DW_OP_deref_size
:
3878 case DW_OP_xderef_size
:
3879 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3882 case INTERNAL_DW_OP_tls_addr
:
3883 if (targetm
.asm_out
.output_dwarf_dtprel
)
3885 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
3888 fputc ('\n', asm_out_file
);
3895 /* Other codes have no operands. */
3900 /* Output a sequence of location operations. */
3903 output_loc_sequence (dw_loc_descr_ref loc
)
3905 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3907 /* Output the opcode. */
3908 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3909 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3911 /* Output the operand(s) (if any). */
3912 output_loc_operands (loc
);
3916 /* This routine will generate the correct assembly data for a location
3917 description based on a cfi entry with a complex address. */
3920 output_cfa_loc (dw_cfi_ref cfi
)
3922 dw_loc_descr_ref loc
;
3925 if (cfi
->dw_cfi_opc
== DW_CFA_expression
)
3926 dw2_asm_output_data (1, cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, NULL
);
3928 /* Output the size of the block. */
3929 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3930 size
= size_of_locs (loc
);
3931 dw2_asm_output_data_uleb128 (size
, NULL
);
3933 /* Now output the operations themselves. */
3934 output_loc_sequence (loc
);
3937 /* This function builds a dwarf location descriptor sequence from a
3938 dw_cfa_location, adding the given OFFSET to the result of the
3941 static struct dw_loc_descr_struct
*
3942 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
3944 struct dw_loc_descr_struct
*head
, *tmp
;
3946 offset
+= cfa
->offset
;
3950 if (cfa
->base_offset
)
3953 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3955 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3957 else if (cfa
->reg
<= 31)
3958 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3960 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3962 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3963 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3964 add_loc_descr (&head
, tmp
);
3967 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
3968 add_loc_descr (&head
, tmp
);
3975 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3977 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3978 else if (cfa
->reg
<= 31)
3979 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, offset
, 0);
3981 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, offset
);
3987 /* This function builds a dwarf location descriptor sequence for
3988 the address at OFFSET from the CFA when stack is aligned to
3991 static struct dw_loc_descr_struct
*
3992 build_cfa_aligned_loc (HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
3994 struct dw_loc_descr_struct
*head
;
3995 unsigned int dwarf_fp
3996 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
3998 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
3999 if (cfa
.reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
.indirect
== 0)
4002 head
= new_loc_descr (DW_OP_breg0
+ dwarf_fp
, 0, 0);
4004 head
= new_loc_descr (DW_OP_bregx
, dwarf_fp
, 0);
4006 add_loc_descr (&head
, int_loc_descriptor (alignment
));
4007 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
4009 add_loc_descr (&head
, int_loc_descriptor (offset
));
4010 add_loc_descr (&head
, new_loc_descr (DW_OP_plus
, 0, 0));
4012 else if (dwarf_fp
<= 31)
4013 head
= new_loc_descr (DW_OP_breg0
+ dwarf_fp
, offset
, 0);
4015 head
= new_loc_descr (DW_OP_bregx
, dwarf_fp
, offset
);
4019 /* This function fills in aa dw_cfa_location structure from a dwarf location
4020 descriptor sequence. */
4023 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
4025 struct dw_loc_descr_struct
*ptr
;
4027 cfa
->base_offset
= 0;
4031 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
4033 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
4069 cfa
->reg
= op
- DW_OP_reg0
;
4072 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4106 cfa
->reg
= op
- DW_OP_breg0
;
4107 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4110 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
4111 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
4116 case DW_OP_plus_uconst
:
4117 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
4120 internal_error ("DW_LOC_OP %s not implemented",
4121 dwarf_stack_op_name (ptr
->dw_loc_opc
));
4125 #endif /* .debug_frame support */
4127 /* And now, the support for symbolic debugging information. */
4128 #ifdef DWARF2_DEBUGGING_INFO
4130 /* .debug_str support. */
4131 static int output_indirect_string (void **, void *);
4133 static void dwarf2out_init (const char *);
4134 static void dwarf2out_finish (const char *);
4135 static void dwarf2out_define (unsigned int, const char *);
4136 static void dwarf2out_undef (unsigned int, const char *);
4137 static void dwarf2out_start_source_file (unsigned, const char *);
4138 static void dwarf2out_end_source_file (unsigned);
4139 static void dwarf2out_begin_block (unsigned, unsigned);
4140 static void dwarf2out_end_block (unsigned, unsigned);
4141 static bool dwarf2out_ignore_block (const_tree
);
4142 static void dwarf2out_global_decl (tree
);
4143 static void dwarf2out_type_decl (tree
, int);
4144 static void dwarf2out_imported_module_or_decl (tree
, tree
);
4145 static void dwarf2out_abstract_function (tree
);
4146 static void dwarf2out_var_location (rtx
);
4147 static void dwarf2out_begin_function (tree
);
4149 /* The debug hooks structure. */
4151 const struct gcc_debug_hooks dwarf2_debug_hooks
=
4157 dwarf2out_start_source_file
,
4158 dwarf2out_end_source_file
,
4159 dwarf2out_begin_block
,
4160 dwarf2out_end_block
,
4161 dwarf2out_ignore_block
,
4162 dwarf2out_source_line
,
4163 dwarf2out_begin_prologue
,
4164 debug_nothing_int_charstar
, /* end_prologue */
4165 dwarf2out_end_epilogue
,
4166 dwarf2out_begin_function
,
4167 debug_nothing_int
, /* end_function */
4168 dwarf2out_decl
, /* function_decl */
4169 dwarf2out_global_decl
,
4170 dwarf2out_type_decl
, /* type_decl */
4171 dwarf2out_imported_module_or_decl
,
4172 debug_nothing_tree
, /* deferred_inline_function */
4173 /* The DWARF 2 backend tries to reduce debugging bloat by not
4174 emitting the abstract description of inline functions until
4175 something tries to reference them. */
4176 dwarf2out_abstract_function
, /* outlining_inline_function */
4177 debug_nothing_rtx
, /* label */
4178 debug_nothing_int
, /* handle_pch */
4179 dwarf2out_var_location
,
4180 dwarf2out_switch_text_section
,
4181 1 /* start_end_main_source_file */
4185 /* NOTE: In the comments in this file, many references are made to
4186 "Debugging Information Entries". This term is abbreviated as `DIE'
4187 throughout the remainder of this file. */
4189 /* An internal representation of the DWARF output is built, and then
4190 walked to generate the DWARF debugging info. The walk of the internal
4191 representation is done after the entire program has been compiled.
4192 The types below are used to describe the internal representation. */
4194 /* Various DIE's use offsets relative to the beginning of the
4195 .debug_info section to refer to each other. */
4197 typedef long int dw_offset
;
4199 /* Define typedefs here to avoid circular dependencies. */
4201 typedef struct dw_attr_struct
*dw_attr_ref
;
4202 typedef struct dw_line_info_struct
*dw_line_info_ref
;
4203 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
4204 typedef struct pubname_struct
*pubname_ref
;
4205 typedef struct dw_ranges_struct
*dw_ranges_ref
;
4206 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
4208 /* Each entry in the line_info_table maintains the file and
4209 line number associated with the label generated for that
4210 entry. The label gives the PC value associated with
4211 the line number entry. */
4213 typedef struct dw_line_info_struct
GTY(())
4215 unsigned long dw_file_num
;
4216 unsigned long dw_line_num
;
4220 /* Line information for functions in separate sections; each one gets its
4222 typedef struct dw_separate_line_info_struct
GTY(())
4224 unsigned long dw_file_num
;
4225 unsigned long dw_line_num
;
4226 unsigned long function
;
4228 dw_separate_line_info_entry
;
4230 /* Each DIE attribute has a field specifying the attribute kind,
4231 a link to the next attribute in the chain, and an attribute value.
4232 Attributes are typically linked below the DIE they modify. */
4234 typedef struct dw_attr_struct
GTY(())
4236 enum dwarf_attribute dw_attr
;
4237 dw_val_node dw_attr_val
;
4241 DEF_VEC_O(dw_attr_node
);
4242 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
4244 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
4245 The children of each node form a circular list linked by
4246 die_sib. die_child points to the node *before* the "first" child node. */
4248 typedef struct die_struct
GTY((chain_circular ("%h.die_sib")))
4250 enum dwarf_tag die_tag
;
4252 VEC(dw_attr_node
,gc
) * die_attr
;
4253 dw_die_ref die_parent
;
4254 dw_die_ref die_child
;
4256 dw_die_ref die_definition
; /* ref from a specification to its definition */
4257 dw_offset die_offset
;
4258 unsigned long die_abbrev
;
4260 /* Die is used and must not be pruned as unused. */
4261 int die_perennial_p
;
4262 unsigned int decl_id
;
4266 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
4267 #define FOR_EACH_CHILD(die, c, expr) do { \
4268 c = die->die_child; \
4272 } while (c != die->die_child); \
4275 /* The pubname structure */
4277 typedef struct pubname_struct
GTY(())
4284 DEF_VEC_O(pubname_entry
);
4285 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
4287 struct dw_ranges_struct
GTY(())
4289 /* If this is positive, it's a block number, otherwise it's a
4290 bitwise-negated index into dw_ranges_by_label. */
4294 struct dw_ranges_by_label_struct
GTY(())
4300 /* The limbo die list structure. */
4301 typedef struct limbo_die_struct
GTY(())
4305 struct limbo_die_struct
*next
;
4309 /* How to start an assembler comment. */
4310 #ifndef ASM_COMMENT_START
4311 #define ASM_COMMENT_START ";#"
4314 /* Define a macro which returns nonzero for a TYPE_DECL which was
4315 implicitly generated for a tagged type.
4317 Note that unlike the gcc front end (which generates a NULL named
4318 TYPE_DECL node for each complete tagged type, each array type, and
4319 each function type node created) the g++ front end generates a
4320 _named_ TYPE_DECL node for each tagged type node created.
4321 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
4322 generate a DW_TAG_typedef DIE for them. */
4324 #define TYPE_DECL_IS_STUB(decl) \
4325 (DECL_NAME (decl) == NULL_TREE \
4326 || (DECL_ARTIFICIAL (decl) \
4327 && is_tagged_type (TREE_TYPE (decl)) \
4328 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
4329 /* This is necessary for stub decls that \
4330 appear in nested inline functions. */ \
4331 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
4332 && (decl_ultimate_origin (decl) \
4333 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
4335 /* Information concerning the compilation unit's programming
4336 language, and compiler version. */
4338 /* Fixed size portion of the DWARF compilation unit header. */
4339 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
4340 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
4342 /* Fixed size portion of public names info. */
4343 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
4345 /* Fixed size portion of the address range info. */
4346 #define DWARF_ARANGES_HEADER_SIZE \
4347 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4348 DWARF2_ADDR_SIZE * 2) \
4349 - DWARF_INITIAL_LENGTH_SIZE)
4351 /* Size of padding portion in the address range info. It must be
4352 aligned to twice the pointer size. */
4353 #define DWARF_ARANGES_PAD_SIZE \
4354 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
4355 DWARF2_ADDR_SIZE * 2) \
4356 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
4358 /* Use assembler line directives if available. */
4359 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
4360 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
4361 #define DWARF2_ASM_LINE_DEBUG_INFO 1
4363 #define DWARF2_ASM_LINE_DEBUG_INFO 0
4367 /* Minimum line offset in a special line info. opcode.
4368 This value was chosen to give a reasonable range of values. */
4369 #define DWARF_LINE_BASE -10
4371 /* First special line opcode - leave room for the standard opcodes. */
4372 #define DWARF_LINE_OPCODE_BASE 10
4374 /* Range of line offsets in a special line info. opcode. */
4375 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
4377 /* Flag that indicates the initial value of the is_stmt_start flag.
4378 In the present implementation, we do not mark any lines as
4379 the beginning of a source statement, because that information
4380 is not made available by the GCC front-end. */
4381 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
4383 #ifdef DWARF2_DEBUGGING_INFO
4384 /* This location is used by calc_die_sizes() to keep track
4385 the offset of each DIE within the .debug_info section. */
4386 static unsigned long next_die_offset
;
4389 /* Record the root of the DIE's built for the current compilation unit. */
4390 static GTY(()) dw_die_ref comp_unit_die
;
4392 /* A list of DIEs with a NULL parent waiting to be relocated. */
4393 static GTY(()) limbo_die_node
*limbo_die_list
;
4395 /* Filenames referenced by this compilation unit. */
4396 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
4398 /* A hash table of references to DIE's that describe declarations.
4399 The key is a DECL_UID() which is a unique number identifying each decl. */
4400 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
4402 /* Node of the variable location list. */
4403 struct var_loc_node
GTY ((chain_next ("%h.next")))
4405 rtx
GTY (()) var_loc_note
;
4406 const char * GTY (()) label
;
4407 const char * GTY (()) section_label
;
4408 struct var_loc_node
* GTY (()) next
;
4411 /* Variable location list. */
4412 struct var_loc_list_def
GTY (())
4414 struct var_loc_node
* GTY (()) first
;
4416 /* Do not mark the last element of the chained list because
4417 it is marked through the chain. */
4418 struct var_loc_node
* GTY ((skip ("%h"))) last
;
4420 /* DECL_UID of the variable decl. */
4421 unsigned int decl_id
;
4423 typedef struct var_loc_list_def var_loc_list
;
4426 /* Table of decl location linked lists. */
4427 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
4429 /* A pointer to the base of a list of references to DIE's that
4430 are uniquely identified by their tag, presence/absence of
4431 children DIE's, and list of attribute/value pairs. */
4432 static GTY((length ("abbrev_die_table_allocated")))
4433 dw_die_ref
*abbrev_die_table
;
4435 /* Number of elements currently allocated for abbrev_die_table. */
4436 static GTY(()) unsigned abbrev_die_table_allocated
;
4438 /* Number of elements in type_die_table currently in use. */
4439 static GTY(()) unsigned abbrev_die_table_in_use
;
4441 /* Size (in elements) of increments by which we may expand the
4442 abbrev_die_table. */
4443 #define ABBREV_DIE_TABLE_INCREMENT 256
4445 /* A pointer to the base of a table that contains line information
4446 for each source code line in .text in the compilation unit. */
4447 static GTY((length ("line_info_table_allocated")))
4448 dw_line_info_ref line_info_table
;
4450 /* Number of elements currently allocated for line_info_table. */
4451 static GTY(()) unsigned line_info_table_allocated
;
4453 /* Number of elements in line_info_table currently in use. */
4454 static GTY(()) unsigned line_info_table_in_use
;
4456 /* A pointer to the base of a table that contains line information
4457 for each source code line outside of .text in the compilation unit. */
4458 static GTY ((length ("separate_line_info_table_allocated")))
4459 dw_separate_line_info_ref separate_line_info_table
;
4461 /* Number of elements currently allocated for separate_line_info_table. */
4462 static GTY(()) unsigned separate_line_info_table_allocated
;
4464 /* Number of elements in separate_line_info_table currently in use. */
4465 static GTY(()) unsigned separate_line_info_table_in_use
;
4467 /* Size (in elements) of increments by which we may expand the
4469 #define LINE_INFO_TABLE_INCREMENT 1024
4471 /* A pointer to the base of a table that contains a list of publicly
4472 accessible names. */
4473 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
4475 /* A pointer to the base of a table that contains a list of publicly
4476 accessible types. */
4477 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
4479 /* Array of dies for which we should generate .debug_arange info. */
4480 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
4482 /* Number of elements currently allocated for arange_table. */
4483 static GTY(()) unsigned arange_table_allocated
;
4485 /* Number of elements in arange_table currently in use. */
4486 static GTY(()) unsigned arange_table_in_use
;
4488 /* Size (in elements) of increments by which we may expand the
4490 #define ARANGE_TABLE_INCREMENT 64
4492 /* Array of dies for which we should generate .debug_ranges info. */
4493 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
4495 /* Number of elements currently allocated for ranges_table. */
4496 static GTY(()) unsigned ranges_table_allocated
;
4498 /* Number of elements in ranges_table currently in use. */
4499 static GTY(()) unsigned ranges_table_in_use
;
4501 /* Array of pairs of labels referenced in ranges_table. */
4502 static GTY ((length ("ranges_by_label_allocated")))
4503 dw_ranges_by_label_ref ranges_by_label
;
4505 /* Number of elements currently allocated for ranges_by_label. */
4506 static GTY(()) unsigned ranges_by_label_allocated
;
4508 /* Number of elements in ranges_by_label currently in use. */
4509 static GTY(()) unsigned ranges_by_label_in_use
;
4511 /* Size (in elements) of increments by which we may expand the
4513 #define RANGES_TABLE_INCREMENT 64
4515 /* Whether we have location lists that need outputting */
4516 static GTY(()) bool have_location_lists
;
4518 /* Unique label counter. */
4519 static GTY(()) unsigned int loclabel_num
;
4521 #ifdef DWARF2_DEBUGGING_INFO
4522 /* Record whether the function being analyzed contains inlined functions. */
4523 static int current_function_has_inlines
;
4525 #if 0 && defined (MIPS_DEBUGGING_INFO)
4526 static int comp_unit_has_inlines
;
4529 /* The last file entry emitted by maybe_emit_file(). */
4530 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
4532 /* Number of internal labels generated by gen_internal_sym(). */
4533 static GTY(()) int label_num
;
4535 /* Cached result of previous call to lookup_filename. */
4536 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
4538 #ifdef DWARF2_DEBUGGING_INFO
4540 /* Offset from the "steady-state frame pointer" to the frame base,
4541 within the current function. */
4542 static HOST_WIDE_INT frame_pointer_fb_offset
;
4544 /* Forward declarations for functions defined in this file. */
4546 static int is_pseudo_reg (const_rtx
);
4547 static tree
type_main_variant (tree
);
4548 static int is_tagged_type (const_tree
);
4549 static const char *dwarf_tag_name (unsigned);
4550 static const char *dwarf_attr_name (unsigned);
4551 static const char *dwarf_form_name (unsigned);
4552 static tree
decl_ultimate_origin (const_tree
);
4553 static tree
block_ultimate_origin (const_tree
);
4554 static tree
decl_class_context (tree
);
4555 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
4556 static inline enum dw_val_class
AT_class (dw_attr_ref
);
4557 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
4558 static inline unsigned AT_flag (dw_attr_ref
);
4559 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
4560 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
4561 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
4562 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
4563 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
4565 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
4566 unsigned int, unsigned char *);
4567 static hashval_t
debug_str_do_hash (const void *);
4568 static int debug_str_eq (const void *, const void *);
4569 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
4570 static inline const char *AT_string (dw_attr_ref
);
4571 static int AT_string_form (dw_attr_ref
);
4572 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
4573 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
4574 static inline dw_die_ref
AT_ref (dw_attr_ref
);
4575 static inline int AT_ref_external (dw_attr_ref
);
4576 static inline void set_AT_ref_external (dw_attr_ref
, int);
4577 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
4578 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
4579 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
4580 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
4582 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
4583 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
4584 static inline rtx
AT_addr (dw_attr_ref
);
4585 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
4586 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4587 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4588 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
4589 unsigned HOST_WIDE_INT
);
4590 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
4592 static inline const char *AT_lbl (dw_attr_ref
);
4593 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
4594 static const char *get_AT_low_pc (dw_die_ref
);
4595 static const char *get_AT_hi_pc (dw_die_ref
);
4596 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
4597 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
4598 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
4599 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
4600 static bool is_c_family (void);
4601 static bool is_cxx (void);
4602 static bool is_java (void);
4603 static bool is_fortran (void);
4604 static bool is_ada (void);
4605 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
4606 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
4607 static void add_child_die (dw_die_ref
, dw_die_ref
);
4608 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
4609 static dw_die_ref
lookup_type_die (tree
);
4610 static void equate_type_number_to_die (tree
, dw_die_ref
);
4611 static hashval_t
decl_die_table_hash (const void *);
4612 static int decl_die_table_eq (const void *, const void *);
4613 static dw_die_ref
lookup_decl_die (tree
);
4614 static hashval_t
decl_loc_table_hash (const void *);
4615 static int decl_loc_table_eq (const void *, const void *);
4616 static var_loc_list
*lookup_decl_loc (const_tree
);
4617 static void equate_decl_number_to_die (tree
, dw_die_ref
);
4618 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
4619 static void print_spaces (FILE *);
4620 static void print_die (dw_die_ref
, FILE *);
4621 static void print_dwarf_line_table (FILE *);
4622 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
4623 static dw_die_ref
pop_compile_unit (dw_die_ref
);
4624 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
4625 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
4626 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
4627 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
4628 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
4629 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
4630 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
4631 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
4632 static void compute_section_prefix (dw_die_ref
);
4633 static int is_type_die (dw_die_ref
);
4634 static int is_comdat_die (dw_die_ref
);
4635 static int is_symbol_die (dw_die_ref
);
4636 static void assign_symbol_names (dw_die_ref
);
4637 static void break_out_includes (dw_die_ref
);
4638 static hashval_t
htab_cu_hash (const void *);
4639 static int htab_cu_eq (const void *, const void *);
4640 static void htab_cu_del (void *);
4641 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
4642 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
4643 static void add_sibling_attributes (dw_die_ref
);
4644 static void build_abbrev_table (dw_die_ref
);
4645 static void output_location_lists (dw_die_ref
);
4646 static int constant_size (long unsigned);
4647 static unsigned long size_of_die (dw_die_ref
);
4648 static void calc_die_sizes (dw_die_ref
);
4649 static void mark_dies (dw_die_ref
);
4650 static void unmark_dies (dw_die_ref
);
4651 static void unmark_all_dies (dw_die_ref
);
4652 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
4653 static unsigned long size_of_aranges (void);
4654 static enum dwarf_form
value_format (dw_attr_ref
);
4655 static void output_value_format (dw_attr_ref
);
4656 static void output_abbrev_section (void);
4657 static void output_die_symbol (dw_die_ref
);
4658 static void output_die (dw_die_ref
);
4659 static void output_compilation_unit_header (void);
4660 static void output_comp_unit (dw_die_ref
, int);
4661 static const char *dwarf2_name (tree
, int);
4662 static void add_pubname (tree
, dw_die_ref
);
4663 static void add_pubname_string (const char *, dw_die_ref
);
4664 static void add_pubtype (tree
, dw_die_ref
);
4665 static void output_pubnames (VEC (pubname_entry
,gc
) *);
4666 static void add_arange (tree
, dw_die_ref
);
4667 static void output_aranges (void);
4668 static unsigned int add_ranges_num (int);
4669 static unsigned int add_ranges (const_tree
);
4670 static unsigned int add_ranges_by_labels (const char *, const char *);
4671 static void output_ranges (void);
4672 static void output_line_info (void);
4673 static void output_file_names (void);
4674 static dw_die_ref
base_type_die (tree
);
4675 static int is_base_type (tree
);
4676 static bool is_subrange_type (const_tree
);
4677 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
4678 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
4679 static int type_is_enum (const_tree
);
4680 static unsigned int dbx_reg_number (const_rtx
);
4681 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
4682 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
4683 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
4684 enum var_init_status
);
4685 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
4686 enum var_init_status
);
4687 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
4688 enum var_init_status
);
4689 static int is_based_loc (const_rtx
);
4690 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
,
4691 enum var_init_status
);
4692 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
4693 enum var_init_status
);
4694 static dw_loc_descr_ref
loc_descriptor (rtx
, enum var_init_status
);
4695 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
4696 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
4697 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
4698 static tree
field_type (const_tree
);
4699 static unsigned int simple_type_align_in_bits (const_tree
);
4700 static unsigned int simple_decl_align_in_bits (const_tree
);
4701 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
4702 static HOST_WIDE_INT
field_byte_offset (const_tree
);
4703 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
4705 static void add_data_member_location_attribute (dw_die_ref
, tree
);
4706 static void add_const_value_attribute (dw_die_ref
, rtx
);
4707 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
4708 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4709 static void insert_float (const_rtx
, unsigned char *);
4710 static rtx
rtl_for_decl_location (tree
);
4711 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
4712 enum dwarf_attribute
);
4713 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
4714 static void add_name_attribute (dw_die_ref
, const char *);
4715 static void add_comp_dir_attribute (dw_die_ref
);
4716 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
4717 static void add_subscript_info (dw_die_ref
, tree
, bool);
4718 static void add_byte_size_attribute (dw_die_ref
, tree
);
4719 static void add_bit_offset_attribute (dw_die_ref
, tree
);
4720 static void add_bit_size_attribute (dw_die_ref
, tree
);
4721 static void add_prototyped_attribute (dw_die_ref
, tree
);
4722 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
4723 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
4724 static void add_src_coords_attributes (dw_die_ref
, tree
);
4725 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
4726 static void push_decl_scope (tree
);
4727 static void pop_decl_scope (void);
4728 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
4729 static inline int local_scope_p (dw_die_ref
);
4730 static inline int class_or_namespace_scope_p (dw_die_ref
);
4731 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
4732 static void add_calling_convention_attribute (dw_die_ref
, tree
);
4733 static const char *type_tag (const_tree
);
4734 static tree
member_declared_type (const_tree
);
4736 static const char *decl_start_label (tree
);
4738 static void gen_array_type_die (tree
, dw_die_ref
);
4739 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
4741 static void gen_entry_point_die (tree
, dw_die_ref
);
4743 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
4744 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
4745 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
4746 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
4747 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
4748 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
4749 static void gen_formal_types_die (tree
, dw_die_ref
);
4750 static void gen_subprogram_die (tree
, dw_die_ref
);
4751 static void gen_variable_die (tree
, dw_die_ref
);
4752 static void gen_label_die (tree
, dw_die_ref
);
4753 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
4754 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
4755 static void gen_field_die (tree
, dw_die_ref
);
4756 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
4757 static dw_die_ref
gen_compile_unit_die (const char *);
4758 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
4759 static void gen_member_die (tree
, dw_die_ref
);
4760 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
4761 enum debug_info_usage
);
4762 static void gen_subroutine_type_die (tree
, dw_die_ref
);
4763 static void gen_typedef_die (tree
, dw_die_ref
);
4764 static void gen_type_die (tree
, dw_die_ref
);
4765 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
4766 static void gen_block_die (tree
, dw_die_ref
, int);
4767 static void decls_for_scope (tree
, dw_die_ref
, int);
4768 static int is_redundant_typedef (const_tree
);
4769 static void gen_namespace_die (tree
);
4770 static void gen_decl_die (tree
, dw_die_ref
);
4771 static dw_die_ref
force_decl_die (tree
);
4772 static dw_die_ref
force_type_die (tree
);
4773 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
4774 static void declare_in_namespace (tree
, dw_die_ref
);
4775 static struct dwarf_file_data
* lookup_filename (const char *);
4776 static void retry_incomplete_types (void);
4777 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
4778 static void splice_child_die (dw_die_ref
, dw_die_ref
);
4779 static int file_info_cmp (const void *, const void *);
4780 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
4781 const char *, const char *, unsigned);
4782 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
4783 const char *, const char *,
4785 static void output_loc_list (dw_loc_list_ref
);
4786 static char *gen_internal_sym (const char *);
4788 static void prune_unmark_dies (dw_die_ref
);
4789 static void prune_unused_types_mark (dw_die_ref
, int);
4790 static void prune_unused_types_walk (dw_die_ref
);
4791 static void prune_unused_types_walk_attribs (dw_die_ref
);
4792 static void prune_unused_types_prune (dw_die_ref
);
4793 static void prune_unused_types (void);
4794 static int maybe_emit_file (struct dwarf_file_data
*fd
);
4796 /* Section names used to hold DWARF debugging information. */
4797 #ifndef DEBUG_INFO_SECTION
4798 #define DEBUG_INFO_SECTION ".debug_info"
4800 #ifndef DEBUG_ABBREV_SECTION
4801 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4803 #ifndef DEBUG_ARANGES_SECTION
4804 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4806 #ifndef DEBUG_MACINFO_SECTION
4807 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4809 #ifndef DEBUG_LINE_SECTION
4810 #define DEBUG_LINE_SECTION ".debug_line"
4812 #ifndef DEBUG_LOC_SECTION
4813 #define DEBUG_LOC_SECTION ".debug_loc"
4815 #ifndef DEBUG_PUBNAMES_SECTION
4816 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4818 #ifndef DEBUG_STR_SECTION
4819 #define DEBUG_STR_SECTION ".debug_str"
4821 #ifndef DEBUG_RANGES_SECTION
4822 #define DEBUG_RANGES_SECTION ".debug_ranges"
4825 /* Standard ELF section names for compiled code and data. */
4826 #ifndef TEXT_SECTION_NAME
4827 #define TEXT_SECTION_NAME ".text"
4830 /* Section flags for .debug_str section. */
4831 #define DEBUG_STR_SECTION_FLAGS \
4832 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4833 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4836 /* Labels we insert at beginning sections we can reference instead of
4837 the section names themselves. */
4839 #ifndef TEXT_SECTION_LABEL
4840 #define TEXT_SECTION_LABEL "Ltext"
4842 #ifndef COLD_TEXT_SECTION_LABEL
4843 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4845 #ifndef DEBUG_LINE_SECTION_LABEL
4846 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4848 #ifndef DEBUG_INFO_SECTION_LABEL
4849 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4851 #ifndef DEBUG_ABBREV_SECTION_LABEL
4852 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4854 #ifndef DEBUG_LOC_SECTION_LABEL
4855 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4857 #ifndef DEBUG_RANGES_SECTION_LABEL
4858 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4860 #ifndef DEBUG_MACINFO_SECTION_LABEL
4861 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4864 /* Definitions of defaults for formats and names of various special
4865 (artificial) labels which may be generated within this file (when the -g
4866 options is used and DWARF2_DEBUGGING_INFO is in effect.
4867 If necessary, these may be overridden from within the tm.h file, but
4868 typically, overriding these defaults is unnecessary. */
4870 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4871 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4872 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4873 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4874 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4875 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4876 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4877 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4878 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4879 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4881 #ifndef TEXT_END_LABEL
4882 #define TEXT_END_LABEL "Letext"
4884 #ifndef COLD_END_LABEL
4885 #define COLD_END_LABEL "Letext_cold"
4887 #ifndef BLOCK_BEGIN_LABEL
4888 #define BLOCK_BEGIN_LABEL "LBB"
4890 #ifndef BLOCK_END_LABEL
4891 #define BLOCK_END_LABEL "LBE"
4893 #ifndef LINE_CODE_LABEL
4894 #define LINE_CODE_LABEL "LM"
4896 #ifndef SEPARATE_LINE_CODE_LABEL
4897 #define SEPARATE_LINE_CODE_LABEL "LSM"
4901 /* We allow a language front-end to designate a function that is to be
4902 called to "demangle" any name before it is put into a DIE. */
4904 static const char *(*demangle_name_func
) (const char *);
4907 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4909 demangle_name_func
= func
;
4912 /* Test if rtl node points to a pseudo register. */
4915 is_pseudo_reg (const_rtx rtl
)
4917 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4918 || (GET_CODE (rtl
) == SUBREG
4919 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4922 /* Return a reference to a type, with its const and volatile qualifiers
4926 type_main_variant (tree type
)
4928 type
= TYPE_MAIN_VARIANT (type
);
4930 /* ??? There really should be only one main variant among any group of
4931 variants of a given type (and all of the MAIN_VARIANT values for all
4932 members of the group should point to that one type) but sometimes the C
4933 front-end messes this up for array types, so we work around that bug
4935 if (TREE_CODE (type
) == ARRAY_TYPE
)
4936 while (type
!= TYPE_MAIN_VARIANT (type
))
4937 type
= TYPE_MAIN_VARIANT (type
);
4942 /* Return nonzero if the given type node represents a tagged type. */
4945 is_tagged_type (const_tree type
)
4947 enum tree_code code
= TREE_CODE (type
);
4949 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4950 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4953 /* Convert a DIE tag into its string name. */
4956 dwarf_tag_name (unsigned int tag
)
4960 case DW_TAG_padding
:
4961 return "DW_TAG_padding";
4962 case DW_TAG_array_type
:
4963 return "DW_TAG_array_type";
4964 case DW_TAG_class_type
:
4965 return "DW_TAG_class_type";
4966 case DW_TAG_entry_point
:
4967 return "DW_TAG_entry_point";
4968 case DW_TAG_enumeration_type
:
4969 return "DW_TAG_enumeration_type";
4970 case DW_TAG_formal_parameter
:
4971 return "DW_TAG_formal_parameter";
4972 case DW_TAG_imported_declaration
:
4973 return "DW_TAG_imported_declaration";
4975 return "DW_TAG_label";
4976 case DW_TAG_lexical_block
:
4977 return "DW_TAG_lexical_block";
4979 return "DW_TAG_member";
4980 case DW_TAG_pointer_type
:
4981 return "DW_TAG_pointer_type";
4982 case DW_TAG_reference_type
:
4983 return "DW_TAG_reference_type";
4984 case DW_TAG_compile_unit
:
4985 return "DW_TAG_compile_unit";
4986 case DW_TAG_string_type
:
4987 return "DW_TAG_string_type";
4988 case DW_TAG_structure_type
:
4989 return "DW_TAG_structure_type";
4990 case DW_TAG_subroutine_type
:
4991 return "DW_TAG_subroutine_type";
4992 case DW_TAG_typedef
:
4993 return "DW_TAG_typedef";
4994 case DW_TAG_union_type
:
4995 return "DW_TAG_union_type";
4996 case DW_TAG_unspecified_parameters
:
4997 return "DW_TAG_unspecified_parameters";
4998 case DW_TAG_variant
:
4999 return "DW_TAG_variant";
5000 case DW_TAG_common_block
:
5001 return "DW_TAG_common_block";
5002 case DW_TAG_common_inclusion
:
5003 return "DW_TAG_common_inclusion";
5004 case DW_TAG_inheritance
:
5005 return "DW_TAG_inheritance";
5006 case DW_TAG_inlined_subroutine
:
5007 return "DW_TAG_inlined_subroutine";
5009 return "DW_TAG_module";
5010 case DW_TAG_ptr_to_member_type
:
5011 return "DW_TAG_ptr_to_member_type";
5012 case DW_TAG_set_type
:
5013 return "DW_TAG_set_type";
5014 case DW_TAG_subrange_type
:
5015 return "DW_TAG_subrange_type";
5016 case DW_TAG_with_stmt
:
5017 return "DW_TAG_with_stmt";
5018 case DW_TAG_access_declaration
:
5019 return "DW_TAG_access_declaration";
5020 case DW_TAG_base_type
:
5021 return "DW_TAG_base_type";
5022 case DW_TAG_catch_block
:
5023 return "DW_TAG_catch_block";
5024 case DW_TAG_const_type
:
5025 return "DW_TAG_const_type";
5026 case DW_TAG_constant
:
5027 return "DW_TAG_constant";
5028 case DW_TAG_enumerator
:
5029 return "DW_TAG_enumerator";
5030 case DW_TAG_file_type
:
5031 return "DW_TAG_file_type";
5033 return "DW_TAG_friend";
5034 case DW_TAG_namelist
:
5035 return "DW_TAG_namelist";
5036 case DW_TAG_namelist_item
:
5037 return "DW_TAG_namelist_item";
5038 case DW_TAG_packed_type
:
5039 return "DW_TAG_packed_type";
5040 case DW_TAG_subprogram
:
5041 return "DW_TAG_subprogram";
5042 case DW_TAG_template_type_param
:
5043 return "DW_TAG_template_type_param";
5044 case DW_TAG_template_value_param
:
5045 return "DW_TAG_template_value_param";
5046 case DW_TAG_thrown_type
:
5047 return "DW_TAG_thrown_type";
5048 case DW_TAG_try_block
:
5049 return "DW_TAG_try_block";
5050 case DW_TAG_variant_part
:
5051 return "DW_TAG_variant_part";
5052 case DW_TAG_variable
:
5053 return "DW_TAG_variable";
5054 case DW_TAG_volatile_type
:
5055 return "DW_TAG_volatile_type";
5056 case DW_TAG_dwarf_procedure
:
5057 return "DW_TAG_dwarf_procedure";
5058 case DW_TAG_restrict_type
:
5059 return "DW_TAG_restrict_type";
5060 case DW_TAG_interface_type
:
5061 return "DW_TAG_interface_type";
5062 case DW_TAG_namespace
:
5063 return "DW_TAG_namespace";
5064 case DW_TAG_imported_module
:
5065 return "DW_TAG_imported_module";
5066 case DW_TAG_unspecified_type
:
5067 return "DW_TAG_unspecified_type";
5068 case DW_TAG_partial_unit
:
5069 return "DW_TAG_partial_unit";
5070 case DW_TAG_imported_unit
:
5071 return "DW_TAG_imported_unit";
5072 case DW_TAG_condition
:
5073 return "DW_TAG_condition";
5074 case DW_TAG_shared_type
:
5075 return "DW_TAG_shared_type";
5076 case DW_TAG_MIPS_loop
:
5077 return "DW_TAG_MIPS_loop";
5078 case DW_TAG_format_label
:
5079 return "DW_TAG_format_label";
5080 case DW_TAG_function_template
:
5081 return "DW_TAG_function_template";
5082 case DW_TAG_class_template
:
5083 return "DW_TAG_class_template";
5084 case DW_TAG_GNU_BINCL
:
5085 return "DW_TAG_GNU_BINCL";
5086 case DW_TAG_GNU_EINCL
:
5087 return "DW_TAG_GNU_EINCL";
5089 return "DW_TAG_<unknown>";
5093 /* Convert a DWARF attribute code into its string name. */
5096 dwarf_attr_name (unsigned int attr
)
5101 return "DW_AT_sibling";
5102 case DW_AT_location
:
5103 return "DW_AT_location";
5105 return "DW_AT_name";
5106 case DW_AT_ordering
:
5107 return "DW_AT_ordering";
5108 case DW_AT_subscr_data
:
5109 return "DW_AT_subscr_data";
5110 case DW_AT_byte_size
:
5111 return "DW_AT_byte_size";
5112 case DW_AT_bit_offset
:
5113 return "DW_AT_bit_offset";
5114 case DW_AT_bit_size
:
5115 return "DW_AT_bit_size";
5116 case DW_AT_element_list
:
5117 return "DW_AT_element_list";
5118 case DW_AT_stmt_list
:
5119 return "DW_AT_stmt_list";
5121 return "DW_AT_low_pc";
5123 return "DW_AT_high_pc";
5124 case DW_AT_language
:
5125 return "DW_AT_language";
5127 return "DW_AT_member";
5129 return "DW_AT_discr";
5130 case DW_AT_discr_value
:
5131 return "DW_AT_discr_value";
5132 case DW_AT_visibility
:
5133 return "DW_AT_visibility";
5135 return "DW_AT_import";
5136 case DW_AT_string_length
:
5137 return "DW_AT_string_length";
5138 case DW_AT_common_reference
:
5139 return "DW_AT_common_reference";
5140 case DW_AT_comp_dir
:
5141 return "DW_AT_comp_dir";
5142 case DW_AT_const_value
:
5143 return "DW_AT_const_value";
5144 case DW_AT_containing_type
:
5145 return "DW_AT_containing_type";
5146 case DW_AT_default_value
:
5147 return "DW_AT_default_value";
5149 return "DW_AT_inline";
5150 case DW_AT_is_optional
:
5151 return "DW_AT_is_optional";
5152 case DW_AT_lower_bound
:
5153 return "DW_AT_lower_bound";
5154 case DW_AT_producer
:
5155 return "DW_AT_producer";
5156 case DW_AT_prototyped
:
5157 return "DW_AT_prototyped";
5158 case DW_AT_return_addr
:
5159 return "DW_AT_return_addr";
5160 case DW_AT_start_scope
:
5161 return "DW_AT_start_scope";
5162 case DW_AT_bit_stride
:
5163 return "DW_AT_bit_stride";
5164 case DW_AT_upper_bound
:
5165 return "DW_AT_upper_bound";
5166 case DW_AT_abstract_origin
:
5167 return "DW_AT_abstract_origin";
5168 case DW_AT_accessibility
:
5169 return "DW_AT_accessibility";
5170 case DW_AT_address_class
:
5171 return "DW_AT_address_class";
5172 case DW_AT_artificial
:
5173 return "DW_AT_artificial";
5174 case DW_AT_base_types
:
5175 return "DW_AT_base_types";
5176 case DW_AT_calling_convention
:
5177 return "DW_AT_calling_convention";
5179 return "DW_AT_count";
5180 case DW_AT_data_member_location
:
5181 return "DW_AT_data_member_location";
5182 case DW_AT_decl_column
:
5183 return "DW_AT_decl_column";
5184 case DW_AT_decl_file
:
5185 return "DW_AT_decl_file";
5186 case DW_AT_decl_line
:
5187 return "DW_AT_decl_line";
5188 case DW_AT_declaration
:
5189 return "DW_AT_declaration";
5190 case DW_AT_discr_list
:
5191 return "DW_AT_discr_list";
5192 case DW_AT_encoding
:
5193 return "DW_AT_encoding";
5194 case DW_AT_external
:
5195 return "DW_AT_external";
5196 case DW_AT_frame_base
:
5197 return "DW_AT_frame_base";
5199 return "DW_AT_friend";
5200 case DW_AT_identifier_case
:
5201 return "DW_AT_identifier_case";
5202 case DW_AT_macro_info
:
5203 return "DW_AT_macro_info";
5204 case DW_AT_namelist_items
:
5205 return "DW_AT_namelist_items";
5206 case DW_AT_priority
:
5207 return "DW_AT_priority";
5209 return "DW_AT_segment";
5210 case DW_AT_specification
:
5211 return "DW_AT_specification";
5212 case DW_AT_static_link
:
5213 return "DW_AT_static_link";
5215 return "DW_AT_type";
5216 case DW_AT_use_location
:
5217 return "DW_AT_use_location";
5218 case DW_AT_variable_parameter
:
5219 return "DW_AT_variable_parameter";
5220 case DW_AT_virtuality
:
5221 return "DW_AT_virtuality";
5222 case DW_AT_vtable_elem_location
:
5223 return "DW_AT_vtable_elem_location";
5225 case DW_AT_allocated
:
5226 return "DW_AT_allocated";
5227 case DW_AT_associated
:
5228 return "DW_AT_associated";
5229 case DW_AT_data_location
:
5230 return "DW_AT_data_location";
5231 case DW_AT_byte_stride
:
5232 return "DW_AT_byte_stride";
5233 case DW_AT_entry_pc
:
5234 return "DW_AT_entry_pc";
5235 case DW_AT_use_UTF8
:
5236 return "DW_AT_use_UTF8";
5237 case DW_AT_extension
:
5238 return "DW_AT_extension";
5240 return "DW_AT_ranges";
5241 case DW_AT_trampoline
:
5242 return "DW_AT_trampoline";
5243 case DW_AT_call_column
:
5244 return "DW_AT_call_column";
5245 case DW_AT_call_file
:
5246 return "DW_AT_call_file";
5247 case DW_AT_call_line
:
5248 return "DW_AT_call_line";
5250 case DW_AT_MIPS_fde
:
5251 return "DW_AT_MIPS_fde";
5252 case DW_AT_MIPS_loop_begin
:
5253 return "DW_AT_MIPS_loop_begin";
5254 case DW_AT_MIPS_tail_loop_begin
:
5255 return "DW_AT_MIPS_tail_loop_begin";
5256 case DW_AT_MIPS_epilog_begin
:
5257 return "DW_AT_MIPS_epilog_begin";
5258 case DW_AT_MIPS_loop_unroll_factor
:
5259 return "DW_AT_MIPS_loop_unroll_factor";
5260 case DW_AT_MIPS_software_pipeline_depth
:
5261 return "DW_AT_MIPS_software_pipeline_depth";
5262 case DW_AT_MIPS_linkage_name
:
5263 return "DW_AT_MIPS_linkage_name";
5264 case DW_AT_MIPS_stride
:
5265 return "DW_AT_MIPS_stride";
5266 case DW_AT_MIPS_abstract_name
:
5267 return "DW_AT_MIPS_abstract_name";
5268 case DW_AT_MIPS_clone_origin
:
5269 return "DW_AT_MIPS_clone_origin";
5270 case DW_AT_MIPS_has_inlines
:
5271 return "DW_AT_MIPS_has_inlines";
5273 case DW_AT_sf_names
:
5274 return "DW_AT_sf_names";
5275 case DW_AT_src_info
:
5276 return "DW_AT_src_info";
5277 case DW_AT_mac_info
:
5278 return "DW_AT_mac_info";
5279 case DW_AT_src_coords
:
5280 return "DW_AT_src_coords";
5281 case DW_AT_body_begin
:
5282 return "DW_AT_body_begin";
5283 case DW_AT_body_end
:
5284 return "DW_AT_body_end";
5285 case DW_AT_GNU_vector
:
5286 return "DW_AT_GNU_vector";
5288 case DW_AT_VMS_rtnbeg_pd_address
:
5289 return "DW_AT_VMS_rtnbeg_pd_address";
5292 return "DW_AT_<unknown>";
5296 /* Convert a DWARF value form code into its string name. */
5299 dwarf_form_name (unsigned int form
)
5304 return "DW_FORM_addr";
5305 case DW_FORM_block2
:
5306 return "DW_FORM_block2";
5307 case DW_FORM_block4
:
5308 return "DW_FORM_block4";
5310 return "DW_FORM_data2";
5312 return "DW_FORM_data4";
5314 return "DW_FORM_data8";
5315 case DW_FORM_string
:
5316 return "DW_FORM_string";
5318 return "DW_FORM_block";
5319 case DW_FORM_block1
:
5320 return "DW_FORM_block1";
5322 return "DW_FORM_data1";
5324 return "DW_FORM_flag";
5326 return "DW_FORM_sdata";
5328 return "DW_FORM_strp";
5330 return "DW_FORM_udata";
5331 case DW_FORM_ref_addr
:
5332 return "DW_FORM_ref_addr";
5334 return "DW_FORM_ref1";
5336 return "DW_FORM_ref2";
5338 return "DW_FORM_ref4";
5340 return "DW_FORM_ref8";
5341 case DW_FORM_ref_udata
:
5342 return "DW_FORM_ref_udata";
5343 case DW_FORM_indirect
:
5344 return "DW_FORM_indirect";
5346 return "DW_FORM_<unknown>";
5350 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
5351 instance of an inlined instance of a decl which is local to an inline
5352 function, so we have to trace all of the way back through the origin chain
5353 to find out what sort of node actually served as the original seed for the
5357 decl_ultimate_origin (const_tree decl
)
5359 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
5362 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
5363 nodes in the function to point to themselves; ignore that if
5364 we're trying to output the abstract instance of this function. */
5365 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
5368 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
5369 most distant ancestor, this should never happen. */
5370 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
5372 return DECL_ABSTRACT_ORIGIN (decl
);
5375 /* Determine the "ultimate origin" of a block. The block may be an inlined
5376 instance of an inlined instance of a block which is local to an inline
5377 function, so we have to trace all of the way back through the origin chain
5378 to find out what sort of node actually served as the original seed for the
5382 block_ultimate_origin (const_tree block
)
5384 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
5386 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
5387 nodes in the function to point to themselves; ignore that if
5388 we're trying to output the abstract instance of this function. */
5389 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
5392 if (immediate_origin
== NULL_TREE
)
5397 tree lookahead
= immediate_origin
;
5401 ret_val
= lookahead
;
5402 lookahead
= (TREE_CODE (ret_val
) == BLOCK
5403 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
5405 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
5407 /* The block's abstract origin chain may not be the *ultimate* origin of
5408 the block. It could lead to a DECL that has an abstract origin set.
5409 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
5410 will give us if it has one). Note that DECL's abstract origins are
5411 supposed to be the most distant ancestor (or so decl_ultimate_origin
5412 claims), so we don't need to loop following the DECL origins. */
5413 if (DECL_P (ret_val
))
5414 return DECL_ORIGIN (ret_val
);
5420 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
5421 of a virtual function may refer to a base class, so we check the 'this'
5425 decl_class_context (tree decl
)
5427 tree context
= NULL_TREE
;
5429 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
5430 context
= DECL_CONTEXT (decl
);
5432 context
= TYPE_MAIN_VARIANT
5433 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
5435 if (context
&& !TYPE_P (context
))
5436 context
= NULL_TREE
;
5441 /* Add an attribute/value pair to a DIE. */
5444 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
5446 /* Maybe this should be an assert? */
5450 if (die
->die_attr
== NULL
)
5451 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
5452 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
5455 static inline enum dw_val_class
5456 AT_class (dw_attr_ref a
)
5458 return a
->dw_attr_val
.val_class
;
5461 /* Add a flag value attribute to a DIE. */
5464 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
5468 attr
.dw_attr
= attr_kind
;
5469 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
5470 attr
.dw_attr_val
.v
.val_flag
= flag
;
5471 add_dwarf_attr (die
, &attr
);
5474 static inline unsigned
5475 AT_flag (dw_attr_ref a
)
5477 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
5478 return a
->dw_attr_val
.v
.val_flag
;
5481 /* Add a signed integer attribute value to a DIE. */
5484 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
5488 attr
.dw_attr
= attr_kind
;
5489 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
5490 attr
.dw_attr_val
.v
.val_int
= int_val
;
5491 add_dwarf_attr (die
, &attr
);
5494 static inline HOST_WIDE_INT
5495 AT_int (dw_attr_ref a
)
5497 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
5498 return a
->dw_attr_val
.v
.val_int
;
5501 /* Add an unsigned integer attribute value to a DIE. */
5504 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5505 unsigned HOST_WIDE_INT unsigned_val
)
5509 attr
.dw_attr
= attr_kind
;
5510 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
5511 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
5512 add_dwarf_attr (die
, &attr
);
5515 static inline unsigned HOST_WIDE_INT
5516 AT_unsigned (dw_attr_ref a
)
5518 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
5519 return a
->dw_attr_val
.v
.val_unsigned
;
5522 /* Add an unsigned double integer attribute value to a DIE. */
5525 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5526 long unsigned int val_hi
, long unsigned int val_low
)
5530 attr
.dw_attr
= attr_kind
;
5531 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
5532 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
5533 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
5534 add_dwarf_attr (die
, &attr
);
5537 /* Add a floating point attribute value to a DIE and return it. */
5540 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5541 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
5545 attr
.dw_attr
= attr_kind
;
5546 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
5547 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
5548 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
5549 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
5550 add_dwarf_attr (die
, &attr
);
5553 /* Hash and equality functions for debug_str_hash. */
5556 debug_str_do_hash (const void *x
)
5558 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
5562 debug_str_eq (const void *x1
, const void *x2
)
5564 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
5565 (const char *)x2
) == 0;
5568 /* Add a string attribute value to a DIE. */
5571 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
5574 struct indirect_string_node
*node
;
5577 if (! debug_str_hash
)
5578 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
5579 debug_str_eq
, NULL
);
5581 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
5582 htab_hash_string (str
), INSERT
);
5585 node
= (struct indirect_string_node
*)
5586 ggc_alloc_cleared (sizeof (struct indirect_string_node
));
5587 node
->str
= ggc_strdup (str
);
5591 node
= (struct indirect_string_node
*) *slot
;
5595 attr
.dw_attr
= attr_kind
;
5596 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
5597 attr
.dw_attr_val
.v
.val_str
= node
;
5598 add_dwarf_attr (die
, &attr
);
5601 static inline const char *
5602 AT_string (dw_attr_ref a
)
5604 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5605 return a
->dw_attr_val
.v
.val_str
->str
;
5608 /* Find out whether a string should be output inline in DIE
5609 or out-of-line in .debug_str section. */
5612 AT_string_form (dw_attr_ref a
)
5614 struct indirect_string_node
*node
;
5618 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5620 node
= a
->dw_attr_val
.v
.val_str
;
5624 len
= strlen (node
->str
) + 1;
5626 /* If the string is shorter or equal to the size of the reference, it is
5627 always better to put it inline. */
5628 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
5629 return node
->form
= DW_FORM_string
;
5631 /* If we cannot expect the linker to merge strings in .debug_str
5632 section, only put it into .debug_str if it is worth even in this
5634 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
5635 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
5636 return node
->form
= DW_FORM_string
;
5638 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
5639 ++dw2_string_counter
;
5640 node
->label
= xstrdup (label
);
5642 return node
->form
= DW_FORM_strp
;
5645 /* Add a DIE reference attribute value to a DIE. */
5648 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
5652 attr
.dw_attr
= attr_kind
;
5653 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
5654 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
5655 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
5656 add_dwarf_attr (die
, &attr
);
5659 /* Add an AT_specification attribute to a DIE, and also make the back
5660 pointer from the specification to the definition. */
5663 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
5665 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
5666 gcc_assert (!targ_die
->die_definition
);
5667 targ_die
->die_definition
= die
;
5670 static inline dw_die_ref
5671 AT_ref (dw_attr_ref a
)
5673 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5674 return a
->dw_attr_val
.v
.val_die_ref
.die
;
5678 AT_ref_external (dw_attr_ref a
)
5680 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
5681 return a
->dw_attr_val
.v
.val_die_ref
.external
;
5687 set_AT_ref_external (dw_attr_ref a
, int i
)
5689 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5690 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
5693 /* Add an FDE reference attribute value to a DIE. */
5696 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
5700 attr
.dw_attr
= attr_kind
;
5701 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
5702 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
5703 add_dwarf_attr (die
, &attr
);
5706 /* Add a location description attribute value to a DIE. */
5709 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
5713 attr
.dw_attr
= attr_kind
;
5714 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
5715 attr
.dw_attr_val
.v
.val_loc
= loc
;
5716 add_dwarf_attr (die
, &attr
);
5719 static inline dw_loc_descr_ref
5720 AT_loc (dw_attr_ref a
)
5722 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
5723 return a
->dw_attr_val
.v
.val_loc
;
5727 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
5731 attr
.dw_attr
= attr_kind
;
5732 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
5733 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
5734 add_dwarf_attr (die
, &attr
);
5735 have_location_lists
= true;
5738 static inline dw_loc_list_ref
5739 AT_loc_list (dw_attr_ref a
)
5741 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5742 return a
->dw_attr_val
.v
.val_loc_list
;
5745 /* Add an address constant attribute value to a DIE. */
5748 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
5752 attr
.dw_attr
= attr_kind
;
5753 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5754 attr
.dw_attr_val
.v
.val_addr
= addr
;
5755 add_dwarf_attr (die
, &attr
);
5758 /* Get the RTX from to an address DIE attribute. */
5761 AT_addr (dw_attr_ref a
)
5763 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5764 return a
->dw_attr_val
.v
.val_addr
;
5767 /* Add a file attribute value to a DIE. */
5770 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5771 struct dwarf_file_data
*fd
)
5775 attr
.dw_attr
= attr_kind
;
5776 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5777 attr
.dw_attr_val
.v
.val_file
= fd
;
5778 add_dwarf_attr (die
, &attr
);
5781 /* Get the dwarf_file_data from a file DIE attribute. */
5783 static inline struct dwarf_file_data
*
5784 AT_file (dw_attr_ref a
)
5786 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
5787 return a
->dw_attr_val
.v
.val_file
;
5790 /* Add a label identifier attribute value to a DIE. */
5793 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5797 attr
.dw_attr
= attr_kind
;
5798 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5799 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5800 add_dwarf_attr (die
, &attr
);
5803 /* Add a section offset attribute value to a DIE, an offset into the
5804 debug_line section. */
5807 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5812 attr
.dw_attr
= attr_kind
;
5813 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5814 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5815 add_dwarf_attr (die
, &attr
);
5818 /* Add a section offset attribute value to a DIE, an offset into the
5819 debug_macinfo section. */
5822 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5827 attr
.dw_attr
= attr_kind
;
5828 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5829 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5830 add_dwarf_attr (die
, &attr
);
5833 /* Add an offset attribute value to a DIE. */
5836 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5837 unsigned HOST_WIDE_INT offset
)
5841 attr
.dw_attr
= attr_kind
;
5842 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
5843 attr
.dw_attr_val
.v
.val_offset
= offset
;
5844 add_dwarf_attr (die
, &attr
);
5847 /* Add an range_list attribute value to a DIE. */
5850 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5851 long unsigned int offset
)
5855 attr
.dw_attr
= attr_kind
;
5856 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5857 attr
.dw_attr_val
.v
.val_offset
= offset
;
5858 add_dwarf_attr (die
, &attr
);
5861 static inline const char *
5862 AT_lbl (dw_attr_ref a
)
5864 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5865 || AT_class (a
) == dw_val_class_lineptr
5866 || AT_class (a
) == dw_val_class_macptr
));
5867 return a
->dw_attr_val
.v
.val_lbl_id
;
5870 /* Get the attribute of type attr_kind. */
5873 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5877 dw_die_ref spec
= NULL
;
5882 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5883 if (a
->dw_attr
== attr_kind
)
5885 else if (a
->dw_attr
== DW_AT_specification
5886 || a
->dw_attr
== DW_AT_abstract_origin
)
5890 return get_AT (spec
, attr_kind
);
5895 /* Return the "low pc" attribute value, typically associated with a subprogram
5896 DIE. Return null if the "low pc" attribute is either not present, or if it
5897 cannot be represented as an assembler label identifier. */
5899 static inline const char *
5900 get_AT_low_pc (dw_die_ref die
)
5902 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5904 return a
? AT_lbl (a
) : NULL
;
5907 /* Return the "high pc" attribute value, typically associated with a subprogram
5908 DIE. Return null if the "high pc" attribute is either not present, or if it
5909 cannot be represented as an assembler label identifier. */
5911 static inline const char *
5912 get_AT_hi_pc (dw_die_ref die
)
5914 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5916 return a
? AT_lbl (a
) : NULL
;
5919 /* Return the value of the string attribute designated by ATTR_KIND, or
5920 NULL if it is not present. */
5922 static inline const char *
5923 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5925 dw_attr_ref a
= get_AT (die
, attr_kind
);
5927 return a
? AT_string (a
) : NULL
;
5930 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5931 if it is not present. */
5934 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5936 dw_attr_ref a
= get_AT (die
, attr_kind
);
5938 return a
? AT_flag (a
) : 0;
5941 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5942 if it is not present. */
5944 static inline unsigned
5945 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5947 dw_attr_ref a
= get_AT (die
, attr_kind
);
5949 return a
? AT_unsigned (a
) : 0;
5952 static inline dw_die_ref
5953 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5955 dw_attr_ref a
= get_AT (die
, attr_kind
);
5957 return a
? AT_ref (a
) : NULL
;
5960 static inline struct dwarf_file_data
*
5961 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5963 dw_attr_ref a
= get_AT (die
, attr_kind
);
5965 return a
? AT_file (a
) : NULL
;
5968 /* Return TRUE if the language is C or C++. */
5973 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5975 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
5976 || lang
== DW_LANG_C99
5977 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
5980 /* Return TRUE if the language is C++. */
5985 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5987 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
5990 /* Return TRUE if the language is Fortran. */
5995 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5997 return (lang
== DW_LANG_Fortran77
5998 || lang
== DW_LANG_Fortran90
5999 || lang
== DW_LANG_Fortran95
);
6002 /* Return TRUE if the language is Java. */
6007 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6009 return lang
== DW_LANG_Java
;
6012 /* Return TRUE if the language is Ada. */
6017 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
6019 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
6022 /* Remove the specified attribute if present. */
6025 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
6033 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6034 if (a
->dw_attr
== attr_kind
)
6036 if (AT_class (a
) == dw_val_class_str
)
6037 if (a
->dw_attr_val
.v
.val_str
->refcount
)
6038 a
->dw_attr_val
.v
.val_str
->refcount
--;
6040 /* VEC_ordered_remove should help reduce the number of abbrevs
6042 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
6047 /* Remove CHILD from its parent. PREV must have the property that
6048 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
6051 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
6053 gcc_assert (child
->die_parent
== prev
->die_parent
);
6054 gcc_assert (prev
->die_sib
== child
);
6057 gcc_assert (child
->die_parent
->die_child
== child
);
6061 prev
->die_sib
= child
->die_sib
;
6062 if (child
->die_parent
->die_child
== child
)
6063 child
->die_parent
->die_child
= prev
;
6066 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
6070 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
6076 dw_die_ref prev
= c
;
6078 while (c
->die_tag
== tag
)
6080 remove_child_with_prev (c
, prev
);
6081 /* Might have removed every child. */
6082 if (c
== c
->die_sib
)
6086 } while (c
!= die
->die_child
);
6089 /* Add a CHILD_DIE as the last child of DIE. */
6092 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
6094 /* FIXME this should probably be an assert. */
6095 if (! die
|| ! child_die
)
6097 gcc_assert (die
!= child_die
);
6099 child_die
->die_parent
= die
;
6102 child_die
->die_sib
= die
->die_child
->die_sib
;
6103 die
->die_child
->die_sib
= child_die
;
6106 child_die
->die_sib
= child_die
;
6107 die
->die_child
= child_die
;
6110 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
6111 is the specification, to the end of PARENT's list of children.
6112 This is done by removing and re-adding it. */
6115 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
6119 /* We want the declaration DIE from inside the class, not the
6120 specification DIE at toplevel. */
6121 if (child
->die_parent
!= parent
)
6123 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
6129 gcc_assert (child
->die_parent
== parent
6130 || (child
->die_parent
6131 == get_AT_ref (parent
, DW_AT_specification
)));
6133 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
6134 if (p
->die_sib
== child
)
6136 remove_child_with_prev (child
, p
);
6140 add_child_die (parent
, child
);
6143 /* Return a pointer to a newly created DIE node. */
6145 static inline dw_die_ref
6146 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
6148 dw_die_ref die
= GGC_CNEW (die_node
);
6150 die
->die_tag
= tag_value
;
6152 if (parent_die
!= NULL
)
6153 add_child_die (parent_die
, die
);
6156 limbo_die_node
*limbo_node
;
6158 limbo_node
= GGC_CNEW (limbo_die_node
);
6159 limbo_node
->die
= die
;
6160 limbo_node
->created_for
= t
;
6161 limbo_node
->next
= limbo_die_list
;
6162 limbo_die_list
= limbo_node
;
6168 /* Return the DIE associated with the given type specifier. */
6170 static inline dw_die_ref
6171 lookup_type_die (tree type
)
6173 return TYPE_SYMTAB_DIE (type
);
6176 /* Equate a DIE to a given type specifier. */
6179 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
6181 TYPE_SYMTAB_DIE (type
) = type_die
;
6184 /* Returns a hash value for X (which really is a die_struct). */
6187 decl_die_table_hash (const void *x
)
6189 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
6192 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
6195 decl_die_table_eq (const void *x
, const void *y
)
6197 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
6200 /* Return the DIE associated with a given declaration. */
6202 static inline dw_die_ref
6203 lookup_decl_die (tree decl
)
6205 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
6208 /* Returns a hash value for X (which really is a var_loc_list). */
6211 decl_loc_table_hash (const void *x
)
6213 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
6216 /* Return nonzero if decl_id of var_loc_list X is the same as
6220 decl_loc_table_eq (const void *x
, const void *y
)
6222 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
6225 /* Return the var_loc list associated with a given declaration. */
6227 static inline var_loc_list
*
6228 lookup_decl_loc (const_tree decl
)
6230 return (var_loc_list
*)
6231 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
6234 /* Equate a DIE to a particular declaration. */
6237 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
6239 unsigned int decl_id
= DECL_UID (decl
);
6242 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
6244 decl_die
->decl_id
= decl_id
;
6247 /* Add a variable location node to the linked list for DECL. */
6250 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
6252 unsigned int decl_id
= DECL_UID (decl
);
6256 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
6259 temp
= GGC_CNEW (var_loc_list
);
6260 temp
->decl_id
= decl_id
;
6264 temp
= (var_loc_list
*) *slot
;
6268 /* If the current location is the same as the end of the list,
6269 and either both or neither of the locations is uninitialized,
6270 we have nothing to do. */
6271 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
6272 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
6273 || ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
6274 != NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
))
6275 && ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
6276 == VAR_INIT_STATUS_UNINITIALIZED
)
6277 || (NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
)
6278 == VAR_INIT_STATUS_UNINITIALIZED
))))
6280 /* Add LOC to the end of list and update LAST. */
6281 temp
->last
->next
= loc
;
6285 /* Do not add empty location to the beginning of the list. */
6286 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
6293 /* Keep track of the number of spaces used to indent the
6294 output of the debugging routines that print the structure of
6295 the DIE internal representation. */
6296 static int print_indent
;
6298 /* Indent the line the number of spaces given by print_indent. */
6301 print_spaces (FILE *outfile
)
6303 fprintf (outfile
, "%*s", print_indent
, "");
6306 /* Print the information associated with a given DIE, and its children.
6307 This routine is a debugging aid only. */
6310 print_die (dw_die_ref die
, FILE *outfile
)
6316 print_spaces (outfile
);
6317 fprintf (outfile
, "DIE %4ld: %s\n",
6318 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6319 print_spaces (outfile
);
6320 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
6321 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
6323 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6325 print_spaces (outfile
);
6326 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
6328 switch (AT_class (a
))
6330 case dw_val_class_addr
:
6331 fprintf (outfile
, "address");
6333 case dw_val_class_offset
:
6334 fprintf (outfile
, "offset");
6336 case dw_val_class_loc
:
6337 fprintf (outfile
, "location descriptor");
6339 case dw_val_class_loc_list
:
6340 fprintf (outfile
, "location list -> label:%s",
6341 AT_loc_list (a
)->ll_symbol
);
6343 case dw_val_class_range_list
:
6344 fprintf (outfile
, "range list");
6346 case dw_val_class_const
:
6347 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
6349 case dw_val_class_unsigned_const
:
6350 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
6352 case dw_val_class_long_long
:
6353 fprintf (outfile
, "constant (%lu,%lu)",
6354 a
->dw_attr_val
.v
.val_long_long
.hi
,
6355 a
->dw_attr_val
.v
.val_long_long
.low
);
6357 case dw_val_class_vec
:
6358 fprintf (outfile
, "floating-point or vector constant");
6360 case dw_val_class_flag
:
6361 fprintf (outfile
, "%u", AT_flag (a
));
6363 case dw_val_class_die_ref
:
6364 if (AT_ref (a
) != NULL
)
6366 if (AT_ref (a
)->die_symbol
)
6367 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
6369 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
6372 fprintf (outfile
, "die -> <null>");
6374 case dw_val_class_lbl_id
:
6375 case dw_val_class_lineptr
:
6376 case dw_val_class_macptr
:
6377 fprintf (outfile
, "label: %s", AT_lbl (a
));
6379 case dw_val_class_str
:
6380 if (AT_string (a
) != NULL
)
6381 fprintf (outfile
, "\"%s\"", AT_string (a
));
6383 fprintf (outfile
, "<null>");
6385 case dw_val_class_file
:
6386 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
6387 AT_file (a
)->emitted_number
);
6393 fprintf (outfile
, "\n");
6396 if (die
->die_child
!= NULL
)
6399 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
6402 if (print_indent
== 0)
6403 fprintf (outfile
, "\n");
6406 /* Print the contents of the source code line number correspondence table.
6407 This routine is a debugging aid only. */
6410 print_dwarf_line_table (FILE *outfile
)
6413 dw_line_info_ref line_info
;
6415 fprintf (outfile
, "\n\nDWARF source line information\n");
6416 for (i
= 1; i
< line_info_table_in_use
; i
++)
6418 line_info
= &line_info_table
[i
];
6419 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
6420 line_info
->dw_file_num
,
6421 line_info
->dw_line_num
);
6424 fprintf (outfile
, "\n\n");
6427 /* Print the information collected for a given DIE. */
6430 debug_dwarf_die (dw_die_ref die
)
6432 print_die (die
, stderr
);
6435 /* Print all DWARF information collected for the compilation unit.
6436 This routine is a debugging aid only. */
6442 print_die (comp_unit_die
, stderr
);
6443 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
6444 print_dwarf_line_table (stderr
);
6447 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6448 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6449 DIE that marks the start of the DIEs for this include file. */
6452 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6454 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6455 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6457 new_unit
->die_sib
= old_unit
;
6461 /* Close an include-file CU and reopen the enclosing one. */
6464 pop_compile_unit (dw_die_ref old_unit
)
6466 dw_die_ref new_unit
= old_unit
->die_sib
;
6468 old_unit
->die_sib
= NULL
;
6472 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6473 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6475 /* Calculate the checksum of a location expression. */
6478 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6480 CHECKSUM (loc
->dw_loc_opc
);
6481 CHECKSUM (loc
->dw_loc_oprnd1
);
6482 CHECKSUM (loc
->dw_loc_oprnd2
);
6485 /* Calculate the checksum of an attribute. */
6488 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
6490 dw_loc_descr_ref loc
;
6493 CHECKSUM (at
->dw_attr
);
6495 /* We don't care that this was compiled with a different compiler
6496 snapshot; if the output is the same, that's what matters. */
6497 if (at
->dw_attr
== DW_AT_producer
)
6500 switch (AT_class (at
))
6502 case dw_val_class_const
:
6503 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6505 case dw_val_class_unsigned_const
:
6506 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6508 case dw_val_class_long_long
:
6509 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
6511 case dw_val_class_vec
:
6512 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
6514 case dw_val_class_flag
:
6515 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6517 case dw_val_class_str
:
6518 CHECKSUM_STRING (AT_string (at
));
6521 case dw_val_class_addr
:
6523 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6524 CHECKSUM_STRING (XSTR (r
, 0));
6527 case dw_val_class_offset
:
6528 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6531 case dw_val_class_loc
:
6532 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6533 loc_checksum (loc
, ctx
);
6536 case dw_val_class_die_ref
:
6537 die_checksum (AT_ref (at
), ctx
, mark
);
6540 case dw_val_class_fde_ref
:
6541 case dw_val_class_lbl_id
:
6542 case dw_val_class_lineptr
:
6543 case dw_val_class_macptr
:
6546 case dw_val_class_file
:
6547 CHECKSUM_STRING (AT_file (at
)->filename
);
6555 /* Calculate the checksum of a DIE. */
6558 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6564 /* To avoid infinite recursion. */
6567 CHECKSUM (die
->die_mark
);
6570 die
->die_mark
= ++(*mark
);
6572 CHECKSUM (die
->die_tag
);
6574 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6575 attr_checksum (a
, ctx
, mark
);
6577 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6581 #undef CHECKSUM_STRING
6583 /* Do the location expressions look same? */
6585 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6587 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6588 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6589 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6592 /* Do the values look the same? */
6594 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6596 dw_loc_descr_ref loc1
, loc2
;
6599 if (v1
->val_class
!= v2
->val_class
)
6602 switch (v1
->val_class
)
6604 case dw_val_class_const
:
6605 return v1
->v
.val_int
== v2
->v
.val_int
;
6606 case dw_val_class_unsigned_const
:
6607 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6608 case dw_val_class_long_long
:
6609 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6610 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6611 case dw_val_class_vec
:
6612 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6613 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6615 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6616 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6619 case dw_val_class_flag
:
6620 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6621 case dw_val_class_str
:
6622 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6624 case dw_val_class_addr
:
6625 r1
= v1
->v
.val_addr
;
6626 r2
= v2
->v
.val_addr
;
6627 if (GET_CODE (r1
) != GET_CODE (r2
))
6629 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
6630 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
6632 case dw_val_class_offset
:
6633 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6635 case dw_val_class_loc
:
6636 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6638 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6639 if (!same_loc_p (loc1
, loc2
, mark
))
6641 return !loc1
&& !loc2
;
6643 case dw_val_class_die_ref
:
6644 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6646 case dw_val_class_fde_ref
:
6647 case dw_val_class_lbl_id
:
6648 case dw_val_class_lineptr
:
6649 case dw_val_class_macptr
:
6652 case dw_val_class_file
:
6653 return v1
->v
.val_file
== v2
->v
.val_file
;
6660 /* Do the attributes look the same? */
6663 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6665 if (at1
->dw_attr
!= at2
->dw_attr
)
6668 /* We don't care that this was compiled with a different compiler
6669 snapshot; if the output is the same, that's what matters. */
6670 if (at1
->dw_attr
== DW_AT_producer
)
6673 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6676 /* Do the dies look the same? */
6679 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6685 /* To avoid infinite recursion. */
6687 return die1
->die_mark
== die2
->die_mark
;
6688 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6690 if (die1
->die_tag
!= die2
->die_tag
)
6693 if (VEC_length (dw_attr_node
, die1
->die_attr
)
6694 != VEC_length (dw_attr_node
, die2
->die_attr
))
6697 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
6698 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
6701 c1
= die1
->die_child
;
6702 c2
= die2
->die_child
;
6711 if (!same_die_p (c1
, c2
, mark
))
6715 if (c1
== die1
->die_child
)
6717 if (c2
== die2
->die_child
)
6727 /* Do the dies look the same? Wrapper around same_die_p. */
6730 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6733 int ret
= same_die_p (die1
, die2
, &mark
);
6735 unmark_all_dies (die1
);
6736 unmark_all_dies (die2
);
6741 /* The prefix to attach to symbols on DIEs in the current comdat debug
6743 static char *comdat_symbol_id
;
6745 /* The index of the current symbol within the current comdat CU. */
6746 static unsigned int comdat_symbol_number
;
6748 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6749 children, and set comdat_symbol_id accordingly. */
6752 compute_section_prefix (dw_die_ref unit_die
)
6754 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6755 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6756 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6759 unsigned char checksum
[16];
6762 /* Compute the checksum of the DIE, then append part of it as hex digits to
6763 the name filename of the unit. */
6765 md5_init_ctx (&ctx
);
6767 die_checksum (unit_die
, &ctx
, &mark
);
6768 unmark_all_dies (unit_die
);
6769 md5_finish_ctx (&ctx
, checksum
);
6771 sprintf (name
, "%s.", base
);
6772 clean_symbol_name (name
);
6774 p
= name
+ strlen (name
);
6775 for (i
= 0; i
< 4; i
++)
6777 sprintf (p
, "%.2x", checksum
[i
]);
6781 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6782 comdat_symbol_number
= 0;
6785 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6788 is_type_die (dw_die_ref die
)
6790 switch (die
->die_tag
)
6792 case DW_TAG_array_type
:
6793 case DW_TAG_class_type
:
6794 case DW_TAG_interface_type
:
6795 case DW_TAG_enumeration_type
:
6796 case DW_TAG_pointer_type
:
6797 case DW_TAG_reference_type
:
6798 case DW_TAG_string_type
:
6799 case DW_TAG_structure_type
:
6800 case DW_TAG_subroutine_type
:
6801 case DW_TAG_union_type
:
6802 case DW_TAG_ptr_to_member_type
:
6803 case DW_TAG_set_type
:
6804 case DW_TAG_subrange_type
:
6805 case DW_TAG_base_type
:
6806 case DW_TAG_const_type
:
6807 case DW_TAG_file_type
:
6808 case DW_TAG_packed_type
:
6809 case DW_TAG_volatile_type
:
6810 case DW_TAG_typedef
:
6817 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6818 Basically, we want to choose the bits that are likely to be shared between
6819 compilations (types) and leave out the bits that are specific to individual
6820 compilations (functions). */
6823 is_comdat_die (dw_die_ref c
)
6825 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6826 we do for stabs. The advantage is a greater likelihood of sharing between
6827 objects that don't include headers in the same order (and therefore would
6828 put the base types in a different comdat). jason 8/28/00 */
6830 if (c
->die_tag
== DW_TAG_base_type
)
6833 if (c
->die_tag
== DW_TAG_pointer_type
6834 || c
->die_tag
== DW_TAG_reference_type
6835 || c
->die_tag
== DW_TAG_const_type
6836 || c
->die_tag
== DW_TAG_volatile_type
)
6838 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6840 return t
? is_comdat_die (t
) : 0;
6843 return is_type_die (c
);
6846 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6847 compilation unit. */
6850 is_symbol_die (dw_die_ref c
)
6852 return (is_type_die (c
)
6853 || (get_AT (c
, DW_AT_declaration
)
6854 && !get_AT (c
, DW_AT_specification
))
6855 || c
->die_tag
== DW_TAG_namespace
);
6859 gen_internal_sym (const char *prefix
)
6863 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6864 return xstrdup (buf
);
6867 /* Assign symbols to all worthy DIEs under DIE. */
6870 assign_symbol_names (dw_die_ref die
)
6874 if (is_symbol_die (die
))
6876 if (comdat_symbol_id
)
6878 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6880 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6881 comdat_symbol_id
, comdat_symbol_number
++);
6882 die
->die_symbol
= xstrdup (p
);
6885 die
->die_symbol
= gen_internal_sym ("LDIE");
6888 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6891 struct cu_hash_table_entry
6894 unsigned min_comdat_num
, max_comdat_num
;
6895 struct cu_hash_table_entry
*next
;
6898 /* Routines to manipulate hash table of CUs. */
6900 htab_cu_hash (const void *of
)
6902 const struct cu_hash_table_entry
*const entry
=
6903 (const struct cu_hash_table_entry
*) of
;
6905 return htab_hash_string (entry
->cu
->die_symbol
);
6909 htab_cu_eq (const void *of1
, const void *of2
)
6911 const struct cu_hash_table_entry
*const entry1
=
6912 (const struct cu_hash_table_entry
*) of1
;
6913 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6915 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6919 htab_cu_del (void *what
)
6921 struct cu_hash_table_entry
*next
,
6922 *entry
= (struct cu_hash_table_entry
*) what
;
6932 /* Check whether we have already seen this CU and set up SYM_NUM
6935 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6937 struct cu_hash_table_entry dummy
;
6938 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6940 dummy
.max_comdat_num
= 0;
6942 slot
= (struct cu_hash_table_entry
**)
6943 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6947 for (; entry
; last
= entry
, entry
= entry
->next
)
6949 if (same_die_p_wrap (cu
, entry
->cu
))
6955 *sym_num
= entry
->min_comdat_num
;
6959 entry
= XCNEW (struct cu_hash_table_entry
);
6961 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6962 entry
->next
= *slot
;
6968 /* Record SYM_NUM to record of CU in HTABLE. */
6970 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6972 struct cu_hash_table_entry
**slot
, *entry
;
6974 slot
= (struct cu_hash_table_entry
**)
6975 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6979 entry
->max_comdat_num
= sym_num
;
6982 /* Traverse the DIE (which is always comp_unit_die), and set up
6983 additional compilation units for each of the include files we see
6984 bracketed by BINCL/EINCL. */
6987 break_out_includes (dw_die_ref die
)
6990 dw_die_ref unit
= NULL
;
6991 limbo_die_node
*node
, **pnode
;
6992 htab_t cu_hash_table
;
6996 dw_die_ref prev
= c
;
6998 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6999 || (unit
&& is_comdat_die (c
)))
7001 dw_die_ref next
= c
->die_sib
;
7003 /* This DIE is for a secondary CU; remove it from the main one. */
7004 remove_child_with_prev (c
, prev
);
7006 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7007 unit
= push_new_compile_unit (unit
, c
);
7008 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7009 unit
= pop_compile_unit (unit
);
7011 add_child_die (unit
, c
);
7013 if (c
== die
->die_child
)
7016 } while (c
!= die
->die_child
);
7019 /* We can only use this in debugging, since the frontend doesn't check
7020 to make sure that we leave every include file we enter. */
7024 assign_symbol_names (die
);
7025 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
7026 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7032 compute_section_prefix (node
->die
);
7033 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
7034 &comdat_symbol_number
);
7035 assign_symbol_names (node
->die
);
7037 *pnode
= node
->next
;
7040 pnode
= &node
->next
;
7041 record_comdat_symbol_number (node
->die
, cu_hash_table
,
7042 comdat_symbol_number
);
7045 htab_delete (cu_hash_table
);
7048 /* Traverse the DIE and add a sibling attribute if it may have the
7049 effect of speeding up access to siblings. To save some space,
7050 avoid generating sibling attributes for DIE's without children. */
7053 add_sibling_attributes (dw_die_ref die
)
7057 if (! die
->die_child
)
7060 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7061 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7063 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7066 /* Output all location lists for the DIE and its children. */
7069 output_location_lists (dw_die_ref die
)
7075 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7076 if (AT_class (a
) == dw_val_class_loc_list
)
7077 output_loc_list (AT_loc_list (a
));
7079 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7082 /* The format of each DIE (and its attribute value pairs) is encoded in an
7083 abbreviation table. This routine builds the abbreviation table and assigns
7084 a unique abbreviation id for each abbreviation entry. The children of each
7085 die are visited recursively. */
7088 build_abbrev_table (dw_die_ref die
)
7090 unsigned long abbrev_id
;
7091 unsigned int n_alloc
;
7096 /* Scan the DIE references, and mark as external any that refer to
7097 DIEs from other CUs (i.e. those which are not marked). */
7098 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7099 if (AT_class (a
) == dw_val_class_die_ref
7100 && AT_ref (a
)->die_mark
== 0)
7102 gcc_assert (AT_ref (a
)->die_symbol
);
7104 set_AT_ref_external (a
, 1);
7107 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7109 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7110 dw_attr_ref die_a
, abbrev_a
;
7114 if (abbrev
->die_tag
!= die
->die_tag
)
7116 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7119 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
7120 != VEC_length (dw_attr_node
, die
->die_attr
))
7123 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
7125 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
7126 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7127 || (value_format (abbrev_a
) != value_format (die_a
)))
7137 if (abbrev_id
>= abbrev_die_table_in_use
)
7139 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7141 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7142 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7145 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7146 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7147 abbrev_die_table_allocated
= n_alloc
;
7150 ++abbrev_die_table_in_use
;
7151 abbrev_die_table
[abbrev_id
] = die
;
7154 die
->die_abbrev
= abbrev_id
;
7155 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
7158 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7161 constant_size (long unsigned int value
)
7168 log
= floor_log2 (value
);
7171 log
= 1 << (floor_log2 (log
) + 1);
7176 /* Return the size of a DIE as it is represented in the
7177 .debug_info section. */
7179 static unsigned long
7180 size_of_die (dw_die_ref die
)
7182 unsigned long size
= 0;
7186 size
+= size_of_uleb128 (die
->die_abbrev
);
7187 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7189 switch (AT_class (a
))
7191 case dw_val_class_addr
:
7192 size
+= DWARF2_ADDR_SIZE
;
7194 case dw_val_class_offset
:
7195 size
+= DWARF_OFFSET_SIZE
;
7197 case dw_val_class_loc
:
7199 unsigned long lsize
= size_of_locs (AT_loc (a
));
7202 size
+= constant_size (lsize
);
7206 case dw_val_class_loc_list
:
7207 size
+= DWARF_OFFSET_SIZE
;
7209 case dw_val_class_range_list
:
7210 size
+= DWARF_OFFSET_SIZE
;
7212 case dw_val_class_const
:
7213 size
+= size_of_sleb128 (AT_int (a
));
7215 case dw_val_class_unsigned_const
:
7216 size
+= constant_size (AT_unsigned (a
));
7218 case dw_val_class_long_long
:
7219 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
7221 case dw_val_class_vec
:
7222 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
7223 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
7225 case dw_val_class_flag
:
7228 case dw_val_class_die_ref
:
7229 if (AT_ref_external (a
))
7230 size
+= DWARF2_ADDR_SIZE
;
7232 size
+= DWARF_OFFSET_SIZE
;
7234 case dw_val_class_fde_ref
:
7235 size
+= DWARF_OFFSET_SIZE
;
7237 case dw_val_class_lbl_id
:
7238 size
+= DWARF2_ADDR_SIZE
;
7240 case dw_val_class_lineptr
:
7241 case dw_val_class_macptr
:
7242 size
+= DWARF_OFFSET_SIZE
;
7244 case dw_val_class_str
:
7245 if (AT_string_form (a
) == DW_FORM_strp
)
7246 size
+= DWARF_OFFSET_SIZE
;
7248 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7250 case dw_val_class_file
:
7251 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7261 /* Size the debugging information associated with a given DIE. Visits the
7262 DIE's children recursively. Updates the global variable next_die_offset, on
7263 each time through. Uses the current value of next_die_offset to update the
7264 die_offset field in each DIE. */
7267 calc_die_sizes (dw_die_ref die
)
7271 die
->die_offset
= next_die_offset
;
7272 next_die_offset
+= size_of_die (die
);
7274 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7276 if (die
->die_child
!= NULL
)
7277 /* Count the null byte used to terminate sibling lists. */
7278 next_die_offset
+= 1;
7281 /* Set the marks for a die and its children. We do this so
7282 that we know whether or not a reference needs to use FORM_ref_addr; only
7283 DIEs in the same CU will be marked. We used to clear out the offset
7284 and use that as the flag, but ran into ordering problems. */
7287 mark_dies (dw_die_ref die
)
7291 gcc_assert (!die
->die_mark
);
7294 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7297 /* Clear the marks for a die and its children. */
7300 unmark_dies (dw_die_ref die
)
7304 gcc_assert (die
->die_mark
);
7307 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7310 /* Clear the marks for a die, its children and referred dies. */
7313 unmark_all_dies (dw_die_ref die
)
7323 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7325 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7326 if (AT_class (a
) == dw_val_class_die_ref
)
7327 unmark_all_dies (AT_ref (a
));
7330 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7331 generated for the compilation unit. */
7333 static unsigned long
7334 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
7340 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7341 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, p
); i
++)
7342 if (names
!= pubtype_table
7343 || p
->die
->die_offset
!= 0
7344 || !flag_eliminate_unused_debug_types
)
7345 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7347 size
+= DWARF_OFFSET_SIZE
;
7351 /* Return the size of the information in the .debug_aranges section. */
7353 static unsigned long
7354 size_of_aranges (void)
7358 size
= DWARF_ARANGES_HEADER_SIZE
;
7360 /* Count the address/length pair for this compilation unit. */
7361 if (text_section_used
)
7362 size
+= 2 * DWARF2_ADDR_SIZE
;
7363 if (cold_text_section_used
)
7364 size
+= 2 * DWARF2_ADDR_SIZE
;
7365 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
7367 /* Count the two zero words used to terminated the address range table. */
7368 size
+= 2 * DWARF2_ADDR_SIZE
;
7372 /* Select the encoding of an attribute value. */
7374 static enum dwarf_form
7375 value_format (dw_attr_ref a
)
7377 switch (a
->dw_attr_val
.val_class
)
7379 case dw_val_class_addr
:
7380 return DW_FORM_addr
;
7381 case dw_val_class_range_list
:
7382 case dw_val_class_offset
:
7383 case dw_val_class_loc_list
:
7384 switch (DWARF_OFFSET_SIZE
)
7387 return DW_FORM_data4
;
7389 return DW_FORM_data8
;
7393 case dw_val_class_loc
:
7394 switch (constant_size (size_of_locs (AT_loc (a
))))
7397 return DW_FORM_block1
;
7399 return DW_FORM_block2
;
7403 case dw_val_class_const
:
7404 return DW_FORM_sdata
;
7405 case dw_val_class_unsigned_const
:
7406 switch (constant_size (AT_unsigned (a
)))
7409 return DW_FORM_data1
;
7411 return DW_FORM_data2
;
7413 return DW_FORM_data4
;
7415 return DW_FORM_data8
;
7419 case dw_val_class_long_long
:
7420 return DW_FORM_block1
;
7421 case dw_val_class_vec
:
7422 return DW_FORM_block1
;
7423 case dw_val_class_flag
:
7424 return DW_FORM_flag
;
7425 case dw_val_class_die_ref
:
7426 if (AT_ref_external (a
))
7427 return DW_FORM_ref_addr
;
7430 case dw_val_class_fde_ref
:
7431 return DW_FORM_data
;
7432 case dw_val_class_lbl_id
:
7433 return DW_FORM_addr
;
7434 case dw_val_class_lineptr
:
7435 case dw_val_class_macptr
:
7436 return DW_FORM_data
;
7437 case dw_val_class_str
:
7438 return AT_string_form (a
);
7439 case dw_val_class_file
:
7440 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7443 return DW_FORM_data1
;
7445 return DW_FORM_data2
;
7447 return DW_FORM_data4
;
7457 /* Output the encoding of an attribute value. */
7460 output_value_format (dw_attr_ref a
)
7462 enum dwarf_form form
= value_format (a
);
7464 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7467 /* Output the .debug_abbrev section which defines the DIE abbreviation
7471 output_abbrev_section (void)
7473 unsigned long abbrev_id
;
7475 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7477 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7481 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7482 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7483 dwarf_tag_name (abbrev
->die_tag
));
7485 if (abbrev
->die_child
!= NULL
)
7486 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7488 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7490 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7493 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7494 dwarf_attr_name (a_attr
->dw_attr
));
7495 output_value_format (a_attr
);
7498 dw2_asm_output_data (1, 0, NULL
);
7499 dw2_asm_output_data (1, 0, NULL
);
7502 /* Terminate the table. */
7503 dw2_asm_output_data (1, 0, NULL
);
7506 /* Output a symbol we can use to refer to this DIE from another CU. */
7509 output_die_symbol (dw_die_ref die
)
7511 char *sym
= die
->die_symbol
;
7516 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7517 /* We make these global, not weak; if the target doesn't support
7518 .linkonce, it doesn't support combining the sections, so debugging
7520 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7522 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7525 /* Return a new location list, given the begin and end range, and the
7526 expression. gensym tells us whether to generate a new internal symbol for
7527 this location list node, which is done for the head of the list only. */
7529 static inline dw_loc_list_ref
7530 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7531 const char *section
, unsigned int gensym
)
7533 dw_loc_list_ref retlist
= GGC_CNEW (dw_loc_list_node
);
7535 retlist
->begin
= begin
;
7537 retlist
->expr
= expr
;
7538 retlist
->section
= section
;
7540 retlist
->ll_symbol
= gen_internal_sym ("LLST");
7545 /* Add a location description expression to a location list. */
7548 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
7549 const char *begin
, const char *end
,
7550 const char *section
)
7554 /* Find the end of the chain. */
7555 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
7558 /* Add a new location list node to the list. */
7559 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
7562 /* Output the location list given to us. */
7565 output_loc_list (dw_loc_list_ref list_head
)
7567 dw_loc_list_ref curr
= list_head
;
7569 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7571 /* Walk the location list, and output each range + expression. */
7572 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7575 /* Don't output an entry that starts and ends at the same address. */
7576 if (strcmp (curr
->begin
, curr
->end
) == 0)
7578 if (!have_multiple_function_sections
)
7580 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7581 "Location list begin address (%s)",
7582 list_head
->ll_symbol
);
7583 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7584 "Location list end address (%s)",
7585 list_head
->ll_symbol
);
7589 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7590 "Location list begin address (%s)",
7591 list_head
->ll_symbol
);
7592 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7593 "Location list end address (%s)",
7594 list_head
->ll_symbol
);
7596 size
= size_of_locs (curr
->expr
);
7598 /* Output the block length for this list of location operations. */
7599 gcc_assert (size
<= 0xffff);
7600 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7602 output_loc_sequence (curr
->expr
);
7605 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7606 "Location list terminator begin (%s)",
7607 list_head
->ll_symbol
);
7608 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7609 "Location list terminator end (%s)",
7610 list_head
->ll_symbol
);
7613 /* Output the DIE and its attributes. Called recursively to generate
7614 the definitions of each child DIE. */
7617 output_die (dw_die_ref die
)
7624 /* If someone in another CU might refer to us, set up a symbol for
7625 them to point to. */
7626 if (die
->die_symbol
)
7627 output_die_symbol (die
);
7629 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
7630 (unsigned long)die
->die_offset
,
7631 dwarf_tag_name (die
->die_tag
));
7633 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7635 const char *name
= dwarf_attr_name (a
->dw_attr
);
7637 switch (AT_class (a
))
7639 case dw_val_class_addr
:
7640 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7643 case dw_val_class_offset
:
7644 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7648 case dw_val_class_range_list
:
7650 char *p
= strchr (ranges_section_label
, '\0');
7652 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7653 a
->dw_attr_val
.v
.val_offset
);
7654 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7655 debug_ranges_section
, "%s", name
);
7660 case dw_val_class_loc
:
7661 size
= size_of_locs (AT_loc (a
));
7663 /* Output the block length for this list of location operations. */
7664 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7666 output_loc_sequence (AT_loc (a
));
7669 case dw_val_class_const
:
7670 /* ??? It would be slightly more efficient to use a scheme like is
7671 used for unsigned constants below, but gdb 4.x does not sign
7672 extend. Gdb 5.x does sign extend. */
7673 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7676 case dw_val_class_unsigned_const
:
7677 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
7678 AT_unsigned (a
), "%s", name
);
7681 case dw_val_class_long_long
:
7683 unsigned HOST_WIDE_INT first
, second
;
7685 dw2_asm_output_data (1,
7686 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7689 if (WORDS_BIG_ENDIAN
)
7691 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7692 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
7696 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
7697 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7700 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7701 first
, "long long constant");
7702 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7707 case dw_val_class_vec
:
7709 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7710 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7714 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
7715 if (elt_size
> sizeof (HOST_WIDE_INT
))
7720 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7723 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7724 "fp or vector constant word %u", i
);
7728 case dw_val_class_flag
:
7729 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7732 case dw_val_class_loc_list
:
7734 char *sym
= AT_loc_list (a
)->ll_symbol
;
7737 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7742 case dw_val_class_die_ref
:
7743 if (AT_ref_external (a
))
7745 char *sym
= AT_ref (a
)->die_symbol
;
7748 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
7753 gcc_assert (AT_ref (a
)->die_offset
);
7754 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7759 case dw_val_class_fde_ref
:
7763 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7764 a
->dw_attr_val
.v
.val_fde_index
* 2);
7765 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7770 case dw_val_class_lbl_id
:
7771 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7774 case dw_val_class_lineptr
:
7775 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7776 debug_line_section
, "%s", name
);
7779 case dw_val_class_macptr
:
7780 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7781 debug_macinfo_section
, "%s", name
);
7784 case dw_val_class_str
:
7785 if (AT_string_form (a
) == DW_FORM_strp
)
7786 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7787 a
->dw_attr_val
.v
.val_str
->label
,
7789 "%s: \"%s\"", name
, AT_string (a
));
7791 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7794 case dw_val_class_file
:
7796 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
7798 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
7799 a
->dw_attr_val
.v
.val_file
->filename
);
7808 FOR_EACH_CHILD (die
, c
, output_die (c
));
7810 /* Add null byte to terminate sibling list. */
7811 if (die
->die_child
!= NULL
)
7812 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7813 (unsigned long) die
->die_offset
);
7816 /* Output the compilation unit that appears at the beginning of the
7817 .debug_info section, and precedes the DIE descriptions. */
7820 output_compilation_unit_header (void)
7822 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7823 dw2_asm_output_data (4, 0xffffffff,
7824 "Initial length escape value indicating 64-bit DWARF extension");
7825 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7826 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7827 "Length of Compilation Unit Info");
7828 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7829 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7830 debug_abbrev_section
,
7831 "Offset Into Abbrev. Section");
7832 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7835 /* Output the compilation unit DIE and its children. */
7838 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7840 const char *secname
;
7843 /* Unless we are outputting main CU, we may throw away empty ones. */
7844 if (!output_if_empty
&& die
->die_child
== NULL
)
7847 /* Even if there are no children of this DIE, we must output the information
7848 about the compilation unit. Otherwise, on an empty translation unit, we
7849 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7850 will then complain when examining the file. First mark all the DIEs in
7851 this CU so we know which get local refs. */
7854 build_abbrev_table (die
);
7856 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7857 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7858 calc_die_sizes (die
);
7860 oldsym
= die
->die_symbol
;
7863 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
7865 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7867 die
->die_symbol
= NULL
;
7868 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
7871 switch_to_section (debug_info_section
);
7873 /* Output debugging information. */
7874 output_compilation_unit_header ();
7877 /* Leave the marks on the main CU, so we can check them in
7882 die
->die_symbol
= oldsym
;
7886 /* Return the DWARF2/3 pubname associated with a decl. */
7889 dwarf2_name (tree decl
, int scope
)
7891 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
7894 /* Add a new entry to .debug_pubnames if appropriate. */
7897 add_pubname_string (const char *str
, dw_die_ref die
)
7902 e
.name
= xstrdup (str
);
7903 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
7907 add_pubname (tree decl
, dw_die_ref die
)
7910 if (TREE_PUBLIC (decl
))
7911 add_pubname_string (dwarf2_name (decl
, 1), die
);
7914 /* Add a new entry to .debug_pubtypes if appropriate. */
7917 add_pubtype (tree decl
, dw_die_ref die
)
7922 if ((TREE_PUBLIC (decl
)
7923 || die
->die_parent
== comp_unit_die
)
7924 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
7929 if (TYPE_NAME (decl
))
7931 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
7932 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
7933 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
7934 && DECL_NAME (TYPE_NAME (decl
)))
7935 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
7937 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
7941 e
.name
= xstrdup (dwarf2_name (decl
, 1));
7943 /* If we don't have a name for the type, there's no point in adding
7945 if (e
.name
&& e
.name
[0] != '\0')
7946 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
7950 /* Output the public names table used to speed up access to externally
7951 visible names; or the public types table used to find type definitions. */
7954 output_pubnames (VEC (pubname_entry
, gc
) * names
)
7957 unsigned long pubnames_length
= size_of_pubnames (names
);
7960 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7961 dw2_asm_output_data (4, 0xffffffff,
7962 "Initial length escape value indicating 64-bit DWARF extension");
7963 if (names
== pubname_table
)
7964 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7965 "Length of Public Names Info");
7967 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7968 "Length of Public Type Names Info");
7969 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7970 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7972 "Offset of Compilation Unit Info");
7973 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7974 "Compilation Unit Length");
7976 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, pub
); i
++)
7978 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7979 if (names
== pubname_table
)
7980 gcc_assert (pub
->die
->die_mark
);
7982 if (names
!= pubtype_table
7983 || pub
->die
->die_offset
!= 0
7984 || !flag_eliminate_unused_debug_types
)
7986 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7989 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7993 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7996 /* Add a new entry to .debug_aranges if appropriate. */
7999 add_arange (tree decl
, dw_die_ref die
)
8001 if (! DECL_SECTION_NAME (decl
))
8004 if (arange_table_in_use
== arange_table_allocated
)
8006 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
8007 arange_table
= GGC_RESIZEVEC (dw_die_ref
, arange_table
,
8008 arange_table_allocated
);
8009 memset (arange_table
+ arange_table_in_use
, 0,
8010 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
8013 arange_table
[arange_table_in_use
++] = die
;
8016 /* Output the information that goes into the .debug_aranges table.
8017 Namely, define the beginning and ending address range of the
8018 text section generated for this compilation unit. */
8021 output_aranges (void)
8024 unsigned long aranges_length
= size_of_aranges ();
8026 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8027 dw2_asm_output_data (4, 0xffffffff,
8028 "Initial length escape value indicating 64-bit DWARF extension");
8029 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
8030 "Length of Address Ranges Info");
8031 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8032 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8034 "Offset of Compilation Unit Info");
8035 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
8036 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
8038 /* We need to align to twice the pointer size here. */
8039 if (DWARF_ARANGES_PAD_SIZE
)
8041 /* Pad using a 2 byte words so that padding is correct for any
8043 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
8044 2 * DWARF2_ADDR_SIZE
);
8045 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
8046 dw2_asm_output_data (2, 0, NULL
);
8049 /* It is necessary not to output these entries if the sections were
8050 not used; if the sections were not used, the length will be 0 and
8051 the address may end up as 0 if the section is discarded by ld
8052 --gc-sections, leaving an invalid (0, 0) entry that can be
8053 confused with the terminator. */
8054 if (text_section_used
)
8056 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
8057 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
8058 text_section_label
, "Length");
8060 if (cold_text_section_used
)
8062 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
8064 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
8065 cold_text_section_label
, "Length");
8068 for (i
= 0; i
< arange_table_in_use
; i
++)
8070 dw_die_ref die
= arange_table
[i
];
8072 /* We shouldn't see aranges for DIEs outside of the main CU. */
8073 gcc_assert (die
->die_mark
);
8075 if (die
->die_tag
== DW_TAG_subprogram
)
8077 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
8079 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
8080 get_AT_low_pc (die
), "Length");
8084 /* A static variable; extract the symbol from DW_AT_location.
8085 Note that this code isn't currently hit, as we only emit
8086 aranges for functions (jason 9/23/99). */
8087 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
8088 dw_loc_descr_ref loc
;
8090 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
8093 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
8095 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
8096 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
8097 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
8098 get_AT_unsigned (die
, DW_AT_byte_size
),
8103 /* Output the terminator words. */
8104 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8105 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8108 /* Add a new entry to .debug_ranges. Return the offset at which it
8112 add_ranges_num (int num
)
8114 unsigned int in_use
= ranges_table_in_use
;
8116 if (in_use
== ranges_table_allocated
)
8118 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
8119 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
8120 ranges_table_allocated
);
8121 memset (ranges_table
+ ranges_table_in_use
, 0,
8122 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
8125 ranges_table
[in_use
].num
= num
;
8126 ranges_table_in_use
= in_use
+ 1;
8128 return in_use
* 2 * DWARF2_ADDR_SIZE
;
8131 /* Add a new entry to .debug_ranges corresponding to a block, or a
8132 range terminator if BLOCK is NULL. */
8135 add_ranges (const_tree block
)
8137 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
8140 /* Add a new entry to .debug_ranges corresponding to a pair of
8144 add_ranges_by_labels (const char *begin
, const char *end
)
8146 unsigned int in_use
= ranges_by_label_in_use
;
8148 if (in_use
== ranges_by_label_allocated
)
8150 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
8151 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
8153 ranges_by_label_allocated
);
8154 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
8155 RANGES_TABLE_INCREMENT
8156 * sizeof (struct dw_ranges_by_label_struct
));
8159 ranges_by_label
[in_use
].begin
= begin
;
8160 ranges_by_label
[in_use
].end
= end
;
8161 ranges_by_label_in_use
= in_use
+ 1;
8163 return add_ranges_num (-(int)in_use
- 1);
8167 output_ranges (void)
8170 static const char *const start_fmt
= "Offset 0x%x";
8171 const char *fmt
= start_fmt
;
8173 for (i
= 0; i
< ranges_table_in_use
; i
++)
8175 int block_num
= ranges_table
[i
].num
;
8179 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8180 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
8182 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
8183 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
8185 /* If all code is in the text section, then the compilation
8186 unit base address defaults to DW_AT_low_pc, which is the
8187 base of the text section. */
8188 if (!have_multiple_function_sections
)
8190 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
8192 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8193 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
8194 text_section_label
, NULL
);
8197 /* Otherwise, the compilation unit base address is zero,
8198 which allows us to use absolute addresses, and not worry
8199 about whether the target supports cross-section
8203 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
8204 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8205 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
8211 /* Negative block_num stands for an index into ranges_by_label. */
8212 else if (block_num
< 0)
8214 int lab_idx
= - block_num
- 1;
8216 if (!have_multiple_function_sections
)
8220 /* If we ever use add_ranges_by_labels () for a single
8221 function section, all we have to do is to take out
8223 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8224 ranges_by_label
[lab_idx
].begin
,
8226 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8227 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
8228 ranges_by_label
[lab_idx
].end
,
8229 text_section_label
, NULL
);
8234 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8235 ranges_by_label
[lab_idx
].begin
,
8236 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
8237 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
8238 ranges_by_label
[lab_idx
].end
,
8244 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8245 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
8251 /* Data structure containing information about input files. */
8254 const char *path
; /* Complete file name. */
8255 const char *fname
; /* File name part. */
8256 int length
; /* Length of entire string. */
8257 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
8258 int dir_idx
; /* Index in directory table. */
8261 /* Data structure containing information about directories with source
8265 const char *path
; /* Path including directory name. */
8266 int length
; /* Path length. */
8267 int prefix
; /* Index of directory entry which is a prefix. */
8268 int count
; /* Number of files in this directory. */
8269 int dir_idx
; /* Index of directory used as base. */
8272 /* Callback function for file_info comparison. We sort by looking at
8273 the directories in the path. */
8276 file_info_cmp (const void *p1
, const void *p2
)
8278 const struct file_info
*const s1
= (const struct file_info
*) p1
;
8279 const struct file_info
*const s2
= (const struct file_info
*) p2
;
8280 const unsigned char *cp1
;
8281 const unsigned char *cp2
;
8283 /* Take care of file names without directories. We need to make sure that
8284 we return consistent values to qsort since some will get confused if
8285 we return the same value when identical operands are passed in opposite
8286 orders. So if neither has a directory, return 0 and otherwise return
8287 1 or -1 depending on which one has the directory. */
8288 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
8289 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
8291 cp1
= (const unsigned char *) s1
->path
;
8292 cp2
= (const unsigned char *) s2
->path
;
8298 /* Reached the end of the first path? If so, handle like above. */
8299 if ((cp1
== (const unsigned char *) s1
->fname
)
8300 || (cp2
== (const unsigned char *) s2
->fname
))
8301 return ((cp2
== (const unsigned char *) s2
->fname
)
8302 - (cp1
== (const unsigned char *) s1
->fname
));
8304 /* Character of current path component the same? */
8305 else if (*cp1
!= *cp2
)
8310 struct file_name_acquire_data
8312 struct file_info
*files
;
8317 /* Traversal function for the hash table. */
8320 file_name_acquire (void ** slot
, void *data
)
8322 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
8323 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
8324 struct file_info
*fi
;
8327 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
8329 if (! d
->emitted_number
)
8332 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
8334 fi
= fnad
->files
+ fnad
->used_files
++;
8336 /* Skip all leading "./". */
8338 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
8341 /* Create a new array entry. */
8343 fi
->length
= strlen (f
);
8346 /* Search for the file name part. */
8347 f
= strrchr (f
, DIR_SEPARATOR
);
8348 #if defined (DIR_SEPARATOR_2)
8350 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
8354 if (f
== NULL
|| f
< g
)
8360 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
8364 /* Output the directory table and the file name table. We try to minimize
8365 the total amount of memory needed. A heuristic is used to avoid large
8366 slowdowns with many input files. */
8369 output_file_names (void)
8371 struct file_name_acquire_data fnad
;
8373 struct file_info
*files
;
8374 struct dir_info
*dirs
;
8383 if (!last_emitted_file
)
8385 dw2_asm_output_data (1, 0, "End directory table");
8386 dw2_asm_output_data (1, 0, "End file name table");
8390 numfiles
= last_emitted_file
->emitted_number
;
8392 /* Allocate the various arrays we need. */
8393 files
= XALLOCAVEC (struct file_info
, numfiles
);
8394 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
8397 fnad
.used_files
= 0;
8398 fnad
.max_files
= numfiles
;
8399 htab_traverse (file_table
, file_name_acquire
, &fnad
);
8400 gcc_assert (fnad
.used_files
== fnad
.max_files
);
8402 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
8404 /* Find all the different directories used. */
8405 dirs
[0].path
= files
[0].path
;
8406 dirs
[0].length
= files
[0].fname
- files
[0].path
;
8407 dirs
[0].prefix
= -1;
8409 dirs
[0].dir_idx
= 0;
8410 files
[0].dir_idx
= 0;
8413 for (i
= 1; i
< numfiles
; i
++)
8414 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
8415 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
8416 dirs
[ndirs
- 1].length
) == 0)
8418 /* Same directory as last entry. */
8419 files
[i
].dir_idx
= ndirs
- 1;
8420 ++dirs
[ndirs
- 1].count
;
8426 /* This is a new directory. */
8427 dirs
[ndirs
].path
= files
[i
].path
;
8428 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
8429 dirs
[ndirs
].count
= 1;
8430 dirs
[ndirs
].dir_idx
= ndirs
;
8431 files
[i
].dir_idx
= ndirs
;
8433 /* Search for a prefix. */
8434 dirs
[ndirs
].prefix
= -1;
8435 for (j
= 0; j
< ndirs
; j
++)
8436 if (dirs
[j
].length
< dirs
[ndirs
].length
8437 && dirs
[j
].length
> 1
8438 && (dirs
[ndirs
].prefix
== -1
8439 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8440 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8441 dirs
[ndirs
].prefix
= j
;
8446 /* Now to the actual work. We have to find a subset of the directories which
8447 allow expressing the file name using references to the directory table
8448 with the least amount of characters. We do not do an exhaustive search
8449 where we would have to check out every combination of every single
8450 possible prefix. Instead we use a heuristic which provides nearly optimal
8451 results in most cases and never is much off. */
8452 saved
= XALLOCAVEC (int, ndirs
);
8453 savehere
= XALLOCAVEC (int, ndirs
);
8455 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8456 for (i
= 0; i
< ndirs
; i
++)
8461 /* We can always save some space for the current directory. But this
8462 does not mean it will be enough to justify adding the directory. */
8463 savehere
[i
] = dirs
[i
].length
;
8464 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8466 for (j
= i
+ 1; j
< ndirs
; j
++)
8469 if (saved
[j
] < dirs
[i
].length
)
8471 /* Determine whether the dirs[i] path is a prefix of the
8476 while (k
!= -1 && k
!= (int) i
)
8481 /* Yes it is. We can possibly save some memory by
8482 writing the filenames in dirs[j] relative to
8484 savehere
[j
] = dirs
[i
].length
;
8485 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8490 /* Check whether we can save enough to justify adding the dirs[i]
8492 if (total
> dirs
[i
].length
+ 1)
8494 /* It's worthwhile adding. */
8495 for (j
= i
; j
< ndirs
; j
++)
8496 if (savehere
[j
] > 0)
8498 /* Remember how much we saved for this directory so far. */
8499 saved
[j
] = savehere
[j
];
8501 /* Remember the prefix directory. */
8502 dirs
[j
].dir_idx
= i
;
8507 /* Emit the directory name table. */
8509 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8510 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8511 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
8512 "Directory Entry: 0x%x", i
+ idx_offset
);
8514 dw2_asm_output_data (1, 0, "End directory table");
8516 /* We have to emit them in the order of emitted_number since that's
8517 used in the debug info generation. To do this efficiently we
8518 generate a back-mapping of the indices first. */
8519 backmap
= XALLOCAVEC (int, numfiles
);
8520 for (i
= 0; i
< numfiles
; i
++)
8521 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8523 /* Now write all the file names. */
8524 for (i
= 0; i
< numfiles
; i
++)
8526 int file_idx
= backmap
[i
];
8527 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8529 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8530 "File Entry: 0x%x", (unsigned) i
+ 1);
8532 /* Include directory index. */
8533 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8535 /* Modification time. */
8536 dw2_asm_output_data_uleb128 (0, NULL
);
8538 /* File length in bytes. */
8539 dw2_asm_output_data_uleb128 (0, NULL
);
8542 dw2_asm_output_data (1, 0, "End file name table");
8546 /* Output the source line number correspondence information. This
8547 information goes into the .debug_line section. */
8550 output_line_info (void)
8552 char l1
[20], l2
[20], p1
[20], p2
[20];
8553 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8554 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8557 unsigned long lt_index
;
8558 unsigned long current_line
;
8561 unsigned long current_file
;
8562 unsigned long function
;
8564 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
8565 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
8566 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
8567 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
8569 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8570 dw2_asm_output_data (4, 0xffffffff,
8571 "Initial length escape value indicating 64-bit DWARF extension");
8572 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
8573 "Length of Source Line Info");
8574 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
8576 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8577 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
8578 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
8580 /* Define the architecture-dependent minimum instruction length (in
8581 bytes). In this implementation of DWARF, this field is used for
8582 information purposes only. Since GCC generates assembly language,
8583 we have no a priori knowledge of how many instruction bytes are
8584 generated for each source line, and therefore can use only the
8585 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8586 commands. Accordingly, we fix this as `1', which is "correct
8587 enough" for all architectures, and don't let the target override. */
8588 dw2_asm_output_data (1, 1,
8589 "Minimum Instruction Length");
8591 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
8592 "Default is_stmt_start flag");
8593 dw2_asm_output_data (1, DWARF_LINE_BASE
,
8594 "Line Base Value (Special Opcodes)");
8595 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
8596 "Line Range Value (Special Opcodes)");
8597 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
8598 "Special Opcode Base");
8600 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
8604 case DW_LNS_advance_pc
:
8605 case DW_LNS_advance_line
:
8606 case DW_LNS_set_file
:
8607 case DW_LNS_set_column
:
8608 case DW_LNS_fixed_advance_pc
:
8616 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
8620 /* Write out the information about the files we use. */
8621 output_file_names ();
8622 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
8624 /* We used to set the address register to the first location in the text
8625 section here, but that didn't accomplish anything since we already
8626 have a line note for the opening brace of the first function. */
8628 /* Generate the line number to PC correspondence table, encoded as
8629 a series of state machine operations. */
8633 if (cfun
&& in_cold_section_p
)
8634 strcpy (prev_line_label
, crtl
->subsections
.cold_section_label
);
8636 strcpy (prev_line_label
, text_section_label
);
8637 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
8639 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
8642 /* Disable this optimization for now; GDB wants to see two line notes
8643 at the beginning of a function so it can find the end of the
8646 /* Don't emit anything for redundant notes. Just updating the
8647 address doesn't accomplish anything, because we already assume
8648 that anything after the last address is this line. */
8649 if (line_info
->dw_line_num
== current_line
8650 && line_info
->dw_file_num
== current_file
)
8654 /* Emit debug info for the address of the current line.
8656 Unfortunately, we have little choice here currently, and must always
8657 use the most general form. GCC does not know the address delta
8658 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8659 attributes which will give an upper bound on the address range. We
8660 could perhaps use length attributes to determine when it is safe to
8661 use DW_LNS_fixed_advance_pc. */
8663 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
8666 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8667 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8668 "DW_LNS_fixed_advance_pc");
8669 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8673 /* This can handle any delta. This takes
8674 4+DWARF2_ADDR_SIZE bytes. */
8675 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8676 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8677 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8678 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8681 strcpy (prev_line_label
, line_label
);
8683 /* Emit debug info for the source file of the current line, if
8684 different from the previous line. */
8685 if (line_info
->dw_file_num
!= current_file
)
8687 current_file
= line_info
->dw_file_num
;
8688 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8689 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
8692 /* Emit debug info for the current line number, choosing the encoding
8693 that uses the least amount of space. */
8694 if (line_info
->dw_line_num
!= current_line
)
8696 line_offset
= line_info
->dw_line_num
- current_line
;
8697 line_delta
= line_offset
- DWARF_LINE_BASE
;
8698 current_line
= line_info
->dw_line_num
;
8699 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8700 /* This can handle deltas from -10 to 234, using the current
8701 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8703 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8704 "line %lu", current_line
);
8707 /* This can handle any delta. This takes at least 4 bytes,
8708 depending on the value being encoded. */
8709 dw2_asm_output_data (1, DW_LNS_advance_line
,
8710 "advance to line %lu", current_line
);
8711 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8712 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8716 /* We still need to start a new row, so output a copy insn. */
8717 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8720 /* Emit debug info for the address of the end of the function. */
8723 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8724 "DW_LNS_fixed_advance_pc");
8725 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
8729 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8730 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8731 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8732 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
8735 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8736 dw2_asm_output_data_uleb128 (1, NULL
);
8737 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8742 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
8744 dw_separate_line_info_ref line_info
8745 = &separate_line_info_table
[lt_index
];
8748 /* Don't emit anything for redundant notes. */
8749 if (line_info
->dw_line_num
== current_line
8750 && line_info
->dw_file_num
== current_file
8751 && line_info
->function
== function
)
8755 /* Emit debug info for the address of the current line. If this is
8756 a new function, or the first line of a function, then we need
8757 to handle it differently. */
8758 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
8760 if (function
!= line_info
->function
)
8762 function
= line_info
->function
;
8764 /* Set the address register to the first line in the function. */
8765 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8766 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8767 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8768 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8772 /* ??? See the DW_LNS_advance_pc comment above. */
8775 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8776 "DW_LNS_fixed_advance_pc");
8777 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8781 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8782 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8783 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8784 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8788 strcpy (prev_line_label
, line_label
);
8790 /* Emit debug info for the source file of the current line, if
8791 different from the previous line. */
8792 if (line_info
->dw_file_num
!= current_file
)
8794 current_file
= line_info
->dw_file_num
;
8795 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8796 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
8799 /* Emit debug info for the current line number, choosing the encoding
8800 that uses the least amount of space. */
8801 if (line_info
->dw_line_num
!= current_line
)
8803 line_offset
= line_info
->dw_line_num
- current_line
;
8804 line_delta
= line_offset
- DWARF_LINE_BASE
;
8805 current_line
= line_info
->dw_line_num
;
8806 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8807 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8808 "line %lu", current_line
);
8811 dw2_asm_output_data (1, DW_LNS_advance_line
,
8812 "advance to line %lu", current_line
);
8813 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8814 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8818 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8826 /* If we're done with a function, end its sequence. */
8827 if (lt_index
== separate_line_info_table_in_use
8828 || separate_line_info_table
[lt_index
].function
!= function
)
8833 /* Emit debug info for the address of the end of the function. */
8834 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
8837 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8838 "DW_LNS_fixed_advance_pc");
8839 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8843 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8844 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8845 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8846 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8849 /* Output the marker for the end of this sequence. */
8850 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8851 dw2_asm_output_data_uleb128 (1, NULL
);
8852 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8856 /* Output the marker for the end of the line number info. */
8857 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
8860 /* Given a pointer to a tree node for some base type, return a pointer to
8861 a DIE that describes the given type.
8863 This routine must only be called for GCC type nodes that correspond to
8864 Dwarf base (fundamental) types. */
8867 base_type_die (tree type
)
8869 dw_die_ref base_type_result
;
8870 enum dwarf_type encoding
;
8872 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
8875 switch (TREE_CODE (type
))
8878 if (TYPE_STRING_FLAG (type
))
8880 if (TYPE_UNSIGNED (type
))
8881 encoding
= DW_ATE_unsigned_char
;
8883 encoding
= DW_ATE_signed_char
;
8885 else if (TYPE_UNSIGNED (type
))
8886 encoding
= DW_ATE_unsigned
;
8888 encoding
= DW_ATE_signed
;
8892 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
8893 encoding
= DW_ATE_decimal_float
;
8895 encoding
= DW_ATE_float
;
8898 case FIXED_POINT_TYPE
:
8899 if (TYPE_UNSIGNED (type
))
8900 encoding
= DW_ATE_unsigned_fixed
;
8902 encoding
= DW_ATE_signed_fixed
;
8905 /* Dwarf2 doesn't know anything about complex ints, so use
8906 a user defined type for it. */
8908 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
8909 encoding
= DW_ATE_complex_float
;
8911 encoding
= DW_ATE_lo_user
;
8915 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8916 encoding
= DW_ATE_boolean
;
8920 /* No other TREE_CODEs are Dwarf fundamental types. */
8924 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8926 /* This probably indicates a bug. */
8927 if (! TYPE_NAME (type
))
8928 add_name_attribute (base_type_result
, "__unknown__");
8930 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8931 int_size_in_bytes (type
));
8932 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8934 return base_type_result
;
8937 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8938 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8941 is_base_type (tree type
)
8943 switch (TREE_CODE (type
))
8949 case FIXED_POINT_TYPE
:
8957 case QUAL_UNION_TYPE
:
8962 case REFERENCE_TYPE
:
8975 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8976 node, return the size in bits for the type if it is a constant, or else
8977 return the alignment for the type if the type's size is not constant, or
8978 else return BITS_PER_WORD if the type actually turns out to be an
8981 static inline unsigned HOST_WIDE_INT
8982 simple_type_size_in_bits (const_tree type
)
8984 if (TREE_CODE (type
) == ERROR_MARK
)
8985 return BITS_PER_WORD
;
8986 else if (TYPE_SIZE (type
) == NULL_TREE
)
8988 else if (host_integerp (TYPE_SIZE (type
), 1))
8989 return tree_low_cst (TYPE_SIZE (type
), 1);
8991 return TYPE_ALIGN (type
);
8994 /* Return true if the debug information for the given type should be
8995 emitted as a subrange type. */
8998 is_subrange_type (const_tree type
)
9000 tree subtype
= TREE_TYPE (type
);
9002 /* Subrange types are identified by the fact that they are integer
9003 types, and that they have a subtype which is either an integer type
9004 or an enumeral type. */
9006 if (TREE_CODE (type
) != INTEGER_TYPE
9007 || subtype
== NULL_TREE
)
9010 if (TREE_CODE (subtype
) != INTEGER_TYPE
9011 && TREE_CODE (subtype
) != ENUMERAL_TYPE
9012 && TREE_CODE (subtype
) != BOOLEAN_TYPE
)
9015 if (TREE_CODE (type
) == TREE_CODE (subtype
)
9016 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
9017 && TYPE_MIN_VALUE (type
) != NULL
9018 && TYPE_MIN_VALUE (subtype
) != NULL
9019 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
9020 && TYPE_MAX_VALUE (type
) != NULL
9021 && TYPE_MAX_VALUE (subtype
) != NULL
9022 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
9024 /* The type and its subtype have the same representation. If in
9025 addition the two types also have the same name, then the given
9026 type is not a subrange type, but rather a plain base type. */
9027 /* FIXME: brobecker/2004-03-22:
9028 Sizetype INTEGER_CSTs nodes are canonicalized. It should
9029 therefore be sufficient to check the TYPE_SIZE node pointers
9030 rather than checking the actual size. Unfortunately, we have
9031 found some cases, such as in the Ada "integer" type, where
9032 this is not the case. Until this problem is solved, we need to
9033 keep checking the actual size. */
9034 tree type_name
= TYPE_NAME (type
);
9035 tree subtype_name
= TYPE_NAME (subtype
);
9037 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
9038 type_name
= DECL_NAME (type_name
);
9040 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
9041 subtype_name
= DECL_NAME (subtype_name
);
9043 if (type_name
== subtype_name
)
9050 /* Given a pointer to a tree node for a subrange type, return a pointer
9051 to a DIE that describes the given type. */
9054 subrange_type_die (tree type
, dw_die_ref context_die
)
9056 dw_die_ref subrange_die
;
9057 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
9059 if (context_die
== NULL
)
9060 context_die
= comp_unit_die
;
9062 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
9064 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
9066 /* The size of the subrange type and its base type do not match,
9067 so we need to generate a size attribute for the subrange type. */
9068 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
9071 if (TYPE_MIN_VALUE (type
) != NULL
)
9072 add_bound_info (subrange_die
, DW_AT_lower_bound
,
9073 TYPE_MIN_VALUE (type
));
9074 if (TYPE_MAX_VALUE (type
) != NULL
)
9075 add_bound_info (subrange_die
, DW_AT_upper_bound
,
9076 TYPE_MAX_VALUE (type
));
9078 return subrange_die
;
9081 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
9082 entry that chains various modifiers in front of the given type. */
9085 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
9086 dw_die_ref context_die
)
9088 enum tree_code code
= TREE_CODE (type
);
9089 dw_die_ref mod_type_die
;
9090 dw_die_ref sub_die
= NULL
;
9091 tree item_type
= NULL
;
9092 tree qualified_type
;
9095 if (code
== ERROR_MARK
)
9098 /* See if we already have the appropriately qualified variant of
9101 = get_qualified_type (type
,
9102 ((is_const_type
? TYPE_QUAL_CONST
: 0)
9103 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
9105 /* If we do, then we can just use its DIE, if it exists. */
9108 mod_type_die
= lookup_type_die (qualified_type
);
9110 return mod_type_die
;
9113 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
9115 /* Handle C typedef types. */
9116 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
9118 tree dtype
= TREE_TYPE (name
);
9120 if (qualified_type
== dtype
)
9122 /* For a named type, use the typedef. */
9123 gen_type_die (qualified_type
, context_die
);
9124 return lookup_type_die (qualified_type
);
9126 else if (is_const_type
< TYPE_READONLY (dtype
)
9127 || is_volatile_type
< TYPE_VOLATILE (dtype
)
9128 || (is_const_type
<= TYPE_READONLY (dtype
)
9129 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
9130 && DECL_ORIGINAL_TYPE (name
) != type
))
9131 /* cv-unqualified version of named type. Just use the unnamed
9132 type to which it refers. */
9133 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
9134 is_const_type
, is_volatile_type
,
9136 /* Else cv-qualified version of named type; fall through. */
9141 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
9142 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
9144 else if (is_volatile_type
)
9146 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
9147 sub_die
= modified_type_die (type
, 0, 0, context_die
);
9149 else if (code
== POINTER_TYPE
)
9151 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
9152 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9153 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9154 item_type
= TREE_TYPE (type
);
9156 else if (code
== REFERENCE_TYPE
)
9158 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
9159 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
9160 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
9161 item_type
= TREE_TYPE (type
);
9163 else if (is_subrange_type (type
))
9165 mod_type_die
= subrange_type_die (type
, context_die
);
9166 item_type
= TREE_TYPE (type
);
9168 else if (is_base_type (type
))
9169 mod_type_die
= base_type_die (type
);
9172 gen_type_die (type
, context_die
);
9174 /* We have to get the type_main_variant here (and pass that to the
9175 `lookup_type_die' routine) because the ..._TYPE node we have
9176 might simply be a *copy* of some original type node (where the
9177 copy was created to help us keep track of typedef names) and
9178 that copy might have a different TYPE_UID from the original
9180 if (TREE_CODE (type
) != VECTOR_TYPE
)
9181 return lookup_type_die (type_main_variant (type
));
9183 /* Vectors have the debugging information in the type,
9184 not the main variant. */
9185 return lookup_type_die (type
);
9188 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
9189 don't output a DW_TAG_typedef, since there isn't one in the
9190 user's program; just attach a DW_AT_name to the type. */
9192 && (TREE_CODE (name
) != TYPE_DECL
9193 || (TREE_TYPE (name
) == qualified_type
&& DECL_NAME (name
))))
9195 if (TREE_CODE (name
) == TYPE_DECL
)
9196 /* Could just call add_name_and_src_coords_attributes here,
9197 but since this is a builtin type it doesn't have any
9198 useful source coordinates anyway. */
9199 name
= DECL_NAME (name
);
9200 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
9204 equate_type_number_to_die (qualified_type
, mod_type_die
);
9207 /* We must do this after the equate_type_number_to_die call, in case
9208 this is a recursive type. This ensures that the modified_type_die
9209 recursion will terminate even if the type is recursive. Recursive
9210 types are possible in Ada. */
9211 sub_die
= modified_type_die (item_type
,
9212 TYPE_READONLY (item_type
),
9213 TYPE_VOLATILE (item_type
),
9216 if (sub_die
!= NULL
)
9217 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
9219 return mod_type_die
;
9222 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
9223 an enumerated type. */
9226 type_is_enum (const_tree type
)
9228 return TREE_CODE (type
) == ENUMERAL_TYPE
;
9231 /* Return the DBX register number described by a given RTL node. */
9234 dbx_reg_number (const_rtx rtl
)
9236 unsigned regno
= REGNO (rtl
);
9238 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
9240 #ifdef LEAF_REG_REMAP
9241 if (current_function_uses_only_leaf_regs
)
9243 int leaf_reg
= LEAF_REG_REMAP (regno
);
9245 regno
= (unsigned) leaf_reg
;
9249 return DBX_REGISTER_NUMBER (regno
);
9252 /* Optionally add a DW_OP_piece term to a location description expression.
9253 DW_OP_piece is only added if the location description expression already
9254 doesn't end with DW_OP_piece. */
9257 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
9259 dw_loc_descr_ref loc
;
9261 if (*list_head
!= NULL
)
9263 /* Find the end of the chain. */
9264 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
9267 if (loc
->dw_loc_opc
!= DW_OP_piece
)
9268 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
9272 /* Return a location descriptor that designates a machine register or
9273 zero if there is none. */
9275 static dw_loc_descr_ref
9276 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9280 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
9283 regs
= targetm
.dwarf_register_span (rtl
);
9285 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
9286 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
9288 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
9291 /* Return a location descriptor that designates a machine register for
9292 a given hard register number. */
9294 static dw_loc_descr_ref
9295 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
9297 dw_loc_descr_ref reg_loc_descr
;
9299 reg_loc_descr
= new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
9301 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
9303 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9304 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9306 return reg_loc_descr
;
9309 /* Given an RTL of a register, return a location descriptor that
9310 designates a value that spans more than one register. */
9312 static dw_loc_descr_ref
9313 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
9314 enum var_init_status initialized
)
9318 dw_loc_descr_ref loc_result
= NULL
;
9321 #ifdef LEAF_REG_REMAP
9322 if (current_function_uses_only_leaf_regs
)
9324 int leaf_reg
= LEAF_REG_REMAP (reg
);
9326 reg
= (unsigned) leaf_reg
;
9329 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
9330 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
9332 /* Simple, contiguous registers. */
9333 if (regs
== NULL_RTX
)
9335 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
9342 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
9343 VAR_INIT_STATUS_INITIALIZED
);
9344 add_loc_descr (&loc_result
, t
);
9345 add_loc_descr_op_piece (&loc_result
, size
);
9351 /* Now onto stupid register sets in non contiguous locations. */
9353 gcc_assert (GET_CODE (regs
) == PARALLEL
);
9355 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9358 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
9362 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
9363 VAR_INIT_STATUS_INITIALIZED
);
9364 add_loc_descr (&loc_result
, t
);
9365 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
9366 add_loc_descr_op_piece (&loc_result
, size
);
9369 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9370 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9374 #endif /* DWARF2_DEBUGGING_INFO */
9376 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
9378 /* Return a location descriptor that designates a constant. */
9380 static dw_loc_descr_ref
9381 int_loc_descriptor (HOST_WIDE_INT i
)
9383 enum dwarf_location_atom op
;
9385 /* Pick the smallest representation of a constant, rather than just
9386 defaulting to the LEB encoding. */
9390 op
= DW_OP_lit0
+ i
;
9393 else if (i
<= 0xffff)
9395 else if (HOST_BITS_PER_WIDE_INT
== 32
9405 else if (i
>= -0x8000)
9407 else if (HOST_BITS_PER_WIDE_INT
== 32
9408 || i
>= -0x80000000)
9414 return new_loc_descr (op
, i
, 0);
9418 #ifdef DWARF2_DEBUGGING_INFO
9420 /* Return a location descriptor that designates a base+offset location. */
9422 static dw_loc_descr_ref
9423 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
9424 enum var_init_status initialized
)
9427 dw_loc_descr_ref result
;
9428 dw_fde_ref fde
= current_fde ();
9430 /* We only use "frame base" when we're sure we're talking about the
9431 post-prologue local stack frame. We do this by *not* running
9432 register elimination until this point, and recognizing the special
9433 argument pointer and soft frame pointer rtx's. */
9434 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
9436 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
9440 if (GET_CODE (elim
) == PLUS
)
9442 offset
+= INTVAL (XEXP (elim
, 1));
9443 elim
= XEXP (elim
, 0);
9445 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
9446 && (elim
== hard_frame_pointer_rtx
9447 || elim
== stack_pointer_rtx
))
9448 || elim
== (frame_pointer_needed
9449 ? hard_frame_pointer_rtx
9450 : stack_pointer_rtx
));
9452 /* If drap register is used to align stack, use frame
9453 pointer + offset to access stack variables. If stack
9454 is aligned without drap, use stack pointer + offset to
9455 access stack variables. */
9456 if (crtl
->stack_realign_tried
9457 && cfa
.reg
== HARD_FRAME_POINTER_REGNUM
9458 && reg
== frame_pointer_rtx
)
9461 = DWARF_FRAME_REGNUM (cfa
.indirect
9462 ? HARD_FRAME_POINTER_REGNUM
9463 : STACK_POINTER_REGNUM
);
9465 return new_loc_descr (DW_OP_breg0
+ base_reg
, offset
, 0);
9467 return new_loc_descr (DW_OP_bregx
, base_reg
, offset
);
9470 offset
+= frame_pointer_fb_offset
;
9471 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9475 && fde
->drap_reg
!= INVALID_REGNUM
9476 && (fde
->drap_reg
== REGNO (reg
)
9477 || fde
->vdrap_reg
== REGNO (reg
)))
9479 /* Use cfa+offset to represent the location of arguments passed
9480 on stack when drap is used to align stack. */
9481 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9484 regno
= dbx_reg_number (reg
);
9486 result
= new_loc_descr (DW_OP_breg0
+ regno
, offset
, 0);
9488 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
9490 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9491 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9496 /* Return true if this RTL expression describes a base+offset calculation. */
9499 is_based_loc (const_rtx rtl
)
9501 return (GET_CODE (rtl
) == PLUS
9502 && ((REG_P (XEXP (rtl
, 0))
9503 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
9504 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
9507 /* Return a descriptor that describes the concatenation of N locations
9508 used to form the address of a memory location. */
9510 static dw_loc_descr_ref
9511 concatn_mem_loc_descriptor (rtx concatn
, enum machine_mode mode
,
9512 enum var_init_status initialized
)
9515 dw_loc_descr_ref cc_loc_result
= NULL
;
9516 unsigned int n
= XVECLEN (concatn
, 0);
9518 for (i
= 0; i
< n
; ++i
)
9520 dw_loc_descr_ref ref
;
9521 rtx x
= XVECEXP (concatn
, 0, i
);
9523 ref
= mem_loc_descriptor (x
, mode
, VAR_INIT_STATUS_INITIALIZED
);
9527 add_loc_descr (&cc_loc_result
, ref
);
9528 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
9531 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9532 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9534 return cc_loc_result
;
9537 /* The following routine converts the RTL for a variable or parameter
9538 (resident in memory) into an equivalent Dwarf representation of a
9539 mechanism for getting the address of that same variable onto the top of a
9540 hypothetical "address evaluation" stack.
9542 When creating memory location descriptors, we are effectively transforming
9543 the RTL for a memory-resident object into its Dwarf postfix expression
9544 equivalent. This routine recursively descends an RTL tree, turning
9545 it into Dwarf postfix code as it goes.
9547 MODE is the mode of the memory reference, needed to handle some
9548 autoincrement addressing modes.
9550 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9551 location list for RTL.
9553 Return 0 if we can't represent the location. */
9555 static dw_loc_descr_ref
9556 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
9557 enum var_init_status initialized
)
9559 dw_loc_descr_ref mem_loc_result
= NULL
;
9560 enum dwarf_location_atom op
;
9562 /* Note that for a dynamically sized array, the location we will generate a
9563 description of here will be the lowest numbered location which is
9564 actually within the array. That's *not* necessarily the same as the
9565 zeroth element of the array. */
9567 rtl
= targetm
.delegitimize_address (rtl
);
9569 switch (GET_CODE (rtl
))
9574 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9575 just fall into the SUBREG code. */
9577 /* ... fall through ... */
9580 /* The case of a subreg may arise when we have a local (register)
9581 variable or a formal (register) parameter which doesn't quite fill
9582 up an entire register. For now, just assume that it is
9583 legitimate to make the Dwarf info refer to the whole register which
9584 contains the given subreg. */
9585 rtl
= XEXP (rtl
, 0);
9587 /* ... fall through ... */
9590 /* Whenever a register number forms a part of the description of the
9591 method for calculating the (dynamic) address of a memory resident
9592 object, DWARF rules require the register number be referred to as
9593 a "base register". This distinction is not based in any way upon
9594 what category of register the hardware believes the given register
9595 belongs to. This is strictly DWARF terminology we're dealing with
9596 here. Note that in cases where the location of a memory-resident
9597 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9598 OP_CONST (0)) the actual DWARF location descriptor that we generate
9599 may just be OP_BASEREG (basereg). This may look deceptively like
9600 the object in question was allocated to a register (rather than in
9601 memory) so DWARF consumers need to be aware of the subtle
9602 distinction between OP_REG and OP_BASEREG. */
9603 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
9604 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
9608 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
9609 VAR_INIT_STATUS_INITIALIZED
);
9610 if (mem_loc_result
!= 0)
9611 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
9615 rtl
= XEXP (rtl
, 1);
9617 /* ... fall through ... */
9620 /* Some ports can transform a symbol ref into a label ref, because
9621 the symbol ref is too far away and has to be dumped into a constant
9625 /* Alternatively, the symbol in the constant pool might be referenced
9626 by a different symbol. */
9627 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
9630 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
9632 if (GET_CODE (tmp
) == SYMBOL_REF
)
9635 if (CONSTANT_POOL_ADDRESS_P (tmp
))
9636 get_pool_constant_mark (tmp
, &marked
);
9641 /* If all references to this pool constant were optimized away,
9642 it was not output and thus we can't represent it.
9643 FIXME: might try to use DW_OP_const_value here, though
9644 DW_OP_piece complicates it. */
9649 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
9650 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9651 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9652 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
9656 /* Extract the PLUS expression nested inside and fall into
9658 rtl
= XEXP (rtl
, 1);
9663 /* Turn these into a PLUS expression and fall into the PLUS code
9665 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
9666 GEN_INT (GET_CODE (rtl
) == PRE_INC
9667 ? GET_MODE_UNIT_SIZE (mode
)
9668 : -GET_MODE_UNIT_SIZE (mode
)));
9670 /* ... fall through ... */
9674 if (is_based_loc (rtl
))
9675 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
9676 INTVAL (XEXP (rtl
, 1)),
9677 VAR_INIT_STATUS_INITIALIZED
);
9680 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
9681 VAR_INIT_STATUS_INITIALIZED
);
9682 if (mem_loc_result
== 0)
9685 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
9686 && INTVAL (XEXP (rtl
, 1)) >= 0)
9687 add_loc_descr (&mem_loc_result
,
9688 new_loc_descr (DW_OP_plus_uconst
,
9689 INTVAL (XEXP (rtl
, 1)), 0));
9692 add_loc_descr (&mem_loc_result
,
9693 mem_loc_descriptor (XEXP (rtl
, 1), mode
,
9694 VAR_INIT_STATUS_INITIALIZED
));
9695 add_loc_descr (&mem_loc_result
,
9696 new_loc_descr (DW_OP_plus
, 0, 0));
9701 /* If a pseudo-reg is optimized away, it is possible for it to
9702 be replaced with a MEM containing a multiply or shift. */
9721 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
9722 VAR_INIT_STATUS_INITIALIZED
);
9723 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
9724 VAR_INIT_STATUS_INITIALIZED
);
9726 if (op0
== 0 || op1
== 0)
9729 mem_loc_result
= op0
;
9730 add_loc_descr (&mem_loc_result
, op1
);
9731 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
9736 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
9740 mem_loc_result
= concatn_mem_loc_descriptor (rtl
, mode
,
9741 VAR_INIT_STATUS_INITIALIZED
);
9748 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9749 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9751 return mem_loc_result
;
9754 /* Return a descriptor that describes the concatenation of two locations.
9755 This is typically a complex variable. */
9757 static dw_loc_descr_ref
9758 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
9760 dw_loc_descr_ref cc_loc_result
= NULL
;
9761 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, VAR_INIT_STATUS_INITIALIZED
);
9762 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, VAR_INIT_STATUS_INITIALIZED
);
9764 if (x0_ref
== 0 || x1_ref
== 0)
9767 cc_loc_result
= x0_ref
;
9768 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
9770 add_loc_descr (&cc_loc_result
, x1_ref
);
9771 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
9773 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9774 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9776 return cc_loc_result
;
9779 /* Return a descriptor that describes the concatenation of N
9782 static dw_loc_descr_ref
9783 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
9786 dw_loc_descr_ref cc_loc_result
= NULL
;
9787 unsigned int n
= XVECLEN (concatn
, 0);
9789 for (i
= 0; i
< n
; ++i
)
9791 dw_loc_descr_ref ref
;
9792 rtx x
= XVECEXP (concatn
, 0, i
);
9794 ref
= loc_descriptor (x
, VAR_INIT_STATUS_INITIALIZED
);
9798 add_loc_descr (&cc_loc_result
, ref
);
9799 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
9802 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9803 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9805 return cc_loc_result
;
9808 /* Output a proper Dwarf location descriptor for a variable or parameter
9809 which is either allocated in a register or in a memory location. For a
9810 register, we just generate an OP_REG and the register number. For a
9811 memory location we provide a Dwarf postfix expression describing how to
9812 generate the (dynamic) address of the object onto the address stack.
9814 If we don't know how to describe it, return 0. */
9816 static dw_loc_descr_ref
9817 loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9819 dw_loc_descr_ref loc_result
= NULL
;
9821 switch (GET_CODE (rtl
))
9824 /* The case of a subreg may arise when we have a local (register)
9825 variable or a formal (register) parameter which doesn't quite fill
9826 up an entire register. For now, just assume that it is
9827 legitimate to make the Dwarf info refer to the whole register which
9828 contains the given subreg. */
9829 rtl
= SUBREG_REG (rtl
);
9831 /* ... fall through ... */
9834 loc_result
= reg_loc_descriptor (rtl
, initialized
);
9838 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
9843 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
9848 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
9853 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
9855 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), initialized
);
9859 rtl
= XEXP (rtl
, 1);
9864 rtvec par_elems
= XVEC (rtl
, 0);
9865 int num_elem
= GET_NUM_ELEM (par_elems
);
9866 enum machine_mode mode
;
9869 /* Create the first one, so we have something to add to. */
9870 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
9872 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
9873 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9874 for (i
= 1; i
< num_elem
; i
++)
9876 dw_loc_descr_ref temp
;
9878 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
9880 add_loc_descr (&loc_result
, temp
);
9881 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9882 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9894 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9895 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9896 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9897 top-level invocation, and we require the address of LOC; is 0 if we require
9898 the value of LOC. */
9900 static dw_loc_descr_ref
9901 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
9903 dw_loc_descr_ref ret
, ret1
;
9904 int have_address
= 0;
9905 enum dwarf_location_atom op
;
9907 /* ??? Most of the time we do not take proper care for sign/zero
9908 extending the values properly. Hopefully this won't be a real
9911 switch (TREE_CODE (loc
))
9916 case PLACEHOLDER_EXPR
:
9917 /* This case involves extracting fields from an object to determine the
9918 position of other fields. We don't try to encode this here. The
9919 only user of this is Ada, which encodes the needed information using
9920 the names of types. */
9926 case PREINCREMENT_EXPR
:
9927 case PREDECREMENT_EXPR
:
9928 case POSTINCREMENT_EXPR
:
9929 case POSTDECREMENT_EXPR
:
9930 /* There are no opcodes for these operations. */
9934 /* If we already want an address, there's nothing we can do. */
9938 /* Otherwise, process the argument and look for the address. */
9939 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
9942 if (DECL_THREAD_LOCAL_P (loc
))
9948 if (targetm
.have_tls
)
9950 /* If this is not defined, we have no way to emit the
9952 if (!targetm
.asm_out
.output_dwarf_dtprel
)
9955 /* The way DW_OP_GNU_push_tls_address is specified, we
9956 can only look up addresses of objects in the current
9958 if (DECL_EXTERNAL (loc
))
9960 first_op
= INTERNAL_DW_OP_tls_addr
;
9961 second_op
= DW_OP_GNU_push_tls_address
;
9965 if (!targetm
.emutls
.debug_form_tls_address
)
9967 loc
= emutls_decl (loc
);
9968 first_op
= DW_OP_addr
;
9969 second_op
= DW_OP_form_tls_address
;
9972 rtl
= rtl_for_decl_location (loc
);
9973 if (rtl
== NULL_RTX
)
9978 rtl
= XEXP (rtl
, 0);
9979 if (! CONSTANT_P (rtl
))
9982 ret
= new_loc_descr (first_op
, 0, 0);
9983 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9984 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9986 ret1
= new_loc_descr (second_op
, 0, 0);
9987 add_loc_descr (&ret
, ret1
);
9995 if (DECL_HAS_VALUE_EXPR_P (loc
))
9996 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
10001 case FUNCTION_DECL
:
10003 rtx rtl
= rtl_for_decl_location (loc
);
10005 if (rtl
== NULL_RTX
)
10007 else if (GET_CODE (rtl
) == CONST_INT
)
10009 HOST_WIDE_INT val
= INTVAL (rtl
);
10010 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
10011 val
&= GET_MODE_MASK (DECL_MODE (loc
));
10012 ret
= int_loc_descriptor (val
);
10014 else if (GET_CODE (rtl
) == CONST_STRING
)
10016 else if (CONSTANT_P (rtl
))
10018 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
10019 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
10020 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
10024 enum machine_mode mode
;
10026 /* Certain constructs can only be represented at top-level. */
10027 if (want_address
== 2)
10028 return loc_descriptor (rtl
, VAR_INIT_STATUS_INITIALIZED
);
10030 mode
= GET_MODE (rtl
);
10033 rtl
= XEXP (rtl
, 0);
10036 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10042 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10046 case COMPOUND_EXPR
:
10047 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
10050 case VIEW_CONVERT_EXPR
:
10053 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
10055 case COMPONENT_REF
:
10056 case BIT_FIELD_REF
:
10058 case ARRAY_RANGE_REF
:
10061 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
10062 enum machine_mode mode
;
10064 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
10066 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
10067 &unsignedp
, &volatilep
, false);
10072 ret
= loc_descriptor_from_tree_1 (obj
, 1);
10074 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
10077 if (offset
!= NULL_TREE
)
10079 /* Variable offset. */
10080 add_loc_descr (&ret
, loc_descriptor_from_tree_1 (offset
, 0));
10081 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
10084 bytepos
= bitpos
/ BITS_PER_UNIT
;
10086 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
10087 else if (bytepos
< 0)
10089 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
10090 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
10098 if (host_integerp (loc
, 0))
10099 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
10106 /* Get an RTL for this, if something has been emitted. */
10107 rtx rtl
= lookup_constant_def (loc
);
10108 enum machine_mode mode
;
10110 if (!rtl
|| !MEM_P (rtl
))
10112 mode
= GET_MODE (rtl
);
10113 rtl
= XEXP (rtl
, 0);
10114 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
10119 case TRUTH_AND_EXPR
:
10120 case TRUTH_ANDIF_EXPR
:
10125 case TRUTH_XOR_EXPR
:
10130 case TRUTH_OR_EXPR
:
10131 case TRUTH_ORIF_EXPR
:
10136 case FLOOR_DIV_EXPR
:
10137 case CEIL_DIV_EXPR
:
10138 case ROUND_DIV_EXPR
:
10139 case TRUNC_DIV_EXPR
:
10147 case FLOOR_MOD_EXPR
:
10148 case CEIL_MOD_EXPR
:
10149 case ROUND_MOD_EXPR
:
10150 case TRUNC_MOD_EXPR
:
10163 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
10166 case POINTER_PLUS_EXPR
:
10168 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
10169 && host_integerp (TREE_OPERAND (loc
, 1), 0))
10171 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10175 add_loc_descr (&ret
,
10176 new_loc_descr (DW_OP_plus_uconst
,
10177 tree_low_cst (TREE_OPERAND (loc
, 1),
10187 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10194 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10201 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10208 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
10223 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10224 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
10225 if (ret
== 0 || ret1
== 0)
10228 add_loc_descr (&ret
, ret1
);
10229 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10232 case TRUTH_NOT_EXPR
:
10246 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10250 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
10256 const enum tree_code code
=
10257 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
10259 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
10260 build2 (code
, integer_type_node
,
10261 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
10262 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
10265 /* ... fall through ... */
10269 dw_loc_descr_ref lhs
10270 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
10271 dw_loc_descr_ref rhs
10272 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
10273 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
10275 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
10276 if (ret
== 0 || lhs
== 0 || rhs
== 0)
10279 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
10280 add_loc_descr (&ret
, bra_node
);
10282 add_loc_descr (&ret
, rhs
);
10283 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
10284 add_loc_descr (&ret
, jump_node
);
10286 add_loc_descr (&ret
, lhs
);
10287 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10288 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
10290 /* ??? Need a node to point the skip at. Use a nop. */
10291 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
10292 add_loc_descr (&ret
, tmp
);
10293 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
10294 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
10298 case FIX_TRUNC_EXPR
:
10302 /* Leave front-end specific codes as simply unknown. This comes
10303 up, for instance, with the C STMT_EXPR. */
10304 if ((unsigned int) TREE_CODE (loc
)
10305 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
10308 #ifdef ENABLE_CHECKING
10309 /* Otherwise this is a generic code; we should just lists all of
10310 these explicitly. We forgot one. */
10311 gcc_unreachable ();
10313 /* In a release build, we want to degrade gracefully: better to
10314 generate incomplete debugging information than to crash. */
10319 /* Show if we can't fill the request for an address. */
10320 if (want_address
&& !have_address
)
10323 /* If we've got an address and don't want one, dereference. */
10324 if (!want_address
&& have_address
&& ret
)
10326 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
10328 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
10330 else if (size
== DWARF2_ADDR_SIZE
)
10333 op
= DW_OP_deref_size
;
10335 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
10341 static inline dw_loc_descr_ref
10342 loc_descriptor_from_tree (tree loc
)
10344 return loc_descriptor_from_tree_1 (loc
, 2);
10347 /* Given a value, round it up to the lowest multiple of `boundary'
10348 which is not less than the value itself. */
10350 static inline HOST_WIDE_INT
10351 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
10353 return (((value
+ boundary
- 1) / boundary
) * boundary
);
10356 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
10357 pointer to the declared type for the relevant field variable, or return
10358 `integer_type_node' if the given node turns out to be an
10359 ERROR_MARK node. */
10362 field_type (const_tree decl
)
10366 if (TREE_CODE (decl
) == ERROR_MARK
)
10367 return integer_type_node
;
10369 type
= DECL_BIT_FIELD_TYPE (decl
);
10370 if (type
== NULL_TREE
)
10371 type
= TREE_TYPE (decl
);
10376 /* Given a pointer to a tree node, return the alignment in bits for
10377 it, or else return BITS_PER_WORD if the node actually turns out to
10378 be an ERROR_MARK node. */
10380 static inline unsigned
10381 simple_type_align_in_bits (const_tree type
)
10383 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
10386 static inline unsigned
10387 simple_decl_align_in_bits (const_tree decl
)
10389 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
10392 /* Return the result of rounding T up to ALIGN. */
10394 static inline HOST_WIDE_INT
10395 round_up_to_align (HOST_WIDE_INT t
, unsigned int align
)
10397 /* We must be careful if T is negative because HOST_WIDE_INT can be
10398 either "above" or "below" unsigned int as per the C promotion
10399 rules, depending on the host, thus making the signedness of the
10400 direct multiplication and division unpredictable. */
10401 unsigned HOST_WIDE_INT u
= (unsigned HOST_WIDE_INT
) t
;
10407 return (HOST_WIDE_INT
) u
;
10410 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
10411 lowest addressed byte of the "containing object" for the given FIELD_DECL,
10412 or return 0 if we are unable to determine what that offset is, either
10413 because the argument turns out to be a pointer to an ERROR_MARK node, or
10414 because the offset is actually variable. (We can't handle the latter case
10417 static HOST_WIDE_INT
10418 field_byte_offset (const_tree decl
)
10420 HOST_WIDE_INT object_offset_in_bits
;
10421 HOST_WIDE_INT bitpos_int
;
10423 if (TREE_CODE (decl
) == ERROR_MARK
)
10426 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
10428 /* We cannot yet cope with fields whose positions are variable, so
10429 for now, when we see such things, we simply return 0. Someday, we may
10430 be able to handle such cases, but it will be damn difficult. */
10431 if (! host_integerp (bit_position (decl
), 0))
10434 bitpos_int
= int_bit_position (decl
);
10436 #ifdef PCC_BITFIELD_TYPE_MATTERS
10437 if (PCC_BITFIELD_TYPE_MATTERS
)
10440 tree field_size_tree
;
10441 HOST_WIDE_INT deepest_bitpos
;
10442 unsigned HOST_WIDE_INT field_size_in_bits
;
10443 unsigned int type_align_in_bits
;
10444 unsigned int decl_align_in_bits
;
10445 unsigned HOST_WIDE_INT type_size_in_bits
;
10447 type
= field_type (decl
);
10448 field_size_tree
= DECL_SIZE (decl
);
10450 /* The size could be unspecified if there was an error, or for
10451 a flexible array member. */
10452 if (! field_size_tree
)
10453 field_size_tree
= bitsize_zero_node
;
10455 /* If we don't know the size of the field, pretend it's a full word. */
10456 if (host_integerp (field_size_tree
, 1))
10457 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
10459 field_size_in_bits
= BITS_PER_WORD
;
10461 type_size_in_bits
= simple_type_size_in_bits (type
);
10462 type_align_in_bits
= simple_type_align_in_bits (type
);
10463 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
10465 /* The GCC front-end doesn't make any attempt to keep track of the
10466 starting bit offset (relative to the start of the containing
10467 structure type) of the hypothetical "containing object" for a
10468 bit-field. Thus, when computing the byte offset value for the
10469 start of the "containing object" of a bit-field, we must deduce
10470 this information on our own. This can be rather tricky to do in
10471 some cases. For example, handling the following structure type
10472 definition when compiling for an i386/i486 target (which only
10473 aligns long long's to 32-bit boundaries) can be very tricky:
10475 struct S { int field1; long long field2:31; };
10477 Fortunately, there is a simple rule-of-thumb which can be used
10478 in such cases. When compiling for an i386/i486, GCC will
10479 allocate 8 bytes for the structure shown above. It decides to
10480 do this based upon one simple rule for bit-field allocation.
10481 GCC allocates each "containing object" for each bit-field at
10482 the first (i.e. lowest addressed) legitimate alignment boundary
10483 (based upon the required minimum alignment for the declared
10484 type of the field) which it can possibly use, subject to the
10485 condition that there is still enough available space remaining
10486 in the containing object (when allocated at the selected point)
10487 to fully accommodate all of the bits of the bit-field itself.
10489 This simple rule makes it obvious why GCC allocates 8 bytes for
10490 each object of the structure type shown above. When looking
10491 for a place to allocate the "containing object" for `field2',
10492 the compiler simply tries to allocate a 64-bit "containing
10493 object" at each successive 32-bit boundary (starting at zero)
10494 until it finds a place to allocate that 64- bit field such that
10495 at least 31 contiguous (and previously unallocated) bits remain
10496 within that selected 64 bit field. (As it turns out, for the
10497 example above, the compiler finds it is OK to allocate the
10498 "containing object" 64-bit field at bit-offset zero within the
10501 Here we attempt to work backwards from the limited set of facts
10502 we're given, and we try to deduce from those facts, where GCC
10503 must have believed that the containing object started (within
10504 the structure type). The value we deduce is then used (by the
10505 callers of this routine) to generate DW_AT_location and
10506 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10507 the case of DW_AT_location, regular fields as well). */
10509 /* Figure out the bit-distance from the start of the structure to
10510 the "deepest" bit of the bit-field. */
10511 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
10513 /* This is the tricky part. Use some fancy footwork to deduce
10514 where the lowest addressed bit of the containing object must
10516 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10518 /* Round up to type_align by default. This works best for
10520 object_offset_in_bits
10521 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
10523 if (object_offset_in_bits
> bitpos_int
)
10525 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10527 /* Round up to decl_align instead. */
10528 object_offset_in_bits
10529 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
10534 object_offset_in_bits
= bitpos_int
;
10536 return object_offset_in_bits
/ BITS_PER_UNIT
;
10539 /* The following routines define various Dwarf attributes and any data
10540 associated with them. */
10542 /* Add a location description attribute value to a DIE.
10544 This emits location attributes suitable for whole variables and
10545 whole parameters. Note that the location attributes for struct fields are
10546 generated by the routine `data_member_location_attribute' below. */
10549 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10550 dw_loc_descr_ref descr
)
10553 add_AT_loc (die
, attr_kind
, descr
);
10556 /* Attach the specialized form of location attribute used for data members of
10557 struct and union types. In the special case of a FIELD_DECL node which
10558 represents a bit-field, the "offset" part of this special location
10559 descriptor must indicate the distance in bytes from the lowest-addressed
10560 byte of the containing struct or union type to the lowest-addressed byte of
10561 the "containing object" for the bit-field. (See the `field_byte_offset'
10564 For any given bit-field, the "containing object" is a hypothetical object
10565 (of some integral or enum type) within which the given bit-field lives. The
10566 type of this hypothetical "containing object" is always the same as the
10567 declared type of the individual bit-field itself (for GCC anyway... the
10568 DWARF spec doesn't actually mandate this). Note that it is the size (in
10569 bytes) of the hypothetical "containing object" which will be given in the
10570 DW_AT_byte_size attribute for this bit-field. (See the
10571 `byte_size_attribute' function below.) It is also used when calculating the
10572 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10573 function below.) */
10576 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
10578 HOST_WIDE_INT offset
;
10579 dw_loc_descr_ref loc_descr
= 0;
10581 if (TREE_CODE (decl
) == TREE_BINFO
)
10583 /* We're working on the TAG_inheritance for a base class. */
10584 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
10586 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10587 aren't at a fixed offset from all (sub)objects of the same
10588 type. We need to extract the appropriate offset from our
10589 vtable. The following dwarf expression means
10591 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10593 This is specific to the V3 ABI, of course. */
10595 dw_loc_descr_ref tmp
;
10597 /* Make a copy of the object address. */
10598 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
10599 add_loc_descr (&loc_descr
, tmp
);
10601 /* Extract the vtable address. */
10602 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
10603 add_loc_descr (&loc_descr
, tmp
);
10605 /* Calculate the address of the offset. */
10606 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
10607 gcc_assert (offset
< 0);
10609 tmp
= int_loc_descriptor (-offset
);
10610 add_loc_descr (&loc_descr
, tmp
);
10611 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
10612 add_loc_descr (&loc_descr
, tmp
);
10614 /* Extract the offset. */
10615 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
10616 add_loc_descr (&loc_descr
, tmp
);
10618 /* Add it to the object address. */
10619 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
10620 add_loc_descr (&loc_descr
, tmp
);
10623 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
10626 offset
= field_byte_offset (decl
);
10630 enum dwarf_location_atom op
;
10632 /* The DWARF2 standard says that we should assume that the structure
10633 address is already on the stack, so we can specify a structure field
10634 address by using DW_OP_plus_uconst. */
10636 #ifdef MIPS_DEBUGGING_INFO
10637 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10638 operator correctly. It works only if we leave the offset on the
10642 op
= DW_OP_plus_uconst
;
10645 loc_descr
= new_loc_descr (op
, offset
, 0);
10648 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
10651 /* Writes integer values to dw_vec_const array. */
10654 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
10658 *dest
++ = val
& 0xff;
10664 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10666 static HOST_WIDE_INT
10667 extract_int (const unsigned char *src
, unsigned int size
)
10669 HOST_WIDE_INT val
= 0;
10675 val
|= *--src
& 0xff;
10681 /* Writes floating point values to dw_vec_const array. */
10684 insert_float (const_rtx rtl
, unsigned char *array
)
10686 REAL_VALUE_TYPE rv
;
10690 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
10691 real_to_target (val
, &rv
, GET_MODE (rtl
));
10693 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10694 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
10696 insert_int (val
[i
], 4, array
);
10701 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10702 does not have a "location" either in memory or in a register. These
10703 things can arise in GNU C when a constant is passed as an actual parameter
10704 to an inlined function. They can also arise in C++ where declared
10705 constants do not necessarily get memory "homes". */
10708 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
10710 switch (GET_CODE (rtl
))
10714 HOST_WIDE_INT val
= INTVAL (rtl
);
10717 add_AT_int (die
, DW_AT_const_value
, val
);
10719 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
10724 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10725 floating-point constant. A CONST_DOUBLE is used whenever the
10726 constant requires more than one word in order to be adequately
10727 represented. We output CONST_DOUBLEs as blocks. */
10729 enum machine_mode mode
= GET_MODE (rtl
);
10731 if (SCALAR_FLOAT_MODE_P (mode
))
10733 unsigned int length
= GET_MODE_SIZE (mode
);
10734 unsigned char *array
= GGC_NEWVEC (unsigned char, length
);
10736 insert_float (rtl
, array
);
10737 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
10741 /* ??? We really should be using HOST_WIDE_INT throughout. */
10742 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
10744 add_AT_long_long (die
, DW_AT_const_value
,
10745 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
10752 enum machine_mode mode
= GET_MODE (rtl
);
10753 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
10754 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
10755 unsigned char *array
= GGC_NEWVEC (unsigned char, length
* elt_size
);
10759 switch (GET_MODE_CLASS (mode
))
10761 case MODE_VECTOR_INT
:
10762 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
10764 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
10765 HOST_WIDE_INT lo
, hi
;
10767 switch (GET_CODE (elt
))
10775 lo
= CONST_DOUBLE_LOW (elt
);
10776 hi
= CONST_DOUBLE_HIGH (elt
);
10780 gcc_unreachable ();
10783 if (elt_size
<= sizeof (HOST_WIDE_INT
))
10784 insert_int (lo
, elt_size
, p
);
10787 unsigned char *p0
= p
;
10788 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
10790 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
10791 if (WORDS_BIG_ENDIAN
)
10796 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
10797 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
10802 case MODE_VECTOR_FLOAT
:
10803 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
10805 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
10806 insert_float (elt
, p
);
10811 gcc_unreachable ();
10814 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
10819 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
10825 add_AT_addr (die
, DW_AT_const_value
, rtl
);
10826 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
10830 /* In cases where an inlined instance of an inline function is passed
10831 the address of an `auto' variable (which is local to the caller) we
10832 can get a situation where the DECL_RTL of the artificial local
10833 variable (for the inlining) which acts as a stand-in for the
10834 corresponding formal parameter (of the inline function) will look
10835 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10836 exactly a compile-time constant expression, but it isn't the address
10837 of the (artificial) local variable either. Rather, it represents the
10838 *value* which the artificial local variable always has during its
10839 lifetime. We currently have no way to represent such quasi-constant
10840 values in Dwarf, so for now we just punt and generate nothing. */
10844 /* No other kinds of rtx should be possible here. */
10845 gcc_unreachable ();
10850 /* Determine whether the evaluation of EXPR references any variables
10851 or functions which aren't otherwise used (and therefore may not be
10854 reference_to_unused (tree
* tp
, int * walk_subtrees
,
10855 void * data ATTRIBUTE_UNUSED
)
10857 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
10858 *walk_subtrees
= 0;
10860 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
10861 && ! TREE_ASM_WRITTEN (*tp
))
10863 /* ??? The C++ FE emits debug information for using decls, so
10864 putting gcc_unreachable here falls over. See PR31899. For now
10865 be conservative. */
10866 else if (!cgraph_global_info_ready
10867 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
10869 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == VAR_DECL
)
10871 struct varpool_node
*node
= varpool_node (*tp
);
10875 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == FUNCTION_DECL
10876 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
10878 struct cgraph_node
*node
= cgraph_node (*tp
);
10882 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
10888 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10889 for use in a later add_const_value_attribute call. */
10892 rtl_for_decl_init (tree init
, tree type
)
10894 rtx rtl
= NULL_RTX
;
10896 /* If a variable is initialized with a string constant without embedded
10897 zeros, build CONST_STRING. */
10898 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
10900 tree enttype
= TREE_TYPE (type
);
10901 tree domain
= TYPE_DOMAIN (type
);
10902 enum machine_mode mode
= TYPE_MODE (enttype
);
10904 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
10906 && integer_zerop (TYPE_MIN_VALUE (domain
))
10907 && compare_tree_int (TYPE_MAX_VALUE (domain
),
10908 TREE_STRING_LENGTH (init
) - 1) == 0
10909 && ((size_t) TREE_STRING_LENGTH (init
)
10910 == strlen (TREE_STRING_POINTER (init
)) + 1))
10911 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
10912 ggc_strdup (TREE_STRING_POINTER (init
)));
10914 /* Other aggregates, and complex values, could be represented using
10916 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
10918 /* Vectors only work if their mode is supported by the target.
10919 FIXME: generic vectors ought to work too. */
10920 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
10922 /* If the initializer is something that we know will expand into an
10923 immediate RTL constant, expand it now. We must be careful not to
10924 reference variables which won't be output. */
10925 else if (initializer_constant_valid_p (init
, type
)
10926 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
10928 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10930 if (TREE_CODE (type
) == VECTOR_TYPE
)
10931 switch (TREE_CODE (init
))
10936 if (TREE_CONSTANT (init
))
10938 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
10939 bool constant_p
= true;
10941 unsigned HOST_WIDE_INT ix
;
10943 /* Even when ctor is constant, it might contain non-*_CST
10944 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10945 belong into VECTOR_CST nodes. */
10946 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
10947 if (!CONSTANT_CLASS_P (value
))
10949 constant_p
= false;
10955 init
= build_vector_from_ctor (type
, elts
);
10965 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
10967 /* If expand_expr returns a MEM, it wasn't immediate. */
10968 gcc_assert (!rtl
|| !MEM_P (rtl
));
10974 /* Generate RTL for the variable DECL to represent its location. */
10977 rtl_for_decl_location (tree decl
)
10981 /* Here we have to decide where we are going to say the parameter "lives"
10982 (as far as the debugger is concerned). We only have a couple of
10983 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10985 DECL_RTL normally indicates where the parameter lives during most of the
10986 activation of the function. If optimization is enabled however, this
10987 could be either NULL or else a pseudo-reg. Both of those cases indicate
10988 that the parameter doesn't really live anywhere (as far as the code
10989 generation parts of GCC are concerned) during most of the function's
10990 activation. That will happen (for example) if the parameter is never
10991 referenced within the function.
10993 We could just generate a location descriptor here for all non-NULL
10994 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10995 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10996 where DECL_RTL is NULL or is a pseudo-reg.
10998 Note however that we can only get away with using DECL_INCOMING_RTL as
10999 a backup substitute for DECL_RTL in certain limited cases. In cases
11000 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
11001 we can be sure that the parameter was passed using the same type as it is
11002 declared to have within the function, and that its DECL_INCOMING_RTL
11003 points us to a place where a value of that type is passed.
11005 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
11006 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
11007 because in these cases DECL_INCOMING_RTL points us to a value of some
11008 type which is *different* from the type of the parameter itself. Thus,
11009 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
11010 such cases, the debugger would end up (for example) trying to fetch a
11011 `float' from a place which actually contains the first part of a
11012 `double'. That would lead to really incorrect and confusing
11013 output at debug-time.
11015 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
11016 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
11017 are a couple of exceptions however. On little-endian machines we can
11018 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
11019 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
11020 an integral type that is smaller than TREE_TYPE (decl). These cases arise
11021 when (on a little-endian machine) a non-prototyped function has a
11022 parameter declared to be of type `short' or `char'. In such cases,
11023 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
11024 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
11025 passed `int' value. If the debugger then uses that address to fetch
11026 a `short' or a `char' (on a little-endian machine) the result will be
11027 the correct data, so we allow for such exceptional cases below.
11029 Note that our goal here is to describe the place where the given formal
11030 parameter lives during most of the function's activation (i.e. between the
11031 end of the prologue and the start of the epilogue). We'll do that as best
11032 as we can. Note however that if the given formal parameter is modified
11033 sometime during the execution of the function, then a stack backtrace (at
11034 debug-time) will show the function as having been called with the *new*
11035 value rather than the value which was originally passed in. This happens
11036 rarely enough that it is not a major problem, but it *is* a problem, and
11037 I'd like to fix it.
11039 A future version of dwarf2out.c may generate two additional attributes for
11040 any given DW_TAG_formal_parameter DIE which will describe the "passed
11041 type" and the "passed location" for the given formal parameter in addition
11042 to the attributes we now generate to indicate the "declared type" and the
11043 "active location" for each parameter. This additional set of attributes
11044 could be used by debuggers for stack backtraces. Separately, note that
11045 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
11046 This happens (for example) for inlined-instances of inline function formal
11047 parameters which are never referenced. This really shouldn't be
11048 happening. All PARM_DECL nodes should get valid non-NULL
11049 DECL_INCOMING_RTL values. FIXME. */
11051 /* Use DECL_RTL as the "location" unless we find something better. */
11052 rtl
= DECL_RTL_IF_SET (decl
);
11054 /* When generating abstract instances, ignore everything except
11055 constants, symbols living in memory, and symbols living in
11056 fixed registers. */
11057 if (! reload_completed
)
11060 && (CONSTANT_P (rtl
)
11062 && CONSTANT_P (XEXP (rtl
, 0)))
11064 && TREE_CODE (decl
) == VAR_DECL
11065 && TREE_STATIC (decl
))))
11067 rtl
= targetm
.delegitimize_address (rtl
);
11072 else if (TREE_CODE (decl
) == PARM_DECL
)
11074 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
11076 tree declared_type
= TREE_TYPE (decl
);
11077 tree passed_type
= DECL_ARG_TYPE (decl
);
11078 enum machine_mode dmode
= TYPE_MODE (declared_type
);
11079 enum machine_mode pmode
= TYPE_MODE (passed_type
);
11081 /* This decl represents a formal parameter which was optimized out.
11082 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
11083 all cases where (rtl == NULL_RTX) just below. */
11084 if (dmode
== pmode
)
11085 rtl
= DECL_INCOMING_RTL (decl
);
11086 else if (SCALAR_INT_MODE_P (dmode
)
11087 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
11088 && DECL_INCOMING_RTL (decl
))
11090 rtx inc
= DECL_INCOMING_RTL (decl
);
11093 else if (MEM_P (inc
))
11095 if (BYTES_BIG_ENDIAN
)
11096 rtl
= adjust_address_nv (inc
, dmode
,
11097 GET_MODE_SIZE (pmode
)
11098 - GET_MODE_SIZE (dmode
));
11105 /* If the parm was passed in registers, but lives on the stack, then
11106 make a big endian correction if the mode of the type of the
11107 parameter is not the same as the mode of the rtl. */
11108 /* ??? This is the same series of checks that are made in dbxout.c before
11109 we reach the big endian correction code there. It isn't clear if all
11110 of these checks are necessary here, but keeping them all is the safe
11112 else if (MEM_P (rtl
)
11113 && XEXP (rtl
, 0) != const0_rtx
11114 && ! CONSTANT_P (XEXP (rtl
, 0))
11115 /* Not passed in memory. */
11116 && !MEM_P (DECL_INCOMING_RTL (decl
))
11117 /* Not passed by invisible reference. */
11118 && (!REG_P (XEXP (rtl
, 0))
11119 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
11120 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
11121 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
11122 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
11125 /* Big endian correction check. */
11126 && BYTES_BIG_ENDIAN
11127 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
11128 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
11131 int offset
= (UNITS_PER_WORD
11132 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
11134 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11135 plus_constant (XEXP (rtl
, 0), offset
));
11138 else if (TREE_CODE (decl
) == VAR_DECL
11141 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
11142 && BYTES_BIG_ENDIAN
)
11144 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
11145 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
11147 /* If a variable is declared "register" yet is smaller than
11148 a register, then if we store the variable to memory, it
11149 looks like we're storing a register-sized value, when in
11150 fact we are not. We need to adjust the offset of the
11151 storage location to reflect the actual value's bytes,
11152 else gdb will not be able to display it. */
11154 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
11155 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
11158 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
11159 and will have been substituted directly into all expressions that use it.
11160 C does not have such a concept, but C++ and other languages do. */
11161 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
11162 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
11165 rtl
= targetm
.delegitimize_address (rtl
);
11167 /* If we don't look past the constant pool, we risk emitting a
11168 reference to a constant pool entry that isn't referenced from
11169 code, and thus is not emitted. */
11171 rtl
= avoid_constant_pool_reference (rtl
);
11176 /* We need to figure out what section we should use as the base for the
11177 address ranges where a given location is valid.
11178 1. If this particular DECL has a section associated with it, use that.
11179 2. If this function has a section associated with it, use that.
11180 3. Otherwise, use the text section.
11181 XXX: If you split a variable across multiple sections, we won't notice. */
11183 static const char *
11184 secname_for_decl (const_tree decl
)
11186 const char *secname
;
11188 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
11190 tree sectree
= DECL_SECTION_NAME (decl
);
11191 secname
= TREE_STRING_POINTER (sectree
);
11193 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
11195 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
11196 secname
= TREE_STRING_POINTER (sectree
);
11198 else if (cfun
&& in_cold_section_p
)
11199 secname
= crtl
->subsections
.cold_section_label
;
11201 secname
= text_section_label
;
11206 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_RTX is returned.
11207 If so, the rtx for the SYMBOL_REF for the COMMON block is returned, and the
11208 value is the offset into the common block for the symbol. */
11211 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
11213 tree val_expr
, cvar
;
11214 enum machine_mode mode
;
11215 HOST_WIDE_INT bitsize
, bitpos
;
11217 int volatilep
= 0, unsignedp
= 0;
11219 /* If the decl isn't a VAR_DECL, or if it isn't public or static, or if
11220 it does not have a value (the offset into the common area), or if it
11221 is thread local (as opposed to global) then it isn't common, and shouldn't
11222 be handled as such. */
11223 if (TREE_CODE (decl
) != VAR_DECL
11224 || !TREE_PUBLIC (decl
)
11225 || !TREE_STATIC (decl
)
11226 || !DECL_HAS_VALUE_EXPR_P (decl
)
11230 val_expr
= DECL_VALUE_EXPR (decl
);
11231 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
11234 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
11235 &mode
, &unsignedp
, &volatilep
, true);
11237 if (cvar
== NULL_TREE
11238 || TREE_CODE (cvar
) != VAR_DECL
11239 || DECL_ARTIFICIAL (cvar
)
11240 || !TREE_PUBLIC (cvar
))
11244 if (offset
!= NULL
)
11246 if (!host_integerp (offset
, 0))
11248 *value
= tree_low_cst (offset
, 0);
11251 *value
+= bitpos
/ BITS_PER_UNIT
;
11257 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
11258 data attribute for a variable or a parameter. We generate the
11259 DW_AT_const_value attribute only in those cases where the given variable
11260 or parameter does not have a true "location" either in memory or in a
11261 register. This can happen (for example) when a constant is passed as an
11262 actual argument in a call to an inline function. (It's possible that
11263 these things can crop up in other ways also.) Note that one type of
11264 constant value which can be passed into an inlined function is a constant
11265 pointer. This can happen for example if an actual argument in an inlined
11266 function call evaluates to a compile-time constant address. */
11269 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
11270 enum dwarf_attribute attr
)
11273 dw_loc_descr_ref descr
;
11274 var_loc_list
*loc_list
;
11275 struct var_loc_node
*node
;
11276 if (TREE_CODE (decl
) == ERROR_MARK
)
11279 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
11280 || TREE_CODE (decl
) == RESULT_DECL
);
11282 /* See if we possibly have multiple locations for this variable. */
11283 loc_list
= lookup_decl_loc (decl
);
11285 /* If it truly has multiple locations, the first and last node will
11287 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
11289 const char *endname
, *secname
;
11290 dw_loc_list_ref list
;
11292 enum var_init_status initialized
;
11294 /* Now that we know what section we are using for a base,
11295 actually construct the list of locations.
11296 The first location information is what is passed to the
11297 function that creates the location list, and the remaining
11298 locations just get added on to that list.
11299 Note that we only know the start address for a location
11300 (IE location changes), so to build the range, we use
11301 the range [current location start, next location start].
11302 This means we have to special case the last node, and generate
11303 a range of [last location start, end of function label]. */
11305 node
= loc_list
->first
;
11306 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11307 secname
= secname_for_decl (decl
);
11309 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
))
11310 initialized
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11312 initialized
= VAR_INIT_STATUS_INITIALIZED
;
11314 list
= new_loc_list (loc_descriptor (varloc
, initialized
),
11315 node
->label
, node
->next
->label
, secname
, 1);
11318 for (; node
->next
; node
= node
->next
)
11319 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
11321 /* The variable has a location between NODE->LABEL and
11322 NODE->NEXT->LABEL. */
11323 enum var_init_status initialized
=
11324 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11325 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11326 add_loc_descr_to_loc_list (&list
,
11327 loc_descriptor (varloc
, initialized
),
11328 node
->label
, node
->next
->label
, secname
);
11331 /* If the variable has a location at the last label
11332 it keeps its location until the end of function. */
11333 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
11335 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11336 enum var_init_status initialized
=
11337 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11339 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
11340 if (!current_function_decl
)
11341 endname
= text_end_label
;
11344 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11345 current_function_funcdef_no
);
11346 endname
= ggc_strdup (label_id
);
11348 add_loc_descr_to_loc_list (&list
,
11349 loc_descriptor (varloc
, initialized
),
11350 node
->label
, endname
, secname
);
11353 /* Finally, add the location list to the DIE, and we are done. */
11354 add_AT_loc_list (die
, attr
, list
);
11358 /* Try to get some constant RTL for this decl, and use that as the value of
11361 rtl
= rtl_for_decl_location (decl
);
11362 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
11364 add_const_value_attribute (die
, rtl
);
11368 /* If we have tried to generate the location otherwise, and it
11369 didn't work out (we wouldn't be here if we did), and we have a one entry
11370 location list, try generating a location from that. */
11371 if (loc_list
&& loc_list
->first
)
11373 enum var_init_status status
;
11374 node
= loc_list
->first
;
11375 status
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
11376 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
), status
);
11379 add_AT_location_description (die
, attr
, descr
);
11384 /* We couldn't get any rtl, so try directly generating the location
11385 description from the tree. */
11386 descr
= loc_descriptor_from_tree (decl
);
11389 add_AT_location_description (die
, attr
, descr
);
11392 /* None of that worked, so it must not really have a location;
11393 try adding a constant value attribute from the DECL_INITIAL. */
11394 tree_add_const_value_attribute (die
, decl
);
11397 /* If we don't have a copy of this variable in memory for some reason (such
11398 as a C++ member constant that doesn't have an out-of-line definition),
11399 we should tell the debugger about the constant value. */
11402 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
11404 tree init
= DECL_INITIAL (decl
);
11405 tree type
= TREE_TYPE (decl
);
11408 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
11413 rtl
= rtl_for_decl_init (init
, type
);
11415 add_const_value_attribute (var_die
, rtl
);
11418 /* Convert the CFI instructions for the current function into a
11419 location list. This is used for DW_AT_frame_base when we targeting
11420 a dwarf2 consumer that does not support the dwarf3
11421 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
11424 static dw_loc_list_ref
11425 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
11428 dw_loc_list_ref list
, *list_tail
;
11430 dw_cfa_location last_cfa
, next_cfa
;
11431 const char *start_label
, *last_label
, *section
;
11433 fde
= current_fde ();
11434 gcc_assert (fde
!= NULL
);
11436 section
= secname_for_decl (current_function_decl
);
11440 next_cfa
.reg
= INVALID_REGNUM
;
11441 next_cfa
.offset
= 0;
11442 next_cfa
.indirect
= 0;
11443 next_cfa
.base_offset
= 0;
11445 start_label
= fde
->dw_fde_begin
;
11447 /* ??? Bald assumption that the CIE opcode list does not contain
11448 advance opcodes. */
11449 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
11450 lookup_cfa_1 (cfi
, &next_cfa
);
11452 last_cfa
= next_cfa
;
11453 last_label
= start_label
;
11455 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
11456 switch (cfi
->dw_cfi_opc
)
11458 case DW_CFA_set_loc
:
11459 case DW_CFA_advance_loc1
:
11460 case DW_CFA_advance_loc2
:
11461 case DW_CFA_advance_loc4
:
11462 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
11464 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
11465 start_label
, last_label
, section
,
11468 list_tail
= &(*list_tail
)->dw_loc_next
;
11469 last_cfa
= next_cfa
;
11470 start_label
= last_label
;
11472 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
11475 case DW_CFA_advance_loc
:
11476 /* The encoding is complex enough that we should never emit this. */
11477 case DW_CFA_remember_state
:
11478 case DW_CFA_restore_state
:
11479 /* We don't handle these two in this function. It would be possible
11480 if it were to be required. */
11481 gcc_unreachable ();
11484 lookup_cfa_1 (cfi
, &next_cfa
);
11488 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
11490 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
11491 start_label
, last_label
, section
,
11493 list_tail
= &(*list_tail
)->dw_loc_next
;
11494 start_label
= last_label
;
11496 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
11497 start_label
, fde
->dw_fde_end
, section
,
11503 /* Compute a displacement from the "steady-state frame pointer" to the
11504 frame base (often the same as the CFA), and store it in
11505 frame_pointer_fb_offset. OFFSET is added to the displacement
11506 before the latter is negated. */
11509 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
11513 #ifdef FRAME_POINTER_CFA_OFFSET
11514 reg
= frame_pointer_rtx
;
11515 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
11517 reg
= arg_pointer_rtx
;
11518 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
11521 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
11522 if (GET_CODE (elim
) == PLUS
)
11524 offset
+= INTVAL (XEXP (elim
, 1));
11525 elim
= XEXP (elim
, 0);
11528 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11529 && (elim
== hard_frame_pointer_rtx
11530 || elim
== stack_pointer_rtx
))
11531 || elim
== (frame_pointer_needed
11532 ? hard_frame_pointer_rtx
11533 : stack_pointer_rtx
));
11535 frame_pointer_fb_offset
= -offset
;
11538 /* Generate a DW_AT_name attribute given some string value to be included as
11539 the value of the attribute. */
11542 add_name_attribute (dw_die_ref die
, const char *name_string
)
11544 if (name_string
!= NULL
&& *name_string
!= 0)
11546 if (demangle_name_func
)
11547 name_string
= (*demangle_name_func
) (name_string
);
11549 add_AT_string (die
, DW_AT_name
, name_string
);
11553 /* Generate a DW_AT_comp_dir attribute for DIE. */
11556 add_comp_dir_attribute (dw_die_ref die
)
11558 const char *wd
= get_src_pwd ();
11560 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
11563 /* Given a tree node describing an array bound (either lower or upper) output
11564 a representation for that bound. */
11567 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
11569 switch (TREE_CODE (bound
))
11574 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11576 if (! host_integerp (bound
, 0)
11577 || (bound_attr
== DW_AT_lower_bound
11578 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
11579 || (is_fortran () && integer_onep (bound
)))))
11580 /* Use the default. */
11583 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
11587 case VIEW_CONVERT_EXPR
:
11588 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
11598 dw_die_ref decl_die
= lookup_decl_die (bound
);
11600 /* ??? Can this happen, or should the variable have been bound
11601 first? Probably it can, since I imagine that we try to create
11602 the types of parameters in the order in which they exist in
11603 the list, and won't have created a forward reference to a
11604 later parameter. */
11605 if (decl_die
!= NULL
)
11606 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
11612 /* Otherwise try to create a stack operation procedure to
11613 evaluate the value of the array bound. */
11615 dw_die_ref ctx
, decl_die
;
11616 dw_loc_descr_ref loc
;
11618 loc
= loc_descriptor_from_tree (bound
);
11622 if (current_function_decl
== 0)
11623 ctx
= comp_unit_die
;
11625 ctx
= lookup_decl_die (current_function_decl
);
11627 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
11628 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11629 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
11630 add_AT_loc (decl_die
, DW_AT_location
, loc
);
11632 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
11638 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
11639 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
11640 Note that the block of subscript information for an array type also
11641 includes information about the element type of the given array type. */
11644 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
11646 unsigned dimension_number
;
11648 dw_die_ref subrange_die
;
11650 for (dimension_number
= 0;
11651 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
11652 type
= TREE_TYPE (type
), dimension_number
++)
11654 tree domain
= TYPE_DOMAIN (type
);
11656 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11657 and (in GNU C only) variable bounds. Handle all three forms
11659 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
11662 /* We have an array type with specified bounds. */
11663 lower
= TYPE_MIN_VALUE (domain
);
11664 upper
= TYPE_MAX_VALUE (domain
);
11666 /* Define the index type. */
11667 if (TREE_TYPE (domain
))
11669 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11670 TREE_TYPE field. We can't emit debug info for this
11671 because it is an unnamed integral type. */
11672 if (TREE_CODE (domain
) == INTEGER_TYPE
11673 && TYPE_NAME (domain
) == NULL_TREE
11674 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
11675 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
11678 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
11682 /* ??? If upper is NULL, the array has unspecified length,
11683 but it does have a lower bound. This happens with Fortran
11685 Since the debugger is definitely going to need to know N
11686 to produce useful results, go ahead and output the lower
11687 bound solo, and hope the debugger can cope. */
11689 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
11691 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
11694 /* Otherwise we have an array type with an unspecified length. The
11695 DWARF-2 spec does not say how to handle this; let's just leave out the
11701 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
11705 switch (TREE_CODE (tree_node
))
11710 case ENUMERAL_TYPE
:
11713 case QUAL_UNION_TYPE
:
11714 size
= int_size_in_bytes (tree_node
);
11717 /* For a data member of a struct or union, the DW_AT_byte_size is
11718 generally given as the number of bytes normally allocated for an
11719 object of the *declared* type of the member itself. This is true
11720 even for bit-fields. */
11721 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
11724 gcc_unreachable ();
11727 /* Note that `size' might be -1 when we get to this point. If it is, that
11728 indicates that the byte size of the entity in question is variable. We
11729 have no good way of expressing this fact in Dwarf at the present time,
11730 so just let the -1 pass on through. */
11731 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
11734 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11735 which specifies the distance in bits from the highest order bit of the
11736 "containing object" for the bit-field to the highest order bit of the
11739 For any given bit-field, the "containing object" is a hypothetical object
11740 (of some integral or enum type) within which the given bit-field lives. The
11741 type of this hypothetical "containing object" is always the same as the
11742 declared type of the individual bit-field itself. The determination of the
11743 exact location of the "containing object" for a bit-field is rather
11744 complicated. It's handled by the `field_byte_offset' function (above).
11746 Note that it is the size (in bytes) of the hypothetical "containing object"
11747 which will be given in the DW_AT_byte_size attribute for this bit-field.
11748 (See `byte_size_attribute' above). */
11751 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
11753 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
11754 tree type
= DECL_BIT_FIELD_TYPE (decl
);
11755 HOST_WIDE_INT bitpos_int
;
11756 HOST_WIDE_INT highest_order_object_bit_offset
;
11757 HOST_WIDE_INT highest_order_field_bit_offset
;
11758 HOST_WIDE_INT
unsigned bit_offset
;
11760 /* Must be a field and a bit field. */
11761 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
11763 /* We can't yet handle bit-fields whose offsets are variable, so if we
11764 encounter such things, just return without generating any attribute
11765 whatsoever. Likewise for variable or too large size. */
11766 if (! host_integerp (bit_position (decl
), 0)
11767 || ! host_integerp (DECL_SIZE (decl
), 1))
11770 bitpos_int
= int_bit_position (decl
);
11772 /* Note that the bit offset is always the distance (in bits) from the
11773 highest-order bit of the "containing object" to the highest-order bit of
11774 the bit-field itself. Since the "high-order end" of any object or field
11775 is different on big-endian and little-endian machines, the computation
11776 below must take account of these differences. */
11777 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
11778 highest_order_field_bit_offset
= bitpos_int
;
11780 if (! BYTES_BIG_ENDIAN
)
11782 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
11783 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
11787 = (! BYTES_BIG_ENDIAN
11788 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
11789 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
11791 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
11794 /* For a FIELD_DECL node which represents a bit field, output an attribute
11795 which specifies the length in bits of the given field. */
11798 add_bit_size_attribute (dw_die_ref die
, tree decl
)
11800 /* Must be a field and a bit field. */
11801 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
11802 && DECL_BIT_FIELD_TYPE (decl
));
11804 if (host_integerp (DECL_SIZE (decl
), 1))
11805 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
11808 /* If the compiled language is ANSI C, then add a 'prototyped'
11809 attribute, if arg types are given for the parameters of a function. */
11812 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
11814 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
11815 && TYPE_ARG_TYPES (func_type
) != NULL
)
11816 add_AT_flag (die
, DW_AT_prototyped
, 1);
11819 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11820 by looking in either the type declaration or object declaration
11824 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
11826 dw_die_ref origin_die
= NULL
;
11828 if (TREE_CODE (origin
) != FUNCTION_DECL
)
11830 /* We may have gotten separated from the block for the inlined
11831 function, if we're in an exception handler or some such; make
11832 sure that the abstract function has been written out.
11834 Doing this for nested functions is wrong, however; functions are
11835 distinct units, and our context might not even be inline. */
11839 fn
= TYPE_STUB_DECL (fn
);
11841 fn
= decl_function_context (fn
);
11843 dwarf2out_abstract_function (fn
);
11846 if (DECL_P (origin
))
11847 origin_die
= lookup_decl_die (origin
);
11848 else if (TYPE_P (origin
))
11849 origin_die
= lookup_type_die (origin
);
11851 /* XXX: Functions that are never lowered don't always have correct block
11852 trees (in the case of java, they simply have no block tree, in some other
11853 languages). For these functions, there is nothing we can really do to
11854 output correct debug info for inlined functions in all cases. Rather
11855 than die, we'll just produce deficient debug info now, in that we will
11856 have variables without a proper abstract origin. In the future, when all
11857 functions are lowered, we should re-add a gcc_assert (origin_die)
11861 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
11864 /* We do not currently support the pure_virtual attribute. */
11867 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
11869 if (DECL_VINDEX (func_decl
))
11871 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11873 if (host_integerp (DECL_VINDEX (func_decl
), 0))
11874 add_AT_loc (die
, DW_AT_vtable_elem_location
,
11875 new_loc_descr (DW_OP_constu
,
11876 tree_low_cst (DECL_VINDEX (func_decl
), 0),
11879 /* GNU extension: Record what type this method came from originally. */
11880 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11881 add_AT_die_ref (die
, DW_AT_containing_type
,
11882 lookup_type_die (DECL_CONTEXT (func_decl
)));
11886 /* Add source coordinate attributes for the given decl. */
11889 add_src_coords_attributes (dw_die_ref die
, tree decl
)
11891 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11893 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
11894 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
11897 /* Add a DW_AT_name attribute and source coordinate attribute for the
11898 given decl, but only if it actually has a name. */
11901 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
11905 decl_name
= DECL_NAME (decl
);
11906 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
11908 add_name_attribute (die
, dwarf2_name (decl
, 0));
11909 if (! DECL_ARTIFICIAL (decl
))
11910 add_src_coords_attributes (die
, decl
);
11912 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
11913 && TREE_PUBLIC (decl
)
11914 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
11915 && !DECL_ABSTRACT (decl
)
11916 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
11918 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
11919 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
11922 #ifdef VMS_DEBUGGING_INFO
11923 /* Get the function's name, as described by its RTL. This may be different
11924 from the DECL_NAME name used in the source file. */
11925 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
11927 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
11928 XEXP (DECL_RTL (decl
), 0));
11929 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
11934 /* Push a new declaration scope. */
11937 push_decl_scope (tree scope
)
11939 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
11942 /* Pop a declaration scope. */
11945 pop_decl_scope (void)
11947 VEC_pop (tree
, decl_scope_table
);
11950 /* Return the DIE for the scope that immediately contains this type.
11951 Non-named types get global scope. Named types nested in other
11952 types get their containing scope if it's open, or global scope
11953 otherwise. All other types (i.e. function-local named types) get
11954 the current active scope. */
11957 scope_die_for (tree t
, dw_die_ref context_die
)
11959 dw_die_ref scope_die
= NULL
;
11960 tree containing_scope
;
11963 /* Non-types always go in the current scope. */
11964 gcc_assert (TYPE_P (t
));
11966 containing_scope
= TYPE_CONTEXT (t
);
11968 /* Use the containing namespace if it was passed in (for a declaration). */
11969 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
11971 if (context_die
== lookup_decl_die (containing_scope
))
11974 containing_scope
= NULL_TREE
;
11977 /* Ignore function type "scopes" from the C frontend. They mean that
11978 a tagged type is local to a parmlist of a function declarator, but
11979 that isn't useful to DWARF. */
11980 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
11981 containing_scope
= NULL_TREE
;
11983 if (containing_scope
== NULL_TREE
)
11984 scope_die
= comp_unit_die
;
11985 else if (TYPE_P (containing_scope
))
11987 /* For types, we can just look up the appropriate DIE. But
11988 first we check to see if we're in the middle of emitting it
11989 so we know where the new DIE should go. */
11990 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
11991 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
11996 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
11997 || TREE_ASM_WRITTEN (containing_scope
));
11999 /* If none of the current dies are suitable, we get file scope. */
12000 scope_die
= comp_unit_die
;
12003 scope_die
= lookup_type_die (containing_scope
);
12006 scope_die
= context_die
;
12011 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
12014 local_scope_p (dw_die_ref context_die
)
12016 for (; context_die
; context_die
= context_die
->die_parent
)
12017 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
12018 || context_die
->die_tag
== DW_TAG_subprogram
)
12024 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
12025 whether or not to treat a DIE in this context as a declaration. */
12028 class_or_namespace_scope_p (dw_die_ref context_die
)
12030 return (context_die
12031 && (context_die
->die_tag
== DW_TAG_structure_type
12032 || context_die
->die_tag
== DW_TAG_class_type
12033 || context_die
->die_tag
== DW_TAG_interface_type
12034 || context_die
->die_tag
== DW_TAG_union_type
12035 || context_die
->die_tag
== DW_TAG_namespace
));
12038 /* Many forms of DIEs require a "type description" attribute. This
12039 routine locates the proper "type descriptor" die for the type given
12040 by 'type', and adds a DW_AT_type attribute below the given die. */
12043 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
12044 int decl_volatile
, dw_die_ref context_die
)
12046 enum tree_code code
= TREE_CODE (type
);
12047 dw_die_ref type_die
= NULL
;
12049 /* ??? If this type is an unnamed subrange type of an integral, floating-point
12050 or fixed-point type, use the inner type. This is because we have no
12051 support for unnamed types in base_type_die. This can happen if this is
12052 an Ada subrange type. Correct solution is emit a subrange type die. */
12053 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
12054 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
12055 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
12057 if (code
== ERROR_MARK
12058 /* Handle a special case. For functions whose return type is void, we
12059 generate *no* type attribute. (Note that no object may have type
12060 `void', so this only applies to function return types). */
12061 || code
== VOID_TYPE
)
12064 type_die
= modified_type_die (type
,
12065 decl_const
|| TYPE_READONLY (type
),
12066 decl_volatile
|| TYPE_VOLATILE (type
),
12069 if (type_die
!= NULL
)
12070 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
12073 /* Given an object die, add the calling convention attribute for the
12074 function call type. */
12076 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
12078 enum dwarf_calling_convention value
= DW_CC_normal
;
12080 value
= targetm
.dwarf_calling_convention (TREE_TYPE (decl
));
12082 /* DWARF doesn't provide a way to identify a program's source-level
12083 entry point. DW_AT_calling_convention attributes are only meant
12084 to describe functions' calling conventions. However, lacking a
12085 better way to signal the Fortran main program, we use this for the
12086 time being, following existing custom. */
12088 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
12089 value
= DW_CC_program
;
12091 /* Only add the attribute if the backend requests it, and
12092 is not DW_CC_normal. */
12093 if (value
&& (value
!= DW_CC_normal
))
12094 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
12097 /* Given a tree pointer to a struct, class, union, or enum type node, return
12098 a pointer to the (string) tag name for the given type, or zero if the type
12099 was declared without a tag. */
12101 static const char *
12102 type_tag (const_tree type
)
12104 const char *name
= 0;
12106 if (TYPE_NAME (type
) != 0)
12110 /* Find the IDENTIFIER_NODE for the type name. */
12111 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
12112 t
= TYPE_NAME (type
);
12114 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
12115 a TYPE_DECL node, regardless of whether or not a `typedef' was
12117 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12118 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
12120 /* We want to be extra verbose. Don't call dwarf_name if
12121 DECL_NAME isn't set. The default hook for decl_printable_name
12122 doesn't like that, and in this context it's correct to return
12123 0, instead of "<anonymous>" or the like. */
12124 if (DECL_NAME (TYPE_NAME (type
)))
12125 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
12128 /* Now get the name as a string, or invent one. */
12129 if (!name
&& t
!= 0)
12130 name
= IDENTIFIER_POINTER (t
);
12133 return (name
== 0 || *name
== '\0') ? 0 : name
;
12136 /* Return the type associated with a data member, make a special check
12137 for bit field types. */
12140 member_declared_type (const_tree member
)
12142 return (DECL_BIT_FIELD_TYPE (member
)
12143 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
12146 /* Get the decl's label, as described by its RTL. This may be different
12147 from the DECL_NAME name used in the source file. */
12150 static const char *
12151 decl_start_label (tree decl
)
12154 const char *fnname
;
12156 x
= DECL_RTL (decl
);
12157 gcc_assert (MEM_P (x
));
12160 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
12162 fnname
= XSTR (x
, 0);
12167 /* These routines generate the internal representation of the DIE's for
12168 the compilation unit. Debugging information is collected by walking
12169 the declaration trees passed in from dwarf2out_decl(). */
12172 gen_array_type_die (tree type
, dw_die_ref context_die
)
12174 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
12175 dw_die_ref array_die
;
12177 /* GNU compilers represent multidimensional array types as sequences of one
12178 dimensional array types whose element types are themselves array types.
12179 We sometimes squish that down to a single array_type DIE with multiple
12180 subscripts in the Dwarf debugging info. The draft Dwarf specification
12181 say that we are allowed to do this kind of compression in C, because
12182 there is no difference between an array of arrays and a multidimensional
12183 array. We don't do this for Ada to remain as close as possible to the
12184 actual representation, which is especially important against the language
12185 flexibilty wrt arrays of variable size. */
12187 bool collapse_nested_arrays
= !is_ada ();
12190 /* ??? The SGI dwarf reader fails for array of array of enum types
12191 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
12192 array type comes before the outer array type. We thus call gen_type_die
12193 before we new_die and must prevent nested array types collapsing for this
12196 #ifdef MIPS_DEBUGGING_INFO
12197 gen_type_die (TREE_TYPE (type
), context_die
);
12198 collapse_nested_arrays
= false;
12201 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
12202 add_name_attribute (array_die
, type_tag (type
));
12203 equate_type_number_to_die (type
, array_die
);
12205 if (TREE_CODE (type
) == VECTOR_TYPE
)
12207 /* The frontend feeds us a representation for the vector as a struct
12208 containing an array. Pull out the array type. */
12209 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
12210 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
12213 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12215 && TREE_CODE (type
) == ARRAY_TYPE
12216 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
)
12217 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
12220 /* We default the array ordering. SDB will probably do
12221 the right things even if DW_AT_ordering is not present. It's not even
12222 an issue until we start to get into multidimensional arrays anyway. If
12223 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
12224 then we'll have to put the DW_AT_ordering attribute back in. (But if
12225 and when we find out that we need to put these in, we will only do so
12226 for multidimensional arrays. */
12227 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
12230 #ifdef MIPS_DEBUGGING_INFO
12231 /* The SGI compilers handle arrays of unknown bound by setting
12232 AT_declaration and not emitting any subrange DIEs. */
12233 if (! TYPE_DOMAIN (type
))
12234 add_AT_flag (array_die
, DW_AT_declaration
, 1);
12237 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
12239 /* Add representation of the type of the elements of this array type and
12240 emit the corresponding DIE if we haven't done it already. */
12241 element_type
= TREE_TYPE (type
);
12242 if (collapse_nested_arrays
)
12243 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
12244 element_type
= TREE_TYPE (element_type
);
12246 #ifndef MIPS_DEBUGGING_INFO
12247 gen_type_die (element_type
, context_die
);
12250 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
12252 if (get_AT (array_die
, DW_AT_name
))
12253 add_pubtype (type
, array_die
);
12256 static dw_loc_descr_ref
12257 descr_info_loc (tree val
, tree base_decl
)
12259 HOST_WIDE_INT size
;
12260 dw_loc_descr_ref loc
, loc2
;
12261 enum dwarf_location_atom op
;
12263 if (val
== base_decl
)
12264 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
12266 switch (TREE_CODE (val
))
12269 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12271 if (host_integerp (val
, 0))
12272 return int_loc_descriptor (tree_low_cst (val
, 0));
12275 size
= int_size_in_bytes (TREE_TYPE (val
));
12278 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12281 if (size
== DWARF2_ADDR_SIZE
)
12282 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
12284 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
12286 case POINTER_PLUS_EXPR
:
12288 if (host_integerp (TREE_OPERAND (val
, 1), 1)
12289 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
12292 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12295 add_loc_descr (&loc
,
12296 new_loc_descr (DW_OP_plus_uconst
,
12297 tree_low_cst (TREE_OPERAND (val
, 1),
12304 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
12307 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
12310 add_loc_descr (&loc
, loc2
);
12311 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
12333 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
12334 tree val
, tree base_decl
)
12336 dw_loc_descr_ref loc
;
12338 if (host_integerp (val
, 0))
12340 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
12344 loc
= descr_info_loc (val
, base_decl
);
12348 add_AT_loc (die
, attr
, loc
);
12351 /* This routine generates DIE for array with hidden descriptor, details
12352 are filled into *info by a langhook. */
12355 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
12356 dw_die_ref context_die
)
12358 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
12359 dw_die_ref array_die
;
12362 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
12363 add_name_attribute (array_die
, type_tag (type
));
12364 equate_type_number_to_die (type
, array_die
);
12366 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
12368 && info
->ndimensions
>= 2)
12369 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
12371 if (info
->data_location
)
12372 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
12374 if (info
->associated
)
12375 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
12377 if (info
->allocated
)
12378 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
12381 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
12383 dw_die_ref subrange_die
12384 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
12386 if (info
->dimen
[dim
].lower_bound
)
12388 /* If it is the default value, omit it. */
12389 if ((is_c_family () || is_java ())
12390 && integer_zerop (info
->dimen
[dim
].lower_bound
))
12392 else if (is_fortran ()
12393 && integer_onep (info
->dimen
[dim
].lower_bound
))
12396 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
12397 info
->dimen
[dim
].lower_bound
,
12400 if (info
->dimen
[dim
].upper_bound
)
12401 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
12402 info
->dimen
[dim
].upper_bound
,
12404 if (info
->dimen
[dim
].stride
)
12405 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
12406 info
->dimen
[dim
].stride
,
12410 gen_type_die (info
->element_type
, context_die
);
12411 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
12413 if (get_AT (array_die
, DW_AT_name
))
12414 add_pubtype (type
, array_die
);
12419 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
12421 tree origin
= decl_ultimate_origin (decl
);
12422 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
12424 if (origin
!= NULL
)
12425 add_abstract_origin_attribute (decl_die
, origin
);
12428 add_name_and_src_coords_attributes (decl_die
, decl
);
12429 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
12430 0, 0, context_die
);
12433 if (DECL_ABSTRACT (decl
))
12434 equate_decl_number_to_die (decl
, decl_die
);
12436 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
12440 /* Walk through the list of incomplete types again, trying once more to
12441 emit full debugging info for them. */
12444 retry_incomplete_types (void)
12448 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
12449 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
12452 /* Generate a DIE to represent an inlined instance of an enumeration type. */
12455 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
12457 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
12459 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12460 be incomplete and such types are not marked. */
12461 add_abstract_origin_attribute (type_die
, type
);
12464 /* Determine what tag to use for a record type. */
12466 static enum dwarf_tag
12467 record_type_tag (tree type
)
12469 if (! lang_hooks
.types
.classify_record
)
12470 return DW_TAG_structure_type
;
12472 switch (lang_hooks
.types
.classify_record (type
))
12474 case RECORD_IS_STRUCT
:
12475 return DW_TAG_structure_type
;
12477 case RECORD_IS_CLASS
:
12478 return DW_TAG_class_type
;
12480 case RECORD_IS_INTERFACE
:
12481 return DW_TAG_interface_type
;
12484 gcc_unreachable ();
12488 /* Generate a DIE to represent an inlined instance of a structure type. */
12491 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
12493 dw_die_ref type_die
= new_die (record_type_tag (type
), context_die
, type
);
12495 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12496 be incomplete and such types are not marked. */
12497 add_abstract_origin_attribute (type_die
, type
);
12500 /* Generate a DIE to represent an inlined instance of a union type. */
12503 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
12505 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
12507 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
12508 be incomplete and such types are not marked. */
12509 add_abstract_origin_attribute (type_die
, type
);
12512 /* Generate a DIE to represent an enumeration type. Note that these DIEs
12513 include all of the information about the enumeration values also. Each
12514 enumerated type name/value is listed as a child of the enumerated type
12518 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
12520 dw_die_ref type_die
= lookup_type_die (type
);
12522 if (type_die
== NULL
)
12524 type_die
= new_die (DW_TAG_enumeration_type
,
12525 scope_die_for (type
, context_die
), type
);
12526 equate_type_number_to_die (type
, type_die
);
12527 add_name_attribute (type_die
, type_tag (type
));
12529 else if (! TYPE_SIZE (type
))
12532 remove_AT (type_die
, DW_AT_declaration
);
12534 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
12535 given enum type is incomplete, do not generate the DW_AT_byte_size
12536 attribute or the DW_AT_element_list attribute. */
12537 if (TYPE_SIZE (type
))
12541 TREE_ASM_WRITTEN (type
) = 1;
12542 add_byte_size_attribute (type_die
, type
);
12543 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
12544 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
12546 /* If the first reference to this type was as the return type of an
12547 inline function, then it may not have a parent. Fix this now. */
12548 if (type_die
->die_parent
== NULL
)
12549 add_child_die (scope_die_for (type
, context_die
), type_die
);
12551 for (link
= TYPE_VALUES (type
);
12552 link
!= NULL
; link
= TREE_CHAIN (link
))
12554 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
12555 tree value
= TREE_VALUE (link
);
12557 add_name_attribute (enum_die
,
12558 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
12560 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
12561 /* DWARF2 does not provide a way of indicating whether or
12562 not enumeration constants are signed or unsigned. GDB
12563 always assumes the values are signed, so we output all
12564 values as if they were signed. That means that
12565 enumeration constants with very large unsigned values
12566 will appear to have negative values in the debugger. */
12567 add_AT_int (enum_die
, DW_AT_const_value
,
12568 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
12572 add_AT_flag (type_die
, DW_AT_declaration
, 1);
12574 if (get_AT (type_die
, DW_AT_name
))
12575 add_pubtype (type
, type_die
);
12580 /* Generate a DIE to represent either a real live formal parameter decl or to
12581 represent just the type of some formal parameter position in some function
12584 Note that this routine is a bit unusual because its argument may be a
12585 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12586 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12587 node. If it's the former then this function is being called to output a
12588 DIE to represent a formal parameter object (or some inlining thereof). If
12589 it's the latter, then this function is only being called to output a
12590 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12591 argument type of some subprogram type. */
12594 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
12596 dw_die_ref parm_die
12597 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
12600 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
12602 case tcc_declaration
:
12603 origin
= decl_ultimate_origin (node
);
12604 if (origin
!= NULL
)
12605 add_abstract_origin_attribute (parm_die
, origin
);
12608 tree type
= TREE_TYPE (node
);
12609 add_name_and_src_coords_attributes (parm_die
, node
);
12610 if (DECL_BY_REFERENCE (node
))
12611 type
= TREE_TYPE (type
);
12612 add_type_attribute (parm_die
, type
,
12613 TREE_READONLY (node
),
12614 TREE_THIS_VOLATILE (node
),
12616 if (DECL_ARTIFICIAL (node
))
12617 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
12620 equate_decl_number_to_die (node
, parm_die
);
12621 if (! DECL_ABSTRACT (node
))
12622 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
12627 /* We were called with some kind of a ..._TYPE node. */
12628 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
12632 gcc_unreachable ();
12638 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12639 at the end of an (ANSI prototyped) formal parameters list. */
12642 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
12644 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
12647 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12648 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12649 parameters as specified in some function type specification (except for
12650 those which appear as part of a function *definition*). */
12653 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
12656 tree formal_type
= NULL
;
12657 tree first_parm_type
;
12660 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
12662 arg
= DECL_ARGUMENTS (function_or_method_type
);
12663 function_or_method_type
= TREE_TYPE (function_or_method_type
);
12668 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
12670 /* Make our first pass over the list of formal parameter types and output a
12671 DW_TAG_formal_parameter DIE for each one. */
12672 for (link
= first_parm_type
; link
; )
12674 dw_die_ref parm_die
;
12676 formal_type
= TREE_VALUE (link
);
12677 if (formal_type
== void_type_node
)
12680 /* Output a (nameless) DIE to represent the formal parameter itself. */
12681 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
12682 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
12683 && link
== first_parm_type
)
12684 || (arg
&& DECL_ARTIFICIAL (arg
)))
12685 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
12687 link
= TREE_CHAIN (link
);
12689 arg
= TREE_CHAIN (arg
);
12692 /* If this function type has an ellipsis, add a
12693 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12694 if (formal_type
!= void_type_node
)
12695 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
12697 /* Make our second (and final) pass over the list of formal parameter types
12698 and output DIEs to represent those types (as necessary). */
12699 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
12700 link
&& TREE_VALUE (link
);
12701 link
= TREE_CHAIN (link
))
12702 gen_type_die (TREE_VALUE (link
), context_die
);
12705 /* We want to generate the DIE for TYPE so that we can generate the
12706 die for MEMBER, which has been defined; we will need to refer back
12707 to the member declaration nested within TYPE. If we're trying to
12708 generate minimal debug info for TYPE, processing TYPE won't do the
12709 trick; we need to attach the member declaration by hand. */
12712 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
12714 gen_type_die (type
, context_die
);
12716 /* If we're trying to avoid duplicate debug info, we may not have
12717 emitted the member decl for this function. Emit it now. */
12718 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
12719 && ! lookup_decl_die (member
))
12721 dw_die_ref type_die
;
12722 gcc_assert (!decl_ultimate_origin (member
));
12724 push_decl_scope (type
);
12725 type_die
= lookup_type_die (type
);
12726 if (TREE_CODE (member
) == FUNCTION_DECL
)
12727 gen_subprogram_die (member
, type_die
);
12728 else if (TREE_CODE (member
) == FIELD_DECL
)
12730 /* Ignore the nameless fields that are used to skip bits but handle
12731 C++ anonymous unions and structs. */
12732 if (DECL_NAME (member
) != NULL_TREE
12733 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
12734 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
12736 gen_type_die (member_declared_type (member
), type_die
);
12737 gen_field_die (member
, type_die
);
12741 gen_variable_die (member
, type_die
);
12747 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12748 may later generate inlined and/or out-of-line instances of. */
12751 dwarf2out_abstract_function (tree decl
)
12753 dw_die_ref old_die
;
12756 int was_abstract
= DECL_ABSTRACT (decl
);
12758 /* Make sure we have the actual abstract inline, not a clone. */
12759 decl
= DECL_ORIGIN (decl
);
12761 old_die
= lookup_decl_die (decl
);
12762 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
12763 /* We've already generated the abstract instance. */
12766 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12767 we don't get confused by DECL_ABSTRACT. */
12768 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12770 context
= decl_class_context (decl
);
12772 gen_type_die_for_member
12773 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
12776 /* Pretend we've just finished compiling this function. */
12777 save_fn
= current_function_decl
;
12778 current_function_decl
= decl
;
12779 push_cfun (DECL_STRUCT_FUNCTION (decl
));
12781 set_decl_abstract_flags (decl
, 1);
12782 dwarf2out_decl (decl
);
12783 if (! was_abstract
)
12784 set_decl_abstract_flags (decl
, 0);
12786 current_function_decl
= save_fn
;
12790 /* Helper function of premark_used_types() which gets called through
12791 htab_traverse_resize().
12793 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12794 marked as unused by prune_unused_types. */
12796 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
12801 type
= (tree
) *slot
;
12802 die
= lookup_type_die (type
);
12804 die
->die_perennial_p
= 1;
12808 /* Mark all members of used_types_hash as perennial. */
12810 premark_used_types (void)
12812 if (cfun
&& cfun
->used_types_hash
)
12813 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
12816 /* Generate a DIE to represent a declared function (either file-scope or
12820 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
12822 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
12823 tree origin
= decl_ultimate_origin (decl
);
12824 dw_die_ref subr_die
;
12827 dw_die_ref old_die
= lookup_decl_die (decl
);
12828 int declaration
= (current_function_decl
!= decl
12829 || class_or_namespace_scope_p (context_die
));
12831 premark_used_types ();
12833 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12834 started to generate the abstract instance of an inline, decided to output
12835 its containing class, and proceeded to emit the declaration of the inline
12836 from the member list for the class. If so, DECLARATION takes priority;
12837 we'll get back to the abstract instance when done with the class. */
12839 /* The class-scope declaration DIE must be the primary DIE. */
12840 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
12843 gcc_assert (!old_die
);
12846 /* Now that the C++ front end lazily declares artificial member fns, we
12847 might need to retrofit the declaration into its class. */
12848 if (!declaration
&& !origin
&& !old_die
12849 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
12850 && !class_or_namespace_scope_p (context_die
)
12851 && debug_info_level
> DINFO_LEVEL_TERSE
)
12852 old_die
= force_decl_die (decl
);
12854 if (origin
!= NULL
)
12856 gcc_assert (!declaration
|| local_scope_p (context_die
));
12858 /* Fixup die_parent for the abstract instance of a nested
12859 inline function. */
12860 if (old_die
&& old_die
->die_parent
== NULL
)
12861 add_child_die (context_die
, old_die
);
12863 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
12864 add_abstract_origin_attribute (subr_die
, origin
);
12868 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12869 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
12871 if (!get_AT_flag (old_die
, DW_AT_declaration
)
12872 /* We can have a normal definition following an inline one in the
12873 case of redefinition of GNU C extern inlines.
12874 It seems reasonable to use AT_specification in this case. */
12875 && !get_AT (old_die
, DW_AT_inline
))
12877 /* Detect and ignore this case, where we are trying to output
12878 something we have already output. */
12882 /* If the definition comes from the same place as the declaration,
12883 maybe use the old DIE. We always want the DIE for this function
12884 that has the *_pc attributes to be under comp_unit_die so the
12885 debugger can find it. We also need to do this for abstract
12886 instances of inlines, since the spec requires the out-of-line copy
12887 to have the same parent. For local class methods, this doesn't
12888 apply; we just use the old DIE. */
12889 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
12890 && (DECL_ARTIFICIAL (decl
)
12891 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
12892 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
12893 == (unsigned) s
.line
))))
12895 subr_die
= old_die
;
12897 /* Clear out the declaration attribute and the formal parameters.
12898 Do not remove all children, because it is possible that this
12899 declaration die was forced using force_decl_die(). In such
12900 cases die that forced declaration die (e.g. TAG_imported_module)
12901 is one of the children that we do not want to remove. */
12902 remove_AT (subr_die
, DW_AT_declaration
);
12903 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
12907 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
12908 add_AT_specification (subr_die
, old_die
);
12909 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
12910 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
12911 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
12912 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
12917 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
12919 if (TREE_PUBLIC (decl
))
12920 add_AT_flag (subr_die
, DW_AT_external
, 1);
12922 add_name_and_src_coords_attributes (subr_die
, decl
);
12923 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12925 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
12926 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
12927 0, 0, context_die
);
12930 add_pure_or_virtual_attribute (subr_die
, decl
);
12931 if (DECL_ARTIFICIAL (decl
))
12932 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
12934 if (TREE_PROTECTED (decl
))
12935 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12936 else if (TREE_PRIVATE (decl
))
12937 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12942 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
12944 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
12946 /* The first time we see a member function, it is in the context of
12947 the class to which it belongs. We make sure of this by emitting
12948 the class first. The next time is the definition, which is
12949 handled above. The two may come from the same source text.
12951 Note that force_decl_die() forces function declaration die. It is
12952 later reused to represent definition. */
12953 equate_decl_number_to_die (decl
, subr_die
);
12956 else if (DECL_ABSTRACT (decl
))
12958 if (DECL_DECLARED_INLINE_P (decl
))
12960 if (cgraph_function_possibly_inlined_p (decl
))
12961 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
12963 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
12967 if (cgraph_function_possibly_inlined_p (decl
))
12968 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
12970 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
12973 if (DECL_DECLARED_INLINE_P (decl
)
12974 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
12975 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
12977 equate_decl_number_to_die (decl
, subr_die
);
12979 else if (!DECL_EXTERNAL (decl
))
12981 HOST_WIDE_INT cfa_fb_offset
;
12983 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
12984 equate_decl_number_to_die (decl
, subr_die
);
12986 if (!flag_reorder_blocks_and_partition
)
12988 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
12989 current_function_funcdef_no
);
12990 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
12991 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
12992 current_function_funcdef_no
);
12993 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
12995 add_pubname (decl
, subr_die
);
12996 add_arange (decl
, subr_die
);
12999 { /* Do nothing for now; maybe need to duplicate die, one for
13000 hot section and one for cold section, then use the hot/cold
13001 section begin/end labels to generate the aranges... */
13003 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
13004 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
13005 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
13006 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
13008 add_pubname (decl, subr_die);
13009 add_arange (decl, subr_die);
13010 add_arange (decl, subr_die);
13014 #ifdef MIPS_DEBUGGING_INFO
13015 /* Add a reference to the FDE for this routine. */
13016 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
13019 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
13021 /* We define the "frame base" as the function's CFA. This is more
13022 convenient for several reasons: (1) It's stable across the prologue
13023 and epilogue, which makes it better than just a frame pointer,
13024 (2) With dwarf3, there exists a one-byte encoding that allows us
13025 to reference the .debug_frame data by proxy, but failing that,
13026 (3) We can at least reuse the code inspection and interpretation
13027 code that determines the CFA position at various points in the
13029 /* ??? Use some command-line or configury switch to enable the use
13030 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
13031 consumers that understand it; fall back to "pure" dwarf2 and
13032 convert the CFA data into a location list. */
13034 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
13035 if (list
->dw_loc_next
)
13036 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
13038 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
13041 /* Compute a displacement from the "steady-state frame pointer" to
13042 the CFA. The former is what all stack slots and argument slots
13043 will reference in the rtl; the later is what we've told the
13044 debugger about. We'll need to adjust all frame_base references
13045 by this displacement. */
13046 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
13048 if (cfun
->static_chain_decl
)
13049 add_AT_location_description (subr_die
, DW_AT_static_link
,
13050 loc_descriptor_from_tree (cfun
->static_chain_decl
));
13053 /* Now output descriptions of the arguments for this function. This gets
13054 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
13055 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
13056 `...' at the end of the formal parameter list. In order to find out if
13057 there was a trailing ellipsis or not, we must instead look at the type
13058 associated with the FUNCTION_DECL. This will be a node of type
13059 FUNCTION_TYPE. If the chain of type nodes hanging off of this
13060 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
13061 an ellipsis at the end. */
13063 /* In the case where we are describing a mere function declaration, all we
13064 need to do here (and all we *can* do here) is to describe the *types* of
13065 its formal parameters. */
13066 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13068 else if (declaration
)
13069 gen_formal_types_die (decl
, subr_die
);
13072 /* Generate DIEs to represent all known formal parameters. */
13073 tree arg_decls
= DECL_ARGUMENTS (decl
);
13076 /* When generating DIEs, generate the unspecified_parameters DIE
13077 instead if we come across the arg "__builtin_va_alist" */
13078 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
13079 if (TREE_CODE (parm
) == PARM_DECL
)
13081 if (DECL_NAME (parm
)
13082 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
13083 "__builtin_va_alist"))
13084 gen_unspecified_parameters_die (parm
, subr_die
);
13086 gen_decl_die (parm
, subr_die
);
13089 /* Decide whether we need an unspecified_parameters DIE at the end.
13090 There are 2 more cases to do this for: 1) the ansi ... declaration -
13091 this is detectable when the end of the arg list is not a
13092 void_type_node 2) an unprototyped function declaration (not a
13093 definition). This just means that we have no info about the
13094 parameters at all. */
13095 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
13096 if (fn_arg_types
!= NULL
)
13098 /* This is the prototyped case, check for.... */
13099 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
13100 gen_unspecified_parameters_die (decl
, subr_die
);
13102 else if (DECL_INITIAL (decl
) == NULL_TREE
)
13103 gen_unspecified_parameters_die (decl
, subr_die
);
13106 /* Output Dwarf info for all of the stuff within the body of the function
13107 (if it has one - it may be just a declaration). */
13108 outer_scope
= DECL_INITIAL (decl
);
13110 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
13111 a function. This BLOCK actually represents the outermost binding contour
13112 for the function, i.e. the contour in which the function's formal
13113 parameters and labels get declared. Curiously, it appears that the front
13114 end doesn't actually put the PARM_DECL nodes for the current function onto
13115 the BLOCK_VARS list for this outer scope, but are strung off of the
13116 DECL_ARGUMENTS list for the function instead.
13118 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
13119 the LABEL_DECL nodes for the function however, and we output DWARF info
13120 for those in decls_for_scope. Just within the `outer_scope' there will be
13121 a BLOCK node representing the function's outermost pair of curly braces,
13122 and any blocks used for the base and member initializers of a C++
13123 constructor function. */
13124 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
13126 /* Emit a DW_TAG_variable DIE for a named return value. */
13127 if (DECL_NAME (DECL_RESULT (decl
)))
13128 gen_decl_die (DECL_RESULT (decl
), subr_die
);
13130 current_function_has_inlines
= 0;
13131 decls_for_scope (outer_scope
, subr_die
, 0);
13133 #if 0 && defined (MIPS_DEBUGGING_INFO)
13134 if (current_function_has_inlines
)
13136 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
13137 if (! comp_unit_has_inlines
)
13139 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
13140 comp_unit_has_inlines
= 1;
13145 /* Add the calling convention attribute if requested. */
13146 add_calling_convention_attribute (subr_die
, decl
);
13150 /* Generate a DIE to represent a declared data object. */
13153 gen_variable_die (tree decl
, dw_die_ref context_die
)
13157 dw_die_ref var_die
;
13158 tree origin
= decl_ultimate_origin (decl
);
13159 dw_die_ref old_die
= lookup_decl_die (decl
);
13160 int declaration
= (DECL_EXTERNAL (decl
)
13161 /* If DECL is COMDAT and has not actually been
13162 emitted, we cannot take its address; there
13163 might end up being no definition anywhere in
13164 the program. For example, consider the C++
13168 struct S { static const int i = 7; };
13173 int f() { return S<int>::i; }
13175 Here, S<int>::i is not DECL_EXTERNAL, but no
13176 definition is required, so the compiler will
13177 not emit a definition. */
13178 || (TREE_CODE (decl
) == VAR_DECL
13179 && DECL_COMDAT (decl
) && !TREE_ASM_WRITTEN (decl
))
13180 || class_or_namespace_scope_p (context_die
));
13182 com_decl
= fortran_common (decl
, &off
);
13184 /* Symbol in common gets emitted as a child of the common block, in the form
13187 ??? This creates a new common block die for every common block symbol.
13188 Better to share same common block die for all symbols in that block. */
13192 dw_die_ref com_die
;
13193 const char *cnam
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
13194 dw_loc_descr_ref loc
= loc_descriptor_from_tree (com_decl
);
13196 field
= TREE_OPERAND (DECL_VALUE_EXPR (decl
), 0);
13197 var_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
13198 add_name_and_src_coords_attributes (var_die
, field
);
13199 add_AT_flag (var_die
, DW_AT_external
, 1);
13200 add_AT_loc (var_die
, DW_AT_location
, loc
);
13201 com_die
= new_die (DW_TAG_member
, var_die
, decl
);
13202 add_name_and_src_coords_attributes (com_die
, decl
);
13203 add_type_attribute (com_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
13204 TREE_THIS_VOLATILE (decl
), context_die
);
13205 add_AT_loc (com_die
, DW_AT_data_member_location
,
13206 int_loc_descriptor (off
));
13207 add_pubname_string (cnam
, var_die
); /* ??? needed? */
13211 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
13213 if (origin
!= NULL
)
13214 add_abstract_origin_attribute (var_die
, origin
);
13216 /* Loop unrolling can create multiple blocks that refer to the same
13217 static variable, so we must test for the DW_AT_declaration flag.
13219 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
13220 copy decls and set the DECL_ABSTRACT flag on them instead of
13223 ??? Duplicated blocks have been rewritten to use .debug_ranges.
13225 ??? The declare_in_namespace support causes us to get two DIEs for one
13226 variable, both of which are declarations. We want to avoid considering
13227 one to be a specification, so we must test that this DIE is not a
13229 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
13230 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
13232 /* This is a definition of a C++ class level static. */
13233 add_AT_specification (var_die
, old_die
);
13234 if (DECL_NAME (decl
))
13236 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
13237 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
13239 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
13240 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
13242 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
13243 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
13248 tree type
= TREE_TYPE (decl
);
13249 if ((TREE_CODE (decl
) == PARM_DECL
13250 || TREE_CODE (decl
) == RESULT_DECL
)
13251 && DECL_BY_REFERENCE (decl
))
13252 type
= TREE_TYPE (type
);
13254 add_name_and_src_coords_attributes (var_die
, decl
);
13255 add_type_attribute (var_die
, type
, TREE_READONLY (decl
),
13256 TREE_THIS_VOLATILE (decl
), context_die
);
13258 if (TREE_PUBLIC (decl
))
13259 add_AT_flag (var_die
, DW_AT_external
, 1);
13261 if (DECL_ARTIFICIAL (decl
))
13262 add_AT_flag (var_die
, DW_AT_artificial
, 1);
13264 if (TREE_PROTECTED (decl
))
13265 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13266 else if (TREE_PRIVATE (decl
))
13267 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
13271 add_AT_flag (var_die
, DW_AT_declaration
, 1);
13273 if (DECL_ABSTRACT (decl
) || declaration
)
13274 equate_decl_number_to_die (decl
, var_die
);
13276 if (! declaration
&& ! DECL_ABSTRACT (decl
))
13278 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
13279 add_pubname (decl
, var_die
);
13282 tree_add_const_value_attribute (var_die
, decl
);
13285 /* Generate a DIE to represent a label identifier. */
13288 gen_label_die (tree decl
, dw_die_ref context_die
)
13290 tree origin
= decl_ultimate_origin (decl
);
13291 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
13293 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
13295 if (origin
!= NULL
)
13296 add_abstract_origin_attribute (lbl_die
, origin
);
13298 add_name_and_src_coords_attributes (lbl_die
, decl
);
13300 if (DECL_ABSTRACT (decl
))
13301 equate_decl_number_to_die (decl
, lbl_die
);
13304 insn
= DECL_RTL_IF_SET (decl
);
13306 /* Deleted labels are programmer specified labels which have been
13307 eliminated because of various optimizations. We still emit them
13308 here so that it is possible to put breakpoints on them. */
13312 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
13314 /* When optimization is enabled (via -O) some parts of the compiler
13315 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
13316 represent source-level labels which were explicitly declared by
13317 the user. This really shouldn't be happening though, so catch
13318 it if it ever does happen. */
13319 gcc_assert (!INSN_DELETED_P (insn
));
13321 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
13322 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
13327 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
13328 attributes to the DIE for a block STMT, to describe where the inlined
13329 function was called from. This is similar to add_src_coords_attributes. */
13332 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
13334 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
13336 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
13337 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
13341 /* If STMT's abstract origin is a function declaration and STMT's
13342 first subblock's abstract origin is the function's outermost block,
13343 then we're looking at the main entry point. */
13345 is_inlined_entry_point (const_tree stmt
)
13349 if (!stmt
|| TREE_CODE (stmt
) != BLOCK
)
13352 decl
= block_ultimate_origin (stmt
);
13354 if (!decl
|| TREE_CODE (decl
) != FUNCTION_DECL
)
13357 block
= BLOCK_SUBBLOCKS (stmt
);
13361 if (TREE_CODE (block
) != BLOCK
)
13364 block
= block_ultimate_origin (block
);
13367 return block
== DECL_INITIAL (decl
);
13370 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
13371 Add low_pc and high_pc attributes to the DIE for a block STMT. */
13374 add_high_low_attributes (tree stmt
, dw_die_ref die
)
13376 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
13378 if (BLOCK_FRAGMENT_CHAIN (stmt
))
13382 if (is_inlined_entry_point (stmt
))
13384 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
13385 BLOCK_NUMBER (stmt
));
13386 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
13389 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
13391 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
13394 add_ranges (chain
);
13395 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
13402 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
13403 BLOCK_NUMBER (stmt
));
13404 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
13405 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
13406 BLOCK_NUMBER (stmt
));
13407 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
13411 /* Generate a DIE for a lexical block. */
13414 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
13416 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
13418 if (! BLOCK_ABSTRACT (stmt
))
13419 add_high_low_attributes (stmt
, stmt_die
);
13421 decls_for_scope (stmt
, stmt_die
, depth
);
13424 /* Generate a DIE for an inlined subprogram. */
13427 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
13429 tree decl
= block_ultimate_origin (stmt
);
13431 /* Emit info for the abstract instance first, if we haven't yet. We
13432 must emit this even if the block is abstract, otherwise when we
13433 emit the block below (or elsewhere), we may end up trying to emit
13434 a die whose origin die hasn't been emitted, and crashing. */
13435 dwarf2out_abstract_function (decl
);
13437 if (! BLOCK_ABSTRACT (stmt
))
13439 dw_die_ref subr_die
13440 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
13442 add_abstract_origin_attribute (subr_die
, decl
);
13443 add_high_low_attributes (stmt
, subr_die
);
13444 add_call_src_coords_attributes (stmt
, subr_die
);
13446 decls_for_scope (stmt
, subr_die
, depth
);
13447 current_function_has_inlines
= 1;
13450 /* We may get here if we're the outer block of function A that was
13451 inlined into function B that was inlined into function C. When
13452 generating debugging info for C, dwarf2out_abstract_function(B)
13453 would mark all inlined blocks as abstract, including this one.
13454 So, we wouldn't (and shouldn't) expect labels to be generated
13455 for this one. Instead, just emit debugging info for
13456 declarations within the block. This is particularly important
13457 in the case of initializers of arguments passed from B to us:
13458 if they're statement expressions containing declarations, we
13459 wouldn't generate dies for their abstract variables, and then,
13460 when generating dies for the real variables, we'd die (pun
13462 gen_lexical_block_die (stmt
, context_die
, depth
);
13465 /* Generate a DIE for a field in a record, or structure. */
13468 gen_field_die (tree decl
, dw_die_ref context_die
)
13470 dw_die_ref decl_die
;
13472 if (TREE_TYPE (decl
) == error_mark_node
)
13475 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
13476 add_name_and_src_coords_attributes (decl_die
, decl
);
13477 add_type_attribute (decl_die
, member_declared_type (decl
),
13478 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
13481 if (DECL_BIT_FIELD_TYPE (decl
))
13483 add_byte_size_attribute (decl_die
, decl
);
13484 add_bit_size_attribute (decl_die
, decl
);
13485 add_bit_offset_attribute (decl_die
, decl
);
13488 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
13489 add_data_member_location_attribute (decl_die
, decl
);
13491 if (DECL_ARTIFICIAL (decl
))
13492 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
13494 if (TREE_PROTECTED (decl
))
13495 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13496 else if (TREE_PRIVATE (decl
))
13497 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
13499 /* Equate decl number to die, so that we can look up this decl later on. */
13500 equate_decl_number_to_die (decl
, decl_die
);
13504 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13505 Use modified_type_die instead.
13506 We keep this code here just in case these types of DIEs may be needed to
13507 represent certain things in other languages (e.g. Pascal) someday. */
13510 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
13513 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
13515 equate_type_number_to_die (type
, ptr_die
);
13516 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
13517 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
13520 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
13521 Use modified_type_die instead.
13522 We keep this code here just in case these types of DIEs may be needed to
13523 represent certain things in other languages (e.g. Pascal) someday. */
13526 gen_reference_type_die (tree type
, dw_die_ref context_die
)
13529 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
13531 equate_type_number_to_die (type
, ref_die
);
13532 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
13533 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
13537 /* Generate a DIE for a pointer to a member type. */
13540 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
13543 = new_die (DW_TAG_ptr_to_member_type
,
13544 scope_die_for (type
, context_die
), type
);
13546 equate_type_number_to_die (type
, ptr_die
);
13547 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
13548 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
13549 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
13552 /* Generate the DIE for the compilation unit. */
13555 gen_compile_unit_die (const char *filename
)
13558 char producer
[250];
13559 const char *language_string
= lang_hooks
.name
;
13562 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
13566 add_name_attribute (die
, filename
);
13567 /* Don't add cwd for <built-in>. */
13568 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
13569 add_comp_dir_attribute (die
);
13572 sprintf (producer
, "%s %s", language_string
, version_string
);
13574 #ifdef MIPS_DEBUGGING_INFO
13575 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13576 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13577 not appear in the producer string, the debugger reaches the conclusion
13578 that the object file is stripped and has no debugging information.
13579 To get the MIPS/SGI debugger to believe that there is debugging
13580 information in the object file, we add a -g to the producer string. */
13581 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13582 strcat (producer
, " -g");
13585 add_AT_string (die
, DW_AT_producer
, producer
);
13587 if (strcmp (language_string
, "GNU C++") == 0)
13588 language
= DW_LANG_C_plus_plus
;
13589 else if (strcmp (language_string
, "GNU Ada") == 0)
13590 language
= DW_LANG_Ada95
;
13591 else if (strcmp (language_string
, "GNU F77") == 0)
13592 language
= DW_LANG_Fortran77
;
13593 else if (strcmp (language_string
, "GNU Fortran") == 0)
13594 language
= DW_LANG_Fortran95
;
13595 else if (strcmp (language_string
, "GNU Pascal") == 0)
13596 language
= DW_LANG_Pascal83
;
13597 else if (strcmp (language_string
, "GNU Java") == 0)
13598 language
= DW_LANG_Java
;
13599 else if (strcmp (language_string
, "GNU Objective-C") == 0)
13600 language
= DW_LANG_ObjC
;
13601 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
13602 language
= DW_LANG_ObjC_plus_plus
;
13604 language
= DW_LANG_C89
;
13606 add_AT_unsigned (die
, DW_AT_language
, language
);
13610 /* Generate the DIE for a base class. */
13613 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
13615 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
13617 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
13618 add_data_member_location_attribute (die
, binfo
);
13620 if (BINFO_VIRTUAL_P (binfo
))
13621 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
13623 if (access
== access_public_node
)
13624 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
13625 else if (access
== access_protected_node
)
13626 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13629 /* Generate a DIE for a class member. */
13632 gen_member_die (tree type
, dw_die_ref context_die
)
13635 tree binfo
= TYPE_BINFO (type
);
13638 /* If this is not an incomplete type, output descriptions of each of its
13639 members. Note that as we output the DIEs necessary to represent the
13640 members of this record or union type, we will also be trying to output
13641 DIEs to represent the *types* of those members. However the `type'
13642 function (above) will specifically avoid generating type DIEs for member
13643 types *within* the list of member DIEs for this (containing) type except
13644 for those types (of members) which are explicitly marked as also being
13645 members of this (containing) type themselves. The g++ front- end can
13646 force any given type to be treated as a member of some other (containing)
13647 type by setting the TYPE_CONTEXT of the given (member) type to point to
13648 the TREE node representing the appropriate (containing) type. */
13650 /* First output info about the base classes. */
13653 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
13657 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
13658 gen_inheritance_die (base
,
13659 (accesses
? VEC_index (tree
, accesses
, i
)
13660 : access_public_node
), context_die
);
13663 /* Now output info about the data members and type members. */
13664 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
13666 /* If we thought we were generating minimal debug info for TYPE
13667 and then changed our minds, some of the member declarations
13668 may have already been defined. Don't define them again, but
13669 do put them in the right order. */
13671 child
= lookup_decl_die (member
);
13673 splice_child_die (context_die
, child
);
13675 gen_decl_die (member
, context_die
);
13678 /* Now output info about the function members (if any). */
13679 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
13681 /* Don't include clones in the member list. */
13682 if (DECL_ABSTRACT_ORIGIN (member
))
13685 child
= lookup_decl_die (member
);
13687 splice_child_die (context_die
, child
);
13689 gen_decl_die (member
, context_die
);
13693 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13694 is set, we pretend that the type was never defined, so we only get the
13695 member DIEs needed by later specification DIEs. */
13698 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
13699 enum debug_info_usage usage
)
13701 dw_die_ref type_die
= lookup_type_die (type
);
13702 dw_die_ref scope_die
= 0;
13704 int complete
= (TYPE_SIZE (type
)
13705 && (! TYPE_STUB_DECL (type
)
13706 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
13707 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
13708 complete
= complete
&& should_emit_struct_debug (type
, usage
);
13710 if (type_die
&& ! complete
)
13713 if (TYPE_CONTEXT (type
) != NULL_TREE
13714 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
13715 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
13718 scope_die
= scope_die_for (type
, context_die
);
13720 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
13721 /* First occurrence of type or toplevel definition of nested class. */
13723 dw_die_ref old_die
= type_die
;
13725 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
13726 ? record_type_tag (type
) : DW_TAG_union_type
,
13728 equate_type_number_to_die (type
, type_die
);
13730 add_AT_specification (type_die
, old_die
);
13732 add_name_attribute (type_die
, type_tag (type
));
13735 remove_AT (type_die
, DW_AT_declaration
);
13737 /* If this type has been completed, then give it a byte_size attribute and
13738 then give a list of members. */
13739 if (complete
&& !ns_decl
)
13741 /* Prevent infinite recursion in cases where the type of some member of
13742 this type is expressed in terms of this type itself. */
13743 TREE_ASM_WRITTEN (type
) = 1;
13744 add_byte_size_attribute (type_die
, type
);
13745 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
13746 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
13748 /* If the first reference to this type was as the return type of an
13749 inline function, then it may not have a parent. Fix this now. */
13750 if (type_die
->die_parent
== NULL
)
13751 add_child_die (scope_die
, type_die
);
13753 push_decl_scope (type
);
13754 gen_member_die (type
, type_die
);
13757 /* GNU extension: Record what type our vtable lives in. */
13758 if (TYPE_VFIELD (type
))
13760 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
13762 gen_type_die (vtype
, context_die
);
13763 add_AT_die_ref (type_die
, DW_AT_containing_type
,
13764 lookup_type_die (vtype
));
13769 add_AT_flag (type_die
, DW_AT_declaration
, 1);
13771 /* We don't need to do this for function-local types. */
13772 if (TYPE_STUB_DECL (type
)
13773 && ! decl_function_context (TYPE_STUB_DECL (type
)))
13774 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
13777 if (get_AT (type_die
, DW_AT_name
))
13778 add_pubtype (type
, type_die
);
13781 /* Generate a DIE for a subroutine _type_. */
13784 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
13786 tree return_type
= TREE_TYPE (type
);
13787 dw_die_ref subr_die
13788 = new_die (DW_TAG_subroutine_type
,
13789 scope_die_for (type
, context_die
), type
);
13791 equate_type_number_to_die (type
, subr_die
);
13792 add_prototyped_attribute (subr_die
, type
);
13793 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
13794 gen_formal_types_die (type
, subr_die
);
13796 if (get_AT (subr_die
, DW_AT_name
))
13797 add_pubtype (type
, subr_die
);
13800 /* Generate a DIE for a type definition. */
13803 gen_typedef_die (tree decl
, dw_die_ref context_die
)
13805 dw_die_ref type_die
;
13808 if (TREE_ASM_WRITTEN (decl
))
13811 TREE_ASM_WRITTEN (decl
) = 1;
13812 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
13813 origin
= decl_ultimate_origin (decl
);
13814 if (origin
!= NULL
)
13815 add_abstract_origin_attribute (type_die
, origin
);
13820 add_name_and_src_coords_attributes (type_die
, decl
);
13821 if (DECL_ORIGINAL_TYPE (decl
))
13823 type
= DECL_ORIGINAL_TYPE (decl
);
13825 gcc_assert (type
!= TREE_TYPE (decl
));
13826 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
13829 type
= TREE_TYPE (decl
);
13831 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
13832 TREE_THIS_VOLATILE (decl
), context_die
);
13835 if (DECL_ABSTRACT (decl
))
13836 equate_decl_number_to_die (decl
, type_die
);
13838 if (get_AT (type_die
, DW_AT_name
))
13839 add_pubtype (decl
, type_die
);
13842 /* Generate a type description DIE. */
13845 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
13846 enum debug_info_usage usage
)
13849 struct array_descr_info info
;
13851 if (type
== NULL_TREE
|| type
== error_mark_node
)
13854 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13855 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
13857 if (TREE_ASM_WRITTEN (type
))
13860 /* Prevent broken recursion; we can't hand off to the same type. */
13861 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
13863 TREE_ASM_WRITTEN (type
) = 1;
13864 gen_decl_die (TYPE_NAME (type
), context_die
);
13868 /* If this is an array type with hidden descriptor, handle it first. */
13869 if (!TREE_ASM_WRITTEN (type
)
13870 && lang_hooks
.types
.get_array_descr_info
13871 && lang_hooks
.types
.get_array_descr_info (type
, &info
))
13873 gen_descr_array_type_die (type
, &info
, context_die
);
13874 TREE_ASM_WRITTEN (type
) = 1;
13878 /* We are going to output a DIE to represent the unqualified version
13879 of this type (i.e. without any const or volatile qualifiers) so
13880 get the main variant (i.e. the unqualified version) of this type
13881 now. (Vectors are special because the debugging info is in the
13882 cloned type itself). */
13883 if (TREE_CODE (type
) != VECTOR_TYPE
)
13884 type
= type_main_variant (type
);
13886 if (TREE_ASM_WRITTEN (type
))
13889 switch (TREE_CODE (type
))
13895 case REFERENCE_TYPE
:
13896 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13897 ensures that the gen_type_die recursion will terminate even if the
13898 type is recursive. Recursive types are possible in Ada. */
13899 /* ??? We could perhaps do this for all types before the switch
13901 TREE_ASM_WRITTEN (type
) = 1;
13903 /* For these types, all that is required is that we output a DIE (or a
13904 set of DIEs) to represent the "basis" type. */
13905 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13906 DINFO_USAGE_IND_USE
);
13910 /* This code is used for C++ pointer-to-data-member types.
13911 Output a description of the relevant class type. */
13912 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
13913 DINFO_USAGE_IND_USE
);
13915 /* Output a description of the type of the object pointed to. */
13916 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13917 DINFO_USAGE_IND_USE
);
13919 /* Now output a DIE to represent this pointer-to-data-member type
13921 gen_ptr_to_mbr_type_die (type
, context_die
);
13924 case FUNCTION_TYPE
:
13925 /* Force out return type (in case it wasn't forced out already). */
13926 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13927 DINFO_USAGE_DIR_USE
);
13928 gen_subroutine_type_die (type
, context_die
);
13932 /* Force out return type (in case it wasn't forced out already). */
13933 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13934 DINFO_USAGE_DIR_USE
);
13935 gen_subroutine_type_die (type
, context_die
);
13939 gen_array_type_die (type
, context_die
);
13943 gen_array_type_die (type
, context_die
);
13946 case ENUMERAL_TYPE
:
13949 case QUAL_UNION_TYPE
:
13950 /* If this is a nested type whose containing class hasn't been written
13951 out yet, writing it out will cover this one, too. This does not apply
13952 to instantiations of member class templates; they need to be added to
13953 the containing class as they are generated. FIXME: This hurts the
13954 idea of combining type decls from multiple TUs, since we can't predict
13955 what set of template instantiations we'll get. */
13956 if (TYPE_CONTEXT (type
)
13957 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
13958 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
13960 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
13962 if (TREE_ASM_WRITTEN (type
))
13965 /* If that failed, attach ourselves to the stub. */
13966 push_decl_scope (TYPE_CONTEXT (type
));
13967 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
13972 declare_in_namespace (type
, context_die
);
13976 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
13978 /* This might have been written out by the call to
13979 declare_in_namespace. */
13980 if (!TREE_ASM_WRITTEN (type
))
13981 gen_enumeration_type_die (type
, context_die
);
13984 gen_struct_or_union_type_die (type
, context_die
, usage
);
13989 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13990 it up if it is ever completed. gen_*_type_die will set it for us
13991 when appropriate. */
13997 case FIXED_POINT_TYPE
:
14000 /* No DIEs needed for fundamental types. */
14004 /* No Dwarf representation currently defined. */
14008 gcc_unreachable ();
14011 TREE_ASM_WRITTEN (type
) = 1;
14015 gen_type_die (tree type
, dw_die_ref context_die
)
14017 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
14020 /* Generate a DIE for a tagged type instantiation. */
14023 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
14025 if (type
== NULL_TREE
|| type
== error_mark_node
)
14028 /* We are going to output a DIE to represent the unqualified version of
14029 this type (i.e. without any const or volatile qualifiers) so make sure
14030 that we have the main variant (i.e. the unqualified version) of this
14032 gcc_assert (type
== type_main_variant (type
));
14034 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
14035 an instance of an unresolved type. */
14037 switch (TREE_CODE (type
))
14042 case ENUMERAL_TYPE
:
14043 gen_inlined_enumeration_type_die (type
, context_die
);
14047 gen_inlined_structure_type_die (type
, context_die
);
14051 case QUAL_UNION_TYPE
:
14052 gen_inlined_union_type_die (type
, context_die
);
14056 gcc_unreachable ();
14060 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
14061 things which are local to the given block. */
14064 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
14066 int must_output_die
= 0;
14069 enum tree_code origin_code
;
14071 /* Ignore blocks that are NULL. */
14072 if (stmt
== NULL_TREE
)
14075 /* If the block is one fragment of a non-contiguous block, do not
14076 process the variables, since they will have been done by the
14077 origin block. Do process subblocks. */
14078 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
14082 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
14083 gen_block_die (sub
, context_die
, depth
+ 1);
14088 /* Determine the "ultimate origin" of this block. This block may be an
14089 inlined instance of an inlined instance of inline function, so we have
14090 to trace all of the way back through the origin chain to find out what
14091 sort of node actually served as the original seed for the creation of
14092 the current block. */
14093 origin
= block_ultimate_origin (stmt
);
14094 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
14096 /* Determine if we need to output any Dwarf DIEs at all to represent this
14098 if (origin_code
== FUNCTION_DECL
)
14099 /* The outer scopes for inlinings *must* always be represented. We
14100 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
14101 must_output_die
= 1;
14104 /* In the case where the current block represents an inlining of the
14105 "body block" of an inline function, we must *NOT* output any DIE for
14106 this block because we have already output a DIE to represent the whole
14107 inlined function scope and the "body block" of any function doesn't
14108 really represent a different scope according to ANSI C rules. So we
14109 check here to make sure that this block does not represent a "body
14110 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
14111 if (! is_body_block (origin
? origin
: stmt
))
14113 /* Determine if this block directly contains any "significant"
14114 local declarations which we will need to output DIEs for. */
14115 if (debug_info_level
> DINFO_LEVEL_TERSE
)
14116 /* We are not in terse mode so *any* local declaration counts
14117 as being a "significant" one. */
14118 must_output_die
= (BLOCK_VARS (stmt
) != NULL
14119 && (TREE_USED (stmt
)
14120 || TREE_ASM_WRITTEN (stmt
)
14121 || BLOCK_ABSTRACT (stmt
)));
14123 /* We are in terse mode, so only local (nested) function
14124 definitions count as "significant" local declarations. */
14125 for (decl
= BLOCK_VARS (stmt
);
14126 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
14127 if (TREE_CODE (decl
) == FUNCTION_DECL
14128 && DECL_INITIAL (decl
))
14130 must_output_die
= 1;
14136 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
14137 DIE for any block which contains no significant local declarations at
14138 all. Rather, in such cases we just call `decls_for_scope' so that any
14139 needed Dwarf info for any sub-blocks will get properly generated. Note
14140 that in terse mode, our definition of what constitutes a "significant"
14141 local declaration gets restricted to include only inlined function
14142 instances and local (nested) function definitions. */
14143 if (must_output_die
)
14145 if (origin_code
== FUNCTION_DECL
)
14146 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
14148 gen_lexical_block_die (stmt
, context_die
, depth
);
14151 decls_for_scope (stmt
, context_die
, depth
);
14154 /* Generate all of the decls declared within a given scope and (recursively)
14155 all of its sub-blocks. */
14158 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
14163 /* Ignore NULL blocks. */
14164 if (stmt
== NULL_TREE
)
14167 if (TREE_USED (stmt
))
14169 /* Output the DIEs to represent all of the data objects and typedefs
14170 declared directly within this block but not within any nested
14171 sub-blocks. Also, nested function and tag DIEs have been
14172 generated with a parent of NULL; fix that up now. */
14173 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
14177 if (TREE_CODE (decl
) == FUNCTION_DECL
)
14178 die
= lookup_decl_die (decl
);
14179 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
14180 die
= lookup_type_die (TREE_TYPE (decl
));
14184 if (die
!= NULL
&& die
->die_parent
== NULL
)
14185 add_child_die (context_die
, die
);
14186 /* Do not produce debug information for static variables since
14187 these might be optimized out. We are called for these later
14188 in varpool_analyze_pending_decls.
14190 But *do* produce it for Fortran COMMON variables because,
14191 even though they are static, their names can differ depending
14192 on the scope, which we need to preserve. */
14193 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
)
14194 && !(is_fortran () && TREE_PUBLIC (decl
)))
14197 gen_decl_die (decl
, context_die
);
14201 /* If we're at -g1, we're not interested in subblocks. */
14202 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14205 /* Output the DIEs to represent all sub-blocks (and the items declared
14206 therein) of this block. */
14207 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
14209 subblocks
= BLOCK_CHAIN (subblocks
))
14210 gen_block_die (subblocks
, context_die
, depth
+ 1);
14213 /* Is this a typedef we can avoid emitting? */
14216 is_redundant_typedef (const_tree decl
)
14218 if (TYPE_DECL_IS_STUB (decl
))
14221 if (DECL_ARTIFICIAL (decl
)
14222 && DECL_CONTEXT (decl
)
14223 && is_tagged_type (DECL_CONTEXT (decl
))
14224 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
14225 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
14226 /* Also ignore the artificial member typedef for the class name. */
14232 /* Returns the DIE for a context. */
14234 static inline dw_die_ref
14235 get_context_die (tree context
)
14239 /* Find die that represents this context. */
14240 if (TYPE_P (context
))
14241 return force_type_die (context
);
14243 return force_decl_die (context
);
14245 return comp_unit_die
;
14248 /* Returns the DIE for decl. A DIE will always be returned. */
14251 force_decl_die (tree decl
)
14253 dw_die_ref decl_die
;
14254 unsigned saved_external_flag
;
14255 tree save_fn
= NULL_TREE
;
14256 decl_die
= lookup_decl_die (decl
);
14259 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
14261 decl_die
= lookup_decl_die (decl
);
14265 switch (TREE_CODE (decl
))
14267 case FUNCTION_DECL
:
14268 /* Clear current_function_decl, so that gen_subprogram_die thinks
14269 that this is a declaration. At this point, we just want to force
14270 declaration die. */
14271 save_fn
= current_function_decl
;
14272 current_function_decl
= NULL_TREE
;
14273 gen_subprogram_die (decl
, context_die
);
14274 current_function_decl
= save_fn
;
14278 /* Set external flag to force declaration die. Restore it after
14279 gen_decl_die() call. */
14280 saved_external_flag
= DECL_EXTERNAL (decl
);
14281 DECL_EXTERNAL (decl
) = 1;
14282 gen_decl_die (decl
, context_die
);
14283 DECL_EXTERNAL (decl
) = saved_external_flag
;
14286 case NAMESPACE_DECL
:
14287 dwarf2out_decl (decl
);
14291 gcc_unreachable ();
14294 /* We should be able to find the DIE now. */
14296 decl_die
= lookup_decl_die (decl
);
14297 gcc_assert (decl_die
);
14303 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
14304 always returned. */
14307 force_type_die (tree type
)
14309 dw_die_ref type_die
;
14311 type_die
= lookup_type_die (type
);
14314 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
14316 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
14317 TYPE_VOLATILE (type
), context_die
);
14318 gcc_assert (type_die
);
14323 /* Force out any required namespaces to be able to output DECL,
14324 and return the new context_die for it, if it's changed. */
14327 setup_namespace_context (tree thing
, dw_die_ref context_die
)
14329 tree context
= (DECL_P (thing
)
14330 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
14331 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
14332 /* Force out the namespace. */
14333 context_die
= force_decl_die (context
);
14335 return context_die
;
14338 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
14339 type) within its namespace, if appropriate.
14341 For compatibility with older debuggers, namespace DIEs only contain
14342 declarations; all definitions are emitted at CU scope. */
14345 declare_in_namespace (tree thing
, dw_die_ref context_die
)
14347 dw_die_ref ns_context
;
14349 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14352 /* If this decl is from an inlined function, then don't try to emit it in its
14353 namespace, as we will get confused. It would have already been emitted
14354 when the abstract instance of the inline function was emitted anyways. */
14355 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
14358 ns_context
= setup_namespace_context (thing
, context_die
);
14360 if (ns_context
!= context_die
)
14362 if (DECL_P (thing
))
14363 gen_decl_die (thing
, ns_context
);
14365 gen_type_die (thing
, ns_context
);
14369 /* Generate a DIE for a namespace or namespace alias. */
14372 gen_namespace_die (tree decl
)
14374 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
14376 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
14377 they are an alias of. */
14378 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
14380 /* Output a real namespace. */
14381 dw_die_ref namespace_die
14382 = new_die (DW_TAG_namespace
, context_die
, decl
);
14383 add_name_and_src_coords_attributes (namespace_die
, decl
);
14384 equate_decl_number_to_die (decl
, namespace_die
);
14388 /* Output a namespace alias. */
14390 /* Force out the namespace we are an alias of, if necessary. */
14391 dw_die_ref origin_die
14392 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
14394 /* Now create the namespace alias DIE. */
14395 dw_die_ref namespace_die
14396 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
14397 add_name_and_src_coords_attributes (namespace_die
, decl
);
14398 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
14399 equate_decl_number_to_die (decl
, namespace_die
);
14403 /* Generate Dwarf debug information for a decl described by DECL. */
14406 gen_decl_die (tree decl
, dw_die_ref context_die
)
14410 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
14413 switch (TREE_CODE (decl
))
14419 /* The individual enumerators of an enum type get output when we output
14420 the Dwarf representation of the relevant enum type itself. */
14423 case FUNCTION_DECL
:
14424 /* Don't output any DIEs to represent mere function declarations,
14425 unless they are class members or explicit block externs. */
14426 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
14427 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
14432 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
14433 on local redeclarations of global functions. That seems broken. */
14434 if (current_function_decl
!= decl
)
14435 /* This is only a declaration. */;
14438 /* If we're emitting a clone, emit info for the abstract instance. */
14439 if (DECL_ORIGIN (decl
) != decl
)
14440 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
14442 /* If we're emitting an out-of-line copy of an inline function,
14443 emit info for the abstract instance and set up to refer to it. */
14444 else if (cgraph_function_possibly_inlined_p (decl
)
14445 && ! DECL_ABSTRACT (decl
)
14446 && ! class_or_namespace_scope_p (context_die
)
14447 /* dwarf2out_abstract_function won't emit a die if this is just
14448 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
14449 that case, because that works only if we have a die. */
14450 && DECL_INITIAL (decl
) != NULL_TREE
)
14452 dwarf2out_abstract_function (decl
);
14453 set_decl_origin_self (decl
);
14456 /* Otherwise we're emitting the primary DIE for this decl. */
14457 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
14459 /* Before we describe the FUNCTION_DECL itself, make sure that we
14460 have described its return type. */
14461 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
14463 /* And its virtual context. */
14464 if (DECL_VINDEX (decl
) != NULL_TREE
)
14465 gen_type_die (DECL_CONTEXT (decl
), context_die
);
14467 /* And its containing type. */
14468 origin
= decl_class_context (decl
);
14469 if (origin
!= NULL_TREE
)
14470 gen_type_die_for_member (origin
, decl
, context_die
);
14472 /* And its containing namespace. */
14473 declare_in_namespace (decl
, context_die
);
14476 /* Now output a DIE to represent the function itself. */
14477 gen_subprogram_die (decl
, context_die
);
14481 /* If we are in terse mode, don't generate any DIEs to represent any
14482 actual typedefs. */
14483 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14486 /* In the special case of a TYPE_DECL node representing the declaration
14487 of some type tag, if the given TYPE_DECL is marked as having been
14488 instantiated from some other (original) TYPE_DECL node (e.g. one which
14489 was generated within the original definition of an inline function) we
14490 have to generate a special (abbreviated) DW_TAG_structure_type,
14491 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
14492 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
14493 && is_tagged_type (TREE_TYPE (decl
)))
14495 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
14499 if (is_redundant_typedef (decl
))
14500 gen_type_die (TREE_TYPE (decl
), context_die
);
14502 /* Output a DIE to represent the typedef itself. */
14503 gen_typedef_die (decl
, context_die
);
14507 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
14508 gen_label_die (decl
, context_die
);
14513 /* If we are in terse mode, don't generate any DIEs to represent any
14514 variable declarations or definitions. */
14515 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14518 /* If this is the global definition of the Fortran COMMON block, we don't
14519 need to do anything. Syntactically, the block itself has no identity,
14520 just its constituent identifiers. */
14521 if (TREE_CODE (decl
) == VAR_DECL
14522 && TREE_PUBLIC (decl
)
14523 && TREE_STATIC (decl
)
14525 && !DECL_HAS_VALUE_EXPR_P (decl
))
14528 /* Output any DIEs that are needed to specify the type of this data
14530 if (TREE_CODE (decl
) == RESULT_DECL
&& DECL_BY_REFERENCE (decl
))
14531 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
14533 gen_type_die (TREE_TYPE (decl
), context_die
);
14535 /* And its containing type. */
14536 origin
= decl_class_context (decl
);
14537 if (origin
!= NULL_TREE
)
14538 gen_type_die_for_member (origin
, decl
, context_die
);
14540 /* And its containing namespace. */
14541 declare_in_namespace (decl
, context_die
);
14543 /* Now output the DIE to represent the data object itself. This gets
14544 complicated because of the possibility that the VAR_DECL really
14545 represents an inlined instance of a formal parameter for an inline
14547 origin
= decl_ultimate_origin (decl
);
14548 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
14549 gen_formal_parameter_die (decl
, context_die
);
14551 gen_variable_die (decl
, context_die
);
14555 /* Ignore the nameless fields that are used to skip bits but handle C++
14556 anonymous unions and structs. */
14557 if (DECL_NAME (decl
) != NULL_TREE
14558 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
14559 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
14561 gen_type_die (member_declared_type (decl
), context_die
);
14562 gen_field_die (decl
, context_die
);
14567 if (DECL_BY_REFERENCE (decl
))
14568 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
14570 gen_type_die (TREE_TYPE (decl
), context_die
);
14571 gen_formal_parameter_die (decl
, context_die
);
14574 case NAMESPACE_DECL
:
14575 gen_namespace_die (decl
);
14579 /* Probably some frontend-internal decl. Assume we don't care. */
14580 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
14585 /* Output debug information for global decl DECL. Called from toplev.c after
14586 compilation proper has finished. */
14589 dwarf2out_global_decl (tree decl
)
14591 /* Output DWARF2 information for file-scope tentative data object
14592 declarations, file-scope (extern) function declarations (which
14593 had no corresponding body) and file-scope tagged type declarations
14594 and definitions which have not yet been forced out.
14596 Ignore the global decl of any Fortran COMMON blocks which also
14597 wind up here though they have already been described in the local
14598 scope for the procedures using them. */
14599 if (TREE_CODE (decl
) == VAR_DECL
14600 && TREE_PUBLIC (decl
) && TREE_STATIC (decl
) && is_fortran ())
14603 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
14604 dwarf2out_decl (decl
);
14607 /* Output debug information for type decl DECL. Called from toplev.c
14608 and from language front ends (to record built-in types). */
14610 dwarf2out_type_decl (tree decl
, int local
)
14613 dwarf2out_decl (decl
);
14616 /* Output debug information for imported module or decl. */
14619 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
14621 dw_die_ref imported_die
, at_import_die
;
14622 dw_die_ref scope_die
;
14623 expanded_location xloc
;
14625 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14630 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14631 We need decl DIE for reference and scope die. First, get DIE for the decl
14634 /* Get the scope die for decl context. Use comp_unit_die for global module
14635 or decl. If die is not found for non globals, force new die. */
14637 && TYPE_P (context
)
14638 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
14640 scope_die
= get_context_die (context
);
14642 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14643 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
14645 if (is_base_type (TREE_TYPE (decl
)))
14646 at_import_die
= base_type_die (TREE_TYPE (decl
));
14648 at_import_die
= force_type_die (TREE_TYPE (decl
));
14649 /* For namespace N { typedef void T; } using N::T; base_type_die
14650 returns NULL, but DW_TAG_imported_declaration requires
14651 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
14652 if (!at_import_die
)
14654 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
14655 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
14656 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
14657 gcc_assert (at_import_die
);
14662 at_import_die
= lookup_decl_die (decl
);
14663 if (!at_import_die
)
14665 /* If we're trying to avoid duplicate debug info, we may not have
14666 emitted the member decl for this field. Emit it now. */
14667 if (TREE_CODE (decl
) == FIELD_DECL
)
14669 tree type
= DECL_CONTEXT (decl
);
14671 if (TYPE_CONTEXT (type
)
14672 && TYPE_P (TYPE_CONTEXT (type
))
14673 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
14674 DINFO_USAGE_DIR_USE
))
14676 gen_type_die_for_member (type
, decl
,
14677 get_context_die (TYPE_CONTEXT (type
)));
14679 at_import_die
= force_decl_die (decl
);
14683 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14684 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
14685 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
14687 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
14689 xloc
= expand_location (input_location
);
14690 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
14691 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
14692 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
14695 /* Write the debugging output for DECL. */
14698 dwarf2out_decl (tree decl
)
14700 dw_die_ref context_die
= comp_unit_die
;
14702 switch (TREE_CODE (decl
))
14707 case FUNCTION_DECL
:
14708 /* What we would really like to do here is to filter out all mere
14709 file-scope declarations of file-scope functions which are never
14710 referenced later within this translation unit (and keep all of ones
14711 that *are* referenced later on) but we aren't clairvoyant, so we have
14712 no idea which functions will be referenced in the future (i.e. later
14713 on within the current translation unit). So here we just ignore all
14714 file-scope function declarations which are not also definitions. If
14715 and when the debugger needs to know something about these functions,
14716 it will have to hunt around and find the DWARF information associated
14717 with the definition of the function.
14719 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14720 nodes represent definitions and which ones represent mere
14721 declarations. We have to check DECL_INITIAL instead. That's because
14722 the C front-end supports some weird semantics for "extern inline"
14723 function definitions. These can get inlined within the current
14724 translation unit (and thus, we need to generate Dwarf info for their
14725 abstract instances so that the Dwarf info for the concrete inlined
14726 instances can have something to refer to) but the compiler never
14727 generates any out-of-lines instances of such things (despite the fact
14728 that they *are* definitions).
14730 The important point is that the C front-end marks these "extern
14731 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14732 them anyway. Note that the C++ front-end also plays some similar games
14733 for inline function definitions appearing within include files which
14734 also contain `#pragma interface' pragmas. */
14735 if (DECL_INITIAL (decl
) == NULL_TREE
)
14738 /* If we're a nested function, initially use a parent of NULL; if we're
14739 a plain function, this will be fixed up in decls_for_scope. If
14740 we're a method, it will be ignored, since we already have a DIE. */
14741 if (decl_function_context (decl
)
14742 /* But if we're in terse mode, we don't care about scope. */
14743 && debug_info_level
> DINFO_LEVEL_TERSE
)
14744 context_die
= NULL
;
14748 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14749 declaration and if the declaration was never even referenced from
14750 within this entire compilation unit. We suppress these DIEs in
14751 order to save space in the .debug section (by eliminating entries
14752 which are probably useless). Note that we must not suppress
14753 block-local extern declarations (whether used or not) because that
14754 would screw-up the debugger's name lookup mechanism and cause it to
14755 miss things which really ought to be in scope at a given point. */
14756 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
14759 /* For local statics lookup proper context die. */
14760 if (TREE_STATIC (decl
) && decl_function_context (decl
))
14761 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
14763 /* If we are in terse mode, don't generate any DIEs to represent any
14764 variable declarations or definitions. */
14765 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14769 case NAMESPACE_DECL
:
14770 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14772 if (lookup_decl_die (decl
) != NULL
)
14777 /* Don't emit stubs for types unless they are needed by other DIEs. */
14778 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
14781 /* Don't bother trying to generate any DIEs to represent any of the
14782 normal built-in types for the language we are compiling. */
14783 if (DECL_IS_BUILTIN (decl
))
14785 /* OK, we need to generate one for `bool' so GDB knows what type
14786 comparisons have. */
14788 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
14789 && ! DECL_IGNORED_P (decl
))
14790 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
14795 /* If we are in terse mode, don't generate any DIEs for types. */
14796 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14799 /* If we're a function-scope tag, initially use a parent of NULL;
14800 this will be fixed up in decls_for_scope. */
14801 if (decl_function_context (decl
))
14802 context_die
= NULL
;
14810 gen_decl_die (decl
, context_die
);
14813 /* Output a marker (i.e. a label) for the beginning of the generated code for
14814 a lexical block. */
14817 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
14818 unsigned int blocknum
)
14820 switch_to_section (current_function_section ());
14821 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
14824 /* Output a marker (i.e. a label) for the end of the generated code for a
14828 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
14830 switch_to_section (current_function_section ());
14831 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
14834 /* Returns nonzero if it is appropriate not to emit any debugging
14835 information for BLOCK, because it doesn't contain any instructions.
14837 Don't allow this for blocks with nested functions or local classes
14838 as we would end up with orphans, and in the presence of scheduling
14839 we may end up calling them anyway. */
14842 dwarf2out_ignore_block (const_tree block
)
14846 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
14847 if (TREE_CODE (decl
) == FUNCTION_DECL
14848 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
14854 /* Hash table routines for file_hash. */
14857 file_table_eq (const void *p1_p
, const void *p2_p
)
14859 const struct dwarf_file_data
*const p1
=
14860 (const struct dwarf_file_data
*) p1_p
;
14861 const char *const p2
= (const char *) p2_p
;
14862 return strcmp (p1
->filename
, p2
) == 0;
14866 file_table_hash (const void *p_p
)
14868 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
14869 return htab_hash_string (p
->filename
);
14872 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14873 dwarf2out.c) and return its "index". The index of each (known) filename is
14874 just a unique number which is associated with only that one filename. We
14875 need such numbers for the sake of generating labels (in the .debug_sfnames
14876 section) and references to those files numbers (in the .debug_srcinfo
14877 and.debug_macinfo sections). If the filename given as an argument is not
14878 found in our current list, add it to the list and assign it the next
14879 available unique index number. In order to speed up searches, we remember
14880 the index of the filename was looked up last. This handles the majority of
14883 static struct dwarf_file_data
*
14884 lookup_filename (const char *file_name
)
14887 struct dwarf_file_data
* created
;
14889 /* Check to see if the file name that was searched on the previous
14890 call matches this file name. If so, return the index. */
14891 if (file_table_last_lookup
14892 && (file_name
== file_table_last_lookup
->filename
14893 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
14894 return file_table_last_lookup
;
14896 /* Didn't match the previous lookup, search the table. */
14897 slot
= htab_find_slot_with_hash (file_table
, file_name
,
14898 htab_hash_string (file_name
), INSERT
);
14900 return (struct dwarf_file_data
*) *slot
;
14902 created
= GGC_NEW (struct dwarf_file_data
);
14903 created
->filename
= file_name
;
14904 created
->emitted_number
= 0;
14909 /* If the assembler will construct the file table, then translate the compiler
14910 internal file table number into the assembler file table number, and emit
14911 a .file directive if we haven't already emitted one yet. The file table
14912 numbers are different because we prune debug info for unused variables and
14913 types, which may include filenames. */
14916 maybe_emit_file (struct dwarf_file_data
* fd
)
14918 if (! fd
->emitted_number
)
14920 if (last_emitted_file
)
14921 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
14923 fd
->emitted_number
= 1;
14924 last_emitted_file
= fd
;
14926 if (DWARF2_ASM_LINE_DEBUG_INFO
)
14928 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
14929 output_quoted_string (asm_out_file
,
14930 remap_debug_filename (fd
->filename
));
14931 fputc ('\n', asm_out_file
);
14935 return fd
->emitted_number
;
14938 /* Called by the final INSN scan whenever we see a var location. We
14939 use it to drop labels in the right places, and throw the location in
14940 our lookup table. */
14943 dwarf2out_var_location (rtx loc_note
)
14945 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
14946 struct var_loc_node
*newloc
;
14948 static rtx last_insn
;
14949 static const char *last_label
;
14952 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
14954 prev_insn
= PREV_INSN (loc_note
);
14956 newloc
= GGC_CNEW (struct var_loc_node
);
14957 /* If the insn we processed last time is the previous insn
14958 and it is also a var location note, use the label we emitted
14960 if (last_insn
!= NULL_RTX
14961 && last_insn
== prev_insn
14962 && NOTE_P (prev_insn
)
14963 && NOTE_KIND (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
14965 newloc
->label
= last_label
;
14969 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
14970 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
14972 newloc
->label
= ggc_strdup (loclabel
);
14974 newloc
->var_loc_note
= loc_note
;
14975 newloc
->next
= NULL
;
14977 if (cfun
&& in_cold_section_p
)
14978 newloc
->section_label
= crtl
->subsections
.cold_section_label
;
14980 newloc
->section_label
= text_section_label
;
14982 last_insn
= loc_note
;
14983 last_label
= newloc
->label
;
14984 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
14985 add_var_loc_to_decl (decl
, newloc
);
14988 /* We need to reset the locations at the beginning of each
14989 function. We can't do this in the end_function hook, because the
14990 declarations that use the locations won't have been output when
14991 that hook is called. Also compute have_multiple_function_sections here. */
14994 dwarf2out_begin_function (tree fun
)
14996 htab_empty (decl_loc_table
);
14998 if (function_section (fun
) != text_section
)
14999 have_multiple_function_sections
= true;
15001 dwarf2out_note_section_used ();
15004 /* Output a label to mark the beginning of a source code line entry
15005 and record information relating to this source line, in
15006 'line_info_table' for later output of the .debug_line section. */
15009 dwarf2out_source_line (unsigned int line
, const char *filename
)
15011 if (debug_info_level
>= DINFO_LEVEL_NORMAL
15014 int file_num
= maybe_emit_file (lookup_filename (filename
));
15016 switch_to_section (current_function_section ());
15018 /* If requested, emit something human-readable. */
15019 if (flag_debug_asm
)
15020 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
15023 if (DWARF2_ASM_LINE_DEBUG_INFO
)
15025 /* Emit the .loc directive understood by GNU as. */
15026 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
15028 /* Indicate that line number info exists. */
15029 line_info_table_in_use
++;
15031 else if (function_section (current_function_decl
) != text_section
)
15033 dw_separate_line_info_ref line_info
;
15034 targetm
.asm_out
.internal_label (asm_out_file
,
15035 SEPARATE_LINE_CODE_LABEL
,
15036 separate_line_info_table_in_use
);
15038 /* Expand the line info table if necessary. */
15039 if (separate_line_info_table_in_use
15040 == separate_line_info_table_allocated
)
15042 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
15043 separate_line_info_table
15044 = GGC_RESIZEVEC (dw_separate_line_info_entry
,
15045 separate_line_info_table
,
15046 separate_line_info_table_allocated
);
15047 memset (separate_line_info_table
15048 + separate_line_info_table_in_use
,
15050 (LINE_INFO_TABLE_INCREMENT
15051 * sizeof (dw_separate_line_info_entry
)));
15054 /* Add the new entry at the end of the line_info_table. */
15056 = &separate_line_info_table
[separate_line_info_table_in_use
++];
15057 line_info
->dw_file_num
= file_num
;
15058 line_info
->dw_line_num
= line
;
15059 line_info
->function
= current_function_funcdef_no
;
15063 dw_line_info_ref line_info
;
15065 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
15066 line_info_table_in_use
);
15068 /* Expand the line info table if necessary. */
15069 if (line_info_table_in_use
== line_info_table_allocated
)
15071 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
15073 = GGC_RESIZEVEC (dw_line_info_entry
, line_info_table
,
15074 line_info_table_allocated
);
15075 memset (line_info_table
+ line_info_table_in_use
, 0,
15076 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
15079 /* Add the new entry at the end of the line_info_table. */
15080 line_info
= &line_info_table
[line_info_table_in_use
++];
15081 line_info
->dw_file_num
= file_num
;
15082 line_info
->dw_line_num
= line
;
15087 /* Record the beginning of a new source file. */
15090 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
15092 if (flag_eliminate_dwarf2_dups
)
15094 /* Record the beginning of the file for break_out_includes. */
15095 dw_die_ref bincl_die
;
15097 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
15098 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
15101 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15103 int file_num
= maybe_emit_file (lookup_filename (filename
));
15105 switch_to_section (debug_macinfo_section
);
15106 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
15107 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
15110 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
15114 /* Record the end of a source file. */
15117 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
15119 if (flag_eliminate_dwarf2_dups
)
15120 /* Record the end of the file for break_out_includes. */
15121 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
15123 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15125 switch_to_section (debug_macinfo_section
);
15126 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
15130 /* Called from debug_define in toplev.c. The `buffer' parameter contains
15131 the tail part of the directive line, i.e. the part which is past the
15132 initial whitespace, #, whitespace, directive-name, whitespace part. */
15135 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
15136 const char *buffer ATTRIBUTE_UNUSED
)
15138 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15140 switch_to_section (debug_macinfo_section
);
15141 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
15142 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
15143 dw2_asm_output_nstring (buffer
, -1, "The macro");
15147 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
15148 the tail part of the directive line, i.e. the part which is past the
15149 initial whitespace, #, whitespace, directive-name, whitespace part. */
15152 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
15153 const char *buffer ATTRIBUTE_UNUSED
)
15155 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15157 switch_to_section (debug_macinfo_section
);
15158 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
15159 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
15160 dw2_asm_output_nstring (buffer
, -1, "The macro");
15164 /* Set up for Dwarf output at the start of compilation. */
15167 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
15169 /* Allocate the file_table. */
15170 file_table
= htab_create_ggc (50, file_table_hash
,
15171 file_table_eq
, NULL
);
15173 /* Allocate the decl_die_table. */
15174 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
15175 decl_die_table_eq
, NULL
);
15177 /* Allocate the decl_loc_table. */
15178 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
15179 decl_loc_table_eq
, NULL
);
15181 /* Allocate the initial hunk of the decl_scope_table. */
15182 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
15184 /* Allocate the initial hunk of the abbrev_die_table. */
15185 abbrev_die_table
= GGC_CNEWVEC (dw_die_ref
, ABBREV_DIE_TABLE_INCREMENT
);
15186 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
15187 /* Zero-th entry is allocated, but unused. */
15188 abbrev_die_table_in_use
= 1;
15190 /* Allocate the initial hunk of the line_info_table. */
15191 line_info_table
= GGC_CNEWVEC (dw_line_info_entry
, LINE_INFO_TABLE_INCREMENT
);
15192 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
15194 /* Zero-th entry is allocated, but unused. */
15195 line_info_table_in_use
= 1;
15197 /* Allocate the pubtypes and pubnames vectors. */
15198 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
15199 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
15201 /* Generate the initial DIE for the .debug section. Note that the (string)
15202 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
15203 will (typically) be a relative pathname and that this pathname should be
15204 taken as being relative to the directory from which the compiler was
15205 invoked when the given (base) source file was compiled. We will fill
15206 in this value in dwarf2out_finish. */
15207 comp_unit_die
= gen_compile_unit_die (NULL
);
15209 incomplete_types
= VEC_alloc (tree
, gc
, 64);
15211 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
15213 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
15214 SECTION_DEBUG
, NULL
);
15215 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
15216 SECTION_DEBUG
, NULL
);
15217 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
15218 SECTION_DEBUG
, NULL
);
15219 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
15220 SECTION_DEBUG
, NULL
);
15221 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
15222 SECTION_DEBUG
, NULL
);
15223 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
15224 SECTION_DEBUG
, NULL
);
15225 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
15226 SECTION_DEBUG
, NULL
);
15227 #ifdef DEBUG_PUBTYPES_SECTION
15228 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
15229 SECTION_DEBUG
, NULL
);
15231 debug_str_section
= get_section (DEBUG_STR_SECTION
,
15232 DEBUG_STR_SECTION_FLAGS
, NULL
);
15233 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
15234 SECTION_DEBUG
, NULL
);
15235 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
15236 SECTION_DEBUG
, NULL
);
15238 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
15239 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
15240 DEBUG_ABBREV_SECTION_LABEL
, 0);
15241 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
15242 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
15243 COLD_TEXT_SECTION_LABEL
, 0);
15244 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
15246 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
15247 DEBUG_INFO_SECTION_LABEL
, 0);
15248 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
15249 DEBUG_LINE_SECTION_LABEL
, 0);
15250 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
15251 DEBUG_RANGES_SECTION_LABEL
, 0);
15252 switch_to_section (debug_abbrev_section
);
15253 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
15254 switch_to_section (debug_info_section
);
15255 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
15256 switch_to_section (debug_line_section
);
15257 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
15259 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15261 switch_to_section (debug_macinfo_section
);
15262 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
15263 DEBUG_MACINFO_SECTION_LABEL
, 0);
15264 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
15267 switch_to_section (text_section
);
15268 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
15269 if (flag_reorder_blocks_and_partition
)
15271 cold_text_section
= unlikely_text_section ();
15272 switch_to_section (cold_text_section
);
15273 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
15277 /* A helper function for dwarf2out_finish called through
15278 ht_forall. Emit one queued .debug_str string. */
15281 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
15283 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
15285 if (node
->form
== DW_FORM_strp
)
15287 switch_to_section (debug_str_section
);
15288 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
15289 assemble_string (node
->str
, strlen (node
->str
) + 1);
15295 #if ENABLE_ASSERT_CHECKING
15296 /* Verify that all marks are clear. */
15299 verify_marks_clear (dw_die_ref die
)
15303 gcc_assert (! die
->die_mark
);
15304 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
15306 #endif /* ENABLE_ASSERT_CHECKING */
15308 /* Clear the marks for a die and its children.
15309 Be cool if the mark isn't set. */
15312 prune_unmark_dies (dw_die_ref die
)
15318 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
15321 /* Given DIE that we're marking as used, find any other dies
15322 it references as attributes and mark them as used. */
15325 prune_unused_types_walk_attribs (dw_die_ref die
)
15330 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
15332 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
15334 /* A reference to another DIE.
15335 Make sure that it will get emitted. */
15336 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
15338 /* Set the string's refcount to 0 so that prune_unused_types_mark
15339 accounts properly for it. */
15340 if (AT_class (a
) == dw_val_class_str
)
15341 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
15346 /* Mark DIE as being used. If DOKIDS is true, then walk down
15347 to DIE's children. */
15350 prune_unused_types_mark (dw_die_ref die
, int dokids
)
15354 if (die
->die_mark
== 0)
15356 /* We haven't done this node yet. Mark it as used. */
15359 /* We also have to mark its parents as used.
15360 (But we don't want to mark our parents' kids due to this.) */
15361 if (die
->die_parent
)
15362 prune_unused_types_mark (die
->die_parent
, 0);
15364 /* Mark any referenced nodes. */
15365 prune_unused_types_walk_attribs (die
);
15367 /* If this node is a specification,
15368 also mark the definition, if it exists. */
15369 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
15370 prune_unused_types_mark (die
->die_definition
, 1);
15373 if (dokids
&& die
->die_mark
!= 2)
15375 /* We need to walk the children, but haven't done so yet.
15376 Remember that we've walked the kids. */
15379 /* If this is an array type, we need to make sure our
15380 kids get marked, even if they're types. */
15381 if (die
->die_tag
== DW_TAG_array_type
)
15382 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
15384 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
15389 /* Walk the tree DIE and mark types that we actually use. */
15392 prune_unused_types_walk (dw_die_ref die
)
15396 /* Don't do anything if this node is already marked. */
15400 switch (die
->die_tag
)
15402 case DW_TAG_const_type
:
15403 case DW_TAG_packed_type
:
15404 case DW_TAG_pointer_type
:
15405 case DW_TAG_reference_type
:
15406 case DW_TAG_volatile_type
:
15407 case DW_TAG_typedef
:
15408 case DW_TAG_array_type
:
15409 case DW_TAG_structure_type
:
15410 case DW_TAG_union_type
:
15411 case DW_TAG_class_type
:
15412 case DW_TAG_interface_type
:
15413 case DW_TAG_friend
:
15414 case DW_TAG_variant_part
:
15415 case DW_TAG_enumeration_type
:
15416 case DW_TAG_subroutine_type
:
15417 case DW_TAG_string_type
:
15418 case DW_TAG_set_type
:
15419 case DW_TAG_subrange_type
:
15420 case DW_TAG_ptr_to_member_type
:
15421 case DW_TAG_file_type
:
15422 if (die
->die_perennial_p
)
15425 /* It's a type node --- don't mark it. */
15429 /* Mark everything else. */
15435 /* Now, mark any dies referenced from here. */
15436 prune_unused_types_walk_attribs (die
);
15438 /* Mark children. */
15439 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
15442 /* Increment the string counts on strings referred to from DIE's
15446 prune_unused_types_update_strings (dw_die_ref die
)
15451 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
15452 if (AT_class (a
) == dw_val_class_str
)
15454 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
15456 /* Avoid unnecessarily putting strings that are used less than
15457 twice in the hash table. */
15459 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
15462 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
15463 htab_hash_string (s
->str
),
15465 gcc_assert (*slot
== NULL
);
15471 /* Remove from the tree DIE any dies that aren't marked. */
15474 prune_unused_types_prune (dw_die_ref die
)
15478 gcc_assert (die
->die_mark
);
15479 prune_unused_types_update_strings (die
);
15481 if (! die
->die_child
)
15484 c
= die
->die_child
;
15486 dw_die_ref prev
= c
;
15487 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
15488 if (c
== die
->die_child
)
15490 /* No marked children between 'prev' and the end of the list. */
15492 /* No marked children at all. */
15493 die
->die_child
= NULL
;
15496 prev
->die_sib
= c
->die_sib
;
15497 die
->die_child
= prev
;
15502 if (c
!= prev
->die_sib
)
15504 prune_unused_types_prune (c
);
15505 } while (c
!= die
->die_child
);
15509 /* Remove dies representing declarations that we never use. */
15512 prune_unused_types (void)
15515 limbo_die_node
*node
;
15518 #if ENABLE_ASSERT_CHECKING
15519 /* All the marks should already be clear. */
15520 verify_marks_clear (comp_unit_die
);
15521 for (node
= limbo_die_list
; node
; node
= node
->next
)
15522 verify_marks_clear (node
->die
);
15523 #endif /* ENABLE_ASSERT_CHECKING */
15525 /* Set the mark on nodes that are actually used. */
15526 prune_unused_types_walk (comp_unit_die
);
15527 for (node
= limbo_die_list
; node
; node
= node
->next
)
15528 prune_unused_types_walk (node
->die
);
15530 /* Also set the mark on nodes referenced from the
15531 pubname_table or arange_table. */
15532 for (i
= 0; VEC_iterate (pubname_entry
, pubname_table
, i
, pub
); i
++)
15533 prune_unused_types_mark (pub
->die
, 1);
15534 for (i
= 0; i
< arange_table_in_use
; i
++)
15535 prune_unused_types_mark (arange_table
[i
], 1);
15537 /* Get rid of nodes that aren't marked; and update the string counts. */
15538 if (debug_str_hash
)
15539 htab_empty (debug_str_hash
);
15540 prune_unused_types_prune (comp_unit_die
);
15541 for (node
= limbo_die_list
; node
; node
= node
->next
)
15542 prune_unused_types_prune (node
->die
);
15544 /* Leave the marks clear. */
15545 prune_unmark_dies (comp_unit_die
);
15546 for (node
= limbo_die_list
; node
; node
= node
->next
)
15547 prune_unmark_dies (node
->die
);
15550 /* Set the parameter to true if there are any relative pathnames in
15553 file_table_relative_p (void ** slot
, void *param
)
15555 bool *p
= (bool *) param
;
15556 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
15557 if (!IS_ABSOLUTE_PATH (d
->filename
))
15565 /* Output stuff that dwarf requires at the end of every file,
15566 and generate the DWARF-2 debugging info. */
15569 dwarf2out_finish (const char *filename
)
15571 limbo_die_node
*node
, *next_node
;
15572 dw_die_ref die
= 0;
15574 /* Add the name for the main input file now. We delayed this from
15575 dwarf2out_init to avoid complications with PCH. */
15576 add_name_attribute (comp_unit_die
, remap_debug_filename (filename
));
15577 if (!IS_ABSOLUTE_PATH (filename
))
15578 add_comp_dir_attribute (comp_unit_die
);
15579 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
15582 htab_traverse (file_table
, file_table_relative_p
, &p
);
15584 add_comp_dir_attribute (comp_unit_die
);
15587 /* Traverse the limbo die list, and add parent/child links. The only
15588 dies without parents that should be here are concrete instances of
15589 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
15590 For concrete instances, we can get the parent die from the abstract
15592 for (node
= limbo_die_list
; node
; node
= next_node
)
15594 next_node
= node
->next
;
15597 if (die
->die_parent
== NULL
)
15599 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
15602 add_child_die (origin
->die_parent
, die
);
15603 else if (die
== comp_unit_die
)
15605 else if (errorcount
> 0 || sorrycount
> 0)
15606 /* It's OK to be confused by errors in the input. */
15607 add_child_die (comp_unit_die
, die
);
15610 /* In certain situations, the lexical block containing a
15611 nested function can be optimized away, which results
15612 in the nested function die being orphaned. Likewise
15613 with the return type of that nested function. Force
15614 this to be a child of the containing function.
15616 It may happen that even the containing function got fully
15617 inlined and optimized out. In that case we are lost and
15618 assign the empty child. This should not be big issue as
15619 the function is likely unreachable too. */
15620 tree context
= NULL_TREE
;
15622 gcc_assert (node
->created_for
);
15624 if (DECL_P (node
->created_for
))
15625 context
= DECL_CONTEXT (node
->created_for
);
15626 else if (TYPE_P (node
->created_for
))
15627 context
= TYPE_CONTEXT (node
->created_for
);
15629 gcc_assert (context
15630 && (TREE_CODE (context
) == FUNCTION_DECL
15631 || TREE_CODE (context
) == NAMESPACE_DECL
));
15633 origin
= lookup_decl_die (context
);
15635 add_child_die (origin
, die
);
15637 add_child_die (comp_unit_die
, die
);
15642 limbo_die_list
= NULL
;
15644 /* Walk through the list of incomplete types again, trying once more to
15645 emit full debugging info for them. */
15646 retry_incomplete_types ();
15648 if (flag_eliminate_unused_debug_types
)
15649 prune_unused_types ();
15651 /* Generate separate CUs for each of the include files we've seen.
15652 They will go into limbo_die_list. */
15653 if (flag_eliminate_dwarf2_dups
)
15654 break_out_includes (comp_unit_die
);
15656 /* Traverse the DIE's and add add sibling attributes to those DIE's
15657 that have children. */
15658 add_sibling_attributes (comp_unit_die
);
15659 for (node
= limbo_die_list
; node
; node
= node
->next
)
15660 add_sibling_attributes (node
->die
);
15662 /* Output a terminator label for the .text section. */
15663 switch_to_section (text_section
);
15664 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
15665 if (flag_reorder_blocks_and_partition
)
15667 switch_to_section (unlikely_text_section ());
15668 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
15671 /* We can only use the low/high_pc attributes if all of the code was
15673 if (!have_multiple_function_sections
)
15675 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
15676 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
15681 unsigned fde_idx
= 0;
15683 /* We need to give .debug_loc and .debug_ranges an appropriate
15684 "base address". Use zero so that these addresses become
15685 absolute. Historically, we've emitted the unexpected
15686 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15687 Emit both to give time for other tools to adapt. */
15688 add_AT_addr (comp_unit_die
, DW_AT_low_pc
, const0_rtx
);
15689 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
15691 add_AT_range_list (comp_unit_die
, DW_AT_ranges
,
15692 add_ranges_by_labels (text_section_label
,
15694 if (flag_reorder_blocks_and_partition
)
15695 add_ranges_by_labels (cold_text_section_label
,
15698 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
15700 dw_fde_ref fde
= &fde_table
[fde_idx
];
15702 if (fde
->dw_fde_switched_sections
)
15704 add_ranges_by_labels (fde
->dw_fde_hot_section_label
,
15705 fde
->dw_fde_hot_section_end_label
);
15706 add_ranges_by_labels (fde
->dw_fde_unlikely_section_label
,
15707 fde
->dw_fde_unlikely_section_end_label
);
15710 add_ranges_by_labels (fde
->dw_fde_begin
,
15717 /* Output location list section if necessary. */
15718 if (have_location_lists
)
15720 /* Output the location lists info. */
15721 switch_to_section (debug_loc_section
);
15722 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
15723 DEBUG_LOC_SECTION_LABEL
, 0);
15724 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
15725 output_location_lists (die
);
15728 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
15729 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
15730 debug_line_section_label
);
15732 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15733 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
15735 /* Output all of the compilation units. We put the main one last so that
15736 the offsets are available to output_pubnames. */
15737 for (node
= limbo_die_list
; node
; node
= node
->next
)
15738 output_comp_unit (node
->die
, 0);
15740 output_comp_unit (comp_unit_die
, 0);
15742 /* Output the abbreviation table. */
15743 switch_to_section (debug_abbrev_section
);
15744 output_abbrev_section ();
15746 /* Output public names table if necessary. */
15747 if (!VEC_empty (pubname_entry
, pubname_table
))
15749 switch_to_section (debug_pubnames_section
);
15750 output_pubnames (pubname_table
);
15753 #ifdef DEBUG_PUBTYPES_SECTION
15754 /* Output public types table if necessary. */
15755 if (!VEC_empty (pubname_entry
, pubtype_table
))
15757 switch_to_section (debug_pubtypes_section
);
15758 output_pubnames (pubtype_table
);
15762 /* Output the address range information. We only put functions in the arange
15763 table, so don't write it out if we don't have any. */
15764 if (fde_table_in_use
)
15766 switch_to_section (debug_aranges_section
);
15770 /* Output ranges section if necessary. */
15771 if (ranges_table_in_use
)
15773 switch_to_section (debug_ranges_section
);
15774 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
15778 /* Output the source line correspondence table. We must do this
15779 even if there is no line information. Otherwise, on an empty
15780 translation unit, we will generate a present, but empty,
15781 .debug_info section. IRIX 6.5 `nm' will then complain when
15782 examining the file. This is done late so that any filenames
15783 used by the debug_info section are marked as 'used'. */
15784 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
15786 switch_to_section (debug_line_section
);
15787 output_line_info ();
15790 /* Have to end the macro section. */
15791 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15793 switch_to_section (debug_macinfo_section
);
15794 dw2_asm_output_data (1, 0, "End compilation unit");
15797 /* If we emitted any DW_FORM_strp form attribute, output the string
15799 if (debug_str_hash
)
15800 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
15804 /* This should never be used, but its address is needed for comparisons. */
15805 const struct gcc_debug_hooks dwarf2_debug_hooks
;
15807 #endif /* DWARF2_DEBUGGING_INFO */
15809 #include "gt-dwarf2out.h"