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 ASM_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 ()
2137 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2139 /* Output a label to mark the endpoint of the code generated for this
2141 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2142 current_function_funcdef_no
);
2143 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2144 fde
= &fde_table
[fde_table_in_use
- 1];
2145 fde
->dw_fde_end
= xstrdup (label
);
2149 dwarf2out_frame_init ()
2151 /* Allocate the initial hunk of the fde_table. */
2152 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2153 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2154 fde_table_in_use
= 0;
2156 /* Generate the CFA instructions common to all FDE's. Do it now for the
2157 sake of lookup_cfa. */
2159 #ifdef DWARF2_UNWIND_INFO
2160 /* On entry, the Canonical Frame Address is at SP. */
2161 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2162 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2167 dwarf2out_frame_finish ()
2169 /* Output call frame information. */
2170 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2171 output_call_frame_info (0);
2173 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2174 output_call_frame_info (1);
2177 /* And now, the subset of the debugging information support code necessary
2178 for emitting location expressions. */
2180 typedef struct dw_val_struct
*dw_val_ref
;
2181 typedef struct die_struct
*dw_die_ref
;
2182 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2183 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2185 /* Each DIE may have a series of attribute/value pairs. Values
2186 can take on several forms. The forms that are used in this
2187 implementation are listed below. */
2192 dw_val_class_offset
,
2194 dw_val_class_loc_list
,
2195 dw_val_class_range_list
,
2197 dw_val_class_unsigned_const
,
2198 dw_val_class_long_long
,
2201 dw_val_class_die_ref
,
2202 dw_val_class_fde_ref
,
2203 dw_val_class_lbl_id
,
2204 dw_val_class_lbl_offset
,
2209 /* Describe a double word constant value. */
2210 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2212 typedef struct dw_long_long_struct
2219 /* Describe a floating point constant value. */
2221 typedef struct dw_fp_struct
2228 /* The dw_val_node describes an attribute's value, as it is
2229 represented internally. */
2231 typedef struct dw_val_struct
2233 dw_val_class val_class
;
2237 long unsigned val_offset
;
2238 dw_loc_list_ref val_loc_list
;
2239 dw_loc_descr_ref val_loc
;
2241 long unsigned val_unsigned
;
2242 dw_long_long_const val_long_long
;
2243 dw_float_const val_float
;
2249 unsigned val_fde_index
;
2250 struct indirect_string_node
*val_str
;
2252 unsigned char val_flag
;
2258 /* Locations in memory are described using a sequence of stack machine
2261 typedef struct dw_loc_descr_struct
2263 dw_loc_descr_ref dw_loc_next
;
2264 enum dwarf_location_atom dw_loc_opc
;
2265 dw_val_node dw_loc_oprnd1
;
2266 dw_val_node dw_loc_oprnd2
;
2271 /* Location lists are ranges + location descriptions for that range,
2272 so you can track variables that are in different places over
2273 their entire life. */
2274 typedef struct dw_loc_list_struct
2276 dw_loc_list_ref dw_loc_next
;
2277 const char *begin
; /* Label for begin address of range */
2278 const char *end
; /* Label for end address of range */
2279 char *ll_symbol
; /* Label for beginning of location list.
2280 Only on head of list */
2281 const char *section
; /* Section this loclist is relative to */
2282 dw_loc_descr_ref expr
;
2285 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2286 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2289 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2291 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2292 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2293 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2294 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2296 /* Convert a DWARF stack opcode into its string name. */
2299 dwarf_stack_op_name (op
)
2305 return "DW_OP_addr";
2307 return "DW_OP_deref";
2309 return "DW_OP_const1u";
2311 return "DW_OP_const1s";
2313 return "DW_OP_const2u";
2315 return "DW_OP_const2s";
2317 return "DW_OP_const4u";
2319 return "DW_OP_const4s";
2321 return "DW_OP_const8u";
2323 return "DW_OP_const8s";
2325 return "DW_OP_constu";
2327 return "DW_OP_consts";
2331 return "DW_OP_drop";
2333 return "DW_OP_over";
2335 return "DW_OP_pick";
2337 return "DW_OP_swap";
2341 return "DW_OP_xderef";
2349 return "DW_OP_minus";
2361 return "DW_OP_plus";
2362 case DW_OP_plus_uconst
:
2363 return "DW_OP_plus_uconst";
2369 return "DW_OP_shra";
2387 return "DW_OP_skip";
2389 return "DW_OP_lit0";
2391 return "DW_OP_lit1";
2393 return "DW_OP_lit2";
2395 return "DW_OP_lit3";
2397 return "DW_OP_lit4";
2399 return "DW_OP_lit5";
2401 return "DW_OP_lit6";
2403 return "DW_OP_lit7";
2405 return "DW_OP_lit8";
2407 return "DW_OP_lit9";
2409 return "DW_OP_lit10";
2411 return "DW_OP_lit11";
2413 return "DW_OP_lit12";
2415 return "DW_OP_lit13";
2417 return "DW_OP_lit14";
2419 return "DW_OP_lit15";
2421 return "DW_OP_lit16";
2423 return "DW_OP_lit17";
2425 return "DW_OP_lit18";
2427 return "DW_OP_lit19";
2429 return "DW_OP_lit20";
2431 return "DW_OP_lit21";
2433 return "DW_OP_lit22";
2435 return "DW_OP_lit23";
2437 return "DW_OP_lit24";
2439 return "DW_OP_lit25";
2441 return "DW_OP_lit26";
2443 return "DW_OP_lit27";
2445 return "DW_OP_lit28";
2447 return "DW_OP_lit29";
2449 return "DW_OP_lit30";
2451 return "DW_OP_lit31";
2453 return "DW_OP_reg0";
2455 return "DW_OP_reg1";
2457 return "DW_OP_reg2";
2459 return "DW_OP_reg3";
2461 return "DW_OP_reg4";
2463 return "DW_OP_reg5";
2465 return "DW_OP_reg6";
2467 return "DW_OP_reg7";
2469 return "DW_OP_reg8";
2471 return "DW_OP_reg9";
2473 return "DW_OP_reg10";
2475 return "DW_OP_reg11";
2477 return "DW_OP_reg12";
2479 return "DW_OP_reg13";
2481 return "DW_OP_reg14";
2483 return "DW_OP_reg15";
2485 return "DW_OP_reg16";
2487 return "DW_OP_reg17";
2489 return "DW_OP_reg18";
2491 return "DW_OP_reg19";
2493 return "DW_OP_reg20";
2495 return "DW_OP_reg21";
2497 return "DW_OP_reg22";
2499 return "DW_OP_reg23";
2501 return "DW_OP_reg24";
2503 return "DW_OP_reg25";
2505 return "DW_OP_reg26";
2507 return "DW_OP_reg27";
2509 return "DW_OP_reg28";
2511 return "DW_OP_reg29";
2513 return "DW_OP_reg30";
2515 return "DW_OP_reg31";
2517 return "DW_OP_breg0";
2519 return "DW_OP_breg1";
2521 return "DW_OP_breg2";
2523 return "DW_OP_breg3";
2525 return "DW_OP_breg4";
2527 return "DW_OP_breg5";
2529 return "DW_OP_breg6";
2531 return "DW_OP_breg7";
2533 return "DW_OP_breg8";
2535 return "DW_OP_breg9";
2537 return "DW_OP_breg10";
2539 return "DW_OP_breg11";
2541 return "DW_OP_breg12";
2543 return "DW_OP_breg13";
2545 return "DW_OP_breg14";
2547 return "DW_OP_breg15";
2549 return "DW_OP_breg16";
2551 return "DW_OP_breg17";
2553 return "DW_OP_breg18";
2555 return "DW_OP_breg19";
2557 return "DW_OP_breg20";
2559 return "DW_OP_breg21";
2561 return "DW_OP_breg22";
2563 return "DW_OP_breg23";
2565 return "DW_OP_breg24";
2567 return "DW_OP_breg25";
2569 return "DW_OP_breg26";
2571 return "DW_OP_breg27";
2573 return "DW_OP_breg28";
2575 return "DW_OP_breg29";
2577 return "DW_OP_breg30";
2579 return "DW_OP_breg31";
2581 return "DW_OP_regx";
2583 return "DW_OP_fbreg";
2585 return "DW_OP_bregx";
2587 return "DW_OP_piece";
2588 case DW_OP_deref_size
:
2589 return "DW_OP_deref_size";
2590 case DW_OP_xderef_size
:
2591 return "DW_OP_xderef_size";
2595 return "OP_<unknown>";
2599 /* Return a pointer to a newly allocated location description. Location
2600 descriptions are simple expression terms that can be strung
2601 together to form more complicated location (address) descriptions. */
2603 static inline dw_loc_descr_ref
2604 new_loc_descr (op
, oprnd1
, oprnd2
)
2605 enum dwarf_location_atom op
;
2606 unsigned long oprnd1
;
2607 unsigned long oprnd2
;
2609 /* Use xcalloc here so we clear out all of the long_long constant in
2611 dw_loc_descr_ref descr
2612 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2614 descr
->dw_loc_opc
= op
;
2615 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2616 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2617 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2618 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2624 /* Add a location description term to a location description expression. */
2627 add_loc_descr (list_head
, descr
)
2628 dw_loc_descr_ref
*list_head
;
2629 dw_loc_descr_ref descr
;
2631 dw_loc_descr_ref
*d
;
2633 /* Find the end of the chain. */
2634 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2640 /* Return the size of a location descriptor. */
2642 static unsigned long
2643 size_of_loc_descr (loc
)
2644 dw_loc_descr_ref loc
;
2646 unsigned long size
= 1;
2648 switch (loc
->dw_loc_opc
)
2651 size
+= DWARF2_ADDR_SIZE
;
2670 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2673 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2678 case DW_OP_plus_uconst
:
2679 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2717 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2720 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2723 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2726 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2727 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2730 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2732 case DW_OP_deref_size
:
2733 case DW_OP_xderef_size
:
2743 /* Return the size of a series of location descriptors. */
2745 static unsigned long
2747 dw_loc_descr_ref loc
;
2751 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2753 loc
->dw_loc_addr
= size
;
2754 size
+= size_of_loc_descr (loc
);
2760 /* Output location description stack opcode's operands (if any). */
2763 output_loc_operands (loc
)
2764 dw_loc_descr_ref loc
;
2766 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2767 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2769 switch (loc
->dw_loc_opc
)
2771 #ifdef DWARF2_DEBUGGING_INFO
2773 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2777 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2781 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2785 if (HOST_BITS_PER_LONG
< 64)
2787 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2794 if (val1
->val_class
== dw_val_class_loc
)
2795 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2799 dw2_asm_output_data (2, offset
, NULL
);
2812 /* We currently don't make any attempt to make sure these are
2813 aligned properly like we do for the main unwind info, so
2814 don't support emitting things larger than a byte if we're
2815 only doing unwinding. */
2820 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2823 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2826 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2829 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2831 case DW_OP_plus_uconst
:
2832 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2866 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2869 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2872 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2875 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2876 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2879 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2881 case DW_OP_deref_size
:
2882 case DW_OP_xderef_size
:
2883 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2886 /* Other codes have no operands. */
2891 /* Output a sequence of location operations. */
2894 output_loc_sequence (loc
)
2895 dw_loc_descr_ref loc
;
2897 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2899 /* Output the opcode. */
2900 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2901 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2903 /* Output the operand(s) (if any). */
2904 output_loc_operands (loc
);
2908 /* This routine will generate the correct assembly data for a location
2909 description based on a cfi entry with a complex address. */
2912 output_cfa_loc (cfi
)
2915 dw_loc_descr_ref loc
;
2918 /* Output the size of the block. */
2919 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2920 size
= size_of_locs (loc
);
2921 dw2_asm_output_data_uleb128 (size
, NULL
);
2923 /* Now output the operations themselves. */
2924 output_loc_sequence (loc
);
2927 /* This function builds a dwarf location descriptor sequence from
2928 a dw_cfa_location. */
2930 static struct dw_loc_descr_struct
*
2932 dw_cfa_location
*cfa
;
2934 struct dw_loc_descr_struct
*head
, *tmp
;
2936 if (cfa
->indirect
== 0)
2939 if (cfa
->base_offset
)
2942 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
2944 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
2946 else if (cfa
->reg
<= 31)
2947 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
2949 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
2951 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2952 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2953 add_loc_descr (&head
, tmp
);
2954 if (cfa
->offset
!= 0)
2956 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
2957 add_loc_descr (&head
, tmp
);
2963 /* This function fills in aa dw_cfa_location structure from a dwarf location
2964 descriptor sequence. */
2967 get_cfa_from_loc_descr (cfa
, loc
)
2968 dw_cfa_location
*cfa
;
2969 struct dw_loc_descr_struct
*loc
;
2971 struct dw_loc_descr_struct
*ptr
;
2973 cfa
->base_offset
= 0;
2977 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
2979 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3015 cfa
->reg
= op
- DW_OP_reg0
;
3018 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3052 cfa
->reg
= op
- DW_OP_breg0
;
3053 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3056 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3057 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3062 case DW_OP_plus_uconst
:
3063 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3066 internal_error ("DW_LOC_OP %s not implemented\n",
3067 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3071 #endif /* .debug_frame support */
3073 /* And now, the support for symbolic debugging information. */
3074 #ifdef DWARF2_DEBUGGING_INFO
3076 /* .debug_str support. */
3077 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3078 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3079 hashnode
, const PTR
));
3082 static void dwarf2out_init
PARAMS ((const char *));
3083 static void dwarf2out_finish
PARAMS ((const char *));
3084 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3085 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3086 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3087 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3088 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3089 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3090 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3091 static void dwarf2out_global_decl
PARAMS ((tree
));
3092 static void dwarf2out_abstract_function
PARAMS ((tree
));
3094 /* The debug hooks structure. */
3096 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3102 dwarf2out_start_source_file
,
3103 dwarf2out_end_source_file
,
3104 dwarf2out_begin_block
,
3105 dwarf2out_end_block
,
3106 dwarf2out_ignore_block
,
3107 dwarf2out_source_line
,
3108 dwarf2out_begin_prologue
,
3109 debug_nothing_int
, /* end_prologue */
3110 dwarf2out_end_epilogue
,
3111 debug_nothing_tree
, /* begin_function */
3112 debug_nothing_int
, /* end_function */
3113 dwarf2out_decl
, /* function_decl */
3114 dwarf2out_global_decl
,
3115 debug_nothing_tree
, /* deferred_inline_function */
3116 /* The DWARF 2 backend tries to reduce debugging bloat by not
3117 emitting the abstract description of inline functions until
3118 something tries to reference them. */
3119 dwarf2out_abstract_function
, /* outlining_inline_function */
3120 debug_nothing_rtx
/* label */
3123 /* NOTE: In the comments in this file, many references are made to
3124 "Debugging Information Entries". This term is abbreviated as `DIE'
3125 throughout the remainder of this file. */
3127 /* An internal representation of the DWARF output is built, and then
3128 walked to generate the DWARF debugging info. The walk of the internal
3129 representation is done after the entire program has been compiled.
3130 The types below are used to describe the internal representation. */
3132 /* Various DIE's use offsets relative to the beginning of the
3133 .debug_info section to refer to each other. */
3135 typedef long int dw_offset
;
3137 /* Define typedefs here to avoid circular dependencies. */
3139 typedef struct dw_attr_struct
*dw_attr_ref
;
3140 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3141 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3142 typedef struct pubname_struct
*pubname_ref
;
3143 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3145 /* Each entry in the line_info_table maintains the file and
3146 line number associated with the label generated for that
3147 entry. The label gives the PC value associated with
3148 the line number entry. */
3150 typedef struct dw_line_info_struct
3152 unsigned long dw_file_num
;
3153 unsigned long dw_line_num
;
3157 /* Line information for functions in separate sections; each one gets its
3159 typedef struct dw_separate_line_info_struct
3161 unsigned long dw_file_num
;
3162 unsigned long dw_line_num
;
3163 unsigned long function
;
3165 dw_separate_line_info_entry
;
3167 /* Each DIE attribute has a field specifying the attribute kind,
3168 a link to the next attribute in the chain, and an attribute value.
3169 Attributes are typically linked below the DIE they modify. */
3171 typedef struct dw_attr_struct
3173 enum dwarf_attribute dw_attr
;
3174 dw_attr_ref dw_attr_next
;
3175 dw_val_node dw_attr_val
;
3179 /* The Debugging Information Entry (DIE) structure */
3181 typedef struct die_struct
3183 enum dwarf_tag die_tag
;
3185 dw_attr_ref die_attr
;
3186 dw_die_ref die_parent
;
3187 dw_die_ref die_child
;
3189 dw_offset die_offset
;
3190 unsigned long die_abbrev
;
3195 /* The pubname structure */
3197 typedef struct pubname_struct
3204 struct dw_ranges_struct
3209 /* The limbo die list structure. */
3210 typedef struct limbo_die_struct
3214 struct limbo_die_struct
*next
;
3218 /* How to start an assembler comment. */
3219 #ifndef ASM_COMMENT_START
3220 #define ASM_COMMENT_START ";#"
3223 /* Define a macro which returns non-zero for a TYPE_DECL which was
3224 implicitly generated for a tagged type.
3226 Note that unlike the gcc front end (which generates a NULL named
3227 TYPE_DECL node for each complete tagged type, each array type, and
3228 each function type node created) the g++ front end generates a
3229 _named_ TYPE_DECL node for each tagged type node created.
3230 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3231 generate a DW_TAG_typedef DIE for them. */
3233 #define TYPE_DECL_IS_STUB(decl) \
3234 (DECL_NAME (decl) == NULL_TREE \
3235 || (DECL_ARTIFICIAL (decl) \
3236 && is_tagged_type (TREE_TYPE (decl)) \
3237 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3238 /* This is necessary for stub decls that \
3239 appear in nested inline functions. */ \
3240 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3241 && (decl_ultimate_origin (decl) \
3242 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3244 /* Information concerning the compilation unit's programming
3245 language, and compiler version. */
3247 /* Fixed size portion of the DWARF compilation unit header. */
3248 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3250 /* Fixed size portion of public names info. */
3251 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3253 /* Fixed size portion of the address range info. */
3254 #define DWARF_ARANGES_HEADER_SIZE \
3255 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3256 - DWARF_OFFSET_SIZE)
3258 /* Size of padding portion in the address range info. It must be
3259 aligned to twice the pointer size. */
3260 #define DWARF_ARANGES_PAD_SIZE \
3261 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3262 - (2 * DWARF_OFFSET_SIZE + 4))
3264 /* Use assembler line directives if available. */
3265 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3266 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3267 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3269 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3273 /* Minimum line offset in a special line info. opcode.
3274 This value was chosen to give a reasonable range of values. */
3275 #define DWARF_LINE_BASE -10
3277 /* First special line opcode - leave room for the standard opcodes. */
3278 #define DWARF_LINE_OPCODE_BASE 10
3280 /* Range of line offsets in a special line info. opcode. */
3281 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3283 /* Flag that indicates the initial value of the is_stmt_start flag.
3284 In the present implementation, we do not mark any lines as
3285 the beginning of a source statement, because that information
3286 is not made available by the GCC front-end. */
3287 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3289 /* This location is used by calc_die_sizes() to keep track
3290 the offset of each DIE within the .debug_info section. */
3291 static unsigned long next_die_offset
;
3293 /* Record the root of the DIE's built for the current compilation unit. */
3294 static dw_die_ref comp_unit_die
;
3296 /* A list of DIEs with a NULL parent waiting to be relocated. */
3297 static limbo_die_node
*limbo_die_list
= 0;
3299 /* Structure used by lookup_filename to manage sets of filenames. */
3305 unsigned last_lookup_index
;
3308 /* Size (in elements) of increments by which we may expand the filename
3310 #define FILE_TABLE_INCREMENT 64
3312 /* Filenames referenced by this compilation unit. */
3313 static struct file_table file_table
;
3315 /* Local pointer to the name of the main input file. Initialized in
3317 static const char *primary_filename
;
3319 /* A pointer to the base of a table of references to DIE's that describe
3320 declarations. The table is indexed by DECL_UID() which is a unique
3321 number identifying each decl. */
3322 static dw_die_ref
*decl_die_table
;
3324 /* Number of elements currently allocated for the decl_die_table. */
3325 static unsigned decl_die_table_allocated
;
3327 /* Number of elements in decl_die_table currently in use. */
3328 static unsigned decl_die_table_in_use
;
3330 /* Size (in elements) of increments by which we may expand the
3332 #define DECL_DIE_TABLE_INCREMENT 256
3334 /* A pointer to the base of a list of references to DIE's that
3335 are uniquely identified by their tag, presence/absence of
3336 children DIE's, and list of attribute/value pairs. */
3337 static dw_die_ref
*abbrev_die_table
;
3339 /* Number of elements currently allocated for abbrev_die_table. */
3340 static unsigned abbrev_die_table_allocated
;
3342 /* Number of elements in type_die_table currently in use. */
3343 static unsigned abbrev_die_table_in_use
;
3345 /* Size (in elements) of increments by which we may expand the
3346 abbrev_die_table. */
3347 #define ABBREV_DIE_TABLE_INCREMENT 256
3349 /* A pointer to the base of a table that contains line information
3350 for each source code line in .text in the compilation unit. */
3351 static dw_line_info_ref line_info_table
;
3353 /* Number of elements currently allocated for line_info_table. */
3354 static unsigned line_info_table_allocated
;
3356 /* Number of elements in separate_line_info_table currently in use. */
3357 static unsigned separate_line_info_table_in_use
;
3359 /* A pointer to the base of a table that contains line information
3360 for each source code line outside of .text in the compilation unit. */
3361 static dw_separate_line_info_ref separate_line_info_table
;
3363 /* Number of elements currently allocated for separate_line_info_table. */
3364 static unsigned separate_line_info_table_allocated
;
3366 /* Number of elements in line_info_table currently in use. */
3367 static unsigned line_info_table_in_use
;
3369 /* Size (in elements) of increments by which we may expand the
3371 #define LINE_INFO_TABLE_INCREMENT 1024
3373 /* A pointer to the base of a table that contains a list of publicly
3374 accessible names. */
3375 static pubname_ref pubname_table
;
3377 /* Number of elements currently allocated for pubname_table. */
3378 static unsigned pubname_table_allocated
;
3380 /* Number of elements in pubname_table currently in use. */
3381 static unsigned pubname_table_in_use
;
3383 /* Size (in elements) of increments by which we may expand the
3385 #define PUBNAME_TABLE_INCREMENT 64
3387 /* Array of dies for which we should generate .debug_arange info. */
3388 static dw_die_ref
*arange_table
;
3390 /* Number of elements currently allocated for arange_table. */
3391 static unsigned arange_table_allocated
;
3393 /* Number of elements in arange_table currently in use. */
3394 static unsigned arange_table_in_use
;
3396 /* Size (in elements) of increments by which we may expand the
3398 #define ARANGE_TABLE_INCREMENT 64
3400 /* Array of dies for which we should generate .debug_ranges info. */
3401 static dw_ranges_ref ranges_table
;
3403 /* Number of elements currently allocated for ranges_table. */
3404 static unsigned ranges_table_allocated
;
3406 /* Number of elements in ranges_table currently in use. */
3407 static unsigned ranges_table_in_use
;
3409 /* Size (in elements) of increments by which we may expand the
3411 #define RANGES_TABLE_INCREMENT 64
3413 /* Whether we have location lists that need outputting */
3414 static unsigned have_location_lists
;
3416 /* Record whether the function being analyzed contains inlined functions. */
3417 static int current_function_has_inlines
;
3418 #if 0 && defined (MIPS_DEBUGGING_INFO)
3419 static int comp_unit_has_inlines
;
3422 /* Forward declarations for functions defined in this file. */
3424 static int is_pseudo_reg
PARAMS ((rtx
));
3425 static tree type_main_variant
PARAMS ((tree
));
3426 static int is_tagged_type
PARAMS ((tree
));
3427 static const char *dwarf_tag_name
PARAMS ((unsigned));
3428 static const char *dwarf_attr_name
PARAMS ((unsigned));
3429 static const char *dwarf_form_name
PARAMS ((unsigned));
3431 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3433 static tree decl_ultimate_origin
PARAMS ((tree
));
3434 static tree block_ultimate_origin
PARAMS ((tree
));
3435 static tree decl_class_context
PARAMS ((tree
));
3436 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3437 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3438 static void add_AT_flag
PARAMS ((dw_die_ref
,
3439 enum dwarf_attribute
,
3441 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3442 static void add_AT_int
PARAMS ((dw_die_ref
,
3443 enum dwarf_attribute
, long));
3444 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3445 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3446 enum dwarf_attribute
,
3448 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3449 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3450 enum dwarf_attribute
,
3453 static void add_AT_float
PARAMS ((dw_die_ref
,
3454 enum dwarf_attribute
,
3456 static void add_AT_string
PARAMS ((dw_die_ref
,
3457 enum dwarf_attribute
,
3459 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3460 static int AT_string_form
PARAMS ((dw_attr_ref
));
3461 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3462 enum dwarf_attribute
,
3464 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3465 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3466 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3467 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3468 enum dwarf_attribute
,
3470 static void add_AT_loc
PARAMS ((dw_die_ref
,
3471 enum dwarf_attribute
,
3473 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3474 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3475 enum dwarf_attribute
,
3477 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3478 static void add_AT_addr
PARAMS ((dw_die_ref
,
3479 enum dwarf_attribute
,
3481 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3482 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3483 enum dwarf_attribute
,
3485 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3486 enum dwarf_attribute
,
3488 static void add_AT_offset
PARAMS ((dw_die_ref
,
3489 enum dwarf_attribute
,
3491 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3492 enum dwarf_attribute
,
3494 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3495 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3496 enum dwarf_attribute
));
3497 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3498 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3499 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3500 enum dwarf_attribute
));
3501 static int get_AT_flag
PARAMS ((dw_die_ref
,
3502 enum dwarf_attribute
));
3503 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3504 enum dwarf_attribute
));
3505 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3506 enum dwarf_attribute
));
3507 static int is_c_family
PARAMS ((void));
3508 static int is_cxx
PARAMS ((void));
3509 static int is_java
PARAMS ((void));
3510 static int is_fortran
PARAMS ((void));
3511 static void remove_AT
PARAMS ((dw_die_ref
,
3512 enum dwarf_attribute
));
3513 static inline void free_die
PARAMS ((dw_die_ref
));
3514 static void remove_children
PARAMS ((dw_die_ref
));
3515 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3516 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3518 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3519 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3520 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3521 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3522 static void print_spaces
PARAMS ((FILE *));
3523 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3524 static void print_dwarf_line_table
PARAMS ((FILE *));
3525 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3526 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3527 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3528 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3529 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3531 static void attr_checksum
PARAMS ((dw_attr_ref
,
3533 static void die_checksum
PARAMS ((dw_die_ref
,
3535 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3536 static int is_type_die
PARAMS ((dw_die_ref
));
3537 static int is_comdat_die
PARAMS ((dw_die_ref
));
3538 static int is_symbol_die
PARAMS ((dw_die_ref
));
3539 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3540 static void break_out_includes
PARAMS ((dw_die_ref
));
3541 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3542 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3543 static void output_location_lists
PARAMS ((dw_die_ref
));
3544 static int constant_size
PARAMS ((long unsigned));
3545 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3546 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3547 static void mark_dies
PARAMS ((dw_die_ref
));
3548 static void unmark_dies
PARAMS ((dw_die_ref
));
3549 static unsigned long size_of_pubnames
PARAMS ((void));
3550 static unsigned long size_of_aranges
PARAMS ((void));
3551 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3552 static void output_value_format
PARAMS ((dw_attr_ref
));
3553 static void output_abbrev_section
PARAMS ((void));
3554 static void output_die_symbol
PARAMS ((dw_die_ref
));
3555 static void output_die
PARAMS ((dw_die_ref
));
3556 static void output_compilation_unit_header
PARAMS ((void));
3557 static void output_comp_unit
PARAMS ((dw_die_ref
));
3558 static const char *dwarf2_name
PARAMS ((tree
, int));
3559 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3560 static void output_pubnames
PARAMS ((void));
3561 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3562 static void output_aranges
PARAMS ((void));
3563 static unsigned int add_ranges
PARAMS ((tree
));
3564 static void output_ranges
PARAMS ((void));
3565 static void output_line_info
PARAMS ((void));
3566 static void output_file_names
PARAMS ((void));
3567 static dw_die_ref base_type_die
PARAMS ((tree
));
3568 static tree root_type
PARAMS ((tree
));
3569 static int is_base_type
PARAMS ((tree
));
3570 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3571 static int type_is_enum
PARAMS ((tree
));
3572 static unsigned int reg_number
PARAMS ((rtx
));
3573 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3574 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3575 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3576 static int is_based_loc
PARAMS ((rtx
));
3577 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3578 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3579 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3580 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3581 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3582 static tree field_type
PARAMS ((tree
));
3583 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3584 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3585 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3586 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3587 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3588 enum dwarf_attribute
, rtx
));
3589 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3590 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3591 static rtx rtl_for_decl_location
PARAMS ((tree
));
3592 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3593 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3594 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3595 static void add_bound_info
PARAMS ((dw_die_ref
,
3596 enum dwarf_attribute
, tree
));
3597 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3598 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3599 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3600 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3601 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3602 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3603 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3604 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3605 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3606 static void push_decl_scope
PARAMS ((tree
));
3607 static void pop_decl_scope
PARAMS ((void));
3608 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3609 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3610 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3611 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3613 static const char *type_tag
PARAMS ((tree
));
3614 static tree member_declared_type
PARAMS ((tree
));
3616 static const char *decl_start_label
PARAMS ((tree
));
3618 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3619 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3621 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3623 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3624 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3625 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3626 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3627 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3628 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3629 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3630 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3631 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3632 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3633 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3634 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3635 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3636 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3637 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3638 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3639 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3640 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3641 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3642 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3643 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3644 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3645 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3646 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3647 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3648 static int is_redundant_typedef
PARAMS ((tree
));
3649 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3650 static unsigned lookup_filename
PARAMS ((const char *));
3651 static void init_file_table
PARAMS ((void));
3652 static void retry_incomplete_types
PARAMS ((void));
3653 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3654 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3655 static int file_info_cmp
PARAMS ((const void *, const void *));
3656 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3657 const char *, const char *,
3658 const char *, unsigned));
3659 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3661 const char *, const char *, const char *));
3662 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3663 static char *gen_internal_sym
PARAMS ((const char *));
3664 static void mark_limbo_die_list
PARAMS ((void *));
3666 /* Section names used to hold DWARF debugging information. */
3667 #ifndef DEBUG_INFO_SECTION
3668 #define DEBUG_INFO_SECTION ".debug_info"
3670 #ifndef DEBUG_ABBREV_SECTION
3671 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3673 #ifndef DEBUG_ARANGES_SECTION
3674 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3676 #ifndef DEBUG_MACINFO_SECTION
3677 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3679 #ifndef DEBUG_LINE_SECTION
3680 #define DEBUG_LINE_SECTION ".debug_line"
3682 #ifndef DEBUG_LOC_SECTION
3683 #define DEBUG_LOC_SECTION ".debug_loc"
3685 #ifndef DEBUG_PUBNAMES_SECTION
3686 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3688 #ifndef DEBUG_STR_SECTION
3689 #define DEBUG_STR_SECTION ".debug_str"
3691 #ifndef DEBUG_RANGES_SECTION
3692 #define DEBUG_RANGES_SECTION ".debug_ranges"
3695 /* Standard ELF section names for compiled code and data. */
3696 #ifndef TEXT_SECTION_NAME
3697 #define TEXT_SECTION_NAME ".text"
3700 /* Section flags for .debug_str section. */
3701 #ifdef HAVE_GAS_SHF_MERGE
3702 #define DEBUG_STR_SECTION_FLAGS \
3703 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3705 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3708 /* Labels we insert at beginning sections we can reference instead of
3709 the section names themselves. */
3711 #ifndef TEXT_SECTION_LABEL
3712 #define TEXT_SECTION_LABEL "Ltext"
3714 #ifndef DEBUG_LINE_SECTION_LABEL
3715 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3717 #ifndef DEBUG_INFO_SECTION_LABEL
3718 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3720 #ifndef DEBUG_ABBREV_SECTION_LABEL
3721 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3723 #ifndef DEBUG_LOC_SECTION_LABEL
3724 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3726 #ifndef DEBUG_RANGES_SECTION_LABEL
3727 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3729 #ifndef DEBUG_MACINFO_SECTION_LABEL
3730 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3733 /* Definitions of defaults for formats and names of various special
3734 (artificial) labels which may be generated within this file (when the -g
3735 options is used and DWARF_DEBUGGING_INFO is in effect.
3736 If necessary, these may be overridden from within the tm.h file, but
3737 typically, overriding these defaults is unnecessary. */
3739 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3740 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3741 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3742 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3743 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3744 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3745 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3746 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3748 #ifndef TEXT_END_LABEL
3749 #define TEXT_END_LABEL "Letext"
3751 #ifndef BLOCK_BEGIN_LABEL
3752 #define BLOCK_BEGIN_LABEL "LBB"
3754 #ifndef BLOCK_END_LABEL
3755 #define BLOCK_END_LABEL "LBE"
3757 #ifndef LINE_CODE_LABEL
3758 #define LINE_CODE_LABEL "LM"
3760 #ifndef SEPARATE_LINE_CODE_LABEL
3761 #define SEPARATE_LINE_CODE_LABEL "LSM"
3764 /* We allow a language front-end to designate a function that is to be
3765 called to "demangle" any name before it it put into a DIE. */
3767 static const char *(*demangle_name_func
) PARAMS ((const char *));
3770 dwarf2out_set_demangle_name_func (func
)
3771 const char *(*func
) PARAMS ((const char *));
3773 demangle_name_func
= func
;
3776 /* Test if rtl node points to a pseudo register. */
3782 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3783 || (GET_CODE (rtl
) == SUBREG
3784 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3787 /* Return a reference to a type, with its const and volatile qualifiers
3791 type_main_variant (type
)
3794 type
= TYPE_MAIN_VARIANT (type
);
3796 /* ??? There really should be only one main variant among any group of
3797 variants of a given type (and all of the MAIN_VARIANT values for all
3798 members of the group should point to that one type) but sometimes the C
3799 front-end messes this up for array types, so we work around that bug
3801 if (TREE_CODE (type
) == ARRAY_TYPE
)
3802 while (type
!= TYPE_MAIN_VARIANT (type
))
3803 type
= TYPE_MAIN_VARIANT (type
);
3808 /* Return non-zero if the given type node represents a tagged type. */
3811 is_tagged_type (type
)
3814 enum tree_code code
= TREE_CODE (type
);
3816 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3817 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3820 /* Convert a DIE tag into its string name. */
3823 dwarf_tag_name (tag
)
3828 case DW_TAG_padding
:
3829 return "DW_TAG_padding";
3830 case DW_TAG_array_type
:
3831 return "DW_TAG_array_type";
3832 case DW_TAG_class_type
:
3833 return "DW_TAG_class_type";
3834 case DW_TAG_entry_point
:
3835 return "DW_TAG_entry_point";
3836 case DW_TAG_enumeration_type
:
3837 return "DW_TAG_enumeration_type";
3838 case DW_TAG_formal_parameter
:
3839 return "DW_TAG_formal_parameter";
3840 case DW_TAG_imported_declaration
:
3841 return "DW_TAG_imported_declaration";
3843 return "DW_TAG_label";
3844 case DW_TAG_lexical_block
:
3845 return "DW_TAG_lexical_block";
3847 return "DW_TAG_member";
3848 case DW_TAG_pointer_type
:
3849 return "DW_TAG_pointer_type";
3850 case DW_TAG_reference_type
:
3851 return "DW_TAG_reference_type";
3852 case DW_TAG_compile_unit
:
3853 return "DW_TAG_compile_unit";
3854 case DW_TAG_string_type
:
3855 return "DW_TAG_string_type";
3856 case DW_TAG_structure_type
:
3857 return "DW_TAG_structure_type";
3858 case DW_TAG_subroutine_type
:
3859 return "DW_TAG_subroutine_type";
3860 case DW_TAG_typedef
:
3861 return "DW_TAG_typedef";
3862 case DW_TAG_union_type
:
3863 return "DW_TAG_union_type";
3864 case DW_TAG_unspecified_parameters
:
3865 return "DW_TAG_unspecified_parameters";
3866 case DW_TAG_variant
:
3867 return "DW_TAG_variant";
3868 case DW_TAG_common_block
:
3869 return "DW_TAG_common_block";
3870 case DW_TAG_common_inclusion
:
3871 return "DW_TAG_common_inclusion";
3872 case DW_TAG_inheritance
:
3873 return "DW_TAG_inheritance";
3874 case DW_TAG_inlined_subroutine
:
3875 return "DW_TAG_inlined_subroutine";
3877 return "DW_TAG_module";
3878 case DW_TAG_ptr_to_member_type
:
3879 return "DW_TAG_ptr_to_member_type";
3880 case DW_TAG_set_type
:
3881 return "DW_TAG_set_type";
3882 case DW_TAG_subrange_type
:
3883 return "DW_TAG_subrange_type";
3884 case DW_TAG_with_stmt
:
3885 return "DW_TAG_with_stmt";
3886 case DW_TAG_access_declaration
:
3887 return "DW_TAG_access_declaration";
3888 case DW_TAG_base_type
:
3889 return "DW_TAG_base_type";
3890 case DW_TAG_catch_block
:
3891 return "DW_TAG_catch_block";
3892 case DW_TAG_const_type
:
3893 return "DW_TAG_const_type";
3894 case DW_TAG_constant
:
3895 return "DW_TAG_constant";
3896 case DW_TAG_enumerator
:
3897 return "DW_TAG_enumerator";
3898 case DW_TAG_file_type
:
3899 return "DW_TAG_file_type";
3901 return "DW_TAG_friend";
3902 case DW_TAG_namelist
:
3903 return "DW_TAG_namelist";
3904 case DW_TAG_namelist_item
:
3905 return "DW_TAG_namelist_item";
3906 case DW_TAG_packed_type
:
3907 return "DW_TAG_packed_type";
3908 case DW_TAG_subprogram
:
3909 return "DW_TAG_subprogram";
3910 case DW_TAG_template_type_param
:
3911 return "DW_TAG_template_type_param";
3912 case DW_TAG_template_value_param
:
3913 return "DW_TAG_template_value_param";
3914 case DW_TAG_thrown_type
:
3915 return "DW_TAG_thrown_type";
3916 case DW_TAG_try_block
:
3917 return "DW_TAG_try_block";
3918 case DW_TAG_variant_part
:
3919 return "DW_TAG_variant_part";
3920 case DW_TAG_variable
:
3921 return "DW_TAG_variable";
3922 case DW_TAG_volatile_type
:
3923 return "DW_TAG_volatile_type";
3924 case DW_TAG_MIPS_loop
:
3925 return "DW_TAG_MIPS_loop";
3926 case DW_TAG_format_label
:
3927 return "DW_TAG_format_label";
3928 case DW_TAG_function_template
:
3929 return "DW_TAG_function_template";
3930 case DW_TAG_class_template
:
3931 return "DW_TAG_class_template";
3932 case DW_TAG_GNU_BINCL
:
3933 return "DW_TAG_GNU_BINCL";
3934 case DW_TAG_GNU_EINCL
:
3935 return "DW_TAG_GNU_EINCL";
3937 return "DW_TAG_<unknown>";
3941 /* Convert a DWARF attribute code into its string name. */
3944 dwarf_attr_name (attr
)
3950 return "DW_AT_sibling";
3951 case DW_AT_location
:
3952 return "DW_AT_location";
3954 return "DW_AT_name";
3955 case DW_AT_ordering
:
3956 return "DW_AT_ordering";
3957 case DW_AT_subscr_data
:
3958 return "DW_AT_subscr_data";
3959 case DW_AT_byte_size
:
3960 return "DW_AT_byte_size";
3961 case DW_AT_bit_offset
:
3962 return "DW_AT_bit_offset";
3963 case DW_AT_bit_size
:
3964 return "DW_AT_bit_size";
3965 case DW_AT_element_list
:
3966 return "DW_AT_element_list";
3967 case DW_AT_stmt_list
:
3968 return "DW_AT_stmt_list";
3970 return "DW_AT_low_pc";
3972 return "DW_AT_high_pc";
3973 case DW_AT_language
:
3974 return "DW_AT_language";
3976 return "DW_AT_member";
3978 return "DW_AT_discr";
3979 case DW_AT_discr_value
:
3980 return "DW_AT_discr_value";
3981 case DW_AT_visibility
:
3982 return "DW_AT_visibility";
3984 return "DW_AT_import";
3985 case DW_AT_string_length
:
3986 return "DW_AT_string_length";
3987 case DW_AT_common_reference
:
3988 return "DW_AT_common_reference";
3989 case DW_AT_comp_dir
:
3990 return "DW_AT_comp_dir";
3991 case DW_AT_const_value
:
3992 return "DW_AT_const_value";
3993 case DW_AT_containing_type
:
3994 return "DW_AT_containing_type";
3995 case DW_AT_default_value
:
3996 return "DW_AT_default_value";
3998 return "DW_AT_inline";
3999 case DW_AT_is_optional
:
4000 return "DW_AT_is_optional";
4001 case DW_AT_lower_bound
:
4002 return "DW_AT_lower_bound";
4003 case DW_AT_producer
:
4004 return "DW_AT_producer";
4005 case DW_AT_prototyped
:
4006 return "DW_AT_prototyped";
4007 case DW_AT_return_addr
:
4008 return "DW_AT_return_addr";
4009 case DW_AT_start_scope
:
4010 return "DW_AT_start_scope";
4011 case DW_AT_stride_size
:
4012 return "DW_AT_stride_size";
4013 case DW_AT_upper_bound
:
4014 return "DW_AT_upper_bound";
4015 case DW_AT_abstract_origin
:
4016 return "DW_AT_abstract_origin";
4017 case DW_AT_accessibility
:
4018 return "DW_AT_accessibility";
4019 case DW_AT_address_class
:
4020 return "DW_AT_address_class";
4021 case DW_AT_artificial
:
4022 return "DW_AT_artificial";
4023 case DW_AT_base_types
:
4024 return "DW_AT_base_types";
4025 case DW_AT_calling_convention
:
4026 return "DW_AT_calling_convention";
4028 return "DW_AT_count";
4029 case DW_AT_data_member_location
:
4030 return "DW_AT_data_member_location";
4031 case DW_AT_decl_column
:
4032 return "DW_AT_decl_column";
4033 case DW_AT_decl_file
:
4034 return "DW_AT_decl_file";
4035 case DW_AT_decl_line
:
4036 return "DW_AT_decl_line";
4037 case DW_AT_declaration
:
4038 return "DW_AT_declaration";
4039 case DW_AT_discr_list
:
4040 return "DW_AT_discr_list";
4041 case DW_AT_encoding
:
4042 return "DW_AT_encoding";
4043 case DW_AT_external
:
4044 return "DW_AT_external";
4045 case DW_AT_frame_base
:
4046 return "DW_AT_frame_base";
4048 return "DW_AT_friend";
4049 case DW_AT_identifier_case
:
4050 return "DW_AT_identifier_case";
4051 case DW_AT_macro_info
:
4052 return "DW_AT_macro_info";
4053 case DW_AT_namelist_items
:
4054 return "DW_AT_namelist_items";
4055 case DW_AT_priority
:
4056 return "DW_AT_priority";
4058 return "DW_AT_segment";
4059 case DW_AT_specification
:
4060 return "DW_AT_specification";
4061 case DW_AT_static_link
:
4062 return "DW_AT_static_link";
4064 return "DW_AT_type";
4065 case DW_AT_use_location
:
4066 return "DW_AT_use_location";
4067 case DW_AT_variable_parameter
:
4068 return "DW_AT_variable_parameter";
4069 case DW_AT_virtuality
:
4070 return "DW_AT_virtuality";
4071 case DW_AT_vtable_elem_location
:
4072 return "DW_AT_vtable_elem_location";
4074 case DW_AT_allocated
:
4075 return "DW_AT_allocated";
4076 case DW_AT_associated
:
4077 return "DW_AT_associated";
4078 case DW_AT_data_location
:
4079 return "DW_AT_data_location";
4081 return "DW_AT_stride";
4082 case DW_AT_entry_pc
:
4083 return "DW_AT_entry_pc";
4084 case DW_AT_use_UTF8
:
4085 return "DW_AT_use_UTF8";
4086 case DW_AT_extension
:
4087 return "DW_AT_extension";
4089 return "DW_AT_ranges";
4090 case DW_AT_trampoline
:
4091 return "DW_AT_trampoline";
4092 case DW_AT_call_column
:
4093 return "DW_AT_call_column";
4094 case DW_AT_call_file
:
4095 return "DW_AT_call_file";
4096 case DW_AT_call_line
:
4097 return "DW_AT_call_line";
4099 case DW_AT_MIPS_fde
:
4100 return "DW_AT_MIPS_fde";
4101 case DW_AT_MIPS_loop_begin
:
4102 return "DW_AT_MIPS_loop_begin";
4103 case DW_AT_MIPS_tail_loop_begin
:
4104 return "DW_AT_MIPS_tail_loop_begin";
4105 case DW_AT_MIPS_epilog_begin
:
4106 return "DW_AT_MIPS_epilog_begin";
4107 case DW_AT_MIPS_loop_unroll_factor
:
4108 return "DW_AT_MIPS_loop_unroll_factor";
4109 case DW_AT_MIPS_software_pipeline_depth
:
4110 return "DW_AT_MIPS_software_pipeline_depth";
4111 case DW_AT_MIPS_linkage_name
:
4112 return "DW_AT_MIPS_linkage_name";
4113 case DW_AT_MIPS_stride
:
4114 return "DW_AT_MIPS_stride";
4115 case DW_AT_MIPS_abstract_name
:
4116 return "DW_AT_MIPS_abstract_name";
4117 case DW_AT_MIPS_clone_origin
:
4118 return "DW_AT_MIPS_clone_origin";
4119 case DW_AT_MIPS_has_inlines
:
4120 return "DW_AT_MIPS_has_inlines";
4122 case DW_AT_sf_names
:
4123 return "DW_AT_sf_names";
4124 case DW_AT_src_info
:
4125 return "DW_AT_src_info";
4126 case DW_AT_mac_info
:
4127 return "DW_AT_mac_info";
4128 case DW_AT_src_coords
:
4129 return "DW_AT_src_coords";
4130 case DW_AT_body_begin
:
4131 return "DW_AT_body_begin";
4132 case DW_AT_body_end
:
4133 return "DW_AT_body_end";
4134 case DW_AT_GNU_vector
:
4135 return "DW_AT_GNU_vector";
4137 case DW_AT_VMS_rtnbeg_pd_address
:
4138 return "DW_AT_VMS_rtnbeg_pd_address";
4141 return "DW_AT_<unknown>";
4145 /* Convert a DWARF value form code into its string name. */
4148 dwarf_form_name (form
)
4154 return "DW_FORM_addr";
4155 case DW_FORM_block2
:
4156 return "DW_FORM_block2";
4157 case DW_FORM_block4
:
4158 return "DW_FORM_block4";
4160 return "DW_FORM_data2";
4162 return "DW_FORM_data4";
4164 return "DW_FORM_data8";
4165 case DW_FORM_string
:
4166 return "DW_FORM_string";
4168 return "DW_FORM_block";
4169 case DW_FORM_block1
:
4170 return "DW_FORM_block1";
4172 return "DW_FORM_data1";
4174 return "DW_FORM_flag";
4176 return "DW_FORM_sdata";
4178 return "DW_FORM_strp";
4180 return "DW_FORM_udata";
4181 case DW_FORM_ref_addr
:
4182 return "DW_FORM_ref_addr";
4184 return "DW_FORM_ref1";
4186 return "DW_FORM_ref2";
4188 return "DW_FORM_ref4";
4190 return "DW_FORM_ref8";
4191 case DW_FORM_ref_udata
:
4192 return "DW_FORM_ref_udata";
4193 case DW_FORM_indirect
:
4194 return "DW_FORM_indirect";
4196 return "DW_FORM_<unknown>";
4200 /* Convert a DWARF type code into its string name. */
4204 dwarf_type_encoding_name (enc
)
4209 case DW_ATE_address
:
4210 return "DW_ATE_address";
4211 case DW_ATE_boolean
:
4212 return "DW_ATE_boolean";
4213 case DW_ATE_complex_float
:
4214 return "DW_ATE_complex_float";
4216 return "DW_ATE_float";
4218 return "DW_ATE_signed";
4219 case DW_ATE_signed_char
:
4220 return "DW_ATE_signed_char";
4221 case DW_ATE_unsigned
:
4222 return "DW_ATE_unsigned";
4223 case DW_ATE_unsigned_char
:
4224 return "DW_ATE_unsigned_char";
4226 return "DW_ATE_<unknown>";
4231 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4232 instance of an inlined instance of a decl which is local to an inline
4233 function, so we have to trace all of the way back through the origin chain
4234 to find out what sort of node actually served as the original seed for the
4238 decl_ultimate_origin (decl
)
4241 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4242 nodes in the function to point to themselves; ignore that if
4243 we're trying to output the abstract instance of this function. */
4244 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4247 #ifdef ENABLE_CHECKING
4248 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4249 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4250 most distant ancestor, this should never happen. */
4254 return DECL_ABSTRACT_ORIGIN (decl
);
4257 /* Determine the "ultimate origin" of a block. The block may be an inlined
4258 instance of an inlined instance of a block which is local to an inline
4259 function, so we have to trace all of the way back through the origin chain
4260 to find out what sort of node actually served as the original seed for the
4264 block_ultimate_origin (block
)
4267 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4269 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4270 nodes in the function to point to themselves; ignore that if
4271 we're trying to output the abstract instance of this function. */
4272 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4275 if (immediate_origin
== NULL_TREE
)
4280 tree lookahead
= immediate_origin
;
4284 ret_val
= lookahead
;
4285 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4286 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4288 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4294 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4295 of a virtual function may refer to a base class, so we check the 'this'
4299 decl_class_context (decl
)
4302 tree context
= NULL_TREE
;
4304 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4305 context
= DECL_CONTEXT (decl
);
4307 context
= TYPE_MAIN_VARIANT
4308 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4310 if (context
&& !TYPE_P (context
))
4311 context
= NULL_TREE
;
4316 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4317 addition order, and correct that in reverse_all_dies. */
4320 add_dwarf_attr (die
, attr
)
4324 if (die
!= NULL
&& attr
!= NULL
)
4326 attr
->dw_attr_next
= die
->die_attr
;
4327 die
->die_attr
= attr
;
4331 static inline dw_val_class
4335 return a
->dw_attr_val
.val_class
;
4338 /* Add a flag value attribute to a DIE. */
4341 add_AT_flag (die
, attr_kind
, flag
)
4343 enum dwarf_attribute attr_kind
;
4346 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4348 attr
->dw_attr_next
= NULL
;
4349 attr
->dw_attr
= attr_kind
;
4350 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4351 attr
->dw_attr_val
.v
.val_flag
= flag
;
4352 add_dwarf_attr (die
, attr
);
4355 static inline unsigned
4359 if (a
&& AT_class (a
) == dw_val_class_flag
)
4360 return a
->dw_attr_val
.v
.val_flag
;
4365 /* Add a signed integer attribute value to a DIE. */
4368 add_AT_int (die
, attr_kind
, int_val
)
4370 enum dwarf_attribute attr_kind
;
4373 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4375 attr
->dw_attr_next
= NULL
;
4376 attr
->dw_attr
= attr_kind
;
4377 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4378 attr
->dw_attr_val
.v
.val_int
= int_val
;
4379 add_dwarf_attr (die
, attr
);
4382 static inline long int
4386 if (a
&& AT_class (a
) == dw_val_class_const
)
4387 return a
->dw_attr_val
.v
.val_int
;
4392 /* Add an unsigned integer attribute value to a DIE. */
4395 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4397 enum dwarf_attribute attr_kind
;
4398 unsigned long unsigned_val
;
4400 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4402 attr
->dw_attr_next
= NULL
;
4403 attr
->dw_attr
= attr_kind
;
4404 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4405 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4406 add_dwarf_attr (die
, attr
);
4409 static inline unsigned long
4413 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4414 return a
->dw_attr_val
.v
.val_unsigned
;
4419 /* Add an unsigned double integer attribute value to a DIE. */
4422 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4424 enum dwarf_attribute attr_kind
;
4425 unsigned long val_hi
;
4426 unsigned long val_low
;
4428 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4430 attr
->dw_attr_next
= NULL
;
4431 attr
->dw_attr
= attr_kind
;
4432 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4433 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4434 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4435 add_dwarf_attr (die
, attr
);
4438 /* Add a floating point attribute value to a DIE and return it. */
4441 add_AT_float (die
, attr_kind
, length
, array
)
4443 enum dwarf_attribute attr_kind
;
4447 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4449 attr
->dw_attr_next
= NULL
;
4450 attr
->dw_attr
= attr_kind
;
4451 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4452 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4453 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4454 add_dwarf_attr (die
, attr
);
4457 /* Add a string attribute value to a DIE. */
4460 add_AT_string (die
, attr_kind
, str
)
4462 enum dwarf_attribute attr_kind
;
4465 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4466 struct indirect_string_node
*node
;
4468 if (! debug_str_hash
)
4470 debug_str_hash
= ht_create (10);
4471 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4474 node
= (struct indirect_string_node
*)
4475 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4476 strlen (str
), HT_ALLOC
);
4479 attr
->dw_attr_next
= NULL
;
4480 attr
->dw_attr
= attr_kind
;
4481 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4482 attr
->dw_attr_val
.v
.val_str
= node
;
4483 add_dwarf_attr (die
, attr
);
4486 static inline const char *
4490 if (a
&& AT_class (a
) == dw_val_class_str
)
4491 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4496 /* Find out whether a string should be output inline in DIE
4497 or out-of-line in .debug_str section. */
4503 if (a
&& AT_class (a
) == dw_val_class_str
)
4505 struct indirect_string_node
*node
;
4507 extern int const_labelno
;
4510 node
= a
->dw_attr_val
.v
.val_str
;
4514 len
= HT_LEN (&node
->id
) + 1;
4516 /* If the string is shorter or equal to the size of the reference, it is
4517 always better to put it inline. */
4518 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4519 return node
->form
= DW_FORM_string
;
4521 /* If we cannot expect the linker to merge strings in .debug_str
4522 section, only put it into .debug_str if it is worth even in this
4524 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4525 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4526 return node
->form
= DW_FORM_string
;
4528 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4530 node
->label
= xstrdup (label
);
4532 return node
->form
= DW_FORM_strp
;
4538 /* Add a DIE reference attribute value to a DIE. */
4541 add_AT_die_ref (die
, attr_kind
, targ_die
)
4543 enum dwarf_attribute attr_kind
;
4544 dw_die_ref targ_die
;
4546 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4548 attr
->dw_attr_next
= NULL
;
4549 attr
->dw_attr
= attr_kind
;
4550 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4551 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4552 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4553 add_dwarf_attr (die
, attr
);
4556 static inline dw_die_ref
4560 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4561 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4570 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4571 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4577 set_AT_ref_external (a
, i
)
4581 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4582 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4587 /* Add an FDE reference attribute value to a DIE. */
4590 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4592 enum dwarf_attribute attr_kind
;
4595 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4597 attr
->dw_attr_next
= NULL
;
4598 attr
->dw_attr
= attr_kind
;
4599 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4600 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4601 add_dwarf_attr (die
, attr
);
4604 /* Add a location description attribute value to a DIE. */
4607 add_AT_loc (die
, attr_kind
, loc
)
4609 enum dwarf_attribute attr_kind
;
4610 dw_loc_descr_ref loc
;
4612 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4614 attr
->dw_attr_next
= NULL
;
4615 attr
->dw_attr
= attr_kind
;
4616 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4617 attr
->dw_attr_val
.v
.val_loc
= loc
;
4618 add_dwarf_attr (die
, attr
);
4621 static inline dw_loc_descr_ref
4625 if (a
&& AT_class (a
) == dw_val_class_loc
)
4626 return a
->dw_attr_val
.v
.val_loc
;
4632 add_AT_loc_list (die
, attr_kind
, loc_list
)
4634 enum dwarf_attribute attr_kind
;
4635 dw_loc_list_ref loc_list
;
4637 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4639 attr
->dw_attr_next
= NULL
;
4640 attr
->dw_attr
= attr_kind
;
4641 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4642 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4643 add_dwarf_attr (die
, attr
);
4644 have_location_lists
= 1;
4647 static inline dw_loc_list_ref
4651 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4652 return a
->dw_attr_val
.v
.val_loc_list
;
4657 /* Add an address constant attribute value to a DIE. */
4660 add_AT_addr (die
, attr_kind
, addr
)
4662 enum dwarf_attribute attr_kind
;
4665 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4667 attr
->dw_attr_next
= NULL
;
4668 attr
->dw_attr
= attr_kind
;
4669 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4670 attr
->dw_attr_val
.v
.val_addr
= addr
;
4671 add_dwarf_attr (die
, attr
);
4678 if (a
&& AT_class (a
) == dw_val_class_addr
)
4679 return a
->dw_attr_val
.v
.val_addr
;
4684 /* Add a label identifier attribute value to a DIE. */
4687 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4689 enum dwarf_attribute attr_kind
;
4692 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4694 attr
->dw_attr_next
= NULL
;
4695 attr
->dw_attr
= attr_kind
;
4696 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4697 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4698 add_dwarf_attr (die
, attr
);
4701 /* Add a section offset attribute value to a DIE. */
4704 add_AT_lbl_offset (die
, attr_kind
, label
)
4706 enum dwarf_attribute attr_kind
;
4709 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4711 attr
->dw_attr_next
= NULL
;
4712 attr
->dw_attr
= attr_kind
;
4713 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4714 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4715 add_dwarf_attr (die
, attr
);
4718 /* Add an offset attribute value to a DIE. */
4721 add_AT_offset (die
, attr_kind
, offset
)
4723 enum dwarf_attribute attr_kind
;
4724 unsigned long offset
;
4726 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4728 attr
->dw_attr_next
= NULL
;
4729 attr
->dw_attr
= attr_kind
;
4730 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4731 attr
->dw_attr_val
.v
.val_offset
= offset
;
4732 add_dwarf_attr (die
, attr
);
4735 /* Add an range_list attribute value to a DIE. */
4738 add_AT_range_list (die
, attr_kind
, offset
)
4740 enum dwarf_attribute attr_kind
;
4741 unsigned long offset
;
4743 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4745 attr
->dw_attr_next
= NULL
;
4746 attr
->dw_attr
= attr_kind
;
4747 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4748 attr
->dw_attr_val
.v
.val_offset
= offset
;
4749 add_dwarf_attr (die
, attr
);
4752 static inline const char *
4756 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4757 || AT_class (a
) == dw_val_class_lbl_offset
))
4758 return a
->dw_attr_val
.v
.val_lbl_id
;
4763 /* Get the attribute of type attr_kind. */
4765 static inline dw_attr_ref
4766 get_AT (die
, attr_kind
)
4768 enum dwarf_attribute attr_kind
;
4771 dw_die_ref spec
= NULL
;
4775 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4776 if (a
->dw_attr
== attr_kind
)
4778 else if (a
->dw_attr
== DW_AT_specification
4779 || a
->dw_attr
== DW_AT_abstract_origin
)
4783 return get_AT (spec
, attr_kind
);
4789 /* Return the "low pc" attribute value, typically associated with a subprogram
4790 DIE. Return null if the "low pc" attribute is either not present, or if it
4791 cannot be represented as an assembler label identifier. */
4793 static inline const char *
4797 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4799 return a
? AT_lbl (a
) : NULL
;
4802 /* Return the "high pc" attribute value, typically associated with a subprogram
4803 DIE. Return null if the "high pc" attribute is either not present, or if it
4804 cannot be represented as an assembler label identifier. */
4806 static inline const char *
4810 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4812 return a
? AT_lbl (a
) : NULL
;
4815 /* Return the value of the string attribute designated by ATTR_KIND, or
4816 NULL if it is not present. */
4818 static inline const char *
4819 get_AT_string (die
, attr_kind
)
4821 enum dwarf_attribute attr_kind
;
4823 dw_attr_ref a
= get_AT (die
, attr_kind
);
4825 return a
? AT_string (a
) : NULL
;
4828 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4829 if it is not present. */
4832 get_AT_flag (die
, attr_kind
)
4834 enum dwarf_attribute attr_kind
;
4836 dw_attr_ref a
= get_AT (die
, attr_kind
);
4838 return a
? AT_flag (a
) : 0;
4841 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4842 if it is not present. */
4844 static inline unsigned
4845 get_AT_unsigned (die
, attr_kind
)
4847 enum dwarf_attribute attr_kind
;
4849 dw_attr_ref a
= get_AT (die
, attr_kind
);
4851 return a
? AT_unsigned (a
) : 0;
4854 static inline dw_die_ref
4855 get_AT_ref (die
, attr_kind
)
4857 enum dwarf_attribute attr_kind
;
4859 dw_attr_ref a
= get_AT (die
, attr_kind
);
4861 return a
? AT_ref (a
) : NULL
;
4867 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4869 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4870 || lang
== DW_LANG_C_plus_plus
);
4876 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4877 == DW_LANG_C_plus_plus
);
4883 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4885 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4891 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4893 return (lang
== DW_LANG_Java
);
4896 /* Free up the memory used by A. */
4898 static inline void free_AT
PARAMS ((dw_attr_ref
));
4903 switch (AT_class (a
))
4905 case dw_val_class_str
:
4906 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4907 a
->dw_attr_val
.v
.val_str
->refcount
--;
4910 case dw_val_class_lbl_id
:
4911 case dw_val_class_lbl_offset
:
4912 free (a
->dw_attr_val
.v
.val_lbl_id
);
4915 case dw_val_class_float
:
4916 free (a
->dw_attr_val
.v
.val_float
.array
);
4926 /* Remove the specified attribute if present. */
4929 remove_AT (die
, attr_kind
)
4931 enum dwarf_attribute attr_kind
;
4934 dw_attr_ref removed
= NULL
;
4938 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4939 if ((*p
)->dw_attr
== attr_kind
)
4942 *p
= (*p
)->dw_attr_next
;
4951 /* Free up the memory used by DIE. */
4957 remove_children (die
);
4961 /* Discard the children of this DIE. */
4964 remove_children (die
)
4967 dw_die_ref child_die
= die
->die_child
;
4969 die
->die_child
= NULL
;
4971 while (child_die
!= NULL
)
4973 dw_die_ref tmp_die
= child_die
;
4976 child_die
= child_die
->die_sib
;
4978 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
4980 dw_attr_ref tmp_a
= a
;
4982 a
= a
->dw_attr_next
;
4990 /* Add a child DIE below its parent. We build the lists up in reverse
4991 addition order, and correct that in reverse_all_dies. */
4994 add_child_die (die
, child_die
)
4996 dw_die_ref child_die
;
4998 if (die
!= NULL
&& child_die
!= NULL
)
5000 if (die
== child_die
)
5003 child_die
->die_parent
= die
;
5004 child_die
->die_sib
= die
->die_child
;
5005 die
->die_child
= child_die
;
5009 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5010 is the specification, to the front of PARENT's list of children. */
5013 splice_child_die (parent
, child
)
5014 dw_die_ref parent
, child
;
5018 /* We want the declaration DIE from inside the class, not the
5019 specification DIE at toplevel. */
5020 if (child
->die_parent
!= parent
)
5022 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5028 if (child
->die_parent
!= parent
5029 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5032 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5035 *p
= child
->die_sib
;
5039 child
->die_sib
= parent
->die_child
;
5040 parent
->die_child
= child
;
5043 /* Return a pointer to a newly created DIE node. */
5045 static inline dw_die_ref
5046 new_die (tag_value
, parent_die
, t
)
5047 enum dwarf_tag tag_value
;
5048 dw_die_ref parent_die
;
5051 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5053 die
->die_tag
= tag_value
;
5055 if (parent_die
!= NULL
)
5056 add_child_die (parent_die
, die
);
5059 limbo_die_node
*limbo_node
;
5061 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5062 limbo_node
->die
= die
;
5063 limbo_node
->created_for
= t
;
5064 limbo_node
->next
= limbo_die_list
;
5065 limbo_die_list
= limbo_node
;
5071 /* Return the DIE associated with the given type specifier. */
5073 static inline dw_die_ref
5074 lookup_type_die (type
)
5077 return TYPE_SYMTAB_DIE (type
);
5080 /* Equate a DIE to a given type specifier. */
5083 equate_type_number_to_die (type
, type_die
)
5085 dw_die_ref type_die
;
5087 TYPE_SYMTAB_DIE (type
) = type_die
;
5090 /* Return the DIE associated with a given declaration. */
5092 static inline dw_die_ref
5093 lookup_decl_die (decl
)
5096 unsigned decl_id
= DECL_UID (decl
);
5098 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5101 /* Equate a DIE to a particular declaration. */
5104 equate_decl_number_to_die (decl
, decl_die
)
5106 dw_die_ref decl_die
;
5108 unsigned int decl_id
= DECL_UID (decl
);
5109 unsigned int num_allocated
;
5111 if (decl_id
>= decl_die_table_allocated
)
5114 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5115 / DECL_DIE_TABLE_INCREMENT
)
5116 * DECL_DIE_TABLE_INCREMENT
;
5119 = (dw_die_ref
*) xrealloc (decl_die_table
,
5120 sizeof (dw_die_ref
) * num_allocated
);
5122 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5123 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5124 decl_die_table_allocated
= num_allocated
;
5127 if (decl_id
>= decl_die_table_in_use
)
5128 decl_die_table_in_use
= (decl_id
+ 1);
5130 decl_die_table
[decl_id
] = decl_die
;
5133 /* Keep track of the number of spaces used to indent the
5134 output of the debugging routines that print the structure of
5135 the DIE internal representation. */
5136 static int print_indent
;
5138 /* Indent the line the number of spaces given by print_indent. */
5141 print_spaces (outfile
)
5144 fprintf (outfile
, "%*s", print_indent
, "");
5147 /* Print the information associated with a given DIE, and its children.
5148 This routine is a debugging aid only. */
5151 print_die (die
, outfile
)
5158 print_spaces (outfile
);
5159 fprintf (outfile
, "DIE %4lu: %s\n",
5160 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5161 print_spaces (outfile
);
5162 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5163 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5165 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5167 print_spaces (outfile
);
5168 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5170 switch (AT_class (a
))
5172 case dw_val_class_addr
:
5173 fprintf (outfile
, "address");
5175 case dw_val_class_offset
:
5176 fprintf (outfile
, "offset");
5178 case dw_val_class_loc
:
5179 fprintf (outfile
, "location descriptor");
5181 case dw_val_class_loc_list
:
5182 fprintf (outfile
, "location list -> label:%s",
5183 AT_loc_list (a
)->ll_symbol
);
5185 case dw_val_class_range_list
:
5186 fprintf (outfile
, "range list");
5188 case dw_val_class_const
:
5189 fprintf (outfile
, "%ld", AT_int (a
));
5191 case dw_val_class_unsigned_const
:
5192 fprintf (outfile
, "%lu", AT_unsigned (a
));
5194 case dw_val_class_long_long
:
5195 fprintf (outfile
, "constant (%lu,%lu)",
5196 a
->dw_attr_val
.v
.val_long_long
.hi
,
5197 a
->dw_attr_val
.v
.val_long_long
.low
);
5199 case dw_val_class_float
:
5200 fprintf (outfile
, "floating-point constant");
5202 case dw_val_class_flag
:
5203 fprintf (outfile
, "%u", AT_flag (a
));
5205 case dw_val_class_die_ref
:
5206 if (AT_ref (a
) != NULL
)
5208 if (AT_ref (a
)->die_symbol
)
5209 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5211 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5214 fprintf (outfile
, "die -> <null>");
5216 case dw_val_class_lbl_id
:
5217 case dw_val_class_lbl_offset
:
5218 fprintf (outfile
, "label: %s", AT_lbl (a
));
5220 case dw_val_class_str
:
5221 if (AT_string (a
) != NULL
)
5222 fprintf (outfile
, "\"%s\"", AT_string (a
));
5224 fprintf (outfile
, "<null>");
5230 fprintf (outfile
, "\n");
5233 if (die
->die_child
!= NULL
)
5236 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5237 print_die (c
, outfile
);
5241 if (print_indent
== 0)
5242 fprintf (outfile
, "\n");
5245 /* Print the contents of the source code line number correspondence table.
5246 This routine is a debugging aid only. */
5249 print_dwarf_line_table (outfile
)
5253 dw_line_info_ref line_info
;
5255 fprintf (outfile
, "\n\nDWARF source line information\n");
5256 for (i
= 1; i
< line_info_table_in_use
; i
++)
5258 line_info
= &line_info_table
[i
];
5259 fprintf (outfile
, "%5d: ", i
);
5260 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5261 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5262 fprintf (outfile
, "\n");
5265 fprintf (outfile
, "\n\n");
5268 /* Print the information collected for a given DIE. */
5271 debug_dwarf_die (die
)
5274 print_die (die
, stderr
);
5277 /* Print all DWARF information collected for the compilation unit.
5278 This routine is a debugging aid only. */
5284 print_die (comp_unit_die
, stderr
);
5285 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5286 print_dwarf_line_table (stderr
);
5289 /* We build up the lists of children and attributes by pushing new ones
5290 onto the beginning of the list. Reverse the lists for DIE so that
5291 they are in order of addition. */
5294 reverse_die_lists (die
)
5297 dw_die_ref c
, cp
, cn
;
5298 dw_attr_ref a
, ap
, an
;
5300 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5302 an
= a
->dw_attr_next
;
5303 a
->dw_attr_next
= ap
;
5309 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5316 die
->die_child
= cp
;
5319 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5320 reverse all dies in add_sibling_attributes, which runs through all the dies,
5321 it would reverse all the dies. Now, however, since we don't call
5322 reverse_die_lists in add_sibling_attributes, we need a routine to
5323 recursively reverse all the dies. This is that routine. */
5326 reverse_all_dies (die
)
5331 reverse_die_lists (die
);
5333 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5334 reverse_all_dies (c
);
5337 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5338 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5339 DIE that marks the start of the DIEs for this include file. */
5342 push_new_compile_unit (old_unit
, bincl_die
)
5343 dw_die_ref old_unit
, bincl_die
;
5345 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5346 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5348 new_unit
->die_sib
= old_unit
;
5352 /* Close an include-file CU and reopen the enclosing one. */
5355 pop_compile_unit (old_unit
)
5356 dw_die_ref old_unit
;
5358 dw_die_ref new_unit
= old_unit
->die_sib
;
5360 old_unit
->die_sib
= NULL
;
5364 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5365 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5367 /* Calculate the checksum of a location expression. */
5370 loc_checksum (loc
, ctx
)
5371 dw_loc_descr_ref loc
;
5372 struct md5_ctx
*ctx
;
5374 CHECKSUM (loc
->dw_loc_opc
);
5375 CHECKSUM (loc
->dw_loc_oprnd1
);
5376 CHECKSUM (loc
->dw_loc_oprnd2
);
5379 /* Calculate the checksum of an attribute. */
5382 attr_checksum (at
, ctx
)
5384 struct md5_ctx
*ctx
;
5386 dw_loc_descr_ref loc
;
5389 CHECKSUM (at
->dw_attr
);
5391 /* We don't care about differences in file numbering. */
5392 if (at
->dw_attr
== DW_AT_decl_file
5393 /* Or that this was compiled with a different compiler snapshot; if
5394 the output is the same, that's what matters. */
5395 || at
->dw_attr
== DW_AT_producer
)
5398 switch (AT_class (at
))
5400 case dw_val_class_const
:
5401 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5403 case dw_val_class_unsigned_const
:
5404 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5406 case dw_val_class_long_long
:
5407 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5409 case dw_val_class_float
:
5410 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5412 case dw_val_class_flag
:
5413 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5415 case dw_val_class_str
:
5416 CHECKSUM_STRING (AT_string (at
));
5419 case dw_val_class_addr
:
5421 switch (GET_CODE (r
))
5424 CHECKSUM_STRING (XSTR (r
, 0));
5432 case dw_val_class_offset
:
5433 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5436 case dw_val_class_loc
:
5437 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5438 loc_checksum (loc
, ctx
);
5441 case dw_val_class_die_ref
:
5442 if (AT_ref (at
)->die_offset
)
5443 CHECKSUM (AT_ref (at
)->die_offset
);
5444 /* FIXME else use target die name or something. */
5446 case dw_val_class_fde_ref
:
5447 case dw_val_class_lbl_id
:
5448 case dw_val_class_lbl_offset
:
5456 /* Calculate the checksum of a DIE. */
5459 die_checksum (die
, ctx
)
5461 struct md5_ctx
*ctx
;
5466 CHECKSUM (die
->die_tag
);
5468 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5469 attr_checksum (a
, ctx
);
5471 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5472 die_checksum (c
, ctx
);
5476 #undef CHECKSUM_STRING
5478 /* The prefix to attach to symbols on DIEs in the current comdat debug
5480 static char *comdat_symbol_id
;
5482 /* The index of the current symbol within the current comdat CU. */
5483 static unsigned int comdat_symbol_number
;
5485 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5486 children, and set comdat_symbol_id accordingly. */
5489 compute_section_prefix (unit_die
)
5490 dw_die_ref unit_die
;
5492 const char *base
= lbasename (get_AT_string (unit_die
, DW_AT_name
));
5493 char *name
= (char *) alloca (strlen (base
) + 64);
5496 unsigned char checksum
[16];
5499 /* Compute the checksum of the DIE, then append part of it as hex digits to
5500 the name filename of the unit. */
5502 md5_init_ctx (&ctx
);
5503 die_checksum (unit_die
, &ctx
);
5504 md5_finish_ctx (&ctx
, checksum
);
5506 sprintf (name
, "%s.", base
);
5507 clean_symbol_name (name
);
5509 p
= name
+ strlen (name
);
5510 for (i
= 0; i
< 4; i
++)
5512 sprintf (p
, "%.2x", checksum
[i
]);
5516 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5517 comdat_symbol_number
= 0;
5520 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5526 switch (die
->die_tag
)
5528 case DW_TAG_array_type
:
5529 case DW_TAG_class_type
:
5530 case DW_TAG_enumeration_type
:
5531 case DW_TAG_pointer_type
:
5532 case DW_TAG_reference_type
:
5533 case DW_TAG_string_type
:
5534 case DW_TAG_structure_type
:
5535 case DW_TAG_subroutine_type
:
5536 case DW_TAG_union_type
:
5537 case DW_TAG_ptr_to_member_type
:
5538 case DW_TAG_set_type
:
5539 case DW_TAG_subrange_type
:
5540 case DW_TAG_base_type
:
5541 case DW_TAG_const_type
:
5542 case DW_TAG_file_type
:
5543 case DW_TAG_packed_type
:
5544 case DW_TAG_volatile_type
:
5551 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5552 Basically, we want to choose the bits that are likely to be shared between
5553 compilations (types) and leave out the bits that are specific to individual
5554 compilations (functions). */
5560 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5561 we do for stabs. The advantage is a greater likelihood of sharing between
5562 objects that don't include headers in the same order (and therefore would
5563 put the base types in a different comdat). jason 8/28/00 */
5565 if (c
->die_tag
== DW_TAG_base_type
)
5568 if (c
->die_tag
== DW_TAG_pointer_type
5569 || c
->die_tag
== DW_TAG_reference_type
5570 || c
->die_tag
== DW_TAG_const_type
5571 || c
->die_tag
== DW_TAG_volatile_type
)
5573 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5575 return t
? is_comdat_die (t
) : 0;
5578 return is_type_die (c
);
5581 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5582 compilation unit. */
5588 return (is_type_die (c
)
5589 || (get_AT (c
, DW_AT_declaration
)
5590 && !get_AT (c
, DW_AT_specification
)));
5594 gen_internal_sym (prefix
)
5598 static int label_num
;
5600 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5601 return xstrdup (buf
);
5604 /* Assign symbols to all worthy DIEs under DIE. */
5607 assign_symbol_names (die
)
5612 if (is_symbol_die (die
))
5614 if (comdat_symbol_id
)
5616 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5618 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5619 comdat_symbol_id
, comdat_symbol_number
++);
5620 die
->die_symbol
= xstrdup (p
);
5623 die
->die_symbol
= gen_internal_sym ("LDIE");
5626 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5627 assign_symbol_names (c
);
5630 /* Traverse the DIE (which is always comp_unit_die), and set up
5631 additional compilation units for each of the include files we see
5632 bracketed by BINCL/EINCL. */
5635 break_out_includes (die
)
5639 dw_die_ref unit
= NULL
;
5640 limbo_die_node
*node
;
5642 for (ptr
= &(die
->die_child
); *ptr
;)
5644 dw_die_ref c
= *ptr
;
5646 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5647 || (unit
&& is_comdat_die (c
)))
5649 /* This DIE is for a secondary CU; remove it from the main one. */
5652 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5654 unit
= push_new_compile_unit (unit
, c
);
5657 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5659 unit
= pop_compile_unit (unit
);
5663 add_child_die (unit
, c
);
5667 /* Leave this DIE in the main CU. */
5668 ptr
= &(c
->die_sib
);
5674 /* We can only use this in debugging, since the frontend doesn't check
5675 to make sure that we leave every include file we enter. */
5680 assign_symbol_names (die
);
5681 for (node
= limbo_die_list
; node
; node
= node
->next
)
5683 compute_section_prefix (node
->die
);
5684 assign_symbol_names (node
->die
);
5688 /* Traverse the DIE and add a sibling attribute if it may have the
5689 effect of speeding up access to siblings. To save some space,
5690 avoid generating sibling attributes for DIE's without children. */
5693 add_sibling_attributes (die
)
5698 if (die
->die_tag
!= DW_TAG_compile_unit
5699 && die
->die_sib
&& die
->die_child
!= NULL
)
5700 /* Add the sibling link to the front of the attribute list. */
5701 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5703 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5704 add_sibling_attributes (c
);
5707 /* Output all location lists for the DIE and its children. */
5710 output_location_lists (die
)
5716 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5717 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5718 output_loc_list (AT_loc_list (d_attr
));
5720 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5721 output_location_lists (c
);
5725 /* The format of each DIE (and its attribute value pairs) is encoded in an
5726 abbreviation table. This routine builds the abbreviation table and assigns
5727 a unique abbreviation id for each abbreviation entry. The children of each
5728 die are visited recursively. */
5731 build_abbrev_table (die
)
5734 unsigned long abbrev_id
;
5735 unsigned int n_alloc
;
5737 dw_attr_ref d_attr
, a_attr
;
5739 /* Scan the DIE references, and mark as external any that refer to
5740 DIEs from other CUs (i.e. those which are not marked). */
5741 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5742 if (AT_class (d_attr
) == dw_val_class_die_ref
5743 && AT_ref (d_attr
)->die_mark
== 0)
5745 if (AT_ref (d_attr
)->die_symbol
== 0)
5748 set_AT_ref_external (d_attr
, 1);
5751 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5753 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5755 if (abbrev
->die_tag
== die
->die_tag
)
5757 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
5759 a_attr
= abbrev
->die_attr
;
5760 d_attr
= die
->die_attr
;
5762 while (a_attr
!= NULL
&& d_attr
!= NULL
)
5764 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
5765 || (value_format (a_attr
) != value_format (d_attr
)))
5768 a_attr
= a_attr
->dw_attr_next
;
5769 d_attr
= d_attr
->dw_attr_next
;
5772 if (a_attr
== NULL
&& d_attr
== NULL
)
5778 if (abbrev_id
>= abbrev_die_table_in_use
)
5780 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
5782 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
5784 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
5785 sizeof (dw_die_ref
) * n_alloc
);
5787 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
5788 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
5789 abbrev_die_table_allocated
= n_alloc
;
5792 ++abbrev_die_table_in_use
;
5793 abbrev_die_table
[abbrev_id
] = die
;
5796 die
->die_abbrev
= abbrev_id
;
5797 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5798 build_abbrev_table (c
);
5801 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5804 constant_size (value
)
5805 long unsigned value
;
5812 log
= floor_log2 (value
);
5815 log
= 1 << (floor_log2 (log
) + 1);
5820 /* Return the size of a DIE as it is represented in the
5821 .debug_info section. */
5823 static unsigned long
5827 unsigned long size
= 0;
5830 size
+= size_of_uleb128 (die
->die_abbrev
);
5831 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5833 switch (AT_class (a
))
5835 case dw_val_class_addr
:
5836 size
+= DWARF2_ADDR_SIZE
;
5838 case dw_val_class_offset
:
5839 size
+= DWARF_OFFSET_SIZE
;
5841 case dw_val_class_loc
:
5843 unsigned long lsize
= size_of_locs (AT_loc (a
));
5846 size
+= constant_size (lsize
);
5850 case dw_val_class_loc_list
:
5851 size
+= DWARF_OFFSET_SIZE
;
5853 case dw_val_class_range_list
:
5854 size
+= DWARF_OFFSET_SIZE
;
5856 case dw_val_class_const
:
5857 size
+= size_of_sleb128 (AT_int (a
));
5859 case dw_val_class_unsigned_const
:
5860 size
+= constant_size (AT_unsigned (a
));
5862 case dw_val_class_long_long
:
5863 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
5865 case dw_val_class_float
:
5866 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
5868 case dw_val_class_flag
:
5871 case dw_val_class_die_ref
:
5872 size
+= DWARF_OFFSET_SIZE
;
5874 case dw_val_class_fde_ref
:
5875 size
+= DWARF_OFFSET_SIZE
;
5877 case dw_val_class_lbl_id
:
5878 size
+= DWARF2_ADDR_SIZE
;
5880 case dw_val_class_lbl_offset
:
5881 size
+= DWARF_OFFSET_SIZE
;
5883 case dw_val_class_str
:
5884 if (AT_string_form (a
) == DW_FORM_strp
)
5885 size
+= DWARF_OFFSET_SIZE
;
5887 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
5897 /* Size the debugging information associated with a given DIE. Visits the
5898 DIE's children recursively. Updates the global variable next_die_offset, on
5899 each time through. Uses the current value of next_die_offset to update the
5900 die_offset field in each DIE. */
5903 calc_die_sizes (die
)
5908 die
->die_offset
= next_die_offset
;
5909 next_die_offset
+= size_of_die (die
);
5911 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5914 if (die
->die_child
!= NULL
)
5915 /* Count the null byte used to terminate sibling lists. */
5916 next_die_offset
+= 1;
5919 /* Set the marks for a die and its children. We do this so
5920 that we know whether or not a reference needs to use FORM_ref_addr; only
5921 DIEs in the same CU will be marked. We used to clear out the offset
5922 and use that as the flag, but ran into ordering problems. */
5931 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5935 /* Clear the marks for a die and its children. */
5944 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5948 /* Return the size of the .debug_pubnames table generated for the
5949 compilation unit. */
5951 static unsigned long
5957 size
= DWARF_PUBNAMES_HEADER_SIZE
;
5958 for (i
= 0; i
< pubname_table_in_use
; i
++)
5960 pubname_ref p
= &pubname_table
[i
];
5961 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
5964 size
+= DWARF_OFFSET_SIZE
;
5968 /* Return the size of the information in the .debug_aranges section. */
5970 static unsigned long
5975 size
= DWARF_ARANGES_HEADER_SIZE
;
5977 /* Count the address/length pair for this compilation unit. */
5978 size
+= 2 * DWARF2_ADDR_SIZE
;
5979 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
5981 /* Count the two zero words used to terminated the address range table. */
5982 size
+= 2 * DWARF2_ADDR_SIZE
;
5986 /* Select the encoding of an attribute value. */
5988 static enum dwarf_form
5992 switch (a
->dw_attr_val
.val_class
)
5994 case dw_val_class_addr
:
5995 return DW_FORM_addr
;
5996 case dw_val_class_range_list
:
5997 case dw_val_class_offset
:
5998 if (DWARF_OFFSET_SIZE
== 4)
5999 return DW_FORM_data4
;
6000 if (DWARF_OFFSET_SIZE
== 8)
6001 return DW_FORM_data8
;
6003 case dw_val_class_loc_list
:
6004 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6005 .debug_loc section */
6006 return DW_FORM_data4
;
6007 case dw_val_class_loc
:
6008 switch (constant_size (size_of_locs (AT_loc (a
))))
6011 return DW_FORM_block1
;
6013 return DW_FORM_block2
;
6017 case dw_val_class_const
:
6018 return DW_FORM_sdata
;
6019 case dw_val_class_unsigned_const
:
6020 switch (constant_size (AT_unsigned (a
)))
6023 return DW_FORM_data1
;
6025 return DW_FORM_data2
;
6027 return DW_FORM_data4
;
6029 return DW_FORM_data8
;
6033 case dw_val_class_long_long
:
6034 return DW_FORM_block1
;
6035 case dw_val_class_float
:
6036 return DW_FORM_block1
;
6037 case dw_val_class_flag
:
6038 return DW_FORM_flag
;
6039 case dw_val_class_die_ref
:
6040 if (AT_ref_external (a
))
6041 return DW_FORM_ref_addr
;
6044 case dw_val_class_fde_ref
:
6045 return DW_FORM_data
;
6046 case dw_val_class_lbl_id
:
6047 return DW_FORM_addr
;
6048 case dw_val_class_lbl_offset
:
6049 return DW_FORM_data
;
6050 case dw_val_class_str
:
6051 return AT_string_form (a
);
6058 /* Output the encoding of an attribute value. */
6061 output_value_format (a
)
6064 enum dwarf_form form
= value_format (a
);
6066 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6069 /* Output the .debug_abbrev section which defines the DIE abbreviation
6073 output_abbrev_section ()
6075 unsigned long abbrev_id
;
6079 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6081 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6083 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6084 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6085 dwarf_tag_name (abbrev
->die_tag
));
6087 if (abbrev
->die_child
!= NULL
)
6088 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6090 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6092 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6093 a_attr
= a_attr
->dw_attr_next
)
6095 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6096 dwarf_attr_name (a_attr
->dw_attr
));
6097 output_value_format (a_attr
);
6100 dw2_asm_output_data (1, 0, NULL
);
6101 dw2_asm_output_data (1, 0, NULL
);
6104 /* Terminate the table. */
6105 dw2_asm_output_data (1, 0, NULL
);
6108 /* Output a symbol we can use to refer to this DIE from another CU. */
6111 output_die_symbol (die
)
6114 char *sym
= die
->die_symbol
;
6119 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6120 /* We make these global, not weak; if the target doesn't support
6121 .linkonce, it doesn't support combining the sections, so debugging
6123 ASM_GLOBALIZE_LABEL (asm_out_file
, sym
);
6125 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6128 /* Return a new location list, given the begin and end range, and the
6129 expression. gensym tells us whether to generate a new internal symbol for
6130 this location list node, which is done for the head of the list only. */
6132 static inline dw_loc_list_ref
6133 new_loc_list (expr
, begin
, end
, section
, gensym
)
6134 dw_loc_descr_ref expr
;
6137 const char *section
;
6140 dw_loc_list_ref retlist
6141 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6143 retlist
->begin
= begin
;
6145 retlist
->expr
= expr
;
6146 retlist
->section
= section
;
6148 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6153 /* Add a location description expression to a location list */
6156 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6157 dw_loc_list_ref
*list_head
;
6158 dw_loc_descr_ref descr
;
6161 const char *section
;
6165 /* Find the end of the chain. */
6166 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6169 /* Add a new location list node to the list */
6170 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6173 /* Output the location list given to us */
6176 output_loc_list (list_head
)
6177 dw_loc_list_ref list_head
;
6179 dw_loc_list_ref curr
= list_head
;
6181 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6183 /* ??? This shouldn't be needed now that we've forced the
6184 compilation unit base address to zero when there is code
6185 in more than one section. */
6186 if (strcmp (curr
->section
, ".text") == 0)
6188 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6189 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6190 "Location list base address specifier fake entry");
6191 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6192 "Location list base address specifier base");
6195 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6199 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6200 "Location list begin address (%s)",
6201 list_head
->ll_symbol
);
6202 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6203 "Location list end address (%s)",
6204 list_head
->ll_symbol
);
6205 size
= size_of_locs (curr
->expr
);
6207 /* Output the block length for this list of location operations. */
6210 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6212 output_loc_sequence (curr
->expr
);
6215 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6216 "Location list terminator begin (%s)",
6217 list_head
->ll_symbol
);
6218 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6219 "Location list terminator end (%s)",
6220 list_head
->ll_symbol
);
6223 /* Output the DIE and its attributes. Called recursively to generate
6224 the definitions of each child DIE. */
6234 /* If someone in another CU might refer to us, set up a symbol for
6235 them to point to. */
6236 if (die
->die_symbol
)
6237 output_die_symbol (die
);
6239 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6240 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6242 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6244 const char *name
= dwarf_attr_name (a
->dw_attr
);
6246 switch (AT_class (a
))
6248 case dw_val_class_addr
:
6249 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6252 case dw_val_class_offset
:
6253 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6257 case dw_val_class_range_list
:
6259 char *p
= strchr (ranges_section_label
, '\0');
6261 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6262 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6268 case dw_val_class_loc
:
6269 size
= size_of_locs (AT_loc (a
));
6271 /* Output the block length for this list of location operations. */
6272 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6274 output_loc_sequence (AT_loc (a
));
6277 case dw_val_class_const
:
6278 /* ??? It would be slightly more efficient to use a scheme like is
6279 used for unsigned constants below, but gdb 4.x does not sign
6280 extend. Gdb 5.x does sign extend. */
6281 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6284 case dw_val_class_unsigned_const
:
6285 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6286 AT_unsigned (a
), "%s", name
);
6289 case dw_val_class_long_long
:
6291 unsigned HOST_WIDE_INT first
, second
;
6293 dw2_asm_output_data (1,
6294 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6297 if (WORDS_BIG_ENDIAN
)
6299 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6300 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6304 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6305 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6308 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6309 first
, "long long constant");
6310 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6315 case dw_val_class_float
:
6319 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6322 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6323 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6324 "fp constant word %u", i
);
6328 case dw_val_class_flag
:
6329 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6332 case dw_val_class_loc_list
:
6334 char *sym
= AT_loc_list (a
)->ll_symbol
;
6338 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6339 loc_section_label
, "%s", name
);
6343 case dw_val_class_die_ref
:
6344 if (AT_ref_external (a
))
6346 char *sym
= AT_ref (a
)->die_symbol
;
6350 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6352 else if (AT_ref (a
)->die_offset
== 0)
6355 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6359 case dw_val_class_fde_ref
:
6363 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6364 a
->dw_attr_val
.v
.val_fde_index
* 2);
6365 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6369 case dw_val_class_lbl_id
:
6370 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6373 case dw_val_class_lbl_offset
:
6374 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6377 case dw_val_class_str
:
6378 if (AT_string_form (a
) == DW_FORM_strp
)
6379 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6380 a
->dw_attr_val
.v
.val_str
->label
,
6381 "%s: \"%s\"", name
, AT_string (a
));
6383 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6391 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6394 /* Add null byte to terminate sibling list. */
6395 if (die
->die_child
!= NULL
)
6396 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6400 /* Output the compilation unit that appears at the beginning of the
6401 .debug_info section, and precedes the DIE descriptions. */
6404 output_compilation_unit_header ()
6406 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6407 "Length of Compilation Unit Info");
6408 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6409 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6410 "Offset Into Abbrev. Section");
6411 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6414 /* Output the compilation unit DIE and its children. */
6417 output_comp_unit (die
)
6420 const char *secname
;
6422 /* Even if there are no children of this DIE, we must output the information
6423 about the compilation unit. Otherwise, on an empty translation unit, we
6424 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6425 will then complain when examining the file. First mark all the DIEs in
6426 this CU so we know which get local refs. */
6429 build_abbrev_table (die
);
6431 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6432 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6433 calc_die_sizes (die
);
6435 if (die
->die_symbol
)
6437 char *tmp
= (char *) alloca (strlen (die
->die_symbol
) + 24);
6439 sprintf (tmp
, ".gnu.linkonce.wi.%s", die
->die_symbol
);
6441 die
->die_symbol
= NULL
;
6444 secname
= (const char *) DEBUG_INFO_SECTION
;
6446 /* Output debugging information. */
6447 named_section_flags (secname
, SECTION_DEBUG
);
6448 output_compilation_unit_header ();
6451 /* Leave the marks on the main CU, so we can check them in
6453 if (die
->die_symbol
)
6457 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6458 output of lang_hooks.decl_printable_name for C++ looks like
6459 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6462 dwarf2_name (decl
, scope
)
6466 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6469 /* Add a new entry to .debug_pubnames if appropriate. */
6472 add_pubname (decl
, die
)
6478 if (! TREE_PUBLIC (decl
))
6481 if (pubname_table_in_use
== pubname_table_allocated
)
6483 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6485 = (pubname_ref
) xrealloc (pubname_table
,
6486 (pubname_table_allocated
6487 * sizeof (pubname_entry
)));
6490 p
= &pubname_table
[pubname_table_in_use
++];
6492 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6495 /* Output the public names table used to speed up access to externally
6496 visible names. For now, only generate entries for externally
6497 visible procedures. */
6503 unsigned long pubnames_length
= size_of_pubnames ();
6505 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6506 "Length of Public Names Info");
6507 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6508 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6509 "Offset of Compilation Unit Info");
6510 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6511 "Compilation Unit Length");
6513 for (i
= 0; i
< pubname_table_in_use
; i
++)
6515 pubname_ref pub
= &pubname_table
[i
];
6517 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6518 if (pub
->die
->die_mark
== 0)
6521 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6524 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6527 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6530 /* Add a new entry to .debug_aranges if appropriate. */
6533 add_arange (decl
, die
)
6537 if (! DECL_SECTION_NAME (decl
))
6540 if (arange_table_in_use
== arange_table_allocated
)
6542 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6543 arange_table
= (dw_die_ref
*)
6544 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6547 arange_table
[arange_table_in_use
++] = die
;
6550 /* Output the information that goes into the .debug_aranges table.
6551 Namely, define the beginning and ending address range of the
6552 text section generated for this compilation unit. */
6558 unsigned long aranges_length
= size_of_aranges ();
6560 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6561 "Length of Address Ranges Info");
6562 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6563 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6564 "Offset of Compilation Unit Info");
6565 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6566 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6568 /* We need to align to twice the pointer size here. */
6569 if (DWARF_ARANGES_PAD_SIZE
)
6571 /* Pad using a 2 byte words so that padding is correct for any
6573 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6574 2 * DWARF2_ADDR_SIZE
);
6575 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6576 dw2_asm_output_data (2, 0, NULL
);
6579 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6580 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6581 text_section_label
, "Length");
6583 for (i
= 0; i
< arange_table_in_use
; i
++)
6585 dw_die_ref die
= arange_table
[i
];
6587 /* We shouldn't see aranges for DIEs outside of the main CU. */
6588 if (die
->die_mark
== 0)
6591 if (die
->die_tag
== DW_TAG_subprogram
)
6593 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6595 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6596 get_AT_low_pc (die
), "Length");
6600 /* A static variable; extract the symbol from DW_AT_location.
6601 Note that this code isn't currently hit, as we only emit
6602 aranges for functions (jason 9/23/99). */
6603 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6604 dw_loc_descr_ref loc
;
6606 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6610 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6613 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6614 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6615 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6616 get_AT_unsigned (die
, DW_AT_byte_size
),
6621 /* Output the terminator words. */
6622 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6623 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6626 /* Add a new entry to .debug_ranges. Return the offset at which it
6633 unsigned int in_use
= ranges_table_in_use
;
6635 if (in_use
== ranges_table_allocated
)
6637 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6638 ranges_table
= (dw_ranges_ref
)
6639 xrealloc (ranges_table
, (ranges_table_allocated
6640 * sizeof (struct dw_ranges_struct
)));
6643 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6644 ranges_table_in_use
= in_use
+ 1;
6646 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6653 static const char *const start_fmt
= "Offset 0x%x";
6654 const char *fmt
= start_fmt
;
6656 for (i
= 0; i
< ranges_table_in_use
; i
++)
6658 int block_num
= ranges_table
[i
].block_num
;
6662 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6663 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6665 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6666 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6668 /* If all code is in the text section, then the compilation
6669 unit base address defaults to DW_AT_low_pc, which is the
6670 base of the text section. */
6671 if (separate_line_info_table_in_use
== 0)
6673 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6675 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6676 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6677 text_section_label
, NULL
);
6680 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6681 compilation unit base address to zero, which allows us to
6682 use absolute addresses, and not worry about whether the
6683 target supports cross-section arithmetic. */
6686 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6687 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6688 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6695 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6696 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6702 /* Data structure containing information about input files. */
6705 char *path
; /* Complete file name. */
6706 char *fname
; /* File name part. */
6707 int length
; /* Length of entire string. */
6708 int file_idx
; /* Index in input file table. */
6709 int dir_idx
; /* Index in directory table. */
6712 /* Data structure containing information about directories with source
6716 char *path
; /* Path including directory name. */
6717 int length
; /* Path length. */
6718 int prefix
; /* Index of directory entry which is a prefix. */
6719 int count
; /* Number of files in this directory. */
6720 int dir_idx
; /* Index of directory used as base. */
6721 int used
; /* Used in the end? */
6724 /* Callback function for file_info comparison. We sort by looking at
6725 the directories in the path. */
6728 file_info_cmp (p1
, p2
)
6732 const struct file_info
*s1
= p1
;
6733 const struct file_info
*s2
= p2
;
6737 /* Take care of file names without directories. We need to make sure that
6738 we return consistent values to qsort since some will get confused if
6739 we return the same value when identical operands are passed in opposite
6740 orders. So if neither has a directory, return 0 and otherwise return
6741 1 or -1 depending on which one has the directory. */
6742 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
6743 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
6745 cp1
= (unsigned char *) s1
->path
;
6746 cp2
= (unsigned char *) s2
->path
;
6752 /* Reached the end of the first path? If so, handle like above. */
6753 if ((cp1
== (unsigned char *) s1
->fname
)
6754 || (cp2
== (unsigned char *) s2
->fname
))
6755 return ((cp2
== (unsigned char *) s2
->fname
)
6756 - (cp1
== (unsigned char *) s1
->fname
));
6758 /* Character of current path component the same? */
6759 else if (*cp1
!= *cp2
)
6764 /* Output the directory table and the file name table. We try to minimize
6765 the total amount of memory needed. A heuristic is used to avoid large
6766 slowdowns with many input files. */
6769 output_file_names ()
6771 struct file_info
*files
;
6772 struct dir_info
*dirs
;
6781 /* Allocate the various arrays we need. */
6782 files
= (struct file_info
*) alloca (file_table
.in_use
6783 * sizeof (struct file_info
));
6784 dirs
= (struct dir_info
*) alloca (file_table
.in_use
6785 * sizeof (struct dir_info
));
6787 /* Sort the file names. */
6788 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6792 /* Skip all leading "./". */
6793 f
= file_table
.table
[i
];
6794 while (f
[0] == '.' && f
[1] == '/')
6797 /* Create a new array entry. */
6799 files
[i
].length
= strlen (f
);
6800 files
[i
].file_idx
= i
;
6802 /* Search for the file name part. */
6803 f
= strrchr (f
, '/');
6804 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
6807 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
6809 /* Find all the different directories used. */
6810 dirs
[0].path
= files
[1].path
;
6811 dirs
[0].length
= files
[1].fname
- files
[1].path
;
6812 dirs
[0].prefix
= -1;
6814 dirs
[0].dir_idx
= 0;
6816 files
[1].dir_idx
= 0;
6819 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
6820 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
6821 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
6822 dirs
[ndirs
- 1].length
) == 0)
6824 /* Same directory as last entry. */
6825 files
[i
].dir_idx
= ndirs
- 1;
6826 ++dirs
[ndirs
- 1].count
;
6832 /* This is a new directory. */
6833 dirs
[ndirs
].path
= files
[i
].path
;
6834 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
6835 dirs
[ndirs
].count
= 1;
6836 dirs
[ndirs
].dir_idx
= ndirs
;
6837 dirs
[ndirs
].used
= 0;
6838 files
[i
].dir_idx
= ndirs
;
6840 /* Search for a prefix. */
6841 dirs
[ndirs
].prefix
= -1;
6842 for (j
= 0; j
< ndirs
; j
++)
6843 if (dirs
[j
].length
< dirs
[ndirs
].length
6844 && dirs
[j
].length
> 1
6845 && (dirs
[ndirs
].prefix
== -1
6846 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
6847 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
6848 dirs
[ndirs
].prefix
= j
;
6853 /* Now to the actual work. We have to find a subset of the directories which
6854 allow expressing the file name using references to the directory table
6855 with the least amount of characters. We do not do an exhaustive search
6856 where we would have to check out every combination of every single
6857 possible prefix. Instead we use a heuristic which provides nearly optimal
6858 results in most cases and never is much off. */
6859 saved
= (int *) alloca (ndirs
* sizeof (int));
6860 savehere
= (int *) alloca (ndirs
* sizeof (int));
6862 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
6863 for (i
= 0; i
< ndirs
; i
++)
6868 /* We can always save some space for the current directory. But this
6869 does not mean it will be enough to justify adding the directory. */
6870 savehere
[i
] = dirs
[i
].length
;
6871 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
6873 for (j
= i
+ 1; j
< ndirs
; j
++)
6876 if (saved
[j
] < dirs
[i
].length
)
6878 /* Determine whether the dirs[i] path is a prefix of the
6883 while (k
!= -1 && k
!= i
)
6888 /* Yes it is. We can possibly safe some memory but
6889 writing the filenames in dirs[j] relative to
6891 savehere
[j
] = dirs
[i
].length
;
6892 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
6897 /* Check whether we can safe enough to justify adding the dirs[i]
6899 if (total
> dirs
[i
].length
+ 1)
6901 /* It's worthwhile adding. */
6902 for (j
= i
; j
< ndirs
; j
++)
6903 if (savehere
[j
] > 0)
6905 /* Remember how much we saved for this directory so far. */
6906 saved
[j
] = savehere
[j
];
6908 /* Remember the prefix directory. */
6909 dirs
[j
].dir_idx
= i
;
6914 /* We have to emit them in the order they appear in the file_table array
6915 since the index is used in the debug info generation. To do this
6916 efficiently we generate a back-mapping of the indices first. */
6917 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
6918 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6920 backmap
[files
[i
].file_idx
] = i
;
6922 /* Mark this directory as used. */
6923 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
6926 /* That was it. We are ready to emit the information. First emit the
6927 directory name table. We have to make sure the first actually emitted
6928 directory name has index one; zero is reserved for the current working
6929 directory. Make sure we do not confuse these indices with the one for the
6930 constructed table (even though most of the time they are identical). */
6932 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
6933 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
6934 if (dirs
[i
].used
!= 0)
6936 dirs
[i
].used
= idx
++;
6937 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
6938 "Directory Entry: 0x%x", dirs
[i
].used
);
6941 dw2_asm_output_data (1, 0, "End directory table");
6943 /* Correct the index for the current working directory entry if it
6945 if (idx_offset
== 0)
6948 /* Now write all the file names. */
6949 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6951 int file_idx
= backmap
[i
];
6952 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
6954 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
6955 "File Entry: 0x%x", i
);
6957 /* Include directory index. */
6958 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
6960 /* Modification time. */
6961 dw2_asm_output_data_uleb128 (0, NULL
);
6963 /* File length in bytes. */
6964 dw2_asm_output_data_uleb128 (0, NULL
);
6967 dw2_asm_output_data (1, 0, "End file name table");
6971 /* Output the source line number correspondence information. This
6972 information goes into the .debug_line section. */
6977 char l1
[20], l2
[20], p1
[20], p2
[20];
6978 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6979 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6982 unsigned long lt_index
;
6983 unsigned long current_line
;
6986 unsigned long current_file
;
6987 unsigned long function
;
6989 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
6990 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
6991 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
6992 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
6994 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
6995 "Length of Source Line Info");
6996 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
6998 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6999 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7000 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7002 /* Define the architecture-dependent minimum instruction length (in
7003 bytes). In this implementation of DWARF, this field is used for
7004 information purposes only. Since GCC generates assembly language,
7005 we have no a priori knowledge of how many instruction bytes are
7006 generated for each source line, and therefore can use only the
7007 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7008 commands. Accordingly, we fix this as `1', which is "correct
7009 enough" for all architectures, and don't let the target override. */
7010 dw2_asm_output_data (1, 1,
7011 "Minimum Instruction Length");
7013 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7014 "Default is_stmt_start flag");
7015 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7016 "Line Base Value (Special Opcodes)");
7017 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7018 "Line Range Value (Special Opcodes)");
7019 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7020 "Special Opcode Base");
7022 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7026 case DW_LNS_advance_pc
:
7027 case DW_LNS_advance_line
:
7028 case DW_LNS_set_file
:
7029 case DW_LNS_set_column
:
7030 case DW_LNS_fixed_advance_pc
:
7038 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7042 /* Write out the information about the files we use. */
7043 output_file_names ();
7044 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7046 /* We used to set the address register to the first location in the text
7047 section here, but that didn't accomplish anything since we already
7048 have a line note for the opening brace of the first function. */
7050 /* Generate the line number to PC correspondence table, encoded as
7051 a series of state machine operations. */
7054 strcpy (prev_line_label
, text_section_label
);
7055 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7057 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7060 /* Disable this optimization for now; GDB wants to see two line notes
7061 at the beginning of a function so it can find the end of the
7064 /* Don't emit anything for redundant notes. Just updating the
7065 address doesn't accomplish anything, because we already assume
7066 that anything after the last address is this line. */
7067 if (line_info
->dw_line_num
== current_line
7068 && line_info
->dw_file_num
== current_file
)
7072 /* Emit debug info for the address of the current line.
7074 Unfortunately, we have little choice here currently, and must always
7075 use the most general form. GCC does not know the address delta
7076 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7077 attributes which will give an upper bound on the address range. We
7078 could perhaps use length attributes to determine when it is safe to
7079 use DW_LNS_fixed_advance_pc. */
7081 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7084 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7085 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7086 "DW_LNS_fixed_advance_pc");
7087 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7091 /* This can handle any delta. This takes
7092 4+DWARF2_ADDR_SIZE bytes. */
7093 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7094 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7095 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7096 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7099 strcpy (prev_line_label
, line_label
);
7101 /* Emit debug info for the source file of the current line, if
7102 different from the previous line. */
7103 if (line_info
->dw_file_num
!= current_file
)
7105 current_file
= line_info
->dw_file_num
;
7106 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7107 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7108 file_table
.table
[current_file
]);
7111 /* Emit debug info for the current line number, choosing the encoding
7112 that uses the least amount of space. */
7113 if (line_info
->dw_line_num
!= current_line
)
7115 line_offset
= line_info
->dw_line_num
- current_line
;
7116 line_delta
= line_offset
- DWARF_LINE_BASE
;
7117 current_line
= line_info
->dw_line_num
;
7118 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7119 /* This can handle deltas from -10 to 234, using the current
7120 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7122 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7123 "line %lu", current_line
);
7126 /* This can handle any delta. This takes at least 4 bytes,
7127 depending on the value being encoded. */
7128 dw2_asm_output_data (1, DW_LNS_advance_line
,
7129 "advance to line %lu", current_line
);
7130 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7131 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7135 /* We still need to start a new row, so output a copy insn. */
7136 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7139 /* Emit debug info for the address of the end of the function. */
7142 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7143 "DW_LNS_fixed_advance_pc");
7144 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7148 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7149 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7150 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7151 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7154 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7155 dw2_asm_output_data_uleb128 (1, NULL
);
7156 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7161 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7163 dw_separate_line_info_ref line_info
7164 = &separate_line_info_table
[lt_index
];
7167 /* Don't emit anything for redundant notes. */
7168 if (line_info
->dw_line_num
== current_line
7169 && line_info
->dw_file_num
== current_file
7170 && line_info
->function
== function
)
7174 /* Emit debug info for the address of the current line. If this is
7175 a new function, or the first line of a function, then we need
7176 to handle it differently. */
7177 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7179 if (function
!= line_info
->function
)
7181 function
= line_info
->function
;
7183 /* Set the address register to the first line in the function */
7184 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7185 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7186 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7187 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7191 /* ??? See the DW_LNS_advance_pc comment above. */
7194 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7195 "DW_LNS_fixed_advance_pc");
7196 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7200 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7201 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7202 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7203 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7207 strcpy (prev_line_label
, line_label
);
7209 /* Emit debug info for the source file of the current line, if
7210 different from the previous line. */
7211 if (line_info
->dw_file_num
!= current_file
)
7213 current_file
= line_info
->dw_file_num
;
7214 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7215 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7216 file_table
.table
[current_file
]);
7219 /* Emit debug info for the current line number, choosing the encoding
7220 that uses the least amount of space. */
7221 if (line_info
->dw_line_num
!= current_line
)
7223 line_offset
= line_info
->dw_line_num
- current_line
;
7224 line_delta
= line_offset
- DWARF_LINE_BASE
;
7225 current_line
= line_info
->dw_line_num
;
7226 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7227 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7228 "line %lu", current_line
);
7231 dw2_asm_output_data (1, DW_LNS_advance_line
,
7232 "advance to line %lu", current_line
);
7233 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7234 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7238 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7246 /* If we're done with a function, end its sequence. */
7247 if (lt_index
== separate_line_info_table_in_use
7248 || separate_line_info_table
[lt_index
].function
!= function
)
7253 /* Emit debug info for the address of the end of the function. */
7254 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7257 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7258 "DW_LNS_fixed_advance_pc");
7259 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7263 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7264 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7265 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7266 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7269 /* Output the marker for the end of this sequence. */
7270 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7271 dw2_asm_output_data_uleb128 (1, NULL
);
7272 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7276 /* Output the marker for the end of the line number info. */
7277 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7280 /* Given a pointer to a tree node for some base type, return a pointer to
7281 a DIE that describes the given type.
7283 This routine must only be called for GCC type nodes that correspond to
7284 Dwarf base (fundamental) types. */
7287 base_type_die (type
)
7290 dw_die_ref base_type_result
;
7291 const char *type_name
;
7292 enum dwarf_type encoding
;
7293 tree name
= TYPE_NAME (type
);
7295 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7300 if (TREE_CODE (name
) == TYPE_DECL
)
7301 name
= DECL_NAME (name
);
7303 type_name
= IDENTIFIER_POINTER (name
);
7306 type_name
= "__unknown__";
7308 switch (TREE_CODE (type
))
7311 /* Carefully distinguish the C character types, without messing
7312 up if the language is not C. Note that we check only for the names
7313 that contain spaces; other names might occur by coincidence in other
7315 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7316 && (type
== char_type_node
7317 || ! strcmp (type_name
, "signed char")
7318 || ! strcmp (type_name
, "unsigned char"))))
7320 if (TREE_UNSIGNED (type
))
7321 encoding
= DW_ATE_unsigned
;
7323 encoding
= DW_ATE_signed
;
7326 /* else fall through. */
7329 /* GNU Pascal/Ada CHAR type. Not used in C. */
7330 if (TREE_UNSIGNED (type
))
7331 encoding
= DW_ATE_unsigned_char
;
7333 encoding
= DW_ATE_signed_char
;
7337 encoding
= DW_ATE_float
;
7340 /* Dwarf2 doesn't know anything about complex ints, so use
7341 a user defined type for it. */
7343 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7344 encoding
= DW_ATE_complex_float
;
7346 encoding
= DW_ATE_lo_user
;
7350 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7351 encoding
= DW_ATE_boolean
;
7355 /* No other TREE_CODEs are Dwarf fundamental types. */
7359 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7360 if (demangle_name_func
)
7361 type_name
= (*demangle_name_func
) (type_name
);
7363 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7364 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7365 int_size_in_bytes (type
));
7366 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7368 return base_type_result
;
7371 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7372 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7373 a given type is generally the same as the given type, except that if the
7374 given type is a pointer or reference type, then the root type of the given
7375 type is the root type of the "basis" type for the pointer or reference
7376 type. (This definition of the "root" type is recursive.) Also, the root
7377 type of a `const' qualified type or a `volatile' qualified type is the
7378 root type of the given type without the qualifiers. */
7384 if (TREE_CODE (type
) == ERROR_MARK
)
7385 return error_mark_node
;
7387 switch (TREE_CODE (type
))
7390 return error_mark_node
;
7393 case REFERENCE_TYPE
:
7394 return type_main_variant (root_type (TREE_TYPE (type
)));
7397 return type_main_variant (type
);
7401 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7402 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7408 switch (TREE_CODE (type
))
7423 case QUAL_UNION_TYPE
:
7428 case REFERENCE_TYPE
:
7442 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7443 entry that chains various modifiers in front of the given type. */
7446 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7449 int is_volatile_type
;
7450 dw_die_ref context_die
;
7452 enum tree_code code
= TREE_CODE (type
);
7453 dw_die_ref mod_type_die
= NULL
;
7454 dw_die_ref sub_die
= NULL
;
7455 tree item_type
= NULL
;
7457 if (code
!= ERROR_MARK
)
7459 tree qualified_type
;
7461 /* See if we already have the appropriately qualified variant of
7464 = get_qualified_type (type
,
7465 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7467 ? TYPE_QUAL_VOLATILE
: 0)));
7469 /* If we do, then we can just use its DIE, if it exists. */
7472 mod_type_die
= lookup_type_die (qualified_type
);
7474 return mod_type_die
;
7477 /* Handle C typedef types. */
7478 if (qualified_type
&& TYPE_NAME (qualified_type
)
7479 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7480 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7482 tree type_name
= TYPE_NAME (qualified_type
);
7483 tree dtype
= TREE_TYPE (type_name
);
7485 if (qualified_type
== dtype
)
7487 /* For a named type, use the typedef. */
7488 gen_type_die (qualified_type
, context_die
);
7489 mod_type_die
= lookup_type_die (qualified_type
);
7491 else if (is_const_type
< TYPE_READONLY (dtype
)
7492 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7493 /* cv-unqualified version of named type. Just use the unnamed
7494 type to which it refers. */
7496 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7497 is_const_type
, is_volatile_type
,
7500 /* Else cv-qualified version of named type; fall through. */
7506 else if (is_const_type
)
7508 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7509 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7511 else if (is_volatile_type
)
7513 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7514 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7516 else if (code
== POINTER_TYPE
)
7518 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7519 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7521 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7523 item_type
= TREE_TYPE (type
);
7525 else if (code
== REFERENCE_TYPE
)
7527 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7528 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7530 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7532 item_type
= TREE_TYPE (type
);
7534 else if (is_base_type (type
))
7535 mod_type_die
= base_type_die (type
);
7538 gen_type_die (type
, context_die
);
7540 /* We have to get the type_main_variant here (and pass that to the
7541 `lookup_type_die' routine) because the ..._TYPE node we have
7542 might simply be a *copy* of some original type node (where the
7543 copy was created to help us keep track of typedef names) and
7544 that copy might have a different TYPE_UID from the original
7546 if (TREE_CODE (type
) != VECTOR_TYPE
)
7547 mod_type_die
= lookup_type_die (type_main_variant (type
));
7549 /* Vectors have the debugging information in the type,
7550 not the main variant. */
7551 mod_type_die
= lookup_type_die (type
);
7552 if (mod_type_die
== NULL
)
7556 /* We want to equate the qualified type to the die below. */
7557 type
= qualified_type
;
7561 equate_type_number_to_die (type
, mod_type_die
);
7563 /* We must do this after the equate_type_number_to_die call, in case
7564 this is a recursive type. This ensures that the modified_type_die
7565 recursion will terminate even if the type is recursive. Recursive
7566 types are possible in Ada. */
7567 sub_die
= modified_type_die (item_type
,
7568 TYPE_READONLY (item_type
),
7569 TYPE_VOLATILE (item_type
),
7572 if (sub_die
!= NULL
)
7573 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7575 return mod_type_die
;
7578 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7579 an enumerated type. */
7585 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7588 /* Return the register number described by a given RTL node. */
7594 unsigned regno
= REGNO (rtl
);
7596 if (regno
>= FIRST_PSEUDO_REGISTER
)
7599 return DBX_REGISTER_NUMBER (regno
);
7602 /* Return a location descriptor that designates a machine register or
7603 zero if there is no such. */
7605 static dw_loc_descr_ref
7606 reg_loc_descriptor (rtl
)
7609 dw_loc_descr_ref loc_result
= NULL
;
7612 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7615 reg
= reg_number (rtl
);
7617 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
7619 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
7624 /* Return a location descriptor that designates a constant. */
7626 static dw_loc_descr_ref
7627 int_loc_descriptor (i
)
7630 enum dwarf_location_atom op
;
7632 /* Pick the smallest representation of a constant, rather than just
7633 defaulting to the LEB encoding. */
7637 op
= DW_OP_lit0
+ i
;
7640 else if (i
<= 0xffff)
7642 else if (HOST_BITS_PER_WIDE_INT
== 32
7652 else if (i
>= -0x8000)
7654 else if (HOST_BITS_PER_WIDE_INT
== 32
7655 || i
>= -0x80000000)
7661 return new_loc_descr (op
, i
, 0);
7664 /* Return a location descriptor that designates a base+offset location. */
7666 static dw_loc_descr_ref
7667 based_loc_descr (reg
, offset
)
7671 dw_loc_descr_ref loc_result
;
7672 /* For the "frame base", we use the frame pointer or stack pointer
7673 registers, since the RTL for local variables is relative to one of
7675 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7676 ? HARD_FRAME_POINTER_REGNUM
7677 : STACK_POINTER_REGNUM
);
7680 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
7682 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
7684 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
7689 /* Return true if this RTL expression describes a base+offset calculation. */
7695 return (GET_CODE (rtl
) == PLUS
7696 && ((GET_CODE (XEXP (rtl
, 0)) == REG
7697 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
7698 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
7701 /* The following routine converts the RTL for a variable or parameter
7702 (resident in memory) into an equivalent Dwarf representation of a
7703 mechanism for getting the address of that same variable onto the top of a
7704 hypothetical "address evaluation" stack.
7706 When creating memory location descriptors, we are effectively transforming
7707 the RTL for a memory-resident object into its Dwarf postfix expression
7708 equivalent. This routine recursively descends an RTL tree, turning
7709 it into Dwarf postfix code as it goes.
7711 MODE is the mode of the memory reference, needed to handle some
7712 autoincrement addressing modes.
7714 Return 0 if we can't represent the location. */
7716 static dw_loc_descr_ref
7717 mem_loc_descriptor (rtl
, mode
)
7719 enum machine_mode mode
;
7721 dw_loc_descr_ref mem_loc_result
= NULL
;
7723 /* Note that for a dynamically sized array, the location we will generate a
7724 description of here will be the lowest numbered location which is
7725 actually within the array. That's *not* necessarily the same as the
7726 zeroth element of the array. */
7728 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7729 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
7732 switch (GET_CODE (rtl
))
7737 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7738 just fall into the SUBREG code. */
7740 /* ... fall through ... */
7743 /* The case of a subreg may arise when we have a local (register)
7744 variable or a formal (register) parameter which doesn't quite fill
7745 up an entire register. For now, just assume that it is
7746 legitimate to make the Dwarf info refer to the whole register which
7747 contains the given subreg. */
7748 rtl
= SUBREG_REG (rtl
);
7750 /* ... fall through ... */
7753 /* Whenever a register number forms a part of the description of the
7754 method for calculating the (dynamic) address of a memory resident
7755 object, DWARF rules require the register number be referred to as
7756 a "base register". This distinction is not based in any way upon
7757 what category of register the hardware believes the given register
7758 belongs to. This is strictly DWARF terminology we're dealing with
7759 here. Note that in cases where the location of a memory-resident
7760 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7761 OP_CONST (0)) the actual DWARF location descriptor that we generate
7762 may just be OP_BASEREG (basereg). This may look deceptively like
7763 the object in question was allocated to a register (rather than in
7764 memory) so DWARF consumers need to be aware of the subtle
7765 distinction between OP_REG and OP_BASEREG. */
7766 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
7767 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
7771 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7772 if (mem_loc_result
!= 0)
7773 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
7777 /* Some ports can transform a symbol ref into a label ref, because
7778 the symbol ref is too far away and has to be dumped into a constant
7782 /* Alternatively, the symbol in the constant pool might be referenced
7783 by a different symbol. */
7784 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
7787 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
7789 if (GET_CODE (tmp
) == SYMBOL_REF
)
7792 if (CONSTANT_POOL_ADDRESS_P (tmp
))
7793 get_pool_constant_mark (tmp
, &marked
);
7798 /* If all references to this pool constant were optimized away,
7799 it was not output and thus we can't represent it.
7800 FIXME: might try to use DW_OP_const_value here, though
7801 DW_OP_piece complicates it. */
7806 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
7807 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7808 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
7809 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
7813 /* Extract the PLUS expression nested inside and fall into
7815 rtl
= XEXP (rtl
, 1);
7820 /* Turn these into a PLUS expression and fall into the PLUS code
7822 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
7823 GEN_INT (GET_CODE (rtl
) == PRE_INC
7824 ? GET_MODE_UNIT_SIZE (mode
)
7825 : -GET_MODE_UNIT_SIZE (mode
)));
7827 /* ... fall through ... */
7831 if (is_based_loc (rtl
))
7832 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
7833 INTVAL (XEXP (rtl
, 1)));
7836 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7837 if (mem_loc_result
== 0)
7840 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
7841 && INTVAL (XEXP (rtl
, 1)) >= 0)
7842 add_loc_descr (&mem_loc_result
,
7843 new_loc_descr (DW_OP_plus_uconst
,
7844 INTVAL (XEXP (rtl
, 1)), 0));
7847 add_loc_descr (&mem_loc_result
,
7848 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7849 add_loc_descr (&mem_loc_result
,
7850 new_loc_descr (DW_OP_plus
, 0, 0));
7857 /* If a pseudo-reg is optimized away, it is possible for it to
7858 be replaced with a MEM containing a multiply. */
7859 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7860 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
7862 if (op0
== 0 || op1
== 0)
7865 mem_loc_result
= op0
;
7866 add_loc_descr (&mem_loc_result
, op1
);
7867 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
7872 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
7876 /* If this is a MEM, return its address. Otherwise, we can't
7878 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
7879 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
7887 return mem_loc_result
;
7890 /* Return a descriptor that describes the concatenation of two locations.
7891 This is typically a complex variable. */
7893 static dw_loc_descr_ref
7894 concat_loc_descriptor (x0
, x1
)
7897 dw_loc_descr_ref cc_loc_result
= NULL
;
7898 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
7899 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
7901 if (x0_ref
== 0 || x1_ref
== 0)
7904 cc_loc_result
= x0_ref
;
7905 add_loc_descr (&cc_loc_result
,
7906 new_loc_descr (DW_OP_piece
,
7907 GET_MODE_SIZE (GET_MODE (x0
)), 0));
7909 add_loc_descr (&cc_loc_result
, x1_ref
);
7910 add_loc_descr (&cc_loc_result
,
7911 new_loc_descr (DW_OP_piece
,
7912 GET_MODE_SIZE (GET_MODE (x1
)), 0));
7914 return cc_loc_result
;
7917 /* Output a proper Dwarf location descriptor for a variable or parameter
7918 which is either allocated in a register or in a memory location. For a
7919 register, we just generate an OP_REG and the register number. For a
7920 memory location we provide a Dwarf postfix expression describing how to
7921 generate the (dynamic) address of the object onto the address stack.
7923 If we don't know how to describe it, return 0. */
7925 static dw_loc_descr_ref
7926 loc_descriptor (rtl
)
7929 dw_loc_descr_ref loc_result
= NULL
;
7931 switch (GET_CODE (rtl
))
7934 /* The case of a subreg may arise when we have a local (register)
7935 variable or a formal (register) parameter which doesn't quite fill
7936 up an entire register. For now, just assume that it is
7937 legitimate to make the Dwarf info refer to the whole register which
7938 contains the given subreg. */
7939 rtl
= SUBREG_REG (rtl
);
7941 /* ... fall through ... */
7944 loc_result
= reg_loc_descriptor (rtl
);
7948 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7952 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
7962 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7963 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7964 looking for an address. Otherwise, we return a value. If we can't make a
7965 descriptor, return 0. */
7967 static dw_loc_descr_ref
7968 loc_descriptor_from_tree (loc
, addressp
)
7972 dw_loc_descr_ref ret
, ret1
;
7974 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
7975 enum dwarf_location_atom op
;
7977 /* ??? Most of the time we do not take proper care for sign/zero
7978 extending the values properly. Hopefully this won't be a real
7981 switch (TREE_CODE (loc
))
7986 case WITH_RECORD_EXPR
:
7987 case PLACEHOLDER_EXPR
:
7988 /* This case involves extracting fields from an object to determine the
7989 position of other fields. We don't try to encode this here. The
7990 only user of this is Ada, which encodes the needed information using
7991 the names of types. */
7998 /* We can support this only if we can look through conversions and
7999 find an INDIRECT_EXPR. */
8000 for (loc
= TREE_OPERAND (loc
, 0);
8001 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8002 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8003 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8004 || TREE_CODE (loc
) == SAVE_EXPR
;
8005 loc
= TREE_OPERAND (loc
, 0))
8008 return (TREE_CODE (loc
) == INDIRECT_REF
8009 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8015 rtx rtl
= rtl_for_decl_location (loc
);
8017 if (rtl
== NULL_RTX
)
8019 else if (CONSTANT_P (rtl
))
8021 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8022 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8023 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8028 enum machine_mode mode
= GET_MODE (rtl
);
8030 if (GET_CODE (rtl
) == MEM
)
8033 rtl
= XEXP (rtl
, 0);
8036 ret
= mem_loc_descriptor (rtl
, mode
);
8042 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8047 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8051 case NON_LVALUE_EXPR
:
8052 case VIEW_CONVERT_EXPR
:
8054 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8059 case ARRAY_RANGE_REF
:
8062 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8063 enum machine_mode mode
;
8066 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8067 &unsignedp
, &volatilep
);
8072 ret
= loc_descriptor_from_tree (obj
, 1);
8074 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8077 if (offset
!= NULL_TREE
)
8079 /* Variable offset. */
8080 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8081 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8087 bytepos
= bitpos
/ BITS_PER_UNIT
;
8089 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8090 else if (bytepos
< 0)
8092 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8093 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8099 if (host_integerp (loc
, 0))
8100 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8105 case TRUTH_AND_EXPR
:
8106 case TRUTH_ANDIF_EXPR
:
8111 case TRUTH_XOR_EXPR
:
8117 case TRUTH_ORIF_EXPR
:
8122 case TRUNC_DIV_EXPR
:
8130 case TRUNC_MOD_EXPR
:
8143 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8147 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8148 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8150 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8154 add_loc_descr (&ret
,
8155 new_loc_descr (DW_OP_plus_uconst
,
8156 tree_low_cst (TREE_OPERAND (loc
, 1),
8166 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8173 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8180 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8187 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8202 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8203 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8204 if (ret
== 0 || ret1
== 0)
8207 add_loc_descr (&ret
, ret1
);
8208 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8211 case TRUTH_NOT_EXPR
:
8225 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8229 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8233 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8234 build (LT_EXPR
, integer_type_node
,
8235 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8236 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8238 /* ... fall through ... */
8242 dw_loc_descr_ref lhs
8243 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8244 dw_loc_descr_ref rhs
8245 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8246 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8248 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8249 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8252 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8253 add_loc_descr (&ret
, bra_node
);
8255 add_loc_descr (&ret
, rhs
);
8256 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8257 add_loc_descr (&ret
, jump_node
);
8259 add_loc_descr (&ret
, lhs
);
8260 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8261 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8263 /* ??? Need a node to point the skip at. Use a nop. */
8264 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8265 add_loc_descr (&ret
, tmp
);
8266 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8267 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8275 /* Show if we can't fill the request for an address. */
8276 if (addressp
&& indirect_p
== 0)
8279 /* If we've got an address and don't want one, dereference. */
8280 if (!addressp
&& indirect_p
> 0)
8282 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8284 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8286 else if (size
== DWARF2_ADDR_SIZE
)
8289 op
= DW_OP_deref_size
;
8291 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8297 /* Given a value, round it up to the lowest multiple of `boundary'
8298 which is not less than the value itself. */
8300 static inline HOST_WIDE_INT
8301 ceiling (value
, boundary
)
8302 HOST_WIDE_INT value
;
8303 unsigned int boundary
;
8305 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8308 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8309 pointer to the declared type for the relevant field variable, or return
8310 `integer_type_node' if the given node turns out to be an
8319 if (TREE_CODE (decl
) == ERROR_MARK
)
8320 return integer_type_node
;
8322 type
= DECL_BIT_FIELD_TYPE (decl
);
8323 if (type
== NULL_TREE
)
8324 type
= TREE_TYPE (decl
);
8329 /* Given a pointer to a tree node, return the alignment in bits for
8330 it, or else return BITS_PER_WORD if the node actually turns out to
8331 be an ERROR_MARK node. */
8333 static inline unsigned
8334 simple_type_align_in_bits (type
)
8337 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8340 static inline unsigned
8341 simple_decl_align_in_bits (decl
)
8344 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8347 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8348 node, return the size in bits for the type if it is a constant, or else
8349 return the alignment for the type if the type's size is not constant, or
8350 else return BITS_PER_WORD if the type actually turns out to be an
8353 static inline unsigned HOST_WIDE_INT
8354 simple_type_size_in_bits (type
)
8358 if (TREE_CODE (type
) == ERROR_MARK
)
8359 return BITS_PER_WORD
;
8360 else if (TYPE_SIZE (type
) == NULL_TREE
)
8362 else if (host_integerp (TYPE_SIZE (type
), 1))
8363 return tree_low_cst (TYPE_SIZE (type
), 1);
8365 return TYPE_ALIGN (type
);
8368 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8369 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8370 or return 0 if we are unable to determine what that offset is, either
8371 because the argument turns out to be a pointer to an ERROR_MARK node, or
8372 because the offset is actually variable. (We can't handle the latter case
8375 static HOST_WIDE_INT
8376 field_byte_offset (decl
)
8379 unsigned int type_align_in_bits
;
8380 unsigned int decl_align_in_bits
;
8381 unsigned HOST_WIDE_INT type_size_in_bits
;
8382 HOST_WIDE_INT object_offset_in_bits
;
8384 tree field_size_tree
;
8385 HOST_WIDE_INT bitpos_int
;
8386 HOST_WIDE_INT deepest_bitpos
;
8387 unsigned HOST_WIDE_INT field_size_in_bits
;
8389 if (TREE_CODE (decl
) == ERROR_MARK
)
8391 else if (TREE_CODE (decl
) != FIELD_DECL
)
8394 type
= field_type (decl
);
8395 field_size_tree
= DECL_SIZE (decl
);
8397 /* The size could be unspecified if there was an error, or for
8398 a flexible array member. */
8399 if (! field_size_tree
)
8400 field_size_tree
= bitsize_zero_node
;
8402 /* We cannot yet cope with fields whose positions are variable, so
8403 for now, when we see such things, we simply return 0. Someday, we may
8404 be able to handle such cases, but it will be damn difficult. */
8405 if (! host_integerp (bit_position (decl
), 0))
8408 bitpos_int
= int_bit_position (decl
);
8410 /* If we don't know the size of the field, pretend it's a full word. */
8411 if (host_integerp (field_size_tree
, 1))
8412 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8414 field_size_in_bits
= BITS_PER_WORD
;
8416 type_size_in_bits
= simple_type_size_in_bits (type
);
8417 type_align_in_bits
= simple_type_align_in_bits (type
);
8418 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8420 /* The GCC front-end doesn't make any attempt to keep track of the starting
8421 bit offset (relative to the start of the containing structure type) of the
8422 hypothetical "containing object" for a bit-field. Thus, when computing
8423 the byte offset value for the start of the "containing object" of a
8424 bit-field, we must deduce this information on our own. This can be rather
8425 tricky to do in some cases. For example, handling the following structure
8426 type definition when compiling for an i386/i486 target (which only aligns
8427 long long's to 32-bit boundaries) can be very tricky:
8429 struct S { int field1; long long field2:31; };
8431 Fortunately, there is a simple rule-of-thumb which can be used in such
8432 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8433 structure shown above. It decides to do this based upon one simple rule
8434 for bit-field allocation. GCC allocates each "containing object" for each
8435 bit-field at the first (i.e. lowest addressed) legitimate alignment
8436 boundary (based upon the required minimum alignment for the declared type
8437 of the field) which it can possibly use, subject to the condition that
8438 there is still enough available space remaining in the containing object
8439 (when allocated at the selected point) to fully accommodate all of the
8440 bits of the bit-field itself.
8442 This simple rule makes it obvious why GCC allocates 8 bytes for each
8443 object of the structure type shown above. When looking for a place to
8444 allocate the "containing object" for `field2', the compiler simply tries
8445 to allocate a 64-bit "containing object" at each successive 32-bit
8446 boundary (starting at zero) until it finds a place to allocate that 64-
8447 bit field such that at least 31 contiguous (and previously unallocated)
8448 bits remain within that selected 64 bit field. (As it turns out, for the
8449 example above, the compiler finds it is OK to allocate the "containing
8450 object" 64-bit field at bit-offset zero within the structure type.)
8452 Here we attempt to work backwards from the limited set of facts we're
8453 given, and we try to deduce from those facts, where GCC must have believed
8454 that the containing object started (within the structure type). The value
8455 we deduce is then used (by the callers of this routine) to generate
8456 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8457 and, in the case of DW_AT_location, regular fields as well). */
8459 /* Figure out the bit-distance from the start of the structure to the
8460 "deepest" bit of the bit-field. */
8461 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8463 /* This is the tricky part. Use some fancy footwork to deduce where the
8464 lowest addressed bit of the containing object must be. */
8465 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8467 /* Round up to type_align by default. This works best for bitfields. */
8468 object_offset_in_bits
+= type_align_in_bits
- 1;
8469 object_offset_in_bits
/= type_align_in_bits
;
8470 object_offset_in_bits
*= type_align_in_bits
;
8472 if (object_offset_in_bits
> bitpos_int
)
8474 /* Sigh, the decl must be packed. */
8475 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8477 /* Round up to decl_align instead. */
8478 object_offset_in_bits
+= decl_align_in_bits
- 1;
8479 object_offset_in_bits
/= decl_align_in_bits
;
8480 object_offset_in_bits
*= decl_align_in_bits
;
8483 return object_offset_in_bits
/ BITS_PER_UNIT
;
8486 /* The following routines define various Dwarf attributes and any data
8487 associated with them. */
8489 /* Add a location description attribute value to a DIE.
8491 This emits location attributes suitable for whole variables and
8492 whole parameters. Note that the location attributes for struct fields are
8493 generated by the routine `data_member_location_attribute' below. */
8496 add_AT_location_description (die
, attr_kind
, rtl
)
8498 enum dwarf_attribute attr_kind
;
8501 dw_loc_descr_ref descr
= loc_descriptor (rtl
);
8504 add_AT_loc (die
, attr_kind
, descr
);
8507 /* Attach the specialized form of location attribute used for data members of
8508 struct and union types. In the special case of a FIELD_DECL node which
8509 represents a bit-field, the "offset" part of this special location
8510 descriptor must indicate the distance in bytes from the lowest-addressed
8511 byte of the containing struct or union type to the lowest-addressed byte of
8512 the "containing object" for the bit-field. (See the `field_byte_offset'
8515 For any given bit-field, the "containing object" is a hypothetical object
8516 (of some integral or enum type) within which the given bit-field lives. The
8517 type of this hypothetical "containing object" is always the same as the
8518 declared type of the individual bit-field itself (for GCC anyway... the
8519 DWARF spec doesn't actually mandate this). Note that it is the size (in
8520 bytes) of the hypothetical "containing object" which will be given in the
8521 DW_AT_byte_size attribute for this bit-field. (See the
8522 `byte_size_attribute' function below.) It is also used when calculating the
8523 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8527 add_data_member_location_attribute (die
, decl
)
8532 dw_loc_descr_ref loc_descr
= 0;
8534 if (TREE_CODE (decl
) == TREE_VEC
)
8536 /* We're working on the TAG_inheritance for a base class. */
8537 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8539 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8540 aren't at a fixed offset from all (sub)objects of the same
8541 type. We need to extract the appropriate offset from our
8542 vtable. The following dwarf expression means
8544 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8546 This is specific to the V3 ABI, of course. */
8548 dw_loc_descr_ref tmp
;
8550 /* Make a copy of the object address. */
8551 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8552 add_loc_descr (&loc_descr
, tmp
);
8554 /* Extract the vtable address. */
8555 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8556 add_loc_descr (&loc_descr
, tmp
);
8558 /* Calculate the address of the offset. */
8559 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8563 tmp
= int_loc_descriptor (-offset
);
8564 add_loc_descr (&loc_descr
, tmp
);
8565 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8566 add_loc_descr (&loc_descr
, tmp
);
8568 /* Extract the offset. */
8569 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8570 add_loc_descr (&loc_descr
, tmp
);
8572 /* Add it to the object address. */
8573 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
8574 add_loc_descr (&loc_descr
, tmp
);
8577 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
8580 offset
= field_byte_offset (decl
);
8584 enum dwarf_location_atom op
;
8586 /* The DWARF2 standard says that we should assume that the structure
8587 address is already on the stack, so we can specify a structure field
8588 address by using DW_OP_plus_uconst. */
8590 #ifdef MIPS_DEBUGGING_INFO
8591 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8592 operator correctly. It works only if we leave the offset on the
8596 op
= DW_OP_plus_uconst
;
8599 loc_descr
= new_loc_descr (op
, offset
, 0);
8602 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
8605 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8606 does not have a "location" either in memory or in a register. These
8607 things can arise in GNU C when a constant is passed as an actual parameter
8608 to an inlined function. They can also arise in C++ where declared
8609 constants do not necessarily get memory "homes". */
8612 add_const_value_attribute (die
, rtl
)
8616 switch (GET_CODE (rtl
))
8619 /* Note that a CONST_INT rtx could represent either an integer
8620 or a floating-point constant. A CONST_INT is used whenever
8621 the constant will fit into a single word. In all such
8622 cases, the original mode of the constant value is wiped
8623 out, and the CONST_INT rtx is assigned VOIDmode. */
8625 HOST_WIDE_INT val
= INTVAL (rtl
);
8627 /* ??? We really should be using HOST_WIDE_INT throughout. */
8628 if (val
< 0 && (long) val
== val
)
8629 add_AT_int (die
, DW_AT_const_value
, (long) val
);
8630 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
8631 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
8634 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8635 add_AT_long_long (die
, DW_AT_const_value
,
8636 val
>> HOST_BITS_PER_LONG
, val
);
8645 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8646 floating-point constant. A CONST_DOUBLE is used whenever the
8647 constant requires more than one word in order to be adequately
8648 represented. We output CONST_DOUBLEs as blocks. */
8650 enum machine_mode mode
= GET_MODE (rtl
);
8652 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
8654 unsigned length
= GET_MODE_SIZE (mode
) / 4;
8655 long *array
= (long *) xmalloc (sizeof (long) * length
);
8658 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
8662 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
8666 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
8671 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
8678 add_AT_float (die
, DW_AT_const_value
, length
, array
);
8682 /* ??? We really should be using HOST_WIDE_INT throughout. */
8683 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
8686 add_AT_long_long (die
, DW_AT_const_value
,
8687 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
8693 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
8699 add_AT_addr (die
, DW_AT_const_value
, rtl
);
8700 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8704 /* In cases where an inlined instance of an inline function is passed
8705 the address of an `auto' variable (which is local to the caller) we
8706 can get a situation where the DECL_RTL of the artificial local
8707 variable (for the inlining) which acts as a stand-in for the
8708 corresponding formal parameter (of the inline function) will look
8709 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8710 exactly a compile-time constant expression, but it isn't the address
8711 of the (artificial) local variable either. Rather, it represents the
8712 *value* which the artificial local variable always has during its
8713 lifetime. We currently have no way to represent such quasi-constant
8714 values in Dwarf, so for now we just punt and generate nothing. */
8718 /* No other kinds of rtx should be possible here. */
8725 rtl_for_decl_location (decl
)
8730 /* Here we have to decide where we are going to say the parameter "lives"
8731 (as far as the debugger is concerned). We only have a couple of
8732 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8734 DECL_RTL normally indicates where the parameter lives during most of the
8735 activation of the function. If optimization is enabled however, this
8736 could be either NULL or else a pseudo-reg. Both of those cases indicate
8737 that the parameter doesn't really live anywhere (as far as the code
8738 generation parts of GCC are concerned) during most of the function's
8739 activation. That will happen (for example) if the parameter is never
8740 referenced within the function.
8742 We could just generate a location descriptor here for all non-NULL
8743 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8744 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8745 where DECL_RTL is NULL or is a pseudo-reg.
8747 Note however that we can only get away with using DECL_INCOMING_RTL as
8748 a backup substitute for DECL_RTL in certain limited cases. In cases
8749 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8750 we can be sure that the parameter was passed using the same type as it is
8751 declared to have within the function, and that its DECL_INCOMING_RTL
8752 points us to a place where a value of that type is passed.
8754 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8755 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8756 because in these cases DECL_INCOMING_RTL points us to a value of some
8757 type which is *different* from the type of the parameter itself. Thus,
8758 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8759 such cases, the debugger would end up (for example) trying to fetch a
8760 `float' from a place which actually contains the first part of a
8761 `double'. That would lead to really incorrect and confusing
8762 output at debug-time.
8764 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8765 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8766 are a couple of exceptions however. On little-endian machines we can
8767 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8768 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8769 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8770 when (on a little-endian machine) a non-prototyped function has a
8771 parameter declared to be of type `short' or `char'. In such cases,
8772 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8773 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8774 passed `int' value. If the debugger then uses that address to fetch
8775 a `short' or a `char' (on a little-endian machine) the result will be
8776 the correct data, so we allow for such exceptional cases below.
8778 Note that our goal here is to describe the place where the given formal
8779 parameter lives during most of the function's activation (i.e. between the
8780 end of the prologue and the start of the epilogue). We'll do that as best
8781 as we can. Note however that if the given formal parameter is modified
8782 sometime during the execution of the function, then a stack backtrace (at
8783 debug-time) will show the function as having been called with the *new*
8784 value rather than the value which was originally passed in. This happens
8785 rarely enough that it is not a major problem, but it *is* a problem, and
8788 A future version of dwarf2out.c may generate two additional attributes for
8789 any given DW_TAG_formal_parameter DIE which will describe the "passed
8790 type" and the "passed location" for the given formal parameter in addition
8791 to the attributes we now generate to indicate the "declared type" and the
8792 "active location" for each parameter. This additional set of attributes
8793 could be used by debuggers for stack backtraces. Separately, note that
8794 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8795 This happens (for example) for inlined-instances of inline function formal
8796 parameters which are never referenced. This really shouldn't be
8797 happening. All PARM_DECL nodes should get valid non-NULL
8798 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8799 values for inlined instances of inline function parameters, so when we see
8800 such cases, we are just out-of-luck for the time being (until integrate.c
8803 /* Use DECL_RTL as the "location" unless we find something better. */
8804 rtl
= DECL_RTL_IF_SET (decl
);
8806 /* When generating abstract instances, ignore everything except
8807 constants and symbols living in memory. */
8808 if (! reload_completed
)
8811 && (CONSTANT_P (rtl
)
8812 || (GET_CODE (rtl
) == MEM
8813 && CONSTANT_P (XEXP (rtl
, 0)))))
8815 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8816 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8822 else if (TREE_CODE (decl
) == PARM_DECL
)
8824 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
8826 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
8827 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
8829 /* This decl represents a formal parameter which was optimized out.
8830 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8831 all cases where (rtl == NULL_RTX) just below. */
8832 if (declared_type
== passed_type
)
8833 rtl
= DECL_INCOMING_RTL (decl
);
8834 else if (! BYTES_BIG_ENDIAN
8835 && TREE_CODE (declared_type
) == INTEGER_TYPE
8836 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
8837 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
8838 rtl
= DECL_INCOMING_RTL (decl
);
8841 /* If the parm was passed in registers, but lives on the stack, then
8842 make a big endian correction if the mode of the type of the
8843 parameter is not the same as the mode of the rtl. */
8844 /* ??? This is the same series of checks that are made in dbxout.c before
8845 we reach the big endian correction code there. It isn't clear if all
8846 of these checks are necessary here, but keeping them all is the safe
8848 else if (GET_CODE (rtl
) == MEM
8849 && XEXP (rtl
, 0) != const0_rtx
8850 && ! CONSTANT_P (XEXP (rtl
, 0))
8851 /* Not passed in memory. */
8852 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
8853 /* Not passed by invisible reference. */
8854 && (GET_CODE (XEXP (rtl
, 0)) != REG
8855 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
8856 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
8857 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8858 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
8861 /* Big endian correction check. */
8863 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
8864 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
8867 int offset
= (UNITS_PER_WORD
8868 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
8870 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
8871 plus_constant (XEXP (rtl
, 0), offset
));
8875 if (rtl
!= NULL_RTX
)
8877 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
8878 #ifdef LEAF_REG_REMAP
8879 if (current_function_uses_only_leaf_regs
)
8880 leaf_renumber_regs_insn (rtl
);
8884 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8885 and will have been substituted directly into all expressions that use it.
8886 C does not have such a concept, but C++ and other languages do. */
8887 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
8889 /* If a variable is initialized with a string constant without embedded
8890 zeros, build CONST_STRING. */
8891 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
8892 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
8894 tree arrtype
= TREE_TYPE (decl
);
8895 tree enttype
= TREE_TYPE (arrtype
);
8896 tree domain
= TYPE_DOMAIN (arrtype
);
8897 tree init
= DECL_INITIAL (decl
);
8898 enum machine_mode mode
= TYPE_MODE (enttype
);
8900 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
8902 && integer_zerop (TYPE_MIN_VALUE (domain
))
8903 && compare_tree_int (TYPE_MAX_VALUE (domain
),
8904 TREE_STRING_LENGTH (init
) - 1) == 0
8905 && ((size_t) TREE_STRING_LENGTH (init
)
8906 == strlen (TREE_STRING_POINTER (init
)) + 1))
8907 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
8909 /* If the initializer is something that we know will expand into an
8910 immediate RTL constant, expand it now. Expanding anything else
8911 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8912 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
8913 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
8915 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
8916 EXPAND_INITIALIZER
);
8917 /* If expand_expr returns a MEM, it wasn't immediate. */
8918 if (rtl
&& GET_CODE (rtl
) == MEM
)
8923 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8925 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8930 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8931 data attribute for a variable or a parameter. We generate the
8932 DW_AT_const_value attribute only in those cases where the given variable
8933 or parameter does not have a true "location" either in memory or in a
8934 register. This can happen (for example) when a constant is passed as an
8935 actual argument in a call to an inline function. (It's possible that
8936 these things can crop up in other ways also.) Note that one type of
8937 constant value which can be passed into an inlined function is a constant
8938 pointer. This can happen for example if an actual argument in an inlined
8939 function call evaluates to a compile-time constant address. */
8942 add_location_or_const_value_attribute (die
, decl
)
8948 if (TREE_CODE (decl
) == ERROR_MARK
)
8950 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
8953 rtl
= rtl_for_decl_location (decl
);
8954 if (rtl
== NULL_RTX
)
8957 /* If we don't look past the constant pool, we risk emitting a
8958 reference to a constant pool entry that isn't referenced from
8959 code, and thus is not emitted. */
8960 rtl
= avoid_constant_pool_reference (rtl
);
8962 switch (GET_CODE (rtl
))
8965 /* The address of a variable that was optimized away; don't emit
8976 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8977 add_const_value_attribute (die
, rtl
);
8984 add_AT_location_description (die
, DW_AT_location
, rtl
);
8992 /* If we don't have a copy of this variable in memory for some reason (such
8993 as a C++ member constant that doesn't have an out-of-line definition),
8994 we should tell the debugger about the constant value. */
8997 tree_add_const_value_attribute (var_die
, decl
)
9001 tree init
= DECL_INITIAL (decl
);
9002 tree type
= TREE_TYPE (decl
);
9004 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9005 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9010 switch (TREE_CODE (type
))
9013 if (host_integerp (init
, 0))
9014 add_AT_unsigned (var_die
, DW_AT_const_value
,
9015 tree_low_cst (init
, 0));
9017 add_AT_long_long (var_die
, DW_AT_const_value
,
9018 TREE_INT_CST_HIGH (init
),
9019 TREE_INT_CST_LOW (init
));
9026 /* Generate an DW_AT_name attribute given some string value to be included as
9027 the value of the attribute. */
9030 add_name_attribute (die
, name_string
)
9032 const char *name_string
;
9034 if (name_string
!= NULL
&& *name_string
!= 0)
9036 if (demangle_name_func
)
9037 name_string
= (*demangle_name_func
) (name_string
);
9039 add_AT_string (die
, DW_AT_name
, name_string
);
9043 /* Given a tree node describing an array bound (either lower or upper) output
9044 a representation for that bound. */
9047 add_bound_info (subrange_die
, bound_attr
, bound
)
9048 dw_die_ref subrange_die
;
9049 enum dwarf_attribute bound_attr
;
9052 switch (TREE_CODE (bound
))
9057 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9059 if (! host_integerp (bound
, 0)
9060 || (bound_attr
== DW_AT_lower_bound
9061 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9062 || (is_fortran () && integer_onep (bound
)))))
9063 /* use the default */
9066 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9071 case NON_LVALUE_EXPR
:
9072 case VIEW_CONVERT_EXPR
:
9073 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9077 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9078 access the upper bound values may be bogus. If they refer to a
9079 register, they may only describe how to get at these values at the
9080 points in the generated code right after they have just been
9081 computed. Worse yet, in the typical case, the upper bound values
9082 will not even *be* computed in the optimized code (though the
9083 number of elements will), so these SAVE_EXPRs are entirely
9084 bogus. In order to compensate for this fact, we check here to see
9085 if optimization is enabled, and if so, we don't add an attribute
9086 for the (unknown and unknowable) upper bound. This should not
9087 cause too much trouble for existing (stupid?) debuggers because
9088 they have to deal with empty upper bounds location descriptions
9089 anyway in order to be able to deal with incomplete array types.
9090 Of course an intelligent debugger (GDB?) should be able to
9091 comprehend that a missing upper bound specification in an array
9092 type used for a storage class `auto' local array variable
9093 indicates that the upper bound is both unknown (at compile- time)
9094 and unknowable (at run-time) due to optimization.
9096 We assume that a MEM rtx is safe because gcc wouldn't put the
9097 value there unless it was going to be used repeatedly in the
9098 function, i.e. for cleanups. */
9099 if (SAVE_EXPR_RTL (bound
)
9100 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9102 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9103 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9104 rtx loc
= SAVE_EXPR_RTL (bound
);
9106 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9107 it references an outer function's frame. */
9108 if (GET_CODE (loc
) == MEM
)
9110 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9112 if (XEXP (loc
, 0) != new_addr
)
9113 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9116 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9117 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9118 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
9119 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9122 /* Else leave out the attribute. */
9128 dw_die_ref decl_die
= lookup_decl_die (bound
);
9130 /* ??? Can this happen, or should the variable have been bound
9131 first? Probably it can, since I imagine that we try to create
9132 the types of parameters in the order in which they exist in
9133 the list, and won't have created a forward reference to a
9135 if (decl_die
!= NULL
)
9136 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9142 /* Otherwise try to create a stack operation procedure to
9143 evaluate the value of the array bound. */
9145 dw_die_ref ctx
, decl_die
;
9146 dw_loc_descr_ref loc
;
9148 loc
= loc_descriptor_from_tree (bound
, 0);
9152 if (current_function_decl
== 0)
9153 ctx
= comp_unit_die
;
9155 ctx
= lookup_decl_die (current_function_decl
);
9157 /* If we weren't able to find a context, it's most likely the case
9158 that we are processing the return type of the function. So
9159 make a SAVE_EXPR to point to it and have the limbo DIE code
9160 find the proper die. The save_expr function doesn't always
9161 make a SAVE_EXPR, so do it ourselves. */
9163 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9164 current_function_decl
, NULL_TREE
);
9166 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9167 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9168 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9169 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9171 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9177 /* Note that the block of subscript information for an array type also
9178 includes information about the element type of type given array type. */
9181 add_subscript_info (type_die
, type
)
9182 dw_die_ref type_die
;
9185 #ifndef MIPS_DEBUGGING_INFO
9186 unsigned dimension_number
;
9189 dw_die_ref subrange_die
;
9191 /* The GNU compilers represent multidimensional array types as sequences of
9192 one dimensional array types whose element types are themselves array
9193 types. Here we squish that down, so that each multidimensional array
9194 type gets only one array_type DIE in the Dwarf debugging info. The draft
9195 Dwarf specification say that we are allowed to do this kind of
9196 compression in C (because there is no difference between an array or
9197 arrays and a multidimensional array in C) but for other source languages
9198 (e.g. Ada) we probably shouldn't do this. */
9200 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9201 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9202 We work around this by disabling this feature. See also
9203 gen_array_type_die. */
9204 #ifndef MIPS_DEBUGGING_INFO
9205 for (dimension_number
= 0;
9206 TREE_CODE (type
) == ARRAY_TYPE
;
9207 type
= TREE_TYPE (type
), dimension_number
++)
9210 tree domain
= TYPE_DOMAIN (type
);
9212 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9213 and (in GNU C only) variable bounds. Handle all three forms
9215 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9218 /* We have an array type with specified bounds. */
9219 lower
= TYPE_MIN_VALUE (domain
);
9220 upper
= TYPE_MAX_VALUE (domain
);
9222 /* define the index type. */
9223 if (TREE_TYPE (domain
))
9225 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9226 TREE_TYPE field. We can't emit debug info for this
9227 because it is an unnamed integral type. */
9228 if (TREE_CODE (domain
) == INTEGER_TYPE
9229 && TYPE_NAME (domain
) == NULL_TREE
9230 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9231 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9234 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9238 /* ??? If upper is NULL, the array has unspecified length,
9239 but it does have a lower bound. This happens with Fortran
9241 Since the debugger is definitely going to need to know N
9242 to produce useful results, go ahead and output the lower
9243 bound solo, and hope the debugger can cope. */
9245 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9247 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9250 /* Otherwise we have an array type with an unspecified length. The
9251 DWARF-2 spec does not say how to handle this; let's just leave out the
9257 add_byte_size_attribute (die
, tree_node
)
9263 switch (TREE_CODE (tree_node
))
9271 case QUAL_UNION_TYPE
:
9272 size
= int_size_in_bytes (tree_node
);
9275 /* For a data member of a struct or union, the DW_AT_byte_size is
9276 generally given as the number of bytes normally allocated for an
9277 object of the *declared* type of the member itself. This is true
9278 even for bit-fields. */
9279 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9285 /* Note that `size' might be -1 when we get to this point. If it is, that
9286 indicates that the byte size of the entity in question is variable. We
9287 have no good way of expressing this fact in Dwarf at the present time,
9288 so just let the -1 pass on through. */
9289 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9292 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9293 which specifies the distance in bits from the highest order bit of the
9294 "containing object" for the bit-field to the highest order bit of the
9297 For any given bit-field, the "containing object" is a hypothetical object
9298 (of some integral or enum type) within which the given bit-field lives. The
9299 type of this hypothetical "containing object" is always the same as the
9300 declared type of the individual bit-field itself. The determination of the
9301 exact location of the "containing object" for a bit-field is rather
9302 complicated. It's handled by the `field_byte_offset' function (above).
9304 Note that it is the size (in bytes) of the hypothetical "containing object"
9305 which will be given in the DW_AT_byte_size attribute for this bit-field.
9306 (See `byte_size_attribute' above). */
9309 add_bit_offset_attribute (die
, decl
)
9313 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9314 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9315 HOST_WIDE_INT bitpos_int
;
9316 HOST_WIDE_INT highest_order_object_bit_offset
;
9317 HOST_WIDE_INT highest_order_field_bit_offset
;
9318 HOST_WIDE_INT
unsigned bit_offset
;
9320 /* Must be a field and a bit field. */
9322 || TREE_CODE (decl
) != FIELD_DECL
)
9325 /* We can't yet handle bit-fields whose offsets are variable, so if we
9326 encounter such things, just return without generating any attribute
9327 whatsoever. Likewise for variable or too large size. */
9328 if (! host_integerp (bit_position (decl
), 0)
9329 || ! host_integerp (DECL_SIZE (decl
), 1))
9332 bitpos_int
= int_bit_position (decl
);
9334 /* Note that the bit offset is always the distance (in bits) from the
9335 highest-order bit of the "containing object" to the highest-order bit of
9336 the bit-field itself. Since the "high-order end" of any object or field
9337 is different on big-endian and little-endian machines, the computation
9338 below must take account of these differences. */
9339 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9340 highest_order_field_bit_offset
= bitpos_int
;
9342 if (! BYTES_BIG_ENDIAN
)
9344 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9345 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9349 = (! BYTES_BIG_ENDIAN
9350 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9351 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9353 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9356 /* For a FIELD_DECL node which represents a bit field, output an attribute
9357 which specifies the length in bits of the given field. */
9360 add_bit_size_attribute (die
, decl
)
9364 /* Must be a field and a bit field. */
9365 if (TREE_CODE (decl
) != FIELD_DECL
9366 || ! DECL_BIT_FIELD_TYPE (decl
))
9369 if (host_integerp (DECL_SIZE (decl
), 1))
9370 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9373 /* If the compiled language is ANSI C, then add a 'prototyped'
9374 attribute, if arg types are given for the parameters of a function. */
9377 add_prototyped_attribute (die
, func_type
)
9381 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9382 && TYPE_ARG_TYPES (func_type
) != NULL
)
9383 add_AT_flag (die
, DW_AT_prototyped
, 1);
9386 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9387 by looking in either the type declaration or object declaration
9391 add_abstract_origin_attribute (die
, origin
)
9395 dw_die_ref origin_die
= NULL
;
9397 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9399 /* We may have gotten separated from the block for the inlined
9400 function, if we're in an exception handler or some such; make
9401 sure that the abstract function has been written out.
9403 Doing this for nested functions is wrong, however; functions are
9404 distinct units, and our context might not even be inline. */
9408 fn
= TYPE_STUB_DECL (fn
);
9410 fn
= decl_function_context (fn
);
9412 dwarf2out_abstract_function (fn
);
9415 if (DECL_P (origin
))
9416 origin_die
= lookup_decl_die (origin
);
9417 else if (TYPE_P (origin
))
9418 origin_die
= lookup_type_die (origin
);
9420 if (origin_die
== NULL
)
9423 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9426 /* We do not currently support the pure_virtual attribute. */
9429 add_pure_or_virtual_attribute (die
, func_decl
)
9433 if (DECL_VINDEX (func_decl
))
9435 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9437 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9438 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9439 new_loc_descr (DW_OP_constu
,
9440 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9443 /* GNU extension: Record what type this method came from originally. */
9444 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9445 add_AT_die_ref (die
, DW_AT_containing_type
,
9446 lookup_type_die (DECL_CONTEXT (func_decl
)));
9450 /* Add source coordinate attributes for the given decl. */
9453 add_src_coords_attributes (die
, decl
)
9457 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9459 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9460 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9463 /* Add an DW_AT_name attribute and source coordinate attribute for the
9464 given decl, but only if it actually has a name. */
9467 add_name_and_src_coords_attributes (die
, decl
)
9473 decl_name
= DECL_NAME (decl
);
9474 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9476 add_name_attribute (die
, dwarf2_name (decl
, 0));
9477 if (! DECL_ARTIFICIAL (decl
))
9478 add_src_coords_attributes (die
, decl
);
9480 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9481 && TREE_PUBLIC (decl
)
9482 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9483 && !DECL_ABSTRACT (decl
))
9484 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9485 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9488 #ifdef VMS_DEBUGGING_INFO
9489 /* Get the function's name, as described by its RTL. This may be different
9490 from the DECL_NAME name used in the source file. */
9491 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9493 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9494 XEXP (DECL_RTL (decl
), 0));
9495 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9500 /* Push a new declaration scope. */
9503 push_decl_scope (scope
)
9506 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9509 /* Pop a declaration scope. */
9514 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9517 VARRAY_POP (decl_scope_table
);
9520 /* Return the DIE for the scope that immediately contains this type.
9521 Non-named types get global scope. Named types nested in other
9522 types get their containing scope if it's open, or global scope
9523 otherwise. All other types (i.e. function-local named types) get
9524 the current active scope. */
9527 scope_die_for (t
, context_die
)
9529 dw_die_ref context_die
;
9531 dw_die_ref scope_die
= NULL
;
9532 tree containing_scope
;
9535 /* Non-types always go in the current scope. */
9539 containing_scope
= TYPE_CONTEXT (t
);
9541 /* Ignore namespaces for the moment. */
9542 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9543 containing_scope
= NULL_TREE
;
9545 /* Ignore function type "scopes" from the C frontend. They mean that
9546 a tagged type is local to a parmlist of a function declarator, but
9547 that isn't useful to DWARF. */
9548 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9549 containing_scope
= NULL_TREE
;
9551 if (containing_scope
== NULL_TREE
)
9552 scope_die
= comp_unit_die
;
9553 else if (TYPE_P (containing_scope
))
9555 /* For types, we can just look up the appropriate DIE. But
9556 first we check to see if we're in the middle of emitting it
9557 so we know where the new DIE should go. */
9558 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9559 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9564 if (debug_info_level
> DINFO_LEVEL_TERSE
9565 && !TREE_ASM_WRITTEN (containing_scope
))
9568 /* If none of the current dies are suitable, we get file scope. */
9569 scope_die
= comp_unit_die
;
9572 scope_die
= lookup_type_die (containing_scope
);
9575 scope_die
= context_die
;
9580 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9583 local_scope_p (context_die
)
9584 dw_die_ref context_die
;
9586 for (; context_die
; context_die
= context_die
->die_parent
)
9587 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
9588 || context_die
->die_tag
== DW_TAG_subprogram
)
9594 /* Returns nonzero if CONTEXT_DIE is a class. */
9597 class_scope_p (context_die
)
9598 dw_die_ref context_die
;
9601 && (context_die
->die_tag
== DW_TAG_structure_type
9602 || context_die
->die_tag
== DW_TAG_union_type
));
9605 /* Many forms of DIEs require a "type description" attribute. This
9606 routine locates the proper "type descriptor" die for the type given
9607 by 'type', and adds an DW_AT_type attribute below the given die. */
9610 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
9611 dw_die_ref object_die
;
9615 dw_die_ref context_die
;
9617 enum tree_code code
= TREE_CODE (type
);
9618 dw_die_ref type_die
= NULL
;
9620 /* ??? If this type is an unnamed subrange type of an integral or
9621 floating-point type, use the inner type. This is because we have no
9622 support for unnamed types in base_type_die. This can happen if this is
9623 an Ada subrange type. Correct solution is emit a subrange type die. */
9624 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
9625 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
9626 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
9628 if (code
== ERROR_MARK
9629 /* Handle a special case. For functions whose return type is void, we
9630 generate *no* type attribute. (Note that no object may have type
9631 `void', so this only applies to function return types). */
9632 || code
== VOID_TYPE
)
9635 type_die
= modified_type_die (type
,
9636 decl_const
|| TYPE_READONLY (type
),
9637 decl_volatile
|| TYPE_VOLATILE (type
),
9640 if (type_die
!= NULL
)
9641 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
9644 /* Given a tree pointer to a struct, class, union, or enum type node, return
9645 a pointer to the (string) tag name for the given type, or zero if the type
9646 was declared without a tag. */
9652 const char *name
= 0;
9654 if (TYPE_NAME (type
) != 0)
9658 /* Find the IDENTIFIER_NODE for the type name. */
9659 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9660 t
= TYPE_NAME (type
);
9662 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9663 a TYPE_DECL node, regardless of whether or not a `typedef' was
9665 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9666 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
9667 t
= DECL_NAME (TYPE_NAME (type
));
9669 /* Now get the name as a string, or invent one. */
9671 name
= IDENTIFIER_POINTER (t
);
9674 return (name
== 0 || *name
== '\0') ? 0 : name
;
9677 /* Return the type associated with a data member, make a special check
9678 for bit field types. */
9681 member_declared_type (member
)
9684 return (DECL_BIT_FIELD_TYPE (member
)
9685 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
9688 /* Get the decl's label, as described by its RTL. This may be different
9689 from the DECL_NAME name used in the source file. */
9693 decl_start_label (decl
)
9699 x
= DECL_RTL (decl
);
9700 if (GET_CODE (x
) != MEM
)
9704 if (GET_CODE (x
) != SYMBOL_REF
)
9707 fnname
= XSTR (x
, 0);
9712 /* These routines generate the internal representation of the DIE's for
9713 the compilation unit. Debugging information is collected by walking
9714 the declaration trees passed in from dwarf2out_decl(). */
9717 gen_array_type_die (type
, context_die
)
9719 dw_die_ref context_die
;
9721 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
9722 dw_die_ref array_die
;
9725 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9726 the inner array type comes before the outer array type. Thus we must
9727 call gen_type_die before we call new_die. See below also. */
9728 #ifdef MIPS_DEBUGGING_INFO
9729 gen_type_die (TREE_TYPE (type
), context_die
);
9732 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
9733 add_name_attribute (array_die
, type_tag (type
));
9734 equate_type_number_to_die (type
, array_die
);
9736 if (TREE_CODE (type
) == VECTOR_TYPE
)
9738 /* The frontend feeds us a representation for the vector as a struct
9739 containing an array. Pull out the array type. */
9740 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
9741 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
9745 /* We default the array ordering. SDB will probably do
9746 the right things even if DW_AT_ordering is not present. It's not even
9747 an issue until we start to get into multidimensional arrays anyway. If
9748 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9749 then we'll have to put the DW_AT_ordering attribute back in. (But if
9750 and when we find out that we need to put these in, we will only do so
9751 for multidimensional arrays. */
9752 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
9755 #ifdef MIPS_DEBUGGING_INFO
9756 /* The SGI compilers handle arrays of unknown bound by setting
9757 AT_declaration and not emitting any subrange DIEs. */
9758 if (! TYPE_DOMAIN (type
))
9759 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
9762 add_subscript_info (array_die
, type
);
9764 /* Add representation of the type of the elements of this array type. */
9765 element_type
= TREE_TYPE (type
);
9767 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9768 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9769 We work around this by disabling this feature. See also
9770 add_subscript_info. */
9771 #ifndef MIPS_DEBUGGING_INFO
9772 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
9773 element_type
= TREE_TYPE (element_type
);
9775 gen_type_die (element_type
, context_die
);
9778 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
9782 gen_set_type_die (type
, context_die
)
9784 dw_die_ref context_die
;
9787 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
9789 equate_type_number_to_die (type
, type_die
);
9790 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
9795 gen_entry_point_die (decl
, context_die
)
9797 dw_die_ref context_die
;
9799 tree origin
= decl_ultimate_origin (decl
);
9800 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
9803 add_abstract_origin_attribute (decl_die
, origin
);
9806 add_name_and_src_coords_attributes (decl_die
, decl
);
9807 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
9811 if (DECL_ABSTRACT (decl
))
9812 equate_decl_number_to_die (decl
, decl_die
);
9814 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
9818 /* Walk through the list of incomplete types again, trying once more to
9819 emit full debugging info for them. */
9822 retry_incomplete_types ()
9826 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
9827 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
9830 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9833 gen_inlined_enumeration_type_die (type
, context_die
)
9835 dw_die_ref context_die
;
9837 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
9839 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9840 be incomplete and such types are not marked. */
9841 add_abstract_origin_attribute (type_die
, type
);
9844 /* Generate a DIE to represent an inlined instance of a structure type. */
9847 gen_inlined_structure_type_die (type
, context_die
)
9849 dw_die_ref context_die
;
9851 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
9853 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9854 be incomplete and such types are not marked. */
9855 add_abstract_origin_attribute (type_die
, type
);
9858 /* Generate a DIE to represent an inlined instance of a union type. */
9861 gen_inlined_union_type_die (type
, context_die
)
9863 dw_die_ref context_die
;
9865 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
9867 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9868 be incomplete and such types are not marked. */
9869 add_abstract_origin_attribute (type_die
, type
);
9872 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9873 include all of the information about the enumeration values also. Each
9874 enumerated type name/value is listed as a child of the enumerated type
9878 gen_enumeration_type_die (type
, context_die
)
9880 dw_die_ref context_die
;
9882 dw_die_ref type_die
= lookup_type_die (type
);
9884 if (type_die
== NULL
)
9886 type_die
= new_die (DW_TAG_enumeration_type
,
9887 scope_die_for (type
, context_die
), type
);
9888 equate_type_number_to_die (type
, type_die
);
9889 add_name_attribute (type_die
, type_tag (type
));
9891 else if (! TYPE_SIZE (type
))
9894 remove_AT (type_die
, DW_AT_declaration
);
9896 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9897 given enum type is incomplete, do not generate the DW_AT_byte_size
9898 attribute or the DW_AT_element_list attribute. */
9899 if (TYPE_SIZE (type
))
9903 TREE_ASM_WRITTEN (type
) = 1;
9904 add_byte_size_attribute (type_die
, type
);
9905 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
9906 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
9908 /* If the first reference to this type was as the return type of an
9909 inline function, then it may not have a parent. Fix this now. */
9910 if (type_die
->die_parent
== NULL
)
9911 add_child_die (scope_die_for (type
, context_die
), type_die
);
9913 for (link
= TYPE_FIELDS (type
);
9914 link
!= NULL
; link
= TREE_CHAIN (link
))
9916 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
9918 add_name_attribute (enum_die
,
9919 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
9921 if (host_integerp (TREE_VALUE (link
), 0))
9923 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
9924 add_AT_int (enum_die
, DW_AT_const_value
,
9925 tree_low_cst (TREE_VALUE (link
), 0));
9927 add_AT_unsigned (enum_die
, DW_AT_const_value
,
9928 tree_low_cst (TREE_VALUE (link
), 0));
9933 add_AT_flag (type_die
, DW_AT_declaration
, 1);
9936 /* Generate a DIE to represent either a real live formal parameter decl or to
9937 represent just the type of some formal parameter position in some function
9940 Note that this routine is a bit unusual because its argument may be a
9941 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9942 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9943 node. If it's the former then this function is being called to output a
9944 DIE to represent a formal parameter object (or some inlining thereof). If
9945 it's the latter, then this function is only being called to output a
9946 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9947 argument type of some subprogram type. */
9950 gen_formal_parameter_die (node
, context_die
)
9952 dw_die_ref context_die
;
9955 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
9958 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
9961 origin
= decl_ultimate_origin (node
);
9963 add_abstract_origin_attribute (parm_die
, origin
);
9966 add_name_and_src_coords_attributes (parm_die
, node
);
9967 add_type_attribute (parm_die
, TREE_TYPE (node
),
9968 TREE_READONLY (node
),
9969 TREE_THIS_VOLATILE (node
),
9971 if (DECL_ARTIFICIAL (node
))
9972 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
9975 equate_decl_number_to_die (node
, parm_die
);
9976 if (! DECL_ABSTRACT (node
))
9977 add_location_or_const_value_attribute (parm_die
, node
);
9982 /* We were called with some kind of a ..._TYPE node. */
9983 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
9993 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9994 at the end of an (ANSI prototyped) formal parameters list. */
9997 gen_unspecified_parameters_die (decl_or_type
, context_die
)
9999 dw_die_ref context_die
;
10001 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10004 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10005 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10006 parameters as specified in some function type specification (except for
10007 those which appear as part of a function *definition*). */
10010 gen_formal_types_die (function_or_method_type
, context_die
)
10011 tree function_or_method_type
;
10012 dw_die_ref context_die
;
10015 tree formal_type
= NULL
;
10016 tree first_parm_type
;
10019 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10021 arg
= DECL_ARGUMENTS (function_or_method_type
);
10022 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10027 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10029 /* Make our first pass over the list of formal parameter types and output a
10030 DW_TAG_formal_parameter DIE for each one. */
10031 for (link
= first_parm_type
; link
; )
10033 dw_die_ref parm_die
;
10035 formal_type
= TREE_VALUE (link
);
10036 if (formal_type
== void_type_node
)
10039 /* Output a (nameless) DIE to represent the formal parameter itself. */
10040 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10041 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10042 && link
== first_parm_type
)
10043 || (arg
&& DECL_ARTIFICIAL (arg
)))
10044 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10046 link
= TREE_CHAIN (link
);
10048 arg
= TREE_CHAIN (arg
);
10051 /* If this function type has an ellipsis, add a
10052 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10053 if (formal_type
!= void_type_node
)
10054 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10056 /* Make our second (and final) pass over the list of formal parameter types
10057 and output DIEs to represent those types (as necessary). */
10058 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10059 link
&& TREE_VALUE (link
);
10060 link
= TREE_CHAIN (link
))
10061 gen_type_die (TREE_VALUE (link
), context_die
);
10064 /* We want to generate the DIE for TYPE so that we can generate the
10065 die for MEMBER, which has been defined; we will need to refer back
10066 to the member declaration nested within TYPE. If we're trying to
10067 generate minimal debug info for TYPE, processing TYPE won't do the
10068 trick; we need to attach the member declaration by hand. */
10071 gen_type_die_for_member (type
, member
, context_die
)
10073 dw_die_ref context_die
;
10075 gen_type_die (type
, context_die
);
10077 /* If we're trying to avoid duplicate debug info, we may not have
10078 emitted the member decl for this function. Emit it now. */
10079 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10080 && ! lookup_decl_die (member
))
10082 if (decl_ultimate_origin (member
))
10085 push_decl_scope (type
);
10086 if (TREE_CODE (member
) == FUNCTION_DECL
)
10087 gen_subprogram_die (member
, lookup_type_die (type
));
10089 gen_variable_die (member
, lookup_type_die (type
));
10095 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10096 may later generate inlined and/or out-of-line instances of. */
10099 dwarf2out_abstract_function (decl
)
10102 dw_die_ref old_die
;
10105 int was_abstract
= DECL_ABSTRACT (decl
);
10107 /* Make sure we have the actual abstract inline, not a clone. */
10108 decl
= DECL_ORIGIN (decl
);
10110 old_die
= lookup_decl_die (decl
);
10111 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10112 /* We've already generated the abstract instance. */
10115 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10116 we don't get confused by DECL_ABSTRACT. */
10117 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10119 context
= decl_class_context (decl
);
10121 gen_type_die_for_member
10122 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10125 /* Pretend we've just finished compiling this function. */
10126 save_fn
= current_function_decl
;
10127 current_function_decl
= decl
;
10129 set_decl_abstract_flags (decl
, 1);
10130 dwarf2out_decl (decl
);
10131 if (! was_abstract
)
10132 set_decl_abstract_flags (decl
, 0);
10134 current_function_decl
= save_fn
;
10137 /* Generate a DIE to represent a declared function (either file-scope or
10141 gen_subprogram_die (decl
, context_die
)
10143 dw_die_ref context_die
;
10145 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10146 tree origin
= decl_ultimate_origin (decl
);
10147 dw_die_ref subr_die
;
10151 dw_die_ref old_die
= lookup_decl_die (decl
);
10152 int declaration
= (current_function_decl
!= decl
10153 || class_scope_p (context_die
));
10155 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10156 started to generate the abstract instance of an inline, decided to output
10157 its containing class, and proceeded to emit the declaration of the inline
10158 from the member list for the class. If so, DECLARATION takes priority;
10159 we'll get back to the abstract instance when done with the class. */
10161 /* The class-scope declaration DIE must be the primary DIE. */
10162 if (origin
&& declaration
&& class_scope_p (context_die
))
10169 if (origin
!= NULL
)
10171 if (declaration
&& ! local_scope_p (context_die
))
10174 /* Fixup die_parent for the abstract instance of a nested
10175 inline function. */
10176 if (old_die
&& old_die
->die_parent
== NULL
)
10177 add_child_die (context_die
, old_die
);
10179 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10180 add_abstract_origin_attribute (subr_die
, origin
);
10184 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10186 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10187 /* We can have a normal definition following an inline one in the
10188 case of redefinition of GNU C extern inlines.
10189 It seems reasonable to use AT_specification in this case. */
10190 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10192 /* ??? This can happen if there is a bug in the program, for
10193 instance, if it has duplicate function definitions. Ideally,
10194 we should detect this case and ignore it. For now, if we have
10195 already reported an error, any error at all, then assume that
10196 we got here because of an input error, not a dwarf2 bug. */
10202 /* If the definition comes from the same place as the declaration,
10203 maybe use the old DIE. We always want the DIE for this function
10204 that has the *_pc attributes to be under comp_unit_die so the
10205 debugger can find it. We also need to do this for abstract
10206 instances of inlines, since the spec requires the out-of-line copy
10207 to have the same parent. For local class methods, this doesn't
10208 apply; we just use the old DIE. */
10209 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10210 && (DECL_ARTIFICIAL (decl
)
10211 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10212 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10213 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10215 subr_die
= old_die
;
10217 /* Clear out the declaration attribute and the parm types. */
10218 remove_AT (subr_die
, DW_AT_declaration
);
10219 remove_children (subr_die
);
10223 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10224 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10225 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10226 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10227 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10228 != (unsigned) DECL_SOURCE_LINE (decl
))
10230 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10235 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10237 if (TREE_PUBLIC (decl
))
10238 add_AT_flag (subr_die
, DW_AT_external
, 1);
10240 add_name_and_src_coords_attributes (subr_die
, decl
);
10241 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10243 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10244 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10245 0, 0, context_die
);
10248 add_pure_or_virtual_attribute (subr_die
, decl
);
10249 if (DECL_ARTIFICIAL (decl
))
10250 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10252 if (TREE_PROTECTED (decl
))
10253 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10254 else if (TREE_PRIVATE (decl
))
10255 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10260 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10262 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10264 /* The first time we see a member function, it is in the context of
10265 the class to which it belongs. We make sure of this by emitting
10266 the class first. The next time is the definition, which is
10267 handled above. The two may come from the same source text. */
10268 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10269 equate_decl_number_to_die (decl
, subr_die
);
10272 else if (DECL_ABSTRACT (decl
))
10274 if (DECL_INLINE (decl
) && !flag_no_inline
)
10276 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10277 inline functions, but not for extern inline functions.
10278 We can't get this completely correct because information
10279 about whether the function was declared inline is not
10281 if (DECL_DEFER_OUTPUT (decl
))
10282 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10284 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10287 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10289 equate_decl_number_to_die (decl
, subr_die
);
10291 else if (!DECL_EXTERNAL (decl
))
10293 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10294 equate_decl_number_to_die (decl
, subr_die
);
10296 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10297 current_function_funcdef_no
);
10298 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10299 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10300 current_function_funcdef_no
);
10301 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10303 add_pubname (decl
, subr_die
);
10304 add_arange (decl
, subr_die
);
10306 #ifdef MIPS_DEBUGGING_INFO
10307 /* Add a reference to the FDE for this routine. */
10308 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10311 /* Define the "frame base" location for this routine. We use the
10312 frame pointer or stack pointer registers, since the RTL for local
10313 variables is relative to one of them. */
10315 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10316 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10319 /* ??? This fails for nested inline functions, because context_display
10320 is not part of the state saved/restored for inline functions. */
10321 if (current_function_needs_context
)
10322 add_AT_location_description (subr_die
, DW_AT_static_link
,
10323 lookup_static_chain (decl
));
10327 /* Now output descriptions of the arguments for this function. This gets
10328 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10329 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10330 `...' at the end of the formal parameter list. In order to find out if
10331 there was a trailing ellipsis or not, we must instead look at the type
10332 associated with the FUNCTION_DECL. This will be a node of type
10333 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10334 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10335 an ellipsis at the end. */
10337 /* In the case where we are describing a mere function declaration, all we
10338 need to do here (and all we *can* do here) is to describe the *types* of
10339 its formal parameters. */
10340 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10342 else if (declaration
)
10343 gen_formal_types_die (decl
, subr_die
);
10346 /* Generate DIEs to represent all known formal parameters */
10347 tree arg_decls
= DECL_ARGUMENTS (decl
);
10350 /* When generating DIEs, generate the unspecified_parameters DIE
10351 instead if we come across the arg "__builtin_va_alist" */
10352 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10353 if (TREE_CODE (parm
) == PARM_DECL
)
10355 if (DECL_NAME (parm
)
10356 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10357 "__builtin_va_alist"))
10358 gen_unspecified_parameters_die (parm
, subr_die
);
10360 gen_decl_die (parm
, subr_die
);
10363 /* Decide whether we need an unspecified_parameters DIE at the end.
10364 There are 2 more cases to do this for: 1) the ansi ... declaration -
10365 this is detectable when the end of the arg list is not a
10366 void_type_node 2) an unprototyped function declaration (not a
10367 definition). This just means that we have no info about the
10368 parameters at all. */
10369 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10370 if (fn_arg_types
!= NULL
)
10372 /* this is the prototyped case, check for ... */
10373 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10374 gen_unspecified_parameters_die (decl
, subr_die
);
10376 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10377 gen_unspecified_parameters_die (decl
, subr_die
);
10380 /* Output Dwarf info for all of the stuff within the body of the function
10381 (if it has one - it may be just a declaration). */
10382 outer_scope
= DECL_INITIAL (decl
);
10384 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10385 a function. This BLOCK actually represents the outermost binding contour
10386 for the function, i.e. the contour in which the function's formal
10387 parameters and labels get declared. Curiously, it appears that the front
10388 end doesn't actually put the PARM_DECL nodes for the current function onto
10389 the BLOCK_VARS list for this outer scope, but are strung off of the
10390 DECL_ARGUMENTS list for the function instead.
10392 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10393 the LABEL_DECL nodes for the function however, and we output DWARF info
10394 for those in decls_for_scope. Just within the `outer_scope' there will be
10395 a BLOCK node representing the function's outermost pair of curly braces,
10396 and any blocks used for the base and member initializers of a C++
10397 constructor function. */
10398 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10400 current_function_has_inlines
= 0;
10401 decls_for_scope (outer_scope
, subr_die
, 0);
10403 #if 0 && defined (MIPS_DEBUGGING_INFO)
10404 if (current_function_has_inlines
)
10406 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10407 if (! comp_unit_has_inlines
)
10409 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10410 comp_unit_has_inlines
= 1;
10417 /* Generate a DIE to represent a declared data object. */
10420 gen_variable_die (decl
, context_die
)
10422 dw_die_ref context_die
;
10424 tree origin
= decl_ultimate_origin (decl
);
10425 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10427 dw_die_ref old_die
= lookup_decl_die (decl
);
10428 int declaration
= (DECL_EXTERNAL (decl
)
10429 || class_scope_p (context_die
));
10431 if (origin
!= NULL
)
10432 add_abstract_origin_attribute (var_die
, origin
);
10434 /* Loop unrolling can create multiple blocks that refer to the same
10435 static variable, so we must test for the DW_AT_declaration flag.
10437 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10438 copy decls and set the DECL_ABSTRACT flag on them instead of
10441 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10442 else if (old_die
&& TREE_STATIC (decl
)
10443 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10445 /* This is a definition of a C++ class level static. */
10446 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10447 if (DECL_NAME (decl
))
10449 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10451 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10452 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10454 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10455 != (unsigned) DECL_SOURCE_LINE (decl
))
10457 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10458 DECL_SOURCE_LINE (decl
));
10463 add_name_and_src_coords_attributes (var_die
, decl
);
10464 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10465 TREE_THIS_VOLATILE (decl
), context_die
);
10467 if (TREE_PUBLIC (decl
))
10468 add_AT_flag (var_die
, DW_AT_external
, 1);
10470 if (DECL_ARTIFICIAL (decl
))
10471 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10473 if (TREE_PROTECTED (decl
))
10474 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10475 else if (TREE_PRIVATE (decl
))
10476 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10480 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10482 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10483 equate_decl_number_to_die (decl
, var_die
);
10485 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10487 add_location_or_const_value_attribute (var_die
, decl
);
10488 add_pubname (decl
, var_die
);
10491 tree_add_const_value_attribute (var_die
, decl
);
10494 /* Generate a DIE to represent a label identifier. */
10497 gen_label_die (decl
, context_die
)
10499 dw_die_ref context_die
;
10501 tree origin
= decl_ultimate_origin (decl
);
10502 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10504 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10506 if (origin
!= NULL
)
10507 add_abstract_origin_attribute (lbl_die
, origin
);
10509 add_name_and_src_coords_attributes (lbl_die
, decl
);
10511 if (DECL_ABSTRACT (decl
))
10512 equate_decl_number_to_die (decl
, lbl_die
);
10515 insn
= DECL_RTL (decl
);
10517 /* Deleted labels are programmer specified labels which have been
10518 eliminated because of various optimisations. We still emit them
10519 here so that it is possible to put breakpoints on them. */
10520 if (GET_CODE (insn
) == CODE_LABEL
10521 || ((GET_CODE (insn
) == NOTE
10522 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10524 /* When optimization is enabled (via -O) some parts of the compiler
10525 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10526 represent source-level labels which were explicitly declared by
10527 the user. This really shouldn't be happening though, so catch
10528 it if it ever does happen. */
10529 if (INSN_DELETED_P (insn
))
10532 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10533 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10538 /* Generate a DIE for a lexical block. */
10541 gen_lexical_block_die (stmt
, context_die
, depth
)
10543 dw_die_ref context_die
;
10546 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10547 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10549 if (! BLOCK_ABSTRACT (stmt
))
10551 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10555 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10557 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10560 add_ranges (chain
);
10561 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10568 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10569 BLOCK_NUMBER (stmt
));
10570 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10571 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10572 BLOCK_NUMBER (stmt
));
10573 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10577 decls_for_scope (stmt
, stmt_die
, depth
);
10580 /* Generate a DIE for an inlined subprogram. */
10583 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
10585 dw_die_ref context_die
;
10588 if (! BLOCK_ABSTRACT (stmt
))
10590 dw_die_ref subr_die
10591 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10592 tree decl
= block_ultimate_origin (stmt
);
10593 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10595 /* Emit info for the abstract instance first, if we haven't yet. */
10596 dwarf2out_abstract_function (decl
);
10598 add_abstract_origin_attribute (subr_die
, decl
);
10599 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10600 BLOCK_NUMBER (stmt
));
10601 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10602 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10603 BLOCK_NUMBER (stmt
));
10604 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10605 decls_for_scope (stmt
, subr_die
, depth
);
10606 current_function_has_inlines
= 1;
10609 /* We may get here if we're the outer block of function A that was
10610 inlined into function B that was inlined into function C. When
10611 generating debugging info for C, dwarf2out_abstract_function(B)
10612 would mark all inlined blocks as abstract, including this one.
10613 So, we wouldn't (and shouldn't) expect labels to be generated
10614 for this one. Instead, just emit debugging info for
10615 declarations within the block. This is particularly important
10616 in the case of initializers of arguments passed from B to us:
10617 if they're statement expressions containing declarations, we
10618 wouldn't generate dies for their abstract variables, and then,
10619 when generating dies for the real variables, we'd die (pun
10621 gen_lexical_block_die (stmt
, context_die
, depth
);
10624 /* Generate a DIE for a field in a record, or structure. */
10627 gen_field_die (decl
, context_die
)
10629 dw_die_ref context_die
;
10631 dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
10633 add_name_and_src_coords_attributes (decl_die
, decl
);
10634 add_type_attribute (decl_die
, member_declared_type (decl
),
10635 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
10638 if (DECL_BIT_FIELD_TYPE (decl
))
10640 add_byte_size_attribute (decl_die
, decl
);
10641 add_bit_size_attribute (decl_die
, decl
);
10642 add_bit_offset_attribute (decl_die
, decl
);
10645 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
10646 add_data_member_location_attribute (decl_die
, decl
);
10648 if (DECL_ARTIFICIAL (decl
))
10649 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10651 if (TREE_PROTECTED (decl
))
10652 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10653 else if (TREE_PRIVATE (decl
))
10654 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10658 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10659 Use modified_type_die instead.
10660 We keep this code here just in case these types of DIEs may be needed to
10661 represent certain things in other languages (e.g. Pascal) someday. */
10664 gen_pointer_type_die (type
, context_die
)
10666 dw_die_ref context_die
;
10669 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
10671 equate_type_number_to_die (type
, ptr_die
);
10672 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10673 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10676 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10677 Use modified_type_die instead.
10678 We keep this code here just in case these types of DIEs may be needed to
10679 represent certain things in other languages (e.g. Pascal) someday. */
10682 gen_reference_type_die (type
, context_die
)
10684 dw_die_ref context_die
;
10687 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
10689 equate_type_number_to_die (type
, ref_die
);
10690 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
10691 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10695 /* Generate a DIE for a pointer to a member type. */
10698 gen_ptr_to_mbr_type_die (type
, context_die
)
10700 dw_die_ref context_die
;
10703 = new_die (DW_TAG_ptr_to_member_type
,
10704 scope_die_for (type
, context_die
), type
);
10706 equate_type_number_to_die (type
, ptr_die
);
10707 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
10708 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
10709 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10712 /* Generate the DIE for the compilation unit. */
10715 gen_compile_unit_die (filename
)
10716 const char *filename
;
10719 char producer
[250];
10720 const char *wd
= getpwd ();
10721 const char *language_string
= lang_hooks
.name
;
10724 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
10725 add_name_attribute (die
, filename
);
10727 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
10728 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10730 sprintf (producer
, "%s %s", language_string
, version_string
);
10732 #ifdef MIPS_DEBUGGING_INFO
10733 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10734 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10735 not appear in the producer string, the debugger reaches the conclusion
10736 that the object file is stripped and has no debugging information.
10737 To get the MIPS/SGI debugger to believe that there is debugging
10738 information in the object file, we add a -g to the producer string. */
10739 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10740 strcat (producer
, " -g");
10743 add_AT_string (die
, DW_AT_producer
, producer
);
10745 if (strcmp (language_string
, "GNU C++") == 0)
10746 language
= DW_LANG_C_plus_plus
;
10747 else if (strcmp (language_string
, "GNU Ada") == 0)
10748 language
= DW_LANG_Ada83
;
10749 else if (strcmp (language_string
, "GNU F77") == 0)
10750 language
= DW_LANG_Fortran77
;
10751 else if (strcmp (language_string
, "GNU Pascal") == 0)
10752 language
= DW_LANG_Pascal83
;
10753 else if (strcmp (language_string
, "GNU Java") == 0)
10754 language
= DW_LANG_Java
;
10756 language
= DW_LANG_C89
;
10758 add_AT_unsigned (die
, DW_AT_language
, language
);
10762 /* Generate a DIE for a string type. */
10765 gen_string_type_die (type
, context_die
)
10767 dw_die_ref context_die
;
10769 dw_die_ref type_die
10770 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
10772 equate_type_number_to_die (type
, type_die
);
10774 /* ??? Fudge the string length attribute for now.
10775 TODO: add string length info. */
10777 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
10778 bound_representation (upper_bound
, 0, 'u');
10782 /* Generate the DIE for a base class. */
10785 gen_inheritance_die (binfo
, context_die
)
10787 dw_die_ref context_die
;
10789 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
10791 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
10792 add_data_member_location_attribute (die
, binfo
);
10794 if (TREE_VIA_VIRTUAL (binfo
))
10795 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10797 if (TREE_VIA_PUBLIC (binfo
))
10798 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
10799 else if (TREE_VIA_PROTECTED (binfo
))
10800 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10803 /* Generate a DIE for a class member. */
10806 gen_member_die (type
, context_die
)
10808 dw_die_ref context_die
;
10813 /* If this is not an incomplete type, output descriptions of each of its
10814 members. Note that as we output the DIEs necessary to represent the
10815 members of this record or union type, we will also be trying to output
10816 DIEs to represent the *types* of those members. However the `type'
10817 function (above) will specifically avoid generating type DIEs for member
10818 types *within* the list of member DIEs for this (containing) type except
10819 for those types (of members) which are explicitly marked as also being
10820 members of this (containing) type themselves. The g++ front- end can
10821 force any given type to be treated as a member of some other (containing)
10822 type by setting the TYPE_CONTEXT of the given (member) type to point to
10823 the TREE node representing the appropriate (containing) type. */
10825 /* First output info about the base classes. */
10826 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
10828 tree bases
= TYPE_BINFO_BASETYPES (type
);
10829 int n_bases
= TREE_VEC_LENGTH (bases
);
10832 for (i
= 0; i
< n_bases
; i
++)
10833 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
10836 /* Now output info about the data members and type members. */
10837 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
10839 /* If we thought we were generating minimal debug info for TYPE
10840 and then changed our minds, some of the member declarations
10841 may have already been defined. Don't define them again, but
10842 do put them in the right order. */
10844 child
= lookup_decl_die (member
);
10846 splice_child_die (context_die
, child
);
10848 gen_decl_die (member
, context_die
);
10851 /* Now output info about the function members (if any). */
10852 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
10854 /* Don't include clones in the member list. */
10855 if (DECL_ABSTRACT_ORIGIN (member
))
10858 child
= lookup_decl_die (member
);
10860 splice_child_die (context_die
, child
);
10862 gen_decl_die (member
, context_die
);
10866 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10867 is set, we pretend that the type was never defined, so we only get the
10868 member DIEs needed by later specification DIEs. */
10871 gen_struct_or_union_type_die (type
, context_die
)
10873 dw_die_ref context_die
;
10875 dw_die_ref type_die
= lookup_type_die (type
);
10876 dw_die_ref scope_die
= 0;
10878 int complete
= (TYPE_SIZE (type
)
10879 && (! TYPE_STUB_DECL (type
)
10880 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
10882 if (type_die
&& ! complete
)
10885 if (TYPE_CONTEXT (type
) != NULL_TREE
10886 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
10889 scope_die
= scope_die_for (type
, context_die
);
10891 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
10892 /* First occurrence of type or toplevel definition of nested class. */
10894 dw_die_ref old_die
= type_die
;
10896 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
10897 ? DW_TAG_structure_type
: DW_TAG_union_type
,
10899 equate_type_number_to_die (type
, type_die
);
10901 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
10903 add_name_attribute (type_die
, type_tag (type
));
10906 remove_AT (type_die
, DW_AT_declaration
);
10908 /* If this type has been completed, then give it a byte_size attribute and
10909 then give a list of members. */
10912 /* Prevent infinite recursion in cases where the type of some member of
10913 this type is expressed in terms of this type itself. */
10914 TREE_ASM_WRITTEN (type
) = 1;
10915 add_byte_size_attribute (type_die
, type
);
10916 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10917 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10919 /* If the first reference to this type was as the return type of an
10920 inline function, then it may not have a parent. Fix this now. */
10921 if (type_die
->die_parent
== NULL
)
10922 add_child_die (scope_die
, type_die
);
10924 push_decl_scope (type
);
10925 gen_member_die (type
, type_die
);
10928 /* GNU extension: Record what type our vtable lives in. */
10929 if (TYPE_VFIELD (type
))
10931 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
10933 gen_type_die (vtype
, context_die
);
10934 add_AT_die_ref (type_die
, DW_AT_containing_type
,
10935 lookup_type_die (vtype
));
10940 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10942 /* We don't need to do this for function-local types. */
10943 if (TYPE_STUB_DECL (type
)
10944 && ! decl_function_context (TYPE_STUB_DECL (type
)))
10945 VARRAY_PUSH_TREE (incomplete_types
, type
);
10949 /* Generate a DIE for a subroutine _type_. */
10952 gen_subroutine_type_die (type
, context_die
)
10954 dw_die_ref context_die
;
10956 tree return_type
= TREE_TYPE (type
);
10957 dw_die_ref subr_die
10958 = new_die (DW_TAG_subroutine_type
,
10959 scope_die_for (type
, context_die
), type
);
10961 equate_type_number_to_die (type
, subr_die
);
10962 add_prototyped_attribute (subr_die
, type
);
10963 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
10964 gen_formal_types_die (type
, subr_die
);
10967 /* Generate a DIE for a type definition */
10970 gen_typedef_die (decl
, context_die
)
10972 dw_die_ref context_die
;
10974 dw_die_ref type_die
;
10977 if (TREE_ASM_WRITTEN (decl
))
10980 TREE_ASM_WRITTEN (decl
) = 1;
10981 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
10982 origin
= decl_ultimate_origin (decl
);
10983 if (origin
!= NULL
)
10984 add_abstract_origin_attribute (type_die
, origin
);
10989 add_name_and_src_coords_attributes (type_die
, decl
);
10990 if (DECL_ORIGINAL_TYPE (decl
))
10992 type
= DECL_ORIGINAL_TYPE (decl
);
10994 if (type
== TREE_TYPE (decl
))
10997 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11000 type
= TREE_TYPE (decl
);
11002 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11003 TREE_THIS_VOLATILE (decl
), context_die
);
11006 if (DECL_ABSTRACT (decl
))
11007 equate_decl_number_to_die (decl
, type_die
);
11010 /* Generate a type description DIE. */
11013 gen_type_die (type
, context_die
)
11015 dw_die_ref context_die
;
11019 if (type
== NULL_TREE
|| type
== error_mark_node
)
11022 /* We are going to output a DIE to represent the unqualified version
11023 of this type (i.e. without any const or volatile qualifiers) so
11024 get the main variant (i.e. the unqualified version) of this type
11025 now. (Vectors are special because the debugging info is in the
11026 cloned type itself). */
11027 if (TREE_CODE (type
) != VECTOR_TYPE
)
11028 type
= type_main_variant (type
);
11030 if (TREE_ASM_WRITTEN (type
))
11033 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11034 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11036 /* Prevent broken recursion; we can't hand off to the same type. */
11037 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11040 TREE_ASM_WRITTEN (type
) = 1;
11041 gen_decl_die (TYPE_NAME (type
), context_die
);
11045 switch (TREE_CODE (type
))
11051 case REFERENCE_TYPE
:
11052 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11053 ensures that the gen_type_die recursion will terminate even if the
11054 type is recursive. Recursive types are possible in Ada. */
11055 /* ??? We could perhaps do this for all types before the switch
11057 TREE_ASM_WRITTEN (type
) = 1;
11059 /* For these types, all that is required is that we output a DIE (or a
11060 set of DIEs) to represent the "basis" type. */
11061 gen_type_die (TREE_TYPE (type
), context_die
);
11065 /* This code is used for C++ pointer-to-data-member types.
11066 Output a description of the relevant class type. */
11067 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11069 /* Output a description of the type of the object pointed to. */
11070 gen_type_die (TREE_TYPE (type
), context_die
);
11072 /* Now output a DIE to represent this pointer-to-data-member type
11074 gen_ptr_to_mbr_type_die (type
, context_die
);
11078 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11079 gen_set_type_die (type
, context_die
);
11083 gen_type_die (TREE_TYPE (type
), context_die
);
11084 abort (); /* No way to represent these in Dwarf yet! */
11087 case FUNCTION_TYPE
:
11088 /* Force out return type (in case it wasn't forced out already). */
11089 gen_type_die (TREE_TYPE (type
), context_die
);
11090 gen_subroutine_type_die (type
, context_die
);
11094 /* Force out return type (in case it wasn't forced out already). */
11095 gen_type_die (TREE_TYPE (type
), context_die
);
11096 gen_subroutine_type_die (type
, context_die
);
11100 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11102 gen_type_die (TREE_TYPE (type
), context_die
);
11103 gen_string_type_die (type
, context_die
);
11106 gen_array_type_die (type
, context_die
);
11110 gen_array_type_die (type
, context_die
);
11113 case ENUMERAL_TYPE
:
11116 case QUAL_UNION_TYPE
:
11117 /* If this is a nested type whose containing class hasn't been written
11118 out yet, writing it out will cover this one, too. This does not apply
11119 to instantiations of member class templates; they need to be added to
11120 the containing class as they are generated. FIXME: This hurts the
11121 idea of combining type decls from multiple TUs, since we can't predict
11122 what set of template instantiations we'll get. */
11123 if (TYPE_CONTEXT (type
)
11124 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11125 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11127 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11129 if (TREE_ASM_WRITTEN (type
))
11132 /* If that failed, attach ourselves to the stub. */
11133 push_decl_scope (TYPE_CONTEXT (type
));
11134 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11140 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11141 gen_enumeration_type_die (type
, context_die
);
11143 gen_struct_or_union_type_die (type
, context_die
);
11148 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11149 it up if it is ever completed. gen_*_type_die will set it for us
11150 when appropriate. */
11159 /* No DIEs needed for fundamental types. */
11163 /* No Dwarf representation currently defined. */
11170 TREE_ASM_WRITTEN (type
) = 1;
11173 /* Generate a DIE for a tagged type instantiation. */
11176 gen_tagged_type_instantiation_die (type
, context_die
)
11178 dw_die_ref context_die
;
11180 if (type
== NULL_TREE
|| type
== error_mark_node
)
11183 /* We are going to output a DIE to represent the unqualified version of
11184 this type (i.e. without any const or volatile qualifiers) so make sure
11185 that we have the main variant (i.e. the unqualified version) of this
11187 if (type
!= type_main_variant (type
))
11190 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11191 an instance of an unresolved type. */
11193 switch (TREE_CODE (type
))
11198 case ENUMERAL_TYPE
:
11199 gen_inlined_enumeration_type_die (type
, context_die
);
11203 gen_inlined_structure_type_die (type
, context_die
);
11207 case QUAL_UNION_TYPE
:
11208 gen_inlined_union_type_die (type
, context_die
);
11216 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11217 things which are local to the given block. */
11220 gen_block_die (stmt
, context_die
, depth
)
11222 dw_die_ref context_die
;
11225 int must_output_die
= 0;
11228 enum tree_code origin_code
;
11230 /* Ignore blocks never really used to make RTL. */
11231 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11232 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11235 /* If the block is one fragment of a non-contiguous block, do not
11236 process the variables, since they will have been done by the
11237 origin block. Do process subblocks. */
11238 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11242 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11243 gen_block_die (sub
, context_die
, depth
+ 1);
11248 /* Determine the "ultimate origin" of this block. This block may be an
11249 inlined instance of an inlined instance of inline function, so we have
11250 to trace all of the way back through the origin chain to find out what
11251 sort of node actually served as the original seed for the creation of
11252 the current block. */
11253 origin
= block_ultimate_origin (stmt
);
11254 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11256 /* Determine if we need to output any Dwarf DIEs at all to represent this
11258 if (origin_code
== FUNCTION_DECL
)
11259 /* The outer scopes for inlinings *must* always be represented. We
11260 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11261 must_output_die
= 1;
11264 /* In the case where the current block represents an inlining of the
11265 "body block" of an inline function, we must *NOT* output any DIE for
11266 this block because we have already output a DIE to represent the whole
11267 inlined function scope and the "body block" of any function doesn't
11268 really represent a different scope according to ANSI C rules. So we
11269 check here to make sure that this block does not represent a "body
11270 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11271 if (! is_body_block (origin
? origin
: stmt
))
11273 /* Determine if this block directly contains any "significant"
11274 local declarations which we will need to output DIEs for. */
11275 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11276 /* We are not in terse mode so *any* local declaration counts
11277 as being a "significant" one. */
11278 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11280 /* We are in terse mode, so only local (nested) function
11281 definitions count as "significant" local declarations. */
11282 for (decl
= BLOCK_VARS (stmt
);
11283 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11284 if (TREE_CODE (decl
) == FUNCTION_DECL
11285 && DECL_INITIAL (decl
))
11287 must_output_die
= 1;
11293 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11294 DIE for any block which contains no significant local declarations at
11295 all. Rather, in such cases we just call `decls_for_scope' so that any
11296 needed Dwarf info for any sub-blocks will get properly generated. Note
11297 that in terse mode, our definition of what constitutes a "significant"
11298 local declaration gets restricted to include only inlined function
11299 instances and local (nested) function definitions. */
11300 if (must_output_die
)
11302 if (origin_code
== FUNCTION_DECL
)
11303 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11305 gen_lexical_block_die (stmt
, context_die
, depth
);
11308 decls_for_scope (stmt
, context_die
, depth
);
11311 /* Generate all of the decls declared within a given scope and (recursively)
11312 all of its sub-blocks. */
11315 decls_for_scope (stmt
, context_die
, depth
)
11317 dw_die_ref context_die
;
11323 /* Ignore blocks never really used to make RTL. */
11324 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11327 /* Output the DIEs to represent all of the data objects and typedefs
11328 declared directly within this block but not within any nested
11329 sub-blocks. Also, nested function and tag DIEs have been
11330 generated with a parent of NULL; fix that up now. */
11331 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11335 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11336 die
= lookup_decl_die (decl
);
11337 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11338 die
= lookup_type_die (TREE_TYPE (decl
));
11342 if (die
!= NULL
&& die
->die_parent
== NULL
)
11343 add_child_die (context_die
, die
);
11345 gen_decl_die (decl
, context_die
);
11348 /* Output the DIEs to represent all sub-blocks (and the items declared
11349 therein) of this block. */
11350 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11352 subblocks
= BLOCK_CHAIN (subblocks
))
11353 gen_block_die (subblocks
, context_die
, depth
+ 1);
11356 /* Is this a typedef we can avoid emitting? */
11359 is_redundant_typedef (decl
)
11362 if (TYPE_DECL_IS_STUB (decl
))
11365 if (DECL_ARTIFICIAL (decl
)
11366 && DECL_CONTEXT (decl
)
11367 && is_tagged_type (DECL_CONTEXT (decl
))
11368 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11369 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11370 /* Also ignore the artificial member typedef for the class name. */
11376 /* Generate Dwarf debug information for a decl described by DECL. */
11379 gen_decl_die (decl
, context_die
)
11381 dw_die_ref context_die
;
11385 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11388 switch (TREE_CODE (decl
))
11394 /* The individual enumerators of an enum type get output when we output
11395 the Dwarf representation of the relevant enum type itself. */
11398 case FUNCTION_DECL
:
11399 /* Don't output any DIEs to represent mere function declarations,
11400 unless they are class members or explicit block externs. */
11401 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11402 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11405 /* If we're emitting a clone, emit info for the abstract instance. */
11406 if (DECL_ORIGIN (decl
) != decl
)
11407 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11409 /* If we're emitting an out-of-line copy of an inline function,
11410 emit info for the abstract instance and set up to refer to it. */
11411 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11412 && ! class_scope_p (context_die
)
11413 /* dwarf2out_abstract_function won't emit a die if this is just
11414 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11415 that case, because that works only if we have a die. */
11416 && DECL_INITIAL (decl
) != NULL_TREE
)
11418 dwarf2out_abstract_function (decl
);
11419 set_decl_origin_self (decl
);
11422 /* Otherwise we're emitting the primary DIE for this decl. */
11423 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11425 /* Before we describe the FUNCTION_DECL itself, make sure that we
11426 have described its return type. */
11427 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11429 /* And its virtual context. */
11430 if (DECL_VINDEX (decl
) != NULL_TREE
)
11431 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11433 /* And its containing type. */
11434 origin
= decl_class_context (decl
);
11435 if (origin
!= NULL_TREE
)
11436 gen_type_die_for_member (origin
, decl
, context_die
);
11439 /* Now output a DIE to represent the function itself. */
11440 gen_subprogram_die (decl
, context_die
);
11444 /* If we are in terse mode, don't generate any DIEs to represent any
11445 actual typedefs. */
11446 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11449 /* In the special case of a TYPE_DECL node representing the declaration
11450 of some type tag, if the given TYPE_DECL is marked as having been
11451 instantiated from some other (original) TYPE_DECL node (e.g. one which
11452 was generated within the original definition of an inline function) we
11453 have to generate a special (abbreviated) DW_TAG_structure_type,
11454 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11455 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11457 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11461 if (is_redundant_typedef (decl
))
11462 gen_type_die (TREE_TYPE (decl
), context_die
);
11464 /* Output a DIE to represent the typedef itself. */
11465 gen_typedef_die (decl
, context_die
);
11469 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11470 gen_label_die (decl
, context_die
);
11474 /* If we are in terse mode, don't generate any DIEs to represent any
11475 variable declarations or definitions. */
11476 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11479 /* Output any DIEs that are needed to specify the type of this data
11481 gen_type_die (TREE_TYPE (decl
), context_die
);
11483 /* And its containing type. */
11484 origin
= decl_class_context (decl
);
11485 if (origin
!= NULL_TREE
)
11486 gen_type_die_for_member (origin
, decl
, context_die
);
11488 /* Now output the DIE to represent the data object itself. This gets
11489 complicated because of the possibility that the VAR_DECL really
11490 represents an inlined instance of a formal parameter for an inline
11492 origin
= decl_ultimate_origin (decl
);
11493 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11494 gen_formal_parameter_die (decl
, context_die
);
11496 gen_variable_die (decl
, context_die
);
11500 /* Ignore the nameless fields that are used to skip bits but handle C++
11501 anonymous unions. */
11502 if (DECL_NAME (decl
) != NULL_TREE
11503 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11505 gen_type_die (member_declared_type (decl
), context_die
);
11506 gen_field_die (decl
, context_die
);
11511 gen_type_die (TREE_TYPE (decl
), context_die
);
11512 gen_formal_parameter_die (decl
, context_die
);
11515 case NAMESPACE_DECL
:
11516 /* Ignore for now. */
11525 mark_limbo_die_list (ptr
)
11526 void *ptr ATTRIBUTE_UNUSED
;
11528 limbo_die_node
*node
;
11529 for (node
= limbo_die_list
; node
; node
= node
->next
)
11530 ggc_mark_tree (node
->created_for
);
11533 /* Add Ada "use" clause information for SGI Workshop debugger. */
11536 dwarf2out_add_library_unit_info (filename
, context_list
)
11537 const char *filename
;
11538 const char *context_list
;
11540 unsigned int file_index
;
11542 if (filename
!= NULL
)
11544 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11545 tree context_list_decl
11546 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11549 TREE_PUBLIC (context_list_decl
) = TRUE
;
11550 add_name_attribute (unit_die
, context_list
);
11551 file_index
= lookup_filename (filename
);
11552 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11553 add_pubname (context_list_decl
, unit_die
);
11557 /* Output debug information for global decl DECL. Called from toplev.c after
11558 compilation proper has finished. */
11561 dwarf2out_global_decl (decl
)
11564 /* Output DWARF2 information for file-scope tentative data object
11565 declarations, file-scope (extern) function declarations (which had no
11566 corresponding body) and file-scope tagged type declarations and
11567 definitions which have not yet been forced out. */
11568 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11569 dwarf2out_decl (decl
);
11572 /* Write the debugging output for DECL. */
11575 dwarf2out_decl (decl
)
11578 dw_die_ref context_die
= comp_unit_die
;
11580 switch (TREE_CODE (decl
))
11585 case FUNCTION_DECL
:
11586 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11587 builtin function. Explicit programmer-supplied declarations of
11588 these same functions should NOT be ignored however. */
11589 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11592 /* What we would really like to do here is to filter out all mere
11593 file-scope declarations of file-scope functions which are never
11594 referenced later within this translation unit (and keep all of ones
11595 that *are* referenced later on) but we aren't clairvoyant, so we have
11596 no idea which functions will be referenced in the future (i.e. later
11597 on within the current translation unit). So here we just ignore all
11598 file-scope function declarations which are not also definitions. If
11599 and when the debugger needs to know something about these functions,
11600 it will have to hunt around and find the DWARF information associated
11601 with the definition of the function.
11603 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11604 nodes represent definitions and which ones represent mere
11605 declarations. We have to check DECL_INITIAL instead. That's because
11606 the C front-end supports some weird semantics for "extern inline"
11607 function definitions. These can get inlined within the current
11608 translation unit (an thus, we need to generate Dwarf info for their
11609 abstract instances so that the Dwarf info for the concrete inlined
11610 instances can have something to refer to) but the compiler never
11611 generates any out-of-lines instances of such things (despite the fact
11612 that they *are* definitions).
11614 The important point is that the C front-end marks these "extern
11615 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11616 them anyway. Note that the C++ front-end also plays some similar games
11617 for inline function definitions appearing within include files which
11618 also contain `#pragma interface' pragmas. */
11619 if (DECL_INITIAL (decl
) == NULL_TREE
)
11622 /* If we're a nested function, initially use a parent of NULL; if we're
11623 a plain function, this will be fixed up in decls_for_scope. If
11624 we're a method, it will be ignored, since we already have a DIE. */
11625 if (decl_function_context (decl
))
11626 context_die
= NULL
;
11630 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11631 declaration and if the declaration was never even referenced from
11632 within this entire compilation unit. We suppress these DIEs in
11633 order to save space in the .debug section (by eliminating entries
11634 which are probably useless). Note that we must not suppress
11635 block-local extern declarations (whether used or not) because that
11636 would screw-up the debugger's name lookup mechanism and cause it to
11637 miss things which really ought to be in scope at a given point. */
11638 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11641 /* If we are in terse mode, don't generate any DIEs to represent any
11642 variable declarations or definitions. */
11643 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11648 /* Don't emit stubs for types unless they are needed by other DIEs. */
11649 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
11652 /* Don't bother trying to generate any DIEs to represent any of the
11653 normal built-in types for the language we are compiling. */
11654 if (DECL_SOURCE_LINE (decl
) == 0)
11656 /* OK, we need to generate one for `bool' so GDB knows what type
11657 comparisons have. */
11658 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
11659 == DW_LANG_C_plus_plus
)
11660 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
11661 && ! DECL_IGNORED_P (decl
))
11662 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
11667 /* If we are in terse mode, don't generate any DIEs for types. */
11668 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11671 /* If we're a function-scope tag, initially use a parent of NULL;
11672 this will be fixed up in decls_for_scope. */
11673 if (decl_function_context (decl
))
11674 context_die
= NULL
;
11682 gen_decl_die (decl
, context_die
);
11685 /* Output a marker (i.e. a label) for the beginning of the generated code for
11686 a lexical block. */
11689 dwarf2out_begin_block (line
, blocknum
)
11690 unsigned int line ATTRIBUTE_UNUSED
;
11691 unsigned int blocknum
;
11693 function_section (current_function_decl
);
11694 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
11697 /* Output a marker (i.e. a label) for the end of the generated code for a
11701 dwarf2out_end_block (line
, blocknum
)
11702 unsigned int line ATTRIBUTE_UNUSED
;
11703 unsigned int blocknum
;
11705 function_section (current_function_decl
);
11706 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
11709 /* Returns nonzero if it is appropriate not to emit any debugging
11710 information for BLOCK, because it doesn't contain any instructions.
11712 Don't allow this for blocks with nested functions or local classes
11713 as we would end up with orphans, and in the presence of scheduling
11714 we may end up calling them anyway. */
11717 dwarf2out_ignore_block (block
)
11722 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
11723 if (TREE_CODE (decl
) == FUNCTION_DECL
11724 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
11730 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11731 dwarf2out.c) and return its "index". The index of each (known) filename is
11732 just a unique number which is associated with only that one filename. We
11733 need such numbers for the sake of generating labels (in the .debug_sfnames
11734 section) and references to those files numbers (in the .debug_srcinfo
11735 and.debug_macinfo sections). If the filename given as an argument is not
11736 found in our current list, add it to the list and assign it the next
11737 available unique index number. In order to speed up searches, we remember
11738 the index of the filename was looked up last. This handles the majority of
11742 lookup_filename (file_name
)
11743 const char *file_name
;
11747 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11748 if (strcmp (file_name
, "<internal>") == 0
11749 || strcmp (file_name
, "<built-in>") == 0)
11752 /* Check to see if the file name that was searched on the previous
11753 call matches this file name. If so, return the index. */
11754 if (file_table
.last_lookup_index
!= 0)
11755 if (0 == strcmp (file_name
,
11756 file_table
.table
[file_table
.last_lookup_index
]))
11757 return file_table
.last_lookup_index
;
11759 /* Didn't match the previous lookup, search the table */
11760 for (i
= 1; i
< file_table
.in_use
; i
++)
11761 if (strcmp (file_name
, file_table
.table
[i
]) == 0)
11763 file_table
.last_lookup_index
= i
;
11767 /* Prepare to add a new table entry by making sure there is enough space in
11768 the table to do so. If not, expand the current table. */
11769 if (i
== file_table
.allocated
)
11771 file_table
.allocated
= i
+ FILE_TABLE_INCREMENT
;
11772 file_table
.table
= (char **)
11773 xrealloc (file_table
.table
, file_table
.allocated
* sizeof (char *));
11776 /* Add the new entry to the end of the filename table. */
11777 file_table
.table
[i
] = xstrdup (file_name
);
11778 file_table
.in_use
= i
+ 1;
11779 file_table
.last_lookup_index
= i
;
11781 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11783 fprintf (asm_out_file
, "\t.file %u ", i
);
11784 output_quoted_string (asm_out_file
, file_name
);
11785 fputc ('\n', asm_out_file
);
11794 /* Allocate the initial hunk of the file_table. */
11795 file_table
.table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
11796 file_table
.allocated
= FILE_TABLE_INCREMENT
;
11798 /* Skip the first entry - file numbers begin at 1. */
11799 file_table
.in_use
= 1;
11800 file_table
.last_lookup_index
= 0;
11803 /* Output a label to mark the beginning of a source code line entry
11804 and record information relating to this source line, in
11805 'line_info_table' for later output of the .debug_line section. */
11808 dwarf2out_source_line (line
, filename
)
11810 const char *filename
;
11812 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11814 function_section (current_function_decl
);
11816 /* If requested, emit something human-readable. */
11817 if (flag_debug_asm
)
11818 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
11821 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11823 unsigned file_num
= lookup_filename (filename
);
11825 /* Emit the .loc directive understood by GNU as. */
11826 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
11828 /* Indicate that line number info exists. */
11829 line_info_table_in_use
++;
11831 /* Indicate that multiple line number tables exist. */
11832 if (DECL_SECTION_NAME (current_function_decl
))
11833 separate_line_info_table_in_use
++;
11835 else if (DECL_SECTION_NAME (current_function_decl
))
11837 dw_separate_line_info_ref line_info
;
11838 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
11839 separate_line_info_table_in_use
);
11841 /* expand the line info table if necessary */
11842 if (separate_line_info_table_in_use
11843 == separate_line_info_table_allocated
)
11845 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11846 separate_line_info_table
11847 = (dw_separate_line_info_ref
)
11848 xrealloc (separate_line_info_table
,
11849 separate_line_info_table_allocated
11850 * sizeof (dw_separate_line_info_entry
));
11853 /* Add the new entry at the end of the line_info_table. */
11855 = &separate_line_info_table
[separate_line_info_table_in_use
++];
11856 line_info
->dw_file_num
= lookup_filename (filename
);
11857 line_info
->dw_line_num
= line
;
11858 line_info
->function
= current_function_funcdef_no
;
11862 dw_line_info_ref line_info
;
11864 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
11865 line_info_table_in_use
);
11867 /* Expand the line info table if necessary. */
11868 if (line_info_table_in_use
== line_info_table_allocated
)
11870 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11872 = (dw_line_info_ref
)
11873 xrealloc (line_info_table
,
11874 (line_info_table_allocated
11875 * sizeof (dw_line_info_entry
)));
11878 /* Add the new entry at the end of the line_info_table. */
11879 line_info
= &line_info_table
[line_info_table_in_use
++];
11880 line_info
->dw_file_num
= lookup_filename (filename
);
11881 line_info
->dw_line_num
= line
;
11886 /* Record the beginning of a new source file. */
11889 dwarf2out_start_source_file (lineno
, filename
)
11890 unsigned int lineno
;
11891 const char *filename
;
11893 if (flag_eliminate_dwarf2_dups
)
11895 /* Record the beginning of the file for break_out_includes. */
11896 dw_die_ref bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
11897 add_AT_string (bincl_die
, DW_AT_name
, filename
);
11900 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11902 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11903 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
11904 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
11906 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
11907 "Filename we just started");
11911 /* Record the end of a source file. */
11914 dwarf2out_end_source_file (lineno
)
11915 unsigned int lineno ATTRIBUTE_UNUSED
;
11917 if (flag_eliminate_dwarf2_dups
)
11918 /* Record the end of the file for break_out_includes. */
11919 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
11921 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11923 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11924 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
11928 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11929 the tail part of the directive line, i.e. the part which is past the
11930 initial whitespace, #, whitespace, directive-name, whitespace part. */
11933 dwarf2out_define (lineno
, buffer
)
11934 unsigned lineno ATTRIBUTE_UNUSED
;
11935 const char *buffer ATTRIBUTE_UNUSED
;
11937 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11939 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11940 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
11941 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11942 dw2_asm_output_nstring (buffer
, -1, "The macro");
11946 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11947 the tail part of the directive line, i.e. the part which is past the
11948 initial whitespace, #, whitespace, directive-name, whitespace part. */
11951 dwarf2out_undef (lineno
, buffer
)
11952 unsigned lineno ATTRIBUTE_UNUSED
;
11953 const char *buffer ATTRIBUTE_UNUSED
;
11955 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11957 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11958 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
11959 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11960 dw2_asm_output_nstring (buffer
, -1, "The macro");
11964 /* Set up for Dwarf output at the start of compilation. */
11967 dwarf2out_init (main_input_filename
)
11968 const char *main_input_filename
;
11970 init_file_table ();
11972 /* Remember the name of the primary input file. */
11973 primary_filename
= main_input_filename
;
11975 /* Add it to the file table first, under the assumption that we'll
11976 be emitting line number data for it first, which avoids having
11977 to add an initial DW_LNS_set_file. */
11978 lookup_filename (main_input_filename
);
11980 /* Allocate the initial hunk of the decl_die_table. */
11982 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
11983 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
11984 decl_die_table_in_use
= 0;
11986 /* Allocate the initial hunk of the decl_scope_table. */
11987 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
11989 /* Allocate the initial hunk of the abbrev_die_table. */
11991 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
11992 sizeof (dw_die_ref
));
11993 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
11994 /* Zero-th entry is allocated, but unused */
11995 abbrev_die_table_in_use
= 1;
11997 /* Allocate the initial hunk of the line_info_table. */
11999 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
12000 sizeof (dw_line_info_entry
));
12001 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12003 /* Zero-th entry is allocated, but unused */
12004 line_info_table_in_use
= 1;
12006 /* Generate the initial DIE for the .debug section. Note that the (string)
12007 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12008 will (typically) be a relative pathname and that this pathname should be
12009 taken as being relative to the directory from which the compiler was
12010 invoked when the given (base) source file was compiled. */
12011 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
12013 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12015 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12017 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
12019 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12020 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12021 DEBUG_ABBREV_SECTION_LABEL
, 0);
12022 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12023 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12025 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12027 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12028 DEBUG_INFO_SECTION_LABEL
, 0);
12029 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12030 DEBUG_LINE_SECTION_LABEL
, 0);
12031 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12032 DEBUG_RANGES_SECTION_LABEL
, 0);
12033 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12034 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12035 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12036 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12037 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12038 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12040 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12042 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12043 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12044 DEBUG_MACINFO_SECTION_LABEL
, 0);
12045 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12048 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12051 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12055 /* Allocate a string in .debug_str hash table. */
12058 indirect_string_alloc (tab
)
12059 hash_table
*tab ATTRIBUTE_UNUSED
;
12061 struct indirect_string_node
*node
;
12063 node
= xmalloc (sizeof (struct indirect_string_node
));
12064 node
->refcount
= 0;
12066 node
->label
= NULL
;
12068 return (hashnode
) node
;
12071 /* A helper function for dwarf2out_finish called through
12072 ht_forall. Emit one queued .debug_str string. */
12075 output_indirect_string (pfile
, h
, v
)
12076 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12078 const PTR v ATTRIBUTE_UNUSED
;
12080 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12082 if (node
->form
== DW_FORM_strp
)
12084 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12085 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12086 assemble_string ((const char *) HT_STR (&node
->id
),
12087 HT_LEN (&node
->id
) + 1);
12093 /* Output stuff that dwarf requires at the end of every file,
12094 and generate the DWARF-2 debugging info. */
12097 dwarf2out_finish (input_filename
)
12098 const char *input_filename ATTRIBUTE_UNUSED
;
12100 limbo_die_node
*node
, *next_node
;
12101 dw_die_ref die
= 0;
12103 /* Traverse the limbo die list, and add parent/child links. The only
12104 dies without parents that should be here are concrete instances of
12105 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12106 For concrete instances, we can get the parent die from the abstract
12108 for (node
= limbo_die_list
; node
; node
= next_node
)
12110 next_node
= node
->next
;
12113 if (die
->die_parent
== NULL
)
12115 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12119 add_child_die (origin
->die_parent
, die
);
12120 else if (die
== comp_unit_die
)
12122 /* If this was an expression for a bound involved in a function
12123 return type, it may be a SAVE_EXPR for which we weren't able
12124 to find a DIE previously. So try now. */
12125 else if (node
->created_for
12126 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12127 && 0 != (origin
= (lookup_decl_die
12129 (node
->created_for
)))))
12130 add_child_die (origin
, die
);
12131 else if (errorcount
> 0 || sorrycount
> 0)
12132 /* It's OK to be confused by errors in the input. */
12133 add_child_die (comp_unit_die
, die
);
12134 else if (node
->created_for
12135 && ((DECL_P (node
->created_for
)
12136 && (context
= DECL_CONTEXT (node
->created_for
)))
12137 || (TYPE_P (node
->created_for
)
12138 && (context
= TYPE_CONTEXT (node
->created_for
))))
12139 && TREE_CODE (context
) == FUNCTION_DECL
)
12141 /* In certain situations, the lexical block containing a
12142 nested function can be optimized away, which results
12143 in the nested function die being orphaned. Likewise
12144 with the return type of that nested function. Force
12145 this to be a child of the containing function. */
12146 origin
= lookup_decl_die (context
);
12149 add_child_die (origin
, die
);
12158 limbo_die_list
= NULL
;
12160 /* Walk through the list of incomplete types again, trying once more to
12161 emit full debugging info for them. */
12162 retry_incomplete_types ();
12164 /* We need to reverse all the dies before break_out_includes, or
12165 we'll see the end of an include file before the beginning. */
12166 reverse_all_dies (comp_unit_die
);
12168 /* Generate separate CUs for each of the include files we've seen.
12169 They will go into limbo_die_list. */
12170 if (flag_eliminate_dwarf2_dups
)
12171 break_out_includes (comp_unit_die
);
12173 /* Traverse the DIE's and add add sibling attributes to those DIE's
12174 that have children. */
12175 add_sibling_attributes (comp_unit_die
);
12176 for (node
= limbo_die_list
; node
; node
= node
->next
)
12177 add_sibling_attributes (node
->die
);
12179 /* Output a terminator label for the .text section. */
12181 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
12183 /* Output the source line correspondence table. We must do this
12184 even if there is no line information. Otherwise, on an empty
12185 translation unit, we will generate a present, but empty,
12186 .debug_info section. IRIX 6.5 `nm' will then complain when
12187 examining the file. */
12188 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12190 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12191 output_line_info ();
12194 /* Output location list section if necessary. */
12195 if (have_location_lists
)
12197 /* Output the location lists info. */
12198 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12199 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12200 DEBUG_LOC_SECTION_LABEL
, 0);
12201 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12202 output_location_lists (die
);
12203 have_location_lists
= 0;
12206 /* We can only use the low/high_pc attributes if all of the code was
12208 if (separate_line_info_table_in_use
== 0)
12210 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12211 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12214 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12215 "base address". Use zero so that these addresses become absolute. */
12216 else if (have_location_lists
|| ranges_table_in_use
)
12217 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12219 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12220 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12221 debug_line_section_label
);
12223 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12224 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12226 /* Output all of the compilation units. We put the main one last so that
12227 the offsets are available to output_pubnames. */
12228 for (node
= limbo_die_list
; node
; node
= node
->next
)
12229 output_comp_unit (node
->die
);
12231 output_comp_unit (comp_unit_die
);
12233 /* Output the abbreviation table. */
12234 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12235 output_abbrev_section ();
12237 /* Output public names table if necessary. */
12238 if (pubname_table_in_use
)
12240 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12241 output_pubnames ();
12244 /* Output the address range information. We only put functions in the arange
12245 table, so don't write it out if we don't have any. */
12246 if (fde_table_in_use
)
12248 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12252 /* Output ranges section if necessary. */
12253 if (ranges_table_in_use
)
12255 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12256 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12260 /* Have to end the primary source file. */
12261 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12263 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12264 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12265 dw2_asm_output_data (1, 0, "End compilation unit");
12268 /* If we emitted any DW_FORM_strp form attribute, output the string
12270 if (debug_str_hash
)
12271 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12275 /* This should never be used, but its address is needed for comparisons. */
12276 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12278 #endif /* DWARF2_DEBUGGING_INFO */
12280 #include "gt-dwarf2out.h"