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 unsigned all_throwers_are_sibcalls
: 1;
243 unsigned nothrow
: 1;
244 unsigned uses_eh_lsda
: 1;
248 /* Maximum size (in bytes) of an artificially generated label. */
249 #define MAX_ARTIFICIAL_LABEL_BYTES 30
251 /* The size of addresses as they appear in the Dwarf 2 data.
252 Some architectures use word addresses to refer to code locations,
253 but Dwarf 2 info always uses byte addresses. On such machines,
254 Dwarf 2 addresses need to be larger than the architecture's
256 #ifndef DWARF2_ADDR_SIZE
257 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
260 /* The size in bytes of a DWARF field indicating an offset or length
261 relative to a debug info section, specified to be 4 bytes in the
262 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
265 #ifndef DWARF_OFFSET_SIZE
266 #define DWARF_OFFSET_SIZE 4
269 /* According to the (draft) DWARF 3 specification, the initial length
270 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
271 bytes are 0xffffffff, followed by the length stored in the next 8
274 However, the SGI/MIPS ABI uses an initial length which is equal to
275 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
277 #ifndef DWARF_INITIAL_LENGTH_SIZE
278 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
281 #define DWARF_VERSION 2
283 /* Round SIZE up to the nearest BOUNDARY. */
284 #define DWARF_ROUND(SIZE,BOUNDARY) \
285 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
287 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
288 #ifndef DWARF_CIE_DATA_ALIGNMENT
289 #ifdef STACK_GROWS_DOWNWARD
290 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
292 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
296 /* CIE identifier. */
297 #if HOST_BITS_PER_WIDE_INT >= 64
298 #define DWARF_CIE_ID \
299 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
301 #define DWARF_CIE_ID DW_CIE_ID
304 /* A pointer to the base of a table that contains frame description
305 information for each routine. */
306 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
308 /* Number of elements currently allocated for fde_table. */
309 static GTY(()) unsigned fde_table_allocated
;
311 /* Number of elements in fde_table currently in use. */
312 static GTY(()) unsigned fde_table_in_use
;
314 /* Size (in elements) of increments by which we may expand the
316 #define FDE_TABLE_INCREMENT 256
318 /* A list of call frame insns for the CIE. */
319 static GTY(()) dw_cfi_ref cie_cfi_head
;
321 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
322 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
323 attribute that accelerates the lookup of the FDE associated
324 with the subprogram. This variable holds the table index of the FDE
325 associated with the current function (body) definition. */
326 static unsigned current_funcdef_fde
;
329 struct indirect_string_node
GTY(())
332 unsigned int refcount
;
337 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
339 static GTY(()) int dw2_string_counter
;
340 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
342 /* True if the compilation unit places functions in more than one section. */
343 static GTY(()) bool have_multiple_function_sections
= false;
345 /* Whether the default text and cold text sections have been used at all. */
347 static GTY(()) bool text_section_used
= false;
348 static GTY(()) bool cold_text_section_used
= false;
350 /* The default cold text section. */
351 static GTY(()) section
*cold_text_section
;
353 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
355 /* Forward declarations for functions defined in this file. */
357 static char *stripattributes (const char *);
358 static const char *dwarf_cfi_name (unsigned);
359 static dw_cfi_ref
new_cfi (void);
360 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
361 static void add_fde_cfi (const char *, dw_cfi_ref
);
362 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
363 static void lookup_cfa (dw_cfa_location
*);
364 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
365 #ifdef DWARF2_UNWIND_INFO
366 static void initial_return_save (rtx
);
368 static HOST_WIDE_INT
stack_adjust_offset (const_rtx
);
369 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
370 static void output_call_frame_info (int);
371 static void dwarf2out_note_section_used (void);
372 static void dwarf2out_stack_adjust (rtx
, bool);
373 static void flush_queued_reg_saves (void);
374 static bool clobbers_queued_reg_save (const_rtx
);
375 static void dwarf2out_frame_debug_expr (rtx
, const char *);
377 /* Support for complex CFA locations. */
378 static void output_cfa_loc (dw_cfi_ref
);
379 static void get_cfa_from_loc_descr (dw_cfa_location
*,
380 struct dw_loc_descr_struct
*);
381 static struct dw_loc_descr_struct
*build_cfa_loc
382 (dw_cfa_location
*, HOST_WIDE_INT
);
383 static void def_cfa_1 (const char *, dw_cfa_location
*);
385 /* How to start an assembler comment. */
386 #ifndef ASM_COMMENT_START
387 #define ASM_COMMENT_START ";#"
390 /* Data and reference forms for relocatable data. */
391 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
392 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
394 #ifndef DEBUG_FRAME_SECTION
395 #define DEBUG_FRAME_SECTION ".debug_frame"
398 #ifndef FUNC_BEGIN_LABEL
399 #define FUNC_BEGIN_LABEL "LFB"
402 #ifndef FUNC_END_LABEL
403 #define FUNC_END_LABEL "LFE"
406 #ifndef FRAME_BEGIN_LABEL
407 #define FRAME_BEGIN_LABEL "Lframe"
409 #define CIE_AFTER_SIZE_LABEL "LSCIE"
410 #define CIE_END_LABEL "LECIE"
411 #define FDE_LABEL "LSFDE"
412 #define FDE_AFTER_SIZE_LABEL "LASFDE"
413 #define FDE_END_LABEL "LEFDE"
414 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
415 #define LINE_NUMBER_END_LABEL "LELT"
416 #define LN_PROLOG_AS_LABEL "LASLTP"
417 #define LN_PROLOG_END_LABEL "LELTP"
418 #define DIE_LABEL_PREFIX "DW"
420 /* The DWARF 2 CFA column which tracks the return address. Normally this
421 is the column for PC, or the first column after all of the hard
423 #ifndef DWARF_FRAME_RETURN_COLUMN
425 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
427 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
431 /* The mapping from gcc register number to DWARF 2 CFA column number. By
432 default, we just provide columns for all registers. */
433 #ifndef DWARF_FRAME_REGNUM
434 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
437 /* Hook used by __throw. */
440 expand_builtin_dwarf_sp_column (void)
442 unsigned int dwarf_regnum
= DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
);
443 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum
, 1));
446 /* Return a pointer to a copy of the section string name S with all
447 attributes stripped off, and an asterisk prepended (for assemble_name). */
450 stripattributes (const char *s
)
452 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
457 while (*s
&& *s
!= ',')
464 /* MEM is a memory reference for the register size table, each element of
465 which has mode MODE. Initialize column C as a return address column. */
468 init_return_column_size (enum machine_mode mode
, rtx mem
, unsigned int c
)
470 HOST_WIDE_INT offset
= c
* GET_MODE_SIZE (mode
);
471 HOST_WIDE_INT size
= GET_MODE_SIZE (Pmode
);
472 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
475 /* Generate code to initialize the register size table. */
478 expand_builtin_init_dwarf_reg_sizes (tree address
)
481 enum machine_mode mode
= TYPE_MODE (char_type_node
);
482 rtx addr
= expand_normal (address
);
483 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
484 bool wrote_return_column
= false;
486 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
488 int rnum
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i
), 1);
490 if (rnum
< DWARF_FRAME_REGISTERS
)
492 HOST_WIDE_INT offset
= rnum
* GET_MODE_SIZE (mode
);
493 enum machine_mode save_mode
= reg_raw_mode
[i
];
496 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
497 save_mode
= choose_hard_reg_mode (i
, 1, true);
498 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
500 if (save_mode
== VOIDmode
)
502 wrote_return_column
= true;
504 size
= GET_MODE_SIZE (save_mode
);
508 emit_move_insn (adjust_address (mem
, mode
, offset
),
509 gen_int_mode (size
, mode
));
513 if (!wrote_return_column
)
514 init_return_column_size (mode
, mem
, DWARF_FRAME_RETURN_COLUMN
);
516 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
517 init_return_column_size (mode
, mem
, DWARF_ALT_FRAME_RETURN_COLUMN
);
520 targetm
.init_dwarf_reg_sizes_extra (address
);
523 /* Convert a DWARF call frame info. operation to its string name */
526 dwarf_cfi_name (unsigned int cfi_opc
)
530 case DW_CFA_advance_loc
:
531 return "DW_CFA_advance_loc";
533 return "DW_CFA_offset";
535 return "DW_CFA_restore";
539 return "DW_CFA_set_loc";
540 case DW_CFA_advance_loc1
:
541 return "DW_CFA_advance_loc1";
542 case DW_CFA_advance_loc2
:
543 return "DW_CFA_advance_loc2";
544 case DW_CFA_advance_loc4
:
545 return "DW_CFA_advance_loc4";
546 case DW_CFA_offset_extended
:
547 return "DW_CFA_offset_extended";
548 case DW_CFA_restore_extended
:
549 return "DW_CFA_restore_extended";
550 case DW_CFA_undefined
:
551 return "DW_CFA_undefined";
552 case DW_CFA_same_value
:
553 return "DW_CFA_same_value";
554 case DW_CFA_register
:
555 return "DW_CFA_register";
556 case DW_CFA_remember_state
:
557 return "DW_CFA_remember_state";
558 case DW_CFA_restore_state
:
559 return "DW_CFA_restore_state";
561 return "DW_CFA_def_cfa";
562 case DW_CFA_def_cfa_register
:
563 return "DW_CFA_def_cfa_register";
564 case DW_CFA_def_cfa_offset
:
565 return "DW_CFA_def_cfa_offset";
568 case DW_CFA_def_cfa_expression
:
569 return "DW_CFA_def_cfa_expression";
570 case DW_CFA_expression
:
571 return "DW_CFA_expression";
572 case DW_CFA_offset_extended_sf
:
573 return "DW_CFA_offset_extended_sf";
574 case DW_CFA_def_cfa_sf
:
575 return "DW_CFA_def_cfa_sf";
576 case DW_CFA_def_cfa_offset_sf
:
577 return "DW_CFA_def_cfa_offset_sf";
579 /* SGI/MIPS specific */
580 case DW_CFA_MIPS_advance_loc8
:
581 return "DW_CFA_MIPS_advance_loc8";
584 case DW_CFA_GNU_window_save
:
585 return "DW_CFA_GNU_window_save";
586 case DW_CFA_GNU_args_size
:
587 return "DW_CFA_GNU_args_size";
588 case DW_CFA_GNU_negative_offset_extended
:
589 return "DW_CFA_GNU_negative_offset_extended";
592 return "DW_CFA_<unknown>";
596 /* Return a pointer to a newly allocated Call Frame Instruction. */
598 static inline dw_cfi_ref
601 dw_cfi_ref cfi
= ggc_alloc (sizeof (dw_cfi_node
));
603 cfi
->dw_cfi_next
= NULL
;
604 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
605 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
610 /* Add a Call Frame Instruction to list of instructions. */
613 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
617 /* Find the end of the chain. */
618 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
624 /* Generate a new label for the CFI info to refer to. */
627 dwarf2out_cfi_label (void)
629 static char label
[20];
631 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
632 ASM_OUTPUT_LABEL (asm_out_file
, label
);
636 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
637 or to the CIE if LABEL is NULL. */
640 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
644 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
647 label
= dwarf2out_cfi_label ();
649 if (fde
->dw_fde_current_label
== NULL
650 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
654 label
= xstrdup (label
);
656 /* Set the location counter to the new label. */
658 /* If we have a current label, advance from there, otherwise
659 set the location directly using set_loc. */
660 xcfi
->dw_cfi_opc
= fde
->dw_fde_current_label
661 ? DW_CFA_advance_loc4
663 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
664 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
666 fde
->dw_fde_current_label
= label
;
669 add_cfi (&fde
->dw_fde_cfi
, cfi
);
673 add_cfi (&cie_cfi_head
, cfi
);
676 /* Subroutine of lookup_cfa. */
679 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
681 switch (cfi
->dw_cfi_opc
)
683 case DW_CFA_def_cfa_offset
:
684 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
686 case DW_CFA_def_cfa_offset_sf
:
688 = cfi
->dw_cfi_oprnd1
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
690 case DW_CFA_def_cfa_register
:
691 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
694 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
695 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
697 case DW_CFA_def_cfa_sf
:
698 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
700 = cfi
->dw_cfi_oprnd2
.dw_cfi_offset
* DWARF_CIE_DATA_ALIGNMENT
;
702 case DW_CFA_def_cfa_expression
:
703 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
710 /* Find the previous value for the CFA. */
713 lookup_cfa (dw_cfa_location
*loc
)
717 loc
->reg
= INVALID_REGNUM
;
720 loc
->base_offset
= 0;
722 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
723 lookup_cfa_1 (cfi
, loc
);
725 if (fde_table_in_use
)
727 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
728 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
729 lookup_cfa_1 (cfi
, loc
);
733 /* The current rule for calculating the DWARF2 canonical frame address. */
734 static dw_cfa_location cfa
;
736 /* The register used for saving registers to the stack, and its offset
738 static dw_cfa_location cfa_store
;
740 /* The running total of the size of arguments pushed onto the stack. */
741 static HOST_WIDE_INT args_size
;
743 /* The last args_size we actually output. */
744 static HOST_WIDE_INT old_args_size
;
746 /* Entry point to update the canonical frame address (CFA).
747 LABEL is passed to add_fde_cfi. The value of CFA is now to be
748 calculated from REG+OFFSET. */
751 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
758 def_cfa_1 (label
, &loc
);
761 /* Determine if two dw_cfa_location structures define the same data. */
764 cfa_equal_p (const dw_cfa_location
*loc1
, const dw_cfa_location
*loc2
)
766 return (loc1
->reg
== loc2
->reg
767 && loc1
->offset
== loc2
->offset
768 && loc1
->indirect
== loc2
->indirect
769 && (loc1
->indirect
== 0
770 || loc1
->base_offset
== loc2
->base_offset
));
773 /* This routine does the actual work. The CFA is now calculated from
774 the dw_cfa_location structure. */
777 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
780 dw_cfa_location old_cfa
, loc
;
785 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
786 cfa_store
.offset
= loc
.offset
;
788 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
789 lookup_cfa (&old_cfa
);
791 /* If nothing changed, no need to issue any call frame instructions. */
792 if (cfa_equal_p (&loc
, &old_cfa
))
797 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
799 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
800 the CFA register did not change but the offset did. */
803 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
804 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
806 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset_sf
;
807 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= f_offset
;
811 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
812 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
816 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
817 else if (loc
.offset
== old_cfa
.offset
818 && old_cfa
.reg
!= INVALID_REGNUM
821 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
822 indicating the CFA register has changed to <register> but the
823 offset has not changed. */
824 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
825 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
829 else if (loc
.indirect
== 0)
831 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
832 indicating the CFA register has changed to <register> with
833 the specified offset. */
836 HOST_WIDE_INT f_offset
= loc
.offset
/ DWARF_CIE_DATA_ALIGNMENT
;
837 gcc_assert (f_offset
* DWARF_CIE_DATA_ALIGNMENT
== loc
.offset
);
839 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_sf
;
840 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
841 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= f_offset
;
845 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
846 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
847 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
852 /* Construct a DW_CFA_def_cfa_expression instruction to
853 calculate the CFA using a full location expression since no
854 register-offset pair is available. */
855 struct dw_loc_descr_struct
*loc_list
;
857 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
858 loc_list
= build_cfa_loc (&loc
, 0);
859 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
862 add_fde_cfi (label
, cfi
);
865 /* Add the CFI for saving a register. REG is the CFA column number.
866 LABEL is passed to add_fde_cfi.
867 If SREG is -1, the register is saved at OFFSET from the CFA;
868 otherwise it is saved in SREG. */
871 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
873 dw_cfi_ref cfi
= new_cfi ();
875 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
877 if (sreg
== INVALID_REGNUM
)
880 /* The register number won't fit in 6 bits, so we have to use
882 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
884 cfi
->dw_cfi_opc
= DW_CFA_offset
;
886 #ifdef ENABLE_CHECKING
888 /* If we get an offset that is not a multiple of
889 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
890 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
892 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
894 gcc_assert (check_offset
* DWARF_CIE_DATA_ALIGNMENT
== offset
);
897 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
899 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
901 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
903 else if (sreg
== reg
)
904 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
907 cfi
->dw_cfi_opc
= DW_CFA_register
;
908 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
911 add_fde_cfi (label
, cfi
);
914 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
915 This CFI tells the unwinder that it needs to restore the window registers
916 from the previous frame's window save area.
918 ??? Perhaps we should note in the CIE where windows are saved (instead of
919 assuming 0(cfa)) and what registers are in the window. */
922 dwarf2out_window_save (const char *label
)
924 dw_cfi_ref cfi
= new_cfi ();
926 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
927 add_fde_cfi (label
, cfi
);
930 /* Add a CFI to update the running total of the size of arguments
931 pushed onto the stack. */
934 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
938 if (size
== old_args_size
)
941 old_args_size
= size
;
944 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
945 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
946 add_fde_cfi (label
, cfi
);
949 /* Entry point for saving a register to the stack. REG is the GCC register
950 number. LABEL and OFFSET are passed to reg_save. */
953 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
955 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
958 /* Entry point for saving the return address in the stack.
959 LABEL and OFFSET are passed to reg_save. */
962 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
964 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
967 /* Entry point for saving the return address in a register.
968 LABEL and SREG are passed to reg_save. */
971 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
973 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
976 #ifdef DWARF2_UNWIND_INFO
977 /* Record the initial position of the return address. RTL is
978 INCOMING_RETURN_ADDR_RTX. */
981 initial_return_save (rtx rtl
)
983 unsigned int reg
= INVALID_REGNUM
;
984 HOST_WIDE_INT offset
= 0;
986 switch (GET_CODE (rtl
))
989 /* RA is in a register. */
990 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
994 /* RA is on the stack. */
996 switch (GET_CODE (rtl
))
999 gcc_assert (REGNO (rtl
) == STACK_POINTER_REGNUM
);
1004 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1005 offset
= INTVAL (XEXP (rtl
, 1));
1009 gcc_assert (REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
);
1010 offset
= -INTVAL (XEXP (rtl
, 1));
1020 /* The return address is at some offset from any value we can
1021 actually load. For instance, on the SPARC it is in %i7+8. Just
1022 ignore the offset for now; it doesn't matter for unwinding frames. */
1023 gcc_assert (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
);
1024 initial_return_save (XEXP (rtl
, 0));
1031 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
1032 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
1036 /* Given a SET, calculate the amount of stack adjustment it
1039 static HOST_WIDE_INT
1040 stack_adjust_offset (const_rtx pattern
)
1042 const_rtx src
= SET_SRC (pattern
);
1043 const_rtx dest
= SET_DEST (pattern
);
1044 HOST_WIDE_INT offset
= 0;
1047 if (dest
== stack_pointer_rtx
)
1049 /* (set (reg sp) (plus (reg sp) (const_int))) */
1050 code
= GET_CODE (src
);
1051 if (! (code
== PLUS
|| code
== MINUS
)
1052 || XEXP (src
, 0) != stack_pointer_rtx
1053 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1056 offset
= INTVAL (XEXP (src
, 1));
1060 else if (MEM_P (dest
))
1062 /* (set (mem (pre_dec (reg sp))) (foo)) */
1063 src
= XEXP (dest
, 0);
1064 code
= GET_CODE (src
);
1070 if (XEXP (src
, 0) == stack_pointer_rtx
)
1072 rtx val
= XEXP (XEXP (src
, 1), 1);
1073 /* We handle only adjustments by constant amount. */
1074 gcc_assert (GET_CODE (XEXP (src
, 1)) == PLUS
1075 && GET_CODE (val
) == CONST_INT
);
1076 offset
= -INTVAL (val
);
1083 if (XEXP (src
, 0) == stack_pointer_rtx
)
1085 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1092 if (XEXP (src
, 0) == stack_pointer_rtx
)
1094 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1109 /* Check INSN to see if it looks like a push or a stack adjustment, and
1110 make a note of it if it does. EH uses this information to find out how
1111 much extra space it needs to pop off the stack. */
1114 dwarf2out_stack_adjust (rtx insn
, bool after_p
)
1116 HOST_WIDE_INT offset
;
1120 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1121 with this function. Proper support would require all frame-related
1122 insns to be marked, and to be able to handle saving state around
1123 epilogues textually in the middle of the function. */
1124 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1127 /* If only calls can throw, and we have a frame pointer,
1128 save up adjustments until we see the CALL_INSN. */
1129 if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1131 if (CALL_P (insn
) && !after_p
)
1133 /* Extract the size of the args from the CALL rtx itself. */
1134 insn
= PATTERN (insn
);
1135 if (GET_CODE (insn
) == PARALLEL
)
1136 insn
= XVECEXP (insn
, 0, 0);
1137 if (GET_CODE (insn
) == SET
)
1138 insn
= SET_SRC (insn
);
1139 gcc_assert (GET_CODE (insn
) == CALL
);
1140 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1145 if (CALL_P (insn
) && !after_p
)
1147 if (!flag_asynchronous_unwind_tables
)
1148 dwarf2out_args_size ("", args_size
);
1151 else if (BARRIER_P (insn
))
1153 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1154 the compiler will have already emitted a stack adjustment, but
1155 doesn't bother for calls to noreturn functions. */
1156 #ifdef STACK_GROWS_DOWNWARD
1157 offset
= -args_size
;
1162 else if (GET_CODE (PATTERN (insn
)) == SET
)
1163 offset
= stack_adjust_offset (PATTERN (insn
));
1164 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1165 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1167 /* There may be stack adjustments inside compound insns. Search
1169 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1170 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1171 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1179 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1180 cfa
.offset
+= offset
;
1182 #ifndef STACK_GROWS_DOWNWARD
1186 args_size
+= offset
;
1190 label
= dwarf2out_cfi_label ();
1191 def_cfa_1 (label
, &cfa
);
1192 if (flag_asynchronous_unwind_tables
)
1193 dwarf2out_args_size (label
, args_size
);
1198 /* We delay emitting a register save until either (a) we reach the end
1199 of the prologue or (b) the register is clobbered. This clusters
1200 register saves so that there are fewer pc advances. */
1202 struct queued_reg_save
GTY(())
1204 struct queued_reg_save
*next
;
1206 HOST_WIDE_INT cfa_offset
;
1210 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1212 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1213 struct reg_saved_in_data
GTY(()) {
1218 /* A list of registers saved in other registers.
1219 The list intentionally has a small maximum capacity of 4; if your
1220 port needs more than that, you might consider implementing a
1221 more efficient data structure. */
1222 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1223 static GTY(()) size_t num_regs_saved_in_regs
;
1225 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1226 static const char *last_reg_save_label
;
1228 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1229 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1232 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1234 struct queued_reg_save
*q
;
1236 /* Duplicates waste space, but it's also necessary to remove them
1237 for correctness, since the queue gets output in reverse
1239 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1240 if (REGNO (q
->reg
) == REGNO (reg
))
1245 q
= ggc_alloc (sizeof (*q
));
1246 q
->next
= queued_reg_saves
;
1247 queued_reg_saves
= q
;
1251 q
->cfa_offset
= offset
;
1252 q
->saved_reg
= sreg
;
1254 last_reg_save_label
= label
;
1257 /* Output all the entries in QUEUED_REG_SAVES. */
1260 flush_queued_reg_saves (void)
1262 struct queued_reg_save
*q
;
1264 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1267 unsigned int reg
, sreg
;
1269 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1270 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1272 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1274 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1275 num_regs_saved_in_regs
++;
1277 if (i
!= num_regs_saved_in_regs
)
1279 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1280 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1283 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1285 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1287 sreg
= INVALID_REGNUM
;
1288 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1291 queued_reg_saves
= NULL
;
1292 last_reg_save_label
= NULL
;
1295 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1296 location for? Or, does it clobber a register which we've previously
1297 said that some other register is saved in, and for which we now
1298 have a new location for? */
1301 clobbers_queued_reg_save (const_rtx insn
)
1303 struct queued_reg_save
*q
;
1305 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1308 if (modified_in_p (q
->reg
, insn
))
1310 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1311 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1312 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1319 /* Entry point for saving the first register into the second. */
1322 dwarf2out_reg_save_reg (const char *label
, rtx reg
, rtx sreg
)
1325 unsigned int regno
, sregno
;
1327 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1328 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (reg
))
1330 if (i
== num_regs_saved_in_regs
)
1332 gcc_assert (i
!= ARRAY_SIZE (regs_saved_in_regs
));
1333 num_regs_saved_in_regs
++;
1335 regs_saved_in_regs
[i
].orig_reg
= reg
;
1336 regs_saved_in_regs
[i
].saved_in_reg
= sreg
;
1338 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
1339 sregno
= DWARF_FRAME_REGNUM (REGNO (sreg
));
1340 reg_save (label
, regno
, sregno
, 0);
1343 /* What register, if any, is currently saved in REG? */
1346 reg_saved_in (rtx reg
)
1348 unsigned int regn
= REGNO (reg
);
1350 struct queued_reg_save
*q
;
1352 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1353 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1356 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1357 if (regs_saved_in_regs
[i
].saved_in_reg
1358 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1359 return regs_saved_in_regs
[i
].orig_reg
;
1365 /* A temporary register holding an integral value used in adjusting SP
1366 or setting up the store_reg. The "offset" field holds the integer
1367 value, not an offset. */
1368 static dw_cfa_location cfa_temp
;
1370 /* Record call frame debugging information for an expression EXPR,
1371 which either sets SP or FP (adjusting how we calculate the frame
1372 address) or saves a register to the stack or another register.
1373 LABEL indicates the address of EXPR.
1375 This function encodes a state machine mapping rtxes to actions on
1376 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1377 users need not read the source code.
1379 The High-Level Picture
1381 Changes in the register we use to calculate the CFA: Currently we
1382 assume that if you copy the CFA register into another register, we
1383 should take the other one as the new CFA register; this seems to
1384 work pretty well. If it's wrong for some target, it's simple
1385 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1387 Changes in the register we use for saving registers to the stack:
1388 This is usually SP, but not always. Again, we deduce that if you
1389 copy SP into another register (and SP is not the CFA register),
1390 then the new register is the one we will be using for register
1391 saves. This also seems to work.
1393 Register saves: There's not much guesswork about this one; if
1394 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1395 register save, and the register used to calculate the destination
1396 had better be the one we think we're using for this purpose.
1397 It's also assumed that a copy from a call-saved register to another
1398 register is saving that register if RTX_FRAME_RELATED_P is set on
1399 that instruction. If the copy is from a call-saved register to
1400 the *same* register, that means that the register is now the same
1401 value as in the caller.
1403 Except: If the register being saved is the CFA register, and the
1404 offset is nonzero, we are saving the CFA, so we assume we have to
1405 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1406 the intent is to save the value of SP from the previous frame.
1408 In addition, if a register has previously been saved to a different
1411 Invariants / Summaries of Rules
1413 cfa current rule for calculating the CFA. It usually
1414 consists of a register and an offset.
1415 cfa_store register used by prologue code to save things to the stack
1416 cfa_store.offset is the offset from the value of
1417 cfa_store.reg to the actual CFA
1418 cfa_temp register holding an integral value. cfa_temp.offset
1419 stores the value, which will be used to adjust the
1420 stack pointer. cfa_temp is also used like cfa_store,
1421 to track stores to the stack via fp or a temp reg.
1423 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1424 with cfa.reg as the first operand changes the cfa.reg and its
1425 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1428 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1429 expression yielding a constant. This sets cfa_temp.reg
1430 and cfa_temp.offset.
1432 Rule 5: Create a new register cfa_store used to save items to the
1435 Rules 10-14: Save a register to the stack. Define offset as the
1436 difference of the original location and cfa_store's
1437 location (or cfa_temp's location if cfa_temp is used).
1441 "{a,b}" indicates a choice of a xor b.
1442 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1445 (set <reg1> <reg2>:cfa.reg)
1446 effects: cfa.reg = <reg1>
1447 cfa.offset unchanged
1448 cfa_temp.reg = <reg1>
1449 cfa_temp.offset = cfa.offset
1452 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1453 {<const_int>,<reg>:cfa_temp.reg}))
1454 effects: cfa.reg = sp if fp used
1455 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1456 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1457 if cfa_store.reg==sp
1460 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1461 effects: cfa.reg = fp
1462 cfa_offset += +/- <const_int>
1465 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1466 constraints: <reg1> != fp
1468 effects: cfa.reg = <reg1>
1469 cfa_temp.reg = <reg1>
1470 cfa_temp.offset = cfa.offset
1473 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1474 constraints: <reg1> != fp
1476 effects: cfa_store.reg = <reg1>
1477 cfa_store.offset = cfa.offset - cfa_temp.offset
1480 (set <reg> <const_int>)
1481 effects: cfa_temp.reg = <reg>
1482 cfa_temp.offset = <const_int>
1485 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1486 effects: cfa_temp.reg = <reg1>
1487 cfa_temp.offset |= <const_int>
1490 (set <reg> (high <exp>))
1494 (set <reg> (lo_sum <exp> <const_int>))
1495 effects: cfa_temp.reg = <reg>
1496 cfa_temp.offset = <const_int>
1499 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1500 effects: cfa_store.offset -= <const_int>
1501 cfa.offset = cfa_store.offset if cfa.reg == sp
1503 cfa.base_offset = -cfa_store.offset
1506 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1507 effects: cfa_store.offset += -/+ mode_size(mem)
1508 cfa.offset = cfa_store.offset if cfa.reg == sp
1510 cfa.base_offset = -cfa_store.offset
1513 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1516 effects: cfa.reg = <reg1>
1517 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1520 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1521 effects: cfa.reg = <reg1>
1522 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1525 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1526 effects: cfa.reg = <reg1>
1527 cfa.base_offset = -cfa_temp.offset
1528 cfa_temp.offset -= mode_size(mem)
1531 (set <reg> {unspec, unspec_volatile})
1532 effects: target-dependent */
1535 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1538 HOST_WIDE_INT offset
;
1540 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1541 the PARALLEL independently. The first element is always processed if
1542 it is a SET. This is for backward compatibility. Other elements
1543 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1544 flag is set in them. */
1545 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1548 int limit
= XVECLEN (expr
, 0);
1551 /* PARALLELs have strict read-modify-write semantics, so we
1552 ought to evaluate every rvalue before changing any lvalue.
1553 It's cumbersome to do that in general, but there's an
1554 easy approximation that is enough for all current users:
1555 handle register saves before register assignments. */
1556 if (GET_CODE (expr
) == PARALLEL
)
1557 for (par_index
= 0; par_index
< limit
; par_index
++)
1559 elem
= XVECEXP (expr
, 0, par_index
);
1560 if (GET_CODE (elem
) == SET
1561 && MEM_P (SET_DEST (elem
))
1562 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1563 dwarf2out_frame_debug_expr (elem
, label
);
1566 for (par_index
= 0; par_index
< limit
; par_index
++)
1568 elem
= XVECEXP (expr
, 0, par_index
);
1569 if (GET_CODE (elem
) == SET
1570 && (!MEM_P (SET_DEST (elem
)) || GET_CODE (expr
) == SEQUENCE
)
1571 && (RTX_FRAME_RELATED_P (elem
) || par_index
== 0))
1572 dwarf2out_frame_debug_expr (elem
, label
);
1577 gcc_assert (GET_CODE (expr
) == SET
);
1579 src
= SET_SRC (expr
);
1580 dest
= SET_DEST (expr
);
1584 rtx rsi
= reg_saved_in (src
);
1589 switch (GET_CODE (dest
))
1592 switch (GET_CODE (src
))
1594 /* Setting FP from SP. */
1596 if (cfa
.reg
== (unsigned) REGNO (src
))
1599 /* Update the CFA rule wrt SP or FP. Make sure src is
1600 relative to the current CFA register.
1602 We used to require that dest be either SP or FP, but the
1603 ARM copies SP to a temporary register, and from there to
1604 FP. So we just rely on the backends to only set
1605 RTX_FRAME_RELATED_P on appropriate insns. */
1606 cfa
.reg
= REGNO (dest
);
1607 cfa_temp
.reg
= cfa
.reg
;
1608 cfa_temp
.offset
= cfa
.offset
;
1612 /* Saving a register in a register. */
1613 gcc_assert (!fixed_regs
[REGNO (dest
)]
1614 /* For the SPARC and its register window. */
1615 || (DWARF_FRAME_REGNUM (REGNO (src
))
1616 == DWARF_FRAME_RETURN_COLUMN
));
1617 queue_reg_save (label
, src
, dest
, 0);
1624 if (dest
== stack_pointer_rtx
)
1628 switch (GET_CODE (XEXP (src
, 1)))
1631 offset
= INTVAL (XEXP (src
, 1));
1634 gcc_assert ((unsigned) REGNO (XEXP (src
, 1))
1636 offset
= cfa_temp
.offset
;
1642 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1644 /* Restoring SP from FP in the epilogue. */
1645 gcc_assert (cfa
.reg
== (unsigned) HARD_FRAME_POINTER_REGNUM
);
1646 cfa
.reg
= STACK_POINTER_REGNUM
;
1648 else if (GET_CODE (src
) == LO_SUM
)
1649 /* Assume we've set the source reg of the LO_SUM from sp. */
1652 gcc_assert (XEXP (src
, 0) == stack_pointer_rtx
);
1654 if (GET_CODE (src
) != MINUS
)
1656 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1657 cfa
.offset
+= offset
;
1658 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1659 cfa_store
.offset
+= offset
;
1661 else if (dest
== hard_frame_pointer_rtx
)
1664 /* Either setting the FP from an offset of the SP,
1665 or adjusting the FP */
1666 gcc_assert (frame_pointer_needed
);
1668 gcc_assert (REG_P (XEXP (src
, 0))
1669 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1670 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1671 offset
= INTVAL (XEXP (src
, 1));
1672 if (GET_CODE (src
) != MINUS
)
1674 cfa
.offset
+= offset
;
1675 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1679 gcc_assert (GET_CODE (src
) != MINUS
);
1682 if (REG_P (XEXP (src
, 0))
1683 && REGNO (XEXP (src
, 0)) == cfa
.reg
1684 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1686 /* Setting a temporary CFA register that will be copied
1687 into the FP later on. */
1688 offset
= - INTVAL (XEXP (src
, 1));
1689 cfa
.offset
+= offset
;
1690 cfa
.reg
= REGNO (dest
);
1691 /* Or used to save regs to the stack. */
1692 cfa_temp
.reg
= cfa
.reg
;
1693 cfa_temp
.offset
= cfa
.offset
;
1697 else if (REG_P (XEXP (src
, 0))
1698 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1699 && XEXP (src
, 1) == stack_pointer_rtx
)
1701 /* Setting a scratch register that we will use instead
1702 of SP for saving registers to the stack. */
1703 gcc_assert (cfa
.reg
== STACK_POINTER_REGNUM
);
1704 cfa_store
.reg
= REGNO (dest
);
1705 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1709 else if (GET_CODE (src
) == LO_SUM
1710 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1712 cfa_temp
.reg
= REGNO (dest
);
1713 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1722 cfa_temp
.reg
= REGNO (dest
);
1723 cfa_temp
.offset
= INTVAL (src
);
1728 gcc_assert (REG_P (XEXP (src
, 0))
1729 && (unsigned) REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1730 && GET_CODE (XEXP (src
, 1)) == CONST_INT
);
1732 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1733 cfa_temp
.reg
= REGNO (dest
);
1734 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1737 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1738 which will fill in all of the bits. */
1745 case UNSPEC_VOLATILE
:
1746 gcc_assert (targetm
.dwarf_handle_frame_unspec
);
1747 targetm
.dwarf_handle_frame_unspec (label
, expr
, XINT (src
, 1));
1754 def_cfa_1 (label
, &cfa
);
1758 gcc_assert (REG_P (src
));
1760 /* Saving a register to the stack. Make sure dest is relative to the
1762 switch (GET_CODE (XEXP (dest
, 0)))
1767 /* We can't handle variable size modifications. */
1768 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1))
1770 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1772 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1773 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1775 cfa_store
.offset
+= offset
;
1776 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1777 cfa
.offset
= cfa_store
.offset
;
1779 offset
= -cfa_store
.offset
;
1785 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1786 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1789 gcc_assert (REGNO (XEXP (XEXP (dest
, 0), 0)) == STACK_POINTER_REGNUM
1790 && cfa_store
.reg
== STACK_POINTER_REGNUM
);
1792 cfa_store
.offset
+= offset
;
1793 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1794 cfa
.offset
= cfa_store
.offset
;
1796 offset
= -cfa_store
.offset
;
1800 /* With an offset. */
1807 gcc_assert (GET_CODE (XEXP (XEXP (dest
, 0), 1)) == CONST_INT
1808 && REG_P (XEXP (XEXP (dest
, 0), 0)));
1809 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1810 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1813 regno
= REGNO (XEXP (XEXP (dest
, 0), 0));
1815 if (cfa_store
.reg
== (unsigned) regno
)
1816 offset
-= cfa_store
.offset
;
1819 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1820 offset
-= cfa_temp
.offset
;
1826 /* Without an offset. */
1829 int regno
= REGNO (XEXP (dest
, 0));
1831 if (cfa_store
.reg
== (unsigned) regno
)
1832 offset
= -cfa_store
.offset
;
1835 gcc_assert (cfa_temp
.reg
== (unsigned) regno
);
1836 offset
= -cfa_temp
.offset
;
1843 gcc_assert (cfa_temp
.reg
1844 == (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)));
1845 offset
= -cfa_temp
.offset
;
1846 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1853 if (REGNO (src
) != STACK_POINTER_REGNUM
1854 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1855 && (unsigned) REGNO (src
) == cfa
.reg
)
1857 /* We're storing the current CFA reg into the stack. */
1859 if (cfa
.offset
== 0)
1861 /* If the source register is exactly the CFA, assume
1862 we're saving SP like any other register; this happens
1864 def_cfa_1 (label
, &cfa
);
1865 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
1870 /* Otherwise, we'll need to look in the stack to
1871 calculate the CFA. */
1872 rtx x
= XEXP (dest
, 0);
1876 gcc_assert (REG_P (x
));
1878 cfa
.reg
= REGNO (x
);
1879 cfa
.base_offset
= offset
;
1881 def_cfa_1 (label
, &cfa
);
1886 def_cfa_1 (label
, &cfa
);
1887 queue_reg_save (label
, src
, NULL_RTX
, offset
);
1895 /* Record call frame debugging information for INSN, which either
1896 sets SP or FP (adjusting how we calculate the frame address) or saves a
1897 register to the stack. If INSN is NULL_RTX, initialize our state.
1899 If AFTER_P is false, we're being called before the insn is emitted,
1900 otherwise after. Call instructions get invoked twice. */
1903 dwarf2out_frame_debug (rtx insn
, bool after_p
)
1908 if (insn
== NULL_RTX
)
1912 /* Flush any queued register saves. */
1913 flush_queued_reg_saves ();
1915 /* Set up state for generating call frame debug info. */
1918 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
1920 cfa
.reg
= STACK_POINTER_REGNUM
;
1923 cfa_temp
.offset
= 0;
1925 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1927 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
1928 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
1930 num_regs_saved_in_regs
= 0;
1934 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
1935 flush_queued_reg_saves ();
1937 if (! RTX_FRAME_RELATED_P (insn
))
1939 if (!ACCUMULATE_OUTGOING_ARGS
)
1940 dwarf2out_stack_adjust (insn
, after_p
);
1944 label
= dwarf2out_cfi_label ();
1945 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1947 insn
= XEXP (src
, 0);
1949 insn
= PATTERN (insn
);
1951 dwarf2out_frame_debug_expr (insn
, label
);
1956 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1957 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1958 (enum dwarf_call_frame_info cfi
);
1960 static enum dw_cfi_oprnd_type
1961 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1966 case DW_CFA_GNU_window_save
:
1967 return dw_cfi_oprnd_unused
;
1969 case DW_CFA_set_loc
:
1970 case DW_CFA_advance_loc1
:
1971 case DW_CFA_advance_loc2
:
1972 case DW_CFA_advance_loc4
:
1973 case DW_CFA_MIPS_advance_loc8
:
1974 return dw_cfi_oprnd_addr
;
1977 case DW_CFA_offset_extended
:
1978 case DW_CFA_def_cfa
:
1979 case DW_CFA_offset_extended_sf
:
1980 case DW_CFA_def_cfa_sf
:
1981 case DW_CFA_restore_extended
:
1982 case DW_CFA_undefined
:
1983 case DW_CFA_same_value
:
1984 case DW_CFA_def_cfa_register
:
1985 case DW_CFA_register
:
1986 return dw_cfi_oprnd_reg_num
;
1988 case DW_CFA_def_cfa_offset
:
1989 case DW_CFA_GNU_args_size
:
1990 case DW_CFA_def_cfa_offset_sf
:
1991 return dw_cfi_oprnd_offset
;
1993 case DW_CFA_def_cfa_expression
:
1994 case DW_CFA_expression
:
1995 return dw_cfi_oprnd_loc
;
2002 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
2003 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
2004 (enum dwarf_call_frame_info cfi
);
2006 static enum dw_cfi_oprnd_type
2007 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
2011 case DW_CFA_def_cfa
:
2012 case DW_CFA_def_cfa_sf
:
2014 case DW_CFA_offset_extended_sf
:
2015 case DW_CFA_offset_extended
:
2016 return dw_cfi_oprnd_offset
;
2018 case DW_CFA_register
:
2019 return dw_cfi_oprnd_reg_num
;
2022 return dw_cfi_oprnd_unused
;
2026 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2028 /* Switch to eh_frame_section. If we don't have an eh_frame_section,
2029 switch to the data section instead, and write out a synthetic label
2033 switch_to_eh_frame_section (void)
2037 #ifdef EH_FRAME_SECTION_NAME
2038 if (eh_frame_section
== 0)
2042 if (EH_TABLES_CAN_BE_READ_ONLY
)
2048 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
2050 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
2052 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
2054 flags
= ((! flag_pic
2055 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
2056 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
2057 && (per_encoding
& 0x70) != DW_EH_PE_absptr
2058 && (per_encoding
& 0x70) != DW_EH_PE_aligned
2059 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
2060 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
2061 ? 0 : SECTION_WRITE
);
2064 flags
= SECTION_WRITE
;
2065 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
2069 if (eh_frame_section
)
2070 switch_to_section (eh_frame_section
);
2073 /* We have no special eh_frame section. Put the information in
2074 the data section and emit special labels to guide collect2. */
2075 switch_to_section (data_section
);
2076 label
= get_file_function_name ("F");
2077 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2078 targetm
.asm_out
.globalize_label (asm_out_file
,
2079 IDENTIFIER_POINTER (label
));
2080 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
2084 /* Output a Call Frame Information opcode and its operand(s). */
2087 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
2090 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
2091 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
2092 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
2093 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
2094 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
2095 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
2097 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2098 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2099 "DW_CFA_offset, column 0x%lx", r
);
2100 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2102 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
2104 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2105 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
2106 "DW_CFA_restore, column 0x%lx", r
);
2110 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
2111 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
2113 switch (cfi
->dw_cfi_opc
)
2115 case DW_CFA_set_loc
:
2117 dw2_asm_output_encoded_addr_rtx (
2118 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
2119 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
2122 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2123 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
2124 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2127 case DW_CFA_advance_loc1
:
2128 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2129 fde
->dw_fde_current_label
, NULL
);
2130 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2133 case DW_CFA_advance_loc2
:
2134 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2135 fde
->dw_fde_current_label
, NULL
);
2136 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2139 case DW_CFA_advance_loc4
:
2140 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2141 fde
->dw_fde_current_label
, NULL
);
2142 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2145 case DW_CFA_MIPS_advance_loc8
:
2146 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
2147 fde
->dw_fde_current_label
, NULL
);
2148 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
2151 case DW_CFA_offset_extended
:
2152 case DW_CFA_def_cfa
:
2153 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2154 dw2_asm_output_data_uleb128 (r
, NULL
);
2155 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2158 case DW_CFA_offset_extended_sf
:
2159 case DW_CFA_def_cfa_sf
:
2160 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2161 dw2_asm_output_data_uleb128 (r
, NULL
);
2162 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
2165 case DW_CFA_restore_extended
:
2166 case DW_CFA_undefined
:
2167 case DW_CFA_same_value
:
2168 case DW_CFA_def_cfa_register
:
2169 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2170 dw2_asm_output_data_uleb128 (r
, NULL
);
2173 case DW_CFA_register
:
2174 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2175 dw2_asm_output_data_uleb128 (r
, NULL
);
2176 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2177 dw2_asm_output_data_uleb128 (r
, NULL
);
2180 case DW_CFA_def_cfa_offset
:
2181 case DW_CFA_GNU_args_size
:
2182 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2185 case DW_CFA_def_cfa_offset_sf
:
2186 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2189 case DW_CFA_GNU_window_save
:
2192 case DW_CFA_def_cfa_expression
:
2193 case DW_CFA_expression
:
2194 output_cfa_loc (cfi
);
2197 case DW_CFA_GNU_negative_offset_extended
:
2198 /* Obsoleted by DW_CFA_offset_extended_sf. */
2207 /* Output the call frame information used to record information
2208 that relates to calculating the frame pointer, and records the
2209 location of saved registers. */
2212 output_call_frame_info (int for_eh
)
2217 char l1
[20], l2
[20], section_start_label
[20];
2218 bool any_lsda_needed
= false;
2219 char augmentation
[6];
2220 int augmentation_size
;
2221 int fde_encoding
= DW_EH_PE_absptr
;
2222 int per_encoding
= DW_EH_PE_absptr
;
2223 int lsda_encoding
= DW_EH_PE_absptr
;
2226 /* Don't emit a CIE if there won't be any FDEs. */
2227 if (fde_table_in_use
== 0)
2230 /* If we make FDEs linkonce, we may have to emit an empty label for
2231 an FDE that wouldn't otherwise be emitted. We want to avoid
2232 having an FDE kept around when the function it refers to is
2233 discarded. Example where this matters: a primary function
2234 template in C++ requires EH information, but an explicit
2235 specialization doesn't. */
2236 if (TARGET_USES_WEAK_UNWIND_INFO
2237 && ! flag_asynchronous_unwind_tables
2240 for (i
= 0; i
< fde_table_in_use
; i
++)
2241 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2242 && !fde_table
[i
].uses_eh_lsda
2243 && ! DECL_WEAK (fde_table
[i
].decl
))
2244 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2245 for_eh
, /* empty */ 1);
2247 /* If we don't have any functions we'll want to unwind out of, don't
2248 emit any EH unwind information. Note that if exceptions aren't
2249 enabled, we won't have collected nothrow information, and if we
2250 asked for asynchronous tables, we always want this info. */
2253 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2255 for (i
= 0; i
< fde_table_in_use
; i
++)
2256 if (fde_table
[i
].uses_eh_lsda
)
2257 any_eh_needed
= any_lsda_needed
= true;
2258 else if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2259 any_eh_needed
= true;
2260 else if (! fde_table
[i
].nothrow
2261 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2262 any_eh_needed
= true;
2264 if (! any_eh_needed
)
2268 /* We're going to be generating comments, so turn on app. */
2273 switch_to_eh_frame_section ();
2276 if (!debug_frame_section
)
2277 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
2278 SECTION_DEBUG
, NULL
);
2279 switch_to_section (debug_frame_section
);
2282 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2283 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2285 /* Output the CIE. */
2286 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2287 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2288 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2289 dw2_asm_output_data (4, 0xffffffff,
2290 "Initial length escape value indicating 64-bit DWARF extension");
2291 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2292 "Length of Common Information Entry");
2293 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2295 /* Now that the CIE pointer is PC-relative for EH,
2296 use 0 to identify the CIE. */
2297 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2298 (for_eh
? 0 : DWARF_CIE_ID
),
2299 "CIE Identifier Tag");
2301 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2303 augmentation
[0] = 0;
2304 augmentation_size
= 0;
2310 z Indicates that a uleb128 is present to size the
2311 augmentation section.
2312 L Indicates the encoding (and thus presence) of
2313 an LSDA pointer in the FDE augmentation.
2314 R Indicates a non-default pointer encoding for
2316 P Indicates the presence of an encoding + language
2317 personality routine in the CIE augmentation. */
2319 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2320 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2321 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2323 p
= augmentation
+ 1;
2324 if (eh_personality_libfunc
)
2327 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2328 assemble_external_libcall (eh_personality_libfunc
);
2330 if (any_lsda_needed
)
2333 augmentation_size
+= 1;
2335 if (fde_encoding
!= DW_EH_PE_absptr
)
2338 augmentation_size
+= 1;
2340 if (p
> augmentation
+ 1)
2342 augmentation
[0] = 'z';
2346 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2347 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2349 int offset
= ( 4 /* Length */
2351 + 1 /* CIE version */
2352 + strlen (augmentation
) + 1 /* Augmentation */
2353 + size_of_uleb128 (1) /* Code alignment */
2354 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2356 + 1 /* Augmentation size */
2357 + 1 /* Personality encoding */ );
2358 int pad
= -offset
& (PTR_SIZE
- 1);
2360 augmentation_size
+= pad
;
2362 /* Augmentations should be small, so there's scarce need to
2363 iterate for a solution. Die if we exceed one uleb128 byte. */
2364 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
2368 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2369 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2370 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2371 "CIE Data Alignment Factor");
2373 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
2374 if (DW_CIE_VERSION
== 1)
2375 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
2377 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
2379 if (augmentation
[0])
2381 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2382 if (eh_personality_libfunc
)
2384 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2385 eh_data_format_name (per_encoding
));
2386 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2387 eh_personality_libfunc
,
2391 if (any_lsda_needed
)
2392 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2393 eh_data_format_name (lsda_encoding
));
2395 if (fde_encoding
!= DW_EH_PE_absptr
)
2396 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2397 eh_data_format_name (fde_encoding
));
2400 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2401 output_cfi (cfi
, NULL
, for_eh
);
2403 /* Pad the CIE out to an address sized boundary. */
2404 ASM_OUTPUT_ALIGN (asm_out_file
,
2405 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2406 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2408 /* Loop through all of the FDE's. */
2409 for (i
= 0; i
< fde_table_in_use
; i
++)
2411 fde
= &fde_table
[i
];
2413 /* Don't emit EH unwind info for leaf functions that don't need it. */
2414 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2415 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2416 && ! (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde_table
[i
].decl
))
2417 && !fde
->uses_eh_lsda
)
2420 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2421 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2422 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2423 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2424 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
2425 dw2_asm_output_data (4, 0xffffffff,
2426 "Initial length escape value indicating 64-bit DWARF extension");
2427 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2429 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2432 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2434 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2435 debug_frame_section
, "FDE CIE offset");
2439 if (fde
->dw_fde_switched_sections
)
2441 rtx sym_ref2
= gen_rtx_SYMBOL_REF (Pmode
,
2442 fde
->dw_fde_unlikely_section_label
);
2443 rtx sym_ref3
= gen_rtx_SYMBOL_REF (Pmode
,
2444 fde
->dw_fde_hot_section_label
);
2445 SYMBOL_REF_FLAGS (sym_ref2
) |= SYMBOL_FLAG_LOCAL
;
2446 SYMBOL_REF_FLAGS (sym_ref3
) |= SYMBOL_FLAG_LOCAL
;
2447 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref3
, false,
2448 "FDE initial location");
2449 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2450 fde
->dw_fde_hot_section_end_label
,
2451 fde
->dw_fde_hot_section_label
,
2452 "FDE address range");
2453 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref2
, false,
2454 "FDE initial location");
2455 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2456 fde
->dw_fde_unlikely_section_end_label
,
2457 fde
->dw_fde_unlikely_section_label
,
2458 "FDE address range");
2462 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
2463 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
2464 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2467 "FDE initial location");
2468 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2469 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2470 "FDE address range");
2475 if (fde
->dw_fde_switched_sections
)
2477 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2478 fde
->dw_fde_hot_section_label
,
2479 "FDE initial location");
2480 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2481 fde
->dw_fde_hot_section_end_label
,
2482 fde
->dw_fde_hot_section_label
,
2483 "FDE address range");
2484 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
2485 fde
->dw_fde_unlikely_section_label
,
2486 "FDE initial location");
2487 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2488 fde
->dw_fde_unlikely_section_end_label
,
2489 fde
->dw_fde_unlikely_section_label
,
2490 "FDE address range");
2494 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2495 "FDE initial location");
2496 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2497 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2498 "FDE address range");
2502 if (augmentation
[0])
2504 if (any_lsda_needed
)
2506 int size
= size_of_encoded_value (lsda_encoding
);
2508 if (lsda_encoding
== DW_EH_PE_aligned
)
2510 int offset
= ( 4 /* Length */
2511 + 4 /* CIE offset */
2512 + 2 * size_of_encoded_value (fde_encoding
)
2513 + 1 /* Augmentation size */ );
2514 int pad
= -offset
& (PTR_SIZE
- 1);
2517 gcc_assert (size_of_uleb128 (size
) == 1);
2520 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2522 if (fde
->uses_eh_lsda
)
2524 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2525 fde
->funcdef_number
);
2526 dw2_asm_output_encoded_addr_rtx (
2527 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2528 false, "Language Specific Data Area");
2532 if (lsda_encoding
== DW_EH_PE_aligned
)
2533 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2535 (size_of_encoded_value (lsda_encoding
), 0,
2536 "Language Specific Data Area (none)");
2540 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2543 /* Loop through the Call Frame Instructions associated with
2545 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2546 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2547 output_cfi (cfi
, fde
, for_eh
);
2549 /* Pad the FDE out to an address sized boundary. */
2550 ASM_OUTPUT_ALIGN (asm_out_file
,
2551 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2552 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2555 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2556 dw2_asm_output_data (4, 0, "End of Table");
2557 #ifdef MIPS_DEBUGGING_INFO
2558 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2559 get a value of 0. Putting .align 0 after the label fixes it. */
2560 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2563 /* Turn off app to make assembly quicker. */
2568 /* Output a marker (i.e. a label) for the beginning of a function, before
2572 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2573 const char *file ATTRIBUTE_UNUSED
)
2575 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2579 current_function_func_begin_label
= NULL
;
2581 #ifdef TARGET_UNWIND_INFO
2582 /* ??? current_function_func_begin_label is also used by except.c
2583 for call-site information. We must emit this label if it might
2585 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2586 && ! dwarf2out_do_frame ())
2589 if (! dwarf2out_do_frame ())
2593 switch_to_section (function_section (current_function_decl
));
2594 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2595 current_function_funcdef_no
);
2596 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2597 current_function_funcdef_no
);
2598 dup_label
= xstrdup (label
);
2599 current_function_func_begin_label
= dup_label
;
2601 #ifdef TARGET_UNWIND_INFO
2602 /* We can elide the fde allocation if we're not emitting debug info. */
2603 if (! dwarf2out_do_frame ())
2607 /* Expand the fde table if necessary. */
2608 if (fde_table_in_use
== fde_table_allocated
)
2610 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2611 fde_table
= ggc_realloc (fde_table
,
2612 fde_table_allocated
* sizeof (dw_fde_node
));
2613 memset (fde_table
+ fde_table_in_use
, 0,
2614 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2617 /* Record the FDE associated with this function. */
2618 current_funcdef_fde
= fde_table_in_use
;
2620 /* Add the new FDE at the end of the fde_table. */
2621 fde
= &fde_table
[fde_table_in_use
++];
2622 fde
->decl
= current_function_decl
;
2623 fde
->dw_fde_begin
= dup_label
;
2624 fde
->dw_fde_current_label
= dup_label
;
2625 fde
->dw_fde_hot_section_label
= NULL
;
2626 fde
->dw_fde_hot_section_end_label
= NULL
;
2627 fde
->dw_fde_unlikely_section_label
= NULL
;
2628 fde
->dw_fde_unlikely_section_end_label
= NULL
;
2629 fde
->dw_fde_switched_sections
= false;
2630 fde
->dw_fde_end
= NULL
;
2631 fde
->dw_fde_cfi
= NULL
;
2632 fde
->funcdef_number
= current_function_funcdef_no
;
2633 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
2634 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2635 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2637 args_size
= old_args_size
= 0;
2639 /* We only want to output line number information for the genuine dwarf2
2640 prologue case, not the eh frame case. */
2641 #ifdef DWARF2_DEBUGGING_INFO
2643 dwarf2out_source_line (line
, file
);
2647 /* Output a marker (i.e. a label) for the absolute end of the generated code
2648 for a function definition. This gets called *after* the epilogue code has
2652 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2653 const char *file ATTRIBUTE_UNUSED
)
2656 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2658 /* Output a label to mark the endpoint of the code generated for this
2660 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2661 current_function_funcdef_no
);
2662 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2663 fde
= &fde_table
[fde_table_in_use
- 1];
2664 fde
->dw_fde_end
= xstrdup (label
);
2668 dwarf2out_frame_init (void)
2670 /* Allocate the initial hunk of the fde_table. */
2671 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2672 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2673 fde_table_in_use
= 0;
2675 /* Generate the CFA instructions common to all FDE's. Do it now for the
2676 sake of lookup_cfa. */
2678 /* On entry, the Canonical Frame Address is at SP. */
2679 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2681 #ifdef DWARF2_UNWIND_INFO
2682 if (DWARF2_UNWIND_INFO
|| DWARF2_FRAME_INFO
)
2683 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2688 dwarf2out_frame_finish (void)
2690 /* Output call frame information. */
2691 if (DWARF2_FRAME_INFO
)
2692 output_call_frame_info (0);
2694 #ifndef TARGET_UNWIND_INFO
2695 /* Output another copy for the unwinder. */
2696 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2697 output_call_frame_info (1);
2701 /* Note that the current function section is being used for code. */
2704 dwarf2out_note_section_used (void)
2706 section
*sec
= current_function_section ();
2707 if (sec
== text_section
)
2708 text_section_used
= true;
2709 else if (sec
== cold_text_section
)
2710 cold_text_section_used
= true;
2714 dwarf2out_switch_text_section (void)
2720 fde
= &fde_table
[fde_table_in_use
- 1];
2721 fde
->dw_fde_switched_sections
= true;
2722 fde
->dw_fde_hot_section_label
= cfun
->hot_section_label
;
2723 fde
->dw_fde_hot_section_end_label
= cfun
->hot_section_end_label
;
2724 fde
->dw_fde_unlikely_section_label
= cfun
->cold_section_label
;
2725 fde
->dw_fde_unlikely_section_end_label
= cfun
->cold_section_end_label
;
2726 have_multiple_function_sections
= true;
2728 /* Reset the current label on switching text sections, so that we
2729 don't attempt to advance_loc4 between labels in different sections. */
2730 fde
->dw_fde_current_label
= NULL
;
2732 /* There is no need to mark used sections when not debugging. */
2733 if (cold_text_section
!= NULL
)
2734 dwarf2out_note_section_used ();
2738 /* And now, the subset of the debugging information support code necessary
2739 for emitting location expressions. */
2741 /* Data about a single source file. */
2742 struct dwarf_file_data
GTY(())
2744 const char * filename
;
2748 /* We need some way to distinguish DW_OP_addr with a direct symbol
2749 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2750 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2753 typedef struct dw_val_struct
*dw_val_ref
;
2754 typedef struct die_struct
*dw_die_ref
;
2755 typedef const struct die_struct
*const_dw_die_ref
;
2756 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2757 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2759 /* Each DIE may have a series of attribute/value pairs. Values
2760 can take on several forms. The forms that are used in this
2761 implementation are listed below. */
2766 dw_val_class_offset
,
2768 dw_val_class_loc_list
,
2769 dw_val_class_range_list
,
2771 dw_val_class_unsigned_const
,
2772 dw_val_class_long_long
,
2775 dw_val_class_die_ref
,
2776 dw_val_class_fde_ref
,
2777 dw_val_class_lbl_id
,
2778 dw_val_class_lineptr
,
2780 dw_val_class_macptr
,
2784 /* Describe a double word constant value. */
2785 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2787 typedef struct dw_long_long_struct
GTY(())
2794 /* Describe a floating point constant value, or a vector constant value. */
2796 typedef struct dw_vec_struct
GTY(())
2798 unsigned char * GTY((length ("%h.length"))) array
;
2804 /* The dw_val_node describes an attribute's value, as it is
2805 represented internally. */
2807 typedef struct dw_val_struct
GTY(())
2809 enum dw_val_class val_class
;
2810 union dw_val_struct_union
2812 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2813 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2814 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2815 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2816 HOST_WIDE_INT
GTY ((default)) val_int
;
2817 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2818 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2819 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2820 struct dw_val_die_union
2824 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2825 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2826 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2827 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2828 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2829 struct dwarf_file_data
* GTY ((tag ("dw_val_class_file"))) val_file
;
2831 GTY ((desc ("%1.val_class"))) v
;
2835 /* Locations in memory are described using a sequence of stack machine
2838 typedef struct dw_loc_descr_struct
GTY(())
2840 dw_loc_descr_ref dw_loc_next
;
2841 enum dwarf_location_atom dw_loc_opc
;
2842 dw_val_node dw_loc_oprnd1
;
2843 dw_val_node dw_loc_oprnd2
;
2848 /* Location lists are ranges + location descriptions for that range,
2849 so you can track variables that are in different places over
2850 their entire life. */
2851 typedef struct dw_loc_list_struct
GTY(())
2853 dw_loc_list_ref dw_loc_next
;
2854 const char *begin
; /* Label for begin address of range */
2855 const char *end
; /* Label for end address of range */
2856 char *ll_symbol
; /* Label for beginning of location list.
2857 Only on head of list */
2858 const char *section
; /* Section this loclist is relative to */
2859 dw_loc_descr_ref expr
;
2862 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2864 static const char *dwarf_stack_op_name (unsigned);
2865 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2866 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2867 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2868 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2869 static unsigned long size_of_locs (dw_loc_descr_ref
);
2870 static void output_loc_operands (dw_loc_descr_ref
);
2871 static void output_loc_sequence (dw_loc_descr_ref
);
2873 /* Convert a DWARF stack opcode into its string name. */
2876 dwarf_stack_op_name (unsigned int op
)
2881 case INTERNAL_DW_OP_tls_addr
:
2882 return "DW_OP_addr";
2884 return "DW_OP_deref";
2886 return "DW_OP_const1u";
2888 return "DW_OP_const1s";
2890 return "DW_OP_const2u";
2892 return "DW_OP_const2s";
2894 return "DW_OP_const4u";
2896 return "DW_OP_const4s";
2898 return "DW_OP_const8u";
2900 return "DW_OP_const8s";
2902 return "DW_OP_constu";
2904 return "DW_OP_consts";
2908 return "DW_OP_drop";
2910 return "DW_OP_over";
2912 return "DW_OP_pick";
2914 return "DW_OP_swap";
2918 return "DW_OP_xderef";
2926 return "DW_OP_minus";
2938 return "DW_OP_plus";
2939 case DW_OP_plus_uconst
:
2940 return "DW_OP_plus_uconst";
2946 return "DW_OP_shra";
2964 return "DW_OP_skip";
2966 return "DW_OP_lit0";
2968 return "DW_OP_lit1";
2970 return "DW_OP_lit2";
2972 return "DW_OP_lit3";
2974 return "DW_OP_lit4";
2976 return "DW_OP_lit5";
2978 return "DW_OP_lit6";
2980 return "DW_OP_lit7";
2982 return "DW_OP_lit8";
2984 return "DW_OP_lit9";
2986 return "DW_OP_lit10";
2988 return "DW_OP_lit11";
2990 return "DW_OP_lit12";
2992 return "DW_OP_lit13";
2994 return "DW_OP_lit14";
2996 return "DW_OP_lit15";
2998 return "DW_OP_lit16";
3000 return "DW_OP_lit17";
3002 return "DW_OP_lit18";
3004 return "DW_OP_lit19";
3006 return "DW_OP_lit20";
3008 return "DW_OP_lit21";
3010 return "DW_OP_lit22";
3012 return "DW_OP_lit23";
3014 return "DW_OP_lit24";
3016 return "DW_OP_lit25";
3018 return "DW_OP_lit26";
3020 return "DW_OP_lit27";
3022 return "DW_OP_lit28";
3024 return "DW_OP_lit29";
3026 return "DW_OP_lit30";
3028 return "DW_OP_lit31";
3030 return "DW_OP_reg0";
3032 return "DW_OP_reg1";
3034 return "DW_OP_reg2";
3036 return "DW_OP_reg3";
3038 return "DW_OP_reg4";
3040 return "DW_OP_reg5";
3042 return "DW_OP_reg6";
3044 return "DW_OP_reg7";
3046 return "DW_OP_reg8";
3048 return "DW_OP_reg9";
3050 return "DW_OP_reg10";
3052 return "DW_OP_reg11";
3054 return "DW_OP_reg12";
3056 return "DW_OP_reg13";
3058 return "DW_OP_reg14";
3060 return "DW_OP_reg15";
3062 return "DW_OP_reg16";
3064 return "DW_OP_reg17";
3066 return "DW_OP_reg18";
3068 return "DW_OP_reg19";
3070 return "DW_OP_reg20";
3072 return "DW_OP_reg21";
3074 return "DW_OP_reg22";
3076 return "DW_OP_reg23";
3078 return "DW_OP_reg24";
3080 return "DW_OP_reg25";
3082 return "DW_OP_reg26";
3084 return "DW_OP_reg27";
3086 return "DW_OP_reg28";
3088 return "DW_OP_reg29";
3090 return "DW_OP_reg30";
3092 return "DW_OP_reg31";
3094 return "DW_OP_breg0";
3096 return "DW_OP_breg1";
3098 return "DW_OP_breg2";
3100 return "DW_OP_breg3";
3102 return "DW_OP_breg4";
3104 return "DW_OP_breg5";
3106 return "DW_OP_breg6";
3108 return "DW_OP_breg7";
3110 return "DW_OP_breg8";
3112 return "DW_OP_breg9";
3114 return "DW_OP_breg10";
3116 return "DW_OP_breg11";
3118 return "DW_OP_breg12";
3120 return "DW_OP_breg13";
3122 return "DW_OP_breg14";
3124 return "DW_OP_breg15";
3126 return "DW_OP_breg16";
3128 return "DW_OP_breg17";
3130 return "DW_OP_breg18";
3132 return "DW_OP_breg19";
3134 return "DW_OP_breg20";
3136 return "DW_OP_breg21";
3138 return "DW_OP_breg22";
3140 return "DW_OP_breg23";
3142 return "DW_OP_breg24";
3144 return "DW_OP_breg25";
3146 return "DW_OP_breg26";
3148 return "DW_OP_breg27";
3150 return "DW_OP_breg28";
3152 return "DW_OP_breg29";
3154 return "DW_OP_breg30";
3156 return "DW_OP_breg31";
3158 return "DW_OP_regx";
3160 return "DW_OP_fbreg";
3162 return "DW_OP_bregx";
3164 return "DW_OP_piece";
3165 case DW_OP_deref_size
:
3166 return "DW_OP_deref_size";
3167 case DW_OP_xderef_size
:
3168 return "DW_OP_xderef_size";
3171 case DW_OP_push_object_address
:
3172 return "DW_OP_push_object_address";
3174 return "DW_OP_call2";
3176 return "DW_OP_call4";
3177 case DW_OP_call_ref
:
3178 return "DW_OP_call_ref";
3179 case DW_OP_GNU_push_tls_address
:
3180 return "DW_OP_GNU_push_tls_address";
3181 case DW_OP_GNU_uninit
:
3182 return "DW_OP_GNU_uninit";
3184 return "OP_<unknown>";
3188 /* Return a pointer to a newly allocated location description. Location
3189 descriptions are simple expression terms that can be strung
3190 together to form more complicated location (address) descriptions. */
3192 static inline dw_loc_descr_ref
3193 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
3194 unsigned HOST_WIDE_INT oprnd2
)
3196 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
3198 descr
->dw_loc_opc
= op
;
3199 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
3200 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
3201 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
3202 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
3207 /* Add a location description term to a location description expression. */
3210 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
3212 dw_loc_descr_ref
*d
;
3214 /* Find the end of the chain. */
3215 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
3221 /* Return the size of a location descriptor. */
3223 static unsigned long
3224 size_of_loc_descr (dw_loc_descr_ref loc
)
3226 unsigned long size
= 1;
3228 switch (loc
->dw_loc_opc
)
3231 case INTERNAL_DW_OP_tls_addr
:
3232 size
+= DWARF2_ADDR_SIZE
;
3251 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3254 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3259 case DW_OP_plus_uconst
:
3260 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3298 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3301 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3304 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3307 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3308 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3311 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3313 case DW_OP_deref_size
:
3314 case DW_OP_xderef_size
:
3323 case DW_OP_call_ref
:
3324 size
+= DWARF2_ADDR_SIZE
;
3333 /* Return the size of a series of location descriptors. */
3335 static unsigned long
3336 size_of_locs (dw_loc_descr_ref loc
)
3341 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
3342 field, to avoid writing to a PCH file. */
3343 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3345 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
3347 size
+= size_of_loc_descr (l
);
3352 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
3354 l
->dw_loc_addr
= size
;
3355 size
+= size_of_loc_descr (l
);
3361 /* Output location description stack opcode's operands (if any). */
3364 output_loc_operands (dw_loc_descr_ref loc
)
3366 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3367 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3369 switch (loc
->dw_loc_opc
)
3371 #ifdef DWARF2_DEBUGGING_INFO
3373 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3377 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3381 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3385 gcc_assert (HOST_BITS_PER_LONG
>= 64);
3386 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3393 gcc_assert (val1
->val_class
== dw_val_class_loc
);
3394 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3396 dw2_asm_output_data (2, offset
, NULL
);
3409 /* We currently don't make any attempt to make sure these are
3410 aligned properly like we do for the main unwind info, so
3411 don't support emitting things larger than a byte if we're
3412 only doing unwinding. */
3417 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3420 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3423 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3426 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3428 case DW_OP_plus_uconst
:
3429 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3463 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3466 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3469 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3472 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3473 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3476 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3478 case DW_OP_deref_size
:
3479 case DW_OP_xderef_size
:
3480 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3483 case INTERNAL_DW_OP_tls_addr
:
3484 if (targetm
.asm_out
.output_dwarf_dtprel
)
3486 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
3489 fputc ('\n', asm_out_file
);
3496 /* Other codes have no operands. */
3501 /* Output a sequence of location operations. */
3504 output_loc_sequence (dw_loc_descr_ref loc
)
3506 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3508 /* Output the opcode. */
3509 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3510 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3512 /* Output the operand(s) (if any). */
3513 output_loc_operands (loc
);
3517 /* This routine will generate the correct assembly data for a location
3518 description based on a cfi entry with a complex address. */
3521 output_cfa_loc (dw_cfi_ref cfi
)
3523 dw_loc_descr_ref loc
;
3526 /* Output the size of the block. */
3527 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3528 size
= size_of_locs (loc
);
3529 dw2_asm_output_data_uleb128 (size
, NULL
);
3531 /* Now output the operations themselves. */
3532 output_loc_sequence (loc
);
3535 /* This function builds a dwarf location descriptor sequence from a
3536 dw_cfa_location, adding the given OFFSET to the result of the
3539 static struct dw_loc_descr_struct
*
3540 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
3542 struct dw_loc_descr_struct
*head
, *tmp
;
3544 offset
+= cfa
->offset
;
3548 if (cfa
->base_offset
)
3551 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3553 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3555 else if (cfa
->reg
<= 31)
3556 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3558 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3560 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3561 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3562 add_loc_descr (&head
, tmp
);
3565 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
3566 add_loc_descr (&head
, tmp
);
3573 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3575 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3576 else if (cfa
->reg
<= 31)
3577 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, offset
, 0);
3579 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, offset
);
3585 /* This function fills in aa dw_cfa_location structure from a dwarf location
3586 descriptor sequence. */
3589 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3591 struct dw_loc_descr_struct
*ptr
;
3593 cfa
->base_offset
= 0;
3597 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3599 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3635 cfa
->reg
= op
- DW_OP_reg0
;
3638 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3672 cfa
->reg
= op
- DW_OP_breg0
;
3673 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3676 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3677 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3682 case DW_OP_plus_uconst
:
3683 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3686 internal_error ("DW_LOC_OP %s not implemented",
3687 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3691 #endif /* .debug_frame support */
3693 /* And now, the support for symbolic debugging information. */
3694 #ifdef DWARF2_DEBUGGING_INFO
3696 /* .debug_str support. */
3697 static int output_indirect_string (void **, void *);
3699 static void dwarf2out_init (const char *);
3700 static void dwarf2out_finish (const char *);
3701 static void dwarf2out_define (unsigned int, const char *);
3702 static void dwarf2out_undef (unsigned int, const char *);
3703 static void dwarf2out_start_source_file (unsigned, const char *);
3704 static void dwarf2out_end_source_file (unsigned);
3705 static void dwarf2out_begin_block (unsigned, unsigned);
3706 static void dwarf2out_end_block (unsigned, unsigned);
3707 static bool dwarf2out_ignore_block (const_tree
);
3708 static void dwarf2out_global_decl (tree
);
3709 static void dwarf2out_type_decl (tree
, int);
3710 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3711 static void dwarf2out_abstract_function (tree
);
3712 static void dwarf2out_var_location (rtx
);
3713 static void dwarf2out_begin_function (tree
);
3715 /* The debug hooks structure. */
3717 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3723 dwarf2out_start_source_file
,
3724 dwarf2out_end_source_file
,
3725 dwarf2out_begin_block
,
3726 dwarf2out_end_block
,
3727 dwarf2out_ignore_block
,
3728 dwarf2out_source_line
,
3729 dwarf2out_begin_prologue
,
3730 debug_nothing_int_charstar
, /* end_prologue */
3731 dwarf2out_end_epilogue
,
3732 dwarf2out_begin_function
,
3733 debug_nothing_int
, /* end_function */
3734 dwarf2out_decl
, /* function_decl */
3735 dwarf2out_global_decl
,
3736 dwarf2out_type_decl
, /* type_decl */
3737 dwarf2out_imported_module_or_decl
,
3738 debug_nothing_tree
, /* deferred_inline_function */
3739 /* The DWARF 2 backend tries to reduce debugging bloat by not
3740 emitting the abstract description of inline functions until
3741 something tries to reference them. */
3742 dwarf2out_abstract_function
, /* outlining_inline_function */
3743 debug_nothing_rtx
, /* label */
3744 debug_nothing_int
, /* handle_pch */
3745 dwarf2out_var_location
,
3746 dwarf2out_switch_text_section
,
3747 1 /* start_end_main_source_file */
3751 /* NOTE: In the comments in this file, many references are made to
3752 "Debugging Information Entries". This term is abbreviated as `DIE'
3753 throughout the remainder of this file. */
3755 /* An internal representation of the DWARF output is built, and then
3756 walked to generate the DWARF debugging info. The walk of the internal
3757 representation is done after the entire program has been compiled.
3758 The types below are used to describe the internal representation. */
3760 /* Various DIE's use offsets relative to the beginning of the
3761 .debug_info section to refer to each other. */
3763 typedef long int dw_offset
;
3765 /* Define typedefs here to avoid circular dependencies. */
3767 typedef struct dw_attr_struct
*dw_attr_ref
;
3768 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3769 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3770 typedef struct pubname_struct
*pubname_ref
;
3771 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3772 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
3774 /* Each entry in the line_info_table maintains the file and
3775 line number associated with the label generated for that
3776 entry. The label gives the PC value associated with
3777 the line number entry. */
3779 typedef struct dw_line_info_struct
GTY(())
3781 unsigned long dw_file_num
;
3782 unsigned long dw_line_num
;
3786 /* Line information for functions in separate sections; each one gets its
3788 typedef struct dw_separate_line_info_struct
GTY(())
3790 unsigned long dw_file_num
;
3791 unsigned long dw_line_num
;
3792 unsigned long function
;
3794 dw_separate_line_info_entry
;
3796 /* Each DIE attribute has a field specifying the attribute kind,
3797 a link to the next attribute in the chain, and an attribute value.
3798 Attributes are typically linked below the DIE they modify. */
3800 typedef struct dw_attr_struct
GTY(())
3802 enum dwarf_attribute dw_attr
;
3803 dw_val_node dw_attr_val
;
3807 DEF_VEC_O(dw_attr_node
);
3808 DEF_VEC_ALLOC_O(dw_attr_node
,gc
);
3810 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
3811 The children of each node form a circular list linked by
3812 die_sib. die_child points to the node *before* the "first" child node. */
3814 typedef struct die_struct
GTY(())
3816 enum dwarf_tag die_tag
;
3818 VEC(dw_attr_node
,gc
) * die_attr
;
3819 dw_die_ref die_parent
;
3820 dw_die_ref die_child
;
3822 dw_die_ref die_definition
; /* ref from a specification to its definition */
3823 dw_offset die_offset
;
3824 unsigned long die_abbrev
;
3826 /* Die is used and must not be pruned as unused. */
3827 int die_perennial_p
;
3828 unsigned int decl_id
;
3832 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
3833 #define FOR_EACH_CHILD(die, c, expr) do { \
3834 c = die->die_child; \
3838 } while (c != die->die_child); \
3841 /* The pubname structure */
3843 typedef struct pubname_struct
GTY(())
3850 DEF_VEC_O(pubname_entry
);
3851 DEF_VEC_ALLOC_O(pubname_entry
, gc
);
3853 struct dw_ranges_struct
GTY(())
3855 /* If this is positive, it's a block number, otherwise it's a
3856 bitwise-negated index into dw_ranges_by_label. */
3860 struct dw_ranges_by_label_struct
GTY(())
3866 /* The limbo die list structure. */
3867 typedef struct limbo_die_struct
GTY(())
3871 struct limbo_die_struct
*next
;
3875 /* How to start an assembler comment. */
3876 #ifndef ASM_COMMENT_START
3877 #define ASM_COMMENT_START ";#"
3880 /* Define a macro which returns nonzero for a TYPE_DECL which was
3881 implicitly generated for a tagged type.
3883 Note that unlike the gcc front end (which generates a NULL named
3884 TYPE_DECL node for each complete tagged type, each array type, and
3885 each function type node created) the g++ front end generates a
3886 _named_ TYPE_DECL node for each tagged type node created.
3887 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3888 generate a DW_TAG_typedef DIE for them. */
3890 #define TYPE_DECL_IS_STUB(decl) \
3891 (DECL_NAME (decl) == NULL_TREE \
3892 || (DECL_ARTIFICIAL (decl) \
3893 && is_tagged_type (TREE_TYPE (decl)) \
3894 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3895 /* This is necessary for stub decls that \
3896 appear in nested inline functions. */ \
3897 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3898 && (decl_ultimate_origin (decl) \
3899 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3901 /* Information concerning the compilation unit's programming
3902 language, and compiler version. */
3904 /* Fixed size portion of the DWARF compilation unit header. */
3905 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3906 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3908 /* Fixed size portion of public names info. */
3909 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3911 /* Fixed size portion of the address range info. */
3912 #define DWARF_ARANGES_HEADER_SIZE \
3913 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3914 DWARF2_ADDR_SIZE * 2) \
3915 - DWARF_INITIAL_LENGTH_SIZE)
3917 /* Size of padding portion in the address range info. It must be
3918 aligned to twice the pointer size. */
3919 #define DWARF_ARANGES_PAD_SIZE \
3920 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3921 DWARF2_ADDR_SIZE * 2) \
3922 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3924 /* Use assembler line directives if available. */
3925 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3926 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3927 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3929 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3933 /* Minimum line offset in a special line info. opcode.
3934 This value was chosen to give a reasonable range of values. */
3935 #define DWARF_LINE_BASE -10
3937 /* First special line opcode - leave room for the standard opcodes. */
3938 #define DWARF_LINE_OPCODE_BASE 10
3940 /* Range of line offsets in a special line info. opcode. */
3941 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3943 /* Flag that indicates the initial value of the is_stmt_start flag.
3944 In the present implementation, we do not mark any lines as
3945 the beginning of a source statement, because that information
3946 is not made available by the GCC front-end. */
3947 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3949 #ifdef DWARF2_DEBUGGING_INFO
3950 /* This location is used by calc_die_sizes() to keep track
3951 the offset of each DIE within the .debug_info section. */
3952 static unsigned long next_die_offset
;
3955 /* Record the root of the DIE's built for the current compilation unit. */
3956 static GTY(()) dw_die_ref comp_unit_die
;
3958 /* A list of DIEs with a NULL parent waiting to be relocated. */
3959 static GTY(()) limbo_die_node
*limbo_die_list
;
3961 /* Filenames referenced by this compilation unit. */
3962 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
3964 /* A hash table of references to DIE's that describe declarations.
3965 The key is a DECL_UID() which is a unique number identifying each decl. */
3966 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3968 /* Node of the variable location list. */
3969 struct var_loc_node
GTY ((chain_next ("%h.next")))
3971 rtx
GTY (()) var_loc_note
;
3972 const char * GTY (()) label
;
3973 const char * GTY (()) section_label
;
3974 struct var_loc_node
* GTY (()) next
;
3977 /* Variable location list. */
3978 struct var_loc_list_def
GTY (())
3980 struct var_loc_node
* GTY (()) first
;
3982 /* Do not mark the last element of the chained list because
3983 it is marked through the chain. */
3984 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3986 /* DECL_UID of the variable decl. */
3987 unsigned int decl_id
;
3989 typedef struct var_loc_list_def var_loc_list
;
3992 /* Table of decl location linked lists. */
3993 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3995 /* A pointer to the base of a list of references to DIE's that
3996 are uniquely identified by their tag, presence/absence of
3997 children DIE's, and list of attribute/value pairs. */
3998 static GTY((length ("abbrev_die_table_allocated")))
3999 dw_die_ref
*abbrev_die_table
;
4001 /* Number of elements currently allocated for abbrev_die_table. */
4002 static GTY(()) unsigned abbrev_die_table_allocated
;
4004 /* Number of elements in type_die_table currently in use. */
4005 static GTY(()) unsigned abbrev_die_table_in_use
;
4007 /* Size (in elements) of increments by which we may expand the
4008 abbrev_die_table. */
4009 #define ABBREV_DIE_TABLE_INCREMENT 256
4011 /* A pointer to the base of a table that contains line information
4012 for each source code line in .text in the compilation unit. */
4013 static GTY((length ("line_info_table_allocated")))
4014 dw_line_info_ref line_info_table
;
4016 /* Number of elements currently allocated for line_info_table. */
4017 static GTY(()) unsigned line_info_table_allocated
;
4019 /* Number of elements in line_info_table currently in use. */
4020 static GTY(()) unsigned line_info_table_in_use
;
4022 /* A pointer to the base of a table that contains line information
4023 for each source code line outside of .text in the compilation unit. */
4024 static GTY ((length ("separate_line_info_table_allocated")))
4025 dw_separate_line_info_ref separate_line_info_table
;
4027 /* Number of elements currently allocated for separate_line_info_table. */
4028 static GTY(()) unsigned separate_line_info_table_allocated
;
4030 /* Number of elements in separate_line_info_table currently in use. */
4031 static GTY(()) unsigned separate_line_info_table_in_use
;
4033 /* Size (in elements) of increments by which we may expand the
4035 #define LINE_INFO_TABLE_INCREMENT 1024
4037 /* A pointer to the base of a table that contains a list of publicly
4038 accessible names. */
4039 static GTY (()) VEC (pubname_entry
, gc
) * pubname_table
;
4041 /* A pointer to the base of a table that contains a list of publicly
4042 accessible types. */
4043 static GTY (()) VEC (pubname_entry
, gc
) * pubtype_table
;
4045 /* Array of dies for which we should generate .debug_arange info. */
4046 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
4048 /* Number of elements currently allocated for arange_table. */
4049 static GTY(()) unsigned arange_table_allocated
;
4051 /* Number of elements in arange_table currently in use. */
4052 static GTY(()) unsigned arange_table_in_use
;
4054 /* Size (in elements) of increments by which we may expand the
4056 #define ARANGE_TABLE_INCREMENT 64
4058 /* Array of dies for which we should generate .debug_ranges info. */
4059 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
4061 /* Number of elements currently allocated for ranges_table. */
4062 static GTY(()) unsigned ranges_table_allocated
;
4064 /* Number of elements in ranges_table currently in use. */
4065 static GTY(()) unsigned ranges_table_in_use
;
4067 /* Array of pairs of labels referenced in ranges_table. */
4068 static GTY ((length ("ranges_by_label_allocated")))
4069 dw_ranges_by_label_ref ranges_by_label
;
4071 /* Number of elements currently allocated for ranges_by_label. */
4072 static GTY(()) unsigned ranges_by_label_allocated
;
4074 /* Number of elements in ranges_by_label currently in use. */
4075 static GTY(()) unsigned ranges_by_label_in_use
;
4077 /* Size (in elements) of increments by which we may expand the
4079 #define RANGES_TABLE_INCREMENT 64
4081 /* Whether we have location lists that need outputting */
4082 static GTY(()) bool have_location_lists
;
4084 /* Unique label counter. */
4085 static GTY(()) unsigned int loclabel_num
;
4087 #ifdef DWARF2_DEBUGGING_INFO
4088 /* Record whether the function being analyzed contains inlined functions. */
4089 static int current_function_has_inlines
;
4091 #if 0 && defined (MIPS_DEBUGGING_INFO)
4092 static int comp_unit_has_inlines
;
4095 /* The last file entry emitted by maybe_emit_file(). */
4096 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
4098 /* Number of internal labels generated by gen_internal_sym(). */
4099 static GTY(()) int label_num
;
4101 /* Cached result of previous call to lookup_filename. */
4102 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
4104 #ifdef DWARF2_DEBUGGING_INFO
4106 /* Offset from the "steady-state frame pointer" to the frame base,
4107 within the current function. */
4108 static HOST_WIDE_INT frame_pointer_fb_offset
;
4110 /* Forward declarations for functions defined in this file. */
4112 static int is_pseudo_reg (const_rtx
);
4113 static tree
type_main_variant (tree
);
4114 static int is_tagged_type (const_tree
);
4115 static const char *dwarf_tag_name (unsigned);
4116 static const char *dwarf_attr_name (unsigned);
4117 static const char *dwarf_form_name (unsigned);
4118 static tree
decl_ultimate_origin (const_tree
);
4119 static tree
block_ultimate_origin (const_tree
);
4120 static tree
decl_class_context (tree
);
4121 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
4122 static inline enum dw_val_class
AT_class (dw_attr_ref
);
4123 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
4124 static inline unsigned AT_flag (dw_attr_ref
);
4125 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
4126 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
4127 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
4128 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
4129 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
4131 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
4132 unsigned int, unsigned char *);
4133 static hashval_t
debug_str_do_hash (const void *);
4134 static int debug_str_eq (const void *, const void *);
4135 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
4136 static inline const char *AT_string (dw_attr_ref
);
4137 static int AT_string_form (dw_attr_ref
);
4138 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
4139 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
4140 static inline dw_die_ref
AT_ref (dw_attr_ref
);
4141 static inline int AT_ref_external (dw_attr_ref
);
4142 static inline void set_AT_ref_external (dw_attr_ref
, int);
4143 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
4144 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
4145 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
4146 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
4148 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
4149 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
4150 static inline rtx
AT_addr (dw_attr_ref
);
4151 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
4152 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4153 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
4154 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
4155 unsigned HOST_WIDE_INT
);
4156 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
4158 static inline const char *AT_lbl (dw_attr_ref
);
4159 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
4160 static const char *get_AT_low_pc (dw_die_ref
);
4161 static const char *get_AT_hi_pc (dw_die_ref
);
4162 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
4163 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
4164 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
4165 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
4166 static bool is_c_family (void);
4167 static bool is_cxx (void);
4168 static bool is_java (void);
4169 static bool is_fortran (void);
4170 static bool is_ada (void);
4171 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
4172 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
4173 static void add_child_die (dw_die_ref
, dw_die_ref
);
4174 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
4175 static dw_die_ref
lookup_type_die (tree
);
4176 static void equate_type_number_to_die (tree
, dw_die_ref
);
4177 static hashval_t
decl_die_table_hash (const void *);
4178 static int decl_die_table_eq (const void *, const void *);
4179 static dw_die_ref
lookup_decl_die (tree
);
4180 static hashval_t
decl_loc_table_hash (const void *);
4181 static int decl_loc_table_eq (const void *, const void *);
4182 static var_loc_list
*lookup_decl_loc (const_tree
);
4183 static void equate_decl_number_to_die (tree
, dw_die_ref
);
4184 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
4185 static void print_spaces (FILE *);
4186 static void print_die (dw_die_ref
, FILE *);
4187 static void print_dwarf_line_table (FILE *);
4188 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
4189 static dw_die_ref
pop_compile_unit (dw_die_ref
);
4190 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
4191 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
4192 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
4193 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
4194 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
4195 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
4196 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
4197 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
4198 static void compute_section_prefix (dw_die_ref
);
4199 static int is_type_die (dw_die_ref
);
4200 static int is_comdat_die (dw_die_ref
);
4201 static int is_symbol_die (dw_die_ref
);
4202 static void assign_symbol_names (dw_die_ref
);
4203 static void break_out_includes (dw_die_ref
);
4204 static hashval_t
htab_cu_hash (const void *);
4205 static int htab_cu_eq (const void *, const void *);
4206 static void htab_cu_del (void *);
4207 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
4208 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
4209 static void add_sibling_attributes (dw_die_ref
);
4210 static void build_abbrev_table (dw_die_ref
);
4211 static void output_location_lists (dw_die_ref
);
4212 static int constant_size (long unsigned);
4213 static unsigned long size_of_die (dw_die_ref
);
4214 static void calc_die_sizes (dw_die_ref
);
4215 static void mark_dies (dw_die_ref
);
4216 static void unmark_dies (dw_die_ref
);
4217 static void unmark_all_dies (dw_die_ref
);
4218 static unsigned long size_of_pubnames (VEC (pubname_entry
,gc
) *);
4219 static unsigned long size_of_aranges (void);
4220 static enum dwarf_form
value_format (dw_attr_ref
);
4221 static void output_value_format (dw_attr_ref
);
4222 static void output_abbrev_section (void);
4223 static void output_die_symbol (dw_die_ref
);
4224 static void output_die (dw_die_ref
);
4225 static void output_compilation_unit_header (void);
4226 static void output_comp_unit (dw_die_ref
, int);
4227 static const char *dwarf2_name (tree
, int);
4228 static void add_pubname (tree
, dw_die_ref
);
4229 static void add_pubtype (tree
, dw_die_ref
);
4230 static void output_pubnames (VEC (pubname_entry
,gc
) *);
4231 static void add_arange (tree
, dw_die_ref
);
4232 static void output_aranges (void);
4233 static unsigned int add_ranges_num (int);
4234 static unsigned int add_ranges (const_tree
);
4235 static unsigned int add_ranges_by_labels (const char *, const char *);
4236 static void output_ranges (void);
4237 static void output_line_info (void);
4238 static void output_file_names (void);
4239 static dw_die_ref
base_type_die (tree
);
4240 static int is_base_type (tree
);
4241 static bool is_subrange_type (const_tree
);
4242 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
4243 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
4244 static int type_is_enum (const_tree
);
4245 static unsigned int dbx_reg_number (const_rtx
);
4246 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
4247 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
4248 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
4249 enum var_init_status
);
4250 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
4251 enum var_init_status
);
4252 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
4253 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
4254 enum var_init_status
);
4255 static int is_based_loc (const_rtx
);
4256 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
,
4257 enum var_init_status
);
4258 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
4259 enum var_init_status
);
4260 static dw_loc_descr_ref
loc_descriptor (rtx
, enum var_init_status
);
4261 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
4262 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
4263 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
4264 static tree
field_type (const_tree
);
4265 static unsigned int simple_type_align_in_bits (const_tree
);
4266 static unsigned int simple_decl_align_in_bits (const_tree
);
4267 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
4268 static HOST_WIDE_INT
field_byte_offset (const_tree
);
4269 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
4271 static void add_data_member_location_attribute (dw_die_ref
, tree
);
4272 static void add_const_value_attribute (dw_die_ref
, rtx
);
4273 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
4274 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
4275 static void insert_float (const_rtx
, unsigned char *);
4276 static rtx
rtl_for_decl_location (tree
);
4277 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
4278 enum dwarf_attribute
);
4279 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
4280 static void add_name_attribute (dw_die_ref
, const char *);
4281 static void add_comp_dir_attribute (dw_die_ref
);
4282 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
4283 static void add_subscript_info (dw_die_ref
, tree
);
4284 static void add_byte_size_attribute (dw_die_ref
, tree
);
4285 static void add_bit_offset_attribute (dw_die_ref
, tree
);
4286 static void add_bit_size_attribute (dw_die_ref
, tree
);
4287 static void add_prototyped_attribute (dw_die_ref
, tree
);
4288 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
4289 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
4290 static void add_src_coords_attributes (dw_die_ref
, tree
);
4291 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
4292 static void push_decl_scope (tree
);
4293 static void pop_decl_scope (void);
4294 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
4295 static inline int local_scope_p (dw_die_ref
);
4296 static inline int class_or_namespace_scope_p (dw_die_ref
);
4297 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
4298 static void add_calling_convention_attribute (dw_die_ref
, tree
);
4299 static const char *type_tag (const_tree
);
4300 static tree
member_declared_type (const_tree
);
4302 static const char *decl_start_label (tree
);
4304 static void gen_array_type_die (tree
, dw_die_ref
);
4305 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
4307 static void gen_entry_point_die (tree
, dw_die_ref
);
4309 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
4310 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
4311 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
4312 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
4313 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
4314 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
4315 static void gen_formal_types_die (tree
, dw_die_ref
);
4316 static void gen_subprogram_die (tree
, dw_die_ref
);
4317 static void gen_variable_die (tree
, dw_die_ref
);
4318 static void gen_label_die (tree
, dw_die_ref
);
4319 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
4320 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
4321 static void gen_field_die (tree
, dw_die_ref
);
4322 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
4323 static dw_die_ref
gen_compile_unit_die (const char *);
4324 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
4325 static void gen_member_die (tree
, dw_die_ref
);
4326 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
4327 enum debug_info_usage
);
4328 static void gen_subroutine_type_die (tree
, dw_die_ref
);
4329 static void gen_typedef_die (tree
, dw_die_ref
);
4330 static void gen_type_die (tree
, dw_die_ref
);
4331 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
4332 static void gen_block_die (tree
, dw_die_ref
, int);
4333 static void decls_for_scope (tree
, dw_die_ref
, int);
4334 static int is_redundant_typedef (const_tree
);
4335 static void gen_namespace_die (tree
);
4336 static void gen_decl_die (tree
, dw_die_ref
);
4337 static dw_die_ref
force_decl_die (tree
);
4338 static dw_die_ref
force_type_die (tree
);
4339 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
4340 static void declare_in_namespace (tree
, dw_die_ref
);
4341 static struct dwarf_file_data
* lookup_filename (const char *);
4342 static void retry_incomplete_types (void);
4343 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
4344 static void splice_child_die (dw_die_ref
, dw_die_ref
);
4345 static int file_info_cmp (const void *, const void *);
4346 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
4347 const char *, const char *, unsigned);
4348 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
4349 const char *, const char *,
4351 static void output_loc_list (dw_loc_list_ref
);
4352 static char *gen_internal_sym (const char *);
4354 static void prune_unmark_dies (dw_die_ref
);
4355 static void prune_unused_types_mark (dw_die_ref
, int);
4356 static void prune_unused_types_walk (dw_die_ref
);
4357 static void prune_unused_types_walk_attribs (dw_die_ref
);
4358 static void prune_unused_types_prune (dw_die_ref
);
4359 static void prune_unused_types (void);
4360 static int maybe_emit_file (struct dwarf_file_data
*fd
);
4362 /* Section names used to hold DWARF debugging information. */
4363 #ifndef DEBUG_INFO_SECTION
4364 #define DEBUG_INFO_SECTION ".debug_info"
4366 #ifndef DEBUG_ABBREV_SECTION
4367 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4369 #ifndef DEBUG_ARANGES_SECTION
4370 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4372 #ifndef DEBUG_MACINFO_SECTION
4373 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4375 #ifndef DEBUG_LINE_SECTION
4376 #define DEBUG_LINE_SECTION ".debug_line"
4378 #ifndef DEBUG_LOC_SECTION
4379 #define DEBUG_LOC_SECTION ".debug_loc"
4381 #ifndef DEBUG_PUBNAMES_SECTION
4382 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4384 #ifndef DEBUG_STR_SECTION
4385 #define DEBUG_STR_SECTION ".debug_str"
4387 #ifndef DEBUG_RANGES_SECTION
4388 #define DEBUG_RANGES_SECTION ".debug_ranges"
4391 /* Standard ELF section names for compiled code and data. */
4392 #ifndef TEXT_SECTION_NAME
4393 #define TEXT_SECTION_NAME ".text"
4396 /* Section flags for .debug_str section. */
4397 #define DEBUG_STR_SECTION_FLAGS \
4398 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
4399 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4402 /* Labels we insert at beginning sections we can reference instead of
4403 the section names themselves. */
4405 #ifndef TEXT_SECTION_LABEL
4406 #define TEXT_SECTION_LABEL "Ltext"
4408 #ifndef COLD_TEXT_SECTION_LABEL
4409 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4411 #ifndef DEBUG_LINE_SECTION_LABEL
4412 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4414 #ifndef DEBUG_INFO_SECTION_LABEL
4415 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4417 #ifndef DEBUG_ABBREV_SECTION_LABEL
4418 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4420 #ifndef DEBUG_LOC_SECTION_LABEL
4421 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4423 #ifndef DEBUG_RANGES_SECTION_LABEL
4424 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4426 #ifndef DEBUG_MACINFO_SECTION_LABEL
4427 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4430 /* Definitions of defaults for formats and names of various special
4431 (artificial) labels which may be generated within this file (when the -g
4432 options is used and DWARF2_DEBUGGING_INFO is in effect.
4433 If necessary, these may be overridden from within the tm.h file, but
4434 typically, overriding these defaults is unnecessary. */
4436 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4437 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4438 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4439 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4440 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4441 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4442 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4443 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4444 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4445 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4447 #ifndef TEXT_END_LABEL
4448 #define TEXT_END_LABEL "Letext"
4450 #ifndef COLD_END_LABEL
4451 #define COLD_END_LABEL "Letext_cold"
4453 #ifndef BLOCK_BEGIN_LABEL
4454 #define BLOCK_BEGIN_LABEL "LBB"
4456 #ifndef BLOCK_END_LABEL
4457 #define BLOCK_END_LABEL "LBE"
4459 #ifndef LINE_CODE_LABEL
4460 #define LINE_CODE_LABEL "LM"
4462 #ifndef SEPARATE_LINE_CODE_LABEL
4463 #define SEPARATE_LINE_CODE_LABEL "LSM"
4467 /* We allow a language front-end to designate a function that is to be
4468 called to "demangle" any name before it is put into a DIE. */
4470 static const char *(*demangle_name_func
) (const char *);
4473 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4475 demangle_name_func
= func
;
4478 /* Test if rtl node points to a pseudo register. */
4481 is_pseudo_reg (const_rtx rtl
)
4483 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4484 || (GET_CODE (rtl
) == SUBREG
4485 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4488 /* Return a reference to a type, with its const and volatile qualifiers
4492 type_main_variant (tree type
)
4494 type
= TYPE_MAIN_VARIANT (type
);
4496 /* ??? There really should be only one main variant among any group of
4497 variants of a given type (and all of the MAIN_VARIANT values for all
4498 members of the group should point to that one type) but sometimes the C
4499 front-end messes this up for array types, so we work around that bug
4501 if (TREE_CODE (type
) == ARRAY_TYPE
)
4502 while (type
!= TYPE_MAIN_VARIANT (type
))
4503 type
= TYPE_MAIN_VARIANT (type
);
4508 /* Return nonzero if the given type node represents a tagged type. */
4511 is_tagged_type (const_tree type
)
4513 enum tree_code code
= TREE_CODE (type
);
4515 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4516 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4519 /* Convert a DIE tag into its string name. */
4522 dwarf_tag_name (unsigned int tag
)
4526 case DW_TAG_padding
:
4527 return "DW_TAG_padding";
4528 case DW_TAG_array_type
:
4529 return "DW_TAG_array_type";
4530 case DW_TAG_class_type
:
4531 return "DW_TAG_class_type";
4532 case DW_TAG_entry_point
:
4533 return "DW_TAG_entry_point";
4534 case DW_TAG_enumeration_type
:
4535 return "DW_TAG_enumeration_type";
4536 case DW_TAG_formal_parameter
:
4537 return "DW_TAG_formal_parameter";
4538 case DW_TAG_imported_declaration
:
4539 return "DW_TAG_imported_declaration";
4541 return "DW_TAG_label";
4542 case DW_TAG_lexical_block
:
4543 return "DW_TAG_lexical_block";
4545 return "DW_TAG_member";
4546 case DW_TAG_pointer_type
:
4547 return "DW_TAG_pointer_type";
4548 case DW_TAG_reference_type
:
4549 return "DW_TAG_reference_type";
4550 case DW_TAG_compile_unit
:
4551 return "DW_TAG_compile_unit";
4552 case DW_TAG_string_type
:
4553 return "DW_TAG_string_type";
4554 case DW_TAG_structure_type
:
4555 return "DW_TAG_structure_type";
4556 case DW_TAG_subroutine_type
:
4557 return "DW_TAG_subroutine_type";
4558 case DW_TAG_typedef
:
4559 return "DW_TAG_typedef";
4560 case DW_TAG_union_type
:
4561 return "DW_TAG_union_type";
4562 case DW_TAG_unspecified_parameters
:
4563 return "DW_TAG_unspecified_parameters";
4564 case DW_TAG_variant
:
4565 return "DW_TAG_variant";
4566 case DW_TAG_common_block
:
4567 return "DW_TAG_common_block";
4568 case DW_TAG_common_inclusion
:
4569 return "DW_TAG_common_inclusion";
4570 case DW_TAG_inheritance
:
4571 return "DW_TAG_inheritance";
4572 case DW_TAG_inlined_subroutine
:
4573 return "DW_TAG_inlined_subroutine";
4575 return "DW_TAG_module";
4576 case DW_TAG_ptr_to_member_type
:
4577 return "DW_TAG_ptr_to_member_type";
4578 case DW_TAG_set_type
:
4579 return "DW_TAG_set_type";
4580 case DW_TAG_subrange_type
:
4581 return "DW_TAG_subrange_type";
4582 case DW_TAG_with_stmt
:
4583 return "DW_TAG_with_stmt";
4584 case DW_TAG_access_declaration
:
4585 return "DW_TAG_access_declaration";
4586 case DW_TAG_base_type
:
4587 return "DW_TAG_base_type";
4588 case DW_TAG_catch_block
:
4589 return "DW_TAG_catch_block";
4590 case DW_TAG_const_type
:
4591 return "DW_TAG_const_type";
4592 case DW_TAG_constant
:
4593 return "DW_TAG_constant";
4594 case DW_TAG_enumerator
:
4595 return "DW_TAG_enumerator";
4596 case DW_TAG_file_type
:
4597 return "DW_TAG_file_type";
4599 return "DW_TAG_friend";
4600 case DW_TAG_namelist
:
4601 return "DW_TAG_namelist";
4602 case DW_TAG_namelist_item
:
4603 return "DW_TAG_namelist_item";
4604 case DW_TAG_packed_type
:
4605 return "DW_TAG_packed_type";
4606 case DW_TAG_subprogram
:
4607 return "DW_TAG_subprogram";
4608 case DW_TAG_template_type_param
:
4609 return "DW_TAG_template_type_param";
4610 case DW_TAG_template_value_param
:
4611 return "DW_TAG_template_value_param";
4612 case DW_TAG_thrown_type
:
4613 return "DW_TAG_thrown_type";
4614 case DW_TAG_try_block
:
4615 return "DW_TAG_try_block";
4616 case DW_TAG_variant_part
:
4617 return "DW_TAG_variant_part";
4618 case DW_TAG_variable
:
4619 return "DW_TAG_variable";
4620 case DW_TAG_volatile_type
:
4621 return "DW_TAG_volatile_type";
4622 case DW_TAG_dwarf_procedure
:
4623 return "DW_TAG_dwarf_procedure";
4624 case DW_TAG_restrict_type
:
4625 return "DW_TAG_restrict_type";
4626 case DW_TAG_interface_type
:
4627 return "DW_TAG_interface_type";
4628 case DW_TAG_namespace
:
4629 return "DW_TAG_namespace";
4630 case DW_TAG_imported_module
:
4631 return "DW_TAG_imported_module";
4632 case DW_TAG_unspecified_type
:
4633 return "DW_TAG_unspecified_type";
4634 case DW_TAG_partial_unit
:
4635 return "DW_TAG_partial_unit";
4636 case DW_TAG_imported_unit
:
4637 return "DW_TAG_imported_unit";
4638 case DW_TAG_condition
:
4639 return "DW_TAG_condition";
4640 case DW_TAG_shared_type
:
4641 return "DW_TAG_shared_type";
4642 case DW_TAG_MIPS_loop
:
4643 return "DW_TAG_MIPS_loop";
4644 case DW_TAG_format_label
:
4645 return "DW_TAG_format_label";
4646 case DW_TAG_function_template
:
4647 return "DW_TAG_function_template";
4648 case DW_TAG_class_template
:
4649 return "DW_TAG_class_template";
4650 case DW_TAG_GNU_BINCL
:
4651 return "DW_TAG_GNU_BINCL";
4652 case DW_TAG_GNU_EINCL
:
4653 return "DW_TAG_GNU_EINCL";
4655 return "DW_TAG_<unknown>";
4659 /* Convert a DWARF attribute code into its string name. */
4662 dwarf_attr_name (unsigned int attr
)
4667 return "DW_AT_sibling";
4668 case DW_AT_location
:
4669 return "DW_AT_location";
4671 return "DW_AT_name";
4672 case DW_AT_ordering
:
4673 return "DW_AT_ordering";
4674 case DW_AT_subscr_data
:
4675 return "DW_AT_subscr_data";
4676 case DW_AT_byte_size
:
4677 return "DW_AT_byte_size";
4678 case DW_AT_bit_offset
:
4679 return "DW_AT_bit_offset";
4680 case DW_AT_bit_size
:
4681 return "DW_AT_bit_size";
4682 case DW_AT_element_list
:
4683 return "DW_AT_element_list";
4684 case DW_AT_stmt_list
:
4685 return "DW_AT_stmt_list";
4687 return "DW_AT_low_pc";
4689 return "DW_AT_high_pc";
4690 case DW_AT_language
:
4691 return "DW_AT_language";
4693 return "DW_AT_member";
4695 return "DW_AT_discr";
4696 case DW_AT_discr_value
:
4697 return "DW_AT_discr_value";
4698 case DW_AT_visibility
:
4699 return "DW_AT_visibility";
4701 return "DW_AT_import";
4702 case DW_AT_string_length
:
4703 return "DW_AT_string_length";
4704 case DW_AT_common_reference
:
4705 return "DW_AT_common_reference";
4706 case DW_AT_comp_dir
:
4707 return "DW_AT_comp_dir";
4708 case DW_AT_const_value
:
4709 return "DW_AT_const_value";
4710 case DW_AT_containing_type
:
4711 return "DW_AT_containing_type";
4712 case DW_AT_default_value
:
4713 return "DW_AT_default_value";
4715 return "DW_AT_inline";
4716 case DW_AT_is_optional
:
4717 return "DW_AT_is_optional";
4718 case DW_AT_lower_bound
:
4719 return "DW_AT_lower_bound";
4720 case DW_AT_producer
:
4721 return "DW_AT_producer";
4722 case DW_AT_prototyped
:
4723 return "DW_AT_prototyped";
4724 case DW_AT_return_addr
:
4725 return "DW_AT_return_addr";
4726 case DW_AT_start_scope
:
4727 return "DW_AT_start_scope";
4728 case DW_AT_bit_stride
:
4729 return "DW_AT_bit_stride";
4730 case DW_AT_upper_bound
:
4731 return "DW_AT_upper_bound";
4732 case DW_AT_abstract_origin
:
4733 return "DW_AT_abstract_origin";
4734 case DW_AT_accessibility
:
4735 return "DW_AT_accessibility";
4736 case DW_AT_address_class
:
4737 return "DW_AT_address_class";
4738 case DW_AT_artificial
:
4739 return "DW_AT_artificial";
4740 case DW_AT_base_types
:
4741 return "DW_AT_base_types";
4742 case DW_AT_calling_convention
:
4743 return "DW_AT_calling_convention";
4745 return "DW_AT_count";
4746 case DW_AT_data_member_location
:
4747 return "DW_AT_data_member_location";
4748 case DW_AT_decl_column
:
4749 return "DW_AT_decl_column";
4750 case DW_AT_decl_file
:
4751 return "DW_AT_decl_file";
4752 case DW_AT_decl_line
:
4753 return "DW_AT_decl_line";
4754 case DW_AT_declaration
:
4755 return "DW_AT_declaration";
4756 case DW_AT_discr_list
:
4757 return "DW_AT_discr_list";
4758 case DW_AT_encoding
:
4759 return "DW_AT_encoding";
4760 case DW_AT_external
:
4761 return "DW_AT_external";
4762 case DW_AT_frame_base
:
4763 return "DW_AT_frame_base";
4765 return "DW_AT_friend";
4766 case DW_AT_identifier_case
:
4767 return "DW_AT_identifier_case";
4768 case DW_AT_macro_info
:
4769 return "DW_AT_macro_info";
4770 case DW_AT_namelist_items
:
4771 return "DW_AT_namelist_items";
4772 case DW_AT_priority
:
4773 return "DW_AT_priority";
4775 return "DW_AT_segment";
4776 case DW_AT_specification
:
4777 return "DW_AT_specification";
4778 case DW_AT_static_link
:
4779 return "DW_AT_static_link";
4781 return "DW_AT_type";
4782 case DW_AT_use_location
:
4783 return "DW_AT_use_location";
4784 case DW_AT_variable_parameter
:
4785 return "DW_AT_variable_parameter";
4786 case DW_AT_virtuality
:
4787 return "DW_AT_virtuality";
4788 case DW_AT_vtable_elem_location
:
4789 return "DW_AT_vtable_elem_location";
4791 case DW_AT_allocated
:
4792 return "DW_AT_allocated";
4793 case DW_AT_associated
:
4794 return "DW_AT_associated";
4795 case DW_AT_data_location
:
4796 return "DW_AT_data_location";
4797 case DW_AT_byte_stride
:
4798 return "DW_AT_byte_stride";
4799 case DW_AT_entry_pc
:
4800 return "DW_AT_entry_pc";
4801 case DW_AT_use_UTF8
:
4802 return "DW_AT_use_UTF8";
4803 case DW_AT_extension
:
4804 return "DW_AT_extension";
4806 return "DW_AT_ranges";
4807 case DW_AT_trampoline
:
4808 return "DW_AT_trampoline";
4809 case DW_AT_call_column
:
4810 return "DW_AT_call_column";
4811 case DW_AT_call_file
:
4812 return "DW_AT_call_file";
4813 case DW_AT_call_line
:
4814 return "DW_AT_call_line";
4816 case DW_AT_MIPS_fde
:
4817 return "DW_AT_MIPS_fde";
4818 case DW_AT_MIPS_loop_begin
:
4819 return "DW_AT_MIPS_loop_begin";
4820 case DW_AT_MIPS_tail_loop_begin
:
4821 return "DW_AT_MIPS_tail_loop_begin";
4822 case DW_AT_MIPS_epilog_begin
:
4823 return "DW_AT_MIPS_epilog_begin";
4824 case DW_AT_MIPS_loop_unroll_factor
:
4825 return "DW_AT_MIPS_loop_unroll_factor";
4826 case DW_AT_MIPS_software_pipeline_depth
:
4827 return "DW_AT_MIPS_software_pipeline_depth";
4828 case DW_AT_MIPS_linkage_name
:
4829 return "DW_AT_MIPS_linkage_name";
4830 case DW_AT_MIPS_stride
:
4831 return "DW_AT_MIPS_stride";
4832 case DW_AT_MIPS_abstract_name
:
4833 return "DW_AT_MIPS_abstract_name";
4834 case DW_AT_MIPS_clone_origin
:
4835 return "DW_AT_MIPS_clone_origin";
4836 case DW_AT_MIPS_has_inlines
:
4837 return "DW_AT_MIPS_has_inlines";
4839 case DW_AT_sf_names
:
4840 return "DW_AT_sf_names";
4841 case DW_AT_src_info
:
4842 return "DW_AT_src_info";
4843 case DW_AT_mac_info
:
4844 return "DW_AT_mac_info";
4845 case DW_AT_src_coords
:
4846 return "DW_AT_src_coords";
4847 case DW_AT_body_begin
:
4848 return "DW_AT_body_begin";
4849 case DW_AT_body_end
:
4850 return "DW_AT_body_end";
4851 case DW_AT_GNU_vector
:
4852 return "DW_AT_GNU_vector";
4854 case DW_AT_VMS_rtnbeg_pd_address
:
4855 return "DW_AT_VMS_rtnbeg_pd_address";
4858 return "DW_AT_<unknown>";
4862 /* Convert a DWARF value form code into its string name. */
4865 dwarf_form_name (unsigned int form
)
4870 return "DW_FORM_addr";
4871 case DW_FORM_block2
:
4872 return "DW_FORM_block2";
4873 case DW_FORM_block4
:
4874 return "DW_FORM_block4";
4876 return "DW_FORM_data2";
4878 return "DW_FORM_data4";
4880 return "DW_FORM_data8";
4881 case DW_FORM_string
:
4882 return "DW_FORM_string";
4884 return "DW_FORM_block";
4885 case DW_FORM_block1
:
4886 return "DW_FORM_block1";
4888 return "DW_FORM_data1";
4890 return "DW_FORM_flag";
4892 return "DW_FORM_sdata";
4894 return "DW_FORM_strp";
4896 return "DW_FORM_udata";
4897 case DW_FORM_ref_addr
:
4898 return "DW_FORM_ref_addr";
4900 return "DW_FORM_ref1";
4902 return "DW_FORM_ref2";
4904 return "DW_FORM_ref4";
4906 return "DW_FORM_ref8";
4907 case DW_FORM_ref_udata
:
4908 return "DW_FORM_ref_udata";
4909 case DW_FORM_indirect
:
4910 return "DW_FORM_indirect";
4912 return "DW_FORM_<unknown>";
4916 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4917 instance of an inlined instance of a decl which is local to an inline
4918 function, so we have to trace all of the way back through the origin chain
4919 to find out what sort of node actually served as the original seed for the
4923 decl_ultimate_origin (const_tree decl
)
4925 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
4928 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4929 nodes in the function to point to themselves; ignore that if
4930 we're trying to output the abstract instance of this function. */
4931 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4934 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4935 most distant ancestor, this should never happen. */
4936 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
4938 return DECL_ABSTRACT_ORIGIN (decl
);
4941 /* Determine the "ultimate origin" of a block. The block may be an inlined
4942 instance of an inlined instance of a block which is local to an inline
4943 function, so we have to trace all of the way back through the origin chain
4944 to find out what sort of node actually served as the original seed for the
4948 block_ultimate_origin (const_tree block
)
4950 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4952 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4953 nodes in the function to point to themselves; ignore that if
4954 we're trying to output the abstract instance of this function. */
4955 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4958 if (immediate_origin
== NULL_TREE
)
4963 tree lookahead
= immediate_origin
;
4967 ret_val
= lookahead
;
4968 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4969 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4971 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4973 /* The block's abstract origin chain may not be the *ultimate* origin of
4974 the block. It could lead to a DECL that has an abstract origin set.
4975 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4976 will give us if it has one). Note that DECL's abstract origins are
4977 supposed to be the most distant ancestor (or so decl_ultimate_origin
4978 claims), so we don't need to loop following the DECL origins. */
4979 if (DECL_P (ret_val
))
4980 return DECL_ORIGIN (ret_val
);
4986 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4987 of a virtual function may refer to a base class, so we check the 'this'
4991 decl_class_context (tree decl
)
4993 tree context
= NULL_TREE
;
4995 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4996 context
= DECL_CONTEXT (decl
);
4998 context
= TYPE_MAIN_VARIANT
4999 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
5001 if (context
&& !TYPE_P (context
))
5002 context
= NULL_TREE
;
5007 /* Add an attribute/value pair to a DIE. */
5010 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
5012 /* Maybe this should be an assert? */
5016 if (die
->die_attr
== NULL
)
5017 die
->die_attr
= VEC_alloc (dw_attr_node
, gc
, 1);
5018 VEC_safe_push (dw_attr_node
, gc
, die
->die_attr
, attr
);
5021 static inline enum dw_val_class
5022 AT_class (dw_attr_ref a
)
5024 return a
->dw_attr_val
.val_class
;
5027 /* Add a flag value attribute to a DIE. */
5030 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
5034 attr
.dw_attr
= attr_kind
;
5035 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
5036 attr
.dw_attr_val
.v
.val_flag
= flag
;
5037 add_dwarf_attr (die
, &attr
);
5040 static inline unsigned
5041 AT_flag (dw_attr_ref a
)
5043 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
5044 return a
->dw_attr_val
.v
.val_flag
;
5047 /* Add a signed integer attribute value to a DIE. */
5050 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
5054 attr
.dw_attr
= attr_kind
;
5055 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
5056 attr
.dw_attr_val
.v
.val_int
= int_val
;
5057 add_dwarf_attr (die
, &attr
);
5060 static inline HOST_WIDE_INT
5061 AT_int (dw_attr_ref a
)
5063 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
5064 return a
->dw_attr_val
.v
.val_int
;
5067 /* Add an unsigned integer attribute value to a DIE. */
5070 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5071 unsigned HOST_WIDE_INT unsigned_val
)
5075 attr
.dw_attr
= attr_kind
;
5076 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
5077 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
5078 add_dwarf_attr (die
, &attr
);
5081 static inline unsigned HOST_WIDE_INT
5082 AT_unsigned (dw_attr_ref a
)
5084 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
5085 return a
->dw_attr_val
.v
.val_unsigned
;
5088 /* Add an unsigned double integer attribute value to a DIE. */
5091 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5092 long unsigned int val_hi
, long unsigned int val_low
)
5096 attr
.dw_attr
= attr_kind
;
5097 attr
.dw_attr_val
.val_class
= dw_val_class_long_long
;
5098 attr
.dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
5099 attr
.dw_attr_val
.v
.val_long_long
.low
= val_low
;
5100 add_dwarf_attr (die
, &attr
);
5103 /* Add a floating point attribute value to a DIE and return it. */
5106 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5107 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
5111 attr
.dw_attr
= attr_kind
;
5112 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
5113 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
5114 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
5115 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
5116 add_dwarf_attr (die
, &attr
);
5119 /* Hash and equality functions for debug_str_hash. */
5122 debug_str_do_hash (const void *x
)
5124 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
5128 debug_str_eq (const void *x1
, const void *x2
)
5130 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
5131 (const char *)x2
) == 0;
5134 /* Add a string attribute value to a DIE. */
5137 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
5140 struct indirect_string_node
*node
;
5143 if (! debug_str_hash
)
5144 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
5145 debug_str_eq
, NULL
);
5147 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
5148 htab_hash_string (str
), INSERT
);
5151 node
= (struct indirect_string_node
*)
5152 ggc_alloc_cleared (sizeof (struct indirect_string_node
));
5153 node
->str
= ggc_strdup (str
);
5157 node
= (struct indirect_string_node
*) *slot
;
5161 attr
.dw_attr
= attr_kind
;
5162 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
5163 attr
.dw_attr_val
.v
.val_str
= node
;
5164 add_dwarf_attr (die
, &attr
);
5167 static inline const char *
5168 AT_string (dw_attr_ref a
)
5170 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5171 return a
->dw_attr_val
.v
.val_str
->str
;
5174 /* Find out whether a string should be output inline in DIE
5175 or out-of-line in .debug_str section. */
5178 AT_string_form (dw_attr_ref a
)
5180 struct indirect_string_node
*node
;
5184 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
5186 node
= a
->dw_attr_val
.v
.val_str
;
5190 len
= strlen (node
->str
) + 1;
5192 /* If the string is shorter or equal to the size of the reference, it is
5193 always better to put it inline. */
5194 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
5195 return node
->form
= DW_FORM_string
;
5197 /* If we cannot expect the linker to merge strings in .debug_str
5198 section, only put it into .debug_str if it is worth even in this
5200 if ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
5201 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
5202 return node
->form
= DW_FORM_string
;
5204 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
5205 ++dw2_string_counter
;
5206 node
->label
= xstrdup (label
);
5208 return node
->form
= DW_FORM_strp
;
5211 /* Add a DIE reference attribute value to a DIE. */
5214 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
5218 attr
.dw_attr
= attr_kind
;
5219 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
5220 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
5221 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
5222 add_dwarf_attr (die
, &attr
);
5225 /* Add an AT_specification attribute to a DIE, and also make the back
5226 pointer from the specification to the definition. */
5229 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
5231 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
5232 gcc_assert (!targ_die
->die_definition
);
5233 targ_die
->die_definition
= die
;
5236 static inline dw_die_ref
5237 AT_ref (dw_attr_ref a
)
5239 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5240 return a
->dw_attr_val
.v
.val_die_ref
.die
;
5244 AT_ref_external (dw_attr_ref a
)
5246 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
5247 return a
->dw_attr_val
.v
.val_die_ref
.external
;
5253 set_AT_ref_external (dw_attr_ref a
, int i
)
5255 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
5256 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
5259 /* Add an FDE reference attribute value to a DIE. */
5262 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
5266 attr
.dw_attr
= attr_kind
;
5267 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
5268 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
5269 add_dwarf_attr (die
, &attr
);
5272 /* Add a location description attribute value to a DIE. */
5275 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
5279 attr
.dw_attr
= attr_kind
;
5280 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
5281 attr
.dw_attr_val
.v
.val_loc
= loc
;
5282 add_dwarf_attr (die
, &attr
);
5285 static inline dw_loc_descr_ref
5286 AT_loc (dw_attr_ref a
)
5288 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
5289 return a
->dw_attr_val
.v
.val_loc
;
5293 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
5297 attr
.dw_attr
= attr_kind
;
5298 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
5299 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
5300 add_dwarf_attr (die
, &attr
);
5301 have_location_lists
= true;
5304 static inline dw_loc_list_ref
5305 AT_loc_list (dw_attr_ref a
)
5307 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
5308 return a
->dw_attr_val
.v
.val_loc_list
;
5311 /* Add an address constant attribute value to a DIE. */
5314 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
5318 attr
.dw_attr
= attr_kind
;
5319 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
5320 attr
.dw_attr_val
.v
.val_addr
= addr
;
5321 add_dwarf_attr (die
, &attr
);
5324 /* Get the RTX from to an address DIE attribute. */
5327 AT_addr (dw_attr_ref a
)
5329 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
5330 return a
->dw_attr_val
.v
.val_addr
;
5333 /* Add a file attribute value to a DIE. */
5336 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5337 struct dwarf_file_data
*fd
)
5341 attr
.dw_attr
= attr_kind
;
5342 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
5343 attr
.dw_attr_val
.v
.val_file
= fd
;
5344 add_dwarf_attr (die
, &attr
);
5347 /* Get the dwarf_file_data from a file DIE attribute. */
5349 static inline struct dwarf_file_data
*
5350 AT_file (dw_attr_ref a
)
5352 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
5353 return a
->dw_attr_val
.v
.val_file
;
5356 /* Add a label identifier attribute value to a DIE. */
5359 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5363 attr
.dw_attr
= attr_kind
;
5364 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5365 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5366 add_dwarf_attr (die
, &attr
);
5369 /* Add a section offset attribute value to a DIE, an offset into the
5370 debug_line section. */
5373 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5378 attr
.dw_attr
= attr_kind
;
5379 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
5380 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5381 add_dwarf_attr (die
, &attr
);
5384 /* Add a section offset attribute value to a DIE, an offset into the
5385 debug_macinfo section. */
5388 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5393 attr
.dw_attr
= attr_kind
;
5394 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
5395 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5396 add_dwarf_attr (die
, &attr
);
5399 /* Add an offset attribute value to a DIE. */
5402 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5403 unsigned HOST_WIDE_INT offset
)
5407 attr
.dw_attr
= attr_kind
;
5408 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
5409 attr
.dw_attr_val
.v
.val_offset
= offset
;
5410 add_dwarf_attr (die
, &attr
);
5413 /* Add an range_list attribute value to a DIE. */
5416 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5417 long unsigned int offset
)
5421 attr
.dw_attr
= attr_kind
;
5422 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
5423 attr
.dw_attr_val
.v
.val_offset
= offset
;
5424 add_dwarf_attr (die
, &attr
);
5427 static inline const char *
5428 AT_lbl (dw_attr_ref a
)
5430 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
5431 || AT_class (a
) == dw_val_class_lineptr
5432 || AT_class (a
) == dw_val_class_macptr
));
5433 return a
->dw_attr_val
.v
.val_lbl_id
;
5436 /* Get the attribute of type attr_kind. */
5439 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5443 dw_die_ref spec
= NULL
;
5448 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5449 if (a
->dw_attr
== attr_kind
)
5451 else if (a
->dw_attr
== DW_AT_specification
5452 || a
->dw_attr
== DW_AT_abstract_origin
)
5456 return get_AT (spec
, attr_kind
);
5461 /* Return the "low pc" attribute value, typically associated with a subprogram
5462 DIE. Return null if the "low pc" attribute is either not present, or if it
5463 cannot be represented as an assembler label identifier. */
5465 static inline const char *
5466 get_AT_low_pc (dw_die_ref die
)
5468 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5470 return a
? AT_lbl (a
) : NULL
;
5473 /* Return the "high pc" attribute value, typically associated with a subprogram
5474 DIE. Return null if the "high pc" attribute is either not present, or if it
5475 cannot be represented as an assembler label identifier. */
5477 static inline const char *
5478 get_AT_hi_pc (dw_die_ref die
)
5480 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5482 return a
? AT_lbl (a
) : NULL
;
5485 /* Return the value of the string attribute designated by ATTR_KIND, or
5486 NULL if it is not present. */
5488 static inline const char *
5489 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5491 dw_attr_ref a
= get_AT (die
, attr_kind
);
5493 return a
? AT_string (a
) : NULL
;
5496 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5497 if it is not present. */
5500 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5502 dw_attr_ref a
= get_AT (die
, attr_kind
);
5504 return a
? AT_flag (a
) : 0;
5507 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5508 if it is not present. */
5510 static inline unsigned
5511 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5513 dw_attr_ref a
= get_AT (die
, attr_kind
);
5515 return a
? AT_unsigned (a
) : 0;
5518 static inline dw_die_ref
5519 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5521 dw_attr_ref a
= get_AT (die
, attr_kind
);
5523 return a
? AT_ref (a
) : NULL
;
5526 static inline struct dwarf_file_data
*
5527 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5529 dw_attr_ref a
= get_AT (die
, attr_kind
);
5531 return a
? AT_file (a
) : NULL
;
5534 /* Return TRUE if the language is C or C++. */
5539 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5541 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
|| lang
== DW_LANG_ObjC
5542 || lang
== DW_LANG_C99
5543 || lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
);
5546 /* Return TRUE if the language is C++. */
5551 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5553 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
5556 /* Return TRUE if the language is Fortran. */
5561 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5563 return (lang
== DW_LANG_Fortran77
5564 || lang
== DW_LANG_Fortran90
5565 || lang
== DW_LANG_Fortran95
);
5568 /* Return TRUE if the language is Java. */
5573 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5575 return lang
== DW_LANG_Java
;
5578 /* Return TRUE if the language is Ada. */
5583 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5585 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5588 /* Remove the specified attribute if present. */
5591 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5599 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5600 if (a
->dw_attr
== attr_kind
)
5602 if (AT_class (a
) == dw_val_class_str
)
5603 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5604 a
->dw_attr_val
.v
.val_str
->refcount
--;
5606 /* VEC_ordered_remove should help reduce the number of abbrevs
5608 VEC_ordered_remove (dw_attr_node
, die
->die_attr
, ix
);
5613 /* Remove CHILD from its parent. PREV must have the property that
5614 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
5617 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
5619 gcc_assert (child
->die_parent
== prev
->die_parent
);
5620 gcc_assert (prev
->die_sib
== child
);
5623 gcc_assert (child
->die_parent
->die_child
== child
);
5627 prev
->die_sib
= child
->die_sib
;
5628 if (child
->die_parent
->die_child
== child
)
5629 child
->die_parent
->die_child
= prev
;
5632 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
5636 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5642 dw_die_ref prev
= c
;
5644 while (c
->die_tag
== tag
)
5646 remove_child_with_prev (c
, prev
);
5647 /* Might have removed every child. */
5648 if (c
== c
->die_sib
)
5652 } while (c
!= die
->die_child
);
5655 /* Add a CHILD_DIE as the last child of DIE. */
5658 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5660 /* FIXME this should probably be an assert. */
5661 if (! die
|| ! child_die
)
5663 gcc_assert (die
!= child_die
);
5665 child_die
->die_parent
= die
;
5668 child_die
->die_sib
= die
->die_child
->die_sib
;
5669 die
->die_child
->die_sib
= child_die
;
5672 child_die
->die_sib
= child_die
;
5673 die
->die_child
= child_die
;
5676 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5677 is the specification, to the end of PARENT's list of children.
5678 This is done by removing and re-adding it. */
5681 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5685 /* We want the declaration DIE from inside the class, not the
5686 specification DIE at toplevel. */
5687 if (child
->die_parent
!= parent
)
5689 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5695 gcc_assert (child
->die_parent
== parent
5696 || (child
->die_parent
5697 == get_AT_ref (parent
, DW_AT_specification
)));
5699 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5700 if (p
->die_sib
== child
)
5702 remove_child_with_prev (child
, p
);
5706 add_child_die (parent
, child
);
5709 /* Return a pointer to a newly created DIE node. */
5711 static inline dw_die_ref
5712 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5714 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5716 die
->die_tag
= tag_value
;
5718 if (parent_die
!= NULL
)
5719 add_child_die (parent_die
, die
);
5722 limbo_die_node
*limbo_node
;
5724 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5725 limbo_node
->die
= die
;
5726 limbo_node
->created_for
= t
;
5727 limbo_node
->next
= limbo_die_list
;
5728 limbo_die_list
= limbo_node
;
5734 /* Return the DIE associated with the given type specifier. */
5736 static inline dw_die_ref
5737 lookup_type_die (tree type
)
5739 return TYPE_SYMTAB_DIE (type
);
5742 /* Equate a DIE to a given type specifier. */
5745 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5747 TYPE_SYMTAB_DIE (type
) = type_die
;
5750 /* Returns a hash value for X (which really is a die_struct). */
5753 decl_die_table_hash (const void *x
)
5755 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
5758 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5761 decl_die_table_eq (const void *x
, const void *y
)
5763 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
5766 /* Return the DIE associated with a given declaration. */
5768 static inline dw_die_ref
5769 lookup_decl_die (tree decl
)
5771 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5774 /* Returns a hash value for X (which really is a var_loc_list). */
5777 decl_loc_table_hash (const void *x
)
5779 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5782 /* Return nonzero if decl_id of var_loc_list X is the same as
5786 decl_loc_table_eq (const void *x
, const void *y
)
5788 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
5791 /* Return the var_loc list associated with a given declaration. */
5793 static inline var_loc_list
*
5794 lookup_decl_loc (const_tree decl
)
5796 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5799 /* Equate a DIE to a particular declaration. */
5802 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5804 unsigned int decl_id
= DECL_UID (decl
);
5807 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5809 decl_die
->decl_id
= decl_id
;
5812 /* Add a variable location node to the linked list for DECL. */
5815 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5817 unsigned int decl_id
= DECL_UID (decl
);
5821 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5824 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5825 temp
->decl_id
= decl_id
;
5833 /* If the current location is the same as the end of the list,
5834 and either both or neither of the locations is uninitialized,
5835 we have nothing to do. */
5836 if ((!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5837 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5838 || ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
5839 != NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
))
5840 && ((NOTE_VAR_LOCATION_STATUS (temp
->last
->var_loc_note
)
5841 == VAR_INIT_STATUS_UNINITIALIZED
)
5842 || (NOTE_VAR_LOCATION_STATUS (loc
->var_loc_note
)
5843 == VAR_INIT_STATUS_UNINITIALIZED
))))
5845 /* Add LOC to the end of list and update LAST. */
5846 temp
->last
->next
= loc
;
5850 /* Do not add empty location to the beginning of the list. */
5851 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5858 /* Keep track of the number of spaces used to indent the
5859 output of the debugging routines that print the structure of
5860 the DIE internal representation. */
5861 static int print_indent
;
5863 /* Indent the line the number of spaces given by print_indent. */
5866 print_spaces (FILE *outfile
)
5868 fprintf (outfile
, "%*s", print_indent
, "");
5871 /* Print the information associated with a given DIE, and its children.
5872 This routine is a debugging aid only. */
5875 print_die (dw_die_ref die
, FILE *outfile
)
5881 print_spaces (outfile
);
5882 fprintf (outfile
, "DIE %4ld: %s\n",
5883 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5884 print_spaces (outfile
);
5885 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5886 fprintf (outfile
, " offset: %ld\n", die
->die_offset
);
5888 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
5890 print_spaces (outfile
);
5891 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5893 switch (AT_class (a
))
5895 case dw_val_class_addr
:
5896 fprintf (outfile
, "address");
5898 case dw_val_class_offset
:
5899 fprintf (outfile
, "offset");
5901 case dw_val_class_loc
:
5902 fprintf (outfile
, "location descriptor");
5904 case dw_val_class_loc_list
:
5905 fprintf (outfile
, "location list -> label:%s",
5906 AT_loc_list (a
)->ll_symbol
);
5908 case dw_val_class_range_list
:
5909 fprintf (outfile
, "range list");
5911 case dw_val_class_const
:
5912 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5914 case dw_val_class_unsigned_const
:
5915 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5917 case dw_val_class_long_long
:
5918 fprintf (outfile
, "constant (%lu,%lu)",
5919 a
->dw_attr_val
.v
.val_long_long
.hi
,
5920 a
->dw_attr_val
.v
.val_long_long
.low
);
5922 case dw_val_class_vec
:
5923 fprintf (outfile
, "floating-point or vector constant");
5925 case dw_val_class_flag
:
5926 fprintf (outfile
, "%u", AT_flag (a
));
5928 case dw_val_class_die_ref
:
5929 if (AT_ref (a
) != NULL
)
5931 if (AT_ref (a
)->die_symbol
)
5932 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5934 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5937 fprintf (outfile
, "die -> <null>");
5939 case dw_val_class_lbl_id
:
5940 case dw_val_class_lineptr
:
5941 case dw_val_class_macptr
:
5942 fprintf (outfile
, "label: %s", AT_lbl (a
));
5944 case dw_val_class_str
:
5945 if (AT_string (a
) != NULL
)
5946 fprintf (outfile
, "\"%s\"", AT_string (a
));
5948 fprintf (outfile
, "<null>");
5950 case dw_val_class_file
:
5951 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5952 AT_file (a
)->emitted_number
);
5958 fprintf (outfile
, "\n");
5961 if (die
->die_child
!= NULL
)
5964 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5967 if (print_indent
== 0)
5968 fprintf (outfile
, "\n");
5971 /* Print the contents of the source code line number correspondence table.
5972 This routine is a debugging aid only. */
5975 print_dwarf_line_table (FILE *outfile
)
5978 dw_line_info_ref line_info
;
5980 fprintf (outfile
, "\n\nDWARF source line information\n");
5981 for (i
= 1; i
< line_info_table_in_use
; i
++)
5983 line_info
= &line_info_table
[i
];
5984 fprintf (outfile
, "%5d: %4ld %6ld\n", i
,
5985 line_info
->dw_file_num
,
5986 line_info
->dw_line_num
);
5989 fprintf (outfile
, "\n\n");
5992 /* Print the information collected for a given DIE. */
5995 debug_dwarf_die (dw_die_ref die
)
5997 print_die (die
, stderr
);
6000 /* Print all DWARF information collected for the compilation unit.
6001 This routine is a debugging aid only. */
6007 print_die (comp_unit_die
, stderr
);
6008 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
6009 print_dwarf_line_table (stderr
);
6012 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
6013 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
6014 DIE that marks the start of the DIEs for this include file. */
6017 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
6019 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
6020 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
6022 new_unit
->die_sib
= old_unit
;
6026 /* Close an include-file CU and reopen the enclosing one. */
6029 pop_compile_unit (dw_die_ref old_unit
)
6031 dw_die_ref new_unit
= old_unit
->die_sib
;
6033 old_unit
->die_sib
= NULL
;
6037 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6038 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
6040 /* Calculate the checksum of a location expression. */
6043 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6045 CHECKSUM (loc
->dw_loc_opc
);
6046 CHECKSUM (loc
->dw_loc_oprnd1
);
6047 CHECKSUM (loc
->dw_loc_oprnd2
);
6050 /* Calculate the checksum of an attribute. */
6053 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
6055 dw_loc_descr_ref loc
;
6058 CHECKSUM (at
->dw_attr
);
6060 /* We don't care that this was compiled with a different compiler
6061 snapshot; if the output is the same, that's what matters. */
6062 if (at
->dw_attr
== DW_AT_producer
)
6065 switch (AT_class (at
))
6067 case dw_val_class_const
:
6068 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
6070 case dw_val_class_unsigned_const
:
6071 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
6073 case dw_val_class_long_long
:
6074 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
6076 case dw_val_class_vec
:
6077 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
6079 case dw_val_class_flag
:
6080 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
6082 case dw_val_class_str
:
6083 CHECKSUM_STRING (AT_string (at
));
6086 case dw_val_class_addr
:
6088 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6089 CHECKSUM_STRING (XSTR (r
, 0));
6092 case dw_val_class_offset
:
6093 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6096 case dw_val_class_loc
:
6097 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6098 loc_checksum (loc
, ctx
);
6101 case dw_val_class_die_ref
:
6102 die_checksum (AT_ref (at
), ctx
, mark
);
6105 case dw_val_class_fde_ref
:
6106 case dw_val_class_lbl_id
:
6107 case dw_val_class_lineptr
:
6108 case dw_val_class_macptr
:
6111 case dw_val_class_file
:
6112 CHECKSUM_STRING (AT_file (at
)->filename
);
6120 /* Calculate the checksum of a DIE. */
6123 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6129 /* To avoid infinite recursion. */
6132 CHECKSUM (die
->die_mark
);
6135 die
->die_mark
= ++(*mark
);
6137 CHECKSUM (die
->die_tag
);
6139 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6140 attr_checksum (a
, ctx
, mark
);
6142 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6146 #undef CHECKSUM_STRING
6148 /* Do the location expressions look same? */
6150 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6152 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6153 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6154 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6157 /* Do the values look the same? */
6159 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6161 dw_loc_descr_ref loc1
, loc2
;
6164 if (v1
->val_class
!= v2
->val_class
)
6167 switch (v1
->val_class
)
6169 case dw_val_class_const
:
6170 return v1
->v
.val_int
== v2
->v
.val_int
;
6171 case dw_val_class_unsigned_const
:
6172 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6173 case dw_val_class_long_long
:
6174 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
6175 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
6176 case dw_val_class_vec
:
6177 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6178 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6180 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6181 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6184 case dw_val_class_flag
:
6185 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6186 case dw_val_class_str
:
6187 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6189 case dw_val_class_addr
:
6190 r1
= v1
->v
.val_addr
;
6191 r2
= v2
->v
.val_addr
;
6192 if (GET_CODE (r1
) != GET_CODE (r2
))
6194 gcc_assert (GET_CODE (r1
) == SYMBOL_REF
);
6195 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
6197 case dw_val_class_offset
:
6198 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6200 case dw_val_class_loc
:
6201 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6203 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6204 if (!same_loc_p (loc1
, loc2
, mark
))
6206 return !loc1
&& !loc2
;
6208 case dw_val_class_die_ref
:
6209 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6211 case dw_val_class_fde_ref
:
6212 case dw_val_class_lbl_id
:
6213 case dw_val_class_lineptr
:
6214 case dw_val_class_macptr
:
6217 case dw_val_class_file
:
6218 return v1
->v
.val_file
== v2
->v
.val_file
;
6225 /* Do the attributes look the same? */
6228 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6230 if (at1
->dw_attr
!= at2
->dw_attr
)
6233 /* We don't care that this was compiled with a different compiler
6234 snapshot; if the output is the same, that's what matters. */
6235 if (at1
->dw_attr
== DW_AT_producer
)
6238 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6241 /* Do the dies look the same? */
6244 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6250 /* To avoid infinite recursion. */
6252 return die1
->die_mark
== die2
->die_mark
;
6253 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6255 if (die1
->die_tag
!= die2
->die_tag
)
6258 if (VEC_length (dw_attr_node
, die1
->die_attr
)
6259 != VEC_length (dw_attr_node
, die2
->die_attr
))
6262 for (ix
= 0; VEC_iterate (dw_attr_node
, die1
->die_attr
, ix
, a1
); ix
++)
6263 if (!same_attr_p (a1
, VEC_index (dw_attr_node
, die2
->die_attr
, ix
), mark
))
6266 c1
= die1
->die_child
;
6267 c2
= die2
->die_child
;
6276 if (!same_die_p (c1
, c2
, mark
))
6280 if (c1
== die1
->die_child
)
6282 if (c2
== die2
->die_child
)
6292 /* Do the dies look the same? Wrapper around same_die_p. */
6295 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6298 int ret
= same_die_p (die1
, die2
, &mark
);
6300 unmark_all_dies (die1
);
6301 unmark_all_dies (die2
);
6306 /* The prefix to attach to symbols on DIEs in the current comdat debug
6308 static char *comdat_symbol_id
;
6310 /* The index of the current symbol within the current comdat CU. */
6311 static unsigned int comdat_symbol_number
;
6313 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6314 children, and set comdat_symbol_id accordingly. */
6317 compute_section_prefix (dw_die_ref unit_die
)
6319 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6320 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6321 char *name
= alloca (strlen (base
) + 64);
6324 unsigned char checksum
[16];
6327 /* Compute the checksum of the DIE, then append part of it as hex digits to
6328 the name filename of the unit. */
6330 md5_init_ctx (&ctx
);
6332 die_checksum (unit_die
, &ctx
, &mark
);
6333 unmark_all_dies (unit_die
);
6334 md5_finish_ctx (&ctx
, checksum
);
6336 sprintf (name
, "%s.", base
);
6337 clean_symbol_name (name
);
6339 p
= name
+ strlen (name
);
6340 for (i
= 0; i
< 4; i
++)
6342 sprintf (p
, "%.2x", checksum
[i
]);
6346 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6347 comdat_symbol_number
= 0;
6350 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6353 is_type_die (dw_die_ref die
)
6355 switch (die
->die_tag
)
6357 case DW_TAG_array_type
:
6358 case DW_TAG_class_type
:
6359 case DW_TAG_interface_type
:
6360 case DW_TAG_enumeration_type
:
6361 case DW_TAG_pointer_type
:
6362 case DW_TAG_reference_type
:
6363 case DW_TAG_string_type
:
6364 case DW_TAG_structure_type
:
6365 case DW_TAG_subroutine_type
:
6366 case DW_TAG_union_type
:
6367 case DW_TAG_ptr_to_member_type
:
6368 case DW_TAG_set_type
:
6369 case DW_TAG_subrange_type
:
6370 case DW_TAG_base_type
:
6371 case DW_TAG_const_type
:
6372 case DW_TAG_file_type
:
6373 case DW_TAG_packed_type
:
6374 case DW_TAG_volatile_type
:
6375 case DW_TAG_typedef
:
6382 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6383 Basically, we want to choose the bits that are likely to be shared between
6384 compilations (types) and leave out the bits that are specific to individual
6385 compilations (functions). */
6388 is_comdat_die (dw_die_ref c
)
6390 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6391 we do for stabs. The advantage is a greater likelihood of sharing between
6392 objects that don't include headers in the same order (and therefore would
6393 put the base types in a different comdat). jason 8/28/00 */
6395 if (c
->die_tag
== DW_TAG_base_type
)
6398 if (c
->die_tag
== DW_TAG_pointer_type
6399 || c
->die_tag
== DW_TAG_reference_type
6400 || c
->die_tag
== DW_TAG_const_type
6401 || c
->die_tag
== DW_TAG_volatile_type
)
6403 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6405 return t
? is_comdat_die (t
) : 0;
6408 return is_type_die (c
);
6411 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6412 compilation unit. */
6415 is_symbol_die (dw_die_ref c
)
6417 return (is_type_die (c
)
6418 || (get_AT (c
, DW_AT_declaration
)
6419 && !get_AT (c
, DW_AT_specification
))
6420 || c
->die_tag
== DW_TAG_namespace
);
6424 gen_internal_sym (const char *prefix
)
6428 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6429 return xstrdup (buf
);
6432 /* Assign symbols to all worthy DIEs under DIE. */
6435 assign_symbol_names (dw_die_ref die
)
6439 if (is_symbol_die (die
))
6441 if (comdat_symbol_id
)
6443 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6445 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6446 comdat_symbol_id
, comdat_symbol_number
++);
6447 die
->die_symbol
= xstrdup (p
);
6450 die
->die_symbol
= gen_internal_sym ("LDIE");
6453 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6456 struct cu_hash_table_entry
6459 unsigned min_comdat_num
, max_comdat_num
;
6460 struct cu_hash_table_entry
*next
;
6463 /* Routines to manipulate hash table of CUs. */
6465 htab_cu_hash (const void *of
)
6467 const struct cu_hash_table_entry
*entry
= of
;
6469 return htab_hash_string (entry
->cu
->die_symbol
);
6473 htab_cu_eq (const void *of1
, const void *of2
)
6475 const struct cu_hash_table_entry
*entry1
= of1
;
6476 const struct die_struct
*entry2
= of2
;
6478 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6482 htab_cu_del (void *what
)
6484 struct cu_hash_table_entry
*next
, *entry
= what
;
6494 /* Check whether we have already seen this CU and set up SYM_NUM
6497 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6499 struct cu_hash_table_entry dummy
;
6500 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6502 dummy
.max_comdat_num
= 0;
6504 slot
= (struct cu_hash_table_entry
**)
6505 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6509 for (; entry
; last
= entry
, entry
= entry
->next
)
6511 if (same_die_p_wrap (cu
, entry
->cu
))
6517 *sym_num
= entry
->min_comdat_num
;
6521 entry
= XCNEW (struct cu_hash_table_entry
);
6523 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6524 entry
->next
= *slot
;
6530 /* Record SYM_NUM to record of CU in HTABLE. */
6532 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6534 struct cu_hash_table_entry
**slot
, *entry
;
6536 slot
= (struct cu_hash_table_entry
**)
6537 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6541 entry
->max_comdat_num
= sym_num
;
6544 /* Traverse the DIE (which is always comp_unit_die), and set up
6545 additional compilation units for each of the include files we see
6546 bracketed by BINCL/EINCL. */
6549 break_out_includes (dw_die_ref die
)
6552 dw_die_ref unit
= NULL
;
6553 limbo_die_node
*node
, **pnode
;
6554 htab_t cu_hash_table
;
6558 dw_die_ref prev
= c
;
6560 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6561 || (unit
&& is_comdat_die (c
)))
6563 dw_die_ref next
= c
->die_sib
;
6565 /* This DIE is for a secondary CU; remove it from the main one. */
6566 remove_child_with_prev (c
, prev
);
6568 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6569 unit
= push_new_compile_unit (unit
, c
);
6570 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6571 unit
= pop_compile_unit (unit
);
6573 add_child_die (unit
, c
);
6575 if (c
== die
->die_child
)
6578 } while (c
!= die
->die_child
);
6581 /* We can only use this in debugging, since the frontend doesn't check
6582 to make sure that we leave every include file we enter. */
6586 assign_symbol_names (die
);
6587 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6588 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6594 compute_section_prefix (node
->die
);
6595 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6596 &comdat_symbol_number
);
6597 assign_symbol_names (node
->die
);
6599 *pnode
= node
->next
;
6602 pnode
= &node
->next
;
6603 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6604 comdat_symbol_number
);
6607 htab_delete (cu_hash_table
);
6610 /* Traverse the DIE and add a sibling attribute if it may have the
6611 effect of speeding up access to siblings. To save some space,
6612 avoid generating sibling attributes for DIE's without children. */
6615 add_sibling_attributes (dw_die_ref die
)
6619 if (! die
->die_child
)
6622 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
6623 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6625 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
6628 /* Output all location lists for the DIE and its children. */
6631 output_location_lists (dw_die_ref die
)
6637 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6638 if (AT_class (a
) == dw_val_class_loc_list
)
6639 output_loc_list (AT_loc_list (a
));
6641 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
6644 /* The format of each DIE (and its attribute value pairs) is encoded in an
6645 abbreviation table. This routine builds the abbreviation table and assigns
6646 a unique abbreviation id for each abbreviation entry. The children of each
6647 die are visited recursively. */
6650 build_abbrev_table (dw_die_ref die
)
6652 unsigned long abbrev_id
;
6653 unsigned int n_alloc
;
6658 /* Scan the DIE references, and mark as external any that refer to
6659 DIEs from other CUs (i.e. those which are not marked). */
6660 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6661 if (AT_class (a
) == dw_val_class_die_ref
6662 && AT_ref (a
)->die_mark
== 0)
6664 gcc_assert (AT_ref (a
)->die_symbol
);
6666 set_AT_ref_external (a
, 1);
6669 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6671 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6672 dw_attr_ref die_a
, abbrev_a
;
6676 if (abbrev
->die_tag
!= die
->die_tag
)
6678 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
6681 if (VEC_length (dw_attr_node
, abbrev
->die_attr
)
6682 != VEC_length (dw_attr_node
, die
->die_attr
))
6685 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, die_a
); ix
++)
6687 abbrev_a
= VEC_index (dw_attr_node
, abbrev
->die_attr
, ix
);
6688 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
6689 || (value_format (abbrev_a
) != value_format (die_a
)))
6699 if (abbrev_id
>= abbrev_die_table_in_use
)
6701 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6703 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6704 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6705 sizeof (dw_die_ref
) * n_alloc
);
6707 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6708 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6709 abbrev_die_table_allocated
= n_alloc
;
6712 ++abbrev_die_table_in_use
;
6713 abbrev_die_table
[abbrev_id
] = die
;
6716 die
->die_abbrev
= abbrev_id
;
6717 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
));
6720 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6723 constant_size (long unsigned int value
)
6730 log
= floor_log2 (value
);
6733 log
= 1 << (floor_log2 (log
) + 1);
6738 /* Return the size of a DIE as it is represented in the
6739 .debug_info section. */
6741 static unsigned long
6742 size_of_die (dw_die_ref die
)
6744 unsigned long size
= 0;
6748 size
+= size_of_uleb128 (die
->die_abbrev
);
6749 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6751 switch (AT_class (a
))
6753 case dw_val_class_addr
:
6754 size
+= DWARF2_ADDR_SIZE
;
6756 case dw_val_class_offset
:
6757 size
+= DWARF_OFFSET_SIZE
;
6759 case dw_val_class_loc
:
6761 unsigned long lsize
= size_of_locs (AT_loc (a
));
6764 size
+= constant_size (lsize
);
6768 case dw_val_class_loc_list
:
6769 size
+= DWARF_OFFSET_SIZE
;
6771 case dw_val_class_range_list
:
6772 size
+= DWARF_OFFSET_SIZE
;
6774 case dw_val_class_const
:
6775 size
+= size_of_sleb128 (AT_int (a
));
6777 case dw_val_class_unsigned_const
:
6778 size
+= constant_size (AT_unsigned (a
));
6780 case dw_val_class_long_long
:
6781 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6783 case dw_val_class_vec
:
6784 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6785 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6787 case dw_val_class_flag
:
6790 case dw_val_class_die_ref
:
6791 if (AT_ref_external (a
))
6792 size
+= DWARF2_ADDR_SIZE
;
6794 size
+= DWARF_OFFSET_SIZE
;
6796 case dw_val_class_fde_ref
:
6797 size
+= DWARF_OFFSET_SIZE
;
6799 case dw_val_class_lbl_id
:
6800 size
+= DWARF2_ADDR_SIZE
;
6802 case dw_val_class_lineptr
:
6803 case dw_val_class_macptr
:
6804 size
+= DWARF_OFFSET_SIZE
;
6806 case dw_val_class_str
:
6807 if (AT_string_form (a
) == DW_FORM_strp
)
6808 size
+= DWARF_OFFSET_SIZE
;
6810 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6812 case dw_val_class_file
:
6813 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
6823 /* Size the debugging information associated with a given DIE. Visits the
6824 DIE's children recursively. Updates the global variable next_die_offset, on
6825 each time through. Uses the current value of next_die_offset to update the
6826 die_offset field in each DIE. */
6829 calc_die_sizes (dw_die_ref die
)
6833 die
->die_offset
= next_die_offset
;
6834 next_die_offset
+= size_of_die (die
);
6836 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
6838 if (die
->die_child
!= NULL
)
6839 /* Count the null byte used to terminate sibling lists. */
6840 next_die_offset
+= 1;
6843 /* Set the marks for a die and its children. We do this so
6844 that we know whether or not a reference needs to use FORM_ref_addr; only
6845 DIEs in the same CU will be marked. We used to clear out the offset
6846 and use that as the flag, but ran into ordering problems. */
6849 mark_dies (dw_die_ref die
)
6853 gcc_assert (!die
->die_mark
);
6856 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
6859 /* Clear the marks for a die and its children. */
6862 unmark_dies (dw_die_ref die
)
6866 gcc_assert (die
->die_mark
);
6869 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
6872 /* Clear the marks for a die, its children and referred dies. */
6875 unmark_all_dies (dw_die_ref die
)
6885 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
6887 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
6888 if (AT_class (a
) == dw_val_class_die_ref
)
6889 unmark_all_dies (AT_ref (a
));
6892 /* Return the size of the .debug_pubnames or .debug_pubtypes table
6893 generated for the compilation unit. */
6895 static unsigned long
6896 size_of_pubnames (VEC (pubname_entry
, gc
) * names
)
6902 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6903 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, p
); i
++)
6904 if (names
!= pubtype_table
6905 || p
->die
->die_offset
!= 0
6906 || !flag_eliminate_unused_debug_types
)
6907 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
6909 size
+= DWARF_OFFSET_SIZE
;
6913 /* Return the size of the information in the .debug_aranges section. */
6915 static unsigned long
6916 size_of_aranges (void)
6920 size
= DWARF_ARANGES_HEADER_SIZE
;
6922 /* Count the address/length pair for this compilation unit. */
6923 if (text_section_used
)
6924 size
+= 2 * DWARF2_ADDR_SIZE
;
6925 if (cold_text_section_used
)
6926 size
+= 2 * DWARF2_ADDR_SIZE
;
6927 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6929 /* Count the two zero words used to terminated the address range table. */
6930 size
+= 2 * DWARF2_ADDR_SIZE
;
6934 /* Select the encoding of an attribute value. */
6936 static enum dwarf_form
6937 value_format (dw_attr_ref a
)
6939 switch (a
->dw_attr_val
.val_class
)
6941 case dw_val_class_addr
:
6942 return DW_FORM_addr
;
6943 case dw_val_class_range_list
:
6944 case dw_val_class_offset
:
6945 case dw_val_class_loc_list
:
6946 switch (DWARF_OFFSET_SIZE
)
6949 return DW_FORM_data4
;
6951 return DW_FORM_data8
;
6955 case dw_val_class_loc
:
6956 switch (constant_size (size_of_locs (AT_loc (a
))))
6959 return DW_FORM_block1
;
6961 return DW_FORM_block2
;
6965 case dw_val_class_const
:
6966 return DW_FORM_sdata
;
6967 case dw_val_class_unsigned_const
:
6968 switch (constant_size (AT_unsigned (a
)))
6971 return DW_FORM_data1
;
6973 return DW_FORM_data2
;
6975 return DW_FORM_data4
;
6977 return DW_FORM_data8
;
6981 case dw_val_class_long_long
:
6982 return DW_FORM_block1
;
6983 case dw_val_class_vec
:
6984 return DW_FORM_block1
;
6985 case dw_val_class_flag
:
6986 return DW_FORM_flag
;
6987 case dw_val_class_die_ref
:
6988 if (AT_ref_external (a
))
6989 return DW_FORM_ref_addr
;
6992 case dw_val_class_fde_ref
:
6993 return DW_FORM_data
;
6994 case dw_val_class_lbl_id
:
6995 return DW_FORM_addr
;
6996 case dw_val_class_lineptr
:
6997 case dw_val_class_macptr
:
6998 return DW_FORM_data
;
6999 case dw_val_class_str
:
7000 return AT_string_form (a
);
7001 case dw_val_class_file
:
7002 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
7005 return DW_FORM_data1
;
7007 return DW_FORM_data2
;
7009 return DW_FORM_data4
;
7019 /* Output the encoding of an attribute value. */
7022 output_value_format (dw_attr_ref a
)
7024 enum dwarf_form form
= value_format (a
);
7026 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
7029 /* Output the .debug_abbrev section which defines the DIE abbreviation
7033 output_abbrev_section (void)
7035 unsigned long abbrev_id
;
7037 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7039 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7043 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
7044 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
7045 dwarf_tag_name (abbrev
->die_tag
));
7047 if (abbrev
->die_child
!= NULL
)
7048 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
7050 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
7052 for (ix
= 0; VEC_iterate (dw_attr_node
, abbrev
->die_attr
, ix
, a_attr
);
7055 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
7056 dwarf_attr_name (a_attr
->dw_attr
));
7057 output_value_format (a_attr
);
7060 dw2_asm_output_data (1, 0, NULL
);
7061 dw2_asm_output_data (1, 0, NULL
);
7064 /* Terminate the table. */
7065 dw2_asm_output_data (1, 0, NULL
);
7068 /* Output a symbol we can use to refer to this DIE from another CU. */
7071 output_die_symbol (dw_die_ref die
)
7073 char *sym
= die
->die_symbol
;
7078 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
7079 /* We make these global, not weak; if the target doesn't support
7080 .linkonce, it doesn't support combining the sections, so debugging
7082 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
7084 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
7087 /* Return a new location list, given the begin and end range, and the
7088 expression. gensym tells us whether to generate a new internal symbol for
7089 this location list node, which is done for the head of the list only. */
7091 static inline dw_loc_list_ref
7092 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
7093 const char *section
, unsigned int gensym
)
7095 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
7097 retlist
->begin
= begin
;
7099 retlist
->expr
= expr
;
7100 retlist
->section
= section
;
7102 retlist
->ll_symbol
= gen_internal_sym ("LLST");
7107 /* Add a location description expression to a location list. */
7110 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
7111 const char *begin
, const char *end
,
7112 const char *section
)
7116 /* Find the end of the chain. */
7117 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
7120 /* Add a new location list node to the list. */
7121 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
7124 /* Output the location list given to us. */
7127 output_loc_list (dw_loc_list_ref list_head
)
7129 dw_loc_list_ref curr
= list_head
;
7131 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
7133 /* Walk the location list, and output each range + expression. */
7134 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
7137 /* Don't output an entry that starts and ends at the same address. */
7138 if (strcmp (curr
->begin
, curr
->end
) == 0)
7140 if (!have_multiple_function_sections
)
7142 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
7143 "Location list begin address (%s)",
7144 list_head
->ll_symbol
);
7145 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
7146 "Location list end address (%s)",
7147 list_head
->ll_symbol
);
7151 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
7152 "Location list begin address (%s)",
7153 list_head
->ll_symbol
);
7154 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
7155 "Location list end address (%s)",
7156 list_head
->ll_symbol
);
7158 size
= size_of_locs (curr
->expr
);
7160 /* Output the block length for this list of location operations. */
7161 gcc_assert (size
<= 0xffff);
7162 dw2_asm_output_data (2, size
, "%s", "Location expression size");
7164 output_loc_sequence (curr
->expr
);
7167 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7168 "Location list terminator begin (%s)",
7169 list_head
->ll_symbol
);
7170 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
7171 "Location list terminator end (%s)",
7172 list_head
->ll_symbol
);
7175 /* Output the DIE and its attributes. Called recursively to generate
7176 the definitions of each child DIE. */
7179 output_die (dw_die_ref die
)
7186 /* If someone in another CU might refer to us, set up a symbol for
7187 them to point to. */
7188 if (die
->die_symbol
)
7189 output_die_symbol (die
);
7191 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
7192 (unsigned long)die
->die_offset
,
7193 dwarf_tag_name (die
->die_tag
));
7195 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
7197 const char *name
= dwarf_attr_name (a
->dw_attr
);
7199 switch (AT_class (a
))
7201 case dw_val_class_addr
:
7202 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
7205 case dw_val_class_offset
:
7206 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
7210 case dw_val_class_range_list
:
7212 char *p
= strchr (ranges_section_label
, '\0');
7214 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
7215 a
->dw_attr_val
.v
.val_offset
);
7216 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
7217 debug_ranges_section
, "%s", name
);
7222 case dw_val_class_loc
:
7223 size
= size_of_locs (AT_loc (a
));
7225 /* Output the block length for this list of location operations. */
7226 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
7228 output_loc_sequence (AT_loc (a
));
7231 case dw_val_class_const
:
7232 /* ??? It would be slightly more efficient to use a scheme like is
7233 used for unsigned constants below, but gdb 4.x does not sign
7234 extend. Gdb 5.x does sign extend. */
7235 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
7238 case dw_val_class_unsigned_const
:
7239 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
7240 AT_unsigned (a
), "%s", name
);
7243 case dw_val_class_long_long
:
7245 unsigned HOST_WIDE_INT first
, second
;
7247 dw2_asm_output_data (1,
7248 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7251 if (WORDS_BIG_ENDIAN
)
7253 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7254 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
7258 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
7259 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
7262 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7263 first
, "long long constant");
7264 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
7269 case dw_val_class_vec
:
7271 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
7272 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
7276 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
7277 if (elt_size
> sizeof (HOST_WIDE_INT
))
7282 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
7285 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
7286 "fp or vector constant word %u", i
);
7290 case dw_val_class_flag
:
7291 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
7294 case dw_val_class_loc_list
:
7296 char *sym
= AT_loc_list (a
)->ll_symbol
;
7299 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
7304 case dw_val_class_die_ref
:
7305 if (AT_ref_external (a
))
7307 char *sym
= AT_ref (a
)->die_symbol
;
7310 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, debug_info_section
,
7315 gcc_assert (AT_ref (a
)->die_offset
);
7316 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
7321 case dw_val_class_fde_ref
:
7325 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
7326 a
->dw_attr_val
.v
.val_fde_index
* 2);
7327 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
7332 case dw_val_class_lbl_id
:
7333 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7336 case dw_val_class_lineptr
:
7337 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7338 debug_line_section
, "%s", name
);
7341 case dw_val_class_macptr
:
7342 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
7343 debug_macinfo_section
, "%s", name
);
7346 case dw_val_class_str
:
7347 if (AT_string_form (a
) == DW_FORM_strp
)
7348 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7349 a
->dw_attr_val
.v
.val_str
->label
,
7351 "%s: \"%s\"", name
, AT_string (a
));
7353 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7356 case dw_val_class_file
:
7358 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
7360 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
7361 a
->dw_attr_val
.v
.val_file
->filename
);
7370 FOR_EACH_CHILD (die
, c
, output_die (c
));
7372 /* Add null byte to terminate sibling list. */
7373 if (die
->die_child
!= NULL
)
7374 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7375 (unsigned long) die
->die_offset
);
7378 /* Output the compilation unit that appears at the beginning of the
7379 .debug_info section, and precedes the DIE descriptions. */
7382 output_compilation_unit_header (void)
7384 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7385 dw2_asm_output_data (4, 0xffffffff,
7386 "Initial length escape value indicating 64-bit DWARF extension");
7387 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7388 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7389 "Length of Compilation Unit Info");
7390 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7391 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7392 debug_abbrev_section
,
7393 "Offset Into Abbrev. Section");
7394 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7397 /* Output the compilation unit DIE and its children. */
7400 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7402 const char *secname
;
7405 /* Unless we are outputting main CU, we may throw away empty ones. */
7406 if (!output_if_empty
&& die
->die_child
== NULL
)
7409 /* Even if there are no children of this DIE, we must output the information
7410 about the compilation unit. Otherwise, on an empty translation unit, we
7411 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7412 will then complain when examining the file. First mark all the DIEs in
7413 this CU so we know which get local refs. */
7416 build_abbrev_table (die
);
7418 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7419 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7420 calc_die_sizes (die
);
7422 oldsym
= die
->die_symbol
;
7425 tmp
= alloca (strlen (oldsym
) + 24);
7427 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7429 die
->die_symbol
= NULL
;
7430 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
7433 switch_to_section (debug_info_section
);
7435 /* Output debugging information. */
7436 output_compilation_unit_header ();
7439 /* Leave the marks on the main CU, so we can check them in
7444 die
->die_symbol
= oldsym
;
7448 /* Return the DWARF2/3 pubname associated with a decl. */
7451 dwarf2_name (tree decl
, int scope
)
7453 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
7456 /* Add a new entry to .debug_pubnames if appropriate. */
7459 add_pubname (tree decl
, dw_die_ref die
)
7463 if (! TREE_PUBLIC (decl
))
7467 e
.name
= xstrdup (dwarf2_name (decl
, 1));
7468 VEC_safe_push (pubname_entry
, gc
, pubname_table
, &e
);
7471 /* Add a new entry to .debug_pubtypes if appropriate. */
7474 add_pubtype (tree decl
, dw_die_ref die
)
7479 if ((TREE_PUBLIC (decl
)
7480 || die
->die_parent
== comp_unit_die
)
7481 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
7486 if (TYPE_NAME (decl
))
7488 if (TREE_CODE (TYPE_NAME (decl
)) == IDENTIFIER_NODE
)
7489 e
.name
= IDENTIFIER_POINTER (TYPE_NAME (decl
));
7490 else if (TREE_CODE (TYPE_NAME (decl
)) == TYPE_DECL
7491 && DECL_NAME (TYPE_NAME (decl
)))
7492 e
.name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl
)));
7494 e
.name
= xstrdup ((const char *) get_AT_string (die
, DW_AT_name
));
7498 e
.name
= xstrdup (dwarf2_name (decl
, 1));
7500 /* If we don't have a name for the type, there's no point in adding
7502 if (e
.name
&& e
.name
[0] != '\0')
7503 VEC_safe_push (pubname_entry
, gc
, pubtype_table
, &e
);
7507 /* Output the public names table used to speed up access to externally
7508 visible names; or the public types table used to find type definitions. */
7511 output_pubnames (VEC (pubname_entry
, gc
) * names
)
7514 unsigned long pubnames_length
= size_of_pubnames (names
);
7517 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7518 dw2_asm_output_data (4, 0xffffffff,
7519 "Initial length escape value indicating 64-bit DWARF extension");
7520 if (names
== pubname_table
)
7521 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7522 "Length of Public Names Info");
7524 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7525 "Length of Public Type Names Info");
7526 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7527 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7529 "Offset of Compilation Unit Info");
7530 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7531 "Compilation Unit Length");
7533 for (i
= 0; VEC_iterate (pubname_entry
, names
, i
, pub
); i
++)
7535 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7536 if (names
== pubname_table
)
7537 gcc_assert (pub
->die
->die_mark
);
7539 if (names
!= pubtype_table
7540 || pub
->die
->die_offset
!= 0
7541 || !flag_eliminate_unused_debug_types
)
7543 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7546 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7550 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7553 /* Add a new entry to .debug_aranges if appropriate. */
7556 add_arange (tree decl
, dw_die_ref die
)
7558 if (! DECL_SECTION_NAME (decl
))
7561 if (arange_table_in_use
== arange_table_allocated
)
7563 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7564 arange_table
= ggc_realloc (arange_table
,
7565 (arange_table_allocated
7566 * sizeof (dw_die_ref
)));
7567 memset (arange_table
+ arange_table_in_use
, 0,
7568 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7571 arange_table
[arange_table_in_use
++] = die
;
7574 /* Output the information that goes into the .debug_aranges table.
7575 Namely, define the beginning and ending address range of the
7576 text section generated for this compilation unit. */
7579 output_aranges (void)
7582 unsigned long aranges_length
= size_of_aranges ();
7584 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7585 dw2_asm_output_data (4, 0xffffffff,
7586 "Initial length escape value indicating 64-bit DWARF extension");
7587 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7588 "Length of Address Ranges Info");
7589 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7590 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7592 "Offset of Compilation Unit Info");
7593 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7594 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7596 /* We need to align to twice the pointer size here. */
7597 if (DWARF_ARANGES_PAD_SIZE
)
7599 /* Pad using a 2 byte words so that padding is correct for any
7601 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7602 2 * DWARF2_ADDR_SIZE
);
7603 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7604 dw2_asm_output_data (2, 0, NULL
);
7607 /* It is necessary not to output these entries if the sections were
7608 not used; if the sections were not used, the length will be 0 and
7609 the address may end up as 0 if the section is discarded by ld
7610 --gc-sections, leaving an invalid (0, 0) entry that can be
7611 confused with the terminator. */
7612 if (text_section_used
)
7614 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7615 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7616 text_section_label
, "Length");
7618 if (cold_text_section_used
)
7620 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
7622 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
7623 cold_text_section_label
, "Length");
7626 for (i
= 0; i
< arange_table_in_use
; i
++)
7628 dw_die_ref die
= arange_table
[i
];
7630 /* We shouldn't see aranges for DIEs outside of the main CU. */
7631 gcc_assert (die
->die_mark
);
7633 if (die
->die_tag
== DW_TAG_subprogram
)
7635 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7637 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7638 get_AT_low_pc (die
), "Length");
7642 /* A static variable; extract the symbol from DW_AT_location.
7643 Note that this code isn't currently hit, as we only emit
7644 aranges for functions (jason 9/23/99). */
7645 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7646 dw_loc_descr_ref loc
;
7648 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
7651 gcc_assert (loc
->dw_loc_opc
== DW_OP_addr
);
7653 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7654 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7655 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7656 get_AT_unsigned (die
, DW_AT_byte_size
),
7661 /* Output the terminator words. */
7662 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7663 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7666 /* Add a new entry to .debug_ranges. Return the offset at which it
7670 add_ranges_num (int num
)
7672 unsigned int in_use
= ranges_table_in_use
;
7674 if (in_use
== ranges_table_allocated
)
7676 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7678 = ggc_realloc (ranges_table
, (ranges_table_allocated
7679 * sizeof (struct dw_ranges_struct
)));
7680 memset (ranges_table
+ ranges_table_in_use
, 0,
7681 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7684 ranges_table
[in_use
].num
= num
;
7685 ranges_table_in_use
= in_use
+ 1;
7687 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7690 /* Add a new entry to .debug_ranges corresponding to a block, or a
7691 range terminator if BLOCK is NULL. */
7694 add_ranges (const_tree block
)
7696 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
7699 /* Add a new entry to .debug_ranges corresponding to a pair of
7703 add_ranges_by_labels (const char *begin
, const char *end
)
7705 unsigned int in_use
= ranges_by_label_in_use
;
7707 if (in_use
== ranges_by_label_allocated
)
7709 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
7711 = ggc_realloc (ranges_by_label
,
7712 (ranges_by_label_allocated
7713 * sizeof (struct dw_ranges_by_label_struct
)));
7714 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
7715 RANGES_TABLE_INCREMENT
7716 * sizeof (struct dw_ranges_by_label_struct
));
7719 ranges_by_label
[in_use
].begin
= begin
;
7720 ranges_by_label
[in_use
].end
= end
;
7721 ranges_by_label_in_use
= in_use
+ 1;
7723 return add_ranges_num (-(int)in_use
- 1);
7727 output_ranges (void)
7730 static const char *const start_fmt
= "Offset 0x%x";
7731 const char *fmt
= start_fmt
;
7733 for (i
= 0; i
< ranges_table_in_use
; i
++)
7735 int block_num
= ranges_table
[i
].num
;
7739 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7740 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7742 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7743 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7745 /* If all code is in the text section, then the compilation
7746 unit base address defaults to DW_AT_low_pc, which is the
7747 base of the text section. */
7748 if (!have_multiple_function_sections
)
7750 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7752 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7753 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7754 text_section_label
, NULL
);
7757 /* Otherwise, the compilation unit base address is zero,
7758 which allows us to use absolute addresses, and not worry
7759 about whether the target supports cross-section
7763 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7764 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7765 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7771 /* Negative block_num stands for an index into ranges_by_label. */
7772 else if (block_num
< 0)
7774 int lab_idx
= - block_num
- 1;
7776 if (!have_multiple_function_sections
)
7780 /* If we ever use add_ranges_by_labels () for a single
7781 function section, all we have to do is to take out
7783 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
7784 ranges_by_label
[lab_idx
].begin
,
7786 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7787 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
7788 ranges_by_label
[lab_idx
].end
,
7789 text_section_label
, NULL
);
7794 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
7795 ranges_by_label
[lab_idx
].begin
,
7796 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7797 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
7798 ranges_by_label
[lab_idx
].end
,
7804 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7805 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7811 /* Data structure containing information about input files. */
7814 const char *path
; /* Complete file name. */
7815 const char *fname
; /* File name part. */
7816 int length
; /* Length of entire string. */
7817 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
7818 int dir_idx
; /* Index in directory table. */
7821 /* Data structure containing information about directories with source
7825 const char *path
; /* Path including directory name. */
7826 int length
; /* Path length. */
7827 int prefix
; /* Index of directory entry which is a prefix. */
7828 int count
; /* Number of files in this directory. */
7829 int dir_idx
; /* Index of directory used as base. */
7832 /* Callback function for file_info comparison. We sort by looking at
7833 the directories in the path. */
7836 file_info_cmp (const void *p1
, const void *p2
)
7838 const struct file_info
*s1
= p1
;
7839 const struct file_info
*s2
= p2
;
7840 const unsigned char *cp1
;
7841 const unsigned char *cp2
;
7843 /* Take care of file names without directories. We need to make sure that
7844 we return consistent values to qsort since some will get confused if
7845 we return the same value when identical operands are passed in opposite
7846 orders. So if neither has a directory, return 0 and otherwise return
7847 1 or -1 depending on which one has the directory. */
7848 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7849 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7851 cp1
= (const unsigned char *) s1
->path
;
7852 cp2
= (const unsigned char *) s2
->path
;
7858 /* Reached the end of the first path? If so, handle like above. */
7859 if ((cp1
== (const unsigned char *) s1
->fname
)
7860 || (cp2
== (const unsigned char *) s2
->fname
))
7861 return ((cp2
== (const unsigned char *) s2
->fname
)
7862 - (cp1
== (const unsigned char *) s1
->fname
));
7864 /* Character of current path component the same? */
7865 else if (*cp1
!= *cp2
)
7870 struct file_name_acquire_data
7872 struct file_info
*files
;
7877 /* Traversal function for the hash table. */
7880 file_name_acquire (void ** slot
, void *data
)
7882 struct file_name_acquire_data
*fnad
= data
;
7883 struct dwarf_file_data
*d
= *slot
;
7884 struct file_info
*fi
;
7887 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
7889 if (! d
->emitted_number
)
7892 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
7894 fi
= fnad
->files
+ fnad
->used_files
++;
7896 /* Skip all leading "./". */
7898 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
7901 /* Create a new array entry. */
7903 fi
->length
= strlen (f
);
7906 /* Search for the file name part. */
7907 f
= strrchr (f
, DIR_SEPARATOR
);
7908 #if defined (DIR_SEPARATOR_2)
7910 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
7914 if (f
== NULL
|| f
< g
)
7920 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
7924 /* Output the directory table and the file name table. We try to minimize
7925 the total amount of memory needed. A heuristic is used to avoid large
7926 slowdowns with many input files. */
7929 output_file_names (void)
7931 struct file_name_acquire_data fnad
;
7933 struct file_info
*files
;
7934 struct dir_info
*dirs
;
7943 if (!last_emitted_file
)
7945 dw2_asm_output_data (1, 0, "End directory table");
7946 dw2_asm_output_data (1, 0, "End file name table");
7950 numfiles
= last_emitted_file
->emitted_number
;
7952 /* Allocate the various arrays we need. */
7953 files
= alloca (numfiles
* sizeof (struct file_info
));
7954 dirs
= alloca (numfiles
* sizeof (struct dir_info
));
7957 fnad
.used_files
= 0;
7958 fnad
.max_files
= numfiles
;
7959 htab_traverse (file_table
, file_name_acquire
, &fnad
);
7960 gcc_assert (fnad
.used_files
== fnad
.max_files
);
7962 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
7964 /* Find all the different directories used. */
7965 dirs
[0].path
= files
[0].path
;
7966 dirs
[0].length
= files
[0].fname
- files
[0].path
;
7967 dirs
[0].prefix
= -1;
7969 dirs
[0].dir_idx
= 0;
7970 files
[0].dir_idx
= 0;
7973 for (i
= 1; i
< numfiles
; i
++)
7974 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7975 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7976 dirs
[ndirs
- 1].length
) == 0)
7978 /* Same directory as last entry. */
7979 files
[i
].dir_idx
= ndirs
- 1;
7980 ++dirs
[ndirs
- 1].count
;
7986 /* This is a new directory. */
7987 dirs
[ndirs
].path
= files
[i
].path
;
7988 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7989 dirs
[ndirs
].count
= 1;
7990 dirs
[ndirs
].dir_idx
= ndirs
;
7991 files
[i
].dir_idx
= ndirs
;
7993 /* Search for a prefix. */
7994 dirs
[ndirs
].prefix
= -1;
7995 for (j
= 0; j
< ndirs
; j
++)
7996 if (dirs
[j
].length
< dirs
[ndirs
].length
7997 && dirs
[j
].length
> 1
7998 && (dirs
[ndirs
].prefix
== -1
7999 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
8000 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
8001 dirs
[ndirs
].prefix
= j
;
8006 /* Now to the actual work. We have to find a subset of the directories which
8007 allow expressing the file name using references to the directory table
8008 with the least amount of characters. We do not do an exhaustive search
8009 where we would have to check out every combination of every single
8010 possible prefix. Instead we use a heuristic which provides nearly optimal
8011 results in most cases and never is much off. */
8012 saved
= alloca (ndirs
* sizeof (int));
8013 savehere
= alloca (ndirs
* sizeof (int));
8015 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
8016 for (i
= 0; i
< ndirs
; i
++)
8021 /* We can always save some space for the current directory. But this
8022 does not mean it will be enough to justify adding the directory. */
8023 savehere
[i
] = dirs
[i
].length
;
8024 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
8026 for (j
= i
+ 1; j
< ndirs
; j
++)
8029 if (saved
[j
] < dirs
[i
].length
)
8031 /* Determine whether the dirs[i] path is a prefix of the
8036 while (k
!= -1 && k
!= (int) i
)
8041 /* Yes it is. We can possibly save some memory by
8042 writing the filenames in dirs[j] relative to
8044 savehere
[j
] = dirs
[i
].length
;
8045 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
8050 /* Check whether we can save enough to justify adding the dirs[i]
8052 if (total
> dirs
[i
].length
+ 1)
8054 /* It's worthwhile adding. */
8055 for (j
= i
; j
< ndirs
; j
++)
8056 if (savehere
[j
] > 0)
8058 /* Remember how much we saved for this directory so far. */
8059 saved
[j
] = savehere
[j
];
8061 /* Remember the prefix directory. */
8062 dirs
[j
].dir_idx
= i
;
8067 /* Emit the directory name table. */
8069 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
8070 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
8071 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
8072 "Directory Entry: 0x%x", i
+ idx_offset
);
8074 dw2_asm_output_data (1, 0, "End directory table");
8076 /* We have to emit them in the order of emitted_number since that's
8077 used in the debug info generation. To do this efficiently we
8078 generate a back-mapping of the indices first. */
8079 backmap
= alloca (numfiles
* sizeof (int));
8080 for (i
= 0; i
< numfiles
; i
++)
8081 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
8083 /* Now write all the file names. */
8084 for (i
= 0; i
< numfiles
; i
++)
8086 int file_idx
= backmap
[i
];
8087 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
8089 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
8090 "File Entry: 0x%x", (unsigned) i
+ 1);
8092 /* Include directory index. */
8093 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
8095 /* Modification time. */
8096 dw2_asm_output_data_uleb128 (0, NULL
);
8098 /* File length in bytes. */
8099 dw2_asm_output_data_uleb128 (0, NULL
);
8102 dw2_asm_output_data (1, 0, "End file name table");
8106 /* Output the source line number correspondence information. This
8107 information goes into the .debug_line section. */
8110 output_line_info (void)
8112 char l1
[20], l2
[20], p1
[20], p2
[20];
8113 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8114 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
8117 unsigned long lt_index
;
8118 unsigned long current_line
;
8121 unsigned long current_file
;
8122 unsigned long function
;
8124 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
8125 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
8126 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
8127 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
8129 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8130 dw2_asm_output_data (4, 0xffffffff,
8131 "Initial length escape value indicating 64-bit DWARF extension");
8132 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
8133 "Length of Source Line Info");
8134 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
8136 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
8137 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
8138 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
8140 /* Define the architecture-dependent minimum instruction length (in
8141 bytes). In this implementation of DWARF, this field is used for
8142 information purposes only. Since GCC generates assembly language,
8143 we have no a priori knowledge of how many instruction bytes are
8144 generated for each source line, and therefore can use only the
8145 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
8146 commands. Accordingly, we fix this as `1', which is "correct
8147 enough" for all architectures, and don't let the target override. */
8148 dw2_asm_output_data (1, 1,
8149 "Minimum Instruction Length");
8151 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
8152 "Default is_stmt_start flag");
8153 dw2_asm_output_data (1, DWARF_LINE_BASE
,
8154 "Line Base Value (Special Opcodes)");
8155 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
8156 "Line Range Value (Special Opcodes)");
8157 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
8158 "Special Opcode Base");
8160 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
8164 case DW_LNS_advance_pc
:
8165 case DW_LNS_advance_line
:
8166 case DW_LNS_set_file
:
8167 case DW_LNS_set_column
:
8168 case DW_LNS_fixed_advance_pc
:
8176 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
8180 /* Write out the information about the files we use. */
8181 output_file_names ();
8182 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
8184 /* We used to set the address register to the first location in the text
8185 section here, but that didn't accomplish anything since we already
8186 have a line note for the opening brace of the first function. */
8188 /* Generate the line number to PC correspondence table, encoded as
8189 a series of state machine operations. */
8193 if (cfun
&& in_cold_section_p
)
8194 strcpy (prev_line_label
, cfun
->cold_section_label
);
8196 strcpy (prev_line_label
, text_section_label
);
8197 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
8199 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
8202 /* Disable this optimization for now; GDB wants to see two line notes
8203 at the beginning of a function so it can find the end of the
8206 /* Don't emit anything for redundant notes. Just updating the
8207 address doesn't accomplish anything, because we already assume
8208 that anything after the last address is this line. */
8209 if (line_info
->dw_line_num
== current_line
8210 && line_info
->dw_file_num
== current_file
)
8214 /* Emit debug info for the address of the current line.
8216 Unfortunately, we have little choice here currently, and must always
8217 use the most general form. GCC does not know the address delta
8218 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
8219 attributes which will give an upper bound on the address range. We
8220 could perhaps use length attributes to determine when it is safe to
8221 use DW_LNS_fixed_advance_pc. */
8223 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
8226 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
8227 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8228 "DW_LNS_fixed_advance_pc");
8229 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8233 /* This can handle any delta. This takes
8234 4+DWARF2_ADDR_SIZE bytes. */
8235 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8236 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8237 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8238 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8241 strcpy (prev_line_label
, line_label
);
8243 /* Emit debug info for the source file of the current line, if
8244 different from the previous line. */
8245 if (line_info
->dw_file_num
!= current_file
)
8247 current_file
= line_info
->dw_file_num
;
8248 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8249 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
8252 /* Emit debug info for the current line number, choosing the encoding
8253 that uses the least amount of space. */
8254 if (line_info
->dw_line_num
!= current_line
)
8256 line_offset
= line_info
->dw_line_num
- current_line
;
8257 line_delta
= line_offset
- DWARF_LINE_BASE
;
8258 current_line
= line_info
->dw_line_num
;
8259 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8260 /* This can handle deltas from -10 to 234, using the current
8261 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
8263 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8264 "line %lu", current_line
);
8267 /* This can handle any delta. This takes at least 4 bytes,
8268 depending on the value being encoded. */
8269 dw2_asm_output_data (1, DW_LNS_advance_line
,
8270 "advance to line %lu", current_line
);
8271 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8272 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8276 /* We still need to start a new row, so output a copy insn. */
8277 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8280 /* Emit debug info for the address of the end of the function. */
8283 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8284 "DW_LNS_fixed_advance_pc");
8285 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
8289 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8290 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8291 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8292 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
8295 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8296 dw2_asm_output_data_uleb128 (1, NULL
);
8297 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8302 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
8304 dw_separate_line_info_ref line_info
8305 = &separate_line_info_table
[lt_index
];
8308 /* Don't emit anything for redundant notes. */
8309 if (line_info
->dw_line_num
== current_line
8310 && line_info
->dw_file_num
== current_file
8311 && line_info
->function
== function
)
8315 /* Emit debug info for the address of the current line. If this is
8316 a new function, or the first line of a function, then we need
8317 to handle it differently. */
8318 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
8320 if (function
!= line_info
->function
)
8322 function
= line_info
->function
;
8324 /* Set the address register to the first line in the function. */
8325 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8326 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8327 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8328 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8332 /* ??? See the DW_LNS_advance_pc comment above. */
8335 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8336 "DW_LNS_fixed_advance_pc");
8337 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8341 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8342 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8343 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8344 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8348 strcpy (prev_line_label
, line_label
);
8350 /* Emit debug info for the source file of the current line, if
8351 different from the previous line. */
8352 if (line_info
->dw_file_num
!= current_file
)
8354 current_file
= line_info
->dw_file_num
;
8355 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
8356 dw2_asm_output_data_uleb128 (current_file
, "%lu", current_file
);
8359 /* Emit debug info for the current line number, choosing the encoding
8360 that uses the least amount of space. */
8361 if (line_info
->dw_line_num
!= current_line
)
8363 line_offset
= line_info
->dw_line_num
- current_line
;
8364 line_delta
= line_offset
- DWARF_LINE_BASE
;
8365 current_line
= line_info
->dw_line_num
;
8366 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
8367 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
8368 "line %lu", current_line
);
8371 dw2_asm_output_data (1, DW_LNS_advance_line
,
8372 "advance to line %lu", current_line
);
8373 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
8374 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8378 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
8386 /* If we're done with a function, end its sequence. */
8387 if (lt_index
== separate_line_info_table_in_use
8388 || separate_line_info_table
[lt_index
].function
!= function
)
8393 /* Emit debug info for the address of the end of the function. */
8394 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
8397 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
8398 "DW_LNS_fixed_advance_pc");
8399 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
8403 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
8404 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
8405 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
8406 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
8409 /* Output the marker for the end of this sequence. */
8410 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
8411 dw2_asm_output_data_uleb128 (1, NULL
);
8412 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
8416 /* Output the marker for the end of the line number info. */
8417 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
8420 /* Given a pointer to a tree node for some base type, return a pointer to
8421 a DIE that describes the given type.
8423 This routine must only be called for GCC type nodes that correspond to
8424 Dwarf base (fundamental) types. */
8427 base_type_die (tree type
)
8429 dw_die_ref base_type_result
;
8430 enum dwarf_type encoding
;
8432 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
8435 switch (TREE_CODE (type
))
8438 if (TYPE_STRING_FLAG (type
))
8440 if (TYPE_UNSIGNED (type
))
8441 encoding
= DW_ATE_unsigned_char
;
8443 encoding
= DW_ATE_signed_char
;
8445 else if (TYPE_UNSIGNED (type
))
8446 encoding
= DW_ATE_unsigned
;
8448 encoding
= DW_ATE_signed
;
8452 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
8453 encoding
= DW_ATE_decimal_float
;
8455 encoding
= DW_ATE_float
;
8458 case FIXED_POINT_TYPE
:
8459 if (TYPE_UNSIGNED (type
))
8460 encoding
= DW_ATE_unsigned_fixed
;
8462 encoding
= DW_ATE_signed_fixed
;
8465 /* Dwarf2 doesn't know anything about complex ints, so use
8466 a user defined type for it. */
8468 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
8469 encoding
= DW_ATE_complex_float
;
8471 encoding
= DW_ATE_lo_user
;
8475 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8476 encoding
= DW_ATE_boolean
;
8480 /* No other TREE_CODEs are Dwarf fundamental types. */
8484 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8486 /* This probably indicates a bug. */
8487 if (! TYPE_NAME (type
))
8488 add_name_attribute (base_type_result
, "__unknown__");
8490 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8491 int_size_in_bytes (type
));
8492 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8494 return base_type_result
;
8497 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8498 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8501 is_base_type (tree type
)
8503 switch (TREE_CODE (type
))
8509 case FIXED_POINT_TYPE
:
8517 case QUAL_UNION_TYPE
:
8522 case REFERENCE_TYPE
:
8535 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8536 node, return the size in bits for the type if it is a constant, or else
8537 return the alignment for the type if the type's size is not constant, or
8538 else return BITS_PER_WORD if the type actually turns out to be an
8541 static inline unsigned HOST_WIDE_INT
8542 simple_type_size_in_bits (const_tree type
)
8544 if (TREE_CODE (type
) == ERROR_MARK
)
8545 return BITS_PER_WORD
;
8546 else if (TYPE_SIZE (type
) == NULL_TREE
)
8548 else if (host_integerp (TYPE_SIZE (type
), 1))
8549 return tree_low_cst (TYPE_SIZE (type
), 1);
8551 return TYPE_ALIGN (type
);
8554 /* Return true if the debug information for the given type should be
8555 emitted as a subrange type. */
8558 is_subrange_type (const_tree type
)
8560 tree subtype
= TREE_TYPE (type
);
8562 /* Subrange types are identified by the fact that they are integer
8563 types, and that they have a subtype which is either an integer type
8564 or an enumeral type. */
8566 if (TREE_CODE (type
) != INTEGER_TYPE
8567 || subtype
== NULL_TREE
)
8570 if (TREE_CODE (subtype
) != INTEGER_TYPE
8571 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8574 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8575 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8576 && TYPE_MIN_VALUE (type
) != NULL
8577 && TYPE_MIN_VALUE (subtype
) != NULL
8578 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8579 && TYPE_MAX_VALUE (type
) != NULL
8580 && TYPE_MAX_VALUE (subtype
) != NULL
8581 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8583 /* The type and its subtype have the same representation. If in
8584 addition the two types also have the same name, then the given
8585 type is not a subrange type, but rather a plain base type. */
8586 /* FIXME: brobecker/2004-03-22:
8587 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8588 therefore be sufficient to check the TYPE_SIZE node pointers
8589 rather than checking the actual size. Unfortunately, we have
8590 found some cases, such as in the Ada "integer" type, where
8591 this is not the case. Until this problem is solved, we need to
8592 keep checking the actual size. */
8593 tree type_name
= TYPE_NAME (type
);
8594 tree subtype_name
= TYPE_NAME (subtype
);
8596 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8597 type_name
= DECL_NAME (type_name
);
8599 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8600 subtype_name
= DECL_NAME (subtype_name
);
8602 if (type_name
== subtype_name
)
8609 /* Given a pointer to a tree node for a subrange type, return a pointer
8610 to a DIE that describes the given type. */
8613 subrange_type_die (tree type
, dw_die_ref context_die
)
8615 dw_die_ref subrange_die
;
8616 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8618 if (context_die
== NULL
)
8619 context_die
= comp_unit_die
;
8621 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8623 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
8625 /* The size of the subrange type and its base type do not match,
8626 so we need to generate a size attribute for the subrange type. */
8627 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8630 if (TYPE_MIN_VALUE (type
) != NULL
)
8631 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8632 TYPE_MIN_VALUE (type
));
8633 if (TYPE_MAX_VALUE (type
) != NULL
)
8634 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8635 TYPE_MAX_VALUE (type
));
8637 return subrange_die
;
8640 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8641 entry that chains various modifiers in front of the given type. */
8644 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8645 dw_die_ref context_die
)
8647 enum tree_code code
= TREE_CODE (type
);
8648 dw_die_ref mod_type_die
;
8649 dw_die_ref sub_die
= NULL
;
8650 tree item_type
= NULL
;
8651 tree qualified_type
;
8654 if (code
== ERROR_MARK
)
8657 /* See if we already have the appropriately qualified variant of
8660 = get_qualified_type (type
,
8661 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8662 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
8664 /* If we do, then we can just use its DIE, if it exists. */
8667 mod_type_die
= lookup_type_die (qualified_type
);
8669 return mod_type_die
;
8672 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
8674 /* Handle C typedef types. */
8675 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
))
8677 tree dtype
= TREE_TYPE (name
);
8679 if (qualified_type
== dtype
)
8681 /* For a named type, use the typedef. */
8682 gen_type_die (qualified_type
, context_die
);
8683 return lookup_type_die (qualified_type
);
8685 else if (is_const_type
< TYPE_READONLY (dtype
)
8686 || is_volatile_type
< TYPE_VOLATILE (dtype
)
8687 || (is_const_type
<= TYPE_READONLY (dtype
)
8688 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
8689 && DECL_ORIGINAL_TYPE (name
) != type
))
8690 /* cv-unqualified version of named type. Just use the unnamed
8691 type to which it refers. */
8692 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
8693 is_const_type
, is_volatile_type
,
8695 /* Else cv-qualified version of named type; fall through. */
8700 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8701 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8703 else if (is_volatile_type
)
8705 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8706 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8708 else if (code
== POINTER_TYPE
)
8710 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8711 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8712 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8713 item_type
= TREE_TYPE (type
);
8715 else if (code
== REFERENCE_TYPE
)
8717 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8718 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8719 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8720 item_type
= TREE_TYPE (type
);
8722 else if (is_subrange_type (type
))
8724 mod_type_die
= subrange_type_die (type
, context_die
);
8725 item_type
= TREE_TYPE (type
);
8727 else if (is_base_type (type
))
8728 mod_type_die
= base_type_die (type
);
8731 gen_type_die (type
, context_die
);
8733 /* We have to get the type_main_variant here (and pass that to the
8734 `lookup_type_die' routine) because the ..._TYPE node we have
8735 might simply be a *copy* of some original type node (where the
8736 copy was created to help us keep track of typedef names) and
8737 that copy might have a different TYPE_UID from the original
8739 if (TREE_CODE (type
) != VECTOR_TYPE
)
8740 return lookup_type_die (type_main_variant (type
));
8742 /* Vectors have the debugging information in the type,
8743 not the main variant. */
8744 return lookup_type_die (type
);
8747 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
8748 don't output a DW_TAG_typedef, since there isn't one in the
8749 user's program; just attach a DW_AT_name to the type. */
8751 && (TREE_CODE (name
) != TYPE_DECL
8752 || (TREE_TYPE (name
) == qualified_type
&& DECL_NAME (name
))))
8754 if (TREE_CODE (name
) == TYPE_DECL
)
8755 /* Could just call add_name_and_src_coords_attributes here,
8756 but since this is a builtin type it doesn't have any
8757 useful source coordinates anyway. */
8758 name
= DECL_NAME (name
);
8759 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
8763 equate_type_number_to_die (qualified_type
, mod_type_die
);
8766 /* We must do this after the equate_type_number_to_die call, in case
8767 this is a recursive type. This ensures that the modified_type_die
8768 recursion will terminate even if the type is recursive. Recursive
8769 types are possible in Ada. */
8770 sub_die
= modified_type_die (item_type
,
8771 TYPE_READONLY (item_type
),
8772 TYPE_VOLATILE (item_type
),
8775 if (sub_die
!= NULL
)
8776 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8778 return mod_type_die
;
8781 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8782 an enumerated type. */
8785 type_is_enum (const_tree type
)
8787 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8790 /* Return the DBX register number described by a given RTL node. */
8793 dbx_reg_number (const_rtx rtl
)
8795 unsigned regno
= REGNO (rtl
);
8797 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
8799 #ifdef LEAF_REG_REMAP
8800 if (current_function_uses_only_leaf_regs
)
8802 int leaf_reg
= LEAF_REG_REMAP (regno
);
8804 regno
= (unsigned) leaf_reg
;
8808 return DBX_REGISTER_NUMBER (regno
);
8811 /* Optionally add a DW_OP_piece term to a location description expression.
8812 DW_OP_piece is only added if the location description expression already
8813 doesn't end with DW_OP_piece. */
8816 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
8818 dw_loc_descr_ref loc
;
8820 if (*list_head
!= NULL
)
8822 /* Find the end of the chain. */
8823 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
8826 if (loc
->dw_loc_opc
!= DW_OP_piece
)
8827 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
8831 /* Return a location descriptor that designates a machine register or
8832 zero if there is none. */
8834 static dw_loc_descr_ref
8835 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
8839 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8842 regs
= targetm
.dwarf_register_span (rtl
);
8844 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
8845 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
8847 return one_reg_loc_descriptor (dbx_reg_number (rtl
), initialized
);
8850 /* Return a location descriptor that designates a machine register for
8851 a given hard register number. */
8853 static dw_loc_descr_ref
8854 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
8856 dw_loc_descr_ref reg_loc_descr
;
8858 reg_loc_descr
= new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8860 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
8862 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
8863 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
8865 return reg_loc_descr
;
8868 /* Given an RTL of a register, return a location descriptor that
8869 designates a value that spans more than one register. */
8871 static dw_loc_descr_ref
8872 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
8873 enum var_init_status initialized
)
8877 dw_loc_descr_ref loc_result
= NULL
;
8880 #ifdef LEAF_REG_REMAP
8881 if (current_function_uses_only_leaf_regs
)
8883 int leaf_reg
= LEAF_REG_REMAP (reg
);
8885 reg
= (unsigned) leaf_reg
;
8888 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
8889 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8891 /* Simple, contiguous registers. */
8892 if (regs
== NULL_RTX
)
8894 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8901 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
8902 VAR_INIT_STATUS_INITIALIZED
);
8903 add_loc_descr (&loc_result
, t
);
8904 add_loc_descr_op_piece (&loc_result
, size
);
8910 /* Now onto stupid register sets in non contiguous locations. */
8912 gcc_assert (GET_CODE (regs
) == PARALLEL
);
8914 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8917 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8921 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
8922 VAR_INIT_STATUS_INITIALIZED
);
8923 add_loc_descr (&loc_result
, t
);
8924 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8925 add_loc_descr_op_piece (&loc_result
, size
);
8928 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
8929 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
8933 /* Return a location descriptor that designates a constant. */
8935 static dw_loc_descr_ref
8936 int_loc_descriptor (HOST_WIDE_INT i
)
8938 enum dwarf_location_atom op
;
8940 /* Pick the smallest representation of a constant, rather than just
8941 defaulting to the LEB encoding. */
8945 op
= DW_OP_lit0
+ i
;
8948 else if (i
<= 0xffff)
8950 else if (HOST_BITS_PER_WIDE_INT
== 32
8960 else if (i
>= -0x8000)
8962 else if (HOST_BITS_PER_WIDE_INT
== 32
8963 || i
>= -0x80000000)
8969 return new_loc_descr (op
, i
, 0);
8972 /* Return a location descriptor that designates a base+offset location. */
8974 static dw_loc_descr_ref
8975 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
8976 enum var_init_status initialized
)
8979 dw_loc_descr_ref result
;
8981 /* We only use "frame base" when we're sure we're talking about the
8982 post-prologue local stack frame. We do this by *not* running
8983 register elimination until this point, and recognizing the special
8984 argument pointer and soft frame pointer rtx's. */
8985 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
8987 rtx elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
8991 if (GET_CODE (elim
) == PLUS
)
8993 offset
+= INTVAL (XEXP (elim
, 1));
8994 elim
= XEXP (elim
, 0);
8996 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
8997 : stack_pointer_rtx
));
8998 offset
+= frame_pointer_fb_offset
;
9000 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
9004 regno
= dbx_reg_number (reg
);
9006 result
= new_loc_descr (DW_OP_breg0
+ regno
, offset
, 0);
9008 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
9010 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9011 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9016 /* Return true if this RTL expression describes a base+offset calculation. */
9019 is_based_loc (const_rtx rtl
)
9021 return (GET_CODE (rtl
) == PLUS
9022 && ((REG_P (XEXP (rtl
, 0))
9023 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
9024 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
9027 /* Return a descriptor that describes the concatenation of N locations
9028 used to form the address of a memory location. */
9030 static dw_loc_descr_ref
9031 concatn_mem_loc_descriptor (rtx concatn
, enum machine_mode mode
,
9032 enum var_init_status initialized
)
9035 dw_loc_descr_ref cc_loc_result
= NULL
;
9036 unsigned int n
= XVECLEN (concatn
, 0);
9038 for (i
= 0; i
< n
; ++i
)
9040 dw_loc_descr_ref ref
;
9041 rtx x
= XVECEXP (concatn
, 0, i
);
9043 ref
= mem_loc_descriptor (x
, mode
, VAR_INIT_STATUS_INITIALIZED
);
9047 add_loc_descr (&cc_loc_result
, ref
);
9048 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
9051 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9052 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9054 return cc_loc_result
;
9057 /* The following routine converts the RTL for a variable or parameter
9058 (resident in memory) into an equivalent Dwarf representation of a
9059 mechanism for getting the address of that same variable onto the top of a
9060 hypothetical "address evaluation" stack.
9062 When creating memory location descriptors, we are effectively transforming
9063 the RTL for a memory-resident object into its Dwarf postfix expression
9064 equivalent. This routine recursively descends an RTL tree, turning
9065 it into Dwarf postfix code as it goes.
9067 MODE is the mode of the memory reference, needed to handle some
9068 autoincrement addressing modes.
9070 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
9071 location list for RTL.
9073 Return 0 if we can't represent the location. */
9075 static dw_loc_descr_ref
9076 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
9077 enum var_init_status initialized
)
9079 dw_loc_descr_ref mem_loc_result
= NULL
;
9080 enum dwarf_location_atom op
;
9082 /* Note that for a dynamically sized array, the location we will generate a
9083 description of here will be the lowest numbered location which is
9084 actually within the array. That's *not* necessarily the same as the
9085 zeroth element of the array. */
9087 rtl
= targetm
.delegitimize_address (rtl
);
9089 switch (GET_CODE (rtl
))
9094 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
9095 just fall into the SUBREG code. */
9097 /* ... fall through ... */
9100 /* The case of a subreg may arise when we have a local (register)
9101 variable or a formal (register) parameter which doesn't quite fill
9102 up an entire register. For now, just assume that it is
9103 legitimate to make the Dwarf info refer to the whole register which
9104 contains the given subreg. */
9105 rtl
= XEXP (rtl
, 0);
9107 /* ... fall through ... */
9110 /* Whenever a register number forms a part of the description of the
9111 method for calculating the (dynamic) address of a memory resident
9112 object, DWARF rules require the register number be referred to as
9113 a "base register". This distinction is not based in any way upon
9114 what category of register the hardware believes the given register
9115 belongs to. This is strictly DWARF terminology we're dealing with
9116 here. Note that in cases where the location of a memory-resident
9117 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
9118 OP_CONST (0)) the actual DWARF location descriptor that we generate
9119 may just be OP_BASEREG (basereg). This may look deceptively like
9120 the object in question was allocated to a register (rather than in
9121 memory) so DWARF consumers need to be aware of the subtle
9122 distinction between OP_REG and OP_BASEREG. */
9123 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
9124 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
9128 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
9129 VAR_INIT_STATUS_INITIALIZED
);
9130 if (mem_loc_result
!= 0)
9131 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
9135 rtl
= XEXP (rtl
, 1);
9137 /* ... fall through ... */
9140 /* Some ports can transform a symbol ref into a label ref, because
9141 the symbol ref is too far away and has to be dumped into a constant
9145 /* Alternatively, the symbol in the constant pool might be referenced
9146 by a different symbol. */
9147 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
9150 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
9152 if (GET_CODE (tmp
) == SYMBOL_REF
)
9155 if (CONSTANT_POOL_ADDRESS_P (tmp
))
9156 get_pool_constant_mark (tmp
, &marked
);
9161 /* If all references to this pool constant were optimized away,
9162 it was not output and thus we can't represent it.
9163 FIXME: might try to use DW_OP_const_value here, though
9164 DW_OP_piece complicates it. */
9169 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
9170 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9171 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9172 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
9176 /* Extract the PLUS expression nested inside and fall into
9178 rtl
= XEXP (rtl
, 1);
9183 /* Turn these into a PLUS expression and fall into the PLUS code
9185 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
9186 GEN_INT (GET_CODE (rtl
) == PRE_INC
9187 ? GET_MODE_UNIT_SIZE (mode
)
9188 : -GET_MODE_UNIT_SIZE (mode
)));
9190 /* ... fall through ... */
9194 if (is_based_loc (rtl
))
9195 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
9196 INTVAL (XEXP (rtl
, 1)),
9197 VAR_INIT_STATUS_INITIALIZED
);
9200 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
9201 VAR_INIT_STATUS_INITIALIZED
);
9202 if (mem_loc_result
== 0)
9205 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
9206 && INTVAL (XEXP (rtl
, 1)) >= 0)
9207 add_loc_descr (&mem_loc_result
,
9208 new_loc_descr (DW_OP_plus_uconst
,
9209 INTVAL (XEXP (rtl
, 1)), 0));
9212 add_loc_descr (&mem_loc_result
,
9213 mem_loc_descriptor (XEXP (rtl
, 1), mode
,
9214 VAR_INIT_STATUS_INITIALIZED
));
9215 add_loc_descr (&mem_loc_result
,
9216 new_loc_descr (DW_OP_plus
, 0, 0));
9221 /* If a pseudo-reg is optimized away, it is possible for it to
9222 be replaced with a MEM containing a multiply or shift. */
9241 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
9242 VAR_INIT_STATUS_INITIALIZED
);
9243 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
9244 VAR_INIT_STATUS_INITIALIZED
);
9246 if (op0
== 0 || op1
== 0)
9249 mem_loc_result
= op0
;
9250 add_loc_descr (&mem_loc_result
, op1
);
9251 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
9256 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
9260 mem_loc_result
= concatn_mem_loc_descriptor (rtl
, mode
,
9261 VAR_INIT_STATUS_INITIALIZED
);
9268 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9269 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9271 return mem_loc_result
;
9274 /* Return a descriptor that describes the concatenation of two locations.
9275 This is typically a complex variable. */
9277 static dw_loc_descr_ref
9278 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
9280 dw_loc_descr_ref cc_loc_result
= NULL
;
9281 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, VAR_INIT_STATUS_INITIALIZED
);
9282 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, VAR_INIT_STATUS_INITIALIZED
);
9284 if (x0_ref
== 0 || x1_ref
== 0)
9287 cc_loc_result
= x0_ref
;
9288 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
9290 add_loc_descr (&cc_loc_result
, x1_ref
);
9291 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
9293 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9294 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9296 return cc_loc_result
;
9299 /* Return a descriptor that describes the concatenation of N
9302 static dw_loc_descr_ref
9303 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
9306 dw_loc_descr_ref cc_loc_result
= NULL
;
9307 unsigned int n
= XVECLEN (concatn
, 0);
9309 for (i
= 0; i
< n
; ++i
)
9311 dw_loc_descr_ref ref
;
9312 rtx x
= XVECEXP (concatn
, 0, i
);
9314 ref
= loc_descriptor (x
, VAR_INIT_STATUS_INITIALIZED
);
9318 add_loc_descr (&cc_loc_result
, ref
);
9319 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
9322 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
9323 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
9325 return cc_loc_result
;
9328 /* Output a proper Dwarf location descriptor for a variable or parameter
9329 which is either allocated in a register or in a memory location. For a
9330 register, we just generate an OP_REG and the register number. For a
9331 memory location we provide a Dwarf postfix expression describing how to
9332 generate the (dynamic) address of the object onto the address stack.
9334 If we don't know how to describe it, return 0. */
9336 static dw_loc_descr_ref
9337 loc_descriptor (rtx rtl
, enum var_init_status initialized
)
9339 dw_loc_descr_ref loc_result
= NULL
;
9341 switch (GET_CODE (rtl
))
9344 /* The case of a subreg may arise when we have a local (register)
9345 variable or a formal (register) parameter which doesn't quite fill
9346 up an entire register. For now, just assume that it is
9347 legitimate to make the Dwarf info refer to the whole register which
9348 contains the given subreg. */
9349 rtl
= SUBREG_REG (rtl
);
9351 /* ... fall through ... */
9354 loc_result
= reg_loc_descriptor (rtl
, initialized
);
9358 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
9363 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
9368 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
9373 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
9375 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), initialized
);
9379 rtl
= XEXP (rtl
, 1);
9384 rtvec par_elems
= XVEC (rtl
, 0);
9385 int num_elem
= GET_NUM_ELEM (par_elems
);
9386 enum machine_mode mode
;
9389 /* Create the first one, so we have something to add to. */
9390 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
9392 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
9393 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9394 for (i
= 1; i
< num_elem
; i
++)
9396 dw_loc_descr_ref temp
;
9398 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
9400 add_loc_descr (&loc_result
, temp
);
9401 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
9402 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
9414 /* Similar, but generate the descriptor from trees instead of rtl. This comes
9415 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
9416 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
9417 top-level invocation, and we require the address of LOC; is 0 if we require
9418 the value of LOC. */
9420 static dw_loc_descr_ref
9421 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
9423 dw_loc_descr_ref ret
, ret1
;
9424 int have_address
= 0;
9425 enum dwarf_location_atom op
;
9427 /* ??? Most of the time we do not take proper care for sign/zero
9428 extending the values properly. Hopefully this won't be a real
9431 switch (TREE_CODE (loc
))
9436 case PLACEHOLDER_EXPR
:
9437 /* This case involves extracting fields from an object to determine the
9438 position of other fields. We don't try to encode this here. The
9439 only user of this is Ada, which encodes the needed information using
9440 the names of types. */
9446 case PREINCREMENT_EXPR
:
9447 case PREDECREMENT_EXPR
:
9448 case POSTINCREMENT_EXPR
:
9449 case POSTDECREMENT_EXPR
:
9450 /* There are no opcodes for these operations. */
9454 /* If we already want an address, there's nothing we can do. */
9458 /* Otherwise, process the argument and look for the address. */
9459 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
9462 if (DECL_THREAD_LOCAL_P (loc
))
9466 /* If this is not defined, we have no way to emit the data. */
9467 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
9470 /* The way DW_OP_GNU_push_tls_address is specified, we can only
9471 look up addresses of objects in the current module. */
9472 if (DECL_EXTERNAL (loc
))
9475 rtl
= rtl_for_decl_location (loc
);
9476 if (rtl
== NULL_RTX
)
9481 rtl
= XEXP (rtl
, 0);
9482 if (! CONSTANT_P (rtl
))
9485 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
9486 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9487 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9489 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
9490 add_loc_descr (&ret
, ret1
);
9498 if (DECL_HAS_VALUE_EXPR_P (loc
))
9499 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
),
9506 rtx rtl
= rtl_for_decl_location (loc
);
9508 if (rtl
== NULL_RTX
)
9510 else if (GET_CODE (rtl
) == CONST_INT
)
9512 HOST_WIDE_INT val
= INTVAL (rtl
);
9513 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
9514 val
&= GET_MODE_MASK (DECL_MODE (loc
));
9515 ret
= int_loc_descriptor (val
);
9517 else if (GET_CODE (rtl
) == CONST_STRING
)
9519 else if (CONSTANT_P (rtl
))
9521 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
9522 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
9523 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
9527 enum machine_mode mode
;
9529 /* Certain constructs can only be represented at top-level. */
9530 if (want_address
== 2)
9531 return loc_descriptor (rtl
, VAR_INIT_STATUS_INITIALIZED
);
9533 mode
= GET_MODE (rtl
);
9536 rtl
= XEXP (rtl
, 0);
9539 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
9545 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9550 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
9554 case NON_LVALUE_EXPR
:
9555 case VIEW_CONVERT_EXPR
:
9557 case GIMPLE_MODIFY_STMT
:
9558 return loc_descriptor_from_tree_1 (GENERIC_TREE_OPERAND (loc
, 0),
9564 case ARRAY_RANGE_REF
:
9567 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
9568 enum machine_mode mode
;
9570 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
9572 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
9573 &unsignedp
, &volatilep
, false);
9578 ret
= loc_descriptor_from_tree_1 (obj
, 1);
9580 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
9583 if (offset
!= NULL_TREE
)
9585 /* Variable offset. */
9586 add_loc_descr (&ret
, loc_descriptor_from_tree_1 (offset
, 0));
9587 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9590 bytepos
= bitpos
/ BITS_PER_UNIT
;
9592 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
9593 else if (bytepos
< 0)
9595 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
9596 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9604 if (host_integerp (loc
, 0))
9605 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
9612 /* Get an RTL for this, if something has been emitted. */
9613 rtx rtl
= lookup_constant_def (loc
);
9614 enum machine_mode mode
;
9616 if (!rtl
|| !MEM_P (rtl
))
9618 mode
= GET_MODE (rtl
);
9619 rtl
= XEXP (rtl
, 0);
9620 ret
= mem_loc_descriptor (rtl
, mode
, VAR_INIT_STATUS_INITIALIZED
);
9625 case TRUTH_AND_EXPR
:
9626 case TRUTH_ANDIF_EXPR
:
9631 case TRUTH_XOR_EXPR
:
9637 case TRUTH_ORIF_EXPR
:
9642 case FLOOR_DIV_EXPR
:
9644 case ROUND_DIV_EXPR
:
9645 case TRUNC_DIV_EXPR
:
9653 case FLOOR_MOD_EXPR
:
9655 case ROUND_MOD_EXPR
:
9656 case TRUNC_MOD_EXPR
:
9669 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
9672 case POINTER_PLUS_EXPR
:
9674 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
9675 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9677 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9681 add_loc_descr (&ret
,
9682 new_loc_descr (DW_OP_plus_uconst
,
9683 tree_low_cst (TREE_OPERAND (loc
, 1),
9693 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9700 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9707 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9714 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9729 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9730 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9731 if (ret
== 0 || ret1
== 0)
9734 add_loc_descr (&ret
, ret1
);
9735 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9738 case TRUTH_NOT_EXPR
:
9752 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9756 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9762 const enum tree_code code
=
9763 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9765 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
9766 build2 (code
, integer_type_node
,
9767 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9768 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9771 /* ... fall through ... */
9775 dw_loc_descr_ref lhs
9776 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9777 dw_loc_descr_ref rhs
9778 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
9779 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9781 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9782 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9785 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9786 add_loc_descr (&ret
, bra_node
);
9788 add_loc_descr (&ret
, rhs
);
9789 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9790 add_loc_descr (&ret
, jump_node
);
9792 add_loc_descr (&ret
, lhs
);
9793 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9794 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9796 /* ??? Need a node to point the skip at. Use a nop. */
9797 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9798 add_loc_descr (&ret
, tmp
);
9799 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9800 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9804 case FIX_TRUNC_EXPR
:
9808 /* Leave front-end specific codes as simply unknown. This comes
9809 up, for instance, with the C STMT_EXPR. */
9810 if ((unsigned int) TREE_CODE (loc
)
9811 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9814 #ifdef ENABLE_CHECKING
9815 /* Otherwise this is a generic code; we should just lists all of
9816 these explicitly. We forgot one. */
9819 /* In a release build, we want to degrade gracefully: better to
9820 generate incomplete debugging information than to crash. */
9825 /* Show if we can't fill the request for an address. */
9826 if (want_address
&& !have_address
)
9829 /* If we've got an address and don't want one, dereference. */
9830 if (!want_address
&& have_address
&& ret
)
9832 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9834 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9836 else if (size
== DWARF2_ADDR_SIZE
)
9839 op
= DW_OP_deref_size
;
9841 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9847 static inline dw_loc_descr_ref
9848 loc_descriptor_from_tree (tree loc
)
9850 return loc_descriptor_from_tree_1 (loc
, 2);
9853 /* Given a value, round it up to the lowest multiple of `boundary'
9854 which is not less than the value itself. */
9856 static inline HOST_WIDE_INT
9857 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9859 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9862 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9863 pointer to the declared type for the relevant field variable, or return
9864 `integer_type_node' if the given node turns out to be an
9868 field_type (const_tree decl
)
9872 if (TREE_CODE (decl
) == ERROR_MARK
)
9873 return integer_type_node
;
9875 type
= DECL_BIT_FIELD_TYPE (decl
);
9876 if (type
== NULL_TREE
)
9877 type
= TREE_TYPE (decl
);
9882 /* Given a pointer to a tree node, return the alignment in bits for
9883 it, or else return BITS_PER_WORD if the node actually turns out to
9884 be an ERROR_MARK node. */
9886 static inline unsigned
9887 simple_type_align_in_bits (const_tree type
)
9889 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9892 static inline unsigned
9893 simple_decl_align_in_bits (const_tree decl
)
9895 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9898 /* Return the result of rounding T up to ALIGN. */
9900 static inline HOST_WIDE_INT
9901 round_up_to_align (HOST_WIDE_INT t
, unsigned int align
)
9903 /* We must be careful if T is negative because HOST_WIDE_INT can be
9904 either "above" or "below" unsigned int as per the C promotion
9905 rules, depending on the host, thus making the signedness of the
9906 direct multiplication and division unpredictable. */
9907 unsigned HOST_WIDE_INT u
= (unsigned HOST_WIDE_INT
) t
;
9913 return (HOST_WIDE_INT
) u
;
9916 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9917 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9918 or return 0 if we are unable to determine what that offset is, either
9919 because the argument turns out to be a pointer to an ERROR_MARK node, or
9920 because the offset is actually variable. (We can't handle the latter case
9923 static HOST_WIDE_INT
9924 field_byte_offset (const_tree decl
)
9926 HOST_WIDE_INT object_offset_in_bits
;
9927 HOST_WIDE_INT bitpos_int
;
9929 if (TREE_CODE (decl
) == ERROR_MARK
)
9932 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
9934 /* We cannot yet cope with fields whose positions are variable, so
9935 for now, when we see such things, we simply return 0. Someday, we may
9936 be able to handle such cases, but it will be damn difficult. */
9937 if (! host_integerp (bit_position (decl
), 0))
9940 bitpos_int
= int_bit_position (decl
);
9942 #ifdef PCC_BITFIELD_TYPE_MATTERS
9943 if (PCC_BITFIELD_TYPE_MATTERS
)
9946 tree field_size_tree
;
9947 HOST_WIDE_INT deepest_bitpos
;
9948 unsigned HOST_WIDE_INT field_size_in_bits
;
9949 unsigned int type_align_in_bits
;
9950 unsigned int decl_align_in_bits
;
9951 unsigned HOST_WIDE_INT type_size_in_bits
;
9953 type
= field_type (decl
);
9954 field_size_tree
= DECL_SIZE (decl
);
9956 /* The size could be unspecified if there was an error, or for
9957 a flexible array member. */
9958 if (! field_size_tree
)
9959 field_size_tree
= bitsize_zero_node
;
9961 /* If we don't know the size of the field, pretend it's a full word. */
9962 if (host_integerp (field_size_tree
, 1))
9963 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9965 field_size_in_bits
= BITS_PER_WORD
;
9967 type_size_in_bits
= simple_type_size_in_bits (type
);
9968 type_align_in_bits
= simple_type_align_in_bits (type
);
9969 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9971 /* The GCC front-end doesn't make any attempt to keep track of the
9972 starting bit offset (relative to the start of the containing
9973 structure type) of the hypothetical "containing object" for a
9974 bit-field. Thus, when computing the byte offset value for the
9975 start of the "containing object" of a bit-field, we must deduce
9976 this information on our own. This can be rather tricky to do in
9977 some cases. For example, handling the following structure type
9978 definition when compiling for an i386/i486 target (which only
9979 aligns long long's to 32-bit boundaries) can be very tricky:
9981 struct S { int field1; long long field2:31; };
9983 Fortunately, there is a simple rule-of-thumb which can be used
9984 in such cases. When compiling for an i386/i486, GCC will
9985 allocate 8 bytes for the structure shown above. It decides to
9986 do this based upon one simple rule for bit-field allocation.
9987 GCC allocates each "containing object" for each bit-field at
9988 the first (i.e. lowest addressed) legitimate alignment boundary
9989 (based upon the required minimum alignment for the declared
9990 type of the field) which it can possibly use, subject to the
9991 condition that there is still enough available space remaining
9992 in the containing object (when allocated at the selected point)
9993 to fully accommodate all of the bits of the bit-field itself.
9995 This simple rule makes it obvious why GCC allocates 8 bytes for
9996 each object of the structure type shown above. When looking
9997 for a place to allocate the "containing object" for `field2',
9998 the compiler simply tries to allocate a 64-bit "containing
9999 object" at each successive 32-bit boundary (starting at zero)
10000 until it finds a place to allocate that 64- bit field such that
10001 at least 31 contiguous (and previously unallocated) bits remain
10002 within that selected 64 bit field. (As it turns out, for the
10003 example above, the compiler finds it is OK to allocate the
10004 "containing object" 64-bit field at bit-offset zero within the
10007 Here we attempt to work backwards from the limited set of facts
10008 we're given, and we try to deduce from those facts, where GCC
10009 must have believed that the containing object started (within
10010 the structure type). The value we deduce is then used (by the
10011 callers of this routine) to generate DW_AT_location and
10012 DW_AT_bit_offset attributes for fields (both bit-fields and, in
10013 the case of DW_AT_location, regular fields as well). */
10015 /* Figure out the bit-distance from the start of the structure to
10016 the "deepest" bit of the bit-field. */
10017 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
10019 /* This is the tricky part. Use some fancy footwork to deduce
10020 where the lowest addressed bit of the containing object must
10022 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10024 /* Round up to type_align by default. This works best for
10026 object_offset_in_bits
10027 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
10029 if (object_offset_in_bits
> bitpos_int
)
10031 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
10033 /* Round up to decl_align instead. */
10034 object_offset_in_bits
10035 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
10040 object_offset_in_bits
= bitpos_int
;
10042 return object_offset_in_bits
/ BITS_PER_UNIT
;
10045 /* The following routines define various Dwarf attributes and any data
10046 associated with them. */
10048 /* Add a location description attribute value to a DIE.
10050 This emits location attributes suitable for whole variables and
10051 whole parameters. Note that the location attributes for struct fields are
10052 generated by the routine `data_member_location_attribute' below. */
10055 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
10056 dw_loc_descr_ref descr
)
10059 add_AT_loc (die
, attr_kind
, descr
);
10062 /* Attach the specialized form of location attribute used for data members of
10063 struct and union types. In the special case of a FIELD_DECL node which
10064 represents a bit-field, the "offset" part of this special location
10065 descriptor must indicate the distance in bytes from the lowest-addressed
10066 byte of the containing struct or union type to the lowest-addressed byte of
10067 the "containing object" for the bit-field. (See the `field_byte_offset'
10070 For any given bit-field, the "containing object" is a hypothetical object
10071 (of some integral or enum type) within which the given bit-field lives. The
10072 type of this hypothetical "containing object" is always the same as the
10073 declared type of the individual bit-field itself (for GCC anyway... the
10074 DWARF spec doesn't actually mandate this). Note that it is the size (in
10075 bytes) of the hypothetical "containing object" which will be given in the
10076 DW_AT_byte_size attribute for this bit-field. (See the
10077 `byte_size_attribute' function below.) It is also used when calculating the
10078 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
10079 function below.) */
10082 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
10084 HOST_WIDE_INT offset
;
10085 dw_loc_descr_ref loc_descr
= 0;
10087 if (TREE_CODE (decl
) == TREE_BINFO
)
10089 /* We're working on the TAG_inheritance for a base class. */
10090 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
10092 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
10093 aren't at a fixed offset from all (sub)objects of the same
10094 type. We need to extract the appropriate offset from our
10095 vtable. The following dwarf expression means
10097 BaseAddr = ObAddr + *((*ObAddr) - Offset)
10099 This is specific to the V3 ABI, of course. */
10101 dw_loc_descr_ref tmp
;
10103 /* Make a copy of the object address. */
10104 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
10105 add_loc_descr (&loc_descr
, tmp
);
10107 /* Extract the vtable address. */
10108 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
10109 add_loc_descr (&loc_descr
, tmp
);
10111 /* Calculate the address of the offset. */
10112 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
10113 gcc_assert (offset
< 0);
10115 tmp
= int_loc_descriptor (-offset
);
10116 add_loc_descr (&loc_descr
, tmp
);
10117 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
10118 add_loc_descr (&loc_descr
, tmp
);
10120 /* Extract the offset. */
10121 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
10122 add_loc_descr (&loc_descr
, tmp
);
10124 /* Add it to the object address. */
10125 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
10126 add_loc_descr (&loc_descr
, tmp
);
10129 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
10132 offset
= field_byte_offset (decl
);
10136 enum dwarf_location_atom op
;
10138 /* The DWARF2 standard says that we should assume that the structure
10139 address is already on the stack, so we can specify a structure field
10140 address by using DW_OP_plus_uconst. */
10142 #ifdef MIPS_DEBUGGING_INFO
10143 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
10144 operator correctly. It works only if we leave the offset on the
10148 op
= DW_OP_plus_uconst
;
10151 loc_descr
= new_loc_descr (op
, offset
, 0);
10154 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
10157 /* Writes integer values to dw_vec_const array. */
10160 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
10164 *dest
++ = val
& 0xff;
10170 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
10172 static HOST_WIDE_INT
10173 extract_int (const unsigned char *src
, unsigned int size
)
10175 HOST_WIDE_INT val
= 0;
10181 val
|= *--src
& 0xff;
10187 /* Writes floating point values to dw_vec_const array. */
10190 insert_float (const_rtx rtl
, unsigned char *array
)
10192 REAL_VALUE_TYPE rv
;
10196 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
10197 real_to_target (val
, &rv
, GET_MODE (rtl
));
10199 /* real_to_target puts 32-bit pieces in each long. Pack them. */
10200 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
10202 insert_int (val
[i
], 4, array
);
10207 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
10208 does not have a "location" either in memory or in a register. These
10209 things can arise in GNU C when a constant is passed as an actual parameter
10210 to an inlined function. They can also arise in C++ where declared
10211 constants do not necessarily get memory "homes". */
10214 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
10216 switch (GET_CODE (rtl
))
10220 HOST_WIDE_INT val
= INTVAL (rtl
);
10223 add_AT_int (die
, DW_AT_const_value
, val
);
10225 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
10230 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
10231 floating-point constant. A CONST_DOUBLE is used whenever the
10232 constant requires more than one word in order to be adequately
10233 represented. We output CONST_DOUBLEs as blocks. */
10235 enum machine_mode mode
= GET_MODE (rtl
);
10237 if (SCALAR_FLOAT_MODE_P (mode
))
10239 unsigned int length
= GET_MODE_SIZE (mode
);
10240 unsigned char *array
= ggc_alloc (length
);
10242 insert_float (rtl
, array
);
10243 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
10247 /* ??? We really should be using HOST_WIDE_INT throughout. */
10248 gcc_assert (HOST_BITS_PER_LONG
== HOST_BITS_PER_WIDE_INT
);
10250 add_AT_long_long (die
, DW_AT_const_value
,
10251 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
10258 enum machine_mode mode
= GET_MODE (rtl
);
10259 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
10260 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
10261 unsigned char *array
= ggc_alloc (length
* elt_size
);
10265 switch (GET_MODE_CLASS (mode
))
10267 case MODE_VECTOR_INT
:
10268 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
10270 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
10271 HOST_WIDE_INT lo
, hi
;
10273 switch (GET_CODE (elt
))
10281 lo
= CONST_DOUBLE_LOW (elt
);
10282 hi
= CONST_DOUBLE_HIGH (elt
);
10286 gcc_unreachable ();
10289 if (elt_size
<= sizeof (HOST_WIDE_INT
))
10290 insert_int (lo
, elt_size
, p
);
10293 unsigned char *p0
= p
;
10294 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
10296 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
10297 if (WORDS_BIG_ENDIAN
)
10302 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
10303 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
10308 case MODE_VECTOR_FLOAT
:
10309 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
10311 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
10312 insert_float (elt
, p
);
10317 gcc_unreachable ();
10320 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
10325 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
10331 add_AT_addr (die
, DW_AT_const_value
, rtl
);
10332 VEC_safe_push (rtx
, gc
, used_rtx_array
, rtl
);
10336 /* In cases where an inlined instance of an inline function is passed
10337 the address of an `auto' variable (which is local to the caller) we
10338 can get a situation where the DECL_RTL of the artificial local
10339 variable (for the inlining) which acts as a stand-in for the
10340 corresponding formal parameter (of the inline function) will look
10341 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
10342 exactly a compile-time constant expression, but it isn't the address
10343 of the (artificial) local variable either. Rather, it represents the
10344 *value* which the artificial local variable always has during its
10345 lifetime. We currently have no way to represent such quasi-constant
10346 values in Dwarf, so for now we just punt and generate nothing. */
10350 /* No other kinds of rtx should be possible here. */
10351 gcc_unreachable ();
10356 /* Determine whether the evaluation of EXPR references any variables
10357 or functions which aren't otherwise used (and therefore may not be
10360 reference_to_unused (tree
* tp
, int * walk_subtrees
,
10361 void * data ATTRIBUTE_UNUSED
)
10363 if (! EXPR_P (*tp
) && ! GIMPLE_STMT_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
10364 *walk_subtrees
= 0;
10366 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
10367 && ! TREE_ASM_WRITTEN (*tp
))
10369 else if (!flag_unit_at_a_time
)
10371 /* ??? The C++ FE emits debug information for using decls, so
10372 putting gcc_unreachable here falls over. See PR31899. For now
10373 be conservative. */
10374 else if (!cgraph_global_info_ready
10375 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
10377 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == VAR_DECL
)
10379 struct varpool_node
*node
= varpool_node (*tp
);
10383 else if (DECL_P (*tp
) && TREE_CODE (*tp
) == FUNCTION_DECL
10384 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
10386 struct cgraph_node
*node
= cgraph_node (*tp
);
10390 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
10396 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
10397 for use in a later add_const_value_attribute call. */
10400 rtl_for_decl_init (tree init
, tree type
)
10402 rtx rtl
= NULL_RTX
;
10404 /* If a variable is initialized with a string constant without embedded
10405 zeros, build CONST_STRING. */
10406 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
10408 tree enttype
= TREE_TYPE (type
);
10409 tree domain
= TYPE_DOMAIN (type
);
10410 enum machine_mode mode
= TYPE_MODE (enttype
);
10412 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
10414 && integer_zerop (TYPE_MIN_VALUE (domain
))
10415 && compare_tree_int (TYPE_MAX_VALUE (domain
),
10416 TREE_STRING_LENGTH (init
) - 1) == 0
10417 && ((size_t) TREE_STRING_LENGTH (init
)
10418 == strlen (TREE_STRING_POINTER (init
)) + 1))
10419 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
10420 ggc_strdup (TREE_STRING_POINTER (init
)));
10422 /* Other aggregates, and complex values, could be represented using
10424 else if (AGGREGATE_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
10426 /* Vectors only work if their mode is supported by the target.
10427 FIXME: generic vectors ought to work too. */
10428 else if (TREE_CODE (type
) == VECTOR_TYPE
&& TYPE_MODE (type
) == BLKmode
)
10430 /* If the initializer is something that we know will expand into an
10431 immediate RTL constant, expand it now. We must be careful not to
10432 reference variables which won't be output. */
10433 else if (initializer_constant_valid_p (init
, type
)
10434 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
10436 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
10438 if (TREE_CODE (type
) == VECTOR_TYPE
)
10439 switch (TREE_CODE (init
))
10444 if (TREE_CONSTANT (init
))
10446 VEC(constructor_elt
,gc
) *elts
= CONSTRUCTOR_ELTS (init
);
10447 bool constant_p
= true;
10449 unsigned HOST_WIDE_INT ix
;
10451 /* Even when ctor is constant, it might contain non-*_CST
10452 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
10453 belong into VECTOR_CST nodes. */
10454 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
10455 if (!CONSTANT_CLASS_P (value
))
10457 constant_p
= false;
10463 init
= build_vector_from_ctor (type
, elts
);
10473 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
10475 /* If expand_expr returns a MEM, it wasn't immediate. */
10476 gcc_assert (!rtl
|| !MEM_P (rtl
));
10482 /* Generate RTL for the variable DECL to represent its location. */
10485 rtl_for_decl_location (tree decl
)
10489 /* Here we have to decide where we are going to say the parameter "lives"
10490 (as far as the debugger is concerned). We only have a couple of
10491 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
10493 DECL_RTL normally indicates where the parameter lives during most of the
10494 activation of the function. If optimization is enabled however, this
10495 could be either NULL or else a pseudo-reg. Both of those cases indicate
10496 that the parameter doesn't really live anywhere (as far as the code
10497 generation parts of GCC are concerned) during most of the function's
10498 activation. That will happen (for example) if the parameter is never
10499 referenced within the function.
10501 We could just generate a location descriptor here for all non-NULL
10502 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
10503 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
10504 where DECL_RTL is NULL or is a pseudo-reg.
10506 Note however that we can only get away with using DECL_INCOMING_RTL as
10507 a backup substitute for DECL_RTL in certain limited cases. In cases
10508 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
10509 we can be sure that the parameter was passed using the same type as it is
10510 declared to have within the function, and that its DECL_INCOMING_RTL
10511 points us to a place where a value of that type is passed.
10513 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
10514 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
10515 because in these cases DECL_INCOMING_RTL points us to a value of some
10516 type which is *different* from the type of the parameter itself. Thus,
10517 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
10518 such cases, the debugger would end up (for example) trying to fetch a
10519 `float' from a place which actually contains the first part of a
10520 `double'. That would lead to really incorrect and confusing
10521 output at debug-time.
10523 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
10524 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
10525 are a couple of exceptions however. On little-endian machines we can
10526 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
10527 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
10528 an integral type that is smaller than TREE_TYPE (decl). These cases arise
10529 when (on a little-endian machine) a non-prototyped function has a
10530 parameter declared to be of type `short' or `char'. In such cases,
10531 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
10532 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
10533 passed `int' value. If the debugger then uses that address to fetch
10534 a `short' or a `char' (on a little-endian machine) the result will be
10535 the correct data, so we allow for such exceptional cases below.
10537 Note that our goal here is to describe the place where the given formal
10538 parameter lives during most of the function's activation (i.e. between the
10539 end of the prologue and the start of the epilogue). We'll do that as best
10540 as we can. Note however that if the given formal parameter is modified
10541 sometime during the execution of the function, then a stack backtrace (at
10542 debug-time) will show the function as having been called with the *new*
10543 value rather than the value which was originally passed in. This happens
10544 rarely enough that it is not a major problem, but it *is* a problem, and
10545 I'd like to fix it.
10547 A future version of dwarf2out.c may generate two additional attributes for
10548 any given DW_TAG_formal_parameter DIE which will describe the "passed
10549 type" and the "passed location" for the given formal parameter in addition
10550 to the attributes we now generate to indicate the "declared type" and the
10551 "active location" for each parameter. This additional set of attributes
10552 could be used by debuggers for stack backtraces. Separately, note that
10553 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
10554 This happens (for example) for inlined-instances of inline function formal
10555 parameters which are never referenced. This really shouldn't be
10556 happening. All PARM_DECL nodes should get valid non-NULL
10557 DECL_INCOMING_RTL values. FIXME. */
10559 /* Use DECL_RTL as the "location" unless we find something better. */
10560 rtl
= DECL_RTL_IF_SET (decl
);
10562 /* When generating abstract instances, ignore everything except
10563 constants, symbols living in memory, and symbols living in
10564 fixed registers. */
10565 if (! reload_completed
)
10568 && (CONSTANT_P (rtl
)
10570 && CONSTANT_P (XEXP (rtl
, 0)))
10572 && TREE_CODE (decl
) == VAR_DECL
10573 && TREE_STATIC (decl
))))
10575 rtl
= targetm
.delegitimize_address (rtl
);
10580 else if (TREE_CODE (decl
) == PARM_DECL
)
10582 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
10584 tree declared_type
= TREE_TYPE (decl
);
10585 tree passed_type
= DECL_ARG_TYPE (decl
);
10586 enum machine_mode dmode
= TYPE_MODE (declared_type
);
10587 enum machine_mode pmode
= TYPE_MODE (passed_type
);
10589 /* This decl represents a formal parameter which was optimized out.
10590 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10591 all cases where (rtl == NULL_RTX) just below. */
10592 if (dmode
== pmode
)
10593 rtl
= DECL_INCOMING_RTL (decl
);
10594 else if (SCALAR_INT_MODE_P (dmode
)
10595 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
10596 && DECL_INCOMING_RTL (decl
))
10598 rtx inc
= DECL_INCOMING_RTL (decl
);
10601 else if (MEM_P (inc
))
10603 if (BYTES_BIG_ENDIAN
)
10604 rtl
= adjust_address_nv (inc
, dmode
,
10605 GET_MODE_SIZE (pmode
)
10606 - GET_MODE_SIZE (dmode
));
10613 /* If the parm was passed in registers, but lives on the stack, then
10614 make a big endian correction if the mode of the type of the
10615 parameter is not the same as the mode of the rtl. */
10616 /* ??? This is the same series of checks that are made in dbxout.c before
10617 we reach the big endian correction code there. It isn't clear if all
10618 of these checks are necessary here, but keeping them all is the safe
10620 else if (MEM_P (rtl
)
10621 && XEXP (rtl
, 0) != const0_rtx
10622 && ! CONSTANT_P (XEXP (rtl
, 0))
10623 /* Not passed in memory. */
10624 && !MEM_P (DECL_INCOMING_RTL (decl
))
10625 /* Not passed by invisible reference. */
10626 && (!REG_P (XEXP (rtl
, 0))
10627 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
10628 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
10629 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10630 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
10633 /* Big endian correction check. */
10634 && BYTES_BIG_ENDIAN
10635 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
10636 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
10639 int offset
= (UNITS_PER_WORD
10640 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
10642 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10643 plus_constant (XEXP (rtl
, 0), offset
));
10646 else if (TREE_CODE (decl
) == VAR_DECL
10649 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
10650 && BYTES_BIG_ENDIAN
)
10652 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
10653 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
10655 /* If a variable is declared "register" yet is smaller than
10656 a register, then if we store the variable to memory, it
10657 looks like we're storing a register-sized value, when in
10658 fact we are not. We need to adjust the offset of the
10659 storage location to reflect the actual value's bytes,
10660 else gdb will not be able to display it. */
10662 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
10663 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
10666 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10667 and will have been substituted directly into all expressions that use it.
10668 C does not have such a concept, but C++ and other languages do. */
10669 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
10670 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
10673 rtl
= targetm
.delegitimize_address (rtl
);
10675 /* If we don't look past the constant pool, we risk emitting a
10676 reference to a constant pool entry that isn't referenced from
10677 code, and thus is not emitted. */
10679 rtl
= avoid_constant_pool_reference (rtl
);
10684 /* We need to figure out what section we should use as the base for the
10685 address ranges where a given location is valid.
10686 1. If this particular DECL has a section associated with it, use that.
10687 2. If this function has a section associated with it, use that.
10688 3. Otherwise, use the text section.
10689 XXX: If you split a variable across multiple sections, we won't notice. */
10691 static const char *
10692 secname_for_decl (const_tree decl
)
10694 const char *secname
;
10696 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
10698 tree sectree
= DECL_SECTION_NAME (decl
);
10699 secname
= TREE_STRING_POINTER (sectree
);
10701 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
10703 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
10704 secname
= TREE_STRING_POINTER (sectree
);
10706 else if (cfun
&& in_cold_section_p
)
10707 secname
= cfun
->cold_section_label
;
10709 secname
= text_section_label
;
10714 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10715 data attribute for a variable or a parameter. We generate the
10716 DW_AT_const_value attribute only in those cases where the given variable
10717 or parameter does not have a true "location" either in memory or in a
10718 register. This can happen (for example) when a constant is passed as an
10719 actual argument in a call to an inline function. (It's possible that
10720 these things can crop up in other ways also.) Note that one type of
10721 constant value which can be passed into an inlined function is a constant
10722 pointer. This can happen for example if an actual argument in an inlined
10723 function call evaluates to a compile-time constant address. */
10726 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
10727 enum dwarf_attribute attr
)
10730 dw_loc_descr_ref descr
;
10731 var_loc_list
*loc_list
;
10732 struct var_loc_node
*node
;
10733 if (TREE_CODE (decl
) == ERROR_MARK
)
10736 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
10737 || TREE_CODE (decl
) == RESULT_DECL
);
10739 /* See if we possibly have multiple locations for this variable. */
10740 loc_list
= lookup_decl_loc (decl
);
10742 /* If it truly has multiple locations, the first and last node will
10744 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
10746 const char *endname
, *secname
;
10747 dw_loc_list_ref list
;
10749 enum var_init_status initialized
;
10751 /* Now that we know what section we are using for a base,
10752 actually construct the list of locations.
10753 The first location information is what is passed to the
10754 function that creates the location list, and the remaining
10755 locations just get added on to that list.
10756 Note that we only know the start address for a location
10757 (IE location changes), so to build the range, we use
10758 the range [current location start, next location start].
10759 This means we have to special case the last node, and generate
10760 a range of [last location start, end of function label]. */
10762 node
= loc_list
->first
;
10763 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10764 secname
= secname_for_decl (decl
);
10766 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
))
10767 initialized
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
10769 initialized
= VAR_INIT_STATUS_INITIALIZED
;
10771 list
= new_loc_list (loc_descriptor (varloc
, initialized
),
10772 node
->label
, node
->next
->label
, secname
, 1);
10775 for (; node
->next
; node
= node
->next
)
10776 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10778 /* The variable has a location between NODE->LABEL and
10779 NODE->NEXT->LABEL. */
10780 enum var_init_status initialized
=
10781 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
10782 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10783 add_loc_descr_to_loc_list (&list
,
10784 loc_descriptor (varloc
, initialized
),
10785 node
->label
, node
->next
->label
, secname
);
10788 /* If the variable has a location at the last label
10789 it keeps its location until the end of function. */
10790 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10792 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10793 enum var_init_status initialized
=
10794 NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
10796 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10797 if (!current_function_decl
)
10798 endname
= text_end_label
;
10801 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10802 current_function_funcdef_no
);
10803 endname
= ggc_strdup (label_id
);
10805 add_loc_descr_to_loc_list (&list
,
10806 loc_descriptor (varloc
, initialized
),
10807 node
->label
, endname
, secname
);
10810 /* Finally, add the location list to the DIE, and we are done. */
10811 add_AT_loc_list (die
, attr
, list
);
10815 /* Try to get some constant RTL for this decl, and use that as the value of
10818 rtl
= rtl_for_decl_location (decl
);
10819 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
10821 add_const_value_attribute (die
, rtl
);
10825 /* If we have tried to generate the location otherwise, and it
10826 didn't work out (we wouldn't be here if we did), and we have a one entry
10827 location list, try generating a location from that. */
10828 if (loc_list
&& loc_list
->first
)
10830 enum var_init_status status
;
10831 node
= loc_list
->first
;
10832 status
= NOTE_VAR_LOCATION_STATUS (node
->var_loc_note
);
10833 descr
= loc_descriptor (NOTE_VAR_LOCATION (node
->var_loc_note
), status
);
10836 add_AT_location_description (die
, attr
, descr
);
10841 /* We couldn't get any rtl, so try directly generating the location
10842 description from the tree. */
10843 descr
= loc_descriptor_from_tree (decl
);
10846 add_AT_location_description (die
, attr
, descr
);
10849 /* None of that worked, so it must not really have a location;
10850 try adding a constant value attribute from the DECL_INITIAL. */
10851 tree_add_const_value_attribute (die
, decl
);
10854 /* If we don't have a copy of this variable in memory for some reason (such
10855 as a C++ member constant that doesn't have an out-of-line definition),
10856 we should tell the debugger about the constant value. */
10859 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10861 tree init
= DECL_INITIAL (decl
);
10862 tree type
= TREE_TYPE (decl
);
10865 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
)
10870 rtl
= rtl_for_decl_init (init
, type
);
10872 add_const_value_attribute (var_die
, rtl
);
10875 /* Convert the CFI instructions for the current function into a
10876 location list. This is used for DW_AT_frame_base when we targeting
10877 a dwarf2 consumer that does not support the dwarf3
10878 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
10881 static dw_loc_list_ref
10882 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
10885 dw_loc_list_ref list
, *list_tail
;
10887 dw_cfa_location last_cfa
, next_cfa
;
10888 const char *start_label
, *last_label
, *section
;
10890 fde
= &fde_table
[fde_table_in_use
- 1];
10892 section
= secname_for_decl (current_function_decl
);
10896 next_cfa
.reg
= INVALID_REGNUM
;
10897 next_cfa
.offset
= 0;
10898 next_cfa
.indirect
= 0;
10899 next_cfa
.base_offset
= 0;
10901 start_label
= fde
->dw_fde_begin
;
10903 /* ??? Bald assumption that the CIE opcode list does not contain
10904 advance opcodes. */
10905 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
10906 lookup_cfa_1 (cfi
, &next_cfa
);
10908 last_cfa
= next_cfa
;
10909 last_label
= start_label
;
10911 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
10912 switch (cfi
->dw_cfi_opc
)
10914 case DW_CFA_set_loc
:
10915 case DW_CFA_advance_loc1
:
10916 case DW_CFA_advance_loc2
:
10917 case DW_CFA_advance_loc4
:
10918 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10920 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10921 start_label
, last_label
, section
,
10924 list_tail
= &(*list_tail
)->dw_loc_next
;
10925 last_cfa
= next_cfa
;
10926 start_label
= last_label
;
10928 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
10931 case DW_CFA_advance_loc
:
10932 /* The encoding is complex enough that we should never emit this. */
10933 case DW_CFA_remember_state
:
10934 case DW_CFA_restore_state
:
10935 /* We don't handle these two in this function. It would be possible
10936 if it were to be required. */
10937 gcc_unreachable ();
10940 lookup_cfa_1 (cfi
, &next_cfa
);
10944 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
10946 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
10947 start_label
, last_label
, section
,
10949 list_tail
= &(*list_tail
)->dw_loc_next
;
10950 start_label
= last_label
;
10952 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
10953 start_label
, fde
->dw_fde_end
, section
,
10959 /* Compute a displacement from the "steady-state frame pointer" to the
10960 frame base (often the same as the CFA), and store it in
10961 frame_pointer_fb_offset. OFFSET is added to the displacement
10962 before the latter is negated. */
10965 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
10969 #ifdef FRAME_POINTER_CFA_OFFSET
10970 reg
= frame_pointer_rtx
;
10971 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
10973 reg
= arg_pointer_rtx
;
10974 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
10977 elim
= eliminate_regs (reg
, VOIDmode
, NULL_RTX
);
10978 if (GET_CODE (elim
) == PLUS
)
10980 offset
+= INTVAL (XEXP (elim
, 1));
10981 elim
= XEXP (elim
, 0);
10983 gcc_assert (elim
== (frame_pointer_needed
? hard_frame_pointer_rtx
10984 : stack_pointer_rtx
));
10986 frame_pointer_fb_offset
= -offset
;
10989 /* Generate a DW_AT_name attribute given some string value to be included as
10990 the value of the attribute. */
10993 add_name_attribute (dw_die_ref die
, const char *name_string
)
10995 if (name_string
!= NULL
&& *name_string
!= 0)
10997 if (demangle_name_func
)
10998 name_string
= (*demangle_name_func
) (name_string
);
11000 add_AT_string (die
, DW_AT_name
, name_string
);
11004 /* Generate a DW_AT_comp_dir attribute for DIE. */
11007 add_comp_dir_attribute (dw_die_ref die
)
11009 const char *wd
= get_src_pwd ();
11011 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
11014 /* Given a tree node describing an array bound (either lower or upper) output
11015 a representation for that bound. */
11018 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
11020 switch (TREE_CODE (bound
))
11025 /* All fixed-bounds are represented by INTEGER_CST nodes. */
11027 if (! host_integerp (bound
, 0)
11028 || (bound_attr
== DW_AT_lower_bound
11029 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
11030 || (is_fortran () && integer_onep (bound
)))))
11031 /* Use the default. */
11034 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
11039 case NON_LVALUE_EXPR
:
11040 case VIEW_CONVERT_EXPR
:
11041 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
11051 dw_die_ref decl_die
= lookup_decl_die (bound
);
11053 /* ??? Can this happen, or should the variable have been bound
11054 first? Probably it can, since I imagine that we try to create
11055 the types of parameters in the order in which they exist in
11056 the list, and won't have created a forward reference to a
11057 later parameter. */
11058 if (decl_die
!= NULL
)
11059 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
11065 /* Otherwise try to create a stack operation procedure to
11066 evaluate the value of the array bound. */
11068 dw_die_ref ctx
, decl_die
;
11069 dw_loc_descr_ref loc
;
11071 loc
= loc_descriptor_from_tree (bound
);
11075 if (current_function_decl
== 0)
11076 ctx
= comp_unit_die
;
11078 ctx
= lookup_decl_die (current_function_decl
);
11080 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
11081 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11082 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
11083 add_AT_loc (decl_die
, DW_AT_location
, loc
);
11085 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
11091 /* Note that the block of subscript information for an array type also
11092 includes information about the element type of type given array type. */
11095 add_subscript_info (dw_die_ref type_die
, tree type
)
11097 #ifndef MIPS_DEBUGGING_INFO
11098 unsigned dimension_number
;
11101 dw_die_ref subrange_die
;
11103 /* The GNU compilers represent multidimensional array types as sequences of
11104 one dimensional array types whose element types are themselves array
11105 types. Here we squish that down, so that each multidimensional array
11106 type gets only one array_type DIE in the Dwarf debugging info. The draft
11107 Dwarf specification say that we are allowed to do this kind of
11108 compression in C (because there is no difference between an array or
11109 arrays and a multidimensional array in C) but for other source languages
11110 (e.g. Ada) we probably shouldn't do this. */
11112 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11113 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11114 We work around this by disabling this feature. See also
11115 gen_array_type_die. */
11116 #ifndef MIPS_DEBUGGING_INFO
11117 for (dimension_number
= 0;
11118 TREE_CODE (type
) == ARRAY_TYPE
;
11119 type
= TREE_TYPE (type
), dimension_number
++)
11122 tree domain
= TYPE_DOMAIN (type
);
11124 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
11125 and (in GNU C only) variable bounds. Handle all three forms
11127 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
11130 /* We have an array type with specified bounds. */
11131 lower
= TYPE_MIN_VALUE (domain
);
11132 upper
= TYPE_MAX_VALUE (domain
);
11134 /* Define the index type. */
11135 if (TREE_TYPE (domain
))
11137 /* ??? This is probably an Ada unnamed subrange type. Ignore the
11138 TREE_TYPE field. We can't emit debug info for this
11139 because it is an unnamed integral type. */
11140 if (TREE_CODE (domain
) == INTEGER_TYPE
11141 && TYPE_NAME (domain
) == NULL_TREE
11142 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
11143 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
11146 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
11150 /* ??? If upper is NULL, the array has unspecified length,
11151 but it does have a lower bound. This happens with Fortran
11153 Since the debugger is definitely going to need to know N
11154 to produce useful results, go ahead and output the lower
11155 bound solo, and hope the debugger can cope. */
11157 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
11159 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
11162 /* Otherwise we have an array type with an unspecified length. The
11163 DWARF-2 spec does not say how to handle this; let's just leave out the
11169 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
11173 switch (TREE_CODE (tree_node
))
11178 case ENUMERAL_TYPE
:
11181 case QUAL_UNION_TYPE
:
11182 size
= int_size_in_bytes (tree_node
);
11185 /* For a data member of a struct or union, the DW_AT_byte_size is
11186 generally given as the number of bytes normally allocated for an
11187 object of the *declared* type of the member itself. This is true
11188 even for bit-fields. */
11189 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
11192 gcc_unreachable ();
11195 /* Note that `size' might be -1 when we get to this point. If it is, that
11196 indicates that the byte size of the entity in question is variable. We
11197 have no good way of expressing this fact in Dwarf at the present time,
11198 so just let the -1 pass on through. */
11199 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
11202 /* For a FIELD_DECL node which represents a bit-field, output an attribute
11203 which specifies the distance in bits from the highest order bit of the
11204 "containing object" for the bit-field to the highest order bit of the
11207 For any given bit-field, the "containing object" is a hypothetical object
11208 (of some integral or enum type) within which the given bit-field lives. The
11209 type of this hypothetical "containing object" is always the same as the
11210 declared type of the individual bit-field itself. The determination of the
11211 exact location of the "containing object" for a bit-field is rather
11212 complicated. It's handled by the `field_byte_offset' function (above).
11214 Note that it is the size (in bytes) of the hypothetical "containing object"
11215 which will be given in the DW_AT_byte_size attribute for this bit-field.
11216 (See `byte_size_attribute' above). */
11219 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
11221 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
11222 tree type
= DECL_BIT_FIELD_TYPE (decl
);
11223 HOST_WIDE_INT bitpos_int
;
11224 HOST_WIDE_INT highest_order_object_bit_offset
;
11225 HOST_WIDE_INT highest_order_field_bit_offset
;
11226 HOST_WIDE_INT
unsigned bit_offset
;
11228 /* Must be a field and a bit field. */
11229 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
11231 /* We can't yet handle bit-fields whose offsets are variable, so if we
11232 encounter such things, just return without generating any attribute
11233 whatsoever. Likewise for variable or too large size. */
11234 if (! host_integerp (bit_position (decl
), 0)
11235 || ! host_integerp (DECL_SIZE (decl
), 1))
11238 bitpos_int
= int_bit_position (decl
);
11240 /* Note that the bit offset is always the distance (in bits) from the
11241 highest-order bit of the "containing object" to the highest-order bit of
11242 the bit-field itself. Since the "high-order end" of any object or field
11243 is different on big-endian and little-endian machines, the computation
11244 below must take account of these differences. */
11245 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
11246 highest_order_field_bit_offset
= bitpos_int
;
11248 if (! BYTES_BIG_ENDIAN
)
11250 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
11251 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
11255 = (! BYTES_BIG_ENDIAN
11256 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
11257 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
11259 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
11262 /* For a FIELD_DECL node which represents a bit field, output an attribute
11263 which specifies the length in bits of the given field. */
11266 add_bit_size_attribute (dw_die_ref die
, tree decl
)
11268 /* Must be a field and a bit field. */
11269 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
11270 && DECL_BIT_FIELD_TYPE (decl
));
11272 if (host_integerp (DECL_SIZE (decl
), 1))
11273 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
11276 /* If the compiled language is ANSI C, then add a 'prototyped'
11277 attribute, if arg types are given for the parameters of a function. */
11280 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
11282 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
11283 && TYPE_ARG_TYPES (func_type
) != NULL
)
11284 add_AT_flag (die
, DW_AT_prototyped
, 1);
11287 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
11288 by looking in either the type declaration or object declaration
11292 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
11294 dw_die_ref origin_die
= NULL
;
11296 if (TREE_CODE (origin
) != FUNCTION_DECL
)
11298 /* We may have gotten separated from the block for the inlined
11299 function, if we're in an exception handler or some such; make
11300 sure that the abstract function has been written out.
11302 Doing this for nested functions is wrong, however; functions are
11303 distinct units, and our context might not even be inline. */
11307 fn
= TYPE_STUB_DECL (fn
);
11309 fn
= decl_function_context (fn
);
11311 dwarf2out_abstract_function (fn
);
11314 if (DECL_P (origin
))
11315 origin_die
= lookup_decl_die (origin
);
11316 else if (TYPE_P (origin
))
11317 origin_die
= lookup_type_die (origin
);
11319 /* XXX: Functions that are never lowered don't always have correct block
11320 trees (in the case of java, they simply have no block tree, in some other
11321 languages). For these functions, there is nothing we can really do to
11322 output correct debug info for inlined functions in all cases. Rather
11323 than die, we'll just produce deficient debug info now, in that we will
11324 have variables without a proper abstract origin. In the future, when all
11325 functions are lowered, we should re-add a gcc_assert (origin_die)
11329 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
11332 /* We do not currently support the pure_virtual attribute. */
11335 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
11337 if (DECL_VINDEX (func_decl
))
11339 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11341 if (host_integerp (DECL_VINDEX (func_decl
), 0))
11342 add_AT_loc (die
, DW_AT_vtable_elem_location
,
11343 new_loc_descr (DW_OP_constu
,
11344 tree_low_cst (DECL_VINDEX (func_decl
), 0),
11347 /* GNU extension: Record what type this method came from originally. */
11348 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11349 add_AT_die_ref (die
, DW_AT_containing_type
,
11350 lookup_type_die (DECL_CONTEXT (func_decl
)));
11354 /* Add source coordinate attributes for the given decl. */
11357 add_src_coords_attributes (dw_die_ref die
, tree decl
)
11359 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11361 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
11362 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
11365 /* Add a DW_AT_name attribute and source coordinate attribute for the
11366 given decl, but only if it actually has a name. */
11369 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
11373 decl_name
= DECL_NAME (decl
);
11374 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
11376 add_name_attribute (die
, dwarf2_name (decl
, 0));
11377 if (! DECL_ARTIFICIAL (decl
))
11378 add_src_coords_attributes (die
, decl
);
11380 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
11381 && TREE_PUBLIC (decl
)
11382 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
11383 && !DECL_ABSTRACT (decl
)
11384 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
11386 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
11387 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
11390 #ifdef VMS_DEBUGGING_INFO
11391 /* Get the function's name, as described by its RTL. This may be different
11392 from the DECL_NAME name used in the source file. */
11393 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
11395 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
11396 XEXP (DECL_RTL (decl
), 0));
11397 VEC_safe_push (tree
, gc
, used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
11402 /* Push a new declaration scope. */
11405 push_decl_scope (tree scope
)
11407 VEC_safe_push (tree
, gc
, decl_scope_table
, scope
);
11410 /* Pop a declaration scope. */
11413 pop_decl_scope (void)
11415 VEC_pop (tree
, decl_scope_table
);
11418 /* Return the DIE for the scope that immediately contains this type.
11419 Non-named types get global scope. Named types nested in other
11420 types get their containing scope if it's open, or global scope
11421 otherwise. All other types (i.e. function-local named types) get
11422 the current active scope. */
11425 scope_die_for (tree t
, dw_die_ref context_die
)
11427 dw_die_ref scope_die
= NULL
;
11428 tree containing_scope
;
11431 /* Non-types always go in the current scope. */
11432 gcc_assert (TYPE_P (t
));
11434 containing_scope
= TYPE_CONTEXT (t
);
11436 /* Use the containing namespace if it was passed in (for a declaration). */
11437 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
11439 if (context_die
== lookup_decl_die (containing_scope
))
11442 containing_scope
= NULL_TREE
;
11445 /* Ignore function type "scopes" from the C frontend. They mean that
11446 a tagged type is local to a parmlist of a function declarator, but
11447 that isn't useful to DWARF. */
11448 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
11449 containing_scope
= NULL_TREE
;
11451 if (containing_scope
== NULL_TREE
)
11452 scope_die
= comp_unit_die
;
11453 else if (TYPE_P (containing_scope
))
11455 /* For types, we can just look up the appropriate DIE. But
11456 first we check to see if we're in the middle of emitting it
11457 so we know where the new DIE should go. */
11458 for (i
= VEC_length (tree
, decl_scope_table
) - 1; i
>= 0; --i
)
11459 if (VEC_index (tree
, decl_scope_table
, i
) == containing_scope
)
11464 gcc_assert (debug_info_level
<= DINFO_LEVEL_TERSE
11465 || TREE_ASM_WRITTEN (containing_scope
));
11467 /* If none of the current dies are suitable, we get file scope. */
11468 scope_die
= comp_unit_die
;
11471 scope_die
= lookup_type_die (containing_scope
);
11474 scope_die
= context_die
;
11479 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
11482 local_scope_p (dw_die_ref context_die
)
11484 for (; context_die
; context_die
= context_die
->die_parent
)
11485 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
11486 || context_die
->die_tag
== DW_TAG_subprogram
)
11492 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
11493 whether or not to treat a DIE in this context as a declaration. */
11496 class_or_namespace_scope_p (dw_die_ref context_die
)
11498 return (context_die
11499 && (context_die
->die_tag
== DW_TAG_structure_type
11500 || context_die
->die_tag
== DW_TAG_class_type
11501 || context_die
->die_tag
== DW_TAG_interface_type
11502 || context_die
->die_tag
== DW_TAG_union_type
11503 || context_die
->die_tag
== DW_TAG_namespace
));
11506 /* Many forms of DIEs require a "type description" attribute. This
11507 routine locates the proper "type descriptor" die for the type given
11508 by 'type', and adds a DW_AT_type attribute below the given die. */
11511 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
11512 int decl_volatile
, dw_die_ref context_die
)
11514 enum tree_code code
= TREE_CODE (type
);
11515 dw_die_ref type_die
= NULL
;
11517 /* ??? If this type is an unnamed subrange type of an integral, floating-point
11518 or fixed-point type, use the inner type. This is because we have no
11519 support for unnamed types in base_type_die. This can happen if this is
11520 an Ada subrange type. Correct solution is emit a subrange type die. */
11521 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
11522 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
11523 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
11525 if (code
== ERROR_MARK
11526 /* Handle a special case. For functions whose return type is void, we
11527 generate *no* type attribute. (Note that no object may have type
11528 `void', so this only applies to function return types). */
11529 || code
== VOID_TYPE
)
11532 type_die
= modified_type_die (type
,
11533 decl_const
|| TYPE_READONLY (type
),
11534 decl_volatile
|| TYPE_VOLATILE (type
),
11537 if (type_die
!= NULL
)
11538 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
11541 /* Given an object die, add the calling convention attribute for the
11542 function call type. */
11544 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
11546 enum dwarf_calling_convention value
= DW_CC_normal
;
11548 value
= targetm
.dwarf_calling_convention (TREE_TYPE (decl
));
11550 /* DWARF doesn't provide a way to identify a program's source-level
11551 entry point. DW_AT_calling_convention attributes are only meant
11552 to describe functions' calling conventions. However, lacking a
11553 better way to signal the Fortran main program, we use this for the
11554 time being, following existing custom. */
11556 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
11557 value
= DW_CC_program
;
11559 /* Only add the attribute if the backend requests it, and
11560 is not DW_CC_normal. */
11561 if (value
&& (value
!= DW_CC_normal
))
11562 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
11565 /* Given a tree pointer to a struct, class, union, or enum type node, return
11566 a pointer to the (string) tag name for the given type, or zero if the type
11567 was declared without a tag. */
11569 static const char *
11570 type_tag (const_tree type
)
11572 const char *name
= 0;
11574 if (TYPE_NAME (type
) != 0)
11578 /* Find the IDENTIFIER_NODE for the type name. */
11579 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
11580 t
= TYPE_NAME (type
);
11582 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
11583 a TYPE_DECL node, regardless of whether or not a `typedef' was
11585 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11586 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
11588 /* We want to be extra verbose. Don't call dwarf_name if
11589 DECL_NAME isn't set. The default hook for decl_printable_name
11590 doesn't like that, and in this context it's correct to return
11591 0, instead of "<anonymous>" or the like. */
11592 if (DECL_NAME (TYPE_NAME (type
)))
11593 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
11596 /* Now get the name as a string, or invent one. */
11597 if (!name
&& t
!= 0)
11598 name
= IDENTIFIER_POINTER (t
);
11601 return (name
== 0 || *name
== '\0') ? 0 : name
;
11604 /* Return the type associated with a data member, make a special check
11605 for bit field types. */
11608 member_declared_type (const_tree member
)
11610 return (DECL_BIT_FIELD_TYPE (member
)
11611 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
11614 /* Get the decl's label, as described by its RTL. This may be different
11615 from the DECL_NAME name used in the source file. */
11618 static const char *
11619 decl_start_label (tree decl
)
11622 const char *fnname
;
11624 x
= DECL_RTL (decl
);
11625 gcc_assert (MEM_P (x
));
11628 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
11630 fnname
= XSTR (x
, 0);
11635 /* These routines generate the internal representation of the DIE's for
11636 the compilation unit. Debugging information is collected by walking
11637 the declaration trees passed in from dwarf2out_decl(). */
11640 gen_array_type_die (tree type
, dw_die_ref context_die
)
11642 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
11643 dw_die_ref array_die
;
11646 /* ??? The SGI dwarf reader fails for array of array of enum types unless
11647 the inner array type comes before the outer array type. Thus we must
11648 call gen_type_die before we call new_die. See below also. */
11649 #ifdef MIPS_DEBUGGING_INFO
11650 gen_type_die (TREE_TYPE (type
), context_die
);
11653 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
11654 add_name_attribute (array_die
, type_tag (type
));
11655 equate_type_number_to_die (type
, array_die
);
11657 if (TREE_CODE (type
) == VECTOR_TYPE
)
11659 /* The frontend feeds us a representation for the vector as a struct
11660 containing an array. Pull out the array type. */
11661 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
11662 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
11665 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11667 && TREE_CODE (type
) == ARRAY_TYPE
11668 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
)
11669 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
11672 /* We default the array ordering. SDB will probably do
11673 the right things even if DW_AT_ordering is not present. It's not even
11674 an issue until we start to get into multidimensional arrays anyway. If
11675 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
11676 then we'll have to put the DW_AT_ordering attribute back in. (But if
11677 and when we find out that we need to put these in, we will only do so
11678 for multidimensional arrays. */
11679 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
11682 #ifdef MIPS_DEBUGGING_INFO
11683 /* The SGI compilers handle arrays of unknown bound by setting
11684 AT_declaration and not emitting any subrange DIEs. */
11685 if (! TYPE_DOMAIN (type
))
11686 add_AT_flag (array_die
, DW_AT_declaration
, 1);
11689 add_subscript_info (array_die
, type
);
11691 /* Add representation of the type of the elements of this array type. */
11692 element_type
= TREE_TYPE (type
);
11694 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
11695 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
11696 We work around this by disabling this feature. See also
11697 add_subscript_info. */
11698 #ifndef MIPS_DEBUGGING_INFO
11699 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
11700 element_type
= TREE_TYPE (element_type
);
11702 gen_type_die (element_type
, context_die
);
11705 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
11707 if (get_AT (array_die
, DW_AT_name
))
11708 add_pubtype (type
, array_die
);
11711 static dw_loc_descr_ref
11712 descr_info_loc (tree val
, tree base_decl
)
11714 HOST_WIDE_INT size
;
11715 dw_loc_descr_ref loc
, loc2
;
11716 enum dwarf_location_atom op
;
11718 if (val
== base_decl
)
11719 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
11721 switch (TREE_CODE (val
))
11725 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
11727 if (host_integerp (val
, 0))
11728 return int_loc_descriptor (tree_low_cst (val
, 0));
11731 size
= int_size_in_bytes (TREE_TYPE (val
));
11734 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
11737 if (size
== DWARF2_ADDR_SIZE
)
11738 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
11740 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
11742 case POINTER_PLUS_EXPR
:
11744 if (host_integerp (TREE_OPERAND (val
, 1), 1)
11745 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
11748 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
11751 add_loc_descr (&loc
,
11752 new_loc_descr (DW_OP_plus_uconst
,
11753 tree_low_cst (TREE_OPERAND (val
, 1),
11760 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
11763 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
11766 add_loc_descr (&loc
, loc2
);
11767 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
11789 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
11790 tree val
, tree base_decl
)
11792 dw_loc_descr_ref loc
;
11794 if (host_integerp (val
, 0))
11796 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
11800 loc
= descr_info_loc (val
, base_decl
);
11804 add_AT_loc (die
, attr
, loc
);
11807 /* This routine generates DIE for array with hidden descriptor, details
11808 are filled into *info by a langhook. */
11811 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
11812 dw_die_ref context_die
)
11814 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
11815 dw_die_ref array_die
;
11818 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
11819 add_name_attribute (array_die
, type_tag (type
));
11820 equate_type_number_to_die (type
, array_die
);
11822 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
11824 && info
->ndimensions
>= 2)
11825 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
11827 if (info
->data_location
)
11828 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
11830 if (info
->associated
)
11831 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
11833 if (info
->allocated
)
11834 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
11837 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
11839 dw_die_ref subrange_die
11840 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
11842 if (info
->dimen
[dim
].lower_bound
)
11844 /* If it is the default value, omit it. */
11845 if ((is_c_family () || is_java ())
11846 && integer_zerop (info
->dimen
[dim
].lower_bound
))
11848 else if (is_fortran ()
11849 && integer_onep (info
->dimen
[dim
].lower_bound
))
11852 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
11853 info
->dimen
[dim
].lower_bound
,
11856 if (info
->dimen
[dim
].upper_bound
)
11857 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
11858 info
->dimen
[dim
].upper_bound
,
11860 if (info
->dimen
[dim
].stride
)
11861 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
11862 info
->dimen
[dim
].stride
,
11866 gen_type_die (info
->element_type
, context_die
);
11867 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
11869 if (get_AT (array_die
, DW_AT_name
))
11870 add_pubtype (type
, array_die
);
11875 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
11877 tree origin
= decl_ultimate_origin (decl
);
11878 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
11880 if (origin
!= NULL
)
11881 add_abstract_origin_attribute (decl_die
, origin
);
11884 add_name_and_src_coords_attributes (decl_die
, decl
);
11885 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
11886 0, 0, context_die
);
11889 if (DECL_ABSTRACT (decl
))
11890 equate_decl_number_to_die (decl
, decl_die
);
11892 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
11896 /* Walk through the list of incomplete types again, trying once more to
11897 emit full debugging info for them. */
11900 retry_incomplete_types (void)
11904 for (i
= VEC_length (tree
, incomplete_types
) - 1; i
>= 0; i
--)
11905 gen_type_die (VEC_index (tree
, incomplete_types
, i
), comp_unit_die
);
11908 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11911 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
11913 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
11915 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11916 be incomplete and such types are not marked. */
11917 add_abstract_origin_attribute (type_die
, type
);
11920 /* Determine what tag to use for a record type. */
11922 static enum dwarf_tag
11923 record_type_tag (tree type
)
11925 if (! lang_hooks
.types
.classify_record
)
11926 return DW_TAG_structure_type
;
11928 switch (lang_hooks
.types
.classify_record (type
))
11930 case RECORD_IS_STRUCT
:
11931 return DW_TAG_structure_type
;
11933 case RECORD_IS_CLASS
:
11934 return DW_TAG_class_type
;
11936 case RECORD_IS_INTERFACE
:
11937 return DW_TAG_interface_type
;
11940 gcc_unreachable ();
11944 /* Generate a DIE to represent an inlined instance of a structure type. */
11947 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
11949 dw_die_ref type_die
= new_die (record_type_tag (type
), context_die
, type
);
11951 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11952 be incomplete and such types are not marked. */
11953 add_abstract_origin_attribute (type_die
, type
);
11956 /* Generate a DIE to represent an inlined instance of a union type. */
11959 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
11961 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
11963 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11964 be incomplete and such types are not marked. */
11965 add_abstract_origin_attribute (type_die
, type
);
11968 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11969 include all of the information about the enumeration values also. Each
11970 enumerated type name/value is listed as a child of the enumerated type
11974 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
11976 dw_die_ref type_die
= lookup_type_die (type
);
11978 if (type_die
== NULL
)
11980 type_die
= new_die (DW_TAG_enumeration_type
,
11981 scope_die_for (type
, context_die
), type
);
11982 equate_type_number_to_die (type
, type_die
);
11983 add_name_attribute (type_die
, type_tag (type
));
11985 else if (! TYPE_SIZE (type
))
11988 remove_AT (type_die
, DW_AT_declaration
);
11990 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11991 given enum type is incomplete, do not generate the DW_AT_byte_size
11992 attribute or the DW_AT_element_list attribute. */
11993 if (TYPE_SIZE (type
))
11997 TREE_ASM_WRITTEN (type
) = 1;
11998 add_byte_size_attribute (type_die
, type
);
11999 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
12000 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
12002 /* If the first reference to this type was as the return type of an
12003 inline function, then it may not have a parent. Fix this now. */
12004 if (type_die
->die_parent
== NULL
)
12005 add_child_die (scope_die_for (type
, context_die
), type_die
);
12007 for (link
= TYPE_VALUES (type
);
12008 link
!= NULL
; link
= TREE_CHAIN (link
))
12010 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
12011 tree value
= TREE_VALUE (link
);
12013 add_name_attribute (enum_die
,
12014 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
12016 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
12017 /* DWARF2 does not provide a way of indicating whether or
12018 not enumeration constants are signed or unsigned. GDB
12019 always assumes the values are signed, so we output all
12020 values as if they were signed. That means that
12021 enumeration constants with very large unsigned values
12022 will appear to have negative values in the debugger. */
12023 add_AT_int (enum_die
, DW_AT_const_value
,
12024 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
12028 add_AT_flag (type_die
, DW_AT_declaration
, 1);
12030 if (get_AT (type_die
, DW_AT_name
))
12031 add_pubtype (type
, type_die
);
12036 /* Generate a DIE to represent either a real live formal parameter decl or to
12037 represent just the type of some formal parameter position in some function
12040 Note that this routine is a bit unusual because its argument may be a
12041 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
12042 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
12043 node. If it's the former then this function is being called to output a
12044 DIE to represent a formal parameter object (or some inlining thereof). If
12045 it's the latter, then this function is only being called to output a
12046 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
12047 argument type of some subprogram type. */
12050 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
12052 dw_die_ref parm_die
12053 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
12056 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
12058 case tcc_declaration
:
12059 origin
= decl_ultimate_origin (node
);
12060 if (origin
!= NULL
)
12061 add_abstract_origin_attribute (parm_die
, origin
);
12064 tree type
= TREE_TYPE (node
);
12065 add_name_and_src_coords_attributes (parm_die
, node
);
12066 if (DECL_BY_REFERENCE (node
))
12067 type
= TREE_TYPE (type
);
12068 add_type_attribute (parm_die
, type
,
12069 TREE_READONLY (node
),
12070 TREE_THIS_VOLATILE (node
),
12072 if (DECL_ARTIFICIAL (node
))
12073 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
12076 equate_decl_number_to_die (node
, parm_die
);
12077 if (! DECL_ABSTRACT (node
))
12078 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
12083 /* We were called with some kind of a ..._TYPE node. */
12084 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
12088 gcc_unreachable ();
12094 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
12095 at the end of an (ANSI prototyped) formal parameters list. */
12098 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
12100 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
12103 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
12104 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
12105 parameters as specified in some function type specification (except for
12106 those which appear as part of a function *definition*). */
12109 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
12112 tree formal_type
= NULL
;
12113 tree first_parm_type
;
12116 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
12118 arg
= DECL_ARGUMENTS (function_or_method_type
);
12119 function_or_method_type
= TREE_TYPE (function_or_method_type
);
12124 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
12126 /* Make our first pass over the list of formal parameter types and output a
12127 DW_TAG_formal_parameter DIE for each one. */
12128 for (link
= first_parm_type
; link
; )
12130 dw_die_ref parm_die
;
12132 formal_type
= TREE_VALUE (link
);
12133 if (formal_type
== void_type_node
)
12136 /* Output a (nameless) DIE to represent the formal parameter itself. */
12137 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
12138 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
12139 && link
== first_parm_type
)
12140 || (arg
&& DECL_ARTIFICIAL (arg
)))
12141 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
12143 link
= TREE_CHAIN (link
);
12145 arg
= TREE_CHAIN (arg
);
12148 /* If this function type has an ellipsis, add a
12149 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
12150 if (formal_type
!= void_type_node
)
12151 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
12153 /* Make our second (and final) pass over the list of formal parameter types
12154 and output DIEs to represent those types (as necessary). */
12155 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
12156 link
&& TREE_VALUE (link
);
12157 link
= TREE_CHAIN (link
))
12158 gen_type_die (TREE_VALUE (link
), context_die
);
12161 /* We want to generate the DIE for TYPE so that we can generate the
12162 die for MEMBER, which has been defined; we will need to refer back
12163 to the member declaration nested within TYPE. If we're trying to
12164 generate minimal debug info for TYPE, processing TYPE won't do the
12165 trick; we need to attach the member declaration by hand. */
12168 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
12170 gen_type_die (type
, context_die
);
12172 /* If we're trying to avoid duplicate debug info, we may not have
12173 emitted the member decl for this function. Emit it now. */
12174 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
12175 && ! lookup_decl_die (member
))
12177 dw_die_ref type_die
;
12178 gcc_assert (!decl_ultimate_origin (member
));
12180 push_decl_scope (type
);
12181 type_die
= lookup_type_die (type
);
12182 if (TREE_CODE (member
) == FUNCTION_DECL
)
12183 gen_subprogram_die (member
, type_die
);
12184 else if (TREE_CODE (member
) == FIELD_DECL
)
12186 /* Ignore the nameless fields that are used to skip bits but handle
12187 C++ anonymous unions and structs. */
12188 if (DECL_NAME (member
) != NULL_TREE
12189 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
12190 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
12192 gen_type_die (member_declared_type (member
), type_die
);
12193 gen_field_die (member
, type_die
);
12197 gen_variable_die (member
, type_die
);
12203 /* Generate the DWARF2 info for the "abstract" instance of a function which we
12204 may later generate inlined and/or out-of-line instances of. */
12207 dwarf2out_abstract_function (tree decl
)
12209 dw_die_ref old_die
;
12212 int was_abstract
= DECL_ABSTRACT (decl
);
12214 /* Make sure we have the actual abstract inline, not a clone. */
12215 decl
= DECL_ORIGIN (decl
);
12217 old_die
= lookup_decl_die (decl
);
12218 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
12219 /* We've already generated the abstract instance. */
12222 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
12223 we don't get confused by DECL_ABSTRACT. */
12224 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12226 context
= decl_class_context (decl
);
12228 gen_type_die_for_member
12229 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
12232 /* Pretend we've just finished compiling this function. */
12233 save_fn
= current_function_decl
;
12234 current_function_decl
= decl
;
12235 push_cfun (DECL_STRUCT_FUNCTION (decl
));
12237 set_decl_abstract_flags (decl
, 1);
12238 dwarf2out_decl (decl
);
12239 if (! was_abstract
)
12240 set_decl_abstract_flags (decl
, 0);
12242 current_function_decl
= save_fn
;
12246 /* Helper function of premark_used_types() which gets called through
12247 htab_traverse_resize().
12249 Marks the DIE of a given type in *SLOT as perennial, so it never gets
12250 marked as unused by prune_unused_types. */
12252 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
12258 die
= lookup_type_die (type
);
12260 die
->die_perennial_p
= 1;
12264 /* Mark all members of used_types_hash as perennial. */
12266 premark_used_types (void)
12268 if (cfun
&& cfun
->used_types_hash
)
12269 htab_traverse (cfun
->used_types_hash
, premark_used_types_helper
, NULL
);
12272 /* Generate a DIE to represent a declared function (either file-scope or
12276 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
12278 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
12279 tree origin
= decl_ultimate_origin (decl
);
12280 dw_die_ref subr_die
;
12283 dw_die_ref old_die
= lookup_decl_die (decl
);
12284 int declaration
= (current_function_decl
!= decl
12285 || class_or_namespace_scope_p (context_die
));
12287 premark_used_types ();
12289 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
12290 started to generate the abstract instance of an inline, decided to output
12291 its containing class, and proceeded to emit the declaration of the inline
12292 from the member list for the class. If so, DECLARATION takes priority;
12293 we'll get back to the abstract instance when done with the class. */
12295 /* The class-scope declaration DIE must be the primary DIE. */
12296 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
12299 gcc_assert (!old_die
);
12302 /* Now that the C++ front end lazily declares artificial member fns, we
12303 might need to retrofit the declaration into its class. */
12304 if (!declaration
&& !origin
&& !old_die
12305 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
12306 && !class_or_namespace_scope_p (context_die
)
12307 && debug_info_level
> DINFO_LEVEL_TERSE
)
12308 old_die
= force_decl_die (decl
);
12310 if (origin
!= NULL
)
12312 gcc_assert (!declaration
|| local_scope_p (context_die
));
12314 /* Fixup die_parent for the abstract instance of a nested
12315 inline function. */
12316 if (old_die
&& old_die
->die_parent
== NULL
)
12317 add_child_die (context_die
, old_die
);
12319 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
12320 add_abstract_origin_attribute (subr_die
, origin
);
12324 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12325 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
12327 if (!get_AT_flag (old_die
, DW_AT_declaration
)
12328 /* We can have a normal definition following an inline one in the
12329 case of redefinition of GNU C extern inlines.
12330 It seems reasonable to use AT_specification in this case. */
12331 && !get_AT (old_die
, DW_AT_inline
))
12333 /* Detect and ignore this case, where we are trying to output
12334 something we have already output. */
12338 /* If the definition comes from the same place as the declaration,
12339 maybe use the old DIE. We always want the DIE for this function
12340 that has the *_pc attributes to be under comp_unit_die so the
12341 debugger can find it. We also need to do this for abstract
12342 instances of inlines, since the spec requires the out-of-line copy
12343 to have the same parent. For local class methods, this doesn't
12344 apply; we just use the old DIE. */
12345 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
12346 && (DECL_ARTIFICIAL (decl
)
12347 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
12348 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
12349 == (unsigned) s
.line
))))
12351 subr_die
= old_die
;
12353 /* Clear out the declaration attribute and the formal parameters.
12354 Do not remove all children, because it is possible that this
12355 declaration die was forced using force_decl_die(). In such
12356 cases die that forced declaration die (e.g. TAG_imported_module)
12357 is one of the children that we do not want to remove. */
12358 remove_AT (subr_die
, DW_AT_declaration
);
12359 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
12363 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
12364 add_AT_specification (subr_die
, old_die
);
12365 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
12366 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
12367 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
12368 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
12373 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
12375 if (TREE_PUBLIC (decl
))
12376 add_AT_flag (subr_die
, DW_AT_external
, 1);
12378 add_name_and_src_coords_attributes (subr_die
, decl
);
12379 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12381 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
12382 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
12383 0, 0, context_die
);
12386 add_pure_or_virtual_attribute (subr_die
, decl
);
12387 if (DECL_ARTIFICIAL (decl
))
12388 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
12390 if (TREE_PROTECTED (decl
))
12391 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12392 else if (TREE_PRIVATE (decl
))
12393 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12398 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
12400 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
12402 /* The first time we see a member function, it is in the context of
12403 the class to which it belongs. We make sure of this by emitting
12404 the class first. The next time is the definition, which is
12405 handled above. The two may come from the same source text.
12407 Note that force_decl_die() forces function declaration die. It is
12408 later reused to represent definition. */
12409 equate_decl_number_to_die (decl
, subr_die
);
12412 else if (DECL_ABSTRACT (decl
))
12414 if (DECL_DECLARED_INLINE_P (decl
))
12416 if (cgraph_function_possibly_inlined_p (decl
))
12417 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
12419 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
12423 if (cgraph_function_possibly_inlined_p (decl
))
12424 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
12426 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
12429 if (DECL_DECLARED_INLINE_P (decl
)
12430 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
12431 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
12433 equate_decl_number_to_die (decl
, subr_die
);
12435 else if (!DECL_EXTERNAL (decl
))
12437 HOST_WIDE_INT cfa_fb_offset
;
12439 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
12440 equate_decl_number_to_die (decl
, subr_die
);
12442 if (!flag_reorder_blocks_and_partition
)
12444 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
12445 current_function_funcdef_no
);
12446 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
12447 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
12448 current_function_funcdef_no
);
12449 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
12451 add_pubname (decl
, subr_die
);
12452 add_arange (decl
, subr_die
);
12455 { /* Do nothing for now; maybe need to duplicate die, one for
12456 hot section and ond for cold section, then use the hot/cold
12457 section begin/end labels to generate the aranges... */
12459 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
12460 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
12461 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
12462 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
12464 add_pubname (decl, subr_die);
12465 add_arange (decl, subr_die);
12466 add_arange (decl, subr_die);
12470 #ifdef MIPS_DEBUGGING_INFO
12471 /* Add a reference to the FDE for this routine. */
12472 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
12475 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
12477 /* We define the "frame base" as the function's CFA. This is more
12478 convenient for several reasons: (1) It's stable across the prologue
12479 and epilogue, which makes it better than just a frame pointer,
12480 (2) With dwarf3, there exists a one-byte encoding that allows us
12481 to reference the .debug_frame data by proxy, but failing that,
12482 (3) We can at least reuse the code inspection and interpretation
12483 code that determines the CFA position at various points in the
12485 /* ??? Use some command-line or configury switch to enable the use
12486 of dwarf3 DW_OP_call_frame_cfa. At present there are no dwarf
12487 consumers that understand it; fall back to "pure" dwarf2 and
12488 convert the CFA data into a location list. */
12490 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
12491 if (list
->dw_loc_next
)
12492 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
12494 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
12497 /* Compute a displacement from the "steady-state frame pointer" to
12498 the CFA. The former is what all stack slots and argument slots
12499 will reference in the rtl; the later is what we've told the
12500 debugger about. We'll need to adjust all frame_base references
12501 by this displacement. */
12502 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
12504 if (cfun
->static_chain_decl
)
12505 add_AT_location_description (subr_die
, DW_AT_static_link
,
12506 loc_descriptor_from_tree (cfun
->static_chain_decl
));
12509 /* Now output descriptions of the arguments for this function. This gets
12510 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
12511 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
12512 `...' at the end of the formal parameter list. In order to find out if
12513 there was a trailing ellipsis or not, we must instead look at the type
12514 associated with the FUNCTION_DECL. This will be a node of type
12515 FUNCTION_TYPE. If the chain of type nodes hanging off of this
12516 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
12517 an ellipsis at the end. */
12519 /* In the case where we are describing a mere function declaration, all we
12520 need to do here (and all we *can* do here) is to describe the *types* of
12521 its formal parameters. */
12522 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12524 else if (declaration
)
12525 gen_formal_types_die (decl
, subr_die
);
12528 /* Generate DIEs to represent all known formal parameters. */
12529 tree arg_decls
= DECL_ARGUMENTS (decl
);
12532 /* When generating DIEs, generate the unspecified_parameters DIE
12533 instead if we come across the arg "__builtin_va_alist" */
12534 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
12535 if (TREE_CODE (parm
) == PARM_DECL
)
12537 if (DECL_NAME (parm
)
12538 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
12539 "__builtin_va_alist"))
12540 gen_unspecified_parameters_die (parm
, subr_die
);
12542 gen_decl_die (parm
, subr_die
);
12545 /* Decide whether we need an unspecified_parameters DIE at the end.
12546 There are 2 more cases to do this for: 1) the ansi ... declaration -
12547 this is detectable when the end of the arg list is not a
12548 void_type_node 2) an unprototyped function declaration (not a
12549 definition). This just means that we have no info about the
12550 parameters at all. */
12551 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
12552 if (fn_arg_types
!= NULL
)
12554 /* This is the prototyped case, check for.... */
12555 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
12556 gen_unspecified_parameters_die (decl
, subr_die
);
12558 else if (DECL_INITIAL (decl
) == NULL_TREE
)
12559 gen_unspecified_parameters_die (decl
, subr_die
);
12562 /* Output Dwarf info for all of the stuff within the body of the function
12563 (if it has one - it may be just a declaration). */
12564 outer_scope
= DECL_INITIAL (decl
);
12566 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
12567 a function. This BLOCK actually represents the outermost binding contour
12568 for the function, i.e. the contour in which the function's formal
12569 parameters and labels get declared. Curiously, it appears that the front
12570 end doesn't actually put the PARM_DECL nodes for the current function onto
12571 the BLOCK_VARS list for this outer scope, but are strung off of the
12572 DECL_ARGUMENTS list for the function instead.
12574 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
12575 the LABEL_DECL nodes for the function however, and we output DWARF info
12576 for those in decls_for_scope. Just within the `outer_scope' there will be
12577 a BLOCK node representing the function's outermost pair of curly braces,
12578 and any blocks used for the base and member initializers of a C++
12579 constructor function. */
12580 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
12582 /* Emit a DW_TAG_variable DIE for a named return value. */
12583 if (DECL_NAME (DECL_RESULT (decl
)))
12584 gen_decl_die (DECL_RESULT (decl
), subr_die
);
12586 current_function_has_inlines
= 0;
12587 decls_for_scope (outer_scope
, subr_die
, 0);
12589 #if 0 && defined (MIPS_DEBUGGING_INFO)
12590 if (current_function_has_inlines
)
12592 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
12593 if (! comp_unit_has_inlines
)
12595 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
12596 comp_unit_has_inlines
= 1;
12601 /* Add the calling convention attribute if requested. */
12602 add_calling_convention_attribute (subr_die
, decl
);
12606 /* Generate a DIE to represent a declared data object. */
12609 gen_variable_die (tree decl
, dw_die_ref context_die
)
12611 tree origin
= decl_ultimate_origin (decl
);
12612 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
12614 dw_die_ref old_die
= lookup_decl_die (decl
);
12615 int declaration
= (DECL_EXTERNAL (decl
)
12616 /* If DECL is COMDAT and has not actually been
12617 emitted, we cannot take its address; there
12618 might end up being no definition anywhere in
12619 the program. For example, consider the C++
12623 struct S { static const int i = 7; };
12628 int f() { return S<int>::i; }
12630 Here, S<int>::i is not DECL_EXTERNAL, but no
12631 definition is required, so the compiler will
12632 not emit a definition. */
12633 || (TREE_CODE (decl
) == VAR_DECL
12634 && DECL_COMDAT (decl
) && !TREE_ASM_WRITTEN (decl
))
12635 || class_or_namespace_scope_p (context_die
));
12637 if (origin
!= NULL
)
12638 add_abstract_origin_attribute (var_die
, origin
);
12640 /* Loop unrolling can create multiple blocks that refer to the same
12641 static variable, so we must test for the DW_AT_declaration flag.
12643 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
12644 copy decls and set the DECL_ABSTRACT flag on them instead of
12647 ??? Duplicated blocks have been rewritten to use .debug_ranges.
12649 ??? The declare_in_namespace support causes us to get two DIEs for one
12650 variable, both of which are declarations. We want to avoid considering
12651 one to be a specification, so we must test that this DIE is not a
12653 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
12654 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
12656 /* This is a definition of a C++ class level static. */
12657 add_AT_specification (var_die
, old_die
);
12658 if (DECL_NAME (decl
))
12660 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
12661 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
12663 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
12664 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
12666 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
12667 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
12672 tree type
= TREE_TYPE (decl
);
12673 if ((TREE_CODE (decl
) == PARM_DECL
12674 || TREE_CODE (decl
) == RESULT_DECL
)
12675 && DECL_BY_REFERENCE (decl
))
12676 type
= TREE_TYPE (type
);
12678 add_name_and_src_coords_attributes (var_die
, decl
);
12679 add_type_attribute (var_die
, type
, TREE_READONLY (decl
),
12680 TREE_THIS_VOLATILE (decl
), context_die
);
12682 if (TREE_PUBLIC (decl
))
12683 add_AT_flag (var_die
, DW_AT_external
, 1);
12685 if (DECL_ARTIFICIAL (decl
))
12686 add_AT_flag (var_die
, DW_AT_artificial
, 1);
12688 if (TREE_PROTECTED (decl
))
12689 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12690 else if (TREE_PRIVATE (decl
))
12691 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12695 add_AT_flag (var_die
, DW_AT_declaration
, 1);
12697 if (DECL_ABSTRACT (decl
) || declaration
)
12698 equate_decl_number_to_die (decl
, var_die
);
12700 if (! declaration
&& ! DECL_ABSTRACT (decl
))
12702 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
12703 add_pubname (decl
, var_die
);
12706 tree_add_const_value_attribute (var_die
, decl
);
12709 /* Generate a DIE to represent a label identifier. */
12712 gen_label_die (tree decl
, dw_die_ref context_die
)
12714 tree origin
= decl_ultimate_origin (decl
);
12715 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
12717 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12719 if (origin
!= NULL
)
12720 add_abstract_origin_attribute (lbl_die
, origin
);
12722 add_name_and_src_coords_attributes (lbl_die
, decl
);
12724 if (DECL_ABSTRACT (decl
))
12725 equate_decl_number_to_die (decl
, lbl_die
);
12728 insn
= DECL_RTL_IF_SET (decl
);
12730 /* Deleted labels are programmer specified labels which have been
12731 eliminated because of various optimizations. We still emit them
12732 here so that it is possible to put breakpoints on them. */
12736 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
12738 /* When optimization is enabled (via -O) some parts of the compiler
12739 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
12740 represent source-level labels which were explicitly declared by
12741 the user. This really shouldn't be happening though, so catch
12742 it if it ever does happen. */
12743 gcc_assert (!INSN_DELETED_P (insn
));
12745 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
12746 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
12751 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
12752 attributes to the DIE for a block STMT, to describe where the inlined
12753 function was called from. This is similar to add_src_coords_attributes. */
12756 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
12758 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
12760 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
12761 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
12765 /* If STMT's abstract origin is a function declaration and STMT's
12766 first subblock's abstract origin is the function's outermost block,
12767 then we're looking at the main entry point. */
12769 is_inlined_entry_point (const_tree stmt
)
12773 if (!stmt
|| TREE_CODE (stmt
) != BLOCK
)
12776 decl
= block_ultimate_origin (stmt
);
12778 if (!decl
|| TREE_CODE (decl
) != FUNCTION_DECL
)
12781 block
= BLOCK_SUBBLOCKS (stmt
);
12785 if (TREE_CODE (block
) != BLOCK
)
12788 block
= block_ultimate_origin (block
);
12791 return block
== DECL_INITIAL (decl
);
12794 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
12795 Add low_pc and high_pc attributes to the DIE for a block STMT. */
12798 add_high_low_attributes (tree stmt
, dw_die_ref die
)
12800 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
12802 if (BLOCK_FRAGMENT_CHAIN (stmt
))
12806 if (is_inlined_entry_point (stmt
))
12808 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
12809 BLOCK_NUMBER (stmt
));
12810 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
12813 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
));
12815 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
12818 add_ranges (chain
);
12819 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
12826 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
12827 BLOCK_NUMBER (stmt
));
12828 add_AT_lbl_id (die
, DW_AT_low_pc
, label
);
12829 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
12830 BLOCK_NUMBER (stmt
));
12831 add_AT_lbl_id (die
, DW_AT_high_pc
, label
);
12835 /* Generate a DIE for a lexical block. */
12838 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12840 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
12842 if (! BLOCK_ABSTRACT (stmt
))
12843 add_high_low_attributes (stmt
, stmt_die
);
12845 decls_for_scope (stmt
, stmt_die
, depth
);
12848 /* Generate a DIE for an inlined subprogram. */
12851 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
12853 tree decl
= block_ultimate_origin (stmt
);
12855 /* Emit info for the abstract instance first, if we haven't yet. We
12856 must emit this even if the block is abstract, otherwise when we
12857 emit the block below (or elsewhere), we may end up trying to emit
12858 a die whose origin die hasn't been emitted, and crashing. */
12859 dwarf2out_abstract_function (decl
);
12861 if (! BLOCK_ABSTRACT (stmt
))
12863 dw_die_ref subr_die
12864 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
12866 add_abstract_origin_attribute (subr_die
, decl
);
12867 add_high_low_attributes (stmt
, subr_die
);
12868 add_call_src_coords_attributes (stmt
, subr_die
);
12870 decls_for_scope (stmt
, subr_die
, depth
);
12871 current_function_has_inlines
= 1;
12874 /* We may get here if we're the outer block of function A that was
12875 inlined into function B that was inlined into function C. When
12876 generating debugging info for C, dwarf2out_abstract_function(B)
12877 would mark all inlined blocks as abstract, including this one.
12878 So, we wouldn't (and shouldn't) expect labels to be generated
12879 for this one. Instead, just emit debugging info for
12880 declarations within the block. This is particularly important
12881 in the case of initializers of arguments passed from B to us:
12882 if they're statement expressions containing declarations, we
12883 wouldn't generate dies for their abstract variables, and then,
12884 when generating dies for the real variables, we'd die (pun
12886 gen_lexical_block_die (stmt
, context_die
, depth
);
12889 /* Generate a DIE for a field in a record, or structure. */
12892 gen_field_die (tree decl
, dw_die_ref context_die
)
12894 dw_die_ref decl_die
;
12896 if (TREE_TYPE (decl
) == error_mark_node
)
12899 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
12900 add_name_and_src_coords_attributes (decl_die
, decl
);
12901 add_type_attribute (decl_die
, member_declared_type (decl
),
12902 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
12905 if (DECL_BIT_FIELD_TYPE (decl
))
12907 add_byte_size_attribute (decl_die
, decl
);
12908 add_bit_size_attribute (decl_die
, decl
);
12909 add_bit_offset_attribute (decl_die
, decl
);
12912 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
12913 add_data_member_location_attribute (decl_die
, decl
);
12915 if (DECL_ARTIFICIAL (decl
))
12916 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
12918 if (TREE_PROTECTED (decl
))
12919 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
12920 else if (TREE_PRIVATE (decl
))
12921 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
12923 /* Equate decl number to die, so that we can look up this decl later on. */
12924 equate_decl_number_to_die (decl
, decl_die
);
12928 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12929 Use modified_type_die instead.
12930 We keep this code here just in case these types of DIEs may be needed to
12931 represent certain things in other languages (e.g. Pascal) someday. */
12934 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
12937 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
12939 equate_type_number_to_die (type
, ptr_die
);
12940 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12941 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12944 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
12945 Use modified_type_die instead.
12946 We keep this code here just in case these types of DIEs may be needed to
12947 represent certain things in other languages (e.g. Pascal) someday. */
12950 gen_reference_type_die (tree type
, dw_die_ref context_die
)
12953 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
12955 equate_type_number_to_die (type
, ref_die
);
12956 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
12957 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
12961 /* Generate a DIE for a pointer to a member type. */
12964 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
12967 = new_die (DW_TAG_ptr_to_member_type
,
12968 scope_die_for (type
, context_die
), type
);
12970 equate_type_number_to_die (type
, ptr_die
);
12971 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
12972 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
12973 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
12976 /* Generate the DIE for the compilation unit. */
12979 gen_compile_unit_die (const char *filename
)
12982 char producer
[250];
12983 const char *language_string
= lang_hooks
.name
;
12986 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
12990 add_name_attribute (die
, filename
);
12991 /* Don't add cwd for <built-in>. */
12992 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
12993 add_comp_dir_attribute (die
);
12996 sprintf (producer
, "%s %s", language_string
, version_string
);
12998 #ifdef MIPS_DEBUGGING_INFO
12999 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
13000 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
13001 not appear in the producer string, the debugger reaches the conclusion
13002 that the object file is stripped and has no debugging information.
13003 To get the MIPS/SGI debugger to believe that there is debugging
13004 information in the object file, we add a -g to the producer string. */
13005 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13006 strcat (producer
, " -g");
13009 add_AT_string (die
, DW_AT_producer
, producer
);
13011 if (strcmp (language_string
, "GNU C++") == 0)
13012 language
= DW_LANG_C_plus_plus
;
13013 else if (strcmp (language_string
, "GNU Ada") == 0)
13014 language
= DW_LANG_Ada95
;
13015 else if (strcmp (language_string
, "GNU F77") == 0)
13016 language
= DW_LANG_Fortran77
;
13017 else if (strcmp (language_string
, "GNU F95") == 0)
13018 language
= DW_LANG_Fortran95
;
13019 else if (strcmp (language_string
, "GNU Pascal") == 0)
13020 language
= DW_LANG_Pascal83
;
13021 else if (strcmp (language_string
, "GNU Java") == 0)
13022 language
= DW_LANG_Java
;
13023 else if (strcmp (language_string
, "GNU Objective-C") == 0)
13024 language
= DW_LANG_ObjC
;
13025 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
13026 language
= DW_LANG_ObjC_plus_plus
;
13028 language
= DW_LANG_C89
;
13030 add_AT_unsigned (die
, DW_AT_language
, language
);
13034 /* Generate the DIE for a base class. */
13037 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
13039 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
13041 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
13042 add_data_member_location_attribute (die
, binfo
);
13044 if (BINFO_VIRTUAL_P (binfo
))
13045 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
13047 if (access
== access_public_node
)
13048 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
13049 else if (access
== access_protected_node
)
13050 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
13053 /* Generate a DIE for a class member. */
13056 gen_member_die (tree type
, dw_die_ref context_die
)
13059 tree binfo
= TYPE_BINFO (type
);
13062 /* If this is not an incomplete type, output descriptions of each of its
13063 members. Note that as we output the DIEs necessary to represent the
13064 members of this record or union type, we will also be trying to output
13065 DIEs to represent the *types* of those members. However the `type'
13066 function (above) will specifically avoid generating type DIEs for member
13067 types *within* the list of member DIEs for this (containing) type except
13068 for those types (of members) which are explicitly marked as also being
13069 members of this (containing) type themselves. The g++ front- end can
13070 force any given type to be treated as a member of some other (containing)
13071 type by setting the TYPE_CONTEXT of the given (member) type to point to
13072 the TREE node representing the appropriate (containing) type. */
13074 /* First output info about the base classes. */
13077 VEC(tree
,gc
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
13081 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
13082 gen_inheritance_die (base
,
13083 (accesses
? VEC_index (tree
, accesses
, i
)
13084 : access_public_node
), context_die
);
13087 /* Now output info about the data members and type members. */
13088 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
13090 /* If we thought we were generating minimal debug info for TYPE
13091 and then changed our minds, some of the member declarations
13092 may have already been defined. Don't define them again, but
13093 do put them in the right order. */
13095 child
= lookup_decl_die (member
);
13097 splice_child_die (context_die
, child
);
13099 gen_decl_die (member
, context_die
);
13102 /* Now output info about the function members (if any). */
13103 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
13105 /* Don't include clones in the member list. */
13106 if (DECL_ABSTRACT_ORIGIN (member
))
13109 child
= lookup_decl_die (member
);
13111 splice_child_die (context_die
, child
);
13113 gen_decl_die (member
, context_die
);
13117 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
13118 is set, we pretend that the type was never defined, so we only get the
13119 member DIEs needed by later specification DIEs. */
13122 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
13123 enum debug_info_usage usage
)
13125 dw_die_ref type_die
= lookup_type_die (type
);
13126 dw_die_ref scope_die
= 0;
13128 int complete
= (TYPE_SIZE (type
)
13129 && (! TYPE_STUB_DECL (type
)
13130 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
13131 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
13132 complete
= complete
&& should_emit_struct_debug (type
, usage
);
13134 if (type_die
&& ! complete
)
13137 if (TYPE_CONTEXT (type
) != NULL_TREE
13138 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
13139 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
13142 scope_die
= scope_die_for (type
, context_die
);
13144 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
13145 /* First occurrence of type or toplevel definition of nested class. */
13147 dw_die_ref old_die
= type_die
;
13149 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
13150 ? record_type_tag (type
) : DW_TAG_union_type
,
13152 equate_type_number_to_die (type
, type_die
);
13154 add_AT_specification (type_die
, old_die
);
13156 add_name_attribute (type_die
, type_tag (type
));
13159 remove_AT (type_die
, DW_AT_declaration
);
13161 /* If this type has been completed, then give it a byte_size attribute and
13162 then give a list of members. */
13163 if (complete
&& !ns_decl
)
13165 /* Prevent infinite recursion in cases where the type of some member of
13166 this type is expressed in terms of this type itself. */
13167 TREE_ASM_WRITTEN (type
) = 1;
13168 add_byte_size_attribute (type_die
, type
);
13169 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
13170 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
13172 /* If the first reference to this type was as the return type of an
13173 inline function, then it may not have a parent. Fix this now. */
13174 if (type_die
->die_parent
== NULL
)
13175 add_child_die (scope_die
, type_die
);
13177 push_decl_scope (type
);
13178 gen_member_die (type
, type_die
);
13181 /* GNU extension: Record what type our vtable lives in. */
13182 if (TYPE_VFIELD (type
))
13184 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
13186 gen_type_die (vtype
, context_die
);
13187 add_AT_die_ref (type_die
, DW_AT_containing_type
,
13188 lookup_type_die (vtype
));
13193 add_AT_flag (type_die
, DW_AT_declaration
, 1);
13195 /* We don't need to do this for function-local types. */
13196 if (TYPE_STUB_DECL (type
)
13197 && ! decl_function_context (TYPE_STUB_DECL (type
)))
13198 VEC_safe_push (tree
, gc
, incomplete_types
, type
);
13201 if (get_AT (type_die
, DW_AT_name
))
13202 add_pubtype (type
, type_die
);
13205 /* Generate a DIE for a subroutine _type_. */
13208 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
13210 tree return_type
= TREE_TYPE (type
);
13211 dw_die_ref subr_die
13212 = new_die (DW_TAG_subroutine_type
,
13213 scope_die_for (type
, context_die
), type
);
13215 equate_type_number_to_die (type
, subr_die
);
13216 add_prototyped_attribute (subr_die
, type
);
13217 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
13218 gen_formal_types_die (type
, subr_die
);
13220 if (get_AT (subr_die
, DW_AT_name
))
13221 add_pubtype (type
, subr_die
);
13224 /* Generate a DIE for a type definition. */
13227 gen_typedef_die (tree decl
, dw_die_ref context_die
)
13229 dw_die_ref type_die
;
13232 if (TREE_ASM_WRITTEN (decl
))
13235 TREE_ASM_WRITTEN (decl
) = 1;
13236 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
13237 origin
= decl_ultimate_origin (decl
);
13238 if (origin
!= NULL
)
13239 add_abstract_origin_attribute (type_die
, origin
);
13244 add_name_and_src_coords_attributes (type_die
, decl
);
13245 if (DECL_ORIGINAL_TYPE (decl
))
13247 type
= DECL_ORIGINAL_TYPE (decl
);
13249 gcc_assert (type
!= TREE_TYPE (decl
));
13250 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
13253 type
= TREE_TYPE (decl
);
13255 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
13256 TREE_THIS_VOLATILE (decl
), context_die
);
13259 if (DECL_ABSTRACT (decl
))
13260 equate_decl_number_to_die (decl
, type_die
);
13262 if (get_AT (type_die
, DW_AT_name
))
13263 add_pubtype (decl
, type_die
);
13266 /* Generate a type description DIE. */
13269 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
13270 enum debug_info_usage usage
)
13273 struct array_descr_info info
;
13275 if (type
== NULL_TREE
|| type
== error_mark_node
)
13278 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
13279 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
13281 if (TREE_ASM_WRITTEN (type
))
13284 /* Prevent broken recursion; we can't hand off to the same type. */
13285 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
13287 TREE_ASM_WRITTEN (type
) = 1;
13288 gen_decl_die (TYPE_NAME (type
), context_die
);
13292 /* If this is an array type with hidden descriptor, handle it first. */
13293 if (!TREE_ASM_WRITTEN (type
)
13294 && lang_hooks
.types
.get_array_descr_info
13295 && lang_hooks
.types
.get_array_descr_info (type
, &info
))
13297 gen_descr_array_type_die (type
, &info
, context_die
);
13298 TREE_ASM_WRITTEN (type
) = 1;
13302 /* We are going to output a DIE to represent the unqualified version
13303 of this type (i.e. without any const or volatile qualifiers) so
13304 get the main variant (i.e. the unqualified version) of this type
13305 now. (Vectors are special because the debugging info is in the
13306 cloned type itself). */
13307 if (TREE_CODE (type
) != VECTOR_TYPE
)
13308 type
= type_main_variant (type
);
13310 if (TREE_ASM_WRITTEN (type
))
13313 switch (TREE_CODE (type
))
13319 case REFERENCE_TYPE
:
13320 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
13321 ensures that the gen_type_die recursion will terminate even if the
13322 type is recursive. Recursive types are possible in Ada. */
13323 /* ??? We could perhaps do this for all types before the switch
13325 TREE_ASM_WRITTEN (type
) = 1;
13327 /* For these types, all that is required is that we output a DIE (or a
13328 set of DIEs) to represent the "basis" type. */
13329 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13330 DINFO_USAGE_IND_USE
);
13334 /* This code is used for C++ pointer-to-data-member types.
13335 Output a description of the relevant class type. */
13336 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
13337 DINFO_USAGE_IND_USE
);
13339 /* Output a description of the type of the object pointed to. */
13340 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13341 DINFO_USAGE_IND_USE
);
13343 /* Now output a DIE to represent this pointer-to-data-member type
13345 gen_ptr_to_mbr_type_die (type
, context_die
);
13348 case FUNCTION_TYPE
:
13349 /* Force out return type (in case it wasn't forced out already). */
13350 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13351 DINFO_USAGE_DIR_USE
);
13352 gen_subroutine_type_die (type
, context_die
);
13356 /* Force out return type (in case it wasn't forced out already). */
13357 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
13358 DINFO_USAGE_DIR_USE
);
13359 gen_subroutine_type_die (type
, context_die
);
13363 gen_array_type_die (type
, context_die
);
13367 gen_array_type_die (type
, context_die
);
13370 case ENUMERAL_TYPE
:
13373 case QUAL_UNION_TYPE
:
13374 /* If this is a nested type whose containing class hasn't been written
13375 out yet, writing it out will cover this one, too. This does not apply
13376 to instantiations of member class templates; they need to be added to
13377 the containing class as they are generated. FIXME: This hurts the
13378 idea of combining type decls from multiple TUs, since we can't predict
13379 what set of template instantiations we'll get. */
13380 if (TYPE_CONTEXT (type
)
13381 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
13382 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
13384 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
13386 if (TREE_ASM_WRITTEN (type
))
13389 /* If that failed, attach ourselves to the stub. */
13390 push_decl_scope (TYPE_CONTEXT (type
));
13391 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
13396 declare_in_namespace (type
, context_die
);
13400 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
13402 /* This might have been written out by the call to
13403 declare_in_namespace. */
13404 if (!TREE_ASM_WRITTEN (type
))
13405 gen_enumeration_type_die (type
, context_die
);
13408 gen_struct_or_union_type_die (type
, context_die
, usage
);
13413 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
13414 it up if it is ever completed. gen_*_type_die will set it for us
13415 when appropriate. */
13421 case FIXED_POINT_TYPE
:
13424 /* No DIEs needed for fundamental types. */
13428 /* No Dwarf representation currently defined. */
13432 gcc_unreachable ();
13435 TREE_ASM_WRITTEN (type
) = 1;
13439 gen_type_die (tree type
, dw_die_ref context_die
)
13441 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
13444 /* Generate a DIE for a tagged type instantiation. */
13447 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
13449 if (type
== NULL_TREE
|| type
== error_mark_node
)
13452 /* We are going to output a DIE to represent the unqualified version of
13453 this type (i.e. without any const or volatile qualifiers) so make sure
13454 that we have the main variant (i.e. the unqualified version) of this
13456 gcc_assert (type
== type_main_variant (type
));
13458 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
13459 an instance of an unresolved type. */
13461 switch (TREE_CODE (type
))
13466 case ENUMERAL_TYPE
:
13467 gen_inlined_enumeration_type_die (type
, context_die
);
13471 gen_inlined_structure_type_die (type
, context_die
);
13475 case QUAL_UNION_TYPE
:
13476 gen_inlined_union_type_die (type
, context_die
);
13480 gcc_unreachable ();
13484 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
13485 things which are local to the given block. */
13488 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
13490 int must_output_die
= 0;
13493 enum tree_code origin_code
;
13495 /* Ignore blocks that are NULL. */
13496 if (stmt
== NULL_TREE
)
13499 /* If the block is one fragment of a non-contiguous block, do not
13500 process the variables, since they will have been done by the
13501 origin block. Do process subblocks. */
13502 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
13506 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
13507 gen_block_die (sub
, context_die
, depth
+ 1);
13512 /* Determine the "ultimate origin" of this block. This block may be an
13513 inlined instance of an inlined instance of inline function, so we have
13514 to trace all of the way back through the origin chain to find out what
13515 sort of node actually served as the original seed for the creation of
13516 the current block. */
13517 origin
= block_ultimate_origin (stmt
);
13518 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
13520 /* Determine if we need to output any Dwarf DIEs at all to represent this
13522 if (origin_code
== FUNCTION_DECL
)
13523 /* The outer scopes for inlinings *must* always be represented. We
13524 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
13525 must_output_die
= 1;
13528 /* In the case where the current block represents an inlining of the
13529 "body block" of an inline function, we must *NOT* output any DIE for
13530 this block because we have already output a DIE to represent the whole
13531 inlined function scope and the "body block" of any function doesn't
13532 really represent a different scope according to ANSI C rules. So we
13533 check here to make sure that this block does not represent a "body
13534 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
13535 if (! is_body_block (origin
? origin
: stmt
))
13537 /* Determine if this block directly contains any "significant"
13538 local declarations which we will need to output DIEs for. */
13539 if (debug_info_level
> DINFO_LEVEL_TERSE
)
13540 /* We are not in terse mode so *any* local declaration counts
13541 as being a "significant" one. */
13542 must_output_die
= (BLOCK_VARS (stmt
) != NULL
13543 && (TREE_USED (stmt
)
13544 || TREE_ASM_WRITTEN (stmt
)
13545 || BLOCK_ABSTRACT (stmt
)));
13547 /* We are in terse mode, so only local (nested) function
13548 definitions count as "significant" local declarations. */
13549 for (decl
= BLOCK_VARS (stmt
);
13550 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
13551 if (TREE_CODE (decl
) == FUNCTION_DECL
13552 && DECL_INITIAL (decl
))
13554 must_output_die
= 1;
13560 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
13561 DIE for any block which contains no significant local declarations at
13562 all. Rather, in such cases we just call `decls_for_scope' so that any
13563 needed Dwarf info for any sub-blocks will get properly generated. Note
13564 that in terse mode, our definition of what constitutes a "significant"
13565 local declaration gets restricted to include only inlined function
13566 instances and local (nested) function definitions. */
13567 if (must_output_die
)
13569 if (origin_code
== FUNCTION_DECL
)
13570 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
13572 gen_lexical_block_die (stmt
, context_die
, depth
);
13575 decls_for_scope (stmt
, context_die
, depth
);
13578 /* Generate all of the decls declared within a given scope and (recursively)
13579 all of its sub-blocks. */
13582 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
13587 /* Ignore NULL blocks. */
13588 if (stmt
== NULL_TREE
)
13591 if (TREE_USED (stmt
))
13593 /* Output the DIEs to represent all of the data objects and typedefs
13594 declared directly within this block but not within any nested
13595 sub-blocks. Also, nested function and tag DIEs have been
13596 generated with a parent of NULL; fix that up now. */
13597 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
13601 if (TREE_CODE (decl
) == FUNCTION_DECL
)
13602 die
= lookup_decl_die (decl
);
13603 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
13604 die
= lookup_type_die (TREE_TYPE (decl
));
13608 if (die
!= NULL
&& die
->die_parent
== NULL
)
13609 add_child_die (context_die
, die
);
13610 /* Do not produce debug information for static variables since
13611 these might be optimized out. We are called for these later
13612 in varpool_analyze_pending_decls. */
13613 if (TREE_CODE (decl
) == VAR_DECL
&& TREE_STATIC (decl
))
13616 gen_decl_die (decl
, context_die
);
13620 /* If we're at -g1, we're not interested in subblocks. */
13621 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13624 /* Output the DIEs to represent all sub-blocks (and the items declared
13625 therein) of this block. */
13626 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
13628 subblocks
= BLOCK_CHAIN (subblocks
))
13629 gen_block_die (subblocks
, context_die
, depth
+ 1);
13632 /* Is this a typedef we can avoid emitting? */
13635 is_redundant_typedef (const_tree decl
)
13637 if (TYPE_DECL_IS_STUB (decl
))
13640 if (DECL_ARTIFICIAL (decl
)
13641 && DECL_CONTEXT (decl
)
13642 && is_tagged_type (DECL_CONTEXT (decl
))
13643 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
13644 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
13645 /* Also ignore the artificial member typedef for the class name. */
13651 /* Returns the DIE for decl. A DIE will always be returned. */
13654 force_decl_die (tree decl
)
13656 dw_die_ref decl_die
;
13657 unsigned saved_external_flag
;
13658 tree save_fn
= NULL_TREE
;
13659 decl_die
= lookup_decl_die (decl
);
13662 dw_die_ref context_die
;
13663 tree decl_context
= DECL_CONTEXT (decl
);
13666 /* Find die that represents this context. */
13667 if (TYPE_P (decl_context
))
13668 context_die
= force_type_die (decl_context
);
13670 context_die
= force_decl_die (decl_context
);
13673 context_die
= comp_unit_die
;
13675 decl_die
= lookup_decl_die (decl
);
13679 switch (TREE_CODE (decl
))
13681 case FUNCTION_DECL
:
13682 /* Clear current_function_decl, so that gen_subprogram_die thinks
13683 that this is a declaration. At this point, we just want to force
13684 declaration die. */
13685 save_fn
= current_function_decl
;
13686 current_function_decl
= NULL_TREE
;
13687 gen_subprogram_die (decl
, context_die
);
13688 current_function_decl
= save_fn
;
13692 /* Set external flag to force declaration die. Restore it after
13693 gen_decl_die() call. */
13694 saved_external_flag
= DECL_EXTERNAL (decl
);
13695 DECL_EXTERNAL (decl
) = 1;
13696 gen_decl_die (decl
, context_die
);
13697 DECL_EXTERNAL (decl
) = saved_external_flag
;
13700 case NAMESPACE_DECL
:
13701 dwarf2out_decl (decl
);
13705 gcc_unreachable ();
13708 /* We should be able to find the DIE now. */
13710 decl_die
= lookup_decl_die (decl
);
13711 gcc_assert (decl_die
);
13717 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
13718 always returned. */
13721 force_type_die (tree type
)
13723 dw_die_ref type_die
;
13725 type_die
= lookup_type_die (type
);
13728 dw_die_ref context_die
;
13729 if (TYPE_CONTEXT (type
))
13731 if (TYPE_P (TYPE_CONTEXT (type
)))
13732 context_die
= force_type_die (TYPE_CONTEXT (type
));
13734 context_die
= force_decl_die (TYPE_CONTEXT (type
));
13737 context_die
= comp_unit_die
;
13739 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
13740 TYPE_VOLATILE (type
), context_die
);
13741 gcc_assert (type_die
);
13746 /* Force out any required namespaces to be able to output DECL,
13747 and return the new context_die for it, if it's changed. */
13750 setup_namespace_context (tree thing
, dw_die_ref context_die
)
13752 tree context
= (DECL_P (thing
)
13753 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
13754 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
13755 /* Force out the namespace. */
13756 context_die
= force_decl_die (context
);
13758 return context_die
;
13761 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
13762 type) within its namespace, if appropriate.
13764 For compatibility with older debuggers, namespace DIEs only contain
13765 declarations; all definitions are emitted at CU scope. */
13768 declare_in_namespace (tree thing
, dw_die_ref context_die
)
13770 dw_die_ref ns_context
;
13772 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13775 /* If this decl is from an inlined function, then don't try to emit it in its
13776 namespace, as we will get confused. It would have already been emitted
13777 when the abstract instance of the inline function was emitted anyways. */
13778 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
13781 ns_context
= setup_namespace_context (thing
, context_die
);
13783 if (ns_context
!= context_die
)
13785 if (DECL_P (thing
))
13786 gen_decl_die (thing
, ns_context
);
13788 gen_type_die (thing
, ns_context
);
13792 /* Generate a DIE for a namespace or namespace alias. */
13795 gen_namespace_die (tree decl
)
13797 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
13799 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
13800 they are an alias of. */
13801 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
13803 /* Output a real namespace. */
13804 dw_die_ref namespace_die
13805 = new_die (DW_TAG_namespace
, context_die
, decl
);
13806 add_name_and_src_coords_attributes (namespace_die
, decl
);
13807 equate_decl_number_to_die (decl
, namespace_die
);
13811 /* Output a namespace alias. */
13813 /* Force out the namespace we are an alias of, if necessary. */
13814 dw_die_ref origin_die
13815 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
13817 /* Now create the namespace alias DIE. */
13818 dw_die_ref namespace_die
13819 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
13820 add_name_and_src_coords_attributes (namespace_die
, decl
);
13821 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
13822 equate_decl_number_to_die (decl
, namespace_die
);
13826 /* Generate Dwarf debug information for a decl described by DECL. */
13829 gen_decl_die (tree decl
, dw_die_ref context_die
)
13833 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
13836 switch (TREE_CODE (decl
))
13842 /* The individual enumerators of an enum type get output when we output
13843 the Dwarf representation of the relevant enum type itself. */
13846 case FUNCTION_DECL
:
13847 /* Don't output any DIEs to represent mere function declarations,
13848 unless they are class members or explicit block externs. */
13849 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
13850 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
13855 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
13856 on local redeclarations of global functions. That seems broken. */
13857 if (current_function_decl
!= decl
)
13858 /* This is only a declaration. */;
13861 /* If we're emitting a clone, emit info for the abstract instance. */
13862 if (DECL_ORIGIN (decl
) != decl
)
13863 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
13865 /* If we're emitting an out-of-line copy of an inline function,
13866 emit info for the abstract instance and set up to refer to it. */
13867 else if (cgraph_function_possibly_inlined_p (decl
)
13868 && ! DECL_ABSTRACT (decl
)
13869 && ! class_or_namespace_scope_p (context_die
)
13870 /* dwarf2out_abstract_function won't emit a die if this is just
13871 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
13872 that case, because that works only if we have a die. */
13873 && DECL_INITIAL (decl
) != NULL_TREE
)
13875 dwarf2out_abstract_function (decl
);
13876 set_decl_origin_self (decl
);
13879 /* Otherwise we're emitting the primary DIE for this decl. */
13880 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
13882 /* Before we describe the FUNCTION_DECL itself, make sure that we
13883 have described its return type. */
13884 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
13886 /* And its virtual context. */
13887 if (DECL_VINDEX (decl
) != NULL_TREE
)
13888 gen_type_die (DECL_CONTEXT (decl
), context_die
);
13890 /* And its containing type. */
13891 origin
= decl_class_context (decl
);
13892 if (origin
!= NULL_TREE
)
13893 gen_type_die_for_member (origin
, decl
, context_die
);
13895 /* And its containing namespace. */
13896 declare_in_namespace (decl
, context_die
);
13899 /* Now output a DIE to represent the function itself. */
13900 gen_subprogram_die (decl
, context_die
);
13904 /* If we are in terse mode, don't generate any DIEs to represent any
13905 actual typedefs. */
13906 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13909 /* In the special case of a TYPE_DECL node representing the declaration
13910 of some type tag, if the given TYPE_DECL is marked as having been
13911 instantiated from some other (original) TYPE_DECL node (e.g. one which
13912 was generated within the original definition of an inline function) we
13913 have to generate a special (abbreviated) DW_TAG_structure_type,
13914 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
13915 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
13916 && is_tagged_type (TREE_TYPE (decl
)))
13918 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
13922 if (is_redundant_typedef (decl
))
13923 gen_type_die (TREE_TYPE (decl
), context_die
);
13925 /* Output a DIE to represent the typedef itself. */
13926 gen_typedef_die (decl
, context_die
);
13930 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13931 gen_label_die (decl
, context_die
);
13936 /* If we are in terse mode, don't generate any DIEs to represent any
13937 variable declarations or definitions. */
13938 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13941 /* Output any DIEs that are needed to specify the type of this data
13943 if (TREE_CODE (decl
) == RESULT_DECL
&& DECL_BY_REFERENCE (decl
))
13944 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
13946 gen_type_die (TREE_TYPE (decl
), context_die
);
13948 /* And its containing type. */
13949 origin
= decl_class_context (decl
);
13950 if (origin
!= NULL_TREE
)
13951 gen_type_die_for_member (origin
, decl
, context_die
);
13953 /* And its containing namespace. */
13954 declare_in_namespace (decl
, context_die
);
13956 /* Now output the DIE to represent the data object itself. This gets
13957 complicated because of the possibility that the VAR_DECL really
13958 represents an inlined instance of a formal parameter for an inline
13960 origin
= decl_ultimate_origin (decl
);
13961 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
13962 gen_formal_parameter_die (decl
, context_die
);
13964 gen_variable_die (decl
, context_die
);
13968 /* Ignore the nameless fields that are used to skip bits but handle C++
13969 anonymous unions and structs. */
13970 if (DECL_NAME (decl
) != NULL_TREE
13971 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
13972 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
13974 gen_type_die (member_declared_type (decl
), context_die
);
13975 gen_field_die (decl
, context_die
);
13980 if (DECL_BY_REFERENCE (decl
))
13981 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
13983 gen_type_die (TREE_TYPE (decl
), context_die
);
13984 gen_formal_parameter_die (decl
, context_die
);
13987 case NAMESPACE_DECL
:
13988 gen_namespace_die (decl
);
13992 /* Probably some frontend-internal decl. Assume we don't care. */
13993 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
13998 /* Output debug information for global decl DECL. Called from toplev.c after
13999 compilation proper has finished. */
14002 dwarf2out_global_decl (tree decl
)
14004 /* Output DWARF2 information for file-scope tentative data object
14005 declarations, file-scope (extern) function declarations (which had no
14006 corresponding body) and file-scope tagged type declarations and
14007 definitions which have not yet been forced out. */
14008 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
14009 dwarf2out_decl (decl
);
14012 /* Output debug information for type decl DECL. Called from toplev.c
14013 and from language front ends (to record built-in types). */
14015 dwarf2out_type_decl (tree decl
, int local
)
14018 dwarf2out_decl (decl
);
14021 /* Output debug information for imported module or decl. */
14024 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
14026 dw_die_ref imported_die
, at_import_die
;
14027 dw_die_ref scope_die
;
14028 expanded_location xloc
;
14030 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14035 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
14036 We need decl DIE for reference and scope die. First, get DIE for the decl
14039 /* Get the scope die for decl context. Use comp_unit_die for global module
14040 or decl. If die is not found for non globals, force new die. */
14042 scope_die
= comp_unit_die
;
14043 else if (TYPE_P (context
))
14045 if (!should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
14047 scope_die
= force_type_die (context
);
14050 scope_die
= force_decl_die (context
);
14052 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
14053 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
14055 if (is_base_type (TREE_TYPE (decl
)))
14056 at_import_die
= base_type_die (TREE_TYPE (decl
));
14058 at_import_die
= force_type_die (TREE_TYPE (decl
));
14062 at_import_die
= lookup_decl_die (decl
);
14063 if (!at_import_die
)
14065 /* If we're trying to avoid duplicate debug info, we may not have
14066 emitted the member decl for this field. Emit it now. */
14067 if (TREE_CODE (decl
) == FIELD_DECL
)
14069 tree type
= DECL_CONTEXT (decl
);
14070 dw_die_ref type_context_die
;
14072 if (TYPE_CONTEXT (type
))
14073 if (TYPE_P (TYPE_CONTEXT (type
)))
14075 if (!should_emit_struct_debug (TYPE_CONTEXT (type
),
14076 DINFO_USAGE_DIR_USE
))
14078 type_context_die
= force_type_die (TYPE_CONTEXT (type
));
14081 type_context_die
= force_decl_die (TYPE_CONTEXT (type
));
14083 type_context_die
= comp_unit_die
;
14084 gen_type_die_for_member (type
, decl
, type_context_die
);
14086 at_import_die
= force_decl_die (decl
);
14090 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
14091 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
14092 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
14094 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
14096 xloc
= expand_location (input_location
);
14097 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
14098 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
14099 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
14102 /* Write the debugging output for DECL. */
14105 dwarf2out_decl (tree decl
)
14107 dw_die_ref context_die
= comp_unit_die
;
14109 switch (TREE_CODE (decl
))
14114 case FUNCTION_DECL
:
14115 /* What we would really like to do here is to filter out all mere
14116 file-scope declarations of file-scope functions which are never
14117 referenced later within this translation unit (and keep all of ones
14118 that *are* referenced later on) but we aren't clairvoyant, so we have
14119 no idea which functions will be referenced in the future (i.e. later
14120 on within the current translation unit). So here we just ignore all
14121 file-scope function declarations which are not also definitions. If
14122 and when the debugger needs to know something about these functions,
14123 it will have to hunt around and find the DWARF information associated
14124 with the definition of the function.
14126 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
14127 nodes represent definitions and which ones represent mere
14128 declarations. We have to check DECL_INITIAL instead. That's because
14129 the C front-end supports some weird semantics for "extern inline"
14130 function definitions. These can get inlined within the current
14131 translation unit (and thus, we need to generate Dwarf info for their
14132 abstract instances so that the Dwarf info for the concrete inlined
14133 instances can have something to refer to) but the compiler never
14134 generates any out-of-lines instances of such things (despite the fact
14135 that they *are* definitions).
14137 The important point is that the C front-end marks these "extern
14138 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
14139 them anyway. Note that the C++ front-end also plays some similar games
14140 for inline function definitions appearing within include files which
14141 also contain `#pragma interface' pragmas. */
14142 if (DECL_INITIAL (decl
) == NULL_TREE
)
14145 /* If we're a nested function, initially use a parent of NULL; if we're
14146 a plain function, this will be fixed up in decls_for_scope. If
14147 we're a method, it will be ignored, since we already have a DIE. */
14148 if (decl_function_context (decl
)
14149 /* But if we're in terse mode, we don't care about scope. */
14150 && debug_info_level
> DINFO_LEVEL_TERSE
)
14151 context_die
= NULL
;
14155 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
14156 declaration and if the declaration was never even referenced from
14157 within this entire compilation unit. We suppress these DIEs in
14158 order to save space in the .debug section (by eliminating entries
14159 which are probably useless). Note that we must not suppress
14160 block-local extern declarations (whether used or not) because that
14161 would screw-up the debugger's name lookup mechanism and cause it to
14162 miss things which really ought to be in scope at a given point. */
14163 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
14166 /* For local statics lookup proper context die. */
14167 if (TREE_STATIC (decl
) && decl_function_context (decl
))
14168 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
14170 /* If we are in terse mode, don't generate any DIEs to represent any
14171 variable declarations or definitions. */
14172 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14176 case NAMESPACE_DECL
:
14177 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14179 if (lookup_decl_die (decl
) != NULL
)
14184 /* Don't emit stubs for types unless they are needed by other DIEs. */
14185 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
14188 /* Don't bother trying to generate any DIEs to represent any of the
14189 normal built-in types for the language we are compiling. */
14190 if (DECL_IS_BUILTIN (decl
))
14192 /* OK, we need to generate one for `bool' so GDB knows what type
14193 comparisons have. */
14195 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
14196 && ! DECL_IGNORED_P (decl
))
14197 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
14202 /* If we are in terse mode, don't generate any DIEs for types. */
14203 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
14206 /* If we're a function-scope tag, initially use a parent of NULL;
14207 this will be fixed up in decls_for_scope. */
14208 if (decl_function_context (decl
))
14209 context_die
= NULL
;
14217 gen_decl_die (decl
, context_die
);
14220 /* Output a marker (i.e. a label) for the beginning of the generated code for
14221 a lexical block. */
14224 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
14225 unsigned int blocknum
)
14227 switch_to_section (current_function_section ());
14228 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
14231 /* Output a marker (i.e. a label) for the end of the generated code for a
14235 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
14237 switch_to_section (current_function_section ());
14238 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
14241 /* Returns nonzero if it is appropriate not to emit any debugging
14242 information for BLOCK, because it doesn't contain any instructions.
14244 Don't allow this for blocks with nested functions or local classes
14245 as we would end up with orphans, and in the presence of scheduling
14246 we may end up calling them anyway. */
14249 dwarf2out_ignore_block (const_tree block
)
14253 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
14254 if (TREE_CODE (decl
) == FUNCTION_DECL
14255 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
14261 /* Hash table routines for file_hash. */
14264 file_table_eq (const void *p1_p
, const void *p2_p
)
14266 const struct dwarf_file_data
* p1
= p1_p
;
14267 const char * p2
= p2_p
;
14268 return strcmp (p1
->filename
, p2
) == 0;
14272 file_table_hash (const void *p_p
)
14274 const struct dwarf_file_data
* p
= p_p
;
14275 return htab_hash_string (p
->filename
);
14278 /* Lookup FILE_NAME (in the list of filenames that we know about here in
14279 dwarf2out.c) and return its "index". The index of each (known) filename is
14280 just a unique number which is associated with only that one filename. We
14281 need such numbers for the sake of generating labels (in the .debug_sfnames
14282 section) and references to those files numbers (in the .debug_srcinfo
14283 and.debug_macinfo sections). If the filename given as an argument is not
14284 found in our current list, add it to the list and assign it the next
14285 available unique index number. In order to speed up searches, we remember
14286 the index of the filename was looked up last. This handles the majority of
14289 static struct dwarf_file_data
*
14290 lookup_filename (const char *file_name
)
14293 struct dwarf_file_data
* created
;
14295 /* Check to see if the file name that was searched on the previous
14296 call matches this file name. If so, return the index. */
14297 if (file_table_last_lookup
14298 && (file_name
== file_table_last_lookup
->filename
14299 || strcmp (file_table_last_lookup
->filename
, file_name
) == 0))
14300 return file_table_last_lookup
;
14302 /* Didn't match the previous lookup, search the table. */
14303 slot
= htab_find_slot_with_hash (file_table
, file_name
,
14304 htab_hash_string (file_name
), INSERT
);
14308 created
= ggc_alloc (sizeof (struct dwarf_file_data
));
14309 created
->filename
= file_name
;
14310 created
->emitted_number
= 0;
14315 /* If the assembler will construct the file table, then translate the compiler
14316 internal file table number into the assembler file table number, and emit
14317 a .file directive if we haven't already emitted one yet. The file table
14318 numbers are different because we prune debug info for unused variables and
14319 types, which may include filenames. */
14322 maybe_emit_file (struct dwarf_file_data
* fd
)
14324 if (! fd
->emitted_number
)
14326 if (last_emitted_file
)
14327 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
14329 fd
->emitted_number
= 1;
14330 last_emitted_file
= fd
;
14332 if (DWARF2_ASM_LINE_DEBUG_INFO
)
14334 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
14335 output_quoted_string (asm_out_file
,
14336 remap_debug_filename (fd
->filename
));
14337 fputc ('\n', asm_out_file
);
14341 return fd
->emitted_number
;
14344 /* Called by the final INSN scan whenever we see a var location. We
14345 use it to drop labels in the right places, and throw the location in
14346 our lookup table. */
14349 dwarf2out_var_location (rtx loc_note
)
14351 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
14352 struct var_loc_node
*newloc
;
14354 static rtx last_insn
;
14355 static const char *last_label
;
14358 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
14360 prev_insn
= PREV_INSN (loc_note
);
14362 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
14363 /* If the insn we processed last time is the previous insn
14364 and it is also a var location note, use the label we emitted
14366 if (last_insn
!= NULL_RTX
14367 && last_insn
== prev_insn
14368 && NOTE_P (prev_insn
)
14369 && NOTE_KIND (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
14371 newloc
->label
= last_label
;
14375 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
14376 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
14378 newloc
->label
= ggc_strdup (loclabel
);
14380 newloc
->var_loc_note
= loc_note
;
14381 newloc
->next
= NULL
;
14383 if (cfun
&& in_cold_section_p
)
14384 newloc
->section_label
= cfun
->cold_section_label
;
14386 newloc
->section_label
= text_section_label
;
14388 last_insn
= loc_note
;
14389 last_label
= newloc
->label
;
14390 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
14391 add_var_loc_to_decl (decl
, newloc
);
14394 /* We need to reset the locations at the beginning of each
14395 function. We can't do this in the end_function hook, because the
14396 declarations that use the locations won't have been output when
14397 that hook is called. Also compute have_multiple_function_sections here. */
14400 dwarf2out_begin_function (tree fun
)
14402 htab_empty (decl_loc_table
);
14404 if (function_section (fun
) != text_section
)
14405 have_multiple_function_sections
= true;
14407 dwarf2out_note_section_used ();
14410 /* Output a label to mark the beginning of a source code line entry
14411 and record information relating to this source line, in
14412 'line_info_table' for later output of the .debug_line section. */
14415 dwarf2out_source_line (unsigned int line
, const char *filename
)
14417 if (debug_info_level
>= DINFO_LEVEL_NORMAL
14420 int file_num
= maybe_emit_file (lookup_filename (filename
));
14422 switch_to_section (current_function_section ());
14424 /* If requested, emit something human-readable. */
14425 if (flag_debug_asm
)
14426 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
14429 if (DWARF2_ASM_LINE_DEBUG_INFO
)
14431 /* Emit the .loc directive understood by GNU as. */
14432 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
14434 /* Indicate that line number info exists. */
14435 line_info_table_in_use
++;
14437 else if (function_section (current_function_decl
) != text_section
)
14439 dw_separate_line_info_ref line_info
;
14440 targetm
.asm_out
.internal_label (asm_out_file
,
14441 SEPARATE_LINE_CODE_LABEL
,
14442 separate_line_info_table_in_use
);
14444 /* Expand the line info table if necessary. */
14445 if (separate_line_info_table_in_use
14446 == separate_line_info_table_allocated
)
14448 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
14449 separate_line_info_table
14450 = ggc_realloc (separate_line_info_table
,
14451 separate_line_info_table_allocated
14452 * sizeof (dw_separate_line_info_entry
));
14453 memset (separate_line_info_table
14454 + separate_line_info_table_in_use
,
14456 (LINE_INFO_TABLE_INCREMENT
14457 * sizeof (dw_separate_line_info_entry
)));
14460 /* Add the new entry at the end of the line_info_table. */
14462 = &separate_line_info_table
[separate_line_info_table_in_use
++];
14463 line_info
->dw_file_num
= file_num
;
14464 line_info
->dw_line_num
= line
;
14465 line_info
->function
= current_function_funcdef_no
;
14469 dw_line_info_ref line_info
;
14471 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
14472 line_info_table_in_use
);
14474 /* Expand the line info table if necessary. */
14475 if (line_info_table_in_use
== line_info_table_allocated
)
14477 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
14479 = ggc_realloc (line_info_table
,
14480 (line_info_table_allocated
14481 * sizeof (dw_line_info_entry
)));
14482 memset (line_info_table
+ line_info_table_in_use
, 0,
14483 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
14486 /* Add the new entry at the end of the line_info_table. */
14487 line_info
= &line_info_table
[line_info_table_in_use
++];
14488 line_info
->dw_file_num
= file_num
;
14489 line_info
->dw_line_num
= line
;
14494 /* Record the beginning of a new source file. */
14497 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
14499 if (flag_eliminate_dwarf2_dups
)
14501 /* Record the beginning of the file for break_out_includes. */
14502 dw_die_ref bincl_die
;
14504 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
14505 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
14508 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14510 int file_num
= maybe_emit_file (lookup_filename (filename
));
14512 switch_to_section (debug_macinfo_section
);
14513 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
14514 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
14517 dw2_asm_output_data_uleb128 (file_num
, "file %s", filename
);
14521 /* Record the end of a source file. */
14524 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
14526 if (flag_eliminate_dwarf2_dups
)
14527 /* Record the end of the file for break_out_includes. */
14528 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
14530 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14532 switch_to_section (debug_macinfo_section
);
14533 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
14537 /* Called from debug_define in toplev.c. The `buffer' parameter contains
14538 the tail part of the directive line, i.e. the part which is past the
14539 initial whitespace, #, whitespace, directive-name, whitespace part. */
14542 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
14543 const char *buffer ATTRIBUTE_UNUSED
)
14545 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14547 switch_to_section (debug_macinfo_section
);
14548 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
14549 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
14550 dw2_asm_output_nstring (buffer
, -1, "The macro");
14554 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
14555 the tail part of the directive line, i.e. the part which is past the
14556 initial whitespace, #, whitespace, directive-name, whitespace part. */
14559 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
14560 const char *buffer ATTRIBUTE_UNUSED
)
14562 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14564 switch_to_section (debug_macinfo_section
);
14565 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
14566 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
14567 dw2_asm_output_nstring (buffer
, -1, "The macro");
14571 /* Set up for Dwarf output at the start of compilation. */
14574 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
14576 /* Allocate the file_table. */
14577 file_table
= htab_create_ggc (50, file_table_hash
,
14578 file_table_eq
, NULL
);
14580 /* Allocate the decl_die_table. */
14581 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
14582 decl_die_table_eq
, NULL
);
14584 /* Allocate the decl_loc_table. */
14585 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
14586 decl_loc_table_eq
, NULL
);
14588 /* Allocate the initial hunk of the decl_scope_table. */
14589 decl_scope_table
= VEC_alloc (tree
, gc
, 256);
14591 /* Allocate the initial hunk of the abbrev_die_table. */
14592 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
14593 * sizeof (dw_die_ref
));
14594 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
14595 /* Zero-th entry is allocated, but unused. */
14596 abbrev_die_table_in_use
= 1;
14598 /* Allocate the initial hunk of the line_info_table. */
14599 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
14600 * sizeof (dw_line_info_entry
));
14601 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
14603 /* Zero-th entry is allocated, but unused. */
14604 line_info_table_in_use
= 1;
14606 /* Allocate the pubtypes and pubnames vectors. */
14607 pubname_table
= VEC_alloc (pubname_entry
, gc
, 32);
14608 pubtype_table
= VEC_alloc (pubname_entry
, gc
, 32);
14610 /* Generate the initial DIE for the .debug section. Note that the (string)
14611 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
14612 will (typically) be a relative pathname and that this pathname should be
14613 taken as being relative to the directory from which the compiler was
14614 invoked when the given (base) source file was compiled. We will fill
14615 in this value in dwarf2out_finish. */
14616 comp_unit_die
= gen_compile_unit_die (NULL
);
14618 incomplete_types
= VEC_alloc (tree
, gc
, 64);
14620 used_rtx_array
= VEC_alloc (rtx
, gc
, 32);
14622 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
14623 SECTION_DEBUG
, NULL
);
14624 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
14625 SECTION_DEBUG
, NULL
);
14626 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
14627 SECTION_DEBUG
, NULL
);
14628 debug_macinfo_section
= get_section (DEBUG_MACINFO_SECTION
,
14629 SECTION_DEBUG
, NULL
);
14630 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
14631 SECTION_DEBUG
, NULL
);
14632 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
14633 SECTION_DEBUG
, NULL
);
14634 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
14635 SECTION_DEBUG
, NULL
);
14636 #ifdef DEBUG_PUBTYPES_SECTION
14637 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
14638 SECTION_DEBUG
, NULL
);
14640 debug_str_section
= get_section (DEBUG_STR_SECTION
,
14641 DEBUG_STR_SECTION_FLAGS
, NULL
);
14642 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
14643 SECTION_DEBUG
, NULL
);
14644 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
14645 SECTION_DEBUG
, NULL
);
14647 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
14648 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
14649 DEBUG_ABBREV_SECTION_LABEL
, 0);
14650 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
14651 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
14652 COLD_TEXT_SECTION_LABEL
, 0);
14653 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
14655 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
14656 DEBUG_INFO_SECTION_LABEL
, 0);
14657 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
14658 DEBUG_LINE_SECTION_LABEL
, 0);
14659 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
14660 DEBUG_RANGES_SECTION_LABEL
, 0);
14661 switch_to_section (debug_abbrev_section
);
14662 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
14663 switch_to_section (debug_info_section
);
14664 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
14665 switch_to_section (debug_line_section
);
14666 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
14668 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
14670 switch_to_section (debug_macinfo_section
);
14671 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
14672 DEBUG_MACINFO_SECTION_LABEL
, 0);
14673 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
14676 switch_to_section (text_section
);
14677 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
14678 if (flag_reorder_blocks_and_partition
)
14680 cold_text_section
= unlikely_text_section ();
14681 switch_to_section (cold_text_section
);
14682 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
14686 /* A helper function for dwarf2out_finish called through
14687 ht_forall. Emit one queued .debug_str string. */
14690 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
14692 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
14694 if (node
->form
== DW_FORM_strp
)
14696 switch_to_section (debug_str_section
);
14697 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
14698 assemble_string (node
->str
, strlen (node
->str
) + 1);
14704 #if ENABLE_ASSERT_CHECKING
14705 /* Verify that all marks are clear. */
14708 verify_marks_clear (dw_die_ref die
)
14712 gcc_assert (! die
->die_mark
);
14713 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
14715 #endif /* ENABLE_ASSERT_CHECKING */
14717 /* Clear the marks for a die and its children.
14718 Be cool if the mark isn't set. */
14721 prune_unmark_dies (dw_die_ref die
)
14727 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
14730 /* Given DIE that we're marking as used, find any other dies
14731 it references as attributes and mark them as used. */
14734 prune_unused_types_walk_attribs (dw_die_ref die
)
14739 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
14741 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
14743 /* A reference to another DIE.
14744 Make sure that it will get emitted. */
14745 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
14747 /* Set the string's refcount to 0 so that prune_unused_types_mark
14748 accounts properly for it. */
14749 if (AT_class (a
) == dw_val_class_str
)
14750 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
14755 /* Mark DIE as being used. If DOKIDS is true, then walk down
14756 to DIE's children. */
14759 prune_unused_types_mark (dw_die_ref die
, int dokids
)
14763 if (die
->die_mark
== 0)
14765 /* We haven't done this node yet. Mark it as used. */
14768 /* We also have to mark its parents as used.
14769 (But we don't want to mark our parents' kids due to this.) */
14770 if (die
->die_parent
)
14771 prune_unused_types_mark (die
->die_parent
, 0);
14773 /* Mark any referenced nodes. */
14774 prune_unused_types_walk_attribs (die
);
14776 /* If this node is a specification,
14777 also mark the definition, if it exists. */
14778 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
14779 prune_unused_types_mark (die
->die_definition
, 1);
14782 if (dokids
&& die
->die_mark
!= 2)
14784 /* We need to walk the children, but haven't done so yet.
14785 Remember that we've walked the kids. */
14788 /* If this is an array type, we need to make sure our
14789 kids get marked, even if they're types. */
14790 if (die
->die_tag
== DW_TAG_array_type
)
14791 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
14793 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
14798 /* Walk the tree DIE and mark types that we actually use. */
14801 prune_unused_types_walk (dw_die_ref die
)
14805 /* Don't do anything if this node is already marked. */
14809 switch (die
->die_tag
)
14811 case DW_TAG_const_type
:
14812 case DW_TAG_packed_type
:
14813 case DW_TAG_pointer_type
:
14814 case DW_TAG_reference_type
:
14815 case DW_TAG_volatile_type
:
14816 case DW_TAG_typedef
:
14817 case DW_TAG_array_type
:
14818 case DW_TAG_structure_type
:
14819 case DW_TAG_union_type
:
14820 case DW_TAG_class_type
:
14821 case DW_TAG_interface_type
:
14822 case DW_TAG_friend
:
14823 case DW_TAG_variant_part
:
14824 case DW_TAG_enumeration_type
:
14825 case DW_TAG_subroutine_type
:
14826 case DW_TAG_string_type
:
14827 case DW_TAG_set_type
:
14828 case DW_TAG_subrange_type
:
14829 case DW_TAG_ptr_to_member_type
:
14830 case DW_TAG_file_type
:
14831 if (die
->die_perennial_p
)
14834 /* It's a type node --- don't mark it. */
14838 /* Mark everything else. */
14844 /* Now, mark any dies referenced from here. */
14845 prune_unused_types_walk_attribs (die
);
14847 /* Mark children. */
14848 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
14851 /* Increment the string counts on strings referred to from DIE's
14855 prune_unused_types_update_strings (dw_die_ref die
)
14860 for (ix
= 0; VEC_iterate (dw_attr_node
, die
->die_attr
, ix
, a
); ix
++)
14861 if (AT_class (a
) == dw_val_class_str
)
14863 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
14865 /* Avoid unnecessarily putting strings that are used less than
14866 twice in the hash table. */
14868 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
14871 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
14872 htab_hash_string (s
->str
),
14874 gcc_assert (*slot
== NULL
);
14880 /* Remove from the tree DIE any dies that aren't marked. */
14883 prune_unused_types_prune (dw_die_ref die
)
14887 gcc_assert (die
->die_mark
);
14888 prune_unused_types_update_strings (die
);
14890 if (! die
->die_child
)
14893 c
= die
->die_child
;
14895 dw_die_ref prev
= c
;
14896 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
14897 if (c
== die
->die_child
)
14899 /* No marked children between 'prev' and the end of the list. */
14901 /* No marked children at all. */
14902 die
->die_child
= NULL
;
14905 prev
->die_sib
= c
->die_sib
;
14906 die
->die_child
= prev
;
14911 if (c
!= prev
->die_sib
)
14913 prune_unused_types_prune (c
);
14914 } while (c
!= die
->die_child
);
14918 /* Remove dies representing declarations that we never use. */
14921 prune_unused_types (void)
14924 limbo_die_node
*node
;
14927 #if ENABLE_ASSERT_CHECKING
14928 /* All the marks should already be clear. */
14929 verify_marks_clear (comp_unit_die
);
14930 for (node
= limbo_die_list
; node
; node
= node
->next
)
14931 verify_marks_clear (node
->die
);
14932 #endif /* ENABLE_ASSERT_CHECKING */
14934 /* Set the mark on nodes that are actually used. */
14935 prune_unused_types_walk (comp_unit_die
);
14936 for (node
= limbo_die_list
; node
; node
= node
->next
)
14937 prune_unused_types_walk (node
->die
);
14939 /* Also set the mark on nodes referenced from the
14940 pubname_table or arange_table. */
14941 for (i
= 0; VEC_iterate (pubname_entry
, pubname_table
, i
, pub
); i
++)
14942 prune_unused_types_mark (pub
->die
, 1);
14943 for (i
= 0; i
< arange_table_in_use
; i
++)
14944 prune_unused_types_mark (arange_table
[i
], 1);
14946 /* Get rid of nodes that aren't marked; and update the string counts. */
14947 if (debug_str_hash
)
14948 htab_empty (debug_str_hash
);
14949 prune_unused_types_prune (comp_unit_die
);
14950 for (node
= limbo_die_list
; node
; node
= node
->next
)
14951 prune_unused_types_prune (node
->die
);
14953 /* Leave the marks clear. */
14954 prune_unmark_dies (comp_unit_die
);
14955 for (node
= limbo_die_list
; node
; node
= node
->next
)
14956 prune_unmark_dies (node
->die
);
14959 /* Set the parameter to true if there are any relative pathnames in
14962 file_table_relative_p (void ** slot
, void *param
)
14965 struct dwarf_file_data
*d
= *slot
;
14966 if (!IS_ABSOLUTE_PATH (d
->filename
))
14974 /* Output stuff that dwarf requires at the end of every file,
14975 and generate the DWARF-2 debugging info. */
14978 dwarf2out_finish (const char *filename
)
14980 limbo_die_node
*node
, *next_node
;
14981 dw_die_ref die
= 0;
14983 /* Add the name for the main input file now. We delayed this from
14984 dwarf2out_init to avoid complications with PCH. */
14985 add_name_attribute (comp_unit_die
, remap_debug_filename (filename
));
14986 if (!IS_ABSOLUTE_PATH (filename
))
14987 add_comp_dir_attribute (comp_unit_die
);
14988 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
14991 htab_traverse (file_table
, file_table_relative_p
, &p
);
14993 add_comp_dir_attribute (comp_unit_die
);
14996 /* Traverse the limbo die list, and add parent/child links. The only
14997 dies without parents that should be here are concrete instances of
14998 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
14999 For concrete instances, we can get the parent die from the abstract
15001 for (node
= limbo_die_list
; node
; node
= next_node
)
15003 next_node
= node
->next
;
15006 if (die
->die_parent
== NULL
)
15008 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
15011 add_child_die (origin
->die_parent
, die
);
15012 else if (die
== comp_unit_die
)
15014 else if (errorcount
> 0 || sorrycount
> 0)
15015 /* It's OK to be confused by errors in the input. */
15016 add_child_die (comp_unit_die
, die
);
15019 /* In certain situations, the lexical block containing a
15020 nested function can be optimized away, which results
15021 in the nested function die being orphaned. Likewise
15022 with the return type of that nested function. Force
15023 this to be a child of the containing function.
15025 It may happen that even the containing function got fully
15026 inlined and optimized out. In that case we are lost and
15027 assign the empty child. This should not be big issue as
15028 the function is likely unreachable too. */
15029 tree context
= NULL_TREE
;
15031 gcc_assert (node
->created_for
);
15033 if (DECL_P (node
->created_for
))
15034 context
= DECL_CONTEXT (node
->created_for
);
15035 else if (TYPE_P (node
->created_for
))
15036 context
= TYPE_CONTEXT (node
->created_for
);
15038 gcc_assert (context
15039 && (TREE_CODE (context
) == FUNCTION_DECL
15040 || TREE_CODE (context
) == NAMESPACE_DECL
));
15042 origin
= lookup_decl_die (context
);
15044 add_child_die (origin
, die
);
15046 add_child_die (comp_unit_die
, die
);
15051 limbo_die_list
= NULL
;
15053 /* Walk through the list of incomplete types again, trying once more to
15054 emit full debugging info for them. */
15055 retry_incomplete_types ();
15057 if (flag_eliminate_unused_debug_types
)
15058 prune_unused_types ();
15060 /* Generate separate CUs for each of the include files we've seen.
15061 They will go into limbo_die_list. */
15062 if (flag_eliminate_dwarf2_dups
)
15063 break_out_includes (comp_unit_die
);
15065 /* Traverse the DIE's and add add sibling attributes to those DIE's
15066 that have children. */
15067 add_sibling_attributes (comp_unit_die
);
15068 for (node
= limbo_die_list
; node
; node
= node
->next
)
15069 add_sibling_attributes (node
->die
);
15071 /* Output a terminator label for the .text section. */
15072 switch_to_section (text_section
);
15073 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
15074 if (flag_reorder_blocks_and_partition
)
15076 switch_to_section (unlikely_text_section ());
15077 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
15080 /* We can only use the low/high_pc attributes if all of the code was
15082 if (!have_multiple_function_sections
)
15084 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
15085 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
15090 unsigned fde_idx
= 0;
15092 /* We need to give .debug_loc and .debug_ranges an appropriate
15093 "base address". Use zero so that these addresses become
15094 absolute. Historically, we've emitted the unexpected
15095 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
15096 Emit both to give time for other tools to adapt. */
15097 add_AT_addr (comp_unit_die
, DW_AT_low_pc
, const0_rtx
);
15098 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
15100 add_AT_range_list (comp_unit_die
, DW_AT_ranges
,
15101 add_ranges_by_labels (text_section_label
,
15103 if (flag_reorder_blocks_and_partition
)
15104 add_ranges_by_labels (cold_text_section_label
,
15107 for (fde_idx
= 0; fde_idx
< fde_table_in_use
; fde_idx
++)
15109 dw_fde_ref fde
= &fde_table
[fde_idx
];
15111 if (fde
->dw_fde_switched_sections
)
15113 add_ranges_by_labels (fde
->dw_fde_hot_section_label
,
15114 fde
->dw_fde_hot_section_end_label
);
15115 add_ranges_by_labels (fde
->dw_fde_unlikely_section_label
,
15116 fde
->dw_fde_unlikely_section_end_label
);
15119 add_ranges_by_labels (fde
->dw_fde_begin
,
15126 /* Output location list section if necessary. */
15127 if (have_location_lists
)
15129 /* Output the location lists info. */
15130 switch_to_section (debug_loc_section
);
15131 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
15132 DEBUG_LOC_SECTION_LABEL
, 0);
15133 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
15134 output_location_lists (die
);
15137 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
15138 add_AT_lineptr (comp_unit_die
, DW_AT_stmt_list
,
15139 debug_line_section_label
);
15141 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15142 add_AT_macptr (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
15144 /* Output all of the compilation units. We put the main one last so that
15145 the offsets are available to output_pubnames. */
15146 for (node
= limbo_die_list
; node
; node
= node
->next
)
15147 output_comp_unit (node
->die
, 0);
15149 output_comp_unit (comp_unit_die
, 0);
15151 /* Output the abbreviation table. */
15152 switch_to_section (debug_abbrev_section
);
15153 output_abbrev_section ();
15155 /* Output public names table if necessary. */
15156 if (!VEC_empty (pubname_entry
, pubname_table
))
15158 switch_to_section (debug_pubnames_section
);
15159 output_pubnames (pubname_table
);
15162 #ifdef DEBUG_PUBTYPES_SECTION
15163 /* Output public types table if necessary. */
15164 if (!VEC_empty (pubname_entry
, pubtype_table
))
15166 switch_to_section (debug_pubtypes_section
);
15167 output_pubnames (pubtype_table
);
15171 /* Output the address range information. We only put functions in the arange
15172 table, so don't write it out if we don't have any. */
15173 if (fde_table_in_use
)
15175 switch_to_section (debug_aranges_section
);
15179 /* Output ranges section if necessary. */
15180 if (ranges_table_in_use
)
15182 switch_to_section (debug_ranges_section
);
15183 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
15187 /* Output the source line correspondence table. We must do this
15188 even if there is no line information. Otherwise, on an empty
15189 translation unit, we will generate a present, but empty,
15190 .debug_info section. IRIX 6.5 `nm' will then complain when
15191 examining the file. This is done late so that any filenames
15192 used by the debug_info section are marked as 'used'. */
15193 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
15195 switch_to_section (debug_line_section
);
15196 output_line_info ();
15199 /* Have to end the macro section. */
15200 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
15202 switch_to_section (debug_macinfo_section
);
15203 dw2_asm_output_data (1, 0, "End compilation unit");
15206 /* If we emitted any DW_FORM_strp form attribute, output the string
15208 if (debug_str_hash
)
15209 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
15213 /* This should never be used, but its address is needed for comparisons. */
15214 const struct gcc_debug_hooks dwarf2_debug_hooks
;
15216 #endif /* DWARF2_DEBUGGING_INFO */
15218 #include "gt-dwarf2out.h"