1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
66 #ifdef DWARF2_DEBUGGING_INFO
67 static void dwarf2out_source_line
PARAMS ((unsigned int, const char *));
70 /* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
88 /* Decide whether we want to emit frame unwind information for the current
94 return (write_symbols
== DWARF2_DEBUG
95 || write_symbols
== VMS_AND_DWARF2_DEBUG
96 #ifdef DWARF2_FRAME_INFO
99 #ifdef DWARF2_UNWIND_INFO
100 || flag_unwind_tables
101 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
106 /* The size of the target's pointer type. */
108 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
111 /* Default version of targetm.eh_frame_section. Note this must appear
112 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
116 default_eh_frame_section ()
118 #ifdef EH_FRAME_SECTION_NAME
119 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
121 tree label
= get_file_function_name ('F');
124 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
125 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, IDENTIFIER_POINTER (label
));
126 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
130 /* Array of RTXes referenced by the debugging information, which therefore
131 must be kept around forever. */
132 static GTY(()) varray_type used_rtx_varray
;
134 /* A pointer to the base of a list of incomplete types which might be
135 completed at some later time. incomplete_types_list needs to be a VARRAY
136 because we want to tell the garbage collector about it. */
137 static GTY(()) varray_type incomplete_types
;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) varray_type decl_scope_table
;
146 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
148 /* How to start an assembler comment. */
149 #ifndef ASM_COMMENT_START
150 #define ASM_COMMENT_START ";#"
153 typedef struct dw_cfi_struct
*dw_cfi_ref
;
154 typedef struct dw_fde_struct
*dw_fde_ref
;
155 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
157 /* Call frames are described using a sequence of Call Frame
158 Information instructions. The register number, offset
159 and address fields are provided as possible operands;
160 their use is selected by the opcode field. */
162 typedef union dw_cfi_oprnd_struct
164 unsigned long dw_cfi_reg_num
;
165 long int dw_cfi_offset
;
166 const char *dw_cfi_addr
;
167 struct dw_loc_descr_struct
*dw_cfi_loc
;
171 typedef struct dw_cfi_struct
173 dw_cfi_ref dw_cfi_next
;
174 enum dwarf_call_frame_info dw_cfi_opc
;
175 dw_cfi_oprnd dw_cfi_oprnd1
;
176 dw_cfi_oprnd dw_cfi_oprnd2
;
180 /* This is how we define the location of the CFA. We use to handle it
181 as REG + OFFSET all the time, but now it can be more complex.
182 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
183 Instead of passing around REG and OFFSET, we pass a copy
184 of this structure. */
185 typedef struct cfa_loc
190 int indirect
; /* 1 if CFA is accessed via a dereference. */
193 /* All call frame descriptions (FDE's) in the GCC generated DWARF
194 refer to a single Common Information Entry (CIE), defined at
195 the beginning of the .debug_frame section. This use of a single
196 CIE obviates the need to keep track of multiple CIE's
197 in the DWARF generation routines below. */
199 typedef struct dw_fde_struct
201 const char *dw_fde_begin
;
202 const char *dw_fde_current_label
;
203 const char *dw_fde_end
;
204 dw_cfi_ref dw_fde_cfi
;
205 unsigned funcdef_number
;
206 unsigned all_throwers_are_sibcalls
: 1;
207 unsigned nothrow
: 1;
208 unsigned uses_eh_lsda
: 1;
212 /* Maximum size (in bytes) of an artificially generated label. */
213 #define MAX_ARTIFICIAL_LABEL_BYTES 30
215 /* The size of addresses as they appear in the Dwarf 2 data.
216 Some architectures use word addresses to refer to code locations,
217 but Dwarf 2 info always uses byte addresses. On such machines,
218 Dwarf 2 addresses need to be larger than the architecture's
220 #ifndef DWARF2_ADDR_SIZE
221 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
224 /* The size in bytes of a DWARF field indicating an offset or length
225 relative to a debug info section, specified to be 4 bytes in the
226 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
229 #ifndef DWARF_OFFSET_SIZE
230 #define DWARF_OFFSET_SIZE 4
233 #define DWARF_VERSION 2
235 /* Round SIZE up to the nearest BOUNDARY. */
236 #define DWARF_ROUND(SIZE,BOUNDARY) \
237 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
239 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
240 #ifndef DWARF_CIE_DATA_ALIGNMENT
241 #ifdef STACK_GROWS_DOWNWARD
242 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
244 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
248 /* A pointer to the base of a table that contains frame description
249 information for each routine. */
250 static dw_fde_ref fde_table
;
252 /* Number of elements currently allocated for fde_table. */
253 static unsigned fde_table_allocated
;
255 /* Number of elements in fde_table currently in use. */
256 static unsigned fde_table_in_use
;
258 /* Size (in elements) of increments by which we may expand the
260 #define FDE_TABLE_INCREMENT 256
262 /* A list of call frame insns for the CIE. */
263 static dw_cfi_ref cie_cfi_head
;
265 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
266 attribute that accelerates the lookup of the FDE associated
267 with the subprogram. This variable holds the table index of the FDE
268 associated with the current function (body) definition. */
269 static unsigned current_funcdef_fde
;
271 struct ht
*debug_str_hash
;
273 struct indirect_string_node
275 struct ht_identifier id
;
276 unsigned int refcount
;
281 /* Forward declarations for functions defined in this file. */
283 static char *stripattributes
PARAMS ((const char *));
284 static const char *dwarf_cfi_name
PARAMS ((unsigned));
285 static dw_cfi_ref new_cfi
PARAMS ((void));
286 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
287 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
288 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
,
290 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
291 static void reg_save
PARAMS ((const char *, unsigned,
293 static void initial_return_save
PARAMS ((rtx
));
294 static long stack_adjust_offset
PARAMS ((rtx
));
295 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
, int));
296 static void output_call_frame_info
PARAMS ((int));
297 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
298 static void queue_reg_save
PARAMS ((const char *, rtx
, long));
299 static void flush_queued_reg_saves
PARAMS ((void));
300 static bool clobbers_queued_reg_save
PARAMS ((rtx
));
301 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
303 /* Support for complex CFA locations. */
304 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
305 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
306 struct dw_loc_descr_struct
*));
307 static struct dw_loc_descr_struct
*build_cfa_loc
308 PARAMS ((dw_cfa_location
*));
309 static void def_cfa_1
PARAMS ((const char *,
312 /* How to start an assembler comment. */
313 #ifndef ASM_COMMENT_START
314 #define ASM_COMMENT_START ";#"
317 /* Data and reference forms for relocatable data. */
318 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
319 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
321 #ifndef DEBUG_FRAME_SECTION
322 #define DEBUG_FRAME_SECTION ".debug_frame"
325 #ifndef FUNC_BEGIN_LABEL
326 #define FUNC_BEGIN_LABEL "LFB"
329 #ifndef FUNC_END_LABEL
330 #define FUNC_END_LABEL "LFE"
333 #define FRAME_BEGIN_LABEL "Lframe"
334 #define CIE_AFTER_SIZE_LABEL "LSCIE"
335 #define CIE_END_LABEL "LECIE"
336 #define FDE_LABEL "LSFDE"
337 #define FDE_AFTER_SIZE_LABEL "LASFDE"
338 #define FDE_END_LABEL "LEFDE"
339 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
340 #define LINE_NUMBER_END_LABEL "LELT"
341 #define LN_PROLOG_AS_LABEL "LASLTP"
342 #define LN_PROLOG_END_LABEL "LELTP"
343 #define DIE_LABEL_PREFIX "DW"
345 /* The DWARF 2 CFA column which tracks the return address. Normally this
346 is the column for PC, or the first column after all of the hard
348 #ifndef DWARF_FRAME_RETURN_COLUMN
350 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
352 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
356 /* The mapping from gcc register number to DWARF 2 CFA column number. By
357 default, we just provide columns for all registers. */
358 #ifndef DWARF_FRAME_REGNUM
359 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
362 /* The offset from the incoming value of %sp to the top of the stack frame
363 for the current function. */
364 #ifndef INCOMING_FRAME_SP_OFFSET
365 #define INCOMING_FRAME_SP_OFFSET 0
368 /* Hook used by __throw. */
371 expand_builtin_dwarf_fp_regnum ()
373 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
376 /* Return a pointer to a copy of the section string name S with all
377 attributes stripped off, and an asterisk prepended (for assemble_name). */
383 char *stripped
= xmalloc (strlen (s
) + 2);
388 while (*s
&& *s
!= ',')
395 /* Generate code to initialize the register size table. */
398 expand_builtin_init_dwarf_reg_sizes (address
)
402 enum machine_mode mode
= TYPE_MODE (char_type_node
);
403 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
404 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
406 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
407 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
409 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
410 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
415 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
419 /* Convert a DWARF call frame info. operation to its string name */
422 dwarf_cfi_name (cfi_opc
)
427 case DW_CFA_advance_loc
:
428 return "DW_CFA_advance_loc";
430 return "DW_CFA_offset";
432 return "DW_CFA_restore";
436 return "DW_CFA_set_loc";
437 case DW_CFA_advance_loc1
:
438 return "DW_CFA_advance_loc1";
439 case DW_CFA_advance_loc2
:
440 return "DW_CFA_advance_loc2";
441 case DW_CFA_advance_loc4
:
442 return "DW_CFA_advance_loc4";
443 case DW_CFA_offset_extended
:
444 return "DW_CFA_offset_extended";
445 case DW_CFA_restore_extended
:
446 return "DW_CFA_restore_extended";
447 case DW_CFA_undefined
:
448 return "DW_CFA_undefined";
449 case DW_CFA_same_value
:
450 return "DW_CFA_same_value";
451 case DW_CFA_register
:
452 return "DW_CFA_register";
453 case DW_CFA_remember_state
:
454 return "DW_CFA_remember_state";
455 case DW_CFA_restore_state
:
456 return "DW_CFA_restore_state";
458 return "DW_CFA_def_cfa";
459 case DW_CFA_def_cfa_register
:
460 return "DW_CFA_def_cfa_register";
461 case DW_CFA_def_cfa_offset
:
462 return "DW_CFA_def_cfa_offset";
465 case DW_CFA_def_cfa_expression
:
466 return "DW_CFA_def_cfa_expression";
467 case DW_CFA_expression
:
468 return "DW_CFA_expression";
469 case DW_CFA_offset_extended_sf
:
470 return "DW_CFA_offset_extended_sf";
471 case DW_CFA_def_cfa_sf
:
472 return "DW_CFA_def_cfa_sf";
473 case DW_CFA_def_cfa_offset_sf
:
474 return "DW_CFA_def_cfa_offset_sf";
476 /* SGI/MIPS specific */
477 case DW_CFA_MIPS_advance_loc8
:
478 return "DW_CFA_MIPS_advance_loc8";
481 case DW_CFA_GNU_window_save
:
482 return "DW_CFA_GNU_window_save";
483 case DW_CFA_GNU_args_size
:
484 return "DW_CFA_GNU_args_size";
485 case DW_CFA_GNU_negative_offset_extended
:
486 return "DW_CFA_GNU_negative_offset_extended";
489 return "DW_CFA_<unknown>";
493 /* Return a pointer to a newly allocated Call Frame Instruction. */
495 static inline dw_cfi_ref
498 dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
500 cfi
->dw_cfi_next
= NULL
;
501 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
502 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
507 /* Add a Call Frame Instruction to list of instructions. */
510 add_cfi (list_head
, cfi
)
511 dw_cfi_ref
*list_head
;
516 /* Find the end of the chain. */
517 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
523 /* Generate a new label for the CFI info to refer to. */
526 dwarf2out_cfi_label ()
528 static char label
[20];
529 static unsigned long label_num
= 0;
531 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
532 ASM_OUTPUT_LABEL (asm_out_file
, label
);
536 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
537 or to the CIE if LABEL is NULL. */
540 add_fde_cfi (label
, cfi
)
546 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
549 label
= dwarf2out_cfi_label ();
551 if (fde
->dw_fde_current_label
== NULL
552 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
556 fde
->dw_fde_current_label
= label
= xstrdup (label
);
558 /* Set the location counter to the new label. */
560 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
561 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
562 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
565 add_cfi (&fde
->dw_fde_cfi
, cfi
);
569 add_cfi (&cie_cfi_head
, cfi
);
572 /* Subroutine of lookup_cfa. */
575 lookup_cfa_1 (cfi
, loc
)
577 dw_cfa_location
*loc
;
579 switch (cfi
->dw_cfi_opc
)
581 case DW_CFA_def_cfa_offset
:
582 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
584 case DW_CFA_def_cfa_register
:
585 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
588 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
589 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
591 case DW_CFA_def_cfa_expression
:
592 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
599 /* Find the previous value for the CFA. */
603 dw_cfa_location
*loc
;
607 loc
->reg
= (unsigned long) -1;
610 loc
->base_offset
= 0;
612 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
613 lookup_cfa_1 (cfi
, loc
);
615 if (fde_table_in_use
)
617 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
618 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
619 lookup_cfa_1 (cfi
, loc
);
623 /* The current rule for calculating the DWARF2 canonical frame address. */
624 static dw_cfa_location cfa
;
626 /* The register used for saving registers to the stack, and its offset
628 static dw_cfa_location cfa_store
;
630 /* The running total of the size of arguments pushed onto the stack. */
631 static long args_size
;
633 /* The last args_size we actually output. */
634 static long old_args_size
;
636 /* Entry point to update the canonical frame address (CFA).
637 LABEL is passed to add_fde_cfi. The value of CFA is now to be
638 calculated from REG+OFFSET. */
641 dwarf2out_def_cfa (label
, reg
, offset
)
651 def_cfa_1 (label
, &loc
);
654 /* This routine does the actual work. The CFA is now calculated from
655 the dw_cfa_location structure. */
658 def_cfa_1 (label
, loc_p
)
660 dw_cfa_location
*loc_p
;
663 dw_cfa_location old_cfa
, loc
;
668 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
669 cfa_store
.offset
= loc
.offset
;
671 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
672 lookup_cfa (&old_cfa
);
674 /* If nothing changed, no need to issue any call frame instructions. */
675 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
676 && loc
.indirect
== old_cfa
.indirect
677 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
682 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
684 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
685 indicating the CFA register did not change but the offset
687 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
688 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
691 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
692 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
695 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
696 indicating the CFA register has changed to <register> but the
697 offset has not changed. */
698 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
699 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
703 else if (loc
.indirect
== 0)
705 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
706 indicating the CFA register has changed to <register> with
707 the specified offset. */
708 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
709 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
710 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
714 /* Construct a DW_CFA_def_cfa_expression instruction to
715 calculate the CFA using a full location expression since no
716 register-offset pair is available. */
717 struct dw_loc_descr_struct
*loc_list
;
719 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
720 loc_list
= build_cfa_loc (&loc
);
721 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
724 add_fde_cfi (label
, cfi
);
727 /* Add the CFI for saving a register. REG is the CFA column number.
728 LABEL is passed to add_fde_cfi.
729 If SREG is -1, the register is saved at OFFSET from the CFA;
730 otherwise it is saved in SREG. */
733 reg_save (label
, reg
, sreg
, offset
)
739 dw_cfi_ref cfi
= new_cfi ();
741 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
743 /* The following comparison is correct. -1 is used to indicate that
744 the value isn't a register number. */
745 if (sreg
== (unsigned int) -1)
748 /* The register number won't fit in 6 bits, so we have to use
750 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
752 cfi
->dw_cfi_opc
= DW_CFA_offset
;
754 #ifdef ENABLE_CHECKING
756 /* If we get an offset that is not a multiple of
757 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
758 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
760 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
762 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
766 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
768 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
770 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
772 else if (sreg
== reg
)
773 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
777 cfi
->dw_cfi_opc
= DW_CFA_register
;
778 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
781 add_fde_cfi (label
, cfi
);
784 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
785 This CFI tells the unwinder that it needs to restore the window registers
786 from the previous frame's window save area.
788 ??? Perhaps we should note in the CIE where windows are saved (instead of
789 assuming 0(cfa)) and what registers are in the window. */
792 dwarf2out_window_save (label
)
795 dw_cfi_ref cfi
= new_cfi ();
797 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
798 add_fde_cfi (label
, cfi
);
801 /* Add a CFI to update the running total of the size of arguments
802 pushed onto the stack. */
805 dwarf2out_args_size (label
, size
)
811 if (size
== old_args_size
)
814 old_args_size
= size
;
817 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
818 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
819 add_fde_cfi (label
, cfi
);
822 /* Entry point for saving a register to the stack. REG is the GCC register
823 number. LABEL and OFFSET are passed to reg_save. */
826 dwarf2out_reg_save (label
, reg
, offset
)
831 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
834 /* Entry point for saving the return address in the stack.
835 LABEL and OFFSET are passed to reg_save. */
838 dwarf2out_return_save (label
, offset
)
842 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
845 /* Entry point for saving the return address in a register.
846 LABEL and SREG are passed to reg_save. */
849 dwarf2out_return_reg (label
, sreg
)
853 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
856 /* Record the initial position of the return address. RTL is
857 INCOMING_RETURN_ADDR_RTX. */
860 initial_return_save (rtl
)
863 unsigned int reg
= (unsigned int) -1;
864 HOST_WIDE_INT offset
= 0;
866 switch (GET_CODE (rtl
))
869 /* RA is in a register. */
870 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
874 /* RA is on the stack. */
876 switch (GET_CODE (rtl
))
879 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
885 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
887 offset
= INTVAL (XEXP (rtl
, 1));
891 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
893 offset
= -INTVAL (XEXP (rtl
, 1));
903 /* The return address is at some offset from any value we can
904 actually load. For instance, on the SPARC it is in %i7+8. Just
905 ignore the offset for now; it doesn't matter for unwinding frames. */
906 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
908 initial_return_save (XEXP (rtl
, 0));
915 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
918 /* Given a SET, calculate the amount of stack adjustment it
922 stack_adjust_offset (pattern
)
925 rtx src
= SET_SRC (pattern
);
926 rtx dest
= SET_DEST (pattern
);
927 HOST_WIDE_INT offset
= 0;
930 if (dest
== stack_pointer_rtx
)
932 /* (set (reg sp) (plus (reg sp) (const_int))) */
933 code
= GET_CODE (src
);
934 if (! (code
== PLUS
|| code
== MINUS
)
935 || XEXP (src
, 0) != stack_pointer_rtx
936 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
939 offset
= INTVAL (XEXP (src
, 1));
943 else if (GET_CODE (dest
) == MEM
)
945 /* (set (mem (pre_dec (reg sp))) (foo)) */
946 src
= XEXP (dest
, 0);
947 code
= GET_CODE (src
);
953 if (XEXP (src
, 0) == stack_pointer_rtx
)
955 rtx val
= XEXP (XEXP (src
, 1), 1);
956 /* We handle only adjustments by constant amount. */
957 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
958 GET_CODE (val
) != CONST_INT
)
960 offset
= -INTVAL (val
);
967 if (XEXP (src
, 0) == stack_pointer_rtx
)
969 offset
= GET_MODE_SIZE (GET_MODE (dest
));
976 if (XEXP (src
, 0) == stack_pointer_rtx
)
978 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
993 /* Check INSN to see if it looks like a push or a stack adjustment, and
994 make a note of it if it does. EH uses this information to find out how
995 much extra space it needs to pop off the stack. */
998 dwarf2out_stack_adjust (insn
)
1001 HOST_WIDE_INT offset
;
1005 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1007 /* Extract the size of the args from the CALL rtx itself. */
1008 insn
= PATTERN (insn
);
1009 if (GET_CODE (insn
) == PARALLEL
)
1010 insn
= XVECEXP (insn
, 0, 0);
1011 if (GET_CODE (insn
) == SET
)
1012 insn
= SET_SRC (insn
);
1013 if (GET_CODE (insn
) != CALL
)
1016 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1020 /* If only calls can throw, and we have a frame pointer,
1021 save up adjustments until we see the CALL_INSN. */
1022 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1025 if (GET_CODE (insn
) == BARRIER
)
1027 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1028 the compiler will have already emitted a stack adjustment, but
1029 doesn't bother for calls to noreturn functions. */
1030 #ifdef STACK_GROWS_DOWNWARD
1031 offset
= -args_size
;
1036 else if (GET_CODE (PATTERN (insn
)) == SET
)
1037 offset
= stack_adjust_offset (PATTERN (insn
));
1038 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1039 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1041 /* There may be stack adjustments inside compound insns. Search
1043 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1044 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1045 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1053 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1054 cfa
.offset
+= offset
;
1056 #ifndef STACK_GROWS_DOWNWARD
1060 args_size
+= offset
;
1064 label
= dwarf2out_cfi_label ();
1065 def_cfa_1 (label
, &cfa
);
1066 dwarf2out_args_size (label
, args_size
);
1069 /* We delay emitting a register save until either (a) we reach the end
1070 of the prologue or (b) the register is clobbered. This clusters
1071 register saves so that there are fewer pc advances. */
1073 struct queued_reg_save
1075 struct queued_reg_save
*next
;
1080 static struct queued_reg_save
*queued_reg_saves
;
1081 static const char *last_reg_save_label
;
1084 queue_reg_save (label
, reg
, offset
)
1089 struct queued_reg_save
*q
= (struct queued_reg_save
*) xmalloc (sizeof (*q
));
1091 q
->next
= queued_reg_saves
;
1093 q
->cfa_offset
= offset
;
1094 queued_reg_saves
= q
;
1096 last_reg_save_label
= label
;
1100 flush_queued_reg_saves ()
1102 struct queued_reg_save
*q
, *next
;
1104 for (q
= queued_reg_saves
; q
; q
= next
)
1106 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1111 queued_reg_saves
= NULL
;
1112 last_reg_save_label
= NULL
;
1116 clobbers_queued_reg_save (insn
)
1119 struct queued_reg_save
*q
;
1121 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1122 if (modified_in_p (q
->reg
, insn
))
1129 /* A temporary register holding an integral value used in adjusting SP
1130 or setting up the store_reg. The "offset" field holds the integer
1131 value, not an offset. */
1132 static dw_cfa_location cfa_temp
;
1134 /* Record call frame debugging information for an expression EXPR,
1135 which either sets SP or FP (adjusting how we calculate the frame
1136 address) or saves a register to the stack. LABEL indicates the
1139 This function encodes a state machine mapping rtxes to actions on
1140 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1141 users need not read the source code.
1143 The High-Level Picture
1145 Changes in the register we use to calculate the CFA: Currently we
1146 assume that if you copy the CFA register into another register, we
1147 should take the other one as the new CFA register; this seems to
1148 work pretty well. If it's wrong for some target, it's simple
1149 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1151 Changes in the register we use for saving registers to the stack:
1152 This is usually SP, but not always. Again, we deduce that if you
1153 copy SP into another register (and SP is not the CFA register),
1154 then the new register is the one we will be using for register
1155 saves. This also seems to work.
1157 Register saves: There's not much guesswork about this one; if
1158 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1159 register save, and the register used to calculate the destination
1160 had better be the one we think we're using for this purpose.
1162 Except: If the register being saved is the CFA register, and the
1163 offset is non-zero, we are saving the CFA, so we assume we have to
1164 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1165 the intent is to save the value of SP from the previous frame.
1167 Invariants / Summaries of Rules
1169 cfa current rule for calculating the CFA. It usually
1170 consists of a register and an offset.
1171 cfa_store register used by prologue code to save things to the stack
1172 cfa_store.offset is the offset from the value of
1173 cfa_store.reg to the actual CFA
1174 cfa_temp register holding an integral value. cfa_temp.offset
1175 stores the value, which will be used to adjust the
1176 stack pointer. cfa_temp is also used like cfa_store,
1177 to track stores to the stack via fp or a temp reg.
1179 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1180 with cfa.reg as the first operand changes the cfa.reg and its
1181 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1184 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1185 expression yielding a constant. This sets cfa_temp.reg
1186 and cfa_temp.offset.
1188 Rule 5: Create a new register cfa_store used to save items to the
1191 Rules 10-14: Save a register to the stack. Define offset as the
1192 difference of the original location and cfa_store's
1193 location (or cfa_temp's location if cfa_temp is used).
1197 "{a,b}" indicates a choice of a xor b.
1198 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1201 (set <reg1> <reg2>:cfa.reg)
1202 effects: cfa.reg = <reg1>
1203 cfa.offset unchanged
1204 cfa_temp.reg = <reg1>
1205 cfa_temp.offset = cfa.offset
1208 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1209 {<const_int>,<reg>:cfa_temp.reg}))
1210 effects: cfa.reg = sp if fp used
1211 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1212 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1213 if cfa_store.reg==sp
1216 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1217 effects: cfa.reg = fp
1218 cfa_offset += +/- <const_int>
1221 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1222 constraints: <reg1> != fp
1224 effects: cfa.reg = <reg1>
1225 cfa_temp.reg = <reg1>
1226 cfa_temp.offset = cfa.offset
1229 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1230 constraints: <reg1> != fp
1232 effects: cfa_store.reg = <reg1>
1233 cfa_store.offset = cfa.offset - cfa_temp.offset
1236 (set <reg> <const_int>)
1237 effects: cfa_temp.reg = <reg>
1238 cfa_temp.offset = <const_int>
1241 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1242 effects: cfa_temp.reg = <reg1>
1243 cfa_temp.offset |= <const_int>
1246 (set <reg> (high <exp>))
1250 (set <reg> (lo_sum <exp> <const_int>))
1251 effects: cfa_temp.reg = <reg>
1252 cfa_temp.offset = <const_int>
1255 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1256 effects: cfa_store.offset -= <const_int>
1257 cfa.offset = cfa_store.offset if cfa.reg == sp
1259 cfa.base_offset = -cfa_store.offset
1262 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1263 effects: cfa_store.offset += -/+ mode_size(mem)
1264 cfa.offset = cfa_store.offset if cfa.reg == sp
1266 cfa.base_offset = -cfa_store.offset
1269 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1272 effects: cfa.reg = <reg1>
1273 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1276 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1277 effects: cfa.reg = <reg1>
1278 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1281 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1282 effects: cfa.reg = <reg1>
1283 cfa.base_offset = -cfa_temp.offset
1284 cfa_temp.offset -= mode_size(mem) */
1287 dwarf2out_frame_debug_expr (expr
, label
)
1292 HOST_WIDE_INT offset
;
1294 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1295 the PARALLEL independently. The first element is always processed if
1296 it is a SET. This is for backward compatibility. Other elements
1297 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1298 flag is set in them. */
1299 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1302 int limit
= XVECLEN (expr
, 0);
1304 for (par_index
= 0; par_index
< limit
; par_index
++)
1305 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1306 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1308 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1313 if (GET_CODE (expr
) != SET
)
1316 src
= SET_SRC (expr
);
1317 dest
= SET_DEST (expr
);
1319 switch (GET_CODE (dest
))
1323 /* Update the CFA rule wrt SP or FP. Make sure src is
1324 relative to the current CFA register. */
1325 switch (GET_CODE (src
))
1327 /* Setting FP from SP. */
1329 if (cfa
.reg
== (unsigned) REGNO (src
))
1335 /* We used to require that dest be either SP or FP, but the
1336 ARM copies SP to a temporary register, and from there to
1337 FP. So we just rely on the backends to only set
1338 RTX_FRAME_RELATED_P on appropriate insns. */
1339 cfa
.reg
= REGNO (dest
);
1340 cfa_temp
.reg
= cfa
.reg
;
1341 cfa_temp
.offset
= cfa
.offset
;
1347 if (dest
== stack_pointer_rtx
)
1351 switch (GET_CODE (XEXP (src
, 1)))
1354 offset
= INTVAL (XEXP (src
, 1));
1357 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1359 offset
= cfa_temp
.offset
;
1365 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1367 /* Restoring SP from FP in the epilogue. */
1368 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1370 cfa
.reg
= STACK_POINTER_REGNUM
;
1372 else if (GET_CODE (src
) == LO_SUM
)
1373 /* Assume we've set the source reg of the LO_SUM from sp. */
1375 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1378 if (GET_CODE (src
) != MINUS
)
1380 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1381 cfa
.offset
+= offset
;
1382 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1383 cfa_store
.offset
+= offset
;
1385 else if (dest
== hard_frame_pointer_rtx
)
1388 /* Either setting the FP from an offset of the SP,
1389 or adjusting the FP */
1390 if (! frame_pointer_needed
)
1393 if (GET_CODE (XEXP (src
, 0)) == REG
1394 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1395 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1397 offset
= INTVAL (XEXP (src
, 1));
1398 if (GET_CODE (src
) != MINUS
)
1400 cfa
.offset
+= offset
;
1401 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1408 if (GET_CODE (src
) == MINUS
)
1412 if (GET_CODE (XEXP (src
, 0)) == REG
1413 && REGNO (XEXP (src
, 0)) == cfa
.reg
1414 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1416 /* Setting a temporary CFA register that will be copied
1417 into the FP later on. */
1418 offset
= - INTVAL (XEXP (src
, 1));
1419 cfa
.offset
+= offset
;
1420 cfa
.reg
= REGNO (dest
);
1421 /* Or used to save regs to the stack. */
1422 cfa_temp
.reg
= cfa
.reg
;
1423 cfa_temp
.offset
= cfa
.offset
;
1427 else if (GET_CODE (XEXP (src
, 0)) == REG
1428 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1429 && XEXP (src
, 1) == stack_pointer_rtx
)
1431 /* Setting a scratch register that we will use instead
1432 of SP for saving registers to the stack. */
1433 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1435 cfa_store
.reg
= REGNO (dest
);
1436 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1440 else if (GET_CODE (src
) == LO_SUM
1441 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1443 cfa_temp
.reg
= REGNO (dest
);
1444 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1453 cfa_temp
.reg
= REGNO (dest
);
1454 cfa_temp
.offset
= INTVAL (src
);
1459 if (GET_CODE (XEXP (src
, 0)) != REG
1460 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1461 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1464 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1465 cfa_temp
.reg
= REGNO (dest
);
1466 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1469 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1470 which will fill in all of the bits. */
1479 def_cfa_1 (label
, &cfa
);
1483 if (GET_CODE (src
) != REG
)
1486 /* Saving a register to the stack. Make sure dest is relative to the
1488 switch (GET_CODE (XEXP (dest
, 0)))
1493 /* We can't handle variable size modifications. */
1494 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1496 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1498 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1499 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1502 cfa_store
.offset
+= offset
;
1503 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1504 cfa
.offset
= cfa_store
.offset
;
1506 offset
= -cfa_store
.offset
;
1512 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1513 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1516 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1517 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1520 cfa_store
.offset
+= offset
;
1521 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1522 cfa
.offset
= cfa_store
.offset
;
1524 offset
= -cfa_store
.offset
;
1528 /* With an offset. */
1532 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1534 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1535 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1538 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1539 offset
-= cfa_store
.offset
;
1540 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1541 offset
-= cfa_temp
.offset
;
1547 /* Without an offset. */
1549 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1550 offset
= -cfa_store
.offset
;
1551 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1552 offset
= -cfa_temp
.offset
;
1559 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1561 offset
= -cfa_temp
.offset
;
1562 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1569 if (REGNO (src
) != STACK_POINTER_REGNUM
1570 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1571 && (unsigned) REGNO (src
) == cfa
.reg
)
1573 /* We're storing the current CFA reg into the stack. */
1575 if (cfa
.offset
== 0)
1577 /* If the source register is exactly the CFA, assume
1578 we're saving SP like any other register; this happens
1580 def_cfa_1 (label
, &cfa
);
1581 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1586 /* Otherwise, we'll need to look in the stack to
1587 calculate the CFA. */
1588 rtx x
= XEXP (dest
, 0);
1590 if (GET_CODE (x
) != REG
)
1592 if (GET_CODE (x
) != REG
)
1595 cfa
.reg
= REGNO (x
);
1596 cfa
.base_offset
= offset
;
1598 def_cfa_1 (label
, &cfa
);
1603 def_cfa_1 (label
, &cfa
);
1604 queue_reg_save (label
, src
, offset
);
1612 /* Record call frame debugging information for INSN, which either
1613 sets SP or FP (adjusting how we calculate the frame address) or saves a
1614 register to the stack. If INSN is NULL_RTX, initialize our state. */
1617 dwarf2out_frame_debug (insn
)
1623 if (insn
== NULL_RTX
)
1625 /* Flush any queued register saves. */
1626 flush_queued_reg_saves ();
1628 /* Set up state for generating call frame debug info. */
1630 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1633 cfa
.reg
= STACK_POINTER_REGNUM
;
1636 cfa_temp
.offset
= 0;
1640 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1641 flush_queued_reg_saves ();
1643 if (! RTX_FRAME_RELATED_P (insn
))
1645 if (!ACCUMULATE_OUTGOING_ARGS
)
1646 dwarf2out_stack_adjust (insn
);
1651 label
= dwarf2out_cfi_label ();
1652 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1654 insn
= XEXP (src
, 0);
1656 insn
= PATTERN (insn
);
1658 dwarf2out_frame_debug_expr (insn
, label
);
1661 /* Output a Call Frame Information opcode and its operand(s). */
1664 output_cfi (cfi
, fde
, for_eh
)
1669 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1670 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1671 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1672 "DW_CFA_advance_loc 0x%lx",
1673 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1674 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1676 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1677 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1678 "DW_CFA_offset, column 0x%lx",
1679 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1680 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1682 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1683 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1684 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1685 "DW_CFA_restore, column 0x%lx",
1686 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1689 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1690 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1692 switch (cfi
->dw_cfi_opc
)
1694 case DW_CFA_set_loc
:
1696 dw2_asm_output_encoded_addr_rtx (
1697 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1698 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1701 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1702 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1705 case DW_CFA_advance_loc1
:
1706 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1707 fde
->dw_fde_current_label
, NULL
);
1708 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1711 case DW_CFA_advance_loc2
:
1712 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1713 fde
->dw_fde_current_label
, NULL
);
1714 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1717 case DW_CFA_advance_loc4
:
1718 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1719 fde
->dw_fde_current_label
, NULL
);
1720 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1723 case DW_CFA_MIPS_advance_loc8
:
1724 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1725 fde
->dw_fde_current_label
, NULL
);
1726 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1729 case DW_CFA_offset_extended
:
1730 case DW_CFA_def_cfa
:
1731 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1733 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1736 case DW_CFA_offset_extended_sf
:
1737 case DW_CFA_def_cfa_sf
:
1738 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1740 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1743 case DW_CFA_restore_extended
:
1744 case DW_CFA_undefined
:
1745 case DW_CFA_same_value
:
1746 case DW_CFA_def_cfa_register
:
1747 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1751 case DW_CFA_register
:
1752 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1754 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1758 case DW_CFA_def_cfa_offset
:
1759 case DW_CFA_GNU_args_size
:
1760 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1763 case DW_CFA_def_cfa_offset_sf
:
1764 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1767 case DW_CFA_GNU_window_save
:
1770 case DW_CFA_def_cfa_expression
:
1771 case DW_CFA_expression
:
1772 output_cfa_loc (cfi
);
1775 case DW_CFA_GNU_negative_offset_extended
:
1776 /* Obsoleted by DW_CFA_offset_extended_sf. */
1785 /* Output the call frame information used to used to record information
1786 that relates to calculating the frame pointer, and records the
1787 location of saved registers. */
1790 output_call_frame_info (for_eh
)
1796 char l1
[20], l2
[20], section_start_label
[20];
1797 int any_lsda_needed
= 0;
1798 char augmentation
[6];
1799 int augmentation_size
;
1800 int fde_encoding
= DW_EH_PE_absptr
;
1801 int per_encoding
= DW_EH_PE_absptr
;
1802 int lsda_encoding
= DW_EH_PE_absptr
;
1804 /* Don't emit a CIE if there won't be any FDEs. */
1805 if (fde_table_in_use
== 0)
1808 /* If we don't have any functions we'll want to unwind out of, don't emit any
1809 EH unwind information. */
1812 int any_eh_needed
= flag_asynchronous_unwind_tables
;
1814 for (i
= 0; i
< fde_table_in_use
; i
++)
1815 if (fde_table
[i
].uses_eh_lsda
)
1816 any_eh_needed
= any_lsda_needed
= 1;
1817 else if (! fde_table
[i
].nothrow
)
1820 if (! any_eh_needed
)
1824 /* We're going to be generating comments, so turn on app. */
1829 (*targetm
.asm_out
.eh_frame_section
) ();
1831 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1833 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1834 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1836 /* Output the CIE. */
1837 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1838 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1839 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1840 "Length of Common Information Entry");
1841 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1843 /* Now that the CIE pointer is PC-relative for EH,
1844 use 0 to identify the CIE. */
1845 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1846 (for_eh
? 0 : DW_CIE_ID
),
1847 "CIE Identifier Tag");
1849 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1851 augmentation
[0] = 0;
1852 augmentation_size
= 0;
1858 z Indicates that a uleb128 is present to size the
1859 augmentation section.
1860 L Indicates the encoding (and thus presence) of
1861 an LSDA pointer in the FDE augmentation.
1862 R Indicates a non-default pointer encoding for
1864 P Indicates the presence of an encoding + language
1865 personality routine in the CIE augmentation. */
1867 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1868 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1869 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1871 p
= augmentation
+ 1;
1872 if (eh_personality_libfunc
)
1875 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1877 if (any_lsda_needed
)
1880 augmentation_size
+= 1;
1882 if (fde_encoding
!= DW_EH_PE_absptr
)
1885 augmentation_size
+= 1;
1887 if (p
> augmentation
+ 1)
1889 augmentation
[0] = 'z';
1893 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1894 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1896 int offset
= ( 4 /* Length */
1898 + 1 /* CIE version */
1899 + strlen (augmentation
) + 1 /* Augmentation */
1900 + size_of_uleb128 (1) /* Code alignment */
1901 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1903 + 1 /* Augmentation size */
1904 + 1 /* Personality encoding */ );
1905 int pad
= -offset
& (PTR_SIZE
- 1);
1907 augmentation_size
+= pad
;
1909 /* Augmentations should be small, so there's scarce need to
1910 iterate for a solution. Die if we exceed one uleb128 byte. */
1911 if (size_of_uleb128 (augmentation_size
) != 1)
1916 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1917 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1918 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1919 "CIE Data Alignment Factor");
1920 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
1922 if (augmentation
[0])
1924 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
1925 if (eh_personality_libfunc
)
1927 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
1928 eh_data_format_name (per_encoding
));
1929 dw2_asm_output_encoded_addr_rtx (per_encoding
,
1930 eh_personality_libfunc
, NULL
);
1933 if (any_lsda_needed
)
1934 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
1935 eh_data_format_name (lsda_encoding
));
1937 if (fde_encoding
!= DW_EH_PE_absptr
)
1938 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
1939 eh_data_format_name (fde_encoding
));
1942 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1943 output_cfi (cfi
, NULL
, for_eh
);
1945 /* Pad the CIE out to an address sized boundary. */
1946 ASM_OUTPUT_ALIGN (asm_out_file
,
1947 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
1948 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1950 /* Loop through all of the FDE's. */
1951 for (i
= 0; i
< fde_table_in_use
; i
++)
1953 fde
= &fde_table
[i
];
1955 /* Don't emit EH unwind info for leaf functions that don't need it. */
1956 if (!flag_asynchronous_unwind_tables
&& for_eh
1957 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
1958 && !fde
->uses_eh_lsda
)
1961 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
1962 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1963 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1964 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1966 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1969 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
1971 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
1976 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
1977 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
1978 "FDE initial location");
1979 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
1980 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1981 "FDE address range");
1985 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
1986 "FDE initial location");
1987 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
1988 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1989 "FDE address range");
1992 if (augmentation
[0])
1994 if (any_lsda_needed
)
1996 int size
= size_of_encoded_value (lsda_encoding
);
1998 if (lsda_encoding
== DW_EH_PE_aligned
)
2000 int offset
= ( 4 /* Length */
2001 + 4 /* CIE offset */
2002 + 2 * size_of_encoded_value (fde_encoding
)
2003 + 1 /* Augmentation size */ );
2004 int pad
= -offset
& (PTR_SIZE
- 1);
2007 if (size_of_uleb128 (size
) != 1)
2011 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2013 if (fde
->uses_eh_lsda
)
2015 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2016 fde
->funcdef_number
);
2017 dw2_asm_output_encoded_addr_rtx (
2018 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2019 "Language Specific Data Area");
2023 if (lsda_encoding
== DW_EH_PE_aligned
)
2024 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2026 (size_of_encoded_value (lsda_encoding
), 0,
2027 "Language Specific Data Area (none)");
2031 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2034 /* Loop through the Call Frame Instructions associated with
2036 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2037 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2038 output_cfi (cfi
, fde
, for_eh
);
2040 /* Pad the FDE out to an address sized boundary. */
2041 ASM_OUTPUT_ALIGN (asm_out_file
,
2042 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2043 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2046 #ifndef EH_FRAME_SECTION_NAME
2048 dw2_asm_output_data (4, 0, "End of Table");
2050 #ifdef MIPS_DEBUGGING_INFO
2051 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2052 get a value of 0. Putting .align 0 after the label fixes it. */
2053 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2056 /* Turn off app to make assembly quicker. */
2061 /* Output a marker (i.e. a label) for the beginning of a function, before
2065 dwarf2out_begin_prologue (line
, file
)
2066 unsigned int line ATTRIBUTE_UNUSED
;
2067 const char *file ATTRIBUTE_UNUSED
;
2069 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2072 current_function_func_begin_label
= 0;
2074 #ifdef IA64_UNWIND_INFO
2075 /* ??? current_function_func_begin_label is also used by except.c
2076 for call-site information. We must emit this label if it might
2078 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2079 && ! dwarf2out_do_frame ())
2082 if (! dwarf2out_do_frame ())
2086 function_section (current_function_decl
);
2087 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2088 current_function_funcdef_no
);
2089 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2090 current_function_funcdef_no
);
2091 current_function_func_begin_label
= get_identifier (label
);
2093 #ifdef IA64_UNWIND_INFO
2094 /* We can elide the fde allocation if we're not emitting debug info. */
2095 if (! dwarf2out_do_frame ())
2099 /* Expand the fde table if necessary. */
2100 if (fde_table_in_use
== fde_table_allocated
)
2102 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2104 = (dw_fde_ref
) xrealloc (fde_table
,
2105 fde_table_allocated
* sizeof (dw_fde_node
));
2108 /* Record the FDE associated with this function. */
2109 current_funcdef_fde
= fde_table_in_use
;
2111 /* Add the new FDE at the end of the fde_table. */
2112 fde
= &fde_table
[fde_table_in_use
++];
2113 fde
->dw_fde_begin
= xstrdup (label
);
2114 fde
->dw_fde_current_label
= NULL
;
2115 fde
->dw_fde_end
= NULL
;
2116 fde
->dw_fde_cfi
= NULL
;
2117 fde
->funcdef_number
= current_function_funcdef_no
;
2118 fde
->nothrow
= current_function_nothrow
;
2119 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2120 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2122 args_size
= old_args_size
= 0;
2124 /* We only want to output line number information for the genuine dwarf2
2125 prologue case, not the eh frame case. */
2126 #ifdef DWARF2_DEBUGGING_INFO
2128 dwarf2out_source_line (line
, file
);
2132 /* Output a marker (i.e. a label) for the absolute end of the generated code
2133 for a function definition. This gets called *after* the epilogue code has
2137 dwarf2out_end_epilogue (line
, file
)
2138 unsigned int line ATTRIBUTE_UNUSED
;
2139 const char *file ATTRIBUTE_UNUSED
;
2142 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2144 /* Output a label to mark the endpoint of the code generated for this
2146 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2147 current_function_funcdef_no
);
2148 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2149 fde
= &fde_table
[fde_table_in_use
- 1];
2150 fde
->dw_fde_end
= xstrdup (label
);
2154 dwarf2out_frame_init ()
2156 /* Allocate the initial hunk of the fde_table. */
2157 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2158 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2159 fde_table_in_use
= 0;
2161 /* Generate the CFA instructions common to all FDE's. Do it now for the
2162 sake of lookup_cfa. */
2164 #ifdef DWARF2_UNWIND_INFO
2165 /* On entry, the Canonical Frame Address is at SP. */
2166 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2167 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2172 dwarf2out_frame_finish ()
2174 /* Output call frame information. */
2175 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2176 output_call_frame_info (0);
2178 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2179 output_call_frame_info (1);
2182 /* And now, the subset of the debugging information support code necessary
2183 for emitting location expressions. */
2185 typedef struct dw_val_struct
*dw_val_ref
;
2186 typedef struct die_struct
*dw_die_ref
;
2187 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2188 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2190 /* Each DIE may have a series of attribute/value pairs. Values
2191 can take on several forms. The forms that are used in this
2192 implementation are listed below. */
2197 dw_val_class_offset
,
2199 dw_val_class_loc_list
,
2200 dw_val_class_range_list
,
2202 dw_val_class_unsigned_const
,
2203 dw_val_class_long_long
,
2206 dw_val_class_die_ref
,
2207 dw_val_class_fde_ref
,
2208 dw_val_class_lbl_id
,
2209 dw_val_class_lbl_offset
,
2214 /* Describe a double word constant value. */
2215 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2217 typedef struct dw_long_long_struct
2224 /* Describe a floating point constant value. */
2226 typedef struct dw_fp_struct
2233 /* The dw_val_node describes an attribute's value, as it is
2234 represented internally. */
2236 typedef struct dw_val_struct
2238 dw_val_class val_class
;
2242 long unsigned val_offset
;
2243 dw_loc_list_ref val_loc_list
;
2244 dw_loc_descr_ref val_loc
;
2246 long unsigned val_unsigned
;
2247 dw_long_long_const val_long_long
;
2248 dw_float_const val_float
;
2254 unsigned val_fde_index
;
2255 struct indirect_string_node
*val_str
;
2257 unsigned char val_flag
;
2263 /* Locations in memory are described using a sequence of stack machine
2266 typedef struct dw_loc_descr_struct
2268 dw_loc_descr_ref dw_loc_next
;
2269 enum dwarf_location_atom dw_loc_opc
;
2270 dw_val_node dw_loc_oprnd1
;
2271 dw_val_node dw_loc_oprnd2
;
2276 /* Location lists are ranges + location descriptions for that range,
2277 so you can track variables that are in different places over
2278 their entire life. */
2279 typedef struct dw_loc_list_struct
2281 dw_loc_list_ref dw_loc_next
;
2282 const char *begin
; /* Label for begin address of range */
2283 const char *end
; /* Label for end address of range */
2284 char *ll_symbol
; /* Label for beginning of location list.
2285 Only on head of list */
2286 const char *section
; /* Section this loclist is relative to */
2287 dw_loc_descr_ref expr
;
2290 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2291 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2294 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2296 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2297 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2298 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2299 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2301 /* Convert a DWARF stack opcode into its string name. */
2304 dwarf_stack_op_name (op
)
2310 return "DW_OP_addr";
2312 return "DW_OP_deref";
2314 return "DW_OP_const1u";
2316 return "DW_OP_const1s";
2318 return "DW_OP_const2u";
2320 return "DW_OP_const2s";
2322 return "DW_OP_const4u";
2324 return "DW_OP_const4s";
2326 return "DW_OP_const8u";
2328 return "DW_OP_const8s";
2330 return "DW_OP_constu";
2332 return "DW_OP_consts";
2336 return "DW_OP_drop";
2338 return "DW_OP_over";
2340 return "DW_OP_pick";
2342 return "DW_OP_swap";
2346 return "DW_OP_xderef";
2354 return "DW_OP_minus";
2366 return "DW_OP_plus";
2367 case DW_OP_plus_uconst
:
2368 return "DW_OP_plus_uconst";
2374 return "DW_OP_shra";
2392 return "DW_OP_skip";
2394 return "DW_OP_lit0";
2396 return "DW_OP_lit1";
2398 return "DW_OP_lit2";
2400 return "DW_OP_lit3";
2402 return "DW_OP_lit4";
2404 return "DW_OP_lit5";
2406 return "DW_OP_lit6";
2408 return "DW_OP_lit7";
2410 return "DW_OP_lit8";
2412 return "DW_OP_lit9";
2414 return "DW_OP_lit10";
2416 return "DW_OP_lit11";
2418 return "DW_OP_lit12";
2420 return "DW_OP_lit13";
2422 return "DW_OP_lit14";
2424 return "DW_OP_lit15";
2426 return "DW_OP_lit16";
2428 return "DW_OP_lit17";
2430 return "DW_OP_lit18";
2432 return "DW_OP_lit19";
2434 return "DW_OP_lit20";
2436 return "DW_OP_lit21";
2438 return "DW_OP_lit22";
2440 return "DW_OP_lit23";
2442 return "DW_OP_lit24";
2444 return "DW_OP_lit25";
2446 return "DW_OP_lit26";
2448 return "DW_OP_lit27";
2450 return "DW_OP_lit28";
2452 return "DW_OP_lit29";
2454 return "DW_OP_lit30";
2456 return "DW_OP_lit31";
2458 return "DW_OP_reg0";
2460 return "DW_OP_reg1";
2462 return "DW_OP_reg2";
2464 return "DW_OP_reg3";
2466 return "DW_OP_reg4";
2468 return "DW_OP_reg5";
2470 return "DW_OP_reg6";
2472 return "DW_OP_reg7";
2474 return "DW_OP_reg8";
2476 return "DW_OP_reg9";
2478 return "DW_OP_reg10";
2480 return "DW_OP_reg11";
2482 return "DW_OP_reg12";
2484 return "DW_OP_reg13";
2486 return "DW_OP_reg14";
2488 return "DW_OP_reg15";
2490 return "DW_OP_reg16";
2492 return "DW_OP_reg17";
2494 return "DW_OP_reg18";
2496 return "DW_OP_reg19";
2498 return "DW_OP_reg20";
2500 return "DW_OP_reg21";
2502 return "DW_OP_reg22";
2504 return "DW_OP_reg23";
2506 return "DW_OP_reg24";
2508 return "DW_OP_reg25";
2510 return "DW_OP_reg26";
2512 return "DW_OP_reg27";
2514 return "DW_OP_reg28";
2516 return "DW_OP_reg29";
2518 return "DW_OP_reg30";
2520 return "DW_OP_reg31";
2522 return "DW_OP_breg0";
2524 return "DW_OP_breg1";
2526 return "DW_OP_breg2";
2528 return "DW_OP_breg3";
2530 return "DW_OP_breg4";
2532 return "DW_OP_breg5";
2534 return "DW_OP_breg6";
2536 return "DW_OP_breg7";
2538 return "DW_OP_breg8";
2540 return "DW_OP_breg9";
2542 return "DW_OP_breg10";
2544 return "DW_OP_breg11";
2546 return "DW_OP_breg12";
2548 return "DW_OP_breg13";
2550 return "DW_OP_breg14";
2552 return "DW_OP_breg15";
2554 return "DW_OP_breg16";
2556 return "DW_OP_breg17";
2558 return "DW_OP_breg18";
2560 return "DW_OP_breg19";
2562 return "DW_OP_breg20";
2564 return "DW_OP_breg21";
2566 return "DW_OP_breg22";
2568 return "DW_OP_breg23";
2570 return "DW_OP_breg24";
2572 return "DW_OP_breg25";
2574 return "DW_OP_breg26";
2576 return "DW_OP_breg27";
2578 return "DW_OP_breg28";
2580 return "DW_OP_breg29";
2582 return "DW_OP_breg30";
2584 return "DW_OP_breg31";
2586 return "DW_OP_regx";
2588 return "DW_OP_fbreg";
2590 return "DW_OP_bregx";
2592 return "DW_OP_piece";
2593 case DW_OP_deref_size
:
2594 return "DW_OP_deref_size";
2595 case DW_OP_xderef_size
:
2596 return "DW_OP_xderef_size";
2600 return "OP_<unknown>";
2604 /* Return a pointer to a newly allocated location description. Location
2605 descriptions are simple expression terms that can be strung
2606 together to form more complicated location (address) descriptions. */
2608 static inline dw_loc_descr_ref
2609 new_loc_descr (op
, oprnd1
, oprnd2
)
2610 enum dwarf_location_atom op
;
2611 unsigned long oprnd1
;
2612 unsigned long oprnd2
;
2614 /* Use xcalloc here so we clear out all of the long_long constant in
2616 dw_loc_descr_ref descr
2617 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2619 descr
->dw_loc_opc
= op
;
2620 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2621 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2622 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2623 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2629 /* Add a location description term to a location description expression. */
2632 add_loc_descr (list_head
, descr
)
2633 dw_loc_descr_ref
*list_head
;
2634 dw_loc_descr_ref descr
;
2636 dw_loc_descr_ref
*d
;
2638 /* Find the end of the chain. */
2639 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2645 /* Return the size of a location descriptor. */
2647 static unsigned long
2648 size_of_loc_descr (loc
)
2649 dw_loc_descr_ref loc
;
2651 unsigned long size
= 1;
2653 switch (loc
->dw_loc_opc
)
2656 size
+= DWARF2_ADDR_SIZE
;
2675 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2678 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2683 case DW_OP_plus_uconst
:
2684 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2722 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2725 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2728 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2731 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2732 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2735 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2737 case DW_OP_deref_size
:
2738 case DW_OP_xderef_size
:
2748 /* Return the size of a series of location descriptors. */
2750 static unsigned long
2752 dw_loc_descr_ref loc
;
2756 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2758 loc
->dw_loc_addr
= size
;
2759 size
+= size_of_loc_descr (loc
);
2765 /* Output location description stack opcode's operands (if any). */
2768 output_loc_operands (loc
)
2769 dw_loc_descr_ref loc
;
2771 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2772 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2774 switch (loc
->dw_loc_opc
)
2776 #ifdef DWARF2_DEBUGGING_INFO
2778 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2782 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2786 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2790 if (HOST_BITS_PER_LONG
< 64)
2792 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2799 if (val1
->val_class
== dw_val_class_loc
)
2800 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2804 dw2_asm_output_data (2, offset
, NULL
);
2817 /* We currently don't make any attempt to make sure these are
2818 aligned properly like we do for the main unwind info, so
2819 don't support emitting things larger than a byte if we're
2820 only doing unwinding. */
2825 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2828 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2831 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2834 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2836 case DW_OP_plus_uconst
:
2837 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2871 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2874 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2877 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2880 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2881 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2884 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2886 case DW_OP_deref_size
:
2887 case DW_OP_xderef_size
:
2888 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2891 /* Other codes have no operands. */
2896 /* Output a sequence of location operations. */
2899 output_loc_sequence (loc
)
2900 dw_loc_descr_ref loc
;
2902 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2904 /* Output the opcode. */
2905 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2906 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2908 /* Output the operand(s) (if any). */
2909 output_loc_operands (loc
);
2913 /* This routine will generate the correct assembly data for a location
2914 description based on a cfi entry with a complex address. */
2917 output_cfa_loc (cfi
)
2920 dw_loc_descr_ref loc
;
2923 /* Output the size of the block. */
2924 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2925 size
= size_of_locs (loc
);
2926 dw2_asm_output_data_uleb128 (size
, NULL
);
2928 /* Now output the operations themselves. */
2929 output_loc_sequence (loc
);
2932 /* This function builds a dwarf location descriptor sequence from
2933 a dw_cfa_location. */
2935 static struct dw_loc_descr_struct
*
2937 dw_cfa_location
*cfa
;
2939 struct dw_loc_descr_struct
*head
, *tmp
;
2941 if (cfa
->indirect
== 0)
2944 if (cfa
->base_offset
)
2947 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
2949 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
2951 else if (cfa
->reg
<= 31)
2952 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
2954 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
2956 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2957 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2958 add_loc_descr (&head
, tmp
);
2959 if (cfa
->offset
!= 0)
2961 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
2962 add_loc_descr (&head
, tmp
);
2968 /* This function fills in aa dw_cfa_location structure from a dwarf location
2969 descriptor sequence. */
2972 get_cfa_from_loc_descr (cfa
, loc
)
2973 dw_cfa_location
*cfa
;
2974 struct dw_loc_descr_struct
*loc
;
2976 struct dw_loc_descr_struct
*ptr
;
2978 cfa
->base_offset
= 0;
2982 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
2984 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3020 cfa
->reg
= op
- DW_OP_reg0
;
3023 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3057 cfa
->reg
= op
- DW_OP_breg0
;
3058 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3061 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3062 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3067 case DW_OP_plus_uconst
:
3068 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3071 internal_error ("DW_LOC_OP %s not implemented\n",
3072 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3076 #endif /* .debug_frame support */
3078 /* And now, the support for symbolic debugging information. */
3079 #ifdef DWARF2_DEBUGGING_INFO
3081 /* .debug_str support. */
3082 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3083 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3084 hashnode
, const PTR
));
3087 static void dwarf2out_init
PARAMS ((const char *));
3088 static void dwarf2out_finish
PARAMS ((const char *));
3089 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3090 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3091 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3092 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3093 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3094 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3095 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3096 static void dwarf2out_global_decl
PARAMS ((tree
));
3097 static void dwarf2out_abstract_function
PARAMS ((tree
));
3099 /* The debug hooks structure. */
3101 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3107 dwarf2out_start_source_file
,
3108 dwarf2out_end_source_file
,
3109 dwarf2out_begin_block
,
3110 dwarf2out_end_block
,
3111 dwarf2out_ignore_block
,
3112 dwarf2out_source_line
,
3113 dwarf2out_begin_prologue
,
3114 debug_nothing_int_charstar
, /* end_prologue */
3115 dwarf2out_end_epilogue
,
3116 debug_nothing_tree
, /* begin_function */
3117 debug_nothing_int
, /* end_function */
3118 dwarf2out_decl
, /* function_decl */
3119 dwarf2out_global_decl
,
3120 debug_nothing_tree
, /* deferred_inline_function */
3121 /* The DWARF 2 backend tries to reduce debugging bloat by not
3122 emitting the abstract description of inline functions until
3123 something tries to reference them. */
3124 dwarf2out_abstract_function
, /* outlining_inline_function */
3125 debug_nothing_rtx
/* label */
3128 /* NOTE: In the comments in this file, many references are made to
3129 "Debugging Information Entries". This term is abbreviated as `DIE'
3130 throughout the remainder of this file. */
3132 /* An internal representation of the DWARF output is built, and then
3133 walked to generate the DWARF debugging info. The walk of the internal
3134 representation is done after the entire program has been compiled.
3135 The types below are used to describe the internal representation. */
3137 /* Various DIE's use offsets relative to the beginning of the
3138 .debug_info section to refer to each other. */
3140 typedef long int dw_offset
;
3142 /* Define typedefs here to avoid circular dependencies. */
3144 typedef struct dw_attr_struct
*dw_attr_ref
;
3145 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3146 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3147 typedef struct pubname_struct
*pubname_ref
;
3148 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3150 /* Each entry in the line_info_table maintains the file and
3151 line number associated with the label generated for that
3152 entry. The label gives the PC value associated with
3153 the line number entry. */
3155 typedef struct dw_line_info_struct
3157 unsigned long dw_file_num
;
3158 unsigned long dw_line_num
;
3162 /* Line information for functions in separate sections; each one gets its
3164 typedef struct dw_separate_line_info_struct
3166 unsigned long dw_file_num
;
3167 unsigned long dw_line_num
;
3168 unsigned long function
;
3170 dw_separate_line_info_entry
;
3172 /* Each DIE attribute has a field specifying the attribute kind,
3173 a link to the next attribute in the chain, and an attribute value.
3174 Attributes are typically linked below the DIE they modify. */
3176 typedef struct dw_attr_struct
3178 enum dwarf_attribute dw_attr
;
3179 dw_attr_ref dw_attr_next
;
3180 dw_val_node dw_attr_val
;
3184 /* The Debugging Information Entry (DIE) structure */
3186 typedef struct die_struct
3188 enum dwarf_tag die_tag
;
3190 dw_attr_ref die_attr
;
3191 dw_die_ref die_parent
;
3192 dw_die_ref die_child
;
3194 dw_offset die_offset
;
3195 unsigned long die_abbrev
;
3200 /* The pubname structure */
3202 typedef struct pubname_struct
3209 struct dw_ranges_struct
3214 /* The limbo die list structure. */
3215 typedef struct limbo_die_struct
3219 struct limbo_die_struct
*next
;
3223 /* How to start an assembler comment. */
3224 #ifndef ASM_COMMENT_START
3225 #define ASM_COMMENT_START ";#"
3228 /* Define a macro which returns non-zero for a TYPE_DECL which was
3229 implicitly generated for a tagged type.
3231 Note that unlike the gcc front end (which generates a NULL named
3232 TYPE_DECL node for each complete tagged type, each array type, and
3233 each function type node created) the g++ front end generates a
3234 _named_ TYPE_DECL node for each tagged type node created.
3235 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3236 generate a DW_TAG_typedef DIE for them. */
3238 #define TYPE_DECL_IS_STUB(decl) \
3239 (DECL_NAME (decl) == NULL_TREE \
3240 || (DECL_ARTIFICIAL (decl) \
3241 && is_tagged_type (TREE_TYPE (decl)) \
3242 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3243 /* This is necessary for stub decls that \
3244 appear in nested inline functions. */ \
3245 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3246 && (decl_ultimate_origin (decl) \
3247 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3249 /* Information concerning the compilation unit's programming
3250 language, and compiler version. */
3252 /* Fixed size portion of the DWARF compilation unit header. */
3253 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3255 /* Fixed size portion of public names info. */
3256 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3258 /* Fixed size portion of the address range info. */
3259 #define DWARF_ARANGES_HEADER_SIZE \
3260 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3261 - DWARF_OFFSET_SIZE)
3263 /* Size of padding portion in the address range info. It must be
3264 aligned to twice the pointer size. */
3265 #define DWARF_ARANGES_PAD_SIZE \
3266 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3267 - (2 * DWARF_OFFSET_SIZE + 4))
3269 /* Use assembler line directives if available. */
3270 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3271 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3272 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3274 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3278 /* Minimum line offset in a special line info. opcode.
3279 This value was chosen to give a reasonable range of values. */
3280 #define DWARF_LINE_BASE -10
3282 /* First special line opcode - leave room for the standard opcodes. */
3283 #define DWARF_LINE_OPCODE_BASE 10
3285 /* Range of line offsets in a special line info. opcode. */
3286 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3288 /* Flag that indicates the initial value of the is_stmt_start flag.
3289 In the present implementation, we do not mark any lines as
3290 the beginning of a source statement, because that information
3291 is not made available by the GCC front-end. */
3292 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3294 /* This location is used by calc_die_sizes() to keep track
3295 the offset of each DIE within the .debug_info section. */
3296 static unsigned long next_die_offset
;
3298 /* Record the root of the DIE's built for the current compilation unit. */
3299 static dw_die_ref comp_unit_die
;
3301 /* A list of DIEs with a NULL parent waiting to be relocated. */
3302 static limbo_die_node
*limbo_die_list
= 0;
3304 /* Structure used by lookup_filename to manage sets of filenames. */
3310 unsigned last_lookup_index
;
3313 /* Size (in elements) of increments by which we may expand the filename
3315 #define FILE_TABLE_INCREMENT 64
3317 /* Filenames referenced by this compilation unit. */
3318 static struct file_table file_table
;
3320 /* Local pointer to the name of the main input file. Initialized in
3322 static const char *primary_filename
;
3324 /* A pointer to the base of a table of references to DIE's that describe
3325 declarations. The table is indexed by DECL_UID() which is a unique
3326 number identifying each decl. */
3327 static dw_die_ref
*decl_die_table
;
3329 /* Number of elements currently allocated for the decl_die_table. */
3330 static unsigned decl_die_table_allocated
;
3332 /* Number of elements in decl_die_table currently in use. */
3333 static unsigned decl_die_table_in_use
;
3335 /* Size (in elements) of increments by which we may expand the
3337 #define DECL_DIE_TABLE_INCREMENT 256
3339 /* A pointer to the base of a list of references to DIE's that
3340 are uniquely identified by their tag, presence/absence of
3341 children DIE's, and list of attribute/value pairs. */
3342 static dw_die_ref
*abbrev_die_table
;
3344 /* Number of elements currently allocated for abbrev_die_table. */
3345 static unsigned abbrev_die_table_allocated
;
3347 /* Number of elements in type_die_table currently in use. */
3348 static unsigned abbrev_die_table_in_use
;
3350 /* Size (in elements) of increments by which we may expand the
3351 abbrev_die_table. */
3352 #define ABBREV_DIE_TABLE_INCREMENT 256
3354 /* A pointer to the base of a table that contains line information
3355 for each source code line in .text in the compilation unit. */
3356 static dw_line_info_ref line_info_table
;
3358 /* Number of elements currently allocated for line_info_table. */
3359 static unsigned line_info_table_allocated
;
3361 /* Number of elements in separate_line_info_table currently in use. */
3362 static unsigned separate_line_info_table_in_use
;
3364 /* A pointer to the base of a table that contains line information
3365 for each source code line outside of .text in the compilation unit. */
3366 static dw_separate_line_info_ref separate_line_info_table
;
3368 /* Number of elements currently allocated for separate_line_info_table. */
3369 static unsigned separate_line_info_table_allocated
;
3371 /* Number of elements in line_info_table currently in use. */
3372 static unsigned line_info_table_in_use
;
3374 /* Size (in elements) of increments by which we may expand the
3376 #define LINE_INFO_TABLE_INCREMENT 1024
3378 /* A pointer to the base of a table that contains a list of publicly
3379 accessible names. */
3380 static pubname_ref pubname_table
;
3382 /* Number of elements currently allocated for pubname_table. */
3383 static unsigned pubname_table_allocated
;
3385 /* Number of elements in pubname_table currently in use. */
3386 static unsigned pubname_table_in_use
;
3388 /* Size (in elements) of increments by which we may expand the
3390 #define PUBNAME_TABLE_INCREMENT 64
3392 /* Array of dies for which we should generate .debug_arange info. */
3393 static dw_die_ref
*arange_table
;
3395 /* Number of elements currently allocated for arange_table. */
3396 static unsigned arange_table_allocated
;
3398 /* Number of elements in arange_table currently in use. */
3399 static unsigned arange_table_in_use
;
3401 /* Size (in elements) of increments by which we may expand the
3403 #define ARANGE_TABLE_INCREMENT 64
3405 /* Array of dies for which we should generate .debug_ranges info. */
3406 static dw_ranges_ref ranges_table
;
3408 /* Number of elements currently allocated for ranges_table. */
3409 static unsigned ranges_table_allocated
;
3411 /* Number of elements in ranges_table currently in use. */
3412 static unsigned ranges_table_in_use
;
3414 /* Size (in elements) of increments by which we may expand the
3416 #define RANGES_TABLE_INCREMENT 64
3418 /* Whether we have location lists that need outputting */
3419 static unsigned have_location_lists
;
3421 /* Record whether the function being analyzed contains inlined functions. */
3422 static int current_function_has_inlines
;
3423 #if 0 && defined (MIPS_DEBUGGING_INFO)
3424 static int comp_unit_has_inlines
;
3427 /* Forward declarations for functions defined in this file. */
3429 static int is_pseudo_reg
PARAMS ((rtx
));
3430 static tree type_main_variant
PARAMS ((tree
));
3431 static int is_tagged_type
PARAMS ((tree
));
3432 static const char *dwarf_tag_name
PARAMS ((unsigned));
3433 static const char *dwarf_attr_name
PARAMS ((unsigned));
3434 static const char *dwarf_form_name
PARAMS ((unsigned));
3436 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3438 static tree decl_ultimate_origin
PARAMS ((tree
));
3439 static tree block_ultimate_origin
PARAMS ((tree
));
3440 static tree decl_class_context
PARAMS ((tree
));
3441 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3442 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3443 static void add_AT_flag
PARAMS ((dw_die_ref
,
3444 enum dwarf_attribute
,
3446 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3447 static void add_AT_int
PARAMS ((dw_die_ref
,
3448 enum dwarf_attribute
, long));
3449 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3450 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3451 enum dwarf_attribute
,
3453 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3454 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3455 enum dwarf_attribute
,
3458 static void add_AT_float
PARAMS ((dw_die_ref
,
3459 enum dwarf_attribute
,
3461 static void add_AT_string
PARAMS ((dw_die_ref
,
3462 enum dwarf_attribute
,
3464 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3465 static int AT_string_form
PARAMS ((dw_attr_ref
));
3466 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3467 enum dwarf_attribute
,
3469 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3470 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3471 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3472 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3473 enum dwarf_attribute
,
3475 static void add_AT_loc
PARAMS ((dw_die_ref
,
3476 enum dwarf_attribute
,
3478 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3479 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3480 enum dwarf_attribute
,
3482 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3483 static void add_AT_addr
PARAMS ((dw_die_ref
,
3484 enum dwarf_attribute
,
3486 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3487 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3488 enum dwarf_attribute
,
3490 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3491 enum dwarf_attribute
,
3493 static void add_AT_offset
PARAMS ((dw_die_ref
,
3494 enum dwarf_attribute
,
3496 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3497 enum dwarf_attribute
,
3499 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3500 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3501 enum dwarf_attribute
));
3502 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3503 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3504 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3505 enum dwarf_attribute
));
3506 static int get_AT_flag
PARAMS ((dw_die_ref
,
3507 enum dwarf_attribute
));
3508 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3509 enum dwarf_attribute
));
3510 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3511 enum dwarf_attribute
));
3512 static int is_c_family
PARAMS ((void));
3513 static int is_cxx
PARAMS ((void));
3514 static int is_java
PARAMS ((void));
3515 static int is_fortran
PARAMS ((void));
3516 static void remove_AT
PARAMS ((dw_die_ref
,
3517 enum dwarf_attribute
));
3518 static inline void free_die
PARAMS ((dw_die_ref
));
3519 static void remove_children
PARAMS ((dw_die_ref
));
3520 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3521 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3523 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3524 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3525 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3526 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3527 static void print_spaces
PARAMS ((FILE *));
3528 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3529 static void print_dwarf_line_table
PARAMS ((FILE *));
3530 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3531 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3532 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3533 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3534 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3536 static void attr_checksum
PARAMS ((dw_attr_ref
,
3538 static void die_checksum
PARAMS ((dw_die_ref
,
3540 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3541 static int is_type_die
PARAMS ((dw_die_ref
));
3542 static int is_comdat_die
PARAMS ((dw_die_ref
));
3543 static int is_symbol_die
PARAMS ((dw_die_ref
));
3544 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3545 static void break_out_includes
PARAMS ((dw_die_ref
));
3546 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3547 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3548 static void output_location_lists
PARAMS ((dw_die_ref
));
3549 static int constant_size
PARAMS ((long unsigned));
3550 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3551 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3552 static void mark_dies
PARAMS ((dw_die_ref
));
3553 static void unmark_dies
PARAMS ((dw_die_ref
));
3554 static unsigned long size_of_pubnames
PARAMS ((void));
3555 static unsigned long size_of_aranges
PARAMS ((void));
3556 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3557 static void output_value_format
PARAMS ((dw_attr_ref
));
3558 static void output_abbrev_section
PARAMS ((void));
3559 static void output_die_symbol
PARAMS ((dw_die_ref
));
3560 static void output_die
PARAMS ((dw_die_ref
));
3561 static void output_compilation_unit_header
PARAMS ((void));
3562 static void output_comp_unit
PARAMS ((dw_die_ref
));
3563 static const char *dwarf2_name
PARAMS ((tree
, int));
3564 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3565 static void output_pubnames
PARAMS ((void));
3566 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3567 static void output_aranges
PARAMS ((void));
3568 static unsigned int add_ranges
PARAMS ((tree
));
3569 static void output_ranges
PARAMS ((void));
3570 static void output_line_info
PARAMS ((void));
3571 static void output_file_names
PARAMS ((void));
3572 static dw_die_ref base_type_die
PARAMS ((tree
));
3573 static tree root_type
PARAMS ((tree
));
3574 static int is_base_type
PARAMS ((tree
));
3575 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3576 static int type_is_enum
PARAMS ((tree
));
3577 static unsigned int reg_number
PARAMS ((rtx
));
3578 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3579 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3580 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3581 static int is_based_loc
PARAMS ((rtx
));
3582 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3583 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3584 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3585 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3586 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3587 static tree field_type
PARAMS ((tree
));
3588 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3589 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3590 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3591 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3592 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3593 enum dwarf_attribute
, rtx
));
3594 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3595 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3596 static rtx rtl_for_decl_location
PARAMS ((tree
));
3597 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3598 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3599 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3600 static void add_bound_info
PARAMS ((dw_die_ref
,
3601 enum dwarf_attribute
, tree
));
3602 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3603 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3604 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3605 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3606 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3607 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3608 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3609 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3610 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3611 static void push_decl_scope
PARAMS ((tree
));
3612 static void pop_decl_scope
PARAMS ((void));
3613 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3614 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3615 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3616 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3618 static const char *type_tag
PARAMS ((tree
));
3619 static tree member_declared_type
PARAMS ((tree
));
3621 static const char *decl_start_label
PARAMS ((tree
));
3623 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3624 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3626 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3628 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3629 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3630 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3631 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3632 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3633 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3634 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3635 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3636 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3637 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3638 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3639 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3640 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3641 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3642 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3643 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3644 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3645 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3646 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3647 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3648 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3649 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3650 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3651 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3652 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3653 static int is_redundant_typedef
PARAMS ((tree
));
3654 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3655 static unsigned lookup_filename
PARAMS ((const char *));
3656 static void init_file_table
PARAMS ((void));
3657 static void retry_incomplete_types
PARAMS ((void));
3658 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3659 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3660 static int file_info_cmp
PARAMS ((const void *, const void *));
3661 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3662 const char *, const char *,
3663 const char *, unsigned));
3664 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3666 const char *, const char *, const char *));
3667 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3668 static char *gen_internal_sym
PARAMS ((const char *));
3669 static void mark_limbo_die_list
PARAMS ((void *));
3671 /* Section names used to hold DWARF debugging information. */
3672 #ifndef DEBUG_INFO_SECTION
3673 #define DEBUG_INFO_SECTION ".debug_info"
3675 #ifndef DEBUG_ABBREV_SECTION
3676 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3678 #ifndef DEBUG_ARANGES_SECTION
3679 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3681 #ifndef DEBUG_MACINFO_SECTION
3682 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3684 #ifndef DEBUG_LINE_SECTION
3685 #define DEBUG_LINE_SECTION ".debug_line"
3687 #ifndef DEBUG_LOC_SECTION
3688 #define DEBUG_LOC_SECTION ".debug_loc"
3690 #ifndef DEBUG_PUBNAMES_SECTION
3691 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3693 #ifndef DEBUG_STR_SECTION
3694 #define DEBUG_STR_SECTION ".debug_str"
3696 #ifndef DEBUG_RANGES_SECTION
3697 #define DEBUG_RANGES_SECTION ".debug_ranges"
3700 /* Standard ELF section names for compiled code and data. */
3701 #ifndef TEXT_SECTION_NAME
3702 #define TEXT_SECTION_NAME ".text"
3705 /* Section flags for .debug_str section. */
3706 #ifdef HAVE_GAS_SHF_MERGE
3707 #define DEBUG_STR_SECTION_FLAGS \
3708 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3710 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3713 /* Labels we insert at beginning sections we can reference instead of
3714 the section names themselves. */
3716 #ifndef TEXT_SECTION_LABEL
3717 #define TEXT_SECTION_LABEL "Ltext"
3719 #ifndef DEBUG_LINE_SECTION_LABEL
3720 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3722 #ifndef DEBUG_INFO_SECTION_LABEL
3723 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3725 #ifndef DEBUG_ABBREV_SECTION_LABEL
3726 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3728 #ifndef DEBUG_LOC_SECTION_LABEL
3729 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3731 #ifndef DEBUG_RANGES_SECTION_LABEL
3732 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3734 #ifndef DEBUG_MACINFO_SECTION_LABEL
3735 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3738 /* Definitions of defaults for formats and names of various special
3739 (artificial) labels which may be generated within this file (when the -g
3740 options is used and DWARF_DEBUGGING_INFO is in effect.
3741 If necessary, these may be overridden from within the tm.h file, but
3742 typically, overriding these defaults is unnecessary. */
3744 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3745 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3746 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3747 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3748 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3749 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3750 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3751 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3753 #ifndef TEXT_END_LABEL
3754 #define TEXT_END_LABEL "Letext"
3756 #ifndef BLOCK_BEGIN_LABEL
3757 #define BLOCK_BEGIN_LABEL "LBB"
3759 #ifndef BLOCK_END_LABEL
3760 #define BLOCK_END_LABEL "LBE"
3762 #ifndef LINE_CODE_LABEL
3763 #define LINE_CODE_LABEL "LM"
3765 #ifndef SEPARATE_LINE_CODE_LABEL
3766 #define SEPARATE_LINE_CODE_LABEL "LSM"
3769 /* We allow a language front-end to designate a function that is to be
3770 called to "demangle" any name before it it put into a DIE. */
3772 static const char *(*demangle_name_func
) PARAMS ((const char *));
3775 dwarf2out_set_demangle_name_func (func
)
3776 const char *(*func
) PARAMS ((const char *));
3778 demangle_name_func
= func
;
3781 /* Test if rtl node points to a pseudo register. */
3787 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3788 || (GET_CODE (rtl
) == SUBREG
3789 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3792 /* Return a reference to a type, with its const and volatile qualifiers
3796 type_main_variant (type
)
3799 type
= TYPE_MAIN_VARIANT (type
);
3801 /* ??? There really should be only one main variant among any group of
3802 variants of a given type (and all of the MAIN_VARIANT values for all
3803 members of the group should point to that one type) but sometimes the C
3804 front-end messes this up for array types, so we work around that bug
3806 if (TREE_CODE (type
) == ARRAY_TYPE
)
3807 while (type
!= TYPE_MAIN_VARIANT (type
))
3808 type
= TYPE_MAIN_VARIANT (type
);
3813 /* Return non-zero if the given type node represents a tagged type. */
3816 is_tagged_type (type
)
3819 enum tree_code code
= TREE_CODE (type
);
3821 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3822 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3825 /* Convert a DIE tag into its string name. */
3828 dwarf_tag_name (tag
)
3833 case DW_TAG_padding
:
3834 return "DW_TAG_padding";
3835 case DW_TAG_array_type
:
3836 return "DW_TAG_array_type";
3837 case DW_TAG_class_type
:
3838 return "DW_TAG_class_type";
3839 case DW_TAG_entry_point
:
3840 return "DW_TAG_entry_point";
3841 case DW_TAG_enumeration_type
:
3842 return "DW_TAG_enumeration_type";
3843 case DW_TAG_formal_parameter
:
3844 return "DW_TAG_formal_parameter";
3845 case DW_TAG_imported_declaration
:
3846 return "DW_TAG_imported_declaration";
3848 return "DW_TAG_label";
3849 case DW_TAG_lexical_block
:
3850 return "DW_TAG_lexical_block";
3852 return "DW_TAG_member";
3853 case DW_TAG_pointer_type
:
3854 return "DW_TAG_pointer_type";
3855 case DW_TAG_reference_type
:
3856 return "DW_TAG_reference_type";
3857 case DW_TAG_compile_unit
:
3858 return "DW_TAG_compile_unit";
3859 case DW_TAG_string_type
:
3860 return "DW_TAG_string_type";
3861 case DW_TAG_structure_type
:
3862 return "DW_TAG_structure_type";
3863 case DW_TAG_subroutine_type
:
3864 return "DW_TAG_subroutine_type";
3865 case DW_TAG_typedef
:
3866 return "DW_TAG_typedef";
3867 case DW_TAG_union_type
:
3868 return "DW_TAG_union_type";
3869 case DW_TAG_unspecified_parameters
:
3870 return "DW_TAG_unspecified_parameters";
3871 case DW_TAG_variant
:
3872 return "DW_TAG_variant";
3873 case DW_TAG_common_block
:
3874 return "DW_TAG_common_block";
3875 case DW_TAG_common_inclusion
:
3876 return "DW_TAG_common_inclusion";
3877 case DW_TAG_inheritance
:
3878 return "DW_TAG_inheritance";
3879 case DW_TAG_inlined_subroutine
:
3880 return "DW_TAG_inlined_subroutine";
3882 return "DW_TAG_module";
3883 case DW_TAG_ptr_to_member_type
:
3884 return "DW_TAG_ptr_to_member_type";
3885 case DW_TAG_set_type
:
3886 return "DW_TAG_set_type";
3887 case DW_TAG_subrange_type
:
3888 return "DW_TAG_subrange_type";
3889 case DW_TAG_with_stmt
:
3890 return "DW_TAG_with_stmt";
3891 case DW_TAG_access_declaration
:
3892 return "DW_TAG_access_declaration";
3893 case DW_TAG_base_type
:
3894 return "DW_TAG_base_type";
3895 case DW_TAG_catch_block
:
3896 return "DW_TAG_catch_block";
3897 case DW_TAG_const_type
:
3898 return "DW_TAG_const_type";
3899 case DW_TAG_constant
:
3900 return "DW_TAG_constant";
3901 case DW_TAG_enumerator
:
3902 return "DW_TAG_enumerator";
3903 case DW_TAG_file_type
:
3904 return "DW_TAG_file_type";
3906 return "DW_TAG_friend";
3907 case DW_TAG_namelist
:
3908 return "DW_TAG_namelist";
3909 case DW_TAG_namelist_item
:
3910 return "DW_TAG_namelist_item";
3911 case DW_TAG_packed_type
:
3912 return "DW_TAG_packed_type";
3913 case DW_TAG_subprogram
:
3914 return "DW_TAG_subprogram";
3915 case DW_TAG_template_type_param
:
3916 return "DW_TAG_template_type_param";
3917 case DW_TAG_template_value_param
:
3918 return "DW_TAG_template_value_param";
3919 case DW_TAG_thrown_type
:
3920 return "DW_TAG_thrown_type";
3921 case DW_TAG_try_block
:
3922 return "DW_TAG_try_block";
3923 case DW_TAG_variant_part
:
3924 return "DW_TAG_variant_part";
3925 case DW_TAG_variable
:
3926 return "DW_TAG_variable";
3927 case DW_TAG_volatile_type
:
3928 return "DW_TAG_volatile_type";
3929 case DW_TAG_MIPS_loop
:
3930 return "DW_TAG_MIPS_loop";
3931 case DW_TAG_format_label
:
3932 return "DW_TAG_format_label";
3933 case DW_TAG_function_template
:
3934 return "DW_TAG_function_template";
3935 case DW_TAG_class_template
:
3936 return "DW_TAG_class_template";
3937 case DW_TAG_GNU_BINCL
:
3938 return "DW_TAG_GNU_BINCL";
3939 case DW_TAG_GNU_EINCL
:
3940 return "DW_TAG_GNU_EINCL";
3942 return "DW_TAG_<unknown>";
3946 /* Convert a DWARF attribute code into its string name. */
3949 dwarf_attr_name (attr
)
3955 return "DW_AT_sibling";
3956 case DW_AT_location
:
3957 return "DW_AT_location";
3959 return "DW_AT_name";
3960 case DW_AT_ordering
:
3961 return "DW_AT_ordering";
3962 case DW_AT_subscr_data
:
3963 return "DW_AT_subscr_data";
3964 case DW_AT_byte_size
:
3965 return "DW_AT_byte_size";
3966 case DW_AT_bit_offset
:
3967 return "DW_AT_bit_offset";
3968 case DW_AT_bit_size
:
3969 return "DW_AT_bit_size";
3970 case DW_AT_element_list
:
3971 return "DW_AT_element_list";
3972 case DW_AT_stmt_list
:
3973 return "DW_AT_stmt_list";
3975 return "DW_AT_low_pc";
3977 return "DW_AT_high_pc";
3978 case DW_AT_language
:
3979 return "DW_AT_language";
3981 return "DW_AT_member";
3983 return "DW_AT_discr";
3984 case DW_AT_discr_value
:
3985 return "DW_AT_discr_value";
3986 case DW_AT_visibility
:
3987 return "DW_AT_visibility";
3989 return "DW_AT_import";
3990 case DW_AT_string_length
:
3991 return "DW_AT_string_length";
3992 case DW_AT_common_reference
:
3993 return "DW_AT_common_reference";
3994 case DW_AT_comp_dir
:
3995 return "DW_AT_comp_dir";
3996 case DW_AT_const_value
:
3997 return "DW_AT_const_value";
3998 case DW_AT_containing_type
:
3999 return "DW_AT_containing_type";
4000 case DW_AT_default_value
:
4001 return "DW_AT_default_value";
4003 return "DW_AT_inline";
4004 case DW_AT_is_optional
:
4005 return "DW_AT_is_optional";
4006 case DW_AT_lower_bound
:
4007 return "DW_AT_lower_bound";
4008 case DW_AT_producer
:
4009 return "DW_AT_producer";
4010 case DW_AT_prototyped
:
4011 return "DW_AT_prototyped";
4012 case DW_AT_return_addr
:
4013 return "DW_AT_return_addr";
4014 case DW_AT_start_scope
:
4015 return "DW_AT_start_scope";
4016 case DW_AT_stride_size
:
4017 return "DW_AT_stride_size";
4018 case DW_AT_upper_bound
:
4019 return "DW_AT_upper_bound";
4020 case DW_AT_abstract_origin
:
4021 return "DW_AT_abstract_origin";
4022 case DW_AT_accessibility
:
4023 return "DW_AT_accessibility";
4024 case DW_AT_address_class
:
4025 return "DW_AT_address_class";
4026 case DW_AT_artificial
:
4027 return "DW_AT_artificial";
4028 case DW_AT_base_types
:
4029 return "DW_AT_base_types";
4030 case DW_AT_calling_convention
:
4031 return "DW_AT_calling_convention";
4033 return "DW_AT_count";
4034 case DW_AT_data_member_location
:
4035 return "DW_AT_data_member_location";
4036 case DW_AT_decl_column
:
4037 return "DW_AT_decl_column";
4038 case DW_AT_decl_file
:
4039 return "DW_AT_decl_file";
4040 case DW_AT_decl_line
:
4041 return "DW_AT_decl_line";
4042 case DW_AT_declaration
:
4043 return "DW_AT_declaration";
4044 case DW_AT_discr_list
:
4045 return "DW_AT_discr_list";
4046 case DW_AT_encoding
:
4047 return "DW_AT_encoding";
4048 case DW_AT_external
:
4049 return "DW_AT_external";
4050 case DW_AT_frame_base
:
4051 return "DW_AT_frame_base";
4053 return "DW_AT_friend";
4054 case DW_AT_identifier_case
:
4055 return "DW_AT_identifier_case";
4056 case DW_AT_macro_info
:
4057 return "DW_AT_macro_info";
4058 case DW_AT_namelist_items
:
4059 return "DW_AT_namelist_items";
4060 case DW_AT_priority
:
4061 return "DW_AT_priority";
4063 return "DW_AT_segment";
4064 case DW_AT_specification
:
4065 return "DW_AT_specification";
4066 case DW_AT_static_link
:
4067 return "DW_AT_static_link";
4069 return "DW_AT_type";
4070 case DW_AT_use_location
:
4071 return "DW_AT_use_location";
4072 case DW_AT_variable_parameter
:
4073 return "DW_AT_variable_parameter";
4074 case DW_AT_virtuality
:
4075 return "DW_AT_virtuality";
4076 case DW_AT_vtable_elem_location
:
4077 return "DW_AT_vtable_elem_location";
4079 case DW_AT_allocated
:
4080 return "DW_AT_allocated";
4081 case DW_AT_associated
:
4082 return "DW_AT_associated";
4083 case DW_AT_data_location
:
4084 return "DW_AT_data_location";
4086 return "DW_AT_stride";
4087 case DW_AT_entry_pc
:
4088 return "DW_AT_entry_pc";
4089 case DW_AT_use_UTF8
:
4090 return "DW_AT_use_UTF8";
4091 case DW_AT_extension
:
4092 return "DW_AT_extension";
4094 return "DW_AT_ranges";
4095 case DW_AT_trampoline
:
4096 return "DW_AT_trampoline";
4097 case DW_AT_call_column
:
4098 return "DW_AT_call_column";
4099 case DW_AT_call_file
:
4100 return "DW_AT_call_file";
4101 case DW_AT_call_line
:
4102 return "DW_AT_call_line";
4104 case DW_AT_MIPS_fde
:
4105 return "DW_AT_MIPS_fde";
4106 case DW_AT_MIPS_loop_begin
:
4107 return "DW_AT_MIPS_loop_begin";
4108 case DW_AT_MIPS_tail_loop_begin
:
4109 return "DW_AT_MIPS_tail_loop_begin";
4110 case DW_AT_MIPS_epilog_begin
:
4111 return "DW_AT_MIPS_epilog_begin";
4112 case DW_AT_MIPS_loop_unroll_factor
:
4113 return "DW_AT_MIPS_loop_unroll_factor";
4114 case DW_AT_MIPS_software_pipeline_depth
:
4115 return "DW_AT_MIPS_software_pipeline_depth";
4116 case DW_AT_MIPS_linkage_name
:
4117 return "DW_AT_MIPS_linkage_name";
4118 case DW_AT_MIPS_stride
:
4119 return "DW_AT_MIPS_stride";
4120 case DW_AT_MIPS_abstract_name
:
4121 return "DW_AT_MIPS_abstract_name";
4122 case DW_AT_MIPS_clone_origin
:
4123 return "DW_AT_MIPS_clone_origin";
4124 case DW_AT_MIPS_has_inlines
:
4125 return "DW_AT_MIPS_has_inlines";
4127 case DW_AT_sf_names
:
4128 return "DW_AT_sf_names";
4129 case DW_AT_src_info
:
4130 return "DW_AT_src_info";
4131 case DW_AT_mac_info
:
4132 return "DW_AT_mac_info";
4133 case DW_AT_src_coords
:
4134 return "DW_AT_src_coords";
4135 case DW_AT_body_begin
:
4136 return "DW_AT_body_begin";
4137 case DW_AT_body_end
:
4138 return "DW_AT_body_end";
4139 case DW_AT_GNU_vector
:
4140 return "DW_AT_GNU_vector";
4142 case DW_AT_VMS_rtnbeg_pd_address
:
4143 return "DW_AT_VMS_rtnbeg_pd_address";
4146 return "DW_AT_<unknown>";
4150 /* Convert a DWARF value form code into its string name. */
4153 dwarf_form_name (form
)
4159 return "DW_FORM_addr";
4160 case DW_FORM_block2
:
4161 return "DW_FORM_block2";
4162 case DW_FORM_block4
:
4163 return "DW_FORM_block4";
4165 return "DW_FORM_data2";
4167 return "DW_FORM_data4";
4169 return "DW_FORM_data8";
4170 case DW_FORM_string
:
4171 return "DW_FORM_string";
4173 return "DW_FORM_block";
4174 case DW_FORM_block1
:
4175 return "DW_FORM_block1";
4177 return "DW_FORM_data1";
4179 return "DW_FORM_flag";
4181 return "DW_FORM_sdata";
4183 return "DW_FORM_strp";
4185 return "DW_FORM_udata";
4186 case DW_FORM_ref_addr
:
4187 return "DW_FORM_ref_addr";
4189 return "DW_FORM_ref1";
4191 return "DW_FORM_ref2";
4193 return "DW_FORM_ref4";
4195 return "DW_FORM_ref8";
4196 case DW_FORM_ref_udata
:
4197 return "DW_FORM_ref_udata";
4198 case DW_FORM_indirect
:
4199 return "DW_FORM_indirect";
4201 return "DW_FORM_<unknown>";
4205 /* Convert a DWARF type code into its string name. */
4209 dwarf_type_encoding_name (enc
)
4214 case DW_ATE_address
:
4215 return "DW_ATE_address";
4216 case DW_ATE_boolean
:
4217 return "DW_ATE_boolean";
4218 case DW_ATE_complex_float
:
4219 return "DW_ATE_complex_float";
4221 return "DW_ATE_float";
4223 return "DW_ATE_signed";
4224 case DW_ATE_signed_char
:
4225 return "DW_ATE_signed_char";
4226 case DW_ATE_unsigned
:
4227 return "DW_ATE_unsigned";
4228 case DW_ATE_unsigned_char
:
4229 return "DW_ATE_unsigned_char";
4231 return "DW_ATE_<unknown>";
4236 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4237 instance of an inlined instance of a decl which is local to an inline
4238 function, so we have to trace all of the way back through the origin chain
4239 to find out what sort of node actually served as the original seed for the
4243 decl_ultimate_origin (decl
)
4246 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4247 nodes in the function to point to themselves; ignore that if
4248 we're trying to output the abstract instance of this function. */
4249 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4252 #ifdef ENABLE_CHECKING
4253 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4254 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4255 most distant ancestor, this should never happen. */
4259 return DECL_ABSTRACT_ORIGIN (decl
);
4262 /* Determine the "ultimate origin" of a block. The block may be an inlined
4263 instance of an inlined instance of a block which is local to an inline
4264 function, so we have to trace all of the way back through the origin chain
4265 to find out what sort of node actually served as the original seed for the
4269 block_ultimate_origin (block
)
4272 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4274 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4275 nodes in the function to point to themselves; ignore that if
4276 we're trying to output the abstract instance of this function. */
4277 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4280 if (immediate_origin
== NULL_TREE
)
4285 tree lookahead
= immediate_origin
;
4289 ret_val
= lookahead
;
4290 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4291 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4293 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4299 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4300 of a virtual function may refer to a base class, so we check the 'this'
4304 decl_class_context (decl
)
4307 tree context
= NULL_TREE
;
4309 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4310 context
= DECL_CONTEXT (decl
);
4312 context
= TYPE_MAIN_VARIANT
4313 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4315 if (context
&& !TYPE_P (context
))
4316 context
= NULL_TREE
;
4321 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4322 addition order, and correct that in reverse_all_dies. */
4325 add_dwarf_attr (die
, attr
)
4329 if (die
!= NULL
&& attr
!= NULL
)
4331 attr
->dw_attr_next
= die
->die_attr
;
4332 die
->die_attr
= attr
;
4336 static inline dw_val_class
4340 return a
->dw_attr_val
.val_class
;
4343 /* Add a flag value attribute to a DIE. */
4346 add_AT_flag (die
, attr_kind
, flag
)
4348 enum dwarf_attribute attr_kind
;
4351 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4353 attr
->dw_attr_next
= NULL
;
4354 attr
->dw_attr
= attr_kind
;
4355 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4356 attr
->dw_attr_val
.v
.val_flag
= flag
;
4357 add_dwarf_attr (die
, attr
);
4360 static inline unsigned
4364 if (a
&& AT_class (a
) == dw_val_class_flag
)
4365 return a
->dw_attr_val
.v
.val_flag
;
4370 /* Add a signed integer attribute value to a DIE. */
4373 add_AT_int (die
, attr_kind
, int_val
)
4375 enum dwarf_attribute attr_kind
;
4378 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4380 attr
->dw_attr_next
= NULL
;
4381 attr
->dw_attr
= attr_kind
;
4382 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4383 attr
->dw_attr_val
.v
.val_int
= int_val
;
4384 add_dwarf_attr (die
, attr
);
4387 static inline long int
4391 if (a
&& AT_class (a
) == dw_val_class_const
)
4392 return a
->dw_attr_val
.v
.val_int
;
4397 /* Add an unsigned integer attribute value to a DIE. */
4400 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4402 enum dwarf_attribute attr_kind
;
4403 unsigned long unsigned_val
;
4405 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4407 attr
->dw_attr_next
= NULL
;
4408 attr
->dw_attr
= attr_kind
;
4409 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4410 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4411 add_dwarf_attr (die
, attr
);
4414 static inline unsigned long
4418 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4419 return a
->dw_attr_val
.v
.val_unsigned
;
4424 /* Add an unsigned double integer attribute value to a DIE. */
4427 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4429 enum dwarf_attribute attr_kind
;
4430 unsigned long val_hi
;
4431 unsigned long val_low
;
4433 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4435 attr
->dw_attr_next
= NULL
;
4436 attr
->dw_attr
= attr_kind
;
4437 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4438 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4439 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4440 add_dwarf_attr (die
, attr
);
4443 /* Add a floating point attribute value to a DIE and return it. */
4446 add_AT_float (die
, attr_kind
, length
, array
)
4448 enum dwarf_attribute attr_kind
;
4452 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4454 attr
->dw_attr_next
= NULL
;
4455 attr
->dw_attr
= attr_kind
;
4456 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4457 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4458 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4459 add_dwarf_attr (die
, attr
);
4462 /* Add a string attribute value to a DIE. */
4465 add_AT_string (die
, attr_kind
, str
)
4467 enum dwarf_attribute attr_kind
;
4470 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4471 struct indirect_string_node
*node
;
4473 if (! debug_str_hash
)
4475 debug_str_hash
= ht_create (10);
4476 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4479 node
= (struct indirect_string_node
*)
4480 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4481 strlen (str
), HT_ALLOC
);
4484 attr
->dw_attr_next
= NULL
;
4485 attr
->dw_attr
= attr_kind
;
4486 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4487 attr
->dw_attr_val
.v
.val_str
= node
;
4488 add_dwarf_attr (die
, attr
);
4491 static inline const char *
4495 if (a
&& AT_class (a
) == dw_val_class_str
)
4496 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4501 /* Find out whether a string should be output inline in DIE
4502 or out-of-line in .debug_str section. */
4508 if (a
&& AT_class (a
) == dw_val_class_str
)
4510 struct indirect_string_node
*node
;
4512 extern int const_labelno
;
4515 node
= a
->dw_attr_val
.v
.val_str
;
4519 len
= HT_LEN (&node
->id
) + 1;
4521 /* If the string is shorter or equal to the size of the reference, it is
4522 always better to put it inline. */
4523 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4524 return node
->form
= DW_FORM_string
;
4526 /* If we cannot expect the linker to merge strings in .debug_str
4527 section, only put it into .debug_str if it is worth even in this
4529 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4530 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4531 return node
->form
= DW_FORM_string
;
4533 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4535 node
->label
= xstrdup (label
);
4537 return node
->form
= DW_FORM_strp
;
4543 /* Add a DIE reference attribute value to a DIE. */
4546 add_AT_die_ref (die
, attr_kind
, targ_die
)
4548 enum dwarf_attribute attr_kind
;
4549 dw_die_ref targ_die
;
4551 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4553 attr
->dw_attr_next
= NULL
;
4554 attr
->dw_attr
= attr_kind
;
4555 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4556 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4557 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4558 add_dwarf_attr (die
, attr
);
4561 static inline dw_die_ref
4565 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4566 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4575 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4576 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4582 set_AT_ref_external (a
, i
)
4586 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4587 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4592 /* Add an FDE reference attribute value to a DIE. */
4595 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4597 enum dwarf_attribute attr_kind
;
4600 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4602 attr
->dw_attr_next
= NULL
;
4603 attr
->dw_attr
= attr_kind
;
4604 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4605 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4606 add_dwarf_attr (die
, attr
);
4609 /* Add a location description attribute value to a DIE. */
4612 add_AT_loc (die
, attr_kind
, loc
)
4614 enum dwarf_attribute attr_kind
;
4615 dw_loc_descr_ref loc
;
4617 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4619 attr
->dw_attr_next
= NULL
;
4620 attr
->dw_attr
= attr_kind
;
4621 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4622 attr
->dw_attr_val
.v
.val_loc
= loc
;
4623 add_dwarf_attr (die
, attr
);
4626 static inline dw_loc_descr_ref
4630 if (a
&& AT_class (a
) == dw_val_class_loc
)
4631 return a
->dw_attr_val
.v
.val_loc
;
4637 add_AT_loc_list (die
, attr_kind
, loc_list
)
4639 enum dwarf_attribute attr_kind
;
4640 dw_loc_list_ref loc_list
;
4642 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4644 attr
->dw_attr_next
= NULL
;
4645 attr
->dw_attr
= attr_kind
;
4646 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4647 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4648 add_dwarf_attr (die
, attr
);
4649 have_location_lists
= 1;
4652 static inline dw_loc_list_ref
4656 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4657 return a
->dw_attr_val
.v
.val_loc_list
;
4662 /* Add an address constant attribute value to a DIE. */
4665 add_AT_addr (die
, attr_kind
, addr
)
4667 enum dwarf_attribute attr_kind
;
4670 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4672 attr
->dw_attr_next
= NULL
;
4673 attr
->dw_attr
= attr_kind
;
4674 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4675 attr
->dw_attr_val
.v
.val_addr
= addr
;
4676 add_dwarf_attr (die
, attr
);
4683 if (a
&& AT_class (a
) == dw_val_class_addr
)
4684 return a
->dw_attr_val
.v
.val_addr
;
4689 /* Add a label identifier attribute value to a DIE. */
4692 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4694 enum dwarf_attribute attr_kind
;
4697 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4699 attr
->dw_attr_next
= NULL
;
4700 attr
->dw_attr
= attr_kind
;
4701 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4702 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4703 add_dwarf_attr (die
, attr
);
4706 /* Add a section offset attribute value to a DIE. */
4709 add_AT_lbl_offset (die
, attr_kind
, label
)
4711 enum dwarf_attribute attr_kind
;
4714 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4716 attr
->dw_attr_next
= NULL
;
4717 attr
->dw_attr
= attr_kind
;
4718 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4719 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4720 add_dwarf_attr (die
, attr
);
4723 /* Add an offset attribute value to a DIE. */
4726 add_AT_offset (die
, attr_kind
, offset
)
4728 enum dwarf_attribute attr_kind
;
4729 unsigned long offset
;
4731 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4733 attr
->dw_attr_next
= NULL
;
4734 attr
->dw_attr
= attr_kind
;
4735 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4736 attr
->dw_attr_val
.v
.val_offset
= offset
;
4737 add_dwarf_attr (die
, attr
);
4740 /* Add an range_list attribute value to a DIE. */
4743 add_AT_range_list (die
, attr_kind
, offset
)
4745 enum dwarf_attribute attr_kind
;
4746 unsigned long offset
;
4748 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4750 attr
->dw_attr_next
= NULL
;
4751 attr
->dw_attr
= attr_kind
;
4752 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4753 attr
->dw_attr_val
.v
.val_offset
= offset
;
4754 add_dwarf_attr (die
, attr
);
4757 static inline const char *
4761 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4762 || AT_class (a
) == dw_val_class_lbl_offset
))
4763 return a
->dw_attr_val
.v
.val_lbl_id
;
4768 /* Get the attribute of type attr_kind. */
4770 static inline dw_attr_ref
4771 get_AT (die
, attr_kind
)
4773 enum dwarf_attribute attr_kind
;
4776 dw_die_ref spec
= NULL
;
4780 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4781 if (a
->dw_attr
== attr_kind
)
4783 else if (a
->dw_attr
== DW_AT_specification
4784 || a
->dw_attr
== DW_AT_abstract_origin
)
4788 return get_AT (spec
, attr_kind
);
4794 /* Return the "low pc" attribute value, typically associated with a subprogram
4795 DIE. Return null if the "low pc" attribute is either not present, or if it
4796 cannot be represented as an assembler label identifier. */
4798 static inline const char *
4802 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4804 return a
? AT_lbl (a
) : NULL
;
4807 /* Return the "high pc" attribute value, typically associated with a subprogram
4808 DIE. Return null if the "high pc" attribute is either not present, or if it
4809 cannot be represented as an assembler label identifier. */
4811 static inline const char *
4815 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4817 return a
? AT_lbl (a
) : NULL
;
4820 /* Return the value of the string attribute designated by ATTR_KIND, or
4821 NULL if it is not present. */
4823 static inline const char *
4824 get_AT_string (die
, attr_kind
)
4826 enum dwarf_attribute attr_kind
;
4828 dw_attr_ref a
= get_AT (die
, attr_kind
);
4830 return a
? AT_string (a
) : NULL
;
4833 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4834 if it is not present. */
4837 get_AT_flag (die
, attr_kind
)
4839 enum dwarf_attribute attr_kind
;
4841 dw_attr_ref a
= get_AT (die
, attr_kind
);
4843 return a
? AT_flag (a
) : 0;
4846 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4847 if it is not present. */
4849 static inline unsigned
4850 get_AT_unsigned (die
, attr_kind
)
4852 enum dwarf_attribute attr_kind
;
4854 dw_attr_ref a
= get_AT (die
, attr_kind
);
4856 return a
? AT_unsigned (a
) : 0;
4859 static inline dw_die_ref
4860 get_AT_ref (die
, attr_kind
)
4862 enum dwarf_attribute attr_kind
;
4864 dw_attr_ref a
= get_AT (die
, attr_kind
);
4866 return a
? AT_ref (a
) : NULL
;
4872 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4874 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4875 || lang
== DW_LANG_C_plus_plus
);
4881 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4882 == DW_LANG_C_plus_plus
);
4888 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4890 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4896 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4898 return (lang
== DW_LANG_Java
);
4901 /* Free up the memory used by A. */
4903 static inline void free_AT
PARAMS ((dw_attr_ref
));
4908 switch (AT_class (a
))
4910 case dw_val_class_str
:
4911 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4912 a
->dw_attr_val
.v
.val_str
->refcount
--;
4915 case dw_val_class_lbl_id
:
4916 case dw_val_class_lbl_offset
:
4917 free (a
->dw_attr_val
.v
.val_lbl_id
);
4920 case dw_val_class_float
:
4921 free (a
->dw_attr_val
.v
.val_float
.array
);
4931 /* Remove the specified attribute if present. */
4934 remove_AT (die
, attr_kind
)
4936 enum dwarf_attribute attr_kind
;
4939 dw_attr_ref removed
= NULL
;
4943 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4944 if ((*p
)->dw_attr
== attr_kind
)
4947 *p
= (*p
)->dw_attr_next
;
4956 /* Free up the memory used by DIE. */
4962 remove_children (die
);
4966 /* Discard the children of this DIE. */
4969 remove_children (die
)
4972 dw_die_ref child_die
= die
->die_child
;
4974 die
->die_child
= NULL
;
4976 while (child_die
!= NULL
)
4978 dw_die_ref tmp_die
= child_die
;
4981 child_die
= child_die
->die_sib
;
4983 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
4985 dw_attr_ref tmp_a
= a
;
4987 a
= a
->dw_attr_next
;
4995 /* Add a child DIE below its parent. We build the lists up in reverse
4996 addition order, and correct that in reverse_all_dies. */
4999 add_child_die (die
, child_die
)
5001 dw_die_ref child_die
;
5003 if (die
!= NULL
&& child_die
!= NULL
)
5005 if (die
== child_die
)
5008 child_die
->die_parent
= die
;
5009 child_die
->die_sib
= die
->die_child
;
5010 die
->die_child
= child_die
;
5014 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5015 is the specification, to the front of PARENT's list of children. */
5018 splice_child_die (parent
, child
)
5019 dw_die_ref parent
, child
;
5023 /* We want the declaration DIE from inside the class, not the
5024 specification DIE at toplevel. */
5025 if (child
->die_parent
!= parent
)
5027 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5033 if (child
->die_parent
!= parent
5034 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5037 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5040 *p
= child
->die_sib
;
5044 child
->die_sib
= parent
->die_child
;
5045 parent
->die_child
= child
;
5048 /* Return a pointer to a newly created DIE node. */
5050 static inline dw_die_ref
5051 new_die (tag_value
, parent_die
, t
)
5052 enum dwarf_tag tag_value
;
5053 dw_die_ref parent_die
;
5056 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5058 die
->die_tag
= tag_value
;
5060 if (parent_die
!= NULL
)
5061 add_child_die (parent_die
, die
);
5064 limbo_die_node
*limbo_node
;
5066 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5067 limbo_node
->die
= die
;
5068 limbo_node
->created_for
= t
;
5069 limbo_node
->next
= limbo_die_list
;
5070 limbo_die_list
= limbo_node
;
5076 /* Return the DIE associated with the given type specifier. */
5078 static inline dw_die_ref
5079 lookup_type_die (type
)
5082 return TYPE_SYMTAB_DIE (type
);
5085 /* Equate a DIE to a given type specifier. */
5088 equate_type_number_to_die (type
, type_die
)
5090 dw_die_ref type_die
;
5092 TYPE_SYMTAB_DIE (type
) = type_die
;
5095 /* Return the DIE associated with a given declaration. */
5097 static inline dw_die_ref
5098 lookup_decl_die (decl
)
5101 unsigned decl_id
= DECL_UID (decl
);
5103 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5106 /* Equate a DIE to a particular declaration. */
5109 equate_decl_number_to_die (decl
, decl_die
)
5111 dw_die_ref decl_die
;
5113 unsigned int decl_id
= DECL_UID (decl
);
5114 unsigned int num_allocated
;
5116 if (decl_id
>= decl_die_table_allocated
)
5119 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5120 / DECL_DIE_TABLE_INCREMENT
)
5121 * DECL_DIE_TABLE_INCREMENT
;
5124 = (dw_die_ref
*) xrealloc (decl_die_table
,
5125 sizeof (dw_die_ref
) * num_allocated
);
5127 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5128 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5129 decl_die_table_allocated
= num_allocated
;
5132 if (decl_id
>= decl_die_table_in_use
)
5133 decl_die_table_in_use
= (decl_id
+ 1);
5135 decl_die_table
[decl_id
] = decl_die
;
5138 /* Keep track of the number of spaces used to indent the
5139 output of the debugging routines that print the structure of
5140 the DIE internal representation. */
5141 static int print_indent
;
5143 /* Indent the line the number of spaces given by print_indent. */
5146 print_spaces (outfile
)
5149 fprintf (outfile
, "%*s", print_indent
, "");
5152 /* Print the information associated with a given DIE, and its children.
5153 This routine is a debugging aid only. */
5156 print_die (die
, outfile
)
5163 print_spaces (outfile
);
5164 fprintf (outfile
, "DIE %4lu: %s\n",
5165 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5166 print_spaces (outfile
);
5167 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5168 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5170 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5172 print_spaces (outfile
);
5173 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5175 switch (AT_class (a
))
5177 case dw_val_class_addr
:
5178 fprintf (outfile
, "address");
5180 case dw_val_class_offset
:
5181 fprintf (outfile
, "offset");
5183 case dw_val_class_loc
:
5184 fprintf (outfile
, "location descriptor");
5186 case dw_val_class_loc_list
:
5187 fprintf (outfile
, "location list -> label:%s",
5188 AT_loc_list (a
)->ll_symbol
);
5190 case dw_val_class_range_list
:
5191 fprintf (outfile
, "range list");
5193 case dw_val_class_const
:
5194 fprintf (outfile
, "%ld", AT_int (a
));
5196 case dw_val_class_unsigned_const
:
5197 fprintf (outfile
, "%lu", AT_unsigned (a
));
5199 case dw_val_class_long_long
:
5200 fprintf (outfile
, "constant (%lu,%lu)",
5201 a
->dw_attr_val
.v
.val_long_long
.hi
,
5202 a
->dw_attr_val
.v
.val_long_long
.low
);
5204 case dw_val_class_float
:
5205 fprintf (outfile
, "floating-point constant");
5207 case dw_val_class_flag
:
5208 fprintf (outfile
, "%u", AT_flag (a
));
5210 case dw_val_class_die_ref
:
5211 if (AT_ref (a
) != NULL
)
5213 if (AT_ref (a
)->die_symbol
)
5214 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5216 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5219 fprintf (outfile
, "die -> <null>");
5221 case dw_val_class_lbl_id
:
5222 case dw_val_class_lbl_offset
:
5223 fprintf (outfile
, "label: %s", AT_lbl (a
));
5225 case dw_val_class_str
:
5226 if (AT_string (a
) != NULL
)
5227 fprintf (outfile
, "\"%s\"", AT_string (a
));
5229 fprintf (outfile
, "<null>");
5235 fprintf (outfile
, "\n");
5238 if (die
->die_child
!= NULL
)
5241 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5242 print_die (c
, outfile
);
5246 if (print_indent
== 0)
5247 fprintf (outfile
, "\n");
5250 /* Print the contents of the source code line number correspondence table.
5251 This routine is a debugging aid only. */
5254 print_dwarf_line_table (outfile
)
5258 dw_line_info_ref line_info
;
5260 fprintf (outfile
, "\n\nDWARF source line information\n");
5261 for (i
= 1; i
< line_info_table_in_use
; i
++)
5263 line_info
= &line_info_table
[i
];
5264 fprintf (outfile
, "%5d: ", i
);
5265 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5266 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5267 fprintf (outfile
, "\n");
5270 fprintf (outfile
, "\n\n");
5273 /* Print the information collected for a given DIE. */
5276 debug_dwarf_die (die
)
5279 print_die (die
, stderr
);
5282 /* Print all DWARF information collected for the compilation unit.
5283 This routine is a debugging aid only. */
5289 print_die (comp_unit_die
, stderr
);
5290 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5291 print_dwarf_line_table (stderr
);
5294 /* We build up the lists of children and attributes by pushing new ones
5295 onto the beginning of the list. Reverse the lists for DIE so that
5296 they are in order of addition. */
5299 reverse_die_lists (die
)
5302 dw_die_ref c
, cp
, cn
;
5303 dw_attr_ref a
, ap
, an
;
5305 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5307 an
= a
->dw_attr_next
;
5308 a
->dw_attr_next
= ap
;
5314 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5321 die
->die_child
= cp
;
5324 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5325 reverse all dies in add_sibling_attributes, which runs through all the dies,
5326 it would reverse all the dies. Now, however, since we don't call
5327 reverse_die_lists in add_sibling_attributes, we need a routine to
5328 recursively reverse all the dies. This is that routine. */
5331 reverse_all_dies (die
)
5336 reverse_die_lists (die
);
5338 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5339 reverse_all_dies (c
);
5342 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5343 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5344 DIE that marks the start of the DIEs for this include file. */
5347 push_new_compile_unit (old_unit
, bincl_die
)
5348 dw_die_ref old_unit
, bincl_die
;
5350 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5351 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5353 new_unit
->die_sib
= old_unit
;
5357 /* Close an include-file CU and reopen the enclosing one. */
5360 pop_compile_unit (old_unit
)
5361 dw_die_ref old_unit
;
5363 dw_die_ref new_unit
= old_unit
->die_sib
;
5365 old_unit
->die_sib
= NULL
;
5369 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5370 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5372 /* Calculate the checksum of a location expression. */
5375 loc_checksum (loc
, ctx
)
5376 dw_loc_descr_ref loc
;
5377 struct md5_ctx
*ctx
;
5379 CHECKSUM (loc
->dw_loc_opc
);
5380 CHECKSUM (loc
->dw_loc_oprnd1
);
5381 CHECKSUM (loc
->dw_loc_oprnd2
);
5384 /* Calculate the checksum of an attribute. */
5387 attr_checksum (at
, ctx
)
5389 struct md5_ctx
*ctx
;
5391 dw_loc_descr_ref loc
;
5394 CHECKSUM (at
->dw_attr
);
5396 /* We don't care about differences in file numbering. */
5397 if (at
->dw_attr
== DW_AT_decl_file
5398 /* Or that this was compiled with a different compiler snapshot; if
5399 the output is the same, that's what matters. */
5400 || at
->dw_attr
== DW_AT_producer
)
5403 switch (AT_class (at
))
5405 case dw_val_class_const
:
5406 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5408 case dw_val_class_unsigned_const
:
5409 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5411 case dw_val_class_long_long
:
5412 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5414 case dw_val_class_float
:
5415 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5417 case dw_val_class_flag
:
5418 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5420 case dw_val_class_str
:
5421 CHECKSUM_STRING (AT_string (at
));
5424 case dw_val_class_addr
:
5426 switch (GET_CODE (r
))
5429 CHECKSUM_STRING (XSTR (r
, 0));
5437 case dw_val_class_offset
:
5438 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5441 case dw_val_class_loc
:
5442 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5443 loc_checksum (loc
, ctx
);
5446 case dw_val_class_die_ref
:
5447 if (AT_ref (at
)->die_offset
)
5448 CHECKSUM (AT_ref (at
)->die_offset
);
5449 /* FIXME else use target die name or something. */
5451 case dw_val_class_fde_ref
:
5452 case dw_val_class_lbl_id
:
5453 case dw_val_class_lbl_offset
:
5461 /* Calculate the checksum of a DIE. */
5464 die_checksum (die
, ctx
)
5466 struct md5_ctx
*ctx
;
5471 CHECKSUM (die
->die_tag
);
5473 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5474 attr_checksum (a
, ctx
);
5476 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5477 die_checksum (c
, ctx
);
5481 #undef CHECKSUM_STRING
5483 /* The prefix to attach to symbols on DIEs in the current comdat debug
5485 static char *comdat_symbol_id
;
5487 /* The index of the current symbol within the current comdat CU. */
5488 static unsigned int comdat_symbol_number
;
5490 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5491 children, and set comdat_symbol_id accordingly. */
5494 compute_section_prefix (unit_die
)
5495 dw_die_ref unit_die
;
5497 const char *base
= lbasename (get_AT_string (unit_die
, DW_AT_name
));
5498 char *name
= (char *) alloca (strlen (base
) + 64);
5501 unsigned char checksum
[16];
5504 /* Compute the checksum of the DIE, then append part of it as hex digits to
5505 the name filename of the unit. */
5507 md5_init_ctx (&ctx
);
5508 die_checksum (unit_die
, &ctx
);
5509 md5_finish_ctx (&ctx
, checksum
);
5511 sprintf (name
, "%s.", base
);
5512 clean_symbol_name (name
);
5514 p
= name
+ strlen (name
);
5515 for (i
= 0; i
< 4; i
++)
5517 sprintf (p
, "%.2x", checksum
[i
]);
5521 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5522 comdat_symbol_number
= 0;
5525 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5531 switch (die
->die_tag
)
5533 case DW_TAG_array_type
:
5534 case DW_TAG_class_type
:
5535 case DW_TAG_enumeration_type
:
5536 case DW_TAG_pointer_type
:
5537 case DW_TAG_reference_type
:
5538 case DW_TAG_string_type
:
5539 case DW_TAG_structure_type
:
5540 case DW_TAG_subroutine_type
:
5541 case DW_TAG_union_type
:
5542 case DW_TAG_ptr_to_member_type
:
5543 case DW_TAG_set_type
:
5544 case DW_TAG_subrange_type
:
5545 case DW_TAG_base_type
:
5546 case DW_TAG_const_type
:
5547 case DW_TAG_file_type
:
5548 case DW_TAG_packed_type
:
5549 case DW_TAG_volatile_type
:
5556 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5557 Basically, we want to choose the bits that are likely to be shared between
5558 compilations (types) and leave out the bits that are specific to individual
5559 compilations (functions). */
5565 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5566 we do for stabs. The advantage is a greater likelihood of sharing between
5567 objects that don't include headers in the same order (and therefore would
5568 put the base types in a different comdat). jason 8/28/00 */
5570 if (c
->die_tag
== DW_TAG_base_type
)
5573 if (c
->die_tag
== DW_TAG_pointer_type
5574 || c
->die_tag
== DW_TAG_reference_type
5575 || c
->die_tag
== DW_TAG_const_type
5576 || c
->die_tag
== DW_TAG_volatile_type
)
5578 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5580 return t
? is_comdat_die (t
) : 0;
5583 return is_type_die (c
);
5586 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5587 compilation unit. */
5593 return (is_type_die (c
)
5594 || (get_AT (c
, DW_AT_declaration
)
5595 && !get_AT (c
, DW_AT_specification
)));
5599 gen_internal_sym (prefix
)
5603 static int label_num
;
5605 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5606 return xstrdup (buf
);
5609 /* Assign symbols to all worthy DIEs under DIE. */
5612 assign_symbol_names (die
)
5617 if (is_symbol_die (die
))
5619 if (comdat_symbol_id
)
5621 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5623 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5624 comdat_symbol_id
, comdat_symbol_number
++);
5625 die
->die_symbol
= xstrdup (p
);
5628 die
->die_symbol
= gen_internal_sym ("LDIE");
5631 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5632 assign_symbol_names (c
);
5635 /* Traverse the DIE (which is always comp_unit_die), and set up
5636 additional compilation units for each of the include files we see
5637 bracketed by BINCL/EINCL. */
5640 break_out_includes (die
)
5644 dw_die_ref unit
= NULL
;
5645 limbo_die_node
*node
;
5647 for (ptr
= &(die
->die_child
); *ptr
;)
5649 dw_die_ref c
= *ptr
;
5651 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5652 || (unit
&& is_comdat_die (c
)))
5654 /* This DIE is for a secondary CU; remove it from the main one. */
5657 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5659 unit
= push_new_compile_unit (unit
, c
);
5662 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5664 unit
= pop_compile_unit (unit
);
5668 add_child_die (unit
, c
);
5672 /* Leave this DIE in the main CU. */
5673 ptr
= &(c
->die_sib
);
5679 /* We can only use this in debugging, since the frontend doesn't check
5680 to make sure that we leave every include file we enter. */
5685 assign_symbol_names (die
);
5686 for (node
= limbo_die_list
; node
; node
= node
->next
)
5688 compute_section_prefix (node
->die
);
5689 assign_symbol_names (node
->die
);
5693 /* Traverse the DIE and add a sibling attribute if it may have the
5694 effect of speeding up access to siblings. To save some space,
5695 avoid generating sibling attributes for DIE's without children. */
5698 add_sibling_attributes (die
)
5703 if (die
->die_tag
!= DW_TAG_compile_unit
5704 && die
->die_sib
&& die
->die_child
!= NULL
)
5705 /* Add the sibling link to the front of the attribute list. */
5706 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5708 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5709 add_sibling_attributes (c
);
5712 /* Output all location lists for the DIE and its children. */
5715 output_location_lists (die
)
5721 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5722 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5723 output_loc_list (AT_loc_list (d_attr
));
5725 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5726 output_location_lists (c
);
5730 /* The format of each DIE (and its attribute value pairs) is encoded in an
5731 abbreviation table. This routine builds the abbreviation table and assigns
5732 a unique abbreviation id for each abbreviation entry. The children of each
5733 die are visited recursively. */
5736 build_abbrev_table (die
)
5739 unsigned long abbrev_id
;
5740 unsigned int n_alloc
;
5742 dw_attr_ref d_attr
, a_attr
;
5744 /* Scan the DIE references, and mark as external any that refer to
5745 DIEs from other CUs (i.e. those which are not marked). */
5746 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5747 if (AT_class (d_attr
) == dw_val_class_die_ref
5748 && AT_ref (d_attr
)->die_mark
== 0)
5750 if (AT_ref (d_attr
)->die_symbol
== 0)
5753 set_AT_ref_external (d_attr
, 1);
5756 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5758 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5760 if (abbrev
->die_tag
== die
->die_tag
)
5762 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
5764 a_attr
= abbrev
->die_attr
;
5765 d_attr
= die
->die_attr
;
5767 while (a_attr
!= NULL
&& d_attr
!= NULL
)
5769 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
5770 || (value_format (a_attr
) != value_format (d_attr
)))
5773 a_attr
= a_attr
->dw_attr_next
;
5774 d_attr
= d_attr
->dw_attr_next
;
5777 if (a_attr
== NULL
&& d_attr
== NULL
)
5783 if (abbrev_id
>= abbrev_die_table_in_use
)
5785 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
5787 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
5789 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
5790 sizeof (dw_die_ref
) * n_alloc
);
5792 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
5793 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
5794 abbrev_die_table_allocated
= n_alloc
;
5797 ++abbrev_die_table_in_use
;
5798 abbrev_die_table
[abbrev_id
] = die
;
5801 die
->die_abbrev
= abbrev_id
;
5802 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5803 build_abbrev_table (c
);
5806 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5809 constant_size (value
)
5810 long unsigned value
;
5817 log
= floor_log2 (value
);
5820 log
= 1 << (floor_log2 (log
) + 1);
5825 /* Return the size of a DIE as it is represented in the
5826 .debug_info section. */
5828 static unsigned long
5832 unsigned long size
= 0;
5835 size
+= size_of_uleb128 (die
->die_abbrev
);
5836 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5838 switch (AT_class (a
))
5840 case dw_val_class_addr
:
5841 size
+= DWARF2_ADDR_SIZE
;
5843 case dw_val_class_offset
:
5844 size
+= DWARF_OFFSET_SIZE
;
5846 case dw_val_class_loc
:
5848 unsigned long lsize
= size_of_locs (AT_loc (a
));
5851 size
+= constant_size (lsize
);
5855 case dw_val_class_loc_list
:
5856 size
+= DWARF_OFFSET_SIZE
;
5858 case dw_val_class_range_list
:
5859 size
+= DWARF_OFFSET_SIZE
;
5861 case dw_val_class_const
:
5862 size
+= size_of_sleb128 (AT_int (a
));
5864 case dw_val_class_unsigned_const
:
5865 size
+= constant_size (AT_unsigned (a
));
5867 case dw_val_class_long_long
:
5868 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
5870 case dw_val_class_float
:
5871 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
5873 case dw_val_class_flag
:
5876 case dw_val_class_die_ref
:
5877 size
+= DWARF_OFFSET_SIZE
;
5879 case dw_val_class_fde_ref
:
5880 size
+= DWARF_OFFSET_SIZE
;
5882 case dw_val_class_lbl_id
:
5883 size
+= DWARF2_ADDR_SIZE
;
5885 case dw_val_class_lbl_offset
:
5886 size
+= DWARF_OFFSET_SIZE
;
5888 case dw_val_class_str
:
5889 if (AT_string_form (a
) == DW_FORM_strp
)
5890 size
+= DWARF_OFFSET_SIZE
;
5892 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
5902 /* Size the debugging information associated with a given DIE. Visits the
5903 DIE's children recursively. Updates the global variable next_die_offset, on
5904 each time through. Uses the current value of next_die_offset to update the
5905 die_offset field in each DIE. */
5908 calc_die_sizes (die
)
5913 die
->die_offset
= next_die_offset
;
5914 next_die_offset
+= size_of_die (die
);
5916 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5919 if (die
->die_child
!= NULL
)
5920 /* Count the null byte used to terminate sibling lists. */
5921 next_die_offset
+= 1;
5924 /* Set the marks for a die and its children. We do this so
5925 that we know whether or not a reference needs to use FORM_ref_addr; only
5926 DIEs in the same CU will be marked. We used to clear out the offset
5927 and use that as the flag, but ran into ordering problems. */
5936 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5940 /* Clear the marks for a die and its children. */
5949 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5953 /* Return the size of the .debug_pubnames table generated for the
5954 compilation unit. */
5956 static unsigned long
5962 size
= DWARF_PUBNAMES_HEADER_SIZE
;
5963 for (i
= 0; i
< pubname_table_in_use
; i
++)
5965 pubname_ref p
= &pubname_table
[i
];
5966 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
5969 size
+= DWARF_OFFSET_SIZE
;
5973 /* Return the size of the information in the .debug_aranges section. */
5975 static unsigned long
5980 size
= DWARF_ARANGES_HEADER_SIZE
;
5982 /* Count the address/length pair for this compilation unit. */
5983 size
+= 2 * DWARF2_ADDR_SIZE
;
5984 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
5986 /* Count the two zero words used to terminated the address range table. */
5987 size
+= 2 * DWARF2_ADDR_SIZE
;
5991 /* Select the encoding of an attribute value. */
5993 static enum dwarf_form
5997 switch (a
->dw_attr_val
.val_class
)
5999 case dw_val_class_addr
:
6000 return DW_FORM_addr
;
6001 case dw_val_class_range_list
:
6002 case dw_val_class_offset
:
6003 if (DWARF_OFFSET_SIZE
== 4)
6004 return DW_FORM_data4
;
6005 if (DWARF_OFFSET_SIZE
== 8)
6006 return DW_FORM_data8
;
6008 case dw_val_class_loc_list
:
6009 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6010 .debug_loc section */
6011 return DW_FORM_data4
;
6012 case dw_val_class_loc
:
6013 switch (constant_size (size_of_locs (AT_loc (a
))))
6016 return DW_FORM_block1
;
6018 return DW_FORM_block2
;
6022 case dw_val_class_const
:
6023 return DW_FORM_sdata
;
6024 case dw_val_class_unsigned_const
:
6025 switch (constant_size (AT_unsigned (a
)))
6028 return DW_FORM_data1
;
6030 return DW_FORM_data2
;
6032 return DW_FORM_data4
;
6034 return DW_FORM_data8
;
6038 case dw_val_class_long_long
:
6039 return DW_FORM_block1
;
6040 case dw_val_class_float
:
6041 return DW_FORM_block1
;
6042 case dw_val_class_flag
:
6043 return DW_FORM_flag
;
6044 case dw_val_class_die_ref
:
6045 if (AT_ref_external (a
))
6046 return DW_FORM_ref_addr
;
6049 case dw_val_class_fde_ref
:
6050 return DW_FORM_data
;
6051 case dw_val_class_lbl_id
:
6052 return DW_FORM_addr
;
6053 case dw_val_class_lbl_offset
:
6054 return DW_FORM_data
;
6055 case dw_val_class_str
:
6056 return AT_string_form (a
);
6063 /* Output the encoding of an attribute value. */
6066 output_value_format (a
)
6069 enum dwarf_form form
= value_format (a
);
6071 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6074 /* Output the .debug_abbrev section which defines the DIE abbreviation
6078 output_abbrev_section ()
6080 unsigned long abbrev_id
;
6084 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6086 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6088 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6089 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6090 dwarf_tag_name (abbrev
->die_tag
));
6092 if (abbrev
->die_child
!= NULL
)
6093 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6095 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6097 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6098 a_attr
= a_attr
->dw_attr_next
)
6100 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6101 dwarf_attr_name (a_attr
->dw_attr
));
6102 output_value_format (a_attr
);
6105 dw2_asm_output_data (1, 0, NULL
);
6106 dw2_asm_output_data (1, 0, NULL
);
6109 /* Terminate the table. */
6110 dw2_asm_output_data (1, 0, NULL
);
6113 /* Output a symbol we can use to refer to this DIE from another CU. */
6116 output_die_symbol (die
)
6119 char *sym
= die
->die_symbol
;
6124 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6125 /* We make these global, not weak; if the target doesn't support
6126 .linkonce, it doesn't support combining the sections, so debugging
6128 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, sym
);
6130 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6133 /* Return a new location list, given the begin and end range, and the
6134 expression. gensym tells us whether to generate a new internal symbol for
6135 this location list node, which is done for the head of the list only. */
6137 static inline dw_loc_list_ref
6138 new_loc_list (expr
, begin
, end
, section
, gensym
)
6139 dw_loc_descr_ref expr
;
6142 const char *section
;
6145 dw_loc_list_ref retlist
6146 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6148 retlist
->begin
= begin
;
6150 retlist
->expr
= expr
;
6151 retlist
->section
= section
;
6153 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6158 /* Add a location description expression to a location list */
6161 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6162 dw_loc_list_ref
*list_head
;
6163 dw_loc_descr_ref descr
;
6166 const char *section
;
6170 /* Find the end of the chain. */
6171 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6174 /* Add a new location list node to the list */
6175 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6178 /* Output the location list given to us */
6181 output_loc_list (list_head
)
6182 dw_loc_list_ref list_head
;
6184 dw_loc_list_ref curr
= list_head
;
6186 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6188 /* ??? This shouldn't be needed now that we've forced the
6189 compilation unit base address to zero when there is code
6190 in more than one section. */
6191 if (strcmp (curr
->section
, ".text") == 0)
6193 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6194 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6195 "Location list base address specifier fake entry");
6196 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6197 "Location list base address specifier base");
6200 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6204 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6205 "Location list begin address (%s)",
6206 list_head
->ll_symbol
);
6207 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6208 "Location list end address (%s)",
6209 list_head
->ll_symbol
);
6210 size
= size_of_locs (curr
->expr
);
6212 /* Output the block length for this list of location operations. */
6215 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6217 output_loc_sequence (curr
->expr
);
6220 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6221 "Location list terminator begin (%s)",
6222 list_head
->ll_symbol
);
6223 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6224 "Location list terminator end (%s)",
6225 list_head
->ll_symbol
);
6228 /* Output the DIE and its attributes. Called recursively to generate
6229 the definitions of each child DIE. */
6239 /* If someone in another CU might refer to us, set up a symbol for
6240 them to point to. */
6241 if (die
->die_symbol
)
6242 output_die_symbol (die
);
6244 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6245 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6247 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6249 const char *name
= dwarf_attr_name (a
->dw_attr
);
6251 switch (AT_class (a
))
6253 case dw_val_class_addr
:
6254 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6257 case dw_val_class_offset
:
6258 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6262 case dw_val_class_range_list
:
6264 char *p
= strchr (ranges_section_label
, '\0');
6266 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6267 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6273 case dw_val_class_loc
:
6274 size
= size_of_locs (AT_loc (a
));
6276 /* Output the block length for this list of location operations. */
6277 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6279 output_loc_sequence (AT_loc (a
));
6282 case dw_val_class_const
:
6283 /* ??? It would be slightly more efficient to use a scheme like is
6284 used for unsigned constants below, but gdb 4.x does not sign
6285 extend. Gdb 5.x does sign extend. */
6286 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6289 case dw_val_class_unsigned_const
:
6290 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6291 AT_unsigned (a
), "%s", name
);
6294 case dw_val_class_long_long
:
6296 unsigned HOST_WIDE_INT first
, second
;
6298 dw2_asm_output_data (1,
6299 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6302 if (WORDS_BIG_ENDIAN
)
6304 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6305 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6309 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6310 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6313 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6314 first
, "long long constant");
6315 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6320 case dw_val_class_float
:
6324 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6327 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6328 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6329 "fp constant word %u", i
);
6333 case dw_val_class_flag
:
6334 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6337 case dw_val_class_loc_list
:
6339 char *sym
= AT_loc_list (a
)->ll_symbol
;
6343 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6344 loc_section_label
, "%s", name
);
6348 case dw_val_class_die_ref
:
6349 if (AT_ref_external (a
))
6351 char *sym
= AT_ref (a
)->die_symbol
;
6355 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6357 else if (AT_ref (a
)->die_offset
== 0)
6360 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6364 case dw_val_class_fde_ref
:
6368 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6369 a
->dw_attr_val
.v
.val_fde_index
* 2);
6370 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6374 case dw_val_class_lbl_id
:
6375 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6378 case dw_val_class_lbl_offset
:
6379 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6382 case dw_val_class_str
:
6383 if (AT_string_form (a
) == DW_FORM_strp
)
6384 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6385 a
->dw_attr_val
.v
.val_str
->label
,
6386 "%s: \"%s\"", name
, AT_string (a
));
6388 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6396 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6399 /* Add null byte to terminate sibling list. */
6400 if (die
->die_child
!= NULL
)
6401 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6405 /* Output the compilation unit that appears at the beginning of the
6406 .debug_info section, and precedes the DIE descriptions. */
6409 output_compilation_unit_header ()
6411 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6412 "Length of Compilation Unit Info");
6413 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6414 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6415 "Offset Into Abbrev. Section");
6416 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6419 /* Output the compilation unit DIE and its children. */
6422 output_comp_unit (die
)
6425 const char *secname
;
6427 /* Even if there are no children of this DIE, we must output the information
6428 about the compilation unit. Otherwise, on an empty translation unit, we
6429 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6430 will then complain when examining the file. First mark all the DIEs in
6431 this CU so we know which get local refs. */
6434 build_abbrev_table (die
);
6436 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6437 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6438 calc_die_sizes (die
);
6440 if (die
->die_symbol
)
6442 char *tmp
= (char *) alloca (strlen (die
->die_symbol
) + 24);
6444 sprintf (tmp
, ".gnu.linkonce.wi.%s", die
->die_symbol
);
6446 die
->die_symbol
= NULL
;
6449 secname
= (const char *) DEBUG_INFO_SECTION
;
6451 /* Output debugging information. */
6452 named_section_flags (secname
, SECTION_DEBUG
);
6453 output_compilation_unit_header ();
6456 /* Leave the marks on the main CU, so we can check them in
6458 if (die
->die_symbol
)
6462 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6463 output of lang_hooks.decl_printable_name for C++ looks like
6464 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6467 dwarf2_name (decl
, scope
)
6471 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6474 /* Add a new entry to .debug_pubnames if appropriate. */
6477 add_pubname (decl
, die
)
6483 if (! TREE_PUBLIC (decl
))
6486 if (pubname_table_in_use
== pubname_table_allocated
)
6488 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6490 = (pubname_ref
) xrealloc (pubname_table
,
6491 (pubname_table_allocated
6492 * sizeof (pubname_entry
)));
6495 p
= &pubname_table
[pubname_table_in_use
++];
6497 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6500 /* Output the public names table used to speed up access to externally
6501 visible names. For now, only generate entries for externally
6502 visible procedures. */
6508 unsigned long pubnames_length
= size_of_pubnames ();
6510 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6511 "Length of Public Names Info");
6512 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6513 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6514 "Offset of Compilation Unit Info");
6515 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6516 "Compilation Unit Length");
6518 for (i
= 0; i
< pubname_table_in_use
; i
++)
6520 pubname_ref pub
= &pubname_table
[i
];
6522 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6523 if (pub
->die
->die_mark
== 0)
6526 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6529 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6532 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6535 /* Add a new entry to .debug_aranges if appropriate. */
6538 add_arange (decl
, die
)
6542 if (! DECL_SECTION_NAME (decl
))
6545 if (arange_table_in_use
== arange_table_allocated
)
6547 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6548 arange_table
= (dw_die_ref
*)
6549 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6552 arange_table
[arange_table_in_use
++] = die
;
6555 /* Output the information that goes into the .debug_aranges table.
6556 Namely, define the beginning and ending address range of the
6557 text section generated for this compilation unit. */
6563 unsigned long aranges_length
= size_of_aranges ();
6565 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6566 "Length of Address Ranges Info");
6567 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6568 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6569 "Offset of Compilation Unit Info");
6570 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6571 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6573 /* We need to align to twice the pointer size here. */
6574 if (DWARF_ARANGES_PAD_SIZE
)
6576 /* Pad using a 2 byte words so that padding is correct for any
6578 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6579 2 * DWARF2_ADDR_SIZE
);
6580 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6581 dw2_asm_output_data (2, 0, NULL
);
6584 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6585 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6586 text_section_label
, "Length");
6588 for (i
= 0; i
< arange_table_in_use
; i
++)
6590 dw_die_ref die
= arange_table
[i
];
6592 /* We shouldn't see aranges for DIEs outside of the main CU. */
6593 if (die
->die_mark
== 0)
6596 if (die
->die_tag
== DW_TAG_subprogram
)
6598 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6600 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6601 get_AT_low_pc (die
), "Length");
6605 /* A static variable; extract the symbol from DW_AT_location.
6606 Note that this code isn't currently hit, as we only emit
6607 aranges for functions (jason 9/23/99). */
6608 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6609 dw_loc_descr_ref loc
;
6611 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6615 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6618 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6619 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6620 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6621 get_AT_unsigned (die
, DW_AT_byte_size
),
6626 /* Output the terminator words. */
6627 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6628 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6631 /* Add a new entry to .debug_ranges. Return the offset at which it
6638 unsigned int in_use
= ranges_table_in_use
;
6640 if (in_use
== ranges_table_allocated
)
6642 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6643 ranges_table
= (dw_ranges_ref
)
6644 xrealloc (ranges_table
, (ranges_table_allocated
6645 * sizeof (struct dw_ranges_struct
)));
6648 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6649 ranges_table_in_use
= in_use
+ 1;
6651 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6658 static const char *const start_fmt
= "Offset 0x%x";
6659 const char *fmt
= start_fmt
;
6661 for (i
= 0; i
< ranges_table_in_use
; i
++)
6663 int block_num
= ranges_table
[i
].block_num
;
6667 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6668 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6670 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6671 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6673 /* If all code is in the text section, then the compilation
6674 unit base address defaults to DW_AT_low_pc, which is the
6675 base of the text section. */
6676 if (separate_line_info_table_in_use
== 0)
6678 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6680 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6681 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6682 text_section_label
, NULL
);
6685 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6686 compilation unit base address to zero, which allows us to
6687 use absolute addresses, and not worry about whether the
6688 target supports cross-section arithmetic. */
6691 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6692 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6693 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6700 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6701 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6707 /* Data structure containing information about input files. */
6710 char *path
; /* Complete file name. */
6711 char *fname
; /* File name part. */
6712 int length
; /* Length of entire string. */
6713 int file_idx
; /* Index in input file table. */
6714 int dir_idx
; /* Index in directory table. */
6717 /* Data structure containing information about directories with source
6721 char *path
; /* Path including directory name. */
6722 int length
; /* Path length. */
6723 int prefix
; /* Index of directory entry which is a prefix. */
6724 int count
; /* Number of files in this directory. */
6725 int dir_idx
; /* Index of directory used as base. */
6726 int used
; /* Used in the end? */
6729 /* Callback function for file_info comparison. We sort by looking at
6730 the directories in the path. */
6733 file_info_cmp (p1
, p2
)
6737 const struct file_info
*s1
= p1
;
6738 const struct file_info
*s2
= p2
;
6742 /* Take care of file names without directories. We need to make sure that
6743 we return consistent values to qsort since some will get confused if
6744 we return the same value when identical operands are passed in opposite
6745 orders. So if neither has a directory, return 0 and otherwise return
6746 1 or -1 depending on which one has the directory. */
6747 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
6748 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
6750 cp1
= (unsigned char *) s1
->path
;
6751 cp2
= (unsigned char *) s2
->path
;
6757 /* Reached the end of the first path? If so, handle like above. */
6758 if ((cp1
== (unsigned char *) s1
->fname
)
6759 || (cp2
== (unsigned char *) s2
->fname
))
6760 return ((cp2
== (unsigned char *) s2
->fname
)
6761 - (cp1
== (unsigned char *) s1
->fname
));
6763 /* Character of current path component the same? */
6764 else if (*cp1
!= *cp2
)
6769 /* Output the directory table and the file name table. We try to minimize
6770 the total amount of memory needed. A heuristic is used to avoid large
6771 slowdowns with many input files. */
6774 output_file_names ()
6776 struct file_info
*files
;
6777 struct dir_info
*dirs
;
6786 /* Allocate the various arrays we need. */
6787 files
= (struct file_info
*) alloca (file_table
.in_use
6788 * sizeof (struct file_info
));
6789 dirs
= (struct dir_info
*) alloca (file_table
.in_use
6790 * sizeof (struct dir_info
));
6792 /* Sort the file names. */
6793 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6797 /* Skip all leading "./". */
6798 f
= file_table
.table
[i
];
6799 while (f
[0] == '.' && f
[1] == '/')
6802 /* Create a new array entry. */
6804 files
[i
].length
= strlen (f
);
6805 files
[i
].file_idx
= i
;
6807 /* Search for the file name part. */
6808 f
= strrchr (f
, '/');
6809 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
6812 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
6814 /* Find all the different directories used. */
6815 dirs
[0].path
= files
[1].path
;
6816 dirs
[0].length
= files
[1].fname
- files
[1].path
;
6817 dirs
[0].prefix
= -1;
6819 dirs
[0].dir_idx
= 0;
6821 files
[1].dir_idx
= 0;
6824 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
6825 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
6826 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
6827 dirs
[ndirs
- 1].length
) == 0)
6829 /* Same directory as last entry. */
6830 files
[i
].dir_idx
= ndirs
- 1;
6831 ++dirs
[ndirs
- 1].count
;
6837 /* This is a new directory. */
6838 dirs
[ndirs
].path
= files
[i
].path
;
6839 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
6840 dirs
[ndirs
].count
= 1;
6841 dirs
[ndirs
].dir_idx
= ndirs
;
6842 dirs
[ndirs
].used
= 0;
6843 files
[i
].dir_idx
= ndirs
;
6845 /* Search for a prefix. */
6846 dirs
[ndirs
].prefix
= -1;
6847 for (j
= 0; j
< ndirs
; j
++)
6848 if (dirs
[j
].length
< dirs
[ndirs
].length
6849 && dirs
[j
].length
> 1
6850 && (dirs
[ndirs
].prefix
== -1
6851 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
6852 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
6853 dirs
[ndirs
].prefix
= j
;
6858 /* Now to the actual work. We have to find a subset of the directories which
6859 allow expressing the file name using references to the directory table
6860 with the least amount of characters. We do not do an exhaustive search
6861 where we would have to check out every combination of every single
6862 possible prefix. Instead we use a heuristic which provides nearly optimal
6863 results in most cases and never is much off. */
6864 saved
= (int *) alloca (ndirs
* sizeof (int));
6865 savehere
= (int *) alloca (ndirs
* sizeof (int));
6867 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
6868 for (i
= 0; i
< ndirs
; i
++)
6873 /* We can always save some space for the current directory. But this
6874 does not mean it will be enough to justify adding the directory. */
6875 savehere
[i
] = dirs
[i
].length
;
6876 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
6878 for (j
= i
+ 1; j
< ndirs
; j
++)
6881 if (saved
[j
] < dirs
[i
].length
)
6883 /* Determine whether the dirs[i] path is a prefix of the
6888 while (k
!= -1 && k
!= i
)
6893 /* Yes it is. We can possibly safe some memory but
6894 writing the filenames in dirs[j] relative to
6896 savehere
[j
] = dirs
[i
].length
;
6897 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
6902 /* Check whether we can safe enough to justify adding the dirs[i]
6904 if (total
> dirs
[i
].length
+ 1)
6906 /* It's worthwhile adding. */
6907 for (j
= i
; j
< ndirs
; j
++)
6908 if (savehere
[j
] > 0)
6910 /* Remember how much we saved for this directory so far. */
6911 saved
[j
] = savehere
[j
];
6913 /* Remember the prefix directory. */
6914 dirs
[j
].dir_idx
= i
;
6919 /* We have to emit them in the order they appear in the file_table array
6920 since the index is used in the debug info generation. To do this
6921 efficiently we generate a back-mapping of the indices first. */
6922 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
6923 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6925 backmap
[files
[i
].file_idx
] = i
;
6927 /* Mark this directory as used. */
6928 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
6931 /* That was it. We are ready to emit the information. First emit the
6932 directory name table. We have to make sure the first actually emitted
6933 directory name has index one; zero is reserved for the current working
6934 directory. Make sure we do not confuse these indices with the one for the
6935 constructed table (even though most of the time they are identical). */
6937 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
6938 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
6939 if (dirs
[i
].used
!= 0)
6941 dirs
[i
].used
= idx
++;
6942 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
6943 "Directory Entry: 0x%x", dirs
[i
].used
);
6946 dw2_asm_output_data (1, 0, "End directory table");
6948 /* Correct the index for the current working directory entry if it
6950 if (idx_offset
== 0)
6953 /* Now write all the file names. */
6954 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6956 int file_idx
= backmap
[i
];
6957 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
6959 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
6960 "File Entry: 0x%x", i
);
6962 /* Include directory index. */
6963 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
6965 /* Modification time. */
6966 dw2_asm_output_data_uleb128 (0, NULL
);
6968 /* File length in bytes. */
6969 dw2_asm_output_data_uleb128 (0, NULL
);
6972 dw2_asm_output_data (1, 0, "End file name table");
6976 /* Output the source line number correspondence information. This
6977 information goes into the .debug_line section. */
6982 char l1
[20], l2
[20], p1
[20], p2
[20];
6983 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6984 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
6987 unsigned long lt_index
;
6988 unsigned long current_line
;
6991 unsigned long current_file
;
6992 unsigned long function
;
6994 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
6995 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
6996 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
6997 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
6999 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7000 "Length of Source Line Info");
7001 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7003 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7004 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7005 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7007 /* Define the architecture-dependent minimum instruction length (in
7008 bytes). In this implementation of DWARF, this field is used for
7009 information purposes only. Since GCC generates assembly language,
7010 we have no a priori knowledge of how many instruction bytes are
7011 generated for each source line, and therefore can use only the
7012 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7013 commands. Accordingly, we fix this as `1', which is "correct
7014 enough" for all architectures, and don't let the target override. */
7015 dw2_asm_output_data (1, 1,
7016 "Minimum Instruction Length");
7018 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7019 "Default is_stmt_start flag");
7020 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7021 "Line Base Value (Special Opcodes)");
7022 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7023 "Line Range Value (Special Opcodes)");
7024 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7025 "Special Opcode Base");
7027 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7031 case DW_LNS_advance_pc
:
7032 case DW_LNS_advance_line
:
7033 case DW_LNS_set_file
:
7034 case DW_LNS_set_column
:
7035 case DW_LNS_fixed_advance_pc
:
7043 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7047 /* Write out the information about the files we use. */
7048 output_file_names ();
7049 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7051 /* We used to set the address register to the first location in the text
7052 section here, but that didn't accomplish anything since we already
7053 have a line note for the opening brace of the first function. */
7055 /* Generate the line number to PC correspondence table, encoded as
7056 a series of state machine operations. */
7059 strcpy (prev_line_label
, text_section_label
);
7060 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7062 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7065 /* Disable this optimization for now; GDB wants to see two line notes
7066 at the beginning of a function so it can find the end of the
7069 /* Don't emit anything for redundant notes. Just updating the
7070 address doesn't accomplish anything, because we already assume
7071 that anything after the last address is this line. */
7072 if (line_info
->dw_line_num
== current_line
7073 && line_info
->dw_file_num
== current_file
)
7077 /* Emit debug info for the address of the current line.
7079 Unfortunately, we have little choice here currently, and must always
7080 use the most general form. GCC does not know the address delta
7081 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7082 attributes which will give an upper bound on the address range. We
7083 could perhaps use length attributes to determine when it is safe to
7084 use DW_LNS_fixed_advance_pc. */
7086 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7089 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7090 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7091 "DW_LNS_fixed_advance_pc");
7092 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7096 /* This can handle any delta. This takes
7097 4+DWARF2_ADDR_SIZE bytes. */
7098 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7099 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7100 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7101 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7104 strcpy (prev_line_label
, line_label
);
7106 /* Emit debug info for the source file of the current line, if
7107 different from the previous line. */
7108 if (line_info
->dw_file_num
!= current_file
)
7110 current_file
= line_info
->dw_file_num
;
7111 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7112 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7113 file_table
.table
[current_file
]);
7116 /* Emit debug info for the current line number, choosing the encoding
7117 that uses the least amount of space. */
7118 if (line_info
->dw_line_num
!= current_line
)
7120 line_offset
= line_info
->dw_line_num
- current_line
;
7121 line_delta
= line_offset
- DWARF_LINE_BASE
;
7122 current_line
= line_info
->dw_line_num
;
7123 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7124 /* This can handle deltas from -10 to 234, using the current
7125 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7127 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7128 "line %lu", current_line
);
7131 /* This can handle any delta. This takes at least 4 bytes,
7132 depending on the value being encoded. */
7133 dw2_asm_output_data (1, DW_LNS_advance_line
,
7134 "advance to line %lu", current_line
);
7135 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7136 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7140 /* We still need to start a new row, so output a copy insn. */
7141 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7144 /* Emit debug info for the address of the end of the function. */
7147 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7148 "DW_LNS_fixed_advance_pc");
7149 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7153 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7154 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7155 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7156 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7159 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7160 dw2_asm_output_data_uleb128 (1, NULL
);
7161 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7166 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7168 dw_separate_line_info_ref line_info
7169 = &separate_line_info_table
[lt_index
];
7172 /* Don't emit anything for redundant notes. */
7173 if (line_info
->dw_line_num
== current_line
7174 && line_info
->dw_file_num
== current_file
7175 && line_info
->function
== function
)
7179 /* Emit debug info for the address of the current line. If this is
7180 a new function, or the first line of a function, then we need
7181 to handle it differently. */
7182 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7184 if (function
!= line_info
->function
)
7186 function
= line_info
->function
;
7188 /* Set the address register to the first line in the function */
7189 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7190 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7191 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7192 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7196 /* ??? See the DW_LNS_advance_pc comment above. */
7199 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7200 "DW_LNS_fixed_advance_pc");
7201 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7205 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7206 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7207 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7208 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7212 strcpy (prev_line_label
, line_label
);
7214 /* Emit debug info for the source file of the current line, if
7215 different from the previous line. */
7216 if (line_info
->dw_file_num
!= current_file
)
7218 current_file
= line_info
->dw_file_num
;
7219 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7220 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7221 file_table
.table
[current_file
]);
7224 /* Emit debug info for the current line number, choosing the encoding
7225 that uses the least amount of space. */
7226 if (line_info
->dw_line_num
!= current_line
)
7228 line_offset
= line_info
->dw_line_num
- current_line
;
7229 line_delta
= line_offset
- DWARF_LINE_BASE
;
7230 current_line
= line_info
->dw_line_num
;
7231 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7232 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7233 "line %lu", current_line
);
7236 dw2_asm_output_data (1, DW_LNS_advance_line
,
7237 "advance to line %lu", current_line
);
7238 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7239 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7243 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7251 /* If we're done with a function, end its sequence. */
7252 if (lt_index
== separate_line_info_table_in_use
7253 || separate_line_info_table
[lt_index
].function
!= function
)
7258 /* Emit debug info for the address of the end of the function. */
7259 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7262 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7263 "DW_LNS_fixed_advance_pc");
7264 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7268 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7269 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7270 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7271 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7274 /* Output the marker for the end of this sequence. */
7275 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7276 dw2_asm_output_data_uleb128 (1, NULL
);
7277 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7281 /* Output the marker for the end of the line number info. */
7282 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7285 /* Given a pointer to a tree node for some base type, return a pointer to
7286 a DIE that describes the given type.
7288 This routine must only be called for GCC type nodes that correspond to
7289 Dwarf base (fundamental) types. */
7292 base_type_die (type
)
7295 dw_die_ref base_type_result
;
7296 const char *type_name
;
7297 enum dwarf_type encoding
;
7298 tree name
= TYPE_NAME (type
);
7300 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7305 if (TREE_CODE (name
) == TYPE_DECL
)
7306 name
= DECL_NAME (name
);
7308 type_name
= IDENTIFIER_POINTER (name
);
7311 type_name
= "__unknown__";
7313 switch (TREE_CODE (type
))
7316 /* Carefully distinguish the C character types, without messing
7317 up if the language is not C. Note that we check only for the names
7318 that contain spaces; other names might occur by coincidence in other
7320 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7321 && (type
== char_type_node
7322 || ! strcmp (type_name
, "signed char")
7323 || ! strcmp (type_name
, "unsigned char"))))
7325 if (TREE_UNSIGNED (type
))
7326 encoding
= DW_ATE_unsigned
;
7328 encoding
= DW_ATE_signed
;
7331 /* else fall through. */
7334 /* GNU Pascal/Ada CHAR type. Not used in C. */
7335 if (TREE_UNSIGNED (type
))
7336 encoding
= DW_ATE_unsigned_char
;
7338 encoding
= DW_ATE_signed_char
;
7342 encoding
= DW_ATE_float
;
7345 /* Dwarf2 doesn't know anything about complex ints, so use
7346 a user defined type for it. */
7348 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7349 encoding
= DW_ATE_complex_float
;
7351 encoding
= DW_ATE_lo_user
;
7355 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7356 encoding
= DW_ATE_boolean
;
7360 /* No other TREE_CODEs are Dwarf fundamental types. */
7364 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7365 if (demangle_name_func
)
7366 type_name
= (*demangle_name_func
) (type_name
);
7368 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7369 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7370 int_size_in_bytes (type
));
7371 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7373 return base_type_result
;
7376 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7377 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7378 a given type is generally the same as the given type, except that if the
7379 given type is a pointer or reference type, then the root type of the given
7380 type is the root type of the "basis" type for the pointer or reference
7381 type. (This definition of the "root" type is recursive.) Also, the root
7382 type of a `const' qualified type or a `volatile' qualified type is the
7383 root type of the given type without the qualifiers. */
7389 if (TREE_CODE (type
) == ERROR_MARK
)
7390 return error_mark_node
;
7392 switch (TREE_CODE (type
))
7395 return error_mark_node
;
7398 case REFERENCE_TYPE
:
7399 return type_main_variant (root_type (TREE_TYPE (type
)));
7402 return type_main_variant (type
);
7406 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7407 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7413 switch (TREE_CODE (type
))
7428 case QUAL_UNION_TYPE
:
7433 case REFERENCE_TYPE
:
7447 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7448 entry that chains various modifiers in front of the given type. */
7451 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7454 int is_volatile_type
;
7455 dw_die_ref context_die
;
7457 enum tree_code code
= TREE_CODE (type
);
7458 dw_die_ref mod_type_die
= NULL
;
7459 dw_die_ref sub_die
= NULL
;
7460 tree item_type
= NULL
;
7462 if (code
!= ERROR_MARK
)
7464 tree qualified_type
;
7466 /* See if we already have the appropriately qualified variant of
7469 = get_qualified_type (type
,
7470 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7472 ? TYPE_QUAL_VOLATILE
: 0)));
7474 /* If we do, then we can just use its DIE, if it exists. */
7477 mod_type_die
= lookup_type_die (qualified_type
);
7479 return mod_type_die
;
7482 /* Handle C typedef types. */
7483 if (qualified_type
&& TYPE_NAME (qualified_type
)
7484 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7485 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7487 tree type_name
= TYPE_NAME (qualified_type
);
7488 tree dtype
= TREE_TYPE (type_name
);
7490 if (qualified_type
== dtype
)
7492 /* For a named type, use the typedef. */
7493 gen_type_die (qualified_type
, context_die
);
7494 mod_type_die
= lookup_type_die (qualified_type
);
7496 else if (is_const_type
< TYPE_READONLY (dtype
)
7497 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7498 /* cv-unqualified version of named type. Just use the unnamed
7499 type to which it refers. */
7501 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7502 is_const_type
, is_volatile_type
,
7505 /* Else cv-qualified version of named type; fall through. */
7511 else if (is_const_type
)
7513 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7514 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7516 else if (is_volatile_type
)
7518 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7519 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7521 else if (code
== POINTER_TYPE
)
7523 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7524 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7526 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7528 item_type
= TREE_TYPE (type
);
7530 else if (code
== REFERENCE_TYPE
)
7532 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7533 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7535 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7537 item_type
= TREE_TYPE (type
);
7539 else if (is_base_type (type
))
7540 mod_type_die
= base_type_die (type
);
7543 gen_type_die (type
, context_die
);
7545 /* We have to get the type_main_variant here (and pass that to the
7546 `lookup_type_die' routine) because the ..._TYPE node we have
7547 might simply be a *copy* of some original type node (where the
7548 copy was created to help us keep track of typedef names) and
7549 that copy might have a different TYPE_UID from the original
7551 if (TREE_CODE (type
) != VECTOR_TYPE
)
7552 mod_type_die
= lookup_type_die (type_main_variant (type
));
7554 /* Vectors have the debugging information in the type,
7555 not the main variant. */
7556 mod_type_die
= lookup_type_die (type
);
7557 if (mod_type_die
== NULL
)
7561 /* We want to equate the qualified type to the die below. */
7562 type
= qualified_type
;
7566 equate_type_number_to_die (type
, mod_type_die
);
7568 /* We must do this after the equate_type_number_to_die call, in case
7569 this is a recursive type. This ensures that the modified_type_die
7570 recursion will terminate even if the type is recursive. Recursive
7571 types are possible in Ada. */
7572 sub_die
= modified_type_die (item_type
,
7573 TYPE_READONLY (item_type
),
7574 TYPE_VOLATILE (item_type
),
7577 if (sub_die
!= NULL
)
7578 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7580 return mod_type_die
;
7583 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7584 an enumerated type. */
7590 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7593 /* Return the register number described by a given RTL node. */
7599 unsigned regno
= REGNO (rtl
);
7601 if (regno
>= FIRST_PSEUDO_REGISTER
)
7604 return DBX_REGISTER_NUMBER (regno
);
7607 /* Return a location descriptor that designates a machine register or
7608 zero if there is no such. */
7610 static dw_loc_descr_ref
7611 reg_loc_descriptor (rtl
)
7614 dw_loc_descr_ref loc_result
= NULL
;
7617 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7620 reg
= reg_number (rtl
);
7622 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
7624 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
7629 /* Return a location descriptor that designates a constant. */
7631 static dw_loc_descr_ref
7632 int_loc_descriptor (i
)
7635 enum dwarf_location_atom op
;
7637 /* Pick the smallest representation of a constant, rather than just
7638 defaulting to the LEB encoding. */
7642 op
= DW_OP_lit0
+ i
;
7645 else if (i
<= 0xffff)
7647 else if (HOST_BITS_PER_WIDE_INT
== 32
7657 else if (i
>= -0x8000)
7659 else if (HOST_BITS_PER_WIDE_INT
== 32
7660 || i
>= -0x80000000)
7666 return new_loc_descr (op
, i
, 0);
7669 /* Return a location descriptor that designates a base+offset location. */
7671 static dw_loc_descr_ref
7672 based_loc_descr (reg
, offset
)
7676 dw_loc_descr_ref loc_result
;
7677 /* For the "frame base", we use the frame pointer or stack pointer
7678 registers, since the RTL for local variables is relative to one of
7680 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7681 ? HARD_FRAME_POINTER_REGNUM
7682 : STACK_POINTER_REGNUM
);
7685 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
7687 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
7689 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
7694 /* Return true if this RTL expression describes a base+offset calculation. */
7700 return (GET_CODE (rtl
) == PLUS
7701 && ((GET_CODE (XEXP (rtl
, 0)) == REG
7702 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
7703 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
7706 /* The following routine converts the RTL for a variable or parameter
7707 (resident in memory) into an equivalent Dwarf representation of a
7708 mechanism for getting the address of that same variable onto the top of a
7709 hypothetical "address evaluation" stack.
7711 When creating memory location descriptors, we are effectively transforming
7712 the RTL for a memory-resident object into its Dwarf postfix expression
7713 equivalent. This routine recursively descends an RTL tree, turning
7714 it into Dwarf postfix code as it goes.
7716 MODE is the mode of the memory reference, needed to handle some
7717 autoincrement addressing modes.
7719 Return 0 if we can't represent the location. */
7721 static dw_loc_descr_ref
7722 mem_loc_descriptor (rtl
, mode
)
7724 enum machine_mode mode
;
7726 dw_loc_descr_ref mem_loc_result
= NULL
;
7728 /* Note that for a dynamically sized array, the location we will generate a
7729 description of here will be the lowest numbered location which is
7730 actually within the array. That's *not* necessarily the same as the
7731 zeroth element of the array. */
7733 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7734 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
7737 switch (GET_CODE (rtl
))
7742 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7743 just fall into the SUBREG code. */
7745 /* ... fall through ... */
7748 /* The case of a subreg may arise when we have a local (register)
7749 variable or a formal (register) parameter which doesn't quite fill
7750 up an entire register. For now, just assume that it is
7751 legitimate to make the Dwarf info refer to the whole register which
7752 contains the given subreg. */
7753 rtl
= SUBREG_REG (rtl
);
7755 /* ... fall through ... */
7758 /* Whenever a register number forms a part of the description of the
7759 method for calculating the (dynamic) address of a memory resident
7760 object, DWARF rules require the register number be referred to as
7761 a "base register". This distinction is not based in any way upon
7762 what category of register the hardware believes the given register
7763 belongs to. This is strictly DWARF terminology we're dealing with
7764 here. Note that in cases where the location of a memory-resident
7765 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7766 OP_CONST (0)) the actual DWARF location descriptor that we generate
7767 may just be OP_BASEREG (basereg). This may look deceptively like
7768 the object in question was allocated to a register (rather than in
7769 memory) so DWARF consumers need to be aware of the subtle
7770 distinction between OP_REG and OP_BASEREG. */
7771 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
7772 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
7776 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7777 if (mem_loc_result
!= 0)
7778 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
7782 /* Some ports can transform a symbol ref into a label ref, because
7783 the symbol ref is too far away and has to be dumped into a constant
7787 /* Alternatively, the symbol in the constant pool might be referenced
7788 by a different symbol. */
7789 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
7792 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
7794 if (GET_CODE (tmp
) == SYMBOL_REF
)
7797 if (CONSTANT_POOL_ADDRESS_P (tmp
))
7798 get_pool_constant_mark (tmp
, &marked
);
7803 /* If all references to this pool constant were optimized away,
7804 it was not output and thus we can't represent it.
7805 FIXME: might try to use DW_OP_const_value here, though
7806 DW_OP_piece complicates it. */
7811 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
7812 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7813 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
7814 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
7818 /* Extract the PLUS expression nested inside and fall into
7820 rtl
= XEXP (rtl
, 1);
7825 /* Turn these into a PLUS expression and fall into the PLUS code
7827 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
7828 GEN_INT (GET_CODE (rtl
) == PRE_INC
7829 ? GET_MODE_UNIT_SIZE (mode
)
7830 : -GET_MODE_UNIT_SIZE (mode
)));
7832 /* ... fall through ... */
7836 if (is_based_loc (rtl
))
7837 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
7838 INTVAL (XEXP (rtl
, 1)));
7841 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7842 if (mem_loc_result
== 0)
7845 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
7846 && INTVAL (XEXP (rtl
, 1)) >= 0)
7847 add_loc_descr (&mem_loc_result
,
7848 new_loc_descr (DW_OP_plus_uconst
,
7849 INTVAL (XEXP (rtl
, 1)), 0));
7852 add_loc_descr (&mem_loc_result
,
7853 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7854 add_loc_descr (&mem_loc_result
,
7855 new_loc_descr (DW_OP_plus
, 0, 0));
7862 /* If a pseudo-reg is optimized away, it is possible for it to
7863 be replaced with a MEM containing a multiply. */
7864 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7865 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
7867 if (op0
== 0 || op1
== 0)
7870 mem_loc_result
= op0
;
7871 add_loc_descr (&mem_loc_result
, op1
);
7872 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
7877 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
7881 /* If this is a MEM, return its address. Otherwise, we can't
7883 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
7884 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
7892 return mem_loc_result
;
7895 /* Return a descriptor that describes the concatenation of two locations.
7896 This is typically a complex variable. */
7898 static dw_loc_descr_ref
7899 concat_loc_descriptor (x0
, x1
)
7902 dw_loc_descr_ref cc_loc_result
= NULL
;
7903 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
7904 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
7906 if (x0_ref
== 0 || x1_ref
== 0)
7909 cc_loc_result
= x0_ref
;
7910 add_loc_descr (&cc_loc_result
,
7911 new_loc_descr (DW_OP_piece
,
7912 GET_MODE_SIZE (GET_MODE (x0
)), 0));
7914 add_loc_descr (&cc_loc_result
, x1_ref
);
7915 add_loc_descr (&cc_loc_result
,
7916 new_loc_descr (DW_OP_piece
,
7917 GET_MODE_SIZE (GET_MODE (x1
)), 0));
7919 return cc_loc_result
;
7922 /* Output a proper Dwarf location descriptor for a variable or parameter
7923 which is either allocated in a register or in a memory location. For a
7924 register, we just generate an OP_REG and the register number. For a
7925 memory location we provide a Dwarf postfix expression describing how to
7926 generate the (dynamic) address of the object onto the address stack.
7928 If we don't know how to describe it, return 0. */
7930 static dw_loc_descr_ref
7931 loc_descriptor (rtl
)
7934 dw_loc_descr_ref loc_result
= NULL
;
7936 switch (GET_CODE (rtl
))
7939 /* The case of a subreg may arise when we have a local (register)
7940 variable or a formal (register) parameter which doesn't quite fill
7941 up an entire register. For now, just assume that it is
7942 legitimate to make the Dwarf info refer to the whole register which
7943 contains the given subreg. */
7944 rtl
= SUBREG_REG (rtl
);
7946 /* ... fall through ... */
7949 loc_result
= reg_loc_descriptor (rtl
);
7953 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7957 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
7967 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7968 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7969 looking for an address. Otherwise, we return a value. If we can't make a
7970 descriptor, return 0. */
7972 static dw_loc_descr_ref
7973 loc_descriptor_from_tree (loc
, addressp
)
7977 dw_loc_descr_ref ret
, ret1
;
7979 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
7980 enum dwarf_location_atom op
;
7982 /* ??? Most of the time we do not take proper care for sign/zero
7983 extending the values properly. Hopefully this won't be a real
7986 switch (TREE_CODE (loc
))
7991 case WITH_RECORD_EXPR
:
7992 case PLACEHOLDER_EXPR
:
7993 /* This case involves extracting fields from an object to determine the
7994 position of other fields. We don't try to encode this here. The
7995 only user of this is Ada, which encodes the needed information using
7996 the names of types. */
8003 /* We can support this only if we can look through conversions and
8004 find an INDIRECT_EXPR. */
8005 for (loc
= TREE_OPERAND (loc
, 0);
8006 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8007 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8008 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8009 || TREE_CODE (loc
) == SAVE_EXPR
;
8010 loc
= TREE_OPERAND (loc
, 0))
8013 return (TREE_CODE (loc
) == INDIRECT_REF
8014 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8020 rtx rtl
= rtl_for_decl_location (loc
);
8022 if (rtl
== NULL_RTX
)
8024 else if (CONSTANT_P (rtl
))
8026 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8027 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8028 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8033 enum machine_mode mode
= GET_MODE (rtl
);
8035 if (GET_CODE (rtl
) == MEM
)
8038 rtl
= XEXP (rtl
, 0);
8041 ret
= mem_loc_descriptor (rtl
, mode
);
8047 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8052 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8056 case NON_LVALUE_EXPR
:
8057 case VIEW_CONVERT_EXPR
:
8059 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8064 case ARRAY_RANGE_REF
:
8067 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8068 enum machine_mode mode
;
8071 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8072 &unsignedp
, &volatilep
);
8077 ret
= loc_descriptor_from_tree (obj
, 1);
8079 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8082 if (offset
!= NULL_TREE
)
8084 /* Variable offset. */
8085 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8086 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8092 bytepos
= bitpos
/ BITS_PER_UNIT
;
8094 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8095 else if (bytepos
< 0)
8097 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8098 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8104 if (host_integerp (loc
, 0))
8105 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8110 case TRUTH_AND_EXPR
:
8111 case TRUTH_ANDIF_EXPR
:
8116 case TRUTH_XOR_EXPR
:
8122 case TRUTH_ORIF_EXPR
:
8127 case TRUNC_DIV_EXPR
:
8135 case TRUNC_MOD_EXPR
:
8148 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8152 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8153 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8155 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8159 add_loc_descr (&ret
,
8160 new_loc_descr (DW_OP_plus_uconst
,
8161 tree_low_cst (TREE_OPERAND (loc
, 1),
8171 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8178 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8185 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8192 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8207 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8208 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8209 if (ret
== 0 || ret1
== 0)
8212 add_loc_descr (&ret
, ret1
);
8213 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8216 case TRUTH_NOT_EXPR
:
8230 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8234 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8238 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8239 build (LT_EXPR
, integer_type_node
,
8240 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8241 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8243 /* ... fall through ... */
8247 dw_loc_descr_ref lhs
8248 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8249 dw_loc_descr_ref rhs
8250 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8251 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8253 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8254 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8257 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8258 add_loc_descr (&ret
, bra_node
);
8260 add_loc_descr (&ret
, rhs
);
8261 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8262 add_loc_descr (&ret
, jump_node
);
8264 add_loc_descr (&ret
, lhs
);
8265 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8266 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8268 /* ??? Need a node to point the skip at. Use a nop. */
8269 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8270 add_loc_descr (&ret
, tmp
);
8271 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8272 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8280 /* Show if we can't fill the request for an address. */
8281 if (addressp
&& indirect_p
== 0)
8284 /* If we've got an address and don't want one, dereference. */
8285 if (!addressp
&& indirect_p
> 0)
8287 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8289 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8291 else if (size
== DWARF2_ADDR_SIZE
)
8294 op
= DW_OP_deref_size
;
8296 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8302 /* Given a value, round it up to the lowest multiple of `boundary'
8303 which is not less than the value itself. */
8305 static inline HOST_WIDE_INT
8306 ceiling (value
, boundary
)
8307 HOST_WIDE_INT value
;
8308 unsigned int boundary
;
8310 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8313 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8314 pointer to the declared type for the relevant field variable, or return
8315 `integer_type_node' if the given node turns out to be an
8324 if (TREE_CODE (decl
) == ERROR_MARK
)
8325 return integer_type_node
;
8327 type
= DECL_BIT_FIELD_TYPE (decl
);
8328 if (type
== NULL_TREE
)
8329 type
= TREE_TYPE (decl
);
8334 /* Given a pointer to a tree node, return the alignment in bits for
8335 it, or else return BITS_PER_WORD if the node actually turns out to
8336 be an ERROR_MARK node. */
8338 static inline unsigned
8339 simple_type_align_in_bits (type
)
8342 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8345 static inline unsigned
8346 simple_decl_align_in_bits (decl
)
8349 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8352 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8353 node, return the size in bits for the type if it is a constant, or else
8354 return the alignment for the type if the type's size is not constant, or
8355 else return BITS_PER_WORD if the type actually turns out to be an
8358 static inline unsigned HOST_WIDE_INT
8359 simple_type_size_in_bits (type
)
8363 if (TREE_CODE (type
) == ERROR_MARK
)
8364 return BITS_PER_WORD
;
8365 else if (TYPE_SIZE (type
) == NULL_TREE
)
8367 else if (host_integerp (TYPE_SIZE (type
), 1))
8368 return tree_low_cst (TYPE_SIZE (type
), 1);
8370 return TYPE_ALIGN (type
);
8373 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8374 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8375 or return 0 if we are unable to determine what that offset is, either
8376 because the argument turns out to be a pointer to an ERROR_MARK node, or
8377 because the offset is actually variable. (We can't handle the latter case
8380 static HOST_WIDE_INT
8381 field_byte_offset (decl
)
8384 unsigned int type_align_in_bits
;
8385 unsigned int decl_align_in_bits
;
8386 unsigned HOST_WIDE_INT type_size_in_bits
;
8387 HOST_WIDE_INT object_offset_in_bits
;
8389 tree field_size_tree
;
8390 HOST_WIDE_INT bitpos_int
;
8391 HOST_WIDE_INT deepest_bitpos
;
8392 unsigned HOST_WIDE_INT field_size_in_bits
;
8394 if (TREE_CODE (decl
) == ERROR_MARK
)
8396 else if (TREE_CODE (decl
) != FIELD_DECL
)
8399 type
= field_type (decl
);
8400 field_size_tree
= DECL_SIZE (decl
);
8402 /* The size could be unspecified if there was an error, or for
8403 a flexible array member. */
8404 if (! field_size_tree
)
8405 field_size_tree
= bitsize_zero_node
;
8407 /* We cannot yet cope with fields whose positions are variable, so
8408 for now, when we see such things, we simply return 0. Someday, we may
8409 be able to handle such cases, but it will be damn difficult. */
8410 if (! host_integerp (bit_position (decl
), 0))
8413 bitpos_int
= int_bit_position (decl
);
8415 /* If we don't know the size of the field, pretend it's a full word. */
8416 if (host_integerp (field_size_tree
, 1))
8417 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8419 field_size_in_bits
= BITS_PER_WORD
;
8421 type_size_in_bits
= simple_type_size_in_bits (type
);
8422 type_align_in_bits
= simple_type_align_in_bits (type
);
8423 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8425 /* The GCC front-end doesn't make any attempt to keep track of the starting
8426 bit offset (relative to the start of the containing structure type) of the
8427 hypothetical "containing object" for a bit-field. Thus, when computing
8428 the byte offset value for the start of the "containing object" of a
8429 bit-field, we must deduce this information on our own. This can be rather
8430 tricky to do in some cases. For example, handling the following structure
8431 type definition when compiling for an i386/i486 target (which only aligns
8432 long long's to 32-bit boundaries) can be very tricky:
8434 struct S { int field1; long long field2:31; };
8436 Fortunately, there is a simple rule-of-thumb which can be used in such
8437 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8438 structure shown above. It decides to do this based upon one simple rule
8439 for bit-field allocation. GCC allocates each "containing object" for each
8440 bit-field at the first (i.e. lowest addressed) legitimate alignment
8441 boundary (based upon the required minimum alignment for the declared type
8442 of the field) which it can possibly use, subject to the condition that
8443 there is still enough available space remaining in the containing object
8444 (when allocated at the selected point) to fully accommodate all of the
8445 bits of the bit-field itself.
8447 This simple rule makes it obvious why GCC allocates 8 bytes for each
8448 object of the structure type shown above. When looking for a place to
8449 allocate the "containing object" for `field2', the compiler simply tries
8450 to allocate a 64-bit "containing object" at each successive 32-bit
8451 boundary (starting at zero) until it finds a place to allocate that 64-
8452 bit field such that at least 31 contiguous (and previously unallocated)
8453 bits remain within that selected 64 bit field. (As it turns out, for the
8454 example above, the compiler finds it is OK to allocate the "containing
8455 object" 64-bit field at bit-offset zero within the structure type.)
8457 Here we attempt to work backwards from the limited set of facts we're
8458 given, and we try to deduce from those facts, where GCC must have believed
8459 that the containing object started (within the structure type). The value
8460 we deduce is then used (by the callers of this routine) to generate
8461 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8462 and, in the case of DW_AT_location, regular fields as well). */
8464 /* Figure out the bit-distance from the start of the structure to the
8465 "deepest" bit of the bit-field. */
8466 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8468 /* This is the tricky part. Use some fancy footwork to deduce where the
8469 lowest addressed bit of the containing object must be. */
8470 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8472 /* Round up to type_align by default. This works best for bitfields. */
8473 object_offset_in_bits
+= type_align_in_bits
- 1;
8474 object_offset_in_bits
/= type_align_in_bits
;
8475 object_offset_in_bits
*= type_align_in_bits
;
8477 if (object_offset_in_bits
> bitpos_int
)
8479 /* Sigh, the decl must be packed. */
8480 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8482 /* Round up to decl_align instead. */
8483 object_offset_in_bits
+= decl_align_in_bits
- 1;
8484 object_offset_in_bits
/= decl_align_in_bits
;
8485 object_offset_in_bits
*= decl_align_in_bits
;
8488 return object_offset_in_bits
/ BITS_PER_UNIT
;
8491 /* The following routines define various Dwarf attributes and any data
8492 associated with them. */
8494 /* Add a location description attribute value to a DIE.
8496 This emits location attributes suitable for whole variables and
8497 whole parameters. Note that the location attributes for struct fields are
8498 generated by the routine `data_member_location_attribute' below. */
8501 add_AT_location_description (die
, attr_kind
, rtl
)
8503 enum dwarf_attribute attr_kind
;
8506 dw_loc_descr_ref descr
= loc_descriptor (rtl
);
8509 add_AT_loc (die
, attr_kind
, descr
);
8512 /* Attach the specialized form of location attribute used for data members of
8513 struct and union types. In the special case of a FIELD_DECL node which
8514 represents a bit-field, the "offset" part of this special location
8515 descriptor must indicate the distance in bytes from the lowest-addressed
8516 byte of the containing struct or union type to the lowest-addressed byte of
8517 the "containing object" for the bit-field. (See the `field_byte_offset'
8520 For any given bit-field, the "containing object" is a hypothetical object
8521 (of some integral or enum type) within which the given bit-field lives. The
8522 type of this hypothetical "containing object" is always the same as the
8523 declared type of the individual bit-field itself (for GCC anyway... the
8524 DWARF spec doesn't actually mandate this). Note that it is the size (in
8525 bytes) of the hypothetical "containing object" which will be given in the
8526 DW_AT_byte_size attribute for this bit-field. (See the
8527 `byte_size_attribute' function below.) It is also used when calculating the
8528 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8532 add_data_member_location_attribute (die
, decl
)
8537 dw_loc_descr_ref loc_descr
= 0;
8539 if (TREE_CODE (decl
) == TREE_VEC
)
8541 /* We're working on the TAG_inheritance for a base class. */
8542 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8544 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8545 aren't at a fixed offset from all (sub)objects of the same
8546 type. We need to extract the appropriate offset from our
8547 vtable. The following dwarf expression means
8549 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8551 This is specific to the V3 ABI, of course. */
8553 dw_loc_descr_ref tmp
;
8555 /* Make a copy of the object address. */
8556 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8557 add_loc_descr (&loc_descr
, tmp
);
8559 /* Extract the vtable address. */
8560 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8561 add_loc_descr (&loc_descr
, tmp
);
8563 /* Calculate the address of the offset. */
8564 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8568 tmp
= int_loc_descriptor (-offset
);
8569 add_loc_descr (&loc_descr
, tmp
);
8570 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8571 add_loc_descr (&loc_descr
, tmp
);
8573 /* Extract the offset. */
8574 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8575 add_loc_descr (&loc_descr
, tmp
);
8577 /* Add it to the object address. */
8578 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
8579 add_loc_descr (&loc_descr
, tmp
);
8582 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
8585 offset
= field_byte_offset (decl
);
8589 enum dwarf_location_atom op
;
8591 /* The DWARF2 standard says that we should assume that the structure
8592 address is already on the stack, so we can specify a structure field
8593 address by using DW_OP_plus_uconst. */
8595 #ifdef MIPS_DEBUGGING_INFO
8596 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8597 operator correctly. It works only if we leave the offset on the
8601 op
= DW_OP_plus_uconst
;
8604 loc_descr
= new_loc_descr (op
, offset
, 0);
8607 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
8610 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8611 does not have a "location" either in memory or in a register. These
8612 things can arise in GNU C when a constant is passed as an actual parameter
8613 to an inlined function. They can also arise in C++ where declared
8614 constants do not necessarily get memory "homes". */
8617 add_const_value_attribute (die
, rtl
)
8621 switch (GET_CODE (rtl
))
8624 /* Note that a CONST_INT rtx could represent either an integer
8625 or a floating-point constant. A CONST_INT is used whenever
8626 the constant will fit into a single word. In all such
8627 cases, the original mode of the constant value is wiped
8628 out, and the CONST_INT rtx is assigned VOIDmode. */
8630 HOST_WIDE_INT val
= INTVAL (rtl
);
8632 /* ??? We really should be using HOST_WIDE_INT throughout. */
8633 if (val
< 0 && (long) val
== val
)
8634 add_AT_int (die
, DW_AT_const_value
, (long) val
);
8635 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
8636 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
8639 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8640 add_AT_long_long (die
, DW_AT_const_value
,
8641 val
>> HOST_BITS_PER_LONG
, val
);
8650 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8651 floating-point constant. A CONST_DOUBLE is used whenever the
8652 constant requires more than one word in order to be adequately
8653 represented. We output CONST_DOUBLEs as blocks. */
8655 enum machine_mode mode
= GET_MODE (rtl
);
8657 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
8659 unsigned length
= GET_MODE_SIZE (mode
) / 4;
8660 long *array
= (long *) xmalloc (sizeof (long) * length
);
8663 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
8667 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
8671 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
8676 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
8683 add_AT_float (die
, DW_AT_const_value
, length
, array
);
8687 /* ??? We really should be using HOST_WIDE_INT throughout. */
8688 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
8691 add_AT_long_long (die
, DW_AT_const_value
,
8692 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
8698 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
8704 add_AT_addr (die
, DW_AT_const_value
, rtl
);
8705 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8709 /* In cases where an inlined instance of an inline function is passed
8710 the address of an `auto' variable (which is local to the caller) we
8711 can get a situation where the DECL_RTL of the artificial local
8712 variable (for the inlining) which acts as a stand-in for the
8713 corresponding formal parameter (of the inline function) will look
8714 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8715 exactly a compile-time constant expression, but it isn't the address
8716 of the (artificial) local variable either. Rather, it represents the
8717 *value* which the artificial local variable always has during its
8718 lifetime. We currently have no way to represent such quasi-constant
8719 values in Dwarf, so for now we just punt and generate nothing. */
8723 /* No other kinds of rtx should be possible here. */
8730 rtl_for_decl_location (decl
)
8735 /* Here we have to decide where we are going to say the parameter "lives"
8736 (as far as the debugger is concerned). We only have a couple of
8737 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8739 DECL_RTL normally indicates where the parameter lives during most of the
8740 activation of the function. If optimization is enabled however, this
8741 could be either NULL or else a pseudo-reg. Both of those cases indicate
8742 that the parameter doesn't really live anywhere (as far as the code
8743 generation parts of GCC are concerned) during most of the function's
8744 activation. That will happen (for example) if the parameter is never
8745 referenced within the function.
8747 We could just generate a location descriptor here for all non-NULL
8748 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8749 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8750 where DECL_RTL is NULL or is a pseudo-reg.
8752 Note however that we can only get away with using DECL_INCOMING_RTL as
8753 a backup substitute for DECL_RTL in certain limited cases. In cases
8754 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8755 we can be sure that the parameter was passed using the same type as it is
8756 declared to have within the function, and that its DECL_INCOMING_RTL
8757 points us to a place where a value of that type is passed.
8759 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8760 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8761 because in these cases DECL_INCOMING_RTL points us to a value of some
8762 type which is *different* from the type of the parameter itself. Thus,
8763 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8764 such cases, the debugger would end up (for example) trying to fetch a
8765 `float' from a place which actually contains the first part of a
8766 `double'. That would lead to really incorrect and confusing
8767 output at debug-time.
8769 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8770 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8771 are a couple of exceptions however. On little-endian machines we can
8772 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8773 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8774 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8775 when (on a little-endian machine) a non-prototyped function has a
8776 parameter declared to be of type `short' or `char'. In such cases,
8777 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8778 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8779 passed `int' value. If the debugger then uses that address to fetch
8780 a `short' or a `char' (on a little-endian machine) the result will be
8781 the correct data, so we allow for such exceptional cases below.
8783 Note that our goal here is to describe the place where the given formal
8784 parameter lives during most of the function's activation (i.e. between the
8785 end of the prologue and the start of the epilogue). We'll do that as best
8786 as we can. Note however that if the given formal parameter is modified
8787 sometime during the execution of the function, then a stack backtrace (at
8788 debug-time) will show the function as having been called with the *new*
8789 value rather than the value which was originally passed in. This happens
8790 rarely enough that it is not a major problem, but it *is* a problem, and
8793 A future version of dwarf2out.c may generate two additional attributes for
8794 any given DW_TAG_formal_parameter DIE which will describe the "passed
8795 type" and the "passed location" for the given formal parameter in addition
8796 to the attributes we now generate to indicate the "declared type" and the
8797 "active location" for each parameter. This additional set of attributes
8798 could be used by debuggers for stack backtraces. Separately, note that
8799 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8800 This happens (for example) for inlined-instances of inline function formal
8801 parameters which are never referenced. This really shouldn't be
8802 happening. All PARM_DECL nodes should get valid non-NULL
8803 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8804 values for inlined instances of inline function parameters, so when we see
8805 such cases, we are just out-of-luck for the time being (until integrate.c
8808 /* Use DECL_RTL as the "location" unless we find something better. */
8809 rtl
= DECL_RTL_IF_SET (decl
);
8811 /* When generating abstract instances, ignore everything except
8812 constants and symbols living in memory. */
8813 if (! reload_completed
)
8816 && (CONSTANT_P (rtl
)
8817 || (GET_CODE (rtl
) == MEM
8818 && CONSTANT_P (XEXP (rtl
, 0)))))
8820 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8821 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8827 else if (TREE_CODE (decl
) == PARM_DECL
)
8829 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
8831 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
8832 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
8834 /* This decl represents a formal parameter which was optimized out.
8835 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8836 all cases where (rtl == NULL_RTX) just below. */
8837 if (declared_type
== passed_type
)
8838 rtl
= DECL_INCOMING_RTL (decl
);
8839 else if (! BYTES_BIG_ENDIAN
8840 && TREE_CODE (declared_type
) == INTEGER_TYPE
8841 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
8842 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
8843 rtl
= DECL_INCOMING_RTL (decl
);
8846 /* If the parm was passed in registers, but lives on the stack, then
8847 make a big endian correction if the mode of the type of the
8848 parameter is not the same as the mode of the rtl. */
8849 /* ??? This is the same series of checks that are made in dbxout.c before
8850 we reach the big endian correction code there. It isn't clear if all
8851 of these checks are necessary here, but keeping them all is the safe
8853 else if (GET_CODE (rtl
) == MEM
8854 && XEXP (rtl
, 0) != const0_rtx
8855 && ! CONSTANT_P (XEXP (rtl
, 0))
8856 /* Not passed in memory. */
8857 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
8858 /* Not passed by invisible reference. */
8859 && (GET_CODE (XEXP (rtl
, 0)) != REG
8860 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
8861 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
8862 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8863 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
8866 /* Big endian correction check. */
8868 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
8869 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
8872 int offset
= (UNITS_PER_WORD
8873 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
8875 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
8876 plus_constant (XEXP (rtl
, 0), offset
));
8880 if (rtl
!= NULL_RTX
)
8882 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
8883 #ifdef LEAF_REG_REMAP
8884 if (current_function_uses_only_leaf_regs
)
8885 leaf_renumber_regs_insn (rtl
);
8889 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8890 and will have been substituted directly into all expressions that use it.
8891 C does not have such a concept, but C++ and other languages do. */
8892 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
8894 /* If a variable is initialized with a string constant without embedded
8895 zeros, build CONST_STRING. */
8896 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
8897 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
8899 tree arrtype
= TREE_TYPE (decl
);
8900 tree enttype
= TREE_TYPE (arrtype
);
8901 tree domain
= TYPE_DOMAIN (arrtype
);
8902 tree init
= DECL_INITIAL (decl
);
8903 enum machine_mode mode
= TYPE_MODE (enttype
);
8905 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
8907 && integer_zerop (TYPE_MIN_VALUE (domain
))
8908 && compare_tree_int (TYPE_MAX_VALUE (domain
),
8909 TREE_STRING_LENGTH (init
) - 1) == 0
8910 && ((size_t) TREE_STRING_LENGTH (init
)
8911 == strlen (TREE_STRING_POINTER (init
)) + 1))
8912 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
8914 /* If the initializer is something that we know will expand into an
8915 immediate RTL constant, expand it now. Expanding anything else
8916 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8917 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
8918 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
8920 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
8921 EXPAND_INITIALIZER
);
8922 /* If expand_expr returns a MEM, it wasn't immediate. */
8923 if (rtl
&& GET_CODE (rtl
) == MEM
)
8928 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8930 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8935 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8936 data attribute for a variable or a parameter. We generate the
8937 DW_AT_const_value attribute only in those cases where the given variable
8938 or parameter does not have a true "location" either in memory or in a
8939 register. This can happen (for example) when a constant is passed as an
8940 actual argument in a call to an inline function. (It's possible that
8941 these things can crop up in other ways also.) Note that one type of
8942 constant value which can be passed into an inlined function is a constant
8943 pointer. This can happen for example if an actual argument in an inlined
8944 function call evaluates to a compile-time constant address. */
8947 add_location_or_const_value_attribute (die
, decl
)
8953 if (TREE_CODE (decl
) == ERROR_MARK
)
8955 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
8958 rtl
= rtl_for_decl_location (decl
);
8959 if (rtl
== NULL_RTX
)
8962 /* If we don't look past the constant pool, we risk emitting a
8963 reference to a constant pool entry that isn't referenced from
8964 code, and thus is not emitted. */
8965 rtl
= avoid_constant_pool_reference (rtl
);
8967 switch (GET_CODE (rtl
))
8970 /* The address of a variable that was optimized away; don't emit
8981 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8982 add_const_value_attribute (die
, rtl
);
8989 add_AT_location_description (die
, DW_AT_location
, rtl
);
8997 /* If we don't have a copy of this variable in memory for some reason (such
8998 as a C++ member constant that doesn't have an out-of-line definition),
8999 we should tell the debugger about the constant value. */
9002 tree_add_const_value_attribute (var_die
, decl
)
9006 tree init
= DECL_INITIAL (decl
);
9007 tree type
= TREE_TYPE (decl
);
9009 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9010 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9015 switch (TREE_CODE (type
))
9018 if (host_integerp (init
, 0))
9019 add_AT_unsigned (var_die
, DW_AT_const_value
,
9020 tree_low_cst (init
, 0));
9022 add_AT_long_long (var_die
, DW_AT_const_value
,
9023 TREE_INT_CST_HIGH (init
),
9024 TREE_INT_CST_LOW (init
));
9031 /* Generate an DW_AT_name attribute given some string value to be included as
9032 the value of the attribute. */
9035 add_name_attribute (die
, name_string
)
9037 const char *name_string
;
9039 if (name_string
!= NULL
&& *name_string
!= 0)
9041 if (demangle_name_func
)
9042 name_string
= (*demangle_name_func
) (name_string
);
9044 add_AT_string (die
, DW_AT_name
, name_string
);
9048 /* Given a tree node describing an array bound (either lower or upper) output
9049 a representation for that bound. */
9052 add_bound_info (subrange_die
, bound_attr
, bound
)
9053 dw_die_ref subrange_die
;
9054 enum dwarf_attribute bound_attr
;
9057 switch (TREE_CODE (bound
))
9062 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9064 if (! host_integerp (bound
, 0)
9065 || (bound_attr
== DW_AT_lower_bound
9066 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9067 || (is_fortran () && integer_onep (bound
)))))
9068 /* use the default */
9071 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9076 case NON_LVALUE_EXPR
:
9077 case VIEW_CONVERT_EXPR
:
9078 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9082 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9083 access the upper bound values may be bogus. If they refer to a
9084 register, they may only describe how to get at these values at the
9085 points in the generated code right after they have just been
9086 computed. Worse yet, in the typical case, the upper bound values
9087 will not even *be* computed in the optimized code (though the
9088 number of elements will), so these SAVE_EXPRs are entirely
9089 bogus. In order to compensate for this fact, we check here to see
9090 if optimization is enabled, and if so, we don't add an attribute
9091 for the (unknown and unknowable) upper bound. This should not
9092 cause too much trouble for existing (stupid?) debuggers because
9093 they have to deal with empty upper bounds location descriptions
9094 anyway in order to be able to deal with incomplete array types.
9095 Of course an intelligent debugger (GDB?) should be able to
9096 comprehend that a missing upper bound specification in an array
9097 type used for a storage class `auto' local array variable
9098 indicates that the upper bound is both unknown (at compile- time)
9099 and unknowable (at run-time) due to optimization.
9101 We assume that a MEM rtx is safe because gcc wouldn't put the
9102 value there unless it was going to be used repeatedly in the
9103 function, i.e. for cleanups. */
9104 if (SAVE_EXPR_RTL (bound
)
9105 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9107 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9108 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9109 rtx loc
= SAVE_EXPR_RTL (bound
);
9111 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9112 it references an outer function's frame. */
9113 if (GET_CODE (loc
) == MEM
)
9115 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9117 if (XEXP (loc
, 0) != new_addr
)
9118 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9121 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9122 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9123 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
9124 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9127 /* Else leave out the attribute. */
9133 dw_die_ref decl_die
= lookup_decl_die (bound
);
9135 /* ??? Can this happen, or should the variable have been bound
9136 first? Probably it can, since I imagine that we try to create
9137 the types of parameters in the order in which they exist in
9138 the list, and won't have created a forward reference to a
9140 if (decl_die
!= NULL
)
9141 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9147 /* Otherwise try to create a stack operation procedure to
9148 evaluate the value of the array bound. */
9150 dw_die_ref ctx
, decl_die
;
9151 dw_loc_descr_ref loc
;
9153 loc
= loc_descriptor_from_tree (bound
, 0);
9157 if (current_function_decl
== 0)
9158 ctx
= comp_unit_die
;
9160 ctx
= lookup_decl_die (current_function_decl
);
9162 /* If we weren't able to find a context, it's most likely the case
9163 that we are processing the return type of the function. So
9164 make a SAVE_EXPR to point to it and have the limbo DIE code
9165 find the proper die. The save_expr function doesn't always
9166 make a SAVE_EXPR, so do it ourselves. */
9168 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9169 current_function_decl
, NULL_TREE
);
9171 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9172 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9173 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9174 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9176 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9182 /* Note that the block of subscript information for an array type also
9183 includes information about the element type of type given array type. */
9186 add_subscript_info (type_die
, type
)
9187 dw_die_ref type_die
;
9190 #ifndef MIPS_DEBUGGING_INFO
9191 unsigned dimension_number
;
9194 dw_die_ref subrange_die
;
9196 /* The GNU compilers represent multidimensional array types as sequences of
9197 one dimensional array types whose element types are themselves array
9198 types. Here we squish that down, so that each multidimensional array
9199 type gets only one array_type DIE in the Dwarf debugging info. The draft
9200 Dwarf specification say that we are allowed to do this kind of
9201 compression in C (because there is no difference between an array or
9202 arrays and a multidimensional array in C) but for other source languages
9203 (e.g. Ada) we probably shouldn't do this. */
9205 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9206 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9207 We work around this by disabling this feature. See also
9208 gen_array_type_die. */
9209 #ifndef MIPS_DEBUGGING_INFO
9210 for (dimension_number
= 0;
9211 TREE_CODE (type
) == ARRAY_TYPE
;
9212 type
= TREE_TYPE (type
), dimension_number
++)
9215 tree domain
= TYPE_DOMAIN (type
);
9217 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9218 and (in GNU C only) variable bounds. Handle all three forms
9220 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9223 /* We have an array type with specified bounds. */
9224 lower
= TYPE_MIN_VALUE (domain
);
9225 upper
= TYPE_MAX_VALUE (domain
);
9227 /* define the index type. */
9228 if (TREE_TYPE (domain
))
9230 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9231 TREE_TYPE field. We can't emit debug info for this
9232 because it is an unnamed integral type. */
9233 if (TREE_CODE (domain
) == INTEGER_TYPE
9234 && TYPE_NAME (domain
) == NULL_TREE
9235 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9236 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9239 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9243 /* ??? If upper is NULL, the array has unspecified length,
9244 but it does have a lower bound. This happens with Fortran
9246 Since the debugger is definitely going to need to know N
9247 to produce useful results, go ahead and output the lower
9248 bound solo, and hope the debugger can cope. */
9250 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9252 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9255 /* Otherwise we have an array type with an unspecified length. The
9256 DWARF-2 spec does not say how to handle this; let's just leave out the
9262 add_byte_size_attribute (die
, tree_node
)
9268 switch (TREE_CODE (tree_node
))
9276 case QUAL_UNION_TYPE
:
9277 size
= int_size_in_bytes (tree_node
);
9280 /* For a data member of a struct or union, the DW_AT_byte_size is
9281 generally given as the number of bytes normally allocated for an
9282 object of the *declared* type of the member itself. This is true
9283 even for bit-fields. */
9284 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9290 /* Note that `size' might be -1 when we get to this point. If it is, that
9291 indicates that the byte size of the entity in question is variable. We
9292 have no good way of expressing this fact in Dwarf at the present time,
9293 so just let the -1 pass on through. */
9294 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9297 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9298 which specifies the distance in bits from the highest order bit of the
9299 "containing object" for the bit-field to the highest order bit of the
9302 For any given bit-field, the "containing object" is a hypothetical object
9303 (of some integral or enum type) within which the given bit-field lives. The
9304 type of this hypothetical "containing object" is always the same as the
9305 declared type of the individual bit-field itself. The determination of the
9306 exact location of the "containing object" for a bit-field is rather
9307 complicated. It's handled by the `field_byte_offset' function (above).
9309 Note that it is the size (in bytes) of the hypothetical "containing object"
9310 which will be given in the DW_AT_byte_size attribute for this bit-field.
9311 (See `byte_size_attribute' above). */
9314 add_bit_offset_attribute (die
, decl
)
9318 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9319 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9320 HOST_WIDE_INT bitpos_int
;
9321 HOST_WIDE_INT highest_order_object_bit_offset
;
9322 HOST_WIDE_INT highest_order_field_bit_offset
;
9323 HOST_WIDE_INT
unsigned bit_offset
;
9325 /* Must be a field and a bit field. */
9327 || TREE_CODE (decl
) != FIELD_DECL
)
9330 /* We can't yet handle bit-fields whose offsets are variable, so if we
9331 encounter such things, just return without generating any attribute
9332 whatsoever. Likewise for variable or too large size. */
9333 if (! host_integerp (bit_position (decl
), 0)
9334 || ! host_integerp (DECL_SIZE (decl
), 1))
9337 bitpos_int
= int_bit_position (decl
);
9339 /* Note that the bit offset is always the distance (in bits) from the
9340 highest-order bit of the "containing object" to the highest-order bit of
9341 the bit-field itself. Since the "high-order end" of any object or field
9342 is different on big-endian and little-endian machines, the computation
9343 below must take account of these differences. */
9344 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9345 highest_order_field_bit_offset
= bitpos_int
;
9347 if (! BYTES_BIG_ENDIAN
)
9349 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9350 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9354 = (! BYTES_BIG_ENDIAN
9355 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9356 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9358 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9361 /* For a FIELD_DECL node which represents a bit field, output an attribute
9362 which specifies the length in bits of the given field. */
9365 add_bit_size_attribute (die
, decl
)
9369 /* Must be a field and a bit field. */
9370 if (TREE_CODE (decl
) != FIELD_DECL
9371 || ! DECL_BIT_FIELD_TYPE (decl
))
9374 if (host_integerp (DECL_SIZE (decl
), 1))
9375 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9378 /* If the compiled language is ANSI C, then add a 'prototyped'
9379 attribute, if arg types are given for the parameters of a function. */
9382 add_prototyped_attribute (die
, func_type
)
9386 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9387 && TYPE_ARG_TYPES (func_type
) != NULL
)
9388 add_AT_flag (die
, DW_AT_prototyped
, 1);
9391 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9392 by looking in either the type declaration or object declaration
9396 add_abstract_origin_attribute (die
, origin
)
9400 dw_die_ref origin_die
= NULL
;
9402 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9404 /* We may have gotten separated from the block for the inlined
9405 function, if we're in an exception handler or some such; make
9406 sure that the abstract function has been written out.
9408 Doing this for nested functions is wrong, however; functions are
9409 distinct units, and our context might not even be inline. */
9413 fn
= TYPE_STUB_DECL (fn
);
9415 fn
= decl_function_context (fn
);
9417 dwarf2out_abstract_function (fn
);
9420 if (DECL_P (origin
))
9421 origin_die
= lookup_decl_die (origin
);
9422 else if (TYPE_P (origin
))
9423 origin_die
= lookup_type_die (origin
);
9425 if (origin_die
== NULL
)
9428 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9431 /* We do not currently support the pure_virtual attribute. */
9434 add_pure_or_virtual_attribute (die
, func_decl
)
9438 if (DECL_VINDEX (func_decl
))
9440 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9442 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9443 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9444 new_loc_descr (DW_OP_constu
,
9445 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9448 /* GNU extension: Record what type this method came from originally. */
9449 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9450 add_AT_die_ref (die
, DW_AT_containing_type
,
9451 lookup_type_die (DECL_CONTEXT (func_decl
)));
9455 /* Add source coordinate attributes for the given decl. */
9458 add_src_coords_attributes (die
, decl
)
9462 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9464 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9465 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9468 /* Add an DW_AT_name attribute and source coordinate attribute for the
9469 given decl, but only if it actually has a name. */
9472 add_name_and_src_coords_attributes (die
, decl
)
9478 decl_name
= DECL_NAME (decl
);
9479 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9481 add_name_attribute (die
, dwarf2_name (decl
, 0));
9482 if (! DECL_ARTIFICIAL (decl
))
9483 add_src_coords_attributes (die
, decl
);
9485 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9486 && TREE_PUBLIC (decl
)
9487 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9488 && !DECL_ABSTRACT (decl
))
9489 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9490 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9493 #ifdef VMS_DEBUGGING_INFO
9494 /* Get the function's name, as described by its RTL. This may be different
9495 from the DECL_NAME name used in the source file. */
9496 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9498 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9499 XEXP (DECL_RTL (decl
), 0));
9500 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9505 /* Push a new declaration scope. */
9508 push_decl_scope (scope
)
9511 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9514 /* Pop a declaration scope. */
9519 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9522 VARRAY_POP (decl_scope_table
);
9525 /* Return the DIE for the scope that immediately contains this type.
9526 Non-named types get global scope. Named types nested in other
9527 types get their containing scope if it's open, or global scope
9528 otherwise. All other types (i.e. function-local named types) get
9529 the current active scope. */
9532 scope_die_for (t
, context_die
)
9534 dw_die_ref context_die
;
9536 dw_die_ref scope_die
= NULL
;
9537 tree containing_scope
;
9540 /* Non-types always go in the current scope. */
9544 containing_scope
= TYPE_CONTEXT (t
);
9546 /* Ignore namespaces for the moment. */
9547 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9548 containing_scope
= NULL_TREE
;
9550 /* Ignore function type "scopes" from the C frontend. They mean that
9551 a tagged type is local to a parmlist of a function declarator, but
9552 that isn't useful to DWARF. */
9553 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9554 containing_scope
= NULL_TREE
;
9556 if (containing_scope
== NULL_TREE
)
9557 scope_die
= comp_unit_die
;
9558 else if (TYPE_P (containing_scope
))
9560 /* For types, we can just look up the appropriate DIE. But
9561 first we check to see if we're in the middle of emitting it
9562 so we know where the new DIE should go. */
9563 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9564 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9569 if (debug_info_level
> DINFO_LEVEL_TERSE
9570 && !TREE_ASM_WRITTEN (containing_scope
))
9573 /* If none of the current dies are suitable, we get file scope. */
9574 scope_die
= comp_unit_die
;
9577 scope_die
= lookup_type_die (containing_scope
);
9580 scope_die
= context_die
;
9585 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9588 local_scope_p (context_die
)
9589 dw_die_ref context_die
;
9591 for (; context_die
; context_die
= context_die
->die_parent
)
9592 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
9593 || context_die
->die_tag
== DW_TAG_subprogram
)
9599 /* Returns nonzero if CONTEXT_DIE is a class. */
9602 class_scope_p (context_die
)
9603 dw_die_ref context_die
;
9606 && (context_die
->die_tag
== DW_TAG_structure_type
9607 || context_die
->die_tag
== DW_TAG_union_type
));
9610 /* Many forms of DIEs require a "type description" attribute. This
9611 routine locates the proper "type descriptor" die for the type given
9612 by 'type', and adds an DW_AT_type attribute below the given die. */
9615 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
9616 dw_die_ref object_die
;
9620 dw_die_ref context_die
;
9622 enum tree_code code
= TREE_CODE (type
);
9623 dw_die_ref type_die
= NULL
;
9625 /* ??? If this type is an unnamed subrange type of an integral or
9626 floating-point type, use the inner type. This is because we have no
9627 support for unnamed types in base_type_die. This can happen if this is
9628 an Ada subrange type. Correct solution is emit a subrange type die. */
9629 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
9630 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
9631 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
9633 if (code
== ERROR_MARK
9634 /* Handle a special case. For functions whose return type is void, we
9635 generate *no* type attribute. (Note that no object may have type
9636 `void', so this only applies to function return types). */
9637 || code
== VOID_TYPE
)
9640 type_die
= modified_type_die (type
,
9641 decl_const
|| TYPE_READONLY (type
),
9642 decl_volatile
|| TYPE_VOLATILE (type
),
9645 if (type_die
!= NULL
)
9646 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
9649 /* Given a tree pointer to a struct, class, union, or enum type node, return
9650 a pointer to the (string) tag name for the given type, or zero if the type
9651 was declared without a tag. */
9657 const char *name
= 0;
9659 if (TYPE_NAME (type
) != 0)
9663 /* Find the IDENTIFIER_NODE for the type name. */
9664 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9665 t
= TYPE_NAME (type
);
9667 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9668 a TYPE_DECL node, regardless of whether or not a `typedef' was
9670 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9671 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
9672 t
= DECL_NAME (TYPE_NAME (type
));
9674 /* Now get the name as a string, or invent one. */
9676 name
= IDENTIFIER_POINTER (t
);
9679 return (name
== 0 || *name
== '\0') ? 0 : name
;
9682 /* Return the type associated with a data member, make a special check
9683 for bit field types. */
9686 member_declared_type (member
)
9689 return (DECL_BIT_FIELD_TYPE (member
)
9690 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
9693 /* Get the decl's label, as described by its RTL. This may be different
9694 from the DECL_NAME name used in the source file. */
9698 decl_start_label (decl
)
9704 x
= DECL_RTL (decl
);
9705 if (GET_CODE (x
) != MEM
)
9709 if (GET_CODE (x
) != SYMBOL_REF
)
9712 fnname
= XSTR (x
, 0);
9717 /* These routines generate the internal representation of the DIE's for
9718 the compilation unit. Debugging information is collected by walking
9719 the declaration trees passed in from dwarf2out_decl(). */
9722 gen_array_type_die (type
, context_die
)
9724 dw_die_ref context_die
;
9726 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
9727 dw_die_ref array_die
;
9730 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9731 the inner array type comes before the outer array type. Thus we must
9732 call gen_type_die before we call new_die. See below also. */
9733 #ifdef MIPS_DEBUGGING_INFO
9734 gen_type_die (TREE_TYPE (type
), context_die
);
9737 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
9738 add_name_attribute (array_die
, type_tag (type
));
9739 equate_type_number_to_die (type
, array_die
);
9741 if (TREE_CODE (type
) == VECTOR_TYPE
)
9743 /* The frontend feeds us a representation for the vector as a struct
9744 containing an array. Pull out the array type. */
9745 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
9746 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
9750 /* We default the array ordering. SDB will probably do
9751 the right things even if DW_AT_ordering is not present. It's not even
9752 an issue until we start to get into multidimensional arrays anyway. If
9753 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9754 then we'll have to put the DW_AT_ordering attribute back in. (But if
9755 and when we find out that we need to put these in, we will only do so
9756 for multidimensional arrays. */
9757 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
9760 #ifdef MIPS_DEBUGGING_INFO
9761 /* The SGI compilers handle arrays of unknown bound by setting
9762 AT_declaration and not emitting any subrange DIEs. */
9763 if (! TYPE_DOMAIN (type
))
9764 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
9767 add_subscript_info (array_die
, type
);
9769 /* Add representation of the type of the elements of this array type. */
9770 element_type
= TREE_TYPE (type
);
9772 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9773 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9774 We work around this by disabling this feature. See also
9775 add_subscript_info. */
9776 #ifndef MIPS_DEBUGGING_INFO
9777 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
9778 element_type
= TREE_TYPE (element_type
);
9780 gen_type_die (element_type
, context_die
);
9783 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
9787 gen_set_type_die (type
, context_die
)
9789 dw_die_ref context_die
;
9792 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
9794 equate_type_number_to_die (type
, type_die
);
9795 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
9800 gen_entry_point_die (decl
, context_die
)
9802 dw_die_ref context_die
;
9804 tree origin
= decl_ultimate_origin (decl
);
9805 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
9808 add_abstract_origin_attribute (decl_die
, origin
);
9811 add_name_and_src_coords_attributes (decl_die
, decl
);
9812 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
9816 if (DECL_ABSTRACT (decl
))
9817 equate_decl_number_to_die (decl
, decl_die
);
9819 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
9823 /* Walk through the list of incomplete types again, trying once more to
9824 emit full debugging info for them. */
9827 retry_incomplete_types ()
9831 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
9832 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
9835 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9838 gen_inlined_enumeration_type_die (type
, context_die
)
9840 dw_die_ref context_die
;
9842 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
9844 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9845 be incomplete and such types are not marked. */
9846 add_abstract_origin_attribute (type_die
, type
);
9849 /* Generate a DIE to represent an inlined instance of a structure type. */
9852 gen_inlined_structure_type_die (type
, context_die
)
9854 dw_die_ref context_die
;
9856 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
9858 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9859 be incomplete and such types are not marked. */
9860 add_abstract_origin_attribute (type_die
, type
);
9863 /* Generate a DIE to represent an inlined instance of a union type. */
9866 gen_inlined_union_type_die (type
, context_die
)
9868 dw_die_ref context_die
;
9870 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
9872 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9873 be incomplete and such types are not marked. */
9874 add_abstract_origin_attribute (type_die
, type
);
9877 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9878 include all of the information about the enumeration values also. Each
9879 enumerated type name/value is listed as a child of the enumerated type
9883 gen_enumeration_type_die (type
, context_die
)
9885 dw_die_ref context_die
;
9887 dw_die_ref type_die
= lookup_type_die (type
);
9889 if (type_die
== NULL
)
9891 type_die
= new_die (DW_TAG_enumeration_type
,
9892 scope_die_for (type
, context_die
), type
);
9893 equate_type_number_to_die (type
, type_die
);
9894 add_name_attribute (type_die
, type_tag (type
));
9896 else if (! TYPE_SIZE (type
))
9899 remove_AT (type_die
, DW_AT_declaration
);
9901 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9902 given enum type is incomplete, do not generate the DW_AT_byte_size
9903 attribute or the DW_AT_element_list attribute. */
9904 if (TYPE_SIZE (type
))
9908 TREE_ASM_WRITTEN (type
) = 1;
9909 add_byte_size_attribute (type_die
, type
);
9910 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
9911 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
9913 /* If the first reference to this type was as the return type of an
9914 inline function, then it may not have a parent. Fix this now. */
9915 if (type_die
->die_parent
== NULL
)
9916 add_child_die (scope_die_for (type
, context_die
), type_die
);
9918 for (link
= TYPE_FIELDS (type
);
9919 link
!= NULL
; link
= TREE_CHAIN (link
))
9921 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
9923 add_name_attribute (enum_die
,
9924 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
9926 if (host_integerp (TREE_VALUE (link
), 0))
9928 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
9929 add_AT_int (enum_die
, DW_AT_const_value
,
9930 tree_low_cst (TREE_VALUE (link
), 0));
9932 add_AT_unsigned (enum_die
, DW_AT_const_value
,
9933 tree_low_cst (TREE_VALUE (link
), 0));
9938 add_AT_flag (type_die
, DW_AT_declaration
, 1);
9941 /* Generate a DIE to represent either a real live formal parameter decl or to
9942 represent just the type of some formal parameter position in some function
9945 Note that this routine is a bit unusual because its argument may be a
9946 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9947 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9948 node. If it's the former then this function is being called to output a
9949 DIE to represent a formal parameter object (or some inlining thereof). If
9950 it's the latter, then this function is only being called to output a
9951 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9952 argument type of some subprogram type. */
9955 gen_formal_parameter_die (node
, context_die
)
9957 dw_die_ref context_die
;
9960 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
9963 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
9966 origin
= decl_ultimate_origin (node
);
9968 add_abstract_origin_attribute (parm_die
, origin
);
9971 add_name_and_src_coords_attributes (parm_die
, node
);
9972 add_type_attribute (parm_die
, TREE_TYPE (node
),
9973 TREE_READONLY (node
),
9974 TREE_THIS_VOLATILE (node
),
9976 if (DECL_ARTIFICIAL (node
))
9977 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
9980 equate_decl_number_to_die (node
, parm_die
);
9981 if (! DECL_ABSTRACT (node
))
9982 add_location_or_const_value_attribute (parm_die
, node
);
9987 /* We were called with some kind of a ..._TYPE node. */
9988 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
9998 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9999 at the end of an (ANSI prototyped) formal parameters list. */
10002 gen_unspecified_parameters_die (decl_or_type
, context_die
)
10004 dw_die_ref context_die
;
10006 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10009 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10010 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10011 parameters as specified in some function type specification (except for
10012 those which appear as part of a function *definition*). */
10015 gen_formal_types_die (function_or_method_type
, context_die
)
10016 tree function_or_method_type
;
10017 dw_die_ref context_die
;
10020 tree formal_type
= NULL
;
10021 tree first_parm_type
;
10024 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10026 arg
= DECL_ARGUMENTS (function_or_method_type
);
10027 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10032 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10034 /* Make our first pass over the list of formal parameter types and output a
10035 DW_TAG_formal_parameter DIE for each one. */
10036 for (link
= first_parm_type
; link
; )
10038 dw_die_ref parm_die
;
10040 formal_type
= TREE_VALUE (link
);
10041 if (formal_type
== void_type_node
)
10044 /* Output a (nameless) DIE to represent the formal parameter itself. */
10045 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10046 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10047 && link
== first_parm_type
)
10048 || (arg
&& DECL_ARTIFICIAL (arg
)))
10049 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10051 link
= TREE_CHAIN (link
);
10053 arg
= TREE_CHAIN (arg
);
10056 /* If this function type has an ellipsis, add a
10057 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10058 if (formal_type
!= void_type_node
)
10059 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10061 /* Make our second (and final) pass over the list of formal parameter types
10062 and output DIEs to represent those types (as necessary). */
10063 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10064 link
&& TREE_VALUE (link
);
10065 link
= TREE_CHAIN (link
))
10066 gen_type_die (TREE_VALUE (link
), context_die
);
10069 /* We want to generate the DIE for TYPE so that we can generate the
10070 die for MEMBER, which has been defined; we will need to refer back
10071 to the member declaration nested within TYPE. If we're trying to
10072 generate minimal debug info for TYPE, processing TYPE won't do the
10073 trick; we need to attach the member declaration by hand. */
10076 gen_type_die_for_member (type
, member
, context_die
)
10078 dw_die_ref context_die
;
10080 gen_type_die (type
, context_die
);
10082 /* If we're trying to avoid duplicate debug info, we may not have
10083 emitted the member decl for this function. Emit it now. */
10084 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10085 && ! lookup_decl_die (member
))
10087 if (decl_ultimate_origin (member
))
10090 push_decl_scope (type
);
10091 if (TREE_CODE (member
) == FUNCTION_DECL
)
10092 gen_subprogram_die (member
, lookup_type_die (type
));
10094 gen_variable_die (member
, lookup_type_die (type
));
10100 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10101 may later generate inlined and/or out-of-line instances of. */
10104 dwarf2out_abstract_function (decl
)
10107 dw_die_ref old_die
;
10110 int was_abstract
= DECL_ABSTRACT (decl
);
10112 /* Make sure we have the actual abstract inline, not a clone. */
10113 decl
= DECL_ORIGIN (decl
);
10115 old_die
= lookup_decl_die (decl
);
10116 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10117 /* We've already generated the abstract instance. */
10120 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10121 we don't get confused by DECL_ABSTRACT. */
10122 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10124 context
= decl_class_context (decl
);
10126 gen_type_die_for_member
10127 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10130 /* Pretend we've just finished compiling this function. */
10131 save_fn
= current_function_decl
;
10132 current_function_decl
= decl
;
10134 set_decl_abstract_flags (decl
, 1);
10135 dwarf2out_decl (decl
);
10136 if (! was_abstract
)
10137 set_decl_abstract_flags (decl
, 0);
10139 current_function_decl
= save_fn
;
10142 /* Generate a DIE to represent a declared function (either file-scope or
10146 gen_subprogram_die (decl
, context_die
)
10148 dw_die_ref context_die
;
10150 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10151 tree origin
= decl_ultimate_origin (decl
);
10152 dw_die_ref subr_die
;
10156 dw_die_ref old_die
= lookup_decl_die (decl
);
10157 int declaration
= (current_function_decl
!= decl
10158 || class_scope_p (context_die
));
10160 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10161 started to generate the abstract instance of an inline, decided to output
10162 its containing class, and proceeded to emit the declaration of the inline
10163 from the member list for the class. If so, DECLARATION takes priority;
10164 we'll get back to the abstract instance when done with the class. */
10166 /* The class-scope declaration DIE must be the primary DIE. */
10167 if (origin
&& declaration
&& class_scope_p (context_die
))
10174 if (origin
!= NULL
)
10176 if (declaration
&& ! local_scope_p (context_die
))
10179 /* Fixup die_parent for the abstract instance of a nested
10180 inline function. */
10181 if (old_die
&& old_die
->die_parent
== NULL
)
10182 add_child_die (context_die
, old_die
);
10184 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10185 add_abstract_origin_attribute (subr_die
, origin
);
10189 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10191 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10192 /* We can have a normal definition following an inline one in the
10193 case of redefinition of GNU C extern inlines.
10194 It seems reasonable to use AT_specification in this case. */
10195 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10197 /* ??? This can happen if there is a bug in the program, for
10198 instance, if it has duplicate function definitions. Ideally,
10199 we should detect this case and ignore it. For now, if we have
10200 already reported an error, any error at all, then assume that
10201 we got here because of an input error, not a dwarf2 bug. */
10207 /* If the definition comes from the same place as the declaration,
10208 maybe use the old DIE. We always want the DIE for this function
10209 that has the *_pc attributes to be under comp_unit_die so the
10210 debugger can find it. We also need to do this for abstract
10211 instances of inlines, since the spec requires the out-of-line copy
10212 to have the same parent. For local class methods, this doesn't
10213 apply; we just use the old DIE. */
10214 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10215 && (DECL_ARTIFICIAL (decl
)
10216 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10217 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10218 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10220 subr_die
= old_die
;
10222 /* Clear out the declaration attribute and the parm types. */
10223 remove_AT (subr_die
, DW_AT_declaration
);
10224 remove_children (subr_die
);
10228 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10229 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10230 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10231 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10232 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10233 != (unsigned) DECL_SOURCE_LINE (decl
))
10235 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10240 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10242 if (TREE_PUBLIC (decl
))
10243 add_AT_flag (subr_die
, DW_AT_external
, 1);
10245 add_name_and_src_coords_attributes (subr_die
, decl
);
10246 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10248 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10249 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10250 0, 0, context_die
);
10253 add_pure_or_virtual_attribute (subr_die
, decl
);
10254 if (DECL_ARTIFICIAL (decl
))
10255 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10257 if (TREE_PROTECTED (decl
))
10258 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10259 else if (TREE_PRIVATE (decl
))
10260 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10265 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10267 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10269 /* The first time we see a member function, it is in the context of
10270 the class to which it belongs. We make sure of this by emitting
10271 the class first. The next time is the definition, which is
10272 handled above. The two may come from the same source text. */
10273 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10274 equate_decl_number_to_die (decl
, subr_die
);
10277 else if (DECL_ABSTRACT (decl
))
10279 if (DECL_INLINE (decl
) && !flag_no_inline
)
10281 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10282 inline functions, but not for extern inline functions.
10283 We can't get this completely correct because information
10284 about whether the function was declared inline is not
10286 if (DECL_DEFER_OUTPUT (decl
))
10287 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10289 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10292 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10294 equate_decl_number_to_die (decl
, subr_die
);
10296 else if (!DECL_EXTERNAL (decl
))
10298 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10299 equate_decl_number_to_die (decl
, subr_die
);
10301 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10302 current_function_funcdef_no
);
10303 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10304 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10305 current_function_funcdef_no
);
10306 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10308 add_pubname (decl
, subr_die
);
10309 add_arange (decl
, subr_die
);
10311 #ifdef MIPS_DEBUGGING_INFO
10312 /* Add a reference to the FDE for this routine. */
10313 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10316 /* Define the "frame base" location for this routine. We use the
10317 frame pointer or stack pointer registers, since the RTL for local
10318 variables is relative to one of them. */
10320 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10321 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10324 /* ??? This fails for nested inline functions, because context_display
10325 is not part of the state saved/restored for inline functions. */
10326 if (current_function_needs_context
)
10327 add_AT_location_description (subr_die
, DW_AT_static_link
,
10328 lookup_static_chain (decl
));
10332 /* Now output descriptions of the arguments for this function. This gets
10333 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10334 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10335 `...' at the end of the formal parameter list. In order to find out if
10336 there was a trailing ellipsis or not, we must instead look at the type
10337 associated with the FUNCTION_DECL. This will be a node of type
10338 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10339 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10340 an ellipsis at the end. */
10342 /* In the case where we are describing a mere function declaration, all we
10343 need to do here (and all we *can* do here) is to describe the *types* of
10344 its formal parameters. */
10345 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10347 else if (declaration
)
10348 gen_formal_types_die (decl
, subr_die
);
10351 /* Generate DIEs to represent all known formal parameters */
10352 tree arg_decls
= DECL_ARGUMENTS (decl
);
10355 /* When generating DIEs, generate the unspecified_parameters DIE
10356 instead if we come across the arg "__builtin_va_alist" */
10357 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10358 if (TREE_CODE (parm
) == PARM_DECL
)
10360 if (DECL_NAME (parm
)
10361 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10362 "__builtin_va_alist"))
10363 gen_unspecified_parameters_die (parm
, subr_die
);
10365 gen_decl_die (parm
, subr_die
);
10368 /* Decide whether we need an unspecified_parameters DIE at the end.
10369 There are 2 more cases to do this for: 1) the ansi ... declaration -
10370 this is detectable when the end of the arg list is not a
10371 void_type_node 2) an unprototyped function declaration (not a
10372 definition). This just means that we have no info about the
10373 parameters at all. */
10374 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10375 if (fn_arg_types
!= NULL
)
10377 /* this is the prototyped case, check for ... */
10378 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10379 gen_unspecified_parameters_die (decl
, subr_die
);
10381 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10382 gen_unspecified_parameters_die (decl
, subr_die
);
10385 /* Output Dwarf info for all of the stuff within the body of the function
10386 (if it has one - it may be just a declaration). */
10387 outer_scope
= DECL_INITIAL (decl
);
10389 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10390 a function. This BLOCK actually represents the outermost binding contour
10391 for the function, i.e. the contour in which the function's formal
10392 parameters and labels get declared. Curiously, it appears that the front
10393 end doesn't actually put the PARM_DECL nodes for the current function onto
10394 the BLOCK_VARS list for this outer scope, but are strung off of the
10395 DECL_ARGUMENTS list for the function instead.
10397 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10398 the LABEL_DECL nodes for the function however, and we output DWARF info
10399 for those in decls_for_scope. Just within the `outer_scope' there will be
10400 a BLOCK node representing the function's outermost pair of curly braces,
10401 and any blocks used for the base and member initializers of a C++
10402 constructor function. */
10403 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10405 current_function_has_inlines
= 0;
10406 decls_for_scope (outer_scope
, subr_die
, 0);
10408 #if 0 && defined (MIPS_DEBUGGING_INFO)
10409 if (current_function_has_inlines
)
10411 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10412 if (! comp_unit_has_inlines
)
10414 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10415 comp_unit_has_inlines
= 1;
10422 /* Generate a DIE to represent a declared data object. */
10425 gen_variable_die (decl
, context_die
)
10427 dw_die_ref context_die
;
10429 tree origin
= decl_ultimate_origin (decl
);
10430 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10432 dw_die_ref old_die
= lookup_decl_die (decl
);
10433 int declaration
= (DECL_EXTERNAL (decl
)
10434 || class_scope_p (context_die
));
10436 if (origin
!= NULL
)
10437 add_abstract_origin_attribute (var_die
, origin
);
10439 /* Loop unrolling can create multiple blocks that refer to the same
10440 static variable, so we must test for the DW_AT_declaration flag.
10442 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10443 copy decls and set the DECL_ABSTRACT flag on them instead of
10446 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10447 else if (old_die
&& TREE_STATIC (decl
)
10448 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10450 /* This is a definition of a C++ class level static. */
10451 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10452 if (DECL_NAME (decl
))
10454 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10456 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10457 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10459 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10460 != (unsigned) DECL_SOURCE_LINE (decl
))
10462 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10463 DECL_SOURCE_LINE (decl
));
10468 add_name_and_src_coords_attributes (var_die
, decl
);
10469 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10470 TREE_THIS_VOLATILE (decl
), context_die
);
10472 if (TREE_PUBLIC (decl
))
10473 add_AT_flag (var_die
, DW_AT_external
, 1);
10475 if (DECL_ARTIFICIAL (decl
))
10476 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10478 if (TREE_PROTECTED (decl
))
10479 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10480 else if (TREE_PRIVATE (decl
))
10481 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10485 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10487 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10488 equate_decl_number_to_die (decl
, var_die
);
10490 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10492 add_location_or_const_value_attribute (var_die
, decl
);
10493 add_pubname (decl
, var_die
);
10496 tree_add_const_value_attribute (var_die
, decl
);
10499 /* Generate a DIE to represent a label identifier. */
10502 gen_label_die (decl
, context_die
)
10504 dw_die_ref context_die
;
10506 tree origin
= decl_ultimate_origin (decl
);
10507 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10509 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10511 if (origin
!= NULL
)
10512 add_abstract_origin_attribute (lbl_die
, origin
);
10514 add_name_and_src_coords_attributes (lbl_die
, decl
);
10516 if (DECL_ABSTRACT (decl
))
10517 equate_decl_number_to_die (decl
, lbl_die
);
10520 insn
= DECL_RTL (decl
);
10522 /* Deleted labels are programmer specified labels which have been
10523 eliminated because of various optimisations. We still emit them
10524 here so that it is possible to put breakpoints on them. */
10525 if (GET_CODE (insn
) == CODE_LABEL
10526 || ((GET_CODE (insn
) == NOTE
10527 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10529 /* When optimization is enabled (via -O) some parts of the compiler
10530 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10531 represent source-level labels which were explicitly declared by
10532 the user. This really shouldn't be happening though, so catch
10533 it if it ever does happen. */
10534 if (INSN_DELETED_P (insn
))
10537 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10538 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10543 /* Generate a DIE for a lexical block. */
10546 gen_lexical_block_die (stmt
, context_die
, depth
)
10548 dw_die_ref context_die
;
10551 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10552 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10554 if (! BLOCK_ABSTRACT (stmt
))
10556 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10560 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10562 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10565 add_ranges (chain
);
10566 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10573 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10574 BLOCK_NUMBER (stmt
));
10575 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10576 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10577 BLOCK_NUMBER (stmt
));
10578 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10582 decls_for_scope (stmt
, stmt_die
, depth
);
10585 /* Generate a DIE for an inlined subprogram. */
10588 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
10590 dw_die_ref context_die
;
10593 if (! BLOCK_ABSTRACT (stmt
))
10595 dw_die_ref subr_die
10596 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10597 tree decl
= block_ultimate_origin (stmt
);
10598 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10600 /* Emit info for the abstract instance first, if we haven't yet. */
10601 dwarf2out_abstract_function (decl
);
10603 add_abstract_origin_attribute (subr_die
, decl
);
10604 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10605 BLOCK_NUMBER (stmt
));
10606 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10607 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10608 BLOCK_NUMBER (stmt
));
10609 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10610 decls_for_scope (stmt
, subr_die
, depth
);
10611 current_function_has_inlines
= 1;
10614 /* We may get here if we're the outer block of function A that was
10615 inlined into function B that was inlined into function C. When
10616 generating debugging info for C, dwarf2out_abstract_function(B)
10617 would mark all inlined blocks as abstract, including this one.
10618 So, we wouldn't (and shouldn't) expect labels to be generated
10619 for this one. Instead, just emit debugging info for
10620 declarations within the block. This is particularly important
10621 in the case of initializers of arguments passed from B to us:
10622 if they're statement expressions containing declarations, we
10623 wouldn't generate dies for their abstract variables, and then,
10624 when generating dies for the real variables, we'd die (pun
10626 gen_lexical_block_die (stmt
, context_die
, depth
);
10629 /* Generate a DIE for a field in a record, or structure. */
10632 gen_field_die (decl
, context_die
)
10634 dw_die_ref context_die
;
10636 dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
10638 add_name_and_src_coords_attributes (decl_die
, decl
);
10639 add_type_attribute (decl_die
, member_declared_type (decl
),
10640 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
10643 if (DECL_BIT_FIELD_TYPE (decl
))
10645 add_byte_size_attribute (decl_die
, decl
);
10646 add_bit_size_attribute (decl_die
, decl
);
10647 add_bit_offset_attribute (decl_die
, decl
);
10650 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
10651 add_data_member_location_attribute (decl_die
, decl
);
10653 if (DECL_ARTIFICIAL (decl
))
10654 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10656 if (TREE_PROTECTED (decl
))
10657 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10658 else if (TREE_PRIVATE (decl
))
10659 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10663 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10664 Use modified_type_die instead.
10665 We keep this code here just in case these types of DIEs may be needed to
10666 represent certain things in other languages (e.g. Pascal) someday. */
10669 gen_pointer_type_die (type
, context_die
)
10671 dw_die_ref context_die
;
10674 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
10676 equate_type_number_to_die (type
, ptr_die
);
10677 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10678 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10681 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10682 Use modified_type_die instead.
10683 We keep this code here just in case these types of DIEs may be needed to
10684 represent certain things in other languages (e.g. Pascal) someday. */
10687 gen_reference_type_die (type
, context_die
)
10689 dw_die_ref context_die
;
10692 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
10694 equate_type_number_to_die (type
, ref_die
);
10695 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
10696 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10700 /* Generate a DIE for a pointer to a member type. */
10703 gen_ptr_to_mbr_type_die (type
, context_die
)
10705 dw_die_ref context_die
;
10708 = new_die (DW_TAG_ptr_to_member_type
,
10709 scope_die_for (type
, context_die
), type
);
10711 equate_type_number_to_die (type
, ptr_die
);
10712 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
10713 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
10714 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10717 /* Generate the DIE for the compilation unit. */
10720 gen_compile_unit_die (filename
)
10721 const char *filename
;
10724 char producer
[250];
10725 const char *wd
= getpwd ();
10726 const char *language_string
= lang_hooks
.name
;
10729 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
10730 add_name_attribute (die
, filename
);
10732 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
10733 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10735 sprintf (producer
, "%s %s", language_string
, version_string
);
10737 #ifdef MIPS_DEBUGGING_INFO
10738 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10739 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10740 not appear in the producer string, the debugger reaches the conclusion
10741 that the object file is stripped and has no debugging information.
10742 To get the MIPS/SGI debugger to believe that there is debugging
10743 information in the object file, we add a -g to the producer string. */
10744 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10745 strcat (producer
, " -g");
10748 add_AT_string (die
, DW_AT_producer
, producer
);
10750 if (strcmp (language_string
, "GNU C++") == 0)
10751 language
= DW_LANG_C_plus_plus
;
10752 else if (strcmp (language_string
, "GNU Ada") == 0)
10753 language
= DW_LANG_Ada83
;
10754 else if (strcmp (language_string
, "GNU F77") == 0)
10755 language
= DW_LANG_Fortran77
;
10756 else if (strcmp (language_string
, "GNU Pascal") == 0)
10757 language
= DW_LANG_Pascal83
;
10758 else if (strcmp (language_string
, "GNU Java") == 0)
10759 language
= DW_LANG_Java
;
10761 language
= DW_LANG_C89
;
10763 add_AT_unsigned (die
, DW_AT_language
, language
);
10767 /* Generate a DIE for a string type. */
10770 gen_string_type_die (type
, context_die
)
10772 dw_die_ref context_die
;
10774 dw_die_ref type_die
10775 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
10777 equate_type_number_to_die (type
, type_die
);
10779 /* ??? Fudge the string length attribute for now.
10780 TODO: add string length info. */
10782 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
10783 bound_representation (upper_bound
, 0, 'u');
10787 /* Generate the DIE for a base class. */
10790 gen_inheritance_die (binfo
, context_die
)
10792 dw_die_ref context_die
;
10794 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
10796 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
10797 add_data_member_location_attribute (die
, binfo
);
10799 if (TREE_VIA_VIRTUAL (binfo
))
10800 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10802 if (TREE_VIA_PUBLIC (binfo
))
10803 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
10804 else if (TREE_VIA_PROTECTED (binfo
))
10805 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10808 /* Generate a DIE for a class member. */
10811 gen_member_die (type
, context_die
)
10813 dw_die_ref context_die
;
10818 /* If this is not an incomplete type, output descriptions of each of its
10819 members. Note that as we output the DIEs necessary to represent the
10820 members of this record or union type, we will also be trying to output
10821 DIEs to represent the *types* of those members. However the `type'
10822 function (above) will specifically avoid generating type DIEs for member
10823 types *within* the list of member DIEs for this (containing) type except
10824 for those types (of members) which are explicitly marked as also being
10825 members of this (containing) type themselves. The g++ front- end can
10826 force any given type to be treated as a member of some other (containing)
10827 type by setting the TYPE_CONTEXT of the given (member) type to point to
10828 the TREE node representing the appropriate (containing) type. */
10830 /* First output info about the base classes. */
10831 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
10833 tree bases
= TYPE_BINFO_BASETYPES (type
);
10834 int n_bases
= TREE_VEC_LENGTH (bases
);
10837 for (i
= 0; i
< n_bases
; i
++)
10838 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
10841 /* Now output info about the data members and type members. */
10842 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
10844 /* If we thought we were generating minimal debug info for TYPE
10845 and then changed our minds, some of the member declarations
10846 may have already been defined. Don't define them again, but
10847 do put them in the right order. */
10849 child
= lookup_decl_die (member
);
10851 splice_child_die (context_die
, child
);
10853 gen_decl_die (member
, context_die
);
10856 /* Now output info about the function members (if any). */
10857 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
10859 /* Don't include clones in the member list. */
10860 if (DECL_ABSTRACT_ORIGIN (member
))
10863 child
= lookup_decl_die (member
);
10865 splice_child_die (context_die
, child
);
10867 gen_decl_die (member
, context_die
);
10871 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10872 is set, we pretend that the type was never defined, so we only get the
10873 member DIEs needed by later specification DIEs. */
10876 gen_struct_or_union_type_die (type
, context_die
)
10878 dw_die_ref context_die
;
10880 dw_die_ref type_die
= lookup_type_die (type
);
10881 dw_die_ref scope_die
= 0;
10883 int complete
= (TYPE_SIZE (type
)
10884 && (! TYPE_STUB_DECL (type
)
10885 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
10887 if (type_die
&& ! complete
)
10890 if (TYPE_CONTEXT (type
) != NULL_TREE
10891 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
10894 scope_die
= scope_die_for (type
, context_die
);
10896 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
10897 /* First occurrence of type or toplevel definition of nested class. */
10899 dw_die_ref old_die
= type_die
;
10901 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
10902 ? DW_TAG_structure_type
: DW_TAG_union_type
,
10904 equate_type_number_to_die (type
, type_die
);
10906 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
10908 add_name_attribute (type_die
, type_tag (type
));
10911 remove_AT (type_die
, DW_AT_declaration
);
10913 /* If this type has been completed, then give it a byte_size attribute and
10914 then give a list of members. */
10917 /* Prevent infinite recursion in cases where the type of some member of
10918 this type is expressed in terms of this type itself. */
10919 TREE_ASM_WRITTEN (type
) = 1;
10920 add_byte_size_attribute (type_die
, type
);
10921 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10922 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10924 /* If the first reference to this type was as the return type of an
10925 inline function, then it may not have a parent. Fix this now. */
10926 if (type_die
->die_parent
== NULL
)
10927 add_child_die (scope_die
, type_die
);
10929 push_decl_scope (type
);
10930 gen_member_die (type
, type_die
);
10933 /* GNU extension: Record what type our vtable lives in. */
10934 if (TYPE_VFIELD (type
))
10936 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
10938 gen_type_die (vtype
, context_die
);
10939 add_AT_die_ref (type_die
, DW_AT_containing_type
,
10940 lookup_type_die (vtype
));
10945 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10947 /* We don't need to do this for function-local types. */
10948 if (TYPE_STUB_DECL (type
)
10949 && ! decl_function_context (TYPE_STUB_DECL (type
)))
10950 VARRAY_PUSH_TREE (incomplete_types
, type
);
10954 /* Generate a DIE for a subroutine _type_. */
10957 gen_subroutine_type_die (type
, context_die
)
10959 dw_die_ref context_die
;
10961 tree return_type
= TREE_TYPE (type
);
10962 dw_die_ref subr_die
10963 = new_die (DW_TAG_subroutine_type
,
10964 scope_die_for (type
, context_die
), type
);
10966 equate_type_number_to_die (type
, subr_die
);
10967 add_prototyped_attribute (subr_die
, type
);
10968 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
10969 gen_formal_types_die (type
, subr_die
);
10972 /* Generate a DIE for a type definition */
10975 gen_typedef_die (decl
, context_die
)
10977 dw_die_ref context_die
;
10979 dw_die_ref type_die
;
10982 if (TREE_ASM_WRITTEN (decl
))
10985 TREE_ASM_WRITTEN (decl
) = 1;
10986 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
10987 origin
= decl_ultimate_origin (decl
);
10988 if (origin
!= NULL
)
10989 add_abstract_origin_attribute (type_die
, origin
);
10994 add_name_and_src_coords_attributes (type_die
, decl
);
10995 if (DECL_ORIGINAL_TYPE (decl
))
10997 type
= DECL_ORIGINAL_TYPE (decl
);
10999 if (type
== TREE_TYPE (decl
))
11002 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11005 type
= TREE_TYPE (decl
);
11007 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11008 TREE_THIS_VOLATILE (decl
), context_die
);
11011 if (DECL_ABSTRACT (decl
))
11012 equate_decl_number_to_die (decl
, type_die
);
11015 /* Generate a type description DIE. */
11018 gen_type_die (type
, context_die
)
11020 dw_die_ref context_die
;
11024 if (type
== NULL_TREE
|| type
== error_mark_node
)
11027 /* We are going to output a DIE to represent the unqualified version
11028 of this type (i.e. without any const or volatile qualifiers) so
11029 get the main variant (i.e. the unqualified version) of this type
11030 now. (Vectors are special because the debugging info is in the
11031 cloned type itself). */
11032 if (TREE_CODE (type
) != VECTOR_TYPE
)
11033 type
= type_main_variant (type
);
11035 if (TREE_ASM_WRITTEN (type
))
11038 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11039 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11041 /* Prevent broken recursion; we can't hand off to the same type. */
11042 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11045 TREE_ASM_WRITTEN (type
) = 1;
11046 gen_decl_die (TYPE_NAME (type
), context_die
);
11050 switch (TREE_CODE (type
))
11056 case REFERENCE_TYPE
:
11057 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11058 ensures that the gen_type_die recursion will terminate even if the
11059 type is recursive. Recursive types are possible in Ada. */
11060 /* ??? We could perhaps do this for all types before the switch
11062 TREE_ASM_WRITTEN (type
) = 1;
11064 /* For these types, all that is required is that we output a DIE (or a
11065 set of DIEs) to represent the "basis" type. */
11066 gen_type_die (TREE_TYPE (type
), context_die
);
11070 /* This code is used for C++ pointer-to-data-member types.
11071 Output a description of the relevant class type. */
11072 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11074 /* Output a description of the type of the object pointed to. */
11075 gen_type_die (TREE_TYPE (type
), context_die
);
11077 /* Now output a DIE to represent this pointer-to-data-member type
11079 gen_ptr_to_mbr_type_die (type
, context_die
);
11083 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11084 gen_set_type_die (type
, context_die
);
11088 gen_type_die (TREE_TYPE (type
), context_die
);
11089 abort (); /* No way to represent these in Dwarf yet! */
11092 case FUNCTION_TYPE
:
11093 /* Force out return type (in case it wasn't forced out already). */
11094 gen_type_die (TREE_TYPE (type
), context_die
);
11095 gen_subroutine_type_die (type
, context_die
);
11099 /* Force out return type (in case it wasn't forced out already). */
11100 gen_type_die (TREE_TYPE (type
), context_die
);
11101 gen_subroutine_type_die (type
, context_die
);
11105 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11107 gen_type_die (TREE_TYPE (type
), context_die
);
11108 gen_string_type_die (type
, context_die
);
11111 gen_array_type_die (type
, context_die
);
11115 gen_array_type_die (type
, context_die
);
11118 case ENUMERAL_TYPE
:
11121 case QUAL_UNION_TYPE
:
11122 /* If this is a nested type whose containing class hasn't been written
11123 out yet, writing it out will cover this one, too. This does not apply
11124 to instantiations of member class templates; they need to be added to
11125 the containing class as they are generated. FIXME: This hurts the
11126 idea of combining type decls from multiple TUs, since we can't predict
11127 what set of template instantiations we'll get. */
11128 if (TYPE_CONTEXT (type
)
11129 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11130 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11132 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11134 if (TREE_ASM_WRITTEN (type
))
11137 /* If that failed, attach ourselves to the stub. */
11138 push_decl_scope (TYPE_CONTEXT (type
));
11139 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11145 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11146 gen_enumeration_type_die (type
, context_die
);
11148 gen_struct_or_union_type_die (type
, context_die
);
11153 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11154 it up if it is ever completed. gen_*_type_die will set it for us
11155 when appropriate. */
11164 /* No DIEs needed for fundamental types. */
11168 /* No Dwarf representation currently defined. */
11175 TREE_ASM_WRITTEN (type
) = 1;
11178 /* Generate a DIE for a tagged type instantiation. */
11181 gen_tagged_type_instantiation_die (type
, context_die
)
11183 dw_die_ref context_die
;
11185 if (type
== NULL_TREE
|| type
== error_mark_node
)
11188 /* We are going to output a DIE to represent the unqualified version of
11189 this type (i.e. without any const or volatile qualifiers) so make sure
11190 that we have the main variant (i.e. the unqualified version) of this
11192 if (type
!= type_main_variant (type
))
11195 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11196 an instance of an unresolved type. */
11198 switch (TREE_CODE (type
))
11203 case ENUMERAL_TYPE
:
11204 gen_inlined_enumeration_type_die (type
, context_die
);
11208 gen_inlined_structure_type_die (type
, context_die
);
11212 case QUAL_UNION_TYPE
:
11213 gen_inlined_union_type_die (type
, context_die
);
11221 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11222 things which are local to the given block. */
11225 gen_block_die (stmt
, context_die
, depth
)
11227 dw_die_ref context_die
;
11230 int must_output_die
= 0;
11233 enum tree_code origin_code
;
11235 /* Ignore blocks never really used to make RTL. */
11236 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11237 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11240 /* If the block is one fragment of a non-contiguous block, do not
11241 process the variables, since they will have been done by the
11242 origin block. Do process subblocks. */
11243 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11247 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11248 gen_block_die (sub
, context_die
, depth
+ 1);
11253 /* Determine the "ultimate origin" of this block. This block may be an
11254 inlined instance of an inlined instance of inline function, so we have
11255 to trace all of the way back through the origin chain to find out what
11256 sort of node actually served as the original seed for the creation of
11257 the current block. */
11258 origin
= block_ultimate_origin (stmt
);
11259 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11261 /* Determine if we need to output any Dwarf DIEs at all to represent this
11263 if (origin_code
== FUNCTION_DECL
)
11264 /* The outer scopes for inlinings *must* always be represented. We
11265 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11266 must_output_die
= 1;
11269 /* In the case where the current block represents an inlining of the
11270 "body block" of an inline function, we must *NOT* output any DIE for
11271 this block because we have already output a DIE to represent the whole
11272 inlined function scope and the "body block" of any function doesn't
11273 really represent a different scope according to ANSI C rules. So we
11274 check here to make sure that this block does not represent a "body
11275 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11276 if (! is_body_block (origin
? origin
: stmt
))
11278 /* Determine if this block directly contains any "significant"
11279 local declarations which we will need to output DIEs for. */
11280 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11281 /* We are not in terse mode so *any* local declaration counts
11282 as being a "significant" one. */
11283 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11285 /* We are in terse mode, so only local (nested) function
11286 definitions count as "significant" local declarations. */
11287 for (decl
= BLOCK_VARS (stmt
);
11288 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11289 if (TREE_CODE (decl
) == FUNCTION_DECL
11290 && DECL_INITIAL (decl
))
11292 must_output_die
= 1;
11298 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11299 DIE for any block which contains no significant local declarations at
11300 all. Rather, in such cases we just call `decls_for_scope' so that any
11301 needed Dwarf info for any sub-blocks will get properly generated. Note
11302 that in terse mode, our definition of what constitutes a "significant"
11303 local declaration gets restricted to include only inlined function
11304 instances and local (nested) function definitions. */
11305 if (must_output_die
)
11307 if (origin_code
== FUNCTION_DECL
)
11308 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11310 gen_lexical_block_die (stmt
, context_die
, depth
);
11313 decls_for_scope (stmt
, context_die
, depth
);
11316 /* Generate all of the decls declared within a given scope and (recursively)
11317 all of its sub-blocks. */
11320 decls_for_scope (stmt
, context_die
, depth
)
11322 dw_die_ref context_die
;
11328 /* Ignore blocks never really used to make RTL. */
11329 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11332 /* Output the DIEs to represent all of the data objects and typedefs
11333 declared directly within this block but not within any nested
11334 sub-blocks. Also, nested function and tag DIEs have been
11335 generated with a parent of NULL; fix that up now. */
11336 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11340 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11341 die
= lookup_decl_die (decl
);
11342 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11343 die
= lookup_type_die (TREE_TYPE (decl
));
11347 if (die
!= NULL
&& die
->die_parent
== NULL
)
11348 add_child_die (context_die
, die
);
11350 gen_decl_die (decl
, context_die
);
11353 /* Output the DIEs to represent all sub-blocks (and the items declared
11354 therein) of this block. */
11355 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11357 subblocks
= BLOCK_CHAIN (subblocks
))
11358 gen_block_die (subblocks
, context_die
, depth
+ 1);
11361 /* Is this a typedef we can avoid emitting? */
11364 is_redundant_typedef (decl
)
11367 if (TYPE_DECL_IS_STUB (decl
))
11370 if (DECL_ARTIFICIAL (decl
)
11371 && DECL_CONTEXT (decl
)
11372 && is_tagged_type (DECL_CONTEXT (decl
))
11373 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11374 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11375 /* Also ignore the artificial member typedef for the class name. */
11381 /* Generate Dwarf debug information for a decl described by DECL. */
11384 gen_decl_die (decl
, context_die
)
11386 dw_die_ref context_die
;
11390 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11393 switch (TREE_CODE (decl
))
11399 /* The individual enumerators of an enum type get output when we output
11400 the Dwarf representation of the relevant enum type itself. */
11403 case FUNCTION_DECL
:
11404 /* Don't output any DIEs to represent mere function declarations,
11405 unless they are class members or explicit block externs. */
11406 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11407 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11410 /* If we're emitting a clone, emit info for the abstract instance. */
11411 if (DECL_ORIGIN (decl
) != decl
)
11412 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11414 /* If we're emitting an out-of-line copy of an inline function,
11415 emit info for the abstract instance and set up to refer to it. */
11416 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11417 && ! class_scope_p (context_die
)
11418 /* dwarf2out_abstract_function won't emit a die if this is just
11419 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11420 that case, because that works only if we have a die. */
11421 && DECL_INITIAL (decl
) != NULL_TREE
)
11423 dwarf2out_abstract_function (decl
);
11424 set_decl_origin_self (decl
);
11427 /* Otherwise we're emitting the primary DIE for this decl. */
11428 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11430 /* Before we describe the FUNCTION_DECL itself, make sure that we
11431 have described its return type. */
11432 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11434 /* And its virtual context. */
11435 if (DECL_VINDEX (decl
) != NULL_TREE
)
11436 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11438 /* And its containing type. */
11439 origin
= decl_class_context (decl
);
11440 if (origin
!= NULL_TREE
)
11441 gen_type_die_for_member (origin
, decl
, context_die
);
11444 /* Now output a DIE to represent the function itself. */
11445 gen_subprogram_die (decl
, context_die
);
11449 /* If we are in terse mode, don't generate any DIEs to represent any
11450 actual typedefs. */
11451 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11454 /* In the special case of a TYPE_DECL node representing the declaration
11455 of some type tag, if the given TYPE_DECL is marked as having been
11456 instantiated from some other (original) TYPE_DECL node (e.g. one which
11457 was generated within the original definition of an inline function) we
11458 have to generate a special (abbreviated) DW_TAG_structure_type,
11459 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11460 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11462 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11466 if (is_redundant_typedef (decl
))
11467 gen_type_die (TREE_TYPE (decl
), context_die
);
11469 /* Output a DIE to represent the typedef itself. */
11470 gen_typedef_die (decl
, context_die
);
11474 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11475 gen_label_die (decl
, context_die
);
11479 /* If we are in terse mode, don't generate any DIEs to represent any
11480 variable declarations or definitions. */
11481 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11484 /* Output any DIEs that are needed to specify the type of this data
11486 gen_type_die (TREE_TYPE (decl
), context_die
);
11488 /* And its containing type. */
11489 origin
= decl_class_context (decl
);
11490 if (origin
!= NULL_TREE
)
11491 gen_type_die_for_member (origin
, decl
, context_die
);
11493 /* Now output the DIE to represent the data object itself. This gets
11494 complicated because of the possibility that the VAR_DECL really
11495 represents an inlined instance of a formal parameter for an inline
11497 origin
= decl_ultimate_origin (decl
);
11498 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11499 gen_formal_parameter_die (decl
, context_die
);
11501 gen_variable_die (decl
, context_die
);
11505 /* Ignore the nameless fields that are used to skip bits but handle C++
11506 anonymous unions. */
11507 if (DECL_NAME (decl
) != NULL_TREE
11508 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11510 gen_type_die (member_declared_type (decl
), context_die
);
11511 gen_field_die (decl
, context_die
);
11516 gen_type_die (TREE_TYPE (decl
), context_die
);
11517 gen_formal_parameter_die (decl
, context_die
);
11520 case NAMESPACE_DECL
:
11521 /* Ignore for now. */
11530 mark_limbo_die_list (ptr
)
11531 void *ptr ATTRIBUTE_UNUSED
;
11533 limbo_die_node
*node
;
11534 for (node
= limbo_die_list
; node
; node
= node
->next
)
11535 ggc_mark_tree (node
->created_for
);
11538 /* Add Ada "use" clause information for SGI Workshop debugger. */
11541 dwarf2out_add_library_unit_info (filename
, context_list
)
11542 const char *filename
;
11543 const char *context_list
;
11545 unsigned int file_index
;
11547 if (filename
!= NULL
)
11549 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11550 tree context_list_decl
11551 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11554 TREE_PUBLIC (context_list_decl
) = TRUE
;
11555 add_name_attribute (unit_die
, context_list
);
11556 file_index
= lookup_filename (filename
);
11557 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11558 add_pubname (context_list_decl
, unit_die
);
11562 /* Output debug information for global decl DECL. Called from toplev.c after
11563 compilation proper has finished. */
11566 dwarf2out_global_decl (decl
)
11569 /* Output DWARF2 information for file-scope tentative data object
11570 declarations, file-scope (extern) function declarations (which had no
11571 corresponding body) and file-scope tagged type declarations and
11572 definitions which have not yet been forced out. */
11573 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11574 dwarf2out_decl (decl
);
11577 /* Write the debugging output for DECL. */
11580 dwarf2out_decl (decl
)
11583 dw_die_ref context_die
= comp_unit_die
;
11585 switch (TREE_CODE (decl
))
11590 case FUNCTION_DECL
:
11591 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11592 builtin function. Explicit programmer-supplied declarations of
11593 these same functions should NOT be ignored however. */
11594 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11597 /* What we would really like to do here is to filter out all mere
11598 file-scope declarations of file-scope functions which are never
11599 referenced later within this translation unit (and keep all of ones
11600 that *are* referenced later on) but we aren't clairvoyant, so we have
11601 no idea which functions will be referenced in the future (i.e. later
11602 on within the current translation unit). So here we just ignore all
11603 file-scope function declarations which are not also definitions. If
11604 and when the debugger needs to know something about these functions,
11605 it will have to hunt around and find the DWARF information associated
11606 with the definition of the function.
11608 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11609 nodes represent definitions and which ones represent mere
11610 declarations. We have to check DECL_INITIAL instead. That's because
11611 the C front-end supports some weird semantics for "extern inline"
11612 function definitions. These can get inlined within the current
11613 translation unit (an thus, we need to generate Dwarf info for their
11614 abstract instances so that the Dwarf info for the concrete inlined
11615 instances can have something to refer to) but the compiler never
11616 generates any out-of-lines instances of such things (despite the fact
11617 that they *are* definitions).
11619 The important point is that the C front-end marks these "extern
11620 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11621 them anyway. Note that the C++ front-end also plays some similar games
11622 for inline function definitions appearing within include files which
11623 also contain `#pragma interface' pragmas. */
11624 if (DECL_INITIAL (decl
) == NULL_TREE
)
11627 /* If we're a nested function, initially use a parent of NULL; if we're
11628 a plain function, this will be fixed up in decls_for_scope. If
11629 we're a method, it will be ignored, since we already have a DIE. */
11630 if (decl_function_context (decl
))
11631 context_die
= NULL
;
11635 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11636 declaration and if the declaration was never even referenced from
11637 within this entire compilation unit. We suppress these DIEs in
11638 order to save space in the .debug section (by eliminating entries
11639 which are probably useless). Note that we must not suppress
11640 block-local extern declarations (whether used or not) because that
11641 would screw-up the debugger's name lookup mechanism and cause it to
11642 miss things which really ought to be in scope at a given point. */
11643 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11646 /* If we are in terse mode, don't generate any DIEs to represent any
11647 variable declarations or definitions. */
11648 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11653 /* Don't emit stubs for types unless they are needed by other DIEs. */
11654 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
11657 /* Don't bother trying to generate any DIEs to represent any of the
11658 normal built-in types for the language we are compiling. */
11659 if (DECL_SOURCE_LINE (decl
) == 0)
11661 /* OK, we need to generate one for `bool' so GDB knows what type
11662 comparisons have. */
11663 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
11664 == DW_LANG_C_plus_plus
)
11665 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
11666 && ! DECL_IGNORED_P (decl
))
11667 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
11672 /* If we are in terse mode, don't generate any DIEs for types. */
11673 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11676 /* If we're a function-scope tag, initially use a parent of NULL;
11677 this will be fixed up in decls_for_scope. */
11678 if (decl_function_context (decl
))
11679 context_die
= NULL
;
11687 gen_decl_die (decl
, context_die
);
11690 /* Output a marker (i.e. a label) for the beginning of the generated code for
11691 a lexical block. */
11694 dwarf2out_begin_block (line
, blocknum
)
11695 unsigned int line ATTRIBUTE_UNUSED
;
11696 unsigned int blocknum
;
11698 function_section (current_function_decl
);
11699 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
11702 /* Output a marker (i.e. a label) for the end of the generated code for a
11706 dwarf2out_end_block (line
, blocknum
)
11707 unsigned int line ATTRIBUTE_UNUSED
;
11708 unsigned int blocknum
;
11710 function_section (current_function_decl
);
11711 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
11714 /* Returns nonzero if it is appropriate not to emit any debugging
11715 information for BLOCK, because it doesn't contain any instructions.
11717 Don't allow this for blocks with nested functions or local classes
11718 as we would end up with orphans, and in the presence of scheduling
11719 we may end up calling them anyway. */
11722 dwarf2out_ignore_block (block
)
11727 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
11728 if (TREE_CODE (decl
) == FUNCTION_DECL
11729 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
11735 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11736 dwarf2out.c) and return its "index". The index of each (known) filename is
11737 just a unique number which is associated with only that one filename. We
11738 need such numbers for the sake of generating labels (in the .debug_sfnames
11739 section) and references to those files numbers (in the .debug_srcinfo
11740 and.debug_macinfo sections). If the filename given as an argument is not
11741 found in our current list, add it to the list and assign it the next
11742 available unique index number. In order to speed up searches, we remember
11743 the index of the filename was looked up last. This handles the majority of
11747 lookup_filename (file_name
)
11748 const char *file_name
;
11752 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11753 if (strcmp (file_name
, "<internal>") == 0
11754 || strcmp (file_name
, "<built-in>") == 0)
11757 /* Check to see if the file name that was searched on the previous
11758 call matches this file name. If so, return the index. */
11759 if (file_table
.last_lookup_index
!= 0)
11760 if (0 == strcmp (file_name
,
11761 file_table
.table
[file_table
.last_lookup_index
]))
11762 return file_table
.last_lookup_index
;
11764 /* Didn't match the previous lookup, search the table */
11765 for (i
= 1; i
< file_table
.in_use
; i
++)
11766 if (strcmp (file_name
, file_table
.table
[i
]) == 0)
11768 file_table
.last_lookup_index
= i
;
11772 /* Prepare to add a new table entry by making sure there is enough space in
11773 the table to do so. If not, expand the current table. */
11774 if (i
== file_table
.allocated
)
11776 file_table
.allocated
= i
+ FILE_TABLE_INCREMENT
;
11777 file_table
.table
= (char **)
11778 xrealloc (file_table
.table
, file_table
.allocated
* sizeof (char *));
11781 /* Add the new entry to the end of the filename table. */
11782 file_table
.table
[i
] = xstrdup (file_name
);
11783 file_table
.in_use
= i
+ 1;
11784 file_table
.last_lookup_index
= i
;
11786 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11788 fprintf (asm_out_file
, "\t.file %u ", i
);
11789 output_quoted_string (asm_out_file
, file_name
);
11790 fputc ('\n', asm_out_file
);
11799 /* Allocate the initial hunk of the file_table. */
11800 file_table
.table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
11801 file_table
.allocated
= FILE_TABLE_INCREMENT
;
11803 /* Skip the first entry - file numbers begin at 1. */
11804 file_table
.in_use
= 1;
11805 file_table
.last_lookup_index
= 0;
11808 /* Output a label to mark the beginning of a source code line entry
11809 and record information relating to this source line, in
11810 'line_info_table' for later output of the .debug_line section. */
11813 dwarf2out_source_line (line
, filename
)
11815 const char *filename
;
11817 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11819 function_section (current_function_decl
);
11821 /* If requested, emit something human-readable. */
11822 if (flag_debug_asm
)
11823 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
11826 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11828 unsigned file_num
= lookup_filename (filename
);
11830 /* Emit the .loc directive understood by GNU as. */
11831 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
11833 /* Indicate that line number info exists. */
11834 line_info_table_in_use
++;
11836 /* Indicate that multiple line number tables exist. */
11837 if (DECL_SECTION_NAME (current_function_decl
))
11838 separate_line_info_table_in_use
++;
11840 else if (DECL_SECTION_NAME (current_function_decl
))
11842 dw_separate_line_info_ref line_info
;
11843 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
11844 separate_line_info_table_in_use
);
11846 /* expand the line info table if necessary */
11847 if (separate_line_info_table_in_use
11848 == separate_line_info_table_allocated
)
11850 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11851 separate_line_info_table
11852 = (dw_separate_line_info_ref
)
11853 xrealloc (separate_line_info_table
,
11854 separate_line_info_table_allocated
11855 * sizeof (dw_separate_line_info_entry
));
11858 /* Add the new entry at the end of the line_info_table. */
11860 = &separate_line_info_table
[separate_line_info_table_in_use
++];
11861 line_info
->dw_file_num
= lookup_filename (filename
);
11862 line_info
->dw_line_num
= line
;
11863 line_info
->function
= current_function_funcdef_no
;
11867 dw_line_info_ref line_info
;
11869 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
11870 line_info_table_in_use
);
11872 /* Expand the line info table if necessary. */
11873 if (line_info_table_in_use
== line_info_table_allocated
)
11875 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11877 = (dw_line_info_ref
)
11878 xrealloc (line_info_table
,
11879 (line_info_table_allocated
11880 * sizeof (dw_line_info_entry
)));
11883 /* Add the new entry at the end of the line_info_table. */
11884 line_info
= &line_info_table
[line_info_table_in_use
++];
11885 line_info
->dw_file_num
= lookup_filename (filename
);
11886 line_info
->dw_line_num
= line
;
11891 /* Record the beginning of a new source file. */
11894 dwarf2out_start_source_file (lineno
, filename
)
11895 unsigned int lineno
;
11896 const char *filename
;
11898 if (flag_eliminate_dwarf2_dups
)
11900 /* Record the beginning of the file for break_out_includes. */
11901 dw_die_ref bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
11902 add_AT_string (bincl_die
, DW_AT_name
, filename
);
11905 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11907 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11908 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
11909 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
11911 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
11912 "Filename we just started");
11916 /* Record the end of a source file. */
11919 dwarf2out_end_source_file (lineno
)
11920 unsigned int lineno ATTRIBUTE_UNUSED
;
11922 if (flag_eliminate_dwarf2_dups
)
11923 /* Record the end of the file for break_out_includes. */
11924 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
11926 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11928 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11929 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
11933 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11934 the tail part of the directive line, i.e. the part which is past the
11935 initial whitespace, #, whitespace, directive-name, whitespace part. */
11938 dwarf2out_define (lineno
, buffer
)
11939 unsigned lineno ATTRIBUTE_UNUSED
;
11940 const char *buffer ATTRIBUTE_UNUSED
;
11942 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11944 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11945 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
11946 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11947 dw2_asm_output_nstring (buffer
, -1, "The macro");
11951 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11952 the tail part of the directive line, i.e. the part which is past the
11953 initial whitespace, #, whitespace, directive-name, whitespace part. */
11956 dwarf2out_undef (lineno
, buffer
)
11957 unsigned lineno ATTRIBUTE_UNUSED
;
11958 const char *buffer ATTRIBUTE_UNUSED
;
11960 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11962 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11963 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
11964 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11965 dw2_asm_output_nstring (buffer
, -1, "The macro");
11969 /* Set up for Dwarf output at the start of compilation. */
11972 dwarf2out_init (main_input_filename
)
11973 const char *main_input_filename
;
11975 init_file_table ();
11977 /* Remember the name of the primary input file. */
11978 primary_filename
= main_input_filename
;
11980 /* Add it to the file table first, under the assumption that we'll
11981 be emitting line number data for it first, which avoids having
11982 to add an initial DW_LNS_set_file. */
11983 lookup_filename (main_input_filename
);
11985 /* Allocate the initial hunk of the decl_die_table. */
11987 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
11988 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
11989 decl_die_table_in_use
= 0;
11991 /* Allocate the initial hunk of the decl_scope_table. */
11992 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
11994 /* Allocate the initial hunk of the abbrev_die_table. */
11996 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
11997 sizeof (dw_die_ref
));
11998 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
11999 /* Zero-th entry is allocated, but unused */
12000 abbrev_die_table_in_use
= 1;
12002 /* Allocate the initial hunk of the line_info_table. */
12004 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
12005 sizeof (dw_line_info_entry
));
12006 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12008 /* Zero-th entry is allocated, but unused */
12009 line_info_table_in_use
= 1;
12011 /* Generate the initial DIE for the .debug section. Note that the (string)
12012 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12013 will (typically) be a relative pathname and that this pathname should be
12014 taken as being relative to the directory from which the compiler was
12015 invoked when the given (base) source file was compiled. */
12016 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
12018 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12020 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12022 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
12024 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12025 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12026 DEBUG_ABBREV_SECTION_LABEL
, 0);
12027 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12028 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12030 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12032 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12033 DEBUG_INFO_SECTION_LABEL
, 0);
12034 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12035 DEBUG_LINE_SECTION_LABEL
, 0);
12036 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12037 DEBUG_RANGES_SECTION_LABEL
, 0);
12038 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12039 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12040 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12041 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12042 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12043 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12045 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12047 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12048 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12049 DEBUG_MACINFO_SECTION_LABEL
, 0);
12050 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12053 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12056 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12060 /* Allocate a string in .debug_str hash table. */
12063 indirect_string_alloc (tab
)
12064 hash_table
*tab ATTRIBUTE_UNUSED
;
12066 struct indirect_string_node
*node
;
12068 node
= xmalloc (sizeof (struct indirect_string_node
));
12069 node
->refcount
= 0;
12071 node
->label
= NULL
;
12073 return (hashnode
) node
;
12076 /* A helper function for dwarf2out_finish called through
12077 ht_forall. Emit one queued .debug_str string. */
12080 output_indirect_string (pfile
, h
, v
)
12081 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12083 const PTR v ATTRIBUTE_UNUSED
;
12085 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12087 if (node
->form
== DW_FORM_strp
)
12089 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12090 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12091 assemble_string ((const char *) HT_STR (&node
->id
),
12092 HT_LEN (&node
->id
) + 1);
12098 /* Output stuff that dwarf requires at the end of every file,
12099 and generate the DWARF-2 debugging info. */
12102 dwarf2out_finish (input_filename
)
12103 const char *input_filename ATTRIBUTE_UNUSED
;
12105 limbo_die_node
*node
, *next_node
;
12106 dw_die_ref die
= 0;
12108 /* Traverse the limbo die list, and add parent/child links. The only
12109 dies without parents that should be here are concrete instances of
12110 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12111 For concrete instances, we can get the parent die from the abstract
12113 for (node
= limbo_die_list
; node
; node
= next_node
)
12115 next_node
= node
->next
;
12118 if (die
->die_parent
== NULL
)
12120 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12124 add_child_die (origin
->die_parent
, die
);
12125 else if (die
== comp_unit_die
)
12127 /* If this was an expression for a bound involved in a function
12128 return type, it may be a SAVE_EXPR for which we weren't able
12129 to find a DIE previously. So try now. */
12130 else if (node
->created_for
12131 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12132 && 0 != (origin
= (lookup_decl_die
12134 (node
->created_for
)))))
12135 add_child_die (origin
, die
);
12136 else if (errorcount
> 0 || sorrycount
> 0)
12137 /* It's OK to be confused by errors in the input. */
12138 add_child_die (comp_unit_die
, die
);
12139 else if (node
->created_for
12140 && ((DECL_P (node
->created_for
)
12141 && (context
= DECL_CONTEXT (node
->created_for
)))
12142 || (TYPE_P (node
->created_for
)
12143 && (context
= TYPE_CONTEXT (node
->created_for
))))
12144 && TREE_CODE (context
) == FUNCTION_DECL
)
12146 /* In certain situations, the lexical block containing a
12147 nested function can be optimized away, which results
12148 in the nested function die being orphaned. Likewise
12149 with the return type of that nested function. Force
12150 this to be a child of the containing function. */
12151 origin
= lookup_decl_die (context
);
12154 add_child_die (origin
, die
);
12163 limbo_die_list
= NULL
;
12165 /* Walk through the list of incomplete types again, trying once more to
12166 emit full debugging info for them. */
12167 retry_incomplete_types ();
12169 /* We need to reverse all the dies before break_out_includes, or
12170 we'll see the end of an include file before the beginning. */
12171 reverse_all_dies (comp_unit_die
);
12173 /* Generate separate CUs for each of the include files we've seen.
12174 They will go into limbo_die_list. */
12175 if (flag_eliminate_dwarf2_dups
)
12176 break_out_includes (comp_unit_die
);
12178 /* Traverse the DIE's and add add sibling attributes to those DIE's
12179 that have children. */
12180 add_sibling_attributes (comp_unit_die
);
12181 for (node
= limbo_die_list
; node
; node
= node
->next
)
12182 add_sibling_attributes (node
->die
);
12184 /* Output a terminator label for the .text section. */
12186 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
12188 /* Output the source line correspondence table. We must do this
12189 even if there is no line information. Otherwise, on an empty
12190 translation unit, we will generate a present, but empty,
12191 .debug_info section. IRIX 6.5 `nm' will then complain when
12192 examining the file. */
12193 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12195 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12196 output_line_info ();
12199 /* Output location list section if necessary. */
12200 if (have_location_lists
)
12202 /* Output the location lists info. */
12203 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12204 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12205 DEBUG_LOC_SECTION_LABEL
, 0);
12206 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12207 output_location_lists (die
);
12208 have_location_lists
= 0;
12211 /* We can only use the low/high_pc attributes if all of the code was
12213 if (separate_line_info_table_in_use
== 0)
12215 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12216 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12219 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12220 "base address". Use zero so that these addresses become absolute. */
12221 else if (have_location_lists
|| ranges_table_in_use
)
12222 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12224 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12225 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12226 debug_line_section_label
);
12228 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12229 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12231 /* Output all of the compilation units. We put the main one last so that
12232 the offsets are available to output_pubnames. */
12233 for (node
= limbo_die_list
; node
; node
= node
->next
)
12234 output_comp_unit (node
->die
);
12236 output_comp_unit (comp_unit_die
);
12238 /* Output the abbreviation table. */
12239 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12240 output_abbrev_section ();
12242 /* Output public names table if necessary. */
12243 if (pubname_table_in_use
)
12245 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12246 output_pubnames ();
12249 /* Output the address range information. We only put functions in the arange
12250 table, so don't write it out if we don't have any. */
12251 if (fde_table_in_use
)
12253 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12257 /* Output ranges section if necessary. */
12258 if (ranges_table_in_use
)
12260 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12261 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12265 /* Have to end the primary source file. */
12266 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12268 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12269 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12270 dw2_asm_output_data (1, 0, "End compilation unit");
12273 /* If we emitted any DW_FORM_strp form attribute, output the string
12275 if (debug_str_hash
)
12276 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12280 /* This should never be used, but its address is needed for comparisons. */
12281 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12283 #endif /* DWARF2_DEBUGGING_INFO */
12285 #include "gt-dwarf2out.h"