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
42 #include "hard-reg-set.h"
44 #include "insn-config.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
59 #include "diagnostic.h"
62 #include "langhooks.h"
63 #include "hashtable.h"
65 #ifdef DWARF2_DEBUGGING_INFO
66 static void dwarf2out_source_line
PARAMS ((unsigned int, const char *));
69 /* DWARF2 Abbreviation Glossary:
70 CFA = Canonical Frame Address
71 a fixed address on the stack which identifies a call frame.
72 We define it to be the value of SP just before the call insn.
73 The CFA register and offset, which may change during the course
74 of the function, are used to calculate its value at runtime.
75 CFI = Call Frame Instruction
76 an instruction for the DWARF2 abstract machine
77 CIE = Common Information Entry
78 information describing information common to one or more FDEs
79 DIE = Debugging Information Entry
80 FDE = Frame Description Entry
81 information describing the stack call frame, in particular,
82 how to restore registers
84 DW_CFA_... = DWARF2 CFA call frame instruction
85 DW_TAG_... = DWARF2 DIE tag */
87 /* Decide whether we want to emit frame unwind information for the current
93 return (write_symbols
== DWARF2_DEBUG
94 || write_symbols
== VMS_AND_DWARF2_DEBUG
95 #ifdef DWARF2_FRAME_INFO
98 #ifdef DWARF2_UNWIND_INFO
100 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
105 /* The number of the current function definition for which debugging
106 information is being generated. These numbers range from 1 up to the
107 maximum number of function definitions contained within the current
108 compilation unit. These numbers are used to create unique label id's
109 unique to each function definition. */
110 unsigned current_funcdef_number
= 0;
112 /* The size of the target's pointer type. */
114 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
117 /* Default version of targetm.eh_frame_section. Note this must appear
118 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
122 default_eh_frame_section ()
124 #ifdef EH_FRAME_SECTION_NAME
125 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
127 tree label
= get_file_function_name ('F');
130 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
131 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
132 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
136 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
138 /* How to start an assembler comment. */
139 #ifndef ASM_COMMENT_START
140 #define ASM_COMMENT_START ";#"
143 typedef struct dw_cfi_struct
*dw_cfi_ref
;
144 typedef struct dw_fde_struct
*dw_fde_ref
;
145 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
147 /* Call frames are described using a sequence of Call Frame
148 Information instructions. The register number, offset
149 and address fields are provided as possible operands;
150 their use is selected by the opcode field. */
152 typedef union dw_cfi_oprnd_struct
154 unsigned long dw_cfi_reg_num
;
155 long int dw_cfi_offset
;
156 const char *dw_cfi_addr
;
157 struct dw_loc_descr_struct
*dw_cfi_loc
;
161 typedef struct dw_cfi_struct
163 dw_cfi_ref dw_cfi_next
;
164 enum dwarf_call_frame_info dw_cfi_opc
;
165 dw_cfi_oprnd dw_cfi_oprnd1
;
166 dw_cfi_oprnd dw_cfi_oprnd2
;
170 /* This is how we define the location of the CFA. We use to handle it
171 as REG + OFFSET all the time, but now it can be more complex.
172 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
173 Instead of passing around REG and OFFSET, we pass a copy
174 of this structure. */
175 typedef struct cfa_loc
180 int indirect
; /* 1 if CFA is accessed via a dereference. */
183 /* All call frame descriptions (FDE's) in the GCC generated DWARF
184 refer to a single Common Information Entry (CIE), defined at
185 the beginning of the .debug_frame section. This use of a single
186 CIE obviates the need to keep track of multiple CIE's
187 in the DWARF generation routines below. */
189 typedef struct dw_fde_struct
191 const char *dw_fde_begin
;
192 const char *dw_fde_current_label
;
193 const char *dw_fde_end
;
194 dw_cfi_ref dw_fde_cfi
;
195 unsigned funcdef_number
;
196 unsigned nothrow
: 1;
197 unsigned uses_eh_lsda
: 1;
201 /* Maximum size (in bytes) of an artificially generated label. */
202 #define MAX_ARTIFICIAL_LABEL_BYTES 30
204 /* The size of addresses as they appear in the Dwarf 2 data.
205 Some architectures use word addresses to refer to code locations,
206 but Dwarf 2 info always uses byte addresses. On such machines,
207 Dwarf 2 addresses need to be larger than the architecture's
209 #ifndef DWARF2_ADDR_SIZE
210 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
213 /* The size in bytes of a DWARF field indicating an offset or length
214 relative to a debug info section, specified to be 4 bytes in the
215 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
218 #ifndef DWARF_OFFSET_SIZE
219 #define DWARF_OFFSET_SIZE 4
222 #define DWARF_VERSION 2
224 /* Round SIZE up to the nearest BOUNDARY. */
225 #define DWARF_ROUND(SIZE,BOUNDARY) \
226 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
228 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
229 #ifndef DWARF_CIE_DATA_ALIGNMENT
230 #ifdef STACK_GROWS_DOWNWARD
231 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
233 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
237 /* A pointer to the base of a table that contains frame description
238 information for each routine. */
239 static dw_fde_ref fde_table
;
241 /* Number of elements currently allocated for fde_table. */
242 static unsigned fde_table_allocated
;
244 /* Number of elements in fde_table currently in use. */
245 static unsigned fde_table_in_use
;
247 /* Size (in elements) of increments by which we may expand the
249 #define FDE_TABLE_INCREMENT 256
251 /* A list of call frame insns for the CIE. */
252 static dw_cfi_ref cie_cfi_head
;
254 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
255 attribute that accelerates the lookup of the FDE associated
256 with the subprogram. This variable holds the table index of the FDE
257 associated with the current function (body) definition. */
258 static unsigned current_funcdef_fde
;
260 struct ht
*debug_str_hash
;
262 struct indirect_string_node
264 struct ht_identifier id
;
265 unsigned int refcount
;
270 /* Forward declarations for functions defined in this file. */
272 static char *stripattributes
PARAMS ((const char *));
273 static const char *dwarf_cfi_name
PARAMS ((unsigned));
274 static dw_cfi_ref new_cfi
PARAMS ((void));
275 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
276 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
277 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
,
279 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
280 static void reg_save
PARAMS ((const char *, unsigned,
282 static void initial_return_save
PARAMS ((rtx
));
283 static long stack_adjust_offset
PARAMS ((rtx
));
284 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
, int));
285 static void output_call_frame_info
PARAMS ((int));
286 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
287 static void queue_reg_save
PARAMS ((const char *, rtx
, long));
288 static void flush_queued_reg_saves
PARAMS ((void));
289 static bool clobbers_queued_reg_save
PARAMS ((rtx
));
290 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
292 /* Support for complex CFA locations. */
293 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
294 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
295 struct dw_loc_descr_struct
*));
296 static struct dw_loc_descr_struct
*build_cfa_loc
297 PARAMS ((dw_cfa_location
*));
298 static void def_cfa_1
PARAMS ((const char *,
301 /* How to start an assembler comment. */
302 #ifndef ASM_COMMENT_START
303 #define ASM_COMMENT_START ";#"
306 /* Data and reference forms for relocatable data. */
307 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
308 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
310 /* Pseudo-op for defining a new section. */
311 #ifndef SECTION_ASM_OP
312 #define SECTION_ASM_OP "\t.section\t"
315 #ifndef DEBUG_FRAME_SECTION
316 #define DEBUG_FRAME_SECTION ".debug_frame"
319 #ifndef FUNC_BEGIN_LABEL
320 #define FUNC_BEGIN_LABEL "LFB"
323 #ifndef FUNC_END_LABEL
324 #define FUNC_END_LABEL "LFE"
327 #define FRAME_BEGIN_LABEL "Lframe"
328 #define CIE_AFTER_SIZE_LABEL "LSCIE"
329 #define CIE_END_LABEL "LECIE"
330 #define CIE_LENGTH_LABEL "LLCIE"
331 #define FDE_LABEL "LSFDE"
332 #define FDE_AFTER_SIZE_LABEL "LASFDE"
333 #define FDE_END_LABEL "LEFDE"
334 #define FDE_LENGTH_LABEL "LLFDE"
335 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
336 #define LINE_NUMBER_END_LABEL "LELT"
337 #define LN_PROLOG_AS_LABEL "LASLTP"
338 #define LN_PROLOG_END_LABEL "LELTP"
339 #define DIE_LABEL_PREFIX "DW"
341 /* Definitions of defaults for various types of primitive assembly language
342 output operations. These may be overridden from within the tm.h file,
343 but typically, that is unnecessary. */
346 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
347 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
349 fprintf (FILE, "%s", SET_ASM_OP); \
350 assemble_name (FILE, SY); \
352 assemble_name (FILE, HI); \
354 assemble_name (FILE, LO); \
359 /* The DWARF 2 CFA column which tracks the return address. Normally this
360 is the column for PC, or the first column after all of the hard
362 #ifndef DWARF_FRAME_RETURN_COLUMN
364 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
366 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
370 /* The mapping from gcc register number to DWARF 2 CFA column number. By
371 default, we just provide columns for all registers. */
372 #ifndef DWARF_FRAME_REGNUM
373 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
376 /* The offset from the incoming value of %sp to the top of the stack frame
377 for the current function. */
378 #ifndef INCOMING_FRAME_SP_OFFSET
379 #define INCOMING_FRAME_SP_OFFSET 0
382 /* Hook used by __throw. */
385 expand_builtin_dwarf_fp_regnum ()
387 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
390 /* Return a pointer to a copy of the section string name S with all
391 attributes stripped off, and an asterisk prepended (for assemble_name). */
397 char *stripped
= xmalloc (strlen (s
) + 2);
402 while (*s
&& *s
!= ',')
409 /* Generate code to initialize the register size table. */
412 expand_builtin_init_dwarf_reg_sizes (address
)
416 enum machine_mode mode
= TYPE_MODE (char_type_node
);
417 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
418 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
420 for (i
= 0; i
< DWARF_FRAME_REGISTERS
; i
++)
422 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
423 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
428 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
432 /* Convert a DWARF call frame info. operation to its string name */
435 dwarf_cfi_name (cfi_opc
)
440 case DW_CFA_advance_loc
:
441 return "DW_CFA_advance_loc";
443 return "DW_CFA_offset";
445 return "DW_CFA_restore";
449 return "DW_CFA_set_loc";
450 case DW_CFA_advance_loc1
:
451 return "DW_CFA_advance_loc1";
452 case DW_CFA_advance_loc2
:
453 return "DW_CFA_advance_loc2";
454 case DW_CFA_advance_loc4
:
455 return "DW_CFA_advance_loc4";
456 case DW_CFA_offset_extended
:
457 return "DW_CFA_offset_extended";
458 case DW_CFA_restore_extended
:
459 return "DW_CFA_restore_extended";
460 case DW_CFA_undefined
:
461 return "DW_CFA_undefined";
462 case DW_CFA_same_value
:
463 return "DW_CFA_same_value";
464 case DW_CFA_register
:
465 return "DW_CFA_register";
466 case DW_CFA_remember_state
:
467 return "DW_CFA_remember_state";
468 case DW_CFA_restore_state
:
469 return "DW_CFA_restore_state";
471 return "DW_CFA_def_cfa";
472 case DW_CFA_def_cfa_register
:
473 return "DW_CFA_def_cfa_register";
474 case DW_CFA_def_cfa_offset
:
475 return "DW_CFA_def_cfa_offset";
478 case DW_CFA_def_cfa_expression
:
479 return "DW_CFA_def_cfa_expression";
480 case DW_CFA_expression
:
481 return "DW_CFA_expression";
482 case DW_CFA_offset_extended_sf
:
483 return "DW_CFA_offset_extended_sf";
484 case DW_CFA_def_cfa_sf
:
485 return "DW_CFA_def_cfa_sf";
486 case DW_CFA_def_cfa_offset_sf
:
487 return "DW_CFA_def_cfa_offset_sf";
489 /* SGI/MIPS specific */
490 case DW_CFA_MIPS_advance_loc8
:
491 return "DW_CFA_MIPS_advance_loc8";
494 case DW_CFA_GNU_window_save
:
495 return "DW_CFA_GNU_window_save";
496 case DW_CFA_GNU_args_size
:
497 return "DW_CFA_GNU_args_size";
498 case DW_CFA_GNU_negative_offset_extended
:
499 return "DW_CFA_GNU_negative_offset_extended";
502 return "DW_CFA_<unknown>";
506 /* Return a pointer to a newly allocated Call Frame Instruction. */
508 static inline dw_cfi_ref
511 dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
513 cfi
->dw_cfi_next
= NULL
;
514 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
515 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
520 /* Add a Call Frame Instruction to list of instructions. */
523 add_cfi (list_head
, cfi
)
524 dw_cfi_ref
*list_head
;
529 /* Find the end of the chain. */
530 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
536 /* Generate a new label for the CFI info to refer to. */
539 dwarf2out_cfi_label ()
541 static char label
[20];
542 static unsigned long label_num
= 0;
544 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
545 ASM_OUTPUT_LABEL (asm_out_file
, label
);
549 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
550 or to the CIE if LABEL is NULL. */
553 add_fde_cfi (label
, cfi
)
559 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
562 label
= dwarf2out_cfi_label ();
564 if (fde
->dw_fde_current_label
== NULL
565 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
569 fde
->dw_fde_current_label
= label
= xstrdup (label
);
571 /* Set the location counter to the new label. */
573 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
574 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
575 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
578 add_cfi (&fde
->dw_fde_cfi
, cfi
);
582 add_cfi (&cie_cfi_head
, cfi
);
585 /* Subroutine of lookup_cfa. */
588 lookup_cfa_1 (cfi
, loc
)
590 dw_cfa_location
*loc
;
592 switch (cfi
->dw_cfi_opc
)
594 case DW_CFA_def_cfa_offset
:
595 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
597 case DW_CFA_def_cfa_register
:
598 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
601 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
602 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
604 case DW_CFA_def_cfa_expression
:
605 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
612 /* Find the previous value for the CFA. */
616 dw_cfa_location
*loc
;
620 loc
->reg
= (unsigned long) -1;
623 loc
->base_offset
= 0;
625 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
626 lookup_cfa_1 (cfi
, loc
);
628 if (fde_table_in_use
)
630 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
631 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
632 lookup_cfa_1 (cfi
, loc
);
636 /* The current rule for calculating the DWARF2 canonical frame address. */
637 static dw_cfa_location cfa
;
639 /* The register used for saving registers to the stack, and its offset
641 static dw_cfa_location cfa_store
;
643 /* The running total of the size of arguments pushed onto the stack. */
644 static long args_size
;
646 /* The last args_size we actually output. */
647 static long old_args_size
;
649 /* Entry point to update the canonical frame address (CFA).
650 LABEL is passed to add_fde_cfi. The value of CFA is now to be
651 calculated from REG+OFFSET. */
654 dwarf2out_def_cfa (label
, reg
, offset
)
664 def_cfa_1 (label
, &loc
);
667 /* This routine does the actual work. The CFA is now calculated from
668 the dw_cfa_location structure. */
671 def_cfa_1 (label
, loc_p
)
673 dw_cfa_location
*loc_p
;
676 dw_cfa_location old_cfa
, loc
;
681 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
682 cfa_store
.offset
= loc
.offset
;
684 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
685 lookup_cfa (&old_cfa
);
687 /* If nothing changed, no need to issue any call frame instructions. */
688 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
689 && loc
.indirect
== old_cfa
.indirect
690 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
695 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
697 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
698 indicating the CFA register did not change but the offset
700 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
701 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
704 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
705 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
708 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
709 indicating the CFA register has changed to <register> but the
710 offset has not changed. */
711 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
712 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
716 else if (loc
.indirect
== 0)
718 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
719 indicating the CFA register has changed to <register> with
720 the specified offset. */
721 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
722 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
723 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
727 /* Construct a DW_CFA_def_cfa_expression instruction to
728 calculate the CFA using a full location expression since no
729 register-offset pair is available. */
730 struct dw_loc_descr_struct
*loc_list
;
732 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
733 loc_list
= build_cfa_loc (&loc
);
734 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
737 add_fde_cfi (label
, cfi
);
740 /* Add the CFI for saving a register. REG is the CFA column number.
741 LABEL is passed to add_fde_cfi.
742 If SREG is -1, the register is saved at OFFSET from the CFA;
743 otherwise it is saved in SREG. */
746 reg_save (label
, reg
, sreg
, offset
)
752 dw_cfi_ref cfi
= new_cfi ();
754 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
756 /* The following comparison is correct. -1 is used to indicate that
757 the value isn't a register number. */
758 if (sreg
== (unsigned int) -1)
761 /* The register number won't fit in 6 bits, so we have to use
763 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
765 cfi
->dw_cfi_opc
= DW_CFA_offset
;
767 #ifdef ENABLE_CHECKING
769 /* If we get an offset that is not a multiple of
770 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
771 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
773 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
775 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
779 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
781 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
783 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
785 else if (sreg
== reg
)
786 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
790 cfi
->dw_cfi_opc
= DW_CFA_register
;
791 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
794 add_fde_cfi (label
, cfi
);
797 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
798 This CFI tells the unwinder that it needs to restore the window registers
799 from the previous frame's window save area.
801 ??? Perhaps we should note in the CIE where windows are saved (instead of
802 assuming 0(cfa)) and what registers are in the window. */
805 dwarf2out_window_save (label
)
808 dw_cfi_ref cfi
= new_cfi ();
810 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
811 add_fde_cfi (label
, cfi
);
814 /* Add a CFI to update the running total of the size of arguments
815 pushed onto the stack. */
818 dwarf2out_args_size (label
, size
)
824 if (size
== old_args_size
)
827 old_args_size
= size
;
830 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
831 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
832 add_fde_cfi (label
, cfi
);
835 /* Entry point for saving a register to the stack. REG is the GCC register
836 number. LABEL and OFFSET are passed to reg_save. */
839 dwarf2out_reg_save (label
, reg
, offset
)
844 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
847 /* Entry point for saving the return address in the stack.
848 LABEL and OFFSET are passed to reg_save. */
851 dwarf2out_return_save (label
, offset
)
855 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
858 /* Entry point for saving the return address in a register.
859 LABEL and SREG are passed to reg_save. */
862 dwarf2out_return_reg (label
, sreg
)
866 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
869 /* Record the initial position of the return address. RTL is
870 INCOMING_RETURN_ADDR_RTX. */
873 initial_return_save (rtl
)
876 unsigned int reg
= (unsigned int) -1;
877 HOST_WIDE_INT offset
= 0;
879 switch (GET_CODE (rtl
))
882 /* RA is in a register. */
883 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
887 /* RA is on the stack. */
889 switch (GET_CODE (rtl
))
892 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
898 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
900 offset
= INTVAL (XEXP (rtl
, 1));
904 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
906 offset
= -INTVAL (XEXP (rtl
, 1));
916 /* The return address is at some offset from any value we can
917 actually load. For instance, on the SPARC it is in %i7+8. Just
918 ignore the offset for now; it doesn't matter for unwinding frames. */
919 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
921 initial_return_save (XEXP (rtl
, 0));
928 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
931 /* Given a SET, calculate the amount of stack adjustment it
935 stack_adjust_offset (pattern
)
938 rtx src
= SET_SRC (pattern
);
939 rtx dest
= SET_DEST (pattern
);
940 HOST_WIDE_INT offset
= 0;
943 if (dest
== stack_pointer_rtx
)
945 /* (set (reg sp) (plus (reg sp) (const_int))) */
946 code
= GET_CODE (src
);
947 if (! (code
== PLUS
|| code
== MINUS
)
948 || XEXP (src
, 0) != stack_pointer_rtx
949 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
952 offset
= INTVAL (XEXP (src
, 1));
954 else if (GET_CODE (dest
) == MEM
)
956 /* (set (mem (pre_dec (reg sp))) (foo)) */
957 src
= XEXP (dest
, 0);
958 code
= GET_CODE (src
);
960 if ((code
!= PRE_DEC
&& code
!= PRE_INC
&& code
!= PRE_MODIFY
)
961 || XEXP (src
, 0) != stack_pointer_rtx
)
964 if (code
== PRE_MODIFY
)
966 rtx val
= XEXP (XEXP (src
, 1), 1);
968 /* We handle only adjustments by constant amount. */
969 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
970 GET_CODE (val
) != CONST_INT
)
973 offset
= -INTVAL (val
);
976 offset
= GET_MODE_SIZE (GET_MODE (dest
));
981 if (code
== PLUS
|| code
== PRE_INC
)
987 /* Check INSN to see if it looks like a push or a stack adjustment, and
988 make a note of it if it does. EH uses this information to find out how
989 much extra space it needs to pop off the stack. */
992 dwarf2out_stack_adjust (insn
)
995 HOST_WIDE_INT offset
;
999 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1001 /* Extract the size of the args from the CALL rtx itself. */
1002 insn
= PATTERN (insn
);
1003 if (GET_CODE (insn
) == PARALLEL
)
1004 insn
= XVECEXP (insn
, 0, 0);
1005 if (GET_CODE (insn
) == SET
)
1006 insn
= SET_SRC (insn
);
1007 if (GET_CODE (insn
) != CALL
)
1010 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1014 /* If only calls can throw, and we have a frame pointer,
1015 save up adjustments until we see the CALL_INSN. */
1016 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1019 if (GET_CODE (insn
) == BARRIER
)
1021 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1022 the compiler will have already emitted a stack adjustment, but
1023 doesn't bother for calls to noreturn functions. */
1024 #ifdef STACK_GROWS_DOWNWARD
1025 offset
= -args_size
;
1030 else if (GET_CODE (PATTERN (insn
)) == SET
)
1031 offset
= stack_adjust_offset (PATTERN (insn
));
1032 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1033 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1035 /* There may be stack adjustments inside compound insns. Search
1037 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1038 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1039 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1047 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1048 cfa
.offset
+= offset
;
1050 #ifndef STACK_GROWS_DOWNWARD
1054 args_size
+= offset
;
1058 label
= dwarf2out_cfi_label ();
1059 def_cfa_1 (label
, &cfa
);
1060 dwarf2out_args_size (label
, args_size
);
1063 /* We delay emitting a register save until either (a) we reach the end
1064 of the prologue or (b) the register is clobbered. This clusters
1065 register saves so that there are fewer pc advances. */
1067 struct queued_reg_save
1069 struct queued_reg_save
*next
;
1074 static struct queued_reg_save
*queued_reg_saves
;
1075 static const char *last_reg_save_label
;
1078 queue_reg_save (label
, reg
, offset
)
1083 struct queued_reg_save
*q
= (struct queued_reg_save
*) xmalloc (sizeof (*q
));
1085 q
->next
= queued_reg_saves
;
1087 q
->cfa_offset
= offset
;
1088 queued_reg_saves
= q
;
1090 last_reg_save_label
= label
;
1094 flush_queued_reg_saves ()
1096 struct queued_reg_save
*q
, *next
;
1098 for (q
= queued_reg_saves
; q
; q
= next
)
1100 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1105 queued_reg_saves
= NULL
;
1106 last_reg_save_label
= NULL
;
1110 clobbers_queued_reg_save (insn
)
1113 struct queued_reg_save
*q
;
1115 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1116 if (modified_in_p (q
->reg
, insn
))
1123 /* A temporary register holding an integral value used in adjusting SP
1124 or setting up the store_reg. The "offset" field holds the integer
1125 value, not an offset. */
1126 static dw_cfa_location cfa_temp
;
1128 /* Record call frame debugging information for an expression EXPR,
1129 which either sets SP or FP (adjusting how we calculate the frame
1130 address) or saves a register to the stack. LABEL indicates the
1133 This function encodes a state machine mapping rtxes to actions on
1134 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1135 users need not read the source code.
1137 The High-Level Picture
1139 Changes in the register we use to calculate the CFA: Currently we
1140 assume that if you copy the CFA register into another register, we
1141 should take the other one as the new CFA register; this seems to
1142 work pretty well. If it's wrong for some target, it's simple
1143 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1145 Changes in the register we use for saving registers to the stack:
1146 This is usually SP, but not always. Again, we deduce that if you
1147 copy SP into another register (and SP is not the CFA register),
1148 then the new register is the one we will be using for register
1149 saves. This also seems to work.
1151 Register saves: There's not much guesswork about this one; if
1152 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1153 register save, and the register used to calculate the destination
1154 had better be the one we think we're using for this purpose.
1156 Except: If the register being saved is the CFA register, and the
1157 offset is non-zero, we are saving the CFA, so we assume we have to
1158 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1159 the intent is to save the value of SP from the previous frame.
1161 Invariants / Summaries of Rules
1163 cfa current rule for calculating the CFA. It usually
1164 consists of a register and an offset.
1165 cfa_store register used by prologue code to save things to the stack
1166 cfa_store.offset is the offset from the value of
1167 cfa_store.reg to the actual CFA
1168 cfa_temp register holding an integral value. cfa_temp.offset
1169 stores the value, which will be used to adjust the
1170 stack pointer. cfa_temp is also used like cfa_store,
1171 to track stores to the stack via fp or a temp reg.
1173 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1174 with cfa.reg as the first operand changes the cfa.reg and its
1175 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1178 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1179 expression yielding a constant. This sets cfa_temp.reg
1180 and cfa_temp.offset.
1182 Rule 5: Create a new register cfa_store used to save items to the
1185 Rules 10-14: Save a register to the stack. Define offset as the
1186 difference of the original location and cfa_store's
1187 location (or cfa_temp's location if cfa_temp is used).
1191 "{a,b}" indicates a choice of a xor b.
1192 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1195 (set <reg1> <reg2>:cfa.reg)
1196 effects: cfa.reg = <reg1>
1197 cfa.offset unchanged
1198 cfa_temp.reg = <reg1>
1199 cfa_temp.offset = cfa.offset
1202 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1203 {<const_int>,<reg>:cfa_temp.reg}))
1204 effects: cfa.reg = sp if fp used
1205 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1206 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1207 if cfa_store.reg==sp
1210 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1211 effects: cfa.reg = fp
1212 cfa_offset += +/- <const_int>
1215 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1216 constraints: <reg1> != fp
1218 effects: cfa.reg = <reg1>
1219 cfa_temp.reg = <reg1>
1220 cfa_temp.offset = cfa.offset
1223 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1224 constraints: <reg1> != fp
1226 effects: cfa_store.reg = <reg1>
1227 cfa_store.offset = cfa.offset - cfa_temp.offset
1230 (set <reg> <const_int>)
1231 effects: cfa_temp.reg = <reg>
1232 cfa_temp.offset = <const_int>
1235 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1236 effects: cfa_temp.reg = <reg1>
1237 cfa_temp.offset |= <const_int>
1240 (set <reg> (high <exp>))
1244 (set <reg> (lo_sum <exp> <const_int>))
1245 effects: cfa_temp.reg = <reg>
1246 cfa_temp.offset = <const_int>
1249 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1250 effects: cfa_store.offset -= <const_int>
1251 cfa.offset = cfa_store.offset if cfa.reg == sp
1253 cfa.base_offset = -cfa_store.offset
1256 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1257 effects: cfa_store.offset += -/+ mode_size(mem)
1258 cfa.offset = cfa_store.offset if cfa.reg == sp
1260 cfa.base_offset = -cfa_store.offset
1263 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1266 effects: cfa.reg = <reg1>
1267 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1270 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1271 effects: cfa.reg = <reg1>
1272 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1275 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1276 effects: cfa.reg = <reg1>
1277 cfa.base_offset = -cfa_temp.offset
1278 cfa_temp.offset -= mode_size(mem) */
1281 dwarf2out_frame_debug_expr (expr
, label
)
1286 HOST_WIDE_INT offset
;
1288 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1289 the PARALLEL independently. The first element is always processed if
1290 it is a SET. This is for backward compatibility. Other elements
1291 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1292 flag is set in them. */
1293 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1296 int limit
= XVECLEN (expr
, 0);
1298 for (par_index
= 0; par_index
< limit
; par_index
++)
1299 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1300 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1302 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1307 if (GET_CODE (expr
) != SET
)
1310 src
= SET_SRC (expr
);
1311 dest
= SET_DEST (expr
);
1313 switch (GET_CODE (dest
))
1317 /* Update the CFA rule wrt SP or FP. Make sure src is
1318 relative to the current CFA register. */
1319 switch (GET_CODE (src
))
1321 /* Setting FP from SP. */
1323 if (cfa
.reg
== (unsigned) REGNO (src
))
1329 /* We used to require that dest be either SP or FP, but the
1330 ARM copies SP to a temporary register, and from there to
1331 FP. So we just rely on the backends to only set
1332 RTX_FRAME_RELATED_P on appropriate insns. */
1333 cfa
.reg
= REGNO (dest
);
1334 cfa_temp
.reg
= cfa
.reg
;
1335 cfa_temp
.offset
= cfa
.offset
;
1341 if (dest
== stack_pointer_rtx
)
1345 switch (GET_CODE (XEXP (src
, 1)))
1348 offset
= INTVAL (XEXP (src
, 1));
1351 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1353 offset
= cfa_temp
.offset
;
1359 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1361 /* Restoring SP from FP in the epilogue. */
1362 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1364 cfa
.reg
= STACK_POINTER_REGNUM
;
1366 else if (GET_CODE (src
) == LO_SUM
)
1367 /* Assume we've set the source reg of the LO_SUM from sp. */
1369 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1372 if (GET_CODE (src
) != MINUS
)
1374 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1375 cfa
.offset
+= offset
;
1376 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1377 cfa_store
.offset
+= offset
;
1379 else if (dest
== hard_frame_pointer_rtx
)
1382 /* Either setting the FP from an offset of the SP,
1383 or adjusting the FP */
1384 if (! frame_pointer_needed
)
1387 if (GET_CODE (XEXP (src
, 0)) == REG
1388 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1389 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1391 offset
= INTVAL (XEXP (src
, 1));
1392 if (GET_CODE (src
) != MINUS
)
1394 cfa
.offset
+= offset
;
1395 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1402 if (GET_CODE (src
) == MINUS
)
1406 if (GET_CODE (XEXP (src
, 0)) == REG
1407 && REGNO (XEXP (src
, 0)) == cfa
.reg
1408 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1410 /* Setting a temporary CFA register that will be copied
1411 into the FP later on. */
1412 offset
= - INTVAL (XEXP (src
, 1));
1413 cfa
.offset
+= offset
;
1414 cfa
.reg
= REGNO (dest
);
1415 /* Or used to save regs to the stack. */
1416 cfa_temp
.reg
= cfa
.reg
;
1417 cfa_temp
.offset
= cfa
.offset
;
1421 else if (GET_CODE (XEXP (src
, 0)) == REG
1422 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1423 && XEXP (src
, 1) == stack_pointer_rtx
)
1425 /* Setting a scratch register that we will use instead
1426 of SP for saving registers to the stack. */
1427 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1429 cfa_store
.reg
= REGNO (dest
);
1430 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1434 else if (GET_CODE (src
) == LO_SUM
1435 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1437 cfa_temp
.reg
= REGNO (dest
);
1438 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1447 cfa_temp
.reg
= REGNO (dest
);
1448 cfa_temp
.offset
= INTVAL (src
);
1453 if (GET_CODE (XEXP (src
, 0)) != REG
1454 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1455 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1458 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1459 cfa_temp
.reg
= REGNO (dest
);
1460 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1463 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1464 which will fill in all of the bits. */
1473 def_cfa_1 (label
, &cfa
);
1477 if (GET_CODE (src
) != REG
)
1480 /* Saving a register to the stack. Make sure dest is relative to the
1482 switch (GET_CODE (XEXP (dest
, 0)))
1487 /* We can't handle variable size modifications. */
1488 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1490 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1492 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1493 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1496 cfa_store
.offset
+= offset
;
1497 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1498 cfa
.offset
= cfa_store
.offset
;
1500 offset
= -cfa_store
.offset
;
1506 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1507 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1510 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1511 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1514 cfa_store
.offset
+= offset
;
1515 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1516 cfa
.offset
= cfa_store
.offset
;
1518 offset
= -cfa_store
.offset
;
1522 /* With an offset. */
1526 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1528 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1529 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1532 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1533 offset
-= cfa_store
.offset
;
1534 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1535 offset
-= cfa_temp
.offset
;
1541 /* Without an offset. */
1543 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1544 offset
= -cfa_store
.offset
;
1545 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1546 offset
= -cfa_temp
.offset
;
1553 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1555 offset
= -cfa_temp
.offset
;
1556 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1563 if (REGNO (src
) != STACK_POINTER_REGNUM
1564 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1565 && (unsigned) REGNO (src
) == cfa
.reg
)
1567 /* We're storing the current CFA reg into the stack. */
1569 if (cfa
.offset
== 0)
1571 /* If the source register is exactly the CFA, assume
1572 we're saving SP like any other register; this happens
1574 def_cfa_1 (label
, &cfa
);
1575 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1580 /* Otherwise, we'll need to look in the stack to
1581 calculate the CFA. */
1582 rtx x
= XEXP (dest
, 0);
1584 if (GET_CODE (x
) != REG
)
1586 if (GET_CODE (x
) != REG
)
1589 cfa
.reg
= REGNO (x
);
1590 cfa
.base_offset
= offset
;
1592 def_cfa_1 (label
, &cfa
);
1597 def_cfa_1 (label
, &cfa
);
1598 queue_reg_save (label
, src
, offset
);
1606 /* Record call frame debugging information for INSN, which either
1607 sets SP or FP (adjusting how we calculate the frame address) or saves a
1608 register to the stack. If INSN is NULL_RTX, initialize our state. */
1611 dwarf2out_frame_debug (insn
)
1617 if (insn
== NULL_RTX
)
1619 /* Flush any queued register saves. */
1620 flush_queued_reg_saves ();
1622 /* Set up state for generating call frame debug info. */
1624 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1627 cfa
.reg
= STACK_POINTER_REGNUM
;
1630 cfa_temp
.offset
= 0;
1634 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1635 flush_queued_reg_saves ();
1637 if (! RTX_FRAME_RELATED_P (insn
))
1639 if (!ACCUMULATE_OUTGOING_ARGS
)
1640 dwarf2out_stack_adjust (insn
);
1645 label
= dwarf2out_cfi_label ();
1646 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1648 insn
= XEXP (src
, 0);
1650 insn
= PATTERN (insn
);
1652 dwarf2out_frame_debug_expr (insn
, label
);
1655 /* Output a Call Frame Information opcode and its operand(s). */
1658 output_cfi (cfi
, fde
, for_eh
)
1663 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1664 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1665 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1666 "DW_CFA_advance_loc 0x%lx",
1667 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1668 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1670 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1671 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1672 "DW_CFA_offset, column 0x%lx",
1673 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1674 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1676 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1677 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1678 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1679 "DW_CFA_restore, column 0x%lx",
1680 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1683 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1684 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1686 switch (cfi
->dw_cfi_opc
)
1688 case DW_CFA_set_loc
:
1690 dw2_asm_output_encoded_addr_rtx (
1691 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1692 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1695 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1696 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1699 case DW_CFA_advance_loc1
:
1700 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1701 fde
->dw_fde_current_label
, NULL
);
1702 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1705 case DW_CFA_advance_loc2
:
1706 dw2_asm_output_delta (2, 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_loc4
:
1712 dw2_asm_output_delta (4, 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_MIPS_advance_loc8
:
1718 dw2_asm_output_delta (8, 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_offset_extended
:
1724 case DW_CFA_def_cfa
:
1725 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1727 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1730 case DW_CFA_offset_extended_sf
:
1731 case DW_CFA_def_cfa_sf
:
1732 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1734 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1737 case DW_CFA_restore_extended
:
1738 case DW_CFA_undefined
:
1739 case DW_CFA_same_value
:
1740 case DW_CFA_def_cfa_register
:
1741 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1745 case DW_CFA_register
:
1746 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1748 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1752 case DW_CFA_def_cfa_offset
:
1753 case DW_CFA_GNU_args_size
:
1754 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1757 case DW_CFA_def_cfa_offset_sf
:
1758 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1761 case DW_CFA_GNU_window_save
:
1764 case DW_CFA_def_cfa_expression
:
1765 case DW_CFA_expression
:
1766 output_cfa_loc (cfi
);
1769 case DW_CFA_GNU_negative_offset_extended
:
1770 /* Obsoleted by DW_CFA_offset_extended_sf. */
1779 /* Output the call frame information used to used to record information
1780 that relates to calculating the frame pointer, and records the
1781 location of saved registers. */
1784 output_call_frame_info (for_eh
)
1790 char l1
[20], l2
[20], section_start_label
[20];
1791 int any_lsda_needed
= 0;
1792 char augmentation
[6];
1793 int augmentation_size
;
1794 int fde_encoding
= DW_EH_PE_absptr
;
1795 int per_encoding
= DW_EH_PE_absptr
;
1796 int lsda_encoding
= DW_EH_PE_absptr
;
1798 /* If we don't have any functions we'll want to unwind out of, don't emit any
1799 EH unwind information. */
1802 int any_eh_needed
= flag_asynchronous_unwind_tables
;
1804 for (i
= 0; i
< fde_table_in_use
; i
++)
1805 if (fde_table
[i
].uses_eh_lsda
)
1806 any_eh_needed
= any_lsda_needed
= 1;
1807 else if (! fde_table
[i
].nothrow
)
1810 if (! any_eh_needed
)
1814 /* We're going to be generating comments, so turn on app. */
1819 (*targetm
.asm_out
.eh_frame_section
) ();
1821 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1823 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1824 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1826 /* Output the CIE. */
1827 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1828 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1829 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1830 "Length of Common Information Entry");
1831 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1833 /* Now that the CIE pointer is PC-relative for EH,
1834 use 0 to identify the CIE. */
1835 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1836 (for_eh
? 0 : DW_CIE_ID
),
1837 "CIE Identifier Tag");
1839 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1841 augmentation
[0] = 0;
1842 augmentation_size
= 0;
1848 z Indicates that a uleb128 is present to size the
1849 augmentation section.
1850 L Indicates the encoding (and thus presence) of
1851 an LSDA pointer in the FDE augmentation.
1852 R Indicates a non-default pointer encoding for
1854 P Indicates the presence of an encoding + language
1855 personality routine in the CIE augmentation. */
1857 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1858 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1859 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1861 p
= augmentation
+ 1;
1862 if (eh_personality_libfunc
)
1865 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1867 if (any_lsda_needed
)
1870 augmentation_size
+= 1;
1872 if (fde_encoding
!= DW_EH_PE_absptr
)
1875 augmentation_size
+= 1;
1877 if (p
> augmentation
+ 1)
1879 augmentation
[0] = 'z';
1883 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1884 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1886 int offset
= ( 4 /* Length */
1888 + 1 /* CIE version */
1889 + strlen (augmentation
) + 1 /* Augmentation */
1890 + size_of_uleb128 (1) /* Code alignment */
1891 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1893 + 1 /* Augmentation size */
1894 + 1 /* Personality encoding */ );
1895 int pad
= -offset
& (PTR_SIZE
- 1);
1897 augmentation_size
+= pad
;
1899 /* Augmentations should be small, so there's scarce need to
1900 iterate for a solution. Die if we exceed one uleb128 byte. */
1901 if (size_of_uleb128 (augmentation_size
) != 1)
1906 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1907 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1908 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1909 "CIE Data Alignment Factor");
1910 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
1912 if (augmentation
[0])
1914 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
1915 if (eh_personality_libfunc
)
1917 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
1918 eh_data_format_name (per_encoding
));
1919 dw2_asm_output_encoded_addr_rtx (per_encoding
,
1920 eh_personality_libfunc
, NULL
);
1923 if (any_lsda_needed
)
1924 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
1925 eh_data_format_name (lsda_encoding
));
1927 if (fde_encoding
!= DW_EH_PE_absptr
)
1928 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
1929 eh_data_format_name (fde_encoding
));
1932 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1933 output_cfi (cfi
, NULL
, for_eh
);
1935 /* Pad the CIE out to an address sized boundary. */
1936 ASM_OUTPUT_ALIGN (asm_out_file
,
1937 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
1938 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1940 /* Loop through all of the FDE's. */
1941 for (i
= 0; i
< fde_table_in_use
; i
++)
1943 fde
= &fde_table
[i
];
1945 /* Don't emit EH unwind info for leaf functions that don't need it. */
1946 if (for_eh
&& fde
->nothrow
&& ! fde
->uses_eh_lsda
)
1949 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
1950 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1951 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1952 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1954 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1957 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
1959 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
1964 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
1965 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
1966 "FDE initial location");
1967 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
1968 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1969 "FDE address range");
1973 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
1974 "FDE initial location");
1975 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
1976 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1977 "FDE address range");
1980 if (augmentation
[0])
1982 if (any_lsda_needed
)
1984 int size
= size_of_encoded_value (lsda_encoding
);
1986 if (lsda_encoding
== DW_EH_PE_aligned
)
1988 int offset
= ( 4 /* Length */
1989 + 4 /* CIE offset */
1990 + 2 * size_of_encoded_value (fde_encoding
)
1991 + 1 /* Augmentation size */ );
1992 int pad
= -offset
& (PTR_SIZE
- 1);
1995 if (size_of_uleb128 (size
) != 1)
1999 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2001 if (fde
->uses_eh_lsda
)
2003 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2004 fde
->funcdef_number
);
2005 dw2_asm_output_encoded_addr_rtx (
2006 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2007 "Language Specific Data Area");
2011 if (lsda_encoding
== DW_EH_PE_aligned
)
2012 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2014 (size_of_encoded_value (lsda_encoding
), 0,
2015 "Language Specific Data Area (none)");
2019 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2022 /* Loop through the Call Frame Instructions associated with
2024 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2025 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2026 output_cfi (cfi
, fde
, for_eh
);
2028 /* Pad the FDE out to an address sized boundary. */
2029 ASM_OUTPUT_ALIGN (asm_out_file
,
2030 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2031 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2034 #ifndef EH_FRAME_SECTION_NAME
2036 dw2_asm_output_data (4, 0, "End of Table");
2038 #ifdef MIPS_DEBUGGING_INFO
2039 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2040 get a value of 0. Putting .align 0 after the label fixes it. */
2041 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2044 /* Turn off app to make assembly quicker. */
2049 /* Output a marker (i.e. a label) for the beginning of a function, before
2053 dwarf2out_begin_prologue (line
, file
)
2054 unsigned int line ATTRIBUTE_UNUSED
;
2055 const char *file ATTRIBUTE_UNUSED
;
2057 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2060 current_function_func_begin_label
= 0;
2062 #ifdef IA64_UNWIND_INFO
2063 /* ??? current_function_func_begin_label is also used by except.c
2064 for call-site information. We must emit this label if it might
2066 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2067 && ! dwarf2out_do_frame ())
2070 if (! dwarf2out_do_frame ())
2074 current_funcdef_number
++;
2075 function_section (current_function_decl
);
2076 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2077 current_funcdef_number
);
2078 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2079 current_funcdef_number
);
2080 current_function_func_begin_label
= get_identifier (label
);
2082 #ifdef IA64_UNWIND_INFO
2083 /* We can elide the fde allocation if we're not emitting debug info. */
2084 if (! dwarf2out_do_frame ())
2088 /* Expand the fde table if necessary. */
2089 if (fde_table_in_use
== fde_table_allocated
)
2091 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2093 = (dw_fde_ref
) xrealloc (fde_table
,
2094 fde_table_allocated
* sizeof (dw_fde_node
));
2097 /* Record the FDE associated with this function. */
2098 current_funcdef_fde
= fde_table_in_use
;
2100 /* Add the new FDE at the end of the fde_table. */
2101 fde
= &fde_table
[fde_table_in_use
++];
2102 fde
->dw_fde_begin
= xstrdup (label
);
2103 fde
->dw_fde_current_label
= NULL
;
2104 fde
->dw_fde_end
= NULL
;
2105 fde
->dw_fde_cfi
= NULL
;
2106 fde
->funcdef_number
= current_funcdef_number
;
2107 fde
->nothrow
= current_function_nothrow
;
2108 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2110 args_size
= old_args_size
= 0;
2112 /* We only want to output line number information for the genuine dwarf2
2113 prologue case, not the eh frame case. */
2114 #ifdef DWARF2_DEBUGGING_INFO
2116 dwarf2out_source_line (line
, file
);
2120 /* Output a marker (i.e. a label) for the absolute end of the generated code
2121 for a function definition. This gets called *after* the epilogue code has
2125 dwarf2out_end_epilogue ()
2128 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2130 /* Output a label to mark the endpoint of the code generated for this
2132 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
2133 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2134 fde
= &fde_table
[fde_table_in_use
- 1];
2135 fde
->dw_fde_end
= xstrdup (label
);
2139 dwarf2out_frame_init ()
2141 /* Allocate the initial hunk of the fde_table. */
2142 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2143 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2144 fde_table_in_use
= 0;
2146 /* Generate the CFA instructions common to all FDE's. Do it now for the
2147 sake of lookup_cfa. */
2149 #ifdef DWARF2_UNWIND_INFO
2150 /* On entry, the Canonical Frame Address is at SP. */
2151 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2152 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2157 dwarf2out_frame_finish ()
2159 /* Output call frame information. */
2160 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2161 output_call_frame_info (0);
2163 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2164 output_call_frame_info (1);
2167 /* And now, the subset of the debugging information support code necessary
2168 for emitting location expressions. */
2170 typedef struct dw_val_struct
*dw_val_ref
;
2171 typedef struct die_struct
*dw_die_ref
;
2172 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2173 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2175 /* Each DIE may have a series of attribute/value pairs. Values
2176 can take on several forms. The forms that are used in this
2177 implementation are listed below. */
2182 dw_val_class_offset
,
2184 dw_val_class_loc_list
,
2185 dw_val_class_range_list
,
2187 dw_val_class_unsigned_const
,
2188 dw_val_class_long_long
,
2191 dw_val_class_die_ref
,
2192 dw_val_class_fde_ref
,
2193 dw_val_class_lbl_id
,
2194 dw_val_class_lbl_offset
,
2199 /* Describe a double word constant value. */
2200 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2202 typedef struct dw_long_long_struct
2209 /* Describe a floating point constant value. */
2211 typedef struct dw_fp_struct
2218 /* The dw_val_node describes an attribute's value, as it is
2219 represented internally. */
2221 typedef struct dw_val_struct
2223 dw_val_class val_class
;
2227 long unsigned val_offset
;
2228 dw_loc_list_ref val_loc_list
;
2229 dw_loc_descr_ref val_loc
;
2231 long unsigned val_unsigned
;
2232 dw_long_long_const val_long_long
;
2233 dw_float_const val_float
;
2239 unsigned val_fde_index
;
2240 struct indirect_string_node
*val_str
;
2242 unsigned char val_flag
;
2248 /* Locations in memory are described using a sequence of stack machine
2251 typedef struct dw_loc_descr_struct
2253 dw_loc_descr_ref dw_loc_next
;
2254 enum dwarf_location_atom dw_loc_opc
;
2255 dw_val_node dw_loc_oprnd1
;
2256 dw_val_node dw_loc_oprnd2
;
2261 /* Location lists are ranges + location descriptions for that range,
2262 so you can track variables that are in different places over
2263 their entire life. */
2264 typedef struct dw_loc_list_struct
2266 dw_loc_list_ref dw_loc_next
;
2267 const char *begin
; /* Label for begin address of range */
2268 const char *end
; /* Label for end address of range */
2269 char *ll_symbol
; /* Label for beginning of location list.
2270 Only on head of list */
2271 const char *section
; /* Section this loclist is relative to */
2272 dw_loc_descr_ref expr
;
2275 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2276 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2279 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2281 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2282 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2283 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2284 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2286 /* Convert a DWARF stack opcode into its string name. */
2289 dwarf_stack_op_name (op
)
2295 return "DW_OP_addr";
2297 return "DW_OP_deref";
2299 return "DW_OP_const1u";
2301 return "DW_OP_const1s";
2303 return "DW_OP_const2u";
2305 return "DW_OP_const2s";
2307 return "DW_OP_const4u";
2309 return "DW_OP_const4s";
2311 return "DW_OP_const8u";
2313 return "DW_OP_const8s";
2315 return "DW_OP_constu";
2317 return "DW_OP_consts";
2321 return "DW_OP_drop";
2323 return "DW_OP_over";
2325 return "DW_OP_pick";
2327 return "DW_OP_swap";
2331 return "DW_OP_xderef";
2339 return "DW_OP_minus";
2351 return "DW_OP_plus";
2352 case DW_OP_plus_uconst
:
2353 return "DW_OP_plus_uconst";
2359 return "DW_OP_shra";
2377 return "DW_OP_skip";
2379 return "DW_OP_lit0";
2381 return "DW_OP_lit1";
2383 return "DW_OP_lit2";
2385 return "DW_OP_lit3";
2387 return "DW_OP_lit4";
2389 return "DW_OP_lit5";
2391 return "DW_OP_lit6";
2393 return "DW_OP_lit7";
2395 return "DW_OP_lit8";
2397 return "DW_OP_lit9";
2399 return "DW_OP_lit10";
2401 return "DW_OP_lit11";
2403 return "DW_OP_lit12";
2405 return "DW_OP_lit13";
2407 return "DW_OP_lit14";
2409 return "DW_OP_lit15";
2411 return "DW_OP_lit16";
2413 return "DW_OP_lit17";
2415 return "DW_OP_lit18";
2417 return "DW_OP_lit19";
2419 return "DW_OP_lit20";
2421 return "DW_OP_lit21";
2423 return "DW_OP_lit22";
2425 return "DW_OP_lit23";
2427 return "DW_OP_lit24";
2429 return "DW_OP_lit25";
2431 return "DW_OP_lit26";
2433 return "DW_OP_lit27";
2435 return "DW_OP_lit28";
2437 return "DW_OP_lit29";
2439 return "DW_OP_lit30";
2441 return "DW_OP_lit31";
2443 return "DW_OP_reg0";
2445 return "DW_OP_reg1";
2447 return "DW_OP_reg2";
2449 return "DW_OP_reg3";
2451 return "DW_OP_reg4";
2453 return "DW_OP_reg5";
2455 return "DW_OP_reg6";
2457 return "DW_OP_reg7";
2459 return "DW_OP_reg8";
2461 return "DW_OP_reg9";
2463 return "DW_OP_reg10";
2465 return "DW_OP_reg11";
2467 return "DW_OP_reg12";
2469 return "DW_OP_reg13";
2471 return "DW_OP_reg14";
2473 return "DW_OP_reg15";
2475 return "DW_OP_reg16";
2477 return "DW_OP_reg17";
2479 return "DW_OP_reg18";
2481 return "DW_OP_reg19";
2483 return "DW_OP_reg20";
2485 return "DW_OP_reg21";
2487 return "DW_OP_reg22";
2489 return "DW_OP_reg23";
2491 return "DW_OP_reg24";
2493 return "DW_OP_reg25";
2495 return "DW_OP_reg26";
2497 return "DW_OP_reg27";
2499 return "DW_OP_reg28";
2501 return "DW_OP_reg29";
2503 return "DW_OP_reg30";
2505 return "DW_OP_reg31";
2507 return "DW_OP_breg0";
2509 return "DW_OP_breg1";
2511 return "DW_OP_breg2";
2513 return "DW_OP_breg3";
2515 return "DW_OP_breg4";
2517 return "DW_OP_breg5";
2519 return "DW_OP_breg6";
2521 return "DW_OP_breg7";
2523 return "DW_OP_breg8";
2525 return "DW_OP_breg9";
2527 return "DW_OP_breg10";
2529 return "DW_OP_breg11";
2531 return "DW_OP_breg12";
2533 return "DW_OP_breg13";
2535 return "DW_OP_breg14";
2537 return "DW_OP_breg15";
2539 return "DW_OP_breg16";
2541 return "DW_OP_breg17";
2543 return "DW_OP_breg18";
2545 return "DW_OP_breg19";
2547 return "DW_OP_breg20";
2549 return "DW_OP_breg21";
2551 return "DW_OP_breg22";
2553 return "DW_OP_breg23";
2555 return "DW_OP_breg24";
2557 return "DW_OP_breg25";
2559 return "DW_OP_breg26";
2561 return "DW_OP_breg27";
2563 return "DW_OP_breg28";
2565 return "DW_OP_breg29";
2567 return "DW_OP_breg30";
2569 return "DW_OP_breg31";
2571 return "DW_OP_regx";
2573 return "DW_OP_fbreg";
2575 return "DW_OP_bregx";
2577 return "DW_OP_piece";
2578 case DW_OP_deref_size
:
2579 return "DW_OP_deref_size";
2580 case DW_OP_xderef_size
:
2581 return "DW_OP_xderef_size";
2585 return "OP_<unknown>";
2589 /* Return a pointer to a newly allocated location description. Location
2590 descriptions are simple expression terms that can be strung
2591 together to form more complicated location (address) descriptions. */
2593 static inline dw_loc_descr_ref
2594 new_loc_descr (op
, oprnd1
, oprnd2
)
2595 enum dwarf_location_atom op
;
2596 unsigned long oprnd1
;
2597 unsigned long oprnd2
;
2599 /* Use xcalloc here so we clear out all of the long_long constant in
2601 dw_loc_descr_ref descr
2602 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2604 descr
->dw_loc_opc
= op
;
2605 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2606 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2607 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2608 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2614 /* Add a location description term to a location description expression. */
2617 add_loc_descr (list_head
, descr
)
2618 dw_loc_descr_ref
*list_head
;
2619 dw_loc_descr_ref descr
;
2621 dw_loc_descr_ref
*d
;
2623 /* Find the end of the chain. */
2624 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2630 /* Return the size of a location descriptor. */
2632 static unsigned long
2633 size_of_loc_descr (loc
)
2634 dw_loc_descr_ref loc
;
2636 unsigned long size
= 1;
2638 switch (loc
->dw_loc_opc
)
2641 size
+= DWARF2_ADDR_SIZE
;
2660 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2663 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2668 case DW_OP_plus_uconst
:
2669 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2707 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2710 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2713 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2716 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2717 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2720 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2722 case DW_OP_deref_size
:
2723 case DW_OP_xderef_size
:
2733 /* Return the size of a series of location descriptors. */
2735 static unsigned long
2737 dw_loc_descr_ref loc
;
2741 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2743 loc
->dw_loc_addr
= size
;
2744 size
+= size_of_loc_descr (loc
);
2750 /* Output location description stack opcode's operands (if any). */
2753 output_loc_operands (loc
)
2754 dw_loc_descr_ref loc
;
2756 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2757 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2759 switch (loc
->dw_loc_opc
)
2761 #ifdef DWARF2_DEBUGGING_INFO
2763 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2767 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2771 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2775 if (HOST_BITS_PER_LONG
< 64)
2777 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2784 if (val1
->val_class
== dw_val_class_loc
)
2785 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2789 dw2_asm_output_data (2, offset
, NULL
);
2802 /* We currently don't make any attempt to make sure these are
2803 aligned properly like we do for the main unwind info, so
2804 don't support emitting things larger than a byte if we're
2805 only doing unwinding. */
2810 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2813 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2816 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2819 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2821 case DW_OP_plus_uconst
:
2822 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2856 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2859 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2862 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2865 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2866 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2869 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2871 case DW_OP_deref_size
:
2872 case DW_OP_xderef_size
:
2873 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2876 /* Other codes have no operands. */
2881 /* Output a sequence of location operations. */
2884 output_loc_sequence (loc
)
2885 dw_loc_descr_ref loc
;
2887 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2889 /* Output the opcode. */
2890 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2891 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2893 /* Output the operand(s) (if any). */
2894 output_loc_operands (loc
);
2898 /* This routine will generate the correct assembly data for a location
2899 description based on a cfi entry with a complex address. */
2902 output_cfa_loc (cfi
)
2905 dw_loc_descr_ref loc
;
2908 /* Output the size of the block. */
2909 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2910 size
= size_of_locs (loc
);
2911 dw2_asm_output_data_uleb128 (size
, NULL
);
2913 /* Now output the operations themselves. */
2914 output_loc_sequence (loc
);
2917 /* This function builds a dwarf location descriptor sequence from
2918 a dw_cfa_location. */
2920 static struct dw_loc_descr_struct
*
2922 dw_cfa_location
*cfa
;
2924 struct dw_loc_descr_struct
*head
, *tmp
;
2926 if (cfa
->indirect
== 0)
2929 if (cfa
->base_offset
)
2932 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
2934 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
2936 else if (cfa
->reg
<= 31)
2937 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
2939 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
2941 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2942 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2943 add_loc_descr (&head
, tmp
);
2944 if (cfa
->offset
!= 0)
2946 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
2947 add_loc_descr (&head
, tmp
);
2953 /* This function fills in aa dw_cfa_location structure from a dwarf location
2954 descriptor sequence. */
2957 get_cfa_from_loc_descr (cfa
, loc
)
2958 dw_cfa_location
*cfa
;
2959 struct dw_loc_descr_struct
*loc
;
2961 struct dw_loc_descr_struct
*ptr
;
2963 cfa
->base_offset
= 0;
2967 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
2969 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3005 cfa
->reg
= op
- DW_OP_reg0
;
3008 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3042 cfa
->reg
= op
- DW_OP_breg0
;
3043 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3046 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3047 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3052 case DW_OP_plus_uconst
:
3053 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3056 internal_error ("DW_LOC_OP %s not implemented\n",
3057 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3061 #endif /* .debug_frame support */
3063 /* And now, the support for symbolic debugging information. */
3064 #ifdef DWARF2_DEBUGGING_INFO
3066 /* .debug_str support. */
3067 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3068 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3069 hashnode
, const PTR
));
3072 static void dwarf2out_init
PARAMS ((const char *));
3073 static void dwarf2out_finish
PARAMS ((const char *));
3074 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3075 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3076 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3077 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3078 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3079 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3080 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3081 static void dwarf2out_global_decl
PARAMS ((tree
));
3082 static void dwarf2out_abstract_function
PARAMS ((tree
));
3084 /* The debug hooks structure. */
3086 struct gcc_debug_hooks dwarf2_debug_hooks
=
3092 dwarf2out_start_source_file
,
3093 dwarf2out_end_source_file
,
3094 dwarf2out_begin_block
,
3095 dwarf2out_end_block
,
3096 dwarf2out_ignore_block
,
3097 dwarf2out_source_line
,
3098 dwarf2out_begin_prologue
,
3099 debug_nothing_int
, /* end_prologue */
3100 dwarf2out_end_epilogue
,
3101 debug_nothing_tree
, /* begin_function */
3102 debug_nothing_int
, /* end_function */
3103 dwarf2out_decl
, /* function_decl */
3104 dwarf2out_global_decl
,
3105 debug_nothing_tree
, /* deferred_inline_function */
3106 /* The DWARF 2 backend tries to reduce debugging bloat by not
3107 emitting the abstract description of inline functions until
3108 something tries to reference them. */
3109 dwarf2out_abstract_function
, /* outlining_inline_function */
3110 debug_nothing_rtx
/* label */
3113 /* NOTE: In the comments in this file, many references are made to
3114 "Debugging Information Entries". This term is abbreviated as `DIE'
3115 throughout the remainder of this file. */
3117 /* An internal representation of the DWARF output is built, and then
3118 walked to generate the DWARF debugging info. The walk of the internal
3119 representation is done after the entire program has been compiled.
3120 The types below are used to describe the internal representation. */
3122 /* Various DIE's use offsets relative to the beginning of the
3123 .debug_info section to refer to each other. */
3125 typedef long int dw_offset
;
3127 /* Define typedefs here to avoid circular dependencies. */
3129 typedef struct dw_attr_struct
*dw_attr_ref
;
3130 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3131 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3132 typedef struct pubname_struct
*pubname_ref
;
3133 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3135 /* Each entry in the line_info_table maintains the file and
3136 line number associated with the label generated for that
3137 entry. The label gives the PC value associated with
3138 the line number entry. */
3140 typedef struct dw_line_info_struct
3142 unsigned long dw_file_num
;
3143 unsigned long dw_line_num
;
3147 /* Line information for functions in separate sections; each one gets its
3149 typedef struct dw_separate_line_info_struct
3151 unsigned long dw_file_num
;
3152 unsigned long dw_line_num
;
3153 unsigned long function
;
3155 dw_separate_line_info_entry
;
3157 /* Each DIE attribute has a field specifying the attribute kind,
3158 a link to the next attribute in the chain, and an attribute value.
3159 Attributes are typically linked below the DIE they modify. */
3161 typedef struct dw_attr_struct
3163 enum dwarf_attribute dw_attr
;
3164 dw_attr_ref dw_attr_next
;
3165 dw_val_node dw_attr_val
;
3169 /* The Debugging Information Entry (DIE) structure */
3171 typedef struct die_struct
3173 enum dwarf_tag die_tag
;
3175 dw_attr_ref die_attr
;
3176 dw_die_ref die_parent
;
3177 dw_die_ref die_child
;
3179 dw_offset die_offset
;
3180 unsigned long die_abbrev
;
3185 /* The pubname structure */
3187 typedef struct pubname_struct
3194 struct dw_ranges_struct
3199 /* The limbo die list structure. */
3200 typedef struct limbo_die_struct
3204 struct limbo_die_struct
*next
;
3208 /* How to start an assembler comment. */
3209 #ifndef ASM_COMMENT_START
3210 #define ASM_COMMENT_START ";#"
3213 /* Define a macro which returns non-zero for a TYPE_DECL which was
3214 implicitly generated for a tagged type.
3216 Note that unlike the gcc front end (which generates a NULL named
3217 TYPE_DECL node for each complete tagged type, each array type, and
3218 each function type node created) the g++ front end generates a
3219 _named_ TYPE_DECL node for each tagged type node created.
3220 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3221 generate a DW_TAG_typedef DIE for them. */
3223 #define TYPE_DECL_IS_STUB(decl) \
3224 (DECL_NAME (decl) == NULL_TREE \
3225 || (DECL_ARTIFICIAL (decl) \
3226 && is_tagged_type (TREE_TYPE (decl)) \
3227 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3228 /* This is necessary for stub decls that \
3229 appear in nested inline functions. */ \
3230 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3231 && (decl_ultimate_origin (decl) \
3232 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3234 /* Information concerning the compilation unit's programming
3235 language, and compiler version. */
3237 extern int flag_traditional
;
3239 /* Fixed size portion of the DWARF compilation unit header. */
3240 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3242 /* Fixed size portion of debugging line information prolog. */
3243 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3245 /* Fixed size portion of public names info. */
3246 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3248 /* Fixed size portion of the address range info. */
3249 #define DWARF_ARANGES_HEADER_SIZE \
3250 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3251 - DWARF_OFFSET_SIZE)
3253 /* Size of padding portion in the address range info. It must be
3254 aligned to twice the pointer size. */
3255 #define DWARF_ARANGES_PAD_SIZE \
3256 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3257 - (2 * DWARF_OFFSET_SIZE + 4))
3259 /* Use assembler line directives if available. */
3260 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3261 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3262 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3264 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3268 /* Define the architecture-dependent minimum instruction length (in bytes).
3269 In this implementation of DWARF, this field is used for information
3270 purposes only. Since GCC generates assembly language, we have
3271 no a priori knowledge of how many instruction bytes are generated
3272 for each source line, and therefore can use only the DW_LNE_set_address
3273 and DW_LNS_fixed_advance_pc line information commands. */
3274 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3275 #define DWARF_LINE_MIN_INSTR_LENGTH 4
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 table of references to declaration
3340 scopes. This table is a display which tracks the nesting
3341 of declaration scopes at the current scope and containing
3342 scopes. This table is used to find the proper place to
3343 define type declaration DIE's. */
3344 varray_type decl_scope_table
;
3346 /* A pointer to the base of a list of references to DIE's that
3347 are uniquely identified by their tag, presence/absence of
3348 children DIE's, and list of attribute/value pairs. */
3349 static dw_die_ref
*abbrev_die_table
;
3351 /* Number of elements currently allocated for abbrev_die_table. */
3352 static unsigned abbrev_die_table_allocated
;
3354 /* Number of elements in type_die_table currently in use. */
3355 static unsigned abbrev_die_table_in_use
;
3357 /* Size (in elements) of increments by which we may expand the
3358 abbrev_die_table. */
3359 #define ABBREV_DIE_TABLE_INCREMENT 256
3361 /* A pointer to the base of a table that contains line information
3362 for each source code line in .text in the compilation unit. */
3363 static dw_line_info_ref line_info_table
;
3365 /* Number of elements currently allocated for line_info_table. */
3366 static unsigned line_info_table_allocated
;
3368 /* Number of elements in separate_line_info_table currently in use. */
3369 static unsigned separate_line_info_table_in_use
;
3371 /* A pointer to the base of a table that contains line information
3372 for each source code line outside of .text in the compilation unit. */
3373 static dw_separate_line_info_ref separate_line_info_table
;
3375 /* Number of elements currently allocated for separate_line_info_table. */
3376 static unsigned separate_line_info_table_allocated
;
3378 /* Number of elements in line_info_table currently in use. */
3379 static unsigned line_info_table_in_use
;
3381 /* Size (in elements) of increments by which we may expand the
3383 #define LINE_INFO_TABLE_INCREMENT 1024
3385 /* A pointer to the base of a table that contains a list of publicly
3386 accessible names. */
3387 static pubname_ref pubname_table
;
3389 /* Number of elements currently allocated for pubname_table. */
3390 static unsigned pubname_table_allocated
;
3392 /* Number of elements in pubname_table currently in use. */
3393 static unsigned pubname_table_in_use
;
3395 /* Size (in elements) of increments by which we may expand the
3397 #define PUBNAME_TABLE_INCREMENT 64
3399 /* Array of dies for which we should generate .debug_arange info. */
3400 static dw_die_ref
*arange_table
;
3402 /* Number of elements currently allocated for arange_table. */
3403 static unsigned arange_table_allocated
;
3405 /* Number of elements in arange_table currently in use. */
3406 static unsigned arange_table_in_use
;
3408 /* Size (in elements) of increments by which we may expand the
3410 #define ARANGE_TABLE_INCREMENT 64
3412 /* Array of dies for which we should generate .debug_ranges info. */
3413 static dw_ranges_ref ranges_table
;
3415 /* Number of elements currently allocated for ranges_table. */
3416 static unsigned ranges_table_allocated
;
3418 /* Number of elements in ranges_table currently in use. */
3419 static unsigned ranges_table_in_use
;
3421 /* Size (in elements) of increments by which we may expand the
3423 #define RANGES_TABLE_INCREMENT 64
3425 /* Whether we have location lists that need outputting */
3426 static unsigned have_location_lists
;
3428 /* A pointer to the base of a list of incomplete types which might be
3429 completed at some later time. incomplete_types_list needs to be a VARRAY
3430 because we want to tell the garbage collector about it. */
3431 varray_type incomplete_types
;
3433 /* Record whether the function being analyzed contains inlined functions. */
3434 static int current_function_has_inlines
;
3435 #if 0 && defined (MIPS_DEBUGGING_INFO)
3436 static int comp_unit_has_inlines
;
3439 /* Array of RTXes referenced by the debugging information, which therefore
3440 must be kept around forever. This is a GC root. */
3441 static varray_type used_rtx_varray
;
3443 /* Forward declarations for functions defined in this file. */
3445 static int is_pseudo_reg
PARAMS ((rtx
));
3446 static tree type_main_variant
PARAMS ((tree
));
3447 static int is_tagged_type
PARAMS ((tree
));
3448 static const char *dwarf_tag_name
PARAMS ((unsigned));
3449 static const char *dwarf_attr_name
PARAMS ((unsigned));
3450 static const char *dwarf_form_name
PARAMS ((unsigned));
3452 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3454 static tree decl_ultimate_origin
PARAMS ((tree
));
3455 static tree block_ultimate_origin
PARAMS ((tree
));
3456 static tree decl_class_context
PARAMS ((tree
));
3457 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3458 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3459 static void add_AT_flag
PARAMS ((dw_die_ref
,
3460 enum dwarf_attribute
,
3462 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3463 static void add_AT_int
PARAMS ((dw_die_ref
,
3464 enum dwarf_attribute
, long));
3465 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3466 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3467 enum dwarf_attribute
,
3469 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3470 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3471 enum dwarf_attribute
,
3474 static void add_AT_float
PARAMS ((dw_die_ref
,
3475 enum dwarf_attribute
,
3477 static void add_AT_string
PARAMS ((dw_die_ref
,
3478 enum dwarf_attribute
,
3480 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3481 static int AT_string_form
PARAMS ((dw_attr_ref
));
3482 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3483 enum dwarf_attribute
,
3485 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3486 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3487 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3488 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3489 enum dwarf_attribute
,
3491 static void add_AT_loc
PARAMS ((dw_die_ref
,
3492 enum dwarf_attribute
,
3494 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3495 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3496 enum dwarf_attribute
,
3498 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3499 static void add_AT_addr
PARAMS ((dw_die_ref
,
3500 enum dwarf_attribute
,
3502 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3503 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3504 enum dwarf_attribute
,
3506 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3507 enum dwarf_attribute
,
3509 static void add_AT_offset
PARAMS ((dw_die_ref
,
3510 enum dwarf_attribute
,
3512 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3513 enum dwarf_attribute
,
3515 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3516 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3517 enum dwarf_attribute
));
3518 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3519 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3520 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3521 enum dwarf_attribute
));
3522 static int get_AT_flag
PARAMS ((dw_die_ref
,
3523 enum dwarf_attribute
));
3524 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3525 enum dwarf_attribute
));
3526 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3527 enum dwarf_attribute
));
3528 static int is_c_family
PARAMS ((void));
3529 static int is_cxx
PARAMS ((void));
3530 static int is_java
PARAMS ((void));
3531 static int is_fortran
PARAMS ((void));
3532 static void remove_AT
PARAMS ((dw_die_ref
,
3533 enum dwarf_attribute
));
3534 static inline void free_die
PARAMS ((dw_die_ref
));
3535 static void remove_children
PARAMS ((dw_die_ref
));
3536 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3537 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3539 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3540 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3541 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3542 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3543 static void print_spaces
PARAMS ((FILE *));
3544 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3545 static void print_dwarf_line_table
PARAMS ((FILE *));
3546 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3547 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3548 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3549 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3550 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3552 static void attr_checksum
PARAMS ((dw_attr_ref
,
3554 static void die_checksum
PARAMS ((dw_die_ref
,
3556 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3557 static int is_type_die
PARAMS ((dw_die_ref
));
3558 static int is_comdat_die
PARAMS ((dw_die_ref
));
3559 static int is_symbol_die
PARAMS ((dw_die_ref
));
3560 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3561 static void break_out_includes
PARAMS ((dw_die_ref
));
3562 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3563 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3564 static void output_location_lists
PARAMS ((dw_die_ref
));
3565 static int constant_size
PARAMS ((long unsigned));
3566 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3567 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3568 static void mark_dies
PARAMS ((dw_die_ref
));
3569 static void unmark_dies
PARAMS ((dw_die_ref
));
3570 static unsigned long size_of_pubnames
PARAMS ((void));
3571 static unsigned long size_of_aranges
PARAMS ((void));
3572 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3573 static void output_value_format
PARAMS ((dw_attr_ref
));
3574 static void output_abbrev_section
PARAMS ((void));
3575 static void output_die_symbol
PARAMS ((dw_die_ref
));
3576 static void output_die
PARAMS ((dw_die_ref
));
3577 static void output_compilation_unit_header
PARAMS ((void));
3578 static void output_comp_unit
PARAMS ((dw_die_ref
));
3579 static const char *dwarf2_name
PARAMS ((tree
, int));
3580 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3581 static void output_pubnames
PARAMS ((void));
3582 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3583 static void output_aranges
PARAMS ((void));
3584 static unsigned int add_ranges
PARAMS ((tree
));
3585 static void output_ranges
PARAMS ((void));
3586 static void output_line_info
PARAMS ((void));
3587 static void output_file_names
PARAMS ((void));
3588 static dw_die_ref base_type_die
PARAMS ((tree
));
3589 static tree root_type
PARAMS ((tree
));
3590 static int is_base_type
PARAMS ((tree
));
3591 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3592 static int type_is_enum
PARAMS ((tree
));
3593 static unsigned int reg_number
PARAMS ((rtx
));
3594 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3595 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3596 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3597 static int is_based_loc
PARAMS ((rtx
));
3598 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3599 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3600 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3601 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3602 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3603 static tree field_type
PARAMS ((tree
));
3604 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3605 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3606 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3607 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3608 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3609 enum dwarf_attribute
, rtx
));
3610 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3611 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3612 static rtx rtl_for_decl_location
PARAMS ((tree
));
3613 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3614 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3615 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3616 static void add_bound_info
PARAMS ((dw_die_ref
,
3617 enum dwarf_attribute
, tree
));
3618 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3619 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3620 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3621 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3622 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3623 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3624 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3625 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3626 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3627 static void push_decl_scope
PARAMS ((tree
));
3628 static void pop_decl_scope
PARAMS ((void));
3629 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3630 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3631 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3632 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3634 static const char *type_tag
PARAMS ((tree
));
3635 static tree member_declared_type
PARAMS ((tree
));
3637 static const char *decl_start_label
PARAMS ((tree
));
3639 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3640 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3642 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3644 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3645 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3646 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3647 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3648 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3649 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3650 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3651 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3652 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3653 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3654 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3655 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3656 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3657 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3658 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3659 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3660 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3661 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3662 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3663 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3664 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3665 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3666 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3667 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3668 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3669 static int is_redundant_typedef
PARAMS ((tree
));
3670 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3671 static unsigned lookup_filename
PARAMS ((const char *));
3672 static void init_file_table
PARAMS ((void));
3673 static void retry_incomplete_types
PARAMS ((void));
3674 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3675 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3676 static int file_info_cmp
PARAMS ((const void *, const void *));
3677 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3678 const char *, const char *,
3679 const char *, unsigned));
3680 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3682 const char *, const char *, const char *));
3683 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3684 static char *gen_internal_sym
PARAMS ((const char *));
3685 static void mark_limbo_die_list
PARAMS ((void *));
3687 /* Section names used to hold DWARF debugging information. */
3688 #ifndef DEBUG_INFO_SECTION
3689 #define DEBUG_INFO_SECTION ".debug_info"
3691 #ifndef DEBUG_ABBREV_SECTION
3692 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3694 #ifndef DEBUG_ARANGES_SECTION
3695 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3697 #ifndef DEBUG_MACINFO_SECTION
3698 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3700 #ifndef DEBUG_LINE_SECTION
3701 #define DEBUG_LINE_SECTION ".debug_line"
3703 #ifndef DEBUG_LOC_SECTION
3704 #define DEBUG_LOC_SECTION ".debug_loc"
3706 #ifndef DEBUG_PUBNAMES_SECTION
3707 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3709 #ifndef DEBUG_STR_SECTION
3710 #define DEBUG_STR_SECTION ".debug_str"
3712 #ifndef DEBUG_RANGES_SECTION
3713 #define DEBUG_RANGES_SECTION ".debug_ranges"
3716 /* Standard ELF section names for compiled code and data. */
3717 #ifndef TEXT_SECTION_NAME
3718 #define TEXT_SECTION_NAME ".text"
3721 /* Section flags for .debug_str section. */
3722 #ifdef HAVE_GAS_SHF_MERGE
3723 #define DEBUG_STR_SECTION_FLAGS \
3724 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3726 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3729 /* Labels we insert at beginning sections we can reference instead of
3730 the section names themselves. */
3732 #ifndef TEXT_SECTION_LABEL
3733 #define TEXT_SECTION_LABEL "Ltext"
3735 #ifndef DEBUG_LINE_SECTION_LABEL
3736 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3738 #ifndef DEBUG_INFO_SECTION_LABEL
3739 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3741 #ifndef DEBUG_ABBREV_SECTION_LABEL
3742 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3744 #ifndef DEBUG_LOC_SECTION_LABEL
3745 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3747 #ifndef DEBUG_RANGES_SECTION_LABEL
3748 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3750 #ifndef DEBUG_MACINFO_SECTION_LABEL
3751 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3754 /* Definitions of defaults for formats and names of various special
3755 (artificial) labels which may be generated within this file (when the -g
3756 options is used and DWARF_DEBUGGING_INFO is in effect.
3757 If necessary, these may be overridden from within the tm.h file, but
3758 typically, overriding these defaults is unnecessary. */
3760 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3761 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3762 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3763 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3764 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3765 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3766 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3767 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3769 #ifndef TEXT_END_LABEL
3770 #define TEXT_END_LABEL "Letext"
3772 #ifndef DATA_END_LABEL
3773 #define DATA_END_LABEL "Ledata"
3775 #ifndef BSS_END_LABEL
3776 #define BSS_END_LABEL "Lebss"
3778 #ifndef BLOCK_BEGIN_LABEL
3779 #define BLOCK_BEGIN_LABEL "LBB"
3781 #ifndef BLOCK_END_LABEL
3782 #define BLOCK_END_LABEL "LBE"
3784 #ifndef BODY_BEGIN_LABEL
3785 #define BODY_BEGIN_LABEL "Lbb"
3787 #ifndef BODY_END_LABEL
3788 #define BODY_END_LABEL "Lbe"
3790 #ifndef LINE_CODE_LABEL
3791 #define LINE_CODE_LABEL "LM"
3793 #ifndef SEPARATE_LINE_CODE_LABEL
3794 #define SEPARATE_LINE_CODE_LABEL "LSM"
3797 /* We allow a language front-end to designate a function that is to be
3798 called to "demangle" any name before it it put into a DIE. */
3800 static const char *(*demangle_name_func
) PARAMS ((const char *));
3803 dwarf2out_set_demangle_name_func (func
)
3804 const char *(*func
) PARAMS ((const char *));
3806 demangle_name_func
= func
;
3809 /* Test if rtl node points to a pseudo register. */
3815 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3816 || (GET_CODE (rtl
) == SUBREG
3817 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3820 /* Return a reference to a type, with its const and volatile qualifiers
3824 type_main_variant (type
)
3827 type
= TYPE_MAIN_VARIANT (type
);
3829 /* ??? There really should be only one main variant among any group of
3830 variants of a given type (and all of the MAIN_VARIANT values for all
3831 members of the group should point to that one type) but sometimes the C
3832 front-end messes this up for array types, so we work around that bug
3834 if (TREE_CODE (type
) == ARRAY_TYPE
)
3835 while (type
!= TYPE_MAIN_VARIANT (type
))
3836 type
= TYPE_MAIN_VARIANT (type
);
3841 /* Return non-zero if the given type node represents a tagged type. */
3844 is_tagged_type (type
)
3847 enum tree_code code
= TREE_CODE (type
);
3849 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3850 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3853 /* Convert a DIE tag into its string name. */
3856 dwarf_tag_name (tag
)
3861 case DW_TAG_padding
:
3862 return "DW_TAG_padding";
3863 case DW_TAG_array_type
:
3864 return "DW_TAG_array_type";
3865 case DW_TAG_class_type
:
3866 return "DW_TAG_class_type";
3867 case DW_TAG_entry_point
:
3868 return "DW_TAG_entry_point";
3869 case DW_TAG_enumeration_type
:
3870 return "DW_TAG_enumeration_type";
3871 case DW_TAG_formal_parameter
:
3872 return "DW_TAG_formal_parameter";
3873 case DW_TAG_imported_declaration
:
3874 return "DW_TAG_imported_declaration";
3876 return "DW_TAG_label";
3877 case DW_TAG_lexical_block
:
3878 return "DW_TAG_lexical_block";
3880 return "DW_TAG_member";
3881 case DW_TAG_pointer_type
:
3882 return "DW_TAG_pointer_type";
3883 case DW_TAG_reference_type
:
3884 return "DW_TAG_reference_type";
3885 case DW_TAG_compile_unit
:
3886 return "DW_TAG_compile_unit";
3887 case DW_TAG_string_type
:
3888 return "DW_TAG_string_type";
3889 case DW_TAG_structure_type
:
3890 return "DW_TAG_structure_type";
3891 case DW_TAG_subroutine_type
:
3892 return "DW_TAG_subroutine_type";
3893 case DW_TAG_typedef
:
3894 return "DW_TAG_typedef";
3895 case DW_TAG_union_type
:
3896 return "DW_TAG_union_type";
3897 case DW_TAG_unspecified_parameters
:
3898 return "DW_TAG_unspecified_parameters";
3899 case DW_TAG_variant
:
3900 return "DW_TAG_variant";
3901 case DW_TAG_common_block
:
3902 return "DW_TAG_common_block";
3903 case DW_TAG_common_inclusion
:
3904 return "DW_TAG_common_inclusion";
3905 case DW_TAG_inheritance
:
3906 return "DW_TAG_inheritance";
3907 case DW_TAG_inlined_subroutine
:
3908 return "DW_TAG_inlined_subroutine";
3910 return "DW_TAG_module";
3911 case DW_TAG_ptr_to_member_type
:
3912 return "DW_TAG_ptr_to_member_type";
3913 case DW_TAG_set_type
:
3914 return "DW_TAG_set_type";
3915 case DW_TAG_subrange_type
:
3916 return "DW_TAG_subrange_type";
3917 case DW_TAG_with_stmt
:
3918 return "DW_TAG_with_stmt";
3919 case DW_TAG_access_declaration
:
3920 return "DW_TAG_access_declaration";
3921 case DW_TAG_base_type
:
3922 return "DW_TAG_base_type";
3923 case DW_TAG_catch_block
:
3924 return "DW_TAG_catch_block";
3925 case DW_TAG_const_type
:
3926 return "DW_TAG_const_type";
3927 case DW_TAG_constant
:
3928 return "DW_TAG_constant";
3929 case DW_TAG_enumerator
:
3930 return "DW_TAG_enumerator";
3931 case DW_TAG_file_type
:
3932 return "DW_TAG_file_type";
3934 return "DW_TAG_friend";
3935 case DW_TAG_namelist
:
3936 return "DW_TAG_namelist";
3937 case DW_TAG_namelist_item
:
3938 return "DW_TAG_namelist_item";
3939 case DW_TAG_packed_type
:
3940 return "DW_TAG_packed_type";
3941 case DW_TAG_subprogram
:
3942 return "DW_TAG_subprogram";
3943 case DW_TAG_template_type_param
:
3944 return "DW_TAG_template_type_param";
3945 case DW_TAG_template_value_param
:
3946 return "DW_TAG_template_value_param";
3947 case DW_TAG_thrown_type
:
3948 return "DW_TAG_thrown_type";
3949 case DW_TAG_try_block
:
3950 return "DW_TAG_try_block";
3951 case DW_TAG_variant_part
:
3952 return "DW_TAG_variant_part";
3953 case DW_TAG_variable
:
3954 return "DW_TAG_variable";
3955 case DW_TAG_volatile_type
:
3956 return "DW_TAG_volatile_type";
3957 case DW_TAG_MIPS_loop
:
3958 return "DW_TAG_MIPS_loop";
3959 case DW_TAG_format_label
:
3960 return "DW_TAG_format_label";
3961 case DW_TAG_function_template
:
3962 return "DW_TAG_function_template";
3963 case DW_TAG_class_template
:
3964 return "DW_TAG_class_template";
3965 case DW_TAG_GNU_BINCL
:
3966 return "DW_TAG_GNU_BINCL";
3967 case DW_TAG_GNU_EINCL
:
3968 return "DW_TAG_GNU_EINCL";
3970 return "DW_TAG_<unknown>";
3974 /* Convert a DWARF attribute code into its string name. */
3977 dwarf_attr_name (attr
)
3983 return "DW_AT_sibling";
3984 case DW_AT_location
:
3985 return "DW_AT_location";
3987 return "DW_AT_name";
3988 case DW_AT_ordering
:
3989 return "DW_AT_ordering";
3990 case DW_AT_subscr_data
:
3991 return "DW_AT_subscr_data";
3992 case DW_AT_byte_size
:
3993 return "DW_AT_byte_size";
3994 case DW_AT_bit_offset
:
3995 return "DW_AT_bit_offset";
3996 case DW_AT_bit_size
:
3997 return "DW_AT_bit_size";
3998 case DW_AT_element_list
:
3999 return "DW_AT_element_list";
4000 case DW_AT_stmt_list
:
4001 return "DW_AT_stmt_list";
4003 return "DW_AT_low_pc";
4005 return "DW_AT_high_pc";
4006 case DW_AT_language
:
4007 return "DW_AT_language";
4009 return "DW_AT_member";
4011 return "DW_AT_discr";
4012 case DW_AT_discr_value
:
4013 return "DW_AT_discr_value";
4014 case DW_AT_visibility
:
4015 return "DW_AT_visibility";
4017 return "DW_AT_import";
4018 case DW_AT_string_length
:
4019 return "DW_AT_string_length";
4020 case DW_AT_common_reference
:
4021 return "DW_AT_common_reference";
4022 case DW_AT_comp_dir
:
4023 return "DW_AT_comp_dir";
4024 case DW_AT_const_value
:
4025 return "DW_AT_const_value";
4026 case DW_AT_containing_type
:
4027 return "DW_AT_containing_type";
4028 case DW_AT_default_value
:
4029 return "DW_AT_default_value";
4031 return "DW_AT_inline";
4032 case DW_AT_is_optional
:
4033 return "DW_AT_is_optional";
4034 case DW_AT_lower_bound
:
4035 return "DW_AT_lower_bound";
4036 case DW_AT_producer
:
4037 return "DW_AT_producer";
4038 case DW_AT_prototyped
:
4039 return "DW_AT_prototyped";
4040 case DW_AT_return_addr
:
4041 return "DW_AT_return_addr";
4042 case DW_AT_start_scope
:
4043 return "DW_AT_start_scope";
4044 case DW_AT_stride_size
:
4045 return "DW_AT_stride_size";
4046 case DW_AT_upper_bound
:
4047 return "DW_AT_upper_bound";
4048 case DW_AT_abstract_origin
:
4049 return "DW_AT_abstract_origin";
4050 case DW_AT_accessibility
:
4051 return "DW_AT_accessibility";
4052 case DW_AT_address_class
:
4053 return "DW_AT_address_class";
4054 case DW_AT_artificial
:
4055 return "DW_AT_artificial";
4056 case DW_AT_base_types
:
4057 return "DW_AT_base_types";
4058 case DW_AT_calling_convention
:
4059 return "DW_AT_calling_convention";
4061 return "DW_AT_count";
4062 case DW_AT_data_member_location
:
4063 return "DW_AT_data_member_location";
4064 case DW_AT_decl_column
:
4065 return "DW_AT_decl_column";
4066 case DW_AT_decl_file
:
4067 return "DW_AT_decl_file";
4068 case DW_AT_decl_line
:
4069 return "DW_AT_decl_line";
4070 case DW_AT_declaration
:
4071 return "DW_AT_declaration";
4072 case DW_AT_discr_list
:
4073 return "DW_AT_discr_list";
4074 case DW_AT_encoding
:
4075 return "DW_AT_encoding";
4076 case DW_AT_external
:
4077 return "DW_AT_external";
4078 case DW_AT_frame_base
:
4079 return "DW_AT_frame_base";
4081 return "DW_AT_friend";
4082 case DW_AT_identifier_case
:
4083 return "DW_AT_identifier_case";
4084 case DW_AT_macro_info
:
4085 return "DW_AT_macro_info";
4086 case DW_AT_namelist_items
:
4087 return "DW_AT_namelist_items";
4088 case DW_AT_priority
:
4089 return "DW_AT_priority";
4091 return "DW_AT_segment";
4092 case DW_AT_specification
:
4093 return "DW_AT_specification";
4094 case DW_AT_static_link
:
4095 return "DW_AT_static_link";
4097 return "DW_AT_type";
4098 case DW_AT_use_location
:
4099 return "DW_AT_use_location";
4100 case DW_AT_variable_parameter
:
4101 return "DW_AT_variable_parameter";
4102 case DW_AT_virtuality
:
4103 return "DW_AT_virtuality";
4104 case DW_AT_vtable_elem_location
:
4105 return "DW_AT_vtable_elem_location";
4107 case DW_AT_allocated
:
4108 return "DW_AT_allocated";
4109 case DW_AT_associated
:
4110 return "DW_AT_associated";
4111 case DW_AT_data_location
:
4112 return "DW_AT_data_location";
4114 return "DW_AT_stride";
4115 case DW_AT_entry_pc
:
4116 return "DW_AT_entry_pc";
4117 case DW_AT_use_UTF8
:
4118 return "DW_AT_use_UTF8";
4119 case DW_AT_extension
:
4120 return "DW_AT_extension";
4122 return "DW_AT_ranges";
4123 case DW_AT_trampoline
:
4124 return "DW_AT_trampoline";
4125 case DW_AT_call_column
:
4126 return "DW_AT_call_column";
4127 case DW_AT_call_file
:
4128 return "DW_AT_call_file";
4129 case DW_AT_call_line
:
4130 return "DW_AT_call_line";
4132 case DW_AT_MIPS_fde
:
4133 return "DW_AT_MIPS_fde";
4134 case DW_AT_MIPS_loop_begin
:
4135 return "DW_AT_MIPS_loop_begin";
4136 case DW_AT_MIPS_tail_loop_begin
:
4137 return "DW_AT_MIPS_tail_loop_begin";
4138 case DW_AT_MIPS_epilog_begin
:
4139 return "DW_AT_MIPS_epilog_begin";
4140 case DW_AT_MIPS_loop_unroll_factor
:
4141 return "DW_AT_MIPS_loop_unroll_factor";
4142 case DW_AT_MIPS_software_pipeline_depth
:
4143 return "DW_AT_MIPS_software_pipeline_depth";
4144 case DW_AT_MIPS_linkage_name
:
4145 return "DW_AT_MIPS_linkage_name";
4146 case DW_AT_MIPS_stride
:
4147 return "DW_AT_MIPS_stride";
4148 case DW_AT_MIPS_abstract_name
:
4149 return "DW_AT_MIPS_abstract_name";
4150 case DW_AT_MIPS_clone_origin
:
4151 return "DW_AT_MIPS_clone_origin";
4152 case DW_AT_MIPS_has_inlines
:
4153 return "DW_AT_MIPS_has_inlines";
4155 case DW_AT_sf_names
:
4156 return "DW_AT_sf_names";
4157 case DW_AT_src_info
:
4158 return "DW_AT_src_info";
4159 case DW_AT_mac_info
:
4160 return "DW_AT_mac_info";
4161 case DW_AT_src_coords
:
4162 return "DW_AT_src_coords";
4163 case DW_AT_body_begin
:
4164 return "DW_AT_body_begin";
4165 case DW_AT_body_end
:
4166 return "DW_AT_body_end";
4167 case DW_AT_VMS_rtnbeg_pd_address
:
4168 return "DW_AT_VMS_rtnbeg_pd_address";
4171 return "DW_AT_<unknown>";
4175 /* Convert a DWARF value form code into its string name. */
4178 dwarf_form_name (form
)
4184 return "DW_FORM_addr";
4185 case DW_FORM_block2
:
4186 return "DW_FORM_block2";
4187 case DW_FORM_block4
:
4188 return "DW_FORM_block4";
4190 return "DW_FORM_data2";
4192 return "DW_FORM_data4";
4194 return "DW_FORM_data8";
4195 case DW_FORM_string
:
4196 return "DW_FORM_string";
4198 return "DW_FORM_block";
4199 case DW_FORM_block1
:
4200 return "DW_FORM_block1";
4202 return "DW_FORM_data1";
4204 return "DW_FORM_flag";
4206 return "DW_FORM_sdata";
4208 return "DW_FORM_strp";
4210 return "DW_FORM_udata";
4211 case DW_FORM_ref_addr
:
4212 return "DW_FORM_ref_addr";
4214 return "DW_FORM_ref1";
4216 return "DW_FORM_ref2";
4218 return "DW_FORM_ref4";
4220 return "DW_FORM_ref8";
4221 case DW_FORM_ref_udata
:
4222 return "DW_FORM_ref_udata";
4223 case DW_FORM_indirect
:
4224 return "DW_FORM_indirect";
4226 return "DW_FORM_<unknown>";
4230 /* Convert a DWARF type code into its string name. */
4234 dwarf_type_encoding_name (enc
)
4239 case DW_ATE_address
:
4240 return "DW_ATE_address";
4241 case DW_ATE_boolean
:
4242 return "DW_ATE_boolean";
4243 case DW_ATE_complex_float
:
4244 return "DW_ATE_complex_float";
4246 return "DW_ATE_float";
4248 return "DW_ATE_signed";
4249 case DW_ATE_signed_char
:
4250 return "DW_ATE_signed_char";
4251 case DW_ATE_unsigned
:
4252 return "DW_ATE_unsigned";
4253 case DW_ATE_unsigned_char
:
4254 return "DW_ATE_unsigned_char";
4256 return "DW_ATE_<unknown>";
4261 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4262 instance of an inlined instance of a decl which is local to an inline
4263 function, so we have to trace all of the way back through the origin chain
4264 to find out what sort of node actually served as the original seed for the
4268 decl_ultimate_origin (decl
)
4271 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4272 nodes in the function to point to themselves; ignore that if
4273 we're trying to output the abstract instance of this function. */
4274 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4277 #ifdef ENABLE_CHECKING
4278 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4279 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4280 most distant ancestor, this should never happen. */
4284 return DECL_ABSTRACT_ORIGIN (decl
);
4287 /* Determine the "ultimate origin" of a block. The block may be an inlined
4288 instance of an inlined instance of a block which is local to an inline
4289 function, so we have to trace all of the way back through the origin chain
4290 to find out what sort of node actually served as the original seed for the
4294 block_ultimate_origin (block
)
4297 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4299 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4300 nodes in the function to point to themselves; ignore that if
4301 we're trying to output the abstract instance of this function. */
4302 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4305 if (immediate_origin
== NULL_TREE
)
4310 tree lookahead
= immediate_origin
;
4314 ret_val
= lookahead
;
4315 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4316 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4318 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4324 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4325 of a virtual function may refer to a base class, so we check the 'this'
4329 decl_class_context (decl
)
4332 tree context
= NULL_TREE
;
4334 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4335 context
= DECL_CONTEXT (decl
);
4337 context
= TYPE_MAIN_VARIANT
4338 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4340 if (context
&& !TYPE_P (context
))
4341 context
= NULL_TREE
;
4346 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4347 addition order, and correct that in reverse_all_dies. */
4350 add_dwarf_attr (die
, attr
)
4354 if (die
!= NULL
&& attr
!= NULL
)
4356 attr
->dw_attr_next
= die
->die_attr
;
4357 die
->die_attr
= attr
;
4361 static inline dw_val_class
4365 return a
->dw_attr_val
.val_class
;
4368 /* Add a flag value attribute to a DIE. */
4371 add_AT_flag (die
, attr_kind
, flag
)
4373 enum dwarf_attribute attr_kind
;
4376 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4378 attr
->dw_attr_next
= NULL
;
4379 attr
->dw_attr
= attr_kind
;
4380 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4381 attr
->dw_attr_val
.v
.val_flag
= flag
;
4382 add_dwarf_attr (die
, attr
);
4385 static inline unsigned
4389 if (a
&& AT_class (a
) == dw_val_class_flag
)
4390 return a
->dw_attr_val
.v
.val_flag
;
4395 /* Add a signed integer attribute value to a DIE. */
4398 add_AT_int (die
, attr_kind
, int_val
)
4400 enum dwarf_attribute attr_kind
;
4403 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4405 attr
->dw_attr_next
= NULL
;
4406 attr
->dw_attr
= attr_kind
;
4407 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4408 attr
->dw_attr_val
.v
.val_int
= int_val
;
4409 add_dwarf_attr (die
, attr
);
4412 static inline long int
4416 if (a
&& AT_class (a
) == dw_val_class_const
)
4417 return a
->dw_attr_val
.v
.val_int
;
4422 /* Add an unsigned integer attribute value to a DIE. */
4425 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4427 enum dwarf_attribute attr_kind
;
4428 unsigned long unsigned_val
;
4430 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4432 attr
->dw_attr_next
= NULL
;
4433 attr
->dw_attr
= attr_kind
;
4434 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4435 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4436 add_dwarf_attr (die
, attr
);
4439 static inline unsigned long
4443 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4444 return a
->dw_attr_val
.v
.val_unsigned
;
4449 /* Add an unsigned double integer attribute value to a DIE. */
4452 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4454 enum dwarf_attribute attr_kind
;
4455 unsigned long val_hi
;
4456 unsigned long val_low
;
4458 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4460 attr
->dw_attr_next
= NULL
;
4461 attr
->dw_attr
= attr_kind
;
4462 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4463 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4464 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4465 add_dwarf_attr (die
, attr
);
4468 /* Add a floating point attribute value to a DIE and return it. */
4471 add_AT_float (die
, attr_kind
, length
, array
)
4473 enum dwarf_attribute attr_kind
;
4477 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4479 attr
->dw_attr_next
= NULL
;
4480 attr
->dw_attr
= attr_kind
;
4481 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4482 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4483 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4484 add_dwarf_attr (die
, attr
);
4487 /* Add a string attribute value to a DIE. */
4490 add_AT_string (die
, attr_kind
, str
)
4492 enum dwarf_attribute attr_kind
;
4495 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4496 struct indirect_string_node
*node
;
4498 if (! debug_str_hash
)
4500 debug_str_hash
= ht_create (10);
4501 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4504 node
= (struct indirect_string_node
*)
4505 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4506 strlen (str
), HT_ALLOC
);
4509 attr
->dw_attr_next
= NULL
;
4510 attr
->dw_attr
= attr_kind
;
4511 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4512 attr
->dw_attr_val
.v
.val_str
= node
;
4513 add_dwarf_attr (die
, attr
);
4516 static inline const char *
4520 if (a
&& AT_class (a
) == dw_val_class_str
)
4521 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4526 /* Find out whether a string should be output inline in DIE
4527 or out-of-line in .debug_str section. */
4533 if (a
&& AT_class (a
) == dw_val_class_str
)
4535 struct indirect_string_node
*node
;
4537 extern int const_labelno
;
4540 node
= a
->dw_attr_val
.v
.val_str
;
4544 len
= HT_LEN (&node
->id
) + 1;
4546 /* If the string is shorter or equal to the size of the reference, it is
4547 always better to put it inline. */
4548 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4549 return node
->form
= DW_FORM_string
;
4551 /* If we cannot expect the linker to merge strings in .debug_str
4552 section, only put it into .debug_str if it is worth even in this
4554 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4555 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4556 return node
->form
= DW_FORM_string
;
4558 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4560 node
->label
= xstrdup (label
);
4562 return node
->form
= DW_FORM_strp
;
4568 /* Add a DIE reference attribute value to a DIE. */
4571 add_AT_die_ref (die
, attr_kind
, targ_die
)
4573 enum dwarf_attribute attr_kind
;
4574 dw_die_ref targ_die
;
4576 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4578 attr
->dw_attr_next
= NULL
;
4579 attr
->dw_attr
= attr_kind
;
4580 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4581 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4582 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4583 add_dwarf_attr (die
, attr
);
4586 static inline dw_die_ref
4590 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4591 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4600 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4601 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4607 set_AT_ref_external (a
, i
)
4611 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4612 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4617 /* Add an FDE reference attribute value to a DIE. */
4620 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4622 enum dwarf_attribute attr_kind
;
4625 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4627 attr
->dw_attr_next
= NULL
;
4628 attr
->dw_attr
= attr_kind
;
4629 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4630 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4631 add_dwarf_attr (die
, attr
);
4634 /* Add a location description attribute value to a DIE. */
4637 add_AT_loc (die
, attr_kind
, loc
)
4639 enum dwarf_attribute attr_kind
;
4640 dw_loc_descr_ref loc
;
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
;
4647 attr
->dw_attr_val
.v
.val_loc
= loc
;
4648 add_dwarf_attr (die
, attr
);
4651 static inline dw_loc_descr_ref
4655 if (a
&& AT_class (a
) == dw_val_class_loc
)
4656 return a
->dw_attr_val
.v
.val_loc
;
4662 add_AT_loc_list (die
, attr_kind
, loc_list
)
4664 enum dwarf_attribute attr_kind
;
4665 dw_loc_list_ref loc_list
;
4667 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4669 attr
->dw_attr_next
= NULL
;
4670 attr
->dw_attr
= attr_kind
;
4671 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4672 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4673 add_dwarf_attr (die
, attr
);
4674 have_location_lists
= 1;
4677 static inline dw_loc_list_ref
4681 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4682 return a
->dw_attr_val
.v
.val_loc_list
;
4687 /* Add an address constant attribute value to a DIE. */
4690 add_AT_addr (die
, attr_kind
, addr
)
4692 enum dwarf_attribute attr_kind
;
4695 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4697 attr
->dw_attr_next
= NULL
;
4698 attr
->dw_attr
= attr_kind
;
4699 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4700 attr
->dw_attr_val
.v
.val_addr
= addr
;
4701 add_dwarf_attr (die
, attr
);
4708 if (a
&& AT_class (a
) == dw_val_class_addr
)
4709 return a
->dw_attr_val
.v
.val_addr
;
4714 /* Add a label identifier attribute value to a DIE. */
4717 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4719 enum dwarf_attribute attr_kind
;
4722 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4724 attr
->dw_attr_next
= NULL
;
4725 attr
->dw_attr
= attr_kind
;
4726 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4727 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4728 add_dwarf_attr (die
, attr
);
4731 /* Add a section offset attribute value to a DIE. */
4734 add_AT_lbl_offset (die
, attr_kind
, label
)
4736 enum dwarf_attribute attr_kind
;
4739 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4741 attr
->dw_attr_next
= NULL
;
4742 attr
->dw_attr
= attr_kind
;
4743 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4744 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4745 add_dwarf_attr (die
, attr
);
4748 /* Add an offset attribute value to a DIE. */
4751 add_AT_offset (die
, attr_kind
, offset
)
4753 enum dwarf_attribute attr_kind
;
4754 unsigned long offset
;
4756 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4758 attr
->dw_attr_next
= NULL
;
4759 attr
->dw_attr
= attr_kind
;
4760 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4761 attr
->dw_attr_val
.v
.val_offset
= offset
;
4762 add_dwarf_attr (die
, attr
);
4765 /* Add an range_list attribute value to a DIE. */
4768 add_AT_range_list (die
, attr_kind
, offset
)
4770 enum dwarf_attribute attr_kind
;
4771 unsigned long offset
;
4773 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4775 attr
->dw_attr_next
= NULL
;
4776 attr
->dw_attr
= attr_kind
;
4777 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4778 attr
->dw_attr_val
.v
.val_offset
= offset
;
4779 add_dwarf_attr (die
, attr
);
4782 static inline const char *
4786 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4787 || AT_class (a
) == dw_val_class_lbl_offset
))
4788 return a
->dw_attr_val
.v
.val_lbl_id
;
4793 /* Get the attribute of type attr_kind. */
4795 static inline dw_attr_ref
4796 get_AT (die
, attr_kind
)
4798 enum dwarf_attribute attr_kind
;
4801 dw_die_ref spec
= NULL
;
4805 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4806 if (a
->dw_attr
== attr_kind
)
4808 else if (a
->dw_attr
== DW_AT_specification
4809 || a
->dw_attr
== DW_AT_abstract_origin
)
4813 return get_AT (spec
, attr_kind
);
4819 /* Return the "low pc" attribute value, typically associated with a subprogram
4820 DIE. Return null if the "low pc" attribute is either not present, or if it
4821 cannot be represented as an assembler label identifier. */
4823 static inline const char *
4827 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4829 return a
? AT_lbl (a
) : NULL
;
4832 /* Return the "high pc" attribute value, typically associated with a subprogram
4833 DIE. Return null if the "high pc" attribute is either not present, or if it
4834 cannot be represented as an assembler label identifier. */
4836 static inline const char *
4840 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4842 return a
? AT_lbl (a
) : NULL
;
4845 /* Return the value of the string attribute designated by ATTR_KIND, or
4846 NULL if it is not present. */
4848 static inline const char *
4849 get_AT_string (die
, attr_kind
)
4851 enum dwarf_attribute attr_kind
;
4853 dw_attr_ref a
= get_AT (die
, attr_kind
);
4855 return a
? AT_string (a
) : NULL
;
4858 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4859 if it is not present. */
4862 get_AT_flag (die
, attr_kind
)
4864 enum dwarf_attribute attr_kind
;
4866 dw_attr_ref a
= get_AT (die
, attr_kind
);
4868 return a
? AT_flag (a
) : 0;
4871 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4872 if it is not present. */
4874 static inline unsigned
4875 get_AT_unsigned (die
, attr_kind
)
4877 enum dwarf_attribute attr_kind
;
4879 dw_attr_ref a
= get_AT (die
, attr_kind
);
4881 return a
? AT_unsigned (a
) : 0;
4884 static inline dw_die_ref
4885 get_AT_ref (die
, attr_kind
)
4887 enum dwarf_attribute attr_kind
;
4889 dw_attr_ref a
= get_AT (die
, attr_kind
);
4891 return a
? AT_ref (a
) : NULL
;
4897 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4899 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4900 || lang
== DW_LANG_C_plus_plus
);
4906 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4907 == DW_LANG_C_plus_plus
);
4913 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4915 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4921 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4923 return (lang
== DW_LANG_Java
);
4926 /* Free up the memory used by A. */
4928 static inline void free_AT
PARAMS ((dw_attr_ref
));
4933 switch (AT_class (a
))
4935 case dw_val_class_str
:
4936 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4937 a
->dw_attr_val
.v
.val_str
->refcount
--;
4940 case dw_val_class_lbl_id
:
4941 case dw_val_class_lbl_offset
:
4942 free (a
->dw_attr_val
.v
.val_lbl_id
);
4945 case dw_val_class_float
:
4946 free (a
->dw_attr_val
.v
.val_float
.array
);
4956 /* Remove the specified attribute if present. */
4959 remove_AT (die
, attr_kind
)
4961 enum dwarf_attribute attr_kind
;
4964 dw_attr_ref removed
= NULL
;
4968 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4969 if ((*p
)->dw_attr
== attr_kind
)
4972 *p
= (*p
)->dw_attr_next
;
4981 /* Free up the memory used by DIE. */
4987 remove_children (die
);
4991 /* Discard the children of this DIE. */
4994 remove_children (die
)
4997 dw_die_ref child_die
= die
->die_child
;
4999 die
->die_child
= NULL
;
5001 while (child_die
!= NULL
)
5003 dw_die_ref tmp_die
= child_die
;
5006 child_die
= child_die
->die_sib
;
5008 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5010 dw_attr_ref tmp_a
= a
;
5012 a
= a
->dw_attr_next
;
5020 /* Add a child DIE below its parent. We build the lists up in reverse
5021 addition order, and correct that in reverse_all_dies. */
5024 add_child_die (die
, child_die
)
5026 dw_die_ref child_die
;
5028 if (die
!= NULL
&& child_die
!= NULL
)
5030 if (die
== child_die
)
5033 child_die
->die_parent
= die
;
5034 child_die
->die_sib
= die
->die_child
;
5035 die
->die_child
= child_die
;
5039 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5040 is the specification, to the front of PARENT's list of children. */
5043 splice_child_die (parent
, child
)
5044 dw_die_ref parent
, child
;
5048 /* We want the declaration DIE from inside the class, not the
5049 specification DIE at toplevel. */
5050 if (child
->die_parent
!= parent
)
5052 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5058 if (child
->die_parent
!= parent
5059 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5062 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5065 *p
= child
->die_sib
;
5069 child
->die_sib
= parent
->die_child
;
5070 parent
->die_child
= child
;
5073 /* Return a pointer to a newly created DIE node. */
5075 static inline dw_die_ref
5076 new_die (tag_value
, parent_die
, t
)
5077 enum dwarf_tag tag_value
;
5078 dw_die_ref parent_die
;
5081 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5083 die
->die_tag
= tag_value
;
5085 if (parent_die
!= NULL
)
5086 add_child_die (parent_die
, die
);
5089 limbo_die_node
*limbo_node
;
5091 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5092 limbo_node
->die
= die
;
5093 limbo_node
->created_for
= t
;
5094 limbo_node
->next
= limbo_die_list
;
5095 limbo_die_list
= limbo_node
;
5101 /* Return the DIE associated with the given type specifier. */
5103 static inline dw_die_ref
5104 lookup_type_die (type
)
5107 if (TREE_CODE (type
) == VECTOR_TYPE
)
5108 type
= TYPE_DEBUG_REPRESENTATION_TYPE (type
);
5110 return (dw_die_ref
) TYPE_SYMTAB_POINTER (type
);
5113 /* Equate a DIE to a given type specifier. */
5116 equate_type_number_to_die (type
, type_die
)
5118 dw_die_ref type_die
;
5120 TYPE_SYMTAB_POINTER (type
) = (char *) type_die
;
5123 /* Return the DIE associated with a given declaration. */
5125 static inline dw_die_ref
5126 lookup_decl_die (decl
)
5129 unsigned decl_id
= DECL_UID (decl
);
5131 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5134 /* Equate a DIE to a particular declaration. */
5137 equate_decl_number_to_die (decl
, decl_die
)
5139 dw_die_ref decl_die
;
5141 unsigned int decl_id
= DECL_UID (decl
);
5142 unsigned int num_allocated
;
5144 if (decl_id
>= decl_die_table_allocated
)
5147 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5148 / DECL_DIE_TABLE_INCREMENT
)
5149 * DECL_DIE_TABLE_INCREMENT
;
5152 = (dw_die_ref
*) xrealloc (decl_die_table
,
5153 sizeof (dw_die_ref
) * num_allocated
);
5155 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5156 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5157 decl_die_table_allocated
= num_allocated
;
5160 if (decl_id
>= decl_die_table_in_use
)
5161 decl_die_table_in_use
= (decl_id
+ 1);
5163 decl_die_table
[decl_id
] = decl_die
;
5166 /* Keep track of the number of spaces used to indent the
5167 output of the debugging routines that print the structure of
5168 the DIE internal representation. */
5169 static int print_indent
;
5171 /* Indent the line the number of spaces given by print_indent. */
5174 print_spaces (outfile
)
5177 fprintf (outfile
, "%*s", print_indent
, "");
5180 /* Print the information associated with a given DIE, and its children.
5181 This routine is a debugging aid only. */
5184 print_die (die
, outfile
)
5191 print_spaces (outfile
);
5192 fprintf (outfile
, "DIE %4lu: %s\n",
5193 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5194 print_spaces (outfile
);
5195 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5196 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5198 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5200 print_spaces (outfile
);
5201 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5203 switch (AT_class (a
))
5205 case dw_val_class_addr
:
5206 fprintf (outfile
, "address");
5208 case dw_val_class_offset
:
5209 fprintf (outfile
, "offset");
5211 case dw_val_class_loc
:
5212 fprintf (outfile
, "location descriptor");
5214 case dw_val_class_loc_list
:
5215 fprintf (outfile
, "location list -> label:%s",
5216 AT_loc_list (a
)->ll_symbol
);
5218 case dw_val_class_range_list
:
5219 fprintf (outfile
, "range list");
5221 case dw_val_class_const
:
5222 fprintf (outfile
, "%ld", AT_int (a
));
5224 case dw_val_class_unsigned_const
:
5225 fprintf (outfile
, "%lu", AT_unsigned (a
));
5227 case dw_val_class_long_long
:
5228 fprintf (outfile
, "constant (%lu,%lu)",
5229 a
->dw_attr_val
.v
.val_long_long
.hi
,
5230 a
->dw_attr_val
.v
.val_long_long
.low
);
5232 case dw_val_class_float
:
5233 fprintf (outfile
, "floating-point constant");
5235 case dw_val_class_flag
:
5236 fprintf (outfile
, "%u", AT_flag (a
));
5238 case dw_val_class_die_ref
:
5239 if (AT_ref (a
) != NULL
)
5241 if (AT_ref (a
)->die_symbol
)
5242 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5244 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5247 fprintf (outfile
, "die -> <null>");
5249 case dw_val_class_lbl_id
:
5250 case dw_val_class_lbl_offset
:
5251 fprintf (outfile
, "label: %s", AT_lbl (a
));
5253 case dw_val_class_str
:
5254 if (AT_string (a
) != NULL
)
5255 fprintf (outfile
, "\"%s\"", AT_string (a
));
5257 fprintf (outfile
, "<null>");
5263 fprintf (outfile
, "\n");
5266 if (die
->die_child
!= NULL
)
5269 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5270 print_die (c
, outfile
);
5274 if (print_indent
== 0)
5275 fprintf (outfile
, "\n");
5278 /* Print the contents of the source code line number correspondence table.
5279 This routine is a debugging aid only. */
5282 print_dwarf_line_table (outfile
)
5286 dw_line_info_ref line_info
;
5288 fprintf (outfile
, "\n\nDWARF source line information\n");
5289 for (i
= 1; i
< line_info_table_in_use
; i
++)
5291 line_info
= &line_info_table
[i
];
5292 fprintf (outfile
, "%5d: ", i
);
5293 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5294 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5295 fprintf (outfile
, "\n");
5298 fprintf (outfile
, "\n\n");
5301 /* Print the information collected for a given DIE. */
5304 debug_dwarf_die (die
)
5307 print_die (die
, stderr
);
5310 /* Print all DWARF information collected for the compilation unit.
5311 This routine is a debugging aid only. */
5317 print_die (comp_unit_die
, stderr
);
5318 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5319 print_dwarf_line_table (stderr
);
5322 /* We build up the lists of children and attributes by pushing new ones
5323 onto the beginning of the list. Reverse the lists for DIE so that
5324 they are in order of addition. */
5327 reverse_die_lists (die
)
5330 dw_die_ref c
, cp
, cn
;
5331 dw_attr_ref a
, ap
, an
;
5333 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5335 an
= a
->dw_attr_next
;
5336 a
->dw_attr_next
= ap
;
5342 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5349 die
->die_child
= cp
;
5352 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5353 reverse all dies in add_sibling_attributes, which runs through all the dies,
5354 it would reverse all the dies. Now, however, since we don't call
5355 reverse_die_lists in add_sibling_attributes, we need a routine to
5356 recursively reverse all the dies. This is that routine. */
5359 reverse_all_dies (die
)
5364 reverse_die_lists (die
);
5366 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5367 reverse_all_dies (c
);
5370 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5371 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5372 DIE that marks the start of the DIEs for this include file. */
5375 push_new_compile_unit (old_unit
, bincl_die
)
5376 dw_die_ref old_unit
, bincl_die
;
5378 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5379 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5381 new_unit
->die_sib
= old_unit
;
5385 /* Close an include-file CU and reopen the enclosing one. */
5388 pop_compile_unit (old_unit
)
5389 dw_die_ref old_unit
;
5391 dw_die_ref new_unit
= old_unit
->die_sib
;
5393 old_unit
->die_sib
= NULL
;
5397 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5398 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5400 /* Calculate the checksum of a location expression. */
5403 loc_checksum (loc
, ctx
)
5404 dw_loc_descr_ref loc
;
5405 struct md5_ctx
*ctx
;
5407 CHECKSUM (loc
->dw_loc_opc
);
5408 CHECKSUM (loc
->dw_loc_oprnd1
);
5409 CHECKSUM (loc
->dw_loc_oprnd2
);
5412 /* Calculate the checksum of an attribute. */
5415 attr_checksum (at
, ctx
)
5417 struct md5_ctx
*ctx
;
5419 dw_loc_descr_ref loc
;
5422 CHECKSUM (at
->dw_attr
);
5424 /* We don't care about differences in file numbering. */
5425 if (at
->dw_attr
== DW_AT_decl_file
5426 /* Or that this was compiled with a different compiler snapshot; if
5427 the output is the same, that's what matters. */
5428 || at
->dw_attr
== DW_AT_producer
)
5431 switch (AT_class (at
))
5433 case dw_val_class_const
:
5434 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5436 case dw_val_class_unsigned_const
:
5437 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5439 case dw_val_class_long_long
:
5440 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5442 case dw_val_class_float
:
5443 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5445 case dw_val_class_flag
:
5446 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5448 case dw_val_class_str
:
5449 CHECKSUM_STRING (AT_string (at
));
5452 case dw_val_class_addr
:
5454 switch (GET_CODE (r
))
5457 CHECKSUM_STRING (XSTR (r
, 0));
5465 case dw_val_class_offset
:
5466 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5469 case dw_val_class_loc
:
5470 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5471 loc_checksum (loc
, ctx
);
5474 case dw_val_class_die_ref
:
5475 if (AT_ref (at
)->die_offset
)
5476 CHECKSUM (AT_ref (at
)->die_offset
);
5477 /* FIXME else use target die name or something. */
5479 case dw_val_class_fde_ref
:
5480 case dw_val_class_lbl_id
:
5481 case dw_val_class_lbl_offset
:
5489 /* Calculate the checksum of a DIE. */
5492 die_checksum (die
, ctx
)
5494 struct md5_ctx
*ctx
;
5499 CHECKSUM (die
->die_tag
);
5501 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5502 attr_checksum (a
, ctx
);
5504 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5505 die_checksum (c
, ctx
);
5509 #undef CHECKSUM_STRING
5511 /* The prefix to attach to symbols on DIEs in the current comdat debug
5513 static char *comdat_symbol_id
;
5515 /* The index of the current symbol within the current comdat CU. */
5516 static unsigned int comdat_symbol_number
;
5518 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5519 children, and set comdat_symbol_id accordingly. */
5522 compute_section_prefix (unit_die
)
5523 dw_die_ref unit_die
;
5525 const char *base
= lbasename (get_AT_string (unit_die
, DW_AT_name
));
5526 char *name
= (char *) alloca (strlen (base
) + 64);
5529 unsigned char checksum
[16];
5532 /* Compute the checksum of the DIE, then append part of it as hex digits to
5533 the name filename of the unit. */
5535 md5_init_ctx (&ctx
);
5536 die_checksum (unit_die
, &ctx
);
5537 md5_finish_ctx (&ctx
, checksum
);
5539 sprintf (name
, "%s.", base
);
5540 clean_symbol_name (name
);
5542 p
= name
+ strlen (name
);
5543 for (i
= 0; i
< 4; i
++)
5545 sprintf (p
, "%.2x", checksum
[i
]);
5549 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5550 comdat_symbol_number
= 0;
5553 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5559 switch (die
->die_tag
)
5561 case DW_TAG_array_type
:
5562 case DW_TAG_class_type
:
5563 case DW_TAG_enumeration_type
:
5564 case DW_TAG_pointer_type
:
5565 case DW_TAG_reference_type
:
5566 case DW_TAG_string_type
:
5567 case DW_TAG_structure_type
:
5568 case DW_TAG_subroutine_type
:
5569 case DW_TAG_union_type
:
5570 case DW_TAG_ptr_to_member_type
:
5571 case DW_TAG_set_type
:
5572 case DW_TAG_subrange_type
:
5573 case DW_TAG_base_type
:
5574 case DW_TAG_const_type
:
5575 case DW_TAG_file_type
:
5576 case DW_TAG_packed_type
:
5577 case DW_TAG_volatile_type
:
5584 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5585 Basically, we want to choose the bits that are likely to be shared between
5586 compilations (types) and leave out the bits that are specific to individual
5587 compilations (functions). */
5593 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5594 we do for stabs. The advantage is a greater likelihood of sharing between
5595 objects that don't include headers in the same order (and therefore would
5596 put the base types in a different comdat). jason 8/28/00 */
5598 if (c
->die_tag
== DW_TAG_base_type
)
5601 if (c
->die_tag
== DW_TAG_pointer_type
5602 || c
->die_tag
== DW_TAG_reference_type
5603 || c
->die_tag
== DW_TAG_const_type
5604 || c
->die_tag
== DW_TAG_volatile_type
)
5606 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5608 return t
? is_comdat_die (t
) : 0;
5611 return is_type_die (c
);
5614 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5615 compilation unit. */
5621 return (is_type_die (c
)
5622 || (get_AT (c
, DW_AT_declaration
)
5623 && !get_AT (c
, DW_AT_specification
)));
5627 gen_internal_sym (prefix
)
5631 static int label_num
;
5633 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5634 return xstrdup (buf
);
5637 /* Assign symbols to all worthy DIEs under DIE. */
5640 assign_symbol_names (die
)
5645 if (is_symbol_die (die
))
5647 if (comdat_symbol_id
)
5649 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5651 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5652 comdat_symbol_id
, comdat_symbol_number
++);
5653 die
->die_symbol
= xstrdup (p
);
5656 die
->die_symbol
= gen_internal_sym ("LDIE");
5659 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5660 assign_symbol_names (c
);
5663 /* Traverse the DIE (which is always comp_unit_die), and set up
5664 additional compilation units for each of the include files we see
5665 bracketed by BINCL/EINCL. */
5668 break_out_includes (die
)
5672 dw_die_ref unit
= NULL
;
5673 limbo_die_node
*node
;
5675 for (ptr
= &(die
->die_child
); *ptr
; )
5677 dw_die_ref c
= *ptr
;
5679 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5680 || (unit
&& is_comdat_die (c
)))
5682 /* This DIE is for a secondary CU; remove it from the main one. */
5685 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5687 unit
= push_new_compile_unit (unit
, c
);
5690 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5692 unit
= pop_compile_unit (unit
);
5696 add_child_die (unit
, c
);
5700 /* Leave this DIE in the main CU. */
5701 ptr
= &(c
->die_sib
);
5707 /* We can only use this in debugging, since the frontend doesn't check
5708 to make sure that we leave every include file we enter. */
5713 assign_symbol_names (die
);
5714 for (node
= limbo_die_list
; node
; node
= node
->next
)
5716 compute_section_prefix (node
->die
);
5717 assign_symbol_names (node
->die
);
5721 /* Traverse the DIE and add a sibling attribute if it may have the
5722 effect of speeding up access to siblings. To save some space,
5723 avoid generating sibling attributes for DIE's without children. */
5726 add_sibling_attributes (die
)
5731 if (die
->die_tag
!= DW_TAG_compile_unit
5732 && die
->die_sib
&& die
->die_child
!= NULL
)
5733 /* Add the sibling link to the front of the attribute list. */
5734 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5736 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5737 add_sibling_attributes (c
);
5740 /* Output all location lists for the DIE and its children. */
5743 output_location_lists (die
)
5749 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5750 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5751 output_loc_list (AT_loc_list (d_attr
));
5753 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5754 output_location_lists (c
);
5757 /* The format of each DIE (and its attribute value pairs) is encoded in an
5758 abbreviation table. This routine builds the abbreviation table and assigns
5759 a unique abbreviation id for each abbreviation entry. The children of each
5760 die are visited recursively. */
5763 build_abbrev_table (die
)
5766 unsigned long abbrev_id
;
5767 unsigned int n_alloc
;
5769 dw_attr_ref d_attr
, a_attr
;
5771 /* Scan the DIE references, and mark as external any that refer to
5772 DIEs from other CUs (i.e. those which are not marked). */
5773 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5774 if (AT_class (d_attr
) == dw_val_class_die_ref
5775 && AT_ref (d_attr
)->die_mark
== 0)
5777 if (AT_ref (d_attr
)->die_symbol
== 0)
5780 set_AT_ref_external (d_attr
, 1);
5783 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5785 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5787 if (abbrev
->die_tag
== die
->die_tag
)
5789 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
5791 a_attr
= abbrev
->die_attr
;
5792 d_attr
= die
->die_attr
;
5794 while (a_attr
!= NULL
&& d_attr
!= NULL
)
5796 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
5797 || (value_format (a_attr
) != value_format (d_attr
)))
5800 a_attr
= a_attr
->dw_attr_next
;
5801 d_attr
= d_attr
->dw_attr_next
;
5804 if (a_attr
== NULL
&& d_attr
== NULL
)
5810 if (abbrev_id
>= abbrev_die_table_in_use
)
5812 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
5814 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
5816 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
5817 sizeof (dw_die_ref
) * n_alloc
);
5819 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
5820 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
5821 abbrev_die_table_allocated
= n_alloc
;
5824 ++abbrev_die_table_in_use
;
5825 abbrev_die_table
[abbrev_id
] = die
;
5828 die
->die_abbrev
= abbrev_id
;
5829 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5830 build_abbrev_table (c
);
5833 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5836 constant_size (value
)
5837 long unsigned value
;
5844 log
= floor_log2 (value
);
5847 log
= 1 << (floor_log2 (log
) + 1);
5852 /* Return the size of a DIE as it is represented in the
5853 .debug_info section. */
5855 static unsigned long
5859 unsigned long size
= 0;
5862 size
+= size_of_uleb128 (die
->die_abbrev
);
5863 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5865 switch (AT_class (a
))
5867 case dw_val_class_addr
:
5868 size
+= DWARF2_ADDR_SIZE
;
5870 case dw_val_class_offset
:
5871 size
+= DWARF_OFFSET_SIZE
;
5873 case dw_val_class_loc
:
5875 unsigned long lsize
= size_of_locs (AT_loc (a
));
5878 size
+= constant_size (lsize
);
5882 case dw_val_class_loc_list
:
5883 size
+= DWARF_OFFSET_SIZE
;
5885 case dw_val_class_range_list
:
5886 size
+= DWARF_OFFSET_SIZE
;
5888 case dw_val_class_const
:
5889 size
+= size_of_sleb128 (AT_int (a
));
5891 case dw_val_class_unsigned_const
:
5892 size
+= constant_size (AT_unsigned (a
));
5894 case dw_val_class_long_long
:
5895 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
5897 case dw_val_class_float
:
5898 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
5900 case dw_val_class_flag
:
5903 case dw_val_class_die_ref
:
5904 size
+= DWARF_OFFSET_SIZE
;
5906 case dw_val_class_fde_ref
:
5907 size
+= DWARF_OFFSET_SIZE
;
5909 case dw_val_class_lbl_id
:
5910 size
+= DWARF2_ADDR_SIZE
;
5912 case dw_val_class_lbl_offset
:
5913 size
+= DWARF_OFFSET_SIZE
;
5915 case dw_val_class_str
:
5916 if (AT_string_form (a
) == DW_FORM_strp
)
5917 size
+= DWARF_OFFSET_SIZE
;
5919 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
5929 /* Size the debugging information associated with a given DIE. Visits the
5930 DIE's children recursively. Updates the global variable next_die_offset, on
5931 each time through. Uses the current value of next_die_offset to update the
5932 die_offset field in each DIE. */
5935 calc_die_sizes (die
)
5940 die
->die_offset
= next_die_offset
;
5941 next_die_offset
+= size_of_die (die
);
5943 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5946 if (die
->die_child
!= NULL
)
5947 /* Count the null byte used to terminate sibling lists. */
5948 next_die_offset
+= 1;
5951 /* Set the marks for a die and its children. We do this so
5952 that we know whether or not a reference needs to use FORM_ref_addr; only
5953 DIEs in the same CU will be marked. We used to clear out the offset
5954 and use that as the flag, but ran into ordering problems. */
5963 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5967 /* Clear the marks for a die and its children. */
5976 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5980 /* Return the size of the .debug_pubnames table generated for the
5981 compilation unit. */
5983 static unsigned long
5989 size
= DWARF_PUBNAMES_HEADER_SIZE
;
5990 for (i
= 0; i
< pubname_table_in_use
; i
++)
5992 pubname_ref p
= &pubname_table
[i
];
5993 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
5996 size
+= DWARF_OFFSET_SIZE
;
6000 /* Return the size of the information in the .debug_aranges section. */
6002 static unsigned long
6007 size
= DWARF_ARANGES_HEADER_SIZE
;
6009 /* Count the address/length pair for this compilation unit. */
6010 size
+= 2 * DWARF2_ADDR_SIZE
;
6011 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6013 /* Count the two zero words used to terminated the address range table. */
6014 size
+= 2 * DWARF2_ADDR_SIZE
;
6018 /* Select the encoding of an attribute value. */
6020 static enum dwarf_form
6024 switch (a
->dw_attr_val
.val_class
)
6026 case dw_val_class_addr
:
6027 return DW_FORM_addr
;
6028 case dw_val_class_range_list
:
6029 case dw_val_class_offset
:
6030 if (DWARF_OFFSET_SIZE
== 4)
6031 return DW_FORM_data4
;
6032 if (DWARF_OFFSET_SIZE
== 8)
6033 return DW_FORM_data8
;
6035 case dw_val_class_loc_list
:
6036 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6037 .debug_loc section */
6038 return DW_FORM_data4
;
6039 case dw_val_class_loc
:
6040 switch (constant_size (size_of_locs (AT_loc (a
))))
6043 return DW_FORM_block1
;
6045 return DW_FORM_block2
;
6049 case dw_val_class_const
:
6050 return DW_FORM_sdata
;
6051 case dw_val_class_unsigned_const
:
6052 switch (constant_size (AT_unsigned (a
)))
6055 return DW_FORM_data1
;
6057 return DW_FORM_data2
;
6059 return DW_FORM_data4
;
6061 return DW_FORM_data8
;
6065 case dw_val_class_long_long
:
6066 return DW_FORM_block1
;
6067 case dw_val_class_float
:
6068 return DW_FORM_block1
;
6069 case dw_val_class_flag
:
6070 return DW_FORM_flag
;
6071 case dw_val_class_die_ref
:
6072 if (AT_ref_external (a
))
6073 return DW_FORM_ref_addr
;
6076 case dw_val_class_fde_ref
:
6077 return DW_FORM_data
;
6078 case dw_val_class_lbl_id
:
6079 return DW_FORM_addr
;
6080 case dw_val_class_lbl_offset
:
6081 return DW_FORM_data
;
6082 case dw_val_class_str
:
6083 return AT_string_form (a
);
6090 /* Output the encoding of an attribute value. */
6093 output_value_format (a
)
6096 enum dwarf_form form
= value_format (a
);
6098 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6101 /* Output the .debug_abbrev section which defines the DIE abbreviation
6105 output_abbrev_section ()
6107 unsigned long abbrev_id
;
6111 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6113 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6115 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6116 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6117 dwarf_tag_name (abbrev
->die_tag
));
6119 if (abbrev
->die_child
!= NULL
)
6120 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6122 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6124 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6125 a_attr
= a_attr
->dw_attr_next
)
6127 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6128 dwarf_attr_name (a_attr
->dw_attr
));
6129 output_value_format (a_attr
);
6132 dw2_asm_output_data (1, 0, NULL
);
6133 dw2_asm_output_data (1, 0, NULL
);
6136 /* Terminate the table. */
6137 dw2_asm_output_data (1, 0, NULL
);
6140 /* Output a symbol we can use to refer to this DIE from another CU. */
6143 output_die_symbol (die
)
6146 char *sym
= die
->die_symbol
;
6151 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6152 /* We make these global, not weak; if the target doesn't support
6153 .linkonce, it doesn't support combining the sections, so debugging
6155 ASM_GLOBALIZE_LABEL (asm_out_file
, sym
);
6157 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6160 /* Return a new location list, given the begin and end range, and the
6161 expression. gensym tells us whether to generate a new internal symbol for
6162 this location list node, which is done for the head of the list only. */
6164 static inline dw_loc_list_ref
6165 new_loc_list (expr
, begin
, end
, section
, gensym
)
6166 dw_loc_descr_ref expr
;
6169 const char *section
;
6172 dw_loc_list_ref retlist
6173 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6175 retlist
->begin
= begin
;
6177 retlist
->expr
= expr
;
6178 retlist
->section
= section
;
6180 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6185 /* Add a location description expression to a location list */
6188 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6189 dw_loc_list_ref
*list_head
;
6190 dw_loc_descr_ref descr
;
6193 const char *section
;
6197 /* Find the end of the chain. */
6198 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6201 /* Add a new location list node to the list */
6202 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6205 /* Output the location list given to us */
6208 output_loc_list (list_head
)
6209 dw_loc_list_ref list_head
;
6211 dw_loc_list_ref curr
= list_head
;
6213 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6215 /* ??? This shouldn't be needed now that we've forced the
6216 compilation unit base address to zero when there is code
6217 in more than one section. */
6218 if (strcmp (curr
->section
, ".text") == 0)
6220 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6221 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6222 "Location list base address specifier fake entry");
6223 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6224 "Location list base address specifier base");
6227 for (curr
= list_head
; curr
!= NULL
; curr
=curr
->dw_loc_next
)
6231 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6232 "Location list begin address (%s)",
6233 list_head
->ll_symbol
);
6234 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6235 "Location list end address (%s)",
6236 list_head
->ll_symbol
);
6237 size
= size_of_locs (curr
->expr
);
6239 /* Output the block length for this list of location operations. */
6242 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6244 output_loc_sequence (curr
->expr
);
6247 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6248 "Location list terminator begin (%s)",
6249 list_head
->ll_symbol
);
6250 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6251 "Location list terminator end (%s)",
6252 list_head
->ll_symbol
);
6255 /* Output the DIE and its attributes. Called recursively to generate
6256 the definitions of each child DIE. */
6266 /* If someone in another CU might refer to us, set up a symbol for
6267 them to point to. */
6268 if (die
->die_symbol
)
6269 output_die_symbol (die
);
6271 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6272 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6274 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6276 const char *name
= dwarf_attr_name (a
->dw_attr
);
6278 switch (AT_class (a
))
6280 case dw_val_class_addr
:
6281 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6284 case dw_val_class_offset
:
6285 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6289 case dw_val_class_range_list
:
6291 char *p
= strchr (ranges_section_label
, '\0');
6293 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6294 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6300 case dw_val_class_loc
:
6301 size
= size_of_locs (AT_loc (a
));
6303 /* Output the block length for this list of location operations. */
6304 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6306 output_loc_sequence (AT_loc (a
));
6309 case dw_val_class_const
:
6310 /* ??? It would be slightly more efficient to use a scheme like is
6311 used for unsigned constants below, but gdb 4.x does not sign
6312 extend. Gdb 5.x does sign extend. */
6313 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6316 case dw_val_class_unsigned_const
:
6317 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6318 AT_unsigned (a
), "%s", name
);
6321 case dw_val_class_long_long
:
6323 unsigned HOST_WIDE_INT first
, second
;
6325 dw2_asm_output_data (1,
6326 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6329 if (WORDS_BIG_ENDIAN
)
6331 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6332 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6336 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6337 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6340 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6341 first
, "long long constant");
6342 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6347 case dw_val_class_float
:
6351 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6354 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6355 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6356 "fp constant word %u", i
);
6360 case dw_val_class_flag
:
6361 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6364 case dw_val_class_loc_list
:
6366 char *sym
= AT_loc_list (a
)->ll_symbol
;
6370 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6371 loc_section_label
, "%s", name
);
6375 case dw_val_class_die_ref
:
6376 if (AT_ref_external (a
))
6378 char *sym
= AT_ref (a
)->die_symbol
;
6382 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6384 else if (AT_ref (a
)->die_offset
== 0)
6387 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6391 case dw_val_class_fde_ref
:
6395 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6396 a
->dw_attr_val
.v
.val_fde_index
* 2);
6397 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6401 case dw_val_class_lbl_id
:
6402 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6405 case dw_val_class_lbl_offset
:
6406 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6409 case dw_val_class_str
:
6410 if (AT_string_form (a
) == DW_FORM_strp
)
6411 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6412 a
->dw_attr_val
.v
.val_str
->label
,
6413 "%s: \"%s\"", name
, AT_string (a
));
6415 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6423 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6426 /* Add null byte to terminate sibling list. */
6427 if (die
->die_child
!= NULL
)
6428 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6432 /* Output the compilation unit that appears at the beginning of the
6433 .debug_info section, and precedes the DIE descriptions. */
6436 output_compilation_unit_header ()
6438 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6439 "Length of Compilation Unit Info");
6440 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6441 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6442 "Offset Into Abbrev. Section");
6443 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6446 /* Output the compilation unit DIE and its children. */
6449 output_comp_unit (die
)
6452 const char *secname
;
6454 /* Even if there are no children of this DIE, we must output the information
6455 about the compilation unit. Otherwise, on an empty translation unit, we
6456 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6457 will then complain when examining the file. First mark all the DIEs in
6458 this CU so we know which get local refs. */
6461 build_abbrev_table (die
);
6463 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6464 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6465 calc_die_sizes (die
);
6467 if (die
->die_symbol
)
6469 char *tmp
= (char *) alloca (strlen (die
->die_symbol
) + 24);
6471 sprintf (tmp
, ".gnu.linkonce.wi.%s", die
->die_symbol
);
6473 die
->die_symbol
= NULL
;
6476 secname
= (const char *) DEBUG_INFO_SECTION
;
6478 /* Output debugging information. */
6479 named_section_flags (secname
, SECTION_DEBUG
);
6480 output_compilation_unit_header ();
6483 /* Leave the marks on the main CU, so we can check them in
6485 if (die
->die_symbol
)
6489 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6490 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6491 argument list, and maybe the scope. */
6494 dwarf2_name (decl
, scope
)
6498 return (*decl_printable_name
) (decl
, scope
? 1 : 0);
6501 /* Add a new entry to .debug_pubnames if appropriate. */
6504 add_pubname (decl
, die
)
6510 if (! TREE_PUBLIC (decl
))
6513 if (pubname_table_in_use
== pubname_table_allocated
)
6515 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6517 = (pubname_ref
) xrealloc (pubname_table
,
6518 (pubname_table_allocated
6519 * sizeof (pubname_entry
)));
6522 p
= &pubname_table
[pubname_table_in_use
++];
6524 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6527 /* Output the public names table used to speed up access to externally
6528 visible names. For now, only generate entries for externally
6529 visible procedures. */
6535 unsigned long pubnames_length
= size_of_pubnames ();
6537 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6538 "Length of Public Names Info");
6539 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6540 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6541 "Offset of Compilation Unit Info");
6542 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6543 "Compilation Unit Length");
6545 for (i
= 0; i
< pubname_table_in_use
; i
++)
6547 pubname_ref pub
= &pubname_table
[i
];
6549 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6550 if (pub
->die
->die_mark
== 0)
6553 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6556 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6559 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6562 /* Add a new entry to .debug_aranges if appropriate. */
6565 add_arange (decl
, die
)
6569 if (! DECL_SECTION_NAME (decl
))
6572 if (arange_table_in_use
== arange_table_allocated
)
6574 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6575 arange_table
= (dw_die_ref
*)
6576 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6579 arange_table
[arange_table_in_use
++] = die
;
6582 /* Output the information that goes into the .debug_aranges table.
6583 Namely, define the beginning and ending address range of the
6584 text section generated for this compilation unit. */
6590 unsigned long aranges_length
= size_of_aranges ();
6592 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6593 "Length of Address Ranges Info");
6594 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6595 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6596 "Offset of Compilation Unit Info");
6597 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6598 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6600 /* We need to align to twice the pointer size here. */
6601 if (DWARF_ARANGES_PAD_SIZE
)
6603 /* Pad using a 2 byte words so that padding is correct for any
6605 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6606 2 * DWARF2_ADDR_SIZE
);
6607 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6608 dw2_asm_output_data (2, 0, NULL
);
6611 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6612 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6613 text_section_label
, "Length");
6615 for (i
= 0; i
< arange_table_in_use
; i
++)
6617 dw_die_ref die
= arange_table
[i
];
6619 /* We shouldn't see aranges for DIEs outside of the main CU. */
6620 if (die
->die_mark
== 0)
6623 if (die
->die_tag
== DW_TAG_subprogram
)
6625 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6627 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6628 get_AT_low_pc (die
), "Length");
6632 /* A static variable; extract the symbol from DW_AT_location.
6633 Note that this code isn't currently hit, as we only emit
6634 aranges for functions (jason 9/23/99). */
6635 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6636 dw_loc_descr_ref loc
;
6638 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6642 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6645 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6646 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6647 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6648 get_AT_unsigned (die
, DW_AT_byte_size
),
6653 /* Output the terminator words. */
6654 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6655 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6658 /* Add a new entry to .debug_ranges. Return the offset at which it
6665 unsigned int in_use
= ranges_table_in_use
;
6667 if (in_use
== ranges_table_allocated
)
6669 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6670 ranges_table
= (dw_ranges_ref
)
6671 xrealloc (ranges_table
, (ranges_table_allocated
6672 * sizeof (struct dw_ranges_struct
)));
6675 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6676 ranges_table_in_use
= in_use
+ 1;
6678 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6685 static const char *const start_fmt
= "Offset 0x%x";
6686 const char *fmt
= start_fmt
;
6688 for (i
= 0; i
< ranges_table_in_use
; i
++)
6690 int block_num
= ranges_table
[i
].block_num
;
6694 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6695 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6697 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6698 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6700 /* If all code is in the text section, then the compilation
6701 unit base address defaults to DW_AT_low_pc, which is the
6702 base of the text section. */
6703 if (separate_line_info_table_in_use
== 0)
6705 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6707 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6708 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6709 text_section_label
, NULL
);
6712 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6713 compilation unit base address to zero, which allows us to
6714 use absolute addresses, and not worry about whether the
6715 target supports cross-section arithmetic. */
6718 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6719 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6720 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6727 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6728 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6734 /* Data structure containing information about input files. */
6737 char *path
; /* Complete file name. */
6738 char *fname
; /* File name part. */
6739 int length
; /* Length of entire string. */
6740 int file_idx
; /* Index in input file table. */
6741 int dir_idx
; /* Index in directory table. */
6744 /* Data structure containing information about directories with source
6748 char *path
; /* Path including directory name. */
6749 int length
; /* Path length. */
6750 int prefix
; /* Index of directory entry which is a prefix. */
6751 int count
; /* Number of files in this directory. */
6752 int dir_idx
; /* Index of directory used as base. */
6753 int used
; /* Used in the end? */
6756 /* Callback function for file_info comparison. We sort by looking at
6757 the directories in the path. */
6760 file_info_cmp (p1
, p2
)
6764 const struct file_info
*s1
= p1
;
6765 const struct file_info
*s2
= p2
;
6769 /* Take care of file names without directories. We need to make sure that
6770 we return consistent values to qsort since some will get confused if
6771 we return the same value when identical operands are passed in opposite
6772 orders. So if neither has a directory, return 0 and otherwise return
6773 1 or -1 depending on which one has the directory. */
6774 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
6775 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
6777 cp1
= (unsigned char *) s1
->path
;
6778 cp2
= (unsigned char *) s2
->path
;
6784 /* Reached the end of the first path? If so, handle like above. */
6785 if ((cp1
== (unsigned char *) s1
->fname
)
6786 || (cp2
== (unsigned char *) s2
->fname
))
6787 return ((cp2
== (unsigned char *) s2
->fname
)
6788 - (cp1
== (unsigned char *) s1
->fname
));
6790 /* Character of current path component the same? */
6791 else if (*cp1
!= *cp2
)
6796 /* Output the directory table and the file name table. We try to minimize
6797 the total amount of memory needed. A heuristic is used to avoid large
6798 slowdowns with many input files. */
6801 output_file_names ()
6803 struct file_info
*files
;
6804 struct dir_info
*dirs
;
6813 /* Allocate the various arrays we need. */
6814 files
= (struct file_info
*) alloca (file_table
.in_use
6815 * sizeof (struct file_info
));
6816 dirs
= (struct dir_info
*) alloca (file_table
.in_use
6817 * sizeof (struct dir_info
));
6819 /* Sort the file names. */
6820 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6824 /* Skip all leading "./". */
6825 f
= file_table
.table
[i
];
6826 while (f
[0] == '.' && f
[1] == '/')
6829 /* Create a new array entry. */
6831 files
[i
].length
= strlen (f
);
6832 files
[i
].file_idx
= i
;
6834 /* Search for the file name part. */
6835 f
= strrchr (f
, '/');
6836 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
6839 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
6841 /* Find all the different directories used. */
6842 dirs
[0].path
= files
[1].path
;
6843 dirs
[0].length
= files
[1].fname
- files
[1].path
;
6844 dirs
[0].prefix
= -1;
6846 dirs
[0].dir_idx
= 0;
6848 files
[1].dir_idx
= 0;
6851 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
6852 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
6853 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
6854 dirs
[ndirs
- 1].length
) == 0)
6856 /* Same directory as last entry. */
6857 files
[i
].dir_idx
= ndirs
- 1;
6858 ++dirs
[ndirs
- 1].count
;
6864 /* This is a new directory. */
6865 dirs
[ndirs
].path
= files
[i
].path
;
6866 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
6867 dirs
[ndirs
].count
= 1;
6868 dirs
[ndirs
].dir_idx
= ndirs
;
6869 dirs
[ndirs
].used
= 0;
6870 files
[i
].dir_idx
= ndirs
;
6872 /* Search for a prefix. */
6873 dirs
[ndirs
].prefix
= -1;
6874 for (j
= 0; j
< ndirs
; j
++)
6875 if (dirs
[j
].length
< dirs
[ndirs
].length
6876 && dirs
[j
].length
> 1
6877 && (dirs
[ndirs
].prefix
== -1
6878 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
6879 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
6880 dirs
[ndirs
].prefix
= j
;
6885 /* Now to the actual work. We have to find a subset of the directories which
6886 allow expressing the file name using references to the directory table
6887 with the least amount of characters. We do not do an exhaustive search
6888 where we would have to check out every combination of every single
6889 possible prefix. Instead we use a heuristic which provides nearly optimal
6890 results in most cases and never is much off. */
6891 saved
= (int *) alloca (ndirs
* sizeof (int));
6892 savehere
= (int *) alloca (ndirs
* sizeof (int));
6894 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
6895 for (i
= 0; i
< ndirs
; i
++)
6900 /* We can always save some space for the current directory. But this
6901 does not mean it will be enough to justify adding the directory. */
6902 savehere
[i
] = dirs
[i
].length
;
6903 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
6905 for (j
= i
+ 1; j
< ndirs
; j
++)
6908 if (saved
[j
] < dirs
[i
].length
)
6910 /* Determine whether the dirs[i] path is a prefix of the
6915 while (k
!= -1 && k
!= i
)
6920 /* Yes it is. We can possibly safe some memory but
6921 writing the filenames in dirs[j] relative to
6923 savehere
[j
] = dirs
[i
].length
;
6924 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
6929 /* Check whether we can safe enough to justify adding the dirs[i]
6931 if (total
> dirs
[i
].length
+ 1)
6933 /* It's worthwhile adding. */
6934 for (j
= i
; j
< ndirs
; j
++)
6935 if (savehere
[j
] > 0)
6937 /* Remember how much we saved for this directory so far. */
6938 saved
[j
] = savehere
[j
];
6940 /* Remember the prefix directory. */
6941 dirs
[j
].dir_idx
= i
;
6946 /* We have to emit them in the order they appear in the file_table array
6947 since the index is used in the debug info generation. To do this
6948 efficiently we generate a back-mapping of the indices first. */
6949 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
6950 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6952 backmap
[files
[i
].file_idx
] = i
;
6954 /* Mark this directory as used. */
6955 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
6958 /* That was it. We are ready to emit the information. First emit the
6959 directory name table. We have to make sure the first actually emitted
6960 directory name has index one; zero is reserved for the current working
6961 directory. Make sure we do not confuse these indices with the one for the
6962 constructed table (even though most of the time they are identical). */
6964 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
6965 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
6966 if (dirs
[i
].used
!= 0)
6968 dirs
[i
].used
= idx
++;
6969 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
6970 "Directory Entry: 0x%x", dirs
[i
].used
);
6973 dw2_asm_output_data (1, 0, "End directory table");
6975 /* Correct the index for the current working directory entry if it
6977 if (idx_offset
== 0)
6980 /* Now write all the file names. */
6981 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6983 int file_idx
= backmap
[i
];
6984 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
6986 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
6987 "File Entry: 0x%x", i
);
6989 /* Include directory index. */
6990 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
6992 /* Modification time. */
6993 dw2_asm_output_data_uleb128 (0, NULL
);
6995 /* File length in bytes. */
6996 dw2_asm_output_data_uleb128 (0, NULL
);
6999 dw2_asm_output_data (1, 0, "End file name table");
7003 /* Output the source line number correspondence information. This
7004 information goes into the .debug_line section. */
7009 char l1
[20], l2
[20], p1
[20], p2
[20];
7010 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7011 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7014 unsigned long lt_index
;
7015 unsigned long current_line
;
7018 unsigned long current_file
;
7019 unsigned long function
;
7021 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7022 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7023 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7024 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7026 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7027 "Length of Source Line Info");
7028 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7030 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7031 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7032 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7034 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH
,
7035 "Minimum Instruction Length");
7036 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7037 "Default is_stmt_start flag");
7038 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7039 "Line Base Value (Special Opcodes)");
7040 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7041 "Line Range Value (Special Opcodes)");
7042 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7043 "Special Opcode Base");
7045 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7049 case DW_LNS_advance_pc
:
7050 case DW_LNS_advance_line
:
7051 case DW_LNS_set_file
:
7052 case DW_LNS_set_column
:
7053 case DW_LNS_fixed_advance_pc
:
7061 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7065 /* Write out the information about the files we use. */
7066 output_file_names ();
7067 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7069 /* We used to set the address register to the first location in the text
7070 section here, but that didn't accomplish anything since we already
7071 have a line note for the opening brace of the first function. */
7073 /* Generate the line number to PC correspondence table, encoded as
7074 a series of state machine operations. */
7077 strcpy (prev_line_label
, text_section_label
);
7078 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7080 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7083 /* Disable this optimization for now; GDB wants to see two line notes
7084 at the beginning of a function so it can find the end of the
7087 /* Don't emit anything for redundant notes. Just updating the
7088 address doesn't accomplish anything, because we already assume
7089 that anything after the last address is this line. */
7090 if (line_info
->dw_line_num
== current_line
7091 && line_info
->dw_file_num
== current_file
)
7095 /* Emit debug info for the address of the current line.
7097 Unfortunately, we have little choice here currently, and must always
7098 use the most general form. GCC does not know the address delta
7099 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7100 attributes which will give an upper bound on the address range. We
7101 could perhaps use length attributes to determine when it is safe to
7102 use DW_LNS_fixed_advance_pc. */
7104 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7107 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7108 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7109 "DW_LNS_fixed_advance_pc");
7110 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7114 /* This can handle any delta. This takes
7115 4+DWARF2_ADDR_SIZE bytes. */
7116 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7117 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7118 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7119 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7122 strcpy (prev_line_label
, line_label
);
7124 /* Emit debug info for the source file of the current line, if
7125 different from the previous line. */
7126 if (line_info
->dw_file_num
!= current_file
)
7128 current_file
= line_info
->dw_file_num
;
7129 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7130 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7131 file_table
.table
[current_file
]);
7134 /* Emit debug info for the current line number, choosing the encoding
7135 that uses the least amount of space. */
7136 if (line_info
->dw_line_num
!= current_line
)
7138 line_offset
= line_info
->dw_line_num
- current_line
;
7139 line_delta
= line_offset
- DWARF_LINE_BASE
;
7140 current_line
= line_info
->dw_line_num
;
7141 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7142 /* This can handle deltas from -10 to 234, using the current
7143 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7145 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7146 "line %lu", current_line
);
7149 /* This can handle any delta. This takes at least 4 bytes,
7150 depending on the value being encoded. */
7151 dw2_asm_output_data (1, DW_LNS_advance_line
,
7152 "advance to line %lu", current_line
);
7153 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7154 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7158 /* We still need to start a new row, so output a copy insn. */
7159 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7162 /* Emit debug info for the address of the end of the function. */
7165 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7166 "DW_LNS_fixed_advance_pc");
7167 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7171 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7172 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7173 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7174 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7177 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7178 dw2_asm_output_data_uleb128 (1, NULL
);
7179 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7184 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7186 dw_separate_line_info_ref line_info
7187 = &separate_line_info_table
[lt_index
];
7190 /* Don't emit anything for redundant notes. */
7191 if (line_info
->dw_line_num
== current_line
7192 && line_info
->dw_file_num
== current_file
7193 && line_info
->function
== function
)
7197 /* Emit debug info for the address of the current line. If this is
7198 a new function, or the first line of a function, then we need
7199 to handle it differently. */
7200 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7202 if (function
!= line_info
->function
)
7204 function
= line_info
->function
;
7206 /* Set the address register to the first line in the function */
7207 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7208 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7209 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7210 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7214 /* ??? See the DW_LNS_advance_pc comment above. */
7217 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7218 "DW_LNS_fixed_advance_pc");
7219 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7223 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7224 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7225 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7226 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7230 strcpy (prev_line_label
, line_label
);
7232 /* Emit debug info for the source file of the current line, if
7233 different from the previous line. */
7234 if (line_info
->dw_file_num
!= current_file
)
7236 current_file
= line_info
->dw_file_num
;
7237 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7238 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7239 file_table
.table
[current_file
]);
7242 /* Emit debug info for the current line number, choosing the encoding
7243 that uses the least amount of space. */
7244 if (line_info
->dw_line_num
!= current_line
)
7246 line_offset
= line_info
->dw_line_num
- current_line
;
7247 line_delta
= line_offset
- DWARF_LINE_BASE
;
7248 current_line
= line_info
->dw_line_num
;
7249 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7250 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7251 "line %lu", current_line
);
7254 dw2_asm_output_data (1, DW_LNS_advance_line
,
7255 "advance to line %lu", current_line
);
7256 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7257 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7261 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7269 /* If we're done with a function, end its sequence. */
7270 if (lt_index
== separate_line_info_table_in_use
7271 || separate_line_info_table
[lt_index
].function
!= function
)
7276 /* Emit debug info for the address of the end of the function. */
7277 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7280 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7281 "DW_LNS_fixed_advance_pc");
7282 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7286 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7287 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7288 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7289 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7292 /* Output the marker for the end of this sequence. */
7293 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7294 dw2_asm_output_data_uleb128 (1, NULL
);
7295 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7299 /* Output the marker for the end of the line number info. */
7300 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7303 /* Given a pointer to a tree node for some base type, return a pointer to
7304 a DIE that describes the given type.
7306 This routine must only be called for GCC type nodes that correspond to
7307 Dwarf base (fundamental) types. */
7310 base_type_die (type
)
7313 dw_die_ref base_type_result
;
7314 const char *type_name
;
7315 enum dwarf_type encoding
;
7316 tree name
= TYPE_NAME (type
);
7318 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7323 if (TREE_CODE (name
) == TYPE_DECL
)
7324 name
= DECL_NAME (name
);
7326 type_name
= IDENTIFIER_POINTER (name
);
7329 type_name
= "__unknown__";
7331 switch (TREE_CODE (type
))
7334 /* Carefully distinguish the C character types, without messing
7335 up if the language is not C. Note that we check only for the names
7336 that contain spaces; other names might occur by coincidence in other
7338 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7339 && (type
== char_type_node
7340 || ! strcmp (type_name
, "signed char")
7341 || ! strcmp (type_name
, "unsigned char"))))
7343 if (TREE_UNSIGNED (type
))
7344 encoding
= DW_ATE_unsigned
;
7346 encoding
= DW_ATE_signed
;
7349 /* else fall through. */
7352 /* GNU Pascal/Ada CHAR type. Not used in C. */
7353 if (TREE_UNSIGNED (type
))
7354 encoding
= DW_ATE_unsigned_char
;
7356 encoding
= DW_ATE_signed_char
;
7360 encoding
= DW_ATE_float
;
7363 /* Dwarf2 doesn't know anything about complex ints, so use
7364 a user defined type for it. */
7366 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7367 encoding
= DW_ATE_complex_float
;
7369 encoding
= DW_ATE_lo_user
;
7373 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7374 encoding
= DW_ATE_boolean
;
7378 /* No other TREE_CODEs are Dwarf fundamental types. */
7382 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7383 if (demangle_name_func
)
7384 type_name
= (*demangle_name_func
) (type_name
);
7386 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7387 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7388 int_size_in_bytes (type
));
7389 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7391 return base_type_result
;
7394 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7395 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7396 a given type is generally the same as the given type, except that if the
7397 given type is a pointer or reference type, then the root type of the given
7398 type is the root type of the "basis" type for the pointer or reference
7399 type. (This definition of the "root" type is recursive.) Also, the root
7400 type of a `const' qualified type or a `volatile' qualified type is the
7401 root type of the given type without the qualifiers. */
7407 if (TREE_CODE (type
) == ERROR_MARK
)
7408 return error_mark_node
;
7410 switch (TREE_CODE (type
))
7413 return error_mark_node
;
7416 case REFERENCE_TYPE
:
7417 return type_main_variant (root_type (TREE_TYPE (type
)));
7420 return type_main_variant (type
);
7424 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7425 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7431 switch (TREE_CODE (type
))
7446 case QUAL_UNION_TYPE
:
7451 case REFERENCE_TYPE
:
7465 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7466 entry that chains various modifiers in front of the given type. */
7469 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7472 int is_volatile_type
;
7473 dw_die_ref context_die
;
7475 enum tree_code code
= TREE_CODE (type
);
7476 dw_die_ref mod_type_die
= NULL
;
7477 dw_die_ref sub_die
= NULL
;
7478 tree item_type
= NULL
;
7480 if (code
!= ERROR_MARK
)
7482 tree qualified_type
;
7484 /* See if we already have the appropriately qualified variant of
7487 = get_qualified_type (type
,
7488 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7490 ? TYPE_QUAL_VOLATILE
: 0)));
7492 /* If we do, then we can just use its DIE, if it exists. */
7495 mod_type_die
= lookup_type_die (qualified_type
);
7497 return mod_type_die
;
7500 /* Handle C typedef types. */
7501 if (qualified_type
&& TYPE_NAME (qualified_type
)
7502 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7503 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7505 tree type_name
= TYPE_NAME (qualified_type
);
7506 tree dtype
= TREE_TYPE (type_name
);
7508 if (qualified_type
== dtype
)
7510 /* For a named type, use the typedef. */
7511 gen_type_die (qualified_type
, context_die
);
7512 mod_type_die
= lookup_type_die (qualified_type
);
7514 else if (is_const_type
< TYPE_READONLY (dtype
)
7515 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7516 /* cv-unqualified version of named type. Just use the unnamed
7517 type to which it refers. */
7519 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7520 is_const_type
, is_volatile_type
,
7523 /* Else cv-qualified version of named type; fall through. */
7529 else if (is_const_type
)
7531 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7532 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7534 else if (is_volatile_type
)
7536 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7537 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7539 else if (code
== POINTER_TYPE
)
7541 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7542 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7544 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7546 item_type
= TREE_TYPE (type
);
7548 else if (code
== REFERENCE_TYPE
)
7550 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7551 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7553 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7555 item_type
= TREE_TYPE (type
);
7557 else if (is_base_type (type
))
7558 mod_type_die
= base_type_die (type
);
7561 gen_type_die (type
, context_die
);
7563 /* We have to get the type_main_variant here (and pass that to the
7564 `lookup_type_die' routine) because the ..._TYPE node we have
7565 might simply be a *copy* of some original type node (where the
7566 copy was created to help us keep track of typedef names) and
7567 that copy might have a different TYPE_UID from the original
7569 mod_type_die
= lookup_type_die (type_main_variant (type
));
7570 if (mod_type_die
== NULL
)
7574 /* We want to equate the qualified type to the die below. */
7576 type
= qualified_type
;
7579 equate_type_number_to_die (type
, mod_type_die
);
7581 /* We must do this after the equate_type_number_to_die call, in case
7582 this is a recursive type. This ensures that the modified_type_die
7583 recursion will terminate even if the type is recursive. Recursive
7584 types are possible in Ada. */
7585 sub_die
= modified_type_die (item_type
,
7586 TYPE_READONLY (item_type
),
7587 TYPE_VOLATILE (item_type
),
7590 if (sub_die
!= NULL
)
7591 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7593 return mod_type_die
;
7596 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7597 an enumerated type. */
7603 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7606 /* Return the register number described by a given RTL node. */
7612 unsigned regno
= REGNO (rtl
);
7614 if (regno
>= FIRST_PSEUDO_REGISTER
)
7617 return DBX_REGISTER_NUMBER (regno
);
7620 /* Return a location descriptor that designates a machine register or
7621 zero if there is no such. */
7623 static dw_loc_descr_ref
7624 reg_loc_descriptor (rtl
)
7627 dw_loc_descr_ref loc_result
= NULL
;
7630 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7633 reg
= reg_number (rtl
);
7635 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
7637 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
7642 /* Return a location descriptor that designates a constant. */
7644 static dw_loc_descr_ref
7645 int_loc_descriptor (i
)
7648 enum dwarf_location_atom op
;
7650 /* Pick the smallest representation of a constant, rather than just
7651 defaulting to the LEB encoding. */
7655 op
= DW_OP_lit0
+ i
;
7658 else if (i
<= 0xffff)
7660 else if (HOST_BITS_PER_WIDE_INT
== 32
7670 else if (i
>= -0x8000)
7672 else if (HOST_BITS_PER_WIDE_INT
== 32
7673 || i
>= -0x80000000)
7679 return new_loc_descr (op
, i
, 0);
7682 /* Return a location descriptor that designates a base+offset location. */
7684 static dw_loc_descr_ref
7685 based_loc_descr (reg
, offset
)
7689 dw_loc_descr_ref loc_result
;
7690 /* For the "frame base", we use the frame pointer or stack pointer
7691 registers, since the RTL for local variables is relative to one of
7693 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7694 ? HARD_FRAME_POINTER_REGNUM
7695 : STACK_POINTER_REGNUM
);
7698 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
7700 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
7702 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
7707 /* Return true if this RTL expression describes a base+offset calculation. */
7713 return (GET_CODE (rtl
) == PLUS
7714 && ((GET_CODE (XEXP (rtl
, 0)) == REG
7715 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
7716 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
7719 /* The following routine converts the RTL for a variable or parameter
7720 (resident in memory) into an equivalent Dwarf representation of a
7721 mechanism for getting the address of that same variable onto the top of a
7722 hypothetical "address evaluation" stack.
7724 When creating memory location descriptors, we are effectively transforming
7725 the RTL for a memory-resident object into its Dwarf postfix expression
7726 equivalent. This routine recursively descends an RTL tree, turning
7727 it into Dwarf postfix code as it goes.
7729 MODE is the mode of the memory reference, needed to handle some
7730 autoincrement addressing modes.
7732 Return 0 if we can't represent the location. */
7734 static dw_loc_descr_ref
7735 mem_loc_descriptor (rtl
, mode
)
7737 enum machine_mode mode
;
7739 dw_loc_descr_ref mem_loc_result
= NULL
;
7741 /* Note that for a dynamically sized array, the location we will generate a
7742 description of here will be the lowest numbered location which is
7743 actually within the array. That's *not* necessarily the same as the
7744 zeroth element of the array. */
7746 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7747 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
7750 switch (GET_CODE (rtl
))
7755 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7756 just fall into the SUBREG code. */
7758 /* ... fall through ... */
7761 /* The case of a subreg may arise when we have a local (register)
7762 variable or a formal (register) parameter which doesn't quite fill
7763 up an entire register. For now, just assume that it is
7764 legitimate to make the Dwarf info refer to the whole register which
7765 contains the given subreg. */
7766 rtl
= SUBREG_REG (rtl
);
7768 /* ... fall through ... */
7771 /* Whenever a register number forms a part of the description of the
7772 method for calculating the (dynamic) address of a memory resident
7773 object, DWARF rules require the register number be referred to as
7774 a "base register". This distinction is not based in any way upon
7775 what category of register the hardware believes the given register
7776 belongs to. This is strictly DWARF terminology we're dealing with
7777 here. Note that in cases where the location of a memory-resident
7778 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7779 OP_CONST (0)) the actual DWARF location descriptor that we generate
7780 may just be OP_BASEREG (basereg). This may look deceptively like
7781 the object in question was allocated to a register (rather than in
7782 memory) so DWARF consumers need to be aware of the subtle
7783 distinction between OP_REG and OP_BASEREG. */
7784 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
7785 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
7789 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7790 if (mem_loc_result
!= 0)
7791 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
7795 /* Some ports can transform a symbol ref into a label ref, because
7796 the symbol ref is too far away and has to be dumped into a constant
7800 /* Alternatively, the symbol in the constant pool might be referenced
7801 by a different symbol. */
7802 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
7804 rtx tmp
= get_pool_constant (rtl
);
7806 if (GET_CODE (tmp
) == SYMBOL_REF
)
7810 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
7811 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7812 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
7813 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
7817 /* Extract the PLUS expression nested inside and fall into
7819 rtl
= XEXP (rtl
, 1);
7824 /* Turn these into a PLUS expression and fall into the PLUS code
7826 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
7827 GEN_INT (GET_CODE (rtl
) == PRE_INC
7828 ? GET_MODE_UNIT_SIZE (mode
)
7829 : -GET_MODE_UNIT_SIZE (mode
)));
7831 /* ... fall through ... */
7835 if (is_based_loc (rtl
))
7836 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
7837 INTVAL (XEXP (rtl
, 1)));
7840 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7841 if (mem_loc_result
== 0)
7844 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
7845 && INTVAL (XEXP (rtl
, 1)) >= 0)
7846 add_loc_descr (&mem_loc_result
,
7847 new_loc_descr (DW_OP_plus_uconst
,
7848 INTVAL (XEXP (rtl
, 1)), 0));
7851 add_loc_descr (&mem_loc_result
,
7852 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7853 add_loc_descr (&mem_loc_result
,
7854 new_loc_descr (DW_OP_plus
, 0, 0));
7861 /* If a pseudo-reg is optimized away, it is possible for it to
7862 be replaced with a MEM containing a multiply. */
7863 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7864 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
7866 if (op0
== 0 || op1
== 0)
7869 mem_loc_result
= op0
;
7870 add_loc_descr (&mem_loc_result
, op1
);
7871 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
7876 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
7880 /* If this is a MEM, return its address. Otherwise, we can't
7882 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
7883 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
7891 return mem_loc_result
;
7894 /* Return a descriptor that describes the concatenation of two locations.
7895 This is typically a complex variable. */
7897 static dw_loc_descr_ref
7898 concat_loc_descriptor (x0
, x1
)
7901 dw_loc_descr_ref cc_loc_result
= NULL
;
7902 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
7903 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
7905 if (x0_ref
== 0 || x1_ref
== 0)
7908 cc_loc_result
= x0_ref
;
7909 add_loc_descr (&cc_loc_result
,
7910 new_loc_descr (DW_OP_piece
,
7911 GET_MODE_SIZE (GET_MODE (x0
)), 0));
7913 add_loc_descr (&cc_loc_result
, x1_ref
);
7914 add_loc_descr (&cc_loc_result
,
7915 new_loc_descr (DW_OP_piece
,
7916 GET_MODE_SIZE (GET_MODE (x1
)), 0));
7918 return cc_loc_result
;
7921 /* Output a proper Dwarf location descriptor for a variable or parameter
7922 which is either allocated in a register or in a memory location. For a
7923 register, we just generate an OP_REG and the register number. For a
7924 memory location we provide a Dwarf postfix expression describing how to
7925 generate the (dynamic) address of the object onto the address stack.
7927 If we don't know how to describe it, return 0. */
7929 static dw_loc_descr_ref
7930 loc_descriptor (rtl
)
7933 dw_loc_descr_ref loc_result
= NULL
;
7935 switch (GET_CODE (rtl
))
7938 /* The case of a subreg may arise when we have a local (register)
7939 variable or a formal (register) parameter which doesn't quite fill
7940 up an entire register. For now, just assume that it is
7941 legitimate to make the Dwarf info refer to the whole register which
7942 contains the given subreg. */
7943 rtl
= SUBREG_REG (rtl
);
7945 /* ... fall through ... */
7948 loc_result
= reg_loc_descriptor (rtl
);
7952 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7956 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
7966 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7967 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7968 looking for an address. Otherwise, we return a value. If we can't make a
7969 descriptor, return 0. */
7971 static dw_loc_descr_ref
7972 loc_descriptor_from_tree (loc
, addressp
)
7976 dw_loc_descr_ref ret
, ret1
;
7978 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
7979 enum dwarf_location_atom op
;
7981 /* ??? Most of the time we do not take proper care for sign/zero
7982 extending the values properly. Hopefully this won't be a real
7985 switch (TREE_CODE (loc
))
7990 case WITH_RECORD_EXPR
:
7991 case PLACEHOLDER_EXPR
:
7992 /* This case involves extracting fields from an object to determine the
7993 position of other fields. We don't try to encode this here. The
7994 only user of this is Ada, which encodes the needed information using
7995 the names of types. */
8002 /* We can support this only if we can look through conversions and
8003 find an INDIRECT_EXPR. */
8004 for (loc
= TREE_OPERAND (loc
, 0);
8005 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8006 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8007 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8008 || TREE_CODE (loc
) == SAVE_EXPR
;
8009 loc
= TREE_OPERAND (loc
, 0))
8012 return (TREE_CODE (loc
) == INDIRECT_REF
8013 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8019 rtx rtl
= rtl_for_decl_location (loc
);
8021 if (rtl
== NULL_RTX
)
8023 else if (CONSTANT_P (rtl
))
8025 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8026 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8027 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8032 enum machine_mode mode
= GET_MODE (rtl
);
8034 if (GET_CODE (rtl
) == MEM
)
8037 rtl
= XEXP (rtl
, 0);
8040 ret
= mem_loc_descriptor (rtl
, mode
);
8046 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8051 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8055 case NON_LVALUE_EXPR
:
8056 case VIEW_CONVERT_EXPR
:
8058 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8063 case ARRAY_RANGE_REF
:
8066 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8067 enum machine_mode mode
;
8070 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8071 &unsignedp
, &volatilep
);
8076 ret
= loc_descriptor_from_tree (obj
, 1);
8078 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8081 if (offset
!= NULL_TREE
)
8083 /* Variable offset. */
8084 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8085 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8091 bytepos
= bitpos
/ BITS_PER_UNIT
;
8093 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8094 else if (bytepos
< 0)
8096 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8097 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8103 if (host_integerp (loc
, 0))
8104 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8109 case TRUTH_AND_EXPR
:
8110 case TRUTH_ANDIF_EXPR
:
8115 case TRUTH_XOR_EXPR
:
8121 case TRUTH_ORIF_EXPR
:
8126 case TRUNC_DIV_EXPR
:
8134 case TRUNC_MOD_EXPR
:
8147 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8151 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8152 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8154 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8158 add_loc_descr (&ret
,
8159 new_loc_descr (DW_OP_plus_uconst
,
8160 tree_low_cst (TREE_OPERAND (loc
, 1),
8170 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8177 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8184 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8191 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8206 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8207 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8208 if (ret
== 0 || ret1
== 0)
8211 add_loc_descr (&ret
, ret1
);
8212 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8215 case TRUTH_NOT_EXPR
:
8229 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8233 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8237 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8238 build (LT_EXPR
, integer_type_node
,
8239 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8240 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8242 /* ... fall through ... */
8246 dw_loc_descr_ref lhs
8247 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8248 dw_loc_descr_ref rhs
8249 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8250 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8252 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8253 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8256 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8257 add_loc_descr (&ret
, bra_node
);
8259 add_loc_descr (&ret
, rhs
);
8260 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8261 add_loc_descr (&ret
, jump_node
);
8263 add_loc_descr (&ret
, lhs
);
8264 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8265 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8267 /* ??? Need a node to point the skip at. Use a nop. */
8268 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8269 add_loc_descr (&ret
, tmp
);
8270 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8271 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8279 /* Show if we can't fill the request for an address. */
8280 if (addressp
&& indirect_p
== 0)
8283 /* If we've got an address and don't want one, dereference. */
8284 if (!addressp
&& indirect_p
> 0)
8286 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8288 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8290 else if (size
== DWARF2_ADDR_SIZE
)
8293 op
= DW_OP_deref_size
;
8295 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8301 /* Given a value, round it up to the lowest multiple of `boundary'
8302 which is not less than the value itself. */
8304 static inline HOST_WIDE_INT
8305 ceiling (value
, boundary
)
8306 HOST_WIDE_INT value
;
8307 unsigned int boundary
;
8309 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8312 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8313 pointer to the declared type for the relevant field variable, or return
8314 `integer_type_node' if the given node turns out to be an
8323 if (TREE_CODE (decl
) == ERROR_MARK
)
8324 return integer_type_node
;
8326 type
= DECL_BIT_FIELD_TYPE (decl
);
8327 if (type
== NULL_TREE
)
8328 type
= TREE_TYPE (decl
);
8333 /* Given a pointer to a tree node, return the alignment in bits for
8334 it, or else return BITS_PER_WORD if the node actually turns out to
8335 be an ERROR_MARK node. */
8337 static inline unsigned
8338 simple_type_align_in_bits (type
)
8341 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8344 static inline unsigned
8345 simple_decl_align_in_bits (decl
)
8348 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8351 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8352 node, return the size in bits for the type if it is a constant, or else
8353 return the alignment for the type if the type's size is not constant, or
8354 else return BITS_PER_WORD if the type actually turns out to be an
8357 static inline unsigned HOST_WIDE_INT
8358 simple_type_size_in_bits (type
)
8362 if (TREE_CODE (type
) == ERROR_MARK
)
8363 return BITS_PER_WORD
;
8364 else if (TYPE_SIZE (type
) == NULL_TREE
)
8366 else if (host_integerp (TYPE_SIZE (type
), 1))
8367 return tree_low_cst (TYPE_SIZE (type
), 1);
8369 return TYPE_ALIGN (type
);
8372 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8373 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8374 or return 0 if we are unable to determine what that offset is, either
8375 because the argument turns out to be a pointer to an ERROR_MARK node, or
8376 because the offset is actually variable. (We can't handle the latter case
8379 static HOST_WIDE_INT
8380 field_byte_offset (decl
)
8383 unsigned int type_align_in_bits
;
8384 unsigned int decl_align_in_bits
;
8385 unsigned HOST_WIDE_INT type_size_in_bits
;
8386 HOST_WIDE_INT object_offset_in_bits
;
8388 tree field_size_tree
;
8389 HOST_WIDE_INT bitpos_int
;
8390 HOST_WIDE_INT deepest_bitpos
;
8391 unsigned HOST_WIDE_INT field_size_in_bits
;
8393 if (TREE_CODE (decl
) == ERROR_MARK
)
8395 else if (TREE_CODE (decl
) != FIELD_DECL
)
8398 type
= field_type (decl
);
8399 field_size_tree
= DECL_SIZE (decl
);
8401 /* The size could be unspecified if there was an error, or for
8402 a flexible array member. */
8403 if (! field_size_tree
)
8404 field_size_tree
= bitsize_zero_node
;
8406 /* We cannot yet cope with fields whose positions are variable, so
8407 for now, when we see such things, we simply return 0. Someday, we may
8408 be able to handle such cases, but it will be damn difficult. */
8409 if (! host_integerp (bit_position (decl
), 0))
8412 bitpos_int
= int_bit_position (decl
);
8414 /* If we don't know the size of the field, pretend it's a full word. */
8415 if (host_integerp (field_size_tree
, 1))
8416 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8418 field_size_in_bits
= BITS_PER_WORD
;
8420 type_size_in_bits
= simple_type_size_in_bits (type
);
8421 type_align_in_bits
= simple_type_align_in_bits (type
);
8422 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8424 /* The GCC front-end doesn't make any attempt to keep track of the starting
8425 bit offset (relative to the start of the containing structure type) of the
8426 hypothetical "containing object" for a bit-field. Thus, when computing
8427 the byte offset value for the start of the "containing object" of a
8428 bit-field, we must deduce this information on our own. This can be rather
8429 tricky to do in some cases. For example, handling the following structure
8430 type definition when compiling for an i386/i486 target (which only aligns
8431 long long's to 32-bit boundaries) can be very tricky:
8433 struct S { int field1; long long field2:31; };
8435 Fortunately, there is a simple rule-of-thumb which can be used in such
8436 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8437 structure shown above. It decides to do this based upon one simple rule
8438 for bit-field allocation. GCC allocates each "containing object" for each
8439 bit-field at the first (i.e. lowest addressed) legitimate alignment
8440 boundary (based upon the required minimum alignment for the declared type
8441 of the field) which it can possibly use, subject to the condition that
8442 there is still enough available space remaining in the containing object
8443 (when allocated at the selected point) to fully accommodate all of the
8444 bits of the bit-field itself.
8446 This simple rule makes it obvious why GCC allocates 8 bytes for each
8447 object of the structure type shown above. When looking for a place to
8448 allocate the "containing object" for `field2', the compiler simply tries
8449 to allocate a 64-bit "containing object" at each successive 32-bit
8450 boundary (starting at zero) until it finds a place to allocate that 64-
8451 bit field such that at least 31 contiguous (and previously unallocated)
8452 bits remain within that selected 64 bit field. (As it turns out, for the
8453 example above, the compiler finds it is OK to allocate the "containing
8454 object" 64-bit field at bit-offset zero within the structure type.)
8456 Here we attempt to work backwards from the limited set of facts we're
8457 given, and we try to deduce from those facts, where GCC must have believed
8458 that the containing object started (within the structure type). The value
8459 we deduce is then used (by the callers of this routine) to generate
8460 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8461 and, in the case of DW_AT_location, regular fields as well). */
8463 /* Figure out the bit-distance from the start of the structure to the
8464 "deepest" bit of the bit-field. */
8465 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8467 /* This is the tricky part. Use some fancy footwork to deduce where the
8468 lowest addressed bit of the containing object must be. */
8469 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8471 /* Round up to type_align by default. This works best for bitfields. */
8472 object_offset_in_bits
+= type_align_in_bits
- 1;
8473 object_offset_in_bits
/= type_align_in_bits
;
8474 object_offset_in_bits
*= type_align_in_bits
;
8476 if (object_offset_in_bits
> bitpos_int
)
8478 /* Sigh, the decl must be packed. */
8479 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8481 /* Round up to decl_align instead. */
8482 object_offset_in_bits
+= decl_align_in_bits
- 1;
8483 object_offset_in_bits
/= decl_align_in_bits
;
8484 object_offset_in_bits
*= decl_align_in_bits
;
8487 return object_offset_in_bits
/ BITS_PER_UNIT
;
8490 /* The following routines define various Dwarf attributes and any data
8491 associated with them. */
8493 /* Add a location description attribute value to a DIE.
8495 This emits location attributes suitable for whole variables and
8496 whole parameters. Note that the location attributes for struct fields are
8497 generated by the routine `data_member_location_attribute' below. */
8500 add_AT_location_description (die
, attr_kind
, rtl
)
8502 enum dwarf_attribute attr_kind
;
8505 dw_loc_descr_ref descr
= loc_descriptor (rtl
);
8508 add_AT_loc (die
, attr_kind
, descr
);
8511 /* Attach the specialized form of location attribute used for data members of
8512 struct and union types. In the special case of a FIELD_DECL node which
8513 represents a bit-field, the "offset" part of this special location
8514 descriptor must indicate the distance in bytes from the lowest-addressed
8515 byte of the containing struct or union type to the lowest-addressed byte of
8516 the "containing object" for the bit-field. (See the `field_byte_offset'
8519 For any given bit-field, the "containing object" is a hypothetical object
8520 (of some integral or enum type) within which the given bit-field lives. The
8521 type of this hypothetical "containing object" is always the same as the
8522 declared type of the individual bit-field itself (for GCC anyway... the
8523 DWARF spec doesn't actually mandate this). Note that it is the size (in
8524 bytes) of the hypothetical "containing object" which will be given in the
8525 DW_AT_byte_size attribute for this bit-field. (See the
8526 `byte_size_attribute' function below.) It is also used when calculating the
8527 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8531 add_data_member_location_attribute (die
, decl
)
8536 dw_loc_descr_ref loc_descr
= 0;
8538 if (TREE_CODE (decl
) == TREE_VEC
)
8540 /* We're working on the TAG_inheritance for a base class. */
8541 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8543 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8544 aren't at a fixed offset from all (sub)objects of the same
8545 type. We need to extract the appropriate offset from our
8546 vtable. The following dwarf expression means
8548 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8550 This is specific to the V3 ABI, of course. */
8552 dw_loc_descr_ref tmp
;
8554 /* Make a copy of the object address. */
8555 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8556 add_loc_descr (&loc_descr
, tmp
);
8558 /* Extract the vtable address. */
8559 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8560 add_loc_descr (&loc_descr
, tmp
);
8562 /* Calculate the address of the offset. */
8563 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8567 tmp
= int_loc_descriptor (-offset
);
8568 add_loc_descr (&loc_descr
, tmp
);
8569 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8570 add_loc_descr (&loc_descr
, tmp
);
8572 /* Extract the offset. */
8573 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8574 add_loc_descr (&loc_descr
, tmp
);
8576 /* Add it to the object address. */
8577 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
8578 add_loc_descr (&loc_descr
, tmp
);
8581 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
8584 offset
= field_byte_offset (decl
);
8588 enum dwarf_location_atom op
;
8590 /* The DWARF2 standard says that we should assume that the structure
8591 address is already on the stack, so we can specify a structure field
8592 address by using DW_OP_plus_uconst. */
8594 #ifdef MIPS_DEBUGGING_INFO
8595 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8596 operator correctly. It works only if we leave the offset on the
8600 op
= DW_OP_plus_uconst
;
8603 loc_descr
= new_loc_descr (op
, offset
, 0);
8606 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
8609 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8610 does not have a "location" either in memory or in a register. These
8611 things can arise in GNU C when a constant is passed as an actual parameter
8612 to an inlined function. They can also arise in C++ where declared
8613 constants do not necessarily get memory "homes". */
8616 add_const_value_attribute (die
, rtl
)
8620 switch (GET_CODE (rtl
))
8623 /* Note that a CONST_INT rtx could represent either an integer
8624 or a floating-point constant. A CONST_INT is used whenever
8625 the constant will fit into a single word. In all such
8626 cases, the original mode of the constant value is wiped
8627 out, and the CONST_INT rtx is assigned VOIDmode. */
8629 HOST_WIDE_INT val
= INTVAL (rtl
);
8631 /* ??? We really should be using HOST_WIDE_INT throughout. */
8632 if (val
< 0 && (long) val
== val
)
8633 add_AT_int (die
, DW_AT_const_value
, (long) val
);
8634 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
8635 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
8638 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8639 add_AT_long_long (die
, DW_AT_const_value
,
8640 val
>> HOST_BITS_PER_LONG
, val
);
8649 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8650 floating-point constant. A CONST_DOUBLE is used whenever the
8651 constant requires more than one word in order to be adequately
8652 represented. We output CONST_DOUBLEs as blocks. */
8654 enum machine_mode mode
= GET_MODE (rtl
);
8656 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
8658 unsigned length
= GET_MODE_SIZE (mode
) / 4;
8659 long *array
= (long *) xmalloc (sizeof (long) * length
);
8662 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
8666 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
8670 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
8675 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
8682 add_AT_float (die
, DW_AT_const_value
, length
, array
);
8686 /* ??? We really should be using HOST_WIDE_INT throughout. */
8687 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
8690 add_AT_long_long (die
, DW_AT_const_value
,
8691 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
8697 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
8703 add_AT_addr (die
, DW_AT_const_value
, rtl
);
8704 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8708 /* In cases where an inlined instance of an inline function is passed
8709 the address of an `auto' variable (which is local to the caller) we
8710 can get a situation where the DECL_RTL of the artificial local
8711 variable (for the inlining) which acts as a stand-in for the
8712 corresponding formal parameter (of the inline function) will look
8713 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8714 exactly a compile-time constant expression, but it isn't the address
8715 of the (artificial) local variable either. Rather, it represents the
8716 *value* which the artificial local variable always has during its
8717 lifetime. We currently have no way to represent such quasi-constant
8718 values in Dwarf, so for now we just punt and generate nothing. */
8722 /* No other kinds of rtx should be possible here. */
8729 rtl_for_decl_location (decl
)
8734 /* Here we have to decide where we are going to say the parameter "lives"
8735 (as far as the debugger is concerned). We only have a couple of
8736 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8738 DECL_RTL normally indicates where the parameter lives during most of the
8739 activation of the function. If optimization is enabled however, this
8740 could be either NULL or else a pseudo-reg. Both of those cases indicate
8741 that the parameter doesn't really live anywhere (as far as the code
8742 generation parts of GCC are concerned) during most of the function's
8743 activation. That will happen (for example) if the parameter is never
8744 referenced within the function.
8746 We could just generate a location descriptor here for all non-NULL
8747 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8748 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8749 where DECL_RTL is NULL or is a pseudo-reg.
8751 Note however that we can only get away with using DECL_INCOMING_RTL as
8752 a backup substitute for DECL_RTL in certain limited cases. In cases
8753 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8754 we can be sure that the parameter was passed using the same type as it is
8755 declared to have within the function, and that its DECL_INCOMING_RTL
8756 points us to a place where a value of that type is passed.
8758 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8759 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8760 because in these cases DECL_INCOMING_RTL points us to a value of some
8761 type which is *different* from the type of the parameter itself. Thus,
8762 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8763 such cases, the debugger would end up (for example) trying to fetch a
8764 `float' from a place which actually contains the first part of a
8765 `double'. That would lead to really incorrect and confusing
8766 output at debug-time.
8768 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8769 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8770 are a couple of exceptions however. On little-endian machines we can
8771 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8772 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8773 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8774 when (on a little-endian machine) a non-prototyped function has a
8775 parameter declared to be of type `short' or `char'. In such cases,
8776 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8777 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8778 passed `int' value. If the debugger then uses that address to fetch
8779 a `short' or a `char' (on a little-endian machine) the result will be
8780 the correct data, so we allow for such exceptional cases below.
8782 Note that our goal here is to describe the place where the given formal
8783 parameter lives during most of the function's activation (i.e. between the
8784 end of the prologue and the start of the epilogue). We'll do that as best
8785 as we can. Note however that if the given formal parameter is modified
8786 sometime during the execution of the function, then a stack backtrace (at
8787 debug-time) will show the function as having been called with the *new*
8788 value rather than the value which was originally passed in. This happens
8789 rarely enough that it is not a major problem, but it *is* a problem, and
8792 A future version of dwarf2out.c may generate two additional attributes for
8793 any given DW_TAG_formal_parameter DIE which will describe the "passed
8794 type" and the "passed location" for the given formal parameter in addition
8795 to the attributes we now generate to indicate the "declared type" and the
8796 "active location" for each parameter. This additional set of attributes
8797 could be used by debuggers for stack backtraces. Separately, note that
8798 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8799 This happens (for example) for inlined-instances of inline function formal
8800 parameters which are never referenced. This really shouldn't be
8801 happening. All PARM_DECL nodes should get valid non-NULL
8802 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8803 values for inlined instances of inline function parameters, so when we see
8804 such cases, we are just out-of-luck for the time being (until integrate.c
8807 /* Use DECL_RTL as the "location" unless we find something better. */
8808 rtl
= DECL_RTL_IF_SET (decl
);
8810 /* When generating abstract instances, ignore everything except
8811 constants and symbols living in memory. */
8812 if (! reload_completed
)
8815 && (CONSTANT_P (rtl
)
8816 || (GET_CODE (rtl
) == MEM
8817 && CONSTANT_P (XEXP (rtl
, 0)))))
8821 else if (TREE_CODE (decl
) == PARM_DECL
)
8823 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
8825 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
8826 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
8828 /* This decl represents a formal parameter which was optimized out.
8829 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8830 all cases where (rtl == NULL_RTX) just below. */
8831 if (declared_type
== passed_type
)
8832 rtl
= DECL_INCOMING_RTL (decl
);
8833 else if (! BYTES_BIG_ENDIAN
8834 && TREE_CODE (declared_type
) == INTEGER_TYPE
8835 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
8836 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
8837 rtl
= DECL_INCOMING_RTL (decl
);
8840 /* If the parm was passed in registers, but lives on the stack, then
8841 make a big endian correction if the mode of the type of the
8842 parameter is not the same as the mode of the rtl. */
8843 /* ??? This is the same series of checks that are made in dbxout.c before
8844 we reach the big endian correction code there. It isn't clear if all
8845 of these checks are necessary here, but keeping them all is the safe
8847 else if (GET_CODE (rtl
) == MEM
8848 && XEXP (rtl
, 0) != const0_rtx
8849 && ! CONSTANT_P (XEXP (rtl
, 0))
8850 /* Not passed in memory. */
8851 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
8852 /* Not passed by invisible reference. */
8853 && (GET_CODE (XEXP (rtl
, 0)) != REG
8854 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
8855 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
8856 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8857 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
8860 /* Big endian correction check. */
8862 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
8863 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
8866 int offset
= (UNITS_PER_WORD
8867 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
8869 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
8870 plus_constant (XEXP (rtl
, 0), offset
));
8874 if (rtl
!= NULL_RTX
)
8876 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
8877 #ifdef LEAF_REG_REMAP
8878 if (current_function_uses_only_leaf_regs
)
8879 leaf_renumber_regs_insn (rtl
);
8883 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8884 and will have been substituted directly into all expressions that use it.
8885 C does not have such a concept, but C++ and other languages do. */
8886 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
8887 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
8888 EXPAND_INITIALIZER
);
8893 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8894 data attribute for a variable or a parameter. We generate the
8895 DW_AT_const_value attribute only in those cases where the given variable
8896 or parameter does not have a true "location" either in memory or in a
8897 register. This can happen (for example) when a constant is passed as an
8898 actual argument in a call to an inline function. (It's possible that
8899 these things can crop up in other ways also.) Note that one type of
8900 constant value which can be passed into an inlined function is a constant
8901 pointer. This can happen for example if an actual argument in an inlined
8902 function call evaluates to a compile-time constant address. */
8905 add_location_or_const_value_attribute (die
, decl
)
8911 if (TREE_CODE (decl
) == ERROR_MARK
)
8913 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
8916 rtl
= rtl_for_decl_location (decl
);
8917 if (rtl
== NULL_RTX
)
8920 /* If we don't look past the constant pool, we risk emitting a
8921 reference to a constant pool entry that isn't referenced from
8922 code, and thus is not emitted. */
8923 rtl
= avoid_constant_pool_reference (rtl
);
8925 switch (GET_CODE (rtl
))
8928 /* The address of a variable that was optimized away; don't emit
8939 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8940 add_const_value_attribute (die
, rtl
);
8947 add_AT_location_description (die
, DW_AT_location
, rtl
);
8955 /* If we don't have a copy of this variable in memory for some reason (such
8956 as a C++ member constant that doesn't have an out-of-line definition),
8957 we should tell the debugger about the constant value. */
8960 tree_add_const_value_attribute (var_die
, decl
)
8964 tree init
= DECL_INITIAL (decl
);
8965 tree type
= TREE_TYPE (decl
);
8967 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
8968 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
8973 switch (TREE_CODE (type
))
8976 if (host_integerp (init
, 0))
8977 add_AT_unsigned (var_die
, DW_AT_const_value
,
8978 tree_low_cst (init
, 0));
8980 add_AT_long_long (var_die
, DW_AT_const_value
,
8981 TREE_INT_CST_HIGH (init
),
8982 TREE_INT_CST_LOW (init
));
8989 /* Generate an DW_AT_name attribute given some string value to be included as
8990 the value of the attribute. */
8993 add_name_attribute (die
, name_string
)
8995 const char *name_string
;
8997 if (name_string
!= NULL
&& *name_string
!= 0)
8999 if (demangle_name_func
)
9000 name_string
= (*demangle_name_func
) (name_string
);
9002 add_AT_string (die
, DW_AT_name
, name_string
);
9006 /* Given a tree node describing an array bound (either lower or upper) output
9007 a representation for that bound. */
9010 add_bound_info (subrange_die
, bound_attr
, bound
)
9011 dw_die_ref subrange_die
;
9012 enum dwarf_attribute bound_attr
;
9015 switch (TREE_CODE (bound
))
9020 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9022 if (! host_integerp (bound
, 0)
9023 || (bound_attr
== DW_AT_lower_bound
9024 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9025 || (is_fortran () && integer_onep (bound
)))))
9026 /* use the default */
9029 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9034 case NON_LVALUE_EXPR
:
9035 case VIEW_CONVERT_EXPR
:
9036 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9040 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9041 access the upper bound values may be bogus. If they refer to a
9042 register, they may only describe how to get at these values at the
9043 points in the generated code right after they have just been
9044 computed. Worse yet, in the typical case, the upper bound values
9045 will not even *be* computed in the optimized code (though the
9046 number of elements will), so these SAVE_EXPRs are entirely
9047 bogus. In order to compensate for this fact, we check here to see
9048 if optimization is enabled, and if so, we don't add an attribute
9049 for the (unknown and unknowable) upper bound. This should not
9050 cause too much trouble for existing (stupid?) debuggers because
9051 they have to deal with empty upper bounds location descriptions
9052 anyway in order to be able to deal with incomplete array types.
9053 Of course an intelligent debugger (GDB?) should be able to
9054 comprehend that a missing upper bound specification in an array
9055 type used for a storage class `auto' local array variable
9056 indicates that the upper bound is both unknown (at compile- time)
9057 and unknowable (at run-time) due to optimization.
9059 We assume that a MEM rtx is safe because gcc wouldn't put the
9060 value there unless it was going to be used repeatedly in the
9061 function, i.e. for cleanups. */
9062 if (SAVE_EXPR_RTL (bound
)
9063 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9065 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9066 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9067 rtx loc
= SAVE_EXPR_RTL (bound
);
9069 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9070 it references an outer function's frame. */
9071 if (GET_CODE (loc
) == MEM
)
9073 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9075 if (XEXP (loc
, 0) != new_addr
)
9076 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9079 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9080 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9081 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
9082 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9085 /* Else leave out the attribute. */
9091 dw_die_ref decl_die
= lookup_decl_die (bound
);
9093 /* ??? Can this happen, or should the variable have been bound
9094 first? Probably it can, since I imagine that we try to create
9095 the types of parameters in the order in which they exist in
9096 the list, and won't have created a forward reference to a
9098 if (decl_die
!= NULL
)
9099 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9105 /* Otherwise try to create a stack operation procedure to
9106 evaluate the value of the array bound. */
9108 dw_die_ref ctx
, decl_die
;
9109 dw_loc_descr_ref loc
;
9111 loc
= loc_descriptor_from_tree (bound
, 0);
9115 if (current_function_decl
== 0)
9116 ctx
= comp_unit_die
;
9118 ctx
= lookup_decl_die (current_function_decl
);
9120 /* If we weren't able to find a context, it's most likely the case
9121 that we are processing the return type of the function. So
9122 make a SAVE_EXPR to point to it and have the limbo DIE code
9123 find the proper die. The save_expr function doesn't always
9124 make a SAVE_EXPR, so do it ourselves. */
9126 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9127 current_function_decl
, NULL_TREE
);
9129 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9130 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9131 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9132 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9134 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9140 /* Note that the block of subscript information for an array type also
9141 includes information about the element type of type given array type. */
9144 add_subscript_info (type_die
, type
)
9145 dw_die_ref type_die
;
9148 #ifndef MIPS_DEBUGGING_INFO
9149 unsigned dimension_number
;
9152 dw_die_ref subrange_die
;
9154 /* The GNU compilers represent multidimensional array types as sequences of
9155 one dimensional array types whose element types are themselves array
9156 types. Here we squish that down, so that each multidimensional array
9157 type gets only one array_type DIE in the Dwarf debugging info. The draft
9158 Dwarf specification say that we are allowed to do this kind of
9159 compression in C (because there is no difference between an array or
9160 arrays and a multidimensional array in C) but for other source languages
9161 (e.g. Ada) we probably shouldn't do this. */
9163 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9164 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9165 We work around this by disabling this feature. See also
9166 gen_array_type_die. */
9167 #ifndef MIPS_DEBUGGING_INFO
9168 for (dimension_number
= 0;
9169 TREE_CODE (type
) == ARRAY_TYPE
;
9170 type
= TREE_TYPE (type
), dimension_number
++)
9173 tree domain
= TYPE_DOMAIN (type
);
9175 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9176 and (in GNU C only) variable bounds. Handle all three forms
9178 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9181 /* We have an array type with specified bounds. */
9182 lower
= TYPE_MIN_VALUE (domain
);
9183 upper
= TYPE_MAX_VALUE (domain
);
9185 /* define the index type. */
9186 if (TREE_TYPE (domain
))
9188 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9189 TREE_TYPE field. We can't emit debug info for this
9190 because it is an unnamed integral type. */
9191 if (TREE_CODE (domain
) == INTEGER_TYPE
9192 && TYPE_NAME (domain
) == NULL_TREE
9193 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9194 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9197 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9201 /* ??? If upper is NULL, the array has unspecified length,
9202 but it does have a lower bound. This happens with Fortran
9204 Since the debugger is definitely going to need to know N
9205 to produce useful results, go ahead and output the lower
9206 bound solo, and hope the debugger can cope. */
9208 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9210 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9213 /* Otherwise we have an array type with an unspecified length. The
9214 DWARF-2 spec does not say how to handle this; let's just leave out the
9220 add_byte_size_attribute (die
, tree_node
)
9226 switch (TREE_CODE (tree_node
))
9234 case QUAL_UNION_TYPE
:
9235 size
= int_size_in_bytes (tree_node
);
9238 /* For a data member of a struct or union, the DW_AT_byte_size is
9239 generally given as the number of bytes normally allocated for an
9240 object of the *declared* type of the member itself. This is true
9241 even for bit-fields. */
9242 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9248 /* Note that `size' might be -1 when we get to this point. If it is, that
9249 indicates that the byte size of the entity in question is variable. We
9250 have no good way of expressing this fact in Dwarf at the present time,
9251 so just let the -1 pass on through. */
9252 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9255 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9256 which specifies the distance in bits from the highest order bit of the
9257 "containing object" for the bit-field to the highest order bit of the
9260 For any given bit-field, the "containing object" is a hypothetical object
9261 (of some integral or enum type) within which the given bit-field lives. The
9262 type of this hypothetical "containing object" is always the same as the
9263 declared type of the individual bit-field itself. The determination of the
9264 exact location of the "containing object" for a bit-field is rather
9265 complicated. It's handled by the `field_byte_offset' function (above).
9267 Note that it is the size (in bytes) of the hypothetical "containing object"
9268 which will be given in the DW_AT_byte_size attribute for this bit-field.
9269 (See `byte_size_attribute' above). */
9272 add_bit_offset_attribute (die
, decl
)
9276 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9277 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9278 HOST_WIDE_INT bitpos_int
;
9279 HOST_WIDE_INT highest_order_object_bit_offset
;
9280 HOST_WIDE_INT highest_order_field_bit_offset
;
9281 HOST_WIDE_INT
unsigned bit_offset
;
9283 /* Must be a field and a bit field. */
9285 || TREE_CODE (decl
) != FIELD_DECL
)
9288 /* We can't yet handle bit-fields whose offsets are variable, so if we
9289 encounter such things, just return without generating any attribute
9290 whatsoever. Likewise for variable or too large size. */
9291 if (! host_integerp (bit_position (decl
), 0)
9292 || ! host_integerp (DECL_SIZE (decl
), 1))
9295 bitpos_int
= int_bit_position (decl
);
9297 /* Note that the bit offset is always the distance (in bits) from the
9298 highest-order bit of the "containing object" to the highest-order bit of
9299 the bit-field itself. Since the "high-order end" of any object or field
9300 is different on big-endian and little-endian machines, the computation
9301 below must take account of these differences. */
9302 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9303 highest_order_field_bit_offset
= bitpos_int
;
9305 if (! BYTES_BIG_ENDIAN
)
9307 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9308 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9312 = (! BYTES_BIG_ENDIAN
9313 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9314 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9316 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9319 /* For a FIELD_DECL node which represents a bit field, output an attribute
9320 which specifies the length in bits of the given field. */
9323 add_bit_size_attribute (die
, decl
)
9327 /* Must be a field and a bit field. */
9328 if (TREE_CODE (decl
) != FIELD_DECL
9329 || ! DECL_BIT_FIELD_TYPE (decl
))
9332 if (host_integerp (DECL_SIZE (decl
), 1))
9333 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9336 /* If the compiled language is ANSI C, then add a 'prototyped'
9337 attribute, if arg types are given for the parameters of a function. */
9340 add_prototyped_attribute (die
, func_type
)
9344 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9345 && TYPE_ARG_TYPES (func_type
) != NULL
)
9346 add_AT_flag (die
, DW_AT_prototyped
, 1);
9349 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9350 by looking in either the type declaration or object declaration
9354 add_abstract_origin_attribute (die
, origin
)
9358 dw_die_ref origin_die
= NULL
;
9360 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9362 /* We may have gotten separated from the block for the inlined
9363 function, if we're in an exception handler or some such; make
9364 sure that the abstract function has been written out.
9366 Doing this for nested functions is wrong, however; functions are
9367 distinct units, and our context might not even be inline. */
9371 fn
= TYPE_STUB_DECL (fn
);
9373 fn
= decl_function_context (fn
);
9375 dwarf2out_abstract_function (fn
);
9378 if (DECL_P (origin
))
9379 origin_die
= lookup_decl_die (origin
);
9380 else if (TYPE_P (origin
))
9381 origin_die
= lookup_type_die (origin
);
9383 if (origin_die
== NULL
)
9386 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9389 /* We do not currently support the pure_virtual attribute. */
9392 add_pure_or_virtual_attribute (die
, func_decl
)
9396 if (DECL_VINDEX (func_decl
))
9398 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9400 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9401 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9402 new_loc_descr (DW_OP_constu
,
9403 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9406 /* GNU extension: Record what type this method came from originally. */
9407 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9408 add_AT_die_ref (die
, DW_AT_containing_type
,
9409 lookup_type_die (DECL_CONTEXT (func_decl
)));
9413 /* Add source coordinate attributes for the given decl. */
9416 add_src_coords_attributes (die
, decl
)
9420 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9422 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9423 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9426 /* Add an DW_AT_name attribute and source coordinate attribute for the
9427 given decl, but only if it actually has a name. */
9430 add_name_and_src_coords_attributes (die
, decl
)
9436 decl_name
= DECL_NAME (decl
);
9437 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9439 add_name_attribute (die
, dwarf2_name (decl
, 0));
9440 if (! DECL_ARTIFICIAL (decl
))
9441 add_src_coords_attributes (die
, decl
);
9443 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9444 && TREE_PUBLIC (decl
)
9445 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9446 && !DECL_ABSTRACT (decl
))
9447 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9448 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9451 #ifdef VMS_DEBUGGING_INFO
9452 /* Get the function's name, as described by its RTL. This may be different
9453 from the DECL_NAME name used in the source file. */
9454 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9456 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9457 XEXP (DECL_RTL (decl
), 0));
9458 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9463 /* Push a new declaration scope. */
9466 push_decl_scope (scope
)
9469 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9472 /* Pop a declaration scope. */
9477 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9480 VARRAY_POP (decl_scope_table
);
9483 /* Return the DIE for the scope that immediately contains this type.
9484 Non-named types get global scope. Named types nested in other
9485 types get their containing scope if it's open, or global scope
9486 otherwise. All other types (i.e. function-local named types) get
9487 the current active scope. */
9490 scope_die_for (t
, context_die
)
9492 dw_die_ref context_die
;
9494 dw_die_ref scope_die
= NULL
;
9495 tree containing_scope
;
9498 /* Non-types always go in the current scope. */
9502 containing_scope
= TYPE_CONTEXT (t
);
9504 /* Ignore namespaces for the moment. */
9505 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9506 containing_scope
= NULL_TREE
;
9508 /* Ignore function type "scopes" from the C frontend. They mean that
9509 a tagged type is local to a parmlist of a function declarator, but
9510 that isn't useful to DWARF. */
9511 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9512 containing_scope
= NULL_TREE
;
9514 if (containing_scope
== NULL_TREE
)
9515 scope_die
= comp_unit_die
;
9516 else if (TYPE_P (containing_scope
))
9518 /* For types, we can just look up the appropriate DIE. But
9519 first we check to see if we're in the middle of emitting it
9520 so we know where the new DIE should go. */
9521 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9522 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9527 if (debug_info_level
> DINFO_LEVEL_TERSE
9528 && !TREE_ASM_WRITTEN (containing_scope
))
9531 /* If none of the current dies are suitable, we get file scope. */
9532 scope_die
= comp_unit_die
;
9535 scope_die
= lookup_type_die (containing_scope
);
9538 scope_die
= context_die
;
9543 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9546 local_scope_p (context_die
)
9547 dw_die_ref context_die
;
9549 for (; context_die
; context_die
= context_die
->die_parent
)
9550 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
9551 || context_die
->die_tag
== DW_TAG_subprogram
)
9557 /* Returns nonzero if CONTEXT_DIE is a class. */
9560 class_scope_p (context_die
)
9561 dw_die_ref context_die
;
9564 && (context_die
->die_tag
== DW_TAG_structure_type
9565 || context_die
->die_tag
== DW_TAG_union_type
));
9568 /* Many forms of DIEs require a "type description" attribute. This
9569 routine locates the proper "type descriptor" die for the type given
9570 by 'type', and adds an DW_AT_type attribute below the given die. */
9573 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
9574 dw_die_ref object_die
;
9578 dw_die_ref context_die
;
9580 enum tree_code code
= TREE_CODE (type
);
9581 dw_die_ref type_die
= NULL
;
9583 /* ??? If this type is an unnamed subrange type of an integral or
9584 floating-point type, use the inner type. This is because we have no
9585 support for unnamed types in base_type_die. This can happen if this is
9586 an Ada subrange type. Correct solution is emit a subrange type die. */
9587 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
9588 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
9589 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
9591 if (code
== ERROR_MARK
9592 /* Handle a special case. For functions whose return type is void, we
9593 generate *no* type attribute. (Note that no object may have type
9594 `void', so this only applies to function return types). */
9595 || code
== VOID_TYPE
)
9598 type_die
= modified_type_die (type
,
9599 decl_const
|| TYPE_READONLY (type
),
9600 decl_volatile
|| TYPE_VOLATILE (type
),
9603 if (type_die
!= NULL
)
9604 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
9607 /* Given a tree pointer to a struct, class, union, or enum type node, return
9608 a pointer to the (string) tag name for the given type, or zero if the type
9609 was declared without a tag. */
9615 const char *name
= 0;
9617 if (TYPE_NAME (type
) != 0)
9621 /* Find the IDENTIFIER_NODE for the type name. */
9622 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9623 t
= TYPE_NAME (type
);
9625 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9626 a TYPE_DECL node, regardless of whether or not a `typedef' was
9628 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9629 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
9630 t
= DECL_NAME (TYPE_NAME (type
));
9632 /* Now get the name as a string, or invent one. */
9634 name
= IDENTIFIER_POINTER (t
);
9637 return (name
== 0 || *name
== '\0') ? 0 : name
;
9640 /* Return the type associated with a data member, make a special check
9641 for bit field types. */
9644 member_declared_type (member
)
9647 return (DECL_BIT_FIELD_TYPE (member
)
9648 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
9651 /* Get the decl's label, as described by its RTL. This may be different
9652 from the DECL_NAME name used in the source file. */
9656 decl_start_label (decl
)
9662 x
= DECL_RTL (decl
);
9663 if (GET_CODE (x
) != MEM
)
9667 if (GET_CODE (x
) != SYMBOL_REF
)
9670 fnname
= XSTR (x
, 0);
9675 /* These routines generate the internal representation of the DIE's for
9676 the compilation unit. Debugging information is collected by walking
9677 the declaration trees passed in from dwarf2out_decl(). */
9680 gen_array_type_die (type
, context_die
)
9682 dw_die_ref context_die
;
9684 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
9685 dw_die_ref array_die
;
9688 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9689 the inner array type comes before the outer array type. Thus we must
9690 call gen_type_die before we call new_die. See below also. */
9691 #ifdef MIPS_DEBUGGING_INFO
9692 gen_type_die (TREE_TYPE (type
), context_die
);
9695 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
9698 /* We default the array ordering. SDB will probably do
9699 the right things even if DW_AT_ordering is not present. It's not even
9700 an issue until we start to get into multidimensional arrays anyway. If
9701 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9702 then we'll have to put the DW_AT_ordering attribute back in. (But if
9703 and when we find out that we need to put these in, we will only do so
9704 for multidimensional arrays. */
9705 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
9708 #ifdef MIPS_DEBUGGING_INFO
9709 /* The SGI compilers handle arrays of unknown bound by setting
9710 AT_declaration and not emitting any subrange DIEs. */
9711 if (! TYPE_DOMAIN (type
))
9712 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
9715 add_subscript_info (array_die
, type
);
9717 add_name_attribute (array_die
, type_tag (type
));
9718 equate_type_number_to_die (type
, array_die
);
9720 /* Add representation of the type of the elements of this array type. */
9721 element_type
= TREE_TYPE (type
);
9723 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9724 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9725 We work around this by disabling this feature. See also
9726 add_subscript_info. */
9727 #ifndef MIPS_DEBUGGING_INFO
9728 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
9729 element_type
= TREE_TYPE (element_type
);
9731 gen_type_die (element_type
, context_die
);
9734 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
9738 gen_set_type_die (type
, context_die
)
9740 dw_die_ref context_die
;
9743 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
9745 equate_type_number_to_die (type
, type_die
);
9746 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
9751 gen_entry_point_die (decl
, context_die
)
9753 dw_die_ref context_die
;
9755 tree origin
= decl_ultimate_origin (decl
);
9756 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
9759 add_abstract_origin_attribute (decl_die
, origin
);
9762 add_name_and_src_coords_attributes (decl_die
, decl
);
9763 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
9767 if (DECL_ABSTRACT (decl
))
9768 equate_decl_number_to_die (decl
, decl_die
);
9770 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
9774 /* Walk through the list of incomplete types again, trying once more to
9775 emit full debugging info for them. */
9778 retry_incomplete_types ()
9782 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
9783 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
9786 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9789 gen_inlined_enumeration_type_die (type
, context_die
)
9791 dw_die_ref context_die
;
9793 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
9795 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9796 be incomplete and such types are not marked. */
9797 add_abstract_origin_attribute (type_die
, type
);
9800 /* Generate a DIE to represent an inlined instance of a structure type. */
9803 gen_inlined_structure_type_die (type
, context_die
)
9805 dw_die_ref context_die
;
9807 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
9809 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9810 be incomplete and such types are not marked. */
9811 add_abstract_origin_attribute (type_die
, type
);
9814 /* Generate a DIE to represent an inlined instance of a union type. */
9817 gen_inlined_union_type_die (type
, context_die
)
9819 dw_die_ref context_die
;
9821 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
9823 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9824 be incomplete and such types are not marked. */
9825 add_abstract_origin_attribute (type_die
, type
);
9828 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9829 include all of the information about the enumeration values also. Each
9830 enumerated type name/value is listed as a child of the enumerated type
9834 gen_enumeration_type_die (type
, context_die
)
9836 dw_die_ref context_die
;
9838 dw_die_ref type_die
= lookup_type_die (type
);
9840 if (type_die
== NULL
)
9842 type_die
= new_die (DW_TAG_enumeration_type
,
9843 scope_die_for (type
, context_die
), type
);
9844 equate_type_number_to_die (type
, type_die
);
9845 add_name_attribute (type_die
, type_tag (type
));
9847 else if (! TYPE_SIZE (type
))
9850 remove_AT (type_die
, DW_AT_declaration
);
9852 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9853 given enum type is incomplete, do not generate the DW_AT_byte_size
9854 attribute or the DW_AT_element_list attribute. */
9855 if (TYPE_SIZE (type
))
9859 TREE_ASM_WRITTEN (type
) = 1;
9860 add_byte_size_attribute (type_die
, type
);
9861 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
9862 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
9864 /* If the first reference to this type was as the return type of an
9865 inline function, then it may not have a parent. Fix this now. */
9866 if (type_die
->die_parent
== NULL
)
9867 add_child_die (scope_die_for (type
, context_die
), type_die
);
9869 for (link
= TYPE_FIELDS (type
);
9870 link
!= NULL
; link
= TREE_CHAIN (link
))
9872 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
9874 add_name_attribute (enum_die
,
9875 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
9877 if (host_integerp (TREE_VALUE (link
), 0))
9879 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
9880 add_AT_int (enum_die
, DW_AT_const_value
,
9881 tree_low_cst (TREE_VALUE (link
), 0));
9883 add_AT_unsigned (enum_die
, DW_AT_const_value
,
9884 tree_low_cst (TREE_VALUE (link
), 0));
9889 add_AT_flag (type_die
, DW_AT_declaration
, 1);
9892 /* Generate a DIE to represent either a real live formal parameter decl or to
9893 represent just the type of some formal parameter position in some function
9896 Note that this routine is a bit unusual because its argument may be a
9897 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9898 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9899 node. If it's the former then this function is being called to output a
9900 DIE to represent a formal parameter object (or some inlining thereof). If
9901 it's the latter, then this function is only being called to output a
9902 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9903 argument type of some subprogram type. */
9906 gen_formal_parameter_die (node
, context_die
)
9908 dw_die_ref context_die
;
9911 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
9914 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
9917 origin
= decl_ultimate_origin (node
);
9919 add_abstract_origin_attribute (parm_die
, origin
);
9922 add_name_and_src_coords_attributes (parm_die
, node
);
9923 add_type_attribute (parm_die
, TREE_TYPE (node
),
9924 TREE_READONLY (node
),
9925 TREE_THIS_VOLATILE (node
),
9927 if (DECL_ARTIFICIAL (node
))
9928 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
9931 equate_decl_number_to_die (node
, parm_die
);
9932 if (! DECL_ABSTRACT (node
))
9933 add_location_or_const_value_attribute (parm_die
, node
);
9938 /* We were called with some kind of a ..._TYPE node. */
9939 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
9949 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9950 at the end of an (ANSI prototyped) formal parameters list. */
9953 gen_unspecified_parameters_die (decl_or_type
, context_die
)
9955 dw_die_ref context_die
;
9957 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
9960 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9961 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9962 parameters as specified in some function type specification (except for
9963 those which appear as part of a function *definition*). */
9966 gen_formal_types_die (function_or_method_type
, context_die
)
9967 tree function_or_method_type
;
9968 dw_die_ref context_die
;
9971 tree formal_type
= NULL
;
9972 tree first_parm_type
;
9975 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
9977 arg
= DECL_ARGUMENTS (function_or_method_type
);
9978 function_or_method_type
= TREE_TYPE (function_or_method_type
);
9983 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
9985 /* Make our first pass over the list of formal parameter types and output a
9986 DW_TAG_formal_parameter DIE for each one. */
9987 for (link
= first_parm_type
; link
; )
9989 dw_die_ref parm_die
;
9991 formal_type
= TREE_VALUE (link
);
9992 if (formal_type
== void_type_node
)
9995 /* Output a (nameless) DIE to represent the formal parameter itself. */
9996 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
9997 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
9998 && link
== first_parm_type
)
9999 || (arg
&& DECL_ARTIFICIAL (arg
)))
10000 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10002 link
= TREE_CHAIN (link
);
10004 arg
= TREE_CHAIN (arg
);
10007 /* If this function type has an ellipsis, add a
10008 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10009 if (formal_type
!= void_type_node
)
10010 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10012 /* Make our second (and final) pass over the list of formal parameter types
10013 and output DIEs to represent those types (as necessary). */
10014 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10015 link
&& TREE_VALUE (link
);
10016 link
= TREE_CHAIN (link
))
10017 gen_type_die (TREE_VALUE (link
), context_die
);
10020 /* We want to generate the DIE for TYPE so that we can generate the
10021 die for MEMBER, which has been defined; we will need to refer back
10022 to the member declaration nested within TYPE. If we're trying to
10023 generate minimal debug info for TYPE, processing TYPE won't do the
10024 trick; we need to attach the member declaration by hand. */
10027 gen_type_die_for_member (type
, member
, context_die
)
10029 dw_die_ref context_die
;
10031 gen_type_die (type
, context_die
);
10033 /* If we're trying to avoid duplicate debug info, we may not have
10034 emitted the member decl for this function. Emit it now. */
10035 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10036 && ! lookup_decl_die (member
))
10038 if (decl_ultimate_origin (member
))
10041 push_decl_scope (type
);
10042 if (TREE_CODE (member
) == FUNCTION_DECL
)
10043 gen_subprogram_die (member
, lookup_type_die (type
));
10045 gen_variable_die (member
, lookup_type_die (type
));
10051 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10052 may later generate inlined and/or out-of-line instances of. */
10055 dwarf2out_abstract_function (decl
)
10058 dw_die_ref old_die
;
10061 int was_abstract
= DECL_ABSTRACT (decl
);
10063 /* Make sure we have the actual abstract inline, not a clone. */
10064 decl
= DECL_ORIGIN (decl
);
10066 old_die
= lookup_decl_die (decl
);
10067 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10068 /* We've already generated the abstract instance. */
10071 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10072 we don't get confused by DECL_ABSTRACT. */
10073 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10075 context
= decl_class_context (decl
);
10077 gen_type_die_for_member
10078 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10081 /* Pretend we've just finished compiling this function. */
10082 save_fn
= current_function_decl
;
10083 current_function_decl
= decl
;
10085 set_decl_abstract_flags (decl
, 1);
10086 dwarf2out_decl (decl
);
10087 if (! was_abstract
)
10088 set_decl_abstract_flags (decl
, 0);
10090 current_function_decl
= save_fn
;
10093 /* Generate a DIE to represent a declared function (either file-scope or
10097 gen_subprogram_die (decl
, context_die
)
10099 dw_die_ref context_die
;
10101 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10102 tree origin
= decl_ultimate_origin (decl
);
10103 dw_die_ref subr_die
;
10107 dw_die_ref old_die
= lookup_decl_die (decl
);
10108 int declaration
= (current_function_decl
!= decl
10109 || class_scope_p (context_die
));
10111 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10112 started to generate the abstract instance of an inline, decided to output
10113 its containing class, and proceeded to emit the declaration of the inline
10114 from the member list for the class. If so, DECLARATION takes priority;
10115 we'll get back to the abstract instance when done with the class. */
10117 /* The class-scope declaration DIE must be the primary DIE. */
10118 if (origin
&& declaration
&& class_scope_p (context_die
))
10125 if (origin
!= NULL
)
10127 if (declaration
&& ! local_scope_p (context_die
))
10130 /* Fixup die_parent for the abstract instance of a nested
10131 inline function. */
10132 if (old_die
&& old_die
->die_parent
== NULL
)
10133 add_child_die (context_die
, old_die
);
10135 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10136 add_abstract_origin_attribute (subr_die
, origin
);
10140 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10142 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10143 /* We can have a normal definition following an inline one in the
10144 case of redefinition of GNU C extern inlines.
10145 It seems reasonable to use AT_specification in this case. */
10146 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10148 /* ??? This can happen if there is a bug in the program, for
10149 instance, if it has duplicate function definitions. Ideally,
10150 we should detect this case and ignore it. For now, if we have
10151 already reported an error, any error at all, then assume that
10152 we got here because of an input error, not a dwarf2 bug. */
10158 /* If the definition comes from the same place as the declaration,
10159 maybe use the old DIE. We always want the DIE for this function
10160 that has the *_pc attributes to be under comp_unit_die so the
10161 debugger can find it. We also need to do this for abstract
10162 instances of inlines, since the spec requires the out-of-line copy
10163 to have the same parent. For local class methods, this doesn't
10164 apply; we just use the old DIE. */
10165 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10166 && (DECL_ARTIFICIAL (decl
)
10167 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10168 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10169 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10171 subr_die
= old_die
;
10173 /* Clear out the declaration attribute and the parm types. */
10174 remove_AT (subr_die
, DW_AT_declaration
);
10175 remove_children (subr_die
);
10179 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10180 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10181 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10182 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10183 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10184 != (unsigned) DECL_SOURCE_LINE (decl
))
10186 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10191 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10193 if (TREE_PUBLIC (decl
))
10194 add_AT_flag (subr_die
, DW_AT_external
, 1);
10196 add_name_and_src_coords_attributes (subr_die
, decl
);
10197 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10199 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10200 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10201 0, 0, context_die
);
10204 add_pure_or_virtual_attribute (subr_die
, decl
);
10205 if (DECL_ARTIFICIAL (decl
))
10206 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10208 if (TREE_PROTECTED (decl
))
10209 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10210 else if (TREE_PRIVATE (decl
))
10211 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10216 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10218 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10220 /* The first time we see a member function, it is in the context of
10221 the class to which it belongs. We make sure of this by emitting
10222 the class first. The next time is the definition, which is
10223 handled above. The two may come from the same source text. */
10224 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10225 equate_decl_number_to_die (decl
, subr_die
);
10228 else if (DECL_ABSTRACT (decl
))
10230 if (DECL_INLINE (decl
) && !flag_no_inline
)
10232 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10233 inline functions, but not for extern inline functions.
10234 We can't get this completely correct because information
10235 about whether the function was declared inline is not
10237 if (DECL_DEFER_OUTPUT (decl
))
10238 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10240 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10243 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10245 equate_decl_number_to_die (decl
, subr_die
);
10247 else if (!DECL_EXTERNAL (decl
))
10249 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10250 equate_decl_number_to_die (decl
, subr_die
);
10252 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10253 current_funcdef_number
);
10254 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10255 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10256 current_funcdef_number
);
10257 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10259 add_pubname (decl
, subr_die
);
10260 add_arange (decl
, subr_die
);
10262 #ifdef MIPS_DEBUGGING_INFO
10263 /* Add a reference to the FDE for this routine. */
10264 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10267 /* Define the "frame base" location for this routine. We use the
10268 frame pointer or stack pointer registers, since the RTL for local
10269 variables is relative to one of them. */
10271 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10272 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10275 /* ??? This fails for nested inline functions, because context_display
10276 is not part of the state saved/restored for inline functions. */
10277 if (current_function_needs_context
)
10278 add_AT_location_description (subr_die
, DW_AT_static_link
,
10279 lookup_static_chain (decl
));
10283 /* Now output descriptions of the arguments for this function. This gets
10284 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10285 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10286 `...' at the end of the formal parameter list. In order to find out if
10287 there was a trailing ellipsis or not, we must instead look at the type
10288 associated with the FUNCTION_DECL. This will be a node of type
10289 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10290 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10291 an ellipsis at the end. */
10293 /* In the case where we are describing a mere function declaration, all we
10294 need to do here (and all we *can* do here) is to describe the *types* of
10295 its formal parameters. */
10296 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10298 else if (declaration
)
10299 gen_formal_types_die (decl
, subr_die
);
10302 /* Generate DIEs to represent all known formal parameters */
10303 tree arg_decls
= DECL_ARGUMENTS (decl
);
10306 /* When generating DIEs, generate the unspecified_parameters DIE
10307 instead if we come across the arg "__builtin_va_alist" */
10308 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10309 if (TREE_CODE (parm
) == PARM_DECL
)
10311 if (DECL_NAME (parm
)
10312 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10313 "__builtin_va_alist"))
10314 gen_unspecified_parameters_die (parm
, subr_die
);
10316 gen_decl_die (parm
, subr_die
);
10319 /* Decide whether we need an unspecified_parameters DIE at the end.
10320 There are 2 more cases to do this for: 1) the ansi ... declaration -
10321 this is detectable when the end of the arg list is not a
10322 void_type_node 2) an unprototyped function declaration (not a
10323 definition). This just means that we have no info about the
10324 parameters at all. */
10325 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10326 if (fn_arg_types
!= NULL
)
10328 /* this is the prototyped case, check for ... */
10329 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10330 gen_unspecified_parameters_die (decl
, subr_die
);
10332 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10333 gen_unspecified_parameters_die (decl
, subr_die
);
10336 /* Output Dwarf info for all of the stuff within the body of the function
10337 (if it has one - it may be just a declaration). */
10338 outer_scope
= DECL_INITIAL (decl
);
10340 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10341 a function. This BLOCK actually represents the outermost binding contour
10342 for the function, i.e. the contour in which the function's formal
10343 parameters and labels get declared. Curiously, it appears that the front
10344 end doesn't actually put the PARM_DECL nodes for the current function onto
10345 the BLOCK_VARS list for this outer scope, but are strung off of the
10346 DECL_ARGUMENTS list for the function instead.
10348 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10349 the LABEL_DECL nodes for the function however, and we output DWARF info
10350 for those in decls_for_scope. Just within the `outer_scope' there will be
10351 a BLOCK node representing the function's outermost pair of curly braces,
10352 and any blocks used for the base and member initializers of a C++
10353 constructor function. */
10354 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10356 current_function_has_inlines
= 0;
10357 decls_for_scope (outer_scope
, subr_die
, 0);
10359 #if 0 && defined (MIPS_DEBUGGING_INFO)
10360 if (current_function_has_inlines
)
10362 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10363 if (! comp_unit_has_inlines
)
10365 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10366 comp_unit_has_inlines
= 1;
10373 /* Generate a DIE to represent a declared data object. */
10376 gen_variable_die (decl
, context_die
)
10378 dw_die_ref context_die
;
10380 tree origin
= decl_ultimate_origin (decl
);
10381 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10383 dw_die_ref old_die
= lookup_decl_die (decl
);
10384 int declaration
= (DECL_EXTERNAL (decl
)
10385 || class_scope_p (context_die
));
10387 if (origin
!= NULL
)
10388 add_abstract_origin_attribute (var_die
, origin
);
10390 /* Loop unrolling can create multiple blocks that refer to the same
10391 static variable, so we must test for the DW_AT_declaration flag.
10393 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10394 copy decls and set the DECL_ABSTRACT flag on them instead of
10397 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10398 else if (old_die
&& TREE_STATIC (decl
)
10399 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10401 /* This is a definition of a C++ class level static. */
10402 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10403 if (DECL_NAME (decl
))
10405 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10407 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10408 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10410 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10411 != (unsigned) DECL_SOURCE_LINE (decl
))
10413 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10414 DECL_SOURCE_LINE (decl
));
10419 add_name_and_src_coords_attributes (var_die
, decl
);
10420 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10421 TREE_THIS_VOLATILE (decl
), context_die
);
10423 if (TREE_PUBLIC (decl
))
10424 add_AT_flag (var_die
, DW_AT_external
, 1);
10426 if (DECL_ARTIFICIAL (decl
))
10427 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10429 if (TREE_PROTECTED (decl
))
10430 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10431 else if (TREE_PRIVATE (decl
))
10432 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10436 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10438 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10439 equate_decl_number_to_die (decl
, var_die
);
10441 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10443 add_location_or_const_value_attribute (var_die
, decl
);
10444 add_pubname (decl
, var_die
);
10447 tree_add_const_value_attribute (var_die
, decl
);
10450 /* Generate a DIE to represent a label identifier. */
10453 gen_label_die (decl
, context_die
)
10455 dw_die_ref context_die
;
10457 tree origin
= decl_ultimate_origin (decl
);
10458 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10460 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10462 if (origin
!= NULL
)
10463 add_abstract_origin_attribute (lbl_die
, origin
);
10465 add_name_and_src_coords_attributes (lbl_die
, decl
);
10467 if (DECL_ABSTRACT (decl
))
10468 equate_decl_number_to_die (decl
, lbl_die
);
10471 insn
= DECL_RTL (decl
);
10473 /* Deleted labels are programmer specified labels which have been
10474 eliminated because of various optimisations. We still emit them
10475 here so that it is possible to put breakpoints on them. */
10476 if (GET_CODE (insn
) == CODE_LABEL
10477 || ((GET_CODE (insn
) == NOTE
10478 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10480 /* When optimization is enabled (via -O) some parts of the compiler
10481 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10482 represent source-level labels which were explicitly declared by
10483 the user. This really shouldn't be happening though, so catch
10484 it if it ever does happen. */
10485 if (INSN_DELETED_P (insn
))
10488 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10489 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10494 /* Generate a DIE for a lexical block. */
10497 gen_lexical_block_die (stmt
, context_die
, depth
)
10499 dw_die_ref context_die
;
10502 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10503 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10505 if (! BLOCK_ABSTRACT (stmt
))
10507 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10511 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10513 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10516 add_ranges (chain
);
10517 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10524 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10525 BLOCK_NUMBER (stmt
));
10526 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10527 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10528 BLOCK_NUMBER (stmt
));
10529 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10533 decls_for_scope (stmt
, stmt_die
, depth
);
10536 /* Generate a DIE for an inlined subprogram. */
10539 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
10541 dw_die_ref context_die
;
10544 if (! BLOCK_ABSTRACT (stmt
))
10546 dw_die_ref subr_die
10547 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10548 tree decl
= block_ultimate_origin (stmt
);
10549 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10551 /* Emit info for the abstract instance first, if we haven't yet. */
10552 dwarf2out_abstract_function (decl
);
10554 add_abstract_origin_attribute (subr_die
, decl
);
10555 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10556 BLOCK_NUMBER (stmt
));
10557 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10558 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10559 BLOCK_NUMBER (stmt
));
10560 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10561 decls_for_scope (stmt
, subr_die
, depth
);
10562 current_function_has_inlines
= 1;
10566 /* Generate a DIE for a field in a record, or structure. */
10569 gen_field_die (decl
, context_die
)
10571 dw_die_ref context_die
;
10573 dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
10575 add_name_and_src_coords_attributes (decl_die
, decl
);
10576 add_type_attribute (decl_die
, member_declared_type (decl
),
10577 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
10580 if (DECL_BIT_FIELD_TYPE (decl
))
10582 add_byte_size_attribute (decl_die
, decl
);
10583 add_bit_size_attribute (decl_die
, decl
);
10584 add_bit_offset_attribute (decl_die
, decl
);
10587 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
10588 add_data_member_location_attribute (decl_die
, decl
);
10590 if (DECL_ARTIFICIAL (decl
))
10591 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10593 if (TREE_PROTECTED (decl
))
10594 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10595 else if (TREE_PRIVATE (decl
))
10596 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10600 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10601 Use modified_type_die instead.
10602 We keep this code here just in case these types of DIEs may be needed to
10603 represent certain things in other languages (e.g. Pascal) someday. */
10606 gen_pointer_type_die (type
, context_die
)
10608 dw_die_ref context_die
;
10611 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
10613 equate_type_number_to_die (type
, ptr_die
);
10614 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10615 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10618 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10619 Use modified_type_die instead.
10620 We keep this code here just in case these types of DIEs may be needed to
10621 represent certain things in other languages (e.g. Pascal) someday. */
10624 gen_reference_type_die (type
, context_die
)
10626 dw_die_ref context_die
;
10629 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
10631 equate_type_number_to_die (type
, ref_die
);
10632 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
10633 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10637 /* Generate a DIE for a pointer to a member type. */
10640 gen_ptr_to_mbr_type_die (type
, context_die
)
10642 dw_die_ref context_die
;
10645 = new_die (DW_TAG_ptr_to_member_type
,
10646 scope_die_for (type
, context_die
), type
);
10648 equate_type_number_to_die (type
, ptr_die
);
10649 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
10650 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
10651 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10654 /* Generate the DIE for the compilation unit. */
10657 gen_compile_unit_die (filename
)
10658 const char *filename
;
10661 char producer
[250];
10662 const char *wd
= getpwd ();
10663 const char *language_string
= lang_hooks
.name
;
10666 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
10667 add_name_attribute (die
, filename
);
10669 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
10670 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10672 sprintf (producer
, "%s %s", language_string
, version_string
);
10674 #ifdef MIPS_DEBUGGING_INFO
10675 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10676 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10677 not appear in the producer string, the debugger reaches the conclusion
10678 that the object file is stripped and has no debugging information.
10679 To get the MIPS/SGI debugger to believe that there is debugging
10680 information in the object file, we add a -g to the producer string. */
10681 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10682 strcat (producer
, " -g");
10685 add_AT_string (die
, DW_AT_producer
, producer
);
10687 if (strcmp (language_string
, "GNU C++") == 0)
10688 language
= DW_LANG_C_plus_plus
;
10689 else if (strcmp (language_string
, "GNU Ada") == 0)
10690 language
= DW_LANG_Ada83
;
10691 else if (strcmp (language_string
, "GNU F77") == 0)
10692 language
= DW_LANG_Fortran77
;
10693 else if (strcmp (language_string
, "GNU Pascal") == 0)
10694 language
= DW_LANG_Pascal83
;
10695 else if (strcmp (language_string
, "GNU Java") == 0)
10696 language
= DW_LANG_Java
;
10697 else if (flag_traditional
)
10698 language
= DW_LANG_C
;
10700 language
= DW_LANG_C89
;
10702 add_AT_unsigned (die
, DW_AT_language
, language
);
10706 /* Generate a DIE for a string type. */
10709 gen_string_type_die (type
, context_die
)
10711 dw_die_ref context_die
;
10713 dw_die_ref type_die
10714 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
10716 equate_type_number_to_die (type
, type_die
);
10718 /* ??? Fudge the string length attribute for now.
10719 TODO: add string length info. */
10721 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
10722 bound_representation (upper_bound
, 0, 'u');
10726 /* Generate the DIE for a base class. */
10729 gen_inheritance_die (binfo
, context_die
)
10731 dw_die_ref context_die
;
10733 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
10735 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
10736 add_data_member_location_attribute (die
, binfo
);
10738 if (TREE_VIA_VIRTUAL (binfo
))
10739 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10741 if (TREE_VIA_PUBLIC (binfo
))
10742 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
10743 else if (TREE_VIA_PROTECTED (binfo
))
10744 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10747 /* Generate a DIE for a class member. */
10750 gen_member_die (type
, context_die
)
10752 dw_die_ref context_die
;
10757 /* If this is not an incomplete type, output descriptions of each of its
10758 members. Note that as we output the DIEs necessary to represent the
10759 members of this record or union type, we will also be trying to output
10760 DIEs to represent the *types* of those members. However the `type'
10761 function (above) will specifically avoid generating type DIEs for member
10762 types *within* the list of member DIEs for this (containing) type except
10763 for those types (of members) which are explicitly marked as also being
10764 members of this (containing) type themselves. The g++ front- end can
10765 force any given type to be treated as a member of some other (containing)
10766 type by setting the TYPE_CONTEXT of the given (member) type to point to
10767 the TREE node representing the appropriate (containing) type. */
10769 /* First output info about the base classes. */
10770 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
10772 tree bases
= TYPE_BINFO_BASETYPES (type
);
10773 int n_bases
= TREE_VEC_LENGTH (bases
);
10776 for (i
= 0; i
< n_bases
; i
++)
10777 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
10780 /* Now output info about the data members and type members. */
10781 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
10783 /* If we thought we were generating minimal debug info for TYPE
10784 and then changed our minds, some of the member declarations
10785 may have already been defined. Don't define them again, but
10786 do put them in the right order. */
10788 child
= lookup_decl_die (member
);
10790 splice_child_die (context_die
, child
);
10792 gen_decl_die (member
, context_die
);
10795 /* Now output info about the function members (if any). */
10796 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
10798 /* Don't include clones in the member list. */
10799 if (DECL_ABSTRACT_ORIGIN (member
))
10802 child
= lookup_decl_die (member
);
10804 splice_child_die (context_die
, child
);
10806 gen_decl_die (member
, context_die
);
10810 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10811 is set, we pretend that the type was never defined, so we only get the
10812 member DIEs needed by later specification DIEs. */
10815 gen_struct_or_union_type_die (type
, context_die
)
10817 dw_die_ref context_die
;
10819 dw_die_ref type_die
= lookup_type_die (type
);
10820 dw_die_ref scope_die
= 0;
10822 int complete
= (TYPE_SIZE (type
)
10823 && (! TYPE_STUB_DECL (type
)
10824 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
10826 if (type_die
&& ! complete
)
10829 if (TYPE_CONTEXT (type
) != NULL_TREE
10830 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
10833 scope_die
= scope_die_for (type
, context_die
);
10835 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
10836 /* First occurrence of type or toplevel definition of nested class. */
10838 dw_die_ref old_die
= type_die
;
10840 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
10841 ? DW_TAG_structure_type
: DW_TAG_union_type
,
10843 equate_type_number_to_die (type
, type_die
);
10845 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
10847 add_name_attribute (type_die
, type_tag (type
));
10850 remove_AT (type_die
, DW_AT_declaration
);
10852 /* If this type has been completed, then give it a byte_size attribute and
10853 then give a list of members. */
10856 /* Prevent infinite recursion in cases where the type of some member of
10857 this type is expressed in terms of this type itself. */
10858 TREE_ASM_WRITTEN (type
) = 1;
10859 add_byte_size_attribute (type_die
, type
);
10860 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10861 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10863 /* If the first reference to this type was as the return type of an
10864 inline function, then it may not have a parent. Fix this now. */
10865 if (type_die
->die_parent
== NULL
)
10866 add_child_die (scope_die
, type_die
);
10868 push_decl_scope (type
);
10869 gen_member_die (type
, type_die
);
10872 /* GNU extension: Record what type our vtable lives in. */
10873 if (TYPE_VFIELD (type
))
10875 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
10877 gen_type_die (vtype
, context_die
);
10878 add_AT_die_ref (type_die
, DW_AT_containing_type
,
10879 lookup_type_die (vtype
));
10884 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10886 /* We don't need to do this for function-local types. */
10887 if (TYPE_STUB_DECL (type
)
10888 && ! decl_function_context (TYPE_STUB_DECL (type
)))
10889 VARRAY_PUSH_TREE (incomplete_types
, type
);
10893 /* Generate a DIE for a subroutine _type_. */
10896 gen_subroutine_type_die (type
, context_die
)
10898 dw_die_ref context_die
;
10900 tree return_type
= TREE_TYPE (type
);
10901 dw_die_ref subr_die
10902 = new_die (DW_TAG_subroutine_type
,
10903 scope_die_for (type
, context_die
), type
);
10905 equate_type_number_to_die (type
, subr_die
);
10906 add_prototyped_attribute (subr_die
, type
);
10907 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
10908 gen_formal_types_die (type
, subr_die
);
10911 /* Generate a DIE for a type definition */
10914 gen_typedef_die (decl
, context_die
)
10916 dw_die_ref context_die
;
10918 dw_die_ref type_die
;
10921 if (TREE_ASM_WRITTEN (decl
))
10924 TREE_ASM_WRITTEN (decl
) = 1;
10925 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
10926 origin
= decl_ultimate_origin (decl
);
10927 if (origin
!= NULL
)
10928 add_abstract_origin_attribute (type_die
, origin
);
10933 add_name_and_src_coords_attributes (type_die
, decl
);
10934 if (DECL_ORIGINAL_TYPE (decl
))
10936 type
= DECL_ORIGINAL_TYPE (decl
);
10938 if (type
== TREE_TYPE (decl
))
10941 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
10944 type
= TREE_TYPE (decl
);
10946 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
10947 TREE_THIS_VOLATILE (decl
), context_die
);
10950 if (DECL_ABSTRACT (decl
))
10951 equate_decl_number_to_die (decl
, type_die
);
10954 /* Generate a type description DIE. */
10957 gen_type_die (type
, context_die
)
10959 dw_die_ref context_die
;
10963 if (type
== NULL_TREE
|| type
== error_mark_node
)
10966 /* We are going to output a DIE to represent the unqualified version of
10967 this type (i.e. without any const or volatile qualifiers) so get the
10968 main variant (i.e. the unqualified version) of this type now. */
10969 type
= type_main_variant (type
);
10971 if (TREE_ASM_WRITTEN (type
))
10974 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10975 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
10977 TREE_ASM_WRITTEN (type
) = 1;
10978 gen_decl_die (TYPE_NAME (type
), context_die
);
10982 switch (TREE_CODE (type
))
10988 case REFERENCE_TYPE
:
10989 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10990 ensures that the gen_type_die recursion will terminate even if the
10991 type is recursive. Recursive types are possible in Ada. */
10992 /* ??? We could perhaps do this for all types before the switch
10994 TREE_ASM_WRITTEN (type
) = 1;
10996 /* For these types, all that is required is that we output a DIE (or a
10997 set of DIEs) to represent the "basis" type. */
10998 gen_type_die (TREE_TYPE (type
), context_die
);
11002 /* This code is used for C++ pointer-to-data-member types.
11003 Output a description of the relevant class type. */
11004 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11006 /* Output a description of the type of the object pointed to. */
11007 gen_type_die (TREE_TYPE (type
), context_die
);
11009 /* Now output a DIE to represent this pointer-to-data-member type
11011 gen_ptr_to_mbr_type_die (type
, context_die
);
11015 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11016 gen_set_type_die (type
, context_die
);
11020 gen_type_die (TREE_TYPE (type
), context_die
);
11021 abort (); /* No way to represent these in Dwarf yet! */
11024 case FUNCTION_TYPE
:
11025 /* Force out return type (in case it wasn't forced out already). */
11026 gen_type_die (TREE_TYPE (type
), context_die
);
11027 gen_subroutine_type_die (type
, context_die
);
11031 /* Force out return type (in case it wasn't forced out already). */
11032 gen_type_die (TREE_TYPE (type
), context_die
);
11033 gen_subroutine_type_die (type
, context_die
);
11037 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11039 gen_type_die (TREE_TYPE (type
), context_die
);
11040 gen_string_type_die (type
, context_die
);
11043 gen_array_type_die (type
, context_die
);
11047 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type
), context_die
);
11050 case ENUMERAL_TYPE
:
11053 case QUAL_UNION_TYPE
:
11054 /* If this is a nested type whose containing class hasn't been written
11055 out yet, writing it out will cover this one, too. This does not apply
11056 to instantiations of member class templates; they need to be added to
11057 the containing class as they are generated. FIXME: This hurts the
11058 idea of combining type decls from multiple TUs, since we can't predict
11059 what set of template instantiations we'll get. */
11060 if (TYPE_CONTEXT (type
)
11061 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11062 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11064 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11066 if (TREE_ASM_WRITTEN (type
))
11069 /* If that failed, attach ourselves to the stub. */
11070 push_decl_scope (TYPE_CONTEXT (type
));
11071 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11077 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11078 gen_enumeration_type_die (type
, context_die
);
11080 gen_struct_or_union_type_die (type
, context_die
);
11085 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11086 it up if it is ever completed. gen_*_type_die will set it for us
11087 when appropriate. */
11096 /* No DIEs needed for fundamental types. */
11100 /* No Dwarf representation currently defined. */
11107 TREE_ASM_WRITTEN (type
) = 1;
11110 /* Generate a DIE for a tagged type instantiation. */
11113 gen_tagged_type_instantiation_die (type
, context_die
)
11115 dw_die_ref context_die
;
11117 if (type
== NULL_TREE
|| type
== error_mark_node
)
11120 /* We are going to output a DIE to represent the unqualified version of
11121 this type (i.e. without any const or volatile qualifiers) so make sure
11122 that we have the main variant (i.e. the unqualified version) of this
11124 if (type
!= type_main_variant (type
))
11127 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11128 an instance of an unresolved type. */
11130 switch (TREE_CODE (type
))
11135 case ENUMERAL_TYPE
:
11136 gen_inlined_enumeration_type_die (type
, context_die
);
11140 gen_inlined_structure_type_die (type
, context_die
);
11144 case QUAL_UNION_TYPE
:
11145 gen_inlined_union_type_die (type
, context_die
);
11153 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11154 things which are local to the given block. */
11157 gen_block_die (stmt
, context_die
, depth
)
11159 dw_die_ref context_die
;
11162 int must_output_die
= 0;
11165 enum tree_code origin_code
;
11167 /* Ignore blocks never really used to make RTL. */
11168 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11169 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11172 /* If the block is one fragment of a non-contiguous block, do not
11173 process the variables, since they will have been done by the
11174 origin block. Do process subblocks. */
11175 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11179 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11180 gen_block_die (sub
, context_die
, depth
+ 1);
11185 /* Determine the "ultimate origin" of this block. This block may be an
11186 inlined instance of an inlined instance of inline function, so we have
11187 to trace all of the way back through the origin chain to find out what
11188 sort of node actually served as the original seed for the creation of
11189 the current block. */
11190 origin
= block_ultimate_origin (stmt
);
11191 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11193 /* Determine if we need to output any Dwarf DIEs at all to represent this
11195 if (origin_code
== FUNCTION_DECL
)
11196 /* The outer scopes for inlinings *must* always be represented. We
11197 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11198 must_output_die
= 1;
11201 /* In the case where the current block represents an inlining of the
11202 "body block" of an inline function, we must *NOT* output any DIE for
11203 this block because we have already output a DIE to represent the whole
11204 inlined function scope and the "body block" of any function doesn't
11205 really represent a different scope according to ANSI C rules. So we
11206 check here to make sure that this block does not represent a "body
11207 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11208 if (! is_body_block (origin
? origin
: stmt
))
11210 /* Determine if this block directly contains any "significant"
11211 local declarations which we will need to output DIEs for. */
11212 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11213 /* We are not in terse mode so *any* local declaration counts
11214 as being a "significant" one. */
11215 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11217 /* We are in terse mode, so only local (nested) function
11218 definitions count as "significant" local declarations. */
11219 for (decl
= BLOCK_VARS (stmt
);
11220 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11221 if (TREE_CODE (decl
) == FUNCTION_DECL
11222 && DECL_INITIAL (decl
))
11224 must_output_die
= 1;
11230 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11231 DIE for any block which contains no significant local declarations at
11232 all. Rather, in such cases we just call `decls_for_scope' so that any
11233 needed Dwarf info for any sub-blocks will get properly generated. Note
11234 that in terse mode, our definition of what constitutes a "significant"
11235 local declaration gets restricted to include only inlined function
11236 instances and local (nested) function definitions. */
11237 if (must_output_die
)
11239 if (origin_code
== FUNCTION_DECL
)
11240 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11242 gen_lexical_block_die (stmt
, context_die
, depth
);
11245 decls_for_scope (stmt
, context_die
, depth
);
11248 /* Generate all of the decls declared within a given scope and (recursively)
11249 all of its sub-blocks. */
11252 decls_for_scope (stmt
, context_die
, depth
)
11254 dw_die_ref context_die
;
11260 /* Ignore blocks never really used to make RTL. */
11261 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11264 /* Output the DIEs to represent all of the data objects and typedefs
11265 declared directly within this block but not within any nested
11266 sub-blocks. Also, nested function and tag DIEs have been
11267 generated with a parent of NULL; fix that up now. */
11268 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11272 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11273 die
= lookup_decl_die (decl
);
11274 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11275 die
= lookup_type_die (TREE_TYPE (decl
));
11279 if (die
!= NULL
&& die
->die_parent
== NULL
)
11280 add_child_die (context_die
, die
);
11282 gen_decl_die (decl
, context_die
);
11285 /* Output the DIEs to represent all sub-blocks (and the items declared
11286 therein) of this block. */
11287 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11289 subblocks
= BLOCK_CHAIN (subblocks
))
11290 gen_block_die (subblocks
, context_die
, depth
+ 1);
11293 /* Is this a typedef we can avoid emitting? */
11296 is_redundant_typedef (decl
)
11299 if (TYPE_DECL_IS_STUB (decl
))
11302 if (DECL_ARTIFICIAL (decl
)
11303 && DECL_CONTEXT (decl
)
11304 && is_tagged_type (DECL_CONTEXT (decl
))
11305 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11306 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11307 /* Also ignore the artificial member typedef for the class name. */
11313 /* Generate Dwarf debug information for a decl described by DECL. */
11316 gen_decl_die (decl
, context_die
)
11318 dw_die_ref context_die
;
11322 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11325 switch (TREE_CODE (decl
))
11331 /* The individual enumerators of an enum type get output when we output
11332 the Dwarf representation of the relevant enum type itself. */
11335 case FUNCTION_DECL
:
11336 /* Don't output any DIEs to represent mere function declarations,
11337 unless they are class members or explicit block externs. */
11338 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11339 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11342 /* If we're emitting a clone, emit info for the abstract instance. */
11343 if (DECL_ORIGIN (decl
) != decl
)
11344 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11346 /* If we're emitting an out-of-line copy of an inline function,
11347 emit info for the abstract instance and set up to refer to it. */
11348 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11349 && ! class_scope_p (context_die
)
11350 /* dwarf2out_abstract_function won't emit a die if this is just
11351 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11352 that case, because that works only if we have a die. */
11353 && DECL_INITIAL (decl
) != NULL_TREE
)
11355 dwarf2out_abstract_function (decl
);
11356 set_decl_origin_self (decl
);
11359 /* Otherwise we're emitting the primary DIE for this decl. */
11360 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11362 /* Before we describe the FUNCTION_DECL itself, make sure that we
11363 have described its return type. */
11364 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11366 /* And its virtual context. */
11367 if (DECL_VINDEX (decl
) != NULL_TREE
)
11368 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11370 /* And its containing type. */
11371 origin
= decl_class_context (decl
);
11372 if (origin
!= NULL_TREE
)
11373 gen_type_die_for_member (origin
, decl
, context_die
);
11376 /* Now output a DIE to represent the function itself. */
11377 gen_subprogram_die (decl
, context_die
);
11381 /* If we are in terse mode, don't generate any DIEs to represent any
11382 actual typedefs. */
11383 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11386 /* In the special case of a TYPE_DECL node representing the declaration
11387 of some type tag, if the given TYPE_DECL is marked as having been
11388 instantiated from some other (original) TYPE_DECL node (e.g. one which
11389 was generated within the original definition of an inline function) we
11390 have to generate a special (abbreviated) DW_TAG_structure_type,
11391 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11392 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11394 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11398 if (is_redundant_typedef (decl
))
11399 gen_type_die (TREE_TYPE (decl
), context_die
);
11401 /* Output a DIE to represent the typedef itself. */
11402 gen_typedef_die (decl
, context_die
);
11406 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11407 gen_label_die (decl
, context_die
);
11411 /* If we are in terse mode, don't generate any DIEs to represent any
11412 variable declarations or definitions. */
11413 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11416 /* Output any DIEs that are needed to specify the type of this data
11418 gen_type_die (TREE_TYPE (decl
), context_die
);
11420 /* And its containing type. */
11421 origin
= decl_class_context (decl
);
11422 if (origin
!= NULL_TREE
)
11423 gen_type_die_for_member (origin
, decl
, context_die
);
11425 /* Now output the DIE to represent the data object itself. This gets
11426 complicated because of the possibility that the VAR_DECL really
11427 represents an inlined instance of a formal parameter for an inline
11429 origin
= decl_ultimate_origin (decl
);
11430 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11431 gen_formal_parameter_die (decl
, context_die
);
11433 gen_variable_die (decl
, context_die
);
11437 /* Ignore the nameless fields that are used to skip bits but handle C++
11438 anonymous unions. */
11439 if (DECL_NAME (decl
) != NULL_TREE
11440 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11442 gen_type_die (member_declared_type (decl
), context_die
);
11443 gen_field_die (decl
, context_die
);
11448 gen_type_die (TREE_TYPE (decl
), context_die
);
11449 gen_formal_parameter_die (decl
, context_die
);
11452 case NAMESPACE_DECL
:
11453 /* Ignore for now. */
11462 mark_limbo_die_list (ptr
)
11463 void *ptr ATTRIBUTE_UNUSED
;
11465 limbo_die_node
*node
;
11466 for (node
= limbo_die_list
; node
; node
= node
->next
)
11467 ggc_mark_tree (node
->created_for
);
11470 /* Add Ada "use" clause information for SGI Workshop debugger. */
11473 dwarf2out_add_library_unit_info (filename
, context_list
)
11474 const char *filename
;
11475 const char *context_list
;
11477 unsigned int file_index
;
11479 if (filename
!= NULL
)
11481 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11482 tree context_list_decl
11483 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11486 TREE_PUBLIC (context_list_decl
) = TRUE
;
11487 add_name_attribute (unit_die
, context_list
);
11488 file_index
= lookup_filename (filename
);
11489 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11490 add_pubname (context_list_decl
, unit_die
);
11494 /* Output debug information for global decl DECL. Called from toplev.c after
11495 compilation proper has finished. */
11498 dwarf2out_global_decl (decl
)
11501 /* Output DWARF2 information for file-scope tentative data object
11502 declarations, file-scope (extern) function declarations (which had no
11503 corresponding body) and file-scope tagged type declarations and
11504 definitions which have not yet been forced out. */
11505 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11506 dwarf2out_decl (decl
);
11509 /* Write the debugging output for DECL. */
11512 dwarf2out_decl (decl
)
11515 dw_die_ref context_die
= comp_unit_die
;
11517 switch (TREE_CODE (decl
))
11522 case FUNCTION_DECL
:
11523 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11524 builtin function. Explicit programmer-supplied declarations of
11525 these same functions should NOT be ignored however. */
11526 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11529 /* What we would really like to do here is to filter out all mere
11530 file-scope declarations of file-scope functions which are never
11531 referenced later within this translation unit (and keep all of ones
11532 that *are* referenced later on) but we aren't clairvoyant, so we have
11533 no idea which functions will be referenced in the future (i.e. later
11534 on within the current translation unit). So here we just ignore all
11535 file-scope function declarations which are not also definitions. If
11536 and when the debugger needs to know something about these functions,
11537 it will have to hunt around and find the DWARF information associated
11538 with the definition of the function.
11540 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11541 nodes represent definitions and which ones represent mere
11542 declarations. We have to check DECL_INITIAL instead. That's because
11543 the C front-end supports some weird semantics for "extern inline"
11544 function definitions. These can get inlined within the current
11545 translation unit (an thus, we need to generate Dwarf info for their
11546 abstract instances so that the Dwarf info for the concrete inlined
11547 instances can have something to refer to) but the compiler never
11548 generates any out-of-lines instances of such things (despite the fact
11549 that they *are* definitions).
11551 The important point is that the C front-end marks these "extern
11552 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11553 them anyway. Note that the C++ front-end also plays some similar games
11554 for inline function definitions appearing within include files which
11555 also contain `#pragma interface' pragmas. */
11556 if (DECL_INITIAL (decl
) == NULL_TREE
)
11559 /* If we're a nested function, initially use a parent of NULL; if we're
11560 a plain function, this will be fixed up in decls_for_scope. If
11561 we're a method, it will be ignored, since we already have a DIE. */
11562 if (decl_function_context (decl
))
11563 context_die
= NULL
;
11567 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11568 declaration and if the declaration was never even referenced from
11569 within this entire compilation unit. We suppress these DIEs in
11570 order to save space in the .debug section (by eliminating entries
11571 which are probably useless). Note that we must not suppress
11572 block-local extern declarations (whether used or not) because that
11573 would screw-up the debugger's name lookup mechanism and cause it to
11574 miss things which really ought to be in scope at a given point. */
11575 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11578 /* If we are in terse mode, don't generate any DIEs to represent any
11579 variable declarations or definitions. */
11580 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11585 /* Don't emit stubs for types unless they are needed by other DIEs. */
11586 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
11589 /* Don't bother trying to generate any DIEs to represent any of the
11590 normal built-in types for the language we are compiling. */
11591 if (DECL_SOURCE_LINE (decl
) == 0)
11593 /* OK, we need to generate one for `bool' so GDB knows what type
11594 comparisons have. */
11595 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
11596 == DW_LANG_C_plus_plus
)
11597 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
11598 && ! DECL_IGNORED_P (decl
))
11599 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
11604 /* If we are in terse mode, don't generate any DIEs for types. */
11605 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11608 /* If we're a function-scope tag, initially use a parent of NULL;
11609 this will be fixed up in decls_for_scope. */
11610 if (decl_function_context (decl
))
11611 context_die
= NULL
;
11619 gen_decl_die (decl
, context_die
);
11622 /* Output a marker (i.e. a label) for the beginning of the generated code for
11623 a lexical block. */
11626 dwarf2out_begin_block (line
, blocknum
)
11627 unsigned int line ATTRIBUTE_UNUSED
;
11628 unsigned int blocknum
;
11630 function_section (current_function_decl
);
11631 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
11634 /* Output a marker (i.e. a label) for the end of the generated code for a
11638 dwarf2out_end_block (line
, blocknum
)
11639 unsigned int line ATTRIBUTE_UNUSED
;
11640 unsigned int blocknum
;
11642 function_section (current_function_decl
);
11643 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
11646 /* Returns nonzero if it is appropriate not to emit any debugging
11647 information for BLOCK, because it doesn't contain any instructions.
11649 Don't allow this for blocks with nested functions or local classes
11650 as we would end up with orphans, and in the presence of scheduling
11651 we may end up calling them anyway. */
11654 dwarf2out_ignore_block (block
)
11659 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
11660 if (TREE_CODE (decl
) == FUNCTION_DECL
11661 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
11667 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11668 dwarf2out.c) and return its "index". The index of each (known) filename is
11669 just a unique number which is associated with only that one filename. We
11670 need such numbers for the sake of generating labels (in the .debug_sfnames
11671 section) and references to those files numbers (in the .debug_srcinfo
11672 and.debug_macinfo sections). If the filename given as an argument is not
11673 found in our current list, add it to the list and assign it the next
11674 available unique index number. In order to speed up searches, we remember
11675 the index of the filename was looked up last. This handles the majority of
11679 lookup_filename (file_name
)
11680 const char *file_name
;
11684 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11685 if (strcmp (file_name
, "<internal>") == 0
11686 || strcmp (file_name
, "<built-in>") == 0)
11689 /* Check to see if the file name that was searched on the previous
11690 call matches this file name. If so, return the index. */
11691 if (file_table
.last_lookup_index
!= 0)
11692 if (0 == strcmp (file_name
,
11693 file_table
.table
[file_table
.last_lookup_index
]))
11694 return file_table
.last_lookup_index
;
11696 /* Didn't match the previous lookup, search the table */
11697 for (i
= 1; i
< file_table
.in_use
; i
++)
11698 if (strcmp (file_name
, file_table
.table
[i
]) == 0)
11700 file_table
.last_lookup_index
= i
;
11704 /* Prepare to add a new table entry by making sure there is enough space in
11705 the table to do so. If not, expand the current table. */
11706 if (i
== file_table
.allocated
)
11708 file_table
.allocated
= i
+ FILE_TABLE_INCREMENT
;
11709 file_table
.table
= (char **)
11710 xrealloc (file_table
.table
, file_table
.allocated
* sizeof (char *));
11713 /* Add the new entry to the end of the filename table. */
11714 file_table
.table
[i
] = xstrdup (file_name
);
11715 file_table
.in_use
= i
+ 1;
11716 file_table
.last_lookup_index
= i
;
11718 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11719 fprintf (asm_out_file
, "\t.file %u \"%s\"\n", i
, file_name
);
11727 /* Allocate the initial hunk of the file_table. */
11728 file_table
.table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
11729 file_table
.allocated
= FILE_TABLE_INCREMENT
;
11731 /* Skip the first entry - file numbers begin at 1. */
11732 file_table
.in_use
= 1;
11733 file_table
.last_lookup_index
= 0;
11736 /* Output a label to mark the beginning of a source code line entry
11737 and record information relating to this source line, in
11738 'line_info_table' for later output of the .debug_line section. */
11741 dwarf2out_source_line (line
, filename
)
11743 const char *filename
;
11745 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11747 function_section (current_function_decl
);
11749 /* If requested, emit something human-readable. */
11750 if (flag_debug_asm
)
11751 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
11754 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11756 unsigned file_num
= lookup_filename (filename
);
11758 /* Emit the .loc directive understood by GNU as. */
11759 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
11761 /* Indicate that line number info exists. */
11762 line_info_table_in_use
++;
11764 /* Indicate that multiple line number tables exist. */
11765 if (DECL_SECTION_NAME (current_function_decl
))
11766 separate_line_info_table_in_use
++;
11768 else if (DECL_SECTION_NAME (current_function_decl
))
11770 dw_separate_line_info_ref line_info
;
11771 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
11772 separate_line_info_table_in_use
);
11774 /* expand the line info table if necessary */
11775 if (separate_line_info_table_in_use
11776 == separate_line_info_table_allocated
)
11778 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11779 separate_line_info_table
11780 = (dw_separate_line_info_ref
)
11781 xrealloc (separate_line_info_table
,
11782 separate_line_info_table_allocated
11783 * sizeof (dw_separate_line_info_entry
));
11786 /* Add the new entry at the end of the line_info_table. */
11788 = &separate_line_info_table
[separate_line_info_table_in_use
++];
11789 line_info
->dw_file_num
= lookup_filename (filename
);
11790 line_info
->dw_line_num
= line
;
11791 line_info
->function
= current_funcdef_number
;
11795 dw_line_info_ref line_info
;
11797 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
11798 line_info_table_in_use
);
11800 /* Expand the line info table if necessary. */
11801 if (line_info_table_in_use
== line_info_table_allocated
)
11803 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11805 = (dw_line_info_ref
)
11806 xrealloc (line_info_table
,
11807 (line_info_table_allocated
11808 * sizeof (dw_line_info_entry
)));
11811 /* Add the new entry at the end of the line_info_table. */
11812 line_info
= &line_info_table
[line_info_table_in_use
++];
11813 line_info
->dw_file_num
= lookup_filename (filename
);
11814 line_info
->dw_line_num
= line
;
11819 /* Record the beginning of a new source file. */
11822 dwarf2out_start_source_file (lineno
, filename
)
11823 unsigned int lineno
;
11824 const char *filename
;
11826 if (flag_eliminate_dwarf2_dups
)
11828 /* Record the beginning of the file for break_out_includes. */
11829 dw_die_ref bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
11830 add_AT_string (bincl_die
, DW_AT_name
, filename
);
11833 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11835 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11836 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
11837 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
11839 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
11840 "Filename we just started");
11844 /* Record the end of a source file. */
11847 dwarf2out_end_source_file (lineno
)
11848 unsigned int lineno ATTRIBUTE_UNUSED
;
11850 if (flag_eliminate_dwarf2_dups
)
11851 /* Record the end of the file for break_out_includes. */
11852 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
11854 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11856 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11857 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
11861 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11862 the tail part of the directive line, i.e. the part which is past the
11863 initial whitespace, #, whitespace, directive-name, whitespace part. */
11866 dwarf2out_define (lineno
, buffer
)
11867 unsigned lineno ATTRIBUTE_UNUSED
;
11868 const char *buffer ATTRIBUTE_UNUSED
;
11870 static int initialized
= 0;
11873 dwarf2out_start_source_file (0, primary_filename
);
11877 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11879 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11880 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
11881 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11882 dw2_asm_output_nstring (buffer
, -1, "The macro");
11886 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11887 the tail part of the directive line, i.e. the part which is past the
11888 initial whitespace, #, whitespace, directive-name, whitespace part. */
11891 dwarf2out_undef (lineno
, buffer
)
11892 unsigned lineno ATTRIBUTE_UNUSED
;
11893 const char *buffer ATTRIBUTE_UNUSED
;
11895 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11897 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11898 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
11899 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11900 dw2_asm_output_nstring (buffer
, -1, "The macro");
11904 /* Set up for Dwarf output at the start of compilation. */
11907 dwarf2out_init (main_input_filename
)
11908 const char *main_input_filename
;
11910 init_file_table ();
11912 /* Remember the name of the primary input file. */
11913 primary_filename
= main_input_filename
;
11915 /* Add it to the file table first, under the assumption that we'll
11916 be emitting line number data for it first, which avoids having
11917 to add an initial DW_LNS_set_file. */
11918 lookup_filename (main_input_filename
);
11920 /* Allocate the initial hunk of the decl_die_table. */
11922 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
11923 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
11924 decl_die_table_in_use
= 0;
11926 /* Allocate the initial hunk of the decl_scope_table. */
11927 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
11928 ggc_add_tree_varray_root (&decl_scope_table
, 1);
11930 /* Allocate the initial hunk of the abbrev_die_table. */
11932 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
11933 sizeof (dw_die_ref
));
11934 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
11935 /* Zero-th entry is allocated, but unused */
11936 abbrev_die_table_in_use
= 1;
11938 /* Allocate the initial hunk of the line_info_table. */
11940 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
11941 sizeof (dw_line_info_entry
));
11942 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
11944 /* Zero-th entry is allocated, but unused */
11945 line_info_table_in_use
= 1;
11947 /* Generate the initial DIE for the .debug section. Note that the (string)
11948 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11949 will (typically) be a relative pathname and that this pathname should be
11950 taken as being relative to the directory from which the compiler was
11951 invoked when the given (base) source file was compiled. */
11952 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
11954 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
11955 ggc_add_tree_varray_root (&incomplete_types
, 1);
11957 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
11958 ggc_add_rtx_varray_root (&used_rtx_varray
, 1);
11960 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
11962 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
11963 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
11964 DEBUG_ABBREV_SECTION_LABEL
, 0);
11965 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
11966 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
11968 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
11970 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
11971 DEBUG_INFO_SECTION_LABEL
, 0);
11972 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
11973 DEBUG_LINE_SECTION_LABEL
, 0);
11974 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
11975 DEBUG_RANGES_SECTION_LABEL
, 0);
11976 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
11977 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
11978 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
11979 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
11980 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
11981 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
11983 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11985 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11986 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
11987 DEBUG_MACINFO_SECTION_LABEL
, 0);
11988 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
11991 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
11994 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
11998 /* Allocate a string in .debug_str hash table. */
12001 indirect_string_alloc (tab
)
12002 hash_table
*tab ATTRIBUTE_UNUSED
;
12004 struct indirect_string_node
*node
;
12006 node
= xmalloc (sizeof (struct indirect_string_node
));
12007 node
->refcount
= 0;
12009 node
->label
= NULL
;
12011 return (hashnode
) node
;
12014 /* A helper function for dwarf2out_finish called through
12015 ht_forall. Emit one queued .debug_str string. */
12018 output_indirect_string (pfile
, h
, v
)
12019 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12021 const PTR v ATTRIBUTE_UNUSED
;
12023 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12025 if (node
->form
== DW_FORM_strp
)
12027 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12028 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12029 assemble_string ((const char *) HT_STR (&node
->id
),
12030 HT_LEN (&node
->id
) + 1);
12036 /* Output stuff that dwarf requires at the end of every file,
12037 and generate the DWARF-2 debugging info. */
12040 dwarf2out_finish (input_filename
)
12041 const char *input_filename ATTRIBUTE_UNUSED
;
12043 limbo_die_node
*node
, *next_node
;
12044 dw_die_ref die
= 0;
12046 /* Traverse the limbo die list, and add parent/child links. The only
12047 dies without parents that should be here are concrete instances of
12048 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12049 For concrete instances, we can get the parent die from the abstract
12051 for (node
= limbo_die_list
; node
; node
= next_node
)
12053 next_node
= node
->next
;
12056 if (die
->die_parent
== NULL
)
12058 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12062 add_child_die (origin
->die_parent
, die
);
12063 else if (die
== comp_unit_die
)
12065 /* If this was an expression for a bound involved in a function
12066 return type, it may be a SAVE_EXPR for which we weren't able
12067 to find a DIE previously. So try now. */
12068 else if (node
->created_for
12069 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12070 && 0 != (origin
= (lookup_decl_die
12072 (node
->created_for
)))))
12073 add_child_die (origin
, die
);
12074 else if (errorcount
> 0 || sorrycount
> 0)
12075 /* It's OK to be confused by errors in the input. */
12076 add_child_die (comp_unit_die
, die
);
12077 else if (node
->created_for
12078 && ((DECL_P (node
->created_for
)
12079 && (context
= DECL_CONTEXT (node
->created_for
)))
12080 || (TYPE_P (node
->created_for
)
12081 && (context
= TYPE_CONTEXT (node
->created_for
))))
12082 && TREE_CODE (context
) == FUNCTION_DECL
)
12084 /* In certain situations, the lexical block containing a
12085 nested function can be optimized away, which results
12086 in the nested function die being orphaned. Likewise
12087 with the return type of that nested function. Force
12088 this to be a child of the containing function. */
12089 origin
= lookup_decl_die (context
);
12092 add_child_die (origin
, die
);
12101 limbo_die_list
= NULL
;
12103 /* Walk through the list of incomplete types again, trying once more to
12104 emit full debugging info for them. */
12105 retry_incomplete_types ();
12107 /* We need to reverse all the dies before break_out_includes, or
12108 we'll see the end of an include file before the beginning. */
12109 reverse_all_dies (comp_unit_die
);
12111 /* Generate separate CUs for each of the include files we've seen.
12112 They will go into limbo_die_list. */
12113 if (flag_eliminate_dwarf2_dups
)
12114 break_out_includes (comp_unit_die
);
12116 /* Traverse the DIE's and add add sibling attributes to those DIE's
12117 that have children. */
12118 add_sibling_attributes (comp_unit_die
);
12119 for (node
= limbo_die_list
; node
; node
= node
->next
)
12120 add_sibling_attributes (node
->die
);
12122 /* Output a terminator label for the .text section. */
12124 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
12126 /* Output the source line correspondence table. We must do this
12127 even if there is no line information. Otherwise, on an empty
12128 translation unit, we will generate a present, but empty,
12129 .debug_info section. IRIX 6.5 `nm' will then complain when
12130 examining the file. */
12131 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12133 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12134 output_line_info ();
12137 /* Output location list section if necessary. */
12138 if (have_location_lists
)
12140 /* Output the location lists info. */
12141 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12142 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12143 DEBUG_LOC_SECTION_LABEL
, 0);
12144 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12145 output_location_lists (die
);
12146 have_location_lists
= 0;
12149 /* We can only use the low/high_pc attributes if all of the code was
12151 if (separate_line_info_table_in_use
== 0)
12153 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12154 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12157 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12158 "base address". Use zero so that these addresses become absolute. */
12159 else if (have_location_lists
|| ranges_table_in_use
)
12160 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12162 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12163 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12164 debug_line_section_label
);
12166 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12167 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12169 /* Output all of the compilation units. We put the main one last so that
12170 the offsets are available to output_pubnames. */
12171 for (node
= limbo_die_list
; node
; node
= node
->next
)
12172 output_comp_unit (node
->die
);
12174 output_comp_unit (comp_unit_die
);
12176 /* Output the abbreviation table. */
12177 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12178 output_abbrev_section ();
12180 /* Output public names table if necessary. */
12181 if (pubname_table_in_use
)
12183 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12184 output_pubnames ();
12187 /* Output the address range information. We only put functions in the arange
12188 table, so don't write it out if we don't have any. */
12189 if (fde_table_in_use
)
12191 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12195 /* Output ranges section if necessary. */
12196 if (ranges_table_in_use
)
12198 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12199 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12203 /* Have to end the primary source file. */
12204 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12206 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12207 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12210 /* If we emitted any DW_FORM_strp form attribute, output the string
12212 if (debug_str_hash
)
12213 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12215 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */