1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
66 #ifdef DWARF2_DEBUGGING_INFO
67 static void dwarf2out_source_line
PARAMS ((unsigned int, const char *));
70 /* DWARF2 Abbreviation Glossary:
71 CFA = Canonical Frame Address
72 a fixed address on the stack which identifies a call frame.
73 We define it to be the value of SP just before the call insn.
74 The CFA register and offset, which may change during the course
75 of the function, are used to calculate its value at runtime.
76 CFI = Call Frame Instruction
77 an instruction for the DWARF2 abstract machine
78 CIE = Common Information Entry
79 information describing information common to one or more FDEs
80 DIE = Debugging Information Entry
81 FDE = Frame Description Entry
82 information describing the stack call frame, in particular,
83 how to restore registers
85 DW_CFA_... = DWARF2 CFA call frame instruction
86 DW_TAG_... = DWARF2 DIE tag */
88 /* Decide whether we want to emit frame unwind information for the current
94 return (write_symbols
== DWARF2_DEBUG
95 || write_symbols
== VMS_AND_DWARF2_DEBUG
96 #ifdef DWARF2_FRAME_INFO
99 #ifdef DWARF2_UNWIND_INFO
100 || flag_unwind_tables
101 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
106 /* The number of the current function definition for which debugging
107 information is being generated. These numbers range from 1 up to the
108 maximum number of function definitions contained within the current
109 compilation unit. These numbers are used to create unique label id's
110 unique to each function definition. */
111 unsigned current_funcdef_number
= 0;
113 /* The size of the target's pointer type. */
115 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
118 /* Default version of targetm.eh_frame_section. Note this must appear
119 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
123 default_eh_frame_section ()
125 #ifdef EH_FRAME_SECTION_NAME
126 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
128 tree label
= get_file_function_name ('F');
131 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
132 ASM_GLOBALIZE_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
133 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
137 /* Array of RTXes referenced by the debugging information, which therefore
138 must be kept around forever. */
139 static GTY(()) varray_type used_rtx_varray
;
141 /* A pointer to the base of a list of incomplete types which might be
142 completed at some later time. incomplete_types_list needs to be a VARRAY
143 because we want to tell the garbage collector about it. */
144 static GTY(()) varray_type incomplete_types
;
146 /* A pointer to the base of a table of references to declaration
147 scopes. This table is a display which tracks the nesting
148 of declaration scopes at the current scope and containing
149 scopes. This table is used to find the proper place to
150 define type declaration DIE's. */
151 static GTY(()) varray_type decl_scope_table
;
153 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
155 /* How to start an assembler comment. */
156 #ifndef ASM_COMMENT_START
157 #define ASM_COMMENT_START ";#"
160 typedef struct dw_cfi_struct
*dw_cfi_ref
;
161 typedef struct dw_fde_struct
*dw_fde_ref
;
162 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
164 /* Call frames are described using a sequence of Call Frame
165 Information instructions. The register number, offset
166 and address fields are provided as possible operands;
167 their use is selected by the opcode field. */
169 typedef union dw_cfi_oprnd_struct
171 unsigned long dw_cfi_reg_num
;
172 long int dw_cfi_offset
;
173 const char *dw_cfi_addr
;
174 struct dw_loc_descr_struct
*dw_cfi_loc
;
178 typedef struct dw_cfi_struct
180 dw_cfi_ref dw_cfi_next
;
181 enum dwarf_call_frame_info dw_cfi_opc
;
182 dw_cfi_oprnd dw_cfi_oprnd1
;
183 dw_cfi_oprnd dw_cfi_oprnd2
;
187 /* This is how we define the location of the CFA. We use to handle it
188 as REG + OFFSET all the time, but now it can be more complex.
189 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
190 Instead of passing around REG and OFFSET, we pass a copy
191 of this structure. */
192 typedef struct cfa_loc
197 int indirect
; /* 1 if CFA is accessed via a dereference. */
200 /* All call frame descriptions (FDE's) in the GCC generated DWARF
201 refer to a single Common Information Entry (CIE), defined at
202 the beginning of the .debug_frame section. This use of a single
203 CIE obviates the need to keep track of multiple CIE's
204 in the DWARF generation routines below. */
206 typedef struct dw_fde_struct
208 const char *dw_fde_begin
;
209 const char *dw_fde_current_label
;
210 const char *dw_fde_end
;
211 dw_cfi_ref dw_fde_cfi
;
212 unsigned funcdef_number
;
213 unsigned nothrow
: 1;
214 unsigned uses_eh_lsda
: 1;
218 /* Maximum size (in bytes) of an artificially generated label. */
219 #define MAX_ARTIFICIAL_LABEL_BYTES 30
221 /* The size of addresses as they appear in the Dwarf 2 data.
222 Some architectures use word addresses to refer to code locations,
223 but Dwarf 2 info always uses byte addresses. On such machines,
224 Dwarf 2 addresses need to be larger than the architecture's
226 #ifndef DWARF2_ADDR_SIZE
227 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
230 /* The size in bytes of a DWARF field indicating an offset or length
231 relative to a debug info section, specified to be 4 bytes in the
232 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
235 #ifndef DWARF_OFFSET_SIZE
236 #define DWARF_OFFSET_SIZE 4
239 #define DWARF_VERSION 2
241 /* Round SIZE up to the nearest BOUNDARY. */
242 #define DWARF_ROUND(SIZE,BOUNDARY) \
243 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
245 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
246 #ifndef DWARF_CIE_DATA_ALIGNMENT
247 #ifdef STACK_GROWS_DOWNWARD
248 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
250 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
254 /* A pointer to the base of a table that contains frame description
255 information for each routine. */
256 static dw_fde_ref fde_table
;
258 /* Number of elements currently allocated for fde_table. */
259 static unsigned fde_table_allocated
;
261 /* Number of elements in fde_table currently in use. */
262 static unsigned fde_table_in_use
;
264 /* Size (in elements) of increments by which we may expand the
266 #define FDE_TABLE_INCREMENT 256
268 /* A list of call frame insns for the CIE. */
269 static dw_cfi_ref cie_cfi_head
;
271 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
272 attribute that accelerates the lookup of the FDE associated
273 with the subprogram. This variable holds the table index of the FDE
274 associated with the current function (body) definition. */
275 static unsigned current_funcdef_fde
;
277 struct ht
*debug_str_hash
;
279 struct indirect_string_node
281 struct ht_identifier id
;
282 unsigned int refcount
;
287 /* Forward declarations for functions defined in this file. */
289 static char *stripattributes
PARAMS ((const char *));
290 static const char *dwarf_cfi_name
PARAMS ((unsigned));
291 static dw_cfi_ref new_cfi
PARAMS ((void));
292 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
293 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
294 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
,
296 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
297 static void reg_save
PARAMS ((const char *, unsigned,
299 static void initial_return_save
PARAMS ((rtx
));
300 static long stack_adjust_offset
PARAMS ((rtx
));
301 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
, int));
302 static void output_call_frame_info
PARAMS ((int));
303 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
304 static void queue_reg_save
PARAMS ((const char *, rtx
, long));
305 static void flush_queued_reg_saves
PARAMS ((void));
306 static bool clobbers_queued_reg_save
PARAMS ((rtx
));
307 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
309 /* Support for complex CFA locations. */
310 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
311 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
312 struct dw_loc_descr_struct
*));
313 static struct dw_loc_descr_struct
*build_cfa_loc
314 PARAMS ((dw_cfa_location
*));
315 static void def_cfa_1
PARAMS ((const char *,
318 /* How to start an assembler comment. */
319 #ifndef ASM_COMMENT_START
320 #define ASM_COMMENT_START ";#"
323 /* Data and reference forms for relocatable data. */
324 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
325 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
327 /* Pseudo-op for defining a new section. */
328 #ifndef SECTION_ASM_OP
329 #define SECTION_ASM_OP "\t.section\t"
332 #ifndef DEBUG_FRAME_SECTION
333 #define DEBUG_FRAME_SECTION ".debug_frame"
336 #ifndef FUNC_BEGIN_LABEL
337 #define FUNC_BEGIN_LABEL "LFB"
340 #ifndef FUNC_END_LABEL
341 #define FUNC_END_LABEL "LFE"
344 #define FRAME_BEGIN_LABEL "Lframe"
345 #define CIE_AFTER_SIZE_LABEL "LSCIE"
346 #define CIE_END_LABEL "LECIE"
347 #define CIE_LENGTH_LABEL "LLCIE"
348 #define FDE_LABEL "LSFDE"
349 #define FDE_AFTER_SIZE_LABEL "LASFDE"
350 #define FDE_END_LABEL "LEFDE"
351 #define FDE_LENGTH_LABEL "LLFDE"
352 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
353 #define LINE_NUMBER_END_LABEL "LELT"
354 #define LN_PROLOG_AS_LABEL "LASLTP"
355 #define LN_PROLOG_END_LABEL "LELTP"
356 #define DIE_LABEL_PREFIX "DW"
358 /* Definitions of defaults for various types of primitive assembly language
359 output operations. These may be overridden from within the tm.h file,
360 but typically, that is unnecessary. */
363 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
364 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
367 fprintf (FILE, "%s", SET_ASM_OP); \
368 assemble_name (FILE, SY); \
370 assemble_name (FILE, HI); \
372 assemble_name (FILE, LO); \
378 /* The DWARF 2 CFA column which tracks the return address. Normally this
379 is the column for PC, or the first column after all of the hard
381 #ifndef DWARF_FRAME_RETURN_COLUMN
383 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
385 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
389 /* The mapping from gcc register number to DWARF 2 CFA column number. By
390 default, we just provide columns for all registers. */
391 #ifndef DWARF_FRAME_REGNUM
392 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
395 /* The offset from the incoming value of %sp to the top of the stack frame
396 for the current function. */
397 #ifndef INCOMING_FRAME_SP_OFFSET
398 #define INCOMING_FRAME_SP_OFFSET 0
401 /* Hook used by __throw. */
404 expand_builtin_dwarf_fp_regnum ()
406 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
409 /* Return a pointer to a copy of the section string name S with all
410 attributes stripped off, and an asterisk prepended (for assemble_name). */
416 char *stripped
= xmalloc (strlen (s
) + 2);
421 while (*s
&& *s
!= ',')
428 /* Generate code to initialize the register size table. */
431 expand_builtin_init_dwarf_reg_sizes (address
)
435 enum machine_mode mode
= TYPE_MODE (char_type_node
);
436 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
437 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
439 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
440 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
442 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
443 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
448 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
452 /* Convert a DWARF call frame info. operation to its string name */
455 dwarf_cfi_name (cfi_opc
)
460 case DW_CFA_advance_loc
:
461 return "DW_CFA_advance_loc";
463 return "DW_CFA_offset";
465 return "DW_CFA_restore";
469 return "DW_CFA_set_loc";
470 case DW_CFA_advance_loc1
:
471 return "DW_CFA_advance_loc1";
472 case DW_CFA_advance_loc2
:
473 return "DW_CFA_advance_loc2";
474 case DW_CFA_advance_loc4
:
475 return "DW_CFA_advance_loc4";
476 case DW_CFA_offset_extended
:
477 return "DW_CFA_offset_extended";
478 case DW_CFA_restore_extended
:
479 return "DW_CFA_restore_extended";
480 case DW_CFA_undefined
:
481 return "DW_CFA_undefined";
482 case DW_CFA_same_value
:
483 return "DW_CFA_same_value";
484 case DW_CFA_register
:
485 return "DW_CFA_register";
486 case DW_CFA_remember_state
:
487 return "DW_CFA_remember_state";
488 case DW_CFA_restore_state
:
489 return "DW_CFA_restore_state";
491 return "DW_CFA_def_cfa";
492 case DW_CFA_def_cfa_register
:
493 return "DW_CFA_def_cfa_register";
494 case DW_CFA_def_cfa_offset
:
495 return "DW_CFA_def_cfa_offset";
498 case DW_CFA_def_cfa_expression
:
499 return "DW_CFA_def_cfa_expression";
500 case DW_CFA_expression
:
501 return "DW_CFA_expression";
502 case DW_CFA_offset_extended_sf
:
503 return "DW_CFA_offset_extended_sf";
504 case DW_CFA_def_cfa_sf
:
505 return "DW_CFA_def_cfa_sf";
506 case DW_CFA_def_cfa_offset_sf
:
507 return "DW_CFA_def_cfa_offset_sf";
509 /* SGI/MIPS specific */
510 case DW_CFA_MIPS_advance_loc8
:
511 return "DW_CFA_MIPS_advance_loc8";
514 case DW_CFA_GNU_window_save
:
515 return "DW_CFA_GNU_window_save";
516 case DW_CFA_GNU_args_size
:
517 return "DW_CFA_GNU_args_size";
518 case DW_CFA_GNU_negative_offset_extended
:
519 return "DW_CFA_GNU_negative_offset_extended";
522 return "DW_CFA_<unknown>";
526 /* Return a pointer to a newly allocated Call Frame Instruction. */
528 static inline dw_cfi_ref
531 dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
533 cfi
->dw_cfi_next
= NULL
;
534 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
535 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
540 /* Add a Call Frame Instruction to list of instructions. */
543 add_cfi (list_head
, cfi
)
544 dw_cfi_ref
*list_head
;
549 /* Find the end of the chain. */
550 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
556 /* Generate a new label for the CFI info to refer to. */
559 dwarf2out_cfi_label ()
561 static char label
[20];
562 static unsigned long label_num
= 0;
564 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
565 ASM_OUTPUT_LABEL (asm_out_file
, label
);
569 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
570 or to the CIE if LABEL is NULL. */
573 add_fde_cfi (label
, cfi
)
579 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
582 label
= dwarf2out_cfi_label ();
584 if (fde
->dw_fde_current_label
== NULL
585 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
589 fde
->dw_fde_current_label
= label
= xstrdup (label
);
591 /* Set the location counter to the new label. */
593 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
594 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
595 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
598 add_cfi (&fde
->dw_fde_cfi
, cfi
);
602 add_cfi (&cie_cfi_head
, cfi
);
605 /* Subroutine of lookup_cfa. */
608 lookup_cfa_1 (cfi
, loc
)
610 dw_cfa_location
*loc
;
612 switch (cfi
->dw_cfi_opc
)
614 case DW_CFA_def_cfa_offset
:
615 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
617 case DW_CFA_def_cfa_register
:
618 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
621 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
622 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
624 case DW_CFA_def_cfa_expression
:
625 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
632 /* Find the previous value for the CFA. */
636 dw_cfa_location
*loc
;
640 loc
->reg
= (unsigned long) -1;
643 loc
->base_offset
= 0;
645 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
646 lookup_cfa_1 (cfi
, loc
);
648 if (fde_table_in_use
)
650 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
651 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
652 lookup_cfa_1 (cfi
, loc
);
656 /* The current rule for calculating the DWARF2 canonical frame address. */
657 static dw_cfa_location cfa
;
659 /* The register used for saving registers to the stack, and its offset
661 static dw_cfa_location cfa_store
;
663 /* The running total of the size of arguments pushed onto the stack. */
664 static long args_size
;
666 /* The last args_size we actually output. */
667 static long old_args_size
;
669 /* Entry point to update the canonical frame address (CFA).
670 LABEL is passed to add_fde_cfi. The value of CFA is now to be
671 calculated from REG+OFFSET. */
674 dwarf2out_def_cfa (label
, reg
, offset
)
684 def_cfa_1 (label
, &loc
);
687 /* This routine does the actual work. The CFA is now calculated from
688 the dw_cfa_location structure. */
691 def_cfa_1 (label
, loc_p
)
693 dw_cfa_location
*loc_p
;
696 dw_cfa_location old_cfa
, loc
;
701 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
702 cfa_store
.offset
= loc
.offset
;
704 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
705 lookup_cfa (&old_cfa
);
707 /* If nothing changed, no need to issue any call frame instructions. */
708 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
709 && loc
.indirect
== old_cfa
.indirect
710 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
715 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
717 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
718 indicating the CFA register did not change but the offset
720 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
721 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
724 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
725 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
728 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
729 indicating the CFA register has changed to <register> but the
730 offset has not changed. */
731 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
732 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
736 else if (loc
.indirect
== 0)
738 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
739 indicating the CFA register has changed to <register> with
740 the specified offset. */
741 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
742 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
743 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
747 /* Construct a DW_CFA_def_cfa_expression instruction to
748 calculate the CFA using a full location expression since no
749 register-offset pair is available. */
750 struct dw_loc_descr_struct
*loc_list
;
752 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
753 loc_list
= build_cfa_loc (&loc
);
754 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
757 add_fde_cfi (label
, cfi
);
760 /* Add the CFI for saving a register. REG is the CFA column number.
761 LABEL is passed to add_fde_cfi.
762 If SREG is -1, the register is saved at OFFSET from the CFA;
763 otherwise it is saved in SREG. */
766 reg_save (label
, reg
, sreg
, offset
)
772 dw_cfi_ref cfi
= new_cfi ();
774 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
776 /* The following comparison is correct. -1 is used to indicate that
777 the value isn't a register number. */
778 if (sreg
== (unsigned int) -1)
781 /* The register number won't fit in 6 bits, so we have to use
783 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
785 cfi
->dw_cfi_opc
= DW_CFA_offset
;
787 #ifdef ENABLE_CHECKING
789 /* If we get an offset that is not a multiple of
790 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
791 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
793 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
795 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
799 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
801 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
803 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
805 else if (sreg
== reg
)
806 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
810 cfi
->dw_cfi_opc
= DW_CFA_register
;
811 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
814 add_fde_cfi (label
, cfi
);
817 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
818 This CFI tells the unwinder that it needs to restore the window registers
819 from the previous frame's window save area.
821 ??? Perhaps we should note in the CIE where windows are saved (instead of
822 assuming 0(cfa)) and what registers are in the window. */
825 dwarf2out_window_save (label
)
828 dw_cfi_ref cfi
= new_cfi ();
830 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
831 add_fde_cfi (label
, cfi
);
834 /* Add a CFI to update the running total of the size of arguments
835 pushed onto the stack. */
838 dwarf2out_args_size (label
, size
)
844 if (size
== old_args_size
)
847 old_args_size
= size
;
850 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
851 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
852 add_fde_cfi (label
, cfi
);
855 /* Entry point for saving a register to the stack. REG is the GCC register
856 number. LABEL and OFFSET are passed to reg_save. */
859 dwarf2out_reg_save (label
, reg
, offset
)
864 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
867 /* Entry point for saving the return address in the stack.
868 LABEL and OFFSET are passed to reg_save. */
871 dwarf2out_return_save (label
, offset
)
875 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
878 /* Entry point for saving the return address in a register.
879 LABEL and SREG are passed to reg_save. */
882 dwarf2out_return_reg (label
, sreg
)
886 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
889 /* Record the initial position of the return address. RTL is
890 INCOMING_RETURN_ADDR_RTX. */
893 initial_return_save (rtl
)
896 unsigned int reg
= (unsigned int) -1;
897 HOST_WIDE_INT offset
= 0;
899 switch (GET_CODE (rtl
))
902 /* RA is in a register. */
903 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
907 /* RA is on the stack. */
909 switch (GET_CODE (rtl
))
912 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
918 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
920 offset
= INTVAL (XEXP (rtl
, 1));
924 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
926 offset
= -INTVAL (XEXP (rtl
, 1));
936 /* The return address is at some offset from any value we can
937 actually load. For instance, on the SPARC it is in %i7+8. Just
938 ignore the offset for now; it doesn't matter for unwinding frames. */
939 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
941 initial_return_save (XEXP (rtl
, 0));
948 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
951 /* Given a SET, calculate the amount of stack adjustment it
955 stack_adjust_offset (pattern
)
958 rtx src
= SET_SRC (pattern
);
959 rtx dest
= SET_DEST (pattern
);
960 HOST_WIDE_INT offset
= 0;
963 if (dest
== stack_pointer_rtx
)
965 /* (set (reg sp) (plus (reg sp) (const_int))) */
966 code
= GET_CODE (src
);
967 if (! (code
== PLUS
|| code
== MINUS
)
968 || XEXP (src
, 0) != stack_pointer_rtx
969 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
972 offset
= INTVAL (XEXP (src
, 1));
976 else if (GET_CODE (dest
) == MEM
)
978 /* (set (mem (pre_dec (reg sp))) (foo)) */
979 src
= XEXP (dest
, 0);
980 code
= GET_CODE (src
);
986 if (XEXP (src
, 0) == stack_pointer_rtx
)
988 rtx val
= XEXP (XEXP (src
, 1), 1);
989 /* We handle only adjustments by constant amount. */
990 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
991 GET_CODE (val
) != CONST_INT
)
993 offset
= -INTVAL (val
);
1000 if (XEXP (src
, 0) == stack_pointer_rtx
)
1002 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1009 if (XEXP (src
, 0) == stack_pointer_rtx
)
1011 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1026 /* Check INSN to see if it looks like a push or a stack adjustment, and
1027 make a note of it if it does. EH uses this information to find out how
1028 much extra space it needs to pop off the stack. */
1031 dwarf2out_stack_adjust (insn
)
1034 HOST_WIDE_INT offset
;
1038 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1040 /* Extract the size of the args from the CALL rtx itself. */
1041 insn
= PATTERN (insn
);
1042 if (GET_CODE (insn
) == PARALLEL
)
1043 insn
= XVECEXP (insn
, 0, 0);
1044 if (GET_CODE (insn
) == SET
)
1045 insn
= SET_SRC (insn
);
1046 if (GET_CODE (insn
) != CALL
)
1049 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1053 /* If only calls can throw, and we have a frame pointer,
1054 save up adjustments until we see the CALL_INSN. */
1055 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1058 if (GET_CODE (insn
) == BARRIER
)
1060 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1061 the compiler will have already emitted a stack adjustment, but
1062 doesn't bother for calls to noreturn functions. */
1063 #ifdef STACK_GROWS_DOWNWARD
1064 offset
= -args_size
;
1069 else if (GET_CODE (PATTERN (insn
)) == SET
)
1070 offset
= stack_adjust_offset (PATTERN (insn
));
1071 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1072 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1074 /* There may be stack adjustments inside compound insns. Search
1076 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1077 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1078 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1086 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1087 cfa
.offset
+= offset
;
1089 #ifndef STACK_GROWS_DOWNWARD
1093 args_size
+= offset
;
1097 label
= dwarf2out_cfi_label ();
1098 def_cfa_1 (label
, &cfa
);
1099 dwarf2out_args_size (label
, args_size
);
1102 /* We delay emitting a register save until either (a) we reach the end
1103 of the prologue or (b) the register is clobbered. This clusters
1104 register saves so that there are fewer pc advances. */
1106 struct queued_reg_save
1108 struct queued_reg_save
*next
;
1113 static struct queued_reg_save
*queued_reg_saves
;
1114 static const char *last_reg_save_label
;
1117 queue_reg_save (label
, reg
, offset
)
1122 struct queued_reg_save
*q
= (struct queued_reg_save
*) xmalloc (sizeof (*q
));
1124 q
->next
= queued_reg_saves
;
1126 q
->cfa_offset
= offset
;
1127 queued_reg_saves
= q
;
1129 last_reg_save_label
= label
;
1133 flush_queued_reg_saves ()
1135 struct queued_reg_save
*q
, *next
;
1137 for (q
= queued_reg_saves
; q
; q
= next
)
1139 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1144 queued_reg_saves
= NULL
;
1145 last_reg_save_label
= NULL
;
1149 clobbers_queued_reg_save (insn
)
1152 struct queued_reg_save
*q
;
1154 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1155 if (modified_in_p (q
->reg
, insn
))
1162 /* A temporary register holding an integral value used in adjusting SP
1163 or setting up the store_reg. The "offset" field holds the integer
1164 value, not an offset. */
1165 static dw_cfa_location cfa_temp
;
1167 /* Record call frame debugging information for an expression EXPR,
1168 which either sets SP or FP (adjusting how we calculate the frame
1169 address) or saves a register to the stack. LABEL indicates the
1172 This function encodes a state machine mapping rtxes to actions on
1173 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1174 users need not read the source code.
1176 The High-Level Picture
1178 Changes in the register we use to calculate the CFA: Currently we
1179 assume that if you copy the CFA register into another register, we
1180 should take the other one as the new CFA register; this seems to
1181 work pretty well. If it's wrong for some target, it's simple
1182 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1184 Changes in the register we use for saving registers to the stack:
1185 This is usually SP, but not always. Again, we deduce that if you
1186 copy SP into another register (and SP is not the CFA register),
1187 then the new register is the one we will be using for register
1188 saves. This also seems to work.
1190 Register saves: There's not much guesswork about this one; if
1191 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1192 register save, and the register used to calculate the destination
1193 had better be the one we think we're using for this purpose.
1195 Except: If the register being saved is the CFA register, and the
1196 offset is non-zero, we are saving the CFA, so we assume we have to
1197 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1198 the intent is to save the value of SP from the previous frame.
1200 Invariants / Summaries of Rules
1202 cfa current rule for calculating the CFA. It usually
1203 consists of a register and an offset.
1204 cfa_store register used by prologue code to save things to the stack
1205 cfa_store.offset is the offset from the value of
1206 cfa_store.reg to the actual CFA
1207 cfa_temp register holding an integral value. cfa_temp.offset
1208 stores the value, which will be used to adjust the
1209 stack pointer. cfa_temp is also used like cfa_store,
1210 to track stores to the stack via fp or a temp reg.
1212 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1213 with cfa.reg as the first operand changes the cfa.reg and its
1214 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1217 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1218 expression yielding a constant. This sets cfa_temp.reg
1219 and cfa_temp.offset.
1221 Rule 5: Create a new register cfa_store used to save items to the
1224 Rules 10-14: Save a register to the stack. Define offset as the
1225 difference of the original location and cfa_store's
1226 location (or cfa_temp's location if cfa_temp is used).
1230 "{a,b}" indicates a choice of a xor b.
1231 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1234 (set <reg1> <reg2>:cfa.reg)
1235 effects: cfa.reg = <reg1>
1236 cfa.offset unchanged
1237 cfa_temp.reg = <reg1>
1238 cfa_temp.offset = cfa.offset
1241 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1242 {<const_int>,<reg>:cfa_temp.reg}))
1243 effects: cfa.reg = sp if fp used
1244 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1245 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1246 if cfa_store.reg==sp
1249 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1250 effects: cfa.reg = fp
1251 cfa_offset += +/- <const_int>
1254 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1255 constraints: <reg1> != fp
1257 effects: cfa.reg = <reg1>
1258 cfa_temp.reg = <reg1>
1259 cfa_temp.offset = cfa.offset
1262 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1263 constraints: <reg1> != fp
1265 effects: cfa_store.reg = <reg1>
1266 cfa_store.offset = cfa.offset - cfa_temp.offset
1269 (set <reg> <const_int>)
1270 effects: cfa_temp.reg = <reg>
1271 cfa_temp.offset = <const_int>
1274 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1275 effects: cfa_temp.reg = <reg1>
1276 cfa_temp.offset |= <const_int>
1279 (set <reg> (high <exp>))
1283 (set <reg> (lo_sum <exp> <const_int>))
1284 effects: cfa_temp.reg = <reg>
1285 cfa_temp.offset = <const_int>
1288 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1289 effects: cfa_store.offset -= <const_int>
1290 cfa.offset = cfa_store.offset if cfa.reg == sp
1292 cfa.base_offset = -cfa_store.offset
1295 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1296 effects: cfa_store.offset += -/+ mode_size(mem)
1297 cfa.offset = cfa_store.offset if cfa.reg == sp
1299 cfa.base_offset = -cfa_store.offset
1302 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1305 effects: cfa.reg = <reg1>
1306 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1309 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1310 effects: cfa.reg = <reg1>
1311 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1314 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1315 effects: cfa.reg = <reg1>
1316 cfa.base_offset = -cfa_temp.offset
1317 cfa_temp.offset -= mode_size(mem) */
1320 dwarf2out_frame_debug_expr (expr
, label
)
1325 HOST_WIDE_INT offset
;
1327 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1328 the PARALLEL independently. The first element is always processed if
1329 it is a SET. This is for backward compatibility. Other elements
1330 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1331 flag is set in them. */
1332 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1335 int limit
= XVECLEN (expr
, 0);
1337 for (par_index
= 0; par_index
< limit
; par_index
++)
1338 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1339 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1341 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1346 if (GET_CODE (expr
) != SET
)
1349 src
= SET_SRC (expr
);
1350 dest
= SET_DEST (expr
);
1352 switch (GET_CODE (dest
))
1356 /* Update the CFA rule wrt SP or FP. Make sure src is
1357 relative to the current CFA register. */
1358 switch (GET_CODE (src
))
1360 /* Setting FP from SP. */
1362 if (cfa
.reg
== (unsigned) REGNO (src
))
1368 /* We used to require that dest be either SP or FP, but the
1369 ARM copies SP to a temporary register, and from there to
1370 FP. So we just rely on the backends to only set
1371 RTX_FRAME_RELATED_P on appropriate insns. */
1372 cfa
.reg
= REGNO (dest
);
1373 cfa_temp
.reg
= cfa
.reg
;
1374 cfa_temp
.offset
= cfa
.offset
;
1380 if (dest
== stack_pointer_rtx
)
1384 switch (GET_CODE (XEXP (src
, 1)))
1387 offset
= INTVAL (XEXP (src
, 1));
1390 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1392 offset
= cfa_temp
.offset
;
1398 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1400 /* Restoring SP from FP in the epilogue. */
1401 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1403 cfa
.reg
= STACK_POINTER_REGNUM
;
1405 else if (GET_CODE (src
) == LO_SUM
)
1406 /* Assume we've set the source reg of the LO_SUM from sp. */
1408 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1411 if (GET_CODE (src
) != MINUS
)
1413 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1414 cfa
.offset
+= offset
;
1415 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1416 cfa_store
.offset
+= offset
;
1418 else if (dest
== hard_frame_pointer_rtx
)
1421 /* Either setting the FP from an offset of the SP,
1422 or adjusting the FP */
1423 if (! frame_pointer_needed
)
1426 if (GET_CODE (XEXP (src
, 0)) == REG
1427 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1428 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1430 offset
= INTVAL (XEXP (src
, 1));
1431 if (GET_CODE (src
) != MINUS
)
1433 cfa
.offset
+= offset
;
1434 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1441 if (GET_CODE (src
) == MINUS
)
1445 if (GET_CODE (XEXP (src
, 0)) == REG
1446 && REGNO (XEXP (src
, 0)) == cfa
.reg
1447 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1449 /* Setting a temporary CFA register that will be copied
1450 into the FP later on. */
1451 offset
= - INTVAL (XEXP (src
, 1));
1452 cfa
.offset
+= offset
;
1453 cfa
.reg
= REGNO (dest
);
1454 /* Or used to save regs to the stack. */
1455 cfa_temp
.reg
= cfa
.reg
;
1456 cfa_temp
.offset
= cfa
.offset
;
1460 else if (GET_CODE (XEXP (src
, 0)) == REG
1461 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1462 && XEXP (src
, 1) == stack_pointer_rtx
)
1464 /* Setting a scratch register that we will use instead
1465 of SP for saving registers to the stack. */
1466 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1468 cfa_store
.reg
= REGNO (dest
);
1469 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1473 else if (GET_CODE (src
) == LO_SUM
1474 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1476 cfa_temp
.reg
= REGNO (dest
);
1477 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1486 cfa_temp
.reg
= REGNO (dest
);
1487 cfa_temp
.offset
= INTVAL (src
);
1492 if (GET_CODE (XEXP (src
, 0)) != REG
1493 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1494 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1497 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1498 cfa_temp
.reg
= REGNO (dest
);
1499 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1502 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1503 which will fill in all of the bits. */
1512 def_cfa_1 (label
, &cfa
);
1516 if (GET_CODE (src
) != REG
)
1519 /* Saving a register to the stack. Make sure dest is relative to the
1521 switch (GET_CODE (XEXP (dest
, 0)))
1526 /* We can't handle variable size modifications. */
1527 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1529 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1531 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1532 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1535 cfa_store
.offset
+= offset
;
1536 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1537 cfa
.offset
= cfa_store
.offset
;
1539 offset
= -cfa_store
.offset
;
1545 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1546 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1549 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1550 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1553 cfa_store
.offset
+= offset
;
1554 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1555 cfa
.offset
= cfa_store
.offset
;
1557 offset
= -cfa_store
.offset
;
1561 /* With an offset. */
1565 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1567 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1568 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1571 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1572 offset
-= cfa_store
.offset
;
1573 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1574 offset
-= cfa_temp
.offset
;
1580 /* Without an offset. */
1582 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1583 offset
= -cfa_store
.offset
;
1584 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1585 offset
= -cfa_temp
.offset
;
1592 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1594 offset
= -cfa_temp
.offset
;
1595 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1602 if (REGNO (src
) != STACK_POINTER_REGNUM
1603 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1604 && (unsigned) REGNO (src
) == cfa
.reg
)
1606 /* We're storing the current CFA reg into the stack. */
1608 if (cfa
.offset
== 0)
1610 /* If the source register is exactly the CFA, assume
1611 we're saving SP like any other register; this happens
1613 def_cfa_1 (label
, &cfa
);
1614 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1619 /* Otherwise, we'll need to look in the stack to
1620 calculate the CFA. */
1621 rtx x
= XEXP (dest
, 0);
1623 if (GET_CODE (x
) != REG
)
1625 if (GET_CODE (x
) != REG
)
1628 cfa
.reg
= REGNO (x
);
1629 cfa
.base_offset
= offset
;
1631 def_cfa_1 (label
, &cfa
);
1636 def_cfa_1 (label
, &cfa
);
1637 queue_reg_save (label
, src
, offset
);
1645 /* Record call frame debugging information for INSN, which either
1646 sets SP or FP (adjusting how we calculate the frame address) or saves a
1647 register to the stack. If INSN is NULL_RTX, initialize our state. */
1650 dwarf2out_frame_debug (insn
)
1656 if (insn
== NULL_RTX
)
1658 /* Flush any queued register saves. */
1659 flush_queued_reg_saves ();
1661 /* Set up state for generating call frame debug info. */
1663 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1666 cfa
.reg
= STACK_POINTER_REGNUM
;
1669 cfa_temp
.offset
= 0;
1673 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1674 flush_queued_reg_saves ();
1676 if (! RTX_FRAME_RELATED_P (insn
))
1678 if (!ACCUMULATE_OUTGOING_ARGS
)
1679 dwarf2out_stack_adjust (insn
);
1684 label
= dwarf2out_cfi_label ();
1685 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1687 insn
= XEXP (src
, 0);
1689 insn
= PATTERN (insn
);
1691 dwarf2out_frame_debug_expr (insn
, label
);
1694 /* Output a Call Frame Information opcode and its operand(s). */
1697 output_cfi (cfi
, fde
, for_eh
)
1702 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1703 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1704 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1705 "DW_CFA_advance_loc 0x%lx",
1706 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1707 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1709 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1710 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1711 "DW_CFA_offset, column 0x%lx",
1712 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1713 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1715 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1716 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1717 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1718 "DW_CFA_restore, column 0x%lx",
1719 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1722 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1723 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1725 switch (cfi
->dw_cfi_opc
)
1727 case DW_CFA_set_loc
:
1729 dw2_asm_output_encoded_addr_rtx (
1730 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1731 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1734 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1735 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1738 case DW_CFA_advance_loc1
:
1739 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1740 fde
->dw_fde_current_label
, NULL
);
1741 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1744 case DW_CFA_advance_loc2
:
1745 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1746 fde
->dw_fde_current_label
, NULL
);
1747 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1750 case DW_CFA_advance_loc4
:
1751 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1752 fde
->dw_fde_current_label
, NULL
);
1753 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1756 case DW_CFA_MIPS_advance_loc8
:
1757 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1758 fde
->dw_fde_current_label
, NULL
);
1759 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1762 case DW_CFA_offset_extended
:
1763 case DW_CFA_def_cfa
:
1764 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1766 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1769 case DW_CFA_offset_extended_sf
:
1770 case DW_CFA_def_cfa_sf
:
1771 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1773 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1776 case DW_CFA_restore_extended
:
1777 case DW_CFA_undefined
:
1778 case DW_CFA_same_value
:
1779 case DW_CFA_def_cfa_register
:
1780 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1784 case DW_CFA_register
:
1785 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1787 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1791 case DW_CFA_def_cfa_offset
:
1792 case DW_CFA_GNU_args_size
:
1793 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1796 case DW_CFA_def_cfa_offset_sf
:
1797 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1800 case DW_CFA_GNU_window_save
:
1803 case DW_CFA_def_cfa_expression
:
1804 case DW_CFA_expression
:
1805 output_cfa_loc (cfi
);
1808 case DW_CFA_GNU_negative_offset_extended
:
1809 /* Obsoleted by DW_CFA_offset_extended_sf. */
1818 /* Output the call frame information used to used to record information
1819 that relates to calculating the frame pointer, and records the
1820 location of saved registers. */
1823 output_call_frame_info (for_eh
)
1829 char l1
[20], l2
[20], section_start_label
[20];
1830 int any_lsda_needed
= 0;
1831 char augmentation
[6];
1832 int augmentation_size
;
1833 int fde_encoding
= DW_EH_PE_absptr
;
1834 int per_encoding
= DW_EH_PE_absptr
;
1835 int lsda_encoding
= DW_EH_PE_absptr
;
1837 /* Don't emit a CIE if there won't be any FDEs. */
1838 if (fde_table_in_use
== 0)
1841 /* If we don't have any functions we'll want to unwind out of, don't emit any
1842 EH unwind information. */
1845 int any_eh_needed
= flag_asynchronous_unwind_tables
;
1847 for (i
= 0; i
< fde_table_in_use
; i
++)
1848 if (fde_table
[i
].uses_eh_lsda
)
1849 any_eh_needed
= any_lsda_needed
= 1;
1850 else if (! fde_table
[i
].nothrow
)
1853 if (! any_eh_needed
)
1857 /* We're going to be generating comments, so turn on app. */
1862 (*targetm
.asm_out
.eh_frame_section
) ();
1864 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1866 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1867 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1869 /* Output the CIE. */
1870 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1871 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1872 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1873 "Length of Common Information Entry");
1874 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1876 /* Now that the CIE pointer is PC-relative for EH,
1877 use 0 to identify the CIE. */
1878 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1879 (for_eh
? 0 : DW_CIE_ID
),
1880 "CIE Identifier Tag");
1882 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1884 augmentation
[0] = 0;
1885 augmentation_size
= 0;
1891 z Indicates that a uleb128 is present to size the
1892 augmentation section.
1893 L Indicates the encoding (and thus presence) of
1894 an LSDA pointer in the FDE augmentation.
1895 R Indicates a non-default pointer encoding for
1897 P Indicates the presence of an encoding + language
1898 personality routine in the CIE augmentation. */
1900 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1901 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1902 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1904 p
= augmentation
+ 1;
1905 if (eh_personality_libfunc
)
1908 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1910 if (any_lsda_needed
)
1913 augmentation_size
+= 1;
1915 if (fde_encoding
!= DW_EH_PE_absptr
)
1918 augmentation_size
+= 1;
1920 if (p
> augmentation
+ 1)
1922 augmentation
[0] = 'z';
1926 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1927 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1929 int offset
= ( 4 /* Length */
1931 + 1 /* CIE version */
1932 + strlen (augmentation
) + 1 /* Augmentation */
1933 + size_of_uleb128 (1) /* Code alignment */
1934 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1936 + 1 /* Augmentation size */
1937 + 1 /* Personality encoding */ );
1938 int pad
= -offset
& (PTR_SIZE
- 1);
1940 augmentation_size
+= pad
;
1942 /* Augmentations should be small, so there's scarce need to
1943 iterate for a solution. Die if we exceed one uleb128 byte. */
1944 if (size_of_uleb128 (augmentation_size
) != 1)
1949 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1950 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1951 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1952 "CIE Data Alignment Factor");
1953 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
1955 if (augmentation
[0])
1957 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
1958 if (eh_personality_libfunc
)
1960 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
1961 eh_data_format_name (per_encoding
));
1962 dw2_asm_output_encoded_addr_rtx (per_encoding
,
1963 eh_personality_libfunc
, NULL
);
1966 if (any_lsda_needed
)
1967 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
1968 eh_data_format_name (lsda_encoding
));
1970 if (fde_encoding
!= DW_EH_PE_absptr
)
1971 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
1972 eh_data_format_name (fde_encoding
));
1975 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1976 output_cfi (cfi
, NULL
, for_eh
);
1978 /* Pad the CIE out to an address sized boundary. */
1979 ASM_OUTPUT_ALIGN (asm_out_file
,
1980 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
1981 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1983 /* Loop through all of the FDE's. */
1984 for (i
= 0; i
< fde_table_in_use
; i
++)
1986 fde
= &fde_table
[i
];
1988 /* Don't emit EH unwind info for leaf functions that don't need it. */
1989 if (!flag_asynchronous_unwind_tables
&& for_eh
&& fde
->nothrow
1990 && ! fde
->uses_eh_lsda
)
1993 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
1994 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1995 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1996 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1998 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2001 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2003 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2008 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2009 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
2010 "FDE initial location");
2011 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2012 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2013 "FDE address range");
2017 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2018 "FDE initial location");
2019 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2020 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2021 "FDE address range");
2024 if (augmentation
[0])
2026 if (any_lsda_needed
)
2028 int size
= size_of_encoded_value (lsda_encoding
);
2030 if (lsda_encoding
== DW_EH_PE_aligned
)
2032 int offset
= ( 4 /* Length */
2033 + 4 /* CIE offset */
2034 + 2 * size_of_encoded_value (fde_encoding
)
2035 + 1 /* Augmentation size */ );
2036 int pad
= -offset
& (PTR_SIZE
- 1);
2039 if (size_of_uleb128 (size
) != 1)
2043 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2045 if (fde
->uses_eh_lsda
)
2047 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2048 fde
->funcdef_number
);
2049 dw2_asm_output_encoded_addr_rtx (
2050 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2051 "Language Specific Data Area");
2055 if (lsda_encoding
== DW_EH_PE_aligned
)
2056 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2058 (size_of_encoded_value (lsda_encoding
), 0,
2059 "Language Specific Data Area (none)");
2063 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2066 /* Loop through the Call Frame Instructions associated with
2068 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2069 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2070 output_cfi (cfi
, fde
, for_eh
);
2072 /* Pad the FDE out to an address sized boundary. */
2073 ASM_OUTPUT_ALIGN (asm_out_file
,
2074 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2075 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2078 #ifndef EH_FRAME_SECTION_NAME
2080 dw2_asm_output_data (4, 0, "End of Table");
2082 #ifdef MIPS_DEBUGGING_INFO
2083 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2084 get a value of 0. Putting .align 0 after the label fixes it. */
2085 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2088 /* Turn off app to make assembly quicker. */
2093 /* Output a marker (i.e. a label) for the beginning of a function, before
2097 dwarf2out_begin_prologue (line
, file
)
2098 unsigned int line ATTRIBUTE_UNUSED
;
2099 const char *file ATTRIBUTE_UNUSED
;
2101 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2104 current_function_func_begin_label
= 0;
2106 #ifdef IA64_UNWIND_INFO
2107 /* ??? current_function_func_begin_label is also used by except.c
2108 for call-site information. We must emit this label if it might
2110 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2111 && ! dwarf2out_do_frame ())
2114 if (! dwarf2out_do_frame ())
2118 current_funcdef_number
++;
2119 function_section (current_function_decl
);
2120 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2121 current_funcdef_number
);
2122 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2123 current_funcdef_number
);
2124 current_function_func_begin_label
= get_identifier (label
);
2126 #ifdef IA64_UNWIND_INFO
2127 /* We can elide the fde allocation if we're not emitting debug info. */
2128 if (! dwarf2out_do_frame ())
2132 /* Expand the fde table if necessary. */
2133 if (fde_table_in_use
== fde_table_allocated
)
2135 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2137 = (dw_fde_ref
) xrealloc (fde_table
,
2138 fde_table_allocated
* sizeof (dw_fde_node
));
2141 /* Record the FDE associated with this function. */
2142 current_funcdef_fde
= fde_table_in_use
;
2144 /* Add the new FDE at the end of the fde_table. */
2145 fde
= &fde_table
[fde_table_in_use
++];
2146 fde
->dw_fde_begin
= xstrdup (label
);
2147 fde
->dw_fde_current_label
= NULL
;
2148 fde
->dw_fde_end
= NULL
;
2149 fde
->dw_fde_cfi
= NULL
;
2150 fde
->funcdef_number
= current_funcdef_number
;
2151 fde
->nothrow
= current_function_nothrow
;
2152 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2154 args_size
= old_args_size
= 0;
2156 /* We only want to output line number information for the genuine dwarf2
2157 prologue case, not the eh frame case. */
2158 #ifdef DWARF2_DEBUGGING_INFO
2160 dwarf2out_source_line (line
, file
);
2164 /* Output a marker (i.e. a label) for the absolute end of the generated code
2165 for a function definition. This gets called *after* the epilogue code has
2169 dwarf2out_end_epilogue ()
2172 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2174 /* Output a label to mark the endpoint of the code generated for this
2176 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
, current_funcdef_number
);
2177 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2178 fde
= &fde_table
[fde_table_in_use
- 1];
2179 fde
->dw_fde_end
= xstrdup (label
);
2183 dwarf2out_frame_init ()
2185 /* Allocate the initial hunk of the fde_table. */
2186 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2187 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2188 fde_table_in_use
= 0;
2190 /* Generate the CFA instructions common to all FDE's. Do it now for the
2191 sake of lookup_cfa. */
2193 #ifdef DWARF2_UNWIND_INFO
2194 /* On entry, the Canonical Frame Address is at SP. */
2195 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2196 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2201 dwarf2out_frame_finish ()
2203 /* Output call frame information. */
2204 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2205 output_call_frame_info (0);
2207 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2208 output_call_frame_info (1);
2211 /* And now, the subset of the debugging information support code necessary
2212 for emitting location expressions. */
2214 typedef struct dw_val_struct
*dw_val_ref
;
2215 typedef struct die_struct
*dw_die_ref
;
2216 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2217 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2219 /* Each DIE may have a series of attribute/value pairs. Values
2220 can take on several forms. The forms that are used in this
2221 implementation are listed below. */
2226 dw_val_class_offset
,
2228 dw_val_class_loc_list
,
2229 dw_val_class_range_list
,
2231 dw_val_class_unsigned_const
,
2232 dw_val_class_long_long
,
2235 dw_val_class_die_ref
,
2236 dw_val_class_fde_ref
,
2237 dw_val_class_lbl_id
,
2238 dw_val_class_lbl_offset
,
2243 /* Describe a double word constant value. */
2244 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2246 typedef struct dw_long_long_struct
2253 /* Describe a floating point constant value. */
2255 typedef struct dw_fp_struct
2262 /* The dw_val_node describes an attribute's value, as it is
2263 represented internally. */
2265 typedef struct dw_val_struct
2267 dw_val_class val_class
;
2271 long unsigned val_offset
;
2272 dw_loc_list_ref val_loc_list
;
2273 dw_loc_descr_ref val_loc
;
2275 long unsigned val_unsigned
;
2276 dw_long_long_const val_long_long
;
2277 dw_float_const val_float
;
2283 unsigned val_fde_index
;
2284 struct indirect_string_node
*val_str
;
2286 unsigned char val_flag
;
2292 /* Locations in memory are described using a sequence of stack machine
2295 typedef struct dw_loc_descr_struct
2297 dw_loc_descr_ref dw_loc_next
;
2298 enum dwarf_location_atom dw_loc_opc
;
2299 dw_val_node dw_loc_oprnd1
;
2300 dw_val_node dw_loc_oprnd2
;
2305 /* Location lists are ranges + location descriptions for that range,
2306 so you can track variables that are in different places over
2307 their entire life. */
2308 typedef struct dw_loc_list_struct
2310 dw_loc_list_ref dw_loc_next
;
2311 const char *begin
; /* Label for begin address of range */
2312 const char *end
; /* Label for end address of range */
2313 char *ll_symbol
; /* Label for beginning of location list.
2314 Only on head of list */
2315 const char *section
; /* Section this loclist is relative to */
2316 dw_loc_descr_ref expr
;
2319 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2320 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2323 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2325 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2326 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2327 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2328 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2330 /* Convert a DWARF stack opcode into its string name. */
2333 dwarf_stack_op_name (op
)
2339 return "DW_OP_addr";
2341 return "DW_OP_deref";
2343 return "DW_OP_const1u";
2345 return "DW_OP_const1s";
2347 return "DW_OP_const2u";
2349 return "DW_OP_const2s";
2351 return "DW_OP_const4u";
2353 return "DW_OP_const4s";
2355 return "DW_OP_const8u";
2357 return "DW_OP_const8s";
2359 return "DW_OP_constu";
2361 return "DW_OP_consts";
2365 return "DW_OP_drop";
2367 return "DW_OP_over";
2369 return "DW_OP_pick";
2371 return "DW_OP_swap";
2375 return "DW_OP_xderef";
2383 return "DW_OP_minus";
2395 return "DW_OP_plus";
2396 case DW_OP_plus_uconst
:
2397 return "DW_OP_plus_uconst";
2403 return "DW_OP_shra";
2421 return "DW_OP_skip";
2423 return "DW_OP_lit0";
2425 return "DW_OP_lit1";
2427 return "DW_OP_lit2";
2429 return "DW_OP_lit3";
2431 return "DW_OP_lit4";
2433 return "DW_OP_lit5";
2435 return "DW_OP_lit6";
2437 return "DW_OP_lit7";
2439 return "DW_OP_lit8";
2441 return "DW_OP_lit9";
2443 return "DW_OP_lit10";
2445 return "DW_OP_lit11";
2447 return "DW_OP_lit12";
2449 return "DW_OP_lit13";
2451 return "DW_OP_lit14";
2453 return "DW_OP_lit15";
2455 return "DW_OP_lit16";
2457 return "DW_OP_lit17";
2459 return "DW_OP_lit18";
2461 return "DW_OP_lit19";
2463 return "DW_OP_lit20";
2465 return "DW_OP_lit21";
2467 return "DW_OP_lit22";
2469 return "DW_OP_lit23";
2471 return "DW_OP_lit24";
2473 return "DW_OP_lit25";
2475 return "DW_OP_lit26";
2477 return "DW_OP_lit27";
2479 return "DW_OP_lit28";
2481 return "DW_OP_lit29";
2483 return "DW_OP_lit30";
2485 return "DW_OP_lit31";
2487 return "DW_OP_reg0";
2489 return "DW_OP_reg1";
2491 return "DW_OP_reg2";
2493 return "DW_OP_reg3";
2495 return "DW_OP_reg4";
2497 return "DW_OP_reg5";
2499 return "DW_OP_reg6";
2501 return "DW_OP_reg7";
2503 return "DW_OP_reg8";
2505 return "DW_OP_reg9";
2507 return "DW_OP_reg10";
2509 return "DW_OP_reg11";
2511 return "DW_OP_reg12";
2513 return "DW_OP_reg13";
2515 return "DW_OP_reg14";
2517 return "DW_OP_reg15";
2519 return "DW_OP_reg16";
2521 return "DW_OP_reg17";
2523 return "DW_OP_reg18";
2525 return "DW_OP_reg19";
2527 return "DW_OP_reg20";
2529 return "DW_OP_reg21";
2531 return "DW_OP_reg22";
2533 return "DW_OP_reg23";
2535 return "DW_OP_reg24";
2537 return "DW_OP_reg25";
2539 return "DW_OP_reg26";
2541 return "DW_OP_reg27";
2543 return "DW_OP_reg28";
2545 return "DW_OP_reg29";
2547 return "DW_OP_reg30";
2549 return "DW_OP_reg31";
2551 return "DW_OP_breg0";
2553 return "DW_OP_breg1";
2555 return "DW_OP_breg2";
2557 return "DW_OP_breg3";
2559 return "DW_OP_breg4";
2561 return "DW_OP_breg5";
2563 return "DW_OP_breg6";
2565 return "DW_OP_breg7";
2567 return "DW_OP_breg8";
2569 return "DW_OP_breg9";
2571 return "DW_OP_breg10";
2573 return "DW_OP_breg11";
2575 return "DW_OP_breg12";
2577 return "DW_OP_breg13";
2579 return "DW_OP_breg14";
2581 return "DW_OP_breg15";
2583 return "DW_OP_breg16";
2585 return "DW_OP_breg17";
2587 return "DW_OP_breg18";
2589 return "DW_OP_breg19";
2591 return "DW_OP_breg20";
2593 return "DW_OP_breg21";
2595 return "DW_OP_breg22";
2597 return "DW_OP_breg23";
2599 return "DW_OP_breg24";
2601 return "DW_OP_breg25";
2603 return "DW_OP_breg26";
2605 return "DW_OP_breg27";
2607 return "DW_OP_breg28";
2609 return "DW_OP_breg29";
2611 return "DW_OP_breg30";
2613 return "DW_OP_breg31";
2615 return "DW_OP_regx";
2617 return "DW_OP_fbreg";
2619 return "DW_OP_bregx";
2621 return "DW_OP_piece";
2622 case DW_OP_deref_size
:
2623 return "DW_OP_deref_size";
2624 case DW_OP_xderef_size
:
2625 return "DW_OP_xderef_size";
2629 return "OP_<unknown>";
2633 /* Return a pointer to a newly allocated location description. Location
2634 descriptions are simple expression terms that can be strung
2635 together to form more complicated location (address) descriptions. */
2637 static inline dw_loc_descr_ref
2638 new_loc_descr (op
, oprnd1
, oprnd2
)
2639 enum dwarf_location_atom op
;
2640 unsigned long oprnd1
;
2641 unsigned long oprnd2
;
2643 /* Use xcalloc here so we clear out all of the long_long constant in
2645 dw_loc_descr_ref descr
2646 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2648 descr
->dw_loc_opc
= op
;
2649 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2650 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2651 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2652 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2658 /* Add a location description term to a location description expression. */
2661 add_loc_descr (list_head
, descr
)
2662 dw_loc_descr_ref
*list_head
;
2663 dw_loc_descr_ref descr
;
2665 dw_loc_descr_ref
*d
;
2667 /* Find the end of the chain. */
2668 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2674 /* Return the size of a location descriptor. */
2676 static unsigned long
2677 size_of_loc_descr (loc
)
2678 dw_loc_descr_ref loc
;
2680 unsigned long size
= 1;
2682 switch (loc
->dw_loc_opc
)
2685 size
+= DWARF2_ADDR_SIZE
;
2704 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2707 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2712 case DW_OP_plus_uconst
:
2713 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2751 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2754 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2757 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2760 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2761 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2764 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2766 case DW_OP_deref_size
:
2767 case DW_OP_xderef_size
:
2777 /* Return the size of a series of location descriptors. */
2779 static unsigned long
2781 dw_loc_descr_ref loc
;
2785 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2787 loc
->dw_loc_addr
= size
;
2788 size
+= size_of_loc_descr (loc
);
2794 /* Output location description stack opcode's operands (if any). */
2797 output_loc_operands (loc
)
2798 dw_loc_descr_ref loc
;
2800 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2801 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2803 switch (loc
->dw_loc_opc
)
2805 #ifdef DWARF2_DEBUGGING_INFO
2807 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2811 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2815 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2819 if (HOST_BITS_PER_LONG
< 64)
2821 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2828 if (val1
->val_class
== dw_val_class_loc
)
2829 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2833 dw2_asm_output_data (2, offset
, NULL
);
2846 /* We currently don't make any attempt to make sure these are
2847 aligned properly like we do for the main unwind info, so
2848 don't support emitting things larger than a byte if we're
2849 only doing unwinding. */
2854 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2857 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2860 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2863 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2865 case DW_OP_plus_uconst
:
2866 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2900 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2903 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2906 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2909 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2910 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2913 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2915 case DW_OP_deref_size
:
2916 case DW_OP_xderef_size
:
2917 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2920 /* Other codes have no operands. */
2925 /* Output a sequence of location operations. */
2928 output_loc_sequence (loc
)
2929 dw_loc_descr_ref loc
;
2931 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2933 /* Output the opcode. */
2934 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2935 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2937 /* Output the operand(s) (if any). */
2938 output_loc_operands (loc
);
2942 /* This routine will generate the correct assembly data for a location
2943 description based on a cfi entry with a complex address. */
2946 output_cfa_loc (cfi
)
2949 dw_loc_descr_ref loc
;
2952 /* Output the size of the block. */
2953 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2954 size
= size_of_locs (loc
);
2955 dw2_asm_output_data_uleb128 (size
, NULL
);
2957 /* Now output the operations themselves. */
2958 output_loc_sequence (loc
);
2961 /* This function builds a dwarf location descriptor sequence from
2962 a dw_cfa_location. */
2964 static struct dw_loc_descr_struct
*
2966 dw_cfa_location
*cfa
;
2968 struct dw_loc_descr_struct
*head
, *tmp
;
2970 if (cfa
->indirect
== 0)
2973 if (cfa
->base_offset
)
2976 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
2978 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
2980 else if (cfa
->reg
<= 31)
2981 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
2983 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
2985 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2986 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2987 add_loc_descr (&head
, tmp
);
2988 if (cfa
->offset
!= 0)
2990 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
2991 add_loc_descr (&head
, tmp
);
2997 /* This function fills in aa dw_cfa_location structure from a dwarf location
2998 descriptor sequence. */
3001 get_cfa_from_loc_descr (cfa
, loc
)
3002 dw_cfa_location
*cfa
;
3003 struct dw_loc_descr_struct
*loc
;
3005 struct dw_loc_descr_struct
*ptr
;
3007 cfa
->base_offset
= 0;
3011 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3013 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3049 cfa
->reg
= op
- DW_OP_reg0
;
3052 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3086 cfa
->reg
= op
- DW_OP_breg0
;
3087 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3090 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3091 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3096 case DW_OP_plus_uconst
:
3097 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3100 internal_error ("DW_LOC_OP %s not implemented\n",
3101 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3105 #endif /* .debug_frame support */
3107 /* And now, the support for symbolic debugging information. */
3108 #ifdef DWARF2_DEBUGGING_INFO
3110 /* .debug_str support. */
3111 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3112 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3113 hashnode
, const PTR
));
3116 static void dwarf2out_init
PARAMS ((const char *));
3117 static void dwarf2out_finish
PARAMS ((const char *));
3118 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3119 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3120 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3121 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3122 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3123 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3124 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3125 static void dwarf2out_global_decl
PARAMS ((tree
));
3126 static void dwarf2out_abstract_function
PARAMS ((tree
));
3128 /* The debug hooks structure. */
3130 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3136 dwarf2out_start_source_file
,
3137 dwarf2out_end_source_file
,
3138 dwarf2out_begin_block
,
3139 dwarf2out_end_block
,
3140 dwarf2out_ignore_block
,
3141 dwarf2out_source_line
,
3142 dwarf2out_begin_prologue
,
3143 debug_nothing_int
, /* end_prologue */
3144 dwarf2out_end_epilogue
,
3145 debug_nothing_tree
, /* begin_function */
3146 debug_nothing_int
, /* end_function */
3147 dwarf2out_decl
, /* function_decl */
3148 dwarf2out_global_decl
,
3149 debug_nothing_tree
, /* deferred_inline_function */
3150 /* The DWARF 2 backend tries to reduce debugging bloat by not
3151 emitting the abstract description of inline functions until
3152 something tries to reference them. */
3153 dwarf2out_abstract_function
, /* outlining_inline_function */
3154 debug_nothing_rtx
/* label */
3157 /* NOTE: In the comments in this file, many references are made to
3158 "Debugging Information Entries". This term is abbreviated as `DIE'
3159 throughout the remainder of this file. */
3161 /* An internal representation of the DWARF output is built, and then
3162 walked to generate the DWARF debugging info. The walk of the internal
3163 representation is done after the entire program has been compiled.
3164 The types below are used to describe the internal representation. */
3166 /* Various DIE's use offsets relative to the beginning of the
3167 .debug_info section to refer to each other. */
3169 typedef long int dw_offset
;
3171 /* Define typedefs here to avoid circular dependencies. */
3173 typedef struct dw_attr_struct
*dw_attr_ref
;
3174 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3175 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3176 typedef struct pubname_struct
*pubname_ref
;
3177 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3179 /* Each entry in the line_info_table maintains the file and
3180 line number associated with the label generated for that
3181 entry. The label gives the PC value associated with
3182 the line number entry. */
3184 typedef struct dw_line_info_struct
3186 unsigned long dw_file_num
;
3187 unsigned long dw_line_num
;
3191 /* Line information for functions in separate sections; each one gets its
3193 typedef struct dw_separate_line_info_struct
3195 unsigned long dw_file_num
;
3196 unsigned long dw_line_num
;
3197 unsigned long function
;
3199 dw_separate_line_info_entry
;
3201 /* Each DIE attribute has a field specifying the attribute kind,
3202 a link to the next attribute in the chain, and an attribute value.
3203 Attributes are typically linked below the DIE they modify. */
3205 typedef struct dw_attr_struct
3207 enum dwarf_attribute dw_attr
;
3208 dw_attr_ref dw_attr_next
;
3209 dw_val_node dw_attr_val
;
3213 /* The Debugging Information Entry (DIE) structure */
3215 typedef struct die_struct
3217 enum dwarf_tag die_tag
;
3219 dw_attr_ref die_attr
;
3220 dw_die_ref die_parent
;
3221 dw_die_ref die_child
;
3223 dw_offset die_offset
;
3224 unsigned long die_abbrev
;
3229 /* The pubname structure */
3231 typedef struct pubname_struct
3238 struct dw_ranges_struct
3243 /* The limbo die list structure. */
3244 typedef struct limbo_die_struct
3248 struct limbo_die_struct
*next
;
3252 /* How to start an assembler comment. */
3253 #ifndef ASM_COMMENT_START
3254 #define ASM_COMMENT_START ";#"
3257 /* Define a macro which returns non-zero for a TYPE_DECL which was
3258 implicitly generated for a tagged type.
3260 Note that unlike the gcc front end (which generates a NULL named
3261 TYPE_DECL node for each complete tagged type, each array type, and
3262 each function type node created) the g++ front end generates a
3263 _named_ TYPE_DECL node for each tagged type node created.
3264 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3265 generate a DW_TAG_typedef DIE for them. */
3267 #define TYPE_DECL_IS_STUB(decl) \
3268 (DECL_NAME (decl) == NULL_TREE \
3269 || (DECL_ARTIFICIAL (decl) \
3270 && is_tagged_type (TREE_TYPE (decl)) \
3271 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3272 /* This is necessary for stub decls that \
3273 appear in nested inline functions. */ \
3274 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3275 && (decl_ultimate_origin (decl) \
3276 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3278 /* Information concerning the compilation unit's programming
3279 language, and compiler version. */
3281 /* Fixed size portion of the DWARF compilation unit header. */
3282 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3284 /* Fixed size portion of debugging line information prolog. */
3285 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3287 /* Fixed size portion of public names info. */
3288 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3290 /* Fixed size portion of the address range info. */
3291 #define DWARF_ARANGES_HEADER_SIZE \
3292 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3293 - DWARF_OFFSET_SIZE)
3295 /* Size of padding portion in the address range info. It must be
3296 aligned to twice the pointer size. */
3297 #define DWARF_ARANGES_PAD_SIZE \
3298 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3299 - (2 * DWARF_OFFSET_SIZE + 4))
3301 /* Use assembler line directives if available. */
3302 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3303 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3304 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3306 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3310 /* Minimum line offset in a special line info. opcode.
3311 This value was chosen to give a reasonable range of values. */
3312 #define DWARF_LINE_BASE -10
3314 /* First special line opcode - leave room for the standard opcodes. */
3315 #define DWARF_LINE_OPCODE_BASE 10
3317 /* Range of line offsets in a special line info. opcode. */
3318 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3320 /* Flag that indicates the initial value of the is_stmt_start flag.
3321 In the present implementation, we do not mark any lines as
3322 the beginning of a source statement, because that information
3323 is not made available by the GCC front-end. */
3324 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3326 /* This location is used by calc_die_sizes() to keep track
3327 the offset of each DIE within the .debug_info section. */
3328 static unsigned long next_die_offset
;
3330 /* Record the root of the DIE's built for the current compilation unit. */
3331 static dw_die_ref comp_unit_die
;
3333 /* A list of DIEs with a NULL parent waiting to be relocated. */
3334 static limbo_die_node
*limbo_die_list
= 0;
3336 /* Structure used by lookup_filename to manage sets of filenames. */
3342 unsigned last_lookup_index
;
3345 /* Size (in elements) of increments by which we may expand the filename
3347 #define FILE_TABLE_INCREMENT 64
3349 /* Filenames referenced by this compilation unit. */
3350 static struct file_table file_table
;
3352 /* Local pointer to the name of the main input file. Initialized in
3354 static const char *primary_filename
;
3356 /* A pointer to the base of a table of references to DIE's that describe
3357 declarations. The table is indexed by DECL_UID() which is a unique
3358 number identifying each decl. */
3359 static dw_die_ref
*decl_die_table
;
3361 /* Number of elements currently allocated for the decl_die_table. */
3362 static unsigned decl_die_table_allocated
;
3364 /* Number of elements in decl_die_table currently in use. */
3365 static unsigned decl_die_table_in_use
;
3367 /* Size (in elements) of increments by which we may expand the
3369 #define DECL_DIE_TABLE_INCREMENT 256
3371 /* A pointer to the base of a list of references to DIE's that
3372 are uniquely identified by their tag, presence/absence of
3373 children DIE's, and list of attribute/value pairs. */
3374 static dw_die_ref
*abbrev_die_table
;
3376 /* Number of elements currently allocated for abbrev_die_table. */
3377 static unsigned abbrev_die_table_allocated
;
3379 /* Number of elements in type_die_table currently in use. */
3380 static unsigned abbrev_die_table_in_use
;
3382 /* Size (in elements) of increments by which we may expand the
3383 abbrev_die_table. */
3384 #define ABBREV_DIE_TABLE_INCREMENT 256
3386 /* A pointer to the base of a table that contains line information
3387 for each source code line in .text in the compilation unit. */
3388 static dw_line_info_ref line_info_table
;
3390 /* Number of elements currently allocated for line_info_table. */
3391 static unsigned line_info_table_allocated
;
3393 /* Number of elements in separate_line_info_table currently in use. */
3394 static unsigned separate_line_info_table_in_use
;
3396 /* A pointer to the base of a table that contains line information
3397 for each source code line outside of .text in the compilation unit. */
3398 static dw_separate_line_info_ref separate_line_info_table
;
3400 /* Number of elements currently allocated for separate_line_info_table. */
3401 static unsigned separate_line_info_table_allocated
;
3403 /* Number of elements in line_info_table currently in use. */
3404 static unsigned line_info_table_in_use
;
3406 /* Size (in elements) of increments by which we may expand the
3408 #define LINE_INFO_TABLE_INCREMENT 1024
3410 /* A pointer to the base of a table that contains a list of publicly
3411 accessible names. */
3412 static pubname_ref pubname_table
;
3414 /* Number of elements currently allocated for pubname_table. */
3415 static unsigned pubname_table_allocated
;
3417 /* Number of elements in pubname_table currently in use. */
3418 static unsigned pubname_table_in_use
;
3420 /* Size (in elements) of increments by which we may expand the
3422 #define PUBNAME_TABLE_INCREMENT 64
3424 /* Array of dies for which we should generate .debug_arange info. */
3425 static dw_die_ref
*arange_table
;
3427 /* Number of elements currently allocated for arange_table. */
3428 static unsigned arange_table_allocated
;
3430 /* Number of elements in arange_table currently in use. */
3431 static unsigned arange_table_in_use
;
3433 /* Size (in elements) of increments by which we may expand the
3435 #define ARANGE_TABLE_INCREMENT 64
3437 /* Array of dies for which we should generate .debug_ranges info. */
3438 static dw_ranges_ref ranges_table
;
3440 /* Number of elements currently allocated for ranges_table. */
3441 static unsigned ranges_table_allocated
;
3443 /* Number of elements in ranges_table currently in use. */
3444 static unsigned ranges_table_in_use
;
3446 /* Size (in elements) of increments by which we may expand the
3448 #define RANGES_TABLE_INCREMENT 64
3450 /* Whether we have location lists that need outputting */
3451 static unsigned have_location_lists
;
3453 /* Record whether the function being analyzed contains inlined functions. */
3454 static int current_function_has_inlines
;
3455 #if 0 && defined (MIPS_DEBUGGING_INFO)
3456 static int comp_unit_has_inlines
;
3459 /* Forward declarations for functions defined in this file. */
3461 static int is_pseudo_reg
PARAMS ((rtx
));
3462 static tree type_main_variant
PARAMS ((tree
));
3463 static int is_tagged_type
PARAMS ((tree
));
3464 static const char *dwarf_tag_name
PARAMS ((unsigned));
3465 static const char *dwarf_attr_name
PARAMS ((unsigned));
3466 static const char *dwarf_form_name
PARAMS ((unsigned));
3468 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3470 static tree decl_ultimate_origin
PARAMS ((tree
));
3471 static tree block_ultimate_origin
PARAMS ((tree
));
3472 static tree decl_class_context
PARAMS ((tree
));
3473 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3474 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3475 static void add_AT_flag
PARAMS ((dw_die_ref
,
3476 enum dwarf_attribute
,
3478 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3479 static void add_AT_int
PARAMS ((dw_die_ref
,
3480 enum dwarf_attribute
, long));
3481 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3482 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3483 enum dwarf_attribute
,
3485 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3486 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3487 enum dwarf_attribute
,
3490 static void add_AT_float
PARAMS ((dw_die_ref
,
3491 enum dwarf_attribute
,
3493 static void add_AT_string
PARAMS ((dw_die_ref
,
3494 enum dwarf_attribute
,
3496 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3497 static int AT_string_form
PARAMS ((dw_attr_ref
));
3498 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3499 enum dwarf_attribute
,
3501 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3502 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3503 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3504 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3505 enum dwarf_attribute
,
3507 static void add_AT_loc
PARAMS ((dw_die_ref
,
3508 enum dwarf_attribute
,
3510 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3511 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3512 enum dwarf_attribute
,
3514 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3515 static void add_AT_addr
PARAMS ((dw_die_ref
,
3516 enum dwarf_attribute
,
3518 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3519 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3520 enum dwarf_attribute
,
3522 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3523 enum dwarf_attribute
,
3525 static void add_AT_offset
PARAMS ((dw_die_ref
,
3526 enum dwarf_attribute
,
3528 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3529 enum dwarf_attribute
,
3531 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3532 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3533 enum dwarf_attribute
));
3534 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3535 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3536 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3537 enum dwarf_attribute
));
3538 static int get_AT_flag
PARAMS ((dw_die_ref
,
3539 enum dwarf_attribute
));
3540 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3541 enum dwarf_attribute
));
3542 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3543 enum dwarf_attribute
));
3544 static int is_c_family
PARAMS ((void));
3545 static int is_cxx
PARAMS ((void));
3546 static int is_java
PARAMS ((void));
3547 static int is_fortran
PARAMS ((void));
3548 static void remove_AT
PARAMS ((dw_die_ref
,
3549 enum dwarf_attribute
));
3550 static inline void free_die
PARAMS ((dw_die_ref
));
3551 static void remove_children
PARAMS ((dw_die_ref
));
3552 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3553 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3555 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3556 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3557 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3558 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3559 static void print_spaces
PARAMS ((FILE *));
3560 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3561 static void print_dwarf_line_table
PARAMS ((FILE *));
3562 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3563 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3564 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3565 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3566 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3568 static void attr_checksum
PARAMS ((dw_attr_ref
,
3570 static void die_checksum
PARAMS ((dw_die_ref
,
3572 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3573 static int is_type_die
PARAMS ((dw_die_ref
));
3574 static int is_comdat_die
PARAMS ((dw_die_ref
));
3575 static int is_symbol_die
PARAMS ((dw_die_ref
));
3576 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3577 static void break_out_includes
PARAMS ((dw_die_ref
));
3578 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3579 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3580 static void output_location_lists
PARAMS ((dw_die_ref
));
3581 static int constant_size
PARAMS ((long unsigned));
3582 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3583 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3584 static void mark_dies
PARAMS ((dw_die_ref
));
3585 static void unmark_dies
PARAMS ((dw_die_ref
));
3586 static unsigned long size_of_pubnames
PARAMS ((void));
3587 static unsigned long size_of_aranges
PARAMS ((void));
3588 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3589 static void output_value_format
PARAMS ((dw_attr_ref
));
3590 static void output_abbrev_section
PARAMS ((void));
3591 static void output_die_symbol
PARAMS ((dw_die_ref
));
3592 static void output_die
PARAMS ((dw_die_ref
));
3593 static void output_compilation_unit_header
PARAMS ((void));
3594 static void output_comp_unit
PARAMS ((dw_die_ref
));
3595 static const char *dwarf2_name
PARAMS ((tree
, int));
3596 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3597 static void output_pubnames
PARAMS ((void));
3598 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3599 static void output_aranges
PARAMS ((void));
3600 static unsigned int add_ranges
PARAMS ((tree
));
3601 static void output_ranges
PARAMS ((void));
3602 static void output_line_info
PARAMS ((void));
3603 static void output_file_names
PARAMS ((void));
3604 static dw_die_ref base_type_die
PARAMS ((tree
));
3605 static tree root_type
PARAMS ((tree
));
3606 static int is_base_type
PARAMS ((tree
));
3607 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3608 static int type_is_enum
PARAMS ((tree
));
3609 static unsigned int reg_number
PARAMS ((rtx
));
3610 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3611 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3612 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3613 static int is_based_loc
PARAMS ((rtx
));
3614 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3615 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3616 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3617 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3618 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3619 static tree field_type
PARAMS ((tree
));
3620 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3621 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3622 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3623 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3624 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3625 enum dwarf_attribute
, rtx
));
3626 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3627 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3628 static rtx rtl_for_decl_location
PARAMS ((tree
));
3629 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3630 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3631 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3632 static void add_bound_info
PARAMS ((dw_die_ref
,
3633 enum dwarf_attribute
, tree
));
3634 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3635 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3636 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3637 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3638 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3639 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3640 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3641 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3642 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3643 static void push_decl_scope
PARAMS ((tree
));
3644 static void pop_decl_scope
PARAMS ((void));
3645 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3646 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3647 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3648 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3650 static const char *type_tag
PARAMS ((tree
));
3651 static tree member_declared_type
PARAMS ((tree
));
3653 static const char *decl_start_label
PARAMS ((tree
));
3655 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3656 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3658 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3660 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3661 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3662 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3663 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3664 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3665 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3666 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3667 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3668 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3669 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3670 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3671 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3672 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3673 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3674 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3675 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3676 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3677 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3678 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3679 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3680 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3681 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3682 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3683 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3684 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3685 static int is_redundant_typedef
PARAMS ((tree
));
3686 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3687 static unsigned lookup_filename
PARAMS ((const char *));
3688 static void init_file_table
PARAMS ((void));
3689 static void retry_incomplete_types
PARAMS ((void));
3690 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3691 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3692 static int file_info_cmp
PARAMS ((const void *, const void *));
3693 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3694 const char *, const char *,
3695 const char *, unsigned));
3696 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3698 const char *, const char *, const char *));
3699 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3700 static char *gen_internal_sym
PARAMS ((const char *));
3701 static void mark_limbo_die_list
PARAMS ((void *));
3703 /* Section names used to hold DWARF debugging information. */
3704 #ifndef DEBUG_INFO_SECTION
3705 #define DEBUG_INFO_SECTION ".debug_info"
3707 #ifndef DEBUG_ABBREV_SECTION
3708 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3710 #ifndef DEBUG_ARANGES_SECTION
3711 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3713 #ifndef DEBUG_MACINFO_SECTION
3714 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3716 #ifndef DEBUG_LINE_SECTION
3717 #define DEBUG_LINE_SECTION ".debug_line"
3719 #ifndef DEBUG_LOC_SECTION
3720 #define DEBUG_LOC_SECTION ".debug_loc"
3722 #ifndef DEBUG_PUBNAMES_SECTION
3723 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3725 #ifndef DEBUG_STR_SECTION
3726 #define DEBUG_STR_SECTION ".debug_str"
3728 #ifndef DEBUG_RANGES_SECTION
3729 #define DEBUG_RANGES_SECTION ".debug_ranges"
3732 /* Standard ELF section names for compiled code and data. */
3733 #ifndef TEXT_SECTION_NAME
3734 #define TEXT_SECTION_NAME ".text"
3737 /* Section flags for .debug_str section. */
3738 #ifdef HAVE_GAS_SHF_MERGE
3739 #define DEBUG_STR_SECTION_FLAGS \
3740 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3742 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3745 /* Labels we insert at beginning sections we can reference instead of
3746 the section names themselves. */
3748 #ifndef TEXT_SECTION_LABEL
3749 #define TEXT_SECTION_LABEL "Ltext"
3751 #ifndef DEBUG_LINE_SECTION_LABEL
3752 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3754 #ifndef DEBUG_INFO_SECTION_LABEL
3755 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3757 #ifndef DEBUG_ABBREV_SECTION_LABEL
3758 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3760 #ifndef DEBUG_LOC_SECTION_LABEL
3761 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3763 #ifndef DEBUG_RANGES_SECTION_LABEL
3764 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3766 #ifndef DEBUG_MACINFO_SECTION_LABEL
3767 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3770 /* Definitions of defaults for formats and names of various special
3771 (artificial) labels which may be generated within this file (when the -g
3772 options is used and DWARF_DEBUGGING_INFO is in effect.
3773 If necessary, these may be overridden from within the tm.h file, but
3774 typically, overriding these defaults is unnecessary. */
3776 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3777 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3778 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3779 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3780 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3781 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3782 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3783 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3785 #ifndef TEXT_END_LABEL
3786 #define TEXT_END_LABEL "Letext"
3788 #ifndef DATA_END_LABEL
3789 #define DATA_END_LABEL "Ledata"
3791 #ifndef BSS_END_LABEL
3792 #define BSS_END_LABEL "Lebss"
3794 #ifndef BLOCK_BEGIN_LABEL
3795 #define BLOCK_BEGIN_LABEL "LBB"
3797 #ifndef BLOCK_END_LABEL
3798 #define BLOCK_END_LABEL "LBE"
3800 #ifndef BODY_BEGIN_LABEL
3801 #define BODY_BEGIN_LABEL "Lbb"
3803 #ifndef BODY_END_LABEL
3804 #define BODY_END_LABEL "Lbe"
3806 #ifndef LINE_CODE_LABEL
3807 #define LINE_CODE_LABEL "LM"
3809 #ifndef SEPARATE_LINE_CODE_LABEL
3810 #define SEPARATE_LINE_CODE_LABEL "LSM"
3813 /* We allow a language front-end to designate a function that is to be
3814 called to "demangle" any name before it it put into a DIE. */
3816 static const char *(*demangle_name_func
) PARAMS ((const char *));
3819 dwarf2out_set_demangle_name_func (func
)
3820 const char *(*func
) PARAMS ((const char *));
3822 demangle_name_func
= func
;
3825 /* Test if rtl node points to a pseudo register. */
3831 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3832 || (GET_CODE (rtl
) == SUBREG
3833 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3836 /* Return a reference to a type, with its const and volatile qualifiers
3840 type_main_variant (type
)
3843 type
= TYPE_MAIN_VARIANT (type
);
3845 /* ??? There really should be only one main variant among any group of
3846 variants of a given type (and all of the MAIN_VARIANT values for all
3847 members of the group should point to that one type) but sometimes the C
3848 front-end messes this up for array types, so we work around that bug
3850 if (TREE_CODE (type
) == ARRAY_TYPE
)
3851 while (type
!= TYPE_MAIN_VARIANT (type
))
3852 type
= TYPE_MAIN_VARIANT (type
);
3857 /* Return non-zero if the given type node represents a tagged type. */
3860 is_tagged_type (type
)
3863 enum tree_code code
= TREE_CODE (type
);
3865 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3866 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3869 /* Convert a DIE tag into its string name. */
3872 dwarf_tag_name (tag
)
3877 case DW_TAG_padding
:
3878 return "DW_TAG_padding";
3879 case DW_TAG_array_type
:
3880 return "DW_TAG_array_type";
3881 case DW_TAG_class_type
:
3882 return "DW_TAG_class_type";
3883 case DW_TAG_entry_point
:
3884 return "DW_TAG_entry_point";
3885 case DW_TAG_enumeration_type
:
3886 return "DW_TAG_enumeration_type";
3887 case DW_TAG_formal_parameter
:
3888 return "DW_TAG_formal_parameter";
3889 case DW_TAG_imported_declaration
:
3890 return "DW_TAG_imported_declaration";
3892 return "DW_TAG_label";
3893 case DW_TAG_lexical_block
:
3894 return "DW_TAG_lexical_block";
3896 return "DW_TAG_member";
3897 case DW_TAG_pointer_type
:
3898 return "DW_TAG_pointer_type";
3899 case DW_TAG_reference_type
:
3900 return "DW_TAG_reference_type";
3901 case DW_TAG_compile_unit
:
3902 return "DW_TAG_compile_unit";
3903 case DW_TAG_string_type
:
3904 return "DW_TAG_string_type";
3905 case DW_TAG_structure_type
:
3906 return "DW_TAG_structure_type";
3907 case DW_TAG_subroutine_type
:
3908 return "DW_TAG_subroutine_type";
3909 case DW_TAG_typedef
:
3910 return "DW_TAG_typedef";
3911 case DW_TAG_union_type
:
3912 return "DW_TAG_union_type";
3913 case DW_TAG_unspecified_parameters
:
3914 return "DW_TAG_unspecified_parameters";
3915 case DW_TAG_variant
:
3916 return "DW_TAG_variant";
3917 case DW_TAG_common_block
:
3918 return "DW_TAG_common_block";
3919 case DW_TAG_common_inclusion
:
3920 return "DW_TAG_common_inclusion";
3921 case DW_TAG_inheritance
:
3922 return "DW_TAG_inheritance";
3923 case DW_TAG_inlined_subroutine
:
3924 return "DW_TAG_inlined_subroutine";
3926 return "DW_TAG_module";
3927 case DW_TAG_ptr_to_member_type
:
3928 return "DW_TAG_ptr_to_member_type";
3929 case DW_TAG_set_type
:
3930 return "DW_TAG_set_type";
3931 case DW_TAG_subrange_type
:
3932 return "DW_TAG_subrange_type";
3933 case DW_TAG_with_stmt
:
3934 return "DW_TAG_with_stmt";
3935 case DW_TAG_access_declaration
:
3936 return "DW_TAG_access_declaration";
3937 case DW_TAG_base_type
:
3938 return "DW_TAG_base_type";
3939 case DW_TAG_catch_block
:
3940 return "DW_TAG_catch_block";
3941 case DW_TAG_const_type
:
3942 return "DW_TAG_const_type";
3943 case DW_TAG_constant
:
3944 return "DW_TAG_constant";
3945 case DW_TAG_enumerator
:
3946 return "DW_TAG_enumerator";
3947 case DW_TAG_file_type
:
3948 return "DW_TAG_file_type";
3950 return "DW_TAG_friend";
3951 case DW_TAG_namelist
:
3952 return "DW_TAG_namelist";
3953 case DW_TAG_namelist_item
:
3954 return "DW_TAG_namelist_item";
3955 case DW_TAG_packed_type
:
3956 return "DW_TAG_packed_type";
3957 case DW_TAG_subprogram
:
3958 return "DW_TAG_subprogram";
3959 case DW_TAG_template_type_param
:
3960 return "DW_TAG_template_type_param";
3961 case DW_TAG_template_value_param
:
3962 return "DW_TAG_template_value_param";
3963 case DW_TAG_thrown_type
:
3964 return "DW_TAG_thrown_type";
3965 case DW_TAG_try_block
:
3966 return "DW_TAG_try_block";
3967 case DW_TAG_variant_part
:
3968 return "DW_TAG_variant_part";
3969 case DW_TAG_variable
:
3970 return "DW_TAG_variable";
3971 case DW_TAG_volatile_type
:
3972 return "DW_TAG_volatile_type";
3973 case DW_TAG_MIPS_loop
:
3974 return "DW_TAG_MIPS_loop";
3975 case DW_TAG_format_label
:
3976 return "DW_TAG_format_label";
3977 case DW_TAG_function_template
:
3978 return "DW_TAG_function_template";
3979 case DW_TAG_class_template
:
3980 return "DW_TAG_class_template";
3981 case DW_TAG_GNU_BINCL
:
3982 return "DW_TAG_GNU_BINCL";
3983 case DW_TAG_GNU_EINCL
:
3984 return "DW_TAG_GNU_EINCL";
3986 return "DW_TAG_<unknown>";
3990 /* Convert a DWARF attribute code into its string name. */
3993 dwarf_attr_name (attr
)
3999 return "DW_AT_sibling";
4000 case DW_AT_location
:
4001 return "DW_AT_location";
4003 return "DW_AT_name";
4004 case DW_AT_ordering
:
4005 return "DW_AT_ordering";
4006 case DW_AT_subscr_data
:
4007 return "DW_AT_subscr_data";
4008 case DW_AT_byte_size
:
4009 return "DW_AT_byte_size";
4010 case DW_AT_bit_offset
:
4011 return "DW_AT_bit_offset";
4012 case DW_AT_bit_size
:
4013 return "DW_AT_bit_size";
4014 case DW_AT_element_list
:
4015 return "DW_AT_element_list";
4016 case DW_AT_stmt_list
:
4017 return "DW_AT_stmt_list";
4019 return "DW_AT_low_pc";
4021 return "DW_AT_high_pc";
4022 case DW_AT_language
:
4023 return "DW_AT_language";
4025 return "DW_AT_member";
4027 return "DW_AT_discr";
4028 case DW_AT_discr_value
:
4029 return "DW_AT_discr_value";
4030 case DW_AT_visibility
:
4031 return "DW_AT_visibility";
4033 return "DW_AT_import";
4034 case DW_AT_string_length
:
4035 return "DW_AT_string_length";
4036 case DW_AT_common_reference
:
4037 return "DW_AT_common_reference";
4038 case DW_AT_comp_dir
:
4039 return "DW_AT_comp_dir";
4040 case DW_AT_const_value
:
4041 return "DW_AT_const_value";
4042 case DW_AT_containing_type
:
4043 return "DW_AT_containing_type";
4044 case DW_AT_default_value
:
4045 return "DW_AT_default_value";
4047 return "DW_AT_inline";
4048 case DW_AT_is_optional
:
4049 return "DW_AT_is_optional";
4050 case DW_AT_lower_bound
:
4051 return "DW_AT_lower_bound";
4052 case DW_AT_producer
:
4053 return "DW_AT_producer";
4054 case DW_AT_prototyped
:
4055 return "DW_AT_prototyped";
4056 case DW_AT_return_addr
:
4057 return "DW_AT_return_addr";
4058 case DW_AT_start_scope
:
4059 return "DW_AT_start_scope";
4060 case DW_AT_stride_size
:
4061 return "DW_AT_stride_size";
4062 case DW_AT_upper_bound
:
4063 return "DW_AT_upper_bound";
4064 case DW_AT_abstract_origin
:
4065 return "DW_AT_abstract_origin";
4066 case DW_AT_accessibility
:
4067 return "DW_AT_accessibility";
4068 case DW_AT_address_class
:
4069 return "DW_AT_address_class";
4070 case DW_AT_artificial
:
4071 return "DW_AT_artificial";
4072 case DW_AT_base_types
:
4073 return "DW_AT_base_types";
4074 case DW_AT_calling_convention
:
4075 return "DW_AT_calling_convention";
4077 return "DW_AT_count";
4078 case DW_AT_data_member_location
:
4079 return "DW_AT_data_member_location";
4080 case DW_AT_decl_column
:
4081 return "DW_AT_decl_column";
4082 case DW_AT_decl_file
:
4083 return "DW_AT_decl_file";
4084 case DW_AT_decl_line
:
4085 return "DW_AT_decl_line";
4086 case DW_AT_declaration
:
4087 return "DW_AT_declaration";
4088 case DW_AT_discr_list
:
4089 return "DW_AT_discr_list";
4090 case DW_AT_encoding
:
4091 return "DW_AT_encoding";
4092 case DW_AT_external
:
4093 return "DW_AT_external";
4094 case DW_AT_frame_base
:
4095 return "DW_AT_frame_base";
4097 return "DW_AT_friend";
4098 case DW_AT_identifier_case
:
4099 return "DW_AT_identifier_case";
4100 case DW_AT_macro_info
:
4101 return "DW_AT_macro_info";
4102 case DW_AT_namelist_items
:
4103 return "DW_AT_namelist_items";
4104 case DW_AT_priority
:
4105 return "DW_AT_priority";
4107 return "DW_AT_segment";
4108 case DW_AT_specification
:
4109 return "DW_AT_specification";
4110 case DW_AT_static_link
:
4111 return "DW_AT_static_link";
4113 return "DW_AT_type";
4114 case DW_AT_use_location
:
4115 return "DW_AT_use_location";
4116 case DW_AT_variable_parameter
:
4117 return "DW_AT_variable_parameter";
4118 case DW_AT_virtuality
:
4119 return "DW_AT_virtuality";
4120 case DW_AT_vtable_elem_location
:
4121 return "DW_AT_vtable_elem_location";
4123 case DW_AT_allocated
:
4124 return "DW_AT_allocated";
4125 case DW_AT_associated
:
4126 return "DW_AT_associated";
4127 case DW_AT_data_location
:
4128 return "DW_AT_data_location";
4130 return "DW_AT_stride";
4131 case DW_AT_entry_pc
:
4132 return "DW_AT_entry_pc";
4133 case DW_AT_use_UTF8
:
4134 return "DW_AT_use_UTF8";
4135 case DW_AT_extension
:
4136 return "DW_AT_extension";
4138 return "DW_AT_ranges";
4139 case DW_AT_trampoline
:
4140 return "DW_AT_trampoline";
4141 case DW_AT_call_column
:
4142 return "DW_AT_call_column";
4143 case DW_AT_call_file
:
4144 return "DW_AT_call_file";
4145 case DW_AT_call_line
:
4146 return "DW_AT_call_line";
4148 case DW_AT_MIPS_fde
:
4149 return "DW_AT_MIPS_fde";
4150 case DW_AT_MIPS_loop_begin
:
4151 return "DW_AT_MIPS_loop_begin";
4152 case DW_AT_MIPS_tail_loop_begin
:
4153 return "DW_AT_MIPS_tail_loop_begin";
4154 case DW_AT_MIPS_epilog_begin
:
4155 return "DW_AT_MIPS_epilog_begin";
4156 case DW_AT_MIPS_loop_unroll_factor
:
4157 return "DW_AT_MIPS_loop_unroll_factor";
4158 case DW_AT_MIPS_software_pipeline_depth
:
4159 return "DW_AT_MIPS_software_pipeline_depth";
4160 case DW_AT_MIPS_linkage_name
:
4161 return "DW_AT_MIPS_linkage_name";
4162 case DW_AT_MIPS_stride
:
4163 return "DW_AT_MIPS_stride";
4164 case DW_AT_MIPS_abstract_name
:
4165 return "DW_AT_MIPS_abstract_name";
4166 case DW_AT_MIPS_clone_origin
:
4167 return "DW_AT_MIPS_clone_origin";
4168 case DW_AT_MIPS_has_inlines
:
4169 return "DW_AT_MIPS_has_inlines";
4171 case DW_AT_sf_names
:
4172 return "DW_AT_sf_names";
4173 case DW_AT_src_info
:
4174 return "DW_AT_src_info";
4175 case DW_AT_mac_info
:
4176 return "DW_AT_mac_info";
4177 case DW_AT_src_coords
:
4178 return "DW_AT_src_coords";
4179 case DW_AT_body_begin
:
4180 return "DW_AT_body_begin";
4181 case DW_AT_body_end
:
4182 return "DW_AT_body_end";
4183 case DW_AT_GNU_vector
:
4184 return "DW_AT_GNU_vector";
4186 case DW_AT_VMS_rtnbeg_pd_address
:
4187 return "DW_AT_VMS_rtnbeg_pd_address";
4190 return "DW_AT_<unknown>";
4194 /* Convert a DWARF value form code into its string name. */
4197 dwarf_form_name (form
)
4203 return "DW_FORM_addr";
4204 case DW_FORM_block2
:
4205 return "DW_FORM_block2";
4206 case DW_FORM_block4
:
4207 return "DW_FORM_block4";
4209 return "DW_FORM_data2";
4211 return "DW_FORM_data4";
4213 return "DW_FORM_data8";
4214 case DW_FORM_string
:
4215 return "DW_FORM_string";
4217 return "DW_FORM_block";
4218 case DW_FORM_block1
:
4219 return "DW_FORM_block1";
4221 return "DW_FORM_data1";
4223 return "DW_FORM_flag";
4225 return "DW_FORM_sdata";
4227 return "DW_FORM_strp";
4229 return "DW_FORM_udata";
4230 case DW_FORM_ref_addr
:
4231 return "DW_FORM_ref_addr";
4233 return "DW_FORM_ref1";
4235 return "DW_FORM_ref2";
4237 return "DW_FORM_ref4";
4239 return "DW_FORM_ref8";
4240 case DW_FORM_ref_udata
:
4241 return "DW_FORM_ref_udata";
4242 case DW_FORM_indirect
:
4243 return "DW_FORM_indirect";
4245 return "DW_FORM_<unknown>";
4249 /* Convert a DWARF type code into its string name. */
4253 dwarf_type_encoding_name (enc
)
4258 case DW_ATE_address
:
4259 return "DW_ATE_address";
4260 case DW_ATE_boolean
:
4261 return "DW_ATE_boolean";
4262 case DW_ATE_complex_float
:
4263 return "DW_ATE_complex_float";
4265 return "DW_ATE_float";
4267 return "DW_ATE_signed";
4268 case DW_ATE_signed_char
:
4269 return "DW_ATE_signed_char";
4270 case DW_ATE_unsigned
:
4271 return "DW_ATE_unsigned";
4272 case DW_ATE_unsigned_char
:
4273 return "DW_ATE_unsigned_char";
4275 return "DW_ATE_<unknown>";
4280 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4281 instance of an inlined instance of a decl which is local to an inline
4282 function, so we have to trace all of the way back through the origin chain
4283 to find out what sort of node actually served as the original seed for the
4287 decl_ultimate_origin (decl
)
4290 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4291 nodes in the function to point to themselves; ignore that if
4292 we're trying to output the abstract instance of this function. */
4293 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4296 #ifdef ENABLE_CHECKING
4297 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4298 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4299 most distant ancestor, this should never happen. */
4303 return DECL_ABSTRACT_ORIGIN (decl
);
4306 /* Determine the "ultimate origin" of a block. The block may be an inlined
4307 instance of an inlined instance of a block which is local to an inline
4308 function, so we have to trace all of the way back through the origin chain
4309 to find out what sort of node actually served as the original seed for the
4313 block_ultimate_origin (block
)
4316 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4318 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4319 nodes in the function to point to themselves; ignore that if
4320 we're trying to output the abstract instance of this function. */
4321 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4324 if (immediate_origin
== NULL_TREE
)
4329 tree lookahead
= immediate_origin
;
4333 ret_val
= lookahead
;
4334 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4335 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4337 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4343 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4344 of a virtual function may refer to a base class, so we check the 'this'
4348 decl_class_context (decl
)
4351 tree context
= NULL_TREE
;
4353 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4354 context
= DECL_CONTEXT (decl
);
4356 context
= TYPE_MAIN_VARIANT
4357 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4359 if (context
&& !TYPE_P (context
))
4360 context
= NULL_TREE
;
4365 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4366 addition order, and correct that in reverse_all_dies. */
4369 add_dwarf_attr (die
, attr
)
4373 if (die
!= NULL
&& attr
!= NULL
)
4375 attr
->dw_attr_next
= die
->die_attr
;
4376 die
->die_attr
= attr
;
4380 static inline dw_val_class
4384 return a
->dw_attr_val
.val_class
;
4387 /* Add a flag value attribute to a DIE. */
4390 add_AT_flag (die
, attr_kind
, flag
)
4392 enum dwarf_attribute attr_kind
;
4395 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4397 attr
->dw_attr_next
= NULL
;
4398 attr
->dw_attr
= attr_kind
;
4399 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4400 attr
->dw_attr_val
.v
.val_flag
= flag
;
4401 add_dwarf_attr (die
, attr
);
4404 static inline unsigned
4408 if (a
&& AT_class (a
) == dw_val_class_flag
)
4409 return a
->dw_attr_val
.v
.val_flag
;
4414 /* Add a signed integer attribute value to a DIE. */
4417 add_AT_int (die
, attr_kind
, int_val
)
4419 enum dwarf_attribute attr_kind
;
4422 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4424 attr
->dw_attr_next
= NULL
;
4425 attr
->dw_attr
= attr_kind
;
4426 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4427 attr
->dw_attr_val
.v
.val_int
= int_val
;
4428 add_dwarf_attr (die
, attr
);
4431 static inline long int
4435 if (a
&& AT_class (a
) == dw_val_class_const
)
4436 return a
->dw_attr_val
.v
.val_int
;
4441 /* Add an unsigned integer attribute value to a DIE. */
4444 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4446 enum dwarf_attribute attr_kind
;
4447 unsigned long unsigned_val
;
4449 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4451 attr
->dw_attr_next
= NULL
;
4452 attr
->dw_attr
= attr_kind
;
4453 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4454 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4455 add_dwarf_attr (die
, attr
);
4458 static inline unsigned long
4462 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4463 return a
->dw_attr_val
.v
.val_unsigned
;
4468 /* Add an unsigned double integer attribute value to a DIE. */
4471 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4473 enum dwarf_attribute attr_kind
;
4474 unsigned long val_hi
;
4475 unsigned long val_low
;
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_long_long
;
4482 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4483 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4484 add_dwarf_attr (die
, attr
);
4487 /* Add a floating point attribute value to a DIE and return it. */
4490 add_AT_float (die
, attr_kind
, length
, array
)
4492 enum dwarf_attribute attr_kind
;
4496 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4498 attr
->dw_attr_next
= NULL
;
4499 attr
->dw_attr
= attr_kind
;
4500 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4501 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4502 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4503 add_dwarf_attr (die
, attr
);
4506 /* Add a string attribute value to a DIE. */
4509 add_AT_string (die
, attr_kind
, str
)
4511 enum dwarf_attribute attr_kind
;
4514 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4515 struct indirect_string_node
*node
;
4517 if (! debug_str_hash
)
4519 debug_str_hash
= ht_create (10);
4520 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4523 node
= (struct indirect_string_node
*)
4524 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4525 strlen (str
), HT_ALLOC
);
4528 attr
->dw_attr_next
= NULL
;
4529 attr
->dw_attr
= attr_kind
;
4530 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4531 attr
->dw_attr_val
.v
.val_str
= node
;
4532 add_dwarf_attr (die
, attr
);
4535 static inline const char *
4539 if (a
&& AT_class (a
) == dw_val_class_str
)
4540 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4545 /* Find out whether a string should be output inline in DIE
4546 or out-of-line in .debug_str section. */
4552 if (a
&& AT_class (a
) == dw_val_class_str
)
4554 struct indirect_string_node
*node
;
4556 extern int const_labelno
;
4559 node
= a
->dw_attr_val
.v
.val_str
;
4563 len
= HT_LEN (&node
->id
) + 1;
4565 /* If the string is shorter or equal to the size of the reference, it is
4566 always better to put it inline. */
4567 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4568 return node
->form
= DW_FORM_string
;
4570 /* If we cannot expect the linker to merge strings in .debug_str
4571 section, only put it into .debug_str if it is worth even in this
4573 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4574 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4575 return node
->form
= DW_FORM_string
;
4577 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4579 node
->label
= xstrdup (label
);
4581 return node
->form
= DW_FORM_strp
;
4587 /* Add a DIE reference attribute value to a DIE. */
4590 add_AT_die_ref (die
, attr_kind
, targ_die
)
4592 enum dwarf_attribute attr_kind
;
4593 dw_die_ref targ_die
;
4595 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4597 attr
->dw_attr_next
= NULL
;
4598 attr
->dw_attr
= attr_kind
;
4599 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4600 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4601 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4602 add_dwarf_attr (die
, attr
);
4605 static inline dw_die_ref
4609 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4610 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4619 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4620 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4626 set_AT_ref_external (a
, i
)
4630 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4631 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4636 /* Add an FDE reference attribute value to a DIE. */
4639 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4641 enum dwarf_attribute attr_kind
;
4644 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4646 attr
->dw_attr_next
= NULL
;
4647 attr
->dw_attr
= attr_kind
;
4648 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4649 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4650 add_dwarf_attr (die
, attr
);
4653 /* Add a location description attribute value to a DIE. */
4656 add_AT_loc (die
, attr_kind
, loc
)
4658 enum dwarf_attribute attr_kind
;
4659 dw_loc_descr_ref loc
;
4661 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4663 attr
->dw_attr_next
= NULL
;
4664 attr
->dw_attr
= attr_kind
;
4665 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4666 attr
->dw_attr_val
.v
.val_loc
= loc
;
4667 add_dwarf_attr (die
, attr
);
4670 static inline dw_loc_descr_ref
4674 if (a
&& AT_class (a
) == dw_val_class_loc
)
4675 return a
->dw_attr_val
.v
.val_loc
;
4681 add_AT_loc_list (die
, attr_kind
, loc_list
)
4683 enum dwarf_attribute attr_kind
;
4684 dw_loc_list_ref loc_list
;
4686 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4688 attr
->dw_attr_next
= NULL
;
4689 attr
->dw_attr
= attr_kind
;
4690 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4691 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4692 add_dwarf_attr (die
, attr
);
4693 have_location_lists
= 1;
4696 static inline dw_loc_list_ref
4700 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4701 return a
->dw_attr_val
.v
.val_loc_list
;
4706 /* Add an address constant attribute value to a DIE. */
4709 add_AT_addr (die
, attr_kind
, addr
)
4711 enum dwarf_attribute attr_kind
;
4714 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4716 attr
->dw_attr_next
= NULL
;
4717 attr
->dw_attr
= attr_kind
;
4718 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4719 attr
->dw_attr_val
.v
.val_addr
= addr
;
4720 add_dwarf_attr (die
, attr
);
4727 if (a
&& AT_class (a
) == dw_val_class_addr
)
4728 return a
->dw_attr_val
.v
.val_addr
;
4733 /* Add a label identifier attribute value to a DIE. */
4736 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4738 enum dwarf_attribute attr_kind
;
4741 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4743 attr
->dw_attr_next
= NULL
;
4744 attr
->dw_attr
= attr_kind
;
4745 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4746 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4747 add_dwarf_attr (die
, attr
);
4750 /* Add a section offset attribute value to a DIE. */
4753 add_AT_lbl_offset (die
, attr_kind
, label
)
4755 enum dwarf_attribute attr_kind
;
4758 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4760 attr
->dw_attr_next
= NULL
;
4761 attr
->dw_attr
= attr_kind
;
4762 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4763 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4764 add_dwarf_attr (die
, attr
);
4767 /* Add an offset attribute value to a DIE. */
4770 add_AT_offset (die
, attr_kind
, offset
)
4772 enum dwarf_attribute attr_kind
;
4773 unsigned long offset
;
4775 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4777 attr
->dw_attr_next
= NULL
;
4778 attr
->dw_attr
= attr_kind
;
4779 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4780 attr
->dw_attr_val
.v
.val_offset
= offset
;
4781 add_dwarf_attr (die
, attr
);
4784 /* Add an range_list attribute value to a DIE. */
4787 add_AT_range_list (die
, attr_kind
, offset
)
4789 enum dwarf_attribute attr_kind
;
4790 unsigned long offset
;
4792 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4794 attr
->dw_attr_next
= NULL
;
4795 attr
->dw_attr
= attr_kind
;
4796 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4797 attr
->dw_attr_val
.v
.val_offset
= offset
;
4798 add_dwarf_attr (die
, attr
);
4801 static inline const char *
4805 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4806 || AT_class (a
) == dw_val_class_lbl_offset
))
4807 return a
->dw_attr_val
.v
.val_lbl_id
;
4812 /* Get the attribute of type attr_kind. */
4814 static inline dw_attr_ref
4815 get_AT (die
, attr_kind
)
4817 enum dwarf_attribute attr_kind
;
4820 dw_die_ref spec
= NULL
;
4824 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4825 if (a
->dw_attr
== attr_kind
)
4827 else if (a
->dw_attr
== DW_AT_specification
4828 || a
->dw_attr
== DW_AT_abstract_origin
)
4832 return get_AT (spec
, attr_kind
);
4838 /* Return the "low pc" attribute value, typically associated with a subprogram
4839 DIE. Return null if the "low pc" attribute is either not present, or if it
4840 cannot be represented as an assembler label identifier. */
4842 static inline const char *
4846 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4848 return a
? AT_lbl (a
) : NULL
;
4851 /* Return the "high pc" attribute value, typically associated with a subprogram
4852 DIE. Return null if the "high pc" attribute is either not present, or if it
4853 cannot be represented as an assembler label identifier. */
4855 static inline const char *
4859 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4861 return a
? AT_lbl (a
) : NULL
;
4864 /* Return the value of the string attribute designated by ATTR_KIND, or
4865 NULL if it is not present. */
4867 static inline const char *
4868 get_AT_string (die
, attr_kind
)
4870 enum dwarf_attribute attr_kind
;
4872 dw_attr_ref a
= get_AT (die
, attr_kind
);
4874 return a
? AT_string (a
) : NULL
;
4877 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4878 if it is not present. */
4881 get_AT_flag (die
, attr_kind
)
4883 enum dwarf_attribute attr_kind
;
4885 dw_attr_ref a
= get_AT (die
, attr_kind
);
4887 return a
? AT_flag (a
) : 0;
4890 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4891 if it is not present. */
4893 static inline unsigned
4894 get_AT_unsigned (die
, attr_kind
)
4896 enum dwarf_attribute attr_kind
;
4898 dw_attr_ref a
= get_AT (die
, attr_kind
);
4900 return a
? AT_unsigned (a
) : 0;
4903 static inline dw_die_ref
4904 get_AT_ref (die
, attr_kind
)
4906 enum dwarf_attribute attr_kind
;
4908 dw_attr_ref a
= get_AT (die
, attr_kind
);
4910 return a
? AT_ref (a
) : NULL
;
4916 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4918 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4919 || lang
== DW_LANG_C_plus_plus
);
4925 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4926 == DW_LANG_C_plus_plus
);
4932 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4934 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4940 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4942 return (lang
== DW_LANG_Java
);
4945 /* Free up the memory used by A. */
4947 static inline void free_AT
PARAMS ((dw_attr_ref
));
4952 switch (AT_class (a
))
4954 case dw_val_class_str
:
4955 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4956 a
->dw_attr_val
.v
.val_str
->refcount
--;
4959 case dw_val_class_lbl_id
:
4960 case dw_val_class_lbl_offset
:
4961 free (a
->dw_attr_val
.v
.val_lbl_id
);
4964 case dw_val_class_float
:
4965 free (a
->dw_attr_val
.v
.val_float
.array
);
4975 /* Remove the specified attribute if present. */
4978 remove_AT (die
, attr_kind
)
4980 enum dwarf_attribute attr_kind
;
4983 dw_attr_ref removed
= NULL
;
4987 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
4988 if ((*p
)->dw_attr
== attr_kind
)
4991 *p
= (*p
)->dw_attr_next
;
5000 /* Free up the memory used by DIE. */
5006 remove_children (die
);
5010 /* Discard the children of this DIE. */
5013 remove_children (die
)
5016 dw_die_ref child_die
= die
->die_child
;
5018 die
->die_child
= NULL
;
5020 while (child_die
!= NULL
)
5022 dw_die_ref tmp_die
= child_die
;
5025 child_die
= child_die
->die_sib
;
5027 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5029 dw_attr_ref tmp_a
= a
;
5031 a
= a
->dw_attr_next
;
5039 /* Add a child DIE below its parent. We build the lists up in reverse
5040 addition order, and correct that in reverse_all_dies. */
5043 add_child_die (die
, child_die
)
5045 dw_die_ref child_die
;
5047 if (die
!= NULL
&& child_die
!= NULL
)
5049 if (die
== child_die
)
5052 child_die
->die_parent
= die
;
5053 child_die
->die_sib
= die
->die_child
;
5054 die
->die_child
= child_die
;
5058 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5059 is the specification, to the front of PARENT's list of children. */
5062 splice_child_die (parent
, child
)
5063 dw_die_ref parent
, child
;
5067 /* We want the declaration DIE from inside the class, not the
5068 specification DIE at toplevel. */
5069 if (child
->die_parent
!= parent
)
5071 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5077 if (child
->die_parent
!= parent
5078 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5081 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5084 *p
= child
->die_sib
;
5088 child
->die_sib
= parent
->die_child
;
5089 parent
->die_child
= child
;
5092 /* Return a pointer to a newly created DIE node. */
5094 static inline dw_die_ref
5095 new_die (tag_value
, parent_die
, t
)
5096 enum dwarf_tag tag_value
;
5097 dw_die_ref parent_die
;
5100 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5102 die
->die_tag
= tag_value
;
5104 if (parent_die
!= NULL
)
5105 add_child_die (parent_die
, die
);
5108 limbo_die_node
*limbo_node
;
5110 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5111 limbo_node
->die
= die
;
5112 limbo_node
->created_for
= t
;
5113 limbo_node
->next
= limbo_die_list
;
5114 limbo_die_list
= limbo_node
;
5120 /* Return the DIE associated with the given type specifier. */
5122 static inline dw_die_ref
5123 lookup_type_die (type
)
5126 return TYPE_SYMTAB_DIE (type
);
5129 /* Equate a DIE to a given type specifier. */
5132 equate_type_number_to_die (type
, type_die
)
5134 dw_die_ref type_die
;
5136 TYPE_SYMTAB_DIE (type
) = type_die
;
5139 /* Return the DIE associated with a given declaration. */
5141 static inline dw_die_ref
5142 lookup_decl_die (decl
)
5145 unsigned decl_id
= DECL_UID (decl
);
5147 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5150 /* Equate a DIE to a particular declaration. */
5153 equate_decl_number_to_die (decl
, decl_die
)
5155 dw_die_ref decl_die
;
5157 unsigned int decl_id
= DECL_UID (decl
);
5158 unsigned int num_allocated
;
5160 if (decl_id
>= decl_die_table_allocated
)
5163 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5164 / DECL_DIE_TABLE_INCREMENT
)
5165 * DECL_DIE_TABLE_INCREMENT
;
5168 = (dw_die_ref
*) xrealloc (decl_die_table
,
5169 sizeof (dw_die_ref
) * num_allocated
);
5171 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5172 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5173 decl_die_table_allocated
= num_allocated
;
5176 if (decl_id
>= decl_die_table_in_use
)
5177 decl_die_table_in_use
= (decl_id
+ 1);
5179 decl_die_table
[decl_id
] = decl_die
;
5182 /* Keep track of the number of spaces used to indent the
5183 output of the debugging routines that print the structure of
5184 the DIE internal representation. */
5185 static int print_indent
;
5187 /* Indent the line the number of spaces given by print_indent. */
5190 print_spaces (outfile
)
5193 fprintf (outfile
, "%*s", print_indent
, "");
5196 /* Print the information associated with a given DIE, and its children.
5197 This routine is a debugging aid only. */
5200 print_die (die
, outfile
)
5207 print_spaces (outfile
);
5208 fprintf (outfile
, "DIE %4lu: %s\n",
5209 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5210 print_spaces (outfile
);
5211 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5212 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5214 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5216 print_spaces (outfile
);
5217 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5219 switch (AT_class (a
))
5221 case dw_val_class_addr
:
5222 fprintf (outfile
, "address");
5224 case dw_val_class_offset
:
5225 fprintf (outfile
, "offset");
5227 case dw_val_class_loc
:
5228 fprintf (outfile
, "location descriptor");
5230 case dw_val_class_loc_list
:
5231 fprintf (outfile
, "location list -> label:%s",
5232 AT_loc_list (a
)->ll_symbol
);
5234 case dw_val_class_range_list
:
5235 fprintf (outfile
, "range list");
5237 case dw_val_class_const
:
5238 fprintf (outfile
, "%ld", AT_int (a
));
5240 case dw_val_class_unsigned_const
:
5241 fprintf (outfile
, "%lu", AT_unsigned (a
));
5243 case dw_val_class_long_long
:
5244 fprintf (outfile
, "constant (%lu,%lu)",
5245 a
->dw_attr_val
.v
.val_long_long
.hi
,
5246 a
->dw_attr_val
.v
.val_long_long
.low
);
5248 case dw_val_class_float
:
5249 fprintf (outfile
, "floating-point constant");
5251 case dw_val_class_flag
:
5252 fprintf (outfile
, "%u", AT_flag (a
));
5254 case dw_val_class_die_ref
:
5255 if (AT_ref (a
) != NULL
)
5257 if (AT_ref (a
)->die_symbol
)
5258 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5260 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5263 fprintf (outfile
, "die -> <null>");
5265 case dw_val_class_lbl_id
:
5266 case dw_val_class_lbl_offset
:
5267 fprintf (outfile
, "label: %s", AT_lbl (a
));
5269 case dw_val_class_str
:
5270 if (AT_string (a
) != NULL
)
5271 fprintf (outfile
, "\"%s\"", AT_string (a
));
5273 fprintf (outfile
, "<null>");
5279 fprintf (outfile
, "\n");
5282 if (die
->die_child
!= NULL
)
5285 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5286 print_die (c
, outfile
);
5290 if (print_indent
== 0)
5291 fprintf (outfile
, "\n");
5294 /* Print the contents of the source code line number correspondence table.
5295 This routine is a debugging aid only. */
5298 print_dwarf_line_table (outfile
)
5302 dw_line_info_ref line_info
;
5304 fprintf (outfile
, "\n\nDWARF source line information\n");
5305 for (i
= 1; i
< line_info_table_in_use
; i
++)
5307 line_info
= &line_info_table
[i
];
5308 fprintf (outfile
, "%5d: ", i
);
5309 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5310 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5311 fprintf (outfile
, "\n");
5314 fprintf (outfile
, "\n\n");
5317 /* Print the information collected for a given DIE. */
5320 debug_dwarf_die (die
)
5323 print_die (die
, stderr
);
5326 /* Print all DWARF information collected for the compilation unit.
5327 This routine is a debugging aid only. */
5333 print_die (comp_unit_die
, stderr
);
5334 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5335 print_dwarf_line_table (stderr
);
5338 /* We build up the lists of children and attributes by pushing new ones
5339 onto the beginning of the list. Reverse the lists for DIE so that
5340 they are in order of addition. */
5343 reverse_die_lists (die
)
5346 dw_die_ref c
, cp
, cn
;
5347 dw_attr_ref a
, ap
, an
;
5349 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5351 an
= a
->dw_attr_next
;
5352 a
->dw_attr_next
= ap
;
5358 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5365 die
->die_child
= cp
;
5368 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5369 reverse all dies in add_sibling_attributes, which runs through all the dies,
5370 it would reverse all the dies. Now, however, since we don't call
5371 reverse_die_lists in add_sibling_attributes, we need a routine to
5372 recursively reverse all the dies. This is that routine. */
5375 reverse_all_dies (die
)
5380 reverse_die_lists (die
);
5382 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5383 reverse_all_dies (c
);
5386 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5387 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5388 DIE that marks the start of the DIEs for this include file. */
5391 push_new_compile_unit (old_unit
, bincl_die
)
5392 dw_die_ref old_unit
, bincl_die
;
5394 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5395 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5397 new_unit
->die_sib
= old_unit
;
5401 /* Close an include-file CU and reopen the enclosing one. */
5404 pop_compile_unit (old_unit
)
5405 dw_die_ref old_unit
;
5407 dw_die_ref new_unit
= old_unit
->die_sib
;
5409 old_unit
->die_sib
= NULL
;
5413 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5414 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5416 /* Calculate the checksum of a location expression. */
5419 loc_checksum (loc
, ctx
)
5420 dw_loc_descr_ref loc
;
5421 struct md5_ctx
*ctx
;
5423 CHECKSUM (loc
->dw_loc_opc
);
5424 CHECKSUM (loc
->dw_loc_oprnd1
);
5425 CHECKSUM (loc
->dw_loc_oprnd2
);
5428 /* Calculate the checksum of an attribute. */
5431 attr_checksum (at
, ctx
)
5433 struct md5_ctx
*ctx
;
5435 dw_loc_descr_ref loc
;
5438 CHECKSUM (at
->dw_attr
);
5440 /* We don't care about differences in file numbering. */
5441 if (at
->dw_attr
== DW_AT_decl_file
5442 /* Or that this was compiled with a different compiler snapshot; if
5443 the output is the same, that's what matters. */
5444 || at
->dw_attr
== DW_AT_producer
)
5447 switch (AT_class (at
))
5449 case dw_val_class_const
:
5450 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5452 case dw_val_class_unsigned_const
:
5453 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5455 case dw_val_class_long_long
:
5456 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5458 case dw_val_class_float
:
5459 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5461 case dw_val_class_flag
:
5462 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5464 case dw_val_class_str
:
5465 CHECKSUM_STRING (AT_string (at
));
5468 case dw_val_class_addr
:
5470 switch (GET_CODE (r
))
5473 CHECKSUM_STRING (XSTR (r
, 0));
5481 case dw_val_class_offset
:
5482 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5485 case dw_val_class_loc
:
5486 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5487 loc_checksum (loc
, ctx
);
5490 case dw_val_class_die_ref
:
5491 if (AT_ref (at
)->die_offset
)
5492 CHECKSUM (AT_ref (at
)->die_offset
);
5493 /* FIXME else use target die name or something. */
5495 case dw_val_class_fde_ref
:
5496 case dw_val_class_lbl_id
:
5497 case dw_val_class_lbl_offset
:
5505 /* Calculate the checksum of a DIE. */
5508 die_checksum (die
, ctx
)
5510 struct md5_ctx
*ctx
;
5515 CHECKSUM (die
->die_tag
);
5517 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5518 attr_checksum (a
, ctx
);
5520 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5521 die_checksum (c
, ctx
);
5525 #undef CHECKSUM_STRING
5527 /* The prefix to attach to symbols on DIEs in the current comdat debug
5529 static char *comdat_symbol_id
;
5531 /* The index of the current symbol within the current comdat CU. */
5532 static unsigned int comdat_symbol_number
;
5534 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5535 children, and set comdat_symbol_id accordingly. */
5538 compute_section_prefix (unit_die
)
5539 dw_die_ref unit_die
;
5541 const char *base
= lbasename (get_AT_string (unit_die
, DW_AT_name
));
5542 char *name
= (char *) alloca (strlen (base
) + 64);
5545 unsigned char checksum
[16];
5548 /* Compute the checksum of the DIE, then append part of it as hex digits to
5549 the name filename of the unit. */
5551 md5_init_ctx (&ctx
);
5552 die_checksum (unit_die
, &ctx
);
5553 md5_finish_ctx (&ctx
, checksum
);
5555 sprintf (name
, "%s.", base
);
5556 clean_symbol_name (name
);
5558 p
= name
+ strlen (name
);
5559 for (i
= 0; i
< 4; i
++)
5561 sprintf (p
, "%.2x", checksum
[i
]);
5565 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5566 comdat_symbol_number
= 0;
5569 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5575 switch (die
->die_tag
)
5577 case DW_TAG_array_type
:
5578 case DW_TAG_class_type
:
5579 case DW_TAG_enumeration_type
:
5580 case DW_TAG_pointer_type
:
5581 case DW_TAG_reference_type
:
5582 case DW_TAG_string_type
:
5583 case DW_TAG_structure_type
:
5584 case DW_TAG_subroutine_type
:
5585 case DW_TAG_union_type
:
5586 case DW_TAG_ptr_to_member_type
:
5587 case DW_TAG_set_type
:
5588 case DW_TAG_subrange_type
:
5589 case DW_TAG_base_type
:
5590 case DW_TAG_const_type
:
5591 case DW_TAG_file_type
:
5592 case DW_TAG_packed_type
:
5593 case DW_TAG_volatile_type
:
5600 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5601 Basically, we want to choose the bits that are likely to be shared between
5602 compilations (types) and leave out the bits that are specific to individual
5603 compilations (functions). */
5609 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5610 we do for stabs. The advantage is a greater likelihood of sharing between
5611 objects that don't include headers in the same order (and therefore would
5612 put the base types in a different comdat). jason 8/28/00 */
5614 if (c
->die_tag
== DW_TAG_base_type
)
5617 if (c
->die_tag
== DW_TAG_pointer_type
5618 || c
->die_tag
== DW_TAG_reference_type
5619 || c
->die_tag
== DW_TAG_const_type
5620 || c
->die_tag
== DW_TAG_volatile_type
)
5622 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5624 return t
? is_comdat_die (t
) : 0;
5627 return is_type_die (c
);
5630 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5631 compilation unit. */
5637 return (is_type_die (c
)
5638 || (get_AT (c
, DW_AT_declaration
)
5639 && !get_AT (c
, DW_AT_specification
)));
5643 gen_internal_sym (prefix
)
5647 static int label_num
;
5649 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5650 return xstrdup (buf
);
5653 /* Assign symbols to all worthy DIEs under DIE. */
5656 assign_symbol_names (die
)
5661 if (is_symbol_die (die
))
5663 if (comdat_symbol_id
)
5665 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5667 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5668 comdat_symbol_id
, comdat_symbol_number
++);
5669 die
->die_symbol
= xstrdup (p
);
5672 die
->die_symbol
= gen_internal_sym ("LDIE");
5675 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5676 assign_symbol_names (c
);
5679 /* Traverse the DIE (which is always comp_unit_die), and set up
5680 additional compilation units for each of the include files we see
5681 bracketed by BINCL/EINCL. */
5684 break_out_includes (die
)
5688 dw_die_ref unit
= NULL
;
5689 limbo_die_node
*node
;
5691 for (ptr
= &(die
->die_child
); *ptr
;)
5693 dw_die_ref c
= *ptr
;
5695 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5696 || (unit
&& is_comdat_die (c
)))
5698 /* This DIE is for a secondary CU; remove it from the main one. */
5701 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
5703 unit
= push_new_compile_unit (unit
, c
);
5706 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
5708 unit
= pop_compile_unit (unit
);
5712 add_child_die (unit
, c
);
5716 /* Leave this DIE in the main CU. */
5717 ptr
= &(c
->die_sib
);
5723 /* We can only use this in debugging, since the frontend doesn't check
5724 to make sure that we leave every include file we enter. */
5729 assign_symbol_names (die
);
5730 for (node
= limbo_die_list
; node
; node
= node
->next
)
5732 compute_section_prefix (node
->die
);
5733 assign_symbol_names (node
->die
);
5737 /* Traverse the DIE and add a sibling attribute if it may have the
5738 effect of speeding up access to siblings. To save some space,
5739 avoid generating sibling attributes for DIE's without children. */
5742 add_sibling_attributes (die
)
5747 if (die
->die_tag
!= DW_TAG_compile_unit
5748 && die
->die_sib
&& die
->die_child
!= NULL
)
5749 /* Add the sibling link to the front of the attribute list. */
5750 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
5752 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5753 add_sibling_attributes (c
);
5756 /* Output all location lists for the DIE and its children. */
5759 output_location_lists (die
)
5765 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5766 if (AT_class (d_attr
) == dw_val_class_loc_list
)
5767 output_loc_list (AT_loc_list (d_attr
));
5769 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5770 output_location_lists (c
);
5774 /* The format of each DIE (and its attribute value pairs) is encoded in an
5775 abbreviation table. This routine builds the abbreviation table and assigns
5776 a unique abbreviation id for each abbreviation entry. The children of each
5777 die are visited recursively. */
5780 build_abbrev_table (die
)
5783 unsigned long abbrev_id
;
5784 unsigned int n_alloc
;
5786 dw_attr_ref d_attr
, a_attr
;
5788 /* Scan the DIE references, and mark as external any that refer to
5789 DIEs from other CUs (i.e. those which are not marked). */
5790 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
5791 if (AT_class (d_attr
) == dw_val_class_die_ref
5792 && AT_ref (d_attr
)->die_mark
== 0)
5794 if (AT_ref (d_attr
)->die_symbol
== 0)
5797 set_AT_ref_external (d_attr
, 1);
5800 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
5802 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
5804 if (abbrev
->die_tag
== die
->die_tag
)
5806 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
5808 a_attr
= abbrev
->die_attr
;
5809 d_attr
= die
->die_attr
;
5811 while (a_attr
!= NULL
&& d_attr
!= NULL
)
5813 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
5814 || (value_format (a_attr
) != value_format (d_attr
)))
5817 a_attr
= a_attr
->dw_attr_next
;
5818 d_attr
= d_attr
->dw_attr_next
;
5821 if (a_attr
== NULL
&& d_attr
== NULL
)
5827 if (abbrev_id
>= abbrev_die_table_in_use
)
5829 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
5831 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
5833 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
5834 sizeof (dw_die_ref
) * n_alloc
);
5836 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
5837 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
5838 abbrev_die_table_allocated
= n_alloc
;
5841 ++abbrev_die_table_in_use
;
5842 abbrev_die_table
[abbrev_id
] = die
;
5845 die
->die_abbrev
= abbrev_id
;
5846 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5847 build_abbrev_table (c
);
5850 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5853 constant_size (value
)
5854 long unsigned value
;
5861 log
= floor_log2 (value
);
5864 log
= 1 << (floor_log2 (log
) + 1);
5869 /* Return the size of a DIE as it is represented in the
5870 .debug_info section. */
5872 static unsigned long
5876 unsigned long size
= 0;
5879 size
+= size_of_uleb128 (die
->die_abbrev
);
5880 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5882 switch (AT_class (a
))
5884 case dw_val_class_addr
:
5885 size
+= DWARF2_ADDR_SIZE
;
5887 case dw_val_class_offset
:
5888 size
+= DWARF_OFFSET_SIZE
;
5890 case dw_val_class_loc
:
5892 unsigned long lsize
= size_of_locs (AT_loc (a
));
5895 size
+= constant_size (lsize
);
5899 case dw_val_class_loc_list
:
5900 size
+= DWARF_OFFSET_SIZE
;
5902 case dw_val_class_range_list
:
5903 size
+= DWARF_OFFSET_SIZE
;
5905 case dw_val_class_const
:
5906 size
+= size_of_sleb128 (AT_int (a
));
5908 case dw_val_class_unsigned_const
:
5909 size
+= constant_size (AT_unsigned (a
));
5911 case dw_val_class_long_long
:
5912 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
5914 case dw_val_class_float
:
5915 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
5917 case dw_val_class_flag
:
5920 case dw_val_class_die_ref
:
5921 size
+= DWARF_OFFSET_SIZE
;
5923 case dw_val_class_fde_ref
:
5924 size
+= DWARF_OFFSET_SIZE
;
5926 case dw_val_class_lbl_id
:
5927 size
+= DWARF2_ADDR_SIZE
;
5929 case dw_val_class_lbl_offset
:
5930 size
+= DWARF_OFFSET_SIZE
;
5932 case dw_val_class_str
:
5933 if (AT_string_form (a
) == DW_FORM_strp
)
5934 size
+= DWARF_OFFSET_SIZE
;
5936 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
5946 /* Size the debugging information associated with a given DIE. Visits the
5947 DIE's children recursively. Updates the global variable next_die_offset, on
5948 each time through. Uses the current value of next_die_offset to update the
5949 die_offset field in each DIE. */
5952 calc_die_sizes (die
)
5957 die
->die_offset
= next_die_offset
;
5958 next_die_offset
+= size_of_die (die
);
5960 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5963 if (die
->die_child
!= NULL
)
5964 /* Count the null byte used to terminate sibling lists. */
5965 next_die_offset
+= 1;
5968 /* Set the marks for a die and its children. We do this so
5969 that we know whether or not a reference needs to use FORM_ref_addr; only
5970 DIEs in the same CU will be marked. We used to clear out the offset
5971 and use that as the flag, but ran into ordering problems. */
5980 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5984 /* Clear the marks for a die and its children. */
5993 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5997 /* Return the size of the .debug_pubnames table generated for the
5998 compilation unit. */
6000 static unsigned long
6006 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6007 for (i
= 0; i
< pubname_table_in_use
; i
++)
6009 pubname_ref p
= &pubname_table
[i
];
6010 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6013 size
+= DWARF_OFFSET_SIZE
;
6017 /* Return the size of the information in the .debug_aranges section. */
6019 static unsigned long
6024 size
= DWARF_ARANGES_HEADER_SIZE
;
6026 /* Count the address/length pair for this compilation unit. */
6027 size
+= 2 * DWARF2_ADDR_SIZE
;
6028 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6030 /* Count the two zero words used to terminated the address range table. */
6031 size
+= 2 * DWARF2_ADDR_SIZE
;
6035 /* Select the encoding of an attribute value. */
6037 static enum dwarf_form
6041 switch (a
->dw_attr_val
.val_class
)
6043 case dw_val_class_addr
:
6044 return DW_FORM_addr
;
6045 case dw_val_class_range_list
:
6046 case dw_val_class_offset
:
6047 if (DWARF_OFFSET_SIZE
== 4)
6048 return DW_FORM_data4
;
6049 if (DWARF_OFFSET_SIZE
== 8)
6050 return DW_FORM_data8
;
6052 case dw_val_class_loc_list
:
6053 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6054 .debug_loc section */
6055 return DW_FORM_data4
;
6056 case dw_val_class_loc
:
6057 switch (constant_size (size_of_locs (AT_loc (a
))))
6060 return DW_FORM_block1
;
6062 return DW_FORM_block2
;
6066 case dw_val_class_const
:
6067 return DW_FORM_sdata
;
6068 case dw_val_class_unsigned_const
:
6069 switch (constant_size (AT_unsigned (a
)))
6072 return DW_FORM_data1
;
6074 return DW_FORM_data2
;
6076 return DW_FORM_data4
;
6078 return DW_FORM_data8
;
6082 case dw_val_class_long_long
:
6083 return DW_FORM_block1
;
6084 case dw_val_class_float
:
6085 return DW_FORM_block1
;
6086 case dw_val_class_flag
:
6087 return DW_FORM_flag
;
6088 case dw_val_class_die_ref
:
6089 if (AT_ref_external (a
))
6090 return DW_FORM_ref_addr
;
6093 case dw_val_class_fde_ref
:
6094 return DW_FORM_data
;
6095 case dw_val_class_lbl_id
:
6096 return DW_FORM_addr
;
6097 case dw_val_class_lbl_offset
:
6098 return DW_FORM_data
;
6099 case dw_val_class_str
:
6100 return AT_string_form (a
);
6107 /* Output the encoding of an attribute value. */
6110 output_value_format (a
)
6113 enum dwarf_form form
= value_format (a
);
6115 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6118 /* Output the .debug_abbrev section which defines the DIE abbreviation
6122 output_abbrev_section ()
6124 unsigned long abbrev_id
;
6128 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6130 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6132 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6133 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6134 dwarf_tag_name (abbrev
->die_tag
));
6136 if (abbrev
->die_child
!= NULL
)
6137 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6139 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6141 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6142 a_attr
= a_attr
->dw_attr_next
)
6144 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6145 dwarf_attr_name (a_attr
->dw_attr
));
6146 output_value_format (a_attr
);
6149 dw2_asm_output_data (1, 0, NULL
);
6150 dw2_asm_output_data (1, 0, NULL
);
6153 /* Terminate the table. */
6154 dw2_asm_output_data (1, 0, NULL
);
6157 /* Output a symbol we can use to refer to this DIE from another CU. */
6160 output_die_symbol (die
)
6163 char *sym
= die
->die_symbol
;
6168 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6169 /* We make these global, not weak; if the target doesn't support
6170 .linkonce, it doesn't support combining the sections, so debugging
6172 ASM_GLOBALIZE_LABEL (asm_out_file
, sym
);
6174 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6177 /* Return a new location list, given the begin and end range, and the
6178 expression. gensym tells us whether to generate a new internal symbol for
6179 this location list node, which is done for the head of the list only. */
6181 static inline dw_loc_list_ref
6182 new_loc_list (expr
, begin
, end
, section
, gensym
)
6183 dw_loc_descr_ref expr
;
6186 const char *section
;
6189 dw_loc_list_ref retlist
6190 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6192 retlist
->begin
= begin
;
6194 retlist
->expr
= expr
;
6195 retlist
->section
= section
;
6197 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6202 /* Add a location description expression to a location list */
6205 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6206 dw_loc_list_ref
*list_head
;
6207 dw_loc_descr_ref descr
;
6210 const char *section
;
6214 /* Find the end of the chain. */
6215 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6218 /* Add a new location list node to the list */
6219 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6222 /* Output the location list given to us */
6225 output_loc_list (list_head
)
6226 dw_loc_list_ref list_head
;
6228 dw_loc_list_ref curr
= list_head
;
6230 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6232 /* ??? This shouldn't be needed now that we've forced the
6233 compilation unit base address to zero when there is code
6234 in more than one section. */
6235 if (strcmp (curr
->section
, ".text") == 0)
6237 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6238 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6239 "Location list base address specifier fake entry");
6240 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6241 "Location list base address specifier base");
6244 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6248 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6249 "Location list begin address (%s)",
6250 list_head
->ll_symbol
);
6251 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6252 "Location list end address (%s)",
6253 list_head
->ll_symbol
);
6254 size
= size_of_locs (curr
->expr
);
6256 /* Output the block length for this list of location operations. */
6259 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6261 output_loc_sequence (curr
->expr
);
6264 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6265 "Location list terminator begin (%s)",
6266 list_head
->ll_symbol
);
6267 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6268 "Location list terminator end (%s)",
6269 list_head
->ll_symbol
);
6272 /* Output the DIE and its attributes. Called recursively to generate
6273 the definitions of each child DIE. */
6283 /* If someone in another CU might refer to us, set up a symbol for
6284 them to point to. */
6285 if (die
->die_symbol
)
6286 output_die_symbol (die
);
6288 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6289 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6291 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6293 const char *name
= dwarf_attr_name (a
->dw_attr
);
6295 switch (AT_class (a
))
6297 case dw_val_class_addr
:
6298 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6301 case dw_val_class_offset
:
6302 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6306 case dw_val_class_range_list
:
6308 char *p
= strchr (ranges_section_label
, '\0');
6310 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6311 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6317 case dw_val_class_loc
:
6318 size
= size_of_locs (AT_loc (a
));
6320 /* Output the block length for this list of location operations. */
6321 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6323 output_loc_sequence (AT_loc (a
));
6326 case dw_val_class_const
:
6327 /* ??? It would be slightly more efficient to use a scheme like is
6328 used for unsigned constants below, but gdb 4.x does not sign
6329 extend. Gdb 5.x does sign extend. */
6330 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6333 case dw_val_class_unsigned_const
:
6334 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6335 AT_unsigned (a
), "%s", name
);
6338 case dw_val_class_long_long
:
6340 unsigned HOST_WIDE_INT first
, second
;
6342 dw2_asm_output_data (1,
6343 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6346 if (WORDS_BIG_ENDIAN
)
6348 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6349 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6353 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6354 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6357 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6358 first
, "long long constant");
6359 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6364 case dw_val_class_float
:
6368 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6371 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6372 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6373 "fp constant word %u", i
);
6377 case dw_val_class_flag
:
6378 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6381 case dw_val_class_loc_list
:
6383 char *sym
= AT_loc_list (a
)->ll_symbol
;
6387 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6388 loc_section_label
, "%s", name
);
6392 case dw_val_class_die_ref
:
6393 if (AT_ref_external (a
))
6395 char *sym
= AT_ref (a
)->die_symbol
;
6399 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6401 else if (AT_ref (a
)->die_offset
== 0)
6404 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6408 case dw_val_class_fde_ref
:
6412 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6413 a
->dw_attr_val
.v
.val_fde_index
* 2);
6414 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6418 case dw_val_class_lbl_id
:
6419 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6422 case dw_val_class_lbl_offset
:
6423 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6426 case dw_val_class_str
:
6427 if (AT_string_form (a
) == DW_FORM_strp
)
6428 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6429 a
->dw_attr_val
.v
.val_str
->label
,
6430 "%s: \"%s\"", name
, AT_string (a
));
6432 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6440 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6443 /* Add null byte to terminate sibling list. */
6444 if (die
->die_child
!= NULL
)
6445 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6449 /* Output the compilation unit that appears at the beginning of the
6450 .debug_info section, and precedes the DIE descriptions. */
6453 output_compilation_unit_header ()
6455 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6456 "Length of Compilation Unit Info");
6457 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6458 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6459 "Offset Into Abbrev. Section");
6460 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6463 /* Output the compilation unit DIE and its children. */
6466 output_comp_unit (die
)
6469 const char *secname
;
6471 /* Even if there are no children of this DIE, we must output the information
6472 about the compilation unit. Otherwise, on an empty translation unit, we
6473 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6474 will then complain when examining the file. First mark all the DIEs in
6475 this CU so we know which get local refs. */
6478 build_abbrev_table (die
);
6480 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6481 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6482 calc_die_sizes (die
);
6484 if (die
->die_symbol
)
6486 char *tmp
= (char *) alloca (strlen (die
->die_symbol
) + 24);
6488 sprintf (tmp
, ".gnu.linkonce.wi.%s", die
->die_symbol
);
6490 die
->die_symbol
= NULL
;
6493 secname
= (const char *) DEBUG_INFO_SECTION
;
6495 /* Output debugging information. */
6496 named_section_flags (secname
, SECTION_DEBUG
);
6497 output_compilation_unit_header ();
6500 /* Leave the marks on the main CU, so we can check them in
6502 if (die
->die_symbol
)
6506 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6507 output of lang_hooks.decl_printable_name for C++ looks like
6508 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6511 dwarf2_name (decl
, scope
)
6515 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6518 /* Add a new entry to .debug_pubnames if appropriate. */
6521 add_pubname (decl
, die
)
6527 if (! TREE_PUBLIC (decl
))
6530 if (pubname_table_in_use
== pubname_table_allocated
)
6532 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6534 = (pubname_ref
) xrealloc (pubname_table
,
6535 (pubname_table_allocated
6536 * sizeof (pubname_entry
)));
6539 p
= &pubname_table
[pubname_table_in_use
++];
6541 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6544 /* Output the public names table used to speed up access to externally
6545 visible names. For now, only generate entries for externally
6546 visible procedures. */
6552 unsigned long pubnames_length
= size_of_pubnames ();
6554 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6555 "Length of Public Names Info");
6556 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6557 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6558 "Offset of Compilation Unit Info");
6559 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6560 "Compilation Unit Length");
6562 for (i
= 0; i
< pubname_table_in_use
; i
++)
6564 pubname_ref pub
= &pubname_table
[i
];
6566 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6567 if (pub
->die
->die_mark
== 0)
6570 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6573 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6576 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6579 /* Add a new entry to .debug_aranges if appropriate. */
6582 add_arange (decl
, die
)
6586 if (! DECL_SECTION_NAME (decl
))
6589 if (arange_table_in_use
== arange_table_allocated
)
6591 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6592 arange_table
= (dw_die_ref
*)
6593 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6596 arange_table
[arange_table_in_use
++] = die
;
6599 /* Output the information that goes into the .debug_aranges table.
6600 Namely, define the beginning and ending address range of the
6601 text section generated for this compilation unit. */
6607 unsigned long aranges_length
= size_of_aranges ();
6609 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6610 "Length of Address Ranges Info");
6611 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6612 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6613 "Offset of Compilation Unit Info");
6614 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6615 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6617 /* We need to align to twice the pointer size here. */
6618 if (DWARF_ARANGES_PAD_SIZE
)
6620 /* Pad using a 2 byte words so that padding is correct for any
6622 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6623 2 * DWARF2_ADDR_SIZE
);
6624 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6625 dw2_asm_output_data (2, 0, NULL
);
6628 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6629 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6630 text_section_label
, "Length");
6632 for (i
= 0; i
< arange_table_in_use
; i
++)
6634 dw_die_ref die
= arange_table
[i
];
6636 /* We shouldn't see aranges for DIEs outside of the main CU. */
6637 if (die
->die_mark
== 0)
6640 if (die
->die_tag
== DW_TAG_subprogram
)
6642 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6644 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6645 get_AT_low_pc (die
), "Length");
6649 /* A static variable; extract the symbol from DW_AT_location.
6650 Note that this code isn't currently hit, as we only emit
6651 aranges for functions (jason 9/23/99). */
6652 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
6653 dw_loc_descr_ref loc
;
6655 if (! a
|| AT_class (a
) != dw_val_class_loc
)
6659 if (loc
->dw_loc_opc
!= DW_OP_addr
)
6662 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
6663 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
6664 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
6665 get_AT_unsigned (die
, DW_AT_byte_size
),
6670 /* Output the terminator words. */
6671 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6672 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6675 /* Add a new entry to .debug_ranges. Return the offset at which it
6682 unsigned int in_use
= ranges_table_in_use
;
6684 if (in_use
== ranges_table_allocated
)
6686 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
6687 ranges_table
= (dw_ranges_ref
)
6688 xrealloc (ranges_table
, (ranges_table_allocated
6689 * sizeof (struct dw_ranges_struct
)));
6692 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
6693 ranges_table_in_use
= in_use
+ 1;
6695 return in_use
* 2 * DWARF2_ADDR_SIZE
;
6702 static const char *const start_fmt
= "Offset 0x%x";
6703 const char *fmt
= start_fmt
;
6705 for (i
= 0; i
< ranges_table_in_use
; i
++)
6707 int block_num
= ranges_table
[i
].block_num
;
6711 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6712 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
6714 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
6715 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
6717 /* If all code is in the text section, then the compilation
6718 unit base address defaults to DW_AT_low_pc, which is the
6719 base of the text section. */
6720 if (separate_line_info_table_in_use
== 0)
6722 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
6724 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6725 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
6726 text_section_label
, NULL
);
6729 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6730 compilation unit base address to zero, which allows us to
6731 use absolute addresses, and not worry about whether the
6732 target supports cross-section arithmetic. */
6735 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
6736 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
6737 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
6744 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6745 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
6751 /* Data structure containing information about input files. */
6754 char *path
; /* Complete file name. */
6755 char *fname
; /* File name part. */
6756 int length
; /* Length of entire string. */
6757 int file_idx
; /* Index in input file table. */
6758 int dir_idx
; /* Index in directory table. */
6761 /* Data structure containing information about directories with source
6765 char *path
; /* Path including directory name. */
6766 int length
; /* Path length. */
6767 int prefix
; /* Index of directory entry which is a prefix. */
6768 int count
; /* Number of files in this directory. */
6769 int dir_idx
; /* Index of directory used as base. */
6770 int used
; /* Used in the end? */
6773 /* Callback function for file_info comparison. We sort by looking at
6774 the directories in the path. */
6777 file_info_cmp (p1
, p2
)
6781 const struct file_info
*s1
= p1
;
6782 const struct file_info
*s2
= p2
;
6786 /* Take care of file names without directories. We need to make sure that
6787 we return consistent values to qsort since some will get confused if
6788 we return the same value when identical operands are passed in opposite
6789 orders. So if neither has a directory, return 0 and otherwise return
6790 1 or -1 depending on which one has the directory. */
6791 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
6792 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
6794 cp1
= (unsigned char *) s1
->path
;
6795 cp2
= (unsigned char *) s2
->path
;
6801 /* Reached the end of the first path? If so, handle like above. */
6802 if ((cp1
== (unsigned char *) s1
->fname
)
6803 || (cp2
== (unsigned char *) s2
->fname
))
6804 return ((cp2
== (unsigned char *) s2
->fname
)
6805 - (cp1
== (unsigned char *) s1
->fname
));
6807 /* Character of current path component the same? */
6808 else if (*cp1
!= *cp2
)
6813 /* Output the directory table and the file name table. We try to minimize
6814 the total amount of memory needed. A heuristic is used to avoid large
6815 slowdowns with many input files. */
6818 output_file_names ()
6820 struct file_info
*files
;
6821 struct dir_info
*dirs
;
6830 /* Allocate the various arrays we need. */
6831 files
= (struct file_info
*) alloca (file_table
.in_use
6832 * sizeof (struct file_info
));
6833 dirs
= (struct dir_info
*) alloca (file_table
.in_use
6834 * sizeof (struct dir_info
));
6836 /* Sort the file names. */
6837 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6841 /* Skip all leading "./". */
6842 f
= file_table
.table
[i
];
6843 while (f
[0] == '.' && f
[1] == '/')
6846 /* Create a new array entry. */
6848 files
[i
].length
= strlen (f
);
6849 files
[i
].file_idx
= i
;
6851 /* Search for the file name part. */
6852 f
= strrchr (f
, '/');
6853 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
6856 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
6858 /* Find all the different directories used. */
6859 dirs
[0].path
= files
[1].path
;
6860 dirs
[0].length
= files
[1].fname
- files
[1].path
;
6861 dirs
[0].prefix
= -1;
6863 dirs
[0].dir_idx
= 0;
6865 files
[1].dir_idx
= 0;
6868 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
6869 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
6870 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
6871 dirs
[ndirs
- 1].length
) == 0)
6873 /* Same directory as last entry. */
6874 files
[i
].dir_idx
= ndirs
- 1;
6875 ++dirs
[ndirs
- 1].count
;
6881 /* This is a new directory. */
6882 dirs
[ndirs
].path
= files
[i
].path
;
6883 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
6884 dirs
[ndirs
].count
= 1;
6885 dirs
[ndirs
].dir_idx
= ndirs
;
6886 dirs
[ndirs
].used
= 0;
6887 files
[i
].dir_idx
= ndirs
;
6889 /* Search for a prefix. */
6890 dirs
[ndirs
].prefix
= -1;
6891 for (j
= 0; j
< ndirs
; j
++)
6892 if (dirs
[j
].length
< dirs
[ndirs
].length
6893 && dirs
[j
].length
> 1
6894 && (dirs
[ndirs
].prefix
== -1
6895 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
6896 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
6897 dirs
[ndirs
].prefix
= j
;
6902 /* Now to the actual work. We have to find a subset of the directories which
6903 allow expressing the file name using references to the directory table
6904 with the least amount of characters. We do not do an exhaustive search
6905 where we would have to check out every combination of every single
6906 possible prefix. Instead we use a heuristic which provides nearly optimal
6907 results in most cases and never is much off. */
6908 saved
= (int *) alloca (ndirs
* sizeof (int));
6909 savehere
= (int *) alloca (ndirs
* sizeof (int));
6911 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
6912 for (i
= 0; i
< ndirs
; i
++)
6917 /* We can always save some space for the current directory. But this
6918 does not mean it will be enough to justify adding the directory. */
6919 savehere
[i
] = dirs
[i
].length
;
6920 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
6922 for (j
= i
+ 1; j
< ndirs
; j
++)
6925 if (saved
[j
] < dirs
[i
].length
)
6927 /* Determine whether the dirs[i] path is a prefix of the
6932 while (k
!= -1 && k
!= i
)
6937 /* Yes it is. We can possibly safe some memory but
6938 writing the filenames in dirs[j] relative to
6940 savehere
[j
] = dirs
[i
].length
;
6941 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
6946 /* Check whether we can safe enough to justify adding the dirs[i]
6948 if (total
> dirs
[i
].length
+ 1)
6950 /* It's worthwhile adding. */
6951 for (j
= i
; j
< ndirs
; j
++)
6952 if (savehere
[j
] > 0)
6954 /* Remember how much we saved for this directory so far. */
6955 saved
[j
] = savehere
[j
];
6957 /* Remember the prefix directory. */
6958 dirs
[j
].dir_idx
= i
;
6963 /* We have to emit them in the order they appear in the file_table array
6964 since the index is used in the debug info generation. To do this
6965 efficiently we generate a back-mapping of the indices first. */
6966 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
6967 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
6969 backmap
[files
[i
].file_idx
] = i
;
6971 /* Mark this directory as used. */
6972 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
6975 /* That was it. We are ready to emit the information. First emit the
6976 directory name table. We have to make sure the first actually emitted
6977 directory name has index one; zero is reserved for the current working
6978 directory. Make sure we do not confuse these indices with the one for the
6979 constructed table (even though most of the time they are identical). */
6981 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
6982 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
6983 if (dirs
[i
].used
!= 0)
6985 dirs
[i
].used
= idx
++;
6986 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
6987 "Directory Entry: 0x%x", dirs
[i
].used
);
6990 dw2_asm_output_data (1, 0, "End directory table");
6992 /* Correct the index for the current working directory entry if it
6994 if (idx_offset
== 0)
6997 /* Now write all the file names. */
6998 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7000 int file_idx
= backmap
[i
];
7001 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7003 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7004 "File Entry: 0x%x", i
);
7006 /* Include directory index. */
7007 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7009 /* Modification time. */
7010 dw2_asm_output_data_uleb128 (0, NULL
);
7012 /* File length in bytes. */
7013 dw2_asm_output_data_uleb128 (0, NULL
);
7016 dw2_asm_output_data (1, 0, "End file name table");
7020 /* Output the source line number correspondence information. This
7021 information goes into the .debug_line section. */
7026 char l1
[20], l2
[20], p1
[20], p2
[20];
7027 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7028 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7031 unsigned long lt_index
;
7032 unsigned long current_line
;
7035 unsigned long current_file
;
7036 unsigned long function
;
7038 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7039 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7040 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7041 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7043 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7044 "Length of Source Line Info");
7045 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7047 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7048 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7049 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7051 /* Define the architecture-dependent minimum instruction length (in
7052 bytes). In this implementation of DWARF, this field is used for
7053 information purposes only. Since GCC generates assembly language,
7054 we have no a priori knowledge of how many instruction bytes are
7055 generated for each source line, and therefore can use only the
7056 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7057 commands. Accordingly, we fix this as `1', which is "correct
7058 enough" for all architectures, and don't let the target override. */
7059 dw2_asm_output_data (1, 1,
7060 "Minimum Instruction Length");
7062 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7063 "Default is_stmt_start flag");
7064 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7065 "Line Base Value (Special Opcodes)");
7066 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7067 "Line Range Value (Special Opcodes)");
7068 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7069 "Special Opcode Base");
7071 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7075 case DW_LNS_advance_pc
:
7076 case DW_LNS_advance_line
:
7077 case DW_LNS_set_file
:
7078 case DW_LNS_set_column
:
7079 case DW_LNS_fixed_advance_pc
:
7087 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7091 /* Write out the information about the files we use. */
7092 output_file_names ();
7093 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7095 /* We used to set the address register to the first location in the text
7096 section here, but that didn't accomplish anything since we already
7097 have a line note for the opening brace of the first function. */
7099 /* Generate the line number to PC correspondence table, encoded as
7100 a series of state machine operations. */
7103 strcpy (prev_line_label
, text_section_label
);
7104 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7106 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7109 /* Disable this optimization for now; GDB wants to see two line notes
7110 at the beginning of a function so it can find the end of the
7113 /* Don't emit anything for redundant notes. Just updating the
7114 address doesn't accomplish anything, because we already assume
7115 that anything after the last address is this line. */
7116 if (line_info
->dw_line_num
== current_line
7117 && line_info
->dw_file_num
== current_file
)
7121 /* Emit debug info for the address of the current line.
7123 Unfortunately, we have little choice here currently, and must always
7124 use the most general form. GCC does not know the address delta
7125 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7126 attributes which will give an upper bound on the address range. We
7127 could perhaps use length attributes to determine when it is safe to
7128 use DW_LNS_fixed_advance_pc. */
7130 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7133 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7134 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7135 "DW_LNS_fixed_advance_pc");
7136 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7140 /* This can handle any delta. This takes
7141 4+DWARF2_ADDR_SIZE bytes. */
7142 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7143 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7144 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7145 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7148 strcpy (prev_line_label
, line_label
);
7150 /* Emit debug info for the source file of the current line, if
7151 different from the previous line. */
7152 if (line_info
->dw_file_num
!= current_file
)
7154 current_file
= line_info
->dw_file_num
;
7155 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7156 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7157 file_table
.table
[current_file
]);
7160 /* Emit debug info for the current line number, choosing the encoding
7161 that uses the least amount of space. */
7162 if (line_info
->dw_line_num
!= current_line
)
7164 line_offset
= line_info
->dw_line_num
- current_line
;
7165 line_delta
= line_offset
- DWARF_LINE_BASE
;
7166 current_line
= line_info
->dw_line_num
;
7167 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7168 /* This can handle deltas from -10 to 234, using the current
7169 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7171 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7172 "line %lu", current_line
);
7175 /* This can handle any delta. This takes at least 4 bytes,
7176 depending on the value being encoded. */
7177 dw2_asm_output_data (1, DW_LNS_advance_line
,
7178 "advance to line %lu", current_line
);
7179 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7180 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7184 /* We still need to start a new row, so output a copy insn. */
7185 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7188 /* Emit debug info for the address of the end of the function. */
7191 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7192 "DW_LNS_fixed_advance_pc");
7193 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7197 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7198 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7199 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7200 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7203 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7204 dw2_asm_output_data_uleb128 (1, NULL
);
7205 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7210 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7212 dw_separate_line_info_ref line_info
7213 = &separate_line_info_table
[lt_index
];
7216 /* Don't emit anything for redundant notes. */
7217 if (line_info
->dw_line_num
== current_line
7218 && line_info
->dw_file_num
== current_file
7219 && line_info
->function
== function
)
7223 /* Emit debug info for the address of the current line. If this is
7224 a new function, or the first line of a function, then we need
7225 to handle it differently. */
7226 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7228 if (function
!= line_info
->function
)
7230 function
= line_info
->function
;
7232 /* Set the address register to the first line in the function */
7233 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7234 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7235 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7236 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7240 /* ??? See the DW_LNS_advance_pc comment above. */
7243 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7244 "DW_LNS_fixed_advance_pc");
7245 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7249 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7250 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7251 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7252 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7256 strcpy (prev_line_label
, line_label
);
7258 /* Emit debug info for the source file of the current line, if
7259 different from the previous line. */
7260 if (line_info
->dw_file_num
!= current_file
)
7262 current_file
= line_info
->dw_file_num
;
7263 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7264 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7265 file_table
.table
[current_file
]);
7268 /* Emit debug info for the current line number, choosing the encoding
7269 that uses the least amount of space. */
7270 if (line_info
->dw_line_num
!= current_line
)
7272 line_offset
= line_info
->dw_line_num
- current_line
;
7273 line_delta
= line_offset
- DWARF_LINE_BASE
;
7274 current_line
= line_info
->dw_line_num
;
7275 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7276 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7277 "line %lu", current_line
);
7280 dw2_asm_output_data (1, DW_LNS_advance_line
,
7281 "advance to line %lu", current_line
);
7282 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7283 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7287 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7295 /* If we're done with a function, end its sequence. */
7296 if (lt_index
== separate_line_info_table_in_use
7297 || separate_line_info_table
[lt_index
].function
!= function
)
7302 /* Emit debug info for the address of the end of the function. */
7303 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7306 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7307 "DW_LNS_fixed_advance_pc");
7308 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7312 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7313 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7314 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7315 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7318 /* Output the marker for the end of this sequence. */
7319 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7320 dw2_asm_output_data_uleb128 (1, NULL
);
7321 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7325 /* Output the marker for the end of the line number info. */
7326 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7329 /* Given a pointer to a tree node for some base type, return a pointer to
7330 a DIE that describes the given type.
7332 This routine must only be called for GCC type nodes that correspond to
7333 Dwarf base (fundamental) types. */
7336 base_type_die (type
)
7339 dw_die_ref base_type_result
;
7340 const char *type_name
;
7341 enum dwarf_type encoding
;
7342 tree name
= TYPE_NAME (type
);
7344 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7349 if (TREE_CODE (name
) == TYPE_DECL
)
7350 name
= DECL_NAME (name
);
7352 type_name
= IDENTIFIER_POINTER (name
);
7355 type_name
= "__unknown__";
7357 switch (TREE_CODE (type
))
7360 /* Carefully distinguish the C character types, without messing
7361 up if the language is not C. Note that we check only for the names
7362 that contain spaces; other names might occur by coincidence in other
7364 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7365 && (type
== char_type_node
7366 || ! strcmp (type_name
, "signed char")
7367 || ! strcmp (type_name
, "unsigned char"))))
7369 if (TREE_UNSIGNED (type
))
7370 encoding
= DW_ATE_unsigned
;
7372 encoding
= DW_ATE_signed
;
7375 /* else fall through. */
7378 /* GNU Pascal/Ada CHAR type. Not used in C. */
7379 if (TREE_UNSIGNED (type
))
7380 encoding
= DW_ATE_unsigned_char
;
7382 encoding
= DW_ATE_signed_char
;
7386 encoding
= DW_ATE_float
;
7389 /* Dwarf2 doesn't know anything about complex ints, so use
7390 a user defined type for it. */
7392 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7393 encoding
= DW_ATE_complex_float
;
7395 encoding
= DW_ATE_lo_user
;
7399 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7400 encoding
= DW_ATE_boolean
;
7404 /* No other TREE_CODEs are Dwarf fundamental types. */
7408 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7409 if (demangle_name_func
)
7410 type_name
= (*demangle_name_func
) (type_name
);
7412 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7413 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7414 int_size_in_bytes (type
));
7415 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7417 return base_type_result
;
7420 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7421 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7422 a given type is generally the same as the given type, except that if the
7423 given type is a pointer or reference type, then the root type of the given
7424 type is the root type of the "basis" type for the pointer or reference
7425 type. (This definition of the "root" type is recursive.) Also, the root
7426 type of a `const' qualified type or a `volatile' qualified type is the
7427 root type of the given type without the qualifiers. */
7433 if (TREE_CODE (type
) == ERROR_MARK
)
7434 return error_mark_node
;
7436 switch (TREE_CODE (type
))
7439 return error_mark_node
;
7442 case REFERENCE_TYPE
:
7443 return type_main_variant (root_type (TREE_TYPE (type
)));
7446 return type_main_variant (type
);
7450 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7451 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7457 switch (TREE_CODE (type
))
7472 case QUAL_UNION_TYPE
:
7477 case REFERENCE_TYPE
:
7491 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7492 entry that chains various modifiers in front of the given type. */
7495 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7498 int is_volatile_type
;
7499 dw_die_ref context_die
;
7501 enum tree_code code
= TREE_CODE (type
);
7502 dw_die_ref mod_type_die
= NULL
;
7503 dw_die_ref sub_die
= NULL
;
7504 tree item_type
= NULL
;
7506 if (code
!= ERROR_MARK
)
7508 tree qualified_type
;
7510 /* See if we already have the appropriately qualified variant of
7513 = get_qualified_type (type
,
7514 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7516 ? TYPE_QUAL_VOLATILE
: 0)));
7518 /* If we do, then we can just use its DIE, if it exists. */
7521 mod_type_die
= lookup_type_die (qualified_type
);
7523 return mod_type_die
;
7526 /* Handle C typedef types. */
7527 if (qualified_type
&& TYPE_NAME (qualified_type
)
7528 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7529 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7531 tree type_name
= TYPE_NAME (qualified_type
);
7532 tree dtype
= TREE_TYPE (type_name
);
7534 if (qualified_type
== dtype
)
7536 /* For a named type, use the typedef. */
7537 gen_type_die (qualified_type
, context_die
);
7538 mod_type_die
= lookup_type_die (qualified_type
);
7540 else if (is_const_type
< TYPE_READONLY (dtype
)
7541 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7542 /* cv-unqualified version of named type. Just use the unnamed
7543 type to which it refers. */
7545 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7546 is_const_type
, is_volatile_type
,
7549 /* Else cv-qualified version of named type; fall through. */
7555 else if (is_const_type
)
7557 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7558 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7560 else if (is_volatile_type
)
7562 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7563 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7565 else if (code
== POINTER_TYPE
)
7567 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7568 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7570 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7572 item_type
= TREE_TYPE (type
);
7574 else if (code
== REFERENCE_TYPE
)
7576 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7577 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7579 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7581 item_type
= TREE_TYPE (type
);
7583 else if (is_base_type (type
))
7584 mod_type_die
= base_type_die (type
);
7587 gen_type_die (type
, context_die
);
7589 /* We have to get the type_main_variant here (and pass that to the
7590 `lookup_type_die' routine) because the ..._TYPE node we have
7591 might simply be a *copy* of some original type node (where the
7592 copy was created to help us keep track of typedef names) and
7593 that copy might have a different TYPE_UID from the original
7595 if (TREE_CODE (type
) != VECTOR_TYPE
)
7596 mod_type_die
= lookup_type_die (type_main_variant (type
));
7598 /* Vectors have the debugging information in the type,
7599 not the main variant. */
7600 mod_type_die
= lookup_type_die (type
);
7601 if (mod_type_die
== NULL
)
7605 /* We want to equate the qualified type to the die below. */
7607 type
= qualified_type
;
7610 equate_type_number_to_die (type
, mod_type_die
);
7612 /* We must do this after the equate_type_number_to_die call, in case
7613 this is a recursive type. This ensures that the modified_type_die
7614 recursion will terminate even if the type is recursive. Recursive
7615 types are possible in Ada. */
7616 sub_die
= modified_type_die (item_type
,
7617 TYPE_READONLY (item_type
),
7618 TYPE_VOLATILE (item_type
),
7621 if (sub_die
!= NULL
)
7622 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7624 return mod_type_die
;
7627 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7628 an enumerated type. */
7634 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7637 /* Return the register number described by a given RTL node. */
7643 unsigned regno
= REGNO (rtl
);
7645 if (regno
>= FIRST_PSEUDO_REGISTER
)
7648 return DBX_REGISTER_NUMBER (regno
);
7651 /* Return a location descriptor that designates a machine register or
7652 zero if there is no such. */
7654 static dw_loc_descr_ref
7655 reg_loc_descriptor (rtl
)
7658 dw_loc_descr_ref loc_result
= NULL
;
7661 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
7664 reg
= reg_number (rtl
);
7666 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
7668 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
7673 /* Return a location descriptor that designates a constant. */
7675 static dw_loc_descr_ref
7676 int_loc_descriptor (i
)
7679 enum dwarf_location_atom op
;
7681 /* Pick the smallest representation of a constant, rather than just
7682 defaulting to the LEB encoding. */
7686 op
= DW_OP_lit0
+ i
;
7689 else if (i
<= 0xffff)
7691 else if (HOST_BITS_PER_WIDE_INT
== 32
7701 else if (i
>= -0x8000)
7703 else if (HOST_BITS_PER_WIDE_INT
== 32
7704 || i
>= -0x80000000)
7710 return new_loc_descr (op
, i
, 0);
7713 /* Return a location descriptor that designates a base+offset location. */
7715 static dw_loc_descr_ref
7716 based_loc_descr (reg
, offset
)
7720 dw_loc_descr_ref loc_result
;
7721 /* For the "frame base", we use the frame pointer or stack pointer
7722 registers, since the RTL for local variables is relative to one of
7724 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
7725 ? HARD_FRAME_POINTER_REGNUM
7726 : STACK_POINTER_REGNUM
);
7729 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
7731 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
7733 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
7738 /* Return true if this RTL expression describes a base+offset calculation. */
7744 return (GET_CODE (rtl
) == PLUS
7745 && ((GET_CODE (XEXP (rtl
, 0)) == REG
7746 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
7747 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
7750 /* The following routine converts the RTL for a variable or parameter
7751 (resident in memory) into an equivalent Dwarf representation of a
7752 mechanism for getting the address of that same variable onto the top of a
7753 hypothetical "address evaluation" stack.
7755 When creating memory location descriptors, we are effectively transforming
7756 the RTL for a memory-resident object into its Dwarf postfix expression
7757 equivalent. This routine recursively descends an RTL tree, turning
7758 it into Dwarf postfix code as it goes.
7760 MODE is the mode of the memory reference, needed to handle some
7761 autoincrement addressing modes.
7763 Return 0 if we can't represent the location. */
7765 static dw_loc_descr_ref
7766 mem_loc_descriptor (rtl
, mode
)
7768 enum machine_mode mode
;
7770 dw_loc_descr_ref mem_loc_result
= NULL
;
7772 /* Note that for a dynamically sized array, the location we will generate a
7773 description of here will be the lowest numbered location which is
7774 actually within the array. That's *not* necessarily the same as the
7775 zeroth element of the array. */
7777 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7778 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
7781 switch (GET_CODE (rtl
))
7786 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7787 just fall into the SUBREG code. */
7789 /* ... fall through ... */
7792 /* The case of a subreg may arise when we have a local (register)
7793 variable or a formal (register) parameter which doesn't quite fill
7794 up an entire register. For now, just assume that it is
7795 legitimate to make the Dwarf info refer to the whole register which
7796 contains the given subreg. */
7797 rtl
= SUBREG_REG (rtl
);
7799 /* ... fall through ... */
7802 /* Whenever a register number forms a part of the description of the
7803 method for calculating the (dynamic) address of a memory resident
7804 object, DWARF rules require the register number be referred to as
7805 a "base register". This distinction is not based in any way upon
7806 what category of register the hardware believes the given register
7807 belongs to. This is strictly DWARF terminology we're dealing with
7808 here. Note that in cases where the location of a memory-resident
7809 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7810 OP_CONST (0)) the actual DWARF location descriptor that we generate
7811 may just be OP_BASEREG (basereg). This may look deceptively like
7812 the object in question was allocated to a register (rather than in
7813 memory) so DWARF consumers need to be aware of the subtle
7814 distinction between OP_REG and OP_BASEREG. */
7815 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
7816 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
7820 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
7821 if (mem_loc_result
!= 0)
7822 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
7826 /* Some ports can transform a symbol ref into a label ref, because
7827 the symbol ref is too far away and has to be dumped into a constant
7831 /* Alternatively, the symbol in the constant pool might be referenced
7832 by a different symbol. */
7833 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
7836 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
7838 if (GET_CODE (tmp
) == SYMBOL_REF
)
7841 if (CONSTANT_POOL_ADDRESS_P (tmp
))
7842 get_pool_constant_mark (tmp
, &marked
);
7847 /* If all references to this pool constant were optimized away,
7848 it was not output and thus we can't represent it.
7849 FIXME: might try to use DW_OP_const_value here, though
7850 DW_OP_piece complicates it. */
7855 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
7856 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
7857 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
7858 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
7862 /* Extract the PLUS expression nested inside and fall into
7864 rtl
= XEXP (rtl
, 1);
7869 /* Turn these into a PLUS expression and fall into the PLUS code
7871 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
7872 GEN_INT (GET_CODE (rtl
) == PRE_INC
7873 ? GET_MODE_UNIT_SIZE (mode
)
7874 : -GET_MODE_UNIT_SIZE (mode
)));
7876 /* ... fall through ... */
7880 if (is_based_loc (rtl
))
7881 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
7882 INTVAL (XEXP (rtl
, 1)));
7885 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7886 if (mem_loc_result
== 0)
7889 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
7890 && INTVAL (XEXP (rtl
, 1)) >= 0)
7891 add_loc_descr (&mem_loc_result
,
7892 new_loc_descr (DW_OP_plus_uconst
,
7893 INTVAL (XEXP (rtl
, 1)), 0));
7896 add_loc_descr (&mem_loc_result
,
7897 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
7898 add_loc_descr (&mem_loc_result
,
7899 new_loc_descr (DW_OP_plus
, 0, 0));
7906 /* If a pseudo-reg is optimized away, it is possible for it to
7907 be replaced with a MEM containing a multiply. */
7908 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
7909 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
7911 if (op0
== 0 || op1
== 0)
7914 mem_loc_result
= op0
;
7915 add_loc_descr (&mem_loc_result
, op1
);
7916 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
7921 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
7925 /* If this is a MEM, return its address. Otherwise, we can't
7927 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
7928 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
7936 return mem_loc_result
;
7939 /* Return a descriptor that describes the concatenation of two locations.
7940 This is typically a complex variable. */
7942 static dw_loc_descr_ref
7943 concat_loc_descriptor (x0
, x1
)
7946 dw_loc_descr_ref cc_loc_result
= NULL
;
7947 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
7948 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
7950 if (x0_ref
== 0 || x1_ref
== 0)
7953 cc_loc_result
= x0_ref
;
7954 add_loc_descr (&cc_loc_result
,
7955 new_loc_descr (DW_OP_piece
,
7956 GET_MODE_SIZE (GET_MODE (x0
)), 0));
7958 add_loc_descr (&cc_loc_result
, x1_ref
);
7959 add_loc_descr (&cc_loc_result
,
7960 new_loc_descr (DW_OP_piece
,
7961 GET_MODE_SIZE (GET_MODE (x1
)), 0));
7963 return cc_loc_result
;
7966 /* Output a proper Dwarf location descriptor for a variable or parameter
7967 which is either allocated in a register or in a memory location. For a
7968 register, we just generate an OP_REG and the register number. For a
7969 memory location we provide a Dwarf postfix expression describing how to
7970 generate the (dynamic) address of the object onto the address stack.
7972 If we don't know how to describe it, return 0. */
7974 static dw_loc_descr_ref
7975 loc_descriptor (rtl
)
7978 dw_loc_descr_ref loc_result
= NULL
;
7980 switch (GET_CODE (rtl
))
7983 /* The case of a subreg may arise when we have a local (register)
7984 variable or a formal (register) parameter which doesn't quite fill
7985 up an entire register. For now, just assume that it is
7986 legitimate to make the Dwarf info refer to the whole register which
7987 contains the given subreg. */
7988 rtl
= SUBREG_REG (rtl
);
7990 /* ... fall through ... */
7993 loc_result
= reg_loc_descriptor (rtl
);
7997 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8001 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8011 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8012 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8013 looking for an address. Otherwise, we return a value. If we can't make a
8014 descriptor, return 0. */
8016 static dw_loc_descr_ref
8017 loc_descriptor_from_tree (loc
, addressp
)
8021 dw_loc_descr_ref ret
, ret1
;
8023 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
8024 enum dwarf_location_atom op
;
8026 /* ??? Most of the time we do not take proper care for sign/zero
8027 extending the values properly. Hopefully this won't be a real
8030 switch (TREE_CODE (loc
))
8035 case WITH_RECORD_EXPR
:
8036 case PLACEHOLDER_EXPR
:
8037 /* This case involves extracting fields from an object to determine the
8038 position of other fields. We don't try to encode this here. The
8039 only user of this is Ada, which encodes the needed information using
8040 the names of types. */
8047 /* We can support this only if we can look through conversions and
8048 find an INDIRECT_EXPR. */
8049 for (loc
= TREE_OPERAND (loc
, 0);
8050 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8051 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8052 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8053 || TREE_CODE (loc
) == SAVE_EXPR
;
8054 loc
= TREE_OPERAND (loc
, 0))
8057 return (TREE_CODE (loc
) == INDIRECT_REF
8058 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8064 rtx rtl
= rtl_for_decl_location (loc
);
8066 if (rtl
== NULL_RTX
)
8068 else if (CONSTANT_P (rtl
))
8070 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8071 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8072 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8077 enum machine_mode mode
= GET_MODE (rtl
);
8079 if (GET_CODE (rtl
) == MEM
)
8082 rtl
= XEXP (rtl
, 0);
8085 ret
= mem_loc_descriptor (rtl
, mode
);
8091 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8096 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8100 case NON_LVALUE_EXPR
:
8101 case VIEW_CONVERT_EXPR
:
8103 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8108 case ARRAY_RANGE_REF
:
8111 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8112 enum machine_mode mode
;
8115 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8116 &unsignedp
, &volatilep
);
8121 ret
= loc_descriptor_from_tree (obj
, 1);
8123 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8126 if (offset
!= NULL_TREE
)
8128 /* Variable offset. */
8129 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8130 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8136 bytepos
= bitpos
/ BITS_PER_UNIT
;
8138 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8139 else if (bytepos
< 0)
8141 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8142 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8148 if (host_integerp (loc
, 0))
8149 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8154 case TRUTH_AND_EXPR
:
8155 case TRUTH_ANDIF_EXPR
:
8160 case TRUTH_XOR_EXPR
:
8166 case TRUTH_ORIF_EXPR
:
8171 case TRUNC_DIV_EXPR
:
8179 case TRUNC_MOD_EXPR
:
8192 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8196 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8197 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8199 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8203 add_loc_descr (&ret
,
8204 new_loc_descr (DW_OP_plus_uconst
,
8205 tree_low_cst (TREE_OPERAND (loc
, 1),
8215 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8222 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8229 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8236 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8251 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8252 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8253 if (ret
== 0 || ret1
== 0)
8256 add_loc_descr (&ret
, ret1
);
8257 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8260 case TRUTH_NOT_EXPR
:
8274 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8278 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8282 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8283 build (LT_EXPR
, integer_type_node
,
8284 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8285 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8287 /* ... fall through ... */
8291 dw_loc_descr_ref lhs
8292 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8293 dw_loc_descr_ref rhs
8294 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8295 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8297 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8298 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8301 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8302 add_loc_descr (&ret
, bra_node
);
8304 add_loc_descr (&ret
, rhs
);
8305 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8306 add_loc_descr (&ret
, jump_node
);
8308 add_loc_descr (&ret
, lhs
);
8309 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8310 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8312 /* ??? Need a node to point the skip at. Use a nop. */
8313 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8314 add_loc_descr (&ret
, tmp
);
8315 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8316 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8324 /* Show if we can't fill the request for an address. */
8325 if (addressp
&& indirect_p
== 0)
8328 /* If we've got an address and don't want one, dereference. */
8329 if (!addressp
&& indirect_p
> 0)
8331 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8333 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8335 else if (size
== DWARF2_ADDR_SIZE
)
8338 op
= DW_OP_deref_size
;
8340 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8346 /* Given a value, round it up to the lowest multiple of `boundary'
8347 which is not less than the value itself. */
8349 static inline HOST_WIDE_INT
8350 ceiling (value
, boundary
)
8351 HOST_WIDE_INT value
;
8352 unsigned int boundary
;
8354 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8357 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8358 pointer to the declared type for the relevant field variable, or return
8359 `integer_type_node' if the given node turns out to be an
8368 if (TREE_CODE (decl
) == ERROR_MARK
)
8369 return integer_type_node
;
8371 type
= DECL_BIT_FIELD_TYPE (decl
);
8372 if (type
== NULL_TREE
)
8373 type
= TREE_TYPE (decl
);
8378 /* Given a pointer to a tree node, return the alignment in bits for
8379 it, or else return BITS_PER_WORD if the node actually turns out to
8380 be an ERROR_MARK node. */
8382 static inline unsigned
8383 simple_type_align_in_bits (type
)
8386 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8389 static inline unsigned
8390 simple_decl_align_in_bits (decl
)
8393 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8396 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8397 node, return the size in bits for the type if it is a constant, or else
8398 return the alignment for the type if the type's size is not constant, or
8399 else return BITS_PER_WORD if the type actually turns out to be an
8402 static inline unsigned HOST_WIDE_INT
8403 simple_type_size_in_bits (type
)
8407 if (TREE_CODE (type
) == ERROR_MARK
)
8408 return BITS_PER_WORD
;
8409 else if (TYPE_SIZE (type
) == NULL_TREE
)
8411 else if (host_integerp (TYPE_SIZE (type
), 1))
8412 return tree_low_cst (TYPE_SIZE (type
), 1);
8414 return TYPE_ALIGN (type
);
8417 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8418 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8419 or return 0 if we are unable to determine what that offset is, either
8420 because the argument turns out to be a pointer to an ERROR_MARK node, or
8421 because the offset is actually variable. (We can't handle the latter case
8424 static HOST_WIDE_INT
8425 field_byte_offset (decl
)
8428 unsigned int type_align_in_bits
;
8429 unsigned int decl_align_in_bits
;
8430 unsigned HOST_WIDE_INT type_size_in_bits
;
8431 HOST_WIDE_INT object_offset_in_bits
;
8433 tree field_size_tree
;
8434 HOST_WIDE_INT bitpos_int
;
8435 HOST_WIDE_INT deepest_bitpos
;
8436 unsigned HOST_WIDE_INT field_size_in_bits
;
8438 if (TREE_CODE (decl
) == ERROR_MARK
)
8440 else if (TREE_CODE (decl
) != FIELD_DECL
)
8443 type
= field_type (decl
);
8444 field_size_tree
= DECL_SIZE (decl
);
8446 /* The size could be unspecified if there was an error, or for
8447 a flexible array member. */
8448 if (! field_size_tree
)
8449 field_size_tree
= bitsize_zero_node
;
8451 /* We cannot yet cope with fields whose positions are variable, so
8452 for now, when we see such things, we simply return 0. Someday, we may
8453 be able to handle such cases, but it will be damn difficult. */
8454 if (! host_integerp (bit_position (decl
), 0))
8457 bitpos_int
= int_bit_position (decl
);
8459 /* If we don't know the size of the field, pretend it's a full word. */
8460 if (host_integerp (field_size_tree
, 1))
8461 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8463 field_size_in_bits
= BITS_PER_WORD
;
8465 type_size_in_bits
= simple_type_size_in_bits (type
);
8466 type_align_in_bits
= simple_type_align_in_bits (type
);
8467 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8469 /* The GCC front-end doesn't make any attempt to keep track of the starting
8470 bit offset (relative to the start of the containing structure type) of the
8471 hypothetical "containing object" for a bit-field. Thus, when computing
8472 the byte offset value for the start of the "containing object" of a
8473 bit-field, we must deduce this information on our own. This can be rather
8474 tricky to do in some cases. For example, handling the following structure
8475 type definition when compiling for an i386/i486 target (which only aligns
8476 long long's to 32-bit boundaries) can be very tricky:
8478 struct S { int field1; long long field2:31; };
8480 Fortunately, there is a simple rule-of-thumb which can be used in such
8481 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8482 structure shown above. It decides to do this based upon one simple rule
8483 for bit-field allocation. GCC allocates each "containing object" for each
8484 bit-field at the first (i.e. lowest addressed) legitimate alignment
8485 boundary (based upon the required minimum alignment for the declared type
8486 of the field) which it can possibly use, subject to the condition that
8487 there is still enough available space remaining in the containing object
8488 (when allocated at the selected point) to fully accommodate all of the
8489 bits of the bit-field itself.
8491 This simple rule makes it obvious why GCC allocates 8 bytes for each
8492 object of the structure type shown above. When looking for a place to
8493 allocate the "containing object" for `field2', the compiler simply tries
8494 to allocate a 64-bit "containing object" at each successive 32-bit
8495 boundary (starting at zero) until it finds a place to allocate that 64-
8496 bit field such that at least 31 contiguous (and previously unallocated)
8497 bits remain within that selected 64 bit field. (As it turns out, for the
8498 example above, the compiler finds it is OK to allocate the "containing
8499 object" 64-bit field at bit-offset zero within the structure type.)
8501 Here we attempt to work backwards from the limited set of facts we're
8502 given, and we try to deduce from those facts, where GCC must have believed
8503 that the containing object started (within the structure type). The value
8504 we deduce is then used (by the callers of this routine) to generate
8505 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8506 and, in the case of DW_AT_location, regular fields as well). */
8508 /* Figure out the bit-distance from the start of the structure to the
8509 "deepest" bit of the bit-field. */
8510 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8512 /* This is the tricky part. Use some fancy footwork to deduce where the
8513 lowest addressed bit of the containing object must be. */
8514 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8516 /* Round up to type_align by default. This works best for bitfields. */
8517 object_offset_in_bits
+= type_align_in_bits
- 1;
8518 object_offset_in_bits
/= type_align_in_bits
;
8519 object_offset_in_bits
*= type_align_in_bits
;
8521 if (object_offset_in_bits
> bitpos_int
)
8523 /* Sigh, the decl must be packed. */
8524 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8526 /* Round up to decl_align instead. */
8527 object_offset_in_bits
+= decl_align_in_bits
- 1;
8528 object_offset_in_bits
/= decl_align_in_bits
;
8529 object_offset_in_bits
*= decl_align_in_bits
;
8532 return object_offset_in_bits
/ BITS_PER_UNIT
;
8535 /* The following routines define various Dwarf attributes and any data
8536 associated with them. */
8538 /* Add a location description attribute value to a DIE.
8540 This emits location attributes suitable for whole variables and
8541 whole parameters. Note that the location attributes for struct fields are
8542 generated by the routine `data_member_location_attribute' below. */
8545 add_AT_location_description (die
, attr_kind
, rtl
)
8547 enum dwarf_attribute attr_kind
;
8550 dw_loc_descr_ref descr
= loc_descriptor (rtl
);
8553 add_AT_loc (die
, attr_kind
, descr
);
8556 /* Attach the specialized form of location attribute used for data members of
8557 struct and union types. In the special case of a FIELD_DECL node which
8558 represents a bit-field, the "offset" part of this special location
8559 descriptor must indicate the distance in bytes from the lowest-addressed
8560 byte of the containing struct or union type to the lowest-addressed byte of
8561 the "containing object" for the bit-field. (See the `field_byte_offset'
8564 For any given bit-field, the "containing object" is a hypothetical object
8565 (of some integral or enum type) within which the given bit-field lives. The
8566 type of this hypothetical "containing object" is always the same as the
8567 declared type of the individual bit-field itself (for GCC anyway... the
8568 DWARF spec doesn't actually mandate this). Note that it is the size (in
8569 bytes) of the hypothetical "containing object" which will be given in the
8570 DW_AT_byte_size attribute for this bit-field. (See the
8571 `byte_size_attribute' function below.) It is also used when calculating the
8572 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8576 add_data_member_location_attribute (die
, decl
)
8581 dw_loc_descr_ref loc_descr
= 0;
8583 if (TREE_CODE (decl
) == TREE_VEC
)
8585 /* We're working on the TAG_inheritance for a base class. */
8586 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8588 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8589 aren't at a fixed offset from all (sub)objects of the same
8590 type. We need to extract the appropriate offset from our
8591 vtable. The following dwarf expression means
8593 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8595 This is specific to the V3 ABI, of course. */
8597 dw_loc_descr_ref tmp
;
8599 /* Make a copy of the object address. */
8600 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8601 add_loc_descr (&loc_descr
, tmp
);
8603 /* Extract the vtable address. */
8604 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8605 add_loc_descr (&loc_descr
, tmp
);
8607 /* Calculate the address of the offset. */
8608 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
8612 tmp
= int_loc_descriptor (-offset
);
8613 add_loc_descr (&loc_descr
, tmp
);
8614 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
8615 add_loc_descr (&loc_descr
, tmp
);
8617 /* Extract the offset. */
8618 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8619 add_loc_descr (&loc_descr
, tmp
);
8621 /* Add it to the object address. */
8622 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
8623 add_loc_descr (&loc_descr
, tmp
);
8626 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
8629 offset
= field_byte_offset (decl
);
8633 enum dwarf_location_atom op
;
8635 /* The DWARF2 standard says that we should assume that the structure
8636 address is already on the stack, so we can specify a structure field
8637 address by using DW_OP_plus_uconst. */
8639 #ifdef MIPS_DEBUGGING_INFO
8640 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8641 operator correctly. It works only if we leave the offset on the
8645 op
= DW_OP_plus_uconst
;
8648 loc_descr
= new_loc_descr (op
, offset
, 0);
8651 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
8654 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8655 does not have a "location" either in memory or in a register. These
8656 things can arise in GNU C when a constant is passed as an actual parameter
8657 to an inlined function. They can also arise in C++ where declared
8658 constants do not necessarily get memory "homes". */
8661 add_const_value_attribute (die
, rtl
)
8665 switch (GET_CODE (rtl
))
8668 /* Note that a CONST_INT rtx could represent either an integer
8669 or a floating-point constant. A CONST_INT is used whenever
8670 the constant will fit into a single word. In all such
8671 cases, the original mode of the constant value is wiped
8672 out, and the CONST_INT rtx is assigned VOIDmode. */
8674 HOST_WIDE_INT val
= INTVAL (rtl
);
8676 /* ??? We really should be using HOST_WIDE_INT throughout. */
8677 if (val
< 0 && (long) val
== val
)
8678 add_AT_int (die
, DW_AT_const_value
, (long) val
);
8679 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
8680 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
8683 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8684 add_AT_long_long (die
, DW_AT_const_value
,
8685 val
>> HOST_BITS_PER_LONG
, val
);
8694 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8695 floating-point constant. A CONST_DOUBLE is used whenever the
8696 constant requires more than one word in order to be adequately
8697 represented. We output CONST_DOUBLEs as blocks. */
8699 enum machine_mode mode
= GET_MODE (rtl
);
8701 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
8703 unsigned length
= GET_MODE_SIZE (mode
) / 4;
8704 long *array
= (long *) xmalloc (sizeof (long) * length
);
8707 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
8711 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
8715 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
8720 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
8727 add_AT_float (die
, DW_AT_const_value
, length
, array
);
8731 /* ??? We really should be using HOST_WIDE_INT throughout. */
8732 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
8735 add_AT_long_long (die
, DW_AT_const_value
,
8736 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
8742 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
8748 add_AT_addr (die
, DW_AT_const_value
, rtl
);
8749 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8753 /* In cases where an inlined instance of an inline function is passed
8754 the address of an `auto' variable (which is local to the caller) we
8755 can get a situation where the DECL_RTL of the artificial local
8756 variable (for the inlining) which acts as a stand-in for the
8757 corresponding formal parameter (of the inline function) will look
8758 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8759 exactly a compile-time constant expression, but it isn't the address
8760 of the (artificial) local variable either. Rather, it represents the
8761 *value* which the artificial local variable always has during its
8762 lifetime. We currently have no way to represent such quasi-constant
8763 values in Dwarf, so for now we just punt and generate nothing. */
8767 /* No other kinds of rtx should be possible here. */
8774 rtl_for_decl_location (decl
)
8779 /* Here we have to decide where we are going to say the parameter "lives"
8780 (as far as the debugger is concerned). We only have a couple of
8781 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8783 DECL_RTL normally indicates where the parameter lives during most of the
8784 activation of the function. If optimization is enabled however, this
8785 could be either NULL or else a pseudo-reg. Both of those cases indicate
8786 that the parameter doesn't really live anywhere (as far as the code
8787 generation parts of GCC are concerned) during most of the function's
8788 activation. That will happen (for example) if the parameter is never
8789 referenced within the function.
8791 We could just generate a location descriptor here for all non-NULL
8792 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8793 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8794 where DECL_RTL is NULL or is a pseudo-reg.
8796 Note however that we can only get away with using DECL_INCOMING_RTL as
8797 a backup substitute for DECL_RTL in certain limited cases. In cases
8798 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8799 we can be sure that the parameter was passed using the same type as it is
8800 declared to have within the function, and that its DECL_INCOMING_RTL
8801 points us to a place where a value of that type is passed.
8803 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8804 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8805 because in these cases DECL_INCOMING_RTL points us to a value of some
8806 type which is *different* from the type of the parameter itself. Thus,
8807 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8808 such cases, the debugger would end up (for example) trying to fetch a
8809 `float' from a place which actually contains the first part of a
8810 `double'. That would lead to really incorrect and confusing
8811 output at debug-time.
8813 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8814 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8815 are a couple of exceptions however. On little-endian machines we can
8816 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8817 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8818 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8819 when (on a little-endian machine) a non-prototyped function has a
8820 parameter declared to be of type `short' or `char'. In such cases,
8821 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8822 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8823 passed `int' value. If the debugger then uses that address to fetch
8824 a `short' or a `char' (on a little-endian machine) the result will be
8825 the correct data, so we allow for such exceptional cases below.
8827 Note that our goal here is to describe the place where the given formal
8828 parameter lives during most of the function's activation (i.e. between the
8829 end of the prologue and the start of the epilogue). We'll do that as best
8830 as we can. Note however that if the given formal parameter is modified
8831 sometime during the execution of the function, then a stack backtrace (at
8832 debug-time) will show the function as having been called with the *new*
8833 value rather than the value which was originally passed in. This happens
8834 rarely enough that it is not a major problem, but it *is* a problem, and
8837 A future version of dwarf2out.c may generate two additional attributes for
8838 any given DW_TAG_formal_parameter DIE which will describe the "passed
8839 type" and the "passed location" for the given formal parameter in addition
8840 to the attributes we now generate to indicate the "declared type" and the
8841 "active location" for each parameter. This additional set of attributes
8842 could be used by debuggers for stack backtraces. Separately, note that
8843 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8844 This happens (for example) for inlined-instances of inline function formal
8845 parameters which are never referenced. This really shouldn't be
8846 happening. All PARM_DECL nodes should get valid non-NULL
8847 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8848 values for inlined instances of inline function parameters, so when we see
8849 such cases, we are just out-of-luck for the time being (until integrate.c
8852 /* Use DECL_RTL as the "location" unless we find something better. */
8853 rtl
= DECL_RTL_IF_SET (decl
);
8855 /* When generating abstract instances, ignore everything except
8856 constants and symbols living in memory. */
8857 if (! reload_completed
)
8860 && (CONSTANT_P (rtl
)
8861 || (GET_CODE (rtl
) == MEM
8862 && CONSTANT_P (XEXP (rtl
, 0)))))
8864 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8865 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8871 else if (TREE_CODE (decl
) == PARM_DECL
)
8873 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
8875 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
8876 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
8878 /* This decl represents a formal parameter which was optimized out.
8879 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8880 all cases where (rtl == NULL_RTX) just below. */
8881 if (declared_type
== passed_type
)
8882 rtl
= DECL_INCOMING_RTL (decl
);
8883 else if (! BYTES_BIG_ENDIAN
8884 && TREE_CODE (declared_type
) == INTEGER_TYPE
8885 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
8886 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
8887 rtl
= DECL_INCOMING_RTL (decl
);
8890 /* If the parm was passed in registers, but lives on the stack, then
8891 make a big endian correction if the mode of the type of the
8892 parameter is not the same as the mode of the rtl. */
8893 /* ??? This is the same series of checks that are made in dbxout.c before
8894 we reach the big endian correction code there. It isn't clear if all
8895 of these checks are necessary here, but keeping them all is the safe
8897 else if (GET_CODE (rtl
) == MEM
8898 && XEXP (rtl
, 0) != const0_rtx
8899 && ! CONSTANT_P (XEXP (rtl
, 0))
8900 /* Not passed in memory. */
8901 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
8902 /* Not passed by invisible reference. */
8903 && (GET_CODE (XEXP (rtl
, 0)) != REG
8904 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
8905 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
8906 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8907 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
8910 /* Big endian correction check. */
8912 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
8913 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
8916 int offset
= (UNITS_PER_WORD
8917 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
8919 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
8920 plus_constant (XEXP (rtl
, 0), offset
));
8924 if (rtl
!= NULL_RTX
)
8926 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
8927 #ifdef LEAF_REG_REMAP
8928 if (current_function_uses_only_leaf_regs
)
8929 leaf_renumber_regs_insn (rtl
);
8933 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8934 and will have been substituted directly into all expressions that use it.
8935 C does not have such a concept, but C++ and other languages do. */
8936 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
8938 /* If a variable is initialized with a string constant without embedded
8939 zeros, build CONST_STRING. */
8940 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
8941 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
8943 tree arrtype
= TREE_TYPE (decl
);
8944 tree enttype
= TREE_TYPE (arrtype
);
8945 tree domain
= TYPE_DOMAIN (arrtype
);
8946 tree init
= DECL_INITIAL (decl
);
8947 enum machine_mode mode
= TYPE_MODE (enttype
);
8949 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
8951 && integer_zerop (TYPE_MIN_VALUE (domain
))
8952 && compare_tree_int (TYPE_MAX_VALUE (domain
),
8953 TREE_STRING_LENGTH (init
) - 1) == 0
8954 && ((size_t) TREE_STRING_LENGTH (init
)
8955 == strlen (TREE_STRING_POINTER (init
)) + 1))
8956 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
8958 /* If the initializer is something that we know will expand into an
8959 immediate RTL constant, expand it now. Expanding anything else
8960 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8961 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
8962 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
8964 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
8965 EXPAND_INITIALIZER
);
8966 /* If expand_expr returns a MEM, it wasn't immediate. */
8967 if (rtl
&& GET_CODE (rtl
) == MEM
)
8972 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8974 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8979 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8980 data attribute for a variable or a parameter. We generate the
8981 DW_AT_const_value attribute only in those cases where the given variable
8982 or parameter does not have a true "location" either in memory or in a
8983 register. This can happen (for example) when a constant is passed as an
8984 actual argument in a call to an inline function. (It's possible that
8985 these things can crop up in other ways also.) Note that one type of
8986 constant value which can be passed into an inlined function is a constant
8987 pointer. This can happen for example if an actual argument in an inlined
8988 function call evaluates to a compile-time constant address. */
8991 add_location_or_const_value_attribute (die
, decl
)
8997 if (TREE_CODE (decl
) == ERROR_MARK
)
8999 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
9002 rtl
= rtl_for_decl_location (decl
);
9003 if (rtl
== NULL_RTX
)
9006 /* If we don't look past the constant pool, we risk emitting a
9007 reference to a constant pool entry that isn't referenced from
9008 code, and thus is not emitted. */
9009 rtl
= avoid_constant_pool_reference (rtl
);
9011 switch (GET_CODE (rtl
))
9014 /* The address of a variable that was optimized away; don't emit
9025 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9026 add_const_value_attribute (die
, rtl
);
9033 add_AT_location_description (die
, DW_AT_location
, rtl
);
9041 /* If we don't have a copy of this variable in memory for some reason (such
9042 as a C++ member constant that doesn't have an out-of-line definition),
9043 we should tell the debugger about the constant value. */
9046 tree_add_const_value_attribute (var_die
, decl
)
9050 tree init
= DECL_INITIAL (decl
);
9051 tree type
= TREE_TYPE (decl
);
9053 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9054 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9059 switch (TREE_CODE (type
))
9062 if (host_integerp (init
, 0))
9063 add_AT_unsigned (var_die
, DW_AT_const_value
,
9064 tree_low_cst (init
, 0));
9066 add_AT_long_long (var_die
, DW_AT_const_value
,
9067 TREE_INT_CST_HIGH (init
),
9068 TREE_INT_CST_LOW (init
));
9075 /* Generate an DW_AT_name attribute given some string value to be included as
9076 the value of the attribute. */
9079 add_name_attribute (die
, name_string
)
9081 const char *name_string
;
9083 if (name_string
!= NULL
&& *name_string
!= 0)
9085 if (demangle_name_func
)
9086 name_string
= (*demangle_name_func
) (name_string
);
9088 add_AT_string (die
, DW_AT_name
, name_string
);
9092 /* Given a tree node describing an array bound (either lower or upper) output
9093 a representation for that bound. */
9096 add_bound_info (subrange_die
, bound_attr
, bound
)
9097 dw_die_ref subrange_die
;
9098 enum dwarf_attribute bound_attr
;
9101 switch (TREE_CODE (bound
))
9106 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9108 if (! host_integerp (bound
, 0)
9109 || (bound_attr
== DW_AT_lower_bound
9110 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9111 || (is_fortran () && integer_onep (bound
)))))
9112 /* use the default */
9115 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9120 case NON_LVALUE_EXPR
:
9121 case VIEW_CONVERT_EXPR
:
9122 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9126 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9127 access the upper bound values may be bogus. If they refer to a
9128 register, they may only describe how to get at these values at the
9129 points in the generated code right after they have just been
9130 computed. Worse yet, in the typical case, the upper bound values
9131 will not even *be* computed in the optimized code (though the
9132 number of elements will), so these SAVE_EXPRs are entirely
9133 bogus. In order to compensate for this fact, we check here to see
9134 if optimization is enabled, and if so, we don't add an attribute
9135 for the (unknown and unknowable) upper bound. This should not
9136 cause too much trouble for existing (stupid?) debuggers because
9137 they have to deal with empty upper bounds location descriptions
9138 anyway in order to be able to deal with incomplete array types.
9139 Of course an intelligent debugger (GDB?) should be able to
9140 comprehend that a missing upper bound specification in an array
9141 type used for a storage class `auto' local array variable
9142 indicates that the upper bound is both unknown (at compile- time)
9143 and unknowable (at run-time) due to optimization.
9145 We assume that a MEM rtx is safe because gcc wouldn't put the
9146 value there unless it was going to be used repeatedly in the
9147 function, i.e. for cleanups. */
9148 if (SAVE_EXPR_RTL (bound
)
9149 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9151 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9152 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9153 rtx loc
= SAVE_EXPR_RTL (bound
);
9155 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9156 it references an outer function's frame. */
9157 if (GET_CODE (loc
) == MEM
)
9159 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9161 if (XEXP (loc
, 0) != new_addr
)
9162 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9165 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9166 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9167 add_AT_location_description (decl_die
, DW_AT_location
, loc
);
9168 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9171 /* Else leave out the attribute. */
9177 dw_die_ref decl_die
= lookup_decl_die (bound
);
9179 /* ??? Can this happen, or should the variable have been bound
9180 first? Probably it can, since I imagine that we try to create
9181 the types of parameters in the order in which they exist in
9182 the list, and won't have created a forward reference to a
9184 if (decl_die
!= NULL
)
9185 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9191 /* Otherwise try to create a stack operation procedure to
9192 evaluate the value of the array bound. */
9194 dw_die_ref ctx
, decl_die
;
9195 dw_loc_descr_ref loc
;
9197 loc
= loc_descriptor_from_tree (bound
, 0);
9201 if (current_function_decl
== 0)
9202 ctx
= comp_unit_die
;
9204 ctx
= lookup_decl_die (current_function_decl
);
9206 /* If we weren't able to find a context, it's most likely the case
9207 that we are processing the return type of the function. So
9208 make a SAVE_EXPR to point to it and have the limbo DIE code
9209 find the proper die. The save_expr function doesn't always
9210 make a SAVE_EXPR, so do it ourselves. */
9212 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9213 current_function_decl
, NULL_TREE
);
9215 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9216 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9217 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9218 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9220 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9226 /* Note that the block of subscript information for an array type also
9227 includes information about the element type of type given array type. */
9230 add_subscript_info (type_die
, type
)
9231 dw_die_ref type_die
;
9234 #ifndef MIPS_DEBUGGING_INFO
9235 unsigned dimension_number
;
9238 dw_die_ref subrange_die
;
9240 /* The GNU compilers represent multidimensional array types as sequences of
9241 one dimensional array types whose element types are themselves array
9242 types. Here we squish that down, so that each multidimensional array
9243 type gets only one array_type DIE in the Dwarf debugging info. The draft
9244 Dwarf specification say that we are allowed to do this kind of
9245 compression in C (because there is no difference between an array or
9246 arrays and a multidimensional array in C) but for other source languages
9247 (e.g. Ada) we probably shouldn't do this. */
9249 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9250 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9251 We work around this by disabling this feature. See also
9252 gen_array_type_die. */
9253 #ifndef MIPS_DEBUGGING_INFO
9254 for (dimension_number
= 0;
9255 TREE_CODE (type
) == ARRAY_TYPE
;
9256 type
= TREE_TYPE (type
), dimension_number
++)
9259 tree domain
= TYPE_DOMAIN (type
);
9261 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9262 and (in GNU C only) variable bounds. Handle all three forms
9264 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9267 /* We have an array type with specified bounds. */
9268 lower
= TYPE_MIN_VALUE (domain
);
9269 upper
= TYPE_MAX_VALUE (domain
);
9271 /* define the index type. */
9272 if (TREE_TYPE (domain
))
9274 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9275 TREE_TYPE field. We can't emit debug info for this
9276 because it is an unnamed integral type. */
9277 if (TREE_CODE (domain
) == INTEGER_TYPE
9278 && TYPE_NAME (domain
) == NULL_TREE
9279 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9280 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9283 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9287 /* ??? If upper is NULL, the array has unspecified length,
9288 but it does have a lower bound. This happens with Fortran
9290 Since the debugger is definitely going to need to know N
9291 to produce useful results, go ahead and output the lower
9292 bound solo, and hope the debugger can cope. */
9294 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9296 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9299 /* Otherwise we have an array type with an unspecified length. The
9300 DWARF-2 spec does not say how to handle this; let's just leave out the
9306 add_byte_size_attribute (die
, tree_node
)
9312 switch (TREE_CODE (tree_node
))
9320 case QUAL_UNION_TYPE
:
9321 size
= int_size_in_bytes (tree_node
);
9324 /* For a data member of a struct or union, the DW_AT_byte_size is
9325 generally given as the number of bytes normally allocated for an
9326 object of the *declared* type of the member itself. This is true
9327 even for bit-fields. */
9328 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9334 /* Note that `size' might be -1 when we get to this point. If it is, that
9335 indicates that the byte size of the entity in question is variable. We
9336 have no good way of expressing this fact in Dwarf at the present time,
9337 so just let the -1 pass on through. */
9338 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9341 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9342 which specifies the distance in bits from the highest order bit of the
9343 "containing object" for the bit-field to the highest order bit of the
9346 For any given bit-field, the "containing object" is a hypothetical object
9347 (of some integral or enum type) within which the given bit-field lives. The
9348 type of this hypothetical "containing object" is always the same as the
9349 declared type of the individual bit-field itself. The determination of the
9350 exact location of the "containing object" for a bit-field is rather
9351 complicated. It's handled by the `field_byte_offset' function (above).
9353 Note that it is the size (in bytes) of the hypothetical "containing object"
9354 which will be given in the DW_AT_byte_size attribute for this bit-field.
9355 (See `byte_size_attribute' above). */
9358 add_bit_offset_attribute (die
, decl
)
9362 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9363 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9364 HOST_WIDE_INT bitpos_int
;
9365 HOST_WIDE_INT highest_order_object_bit_offset
;
9366 HOST_WIDE_INT highest_order_field_bit_offset
;
9367 HOST_WIDE_INT
unsigned bit_offset
;
9369 /* Must be a field and a bit field. */
9371 || TREE_CODE (decl
) != FIELD_DECL
)
9374 /* We can't yet handle bit-fields whose offsets are variable, so if we
9375 encounter such things, just return without generating any attribute
9376 whatsoever. Likewise for variable or too large size. */
9377 if (! host_integerp (bit_position (decl
), 0)
9378 || ! host_integerp (DECL_SIZE (decl
), 1))
9381 bitpos_int
= int_bit_position (decl
);
9383 /* Note that the bit offset is always the distance (in bits) from the
9384 highest-order bit of the "containing object" to the highest-order bit of
9385 the bit-field itself. Since the "high-order end" of any object or field
9386 is different on big-endian and little-endian machines, the computation
9387 below must take account of these differences. */
9388 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9389 highest_order_field_bit_offset
= bitpos_int
;
9391 if (! BYTES_BIG_ENDIAN
)
9393 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9394 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9398 = (! BYTES_BIG_ENDIAN
9399 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9400 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9402 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9405 /* For a FIELD_DECL node which represents a bit field, output an attribute
9406 which specifies the length in bits of the given field. */
9409 add_bit_size_attribute (die
, decl
)
9413 /* Must be a field and a bit field. */
9414 if (TREE_CODE (decl
) != FIELD_DECL
9415 || ! DECL_BIT_FIELD_TYPE (decl
))
9418 if (host_integerp (DECL_SIZE (decl
), 1))
9419 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9422 /* If the compiled language is ANSI C, then add a 'prototyped'
9423 attribute, if arg types are given for the parameters of a function. */
9426 add_prototyped_attribute (die
, func_type
)
9430 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9431 && TYPE_ARG_TYPES (func_type
) != NULL
)
9432 add_AT_flag (die
, DW_AT_prototyped
, 1);
9435 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9436 by looking in either the type declaration or object declaration
9440 add_abstract_origin_attribute (die
, origin
)
9444 dw_die_ref origin_die
= NULL
;
9446 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9448 /* We may have gotten separated from the block for the inlined
9449 function, if we're in an exception handler or some such; make
9450 sure that the abstract function has been written out.
9452 Doing this for nested functions is wrong, however; functions are
9453 distinct units, and our context might not even be inline. */
9457 fn
= TYPE_STUB_DECL (fn
);
9459 fn
= decl_function_context (fn
);
9461 dwarf2out_abstract_function (fn
);
9464 if (DECL_P (origin
))
9465 origin_die
= lookup_decl_die (origin
);
9466 else if (TYPE_P (origin
))
9467 origin_die
= lookup_type_die (origin
);
9469 if (origin_die
== NULL
)
9472 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9475 /* We do not currently support the pure_virtual attribute. */
9478 add_pure_or_virtual_attribute (die
, func_decl
)
9482 if (DECL_VINDEX (func_decl
))
9484 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9486 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9487 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9488 new_loc_descr (DW_OP_constu
,
9489 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9492 /* GNU extension: Record what type this method came from originally. */
9493 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9494 add_AT_die_ref (die
, DW_AT_containing_type
,
9495 lookup_type_die (DECL_CONTEXT (func_decl
)));
9499 /* Add source coordinate attributes for the given decl. */
9502 add_src_coords_attributes (die
, decl
)
9506 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9508 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9509 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9512 /* Add an DW_AT_name attribute and source coordinate attribute for the
9513 given decl, but only if it actually has a name. */
9516 add_name_and_src_coords_attributes (die
, decl
)
9522 decl_name
= DECL_NAME (decl
);
9523 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9525 add_name_attribute (die
, dwarf2_name (decl
, 0));
9526 if (! DECL_ARTIFICIAL (decl
))
9527 add_src_coords_attributes (die
, decl
);
9529 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9530 && TREE_PUBLIC (decl
)
9531 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9532 && !DECL_ABSTRACT (decl
))
9533 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9534 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9537 #ifdef VMS_DEBUGGING_INFO
9538 /* Get the function's name, as described by its RTL. This may be different
9539 from the DECL_NAME name used in the source file. */
9540 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9542 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9543 XEXP (DECL_RTL (decl
), 0));
9544 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9549 /* Push a new declaration scope. */
9552 push_decl_scope (scope
)
9555 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9558 /* Pop a declaration scope. */
9563 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9566 VARRAY_POP (decl_scope_table
);
9569 /* Return the DIE for the scope that immediately contains this type.
9570 Non-named types get global scope. Named types nested in other
9571 types get their containing scope if it's open, or global scope
9572 otherwise. All other types (i.e. function-local named types) get
9573 the current active scope. */
9576 scope_die_for (t
, context_die
)
9578 dw_die_ref context_die
;
9580 dw_die_ref scope_die
= NULL
;
9581 tree containing_scope
;
9584 /* Non-types always go in the current scope. */
9588 containing_scope
= TYPE_CONTEXT (t
);
9590 /* Ignore namespaces for the moment. */
9591 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9592 containing_scope
= NULL_TREE
;
9594 /* Ignore function type "scopes" from the C frontend. They mean that
9595 a tagged type is local to a parmlist of a function declarator, but
9596 that isn't useful to DWARF. */
9597 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
9598 containing_scope
= NULL_TREE
;
9600 if (containing_scope
== NULL_TREE
)
9601 scope_die
= comp_unit_die
;
9602 else if (TYPE_P (containing_scope
))
9604 /* For types, we can just look up the appropriate DIE. But
9605 first we check to see if we're in the middle of emitting it
9606 so we know where the new DIE should go. */
9607 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
9608 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
9613 if (debug_info_level
> DINFO_LEVEL_TERSE
9614 && !TREE_ASM_WRITTEN (containing_scope
))
9617 /* If none of the current dies are suitable, we get file scope. */
9618 scope_die
= comp_unit_die
;
9621 scope_die
= lookup_type_die (containing_scope
);
9624 scope_die
= context_die
;
9629 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9632 local_scope_p (context_die
)
9633 dw_die_ref context_die
;
9635 for (; context_die
; context_die
= context_die
->die_parent
)
9636 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
9637 || context_die
->die_tag
== DW_TAG_subprogram
)
9643 /* Returns nonzero if CONTEXT_DIE is a class. */
9646 class_scope_p (context_die
)
9647 dw_die_ref context_die
;
9650 && (context_die
->die_tag
== DW_TAG_structure_type
9651 || context_die
->die_tag
== DW_TAG_union_type
));
9654 /* Many forms of DIEs require a "type description" attribute. This
9655 routine locates the proper "type descriptor" die for the type given
9656 by 'type', and adds an DW_AT_type attribute below the given die. */
9659 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
9660 dw_die_ref object_die
;
9664 dw_die_ref context_die
;
9666 enum tree_code code
= TREE_CODE (type
);
9667 dw_die_ref type_die
= NULL
;
9669 /* ??? If this type is an unnamed subrange type of an integral or
9670 floating-point type, use the inner type. This is because we have no
9671 support for unnamed types in base_type_die. This can happen if this is
9672 an Ada subrange type. Correct solution is emit a subrange type die. */
9673 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
9674 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
9675 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
9677 if (code
== ERROR_MARK
9678 /* Handle a special case. For functions whose return type is void, we
9679 generate *no* type attribute. (Note that no object may have type
9680 `void', so this only applies to function return types). */
9681 || code
== VOID_TYPE
)
9684 type_die
= modified_type_die (type
,
9685 decl_const
|| TYPE_READONLY (type
),
9686 decl_volatile
|| TYPE_VOLATILE (type
),
9689 if (type_die
!= NULL
)
9690 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
9693 /* Given a tree pointer to a struct, class, union, or enum type node, return
9694 a pointer to the (string) tag name for the given type, or zero if the type
9695 was declared without a tag. */
9701 const char *name
= 0;
9703 if (TYPE_NAME (type
) != 0)
9707 /* Find the IDENTIFIER_NODE for the type name. */
9708 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
9709 t
= TYPE_NAME (type
);
9711 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9712 a TYPE_DECL node, regardless of whether or not a `typedef' was
9714 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9715 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
9716 t
= DECL_NAME (TYPE_NAME (type
));
9718 /* Now get the name as a string, or invent one. */
9720 name
= IDENTIFIER_POINTER (t
);
9723 return (name
== 0 || *name
== '\0') ? 0 : name
;
9726 /* Return the type associated with a data member, make a special check
9727 for bit field types. */
9730 member_declared_type (member
)
9733 return (DECL_BIT_FIELD_TYPE (member
)
9734 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
9737 /* Get the decl's label, as described by its RTL. This may be different
9738 from the DECL_NAME name used in the source file. */
9742 decl_start_label (decl
)
9748 x
= DECL_RTL (decl
);
9749 if (GET_CODE (x
) != MEM
)
9753 if (GET_CODE (x
) != SYMBOL_REF
)
9756 fnname
= XSTR (x
, 0);
9761 /* These routines generate the internal representation of the DIE's for
9762 the compilation unit. Debugging information is collected by walking
9763 the declaration trees passed in from dwarf2out_decl(). */
9766 gen_array_type_die (type
, context_die
)
9768 dw_die_ref context_die
;
9770 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
9771 dw_die_ref array_die
;
9774 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9775 the inner array type comes before the outer array type. Thus we must
9776 call gen_type_die before we call new_die. See below also. */
9777 #ifdef MIPS_DEBUGGING_INFO
9778 gen_type_die (TREE_TYPE (type
), context_die
);
9781 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
9782 add_name_attribute (array_die
, type_tag (type
));
9783 equate_type_number_to_die (type
, array_die
);
9785 if (TREE_CODE (type
) == VECTOR_TYPE
)
9787 /* The frontend feeds us a representation for the vector as a struct
9788 containing an array. Pull out the array type. */
9789 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
9790 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
9794 /* We default the array ordering. SDB will probably do
9795 the right things even if DW_AT_ordering is not present. It's not even
9796 an issue until we start to get into multidimensional arrays anyway. If
9797 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9798 then we'll have to put the DW_AT_ordering attribute back in. (But if
9799 and when we find out that we need to put these in, we will only do so
9800 for multidimensional arrays. */
9801 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
9804 #ifdef MIPS_DEBUGGING_INFO
9805 /* The SGI compilers handle arrays of unknown bound by setting
9806 AT_declaration and not emitting any subrange DIEs. */
9807 if (! TYPE_DOMAIN (type
))
9808 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
9811 add_subscript_info (array_die
, type
);
9813 /* Add representation of the type of the elements of this array type. */
9814 element_type
= TREE_TYPE (type
);
9816 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9817 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9818 We work around this by disabling this feature. See also
9819 add_subscript_info. */
9820 #ifndef MIPS_DEBUGGING_INFO
9821 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
9822 element_type
= TREE_TYPE (element_type
);
9824 gen_type_die (element_type
, context_die
);
9827 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
9831 gen_set_type_die (type
, context_die
)
9833 dw_die_ref context_die
;
9836 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
9838 equate_type_number_to_die (type
, type_die
);
9839 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
9844 gen_entry_point_die (decl
, context_die
)
9846 dw_die_ref context_die
;
9848 tree origin
= decl_ultimate_origin (decl
);
9849 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
9852 add_abstract_origin_attribute (decl_die
, origin
);
9855 add_name_and_src_coords_attributes (decl_die
, decl
);
9856 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
9860 if (DECL_ABSTRACT (decl
))
9861 equate_decl_number_to_die (decl
, decl_die
);
9863 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
9867 /* Walk through the list of incomplete types again, trying once more to
9868 emit full debugging info for them. */
9871 retry_incomplete_types ()
9875 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
9876 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
9879 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9882 gen_inlined_enumeration_type_die (type
, context_die
)
9884 dw_die_ref context_die
;
9886 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
9888 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9889 be incomplete and such types are not marked. */
9890 add_abstract_origin_attribute (type_die
, type
);
9893 /* Generate a DIE to represent an inlined instance of a structure type. */
9896 gen_inlined_structure_type_die (type
, context_die
)
9898 dw_die_ref context_die
;
9900 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
9902 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9903 be incomplete and such types are not marked. */
9904 add_abstract_origin_attribute (type_die
, type
);
9907 /* Generate a DIE to represent an inlined instance of a union type. */
9910 gen_inlined_union_type_die (type
, context_die
)
9912 dw_die_ref context_die
;
9914 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
9916 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9917 be incomplete and such types are not marked. */
9918 add_abstract_origin_attribute (type_die
, type
);
9921 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9922 include all of the information about the enumeration values also. Each
9923 enumerated type name/value is listed as a child of the enumerated type
9927 gen_enumeration_type_die (type
, context_die
)
9929 dw_die_ref context_die
;
9931 dw_die_ref type_die
= lookup_type_die (type
);
9933 if (type_die
== NULL
)
9935 type_die
= new_die (DW_TAG_enumeration_type
,
9936 scope_die_for (type
, context_die
), type
);
9937 equate_type_number_to_die (type
, type_die
);
9938 add_name_attribute (type_die
, type_tag (type
));
9940 else if (! TYPE_SIZE (type
))
9943 remove_AT (type_die
, DW_AT_declaration
);
9945 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9946 given enum type is incomplete, do not generate the DW_AT_byte_size
9947 attribute or the DW_AT_element_list attribute. */
9948 if (TYPE_SIZE (type
))
9952 TREE_ASM_WRITTEN (type
) = 1;
9953 add_byte_size_attribute (type_die
, type
);
9954 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
9955 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
9957 /* If the first reference to this type was as the return type of an
9958 inline function, then it may not have a parent. Fix this now. */
9959 if (type_die
->die_parent
== NULL
)
9960 add_child_die (scope_die_for (type
, context_die
), type_die
);
9962 for (link
= TYPE_FIELDS (type
);
9963 link
!= NULL
; link
= TREE_CHAIN (link
))
9965 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
9967 add_name_attribute (enum_die
,
9968 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
9970 if (host_integerp (TREE_VALUE (link
), 0))
9972 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
9973 add_AT_int (enum_die
, DW_AT_const_value
,
9974 tree_low_cst (TREE_VALUE (link
), 0));
9976 add_AT_unsigned (enum_die
, DW_AT_const_value
,
9977 tree_low_cst (TREE_VALUE (link
), 0));
9982 add_AT_flag (type_die
, DW_AT_declaration
, 1);
9985 /* Generate a DIE to represent either a real live formal parameter decl or to
9986 represent just the type of some formal parameter position in some function
9989 Note that this routine is a bit unusual because its argument may be a
9990 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9991 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9992 node. If it's the former then this function is being called to output a
9993 DIE to represent a formal parameter object (or some inlining thereof). If
9994 it's the latter, then this function is only being called to output a
9995 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9996 argument type of some subprogram type. */
9999 gen_formal_parameter_die (node
, context_die
)
10001 dw_die_ref context_die
;
10003 dw_die_ref parm_die
10004 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
10007 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
10010 origin
= decl_ultimate_origin (node
);
10011 if (origin
!= NULL
)
10012 add_abstract_origin_attribute (parm_die
, origin
);
10015 add_name_and_src_coords_attributes (parm_die
, node
);
10016 add_type_attribute (parm_die
, TREE_TYPE (node
),
10017 TREE_READONLY (node
),
10018 TREE_THIS_VOLATILE (node
),
10020 if (DECL_ARTIFICIAL (node
))
10021 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10024 equate_decl_number_to_die (node
, parm_die
);
10025 if (! DECL_ABSTRACT (node
))
10026 add_location_or_const_value_attribute (parm_die
, node
);
10031 /* We were called with some kind of a ..._TYPE node. */
10032 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
10042 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10043 at the end of an (ANSI prototyped) formal parameters list. */
10046 gen_unspecified_parameters_die (decl_or_type
, context_die
)
10048 dw_die_ref context_die
;
10050 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10053 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10054 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10055 parameters as specified in some function type specification (except for
10056 those which appear as part of a function *definition*). */
10059 gen_formal_types_die (function_or_method_type
, context_die
)
10060 tree function_or_method_type
;
10061 dw_die_ref context_die
;
10064 tree formal_type
= NULL
;
10065 tree first_parm_type
;
10068 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10070 arg
= DECL_ARGUMENTS (function_or_method_type
);
10071 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10076 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10078 /* Make our first pass over the list of formal parameter types and output a
10079 DW_TAG_formal_parameter DIE for each one. */
10080 for (link
= first_parm_type
; link
; )
10082 dw_die_ref parm_die
;
10084 formal_type
= TREE_VALUE (link
);
10085 if (formal_type
== void_type_node
)
10088 /* Output a (nameless) DIE to represent the formal parameter itself. */
10089 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10090 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10091 && link
== first_parm_type
)
10092 || (arg
&& DECL_ARTIFICIAL (arg
)))
10093 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10095 link
= TREE_CHAIN (link
);
10097 arg
= TREE_CHAIN (arg
);
10100 /* If this function type has an ellipsis, add a
10101 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10102 if (formal_type
!= void_type_node
)
10103 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10105 /* Make our second (and final) pass over the list of formal parameter types
10106 and output DIEs to represent those types (as necessary). */
10107 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10108 link
&& TREE_VALUE (link
);
10109 link
= TREE_CHAIN (link
))
10110 gen_type_die (TREE_VALUE (link
), context_die
);
10113 /* We want to generate the DIE for TYPE so that we can generate the
10114 die for MEMBER, which has been defined; we will need to refer back
10115 to the member declaration nested within TYPE. If we're trying to
10116 generate minimal debug info for TYPE, processing TYPE won't do the
10117 trick; we need to attach the member declaration by hand. */
10120 gen_type_die_for_member (type
, member
, context_die
)
10122 dw_die_ref context_die
;
10124 gen_type_die (type
, context_die
);
10126 /* If we're trying to avoid duplicate debug info, we may not have
10127 emitted the member decl for this function. Emit it now. */
10128 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10129 && ! lookup_decl_die (member
))
10131 if (decl_ultimate_origin (member
))
10134 push_decl_scope (type
);
10135 if (TREE_CODE (member
) == FUNCTION_DECL
)
10136 gen_subprogram_die (member
, lookup_type_die (type
));
10138 gen_variable_die (member
, lookup_type_die (type
));
10144 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10145 may later generate inlined and/or out-of-line instances of. */
10148 dwarf2out_abstract_function (decl
)
10151 dw_die_ref old_die
;
10154 int was_abstract
= DECL_ABSTRACT (decl
);
10156 /* Make sure we have the actual abstract inline, not a clone. */
10157 decl
= DECL_ORIGIN (decl
);
10159 old_die
= lookup_decl_die (decl
);
10160 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10161 /* We've already generated the abstract instance. */
10164 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10165 we don't get confused by DECL_ABSTRACT. */
10166 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10168 context
= decl_class_context (decl
);
10170 gen_type_die_for_member
10171 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10174 /* Pretend we've just finished compiling this function. */
10175 save_fn
= current_function_decl
;
10176 current_function_decl
= decl
;
10178 set_decl_abstract_flags (decl
, 1);
10179 dwarf2out_decl (decl
);
10180 if (! was_abstract
)
10181 set_decl_abstract_flags (decl
, 0);
10183 current_function_decl
= save_fn
;
10186 /* Generate a DIE to represent a declared function (either file-scope or
10190 gen_subprogram_die (decl
, context_die
)
10192 dw_die_ref context_die
;
10194 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10195 tree origin
= decl_ultimate_origin (decl
);
10196 dw_die_ref subr_die
;
10200 dw_die_ref old_die
= lookup_decl_die (decl
);
10201 int declaration
= (current_function_decl
!= decl
10202 || class_scope_p (context_die
));
10204 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10205 started to generate the abstract instance of an inline, decided to output
10206 its containing class, and proceeded to emit the declaration of the inline
10207 from the member list for the class. If so, DECLARATION takes priority;
10208 we'll get back to the abstract instance when done with the class. */
10210 /* The class-scope declaration DIE must be the primary DIE. */
10211 if (origin
&& declaration
&& class_scope_p (context_die
))
10218 if (origin
!= NULL
)
10220 if (declaration
&& ! local_scope_p (context_die
))
10223 /* Fixup die_parent for the abstract instance of a nested
10224 inline function. */
10225 if (old_die
&& old_die
->die_parent
== NULL
)
10226 add_child_die (context_die
, old_die
);
10228 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10229 add_abstract_origin_attribute (subr_die
, origin
);
10233 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10235 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10236 /* We can have a normal definition following an inline one in the
10237 case of redefinition of GNU C extern inlines.
10238 It seems reasonable to use AT_specification in this case. */
10239 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10241 /* ??? This can happen if there is a bug in the program, for
10242 instance, if it has duplicate function definitions. Ideally,
10243 we should detect this case and ignore it. For now, if we have
10244 already reported an error, any error at all, then assume that
10245 we got here because of an input error, not a dwarf2 bug. */
10251 /* If the definition comes from the same place as the declaration,
10252 maybe use the old DIE. We always want the DIE for this function
10253 that has the *_pc attributes to be under comp_unit_die so the
10254 debugger can find it. We also need to do this for abstract
10255 instances of inlines, since the spec requires the out-of-line copy
10256 to have the same parent. For local class methods, this doesn't
10257 apply; we just use the old DIE. */
10258 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10259 && (DECL_ARTIFICIAL (decl
)
10260 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10261 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10262 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10264 subr_die
= old_die
;
10266 /* Clear out the declaration attribute and the parm types. */
10267 remove_AT (subr_die
, DW_AT_declaration
);
10268 remove_children (subr_die
);
10272 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10273 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10274 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10275 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10276 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10277 != (unsigned) DECL_SOURCE_LINE (decl
))
10279 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10284 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10286 if (TREE_PUBLIC (decl
))
10287 add_AT_flag (subr_die
, DW_AT_external
, 1);
10289 add_name_and_src_coords_attributes (subr_die
, decl
);
10290 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10292 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10293 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10294 0, 0, context_die
);
10297 add_pure_or_virtual_attribute (subr_die
, decl
);
10298 if (DECL_ARTIFICIAL (decl
))
10299 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10301 if (TREE_PROTECTED (decl
))
10302 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10303 else if (TREE_PRIVATE (decl
))
10304 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10309 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10311 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10313 /* The first time we see a member function, it is in the context of
10314 the class to which it belongs. We make sure of this by emitting
10315 the class first. The next time is the definition, which is
10316 handled above. The two may come from the same source text. */
10317 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10318 equate_decl_number_to_die (decl
, subr_die
);
10321 else if (DECL_ABSTRACT (decl
))
10323 if (DECL_INLINE (decl
) && !flag_no_inline
)
10325 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10326 inline functions, but not for extern inline functions.
10327 We can't get this completely correct because information
10328 about whether the function was declared inline is not
10330 if (DECL_DEFER_OUTPUT (decl
))
10331 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10333 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10336 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10338 equate_decl_number_to_die (decl
, subr_die
);
10340 else if (!DECL_EXTERNAL (decl
))
10342 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10343 equate_decl_number_to_die (decl
, subr_die
);
10345 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10346 current_funcdef_number
);
10347 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10348 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10349 current_funcdef_number
);
10350 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10352 add_pubname (decl
, subr_die
);
10353 add_arange (decl
, subr_die
);
10355 #ifdef MIPS_DEBUGGING_INFO
10356 /* Add a reference to the FDE for this routine. */
10357 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10360 /* Define the "frame base" location for this routine. We use the
10361 frame pointer or stack pointer registers, since the RTL for local
10362 variables is relative to one of them. */
10364 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10365 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10368 /* ??? This fails for nested inline functions, because context_display
10369 is not part of the state saved/restored for inline functions. */
10370 if (current_function_needs_context
)
10371 add_AT_location_description (subr_die
, DW_AT_static_link
,
10372 lookup_static_chain (decl
));
10376 /* Now output descriptions of the arguments for this function. This gets
10377 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10378 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10379 `...' at the end of the formal parameter list. In order to find out if
10380 there was a trailing ellipsis or not, we must instead look at the type
10381 associated with the FUNCTION_DECL. This will be a node of type
10382 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10383 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10384 an ellipsis at the end. */
10386 /* In the case where we are describing a mere function declaration, all we
10387 need to do here (and all we *can* do here) is to describe the *types* of
10388 its formal parameters. */
10389 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10391 else if (declaration
)
10392 gen_formal_types_die (decl
, subr_die
);
10395 /* Generate DIEs to represent all known formal parameters */
10396 tree arg_decls
= DECL_ARGUMENTS (decl
);
10399 /* When generating DIEs, generate the unspecified_parameters DIE
10400 instead if we come across the arg "__builtin_va_alist" */
10401 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10402 if (TREE_CODE (parm
) == PARM_DECL
)
10404 if (DECL_NAME (parm
)
10405 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10406 "__builtin_va_alist"))
10407 gen_unspecified_parameters_die (parm
, subr_die
);
10409 gen_decl_die (parm
, subr_die
);
10412 /* Decide whether we need an unspecified_parameters DIE at the end.
10413 There are 2 more cases to do this for: 1) the ansi ... declaration -
10414 this is detectable when the end of the arg list is not a
10415 void_type_node 2) an unprototyped function declaration (not a
10416 definition). This just means that we have no info about the
10417 parameters at all. */
10418 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10419 if (fn_arg_types
!= NULL
)
10421 /* this is the prototyped case, check for ... */
10422 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10423 gen_unspecified_parameters_die (decl
, subr_die
);
10425 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10426 gen_unspecified_parameters_die (decl
, subr_die
);
10429 /* Output Dwarf info for all of the stuff within the body of the function
10430 (if it has one - it may be just a declaration). */
10431 outer_scope
= DECL_INITIAL (decl
);
10433 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10434 a function. This BLOCK actually represents the outermost binding contour
10435 for the function, i.e. the contour in which the function's formal
10436 parameters and labels get declared. Curiously, it appears that the front
10437 end doesn't actually put the PARM_DECL nodes for the current function onto
10438 the BLOCK_VARS list for this outer scope, but are strung off of the
10439 DECL_ARGUMENTS list for the function instead.
10441 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10442 the LABEL_DECL nodes for the function however, and we output DWARF info
10443 for those in decls_for_scope. Just within the `outer_scope' there will be
10444 a BLOCK node representing the function's outermost pair of curly braces,
10445 and any blocks used for the base and member initializers of a C++
10446 constructor function. */
10447 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10449 current_function_has_inlines
= 0;
10450 decls_for_scope (outer_scope
, subr_die
, 0);
10452 #if 0 && defined (MIPS_DEBUGGING_INFO)
10453 if (current_function_has_inlines
)
10455 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10456 if (! comp_unit_has_inlines
)
10458 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10459 comp_unit_has_inlines
= 1;
10466 /* Generate a DIE to represent a declared data object. */
10469 gen_variable_die (decl
, context_die
)
10471 dw_die_ref context_die
;
10473 tree origin
= decl_ultimate_origin (decl
);
10474 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10476 dw_die_ref old_die
= lookup_decl_die (decl
);
10477 int declaration
= (DECL_EXTERNAL (decl
)
10478 || class_scope_p (context_die
));
10480 if (origin
!= NULL
)
10481 add_abstract_origin_attribute (var_die
, origin
);
10483 /* Loop unrolling can create multiple blocks that refer to the same
10484 static variable, so we must test for the DW_AT_declaration flag.
10486 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10487 copy decls and set the DECL_ABSTRACT flag on them instead of
10490 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10491 else if (old_die
&& TREE_STATIC (decl
)
10492 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10494 /* This is a definition of a C++ class level static. */
10495 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10496 if (DECL_NAME (decl
))
10498 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10500 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10501 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10503 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10504 != (unsigned) DECL_SOURCE_LINE (decl
))
10506 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10507 DECL_SOURCE_LINE (decl
));
10512 add_name_and_src_coords_attributes (var_die
, decl
);
10513 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10514 TREE_THIS_VOLATILE (decl
), context_die
);
10516 if (TREE_PUBLIC (decl
))
10517 add_AT_flag (var_die
, DW_AT_external
, 1);
10519 if (DECL_ARTIFICIAL (decl
))
10520 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10522 if (TREE_PROTECTED (decl
))
10523 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10524 else if (TREE_PRIVATE (decl
))
10525 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10529 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10531 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10532 equate_decl_number_to_die (decl
, var_die
);
10534 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10536 add_location_or_const_value_attribute (var_die
, decl
);
10537 add_pubname (decl
, var_die
);
10540 tree_add_const_value_attribute (var_die
, decl
);
10543 /* Generate a DIE to represent a label identifier. */
10546 gen_label_die (decl
, context_die
)
10548 dw_die_ref context_die
;
10550 tree origin
= decl_ultimate_origin (decl
);
10551 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10553 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10555 if (origin
!= NULL
)
10556 add_abstract_origin_attribute (lbl_die
, origin
);
10558 add_name_and_src_coords_attributes (lbl_die
, decl
);
10560 if (DECL_ABSTRACT (decl
))
10561 equate_decl_number_to_die (decl
, lbl_die
);
10564 insn
= DECL_RTL (decl
);
10566 /* Deleted labels are programmer specified labels which have been
10567 eliminated because of various optimisations. We still emit them
10568 here so that it is possible to put breakpoints on them. */
10569 if (GET_CODE (insn
) == CODE_LABEL
10570 || ((GET_CODE (insn
) == NOTE
10571 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10573 /* When optimization is enabled (via -O) some parts of the compiler
10574 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10575 represent source-level labels which were explicitly declared by
10576 the user. This really shouldn't be happening though, so catch
10577 it if it ever does happen. */
10578 if (INSN_DELETED_P (insn
))
10581 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10582 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10587 /* Generate a DIE for a lexical block. */
10590 gen_lexical_block_die (stmt
, context_die
, depth
)
10592 dw_die_ref context_die
;
10595 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
10596 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10598 if (! BLOCK_ABSTRACT (stmt
))
10600 if (BLOCK_FRAGMENT_CHAIN (stmt
))
10604 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
10606 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
10609 add_ranges (chain
);
10610 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
10617 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10618 BLOCK_NUMBER (stmt
));
10619 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
10620 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10621 BLOCK_NUMBER (stmt
));
10622 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
10626 decls_for_scope (stmt
, stmt_die
, depth
);
10629 /* Generate a DIE for an inlined subprogram. */
10632 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
10634 dw_die_ref context_die
;
10637 if (! BLOCK_ABSTRACT (stmt
))
10639 dw_die_ref subr_die
10640 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
10641 tree decl
= block_ultimate_origin (stmt
);
10642 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10644 /* Emit info for the abstract instance first, if we haven't yet. */
10645 dwarf2out_abstract_function (decl
);
10647 add_abstract_origin_attribute (subr_die
, decl
);
10648 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
10649 BLOCK_NUMBER (stmt
));
10650 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
10651 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
10652 BLOCK_NUMBER (stmt
));
10653 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
10654 decls_for_scope (stmt
, subr_die
, depth
);
10655 current_function_has_inlines
= 1;
10658 /* We may get here if we're the outer block of function A that was
10659 inlined into function B that was inlined into function C. When
10660 generating debugging info for C, dwarf2out_abstract_function(B)
10661 would mark all inlined blocks as abstract, including this one.
10662 So, we wouldn't (and shouldn't) expect labels to be generated
10663 for this one. Instead, just emit debugging info for
10664 declarations within the block. This is particularly important
10665 in the case of initializers of arguments passed from B to us:
10666 if they're statement expressions containing declarations, we
10667 wouldn't generate dies for their abstract variables, and then,
10668 when generating dies for the real variables, we'd die (pun
10670 gen_lexical_block_die (stmt
, context_die
, depth
);
10673 /* Generate a DIE for a field in a record, or structure. */
10676 gen_field_die (decl
, context_die
)
10678 dw_die_ref context_die
;
10680 dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
10682 add_name_and_src_coords_attributes (decl_die
, decl
);
10683 add_type_attribute (decl_die
, member_declared_type (decl
),
10684 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
10687 if (DECL_BIT_FIELD_TYPE (decl
))
10689 add_byte_size_attribute (decl_die
, decl
);
10690 add_bit_size_attribute (decl_die
, decl
);
10691 add_bit_offset_attribute (decl_die
, decl
);
10694 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
10695 add_data_member_location_attribute (decl_die
, decl
);
10697 if (DECL_ARTIFICIAL (decl
))
10698 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10700 if (TREE_PROTECTED (decl
))
10701 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10702 else if (TREE_PRIVATE (decl
))
10703 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10707 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10708 Use modified_type_die instead.
10709 We keep this code here just in case these types of DIEs may be needed to
10710 represent certain things in other languages (e.g. Pascal) someday. */
10713 gen_pointer_type_die (type
, context_die
)
10715 dw_die_ref context_die
;
10718 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
10720 equate_type_number_to_die (type
, ptr_die
);
10721 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10722 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10725 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10726 Use modified_type_die instead.
10727 We keep this code here just in case these types of DIEs may be needed to
10728 represent certain things in other languages (e.g. Pascal) someday. */
10731 gen_reference_type_die (type
, context_die
)
10733 dw_die_ref context_die
;
10736 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
10738 equate_type_number_to_die (type
, ref_die
);
10739 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
10740 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
10744 /* Generate a DIE for a pointer to a member type. */
10747 gen_ptr_to_mbr_type_die (type
, context_die
)
10749 dw_die_ref context_die
;
10752 = new_die (DW_TAG_ptr_to_member_type
,
10753 scope_die_for (type
, context_die
), type
);
10755 equate_type_number_to_die (type
, ptr_die
);
10756 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
10757 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
10758 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
10761 /* Generate the DIE for the compilation unit. */
10764 gen_compile_unit_die (filename
)
10765 const char *filename
;
10768 char producer
[250];
10769 const char *wd
= getpwd ();
10770 const char *language_string
= lang_hooks
.name
;
10773 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
10774 add_name_attribute (die
, filename
);
10776 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
10777 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10779 sprintf (producer
, "%s %s", language_string
, version_string
);
10781 #ifdef MIPS_DEBUGGING_INFO
10782 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10783 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10784 not appear in the producer string, the debugger reaches the conclusion
10785 that the object file is stripped and has no debugging information.
10786 To get the MIPS/SGI debugger to believe that there is debugging
10787 information in the object file, we add a -g to the producer string. */
10788 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10789 strcat (producer
, " -g");
10792 add_AT_string (die
, DW_AT_producer
, producer
);
10794 if (strcmp (language_string
, "GNU C++") == 0)
10795 language
= DW_LANG_C_plus_plus
;
10796 else if (strcmp (language_string
, "GNU Ada") == 0)
10797 language
= DW_LANG_Ada83
;
10798 else if (strcmp (language_string
, "GNU F77") == 0)
10799 language
= DW_LANG_Fortran77
;
10800 else if (strcmp (language_string
, "GNU Pascal") == 0)
10801 language
= DW_LANG_Pascal83
;
10802 else if (strcmp (language_string
, "GNU Java") == 0)
10803 language
= DW_LANG_Java
;
10805 language
= DW_LANG_C89
;
10807 add_AT_unsigned (die
, DW_AT_language
, language
);
10811 /* Generate a DIE for a string type. */
10814 gen_string_type_die (type
, context_die
)
10816 dw_die_ref context_die
;
10818 dw_die_ref type_die
10819 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
10821 equate_type_number_to_die (type
, type_die
);
10823 /* ??? Fudge the string length attribute for now.
10824 TODO: add string length info. */
10826 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
10827 bound_representation (upper_bound
, 0, 'u');
10831 /* Generate the DIE for a base class. */
10834 gen_inheritance_die (binfo
, context_die
)
10836 dw_die_ref context_die
;
10838 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
10840 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
10841 add_data_member_location_attribute (die
, binfo
);
10843 if (TREE_VIA_VIRTUAL (binfo
))
10844 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10846 if (TREE_VIA_PUBLIC (binfo
))
10847 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
10848 else if (TREE_VIA_PROTECTED (binfo
))
10849 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10852 /* Generate a DIE for a class member. */
10855 gen_member_die (type
, context_die
)
10857 dw_die_ref context_die
;
10862 /* If this is not an incomplete type, output descriptions of each of its
10863 members. Note that as we output the DIEs necessary to represent the
10864 members of this record or union type, we will also be trying to output
10865 DIEs to represent the *types* of those members. However the `type'
10866 function (above) will specifically avoid generating type DIEs for member
10867 types *within* the list of member DIEs for this (containing) type except
10868 for those types (of members) which are explicitly marked as also being
10869 members of this (containing) type themselves. The g++ front- end can
10870 force any given type to be treated as a member of some other (containing)
10871 type by setting the TYPE_CONTEXT of the given (member) type to point to
10872 the TREE node representing the appropriate (containing) type. */
10874 /* First output info about the base classes. */
10875 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
10877 tree bases
= TYPE_BINFO_BASETYPES (type
);
10878 int n_bases
= TREE_VEC_LENGTH (bases
);
10881 for (i
= 0; i
< n_bases
; i
++)
10882 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
10885 /* Now output info about the data members and type members. */
10886 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
10888 /* If we thought we were generating minimal debug info for TYPE
10889 and then changed our minds, some of the member declarations
10890 may have already been defined. Don't define them again, but
10891 do put them in the right order. */
10893 child
= lookup_decl_die (member
);
10895 splice_child_die (context_die
, child
);
10897 gen_decl_die (member
, context_die
);
10900 /* Now output info about the function members (if any). */
10901 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
10903 /* Don't include clones in the member list. */
10904 if (DECL_ABSTRACT_ORIGIN (member
))
10907 child
= lookup_decl_die (member
);
10909 splice_child_die (context_die
, child
);
10911 gen_decl_die (member
, context_die
);
10915 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10916 is set, we pretend that the type was never defined, so we only get the
10917 member DIEs needed by later specification DIEs. */
10920 gen_struct_or_union_type_die (type
, context_die
)
10922 dw_die_ref context_die
;
10924 dw_die_ref type_die
= lookup_type_die (type
);
10925 dw_die_ref scope_die
= 0;
10927 int complete
= (TYPE_SIZE (type
)
10928 && (! TYPE_STUB_DECL (type
)
10929 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
10931 if (type_die
&& ! complete
)
10934 if (TYPE_CONTEXT (type
) != NULL_TREE
10935 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
10938 scope_die
= scope_die_for (type
, context_die
);
10940 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
10941 /* First occurrence of type or toplevel definition of nested class. */
10943 dw_die_ref old_die
= type_die
;
10945 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
10946 ? DW_TAG_structure_type
: DW_TAG_union_type
,
10948 equate_type_number_to_die (type
, type_die
);
10950 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
10952 add_name_attribute (type_die
, type_tag (type
));
10955 remove_AT (type_die
, DW_AT_declaration
);
10957 /* If this type has been completed, then give it a byte_size attribute and
10958 then give a list of members. */
10961 /* Prevent infinite recursion in cases where the type of some member of
10962 this type is expressed in terms of this type itself. */
10963 TREE_ASM_WRITTEN (type
) = 1;
10964 add_byte_size_attribute (type_die
, type
);
10965 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10966 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10968 /* If the first reference to this type was as the return type of an
10969 inline function, then it may not have a parent. Fix this now. */
10970 if (type_die
->die_parent
== NULL
)
10971 add_child_die (scope_die
, type_die
);
10973 push_decl_scope (type
);
10974 gen_member_die (type
, type_die
);
10977 /* GNU extension: Record what type our vtable lives in. */
10978 if (TYPE_VFIELD (type
))
10980 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
10982 gen_type_die (vtype
, context_die
);
10983 add_AT_die_ref (type_die
, DW_AT_containing_type
,
10984 lookup_type_die (vtype
));
10989 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10991 /* We don't need to do this for function-local types. */
10992 if (TYPE_STUB_DECL (type
)
10993 && ! decl_function_context (TYPE_STUB_DECL (type
)))
10994 VARRAY_PUSH_TREE (incomplete_types
, type
);
10998 /* Generate a DIE for a subroutine _type_. */
11001 gen_subroutine_type_die (type
, context_die
)
11003 dw_die_ref context_die
;
11005 tree return_type
= TREE_TYPE (type
);
11006 dw_die_ref subr_die
11007 = new_die (DW_TAG_subroutine_type
,
11008 scope_die_for (type
, context_die
), type
);
11010 equate_type_number_to_die (type
, subr_die
);
11011 add_prototyped_attribute (subr_die
, type
);
11012 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
11013 gen_formal_types_die (type
, subr_die
);
11016 /* Generate a DIE for a type definition */
11019 gen_typedef_die (decl
, context_die
)
11021 dw_die_ref context_die
;
11023 dw_die_ref type_die
;
11026 if (TREE_ASM_WRITTEN (decl
))
11029 TREE_ASM_WRITTEN (decl
) = 1;
11030 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
11031 origin
= decl_ultimate_origin (decl
);
11032 if (origin
!= NULL
)
11033 add_abstract_origin_attribute (type_die
, origin
);
11038 add_name_and_src_coords_attributes (type_die
, decl
);
11039 if (DECL_ORIGINAL_TYPE (decl
))
11041 type
= DECL_ORIGINAL_TYPE (decl
);
11043 if (type
== TREE_TYPE (decl
))
11046 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11049 type
= TREE_TYPE (decl
);
11051 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11052 TREE_THIS_VOLATILE (decl
), context_die
);
11055 if (DECL_ABSTRACT (decl
))
11056 equate_decl_number_to_die (decl
, type_die
);
11059 /* Generate a type description DIE. */
11062 gen_type_die (type
, context_die
)
11064 dw_die_ref context_die
;
11068 if (type
== NULL_TREE
|| type
== error_mark_node
)
11071 /* We are going to output a DIE to represent the unqualified version
11072 of this type (i.e. without any const or volatile qualifiers) so
11073 get the main variant (i.e. the unqualified version) of this type
11074 now. (Vectors are special because the debugging info is in the
11075 cloned type itself). */
11076 if (TREE_CODE (type
) != VECTOR_TYPE
)
11077 type
= type_main_variant (type
);
11079 if (TREE_ASM_WRITTEN (type
))
11082 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11083 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11085 /* Prevent broken recursion; we can't hand off to the same type. */
11086 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11089 TREE_ASM_WRITTEN (type
) = 1;
11090 gen_decl_die (TYPE_NAME (type
), context_die
);
11094 switch (TREE_CODE (type
))
11100 case REFERENCE_TYPE
:
11101 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11102 ensures that the gen_type_die recursion will terminate even if the
11103 type is recursive. Recursive types are possible in Ada. */
11104 /* ??? We could perhaps do this for all types before the switch
11106 TREE_ASM_WRITTEN (type
) = 1;
11108 /* For these types, all that is required is that we output a DIE (or a
11109 set of DIEs) to represent the "basis" type. */
11110 gen_type_die (TREE_TYPE (type
), context_die
);
11114 /* This code is used for C++ pointer-to-data-member types.
11115 Output a description of the relevant class type. */
11116 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11118 /* Output a description of the type of the object pointed to. */
11119 gen_type_die (TREE_TYPE (type
), context_die
);
11121 /* Now output a DIE to represent this pointer-to-data-member type
11123 gen_ptr_to_mbr_type_die (type
, context_die
);
11127 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11128 gen_set_type_die (type
, context_die
);
11132 gen_type_die (TREE_TYPE (type
), context_die
);
11133 abort (); /* No way to represent these in Dwarf yet! */
11136 case FUNCTION_TYPE
:
11137 /* Force out return type (in case it wasn't forced out already). */
11138 gen_type_die (TREE_TYPE (type
), context_die
);
11139 gen_subroutine_type_die (type
, context_die
);
11143 /* Force out return type (in case it wasn't forced out already). */
11144 gen_type_die (TREE_TYPE (type
), context_die
);
11145 gen_subroutine_type_die (type
, context_die
);
11149 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11151 gen_type_die (TREE_TYPE (type
), context_die
);
11152 gen_string_type_die (type
, context_die
);
11155 gen_array_type_die (type
, context_die
);
11159 gen_array_type_die (type
, context_die
);
11162 case ENUMERAL_TYPE
:
11165 case QUAL_UNION_TYPE
:
11166 /* If this is a nested type whose containing class hasn't been written
11167 out yet, writing it out will cover this one, too. This does not apply
11168 to instantiations of member class templates; they need to be added to
11169 the containing class as they are generated. FIXME: This hurts the
11170 idea of combining type decls from multiple TUs, since we can't predict
11171 what set of template instantiations we'll get. */
11172 if (TYPE_CONTEXT (type
)
11173 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11174 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11176 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11178 if (TREE_ASM_WRITTEN (type
))
11181 /* If that failed, attach ourselves to the stub. */
11182 push_decl_scope (TYPE_CONTEXT (type
));
11183 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11189 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11190 gen_enumeration_type_die (type
, context_die
);
11192 gen_struct_or_union_type_die (type
, context_die
);
11197 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11198 it up if it is ever completed. gen_*_type_die will set it for us
11199 when appropriate. */
11208 /* No DIEs needed for fundamental types. */
11212 /* No Dwarf representation currently defined. */
11219 TREE_ASM_WRITTEN (type
) = 1;
11222 /* Generate a DIE for a tagged type instantiation. */
11225 gen_tagged_type_instantiation_die (type
, context_die
)
11227 dw_die_ref context_die
;
11229 if (type
== NULL_TREE
|| type
== error_mark_node
)
11232 /* We are going to output a DIE to represent the unqualified version of
11233 this type (i.e. without any const or volatile qualifiers) so make sure
11234 that we have the main variant (i.e. the unqualified version) of this
11236 if (type
!= type_main_variant (type
))
11239 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11240 an instance of an unresolved type. */
11242 switch (TREE_CODE (type
))
11247 case ENUMERAL_TYPE
:
11248 gen_inlined_enumeration_type_die (type
, context_die
);
11252 gen_inlined_structure_type_die (type
, context_die
);
11256 case QUAL_UNION_TYPE
:
11257 gen_inlined_union_type_die (type
, context_die
);
11265 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11266 things which are local to the given block. */
11269 gen_block_die (stmt
, context_die
, depth
)
11271 dw_die_ref context_die
;
11274 int must_output_die
= 0;
11277 enum tree_code origin_code
;
11279 /* Ignore blocks never really used to make RTL. */
11280 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11281 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11284 /* If the block is one fragment of a non-contiguous block, do not
11285 process the variables, since they will have been done by the
11286 origin block. Do process subblocks. */
11287 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11291 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11292 gen_block_die (sub
, context_die
, depth
+ 1);
11297 /* Determine the "ultimate origin" of this block. This block may be an
11298 inlined instance of an inlined instance of inline function, so we have
11299 to trace all of the way back through the origin chain to find out what
11300 sort of node actually served as the original seed for the creation of
11301 the current block. */
11302 origin
= block_ultimate_origin (stmt
);
11303 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11305 /* Determine if we need to output any Dwarf DIEs at all to represent this
11307 if (origin_code
== FUNCTION_DECL
)
11308 /* The outer scopes for inlinings *must* always be represented. We
11309 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11310 must_output_die
= 1;
11313 /* In the case where the current block represents an inlining of the
11314 "body block" of an inline function, we must *NOT* output any DIE for
11315 this block because we have already output a DIE to represent the whole
11316 inlined function scope and the "body block" of any function doesn't
11317 really represent a different scope according to ANSI C rules. So we
11318 check here to make sure that this block does not represent a "body
11319 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11320 if (! is_body_block (origin
? origin
: stmt
))
11322 /* Determine if this block directly contains any "significant"
11323 local declarations which we will need to output DIEs for. */
11324 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11325 /* We are not in terse mode so *any* local declaration counts
11326 as being a "significant" one. */
11327 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11329 /* We are in terse mode, so only local (nested) function
11330 definitions count as "significant" local declarations. */
11331 for (decl
= BLOCK_VARS (stmt
);
11332 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11333 if (TREE_CODE (decl
) == FUNCTION_DECL
11334 && DECL_INITIAL (decl
))
11336 must_output_die
= 1;
11342 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11343 DIE for any block which contains no significant local declarations at
11344 all. Rather, in such cases we just call `decls_for_scope' so that any
11345 needed Dwarf info for any sub-blocks will get properly generated. Note
11346 that in terse mode, our definition of what constitutes a "significant"
11347 local declaration gets restricted to include only inlined function
11348 instances and local (nested) function definitions. */
11349 if (must_output_die
)
11351 if (origin_code
== FUNCTION_DECL
)
11352 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11354 gen_lexical_block_die (stmt
, context_die
, depth
);
11357 decls_for_scope (stmt
, context_die
, depth
);
11360 /* Generate all of the decls declared within a given scope and (recursively)
11361 all of its sub-blocks. */
11364 decls_for_scope (stmt
, context_die
, depth
)
11366 dw_die_ref context_die
;
11372 /* Ignore blocks never really used to make RTL. */
11373 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11376 /* Output the DIEs to represent all of the data objects and typedefs
11377 declared directly within this block but not within any nested
11378 sub-blocks. Also, nested function and tag DIEs have been
11379 generated with a parent of NULL; fix that up now. */
11380 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11384 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11385 die
= lookup_decl_die (decl
);
11386 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11387 die
= lookup_type_die (TREE_TYPE (decl
));
11391 if (die
!= NULL
&& die
->die_parent
== NULL
)
11392 add_child_die (context_die
, die
);
11394 gen_decl_die (decl
, context_die
);
11397 /* Output the DIEs to represent all sub-blocks (and the items declared
11398 therein) of this block. */
11399 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11401 subblocks
= BLOCK_CHAIN (subblocks
))
11402 gen_block_die (subblocks
, context_die
, depth
+ 1);
11405 /* Is this a typedef we can avoid emitting? */
11408 is_redundant_typedef (decl
)
11411 if (TYPE_DECL_IS_STUB (decl
))
11414 if (DECL_ARTIFICIAL (decl
)
11415 && DECL_CONTEXT (decl
)
11416 && is_tagged_type (DECL_CONTEXT (decl
))
11417 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11418 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11419 /* Also ignore the artificial member typedef for the class name. */
11425 /* Generate Dwarf debug information for a decl described by DECL. */
11428 gen_decl_die (decl
, context_die
)
11430 dw_die_ref context_die
;
11434 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11437 switch (TREE_CODE (decl
))
11443 /* The individual enumerators of an enum type get output when we output
11444 the Dwarf representation of the relevant enum type itself. */
11447 case FUNCTION_DECL
:
11448 /* Don't output any DIEs to represent mere function declarations,
11449 unless they are class members or explicit block externs. */
11450 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11451 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11454 /* If we're emitting a clone, emit info for the abstract instance. */
11455 if (DECL_ORIGIN (decl
) != decl
)
11456 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11458 /* If we're emitting an out-of-line copy of an inline function,
11459 emit info for the abstract instance and set up to refer to it. */
11460 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11461 && ! class_scope_p (context_die
)
11462 /* dwarf2out_abstract_function won't emit a die if this is just
11463 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11464 that case, because that works only if we have a die. */
11465 && DECL_INITIAL (decl
) != NULL_TREE
)
11467 dwarf2out_abstract_function (decl
);
11468 set_decl_origin_self (decl
);
11471 /* Otherwise we're emitting the primary DIE for this decl. */
11472 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11474 /* Before we describe the FUNCTION_DECL itself, make sure that we
11475 have described its return type. */
11476 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11478 /* And its virtual context. */
11479 if (DECL_VINDEX (decl
) != NULL_TREE
)
11480 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11482 /* And its containing type. */
11483 origin
= decl_class_context (decl
);
11484 if (origin
!= NULL_TREE
)
11485 gen_type_die_for_member (origin
, decl
, context_die
);
11488 /* Now output a DIE to represent the function itself. */
11489 gen_subprogram_die (decl
, context_die
);
11493 /* If we are in terse mode, don't generate any DIEs to represent any
11494 actual typedefs. */
11495 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11498 /* In the special case of a TYPE_DECL node representing the declaration
11499 of some type tag, if the given TYPE_DECL is marked as having been
11500 instantiated from some other (original) TYPE_DECL node (e.g. one which
11501 was generated within the original definition of an inline function) we
11502 have to generate a special (abbreviated) DW_TAG_structure_type,
11503 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11504 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11506 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11510 if (is_redundant_typedef (decl
))
11511 gen_type_die (TREE_TYPE (decl
), context_die
);
11513 /* Output a DIE to represent the typedef itself. */
11514 gen_typedef_die (decl
, context_die
);
11518 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11519 gen_label_die (decl
, context_die
);
11523 /* If we are in terse mode, don't generate any DIEs to represent any
11524 variable declarations or definitions. */
11525 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11528 /* Output any DIEs that are needed to specify the type of this data
11530 gen_type_die (TREE_TYPE (decl
), context_die
);
11532 /* And its containing type. */
11533 origin
= decl_class_context (decl
);
11534 if (origin
!= NULL_TREE
)
11535 gen_type_die_for_member (origin
, decl
, context_die
);
11537 /* Now output the DIE to represent the data object itself. This gets
11538 complicated because of the possibility that the VAR_DECL really
11539 represents an inlined instance of a formal parameter for an inline
11541 origin
= decl_ultimate_origin (decl
);
11542 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11543 gen_formal_parameter_die (decl
, context_die
);
11545 gen_variable_die (decl
, context_die
);
11549 /* Ignore the nameless fields that are used to skip bits but handle C++
11550 anonymous unions. */
11551 if (DECL_NAME (decl
) != NULL_TREE
11552 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11554 gen_type_die (member_declared_type (decl
), context_die
);
11555 gen_field_die (decl
, context_die
);
11560 gen_type_die (TREE_TYPE (decl
), context_die
);
11561 gen_formal_parameter_die (decl
, context_die
);
11564 case NAMESPACE_DECL
:
11565 /* Ignore for now. */
11574 mark_limbo_die_list (ptr
)
11575 void *ptr ATTRIBUTE_UNUSED
;
11577 limbo_die_node
*node
;
11578 for (node
= limbo_die_list
; node
; node
= node
->next
)
11579 ggc_mark_tree (node
->created_for
);
11582 /* Add Ada "use" clause information for SGI Workshop debugger. */
11585 dwarf2out_add_library_unit_info (filename
, context_list
)
11586 const char *filename
;
11587 const char *context_list
;
11589 unsigned int file_index
;
11591 if (filename
!= NULL
)
11593 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11594 tree context_list_decl
11595 = build_decl (LABEL_DECL
, get_identifier (context_list
),
11598 TREE_PUBLIC (context_list_decl
) = TRUE
;
11599 add_name_attribute (unit_die
, context_list
);
11600 file_index
= lookup_filename (filename
);
11601 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
11602 add_pubname (context_list_decl
, unit_die
);
11606 /* Output debug information for global decl DECL. Called from toplev.c after
11607 compilation proper has finished. */
11610 dwarf2out_global_decl (decl
)
11613 /* Output DWARF2 information for file-scope tentative data object
11614 declarations, file-scope (extern) function declarations (which had no
11615 corresponding body) and file-scope tagged type declarations and
11616 definitions which have not yet been forced out. */
11617 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
11618 dwarf2out_decl (decl
);
11621 /* Write the debugging output for DECL. */
11624 dwarf2out_decl (decl
)
11627 dw_die_ref context_die
= comp_unit_die
;
11629 switch (TREE_CODE (decl
))
11634 case FUNCTION_DECL
:
11635 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11636 builtin function. Explicit programmer-supplied declarations of
11637 these same functions should NOT be ignored however. */
11638 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
11641 /* What we would really like to do here is to filter out all mere
11642 file-scope declarations of file-scope functions which are never
11643 referenced later within this translation unit (and keep all of ones
11644 that *are* referenced later on) but we aren't clairvoyant, so we have
11645 no idea which functions will be referenced in the future (i.e. later
11646 on within the current translation unit). So here we just ignore all
11647 file-scope function declarations which are not also definitions. If
11648 and when the debugger needs to know something about these functions,
11649 it will have to hunt around and find the DWARF information associated
11650 with the definition of the function.
11652 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11653 nodes represent definitions and which ones represent mere
11654 declarations. We have to check DECL_INITIAL instead. That's because
11655 the C front-end supports some weird semantics for "extern inline"
11656 function definitions. These can get inlined within the current
11657 translation unit (an thus, we need to generate Dwarf info for their
11658 abstract instances so that the Dwarf info for the concrete inlined
11659 instances can have something to refer to) but the compiler never
11660 generates any out-of-lines instances of such things (despite the fact
11661 that they *are* definitions).
11663 The important point is that the C front-end marks these "extern
11664 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11665 them anyway. Note that the C++ front-end also plays some similar games
11666 for inline function definitions appearing within include files which
11667 also contain `#pragma interface' pragmas. */
11668 if (DECL_INITIAL (decl
) == NULL_TREE
)
11671 /* If we're a nested function, initially use a parent of NULL; if we're
11672 a plain function, this will be fixed up in decls_for_scope. If
11673 we're a method, it will be ignored, since we already have a DIE. */
11674 if (decl_function_context (decl
))
11675 context_die
= NULL
;
11679 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11680 declaration and if the declaration was never even referenced from
11681 within this entire compilation unit. We suppress these DIEs in
11682 order to save space in the .debug section (by eliminating entries
11683 which are probably useless). Note that we must not suppress
11684 block-local extern declarations (whether used or not) because that
11685 would screw-up the debugger's name lookup mechanism and cause it to
11686 miss things which really ought to be in scope at a given point. */
11687 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
11690 /* If we are in terse mode, don't generate any DIEs to represent any
11691 variable declarations or definitions. */
11692 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11697 /* Don't emit stubs for types unless they are needed by other DIEs. */
11698 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
11701 /* Don't bother trying to generate any DIEs to represent any of the
11702 normal built-in types for the language we are compiling. */
11703 if (DECL_SOURCE_LINE (decl
) == 0)
11705 /* OK, we need to generate one for `bool' so GDB knows what type
11706 comparisons have. */
11707 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
11708 == DW_LANG_C_plus_plus
)
11709 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
11710 && ! DECL_IGNORED_P (decl
))
11711 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
11716 /* If we are in terse mode, don't generate any DIEs for types. */
11717 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11720 /* If we're a function-scope tag, initially use a parent of NULL;
11721 this will be fixed up in decls_for_scope. */
11722 if (decl_function_context (decl
))
11723 context_die
= NULL
;
11731 gen_decl_die (decl
, context_die
);
11734 /* Output a marker (i.e. a label) for the beginning of the generated code for
11735 a lexical block. */
11738 dwarf2out_begin_block (line
, blocknum
)
11739 unsigned int line ATTRIBUTE_UNUSED
;
11740 unsigned int blocknum
;
11742 function_section (current_function_decl
);
11743 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
11746 /* Output a marker (i.e. a label) for the end of the generated code for a
11750 dwarf2out_end_block (line
, blocknum
)
11751 unsigned int line ATTRIBUTE_UNUSED
;
11752 unsigned int blocknum
;
11754 function_section (current_function_decl
);
11755 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
11758 /* Returns nonzero if it is appropriate not to emit any debugging
11759 information for BLOCK, because it doesn't contain any instructions.
11761 Don't allow this for blocks with nested functions or local classes
11762 as we would end up with orphans, and in the presence of scheduling
11763 we may end up calling them anyway. */
11766 dwarf2out_ignore_block (block
)
11771 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
11772 if (TREE_CODE (decl
) == FUNCTION_DECL
11773 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
11779 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11780 dwarf2out.c) and return its "index". The index of each (known) filename is
11781 just a unique number which is associated with only that one filename. We
11782 need such numbers for the sake of generating labels (in the .debug_sfnames
11783 section) and references to those files numbers (in the .debug_srcinfo
11784 and.debug_macinfo sections). If the filename given as an argument is not
11785 found in our current list, add it to the list and assign it the next
11786 available unique index number. In order to speed up searches, we remember
11787 the index of the filename was looked up last. This handles the majority of
11791 lookup_filename (file_name
)
11792 const char *file_name
;
11796 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11797 if (strcmp (file_name
, "<internal>") == 0
11798 || strcmp (file_name
, "<built-in>") == 0)
11801 /* Check to see if the file name that was searched on the previous
11802 call matches this file name. If so, return the index. */
11803 if (file_table
.last_lookup_index
!= 0)
11804 if (0 == strcmp (file_name
,
11805 file_table
.table
[file_table
.last_lookup_index
]))
11806 return file_table
.last_lookup_index
;
11808 /* Didn't match the previous lookup, search the table */
11809 for (i
= 1; i
< file_table
.in_use
; i
++)
11810 if (strcmp (file_name
, file_table
.table
[i
]) == 0)
11812 file_table
.last_lookup_index
= i
;
11816 /* Prepare to add a new table entry by making sure there is enough space in
11817 the table to do so. If not, expand the current table. */
11818 if (i
== file_table
.allocated
)
11820 file_table
.allocated
= i
+ FILE_TABLE_INCREMENT
;
11821 file_table
.table
= (char **)
11822 xrealloc (file_table
.table
, file_table
.allocated
* sizeof (char *));
11825 /* Add the new entry to the end of the filename table. */
11826 file_table
.table
[i
] = xstrdup (file_name
);
11827 file_table
.in_use
= i
+ 1;
11828 file_table
.last_lookup_index
= i
;
11830 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11832 fprintf (asm_out_file
, "\t.file %u ", i
);
11833 output_quoted_string (asm_out_file
, file_name
);
11834 fputc ('\n', asm_out_file
);
11843 /* Allocate the initial hunk of the file_table. */
11844 file_table
.table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
11845 file_table
.allocated
= FILE_TABLE_INCREMENT
;
11847 /* Skip the first entry - file numbers begin at 1. */
11848 file_table
.in_use
= 1;
11849 file_table
.last_lookup_index
= 0;
11852 /* Output a label to mark the beginning of a source code line entry
11853 and record information relating to this source line, in
11854 'line_info_table' for later output of the .debug_line section. */
11857 dwarf2out_source_line (line
, filename
)
11859 const char *filename
;
11861 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11863 function_section (current_function_decl
);
11865 /* If requested, emit something human-readable. */
11866 if (flag_debug_asm
)
11867 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
11870 if (DWARF2_ASM_LINE_DEBUG_INFO
)
11872 unsigned file_num
= lookup_filename (filename
);
11874 /* Emit the .loc directive understood by GNU as. */
11875 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
11877 /* Indicate that line number info exists. */
11878 line_info_table_in_use
++;
11880 /* Indicate that multiple line number tables exist. */
11881 if (DECL_SECTION_NAME (current_function_decl
))
11882 separate_line_info_table_in_use
++;
11884 else if (DECL_SECTION_NAME (current_function_decl
))
11886 dw_separate_line_info_ref line_info
;
11887 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
11888 separate_line_info_table_in_use
);
11890 /* expand the line info table if necessary */
11891 if (separate_line_info_table_in_use
11892 == separate_line_info_table_allocated
)
11894 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11895 separate_line_info_table
11896 = (dw_separate_line_info_ref
)
11897 xrealloc (separate_line_info_table
,
11898 separate_line_info_table_allocated
11899 * sizeof (dw_separate_line_info_entry
));
11902 /* Add the new entry at the end of the line_info_table. */
11904 = &separate_line_info_table
[separate_line_info_table_in_use
++];
11905 line_info
->dw_file_num
= lookup_filename (filename
);
11906 line_info
->dw_line_num
= line
;
11907 line_info
->function
= current_funcdef_number
;
11911 dw_line_info_ref line_info
;
11913 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, LINE_CODE_LABEL
,
11914 line_info_table_in_use
);
11916 /* Expand the line info table if necessary. */
11917 if (line_info_table_in_use
== line_info_table_allocated
)
11919 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
11921 = (dw_line_info_ref
)
11922 xrealloc (line_info_table
,
11923 (line_info_table_allocated
11924 * sizeof (dw_line_info_entry
)));
11927 /* Add the new entry at the end of the line_info_table. */
11928 line_info
= &line_info_table
[line_info_table_in_use
++];
11929 line_info
->dw_file_num
= lookup_filename (filename
);
11930 line_info
->dw_line_num
= line
;
11935 /* Record the beginning of a new source file. */
11938 dwarf2out_start_source_file (lineno
, filename
)
11939 unsigned int lineno
;
11940 const char *filename
;
11942 if (flag_eliminate_dwarf2_dups
)
11944 /* Record the beginning of the file for break_out_includes. */
11945 dw_die_ref bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
11946 add_AT_string (bincl_die
, DW_AT_name
, filename
);
11949 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11951 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11952 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
11953 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
11955 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
11956 "Filename we just started");
11960 /* Record the end of a source file. */
11963 dwarf2out_end_source_file (lineno
)
11964 unsigned int lineno ATTRIBUTE_UNUSED
;
11966 if (flag_eliminate_dwarf2_dups
)
11967 /* Record the end of the file for break_out_includes. */
11968 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
11970 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11972 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11973 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
11977 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11978 the tail part of the directive line, i.e. the part which is past the
11979 initial whitespace, #, whitespace, directive-name, whitespace part. */
11982 dwarf2out_define (lineno
, buffer
)
11983 unsigned lineno ATTRIBUTE_UNUSED
;
11984 const char *buffer ATTRIBUTE_UNUSED
;
11986 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
11988 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
11989 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
11990 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
11991 dw2_asm_output_nstring (buffer
, -1, "The macro");
11995 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11996 the tail part of the directive line, i.e. the part which is past the
11997 initial whitespace, #, whitespace, directive-name, whitespace part. */
12000 dwarf2out_undef (lineno
, buffer
)
12001 unsigned lineno ATTRIBUTE_UNUSED
;
12002 const char *buffer ATTRIBUTE_UNUSED
;
12004 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12006 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12007 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
12008 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12009 dw2_asm_output_nstring (buffer
, -1, "The macro");
12013 /* Set up for Dwarf output at the start of compilation. */
12016 dwarf2out_init (main_input_filename
)
12017 const char *main_input_filename
;
12019 init_file_table ();
12021 /* Remember the name of the primary input file. */
12022 primary_filename
= main_input_filename
;
12024 /* Add it to the file table first, under the assumption that we'll
12025 be emitting line number data for it first, which avoids having
12026 to add an initial DW_LNS_set_file. */
12027 lookup_filename (main_input_filename
);
12029 /* Allocate the initial hunk of the decl_die_table. */
12031 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
12032 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
12033 decl_die_table_in_use
= 0;
12035 /* Allocate the initial hunk of the decl_scope_table. */
12036 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
12038 /* Allocate the initial hunk of the abbrev_die_table. */
12040 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
12041 sizeof (dw_die_ref
));
12042 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
12043 /* Zero-th entry is allocated, but unused */
12044 abbrev_die_table_in_use
= 1;
12046 /* Allocate the initial hunk of the line_info_table. */
12048 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
12049 sizeof (dw_line_info_entry
));
12050 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12052 /* Zero-th entry is allocated, but unused */
12053 line_info_table_in_use
= 1;
12055 /* Generate the initial DIE for the .debug section. Note that the (string)
12056 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12057 will (typically) be a relative pathname and that this pathname should be
12058 taken as being relative to the directory from which the compiler was
12059 invoked when the given (base) source file was compiled. */
12060 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
12062 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12064 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12066 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
12068 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12069 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12070 DEBUG_ABBREV_SECTION_LABEL
, 0);
12071 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12072 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12074 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12076 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12077 DEBUG_INFO_SECTION_LABEL
, 0);
12078 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12079 DEBUG_LINE_SECTION_LABEL
, 0);
12080 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12081 DEBUG_RANGES_SECTION_LABEL
, 0);
12082 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12083 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12084 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12085 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12086 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12087 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12089 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12091 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12092 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12093 DEBUG_MACINFO_SECTION_LABEL
, 0);
12094 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12097 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12100 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12104 /* Allocate a string in .debug_str hash table. */
12107 indirect_string_alloc (tab
)
12108 hash_table
*tab ATTRIBUTE_UNUSED
;
12110 struct indirect_string_node
*node
;
12112 node
= xmalloc (sizeof (struct indirect_string_node
));
12113 node
->refcount
= 0;
12115 node
->label
= NULL
;
12117 return (hashnode
) node
;
12120 /* A helper function for dwarf2out_finish called through
12121 ht_forall. Emit one queued .debug_str string. */
12124 output_indirect_string (pfile
, h
, v
)
12125 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12127 const PTR v ATTRIBUTE_UNUSED
;
12129 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12131 if (node
->form
== DW_FORM_strp
)
12133 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12134 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12135 assemble_string ((const char *) HT_STR (&node
->id
),
12136 HT_LEN (&node
->id
) + 1);
12142 /* Output stuff that dwarf requires at the end of every file,
12143 and generate the DWARF-2 debugging info. */
12146 dwarf2out_finish (input_filename
)
12147 const char *input_filename ATTRIBUTE_UNUSED
;
12149 limbo_die_node
*node
, *next_node
;
12150 dw_die_ref die
= 0;
12152 /* Traverse the limbo die list, and add parent/child links. The only
12153 dies without parents that should be here are concrete instances of
12154 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12155 For concrete instances, we can get the parent die from the abstract
12157 for (node
= limbo_die_list
; node
; node
= next_node
)
12159 next_node
= node
->next
;
12162 if (die
->die_parent
== NULL
)
12164 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12168 add_child_die (origin
->die_parent
, die
);
12169 else if (die
== comp_unit_die
)
12171 /* If this was an expression for a bound involved in a function
12172 return type, it may be a SAVE_EXPR for which we weren't able
12173 to find a DIE previously. So try now. */
12174 else if (node
->created_for
12175 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12176 && 0 != (origin
= (lookup_decl_die
12178 (node
->created_for
)))))
12179 add_child_die (origin
, die
);
12180 else if (errorcount
> 0 || sorrycount
> 0)
12181 /* It's OK to be confused by errors in the input. */
12182 add_child_die (comp_unit_die
, die
);
12183 else if (node
->created_for
12184 && ((DECL_P (node
->created_for
)
12185 && (context
= DECL_CONTEXT (node
->created_for
)))
12186 || (TYPE_P (node
->created_for
)
12187 && (context
= TYPE_CONTEXT (node
->created_for
))))
12188 && TREE_CODE (context
) == FUNCTION_DECL
)
12190 /* In certain situations, the lexical block containing a
12191 nested function can be optimized away, which results
12192 in the nested function die being orphaned. Likewise
12193 with the return type of that nested function. Force
12194 this to be a child of the containing function. */
12195 origin
= lookup_decl_die (context
);
12198 add_child_die (origin
, die
);
12207 limbo_die_list
= NULL
;
12209 /* Walk through the list of incomplete types again, trying once more to
12210 emit full debugging info for them. */
12211 retry_incomplete_types ();
12213 /* We need to reverse all the dies before break_out_includes, or
12214 we'll see the end of an include file before the beginning. */
12215 reverse_all_dies (comp_unit_die
);
12217 /* Generate separate CUs for each of the include files we've seen.
12218 They will go into limbo_die_list. */
12219 if (flag_eliminate_dwarf2_dups
)
12220 break_out_includes (comp_unit_die
);
12222 /* Traverse the DIE's and add add sibling attributes to those DIE's
12223 that have children. */
12224 add_sibling_attributes (comp_unit_die
);
12225 for (node
= limbo_die_list
; node
; node
= node
->next
)
12226 add_sibling_attributes (node
->die
);
12228 /* Output a terminator label for the .text section. */
12230 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
12232 /* Output the source line correspondence table. We must do this
12233 even if there is no line information. Otherwise, on an empty
12234 translation unit, we will generate a present, but empty,
12235 .debug_info section. IRIX 6.5 `nm' will then complain when
12236 examining the file. */
12237 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12239 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12240 output_line_info ();
12243 /* Output location list section if necessary. */
12244 if (have_location_lists
)
12246 /* Output the location lists info. */
12247 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12248 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12249 DEBUG_LOC_SECTION_LABEL
, 0);
12250 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12251 output_location_lists (die
);
12252 have_location_lists
= 0;
12255 /* We can only use the low/high_pc attributes if all of the code was
12257 if (separate_line_info_table_in_use
== 0)
12259 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12260 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12263 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12264 "base address". Use zero so that these addresses become absolute. */
12265 else if (have_location_lists
|| ranges_table_in_use
)
12266 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12268 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12269 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12270 debug_line_section_label
);
12272 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12273 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12275 /* Output all of the compilation units. We put the main one last so that
12276 the offsets are available to output_pubnames. */
12277 for (node
= limbo_die_list
; node
; node
= node
->next
)
12278 output_comp_unit (node
->die
);
12280 output_comp_unit (comp_unit_die
);
12282 /* Output the abbreviation table. */
12283 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12284 output_abbrev_section ();
12286 /* Output public names table if necessary. */
12287 if (pubname_table_in_use
)
12289 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12290 output_pubnames ();
12293 /* Output the address range information. We only put functions in the arange
12294 table, so don't write it out if we don't have any. */
12295 if (fde_table_in_use
)
12297 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12301 /* Output ranges section if necessary. */
12302 if (ranges_table_in_use
)
12304 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12305 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12309 /* Have to end the primary source file. */
12310 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12312 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12313 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12314 dw2_asm_output_data (1, 0, "End compilation unit");
12317 /* If we emitted any DW_FORM_strp form attribute, output the string
12319 if (debug_str_hash
)
12320 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12324 /* This should never be used, but its address is needed for comparisons. */
12325 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12327 #endif /* DWARF2_DEBUGGING_INFO */
12329 #include "gt-dwarf2out.h"