1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 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 2, 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 COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
66 #ifdef DWARF2_DEBUGGING_INFO
67 static void dwarf2out_source_line
PARAMS ((unsigned int, const char *));
70 /* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
88 /* Decide whether we want to emit frame unwind information for the current
94 return (write_symbols
== DWARF2_DEBUG
95 || write_symbols
== VMS_AND_DWARF2_DEBUG
96 #ifdef DWARF2_FRAME_INFO
99 #ifdef DWARF2_UNWIND_INFO
100 || flag_unwind_tables
101 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
106 /* The size of the target's pointer type. */
108 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
111 /* Default version of targetm.eh_frame_section. Note this must appear
112 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
116 default_eh_frame_section ()
118 #ifdef EH_FRAME_SECTION_NAME
119 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
121 tree label
= get_file_function_name ('F');
124 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
125 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, IDENTIFIER_POINTER (label
));
126 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
130 /* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132 static GTY(()) varray_type used_rtx_varray
;
134 /* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a VARRAY
136 because we want to tell the garbage collector about it. */
137 static GTY(()) varray_type incomplete_types
;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) varray_type decl_scope_table
;
146 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
148 /* How to start an assembler comment. */
149 #ifndef ASM_COMMENT_START
150 #define ASM_COMMENT_START ";#"
153 typedef struct dw_cfi_struct
*dw_cfi_ref
;
154 typedef struct dw_fde_struct
*dw_fde_ref
;
155 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
157 /* Call frames are described using a sequence of Call Frame
158 Information instructions. The register number, offset
159 and address fields are provided as possible operands;
160 their use is selected by the opcode field. */
162 typedef union dw_cfi_oprnd_struct
164 unsigned long dw_cfi_reg_num
;
165 long int dw_cfi_offset
;
166 const char *dw_cfi_addr
;
167 struct dw_loc_descr_struct
*dw_cfi_loc
;
171 typedef struct dw_cfi_struct
173 dw_cfi_ref dw_cfi_next
;
174 enum dwarf_call_frame_info dw_cfi_opc
;
175 dw_cfi_oprnd dw_cfi_oprnd1
;
176 dw_cfi_oprnd dw_cfi_oprnd2
;
180 /* This is how we define the location of the CFA. We use to handle it
181 as REG + OFFSET all the time, but now it can be more complex.
182 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
183 Instead of passing around REG and OFFSET, we pass a copy
184 of this structure. */
185 typedef struct cfa_loc
190 int indirect
; /* 1 if CFA is accessed via a dereference. */
193 /* All call frame descriptions (FDE's) in the GCC generated DWARF
194 refer to a single Common Information Entry (CIE), defined at
195 the beginning of the .debug_frame section. This use of a single
196 CIE obviates the need to keep track of multiple CIE's
197 in the DWARF generation routines below. */
199 typedef struct dw_fde_struct
201 const char *dw_fde_begin
;
202 const char *dw_fde_current_label
;
203 const char *dw_fde_end
;
204 dw_cfi_ref dw_fde_cfi
;
205 unsigned funcdef_number
;
206 unsigned nothrow
: 1;
207 unsigned uses_eh_lsda
: 1;
211 /* Maximum size (in bytes) of an artificially generated label. */
212 #define MAX_ARTIFICIAL_LABEL_BYTES 30
214 /* The size of addresses as they appear in the Dwarf 2 data.
215 Some architectures use word addresses to refer to code locations,
216 but Dwarf 2 info always uses byte addresses. On such machines,
217 Dwarf 2 addresses need to be larger than the architecture's
219 #ifndef DWARF2_ADDR_SIZE
220 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
223 /* The size in bytes of a DWARF field indicating an offset or length
224 relative to a debug info section, specified to be 4 bytes in the
225 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
228 #ifndef DWARF_OFFSET_SIZE
229 #define DWARF_OFFSET_SIZE 4
232 #define DWARF_VERSION 2
234 /* Round SIZE up to the nearest BOUNDARY. */
235 #define DWARF_ROUND(SIZE,BOUNDARY) \
236 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
238 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
239 #ifndef DWARF_CIE_DATA_ALIGNMENT
240 #ifdef STACK_GROWS_DOWNWARD
241 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
243 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
247 /* A pointer to the base of a table that contains frame description
248 information for each routine. */
249 static dw_fde_ref fde_table
;
251 /* Number of elements currently allocated for fde_table. */
252 static unsigned fde_table_allocated
;
254 /* Number of elements in fde_table currently in use. */
255 static unsigned fde_table_in_use
;
257 /* Size (in elements) of increments by which we may expand the
259 #define FDE_TABLE_INCREMENT 256
261 /* A list of call frame insns for the CIE. */
262 static dw_cfi_ref cie_cfi_head
;
264 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
265 attribute that accelerates the lookup of the FDE associated
266 with the subprogram. This variable holds the table index of the FDE
267 associated with the current function (body) definition. */
268 static unsigned current_funcdef_fde
;
270 struct ht
*debug_str_hash
;
272 struct indirect_string_node
274 struct ht_identifier id
;
275 unsigned int refcount
;
280 /* Forward declarations for functions defined in this file. */
282 static char *stripattributes
PARAMS ((const char *));
283 static const char *dwarf_cfi_name
PARAMS ((unsigned));
284 static dw_cfi_ref new_cfi
PARAMS ((void));
285 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
286 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
287 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
,
289 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
290 static void reg_save
PARAMS ((const char *, unsigned,
292 static void initial_return_save
PARAMS ((rtx
));
293 static long stack_adjust_offset
PARAMS ((rtx
));
294 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
, int));
295 static void output_call_frame_info
PARAMS ((int));
296 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
297 static void queue_reg_save
PARAMS ((const char *, rtx
, long));
298 static void flush_queued_reg_saves
PARAMS ((void));
299 static bool clobbers_queued_reg_save
PARAMS ((rtx
));
300 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
302 /* Support for complex CFA locations. */
303 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
304 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
305 struct dw_loc_descr_struct
*));
306 static struct dw_loc_descr_struct
*build_cfa_loc
307 PARAMS ((dw_cfa_location
*));
308 static void def_cfa_1
PARAMS ((const char *,
311 /* How to start an assembler comment. */
312 #ifndef ASM_COMMENT_START
313 #define ASM_COMMENT_START ";#"
316 /* Data and reference forms for relocatable data. */
317 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
318 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
320 #ifndef DEBUG_FRAME_SECTION
321 #define DEBUG_FRAME_SECTION ".debug_frame"
324 #ifndef FUNC_BEGIN_LABEL
325 #define FUNC_BEGIN_LABEL "LFB"
328 #ifndef FUNC_END_LABEL
329 #define FUNC_END_LABEL "LFE"
332 #define FRAME_BEGIN_LABEL "Lframe"
333 #define CIE_AFTER_SIZE_LABEL "LSCIE"
334 #define CIE_END_LABEL "LECIE"
335 #define FDE_LABEL "LSFDE"
336 #define FDE_AFTER_SIZE_LABEL "LASFDE"
337 #define FDE_END_LABEL "LEFDE"
338 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
339 #define LINE_NUMBER_END_LABEL "LELT"
340 #define LN_PROLOG_AS_LABEL "LASLTP"
341 #define LN_PROLOG_END_LABEL "LELTP"
342 #define DIE_LABEL_PREFIX "DW"
344 /* The DWARF 2 CFA column which tracks the return address. Normally this
345 is the column for PC, or the first column after all of the hard
347 #ifndef DWARF_FRAME_RETURN_COLUMN
349 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
351 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
355 /* The mapping from gcc register number to DWARF 2 CFA column number. By
356 default, we just provide columns for all registers. */
357 #ifndef DWARF_FRAME_REGNUM
358 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
361 /* The offset from the incoming value of %sp to the top of the stack frame
362 for the current function. */
363 #ifndef INCOMING_FRAME_SP_OFFSET
364 #define INCOMING_FRAME_SP_OFFSET 0
367 /* Hook used by __throw. */
370 expand_builtin_dwarf_fp_regnum ()
372 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
375 /* Return a pointer to a copy of the section string name S with all
376 attributes stripped off, and an asterisk prepended (for assemble_name). */
382 char *stripped
= xmalloc (strlen (s
) + 2);
387 while (*s
&& *s
!= ',')
394 /* Generate code to initialize the register size table. */
397 expand_builtin_init_dwarf_reg_sizes (address
)
401 enum machine_mode mode
= TYPE_MODE (char_type_node
);
402 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
403 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
405 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
406 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
408 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
409 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
414 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
418 /* Convert a DWARF call frame info. operation to its string name */
421 dwarf_cfi_name (cfi_opc
)
426 case DW_CFA_advance_loc
:
427 return "DW_CFA_advance_loc";
429 return "DW_CFA_offset";
431 return "DW_CFA_restore";
435 return "DW_CFA_set_loc";
436 case DW_CFA_advance_loc1
:
437 return "DW_CFA_advance_loc1";
438 case DW_CFA_advance_loc2
:
439 return "DW_CFA_advance_loc2";
440 case DW_CFA_advance_loc4
:
441 return "DW_CFA_advance_loc4";
442 case DW_CFA_offset_extended
:
443 return "DW_CFA_offset_extended";
444 case DW_CFA_restore_extended
:
445 return "DW_CFA_restore_extended";
446 case DW_CFA_undefined
:
447 return "DW_CFA_undefined";
448 case DW_CFA_same_value
:
449 return "DW_CFA_same_value";
450 case DW_CFA_register
:
451 return "DW_CFA_register";
452 case DW_CFA_remember_state
:
453 return "DW_CFA_remember_state";
454 case DW_CFA_restore_state
:
455 return "DW_CFA_restore_state";
457 return "DW_CFA_def_cfa";
458 case DW_CFA_def_cfa_register
:
459 return "DW_CFA_def_cfa_register";
460 case DW_CFA_def_cfa_offset
:
461 return "DW_CFA_def_cfa_offset";
464 case DW_CFA_def_cfa_expression
:
465 return "DW_CFA_def_cfa_expression";
466 case DW_CFA_expression
:
467 return "DW_CFA_expression";
468 case DW_CFA_offset_extended_sf
:
469 return "DW_CFA_offset_extended_sf";
470 case DW_CFA_def_cfa_sf
:
471 return "DW_CFA_def_cfa_sf";
472 case DW_CFA_def_cfa_offset_sf
:
473 return "DW_CFA_def_cfa_offset_sf";
475 /* SGI/MIPS specific */
476 case DW_CFA_MIPS_advance_loc8
:
477 return "DW_CFA_MIPS_advance_loc8";
480 case DW_CFA_GNU_window_save
:
481 return "DW_CFA_GNU_window_save";
482 case DW_CFA_GNU_args_size
:
483 return "DW_CFA_GNU_args_size";
484 case DW_CFA_GNU_negative_offset_extended
:
485 return "DW_CFA_GNU_negative_offset_extended";
488 return "DW_CFA_<unknown>";
492 /* Return a pointer to a newly allocated Call Frame Instruction. */
494 static inline dw_cfi_ref
497 dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
499 cfi
->dw_cfi_next
= NULL
;
500 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
501 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
506 /* Add a Call Frame Instruction to list of instructions. */
509 add_cfi (list_head
, cfi
)
510 dw_cfi_ref
*list_head
;
515 /* Find the end of the chain. */
516 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
522 /* Generate a new label for the CFI info to refer to. */
525 dwarf2out_cfi_label ()
527 static char label
[20];
528 static unsigned long label_num
= 0;
530 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
531 ASM_OUTPUT_LABEL (asm_out_file
, label
);
535 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
536 or to the CIE if LABEL is NULL. */
539 add_fde_cfi (label
, cfi
)
545 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
548 label
= dwarf2out_cfi_label ();
550 if (fde
->dw_fde_current_label
== NULL
551 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
555 fde
->dw_fde_current_label
= label
= xstrdup (label
);
557 /* Set the location counter to the new label. */
559 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
560 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
561 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
564 add_cfi (&fde
->dw_fde_cfi
, cfi
);
568 add_cfi (&cie_cfi_head
, cfi
);
571 /* Subroutine of lookup_cfa. */
574 lookup_cfa_1 (cfi
, loc
)
576 dw_cfa_location
*loc
;
578 switch (cfi
->dw_cfi_opc
)
580 case DW_CFA_def_cfa_offset
:
581 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
583 case DW_CFA_def_cfa_register
:
584 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
587 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
588 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
590 case DW_CFA_def_cfa_expression
:
591 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
598 /* Find the previous value for the CFA. */
602 dw_cfa_location
*loc
;
606 loc
->reg
= (unsigned long) -1;
609 loc
->base_offset
= 0;
611 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
612 lookup_cfa_1 (cfi
, loc
);
614 if (fde_table_in_use
)
616 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
617 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
618 lookup_cfa_1 (cfi
, loc
);
622 /* The current rule for calculating the DWARF2 canonical frame address. */
623 static dw_cfa_location cfa
;
625 /* The register used for saving registers to the stack, and its offset
627 static dw_cfa_location cfa_store
;
629 /* The running total of the size of arguments pushed onto the stack. */
630 static long args_size
;
632 /* The last args_size we actually output. */
633 static long old_args_size
;
635 /* Entry point to update the canonical frame address (CFA).
636 LABEL is passed to add_fde_cfi. The value of CFA is now to be
637 calculated from REG+OFFSET. */
640 dwarf2out_def_cfa (label
, reg
, offset
)
650 def_cfa_1 (label
, &loc
);
653 /* This routine does the actual work. The CFA is now calculated from
654 the dw_cfa_location structure. */
657 def_cfa_1 (label
, loc_p
)
659 dw_cfa_location
*loc_p
;
662 dw_cfa_location old_cfa
, loc
;
667 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
668 cfa_store
.offset
= loc
.offset
;
670 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
671 lookup_cfa (&old_cfa
);
673 /* If nothing changed, no need to issue any call frame instructions. */
674 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
675 && loc
.indirect
== old_cfa
.indirect
676 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
681 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
683 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
684 indicating the CFA register did not change but the offset
686 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
687 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
690 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
691 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
694 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
695 indicating the CFA register has changed to <register> but the
696 offset has not changed. */
697 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
698 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
702 else if (loc
.indirect
== 0)
704 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
705 indicating the CFA register has changed to <register> with
706 the specified offset. */
707 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
708 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
709 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
713 /* Construct a DW_CFA_def_cfa_expression instruction to
714 calculate the CFA using a full location expression since no
715 register-offset pair is available. */
716 struct dw_loc_descr_struct
*loc_list
;
718 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
719 loc_list
= build_cfa_loc (&loc
);
720 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
723 add_fde_cfi (label
, cfi
);
726 /* Add the CFI for saving a register. REG is the CFA column number.
727 LABEL is passed to add_fde_cfi.
728 If SREG is -1, the register is saved at OFFSET from the CFA;
729 otherwise it is saved in SREG. */
732 reg_save (label
, reg
, sreg
, offset
)
738 dw_cfi_ref cfi
= new_cfi ();
740 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
742 /* The following comparison is correct. -1 is used to indicate that
743 the value isn't a register number. */
744 if (sreg
== (unsigned int) -1)
747 /* The register number won't fit in 6 bits, so we have to use
749 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
751 cfi
->dw_cfi_opc
= DW_CFA_offset
;
753 #ifdef ENABLE_CHECKING
755 /* If we get an offset that is not a multiple of
756 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
757 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
759 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
761 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
765 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
767 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
769 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
771 else if (sreg
== reg
)
772 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
776 cfi
->dw_cfi_opc
= DW_CFA_register
;
777 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
780 add_fde_cfi (label
, cfi
);
783 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
784 This CFI tells the unwinder that it needs to restore the window registers
785 from the previous frame's window save area.
787 ??? Perhaps we should note in the CIE where windows are saved (instead of
788 assuming 0(cfa)) and what registers are in the window. */
791 dwarf2out_window_save (label
)
794 dw_cfi_ref cfi
= new_cfi ();
796 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
797 add_fde_cfi (label
, cfi
);
800 /* Add a CFI to update the running total of the size of arguments
801 pushed onto the stack. */
804 dwarf2out_args_size (label
, size
)
810 if (size
== old_args_size
)
813 old_args_size
= size
;
816 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
817 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
818 add_fde_cfi (label
, cfi
);
821 /* Entry point for saving a register to the stack. REG is the GCC register
822 number. LABEL and OFFSET are passed to reg_save. */
825 dwarf2out_reg_save (label
, reg
, offset
)
830 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
833 /* Entry point for saving the return address in the stack.
834 LABEL and OFFSET are passed to reg_save. */
837 dwarf2out_return_save (label
, offset
)
841 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
844 /* Entry point for saving the return address in a register.
845 LABEL and SREG are passed to reg_save. */
848 dwarf2out_return_reg (label
, sreg
)
852 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
855 /* Record the initial position of the return address. RTL is
856 INCOMING_RETURN_ADDR_RTX. */
859 initial_return_save (rtl
)
862 unsigned int reg
= (unsigned int) -1;
863 HOST_WIDE_INT offset
= 0;
865 switch (GET_CODE (rtl
))
868 /* RA is in a register. */
869 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
873 /* RA is on the stack. */
875 switch (GET_CODE (rtl
))
878 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
884 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
886 offset
= INTVAL (XEXP (rtl
, 1));
890 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
892 offset
= -INTVAL (XEXP (rtl
, 1));
902 /* The return address is at some offset from any value we can
903 actually load. For instance, on the SPARC it is in %i7+8. Just
904 ignore the offset for now; it doesn't matter for unwinding frames. */
905 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
907 initial_return_save (XEXP (rtl
, 0));
914 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
917 /* Given a SET, calculate the amount of stack adjustment it
921 stack_adjust_offset (pattern
)
924 rtx src
= SET_SRC (pattern
);
925 rtx dest
= SET_DEST (pattern
);
926 HOST_WIDE_INT offset
= 0;
929 if (dest
== stack_pointer_rtx
)
931 /* (set (reg sp) (plus (reg sp) (const_int))) */
932 code
= GET_CODE (src
);
933 if (! (code
== PLUS
|| code
== MINUS
)
934 || XEXP (src
, 0) != stack_pointer_rtx
935 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
938 offset
= INTVAL (XEXP (src
, 1));
942 else if (GET_CODE (dest
) == MEM
)
944 /* (set (mem (pre_dec (reg sp))) (foo)) */
945 src
= XEXP (dest
, 0);
946 code
= GET_CODE (src
);
952 if (XEXP (src
, 0) == stack_pointer_rtx
)
954 rtx val
= XEXP (XEXP (src
, 1), 1);
955 /* We handle only adjustments by constant amount. */
956 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
957 GET_CODE (val
) != CONST_INT
)
959 offset
= -INTVAL (val
);
966 if (XEXP (src
, 0) == stack_pointer_rtx
)
968 offset
= GET_MODE_SIZE (GET_MODE (dest
));
975 if (XEXP (src
, 0) == stack_pointer_rtx
)
977 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
992 /* Check INSN to see if it looks like a push or a stack adjustment, and
993 make a note of it if it does. EH uses this information to find out how
994 much extra space it needs to pop off the stack. */
997 dwarf2out_stack_adjust (insn
)
1000 HOST_WIDE_INT offset
;
1004 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1006 /* Extract the size of the args from the CALL rtx itself. */
1007 insn
= PATTERN (insn
);
1008 if (GET_CODE (insn
) == PARALLEL
)
1009 insn
= XVECEXP (insn
, 0, 0);
1010 if (GET_CODE (insn
) == SET
)
1011 insn
= SET_SRC (insn
);
1012 if (GET_CODE (insn
) != CALL
)
1015 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1019 /* If only calls can throw, and we have a frame pointer,
1020 save up adjustments until we see the CALL_INSN. */
1021 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1024 if (GET_CODE (insn
) == BARRIER
)
1026 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1027 the compiler will have already emitted a stack adjustment, but
1028 doesn't bother for calls to noreturn functions. */
1029 #ifdef STACK_GROWS_DOWNWARD
1030 offset
= -args_size
;
1035 else if (GET_CODE (PATTERN (insn
)) == SET
)
1036 offset
= stack_adjust_offset (PATTERN (insn
));
1037 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1038 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1040 /* There may be stack adjustments inside compound insns. Search
1042 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1043 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1044 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1052 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1053 cfa
.offset
+= offset
;
1055 #ifndef STACK_GROWS_DOWNWARD
1059 args_size
+= offset
;
1063 label
= dwarf2out_cfi_label ();
1064 def_cfa_1 (label
, &cfa
);
1065 dwarf2out_args_size (label
, args_size
);
1068 /* We delay emitting a register save until either (a) we reach the end
1069 of the prologue or (b) the register is clobbered. This clusters
1070 register saves so that there are fewer pc advances. */
1072 struct queued_reg_save
1074 struct queued_reg_save
*next
;
1079 static struct queued_reg_save
*queued_reg_saves
;
1080 static const char *last_reg_save_label
;
1083 queue_reg_save (label
, reg
, offset
)
1088 struct queued_reg_save
*q
= (struct queued_reg_save
*) xmalloc (sizeof (*q
));
1090 q
->next
= queued_reg_saves
;
1092 q
->cfa_offset
= offset
;
1093 queued_reg_saves
= q
;
1095 last_reg_save_label
= label
;
1099 flush_queued_reg_saves ()
1101 struct queued_reg_save
*q
, *next
;
1103 for (q
= queued_reg_saves
; q
; q
= next
)
1105 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1110 queued_reg_saves
= NULL
;
1111 last_reg_save_label
= NULL
;
1115 clobbers_queued_reg_save (insn
)
1118 struct queued_reg_save
*q
;
1120 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1121 if (modified_in_p (q
->reg
, insn
))
1128 /* A temporary register holding an integral value used in adjusting SP
1129 or setting up the store_reg. The "offset" field holds the integer
1130 value, not an offset. */
1131 static dw_cfa_location cfa_temp
;
1133 /* Record call frame debugging information for an expression EXPR,
1134 which either sets SP or FP (adjusting how we calculate the frame
1135 address) or saves a register to the stack. LABEL indicates the
1138 This function encodes a state machine mapping rtxes to actions on
1139 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1140 users need not read the source code.
1142 The High-Level Picture
1144 Changes in the register we use to calculate the CFA: Currently we
1145 assume that if you copy the CFA register into another register, we
1146 should take the other one as the new CFA register; this seems to
1147 work pretty well. If it's wrong for some target, it's simple
1148 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1150 Changes in the register we use for saving registers to the stack:
1151 This is usually SP, but not always. Again, we deduce that if you
1152 copy SP into another register (and SP is not the CFA register),
1153 then the new register is the one we will be using for register
1154 saves. This also seems to work.
1156 Register saves: There's not much guesswork about this one; if
1157 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1158 register save, and the register used to calculate the destination
1159 had better be the one we think we're using for this purpose.
1161 Except: If the register being saved is the CFA register, and the
1162 offset is non-zero, we are saving the CFA, so we assume we have to
1163 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1164 the intent is to save the value of SP from the previous frame.
1166 Invariants / Summaries of Rules
1168 cfa current rule for calculating the CFA. It usually
1169 consists of a register and an offset.
1170 cfa_store register used by prologue code to save things to the stack
1171 cfa_store.offset is the offset from the value of
1172 cfa_store.reg to the actual CFA
1173 cfa_temp register holding an integral value. cfa_temp.offset
1174 stores the value, which will be used to adjust the
1175 stack pointer. cfa_temp is also used like cfa_store,
1176 to track stores to the stack via fp or a temp reg.
1178 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1179 with cfa.reg as the first operand changes the cfa.reg and its
1180 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1183 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1184 expression yielding a constant. This sets cfa_temp.reg
1185 and cfa_temp.offset.
1187 Rule 5: Create a new register cfa_store used to save items to the
1190 Rules 10-14: Save a register to the stack. Define offset as the
1191 difference of the original location and cfa_store's
1192 location (or cfa_temp's location if cfa_temp is used).
1196 "{a,b}" indicates a choice of a xor b.
1197 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1200 (set <reg1> <reg2>:cfa.reg)
1201 effects: cfa.reg = <reg1>
1202 cfa.offset unchanged
1203 cfa_temp.reg = <reg1>
1204 cfa_temp.offset = cfa.offset
1207 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1208 {<const_int>,<reg>:cfa_temp.reg}))
1209 effects: cfa.reg = sp if fp used
1210 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1211 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1212 if cfa_store.reg==sp
1215 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1216 effects: cfa.reg = fp
1217 cfa_offset += +/- <const_int>
1220 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1221 constraints: <reg1> != fp
1223 effects: cfa.reg = <reg1>
1224 cfa_temp.reg = <reg1>
1225 cfa_temp.offset = cfa.offset
1228 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1229 constraints: <reg1> != fp
1231 effects: cfa_store.reg = <reg1>
1232 cfa_store.offset = cfa.offset - cfa_temp.offset
1235 (set <reg> <const_int>)
1236 effects: cfa_temp.reg = <reg>
1237 cfa_temp.offset = <const_int>
1240 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1241 effects: cfa_temp.reg = <reg1>
1242 cfa_temp.offset |= <const_int>
1245 (set <reg> (high <exp>))
1249 (set <reg> (lo_sum <exp> <const_int>))
1250 effects: cfa_temp.reg = <reg>
1251 cfa_temp.offset = <const_int>
1254 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1255 effects: cfa_store.offset -= <const_int>
1256 cfa.offset = cfa_store.offset if cfa.reg == sp
1258 cfa.base_offset = -cfa_store.offset
1261 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1262 effects: cfa_store.offset += -/+ mode_size(mem)
1263 cfa.offset = cfa_store.offset if cfa.reg == sp
1265 cfa.base_offset = -cfa_store.offset
1268 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1271 effects: cfa.reg = <reg1>
1272 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1275 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1276 effects: cfa.reg = <reg1>
1277 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1280 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1281 effects: cfa.reg = <reg1>
1282 cfa.base_offset = -cfa_temp.offset
1283 cfa_temp.offset -= mode_size(mem) */
1286 dwarf2out_frame_debug_expr (expr
, label
)
1291 HOST_WIDE_INT offset
;
1293 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1294 the PARALLEL independently. The first element is always processed if
1295 it is a SET. This is for backward compatibility. Other elements
1296 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1297 flag is set in them. */
1298 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1301 int limit
= XVECLEN (expr
, 0);
1303 for (par_index
= 0; par_index
< limit
; par_index
++)
1304 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1305 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1307 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1312 if (GET_CODE (expr
) != SET
)
1315 src
= SET_SRC (expr
);
1316 dest
= SET_DEST (expr
);
1318 switch (GET_CODE (dest
))
1322 /* Update the CFA rule wrt SP or FP. Make sure src is
1323 relative to the current CFA register. */
1324 switch (GET_CODE (src
))
1326 /* Setting FP from SP. */
1328 if (cfa
.reg
== (unsigned) REGNO (src
))
1334 /* We used to require that dest be either SP or FP, but the
1335 ARM copies SP to a temporary register, and from there to
1336 FP. So we just rely on the backends to only set
1337 RTX_FRAME_RELATED_P on appropriate insns. */
1338 cfa
.reg
= REGNO (dest
);
1339 cfa_temp
.reg
= cfa
.reg
;
1340 cfa_temp
.offset
= cfa
.offset
;
1346 if (dest
== stack_pointer_rtx
)
1350 switch (GET_CODE (XEXP (src
, 1)))
1353 offset
= INTVAL (XEXP (src
, 1));
1356 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1358 offset
= cfa_temp
.offset
;
1364 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1366 /* Restoring SP from FP in the epilogue. */
1367 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1369 cfa
.reg
= STACK_POINTER_REGNUM
;
1371 else if (GET_CODE (src
) == LO_SUM
)
1372 /* Assume we've set the source reg of the LO_SUM from sp. */
1374 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1377 if (GET_CODE (src
) != MINUS
)
1379 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1380 cfa
.offset
+= offset
;
1381 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1382 cfa_store
.offset
+= offset
;
1384 else if (dest
== hard_frame_pointer_rtx
)
1387 /* Either setting the FP from an offset of the SP,
1388 or adjusting the FP */
1389 if (! frame_pointer_needed
)
1392 if (GET_CODE (XEXP (src
, 0)) == REG
1393 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1394 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1396 offset
= INTVAL (XEXP (src
, 1));
1397 if (GET_CODE (src
) != MINUS
)
1399 cfa
.offset
+= offset
;
1400 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1407 if (GET_CODE (src
) == MINUS
)
1411 if (GET_CODE (XEXP (src
, 0)) == REG
1412 && REGNO (XEXP (src
, 0)) == cfa
.reg
1413 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1415 /* Setting a temporary CFA register that will be copied
1416 into the FP later on. */
1417 offset
= - INTVAL (XEXP (src
, 1));
1418 cfa
.offset
+= offset
;
1419 cfa
.reg
= REGNO (dest
);
1420 /* Or used to save regs to the stack. */
1421 cfa_temp
.reg
= cfa
.reg
;
1422 cfa_temp
.offset
= cfa
.offset
;
1426 else if (GET_CODE (XEXP (src
, 0)) == REG
1427 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1428 && XEXP (src
, 1) == stack_pointer_rtx
)
1430 /* Setting a scratch register that we will use instead
1431 of SP for saving registers to the stack. */
1432 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1434 cfa_store
.reg
= REGNO (dest
);
1435 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1439 else if (GET_CODE (src
) == LO_SUM
1440 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1442 cfa_temp
.reg
= REGNO (dest
);
1443 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1452 cfa_temp
.reg
= REGNO (dest
);
1453 cfa_temp
.offset
= INTVAL (src
);
1458 if (GET_CODE (XEXP (src
, 0)) != REG
1459 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1460 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1463 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1464 cfa_temp
.reg
= REGNO (dest
);
1465 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1468 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1469 which will fill in all of the bits. */
1478 def_cfa_1 (label
, &cfa
);
1482 if (GET_CODE (src
) != REG
)
1485 /* Saving a register to the stack. Make sure dest is relative to the
1487 switch (GET_CODE (XEXP (dest
, 0)))
1492 /* We can't handle variable size modifications. */
1493 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1495 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1497 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1498 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1501 cfa_store
.offset
+= offset
;
1502 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1503 cfa
.offset
= cfa_store
.offset
;
1505 offset
= -cfa_store
.offset
;
1511 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1512 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1515 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1516 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1519 cfa_store
.offset
+= offset
;
1520 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1521 cfa
.offset
= cfa_store
.offset
;
1523 offset
= -cfa_store
.offset
;
1527 /* With an offset. */
1531 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1533 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1534 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1537 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1538 offset
-= cfa_store
.offset
;
1539 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1540 offset
-= cfa_temp
.offset
;
1546 /* Without an offset. */
1548 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1549 offset
= -cfa_store
.offset
;
1550 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1551 offset
= -cfa_temp
.offset
;
1558 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1560 offset
= -cfa_temp
.offset
;
1561 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1568 if (REGNO (src
) != STACK_POINTER_REGNUM
1569 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1570 && (unsigned) REGNO (src
) == cfa
.reg
)
1572 /* We're storing the current CFA reg into the stack. */
1574 if (cfa
.offset
== 0)
1576 /* If the source register is exactly the CFA, assume
1577 we're saving SP like any other register; this happens
1579 def_cfa_1 (label
, &cfa
);
1580 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1585 /* Otherwise, we'll need to look in the stack to
1586 calculate the CFA. */
1587 rtx x
= XEXP (dest
, 0);
1589 if (GET_CODE (x
) != REG
)
1591 if (GET_CODE (x
) != REG
)
1594 cfa
.reg
= REGNO (x
);
1595 cfa
.base_offset
= offset
;
1597 def_cfa_1 (label
, &cfa
);
1602 def_cfa_1 (label
, &cfa
);
1603 queue_reg_save (label
, src
, offset
);
1611 /* Record call frame debugging information for INSN, which either
1612 sets SP or FP (adjusting how we calculate the frame address) or saves a
1613 register to the stack. If INSN is NULL_RTX, initialize our state. */
1616 dwarf2out_frame_debug (insn
)
1622 if (insn
== NULL_RTX
)
1624 /* Flush any queued register saves. */
1625 flush_queued_reg_saves ();
1627 /* Set up state for generating call frame debug info. */
1629 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1632 cfa
.reg
= STACK_POINTER_REGNUM
;
1635 cfa_temp
.offset
= 0;
1639 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1640 flush_queued_reg_saves ();
1642 if (! RTX_FRAME_RELATED_P (insn
))
1644 if (!ACCUMULATE_OUTGOING_ARGS
)
1645 dwarf2out_stack_adjust (insn
);
1650 label
= dwarf2out_cfi_label ();
1651 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1653 insn
= XEXP (src
, 0);
1655 insn
= PATTERN (insn
);
1657 dwarf2out_frame_debug_expr (insn
, label
);
1660 /* Output a Call Frame Information opcode and its operand(s). */
1663 output_cfi (cfi
, fde
, for_eh
)
1668 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1669 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1670 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1671 "DW_CFA_advance_loc 0x%lx",
1672 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1673 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1675 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1676 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1677 "DW_CFA_offset, column 0x%lx",
1678 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1679 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1681 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1682 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1683 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1684 "DW_CFA_restore, column 0x%lx",
1685 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1688 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1689 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1691 switch (cfi
->dw_cfi_opc
)
1693 case DW_CFA_set_loc
:
1695 dw2_asm_output_encoded_addr_rtx (
1696 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1697 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1700 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1701 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1704 case DW_CFA_advance_loc1
:
1705 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1706 fde
->dw_fde_current_label
, NULL
);
1707 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1710 case DW_CFA_advance_loc2
:
1711 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1712 fde
->dw_fde_current_label
, NULL
);
1713 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1716 case DW_CFA_advance_loc4
:
1717 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1718 fde
->dw_fde_current_label
, NULL
);
1719 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1722 case DW_CFA_MIPS_advance_loc8
:
1723 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1724 fde
->dw_fde_current_label
, NULL
);
1725 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1728 case DW_CFA_offset_extended
:
1729 case DW_CFA_def_cfa
:
1730 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1732 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1735 case DW_CFA_offset_extended_sf
:
1736 case DW_CFA_def_cfa_sf
:
1737 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1739 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1742 case DW_CFA_restore_extended
:
1743 case DW_CFA_undefined
:
1744 case DW_CFA_same_value
:
1745 case DW_CFA_def_cfa_register
:
1746 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1750 case DW_CFA_register
:
1751 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1753 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1757 case DW_CFA_def_cfa_offset
:
1758 case DW_CFA_GNU_args_size
:
1759 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1762 case DW_CFA_def_cfa_offset_sf
:
1763 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1766 case DW_CFA_GNU_window_save
:
1769 case DW_CFA_def_cfa_expression
:
1770 case DW_CFA_expression
:
1771 output_cfa_loc (cfi
);
1774 case DW_CFA_GNU_negative_offset_extended
:
1775 /* Obsoleted by DW_CFA_offset_extended_sf. */
1784 /* Output the call frame information used to used to record information
1785 that relates to calculating the frame pointer, and records the
1786 location of saved registers. */
1789 output_call_frame_info (for_eh
)
1795 char l1
[20], l2
[20], section_start_label
[20];
1796 int any_lsda_needed
= 0;
1797 char augmentation
[6];
1798 int augmentation_size
;
1799 int fde_encoding
= DW_EH_PE_absptr
;
1800 int per_encoding
= DW_EH_PE_absptr
;
1801 int lsda_encoding
= DW_EH_PE_absptr
;
1803 /* Don't emit a CIE if there won't be any FDEs. */
1804 if (fde_table_in_use
== 0)
1807 /* If we don't have any functions we'll want to unwind out of, don't emit any
1808 EH unwind information. */
1811 int any_eh_needed
= flag_asynchronous_unwind_tables
;
1813 for (i
= 0; i
< fde_table_in_use
; i
++)
1814 if (fde_table
[i
].uses_eh_lsda
)
1815 any_eh_needed
= any_lsda_needed
= 1;
1816 else if (! fde_table
[i
].nothrow
)
1819 if (! any_eh_needed
)
1823 /* We're going to be generating comments, so turn on app. */
1828 (*targetm
.asm_out
.eh_frame_section
) ();
1830 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1832 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1833 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1835 /* Output the CIE. */
1836 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1837 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1838 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1839 "Length of Common Information Entry");
1840 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1842 /* Now that the CIE pointer is PC-relative for EH,
1843 use 0 to identify the CIE. */
1844 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1845 (for_eh
? 0 : DW_CIE_ID
),
1846 "CIE Identifier Tag");
1848 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1850 augmentation
[0] = 0;
1851 augmentation_size
= 0;
1857 z Indicates that a uleb128 is present to size the
1858 augmentation section.
1859 L Indicates the encoding (and thus presence) of
1860 an LSDA pointer in the FDE augmentation.
1861 R Indicates a non-default pointer encoding for
1863 P Indicates the presence of an encoding + language
1864 personality routine in the CIE augmentation. */
1866 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1867 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1868 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1870 p
= augmentation
+ 1;
1871 if (eh_personality_libfunc
)
1874 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1876 if (any_lsda_needed
)
1879 augmentation_size
+= 1;
1881 if (fde_encoding
!= DW_EH_PE_absptr
)
1884 augmentation_size
+= 1;
1886 if (p
> augmentation
+ 1)
1888 augmentation
[0] = 'z';
1892 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1893 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1895 int offset
= ( 4 /* Length */
1897 + 1 /* CIE version */
1898 + strlen (augmentation
) + 1 /* Augmentation */
1899 + size_of_uleb128 (1) /* Code alignment */
1900 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1902 + 1 /* Augmentation size */
1903 + 1 /* Personality encoding */ );
1904 int pad
= -offset
& (PTR_SIZE
- 1);
1906 augmentation_size
+= pad
;
1908 /* Augmentations should be small, so there's scarce need to
1909 iterate for a solution. Die if we exceed one uleb128 byte. */
1910 if (size_of_uleb128 (augmentation_size
) != 1)
1915 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1916 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1917 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1918 "CIE Data Alignment Factor");
1919 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
1921 if (augmentation
[0])
1923 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
1924 if (eh_personality_libfunc
)
1926 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
1927 eh_data_format_name (per_encoding
));
1928 dw2_asm_output_encoded_addr_rtx (per_encoding
,
1929 eh_personality_libfunc
, NULL
);
1932 if (any_lsda_needed
)
1933 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
1934 eh_data_format_name (lsda_encoding
));
1936 if (fde_encoding
!= DW_EH_PE_absptr
)
1937 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
1938 eh_data_format_name (fde_encoding
));
1941 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1942 output_cfi (cfi
, NULL
, for_eh
);
1944 /* Pad the CIE out to an address sized boundary. */
1945 ASM_OUTPUT_ALIGN (asm_out_file
,
1946 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
1947 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1949 /* Loop through all of the FDE's. */
1950 for (i
= 0; i
< fde_table_in_use
; i
++)
1952 fde
= &fde_table
[i
];
1954 /* Don't emit EH unwind info for leaf functions that don't need it. */
1955 if (!flag_asynchronous_unwind_tables
&& for_eh
&& fde
->nothrow
1956 && ! fde
->uses_eh_lsda
)
1959 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
1960 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1961 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1962 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1964 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1967 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
1969 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
1974 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
1975 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
1976 "FDE initial location");
1977 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
1978 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1979 "FDE address range");
1983 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
1984 "FDE initial location");
1985 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
1986 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1987 "FDE address range");
1990 if (augmentation
[0])
1992 if (any_lsda_needed
)
1994 int size
= size_of_encoded_value (lsda_encoding
);
1996 if (lsda_encoding
== DW_EH_PE_aligned
)
1998 int offset
= ( 4 /* Length */
1999 + 4 /* CIE offset */
2000 + 2 * size_of_encoded_value (fde_encoding
)
2001 + 1 /* Augmentation size */ );
2002 int pad
= -offset
& (PTR_SIZE
- 1);
2005 if (size_of_uleb128 (size
) != 1)
2009 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2011 if (fde
->uses_eh_lsda
)
2013 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2014 fde
->funcdef_number
);
2015 dw2_asm_output_encoded_addr_rtx (
2016 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2017 "Language Specific Data Area");
2021 if (lsda_encoding
== DW_EH_PE_aligned
)
2022 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2024 (size_of_encoded_value (lsda_encoding
), 0,
2025 "Language Specific Data Area (none)");
2029 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2032 /* Loop through the Call Frame Instructions associated with
2034 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2035 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2036 output_cfi (cfi
, fde
, for_eh
);
2038 /* Pad the FDE out to an address sized boundary. */
2039 ASM_OUTPUT_ALIGN (asm_out_file
,
2040 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2041 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2044 #ifndef EH_FRAME_SECTION_NAME
2046 dw2_asm_output_data (4, 0, "End of Table");
2048 #ifdef MIPS_DEBUGGING_INFO
2049 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2050 get a value of 0. Putting .align 0 after the label fixes it. */
2051 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2054 /* Turn off app to make assembly quicker. */
2059 /* Output a marker (i.e. a label) for the beginning of a function, before
2063 dwarf2out_begin_prologue (line
, file
)
2064 unsigned int line ATTRIBUTE_UNUSED
;
2065 const char *file ATTRIBUTE_UNUSED
;
2067 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2070 current_function_func_begin_label
= 0;
2072 #ifdef IA64_UNWIND_INFO
2073 /* ??? current_function_func_begin_label is also used by except.c
2074 for call-site information. We must emit this label if it might
2076 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2077 && ! dwarf2out_do_frame ())
2080 if (! dwarf2out_do_frame ())
2084 function_section (current_function_decl
);
2085 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2086 current_function_funcdef_no
);
2087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2088 current_function_funcdef_no
);
2089 current_function_func_begin_label
= get_identifier (label
);
2091 #ifdef IA64_UNWIND_INFO
2092 /* We can elide the fde allocation if we're not emitting debug info. */
2093 if (! dwarf2out_do_frame ())
2097 /* Expand the fde table if necessary. */
2098 if (fde_table_in_use
== fde_table_allocated
)
2100 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2102 = (dw_fde_ref
) xrealloc (fde_table
,
2103 fde_table_allocated
* sizeof (dw_fde_node
));
2106 /* Record the FDE associated with this function. */
2107 current_funcdef_fde
= fde_table_in_use
;
2109 /* Add the new FDE at the end of the fde_table. */
2110 fde
= &fde_table
[fde_table_in_use
++];
2111 fde
->dw_fde_begin
= xstrdup (label
);
2112 fde
->dw_fde_current_label
= NULL
;
2113 fde
->dw_fde_end
= NULL
;
2114 fde
->dw_fde_cfi
= NULL
;
2115 fde
->funcdef_number
= current_function_funcdef_no
;
2116 fde
->nothrow
= current_function_nothrow
;
2117 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2119 args_size
= old_args_size
= 0;
2121 /* We only want to output line number information for the genuine dwarf2
2122 prologue case, not the eh frame case. */
2123 #ifdef DWARF2_DEBUGGING_INFO
2125 dwarf2out_source_line (line
, file
);
2129 /* Output a marker (i.e. a label) for the absolute end of the generated code
2130 for a function definition. This gets called *after* the epilogue code has
2134 dwarf2out_end_epilogue (line
, file
)
2135 unsigned int line ATTRIBUTE_UNUSED
;
2136 const char *file ATTRIBUTE_UNUSED
;
2139 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2141 /* Output a label to mark the endpoint of the code generated for this
2143 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2144 current_function_funcdef_no
);
2145 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2146 fde
= &fde_table
[fde_table_in_use
- 1];
2147 fde
->dw_fde_end
= xstrdup (label
);
2151 dwarf2out_frame_init ()
2153 /* Allocate the initial hunk of the fde_table. */
2154 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2155 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2156 fde_table_in_use
= 0;
2158 /* Generate the CFA instructions common to all FDE's. Do it now for the
2159 sake of lookup_cfa. */
2161 #ifdef DWARF2_UNWIND_INFO
2162 /* On entry, the Canonical Frame Address is at SP. */
2163 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2164 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2169 dwarf2out_frame_finish ()
2171 /* Output call frame information. */
2172 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2173 output_call_frame_info (0);
2175 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2176 output_call_frame_info (1);
2179 /* And now, the subset of the debugging information support code necessary
2180 for emitting location expressions. */
2182 typedef struct dw_val_struct
*dw_val_ref
;
2183 typedef struct die_struct
*dw_die_ref
;
2184 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2185 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2187 /* Each DIE may have a series of attribute/value pairs. Values
2188 can take on several forms. The forms that are used in this
2189 implementation are listed below. */
2194 dw_val_class_offset
,
2196 dw_val_class_loc_list
,
2197 dw_val_class_range_list
,
2199 dw_val_class_unsigned_const
,
2200 dw_val_class_long_long
,
2203 dw_val_class_die_ref
,
2204 dw_val_class_fde_ref
,
2205 dw_val_class_lbl_id
,
2206 dw_val_class_lbl_offset
,
2211 /* Describe a double word constant value. */
2212 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2214 typedef struct dw_long_long_struct
2221 /* Describe a floating point constant value. */
2223 typedef struct dw_fp_struct
2230 /* The dw_val_node describes an attribute's value, as it is
2231 represented internally. */
2233 typedef struct dw_val_struct
2235 dw_val_class val_class
;
2239 long unsigned val_offset
;
2240 dw_loc_list_ref val_loc_list
;
2241 dw_loc_descr_ref val_loc
;
2243 long unsigned val_unsigned
;
2244 dw_long_long_const val_long_long
;
2245 dw_float_const val_float
;
2251 unsigned val_fde_index
;
2252 struct indirect_string_node
*val_str
;
2254 unsigned char val_flag
;
2260 /* Locations in memory are described using a sequence of stack machine
2263 typedef struct dw_loc_descr_struct
2265 dw_loc_descr_ref dw_loc_next
;
2266 enum dwarf_location_atom dw_loc_opc
;
2267 dw_val_node dw_loc_oprnd1
;
2268 dw_val_node dw_loc_oprnd2
;
2273 /* Location lists are ranges + location descriptions for that range,
2274 so you can track variables that are in different places over
2275 their entire life. */
2276 typedef struct dw_loc_list_struct
2278 dw_loc_list_ref dw_loc_next
;
2279 const char *begin
; /* Label for begin address of range */
2280 const char *end
; /* Label for end address of range */
2281 char *ll_symbol
; /* Label for beginning of location list.
2282 Only on head of list */
2283 const char *section
; /* Section this loclist is relative to */
2284 dw_loc_descr_ref expr
;
2287 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2288 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2291 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2293 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2294 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2295 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2296 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2298 /* Convert a DWARF stack opcode into its string name. */
2301 dwarf_stack_op_name (op
)
2307 return "DW_OP_addr";
2309 return "DW_OP_deref";
2311 return "DW_OP_const1u";
2313 return "DW_OP_const1s";
2315 return "DW_OP_const2u";
2317 return "DW_OP_const2s";
2319 return "DW_OP_const4u";
2321 return "DW_OP_const4s";
2323 return "DW_OP_const8u";
2325 return "DW_OP_const8s";
2327 return "DW_OP_constu";
2329 return "DW_OP_consts";
2333 return "DW_OP_drop";
2335 return "DW_OP_over";
2337 return "DW_OP_pick";
2339 return "DW_OP_swap";
2343 return "DW_OP_xderef";
2351 return "DW_OP_minus";
2363 return "DW_OP_plus";
2364 case DW_OP_plus_uconst
:
2365 return "DW_OP_plus_uconst";
2371 return "DW_OP_shra";
2389 return "DW_OP_skip";
2391 return "DW_OP_lit0";
2393 return "DW_OP_lit1";
2395 return "DW_OP_lit2";
2397 return "DW_OP_lit3";
2399 return "DW_OP_lit4";
2401 return "DW_OP_lit5";
2403 return "DW_OP_lit6";
2405 return "DW_OP_lit7";
2407 return "DW_OP_lit8";
2409 return "DW_OP_lit9";
2411 return "DW_OP_lit10";
2413 return "DW_OP_lit11";
2415 return "DW_OP_lit12";
2417 return "DW_OP_lit13";
2419 return "DW_OP_lit14";
2421 return "DW_OP_lit15";
2423 return "DW_OP_lit16";
2425 return "DW_OP_lit17";
2427 return "DW_OP_lit18";
2429 return "DW_OP_lit19";
2431 return "DW_OP_lit20";
2433 return "DW_OP_lit21";
2435 return "DW_OP_lit22";
2437 return "DW_OP_lit23";
2439 return "DW_OP_lit24";
2441 return "DW_OP_lit25";
2443 return "DW_OP_lit26";
2445 return "DW_OP_lit27";
2447 return "DW_OP_lit28";
2449 return "DW_OP_lit29";
2451 return "DW_OP_lit30";
2453 return "DW_OP_lit31";
2455 return "DW_OP_reg0";
2457 return "DW_OP_reg1";
2459 return "DW_OP_reg2";
2461 return "DW_OP_reg3";
2463 return "DW_OP_reg4";
2465 return "DW_OP_reg5";
2467 return "DW_OP_reg6";
2469 return "DW_OP_reg7";
2471 return "DW_OP_reg8";
2473 return "DW_OP_reg9";
2475 return "DW_OP_reg10";
2477 return "DW_OP_reg11";
2479 return "DW_OP_reg12";
2481 return "DW_OP_reg13";
2483 return "DW_OP_reg14";
2485 return "DW_OP_reg15";
2487 return "DW_OP_reg16";
2489 return "DW_OP_reg17";
2491 return "DW_OP_reg18";
2493 return "DW_OP_reg19";
2495 return "DW_OP_reg20";
2497 return "DW_OP_reg21";
2499 return "DW_OP_reg22";
2501 return "DW_OP_reg23";
2503 return "DW_OP_reg24";
2505 return "DW_OP_reg25";
2507 return "DW_OP_reg26";
2509 return "DW_OP_reg27";
2511 return "DW_OP_reg28";
2513 return "DW_OP_reg29";
2515 return "DW_OP_reg30";
2517 return "DW_OP_reg31";
2519 return "DW_OP_breg0";
2521 return "DW_OP_breg1";
2523 return "DW_OP_breg2";
2525 return "DW_OP_breg3";
2527 return "DW_OP_breg4";
2529 return "DW_OP_breg5";
2531 return "DW_OP_breg6";
2533 return "DW_OP_breg7";
2535 return "DW_OP_breg8";
2537 return "DW_OP_breg9";
2539 return "DW_OP_breg10";
2541 return "DW_OP_breg11";
2543 return "DW_OP_breg12";
2545 return "DW_OP_breg13";
2547 return "DW_OP_breg14";
2549 return "DW_OP_breg15";
2551 return "DW_OP_breg16";
2553 return "DW_OP_breg17";
2555 return "DW_OP_breg18";
2557 return "DW_OP_breg19";
2559 return "DW_OP_breg20";
2561 return "DW_OP_breg21";
2563 return "DW_OP_breg22";
2565 return "DW_OP_breg23";
2567 return "DW_OP_breg24";
2569 return "DW_OP_breg25";
2571 return "DW_OP_breg26";
2573 return "DW_OP_breg27";
2575 return "DW_OP_breg28";
2577 return "DW_OP_breg29";
2579 return "DW_OP_breg30";
2581 return "DW_OP_breg31";
2583 return "DW_OP_regx";
2585 return "DW_OP_fbreg";
2587 return "DW_OP_bregx";
2589 return "DW_OP_piece";
2590 case DW_OP_deref_size
:
2591 return "DW_OP_deref_size";
2592 case DW_OP_xderef_size
:
2593 return "DW_OP_xderef_size";
2597 return "OP_<unknown>";
2601 /* Return a pointer to a newly allocated location description. Location
2602 descriptions are simple expression terms that can be strung
2603 together to form more complicated location (address) descriptions. */
2605 static inline dw_loc_descr_ref
2606 new_loc_descr (op
, oprnd1
, oprnd2
)
2607 enum dwarf_location_atom op
;
2608 unsigned long oprnd1
;
2609 unsigned long oprnd2
;
2611 /* Use xcalloc here so we clear out all of the long_long constant in
2613 dw_loc_descr_ref descr
2614 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2616 descr
->dw_loc_opc
= op
;
2617 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2618 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2619 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2620 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2626 /* Add a location description term to a location description expression. */
2629 add_loc_descr (list_head
, descr
)
2630 dw_loc_descr_ref
*list_head
;
2631 dw_loc_descr_ref descr
;
2633 dw_loc_descr_ref
*d
;
2635 /* Find the end of the chain. */
2636 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2642 /* Return the size of a location descriptor. */
2644 static unsigned long
2645 size_of_loc_descr (loc
)
2646 dw_loc_descr_ref loc
;
2648 unsigned long size
= 1;
2650 switch (loc
->dw_loc_opc
)
2653 size
+= DWARF2_ADDR_SIZE
;
2672 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2675 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2680 case DW_OP_plus_uconst
:
2681 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2719 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2722 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2725 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2728 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2729 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2732 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2734 case DW_OP_deref_size
:
2735 case DW_OP_xderef_size
:
2745 /* Return the size of a series of location descriptors. */
2747 static unsigned long
2749 dw_loc_descr_ref loc
;
2753 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2755 loc
->dw_loc_addr
= size
;
2756 size
+= size_of_loc_descr (loc
);
2762 /* Output location description stack opcode's operands (if any). */
2765 output_loc_operands (loc
)
2766 dw_loc_descr_ref loc
;
2768 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2769 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2771 switch (loc
->dw_loc_opc
)
2773 #ifdef DWARF2_DEBUGGING_INFO
2775 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2779 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2783 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2787 if (HOST_BITS_PER_LONG
< 64)
2789 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2796 if (val1
->val_class
== dw_val_class_loc
)
2797 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2801 dw2_asm_output_data (2, offset
, NULL
);
2814 /* We currently don't make any attempt to make sure these are
2815 aligned properly like we do for the main unwind info, so
2816 don't support emitting things larger than a byte if we're
2817 only doing unwinding. */
2822 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2825 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2828 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2831 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2833 case DW_OP_plus_uconst
:
2834 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2868 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2871 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2874 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2877 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2878 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2881 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2883 case DW_OP_deref_size
:
2884 case DW_OP_xderef_size
:
2885 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2888 /* Other codes have no operands. */
2893 /* Output a sequence of location operations. */
2896 output_loc_sequence (loc
)
2897 dw_loc_descr_ref loc
;
2899 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2901 /* Output the opcode. */
2902 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2903 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2905 /* Output the operand(s) (if any). */
2906 output_loc_operands (loc
);
2910 /* This routine will generate the correct assembly data for a location
2911 description based on a cfi entry with a complex address. */
2914 output_cfa_loc (cfi
)
2917 dw_loc_descr_ref loc
;
2920 /* Output the size of the block. */
2921 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2922 size
= size_of_locs (loc
);
2923 dw2_asm_output_data_uleb128 (size
, NULL
);
2925 /* Now output the operations themselves. */
2926 output_loc_sequence (loc
);
2929 /* This function builds a dwarf location descriptor sequence from
2930 a dw_cfa_location. */
2932 static struct dw_loc_descr_struct
*
2934 dw_cfa_location
*cfa
;
2936 struct dw_loc_descr_struct
*head
, *tmp
;
2938 if (cfa
->indirect
== 0)
2941 if (cfa
->base_offset
)
2944 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
2946 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
2948 else if (cfa
->reg
<= 31)
2949 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
2951 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
2953 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2954 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2955 add_loc_descr (&head
, tmp
);
2956 if (cfa
->offset
!= 0)
2958 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
2959 add_loc_descr (&head
, tmp
);
2965 /* This function fills in aa dw_cfa_location structure from a dwarf location
2966 descriptor sequence. */
2969 get_cfa_from_loc_descr (cfa
, loc
)
2970 dw_cfa_location
*cfa
;
2971 struct dw_loc_descr_struct
*loc
;
2973 struct dw_loc_descr_struct
*ptr
;
2975 cfa
->base_offset
= 0;
2979 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
2981 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3017 cfa
->reg
= op
- DW_OP_reg0
;
3020 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3054 cfa
->reg
= op
- DW_OP_breg0
;
3055 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3058 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3059 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3064 case DW_OP_plus_uconst
:
3065 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3068 internal_error ("DW_LOC_OP %s not implemented\n",
3069 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3073 #endif /* .debug_frame support */
3075 /* And now, the support for symbolic debugging information. */
3076 #ifdef DWARF2_DEBUGGING_INFO
3078 /* .debug_str support. */
3079 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3080 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3081 hashnode
, const PTR
));
3084 static void dwarf2out_init
PARAMS ((const char *));
3085 static void dwarf2out_finish
PARAMS ((const char *));
3086 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3087 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3088 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3089 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3090 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3091 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3092 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3093 static void dwarf2out_global_decl
PARAMS ((tree
));
3094 static void dwarf2out_abstract_function
PARAMS ((tree
));
3096 /* The debug hooks structure. */
3098 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3104 dwarf2out_start_source_file
,
3105 dwarf2out_end_source_file
,
3106 dwarf2out_begin_block
,
3107 dwarf2out_end_block
,
3108 dwarf2out_ignore_block
,
3109 dwarf2out_source_line
,
3110 dwarf2out_begin_prologue
,
3111 debug_nothing_int_charstar
, /* end_prologue */
3112 dwarf2out_end_epilogue
,
3113 debug_nothing_tree
, /* begin_function */
3114 debug_nothing_int
, /* end_function */
3115 dwarf2out_decl
, /* function_decl */
3116 dwarf2out_global_decl
,
3117 debug_nothing_tree
, /* deferred_inline_function */
3118 /* The DWARF 2 backend tries to reduce debugging bloat by not
3119 emitting the abstract description of inline functions until
3120 something tries to reference them. */
3121 dwarf2out_abstract_function
, /* outlining_inline_function */
3122 debug_nothing_rtx
/* label */
3125 /* NOTE: In the comments in this file, many references are made to
3126 "Debugging Information Entries". This term is abbreviated as `DIE'
3127 throughout the remainder of this file. */
3129 /* An internal representation of the DWARF output is built, and then
3130 walked to generate the DWARF debugging info. The walk of the internal
3131 representation is done after the entire program has been compiled.
3132 The types below are used to describe the internal representation. */
3134 /* Various DIE's use offsets relative to the beginning of the
3135 .debug_info section to refer to each other. */
3137 typedef long int dw_offset
;
3139 /* Define typedefs here to avoid circular dependencies. */
3141 typedef struct dw_attr_struct
*dw_attr_ref
;
3142 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3143 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3144 typedef struct pubname_struct
*pubname_ref
;
3145 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3147 /* Each entry in the line_info_table maintains the file and
3148 line number associated with the label generated for that
3149 entry. The label gives the PC value associated with
3150 the line number entry. */
3152 typedef struct dw_line_info_struct
3154 unsigned long dw_file_num
;
3155 unsigned long dw_line_num
;
3159 /* Line information for functions in separate sections; each one gets its
3161 typedef struct dw_separate_line_info_struct
3163 unsigned long dw_file_num
;
3164 unsigned long dw_line_num
;
3165 unsigned long function
;
3167 dw_separate_line_info_entry
;
3169 /* Each DIE attribute has a field specifying the attribute kind,
3170 a link to the next attribute in the chain, and an attribute value.
3171 Attributes are typically linked below the DIE they modify. */
3173 typedef struct dw_attr_struct
3175 enum dwarf_attribute dw_attr
;
3176 dw_attr_ref dw_attr_next
;
3177 dw_val_node dw_attr_val
;
3181 /* The Debugging Information Entry (DIE) structure */
3183 typedef struct die_struct
3185 enum dwarf_tag die_tag
;
3187 dw_attr_ref die_attr
;
3188 dw_die_ref die_parent
;
3189 dw_die_ref die_child
;
3191 dw_offset die_offset
;
3192 unsigned long die_abbrev
;
3197 /* The pubname structure */
3199 typedef struct pubname_struct
3206 struct dw_ranges_struct
3211 /* The limbo die list structure. */
3212 typedef struct limbo_die_struct
3216 struct limbo_die_struct
*next
;
3220 /* How to start an assembler comment. */
3221 #ifndef ASM_COMMENT_START
3222 #define ASM_COMMENT_START ";#"
3225 /* Define a macro which returns non-zero for a TYPE_DECL which was
3226 implicitly generated for a tagged type.
3228 Note that unlike the gcc front end (which generates a NULL named
3229 TYPE_DECL node for each complete tagged type, each array type, and
3230 each function type node created) the g++ front end generates a
3231 _named_ TYPE_DECL node for each tagged type node created.
3232 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3233 generate a DW_TAG_typedef DIE for them. */
3235 #define TYPE_DECL_IS_STUB(decl) \
3236 (DECL_NAME (decl) == NULL_TREE \
3237 || (DECL_ARTIFICIAL (decl) \
3238 && is_tagged_type (TREE_TYPE (decl)) \
3239 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3240 /* This is necessary for stub decls that \
3241 appear in nested inline functions. */ \
3242 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3243 && (decl_ultimate_origin (decl) \
3244 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3246 /* Information concerning the compilation unit's programming
3247 language, and compiler version. */
3249 /* Fixed size portion of the DWARF compilation unit header. */
3250 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3252 /* Fixed size portion of public names info. */
3253 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3255 /* Fixed size portion of the address range info. */
3256 #define DWARF_ARANGES_HEADER_SIZE \
3257 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3258 - DWARF_OFFSET_SIZE)
3260 /* Size of padding portion in the address range info. It must be
3261 aligned to twice the pointer size. */
3262 #define DWARF_ARANGES_PAD_SIZE \
3263 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3264 - (2 * DWARF_OFFSET_SIZE + 4))
3266 /* Use assembler line directives if available. */
3267 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3268 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3269 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3271 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3275 /* Minimum line offset in a special line info. opcode.
3276 This value was chosen to give a reasonable range of values. */
3277 #define DWARF_LINE_BASE -10
3279 /* First special line opcode - leave room for the standard opcodes. */
3280 #define DWARF_LINE_OPCODE_BASE 10
3282 /* Range of line offsets in a special line info. opcode. */
3283 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3285 /* Flag that indicates the initial value of the is_stmt_start flag.
3286 In the present implementation, we do not mark any lines as
3287 the beginning of a source statement, because that information
3288 is not made available by the GCC front-end. */
3289 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3291 /* This location is used by calc_die_sizes() to keep track
3292 the offset of each DIE within the .debug_info section. */
3293 static unsigned long next_die_offset
;
3295 /* Record the root of the DIE's built for the current compilation unit. */
3296 static dw_die_ref comp_unit_die
;
3298 /* A list of DIEs with a NULL parent waiting to be relocated. */
3299 static limbo_die_node
*limbo_die_list
= 0;
3301 /* Structure used by lookup_filename to manage sets of filenames. */
3307 unsigned last_lookup_index
;
3310 /* Size (in elements) of increments by which we may expand the filename
3312 #define FILE_TABLE_INCREMENT 64
3314 /* Filenames referenced by this compilation unit. */
3315 static struct file_table file_table
;
3317 /* Local pointer to the name of the main input file. Initialized in
3319 static const char *primary_filename
;
3321 /* A pointer to the base of a table of references to DIE's that describe
3322 declarations. The table is indexed by DECL_UID() which is a unique
3323 number identifying each decl. */
3324 static dw_die_ref
*decl_die_table
;
3326 /* Number of elements currently allocated for the decl_die_table. */
3327 static unsigned decl_die_table_allocated
;
3329 /* Number of elements in decl_die_table currently in use. */
3330 static unsigned decl_die_table_in_use
;
3332 /* Size (in elements) of increments by which we may expand the
3334 #define DECL_DIE_TABLE_INCREMENT 256
3336 /* A pointer to the base of a list of references to DIE's that
3337 are uniquely identified by their tag, presence/absence of
3338 children DIE's, and list of attribute/value pairs. */
3339 static dw_die_ref
*abbrev_die_table
;
3341 /* Number of elements currently allocated for abbrev_die_table. */
3342 static unsigned abbrev_die_table_allocated
;
3344 /* Number of elements in type_die_table currently in use. */
3345 static unsigned abbrev_die_table_in_use
;
3347 /* Size (in elements) of increments by which we may expand the
3348 abbrev_die_table. */
3349 #define ABBREV_DIE_TABLE_INCREMENT 256
3351 /* A pointer to the base of a table that contains line information
3352 for each source code line in .text in the compilation unit. */
3353 static dw_line_info_ref line_info_table
;
3355 /* Number of elements currently allocated for line_info_table. */
3356 static unsigned line_info_table_allocated
;
3358 /* Number of elements in separate_line_info_table currently in use. */
3359 static unsigned separate_line_info_table_in_use
;
3361 /* A pointer to the base of a table that contains line information
3362 for each source code line outside of .text in the compilation unit. */
3363 static dw_separate_line_info_ref separate_line_info_table
;
3365 /* Number of elements currently allocated for separate_line_info_table. */
3366 static unsigned separate_line_info_table_allocated
;
3368 /* Number of elements in line_info_table currently in use. */
3369 static unsigned line_info_table_in_use
;
3371 /* Size (in elements) of increments by which we may expand the
3373 #define LINE_INFO_TABLE_INCREMENT 1024
3375 /* A pointer to the base of a table that contains a list of publicly
3376 accessible names. */
3377 static pubname_ref pubname_table
;
3379 /* Number of elements currently allocated for pubname_table. */
3380 static unsigned pubname_table_allocated
;
3382 /* Number of elements in pubname_table currently in use. */
3383 static unsigned pubname_table_in_use
;
3385 /* Size (in elements) of increments by which we may expand the
3387 #define PUBNAME_TABLE_INCREMENT 64
3389 /* Array of dies for which we should generate .debug_arange info. */
3390 static dw_die_ref
*arange_table
;
3392 /* Number of elements currently allocated for arange_table. */
3393 static unsigned arange_table_allocated
;
3395 /* Number of elements in arange_table currently in use. */
3396 static unsigned arange_table_in_use
;
3398 /* Size (in elements) of increments by which we may expand the
3400 #define ARANGE_TABLE_INCREMENT 64
3402 /* Array of dies for which we should generate .debug_ranges info. */
3403 static dw_ranges_ref ranges_table
;
3405 /* Number of elements currently allocated for ranges_table. */
3406 static unsigned ranges_table_allocated
;
3408 /* Number of elements in ranges_table currently in use. */
3409 static unsigned ranges_table_in_use
;
3411 /* Size (in elements) of increments by which we may expand the
3413 #define RANGES_TABLE_INCREMENT 64
3415 /* Whether we have location lists that need outputting */
3416 static unsigned have_location_lists
;
3418 /* Record whether the function being analyzed contains inlined functions. */
3419 static int current_function_has_inlines
;
3420 #if 0 && defined (MIPS_DEBUGGING_INFO)
3421 static int comp_unit_has_inlines
;
3424 /* Forward declarations for functions defined in this file. */
3426 static int is_pseudo_reg
PARAMS ((rtx
));
3427 static tree type_main_variant
PARAMS ((tree
));
3428 static int is_tagged_type
PARAMS ((tree
));
3429 static const char *dwarf_tag_name
PARAMS ((unsigned));
3430 static const char *dwarf_attr_name
PARAMS ((unsigned));
3431 static const char *dwarf_form_name
PARAMS ((unsigned));
3433 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3435 static tree decl_ultimate_origin
PARAMS ((tree
));
3436 static tree block_ultimate_origin
PARAMS ((tree
));
3437 static tree decl_class_context
PARAMS ((tree
));
3438 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3439 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3440 static void add_AT_flag
PARAMS ((dw_die_ref
,
3441 enum dwarf_attribute
,
3443 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3444 static void add_AT_int
PARAMS ((dw_die_ref
,
3445 enum dwarf_attribute
, long));
3446 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3447 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3448 enum dwarf_attribute
,
3450 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3451 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3452 enum dwarf_attribute
,
3455 static void add_AT_float
PARAMS ((dw_die_ref
,
3456 enum dwarf_attribute
,
3458 static void add_AT_string
PARAMS ((dw_die_ref
,
3459 enum dwarf_attribute
,
3461 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3462 static int AT_string_form
PARAMS ((dw_attr_ref
));
3463 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3464 enum dwarf_attribute
,
3466 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3467 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3468 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3469 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3470 enum dwarf_attribute
,
3472 static void add_AT_loc
PARAMS ((dw_die_ref
,
3473 enum dwarf_attribute
,
3475 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3476 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3477 enum dwarf_attribute
,
3479 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3480 static void add_AT_addr
PARAMS ((dw_die_ref
,
3481 enum dwarf_attribute
,
3483 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3484 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3485 enum dwarf_attribute
,
3487 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3488 enum dwarf_attribute
,
3490 static void add_AT_offset
PARAMS ((dw_die_ref
,
3491 enum dwarf_attribute
,
3493 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3494 enum dwarf_attribute
,
3496 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3497 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3498 enum dwarf_attribute
));
3499 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3500 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3501 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3502 enum dwarf_attribute
));
3503 static int get_AT_flag
PARAMS ((dw_die_ref
,
3504 enum dwarf_attribute
));
3505 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3506 enum dwarf_attribute
));
3507 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3508 enum dwarf_attribute
));
3509 static int is_c_family
PARAMS ((void));
3510 static int is_cxx
PARAMS ((void));
3511 static int is_java
PARAMS ((void));
3512 static int is_fortran
PARAMS ((void));
3513 static void remove_AT
PARAMS ((dw_die_ref
,
3514 enum dwarf_attribute
));
3515 static inline void free_die
PARAMS ((dw_die_ref
));
3516 static void remove_children
PARAMS ((dw_die_ref
));
3517 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3518 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3520 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3521 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3522 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3523 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3524 static void print_spaces
PARAMS ((FILE *));
3525 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3526 static void print_dwarf_line_table
PARAMS ((FILE *));
3527 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3528 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3529 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3530 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3531 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3533 static void attr_checksum
PARAMS ((dw_attr_ref
,
3535 static void die_checksum
PARAMS ((dw_die_ref
,
3537 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3538 static int is_type_die
PARAMS ((dw_die_ref
));
3539 static int is_comdat_die
PARAMS ((dw_die_ref
));
3540 static int is_symbol_die
PARAMS ((dw_die_ref
));
3541 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3542 static void break_out_includes
PARAMS ((dw_die_ref
));
3543 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3544 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3545 static void output_location_lists
PARAMS ((dw_die_ref
));
3546 static int constant_size
PARAMS ((long unsigned));
3547 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3548 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3549 static void mark_dies
PARAMS ((dw_die_ref
));
3550 static void unmark_dies
PARAMS ((dw_die_ref
));
3551 static unsigned long size_of_pubnames
PARAMS ((void));
3552 static unsigned long size_of_aranges
PARAMS ((void));
3553 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3554 static void output_value_format
PARAMS ((dw_attr_ref
));
3555 static void output_abbrev_section
PARAMS ((void));
3556 static void output_die_symbol
PARAMS ((dw_die_ref
));
3557 static void output_die
PARAMS ((dw_die_ref
));
3558 static void output_compilation_unit_header
PARAMS ((void));
3559 static void output_comp_unit
PARAMS ((dw_die_ref
));
3560 static const char *dwarf2_name
PARAMS ((tree
, int));
3561 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3562 static void output_pubnames
PARAMS ((void));
3563 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3564 static void output_aranges
PARAMS ((void));
3565 static unsigned int add_ranges
PARAMS ((tree
));
3566 static void output_ranges
PARAMS ((void));
3567 static void output_line_info
PARAMS ((void));
3568 static void output_file_names
PARAMS ((void));
3569 static dw_die_ref base_type_die
PARAMS ((tree
));
3570 static tree root_type
PARAMS ((tree
));
3571 static int is_base_type
PARAMS ((tree
));
3572 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3573 static int type_is_enum
PARAMS ((tree
));
3574 static unsigned int reg_number
PARAMS ((rtx
));
3575 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3576 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3577 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3578 static int is_based_loc
PARAMS ((rtx
));
3579 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3580 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3581 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3582 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3583 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3584 static tree field_type
PARAMS ((tree
));
3585 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3586 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3587 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3588 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3589 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3590 enum dwarf_attribute
, rtx
));
3591 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3592 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3593 static rtx rtl_for_decl_location
PARAMS ((tree
));
3594 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3595 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3596 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3597 static void add_bound_info
PARAMS ((dw_die_ref
,
3598 enum dwarf_attribute
, tree
));
3599 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3600 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3601 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3602 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3603 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3604 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3605 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3606 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3607 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3608 static void push_decl_scope
PARAMS ((tree
));
3609 static void pop_decl_scope
PARAMS ((void));
3610 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3611 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3612 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3613 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3615 static const char *type_tag
PARAMS ((tree
));
3616 static tree member_declared_type
PARAMS ((tree
));
3618 static const char *decl_start_label
PARAMS ((tree
));
3620 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3621 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3623 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3625 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3626 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3627 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3628 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3629 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3630 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3631 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3632 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3633 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3634 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3635 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3636 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3637 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3638 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3639 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3640 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3641 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3642 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3643 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3644 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3645 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3646 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3647 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3648 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3649 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3650 static int is_redundant_typedef
PARAMS ((tree
));
3651 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3652 static unsigned lookup_filename
PARAMS ((const char *));
3653 static void init_file_table
PARAMS ((void));
3654 static void retry_incomplete_types
PARAMS ((void));
3655 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3656 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3657 static int file_info_cmp
PARAMS ((const void *, const void *));
3658 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3659 const char *, const char *,
3660 const char *, unsigned));
3661 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3663 const char *, const char *, const char *));
3664 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3665 static char *gen_internal_sym
PARAMS ((const char *));
3666 static void mark_limbo_die_list
PARAMS ((void *));
3668 /* Section names used to hold DWARF debugging information. */
3669 #ifndef DEBUG_INFO_SECTION
3670 #define DEBUG_INFO_SECTION ".debug_info"
3672 #ifndef DEBUG_ABBREV_SECTION
3673 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3675 #ifndef DEBUG_ARANGES_SECTION
3676 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3678 #ifndef DEBUG_MACINFO_SECTION
3679 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3681 #ifndef DEBUG_LINE_SECTION
3682 #define DEBUG_LINE_SECTION ".debug_line"
3684 #ifndef DEBUG_LOC_SECTION
3685 #define DEBUG_LOC_SECTION ".debug_loc"
3687 #ifndef DEBUG_PUBNAMES_SECTION
3688 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3690 #ifndef DEBUG_STR_SECTION
3691 #define DEBUG_STR_SECTION ".debug_str"
3693 #ifndef DEBUG_RANGES_SECTION
3694 #define DEBUG_RANGES_SECTION ".debug_ranges"
3697 /* Standard ELF section names for compiled code and data. */
3698 #ifndef TEXT_SECTION_NAME
3699 #define TEXT_SECTION_NAME ".text"
3702 /* Section flags for .debug_str section. */
3703 #ifdef HAVE_GAS_SHF_MERGE
3704 #define DEBUG_STR_SECTION_FLAGS \
3705 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3707 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3710 /* Labels we insert at beginning sections we can reference instead of
3711 the section names themselves. */
3713 #ifndef TEXT_SECTION_LABEL
3714 #define TEXT_SECTION_LABEL "Ltext"
3716 #ifndef DEBUG_LINE_SECTION_LABEL
3717 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3719 #ifndef DEBUG_INFO_SECTION_LABEL
3720 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3722 #ifndef DEBUG_ABBREV_SECTION_LABEL
3723 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3725 #ifndef DEBUG_LOC_SECTION_LABEL
3726 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3728 #ifndef DEBUG_RANGES_SECTION_LABEL
3729 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3731 #ifndef DEBUG_MACINFO_SECTION_LABEL
3732 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3735 /* Definitions of defaults for formats and names of various special
3736 (artificial) labels which may be generated within this file (when the -g
3737 options is used and DWARF_DEBUGGING_INFO is in effect.
3738 If necessary, these may be overridden from within the tm.h file, but
3739 typically, overriding these defaults is unnecessary. */
3741 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3742 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3743 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3744 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3745 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3746 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3747 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3748 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3750 #ifndef TEXT_END_LABEL
3751 #define TEXT_END_LABEL "Letext"
3753 #ifndef BLOCK_BEGIN_LABEL
3754 #define BLOCK_BEGIN_LABEL "LBB"
3756 #ifndef BLOCK_END_LABEL
3757 #define BLOCK_END_LABEL "LBE"
3759 #ifndef LINE_CODE_LABEL
3760 #define LINE_CODE_LABEL "LM"
3762 #ifndef SEPARATE_LINE_CODE_LABEL
3763 #define SEPARATE_LINE_CODE_LABEL "LSM"
3766 /* We allow a language front-end to designate a function that is to be
3767 called to "demangle" any name before it it put into a DIE. */
3769 static const char *(*demangle_name_func
) PARAMS ((const char *));
3772 dwarf2out_set_demangle_name_func (func
)
3773 const char *(*func
) PARAMS ((const char *));
3775 demangle_name_func
= func
;
3778 /* Test if rtl node points to a pseudo register. */
3784 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3785 || (GET_CODE (rtl
) == SUBREG
3786 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3789 /* Return a reference to a type, with its const and volatile qualifiers
3793 type_main_variant (type
)
3796 type
= TYPE_MAIN_VARIANT (type
);
3798 /* ??? There really should be only one main variant among any group of
3799 variants of a given type (and all of the MAIN_VARIANT values for all
3800 members of the group should point to that one type) but sometimes the C
3801 front-end messes this up for array types, so we work around that bug
3803 if (TREE_CODE (type
) == ARRAY_TYPE
)
3804 while (type
!= TYPE_MAIN_VARIANT (type
))
3805 type
= TYPE_MAIN_VARIANT (type
);
3810 /* Return non-zero if the given type node represents a tagged type. */
3813 is_tagged_type (type
)
3816 enum tree_code code
= TREE_CODE (type
);
3818 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3819 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3822 /* Convert a DIE tag into its string name. */
3825 dwarf_tag_name (tag
)
3830 case DW_TAG_padding
:
3831 return "DW_TAG_padding";
3832 case DW_TAG_array_type
:
3833 return "DW_TAG_array_type";
3834 case DW_TAG_class_type
:
3835 return "DW_TAG_class_type";
3836 case DW_TAG_entry_point
:
3837 return "DW_TAG_entry_point";
3838 case DW_TAG_enumeration_type
:
3839 return "DW_TAG_enumeration_type";
3840 case DW_TAG_formal_parameter
:
3841 return "DW_TAG_formal_parameter";
3842 case DW_TAG_imported_declaration
:
3843 return "DW_TAG_imported_declaration";
3845 return "DW_TAG_label";
3846 case DW_TAG_lexical_block
:
3847 return "DW_TAG_lexical_block";
3849 return "DW_TAG_member";
3850 case DW_TAG_pointer_type
:
3851 return "DW_TAG_pointer_type";
3852 case DW_TAG_reference_type
:
3853 return "DW_TAG_reference_type";
3854 case DW_TAG_compile_unit
:
3855 return "DW_TAG_compile_unit";
3856 case DW_TAG_string_type
:
3857 return "DW_TAG_string_type";
3858 case DW_TAG_structure_type
:
3859 return "DW_TAG_structure_type";
3860 case DW_TAG_subroutine_type
:
3861 return "DW_TAG_subroutine_type";
3862 case DW_TAG_typedef
:
3863 return "DW_TAG_typedef";
3864 case DW_TAG_union_type
:
3865 return "DW_TAG_union_type";
3866 case DW_TAG_unspecified_parameters
:
3867 return "DW_TAG_unspecified_parameters";
3868 case DW_TAG_variant
:
3869 return "DW_TAG_variant";
3870 case DW_TAG_common_block
:
3871 return "DW_TAG_common_block";
3872 case DW_TAG_common_inclusion
:
3873 return "DW_TAG_common_inclusion";
3874 case DW_TAG_inheritance
:
3875 return "DW_TAG_inheritance";
3876 case DW_TAG_inlined_subroutine
:
3877 return "DW_TAG_inlined_subroutine";
3879 return "DW_TAG_module";
3880 case DW_TAG_ptr_to_member_type
:
3881 return "DW_TAG_ptr_to_member_type";
3882 case DW_TAG_set_type
:
3883 return "DW_TAG_set_type";
3884 case DW_TAG_subrange_type
:
3885 return "DW_TAG_subrange_type";
3886 case DW_TAG_with_stmt
:
3887 return "DW_TAG_with_stmt";
3888 case DW_TAG_access_declaration
:
3889 return "DW_TAG_access_declaration";
3890 case DW_TAG_base_type
:
3891 return "DW_TAG_base_type";
3892 case DW_TAG_catch_block
:
3893 return "DW_TAG_catch_block";
3894 case DW_TAG_const_type
:
3895 return "DW_TAG_const_type";
3896 case DW_TAG_constant
:
3897 return "DW_TAG_constant";
3898 case DW_TAG_enumerator
:
3899 return "DW_TAG_enumerator";
3900 case DW_TAG_file_type
:
3901 return "DW_TAG_file_type";
3903 return "DW_TAG_friend";
3904 case DW_TAG_namelist
:
3905 return "DW_TAG_namelist";
3906 case DW_TAG_namelist_item
:
3907 return "DW_TAG_namelist_item";
3908 case DW_TAG_packed_type
:
3909 return "DW_TAG_packed_type";
3910 case DW_TAG_subprogram
:
3911 return "DW_TAG_subprogram";
3912 case DW_TAG_template_type_param
:
3913 return "DW_TAG_template_type_param";
3914 case DW_TAG_template_value_param
:
3915 return "DW_TAG_template_value_param";
3916 case DW_TAG_thrown_type
:
3917 return "DW_TAG_thrown_type";
3918 case DW_TAG_try_block
:
3919 return "DW_TAG_try_block";
3920 case DW_TAG_variant_part
:
3921 return "DW_TAG_variant_part";
3922 case DW_TAG_variable
:
3923 return "DW_TAG_variable";
3924 case DW_TAG_volatile_type
:
3925 return "DW_TAG_volatile_type";
3926 case DW_TAG_MIPS_loop
:
3927 return "DW_TAG_MIPS_loop";
3928 case DW_TAG_format_label
:
3929 return "DW_TAG_format_label";
3930 case DW_TAG_function_template
:
3931 return "DW_TAG_function_template";
3932 case DW_TAG_class_template
:
3933 return "DW_TAG_class_template";
3934 case DW_TAG_GNU_BINCL
:
3935 return "DW_TAG_GNU_BINCL";
3936 case DW_TAG_GNU_EINCL
:
3937 return "DW_TAG_GNU_EINCL";
3939 return "DW_TAG_<unknown>";
3943 /* Convert a DWARF attribute code into its string name. */
3946 dwarf_attr_name (attr
)
3952 return "DW_AT_sibling";
3953 case DW_AT_location
:
3954 return "DW_AT_location";
3956 return "DW_AT_name";
3957 case DW_AT_ordering
:
3958 return "DW_AT_ordering";
3959 case DW_AT_subscr_data
:
3960 return "DW_AT_subscr_data";
3961 case DW_AT_byte_size
:
3962 return "DW_AT_byte_size";
3963 case DW_AT_bit_offset
:
3964 return "DW_AT_bit_offset";
3965 case DW_AT_bit_size
:
3966 return "DW_AT_bit_size";
3967 case DW_AT_element_list
:
3968 return "DW_AT_element_list";
3969 case DW_AT_stmt_list
:
3970 return "DW_AT_stmt_list";
3972 return "DW_AT_low_pc";
3974 return "DW_AT_high_pc";
3975 case DW_AT_language
:
3976 return "DW_AT_language";
3978 return "DW_AT_member";
3980 return "DW_AT_discr";
3981 case DW_AT_discr_value
:
3982 return "DW_AT_discr_value";
3983 case DW_AT_visibility
:
3984 return "DW_AT_visibility";
3986 return "DW_AT_import";
3987 case DW_AT_string_length
:
3988 return "DW_AT_string_length";
3989 case DW_AT_common_reference
:
3990 return "DW_AT_common_reference";
3991 case DW_AT_comp_dir
:
3992 return "DW_AT_comp_dir";
3993 case DW_AT_const_value
:
3994 return "DW_AT_const_value";
3995 case DW_AT_containing_type
:
3996 return "DW_AT_containing_type";
3997 case DW_AT_default_value
:
3998 return "DW_AT_default_value";
4000 return "DW_AT_inline";
4001 case DW_AT_is_optional
:
4002 return "DW_AT_is_optional";
4003 case DW_AT_lower_bound
:
4004 return "DW_AT_lower_bound";
4005 case DW_AT_producer
:
4006 return "DW_AT_producer";
4007 case DW_AT_prototyped
:
4008 return "DW_AT_prototyped";
4009 case DW_AT_return_addr
:
4010 return "DW_AT_return_addr";
4011 case DW_AT_start_scope
:
4012 return "DW_AT_start_scope";
4013 case DW_AT_stride_size
:
4014 return "DW_AT_stride_size";
4015 case DW_AT_upper_bound
:
4016 return "DW_AT_upper_bound";
4017 case DW_AT_abstract_origin
:
4018 return "DW_AT_abstract_origin";
4019 case DW_AT_accessibility
:
4020 return "DW_AT_accessibility";
4021 case DW_AT_address_class
:
4022 return "DW_AT_address_class";
4023 case DW_AT_artificial
:
4024 return "DW_AT_artificial";
4025 case DW_AT_base_types
:
4026 return "DW_AT_base_types";
4027 case DW_AT_calling_convention
:
4028 return "DW_AT_calling_convention";
4030 return "DW_AT_count";
4031 case DW_AT_data_member_location
:
4032 return "DW_AT_data_member_location";
4033 case DW_AT_decl_column
:
4034 return "DW_AT_decl_column";
4035 case DW_AT_decl_file
:
4036 return "DW_AT_decl_file";
4037 case DW_AT_decl_line
:
4038 return "DW_AT_decl_line";
4039 case DW_AT_declaration
:
4040 return "DW_AT_declaration";
4041 case DW_AT_discr_list
:
4042 return "DW_AT_discr_list";
4043 case DW_AT_encoding
:
4044 return "DW_AT_encoding";
4045 case DW_AT_external
:
4046 return "DW_AT_external";
4047 case DW_AT_frame_base
:
4048 return "DW_AT_frame_base";
4050 return "DW_AT_friend";
4051 case DW_AT_identifier_case
:
4052 return "DW_AT_identifier_case";
4053 case DW_AT_macro_info
:
4054 return "DW_AT_macro_info";
4055 case DW_AT_namelist_items
:
4056 return "DW_AT_namelist_items";
4057 case DW_AT_priority
:
4058 return "DW_AT_priority";
4060 return "DW_AT_segment";
4061 case DW_AT_specification
:
4062 return "DW_AT_specification";
4063 case DW_AT_static_link
:
4064 return "DW_AT_static_link";
4066 return "DW_AT_type";
4067 case DW_AT_use_location
:
4068 return "DW_AT_use_location";
4069 case DW_AT_variable_parameter
:
4070 return "DW_AT_variable_parameter";
4071 case DW_AT_virtuality
:
4072 return "DW_AT_virtuality";
4073 case DW_AT_vtable_elem_location
:
4074 return "DW_AT_vtable_elem_location";
4076 case DW_AT_allocated
:
4077 return "DW_AT_allocated";
4078 case DW_AT_associated
:
4079 return "DW_AT_associated";
4080 case DW_AT_data_location
:
4081 return "DW_AT_data_location";
4083 return "DW_AT_stride";
4084 case DW_AT_entry_pc
:
4085 return "DW_AT_entry_pc";
4086 case DW_AT_use_UTF8
:
4087 return "DW_AT_use_UTF8";
4088 case DW_AT_extension
:
4089 return "DW_AT_extension";
4091 return "DW_AT_ranges";
4092 case DW_AT_trampoline
:
4093 return "DW_AT_trampoline";
4094 case DW_AT_call_column
:
4095 return "DW_AT_call_column";
4096 case DW_AT_call_file
:
4097 return "DW_AT_call_file";
4098 case DW_AT_call_line
:
4099 return "DW_AT_call_line";
4101 case DW_AT_MIPS_fde
:
4102 return "DW_AT_MIPS_fde";
4103 case DW_AT_MIPS_loop_begin
:
4104 return "DW_AT_MIPS_loop_begin";
4105 case DW_AT_MIPS_tail_loop_begin
:
4106 return "DW_AT_MIPS_tail_loop_begin";
4107 case DW_AT_MIPS_epilog_begin
:
4108 return "DW_AT_MIPS_epilog_begin";
4109 case DW_AT_MIPS_loop_unroll_factor
:
4110 return "DW_AT_MIPS_loop_unroll_factor";
4111 case DW_AT_MIPS_software_pipeline_depth
:
4112 return "DW_AT_MIPS_software_pipeline_depth";
4113 case DW_AT_MIPS_linkage_name
:
4114 return "DW_AT_MIPS_linkage_name";
4115 case DW_AT_MIPS_stride
:
4116 return "DW_AT_MIPS_stride";
4117 case DW_AT_MIPS_abstract_name
:
4118 return "DW_AT_MIPS_abstract_name";
4119 case DW_AT_MIPS_clone_origin
:
4120 return "DW_AT_MIPS_clone_origin";
4121 case DW_AT_MIPS_has_inlines
:
4122 return "DW_AT_MIPS_has_inlines";
4124 case DW_AT_sf_names
:
4125 return "DW_AT_sf_names";
4126 case DW_AT_src_info
:
4127 return "DW_AT_src_info";
4128 case DW_AT_mac_info
:
4129 return "DW_AT_mac_info";
4130 case DW_AT_src_coords
:
4131 return "DW_AT_src_coords";
4132 case DW_AT_body_begin
:
4133 return "DW_AT_body_begin";
4134 case DW_AT_body_end
:
4135 return "DW_AT_body_end";
4136 case DW_AT_GNU_vector
:
4137 return "DW_AT_GNU_vector";
4139 case DW_AT_VMS_rtnbeg_pd_address
:
4140 return "DW_AT_VMS_rtnbeg_pd_address";
4143 return "DW_AT_<unknown>";
4147 /* Convert a DWARF value form code into its string name. */
4150 dwarf_form_name (form
)
4156 return "DW_FORM_addr";
4157 case DW_FORM_block2
:
4158 return "DW_FORM_block2";
4159 case DW_FORM_block4
:
4160 return "DW_FORM_block4";
4162 return "DW_FORM_data2";
4164 return "DW_FORM_data4";
4166 return "DW_FORM_data8";
4167 case DW_FORM_string
:
4168 return "DW_FORM_string";
4170 return "DW_FORM_block";
4171 case DW_FORM_block1
:
4172 return "DW_FORM_block1";
4174 return "DW_FORM_data1";
4176 return "DW_FORM_flag";
4178 return "DW_FORM_sdata";
4180 return "DW_FORM_strp";
4182 return "DW_FORM_udata";
4183 case DW_FORM_ref_addr
:
4184 return "DW_FORM_ref_addr";
4186 return "DW_FORM_ref1";
4188 return "DW_FORM_ref2";
4190 return "DW_FORM_ref4";
4192 return "DW_FORM_ref8";
4193 case DW_FORM_ref_udata
:
4194 return "DW_FORM_ref_udata";
4195 case DW_FORM_indirect
:
4196 return "DW_FORM_indirect";
4198 return "DW_FORM_<unknown>";
4202 /* Convert a DWARF type code into its string name. */
4206 dwarf_type_encoding_name (enc
)
4211 case DW_ATE_address
:
4212 return "DW_ATE_address";
4213 case DW_ATE_boolean
:
4214 return "DW_ATE_boolean";
4215 case DW_ATE_complex_float
:
4216 return "DW_ATE_complex_float";
4218 return "DW_ATE_float";
4220 return "DW_ATE_signed";
4221 case DW_ATE_signed_char
:
4222 return "DW_ATE_signed_char";
4223 case DW_ATE_unsigned
:
4224 return "DW_ATE_unsigned";
4225 case DW_ATE_unsigned_char
:
4226 return "DW_ATE_unsigned_char";
4228 return "DW_ATE_<unknown>";
4233 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4234 instance of an inlined instance of a decl which is local to an inline
4235 function, so we have to trace all of the way back through the origin chain
4236 to find out what sort of node actually served as the original seed for the
4240 decl_ultimate_origin (decl
)
4243 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4244 nodes in the function to point to themselves; ignore that if
4245 we're trying to output the abstract instance of this function. */
4246 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4249 #ifdef ENABLE_CHECKING
4250 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4251 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4252 most distant ancestor, this should never happen. */
4256 return DECL_ABSTRACT_ORIGIN (decl
);
4259 /* Determine the "ultimate origin" of a block. The block may be an inlined
4260 instance of an inlined instance of a block which is local to an inline
4261 function, so we have to trace all of the way back through the origin chain
4262 to find out what sort of node actually served as the original seed for the
4266 block_ultimate_origin (block
)
4269 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4271 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4272 nodes in the function to point to themselves; ignore that if
4273 we're trying to output the abstract instance of this function. */
4274 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4277 if (immediate_origin
== NULL_TREE
)
4282 tree lookahead
= immediate_origin
;
4286 ret_val
= lookahead
;
4287 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4288 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4290 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4296 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4297 of a virtual function may refer to a base class, so we check the 'this'
4301 decl_class_context (decl
)
4304 tree context
= NULL_TREE
;
4306 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4307 context
= DECL_CONTEXT (decl
);
4309 context
= TYPE_MAIN_VARIANT
4310 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4312 if (context
&& !TYPE_P (context
))
4313 context
= NULL_TREE
;
4318 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4319 addition order, and correct that in reverse_all_dies. */
4322 add_dwarf_attr (die
, attr
)
4326 if (die
!= NULL
&& attr
!= NULL
)
4328 attr
->dw_attr_next
= die
->die_attr
;
4329 die
->die_attr
= attr
;
4333 static inline dw_val_class
4337 return a
->dw_attr_val
.val_class
;
4340 /* Add a flag value attribute to a DIE. */
4343 add_AT_flag (die
, attr_kind
, flag
)
4345 enum dwarf_attribute attr_kind
;
4348 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4350 attr
->dw_attr_next
= NULL
;
4351 attr
->dw_attr
= attr_kind
;
4352 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4353 attr
->dw_attr_val
.v
.val_flag
= flag
;
4354 add_dwarf_attr (die
, attr
);
4357 static inline unsigned
4361 if (a
&& AT_class (a
) == dw_val_class_flag
)
4362 return a
->dw_attr_val
.v
.val_flag
;
4367 /* Add a signed integer attribute value to a DIE. */
4370 add_AT_int (die
, attr_kind
, int_val
)
4372 enum dwarf_attribute attr_kind
;
4375 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4377 attr
->dw_attr_next
= NULL
;
4378 attr
->dw_attr
= attr_kind
;
4379 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4380 attr
->dw_attr_val
.v
.val_int
= int_val
;
4381 add_dwarf_attr (die
, attr
);
4384 static inline long int
4388 if (a
&& AT_class (a
) == dw_val_class_const
)
4389 return a
->dw_attr_val
.v
.val_int
;
4394 /* Add an unsigned integer attribute value to a DIE. */
4397 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4399 enum dwarf_attribute attr_kind
;
4400 unsigned long unsigned_val
;
4402 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4404 attr
->dw_attr_next
= NULL
;
4405 attr
->dw_attr
= attr_kind
;
4406 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4407 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4408 add_dwarf_attr (die
, attr
);
4411 static inline unsigned long
4415 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4416 return a
->dw_attr_val
.v
.val_unsigned
;
4421 /* Add an unsigned double integer attribute value to a DIE. */
4424 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4426 enum dwarf_attribute attr_kind
;
4427 unsigned long val_hi
;
4428 unsigned long val_low
;
4430 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4432 attr
->dw_attr_next
= NULL
;
4433 attr
->dw_attr
= attr_kind
;
4434 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4435 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4436 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4437 add_dwarf_attr (die
, attr
);
4440 /* Add a floating point attribute value to a DIE and return it. */
4443 add_AT_float (die
, attr_kind
, length
, array
)
4445 enum dwarf_attribute attr_kind
;
4449 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4451 attr
->dw_attr_next
= NULL
;
4452 attr
->dw_attr
= attr_kind
;
4453 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4454 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4455 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4456 add_dwarf_attr (die
, attr
);
4459 /* Add a string attribute value to a DIE. */
4462 add_AT_string (die
, attr_kind
, str
)
4464 enum dwarf_attribute attr_kind
;
4467 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4468 struct indirect_string_node
*node
;
4470 if (! debug_str_hash
)
4472 debug_str_hash
= ht_create (10);
4473 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4476 node
= (struct indirect_string_node
*)
4477 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4478 strlen (str
), HT_ALLOC
);
4481 attr
->dw_attr_next
= NULL
;
4482 attr
->dw_attr
= attr_kind
;
4483 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4484 attr
->dw_attr_val
.v
.val_str
= node
;
4485 add_dwarf_attr (die
, attr
);
4488 static inline const char *
4492 if (a
&& AT_class (a
) == dw_val_class_str
)
4493 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4498 /* Find out whether a string should be output inline in DIE
4499 or out-of-line in .debug_str section. */
4505 if (a
&& AT_class (a
) == dw_val_class_str
)
4507 struct indirect_string_node
*node
;
4509 extern int const_labelno
;
4512 node
= a
->dw_attr_val
.v
.val_str
;
4516 len
= HT_LEN (&node
->id
) + 1;
4518 /* If the string is shorter or equal to the size of the reference, it is
4519 always better to put it inline. */
4520 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4521 return node
->form
= DW_FORM_string
;
4523 /* If we cannot expect the linker to merge strings in .debug_str
4524 section, only put it into .debug_str if it is worth even in this
4526 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4527 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4528 return node
->form
= DW_FORM_string
;
4530 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4532 node
->label
= xstrdup (label
);
4534 return node
->form
= DW_FORM_strp
;
4540 /* Add a DIE reference attribute value to a DIE. */
4543 add_AT_die_ref (die
, attr_kind
, targ_die
)
4545 enum dwarf_attribute attr_kind
;
4546 dw_die_ref targ_die
;
4548 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4550 attr
->dw_attr_next
= NULL
;
4551 attr
->dw_attr
= attr_kind
;
4552 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4553 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4554 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4555 add_dwarf_attr (die
, attr
);
4558 static inline dw_die_ref
4562 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4563 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4572 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4573 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4579 set_AT_ref_external (a
, i
)
4583 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4584 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4589 /* Add an FDE reference attribute value to a DIE. */
4592 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4594 enum dwarf_attribute attr_kind
;
4597 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4599 attr
->dw_attr_next
= NULL
;
4600 attr
->dw_attr
= attr_kind
;
4601 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4602 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4603 add_dwarf_attr (die
, attr
);
4606 /* Add a location description attribute value to a DIE. */
4609 add_AT_loc (die
, attr_kind
, loc
)
4611 enum dwarf_attribute attr_kind
;
4612 dw_loc_descr_ref loc
;
4614 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4616 attr
->dw_attr_next
= NULL
;
4617 attr
->dw_attr
= attr_kind
;
4618 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4619 attr
->dw_attr_val
.v
.val_loc
= loc
;
4620 add_dwarf_attr (die
, attr
);
4623 static inline dw_loc_descr_ref
4627 if (a
&& AT_class (a
) == dw_val_class_loc
)
4628 return a
->dw_attr_val
.v
.val_loc
;
4634 add_AT_loc_list (die
, attr_kind
, loc_list
)
4636 enum dwarf_attribute attr_kind
;
4637 dw_loc_list_ref loc_list
;
4639 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4641 attr
->dw_attr_next
= NULL
;
4642 attr
->dw_attr
= attr_kind
;
4643 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4644 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4645 add_dwarf_attr (die
, attr
);
4646 have_location_lists
= 1;
4649 static inline dw_loc_list_ref
4653 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4654 return a
->dw_attr_val
.v
.val_loc_list
;
4659 /* Add an address constant attribute value to a DIE. */
4662 add_AT_addr (die
, attr_kind
, addr
)
4664 enum dwarf_attribute attr_kind
;
4667 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4669 attr
->dw_attr_next
= NULL
;
4670 attr
->dw_attr
= attr_kind
;
4671 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4672 attr
->dw_attr_val
.v
.val_addr
= addr
;
4673 add_dwarf_attr (die
, attr
);
4680 if (a
&& AT_class (a
) == dw_val_class_addr
)
4681 return a
->dw_attr_val
.v
.val_addr
;
4686 /* Add a label identifier attribute value to a DIE. */
4689 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4691 enum dwarf_attribute attr_kind
;
4694 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4696 attr
->dw_attr_next
= NULL
;
4697 attr
->dw_attr
= attr_kind
;
4698 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4699 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4700 add_dwarf_attr (die
, attr
);
4703 /* Add a section offset attribute value to a DIE. */
4706 add_AT_lbl_offset (die
, attr_kind
, label
)
4708 enum dwarf_attribute attr_kind
;
4711 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4713 attr
->dw_attr_next
= NULL
;
4714 attr
->dw_attr
= attr_kind
;
4715 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4716 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4717 add_dwarf_attr (die
, attr
);
4720 /* Add an offset attribute value to a DIE. */
4723 add_AT_offset (die
, attr_kind
, offset
)
4725 enum dwarf_attribute attr_kind
;
4726 unsigned long offset
;
4728 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4730 attr
->dw_attr_next
= NULL
;
4731 attr
->dw_attr
= attr_kind
;
4732 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4733 attr
->dw_attr_val
.v
.val_offset
= offset
;
4734 add_dwarf_attr (die
, attr
);
4737 /* Add an range_list attribute value to a DIE. */
4740 add_AT_range_list (die
, attr_kind
, offset
)
4742 enum dwarf_attribute attr_kind
;
4743 unsigned long offset
;
4745 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4747 attr
->dw_attr_next
= NULL
;
4748 attr
->dw_attr
= attr_kind
;
4749 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4750 attr
->dw_attr_val
.v
.val_offset
= offset
;
4751 add_dwarf_attr (die
, attr
);
4754 static inline const char *
4758 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4759 || AT_class (a
) == dw_val_class_lbl_offset
))
4760 return a
->dw_attr_val
.v
.val_lbl_id
;
4765 /* Get the attribute of type attr_kind. */
4767 static inline dw_attr_ref
4768 get_AT (die
, attr_kind
)
4770 enum dwarf_attribute attr_kind
;
4773 dw_die_ref spec
= NULL
;
4777 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4778 if (a
->dw_attr
== attr_kind
)
4780 else if (a
->dw_attr
== DW_AT_specification
4781 || a
->dw_attr
== DW_AT_abstract_origin
)
4785 return get_AT (spec
, attr_kind
);
4791 /* Return the "low pc" attribute value, typically associated with a subprogram
4792 DIE. Return null if the "low pc" attribute is either not present, or if it
4793 cannot be represented as an assembler label identifier. */
4795 static inline const char *
4799 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4801 return a
? AT_lbl (a
) : NULL
;
4804 /* Return the "high pc" attribute value, typically associated with a subprogram
4805 DIE. Return null if the "high pc" attribute is either not present, or if it
4806 cannot be represented as an assembler label identifier. */
4808 static inline const char *
4812 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4814 return a
? AT_lbl (a
) : NULL
;
4817 /* Return the value of the string attribute designated by ATTR_KIND, or
4818 NULL if it is not present. */
4820 static inline const char *
4821 get_AT_string (die
, attr_kind
)
4823 enum dwarf_attribute attr_kind
;
4825 dw_attr_ref a
= get_AT (die
, attr_kind
);
4827 return a
? AT_string (a
) : NULL
;
4830 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4831 if it is not present. */
4834 get_AT_flag (die
, attr_kind
)
4836 enum dwarf_attribute attr_kind
;
4838 dw_attr_ref a
= get_AT (die
, attr_kind
);
4840 return a
? AT_flag (a
) : 0;
4843 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4844 if it is not present. */
4846 static inline unsigned
4847 get_AT_unsigned (die
, attr_kind
)
4849 enum dwarf_attribute attr_kind
;
4851 dw_attr_ref a
= get_AT (die
, attr_kind
);
4853 return a
? AT_unsigned (a
) : 0;
4856 static inline dw_die_ref
4857 get_AT_ref (die
, attr_kind
)
4859 enum dwarf_attribute attr_kind
;
4861 dw_attr_ref a
= get_AT (die
, attr_kind
);
4863 return a
? AT_ref (a
) : NULL
;
4869 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4871 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4872 || lang
== DW_LANG_C_plus_plus
);
4878 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4879 == DW_LANG_C_plus_plus
);
4885 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4887 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4893 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4895 return (lang
== DW_LANG_Java
);
4898 /* Free up the memory used by A. */
4900 static inline void free_AT
PARAMS ((dw_attr_ref
));
4905 switch (AT_class (a
))
4907 case dw_val_class_str
:
4908 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4909 a
->dw_attr_val
.v
.val_str
->refcount
--;
4912 case dw_val_class_lbl_id
:
4913 case dw_val_class_lbl_offset
:
4914 free (a
->dw_attr_val
.v
.val_lbl_id
);
4917 case dw_val_class_float
:
4918 free (a
->dw_attr_val
.v
.val_float
.array
);
4928 /* Remove the specified attribute if present. */
4931 remove_AT (die
, attr_kind
)
4933 enum dwarf_attribute attr_kind
;
4936 dw_attr_ref removed
= NULL
;
4940 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4941 if ((*p
)->dw_attr
== attr_kind
)
4944 *p
= (*p
)->dw_attr_next
;
4953 /* Free up the memory used by DIE. */
4959 remove_children (die
);
4963 /* Discard the children of this DIE. */
4966 remove_children (die
)
4969 dw_die_ref child_die
= die
->die_child
;
4971 die
->die_child
= NULL
;
4973 while (child_die
!= NULL
)
4975 dw_die_ref tmp_die
= child_die
;
4978 child_die
= child_die
->die_sib
;
4980 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
4982 dw_attr_ref tmp_a
= a
;
4984 a
= a
->dw_attr_next
;
4992 /* Add a child DIE below its parent. We build the lists up in reverse
4993 addition order, and correct that in reverse_all_dies. */
4996 add_child_die (die
, child_die
)
4998 dw_die_ref child_die
;
5000 if (die
!= NULL
&& child_die
!= NULL
)
5002 if (die
== child_die
)
5005 child_die
->die_parent
= die
;
5006 child_die
->die_sib
= die
->die_child
;
5007 die
->die_child
= child_die
;
5011 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5012 is the specification, to the front of PARENT's list of children. */
5015 splice_child_die (parent
, child
)
5016 dw_die_ref parent
, child
;
5020 /* We want the declaration DIE from inside the class, not the
5021 specification DIE at toplevel. */
5022 if (child
->die_parent
!= parent
)
5024 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5030 if (child
->die_parent
!= parent
5031 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5034 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5037 *p
= child
->die_sib
;
5041 child
->die_sib
= parent
->die_child
;
5042 parent
->die_child
= child
;
5045 /* Return a pointer to a newly created DIE node. */
5047 static inline dw_die_ref
5048 new_die (tag_value
, parent_die
, t
)
5049 enum dwarf_tag tag_value
;
5050 dw_die_ref parent_die
;
5053 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5055 die
->die_tag
= tag_value
;
5057 if (parent_die
!= NULL
)
5058 add_child_die (parent_die
, die
);
5061 limbo_die_node
*limbo_node
;
5063 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5064 limbo_node
->die
= die
;
5065 limbo_node
->created_for
= t
;
5066 limbo_node
->next
= limbo_die_list
;
5067 limbo_die_list
= limbo_node
;
5073 /* Return the DIE associated with the given type specifier. */
5075 static inline dw_die_ref
5076 lookup_type_die (type
)
5079 return TYPE_SYMTAB_DIE (type
);
5082 /* Equate a DIE to a given type specifier. */
5085 equate_type_number_to_die (type
, type_die
)
5087 dw_die_ref type_die
;
5089 TYPE_SYMTAB_DIE (type
) = type_die
;
5092 /* Return the DIE associated with a given declaration. */
5094 static inline dw_die_ref
5095 lookup_decl_die (decl
)
5098 unsigned decl_id
= DECL_UID (decl
);
5100 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5103 /* Equate a DIE to a particular declaration. */
5106 equate_decl_number_to_die (decl
, decl_die
)
5108 dw_die_ref decl_die
;
5110 unsigned int decl_id
= DECL_UID (decl
);
5111 unsigned int num_allocated
;
5113 if (decl_id
>= decl_die_table_allocated
)
5116 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5117 / DECL_DIE_TABLE_INCREMENT
)
5118 * DECL_DIE_TABLE_INCREMENT
;
5121 = (dw_die_ref
*) xrealloc (decl_die_table
,
5122 sizeof (dw_die_ref
) * num_allocated
);
5124 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5125 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5126 decl_die_table_allocated
= num_allocated
;
5129 if (decl_id
>= decl_die_table_in_use
)
5130 decl_die_table_in_use
= (decl_id
+ 1);
5132 decl_die_table
[decl_id
] = decl_die
;
5135 /* Keep track of the number of spaces used to indent the
5136 output of the debugging routines that print the structure of
5137 the DIE internal representation. */
5138 static int print_indent
;
5140 /* Indent the line the number of spaces given by print_indent. */
5143 print_spaces (outfile
)
5146 fprintf (outfile
, "%*s", print_indent
, "");
5149 /* Print the information associated with a given DIE, and its children.
5150 This routine is a debugging aid only. */
5153 print_die (die
, outfile
)
5160 print_spaces (outfile
);
5161 fprintf (outfile
, "DIE %4lu: %s\n",
5162 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5163 print_spaces (outfile
);
5164 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5165 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5167 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5169 print_spaces (outfile
);
5170 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5172 switch (AT_class (a
))
5174 case dw_val_class_addr
:
5175 fprintf (outfile
, "address");
5177 case dw_val_class_offset
:
5178 fprintf (outfile
, "offset");
5180 case dw_val_class_loc
:
5181 fprintf (outfile
, "location descriptor");
5183 case dw_val_class_loc_list
:
5184 fprintf (outfile
, "location list -> label:%s",
5185 AT_loc_list (a
)->ll_symbol
);
5187 case dw_val_class_range_list
:
5188 fprintf (outfile
, "range list");
5190 case dw_val_class_const
:
5191 fprintf (outfile
, "%ld", AT_int (a
));
5193 case dw_val_class_unsigned_const
:
5194 fprintf (outfile
, "%lu", AT_unsigned (a
));
5196 case dw_val_class_long_long
:
5197 fprintf (outfile
, "constant (%lu,%lu)",
5198 a
->dw_attr_val
.v
.val_long_long
.hi
,
5199 a
->dw_attr_val
.v
.val_long_long
.low
);
5201 case dw_val_class_float
:
5202 fprintf (outfile
, "floating-point constant");
5204 case dw_val_class_flag
:
5205 fprintf (outfile
, "%u", AT_flag (a
));
5207 case dw_val_class_die_ref
:
5208 if (AT_ref (a
) != NULL
)
5210 if (AT_ref (a
)->die_symbol
)
5211 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5213 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5216 fprintf (outfile
, "die -> <null>");
5218 case dw_val_class_lbl_id
:
5219 case dw_val_class_lbl_offset
:
5220 fprintf (outfile
, "label: %s", AT_lbl (a
));
5222 case dw_val_class_str
:
5223 if (AT_string (a
) != NULL
)
5224 fprintf (outfile
, "\"%s\"", AT_string (a
));
5226 fprintf (outfile
, "<null>");
5232 fprintf (outfile
, "\n");
5235 if (die
->die_child
!= NULL
)
5238 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5239 print_die (c
, outfile
);
5243 if (print_indent
== 0)
5244 fprintf (outfile
, "\n");
5247 /* Print the contents of the source code line number correspondence table.
5248 This routine is a debugging aid only. */
5251 print_dwarf_line_table (outfile
)
5255 dw_line_info_ref line_info
;
5257 fprintf (outfile
, "\n\nDWARF source line information\n");
5258 for (i
= 1; i
< line_info_table_in_use
; i
++)
5260 line_info
= &line_info_table
[i
];
5261 fprintf (outfile
, "%5d: ", i
);
5262 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5263 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5264 fprintf (outfile
, "\n");
5267 fprintf (outfile
, "\n\n");
5270 /* Print the information collected for a given DIE. */
5273 debug_dwarf_die (die
)
5276 print_die (die
, stderr
);
5279 /* Print all DWARF information collected for the compilation unit.
5280 This routine is a debugging aid only. */
5286 print_die (comp_unit_die
, stderr
);
5287 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5288 print_dwarf_line_table (stderr
);
5291 /* We build up the lists of children and attributes by pushing new ones
5292 onto the beginning of the list. Reverse the lists for DIE so that
5293 they are in order of addition. */
5296 reverse_die_lists (die
)
5299 dw_die_ref c
, cp
, cn
;
5300 dw_attr_ref a
, ap
, an
;
5302 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5304 an
= a
->dw_attr_next
;
5305 a
->dw_attr_next
= ap
;
5311 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5318 die
->die_child
= cp
;
5321 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5322 reverse all dies in add_sibling_attributes, which runs through all the dies,
5323 it would reverse all the dies. Now, however, since we don't call
5324 reverse_die_lists in add_sibling_attributes, we need a routine to
5325 recursively reverse all the dies. This is that routine. */
5328 reverse_all_dies (die
)
5333 reverse_die_lists (die
);
5335 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5336 reverse_all_dies (c
);
5339 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5340 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5341 DIE that marks the start of the DIEs for this include file. */
5344 push_new_compile_unit (old_unit
, bincl_die
)
5345 dw_die_ref old_unit
, bincl_die
;
5347 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5348 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5350 new_unit
->die_sib
= old_unit
;
5354 /* Close an include-file CU and reopen the enclosing one. */
5357 pop_compile_unit (old_unit
)
5358 dw_die_ref old_unit
;
5360 dw_die_ref new_unit
= old_unit
->die_sib
;
5362 old_unit
->die_sib
= NULL
;
5366 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5367 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5369 /* Calculate the checksum of a location expression. */
5372 loc_checksum (loc
, ctx
)
5373 dw_loc_descr_ref loc
;
5374 struct md5_ctx
*ctx
;
5376 CHECKSUM (loc
->dw_loc_opc
);
5377 CHECKSUM (loc
->dw_loc_oprnd1
);
5378 CHECKSUM (loc
->dw_loc_oprnd2
);
5381 /* Calculate the checksum of an attribute. */
5384 attr_checksum (at
, ctx
)
5386 struct md5_ctx
*ctx
;
5388 dw_loc_descr_ref loc
;
5391 CHECKSUM (at
->dw_attr
);
5393 /* We don't care about differences in file numbering. */
5394 if (at
->dw_attr
== DW_AT_decl_file
5395 /* Or that this was compiled with a different compiler snapshot; if
5396 the output is the same, that's what matters. */
5397 || at
->dw_attr
== DW_AT_producer
)
5400 switch (AT_class (at
))
5402 case dw_val_class_const
:
5403 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5405 case dw_val_class_unsigned_const
:
5406 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5408 case dw_val_class_long_long
:
5409 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5411 case dw_val_class_float
:
5412 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5414 case dw_val_class_flag
:
5415 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5417 case dw_val_class_str
:
5418 CHECKSUM_STRING (AT_string (at
));
5421 case dw_val_class_addr
:
5423 switch (GET_CODE (r
))
5426 CHECKSUM_STRING (XSTR (r
, 0));
5434 case dw_val_class_offset
:
5435 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5438 case dw_val_class_loc
:
5439 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5440 loc_checksum (loc
, ctx
);
5443 case dw_val_class_die_ref
:
5444 if (AT_ref (at
)->die_offset
)
5445 CHECKSUM (AT_ref (at
)->die_offset
);
5446 /* FIXME else use target die name or something. */
5448 case dw_val_class_fde_ref
:
5449 case dw_val_class_lbl_id
:
5450 case dw_val_class_lbl_offset
:
5458 /* Calculate the checksum of a DIE. */
5461 die_checksum (die
, ctx
)
5463 struct md5_ctx
*ctx
;
5468 CHECKSUM (die
->die_tag
);
5470 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5471 attr_checksum (a
, ctx
);
5473 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5474 die_checksum (c
, ctx
);
5478 #undef CHECKSUM_STRING
5480 /* The prefix to attach to symbols on DIEs in the current comdat debug
5482 static char *comdat_symbol_id
;
5484 /* The index of the current symbol within the current comdat CU. */
5485 static unsigned int comdat_symbol_number
;
5487 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5488 children, and set comdat_symbol_id accordingly. */
5491 compute_section_prefix (unit_die
)
5492 dw_die_ref unit_die
;
5494 const char *base
= lbasename (get_AT_string (unit_die
, DW_AT_name
));
5495 char *name
= (char *) alloca (strlen (base
) + 64);
5498 unsigned char checksum
[16];
5501 /* Compute the checksum of the DIE, then append part of it as hex digits to
5502 the name filename of the unit. */
5504 md5_init_ctx (&ctx
);
5505 die_checksum (unit_die
, &ctx
);
5506 md5_finish_ctx (&ctx
, checksum
);
5508 sprintf (name
, "%s.", base
);
5509 clean_symbol_name (name
);
5511 p
= name
+ strlen (name
);
5512 for (i
= 0; i
< 4; i
++)
5514 sprintf (p
, "%.2x", checksum
[i
]);
5518 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5519 comdat_symbol_number
= 0;
5522 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5528 switch (die
->die_tag
)
5530 case DW_TAG_array_type
:
5531 case DW_TAG_class_type
:
5532 case DW_TAG_enumeration_type
:
5533 case DW_TAG_pointer_type
:
5534 case DW_TAG_reference_type
:
5535 case DW_TAG_string_type
:
5536 case DW_TAG_structure_type
:
5537 case DW_TAG_subroutine_type
:
5538 case DW_TAG_union_type
:
5539 case DW_TAG_ptr_to_member_type
:
5540 case DW_TAG_set_type
:
5541 case DW_TAG_subrange_type
:
5542 case DW_TAG_base_type
:
5543 case DW_TAG_const_type
:
5544 case DW_TAG_file_type
:
5545 case DW_TAG_packed_type
:
5546 case DW_TAG_volatile_type
:
5553 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5554 Basically, we want to choose the bits that are likely to be shared between
5555 compilations (types) and leave out the bits that are specific to individual
5556 compilations (functions). */
5562 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5563 we do for stabs. The advantage is a greater likelihood of sharing between
5564 objects that don't include headers in the same order (and therefore would
5565 put the base types in a different comdat). jason 8/28/00 */
5567 if (c
->die_tag
== DW_TAG_base_type
)
5570 if (c
->die_tag
== DW_TAG_pointer_type
5571 || c
->die_tag
== DW_TAG_reference_type
5572 || c
->die_tag
== DW_TAG_const_type
5573 || c
->die_tag
== DW_TAG_volatile_type
)
5575 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5577 return t
? is_comdat_die (t
) : 0;
5580 return is_type_die (c
);
5583 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5584 compilation unit. */
5590 return (is_type_die (c
)
5591 || (get_AT (c
, DW_AT_declaration
)
5592 && !get_AT (c
, DW_AT_specification
)));
5596 gen_internal_sym (prefix
)
5600 static int label_num
;
5602 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5603 return xstrdup (buf
);
5606 /* Assign symbols to all worthy DIEs under DIE. */
5609 assign_symbol_names (die
)
5614 if (is_symbol_die (die
))
5616 if (comdat_symbol_id
)
5618 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5620 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5621 comdat_symbol_id
, comdat_symbol_number
++);
5622 die
->die_symbol
= xstrdup (p
);
5625 die
->die_symbol
= gen_internal_sym ("LDIE");
5628 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5629 assign_symbol_names (c
);
5632 /* Traverse the DIE (which is always comp_unit_die), and set up
5633 additional compilation units for each of the include files we see
5634 bracketed by BINCL/EINCL. */
5637 break_out_includes (die
)
5641 dw_die_ref unit
= NULL
;
5642 limbo_die_node
*node
;
5644 for (ptr
= &(die
->die_child
); *ptr
;)
5646 dw_die_ref c
= *ptr
;
5648 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5649 || (unit
&& is_comdat_die (c
)))
5651 /* This DIE is for a secondary CU; remove it from the main one. */
5654 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5656 unit
= push_new_compile_unit (unit
, c
);
5659 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5661 unit
= pop_compile_unit (unit
);
5665 add_child_die (unit
, c
);
5669 /* Leave this DIE in the main CU. */
5670 ptr
= &(c
->die_sib
);
5676 /* We can only use this in debugging, since the frontend doesn't check
5677 to make sure that we leave every include file we enter. */
5682 assign_symbol_names (die
);
5683 for (node
= limbo_die_list
; node
; node
= node
->next
)
5685 compute_section_prefix (node
->die
);
5686 assign_symbol_names (node
->die
);
5690 /* Traverse the DIE and add a sibling attribute if it may have the
5691 effect of speeding up access to siblings. To save some space,
5692 avoid generating sibling attributes for DIE's without children. */
5695 add_sibling_attributes (die
)
5700 if (die
->die_tag
!= DW_TAG_compile_unit
5701 && die
->die_sib
&& die
->die_child
!= NULL
)
5702 /* Add the sibling link to the front of the attribute list. */
5703 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5705 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5706 add_sibling_attributes (c
);
5709 /* Output all location lists for the DIE and its children. */
5712 output_location_lists (die
)
5718 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5719 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5720 output_loc_list (AT_loc_list (d_attr
));
5722 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5723 output_location_lists (c
);
5727 /* The format of each DIE (and its attribute value pairs) is encoded in an
5728 abbreviation table. This routine builds the abbreviation table and assigns
5729 a unique abbreviation id for each abbreviation entry. The children of each
5730 die are visited recursively. */
5733 build_abbrev_table (die
)
5736 unsigned long abbrev_id
;
5737 unsigned int n_alloc
;
5739 dw_attr_ref d_attr
, a_attr
;
5741 /* Scan the DIE references, and mark as external any that refer to
5742 DIEs from other CUs (i.e. those which are not marked). */
5743 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5744 if (AT_class (d_attr
) == dw_val_class_die_ref
5745 && AT_ref (d_attr
)->die_mark
== 0)
5747 if (AT_ref (d_attr
)->die_symbol
== 0)
5750 set_AT_ref_external (d_attr
, 1);
5753 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5755 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5757 if (abbrev
->die_tag
== die
->die_tag
)
5759 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
5761 a_attr
= abbrev
->die_attr
;
5762 d_attr
= die
->die_attr
;
5764 while (a_attr
!= NULL
&& d_attr
!= NULL
)
5766 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
5767 || (value_format (a_attr
) != value_format (d_attr
)))
5770 a_attr
= a_attr
->dw_attr_next
;
5771 d_attr
= d_attr
->dw_attr_next
;
5774 if (a_attr
== NULL
&& d_attr
== NULL
)
5780 if (abbrev_id
>= abbrev_die_table_in_use
)
5782 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
5784 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
5786 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
5787 sizeof (dw_die_ref
) * n_alloc
);
5789 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
5790 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
5791 abbrev_die_table_allocated
= n_alloc
;
5794 ++abbrev_die_table_in_use
;
5795 abbrev_die_table
[abbrev_id
] = die
;
5798 die
->die_abbrev
= abbrev_id
;
5799 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5800 build_abbrev_table (c
);
5803 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5806 constant_size (value
)
5807 long unsigned value
;
5814 log
= floor_log2 (value
);
5817 log
= 1 << (floor_log2 (log
) + 1);
5822 /* Return the size of a DIE as it is represented in the
5823 .debug_info section. */
5825 static unsigned long
5829 unsigned long size
= 0;
5832 size
+= size_of_uleb128 (die
->die_abbrev
);
5833 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5835 switch (AT_class (a
))
5837 case dw_val_class_addr
:
5838 size
+= DWARF2_ADDR_SIZE
;
5840 case dw_val_class_offset
:
5841 size
+= DWARF_OFFSET_SIZE
;
5843 case dw_val_class_loc
:
5845 unsigned long lsize
= size_of_locs (AT_loc (a
));
5848 size
+= constant_size (lsize
);
5852 case dw_val_class_loc_list
:
5853 size
+= DWARF_OFFSET_SIZE
;
5855 case dw_val_class_range_list
:
5856 size
+= DWARF_OFFSET_SIZE
;
5858 case dw_val_class_const
:
5859 size
+= size_of_sleb128 (AT_int (a
));
5861 case dw_val_class_unsigned_const
:
5862 size
+= constant_size (AT_unsigned (a
));
5864 case dw_val_class_long_long
:
5865 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
5867 case dw_val_class_float
:
5868 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
5870 case dw_val_class_flag
:
5873 case dw_val_class_die_ref
:
5874 size
+= DWARF_OFFSET_SIZE
;
5876 case dw_val_class_fde_ref
:
5877 size
+= DWARF_OFFSET_SIZE
;
5879 case dw_val_class_lbl_id
:
5880 size
+= DWARF2_ADDR_SIZE
;
5882 case dw_val_class_lbl_offset
:
5883 size
+= DWARF_OFFSET_SIZE
;
5885 case dw_val_class_str
:
5886 if (AT_string_form (a
) == DW_FORM_strp
)
5887 size
+= DWARF_OFFSET_SIZE
;
5889 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
5899 /* Size the debugging information associated with a given DIE. Visits the
5900 DIE's children recursively. Updates the global variable next_die_offset, on
5901 each time through. Uses the current value of next_die_offset to update the
5902 die_offset field in each DIE. */
5905 calc_die_sizes (die
)
5910 die
->die_offset
= next_die_offset
;
5911 next_die_offset
+= size_of_die (die
);
5913 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5916 if (die
->die_child
!= NULL
)
5917 /* Count the null byte used to terminate sibling lists. */
5918 next_die_offset
+= 1;
5921 /* Set the marks for a die and its children. We do this so
5922 that we know whether or not a reference needs to use FORM_ref_addr; only
5923 DIEs in the same CU will be marked. We used to clear out the offset
5924 and use that as the flag, but ran into ordering problems. */
5933 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5937 /* Clear the marks for a die and its children. */
5946 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5950 /* Return the size of the .debug_pubnames table generated for the
5951 compilation unit. */
5953 static unsigned long
5959 size
= DWARF_PUBNAMES_HEADER_SIZE
;
5960 for (i
= 0; i
< pubname_table_in_use
; i
++)
5962 pubname_ref p
= &pubname_table
[i
];
5963 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
5966 size
+= DWARF_OFFSET_SIZE
;
5970 /* Return the size of the information in the .debug_aranges section. */
5972 static unsigned long
5977 size
= DWARF_ARANGES_HEADER_SIZE
;
5979 /* Count the address/length pair for this compilation unit. */
5980 size
+= 2 * DWARF2_ADDR_SIZE
;
5981 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
5983 /* Count the two zero words used to terminated the address range table. */
5984 size
+= 2 * DWARF2_ADDR_SIZE
;
5988 /* Select the encoding of an attribute value. */
5990 static enum dwarf_form
5994 switch (a
->dw_attr_val
.val_class
)
5996 case dw_val_class_addr
:
5997 return DW_FORM_addr
;
5998 case dw_val_class_range_list
:
5999 case dw_val_class_offset
:
6000 if (DWARF_OFFSET_SIZE
== 4)
6001 return DW_FORM_data4
;
6002 if (DWARF_OFFSET_SIZE
== 8)
6003 return DW_FORM_data8
;
6005 case dw_val_class_loc_list
:
6006 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6007 .debug_loc section */
6008 return DW_FORM_data4
;
6009 case dw_val_class_loc
:
6010 switch (constant_size (size_of_locs (AT_loc (a
))))
6013 return DW_FORM_block1
;
6015 return DW_FORM_block2
;
6019 case dw_val_class_const
:
6020 return DW_FORM_sdata
;
6021 case dw_val_class_unsigned_const
:
6022 switch (constant_size (AT_unsigned (a
)))
6025 return DW_FORM_data1
;
6027 return DW_FORM_data2
;
6029 return DW_FORM_data4
;
6031 return DW_FORM_data8
;
6035 case dw_val_class_long_long
:
6036 return DW_FORM_block1
;
6037 case dw_val_class_float
:
6038 return DW_FORM_block1
;
6039 case dw_val_class_flag
:
6040 return DW_FORM_flag
;
6041 case dw_val_class_die_ref
:
6042 if (AT_ref_external (a
))
6043 return DW_FORM_ref_addr
;
6046 case dw_val_class_fde_ref
:
6047 return DW_FORM_data
;
6048 case dw_val_class_lbl_id
:
6049 return DW_FORM_addr
;
6050 case dw_val_class_lbl_offset
:
6051 return DW_FORM_data
;
6052 case dw_val_class_str
:
6053 return AT_string_form (a
);
6060 /* Output the encoding of an attribute value. */
6063 output_value_format (a
)
6066 enum dwarf_form form
= value_format (a
);
6068 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6071 /* Output the .debug_abbrev section which defines the DIE abbreviation
6075 output_abbrev_section ()
6077 unsigned long abbrev_id
;
6081 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6083 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6085 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6086 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6087 dwarf_tag_name (abbrev
->die_tag
));
6089 if (abbrev
->die_child
!= NULL
)
6090 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6092 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6094 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6095 a_attr
= a_attr
->dw_attr_next
)
6097 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6098 dwarf_attr_name (a_attr
->dw_attr
));
6099 output_value_format (a_attr
);
6102 dw2_asm_output_data (1, 0, NULL
);
6103 dw2_asm_output_data (1, 0, NULL
);
6106 /* Terminate the table. */
6107 dw2_asm_output_data (1, 0, NULL
);
6110 /* Output a symbol we can use to refer to this DIE from another CU. */
6113 output_die_symbol (die
)
6116 char *sym
= die
->die_symbol
;
6121 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6122 /* We make these global, not weak; if the target doesn't support
6123 .linkonce, it doesn't support combining the sections, so debugging
6125 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, sym
);
6127 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6130 /* Return a new location list, given the begin and end range, and the
6131 expression. gensym tells us whether to generate a new internal symbol for
6132 this location list node, which is done for the head of the list only. */
6134 static inline dw_loc_list_ref
6135 new_loc_list (expr
, begin
, end
, section
, gensym
)
6136 dw_loc_descr_ref expr
;
6139 const char *section
;
6142 dw_loc_list_ref retlist
6143 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6145 retlist
->begin
= begin
;
6147 retlist
->expr
= expr
;
6148 retlist
->section
= section
;
6150 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6155 /* Add a location description expression to a location list */
6158 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6159 dw_loc_list_ref
*list_head
;
6160 dw_loc_descr_ref descr
;
6163 const char *section
;
6167 /* Find the end of the chain. */
6168 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6171 /* Add a new location list node to the list */
6172 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6175 /* Output the location list given to us */
6178 output_loc_list (list_head
)
6179 dw_loc_list_ref list_head
;
6181 dw_loc_list_ref curr
= list_head
;
6183 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6185 /* ??? This shouldn't be needed now that we've forced the
6186 compilation unit base address to zero when there is code
6187 in more than one section. */
6188 if (strcmp (curr
->section
, ".text") == 0)
6190 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6191 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6192 "Location list base address specifier fake entry");
6193 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6194 "Location list base address specifier base");
6197 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6201 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6202 "Location list begin address (%s)",
6203 list_head
->ll_symbol
);
6204 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6205 "Location list end address (%s)",
6206 list_head
->ll_symbol
);
6207 size
= size_of_locs (curr
->expr
);
6209 /* Output the block length for this list of location operations. */
6212 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6214 output_loc_sequence (curr
->expr
);
6217 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6218 "Location list terminator begin (%s)",
6219 list_head
->ll_symbol
);
6220 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6221 "Location list terminator end (%s)",
6222 list_head
->ll_symbol
);
6225 /* Output the DIE and its attributes. Called recursively to generate
6226 the definitions of each child DIE. */
6236 /* If someone in another CU might refer to us, set up a symbol for
6237 them to point to. */
6238 if (die
->die_symbol
)
6239 output_die_symbol (die
);
6241 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6242 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6244 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6246 const char *name
= dwarf_attr_name (a
->dw_attr
);
6248 switch (AT_class (a
))
6250 case dw_val_class_addr
:
6251 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6254 case dw_val_class_offset
:
6255 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6259 case dw_val_class_range_list
:
6261 char *p
= strchr (ranges_section_label
, '\0');
6263 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6264 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6270 case dw_val_class_loc
:
6271 size
= size_of_locs (AT_loc (a
));
6273 /* Output the block length for this list of location operations. */
6274 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6276 output_loc_sequence (AT_loc (a
));
6279 case dw_val_class_const
:
6280 /* ??? It would be slightly more efficient to use a scheme like is
6281 used for unsigned constants below, but gdb 4.x does not sign
6282 extend. Gdb 5.x does sign extend. */
6283 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6286 case dw_val_class_unsigned_const
:
6287 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6288 AT_unsigned (a
), "%s", name
);
6291 case dw_val_class_long_long
:
6293 unsigned HOST_WIDE_INT first
, second
;
6295 dw2_asm_output_data (1,
6296 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6299 if (WORDS_BIG_ENDIAN
)
6301 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6302 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6306 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6307 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6310 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6311 first
, "long long constant");
6312 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6317 case dw_val_class_float
:
6321 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6324 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6325 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6326 "fp constant word %u", i
);
6330 case dw_val_class_flag
:
6331 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6334 case dw_val_class_loc_list
:
6336 char *sym
= AT_loc_list (a
)->ll_symbol
;
6340 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6341 loc_section_label
, "%s", name
);
6345 case dw_val_class_die_ref
:
6346 if (AT_ref_external (a
))
6348 char *sym
= AT_ref (a
)->die_symbol
;
6352 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6354 else if (AT_ref (a
)->die_offset
== 0)
6357 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6361 case dw_val_class_fde_ref
:
6365 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6366 a
->dw_attr_val
.v
.val_fde_index
* 2);
6367 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6371 case dw_val_class_lbl_id
:
6372 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6375 case dw_val_class_lbl_offset
:
6376 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6379 case dw_val_class_str
:
6380 if (AT_string_form (a
) == DW_FORM_strp
)
6381 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6382 a
->dw_attr_val
.v
.val_str
->label
,
6383 "%s: \"%s\"", name
, AT_string (a
));
6385 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6393 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6396 /* Add null byte to terminate sibling list. */
6397 if (die
->die_child
!= NULL
)
6398 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6402 /* Output the compilation unit that appears at the beginning of the
6403 .debug_info section, and precedes the DIE descriptions. */
6406 output_compilation_unit_header ()
6408 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6409 "Length of Compilation Unit Info");
6410 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6411 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6412 "Offset Into Abbrev. Section");
6413 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6416 /* Output the compilation unit DIE and its children. */
6419 output_comp_unit (die
)
6422 const char *secname
;
6424 /* Even if there are no children of this DIE, we must output the information
6425 about the compilation unit. Otherwise, on an empty translation unit, we
6426 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6427 will then complain when examining the file. First mark all the DIEs in
6428 this CU so we know which get local refs. */
6431 build_abbrev_table (die
);
6433 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6434 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6435 calc_die_sizes (die
);
6437 if (die
->die_symbol
)
6439 char *tmp
= (char *) alloca (strlen (die
->die_symbol
) + 24);
6441 sprintf (tmp
, ".gnu.linkonce.wi.%s", die
->die_symbol
);
6443 die
->die_symbol
= NULL
;
6446 secname
= (const char *) DEBUG_INFO_SECTION
;
6448 /* Output debugging information. */
6449 named_section_flags (secname
, SECTION_DEBUG
);
6450 output_compilation_unit_header ();
6453 /* Leave the marks on the main CU, so we can check them in
6455 if (die
->die_symbol
)
6459 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6460 output of lang_hooks.decl_printable_name for C++ looks like
6461 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6464 dwarf2_name (decl
, scope
)
6468 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6471 /* Add a new entry to .debug_pubnames if appropriate. */
6474 add_pubname (decl
, die
)
6480 if (! TREE_PUBLIC (decl
))
6483 if (pubname_table_in_use
== pubname_table_allocated
)
6485 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6487 = (pubname_ref
) xrealloc (pubname_table
,
6488 (pubname_table_allocated
6489 * sizeof (pubname_entry
)));
6492 p
= &pubname_table
[pubname_table_in_use
++];
6494 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6497 /* Output the public names table used to speed up access to externally
6498 visible names. For now, only generate entries for externally
6499 visible procedures. */
6505 unsigned long pubnames_length
= size_of_pubnames ();
6507 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6508 "Length of Public Names Info");
6509 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6510 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6511 "Offset of Compilation Unit Info");
6512 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6513 "Compilation Unit Length");
6515 for (i
= 0; i
< pubname_table_in_use
; i
++)
6517 pubname_ref pub
= &pubname_table
[i
];
6519 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6520 if (pub
->die
->die_mark
== 0)
6523 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6526 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6529 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6532 /* Add a new entry to .debug_aranges if appropriate. */
6535 add_arange (decl
, die
)
6539 if (! DECL_SECTION_NAME (decl
))
6542 if (arange_table_in_use
== arange_table_allocated
)
6544 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6545 arange_table
= (dw_die_ref
*)
6546 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6549 arange_table
[arange_table_in_use
++] = die
;
6552 /* Output the information that goes into the .debug_aranges table.
6553 Namely, define the beginning and ending address range of the
6554 text section generated for this compilation unit. */
6560 unsigned long aranges_length
= size_of_aranges ();
6562 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6563 "Length of Address Ranges Info");
6564 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6565 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6566 "Offset of Compilation Unit Info");
6567 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6568 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6570 /* We need to align to twice the pointer size here. */
6571 if (DWARF_ARANGES_PAD_SIZE
)
6573 /* Pad using a 2 byte words so that padding is correct for any
6575 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6576 2 * DWARF2_ADDR_SIZE
);
6577 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6578 dw2_asm_output_data (2, 0, NULL
);
6581 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6582 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6583 text_section_label
, "Length");
6585 for (i
= 0; i
< arange_table_in_use
; i
++)
6587 dw_die_ref die
= arange_table
[i
];
6589 /* We shouldn't see aranges for DIEs outside of the main CU. */
6590 if (die
->die_mark
== 0)
6593 if (die
->die_tag
== DW_TAG_subprogram
)
6595 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6597 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6598 get_AT_low_pc (die
), "Length");
6602 /* A static variable; extract the symbol from DW_AT_location.
6603 Note that this code isn't currently hit, as we only emit
6604 aranges for functions (jason 9/23/99). */
6605 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6606 dw_loc_descr_ref loc
;
6608 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6612 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6615 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6616 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6617 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6618 get_AT_unsigned (die
, DW_AT_byte_size
),
6623 /* Output the terminator words. */
6624 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6625 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6628 /* Add a new entry to .debug_ranges. Return the offset at which it
6635 unsigned int in_use
= ranges_table_in_use
;
6637 if (in_use
== ranges_table_allocated
)
6639 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6640 ranges_table
= (dw_ranges_ref
)
6641 xrealloc (ranges_table
, (ranges_table_allocated
6642 * sizeof (struct dw_ranges_struct
)));
6645 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6646 ranges_table_in_use
= in_use
+ 1;
6648 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6655 static const char *const start_fmt
= "Offset 0x%x";
6656 const char *fmt
= start_fmt
;
6658 for (i
= 0; i
< ranges_table_in_use
; i
++)
6660 int block_num
= ranges_table
[i
].block_num
;
6664 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6665 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6667 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6668 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6670 /* If all code is in the text section, then the compilation
6671 unit base address defaults to DW_AT_low_pc, which is the
6672 base of the text section. */
6673 if (separate_line_info_table_in_use
== 0)
6675 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6677 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6678 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6679 text_section_label
, NULL
);
6682 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6683 compilation unit base address to zero, which allows us to
6684 use absolute addresses, and not worry about whether the
6685 target supports cross-section arithmetic. */
6688 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6689 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6690 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6697 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6698 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6704 /* Data structure containing information about input files. */
6707 char *path
; /* Complete file name. */
6708 char *fname
; /* File name part. */
6709 int length
; /* Length of entire string. */
6710 int file_idx
; /* Index in input file table. */
6711 int dir_idx
; /* Index in directory table. */
6714 /* Data structure containing information about directories with source
6718 char *path
; /* Path including directory name. */
6719 int length
; /* Path length. */
6720 int prefix
; /* Index of directory entry which is a prefix. */
6721 int count
; /* Number of files in this directory. */
6722 int dir_idx
; /* Index of directory used as base. */
6723 int used
; /* Used in the end? */
6726 /* Callback function for file_info comparison. We sort by looking at
6727 the directories in the path. */
6730 file_info_cmp (p1
, p2
)
6734 const struct file_info
*s1
= p1
;
6735 const struct file_info
*s2
= p2
;
6739 /* Take care of file names without directories. We need to make sure that
6740 we return consistent values to qsort since some will get confused if
6741 we return the same value when identical operands are passed in opposite
6742 orders. So if neither has a directory, return 0 and otherwise return
6743 1 or -1 depending on which one has the directory. */
6744 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
6745 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
6747 cp1
= (unsigned char *) s1
->path
;
6748 cp2
= (unsigned char *) s2
->path
;
6754 /* Reached the end of the first path? If so, handle like above. */
6755 if ((cp1
== (unsigned char *) s1
->fname
)
6756 || (cp2
== (unsigned char *) s2
->fname
))
6757 return ((cp2
== (unsigned char *) s2
->fname
)
6758 - (cp1
== (unsigned char *) s1
->fname
));
6760 /* Character of current path component the same? */
6761 else if (*cp1
!= *cp2
)
6766 /* Output the directory table and the file name table. We try to minimize
6767 the total amount of memory needed. A heuristic is used to avoid large
6768 slowdowns with many input files. */
6771 output_file_names ()
6773 struct file_info
*files
;
6774 struct dir_info
*dirs
;
6783 /* Allocate the various arrays we need. */
6784 files
= (struct file_info
*) alloca (file_table
.in_use
6785 * sizeof (struct file_info
));
6786 dirs
= (struct dir_info
*) alloca (file_table
.in_use
6787 * sizeof (struct dir_info
));
6789 /* Sort the file names. */
6790 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6794 /* Skip all leading "./". */
6795 f
= file_table
.table
[i
];
6796 while (f
[0] == '.' && f
[1] == '/')
6799 /* Create a new array entry. */
6801 files
[i
].length
= strlen (f
);
6802 files
[i
].file_idx
= i
;
6804 /* Search for the file name part. */
6805 f
= strrchr (f
, '/');
6806 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
6809 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
6811 /* Find all the different directories used. */
6812 dirs
[0].path
= files
[1].path
;
6813 dirs
[0].length
= files
[1].fname
- files
[1].path
;
6814 dirs
[0].prefix
= -1;
6816 dirs
[0].dir_idx
= 0;
6818 files
[1].dir_idx
= 0;
6821 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
6822 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
6823 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
6824 dirs
[ndirs
- 1].length
) == 0)
6826 /* Same directory as last entry. */
6827 files
[i
].dir_idx
= ndirs
- 1;
6828 ++dirs
[ndirs
- 1].count
;
6834 /* This is a new directory. */
6835 dirs
[ndirs
].path
= files
[i
].path
;
6836 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
6837 dirs
[ndirs
].count
= 1;
6838 dirs
[ndirs
].dir_idx
= ndirs
;
6839 dirs
[ndirs
].used
= 0;
6840 files
[i
].dir_idx
= ndirs
;
6842 /* Search for a prefix. */
6843 dirs
[ndirs
].prefix
= -1;
6844 for (j
= 0; j
< ndirs
; j
++)
6845 if (dirs
[j
].length
< dirs
[ndirs
].length
6846 && dirs
[j
].length
> 1
6847 && (dirs
[ndirs
].prefix
== -1
6848 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
6849 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
6850 dirs
[ndirs
].prefix
= j
;
6855 /* Now to the actual work. We have to find a subset of the directories which
6856 allow expressing the file name using references to the directory table
6857 with the least amount of characters. We do not do an exhaustive search
6858 where we would have to check out every combination of every single
6859 possible prefix. Instead we use a heuristic which provides nearly optimal
6860 results in most cases and never is much off. */
6861 saved
= (int *) alloca (ndirs
* sizeof (int));
6862 savehere
= (int *) alloca (ndirs
* sizeof (int));
6864 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
6865 for (i
= 0; i
< ndirs
; i
++)
6870 /* We can always save some space for the current directory. But this
6871 does not mean it will be enough to justify adding the directory. */
6872 savehere
[i
] = dirs
[i
].length
;
6873 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
6875 for (j
= i
+ 1; j
< ndirs
; j
++)
6878 if (saved
[j
] < dirs
[i
].length
)
6880 /* Determine whether the dirs[i] path is a prefix of the
6885 while (k
!= -1 && k
!= i
)
6890 /* Yes it is. We can possibly safe some memory but
6891 writing the filenames in dirs[j] relative to
6893 savehere
[j
] = dirs
[i
].length
;
6894 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
6899 /* Check whether we can safe enough to justify adding the dirs[i]
6901 if (total
> dirs
[i
].length
+ 1)
6903 /* It's worthwhile adding. */
6904 for (j
= i
; j
< ndirs
; j
++)
6905 if (savehere
[j
] > 0)
6907 /* Remember how much we saved for this directory so far. */
6908 saved
[j
] = savehere
[j
];
6910 /* Remember the prefix directory. */
6911 dirs
[j
].dir_idx
= i
;
6916 /* We have to emit them in the order they appear in the file_table array
6917 since the index is used in the debug info generation. To do this
6918 efficiently we generate a back-mapping of the indices first. */
6919 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
6920 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6922 backmap
[files
[i
].file_idx
] = i
;
6924 /* Mark this directory as used. */
6925 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
6928 /* That was it. We are ready to emit the information. First emit the
6929 directory name table. We have to make sure the first actually emitted
6930 directory name has index one; zero is reserved for the current working
6931 directory. Make sure we do not confuse these indices with the one for the
6932 constructed table (even though most of the time they are identical). */
6934 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
6935 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
6936 if (dirs
[i
].used
!= 0)
6938 dirs
[i
].used
= idx
++;
6939 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
6940 "Directory Entry: 0x%x", dirs
[i
].used
);
6943 dw2_asm_output_data (1, 0, "End directory table");
6945 /* Correct the index for the current working directory entry if it
6947 if (idx_offset
== 0)
6950 /* Now write all the file names. */
6951 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6953 int file_idx
= backmap
[i
];
6954 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
6956 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
6957 "File Entry: 0x%x", i
);
6959 /* Include directory index. */
6960 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
6962 /* Modification time. */
6963 dw2_asm_output_data_uleb128 (0, NULL
);
6965 /* File length in bytes. */
6966 dw2_asm_output_data_uleb128 (0, NULL
);
6969 dw2_asm_output_data (1, 0, "End file name table");
6973 /* Output the source line number correspondence information. This
6974 information goes into the .debug_line section. */
6979 char l1
[20], l2
[20], p1
[20], p2
[20];
6980 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6981 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6984 unsigned long lt_index
;
6985 unsigned long current_line
;
6988 unsigned long current_file
;
6989 unsigned long function
;
6991 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
6992 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
6993 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
6994 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
6996 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
6997 "Length of Source Line Info");
6998 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7000 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7001 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7002 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7004 /* Define the architecture-dependent minimum instruction length (in
7005 bytes). In this implementation of DWARF, this field is used for
7006 information purposes only. Since GCC generates assembly language,
7007 we have no a priori knowledge of how many instruction bytes are
7008 generated for each source line, and therefore can use only the
7009 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7010 commands. Accordingly, we fix this as `1', which is "correct
7011 enough" for all architectures, and don't let the target override. */
7012 dw2_asm_output_data (1, 1,
7013 "Minimum Instruction Length");
7015 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7016 "Default is_stmt_start flag");
7017 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7018 "Line Base Value (Special Opcodes)");
7019 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7020 "Line Range Value (Special Opcodes)");
7021 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7022 "Special Opcode Base");
7024 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7028 case DW_LNS_advance_pc
:
7029 case DW_LNS_advance_line
:
7030 case DW_LNS_set_file
:
7031 case DW_LNS_set_column
:
7032 case DW_LNS_fixed_advance_pc
:
7040 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7044 /* Write out the information about the files we use. */
7045 output_file_names ();
7046 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7048 /* We used to set the address register to the first location in the text
7049 section here, but that didn't accomplish anything since we already
7050 have a line note for the opening brace of the first function. */
7052 /* Generate the line number to PC correspondence table, encoded as
7053 a series of state machine operations. */
7056 strcpy (prev_line_label
, text_section_label
);
7057 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7059 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7062 /* Disable this optimization for now; GDB wants to see two line notes
7063 at the beginning of a function so it can find the end of the
7066 /* Don't emit anything for redundant notes. Just updating the
7067 address doesn't accomplish anything, because we already assume
7068 that anything after the last address is this line. */
7069 if (line_info
->dw_line_num
== current_line
7070 && line_info
->dw_file_num
== current_file
)
7074 /* Emit debug info for the address of the current line.
7076 Unfortunately, we have little choice here currently, and must always
7077 use the most general form. GCC does not know the address delta
7078 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7079 attributes which will give an upper bound on the address range. We
7080 could perhaps use length attributes to determine when it is safe to
7081 use DW_LNS_fixed_advance_pc. */
7083 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7086 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7087 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7088 "DW_LNS_fixed_advance_pc");
7089 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7093 /* This can handle any delta. This takes
7094 4+DWARF2_ADDR_SIZE bytes. */
7095 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7096 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7097 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7098 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7101 strcpy (prev_line_label
, line_label
);
7103 /* Emit debug info for the source file of the current line, if
7104 different from the previous line. */
7105 if (line_info
->dw_file_num
!= current_file
)
7107 current_file
= line_info
->dw_file_num
;
7108 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7109 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7110 file_table
.table
[current_file
]);
7113 /* Emit debug info for the current line number, choosing the encoding
7114 that uses the least amount of space. */
7115 if (line_info
->dw_line_num
!= current_line
)
7117 line_offset
= line_info
->dw_line_num
- current_line
;
7118 line_delta
= line_offset
- DWARF_LINE_BASE
;
7119 current_line
= line_info
->dw_line_num
;
7120 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7121 /* This can handle deltas from -10 to 234, using the current
7122 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7124 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7125 "line %lu", current_line
);
7128 /* This can handle any delta. This takes at least 4 bytes,
7129 depending on the value being encoded. */
7130 dw2_asm_output_data (1, DW_LNS_advance_line
,
7131 "advance to line %lu", current_line
);
7132 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7133 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7137 /* We still need to start a new row, so output a copy insn. */
7138 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7141 /* Emit debug info for the address of the end of the function. */
7144 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7145 "DW_LNS_fixed_advance_pc");
7146 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7150 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7151 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7152 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7153 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7156 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7157 dw2_asm_output_data_uleb128 (1, NULL
);
7158 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7163 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7165 dw_separate_line_info_ref line_info
7166 = &separate_line_info_table
[lt_index
];
7169 /* Don't emit anything for redundant notes. */
7170 if (line_info
->dw_line_num
== current_line
7171 && line_info
->dw_file_num
== current_file
7172 && line_info
->function
== function
)
7176 /* Emit debug info for the address of the current line. If this is
7177 a new function, or the first line of a function, then we need
7178 to handle it differently. */
7179 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7181 if (function
!= line_info
->function
)
7183 function
= line_info
->function
;
7185 /* Set the address register to the first line in the function */
7186 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7187 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7188 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7189 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7193 /* ??? See the DW_LNS_advance_pc comment above. */
7196 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7197 "DW_LNS_fixed_advance_pc");
7198 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7202 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7203 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7204 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7205 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7209 strcpy (prev_line_label
, line_label
);
7211 /* Emit debug info for the source file of the current line, if
7212 different from the previous line. */
7213 if (line_info
->dw_file_num
!= current_file
)
7215 current_file
= line_info
->dw_file_num
;
7216 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7217 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7218 file_table
.table
[current_file
]);
7221 /* Emit debug info for the current line number, choosing the encoding
7222 that uses the least amount of space. */
7223 if (line_info
->dw_line_num
!= current_line
)
7225 line_offset
= line_info
->dw_line_num
- current_line
;
7226 line_delta
= line_offset
- DWARF_LINE_BASE
;
7227 current_line
= line_info
->dw_line_num
;
7228 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7229 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7230 "line %lu", current_line
);
7233 dw2_asm_output_data (1, DW_LNS_advance_line
,
7234 "advance to line %lu", current_line
);
7235 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7236 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7240 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7248 /* If we're done with a function, end its sequence. */
7249 if (lt_index
== separate_line_info_table_in_use
7250 || separate_line_info_table
[lt_index
].function
!= function
)
7255 /* Emit debug info for the address of the end of the function. */
7256 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7259 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7260 "DW_LNS_fixed_advance_pc");
7261 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7265 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7266 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7267 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7268 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7271 /* Output the marker for the end of this sequence. */
7272 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7273 dw2_asm_output_data_uleb128 (1, NULL
);
7274 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7278 /* Output the marker for the end of the line number info. */
7279 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7282 /* Given a pointer to a tree node for some base type, return a pointer to
7283 a DIE that describes the given type.
7285 This routine must only be called for GCC type nodes that correspond to
7286 Dwarf base (fundamental) types. */
7289 base_type_die (type
)
7292 dw_die_ref base_type_result
;
7293 const char *type_name
;
7294 enum dwarf_type encoding
;
7295 tree name
= TYPE_NAME (type
);
7297 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7302 if (TREE_CODE (name
) == TYPE_DECL
)
7303 name
= DECL_NAME (name
);
7305 type_name
= IDENTIFIER_POINTER (name
);
7308 type_name
= "__unknown__";
7310 switch (TREE_CODE (type
))
7313 /* Carefully distinguish the C character types, without messing
7314 up if the language is not C. Note that we check only for the names
7315 that contain spaces; other names might occur by coincidence in other
7317 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7318 && (type
== char_type_node
7319 || ! strcmp (type_name
, "signed char")
7320 || ! strcmp (type_name
, "unsigned char"))))
7322 if (TREE_UNSIGNED (type
))
7323 encoding
= DW_ATE_unsigned
;
7325 encoding
= DW_ATE_signed
;
7328 /* else fall through. */
7331 /* GNU Pascal/Ada CHAR type. Not used in C. */
7332 if (TREE_UNSIGNED (type
))
7333 encoding
= DW_ATE_unsigned_char
;
7335 encoding
= DW_ATE_signed_char
;
7339 encoding
= DW_ATE_float
;
7342 /* Dwarf2 doesn't know anything about complex ints, so use
7343 a user defined type for it. */
7345 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7346 encoding
= DW_ATE_complex_float
;
7348 encoding
= DW_ATE_lo_user
;
7352 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7353 encoding
= DW_ATE_boolean
;
7357 /* No other TREE_CODEs are Dwarf fundamental types. */
7361 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7362 if (demangle_name_func
)
7363 type_name
= (*demangle_name_func
) (type_name
);
7365 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7366 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7367 int_size_in_bytes (type
));
7368 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7370 return base_type_result
;
7373 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7374 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7375 a given type is generally the same as the given type, except that if the
7376 given type is a pointer or reference type, then the root type of the given
7377 type is the root type of the "basis" type for the pointer or reference
7378 type. (This definition of the "root" type is recursive.) Also, the root
7379 type of a `const' qualified type or a `volatile' qualified type is the
7380 root type of the given type without the qualifiers. */
7386 if (TREE_CODE (type
) == ERROR_MARK
)
7387 return error_mark_node
;
7389 switch (TREE_CODE (type
))
7392 return error_mark_node
;
7395 case REFERENCE_TYPE
:
7396 return type_main_variant (root_type (TREE_TYPE (type
)));
7399 return type_main_variant (type
);
7403 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7404 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7410 switch (TREE_CODE (type
))
7425 case QUAL_UNION_TYPE
:
7430 case REFERENCE_TYPE
:
7444 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7445 entry that chains various modifiers in front of the given type. */
7448 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7451 int is_volatile_type
;
7452 dw_die_ref context_die
;
7454 enum tree_code code
= TREE_CODE (type
);
7455 dw_die_ref mod_type_die
= NULL
;
7456 dw_die_ref sub_die
= NULL
;
7457 tree item_type
= NULL
;
7459 if (code
!= ERROR_MARK
)
7461 tree qualified_type
;
7463 /* See if we already have the appropriately qualified variant of
7466 = get_qualified_type (type
,
7467 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7469 ? TYPE_QUAL_VOLATILE
: 0)));
7471 /* If we do, then we can just use its DIE, if it exists. */
7474 mod_type_die
= lookup_type_die (qualified_type
);
7476 return mod_type_die
;
7479 /* Handle C typedef types. */
7480 if (qualified_type
&& TYPE_NAME (qualified_type
)
7481 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7482 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7484 tree type_name
= TYPE_NAME (qualified_type
);
7485 tree dtype
= TREE_TYPE (type_name
);
7487 if (qualified_type
== dtype
)
7489 /* For a named type, use the typedef. */
7490 gen_type_die (qualified_type
, context_die
);
7491 mod_type_die
= lookup_type_die (qualified_type
);
7493 else if (is_const_type
< TYPE_READONLY (dtype
)
7494 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7495 /* cv-unqualified version of named type. Just use the unnamed
7496 type to which it refers. */
7498 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7499 is_const_type
, is_volatile_type
,
7502 /* Else cv-qualified version of named type; fall through. */
7508 else if (is_const_type
)
7510 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7511 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7513 else if (is_volatile_type
)
7515 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7516 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7518 else if (code
== POINTER_TYPE
)
7520 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7521 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7523 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7525 item_type
= TREE_TYPE (type
);
7527 else if (code
== REFERENCE_TYPE
)
7529 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7530 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7532 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7534 item_type
= TREE_TYPE (type
);
7536 else if (is_base_type (type
))
7537 mod_type_die
= base_type_die (type
);
7540 gen_type_die (type
, context_die
);
7542 /* We have to get the type_main_variant here (and pass that to the
7543 `lookup_type_die' routine) because the ..._TYPE node we have
7544 might simply be a *copy* of some original type node (where the
7545 copy was created to help us keep track of typedef names) and
7546 that copy might have a different TYPE_UID from the original
7548 if (TREE_CODE (type
) != VECTOR_TYPE
)
7549 mod_type_die
= lookup_type_die (type_main_variant (type
));
7551 /* Vectors have the debugging information in the type,
7552 not the main variant. */
7553 mod_type_die
= lookup_type_die (type
);
7554 if (mod_type_die
== NULL
)
7558 /* We want to equate the qualified type to the die below. */
7559 type
= qualified_type
;
7563 equate_type_number_to_die (type
, mod_type_die
);
7565 /* We must do this after the equate_type_number_to_die call, in case
7566 this is a recursive type. This ensures that the modified_type_die
7567 recursion will terminate even if the type is recursive. Recursive
7568 types are possible in Ada. */
7569 sub_die
= modified_type_die (item_type
,
7570 TYPE_READONLY (item_type
),
7571 TYPE_VOLATILE (item_type
),
7574 if (sub_die
!= NULL
)
7575 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7577 return mod_type_die
;
7580 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7581 an enumerated type. */
7587 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7590 /* Return the register number described by a given RTL node. */
7596 unsigned regno
= REGNO (rtl
);
7598 if (regno
>= FIRST_PSEUDO_REGISTER
)
7601 return DBX_REGISTER_NUMBER (regno
);
7604 /* Return a location descriptor that designates a machine register or
7605 zero if there is no such. */
7607 static dw_loc_descr_ref
7608 reg_loc_descriptor (rtl
)
7611 dw_loc_descr_ref loc_result
= NULL
;
7614 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7617 reg
= reg_number (rtl
);
7619 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
7621 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
7626 /* Return a location descriptor that designates a constant. */
7628 static dw_loc_descr_ref
7629 int_loc_descriptor (i
)
7632 enum dwarf_location_atom op
;
7634 /* Pick the smallest representation of a constant, rather than just
7635 defaulting to the LEB encoding. */
7639 op
= DW_OP_lit0
+ i
;
7642 else if (i
<= 0xffff)
7644 else if (HOST_BITS_PER_WIDE_INT
== 32
7654 else if (i
>= -0x8000)
7656 else if (HOST_BITS_PER_WIDE_INT
== 32
7657 || i
>= -0x80000000)
7663 return new_loc_descr (op
, i
, 0);
7666 /* Return a location descriptor that designates a base+offset location. */
7668 static dw_loc_descr_ref
7669 based_loc_descr (reg
, offset
)
7673 dw_loc_descr_ref loc_result
;
7674 /* For the "frame base", we use the frame pointer or stack pointer
7675 registers, since the RTL for local variables is relative to one of
7677 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7678 ? HARD_FRAME_POINTER_REGNUM
7679 : STACK_POINTER_REGNUM
);
7682 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
7684 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
7686 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
7691 /* Return true if this RTL expression describes a base+offset calculation. */
7697 return (GET_CODE (rtl
) == PLUS
7698 && ((GET_CODE (XEXP (rtl
, 0)) == REG
7699 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
7700 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
7703 /* The following routine converts the RTL for a variable or parameter
7704 (resident in memory) into an equivalent Dwarf representation of a
7705 mechanism for getting the address of that same variable onto the top of a
7706 hypothetical "address evaluation" stack.
7708 When creating memory location descriptors, we are effectively transforming
7709 the RTL for a memory-resident object into its Dwarf postfix expression
7710 equivalent. This routine recursively descends an RTL tree, turning
7711 it into Dwarf postfix code as it goes.
7713 MODE is the mode of the memory reference, needed to handle some
7714 autoincrement addressing modes.
7716 Return 0 if we can't represent the location. */
7718 static dw_loc_descr_ref
7719 mem_loc_descriptor (rtl
, mode
)
7721 enum machine_mode mode
;
7723 dw_loc_descr_ref mem_loc_result
= NULL
;
7725 /* Note that for a dynamically sized array, the location we will generate a
7726 description of here will be the lowest numbered location which is
7727 actually within the array. That's *not* necessarily the same as the
7728 zeroth element of the array. */
7730 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7731 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
7734 switch (GET_CODE (rtl
))
7739 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7740 just fall into the SUBREG code. */
7742 /* ... fall through ... */
7745 /* The case of a subreg may arise when we have a local (register)
7746 variable or a formal (register) parameter which doesn't quite fill
7747 up an entire register. For now, just assume that it is
7748 legitimate to make the Dwarf info refer to the whole register which
7749 contains the given subreg. */
7750 rtl
= SUBREG_REG (rtl
);
7752 /* ... fall through ... */
7755 /* Whenever a register number forms a part of the description of the
7756 method for calculating the (dynamic) address of a memory resident
7757 object, DWARF rules require the register number be referred to as
7758 a "base register". This distinction is not based in any way upon
7759 what category of register the hardware believes the given register
7760 belongs to. This is strictly DWARF terminology we're dealing with
7761 here. Note that in cases where the location of a memory-resident
7762 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7763 OP_CONST (0)) the actual DWARF location descriptor that we generate
7764 may just be OP_BASEREG (basereg). This may look deceptively like
7765 the object in question was allocated to a register (rather than in
7766 memory) so DWARF consumers need to be aware of the subtle
7767 distinction between OP_REG and OP_BASEREG. */
7768 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
7769 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
7773 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7774 if (mem_loc_result
!= 0)
7775 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
7779 /* Some ports can transform a symbol ref into a label ref, because
7780 the symbol ref is too far away and has to be dumped into a constant
7784 /* Alternatively, the symbol in the constant pool might be referenced
7785 by a different symbol. */
7786 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
7789 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
7791 if (GET_CODE (tmp
) == SYMBOL_REF
)
7794 if (CONSTANT_POOL_ADDRESS_P (tmp
))
7795 get_pool_constant_mark (tmp
, &marked
);
7800 /* If all references to this pool constant were optimized away,
7801 it was not output and thus we can't represent it.
7802 FIXME: might try to use DW_OP_const_value here, though
7803 DW_OP_piece complicates it. */
7808 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
7809 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7810 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
7811 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
7815 /* Extract the PLUS expression nested inside and fall into
7817 rtl
= XEXP (rtl
, 1);
7822 /* Turn these into a PLUS expression and fall into the PLUS code
7824 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
7825 GEN_INT (GET_CODE (rtl
) == PRE_INC
7826 ? GET_MODE_UNIT_SIZE (mode
)
7827 : -GET_MODE_UNIT_SIZE (mode
)));
7829 /* ... fall through ... */
7833 if (is_based_loc (rtl
))
7834 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
7835 INTVAL (XEXP (rtl
, 1)));
7838 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7839 if (mem_loc_result
== 0)
7842 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
7843 && INTVAL (XEXP (rtl
, 1)) >= 0)
7844 add_loc_descr (&mem_loc_result
,
7845 new_loc_descr (DW_OP_plus_uconst
,
7846 INTVAL (XEXP (rtl
, 1)), 0));
7849 add_loc_descr (&mem_loc_result
,
7850 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7851 add_loc_descr (&mem_loc_result
,
7852 new_loc_descr (DW_OP_plus
, 0, 0));
7859 /* If a pseudo-reg is optimized away, it is possible for it to
7860 be replaced with a MEM containing a multiply. */
7861 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7862 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
7864 if (op0
== 0 || op1
== 0)
7867 mem_loc_result
= op0
;
7868 add_loc_descr (&mem_loc_result
, op1
);
7869 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
7874 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
7878 /* If this is a MEM, return its address. Otherwise, we can't
7880 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
7881 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
7889 return mem_loc_result
;
7892 /* Return a descriptor that describes the concatenation of two locations.
7893 This is typically a complex variable. */
7895 static dw_loc_descr_ref
7896 concat_loc_descriptor (x0
, x1
)
7899 dw_loc_descr_ref cc_loc_result
= NULL
;
7900 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
7901 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
7903 if (x0_ref
== 0 || x1_ref
== 0)
7906 cc_loc_result
= x0_ref
;
7907 add_loc_descr (&cc_loc_result
,
7908 new_loc_descr (DW_OP_piece
,
7909 GET_MODE_SIZE (GET_MODE (x0
)), 0));
7911 add_loc_descr (&cc_loc_result
, x1_ref
);
7912 add_loc_descr (&cc_loc_result
,
7913 new_loc_descr (DW_OP_piece
,
7914 GET_MODE_SIZE (GET_MODE (x1
)), 0));
7916 return cc_loc_result
;
7919 /* Output a proper Dwarf location descriptor for a variable or parameter
7920 which is either allocated in a register or in a memory location. For a
7921 register, we just generate an OP_REG and the register number. For a
7922 memory location we provide a Dwarf postfix expression describing how to
7923 generate the (dynamic) address of the object onto the address stack.
7925 If we don't know how to describe it, return 0. */
7927 static dw_loc_descr_ref
7928 loc_descriptor (rtl
)
7931 dw_loc_descr_ref loc_result
= NULL
;
7933 switch (GET_CODE (rtl
))
7936 /* The case of a subreg may arise when we have a local (register)
7937 variable or a formal (register) parameter which doesn't quite fill
7938 up an entire register. For now, just assume that it is
7939 legitimate to make the Dwarf info refer to the whole register which
7940 contains the given subreg. */
7941 rtl
= SUBREG_REG (rtl
);
7943 /* ... fall through ... */
7946 loc_result
= reg_loc_descriptor (rtl
);
7950 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7954 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
7964 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7965 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7966 looking for an address. Otherwise, we return a value. If we can't make a
7967 descriptor, return 0. */
7969 static dw_loc_descr_ref
7970 loc_descriptor_from_tree (loc
, addressp
)
7974 dw_loc_descr_ref ret
, ret1
;
7976 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
7977 enum dwarf_location_atom op
;
7979 /* ??? Most of the time we do not take proper care for sign/zero
7980 extending the values properly. Hopefully this won't be a real
7983 switch (TREE_CODE (loc
))
7988 case WITH_RECORD_EXPR
:
7989 case PLACEHOLDER_EXPR
:
7990 /* This case involves extracting fields from an object to determine the
7991 position of other fields. We don't try to encode this here. The
7992 only user of this is Ada, which encodes the needed information using
7993 the names of types. */
8000 /* We can support this only if we can look through conversions and
8001 find an INDIRECT_EXPR. */
8002 for (loc
= TREE_OPERAND (loc
, 0);
8003 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8004 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8005 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8006 || TREE_CODE (loc
) == SAVE_EXPR
;
8007 loc
= TREE_OPERAND (loc
, 0))
8010 return (TREE_CODE (loc
) == INDIRECT_REF
8011 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8017 rtx rtl
= rtl_for_decl_location (loc
);
8019 if (rtl
== NULL_RTX
)
8021 else if (CONSTANT_P (rtl
))
8023 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8024 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8025 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8030 enum machine_mode mode
= GET_MODE (rtl
);
8032 if (GET_CODE (rtl
) == MEM
)
8035 rtl
= XEXP (rtl
, 0);
8038 ret
= mem_loc_descriptor (rtl
, mode
);
8044 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8049 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8053 case NON_LVALUE_EXPR
:
8054 case VIEW_CONVERT_EXPR
:
8056 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8061 case ARRAY_RANGE_REF
:
8064 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8065 enum machine_mode mode
;
8068 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8069 &unsignedp
, &volatilep
);
8074 ret
= loc_descriptor_from_tree (obj
, 1);
8076 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8079 if (offset
!= NULL_TREE
)
8081 /* Variable offset. */
8082 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8083 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8089 bytepos
= bitpos
/ BITS_PER_UNIT
;
8091 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8092 else if (bytepos
< 0)
8094 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8095 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8101 if (host_integerp (loc
, 0))
8102 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8107 case TRUTH_AND_EXPR
:
8108 case TRUTH_ANDIF_EXPR
:
8113 case TRUTH_XOR_EXPR
:
8119 case TRUTH_ORIF_EXPR
:
8124 case TRUNC_DIV_EXPR
:
8132 case TRUNC_MOD_EXPR
:
8145 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8149 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8150 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8152 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8156 add_loc_descr (&ret
,
8157 new_loc_descr (DW_OP_plus_uconst
,
8158 tree_low_cst (TREE_OPERAND (loc
, 1),
8168 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8175 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8182 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8189 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8204 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8205 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8206 if (ret
== 0 || ret1
== 0)
8209 add_loc_descr (&ret
, ret1
);
8210 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8213 case TRUTH_NOT_EXPR
:
8227 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8231 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8235 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8236 build (LT_EXPR
, integer_type_node
,
8237 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8238 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8240 /* ... fall through ... */
8244 dw_loc_descr_ref lhs
8245 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8246 dw_loc_descr_ref rhs
8247 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8248 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8250 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8251 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8254 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8255 add_loc_descr (&ret
, bra_node
);
8257 add_loc_descr (&ret
, rhs
);
8258 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8259 add_loc_descr (&ret
, jump_node
);
8261 add_loc_descr (&ret
, lhs
);
8262 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8263 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8265 /* ??? Need a node to point the skip at. Use a nop. */
8266 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8267 add_loc_descr (&ret
, tmp
);
8268 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8269 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8277 /* Show if we can't fill the request for an address. */
8278 if (addressp
&& indirect_p
== 0)
8281 /* If we've got an address and don't want one, dereference. */
8282 if (!addressp
&& indirect_p
> 0)
8284 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8286 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8288 else if (size
== DWARF2_ADDR_SIZE
)
8291 op
= DW_OP_deref_size
;
8293 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8299 /* Given a value, round it up to the lowest multiple of `boundary'
8300 which is not less than the value itself. */
8302 static inline HOST_WIDE_INT
8303 ceiling (value
, boundary
)
8304 HOST_WIDE_INT value
;
8305 unsigned int boundary
;
8307 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8310 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8311 pointer to the declared type for the relevant field variable, or return
8312 `integer_type_node' if the given node turns out to be an
8321 if (TREE_CODE (decl
) == ERROR_MARK
)
8322 return integer_type_node
;
8324 type
= DECL_BIT_FIELD_TYPE (decl
);
8325 if (type
== NULL_TREE
)
8326 type
= TREE_TYPE (decl
);
8331 /* Given a pointer to a tree node, return the alignment in bits for
8332 it, or else return BITS_PER_WORD if the node actually turns out to
8333 be an ERROR_MARK node. */
8335 static inline unsigned
8336 simple_type_align_in_bits (type
)
8339 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8342 static inline unsigned
8343 simple_decl_align_in_bits (decl
)
8346 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8349 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8350 node, return the size in bits for the type if it is a constant, or else
8351 return the alignment for the type if the type's size is not constant, or
8352 else return BITS_PER_WORD if the type actually turns out to be an
8355 static inline unsigned HOST_WIDE_INT
8356 simple_type_size_in_bits (type
)
8360 if (TREE_CODE (type
) == ERROR_MARK
)
8361 return BITS_PER_WORD
;
8362 else if (TYPE_SIZE (type
) == NULL_TREE
)
8364 else if (host_integerp (TYPE_SIZE (type
), 1))
8365 return tree_low_cst (TYPE_SIZE (type
), 1);
8367 return TYPE_ALIGN (type
);
8370 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8371 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8372 or return 0 if we are unable to determine what that offset is, either
8373 because the argument turns out to be a pointer to an ERROR_MARK node, or
8374 because the offset is actually variable. (We can't handle the latter case
8377 static HOST_WIDE_INT
8378 field_byte_offset (decl
)
8381 unsigned int type_align_in_bits
;
8382 unsigned int decl_align_in_bits
;
8383 unsigned HOST_WIDE_INT type_size_in_bits
;
8384 HOST_WIDE_INT object_offset_in_bits
;
8386 tree field_size_tree
;
8387 HOST_WIDE_INT bitpos_int
;
8388 HOST_WIDE_INT deepest_bitpos
;
8389 unsigned HOST_WIDE_INT field_size_in_bits
;
8391 if (TREE_CODE (decl
) == ERROR_MARK
)
8393 else if (TREE_CODE (decl
) != FIELD_DECL
)
8396 type
= field_type (decl
);
8397 field_size_tree
= DECL_SIZE (decl
);
8399 /* The size could be unspecified if there was an error, or for
8400 a flexible array member. */
8401 if (! field_size_tree
)
8402 field_size_tree
= bitsize_zero_node
;
8404 /* We cannot yet cope with fields whose positions are variable, so
8405 for now, when we see such things, we simply return 0. Someday, we may
8406 be able to handle such cases, but it will be damn difficult. */
8407 if (! host_integerp (bit_position (decl
), 0))
8410 bitpos_int
= int_bit_position (decl
);
8412 /* If we don't know the size of the field, pretend it's a full word. */
8413 if (host_integerp (field_size_tree
, 1))
8414 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8416 field_size_in_bits
= BITS_PER_WORD
;
8418 type_size_in_bits
= simple_type_size_in_bits (type
);
8419 type_align_in_bits
= simple_type_align_in_bits (type
);
8420 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8422 /* The GCC front-end doesn't make any attempt to keep track of the starting
8423 bit offset (relative to the start of the containing structure type) of the
8424 hypothetical "containing object" for a bit-field. Thus, when computing
8425 the byte offset value for the start of the "containing object" of a
8426 bit-field, we must deduce this information on our own. This can be rather
8427 tricky to do in some cases. For example, handling the following structure
8428 type definition when compiling for an i386/i486 target (which only aligns
8429 long long's to 32-bit boundaries) can be very tricky:
8431 struct S { int field1; long long field2:31; };
8433 Fortunately, there is a simple rule-of-thumb which can be used in such
8434 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8435 structure shown above. It decides to do this based upon one simple rule
8436 for bit-field allocation. GCC allocates each "containing object" for each
8437 bit-field at the first (i.e. lowest addressed) legitimate alignment
8438 boundary (based upon the required minimum alignment for the declared type
8439 of the field) which it can possibly use, subject to the condition that
8440 there is still enough available space remaining in the containing object
8441 (when allocated at the selected point) to fully accommodate all of the
8442 bits of the bit-field itself.
8444 This simple rule makes it obvious why GCC allocates 8 bytes for each
8445 object of the structure type shown above. When looking for a place to
8446 allocate the "containing object" for `field2', the compiler simply tries
8447 to allocate a 64-bit "containing object" at each successive 32-bit
8448 boundary (starting at zero) until it finds a place to allocate that 64-
8449 bit field such that at least 31 contiguous (and previously unallocated)
8450 bits remain within that selected 64 bit field. (As it turns out, for the
8451 example above, the compiler finds it is OK to allocate the "containing
8452 object" 64-bit field at bit-offset zero within the structure type.)
8454 Here we attempt to work backwards from the limited set of facts we're
8455 given, and we try to deduce from those facts, where GCC must have believed
8456 that the containing object started (within the structure type). The value
8457 we deduce is then used (by the callers of this routine) to generate
8458 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8459 and, in the case of DW_AT_location, regular fields as well). */
8461 /* Figure out the bit-distance from the start of the structure to the
8462 "deepest" bit of the bit-field. */
8463 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8465 /* This is the tricky part. Use some fancy footwork to deduce where the
8466 lowest addressed bit of the containing object must be. */
8467 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8469 /* Round up to type_align by default. This works best for bitfields. */
8470 object_offset_in_bits
+= type_align_in_bits
- 1;
8471 object_offset_in_bits
/= type_align_in_bits
;
8472 object_offset_in_bits
*= type_align_in_bits
;
8474 if (object_offset_in_bits
> bitpos_int
)
8476 /* Sigh, the decl must be packed. */
8477 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8479 /* Round up to decl_align instead. */
8480 object_offset_in_bits
+= decl_align_in_bits
- 1;
8481 object_offset_in_bits
/= decl_align_in_bits
;
8482 object_offset_in_bits
*= decl_align_in_bits
;
8485 return object_offset_in_bits
/ BITS_PER_UNIT
;
8488 /* The following routines define various Dwarf attributes and any data
8489 associated with them. */
8491 /* Add a location description attribute value to a DIE.
8493 This emits location attributes suitable for whole variables and
8494 whole parameters. Note that the location attributes for struct fields are
8495 generated by the routine `data_member_location_attribute' below. */
8498 add_AT_location_description (die
, attr_kind
, rtl
)
8500 enum dwarf_attribute attr_kind
;
8503 dw_loc_descr_ref descr
= loc_descriptor (rtl
);
8506 add_AT_loc (die
, attr_kind
, descr
);
8509 /* Attach the specialized form of location attribute used for data members of
8510 struct and union types. In the special case of a FIELD_DECL node which
8511 represents a bit-field, the "offset" part of this special location
8512 descriptor must indicate the distance in bytes from the lowest-addressed
8513 byte of the containing struct or union type to the lowest-addressed byte of
8514 the "containing object" for the bit-field. (See the `field_byte_offset'
8517 For any given bit-field, the "containing object" is a hypothetical object
8518 (of some integral or enum type) within which the given bit-field lives. The
8519 type of this hypothetical "containing object" is always the same as the
8520 declared type of the individual bit-field itself (for GCC anyway... the
8521 DWARF spec doesn't actually mandate this). Note that it is the size (in
8522 bytes) of the hypothetical "containing object" which will be given in the
8523 DW_AT_byte_size attribute for this bit-field. (See the
8524 `byte_size_attribute' function below.) It is also used when calculating the
8525 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8529 add_data_member_location_attribute (die
, decl
)
8534 dw_loc_descr_ref loc_descr
= 0;
8536 if (TREE_CODE (decl
) == TREE_VEC
)
8538 /* We're working on the TAG_inheritance for a base class. */
8539 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8541 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8542 aren't at a fixed offset from all (sub)objects of the same
8543 type. We need to extract the appropriate offset from our
8544 vtable. The following dwarf expression means
8546 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8548 This is specific to the V3 ABI, of course. */
8550 dw_loc_descr_ref tmp
;
8552 /* Make a copy of the object address. */
8553 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8554 add_loc_descr (&loc_descr
, tmp
);
8556 /* Extract the vtable address. */
8557 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8558 add_loc_descr (&loc_descr
, tmp
);
8560 /* Calculate the address of the offset. */
8561 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8565 tmp
= int_loc_descriptor (-offset
);
8566 add_loc_descr (&loc_descr
, tmp
);
8567 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8568 add_loc_descr (&loc_descr
, tmp
);
8570 /* Extract the offset. */
8571 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8572 add_loc_descr (&loc_descr
, tmp
);
8574 /* Add it to the object address. */
8575 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
8576 add_loc_descr (&loc_descr
, tmp
);
8579 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
8582 offset
= field_byte_offset (decl
);
8586 enum dwarf_location_atom op
;
8588 /* The DWARF2 standard says that we should assume that the structure
8589 address is already on the stack, so we can specify a structure field
8590 address by using DW_OP_plus_uconst. */
8592 #ifdef MIPS_DEBUGGING_INFO
8593 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8594 operator correctly. It works only if we leave the offset on the
8598 op
= DW_OP_plus_uconst
;
8601 loc_descr
= new_loc_descr (op
, offset
, 0);
8604 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
8607 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8608 does not have a "location" either in memory or in a register. These
8609 things can arise in GNU C when a constant is passed as an actual parameter
8610 to an inlined function. They can also arise in C++ where declared
8611 constants do not necessarily get memory "homes". */
8614 add_const_value_attribute (die
, rtl
)
8618 switch (GET_CODE (rtl
))
8621 /* Note that a CONST_INT rtx could represent either an integer
8622 or a floating-point constant. A CONST_INT is used whenever
8623 the constant will fit into a single word. In all such
8624 cases, the original mode of the constant value is wiped
8625 out, and the CONST_INT rtx is assigned VOIDmode. */
8627 HOST_WIDE_INT val
= INTVAL (rtl
);
8629 /* ??? We really should be using HOST_WIDE_INT throughout. */
8630 if (val
< 0 && (long) val
== val
)
8631 add_AT_int (die
, DW_AT_const_value
, (long) val
);
8632 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
8633 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
8636 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8637 add_AT_long_long (die
, DW_AT_const_value
,
8638 val
>> HOST_BITS_PER_LONG
, val
);
8647 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8648 floating-point constant. A CONST_DOUBLE is used whenever the
8649 constant requires more than one word in order to be adequately
8650 represented. We output CONST_DOUBLEs as blocks. */
8652 enum machine_mode mode
= GET_MODE (rtl
);
8654 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
8656 unsigned length
= GET_MODE_SIZE (mode
) / 4;
8657 long *array
= (long *) xmalloc (sizeof (long) * length
);
8660 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
8664 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
8668 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
8673 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
8680 add_AT_float (die
, DW_AT_const_value
, length
, array
);
8684 /* ??? We really should be using HOST_WIDE_INT throughout. */
8685 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
8688 add_AT_long_long (die
, DW_AT_const_value
,
8689 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
8695 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
8701 add_AT_addr (die
, DW_AT_const_value
, rtl
);
8702 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8706 /* In cases where an inlined instance of an inline function is passed
8707 the address of an `auto' variable (which is local to the caller) we
8708 can get a situation where the DECL_RTL of the artificial local
8709 variable (for the inlining) which acts as a stand-in for the
8710 corresponding formal parameter (of the inline function) will look
8711 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8712 exactly a compile-time constant expression, but it isn't the address
8713 of the (artificial) local variable either. Rather, it represents the
8714 *value* which the artificial local variable always has during its
8715 lifetime. We currently have no way to represent such quasi-constant
8716 values in Dwarf, so for now we just punt and generate nothing. */
8720 /* No other kinds of rtx should be possible here. */
8727 rtl_for_decl_location (decl
)
8732 /* Here we have to decide where we are going to say the parameter "lives"
8733 (as far as the debugger is concerned). We only have a couple of
8734 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8736 DECL_RTL normally indicates where the parameter lives during most of the
8737 activation of the function. If optimization is enabled however, this
8738 could be either NULL or else a pseudo-reg. Both of those cases indicate
8739 that the parameter doesn't really live anywhere (as far as the code
8740 generation parts of GCC are concerned) during most of the function's
8741 activation. That will happen (for example) if the parameter is never
8742 referenced within the function.
8744 We could just generate a location descriptor here for all non-NULL
8745 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8746 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8747 where DECL_RTL is NULL or is a pseudo-reg.
8749 Note however that we can only get away with using DECL_INCOMING_RTL as
8750 a backup substitute for DECL_RTL in certain limited cases. In cases
8751 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8752 we can be sure that the parameter was passed using the same type as it is
8753 declared to have within the function, and that its DECL_INCOMING_RTL
8754 points us to a place where a value of that type is passed.
8756 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8757 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8758 because in these cases DECL_INCOMING_RTL points us to a value of some
8759 type which is *different* from the type of the parameter itself. Thus,
8760 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8761 such cases, the debugger would end up (for example) trying to fetch a
8762 `float' from a place which actually contains the first part of a
8763 `double'. That would lead to really incorrect and confusing
8764 output at debug-time.
8766 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8767 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8768 are a couple of exceptions however. On little-endian machines we can
8769 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8770 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8771 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8772 when (on a little-endian machine) a non-prototyped function has a
8773 parameter declared to be of type `short' or `char'. In such cases,
8774 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8775 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8776 passed `int' value. If the debugger then uses that address to fetch
8777 a `short' or a `char' (on a little-endian machine) the result will be
8778 the correct data, so we allow for such exceptional cases below.
8780 Note that our goal here is to describe the place where the given formal
8781 parameter lives during most of the function's activation (i.e. between the
8782 end of the prologue and the start of the epilogue). We'll do that as best
8783 as we can. Note however that if the given formal parameter is modified
8784 sometime during the execution of the function, then a stack backtrace (at
8785 debug-time) will show the function as having been called with the *new*
8786 value rather than the value which was originally passed in. This happens
8787 rarely enough that it is not a major problem, but it *is* a problem, and
8790 A future version of dwarf2out.c may generate two additional attributes for
8791 any given DW_TAG_formal_parameter DIE which will describe the "passed
8792 type" and the "passed location" for the given formal parameter in addition
8793 to the attributes we now generate to indicate the "declared type" and the
8794 "active location" for each parameter. This additional set of attributes
8795 could be used by debuggers for stack backtraces. Separately, note that
8796 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8797 This happens (for example) for inlined-instances of inline function formal
8798 parameters which are never referenced. This really shouldn't be
8799 happening. All PARM_DECL nodes should get valid non-NULL
8800 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8801 values for inlined instances of inline function parameters, so when we see
8802 such cases, we are just out-of-luck for the time being (until integrate.c
8805 /* Use DECL_RTL as the "location" unless we find something better. */
8806 rtl
= DECL_RTL_IF_SET (decl
);
8808 /* When generating abstract instances, ignore everything except
8809 constants and symbols living in memory. */
8810 if (! reload_completed
)
8813 && (CONSTANT_P (rtl
)
8814 || (GET_CODE (rtl
) == MEM
8815 && CONSTANT_P (XEXP (rtl
, 0)))))
8817 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8818 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8824 else if (TREE_CODE (decl
) == PARM_DECL
)
8826 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
8828 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
8829 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
8831 /* This decl represents a formal parameter which was optimized out.
8832 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8833 all cases where (rtl == NULL_RTX) just below. */
8834 if (declared_type
== passed_type
)
8835 rtl
= DECL_INCOMING_RTL (decl
);
8836 else if (! BYTES_BIG_ENDIAN
8837 && TREE_CODE (declared_type
) == INTEGER_TYPE
8838 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
8839 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
8840 rtl
= DECL_INCOMING_RTL (decl
);
8843 /* If the parm was passed in registers, but lives on the stack, then
8844 make a big endian correction if the mode of the type of the
8845 parameter is not the same as the mode of the rtl. */
8846 /* ??? This is the same series of checks that are made in dbxout.c before
8847 we reach the big endian correction code there. It isn't clear if all
8848 of these checks are necessary here, but keeping them all is the safe
8850 else if (GET_CODE (rtl
) == MEM
8851 && XEXP (rtl
, 0) != const0_rtx
8852 && ! CONSTANT_P (XEXP (rtl
, 0))
8853 /* Not passed in memory. */
8854 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
8855 /* Not passed by invisible reference. */
8856 && (GET_CODE (XEXP (rtl
, 0)) != REG
8857 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
8858 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
8859 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8860 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
8863 /* Big endian correction check. */
8865 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
8866 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
8869 int offset
= (UNITS_PER_WORD
8870 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
8872 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
8873 plus_constant (XEXP (rtl
, 0), offset
));
8877 if (rtl
!= NULL_RTX
)
8879 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
8880 #ifdef LEAF_REG_REMAP
8881 if (current_function_uses_only_leaf_regs
)
8882 leaf_renumber_regs_insn (rtl
);
8886 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8887 and will have been substituted directly into all expressions that use it.
8888 C does not have such a concept, but C++ and other languages do. */
8889 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
8891 /* If a variable is initialized with a string constant without embedded
8892 zeros, build CONST_STRING. */
8893 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
8894 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
8896 tree arrtype
= TREE_TYPE (decl
);
8897 tree enttype
= TREE_TYPE (arrtype
);
8898 tree domain
= TYPE_DOMAIN (arrtype
);
8899 tree init
= DECL_INITIAL (decl
);
8900 enum machine_mode mode
= TYPE_MODE (enttype
);
8902 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
8904 && integer_zerop (TYPE_MIN_VALUE (domain
))
8905 && compare_tree_int (TYPE_MAX_VALUE (domain
),
8906 TREE_STRING_LENGTH (init
) - 1) == 0
8907 && ((size_t) TREE_STRING_LENGTH (init
)
8908 == strlen (TREE_STRING_POINTER (init
)) + 1))
8909 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
8911 /* If the initializer is something that we know will expand into an
8912 immediate RTL constant, expand it now. Expanding anything else
8913 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8914 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
8915 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
8917 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
8918 EXPAND_INITIALIZER
);
8919 /* If expand_expr returns a MEM, it wasn't immediate. */
8920 if (rtl
&& GET_CODE (rtl
) == MEM
)
8925 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8927 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8932 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8933 data attribute for a variable or a parameter. We generate the
8934 DW_AT_const_value attribute only in those cases where the given variable
8935 or parameter does not have a true "location" either in memory or in a
8936 register. This can happen (for example) when a constant is passed as an
8937 actual argument in a call to an inline function. (It's possible that
8938 these things can crop up in other ways also.) Note that one type of
8939 constant value which can be passed into an inlined function is a constant
8940 pointer. This can happen for example if an actual argument in an inlined
8941 function call evaluates to a compile-time constant address. */
8944 add_location_or_const_value_attribute (die
, decl
)
8950 if (TREE_CODE (decl
) == ERROR_MARK
)
8952 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
8955 rtl
= rtl_for_decl_location (decl
);
8956 if (rtl
== NULL_RTX
)
8959 /* If we don't look past the constant pool, we risk emitting a
8960 reference to a constant pool entry that isn't referenced from
8961 code, and thus is not emitted. */
8962 rtl
= avoid_constant_pool_reference (rtl
);
8964 switch (GET_CODE (rtl
))
8967 /* The address of a variable that was optimized away; don't emit
8978 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8979 add_const_value_attribute (die
, rtl
);
8986 add_AT_location_description (die
, DW_AT_location
, rtl
);
8994 /* If we don't have a copy of this variable in memory for some reason (such
8995 as a C++ member constant that doesn't have an out-of-line definition),
8996 we should tell the debugger about the constant value. */
8999 tree_add_const_value_attribute (var_die
, decl
)
9003 tree init
= DECL_INITIAL (decl
);
9004 tree type
= TREE_TYPE (decl
);
9006 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9007 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9012 switch (TREE_CODE (type
))
9015 if (host_integerp (init
, 0))
9016 add_AT_unsigned (var_die
, DW_AT_const_value
,
9017 tree_low_cst (init
, 0));
9019 add_AT_long_long (var_die
, DW_AT_const_value
,
9020 TREE_INT_CST_HIGH (init
),
9021 TREE_INT_CST_LOW (init
));
9028 /* Generate an DW_AT_name attribute given some string value to be included as
9029 the value of the attribute. */
9032 add_name_attribute (die
, name_string
)
9034 const char *name_string
;
9036 if (name_string
!= NULL
&& *name_string
!= 0)
9038 if (demangle_name_func
)
9039 name_string
= (*demangle_name_func
) (name_string
);
9041 add_AT_string (die
, DW_AT_name
, name_string
);
9045 /* Given a tree node describing an array bound (either lower or upper) output
9046 a representation for that bound. */
9049 add_bound_info (subrange_die
, bound_attr
, bound
)
9050 dw_die_ref subrange_die
;
9051 enum dwarf_attribute bound_attr
;
9054 switch (TREE_CODE (bound
))
9059 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9061 if (! host_integerp (bound
, 0)
9062 || (bound_attr
== DW_AT_lower_bound
9063 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9064 || (is_fortran () && integer_onep (bound
)))))
9065 /* use the default */
9068 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9073 case NON_LVALUE_EXPR
:
9074 case VIEW_CONVERT_EXPR
:
9075 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9079 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9080 access the upper bound values may be bogus. If they refer to a
9081 register, they may only describe how to get at these values at the
9082 points in the generated code right after they have just been
9083 computed. Worse yet, in the typical case, the upper bound values
9084 will not even *be* computed in the optimized code (though the
9085 number of elements will), so these SAVE_EXPRs are entirely
9086 bogus. In order to compensate for this fact, we check here to see
9087 if optimization is enabled, and if so, we don't add an attribute
9088 for the (unknown and unknowable) upper bound. This should not
9089 cause too much trouble for existing (stupid?) debuggers because
9090 they have to deal with empty upper bounds location descriptions
9091 anyway in order to be able to deal with incomplete array types.
9092 Of course an intelligent debugger (GDB?) should be able to
9093 comprehend that a missing upper bound specification in an array
9094 type used for a storage class `auto' local array variable
9095 indicates that the upper bound is both unknown (at compile- time)
9096 and unknowable (at run-time) due to optimization.
9098 We assume that a MEM rtx is safe because gcc wouldn't put the
9099 value there unless it was going to be used repeatedly in the
9100 function, i.e. for cleanups. */
9101 if (SAVE_EXPR_RTL (bound
)
9102 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9104 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9105 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9106 rtx loc
= SAVE_EXPR_RTL (bound
);
9108 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9109 it references an outer function's frame. */
9110 if (GET_CODE (loc
) == MEM
)
9112 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9114 if (XEXP (loc
, 0) != new_addr
)
9115 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9118 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9119 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9120 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
9121 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9124 /* Else leave out the attribute. */
9130 dw_die_ref decl_die
= lookup_decl_die (bound
);
9132 /* ??? Can this happen, or should the variable have been bound
9133 first? Probably it can, since I imagine that we try to create
9134 the types of parameters in the order in which they exist in
9135 the list, and won't have created a forward reference to a
9137 if (decl_die
!= NULL
)
9138 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9144 /* Otherwise try to create a stack operation procedure to
9145 evaluate the value of the array bound. */
9147 dw_die_ref ctx
, decl_die
;
9148 dw_loc_descr_ref loc
;
9150 loc
= loc_descriptor_from_tree (bound
, 0);
9154 if (current_function_decl
== 0)
9155 ctx
= comp_unit_die
;
9157 ctx
= lookup_decl_die (current_function_decl
);
9159 /* If we weren't able to find a context, it's most likely the case
9160 that we are processing the return type of the function. So
9161 make a SAVE_EXPR to point to it and have the limbo DIE code
9162 find the proper die. The save_expr function doesn't always
9163 make a SAVE_EXPR, so do it ourselves. */
9165 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9166 current_function_decl
, NULL_TREE
);
9168 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9169 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9170 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9171 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9173 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9179 /* Note that the block of subscript information for an array type also
9180 includes information about the element type of type given array type. */
9183 add_subscript_info (type_die
, type
)
9184 dw_die_ref type_die
;
9187 #ifndef MIPS_DEBUGGING_INFO
9188 unsigned dimension_number
;
9191 dw_die_ref subrange_die
;
9193 /* The GNU compilers represent multidimensional array types as sequences of
9194 one dimensional array types whose element types are themselves array
9195 types. Here we squish that down, so that each multidimensional array
9196 type gets only one array_type DIE in the Dwarf debugging info. The draft
9197 Dwarf specification say that we are allowed to do this kind of
9198 compression in C (because there is no difference between an array or
9199 arrays and a multidimensional array in C) but for other source languages
9200 (e.g. Ada) we probably shouldn't do this. */
9202 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9203 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9204 We work around this by disabling this feature. See also
9205 gen_array_type_die. */
9206 #ifndef MIPS_DEBUGGING_INFO
9207 for (dimension_number
= 0;
9208 TREE_CODE (type
) == ARRAY_TYPE
;
9209 type
= TREE_TYPE (type
), dimension_number
++)
9212 tree domain
= TYPE_DOMAIN (type
);
9214 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9215 and (in GNU C only) variable bounds. Handle all three forms
9217 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9220 /* We have an array type with specified bounds. */
9221 lower
= TYPE_MIN_VALUE (domain
);
9222 upper
= TYPE_MAX_VALUE (domain
);
9224 /* define the index type. */
9225 if (TREE_TYPE (domain
))
9227 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9228 TREE_TYPE field. We can't emit debug info for this
9229 because it is an unnamed integral type. */
9230 if (TREE_CODE (domain
) == INTEGER_TYPE
9231 && TYPE_NAME (domain
) == NULL_TREE
9232 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9233 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9236 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9240 /* ??? If upper is NULL, the array has unspecified length,
9241 but it does have a lower bound. This happens with Fortran
9243 Since the debugger is definitely going to need to know N
9244 to produce useful results, go ahead and output the lower
9245 bound solo, and hope the debugger can cope. */
9247 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9249 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9252 /* Otherwise we have an array type with an unspecified length. The
9253 DWARF-2 spec does not say how to handle this; let's just leave out the
9259 add_byte_size_attribute (die
, tree_node
)
9265 switch (TREE_CODE (tree_node
))
9273 case QUAL_UNION_TYPE
:
9274 size
= int_size_in_bytes (tree_node
);
9277 /* For a data member of a struct or union, the DW_AT_byte_size is
9278 generally given as the number of bytes normally allocated for an
9279 object of the *declared* type of the member itself. This is true
9280 even for bit-fields. */
9281 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9287 /* Note that `size' might be -1 when we get to this point. If it is, that
9288 indicates that the byte size of the entity in question is variable. We
9289 have no good way of expressing this fact in Dwarf at the present time,
9290 so just let the -1 pass on through. */
9291 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9294 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9295 which specifies the distance in bits from the highest order bit of the
9296 "containing object" for the bit-field to the highest order bit of the
9299 For any given bit-field, the "containing object" is a hypothetical object
9300 (of some integral or enum type) within which the given bit-field lives. The
9301 type of this hypothetical "containing object" is always the same as the
9302 declared type of the individual bit-field itself. The determination of the
9303 exact location of the "containing object" for a bit-field is rather
9304 complicated. It's handled by the `field_byte_offset' function (above).
9306 Note that it is the size (in bytes) of the hypothetical "containing object"
9307 which will be given in the DW_AT_byte_size attribute for this bit-field.
9308 (See `byte_size_attribute' above). */
9311 add_bit_offset_attribute (die
, decl
)
9315 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9316 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9317 HOST_WIDE_INT bitpos_int
;
9318 HOST_WIDE_INT highest_order_object_bit_offset
;
9319 HOST_WIDE_INT highest_order_field_bit_offset
;
9320 HOST_WIDE_INT
unsigned bit_offset
;
9322 /* Must be a field and a bit field. */
9324 || TREE_CODE (decl
) != FIELD_DECL
)
9327 /* We can't yet handle bit-fields whose offsets are variable, so if we
9328 encounter such things, just return without generating any attribute
9329 whatsoever. Likewise for variable or too large size. */
9330 if (! host_integerp (bit_position (decl
), 0)
9331 || ! host_integerp (DECL_SIZE (decl
), 1))
9334 bitpos_int
= int_bit_position (decl
);
9336 /* Note that the bit offset is always the distance (in bits) from the
9337 highest-order bit of the "containing object" to the highest-order bit of
9338 the bit-field itself. Since the "high-order end" of any object or field
9339 is different on big-endian and little-endian machines, the computation
9340 below must take account of these differences. */
9341 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9342 highest_order_field_bit_offset
= bitpos_int
;
9344 if (! BYTES_BIG_ENDIAN
)
9346 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9347 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9351 = (! BYTES_BIG_ENDIAN
9352 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9353 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9355 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9358 /* For a FIELD_DECL node which represents a bit field, output an attribute
9359 which specifies the length in bits of the given field. */
9362 add_bit_size_attribute (die
, decl
)
9366 /* Must be a field and a bit field. */
9367 if (TREE_CODE (decl
) != FIELD_DECL
9368 || ! DECL_BIT_FIELD_TYPE (decl
))
9371 if (host_integerp (DECL_SIZE (decl
), 1))
9372 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9375 /* If the compiled language is ANSI C, then add a 'prototyped'
9376 attribute, if arg types are given for the parameters of a function. */
9379 add_prototyped_attribute (die
, func_type
)
9383 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9384 && TYPE_ARG_TYPES (func_type
) != NULL
)
9385 add_AT_flag (die
, DW_AT_prototyped
, 1);
9388 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9389 by looking in either the type declaration or object declaration
9393 add_abstract_origin_attribute (die
, origin
)
9397 dw_die_ref origin_die
= NULL
;
9399 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9401 /* We may have gotten separated from the block for the inlined
9402 function, if we're in an exception handler or some such; make
9403 sure that the abstract function has been written out.
9405 Doing this for nested functions is wrong, however; functions are
9406 distinct units, and our context might not even be inline. */
9410 fn
= TYPE_STUB_DECL (fn
);
9412 fn
= decl_function_context (fn
);
9414 dwarf2out_abstract_function (fn
);
9417 if (DECL_P (origin
))
9418 origin_die
= lookup_decl_die (origin
);
9419 else if (TYPE_P (origin
))
9420 origin_die
= lookup_type_die (origin
);
9422 if (origin_die
== NULL
)
9425 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9428 /* We do not currently support the pure_virtual attribute. */
9431 add_pure_or_virtual_attribute (die
, func_decl
)
9435 if (DECL_VINDEX (func_decl
))
9437 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9439 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9440 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9441 new_loc_descr (DW_OP_constu
,
9442 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9445 /* GNU extension: Record what type this method came from originally. */
9446 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9447 add_AT_die_ref (die
, DW_AT_containing_type
,
9448 lookup_type_die (DECL_CONTEXT (func_decl
)));
9452 /* Add source coordinate attributes for the given decl. */
9455 add_src_coords_attributes (die
, decl
)
9459 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9461 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9462 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9465 /* Add an DW_AT_name attribute and source coordinate attribute for the
9466 given decl, but only if it actually has a name. */
9469 add_name_and_src_coords_attributes (die
, decl
)
9475 decl_name
= DECL_NAME (decl
);
9476 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9478 add_name_attribute (die
, dwarf2_name (decl
, 0));
9479 if (! DECL_ARTIFICIAL (decl
))
9480 add_src_coords_attributes (die
, decl
);
9482 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9483 && TREE_PUBLIC (decl
)
9484 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9485 && !DECL_ABSTRACT (decl
))
9486 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9487 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9490 #ifdef VMS_DEBUGGING_INFO
9491 /* Get the function's name, as described by its RTL. This may be different
9492 from the DECL_NAME name used in the source file. */
9493 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9495 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9496 XEXP (DECL_RTL (decl
), 0));
9497 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9502 /* Push a new declaration scope. */
9505 push_decl_scope (scope
)
9508 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9511 /* Pop a declaration scope. */
9516 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9519 VARRAY_POP (decl_scope_table
);
9522 /* Return the DIE for the scope that immediately contains this type.
9523 Non-named types get global scope. Named types nested in other
9524 types get their containing scope if it's open, or global scope
9525 otherwise. All other types (i.e. function-local named types) get
9526 the current active scope. */
9529 scope_die_for (t
, context_die
)
9531 dw_die_ref context_die
;
9533 dw_die_ref scope_die
= NULL
;
9534 tree containing_scope
;
9537 /* Non-types always go in the current scope. */
9541 containing_scope
= TYPE_CONTEXT (t
);
9543 /* Ignore namespaces for the moment. */
9544 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9545 containing_scope
= NULL_TREE
;
9547 /* Ignore function type "scopes" from the C frontend. They mean that
9548 a tagged type is local to a parmlist of a function declarator, but
9549 that isn't useful to DWARF. */
9550 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9551 containing_scope
= NULL_TREE
;
9553 if (containing_scope
== NULL_TREE
)
9554 scope_die
= comp_unit_die
;
9555 else if (TYPE_P (containing_scope
))
9557 /* For types, we can just look up the appropriate DIE. But
9558 first we check to see if we're in the middle of emitting it
9559 so we know where the new DIE should go. */
9560 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9561 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9566 if (debug_info_level
> DINFO_LEVEL_TERSE
9567 && !TREE_ASM_WRITTEN (containing_scope
))
9570 /* If none of the current dies are suitable, we get file scope. */
9571 scope_die
= comp_unit_die
;
9574 scope_die
= lookup_type_die (containing_scope
);
9577 scope_die
= context_die
;
9582 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9585 local_scope_p (context_die
)
9586 dw_die_ref context_die
;
9588 for (; context_die
; context_die
= context_die
->die_parent
)
9589 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
9590 || context_die
->die_tag
== DW_TAG_subprogram
)
9596 /* Returns nonzero if CONTEXT_DIE is a class. */
9599 class_scope_p (context_die
)
9600 dw_die_ref context_die
;
9603 && (context_die
->die_tag
== DW_TAG_structure_type
9604 || context_die
->die_tag
== DW_TAG_union_type
));
9607 /* Many forms of DIEs require a "type description" attribute. This
9608 routine locates the proper "type descriptor" die for the type given
9609 by 'type', and adds an DW_AT_type attribute below the given die. */
9612 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
9613 dw_die_ref object_die
;
9617 dw_die_ref context_die
;
9619 enum tree_code code
= TREE_CODE (type
);
9620 dw_die_ref type_die
= NULL
;
9622 /* ??? If this type is an unnamed subrange type of an integral or
9623 floating-point type, use the inner type. This is because we have no
9624 support for unnamed types in base_type_die. This can happen if this is
9625 an Ada subrange type. Correct solution is emit a subrange type die. */
9626 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
9627 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
9628 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
9630 if (code
== ERROR_MARK
9631 /* Handle a special case. For functions whose return type is void, we
9632 generate *no* type attribute. (Note that no object may have type
9633 `void', so this only applies to function return types). */
9634 || code
== VOID_TYPE
)
9637 type_die
= modified_type_die (type
,
9638 decl_const
|| TYPE_READONLY (type
),
9639 decl_volatile
|| TYPE_VOLATILE (type
),
9642 if (type_die
!= NULL
)
9643 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
9646 /* Given a tree pointer to a struct, class, union, or enum type node, return
9647 a pointer to the (string) tag name for the given type, or zero if the type
9648 was declared without a tag. */
9654 const char *name
= 0;
9656 if (TYPE_NAME (type
) != 0)
9660 /* Find the IDENTIFIER_NODE for the type name. */
9661 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9662 t
= TYPE_NAME (type
);
9664 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9665 a TYPE_DECL node, regardless of whether or not a `typedef' was
9667 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9668 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
9669 t
= DECL_NAME (TYPE_NAME (type
));
9671 /* Now get the name as a string, or invent one. */
9673 name
= IDENTIFIER_POINTER (t
);
9676 return (name
== 0 || *name
== '\0') ? 0 : name
;
9679 /* Return the type associated with a data member, make a special check
9680 for bit field types. */
9683 member_declared_type (member
)
9686 return (DECL_BIT_FIELD_TYPE (member
)
9687 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
9690 /* Get the decl's label, as described by its RTL. This may be different
9691 from the DECL_NAME name used in the source file. */
9695 decl_start_label (decl
)
9701 x
= DECL_RTL (decl
);
9702 if (GET_CODE (x
) != MEM
)
9706 if (GET_CODE (x
) != SYMBOL_REF
)
9709 fnname
= XSTR (x
, 0);
9714 /* These routines generate the internal representation of the DIE's for
9715 the compilation unit. Debugging information is collected by walking
9716 the declaration trees passed in from dwarf2out_decl(). */
9719 gen_array_type_die (type
, context_die
)
9721 dw_die_ref context_die
;
9723 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
9724 dw_die_ref array_die
;
9727 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9728 the inner array type comes before the outer array type. Thus we must
9729 call gen_type_die before we call new_die. See below also. */
9730 #ifdef MIPS_DEBUGGING_INFO
9731 gen_type_die (TREE_TYPE (type
), context_die
);
9734 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
9735 add_name_attribute (array_die
, type_tag (type
));
9736 equate_type_number_to_die (type
, array_die
);
9738 if (TREE_CODE (type
) == VECTOR_TYPE
)
9740 /* The frontend feeds us a representation for the vector as a struct
9741 containing an array. Pull out the array type. */
9742 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
9743 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
9747 /* We default the array ordering. SDB will probably do
9748 the right things even if DW_AT_ordering is not present. It's not even
9749 an issue until we start to get into multidimensional arrays anyway. If
9750 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9751 then we'll have to put the DW_AT_ordering attribute back in. (But if
9752 and when we find out that we need to put these in, we will only do so
9753 for multidimensional arrays. */
9754 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
9757 #ifdef MIPS_DEBUGGING_INFO
9758 /* The SGI compilers handle arrays of unknown bound by setting
9759 AT_declaration and not emitting any subrange DIEs. */
9760 if (! TYPE_DOMAIN (type
))
9761 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
9764 add_subscript_info (array_die
, type
);
9766 /* Add representation of the type of the elements of this array type. */
9767 element_type
= TREE_TYPE (type
);
9769 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9770 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9771 We work around this by disabling this feature. See also
9772 add_subscript_info. */
9773 #ifndef MIPS_DEBUGGING_INFO
9774 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
9775 element_type
= TREE_TYPE (element_type
);
9777 gen_type_die (element_type
, context_die
);
9780 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
9784 gen_set_type_die (type
, context_die
)
9786 dw_die_ref context_die
;
9789 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
9791 equate_type_number_to_die (type
, type_die
);
9792 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
9797 gen_entry_point_die (decl
, context_die
)
9799 dw_die_ref context_die
;
9801 tree origin
= decl_ultimate_origin (decl
);
9802 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
9805 add_abstract_origin_attribute (decl_die
, origin
);
9808 add_name_and_src_coords_attributes (decl_die
, decl
);
9809 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
9813 if (DECL_ABSTRACT (decl
))
9814 equate_decl_number_to_die (decl
, decl_die
);
9816 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
9820 /* Walk through the list of incomplete types again, trying once more to
9821 emit full debugging info for them. */
9824 retry_incomplete_types ()
9828 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
9829 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
9832 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9835 gen_inlined_enumeration_type_die (type
, context_die
)
9837 dw_die_ref context_die
;
9839 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
9841 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9842 be incomplete and such types are not marked. */
9843 add_abstract_origin_attribute (type_die
, type
);
9846 /* Generate a DIE to represent an inlined instance of a structure type. */
9849 gen_inlined_structure_type_die (type
, context_die
)
9851 dw_die_ref context_die
;
9853 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
9855 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9856 be incomplete and such types are not marked. */
9857 add_abstract_origin_attribute (type_die
, type
);
9860 /* Generate a DIE to represent an inlined instance of a union type. */
9863 gen_inlined_union_type_die (type
, context_die
)
9865 dw_die_ref context_die
;
9867 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
9869 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9870 be incomplete and such types are not marked. */
9871 add_abstract_origin_attribute (type_die
, type
);
9874 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9875 include all of the information about the enumeration values also. Each
9876 enumerated type name/value is listed as a child of the enumerated type
9880 gen_enumeration_type_die (type
, context_die
)
9882 dw_die_ref context_die
;
9884 dw_die_ref type_die
= lookup_type_die (type
);
9886 if (type_die
== NULL
)
9888 type_die
= new_die (DW_TAG_enumeration_type
,
9889 scope_die_for (type
, context_die
), type
);
9890 equate_type_number_to_die (type
, type_die
);
9891 add_name_attribute (type_die
, type_tag (type
));
9893 else if (! TYPE_SIZE (type
))
9896 remove_AT (type_die
, DW_AT_declaration
);
9898 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9899 given enum type is incomplete, do not generate the DW_AT_byte_size
9900 attribute or the DW_AT_element_list attribute. */
9901 if (TYPE_SIZE (type
))
9905 TREE_ASM_WRITTEN (type
) = 1;
9906 add_byte_size_attribute (type_die
, type
);
9907 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
9908 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
9910 /* If the first reference to this type was as the return type of an
9911 inline function, then it may not have a parent. Fix this now. */
9912 if (type_die
->die_parent
== NULL
)
9913 add_child_die (scope_die_for (type
, context_die
), type_die
);
9915 for (link
= TYPE_FIELDS (type
);
9916 link
!= NULL
; link
= TREE_CHAIN (link
))
9918 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
9920 add_name_attribute (enum_die
,
9921 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
9923 if (host_integerp (TREE_VALUE (link
), 0))
9925 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
9926 add_AT_int (enum_die
, DW_AT_const_value
,
9927 tree_low_cst (TREE_VALUE (link
), 0));
9929 add_AT_unsigned (enum_die
, DW_AT_const_value
,
9930 tree_low_cst (TREE_VALUE (link
), 0));
9935 add_AT_flag (type_die
, DW_AT_declaration
, 1);
9938 /* Generate a DIE to represent either a real live formal parameter decl or to
9939 represent just the type of some formal parameter position in some function
9942 Note that this routine is a bit unusual because its argument may be a
9943 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9944 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9945 node. If it's the former then this function is being called to output a
9946 DIE to represent a formal parameter object (or some inlining thereof). If
9947 it's the latter, then this function is only being called to output a
9948 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9949 argument type of some subprogram type. */
9952 gen_formal_parameter_die (node
, context_die
)
9954 dw_die_ref context_die
;
9957 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
9960 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
9963 origin
= decl_ultimate_origin (node
);
9965 add_abstract_origin_attribute (parm_die
, origin
);
9968 add_name_and_src_coords_attributes (parm_die
, node
);
9969 add_type_attribute (parm_die
, TREE_TYPE (node
),
9970 TREE_READONLY (node
),
9971 TREE_THIS_VOLATILE (node
),
9973 if (DECL_ARTIFICIAL (node
))
9974 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
9977 equate_decl_number_to_die (node
, parm_die
);
9978 if (! DECL_ABSTRACT (node
))
9979 add_location_or_const_value_attribute (parm_die
, node
);
9984 /* We were called with some kind of a ..._TYPE node. */
9985 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
9995 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9996 at the end of an (ANSI prototyped) formal parameters list. */
9999 gen_unspecified_parameters_die (decl_or_type
, context_die
)
10001 dw_die_ref context_die
;
10003 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10006 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10007 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10008 parameters as specified in some function type specification (except for
10009 those which appear as part of a function *definition*). */
10012 gen_formal_types_die (function_or_method_type
, context_die
)
10013 tree function_or_method_type
;
10014 dw_die_ref context_die
;
10017 tree formal_type
= NULL
;
10018 tree first_parm_type
;
10021 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10023 arg
= DECL_ARGUMENTS (function_or_method_type
);
10024 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10029 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10031 /* Make our first pass over the list of formal parameter types and output a
10032 DW_TAG_formal_parameter DIE for each one. */
10033 for (link
= first_parm_type
; link
; )
10035 dw_die_ref parm_die
;
10037 formal_type
= TREE_VALUE (link
);
10038 if (formal_type
== void_type_node
)
10041 /* Output a (nameless) DIE to represent the formal parameter itself. */
10042 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10043 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10044 && link
== first_parm_type
)
10045 || (arg
&& DECL_ARTIFICIAL (arg
)))
10046 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10048 link
= TREE_CHAIN (link
);
10050 arg
= TREE_CHAIN (arg
);
10053 /* If this function type has an ellipsis, add a
10054 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10055 if (formal_type
!= void_type_node
)
10056 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10058 /* Make our second (and final) pass over the list of formal parameter types
10059 and output DIEs to represent those types (as necessary). */
10060 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10061 link
&& TREE_VALUE (link
);
10062 link
= TREE_CHAIN (link
))
10063 gen_type_die (TREE_VALUE (link
), context_die
);
10066 /* We want to generate the DIE for TYPE so that we can generate the
10067 die for MEMBER, which has been defined; we will need to refer back
10068 to the member declaration nested within TYPE. If we're trying to
10069 generate minimal debug info for TYPE, processing TYPE won't do the
10070 trick; we need to attach the member declaration by hand. */
10073 gen_type_die_for_member (type
, member
, context_die
)
10075 dw_die_ref context_die
;
10077 gen_type_die (type
, context_die
);
10079 /* If we're trying to avoid duplicate debug info, we may not have
10080 emitted the member decl for this function. Emit it now. */
10081 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10082 && ! lookup_decl_die (member
))
10084 if (decl_ultimate_origin (member
))
10087 push_decl_scope (type
);
10088 if (TREE_CODE (member
) == FUNCTION_DECL
)
10089 gen_subprogram_die (member
, lookup_type_die (type
));
10091 gen_variable_die (member
, lookup_type_die (type
));
10097 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10098 may later generate inlined and/or out-of-line instances of. */
10101 dwarf2out_abstract_function (decl
)
10104 dw_die_ref old_die
;
10107 int was_abstract
= DECL_ABSTRACT (decl
);
10109 /* Make sure we have the actual abstract inline, not a clone. */
10110 decl
= DECL_ORIGIN (decl
);
10112 old_die
= lookup_decl_die (decl
);
10113 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10114 /* We've already generated the abstract instance. */
10117 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10118 we don't get confused by DECL_ABSTRACT. */
10119 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10121 context
= decl_class_context (decl
);
10123 gen_type_die_for_member
10124 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10127 /* Pretend we've just finished compiling this function. */
10128 save_fn
= current_function_decl
;
10129 current_function_decl
= decl
;
10131 set_decl_abstract_flags (decl
, 1);
10132 dwarf2out_decl (decl
);
10133 if (! was_abstract
)
10134 set_decl_abstract_flags (decl
, 0);
10136 current_function_decl
= save_fn
;
10139 /* Generate a DIE to represent a declared function (either file-scope or
10143 gen_subprogram_die (decl
, context_die
)
10145 dw_die_ref context_die
;
10147 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10148 tree origin
= decl_ultimate_origin (decl
);
10149 dw_die_ref subr_die
;
10153 dw_die_ref old_die
= lookup_decl_die (decl
);
10154 int declaration
= (current_function_decl
!= decl
10155 || class_scope_p (context_die
));
10157 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10158 started to generate the abstract instance of an inline, decided to output
10159 its containing class, and proceeded to emit the declaration of the inline
10160 from the member list for the class. If so, DECLARATION takes priority;
10161 we'll get back to the abstract instance when done with the class. */
10163 /* The class-scope declaration DIE must be the primary DIE. */
10164 if (origin
&& declaration
&& class_scope_p (context_die
))
10171 if (origin
!= NULL
)
10173 if (declaration
&& ! local_scope_p (context_die
))
10176 /* Fixup die_parent for the abstract instance of a nested
10177 inline function. */
10178 if (old_die
&& old_die
->die_parent
== NULL
)
10179 add_child_die (context_die
, old_die
);
10181 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10182 add_abstract_origin_attribute (subr_die
, origin
);
10186 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10188 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10189 /* We can have a normal definition following an inline one in the
10190 case of redefinition of GNU C extern inlines.
10191 It seems reasonable to use AT_specification in this case. */
10192 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10194 /* ??? This can happen if there is a bug in the program, for
10195 instance, if it has duplicate function definitions. Ideally,
10196 we should detect this case and ignore it. For now, if we have
10197 already reported an error, any error at all, then assume that
10198 we got here because of an input error, not a dwarf2 bug. */
10204 /* If the definition comes from the same place as the declaration,
10205 maybe use the old DIE. We always want the DIE for this function
10206 that has the *_pc attributes to be under comp_unit_die so the
10207 debugger can find it. We also need to do this for abstract
10208 instances of inlines, since the spec requires the out-of-line copy
10209 to have the same parent. For local class methods, this doesn't
10210 apply; we just use the old DIE. */
10211 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10212 && (DECL_ARTIFICIAL (decl
)
10213 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10214 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10215 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10217 subr_die
= old_die
;
10219 /* Clear out the declaration attribute and the parm types. */
10220 remove_AT (subr_die
, DW_AT_declaration
);
10221 remove_children (subr_die
);
10225 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10226 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10227 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10228 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10229 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10230 != (unsigned) DECL_SOURCE_LINE (decl
))
10232 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10237 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10239 if (TREE_PUBLIC (decl
))
10240 add_AT_flag (subr_die
, DW_AT_external
, 1);
10242 add_name_and_src_coords_attributes (subr_die
, decl
);
10243 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10245 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10246 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10247 0, 0, context_die
);
10250 add_pure_or_virtual_attribute (subr_die
, decl
);
10251 if (DECL_ARTIFICIAL (decl
))
10252 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10254 if (TREE_PROTECTED (decl
))
10255 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10256 else if (TREE_PRIVATE (decl
))
10257 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10262 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10264 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10266 /* The first time we see a member function, it is in the context of
10267 the class to which it belongs. We make sure of this by emitting
10268 the class first. The next time is the definition, which is
10269 handled above. The two may come from the same source text. */
10270 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10271 equate_decl_number_to_die (decl
, subr_die
);
10274 else if (DECL_ABSTRACT (decl
))
10276 if (DECL_INLINE (decl
) && !flag_no_inline
)
10278 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10279 inline functions, but not for extern inline functions.
10280 We can't get this completely correct because information
10281 about whether the function was declared inline is not
10283 if (DECL_DEFER_OUTPUT (decl
))
10284 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10286 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10289 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10291 equate_decl_number_to_die (decl
, subr_die
);
10293 else if (!DECL_EXTERNAL (decl
))
10295 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10296 equate_decl_number_to_die (decl
, subr_die
);
10298 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10299 current_function_funcdef_no
);
10300 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10301 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10302 current_function_funcdef_no
);
10303 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10305 add_pubname (decl
, subr_die
);
10306 add_arange (decl
, subr_die
);
10308 #ifdef MIPS_DEBUGGING_INFO
10309 /* Add a reference to the FDE for this routine. */
10310 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10313 /* Define the "frame base" location for this routine. We use the
10314 frame pointer or stack pointer registers, since the RTL for local
10315 variables is relative to one of them. */
10317 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10318 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10321 /* ??? This fails for nested inline functions, because context_display
10322 is not part of the state saved/restored for inline functions. */
10323 if (current_function_needs_context
)
10324 add_AT_location_description (subr_die
, DW_AT_static_link
,
10325 lookup_static_chain (decl
));
10329 /* Now output descriptions of the arguments for this function. This gets
10330 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10331 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10332 `...' at the end of the formal parameter list. In order to find out if
10333 there was a trailing ellipsis or not, we must instead look at the type
10334 associated with the FUNCTION_DECL. This will be a node of type
10335 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10336 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10337 an ellipsis at the end. */
10339 /* In the case where we are describing a mere function declaration, all we
10340 need to do here (and all we *can* do here) is to describe the *types* of
10341 its formal parameters. */
10342 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10344 else if (declaration
)
10345 gen_formal_types_die (decl
, subr_die
);
10348 /* Generate DIEs to represent all known formal parameters */
10349 tree arg_decls
= DECL_ARGUMENTS (decl
);
10352 /* When generating DIEs, generate the unspecified_parameters DIE
10353 instead if we come across the arg "__builtin_va_alist" */
10354 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10355 if (TREE_CODE (parm
) == PARM_DECL
)
10357 if (DECL_NAME (parm
)
10358 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10359 "__builtin_va_alist"))
10360 gen_unspecified_parameters_die (parm
, subr_die
);
10362 gen_decl_die (parm
, subr_die
);
10365 /* Decide whether we need an unspecified_parameters DIE at the end.
10366 There are 2 more cases to do this for: 1) the ansi ... declaration -
10367 this is detectable when the end of the arg list is not a
10368 void_type_node 2) an unprototyped function declaration (not a
10369 definition). This just means that we have no info about the
10370 parameters at all. */
10371 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10372 if (fn_arg_types
!= NULL
)
10374 /* this is the prototyped case, check for ... */
10375 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10376 gen_unspecified_parameters_die (decl
, subr_die
);
10378 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10379 gen_unspecified_parameters_die (decl
, subr_die
);
10382 /* Output Dwarf info for all of the stuff within the body of the function
10383 (if it has one - it may be just a declaration). */
10384 outer_scope
= DECL_INITIAL (decl
);
10386 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10387 a function. This BLOCK actually represents the outermost binding contour
10388 for the function, i.e. the contour in which the function's formal
10389 parameters and labels get declared. Curiously, it appears that the front
10390 end doesn't actually put the PARM_DECL nodes for the current function onto
10391 the BLOCK_VARS list for this outer scope, but are strung off of the
10392 DECL_ARGUMENTS list for the function instead.
10394 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10395 the LABEL_DECL nodes for the function however, and we output DWARF info
10396 for those in decls_for_scope. Just within the `outer_scope' there will be
10397 a BLOCK node representing the function's outermost pair of curly braces,
10398 and any blocks used for the base and member initializers of a C++
10399 constructor function. */
10400 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10402 current_function_has_inlines
= 0;
10403 decls_for_scope (outer_scope
, subr_die
, 0);
10405 #if 0 && defined (MIPS_DEBUGGING_INFO)
10406 if (current_function_has_inlines
)
10408 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10409 if (! comp_unit_has_inlines
)
10411 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10412 comp_unit_has_inlines
= 1;
10419 /* Generate a DIE to represent a declared data object. */
10422 gen_variable_die (decl
, context_die
)
10424 dw_die_ref context_die
;
10426 tree origin
= decl_ultimate_origin (decl
);
10427 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10429 dw_die_ref old_die
= lookup_decl_die (decl
);
10430 int declaration
= (DECL_EXTERNAL (decl
)
10431 || class_scope_p (context_die
));
10433 if (origin
!= NULL
)
10434 add_abstract_origin_attribute (var_die
, origin
);
10436 /* Loop unrolling can create multiple blocks that refer to the same
10437 static variable, so we must test for the DW_AT_declaration flag.
10439 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10440 copy decls and set the DECL_ABSTRACT flag on them instead of
10443 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10444 else if (old_die
&& TREE_STATIC (decl
)
10445 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10447 /* This is a definition of a C++ class level static. */
10448 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10449 if (DECL_NAME (decl
))
10451 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10453 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10454 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10456 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10457 != (unsigned) DECL_SOURCE_LINE (decl
))
10459 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10460 DECL_SOURCE_LINE (decl
));
10465 add_name_and_src_coords_attributes (var_die
, decl
);
10466 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10467 TREE_THIS_VOLATILE (decl
), context_die
);
10469 if (TREE_PUBLIC (decl
))
10470 add_AT_flag (var_die
, DW_AT_external
, 1);
10472 if (DECL_ARTIFICIAL (decl
))
10473 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10475 if (TREE_PROTECTED (decl
))
10476 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10477 else if (TREE_PRIVATE (decl
))
10478 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10482 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10484 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10485 equate_decl_number_to_die (decl
, var_die
);
10487 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10489 add_location_or_const_value_attribute (var_die
, decl
);
10490 add_pubname (decl
, var_die
);
10493 tree_add_const_value_attribute (var_die
, decl
);
10496 /* Generate a DIE to represent a label identifier. */
10499 gen_label_die (decl
, context_die
)
10501 dw_die_ref context_die
;
10503 tree origin
= decl_ultimate_origin (decl
);
10504 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10506 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10508 if (origin
!= NULL
)
10509 add_abstract_origin_attribute (lbl_die
, origin
);
10511 add_name_and_src_coords_attributes (lbl_die
, decl
);
10513 if (DECL_ABSTRACT (decl
))
10514 equate_decl_number_to_die (decl
, lbl_die
);
10517 insn
= DECL_RTL (decl
);
10519 /* Deleted labels are programmer specified labels which have been
10520 eliminated because of various optimisations. We still emit them
10521 here so that it is possible to put breakpoints on them. */
10522 if (GET_CODE (insn
) == CODE_LABEL
10523 || ((GET_CODE (insn
) == NOTE
10524 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10526 /* When optimization is enabled (via -O) some parts of the compiler
10527 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10528 represent source-level labels which were explicitly declared by
10529 the user. This really shouldn't be happening though, so catch
10530 it if it ever does happen. */
10531 if (INSN_DELETED_P (insn
))
10534 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10535 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10540 /* Generate a DIE for a lexical block. */
10543 gen_lexical_block_die (stmt
, context_die
, depth
)
10545 dw_die_ref context_die
;
10548 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10549 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10551 if (! BLOCK_ABSTRACT (stmt
))
10553 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10557 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10559 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10562 add_ranges (chain
);
10563 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10570 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10571 BLOCK_NUMBER (stmt
));
10572 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10573 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10574 BLOCK_NUMBER (stmt
));
10575 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10579 decls_for_scope (stmt
, stmt_die
, depth
);
10582 /* Generate a DIE for an inlined subprogram. */
10585 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
10587 dw_die_ref context_die
;
10590 if (! BLOCK_ABSTRACT (stmt
))
10592 dw_die_ref subr_die
10593 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10594 tree decl
= block_ultimate_origin (stmt
);
10595 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10597 /* Emit info for the abstract instance first, if we haven't yet. */
10598 dwarf2out_abstract_function (decl
);
10600 add_abstract_origin_attribute (subr_die
, decl
);
10601 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10602 BLOCK_NUMBER (stmt
));
10603 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10604 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10605 BLOCK_NUMBER (stmt
));
10606 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10607 decls_for_scope (stmt
, subr_die
, depth
);
10608 current_function_has_inlines
= 1;
10611 /* We may get here if we're the outer block of function A that was
10612 inlined into function B that was inlined into function C. When
10613 generating debugging info for C, dwarf2out_abstract_function(B)
10614 would mark all inlined blocks as abstract, including this one.
10615 So, we wouldn't (and shouldn't) expect labels to be generated
10616 for this one. Instead, just emit debugging info for
10617 declarations within the block. This is particularly important
10618 in the case of initializers of arguments passed from B to us:
10619 if they're statement expressions containing declarations, we
10620 wouldn't generate dies for their abstract variables, and then,
10621 when generating dies for the real variables, we'd die (pun
10623 gen_lexical_block_die (stmt
, context_die
, depth
);
10626 /* Generate a DIE for a field in a record, or structure. */
10629 gen_field_die (decl
, context_die
)
10631 dw_die_ref context_die
;
10633 dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
10635 add_name_and_src_coords_attributes (decl_die
, decl
);
10636 add_type_attribute (decl_die
, member_declared_type (decl
),
10637 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
10640 if (DECL_BIT_FIELD_TYPE (decl
))
10642 add_byte_size_attribute (decl_die
, decl
);
10643 add_bit_size_attribute (decl_die
, decl
);
10644 add_bit_offset_attribute (decl_die
, decl
);
10647 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
10648 add_data_member_location_attribute (decl_die
, decl
);
10650 if (DECL_ARTIFICIAL (decl
))
10651 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10653 if (TREE_PROTECTED (decl
))
10654 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10655 else if (TREE_PRIVATE (decl
))
10656 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10660 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10661 Use modified_type_die instead.
10662 We keep this code here just in case these types of DIEs may be needed to
10663 represent certain things in other languages (e.g. Pascal) someday. */
10666 gen_pointer_type_die (type
, context_die
)
10668 dw_die_ref context_die
;
10671 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
10673 equate_type_number_to_die (type
, ptr_die
);
10674 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10675 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10678 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10679 Use modified_type_die instead.
10680 We keep this code here just in case these types of DIEs may be needed to
10681 represent certain things in other languages (e.g. Pascal) someday. */
10684 gen_reference_type_die (type
, context_die
)
10686 dw_die_ref context_die
;
10689 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
10691 equate_type_number_to_die (type
, ref_die
);
10692 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
10693 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10697 /* Generate a DIE for a pointer to a member type. */
10700 gen_ptr_to_mbr_type_die (type
, context_die
)
10702 dw_die_ref context_die
;
10705 = new_die (DW_TAG_ptr_to_member_type
,
10706 scope_die_for (type
, context_die
), type
);
10708 equate_type_number_to_die (type
, ptr_die
);
10709 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
10710 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
10711 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10714 /* Generate the DIE for the compilation unit. */
10717 gen_compile_unit_die (filename
)
10718 const char *filename
;
10721 char producer
[250];
10722 const char *wd
= getpwd ();
10723 const char *language_string
= lang_hooks
.name
;
10726 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
10727 add_name_attribute (die
, filename
);
10729 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
10730 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10732 sprintf (producer
, "%s %s", language_string
, version_string
);
10734 #ifdef MIPS_DEBUGGING_INFO
10735 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10736 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10737 not appear in the producer string, the debugger reaches the conclusion
10738 that the object file is stripped and has no debugging information.
10739 To get the MIPS/SGI debugger to believe that there is debugging
10740 information in the object file, we add a -g to the producer string. */
10741 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10742 strcat (producer
, " -g");
10745 add_AT_string (die
, DW_AT_producer
, producer
);
10747 if (strcmp (language_string
, "GNU C++") == 0)
10748 language
= DW_LANG_C_plus_plus
;
10749 else if (strcmp (language_string
, "GNU Ada") == 0)
10750 language
= DW_LANG_Ada83
;
10751 else if (strcmp (language_string
, "GNU F77") == 0)
10752 language
= DW_LANG_Fortran77
;
10753 else if (strcmp (language_string
, "GNU Pascal") == 0)
10754 language
= DW_LANG_Pascal83
;
10755 else if (strcmp (language_string
, "GNU Java") == 0)
10756 language
= DW_LANG_Java
;
10758 language
= DW_LANG_C89
;
10760 add_AT_unsigned (die
, DW_AT_language
, language
);
10764 /* Generate a DIE for a string type. */
10767 gen_string_type_die (type
, context_die
)
10769 dw_die_ref context_die
;
10771 dw_die_ref type_die
10772 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
10774 equate_type_number_to_die (type
, type_die
);
10776 /* ??? Fudge the string length attribute for now.
10777 TODO: add string length info. */
10779 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
10780 bound_representation (upper_bound
, 0, 'u');
10784 /* Generate the DIE for a base class. */
10787 gen_inheritance_die (binfo
, context_die
)
10789 dw_die_ref context_die
;
10791 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
10793 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
10794 add_data_member_location_attribute (die
, binfo
);
10796 if (TREE_VIA_VIRTUAL (binfo
))
10797 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10799 if (TREE_VIA_PUBLIC (binfo
))
10800 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
10801 else if (TREE_VIA_PROTECTED (binfo
))
10802 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10805 /* Generate a DIE for a class member. */
10808 gen_member_die (type
, context_die
)
10810 dw_die_ref context_die
;
10815 /* If this is not an incomplete type, output descriptions of each of its
10816 members. Note that as we output the DIEs necessary to represent the
10817 members of this record or union type, we will also be trying to output
10818 DIEs to represent the *types* of those members. However the `type'
10819 function (above) will specifically avoid generating type DIEs for member
10820 types *within* the list of member DIEs for this (containing) type except
10821 for those types (of members) which are explicitly marked as also being
10822 members of this (containing) type themselves. The g++ front- end can
10823 force any given type to be treated as a member of some other (containing)
10824 type by setting the TYPE_CONTEXT of the given (member) type to point to
10825 the TREE node representing the appropriate (containing) type. */
10827 /* First output info about the base classes. */
10828 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
10830 tree bases
= TYPE_BINFO_BASETYPES (type
);
10831 int n_bases
= TREE_VEC_LENGTH (bases
);
10834 for (i
= 0; i
< n_bases
; i
++)
10835 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
10838 /* Now output info about the data members and type members. */
10839 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
10841 /* If we thought we were generating minimal debug info for TYPE
10842 and then changed our minds, some of the member declarations
10843 may have already been defined. Don't define them again, but
10844 do put them in the right order. */
10846 child
= lookup_decl_die (member
);
10848 splice_child_die (context_die
, child
);
10850 gen_decl_die (member
, context_die
);
10853 /* Now output info about the function members (if any). */
10854 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
10856 /* Don't include clones in the member list. */
10857 if (DECL_ABSTRACT_ORIGIN (member
))
10860 child
= lookup_decl_die (member
);
10862 splice_child_die (context_die
, child
);
10864 gen_decl_die (member
, context_die
);
10868 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10869 is set, we pretend that the type was never defined, so we only get the
10870 member DIEs needed by later specification DIEs. */
10873 gen_struct_or_union_type_die (type
, context_die
)
10875 dw_die_ref context_die
;
10877 dw_die_ref type_die
= lookup_type_die (type
);
10878 dw_die_ref scope_die
= 0;
10880 int complete
= (TYPE_SIZE (type
)
10881 && (! TYPE_STUB_DECL (type
)
10882 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
10884 if (type_die
&& ! complete
)
10887 if (TYPE_CONTEXT (type
) != NULL_TREE
10888 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
10891 scope_die
= scope_die_for (type
, context_die
);
10893 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
10894 /* First occurrence of type or toplevel definition of nested class. */
10896 dw_die_ref old_die
= type_die
;
10898 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
10899 ? DW_TAG_structure_type
: DW_TAG_union_type
,
10901 equate_type_number_to_die (type
, type_die
);
10903 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
10905 add_name_attribute (type_die
, type_tag (type
));
10908 remove_AT (type_die
, DW_AT_declaration
);
10910 /* If this type has been completed, then give it a byte_size attribute and
10911 then give a list of members. */
10914 /* Prevent infinite recursion in cases where the type of some member of
10915 this type is expressed in terms of this type itself. */
10916 TREE_ASM_WRITTEN (type
) = 1;
10917 add_byte_size_attribute (type_die
, type
);
10918 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10919 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10921 /* If the first reference to this type was as the return type of an
10922 inline function, then it may not have a parent. Fix this now. */
10923 if (type_die
->die_parent
== NULL
)
10924 add_child_die (scope_die
, type_die
);
10926 push_decl_scope (type
);
10927 gen_member_die (type
, type_die
);
10930 /* GNU extension: Record what type our vtable lives in. */
10931 if (TYPE_VFIELD (type
))
10933 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
10935 gen_type_die (vtype
, context_die
);
10936 add_AT_die_ref (type_die
, DW_AT_containing_type
,
10937 lookup_type_die (vtype
));
10942 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10944 /* We don't need to do this for function-local types. */
10945 if (TYPE_STUB_DECL (type
)
10946 && ! decl_function_context (TYPE_STUB_DECL (type
)))
10947 VARRAY_PUSH_TREE (incomplete_types
, type
);
10951 /* Generate a DIE for a subroutine _type_. */
10954 gen_subroutine_type_die (type
, context_die
)
10956 dw_die_ref context_die
;
10958 tree return_type
= TREE_TYPE (type
);
10959 dw_die_ref subr_die
10960 = new_die (DW_TAG_subroutine_type
,
10961 scope_die_for (type
, context_die
), type
);
10963 equate_type_number_to_die (type
, subr_die
);
10964 add_prototyped_attribute (subr_die
, type
);
10965 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
10966 gen_formal_types_die (type
, subr_die
);
10969 /* Generate a DIE for a type definition */
10972 gen_typedef_die (decl
, context_die
)
10974 dw_die_ref context_die
;
10976 dw_die_ref type_die
;
10979 if (TREE_ASM_WRITTEN (decl
))
10982 TREE_ASM_WRITTEN (decl
) = 1;
10983 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
10984 origin
= decl_ultimate_origin (decl
);
10985 if (origin
!= NULL
)
10986 add_abstract_origin_attribute (type_die
, origin
);
10991 add_name_and_src_coords_attributes (type_die
, decl
);
10992 if (DECL_ORIGINAL_TYPE (decl
))
10994 type
= DECL_ORIGINAL_TYPE (decl
);
10996 if (type
== TREE_TYPE (decl
))
10999 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11002 type
= TREE_TYPE (decl
);
11004 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11005 TREE_THIS_VOLATILE (decl
), context_die
);
11008 if (DECL_ABSTRACT (decl
))
11009 equate_decl_number_to_die (decl
, type_die
);
11012 /* Generate a type description DIE. */
11015 gen_type_die (type
, context_die
)
11017 dw_die_ref context_die
;
11021 if (type
== NULL_TREE
|| type
== error_mark_node
)
11024 /* We are going to output a DIE to represent the unqualified version
11025 of this type (i.e. without any const or volatile qualifiers) so
11026 get the main variant (i.e. the unqualified version) of this type
11027 now. (Vectors are special because the debugging info is in the
11028 cloned type itself). */
11029 if (TREE_CODE (type
) != VECTOR_TYPE
)
11030 type
= type_main_variant (type
);
11032 if (TREE_ASM_WRITTEN (type
))
11035 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11036 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11038 /* Prevent broken recursion; we can't hand off to the same type. */
11039 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11042 TREE_ASM_WRITTEN (type
) = 1;
11043 gen_decl_die (TYPE_NAME (type
), context_die
);
11047 switch (TREE_CODE (type
))
11053 case REFERENCE_TYPE
:
11054 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11055 ensures that the gen_type_die recursion will terminate even if the
11056 type is recursive. Recursive types are possible in Ada. */
11057 /* ??? We could perhaps do this for all types before the switch
11059 TREE_ASM_WRITTEN (type
) = 1;
11061 /* For these types, all that is required is that we output a DIE (or a
11062 set of DIEs) to represent the "basis" type. */
11063 gen_type_die (TREE_TYPE (type
), context_die
);
11067 /* This code is used for C++ pointer-to-data-member types.
11068 Output a description of the relevant class type. */
11069 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11071 /* Output a description of the type of the object pointed to. */
11072 gen_type_die (TREE_TYPE (type
), context_die
);
11074 /* Now output a DIE to represent this pointer-to-data-member type
11076 gen_ptr_to_mbr_type_die (type
, context_die
);
11080 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11081 gen_set_type_die (type
, context_die
);
11085 gen_type_die (TREE_TYPE (type
), context_die
);
11086 abort (); /* No way to represent these in Dwarf yet! */
11089 case FUNCTION_TYPE
:
11090 /* Force out return type (in case it wasn't forced out already). */
11091 gen_type_die (TREE_TYPE (type
), context_die
);
11092 gen_subroutine_type_die (type
, context_die
);
11096 /* Force out return type (in case it wasn't forced out already). */
11097 gen_type_die (TREE_TYPE (type
), context_die
);
11098 gen_subroutine_type_die (type
, context_die
);
11102 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11104 gen_type_die (TREE_TYPE (type
), context_die
);
11105 gen_string_type_die (type
, context_die
);
11108 gen_array_type_die (type
, context_die
);
11112 gen_array_type_die (type
, context_die
);
11115 case ENUMERAL_TYPE
:
11118 case QUAL_UNION_TYPE
:
11119 /* If this is a nested type whose containing class hasn't been written
11120 out yet, writing it out will cover this one, too. This does not apply
11121 to instantiations of member class templates; they need to be added to
11122 the containing class as they are generated. FIXME: This hurts the
11123 idea of combining type decls from multiple TUs, since we can't predict
11124 what set of template instantiations we'll get. */
11125 if (TYPE_CONTEXT (type
)
11126 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11127 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11129 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11131 if (TREE_ASM_WRITTEN (type
))
11134 /* If that failed, attach ourselves to the stub. */
11135 push_decl_scope (TYPE_CONTEXT (type
));
11136 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11142 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11143 gen_enumeration_type_die (type
, context_die
);
11145 gen_struct_or_union_type_die (type
, context_die
);
11150 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11151 it up if it is ever completed. gen_*_type_die will set it for us
11152 when appropriate. */
11161 /* No DIEs needed for fundamental types. */
11165 /* No Dwarf representation currently defined. */
11172 TREE_ASM_WRITTEN (type
) = 1;
11175 /* Generate a DIE for a tagged type instantiation. */
11178 gen_tagged_type_instantiation_die (type
, context_die
)
11180 dw_die_ref context_die
;
11182 if (type
== NULL_TREE
|| type
== error_mark_node
)
11185 /* We are going to output a DIE to represent the unqualified version of
11186 this type (i.e. without any const or volatile qualifiers) so make sure
11187 that we have the main variant (i.e. the unqualified version) of this
11189 if (type
!= type_main_variant (type
))
11192 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11193 an instance of an unresolved type. */
11195 switch (TREE_CODE (type
))
11200 case ENUMERAL_TYPE
:
11201 gen_inlined_enumeration_type_die (type
, context_die
);
11205 gen_inlined_structure_type_die (type
, context_die
);
11209 case QUAL_UNION_TYPE
:
11210 gen_inlined_union_type_die (type
, context_die
);
11218 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11219 things which are local to the given block. */
11222 gen_block_die (stmt
, context_die
, depth
)
11224 dw_die_ref context_die
;
11227 int must_output_die
= 0;
11230 enum tree_code origin_code
;
11232 /* Ignore blocks never really used to make RTL. */
11233 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11234 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11237 /* If the block is one fragment of a non-contiguous block, do not
11238 process the variables, since they will have been done by the
11239 origin block. Do process subblocks. */
11240 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11244 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11245 gen_block_die (sub
, context_die
, depth
+ 1);
11250 /* Determine the "ultimate origin" of this block. This block may be an
11251 inlined instance of an inlined instance of inline function, so we have
11252 to trace all of the way back through the origin chain to find out what
11253 sort of node actually served as the original seed for the creation of
11254 the current block. */
11255 origin
= block_ultimate_origin (stmt
);
11256 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11258 /* Determine if we need to output any Dwarf DIEs at all to represent this
11260 if (origin_code
== FUNCTION_DECL
)
11261 /* The outer scopes for inlinings *must* always be represented. We
11262 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11263 must_output_die
= 1;
11266 /* In the case where the current block represents an inlining of the
11267 "body block" of an inline function, we must *NOT* output any DIE for
11268 this block because we have already output a DIE to represent the whole
11269 inlined function scope and the "body block" of any function doesn't
11270 really represent a different scope according to ANSI C rules. So we
11271 check here to make sure that this block does not represent a "body
11272 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11273 if (! is_body_block (origin
? origin
: stmt
))
11275 /* Determine if this block directly contains any "significant"
11276 local declarations which we will need to output DIEs for. */
11277 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11278 /* We are not in terse mode so *any* local declaration counts
11279 as being a "significant" one. */
11280 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11282 /* We are in terse mode, so only local (nested) function
11283 definitions count as "significant" local declarations. */
11284 for (decl
= BLOCK_VARS (stmt
);
11285 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11286 if (TREE_CODE (decl
) == FUNCTION_DECL
11287 && DECL_INITIAL (decl
))
11289 must_output_die
= 1;
11295 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11296 DIE for any block which contains no significant local declarations at
11297 all. Rather, in such cases we just call `decls_for_scope' so that any
11298 needed Dwarf info for any sub-blocks will get properly generated. Note
11299 that in terse mode, our definition of what constitutes a "significant"
11300 local declaration gets restricted to include only inlined function
11301 instances and local (nested) function definitions. */
11302 if (must_output_die
)
11304 if (origin_code
== FUNCTION_DECL
)
11305 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11307 gen_lexical_block_die (stmt
, context_die
, depth
);
11310 decls_for_scope (stmt
, context_die
, depth
);
11313 /* Generate all of the decls declared within a given scope and (recursively)
11314 all of its sub-blocks. */
11317 decls_for_scope (stmt
, context_die
, depth
)
11319 dw_die_ref context_die
;
11325 /* Ignore blocks never really used to make RTL. */
11326 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11329 /* Output the DIEs to represent all of the data objects and typedefs
11330 declared directly within this block but not within any nested
11331 sub-blocks. Also, nested function and tag DIEs have been
11332 generated with a parent of NULL; fix that up now. */
11333 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11337 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11338 die
= lookup_decl_die (decl
);
11339 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11340 die
= lookup_type_die (TREE_TYPE (decl
));
11344 if (die
!= NULL
&& die
->die_parent
== NULL
)
11345 add_child_die (context_die
, die
);
11347 gen_decl_die (decl
, context_die
);
11350 /* Output the DIEs to represent all sub-blocks (and the items declared
11351 therein) of this block. */
11352 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11354 subblocks
= BLOCK_CHAIN (subblocks
))
11355 gen_block_die (subblocks
, context_die
, depth
+ 1);
11358 /* Is this a typedef we can avoid emitting? */
11361 is_redundant_typedef (decl
)
11364 if (TYPE_DECL_IS_STUB (decl
))
11367 if (DECL_ARTIFICIAL (decl
)
11368 && DECL_CONTEXT (decl
)
11369 && is_tagged_type (DECL_CONTEXT (decl
))
11370 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11371 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11372 /* Also ignore the artificial member typedef for the class name. */
11378 /* Generate Dwarf debug information for a decl described by DECL. */
11381 gen_decl_die (decl
, context_die
)
11383 dw_die_ref context_die
;
11387 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11390 switch (TREE_CODE (decl
))
11396 /* The individual enumerators of an enum type get output when we output
11397 the Dwarf representation of the relevant enum type itself. */
11400 case FUNCTION_DECL
:
11401 /* Don't output any DIEs to represent mere function declarations,
11402 unless they are class members or explicit block externs. */
11403 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11404 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11407 /* If we're emitting a clone, emit info for the abstract instance. */
11408 if (DECL_ORIGIN (decl
) != decl
)
11409 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11411 /* If we're emitting an out-of-line copy of an inline function,
11412 emit info for the abstract instance and set up to refer to it. */
11413 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11414 && ! class_scope_p (context_die
)
11415 /* dwarf2out_abstract_function won't emit a die if this is just
11416 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11417 that case, because that works only if we have a die. */
11418 && DECL_INITIAL (decl
) != NULL_TREE
)
11420 dwarf2out_abstract_function (decl
);
11421 set_decl_origin_self (decl
);
11424 /* Otherwise we're emitting the primary DIE for this decl. */
11425 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11427 /* Before we describe the FUNCTION_DECL itself, make sure that we
11428 have described its return type. */
11429 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11431 /* And its virtual context. */
11432 if (DECL_VINDEX (decl
) != NULL_TREE
)
11433 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11435 /* And its containing type. */
11436 origin
= decl_class_context (decl
);
11437 if (origin
!= NULL_TREE
)
11438 gen_type_die_for_member (origin
, decl
, context_die
);
11441 /* Now output a DIE to represent the function itself. */
11442 gen_subprogram_die (decl
, context_die
);
11446 /* If we are in terse mode, don't generate any DIEs to represent any
11447 actual typedefs. */
11448 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11451 /* In the special case of a TYPE_DECL node representing the declaration
11452 of some type tag, if the given TYPE_DECL is marked as having been
11453 instantiated from some other (original) TYPE_DECL node (e.g. one which
11454 was generated within the original definition of an inline function) we
11455 have to generate a special (abbreviated) DW_TAG_structure_type,
11456 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11457 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11459 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11463 if (is_redundant_typedef (decl
))
11464 gen_type_die (TREE_TYPE (decl
), context_die
);
11466 /* Output a DIE to represent the typedef itself. */
11467 gen_typedef_die (decl
, context_die
);
11471 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11472 gen_label_die (decl
, context_die
);
11476 /* If we are in terse mode, don't generate any DIEs to represent any
11477 variable declarations or definitions. */
11478 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11481 /* Output any DIEs that are needed to specify the type of this data
11483 gen_type_die (TREE_TYPE (decl
), context_die
);
11485 /* And its containing type. */
11486 origin
= decl_class_context (decl
);
11487 if (origin
!= NULL_TREE
)
11488 gen_type_die_for_member (origin
, decl
, context_die
);
11490 /* Now output the DIE to represent the data object itself. This gets
11491 complicated because of the possibility that the VAR_DECL really
11492 represents an inlined instance of a formal parameter for an inline
11494 origin
= decl_ultimate_origin (decl
);
11495 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11496 gen_formal_parameter_die (decl
, context_die
);
11498 gen_variable_die (decl
, context_die
);
11502 /* Ignore the nameless fields that are used to skip bits but handle C++
11503 anonymous unions. */
11504 if (DECL_NAME (decl
) != NULL_TREE
11505 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11507 gen_type_die (member_declared_type (decl
), context_die
);
11508 gen_field_die (decl
, context_die
);
11513 gen_type_die (TREE_TYPE (decl
), context_die
);
11514 gen_formal_parameter_die (decl
, context_die
);
11517 case NAMESPACE_DECL
:
11518 /* Ignore for now. */
11527 mark_limbo_die_list (ptr
)
11528 void *ptr ATTRIBUTE_UNUSED
;
11530 limbo_die_node
*node
;
11531 for (node
= limbo_die_list
; node
; node
= node
->next
)
11532 ggc_mark_tree (node
->created_for
);
11535 /* Add Ada "use" clause information for SGI Workshop debugger. */
11538 dwarf2out_add_library_unit_info (filename
, context_list
)
11539 const char *filename
;
11540 const char *context_list
;
11542 unsigned int file_index
;
11544 if (filename
!= NULL
)
11546 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11547 tree context_list_decl
11548 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11551 TREE_PUBLIC (context_list_decl
) = TRUE
;
11552 add_name_attribute (unit_die
, context_list
);
11553 file_index
= lookup_filename (filename
);
11554 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11555 add_pubname (context_list_decl
, unit_die
);
11559 /* Output debug information for global decl DECL. Called from toplev.c after
11560 compilation proper has finished. */
11563 dwarf2out_global_decl (decl
)
11566 /* Output DWARF2 information for file-scope tentative data object
11567 declarations, file-scope (extern) function declarations (which had no
11568 corresponding body) and file-scope tagged type declarations and
11569 definitions which have not yet been forced out. */
11570 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11571 dwarf2out_decl (decl
);
11574 /* Write the debugging output for DECL. */
11577 dwarf2out_decl (decl
)
11580 dw_die_ref context_die
= comp_unit_die
;
11582 switch (TREE_CODE (decl
))
11587 case FUNCTION_DECL
:
11588 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11589 builtin function. Explicit programmer-supplied declarations of
11590 these same functions should NOT be ignored however. */
11591 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11594 /* What we would really like to do here is to filter out all mere
11595 file-scope declarations of file-scope functions which are never
11596 referenced later within this translation unit (and keep all of ones
11597 that *are* referenced later on) but we aren't clairvoyant, so we have
11598 no idea which functions will be referenced in the future (i.e. later
11599 on within the current translation unit). So here we just ignore all
11600 file-scope function declarations which are not also definitions. If
11601 and when the debugger needs to know something about these functions,
11602 it will have to hunt around and find the DWARF information associated
11603 with the definition of the function.
11605 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11606 nodes represent definitions and which ones represent mere
11607 declarations. We have to check DECL_INITIAL instead. That's because
11608 the C front-end supports some weird semantics for "extern inline"
11609 function definitions. These can get inlined within the current
11610 translation unit (an thus, we need to generate Dwarf info for their
11611 abstract instances so that the Dwarf info for the concrete inlined
11612 instances can have something to refer to) but the compiler never
11613 generates any out-of-lines instances of such things (despite the fact
11614 that they *are* definitions).
11616 The important point is that the C front-end marks these "extern
11617 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11618 them anyway. Note that the C++ front-end also plays some similar games
11619 for inline function definitions appearing within include files which
11620 also contain `#pragma interface' pragmas. */
11621 if (DECL_INITIAL (decl
) == NULL_TREE
)
11624 /* If we're a nested function, initially use a parent of NULL; if we're
11625 a plain function, this will be fixed up in decls_for_scope. If
11626 we're a method, it will be ignored, since we already have a DIE. */
11627 if (decl_function_context (decl
))
11628 context_die
= NULL
;
11632 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11633 declaration and if the declaration was never even referenced from
11634 within this entire compilation unit. We suppress these DIEs in
11635 order to save space in the .debug section (by eliminating entries
11636 which are probably useless). Note that we must not suppress
11637 block-local extern declarations (whether used or not) because that
11638 would screw-up the debugger's name lookup mechanism and cause it to
11639 miss things which really ought to be in scope at a given point. */
11640 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11643 /* If we are in terse mode, don't generate any DIEs to represent any
11644 variable declarations or definitions. */
11645 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11650 /* Don't emit stubs for types unless they are needed by other DIEs. */
11651 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
11654 /* Don't bother trying to generate any DIEs to represent any of the
11655 normal built-in types for the language we are compiling. */
11656 if (DECL_SOURCE_LINE (decl
) == 0)
11658 /* OK, we need to generate one for `bool' so GDB knows what type
11659 comparisons have. */
11660 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
11661 == DW_LANG_C_plus_plus
)
11662 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
11663 && ! DECL_IGNORED_P (decl
))
11664 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
11669 /* If we are in terse mode, don't generate any DIEs for types. */
11670 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11673 /* If we're a function-scope tag, initially use a parent of NULL;
11674 this will be fixed up in decls_for_scope. */
11675 if (decl_function_context (decl
))
11676 context_die
= NULL
;
11684 gen_decl_die (decl
, context_die
);
11687 /* Output a marker (i.e. a label) for the beginning of the generated code for
11688 a lexical block. */
11691 dwarf2out_begin_block (line
, blocknum
)
11692 unsigned int line ATTRIBUTE_UNUSED
;
11693 unsigned int blocknum
;
11695 function_section (current_function_decl
);
11696 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
11699 /* Output a marker (i.e. a label) for the end of the generated code for a
11703 dwarf2out_end_block (line
, blocknum
)
11704 unsigned int line ATTRIBUTE_UNUSED
;
11705 unsigned int blocknum
;
11707 function_section (current_function_decl
);
11708 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
11711 /* Returns nonzero if it is appropriate not to emit any debugging
11712 information for BLOCK, because it doesn't contain any instructions.
11714 Don't allow this for blocks with nested functions or local classes
11715 as we would end up with orphans, and in the presence of scheduling
11716 we may end up calling them anyway. */
11719 dwarf2out_ignore_block (block
)
11724 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
11725 if (TREE_CODE (decl
) == FUNCTION_DECL
11726 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
11732 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11733 dwarf2out.c) and return its "index". The index of each (known) filename is
11734 just a unique number which is associated with only that one filename. We
11735 need such numbers for the sake of generating labels (in the .debug_sfnames
11736 section) and references to those files numbers (in the .debug_srcinfo
11737 and.debug_macinfo sections). If the filename given as an argument is not
11738 found in our current list, add it to the list and assign it the next
11739 available unique index number. In order to speed up searches, we remember
11740 the index of the filename was looked up last. This handles the majority of
11744 lookup_filename (file_name
)
11745 const char *file_name
;
11749 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11750 if (strcmp (file_name
, "<internal>") == 0
11751 || strcmp (file_name
, "<built-in>") == 0)
11754 /* Check to see if the file name that was searched on the previous
11755 call matches this file name. If so, return the index. */
11756 if (file_table
.last_lookup_index
!= 0)
11757 if (0 == strcmp (file_name
,
11758 file_table
.table
[file_table
.last_lookup_index
]))
11759 return file_table
.last_lookup_index
;
11761 /* Didn't match the previous lookup, search the table */
11762 for (i
= 1; i
< file_table
.in_use
; i
++)
11763 if (strcmp (file_name
, file_table
.table
[i
]) == 0)
11765 file_table
.last_lookup_index
= i
;
11769 /* Prepare to add a new table entry by making sure there is enough space in
11770 the table to do so. If not, expand the current table. */
11771 if (i
== file_table
.allocated
)
11773 file_table
.allocated
= i
+ FILE_TABLE_INCREMENT
;
11774 file_table
.table
= (char **)
11775 xrealloc (file_table
.table
, file_table
.allocated
* sizeof (char *));
11778 /* Add the new entry to the end of the filename table. */
11779 file_table
.table
[i
] = xstrdup (file_name
);
11780 file_table
.in_use
= i
+ 1;
11781 file_table
.last_lookup_index
= i
;
11783 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11785 fprintf (asm_out_file
, "\t.file %u ", i
);
11786 output_quoted_string (asm_out_file
, file_name
);
11787 fputc ('\n', asm_out_file
);
11796 /* Allocate the initial hunk of the file_table. */
11797 file_table
.table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
11798 file_table
.allocated
= FILE_TABLE_INCREMENT
;
11800 /* Skip the first entry - file numbers begin at 1. */
11801 file_table
.in_use
= 1;
11802 file_table
.last_lookup_index
= 0;
11805 /* Output a label to mark the beginning of a source code line entry
11806 and record information relating to this source line, in
11807 'line_info_table' for later output of the .debug_line section. */
11810 dwarf2out_source_line (line
, filename
)
11812 const char *filename
;
11814 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11816 function_section (current_function_decl
);
11818 /* If requested, emit something human-readable. */
11819 if (flag_debug_asm
)
11820 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
11823 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11825 unsigned file_num
= lookup_filename (filename
);
11827 /* Emit the .loc directive understood by GNU as. */
11828 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
11830 /* Indicate that line number info exists. */
11831 line_info_table_in_use
++;
11833 /* Indicate that multiple line number tables exist. */
11834 if (DECL_SECTION_NAME (current_function_decl
))
11835 separate_line_info_table_in_use
++;
11837 else if (DECL_SECTION_NAME (current_function_decl
))
11839 dw_separate_line_info_ref line_info
;
11840 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
11841 separate_line_info_table_in_use
);
11843 /* expand the line info table if necessary */
11844 if (separate_line_info_table_in_use
11845 == separate_line_info_table_allocated
)
11847 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11848 separate_line_info_table
11849 = (dw_separate_line_info_ref
)
11850 xrealloc (separate_line_info_table
,
11851 separate_line_info_table_allocated
11852 * sizeof (dw_separate_line_info_entry
));
11855 /* Add the new entry at the end of the line_info_table. */
11857 = &separate_line_info_table
[separate_line_info_table_in_use
++];
11858 line_info
->dw_file_num
= lookup_filename (filename
);
11859 line_info
->dw_line_num
= line
;
11860 line_info
->function
= current_function_funcdef_no
;
11864 dw_line_info_ref line_info
;
11866 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
11867 line_info_table_in_use
);
11869 /* Expand the line info table if necessary. */
11870 if (line_info_table_in_use
== line_info_table_allocated
)
11872 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11874 = (dw_line_info_ref
)
11875 xrealloc (line_info_table
,
11876 (line_info_table_allocated
11877 * sizeof (dw_line_info_entry
)));
11880 /* Add the new entry at the end of the line_info_table. */
11881 line_info
= &line_info_table
[line_info_table_in_use
++];
11882 line_info
->dw_file_num
= lookup_filename (filename
);
11883 line_info
->dw_line_num
= line
;
11888 /* Record the beginning of a new source file. */
11891 dwarf2out_start_source_file (lineno
, filename
)
11892 unsigned int lineno
;
11893 const char *filename
;
11895 if (flag_eliminate_dwarf2_dups
)
11897 /* Record the beginning of the file for break_out_includes. */
11898 dw_die_ref bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
11899 add_AT_string (bincl_die
, DW_AT_name
, filename
);
11902 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11904 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11905 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
11906 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
11908 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
11909 "Filename we just started");
11913 /* Record the end of a source file. */
11916 dwarf2out_end_source_file (lineno
)
11917 unsigned int lineno ATTRIBUTE_UNUSED
;
11919 if (flag_eliminate_dwarf2_dups
)
11920 /* Record the end of the file for break_out_includes. */
11921 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
11923 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11925 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11926 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
11930 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11931 the tail part of the directive line, i.e. the part which is past the
11932 initial whitespace, #, whitespace, directive-name, whitespace part. */
11935 dwarf2out_define (lineno
, buffer
)
11936 unsigned lineno ATTRIBUTE_UNUSED
;
11937 const char *buffer ATTRIBUTE_UNUSED
;
11939 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11941 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11942 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
11943 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11944 dw2_asm_output_nstring (buffer
, -1, "The macro");
11948 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11949 the tail part of the directive line, i.e. the part which is past the
11950 initial whitespace, #, whitespace, directive-name, whitespace part. */
11953 dwarf2out_undef (lineno
, buffer
)
11954 unsigned lineno ATTRIBUTE_UNUSED
;
11955 const char *buffer ATTRIBUTE_UNUSED
;
11957 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11959 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11960 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
11961 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11962 dw2_asm_output_nstring (buffer
, -1, "The macro");
11966 /* Set up for Dwarf output at the start of compilation. */
11969 dwarf2out_init (main_input_filename
)
11970 const char *main_input_filename
;
11972 init_file_table ();
11974 /* Remember the name of the primary input file. */
11975 primary_filename
= main_input_filename
;
11977 /* Add it to the file table first, under the assumption that we'll
11978 be emitting line number data for it first, which avoids having
11979 to add an initial DW_LNS_set_file. */
11980 lookup_filename (main_input_filename
);
11982 /* Allocate the initial hunk of the decl_die_table. */
11984 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
11985 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
11986 decl_die_table_in_use
= 0;
11988 /* Allocate the initial hunk of the decl_scope_table. */
11989 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
11991 /* Allocate the initial hunk of the abbrev_die_table. */
11993 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
11994 sizeof (dw_die_ref
));
11995 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
11996 /* Zero-th entry is allocated, but unused */
11997 abbrev_die_table_in_use
= 1;
11999 /* Allocate the initial hunk of the line_info_table. */
12001 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
12002 sizeof (dw_line_info_entry
));
12003 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12005 /* Zero-th entry is allocated, but unused */
12006 line_info_table_in_use
= 1;
12008 /* Generate the initial DIE for the .debug section. Note that the (string)
12009 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12010 will (typically) be a relative pathname and that this pathname should be
12011 taken as being relative to the directory from which the compiler was
12012 invoked when the given (base) source file was compiled. */
12013 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
12015 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12017 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12019 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
12021 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12022 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12023 DEBUG_ABBREV_SECTION_LABEL
, 0);
12024 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12025 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12027 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12029 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12030 DEBUG_INFO_SECTION_LABEL
, 0);
12031 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12032 DEBUG_LINE_SECTION_LABEL
, 0);
12033 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12034 DEBUG_RANGES_SECTION_LABEL
, 0);
12035 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12036 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12037 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12038 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12039 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12040 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12042 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12044 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12045 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12046 DEBUG_MACINFO_SECTION_LABEL
, 0);
12047 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12050 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12053 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12057 /* Allocate a string in .debug_str hash table. */
12060 indirect_string_alloc (tab
)
12061 hash_table
*tab ATTRIBUTE_UNUSED
;
12063 struct indirect_string_node
*node
;
12065 node
= xmalloc (sizeof (struct indirect_string_node
));
12066 node
->refcount
= 0;
12068 node
->label
= NULL
;
12070 return (hashnode
) node
;
12073 /* A helper function for dwarf2out_finish called through
12074 ht_forall. Emit one queued .debug_str string. */
12077 output_indirect_string (pfile
, h
, v
)
12078 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12080 const PTR v ATTRIBUTE_UNUSED
;
12082 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12084 if (node
->form
== DW_FORM_strp
)
12086 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12087 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12088 assemble_string ((const char *) HT_STR (&node
->id
),
12089 HT_LEN (&node
->id
) + 1);
12095 /* Output stuff that dwarf requires at the end of every file,
12096 and generate the DWARF-2 debugging info. */
12099 dwarf2out_finish (input_filename
)
12100 const char *input_filename ATTRIBUTE_UNUSED
;
12102 limbo_die_node
*node
, *next_node
;
12103 dw_die_ref die
= 0;
12105 /* Traverse the limbo die list, and add parent/child links. The only
12106 dies without parents that should be here are concrete instances of
12107 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12108 For concrete instances, we can get the parent die from the abstract
12110 for (node
= limbo_die_list
; node
; node
= next_node
)
12112 next_node
= node
->next
;
12115 if (die
->die_parent
== NULL
)
12117 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12121 add_child_die (origin
->die_parent
, die
);
12122 else if (die
== comp_unit_die
)
12124 /* If this was an expression for a bound involved in a function
12125 return type, it may be a SAVE_EXPR for which we weren't able
12126 to find a DIE previously. So try now. */
12127 else if (node
->created_for
12128 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12129 && 0 != (origin
= (lookup_decl_die
12131 (node
->created_for
)))))
12132 add_child_die (origin
, die
);
12133 else if (errorcount
> 0 || sorrycount
> 0)
12134 /* It's OK to be confused by errors in the input. */
12135 add_child_die (comp_unit_die
, die
);
12136 else if (node
->created_for
12137 && ((DECL_P (node
->created_for
)
12138 && (context
= DECL_CONTEXT (node
->created_for
)))
12139 || (TYPE_P (node
->created_for
)
12140 && (context
= TYPE_CONTEXT (node
->created_for
))))
12141 && TREE_CODE (context
) == FUNCTION_DECL
)
12143 /* In certain situations, the lexical block containing a
12144 nested function can be optimized away, which results
12145 in the nested function die being orphaned. Likewise
12146 with the return type of that nested function. Force
12147 this to be a child of the containing function. */
12148 origin
= lookup_decl_die (context
);
12151 add_child_die (origin
, die
);
12160 limbo_die_list
= NULL
;
12162 /* Walk through the list of incomplete types again, trying once more to
12163 emit full debugging info for them. */
12164 retry_incomplete_types ();
12166 /* We need to reverse all the dies before break_out_includes, or
12167 we'll see the end of an include file before the beginning. */
12168 reverse_all_dies (comp_unit_die
);
12170 /* Generate separate CUs for each of the include files we've seen.
12171 They will go into limbo_die_list. */
12172 if (flag_eliminate_dwarf2_dups
)
12173 break_out_includes (comp_unit_die
);
12175 /* Traverse the DIE's and add add sibling attributes to those DIE's
12176 that have children. */
12177 add_sibling_attributes (comp_unit_die
);
12178 for (node
= limbo_die_list
; node
; node
= node
->next
)
12179 add_sibling_attributes (node
->die
);
12181 /* Output a terminator label for the .text section. */
12183 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
12185 /* Output the source line correspondence table. We must do this
12186 even if there is no line information. Otherwise, on an empty
12187 translation unit, we will generate a present, but empty,
12188 .debug_info section. IRIX 6.5 `nm' will then complain when
12189 examining the file. */
12190 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12192 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12193 output_line_info ();
12196 /* Output location list section if necessary. */
12197 if (have_location_lists
)
12199 /* Output the location lists info. */
12200 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12201 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12202 DEBUG_LOC_SECTION_LABEL
, 0);
12203 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12204 output_location_lists (die
);
12205 have_location_lists
= 0;
12208 /* We can only use the low/high_pc attributes if all of the code was
12210 if (separate_line_info_table_in_use
== 0)
12212 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12213 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12216 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12217 "base address". Use zero so that these addresses become absolute. */
12218 else if (have_location_lists
|| ranges_table_in_use
)
12219 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12221 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12222 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12223 debug_line_section_label
);
12225 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12226 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12228 /* Output all of the compilation units. We put the main one last so that
12229 the offsets are available to output_pubnames. */
12230 for (node
= limbo_die_list
; node
; node
= node
->next
)
12231 output_comp_unit (node
->die
);
12233 output_comp_unit (comp_unit_die
);
12235 /* Output the abbreviation table. */
12236 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12237 output_abbrev_section ();
12239 /* Output public names table if necessary. */
12240 if (pubname_table_in_use
)
12242 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12243 output_pubnames ();
12246 /* Output the address range information. We only put functions in the arange
12247 table, so don't write it out if we don't have any. */
12248 if (fde_table_in_use
)
12250 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12254 /* Output ranges section if necessary. */
12255 if (ranges_table_in_use
)
12257 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12258 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12262 /* Have to end the primary source file. */
12263 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12265 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12266 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12267 dw2_asm_output_data (1, 0, "End compilation unit");
12270 /* If we emitted any DW_FORM_strp form attribute, output the string
12272 if (debug_str_hash
)
12273 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12277 /* This should never be used, but its address is needed for comparisons. */
12278 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12280 #endif /* DWARF2_DEBUGGING_INFO */
12282 #include "gt-dwarf2out.h"