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
39 #include "coretypes.h"
45 #include "hard-reg-set.h"
47 #include "insn-config.h"
55 #include "dwarf2out.h"
56 #include "dwarf2asm.h"
62 #include "diagnostic.h"
65 #include "langhooks.h"
66 #include "hashtable.h"
69 #ifdef DWARF2_DEBUGGING_INFO
70 static void dwarf2out_source_line
PARAMS ((unsigned int, const char *));
73 /* DWARF2 Abbreviation Glossary:
74 CFA = Canonical Frame Address
75 a fixed address on the stack which identifies a call frame.
76 We define it to be the value of SP just before the call insn.
77 The CFA register and offset, which may change during the course
78 of the function, are used to calculate its value at runtime.
79 CFI = Call Frame Instruction
80 an instruction for the DWARF2 abstract machine
81 CIE = Common Information Entry
82 information describing information common to one or more FDEs
83 DIE = Debugging Information Entry
84 FDE = Frame Description Entry
85 information describing the stack call frame, in particular,
86 how to restore registers
88 DW_CFA_... = DWARF2 CFA call frame instruction
89 DW_TAG_... = DWARF2 DIE tag */
91 /* Decide whether we want to emit frame unwind information for the current
97 return (write_symbols
== DWARF2_DEBUG
98 || write_symbols
== VMS_AND_DWARF2_DEBUG
99 #ifdef DWARF2_FRAME_INFO
102 #ifdef DWARF2_UNWIND_INFO
103 || flag_unwind_tables
104 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
109 /* The size of the target's pointer type. */
111 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
114 /* Default version of targetm.eh_frame_section. Note this must appear
115 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
119 default_eh_frame_section ()
121 #ifdef EH_FRAME_SECTION_NAME
122 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
123 int fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
124 int per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
125 int lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
129 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
130 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
131 && (per_encoding
& 0x70) != DW_EH_PE_absptr
132 && (per_encoding
& 0x70) != DW_EH_PE_aligned
133 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
134 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
136 named_section_flags (EH_FRAME_SECTION_NAME
, flags
);
138 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
141 tree label
= get_file_function_name ('F');
144 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
145 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, IDENTIFIER_POINTER (label
));
146 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
150 /* Array of RTXes referenced by the debugging information, which therefore
151 must be kept around forever. */
152 static GTY(()) varray_type used_rtx_varray
;
154 /* A pointer to the base of a list of incomplete types which might be
155 completed at some later time. incomplete_types_list needs to be a VARRAY
156 because we want to tell the garbage collector about it. */
157 static GTY(()) varray_type incomplete_types
;
159 /* A pointer to the base of a table of references to declaration
160 scopes. This table is a display which tracks the nesting
161 of declaration scopes at the current scope and containing
162 scopes. This table is used to find the proper place to
163 define type declaration DIE's. */
164 static GTY(()) varray_type decl_scope_table
;
166 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
168 /* How to start an assembler comment. */
169 #ifndef ASM_COMMENT_START
170 #define ASM_COMMENT_START ";#"
173 typedef struct dw_cfi_struct
*dw_cfi_ref
;
174 typedef struct dw_fde_struct
*dw_fde_ref
;
175 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
177 /* Call frames are described using a sequence of Call Frame
178 Information instructions. The register number, offset
179 and address fields are provided as possible operands;
180 their use is selected by the opcode field. */
182 typedef union dw_cfi_oprnd_struct
184 unsigned long dw_cfi_reg_num
;
185 long int dw_cfi_offset
;
186 const char *dw_cfi_addr
;
187 struct dw_loc_descr_struct
*dw_cfi_loc
;
191 typedef struct dw_cfi_struct
193 dw_cfi_ref dw_cfi_next
;
194 enum dwarf_call_frame_info dw_cfi_opc
;
195 dw_cfi_oprnd dw_cfi_oprnd1
;
196 dw_cfi_oprnd dw_cfi_oprnd2
;
200 /* This is how we define the location of the CFA. We use to handle it
201 as REG + OFFSET all the time, but now it can be more complex.
202 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
203 Instead of passing around REG and OFFSET, we pass a copy
204 of this structure. */
205 typedef struct cfa_loc
210 int indirect
; /* 1 if CFA is accessed via a dereference. */
213 /* All call frame descriptions (FDE's) in the GCC generated DWARF
214 refer to a single Common Information Entry (CIE), defined at
215 the beginning of the .debug_frame section. This use of a single
216 CIE obviates the need to keep track of multiple CIE's
217 in the DWARF generation routines below. */
219 typedef struct dw_fde_struct
221 const char *dw_fde_begin
;
222 const char *dw_fde_current_label
;
223 const char *dw_fde_end
;
224 dw_cfi_ref dw_fde_cfi
;
225 unsigned funcdef_number
;
226 unsigned all_throwers_are_sibcalls
: 1;
227 unsigned nothrow
: 1;
228 unsigned uses_eh_lsda
: 1;
232 /* Maximum size (in bytes) of an artificially generated label. */
233 #define MAX_ARTIFICIAL_LABEL_BYTES 30
235 /* The size of addresses as they appear in the Dwarf 2 data.
236 Some architectures use word addresses to refer to code locations,
237 but Dwarf 2 info always uses byte addresses. On such machines,
238 Dwarf 2 addresses need to be larger than the architecture's
240 #ifndef DWARF2_ADDR_SIZE
241 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
244 /* The size in bytes of a DWARF field indicating an offset or length
245 relative to a debug info section, specified to be 4 bytes in the
246 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
249 #ifndef DWARF_OFFSET_SIZE
250 #define DWARF_OFFSET_SIZE 4
253 #define DWARF_VERSION 2
255 /* Round SIZE up to the nearest BOUNDARY. */
256 #define DWARF_ROUND(SIZE,BOUNDARY) \
257 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
259 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
260 #ifndef DWARF_CIE_DATA_ALIGNMENT
261 #ifdef STACK_GROWS_DOWNWARD
262 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
264 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
268 /* A pointer to the base of a table that contains frame description
269 information for each routine. */
270 static dw_fde_ref fde_table
;
272 /* Number of elements currently allocated for fde_table. */
273 static unsigned fde_table_allocated
;
275 /* Number of elements in fde_table currently in use. */
276 static unsigned fde_table_in_use
;
278 /* Size (in elements) of increments by which we may expand the
280 #define FDE_TABLE_INCREMENT 256
282 /* A list of call frame insns for the CIE. */
283 static dw_cfi_ref cie_cfi_head
;
285 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
286 attribute that accelerates the lookup of the FDE associated
287 with the subprogram. This variable holds the table index of the FDE
288 associated with the current function (body) definition. */
289 static unsigned current_funcdef_fde
;
291 struct ht
*debug_str_hash
;
293 struct indirect_string_node
295 struct ht_identifier id
;
296 unsigned int refcount
;
301 /* Forward declarations for functions defined in this file. */
303 static char *stripattributes
PARAMS ((const char *));
304 static const char *dwarf_cfi_name
PARAMS ((unsigned));
305 static dw_cfi_ref new_cfi
PARAMS ((void));
306 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
307 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
308 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
,
310 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
311 static void reg_save
PARAMS ((const char *, unsigned,
313 static void initial_return_save
PARAMS ((rtx
));
314 static long stack_adjust_offset
PARAMS ((rtx
));
315 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
, int));
316 static void output_call_frame_info
PARAMS ((int));
317 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
318 static void queue_reg_save
PARAMS ((const char *, rtx
, long));
319 static void flush_queued_reg_saves
PARAMS ((void));
320 static bool clobbers_queued_reg_save
PARAMS ((rtx
));
321 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
323 /* Support for complex CFA locations. */
324 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
325 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
326 struct dw_loc_descr_struct
*));
327 static struct dw_loc_descr_struct
*build_cfa_loc
328 PARAMS ((dw_cfa_location
*));
329 static void def_cfa_1
PARAMS ((const char *,
332 /* How to start an assembler comment. */
333 #ifndef ASM_COMMENT_START
334 #define ASM_COMMENT_START ";#"
337 /* Data and reference forms for relocatable data. */
338 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
339 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
341 #ifndef DEBUG_FRAME_SECTION
342 #define DEBUG_FRAME_SECTION ".debug_frame"
345 #ifndef FUNC_BEGIN_LABEL
346 #define FUNC_BEGIN_LABEL "LFB"
349 #ifndef FUNC_END_LABEL
350 #define FUNC_END_LABEL "LFE"
353 #define FRAME_BEGIN_LABEL "Lframe"
354 #define CIE_AFTER_SIZE_LABEL "LSCIE"
355 #define CIE_END_LABEL "LECIE"
356 #define FDE_LABEL "LSFDE"
357 #define FDE_AFTER_SIZE_LABEL "LASFDE"
358 #define FDE_END_LABEL "LEFDE"
359 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
360 #define LINE_NUMBER_END_LABEL "LELT"
361 #define LN_PROLOG_AS_LABEL "LASLTP"
362 #define LN_PROLOG_END_LABEL "LELTP"
363 #define DIE_LABEL_PREFIX "DW"
365 /* The DWARF 2 CFA column which tracks the return address. Normally this
366 is the column for PC, or the first column after all of the hard
368 #ifndef DWARF_FRAME_RETURN_COLUMN
370 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
372 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
376 /* The mapping from gcc register number to DWARF 2 CFA column number. By
377 default, we just provide columns for all registers. */
378 #ifndef DWARF_FRAME_REGNUM
379 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
382 /* The offset from the incoming value of %sp to the top of the stack frame
383 for the current function. */
384 #ifndef INCOMING_FRAME_SP_OFFSET
385 #define INCOMING_FRAME_SP_OFFSET 0
388 /* Hook used by __throw. */
391 expand_builtin_dwarf_fp_regnum ()
393 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
396 /* Return a pointer to a copy of the section string name S with all
397 attributes stripped off, and an asterisk prepended (for assemble_name). */
403 char *stripped
= xmalloc (strlen (s
) + 2);
408 while (*s
&& *s
!= ',')
415 /* Generate code to initialize the register size table. */
418 expand_builtin_init_dwarf_reg_sizes (address
)
422 enum machine_mode mode
= TYPE_MODE (char_type_node
);
423 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
424 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
426 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
427 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
429 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
430 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
435 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
439 /* Convert a DWARF call frame info. operation to its string name */
442 dwarf_cfi_name (cfi_opc
)
447 case DW_CFA_advance_loc
:
448 return "DW_CFA_advance_loc";
450 return "DW_CFA_offset";
452 return "DW_CFA_restore";
456 return "DW_CFA_set_loc";
457 case DW_CFA_advance_loc1
:
458 return "DW_CFA_advance_loc1";
459 case DW_CFA_advance_loc2
:
460 return "DW_CFA_advance_loc2";
461 case DW_CFA_advance_loc4
:
462 return "DW_CFA_advance_loc4";
463 case DW_CFA_offset_extended
:
464 return "DW_CFA_offset_extended";
465 case DW_CFA_restore_extended
:
466 return "DW_CFA_restore_extended";
467 case DW_CFA_undefined
:
468 return "DW_CFA_undefined";
469 case DW_CFA_same_value
:
470 return "DW_CFA_same_value";
471 case DW_CFA_register
:
472 return "DW_CFA_register";
473 case DW_CFA_remember_state
:
474 return "DW_CFA_remember_state";
475 case DW_CFA_restore_state
:
476 return "DW_CFA_restore_state";
478 return "DW_CFA_def_cfa";
479 case DW_CFA_def_cfa_register
:
480 return "DW_CFA_def_cfa_register";
481 case DW_CFA_def_cfa_offset
:
482 return "DW_CFA_def_cfa_offset";
485 case DW_CFA_def_cfa_expression
:
486 return "DW_CFA_def_cfa_expression";
487 case DW_CFA_expression
:
488 return "DW_CFA_expression";
489 case DW_CFA_offset_extended_sf
:
490 return "DW_CFA_offset_extended_sf";
491 case DW_CFA_def_cfa_sf
:
492 return "DW_CFA_def_cfa_sf";
493 case DW_CFA_def_cfa_offset_sf
:
494 return "DW_CFA_def_cfa_offset_sf";
496 /* SGI/MIPS specific */
497 case DW_CFA_MIPS_advance_loc8
:
498 return "DW_CFA_MIPS_advance_loc8";
501 case DW_CFA_GNU_window_save
:
502 return "DW_CFA_GNU_window_save";
503 case DW_CFA_GNU_args_size
:
504 return "DW_CFA_GNU_args_size";
505 case DW_CFA_GNU_negative_offset_extended
:
506 return "DW_CFA_GNU_negative_offset_extended";
509 return "DW_CFA_<unknown>";
513 /* Return a pointer to a newly allocated Call Frame Instruction. */
515 static inline dw_cfi_ref
518 dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
520 cfi
->dw_cfi_next
= NULL
;
521 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
522 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
527 /* Add a Call Frame Instruction to list of instructions. */
530 add_cfi (list_head
, cfi
)
531 dw_cfi_ref
*list_head
;
536 /* Find the end of the chain. */
537 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
543 /* Generate a new label for the CFI info to refer to. */
546 dwarf2out_cfi_label ()
548 static char label
[20];
549 static unsigned long label_num
= 0;
551 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
552 ASM_OUTPUT_LABEL (asm_out_file
, label
);
556 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
557 or to the CIE if LABEL is NULL. */
560 add_fde_cfi (label
, cfi
)
566 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
569 label
= dwarf2out_cfi_label ();
571 if (fde
->dw_fde_current_label
== NULL
572 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
576 fde
->dw_fde_current_label
= label
= xstrdup (label
);
578 /* Set the location counter to the new label. */
580 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
581 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
582 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
585 add_cfi (&fde
->dw_fde_cfi
, cfi
);
589 add_cfi (&cie_cfi_head
, cfi
);
592 /* Subroutine of lookup_cfa. */
595 lookup_cfa_1 (cfi
, loc
)
597 dw_cfa_location
*loc
;
599 switch (cfi
->dw_cfi_opc
)
601 case DW_CFA_def_cfa_offset
:
602 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
604 case DW_CFA_def_cfa_register
:
605 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
608 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
609 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
611 case DW_CFA_def_cfa_expression
:
612 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
619 /* Find the previous value for the CFA. */
623 dw_cfa_location
*loc
;
627 loc
->reg
= (unsigned long) -1;
630 loc
->base_offset
= 0;
632 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
633 lookup_cfa_1 (cfi
, loc
);
635 if (fde_table_in_use
)
637 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
638 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
639 lookup_cfa_1 (cfi
, loc
);
643 /* The current rule for calculating the DWARF2 canonical frame address. */
644 static dw_cfa_location cfa
;
646 /* The register used for saving registers to the stack, and its offset
648 static dw_cfa_location cfa_store
;
650 /* The running total of the size of arguments pushed onto the stack. */
651 static long args_size
;
653 /* The last args_size we actually output. */
654 static long old_args_size
;
656 /* Entry point to update the canonical frame address (CFA).
657 LABEL is passed to add_fde_cfi. The value of CFA is now to be
658 calculated from REG+OFFSET. */
661 dwarf2out_def_cfa (label
, reg
, offset
)
671 def_cfa_1 (label
, &loc
);
674 /* This routine does the actual work. The CFA is now calculated from
675 the dw_cfa_location structure. */
678 def_cfa_1 (label
, loc_p
)
680 dw_cfa_location
*loc_p
;
683 dw_cfa_location old_cfa
, loc
;
688 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
689 cfa_store
.offset
= loc
.offset
;
691 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
692 lookup_cfa (&old_cfa
);
694 /* If nothing changed, no need to issue any call frame instructions. */
695 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
696 && loc
.indirect
== old_cfa
.indirect
697 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
702 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
704 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
705 indicating the CFA register did not change but the offset
707 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
708 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
711 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
712 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
715 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
716 indicating the CFA register has changed to <register> but the
717 offset has not changed. */
718 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
719 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
723 else if (loc
.indirect
== 0)
725 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
726 indicating the CFA register has changed to <register> with
727 the specified offset. */
728 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
729 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
730 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
734 /* Construct a DW_CFA_def_cfa_expression instruction to
735 calculate the CFA using a full location expression since no
736 register-offset pair is available. */
737 struct dw_loc_descr_struct
*loc_list
;
739 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
740 loc_list
= build_cfa_loc (&loc
);
741 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
744 add_fde_cfi (label
, cfi
);
747 /* Add the CFI for saving a register. REG is the CFA column number.
748 LABEL is passed to add_fde_cfi.
749 If SREG is -1, the register is saved at OFFSET from the CFA;
750 otherwise it is saved in SREG. */
753 reg_save (label
, reg
, sreg
, offset
)
759 dw_cfi_ref cfi
= new_cfi ();
761 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
763 /* The following comparison is correct. -1 is used to indicate that
764 the value isn't a register number. */
765 if (sreg
== (unsigned int) -1)
768 /* The register number won't fit in 6 bits, so we have to use
770 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
772 cfi
->dw_cfi_opc
= DW_CFA_offset
;
774 #ifdef ENABLE_CHECKING
776 /* If we get an offset that is not a multiple of
777 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
778 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
780 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
782 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
786 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
788 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
790 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
792 else if (sreg
== reg
)
793 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
797 cfi
->dw_cfi_opc
= DW_CFA_register
;
798 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
801 add_fde_cfi (label
, cfi
);
804 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
805 This CFI tells the unwinder that it needs to restore the window registers
806 from the previous frame's window save area.
808 ??? Perhaps we should note in the CIE where windows are saved (instead of
809 assuming 0(cfa)) and what registers are in the window. */
812 dwarf2out_window_save (label
)
815 dw_cfi_ref cfi
= new_cfi ();
817 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
818 add_fde_cfi (label
, cfi
);
821 /* Add a CFI to update the running total of the size of arguments
822 pushed onto the stack. */
825 dwarf2out_args_size (label
, size
)
831 if (size
== old_args_size
)
834 old_args_size
= size
;
837 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
838 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
839 add_fde_cfi (label
, cfi
);
842 /* Entry point for saving a register to the stack. REG is the GCC register
843 number. LABEL and OFFSET are passed to reg_save. */
846 dwarf2out_reg_save (label
, reg
, offset
)
851 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
854 /* Entry point for saving the return address in the stack.
855 LABEL and OFFSET are passed to reg_save. */
858 dwarf2out_return_save (label
, offset
)
862 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
865 /* Entry point for saving the return address in a register.
866 LABEL and SREG are passed to reg_save. */
869 dwarf2out_return_reg (label
, sreg
)
873 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
876 /* Record the initial position of the return address. RTL is
877 INCOMING_RETURN_ADDR_RTX. */
880 initial_return_save (rtl
)
883 unsigned int reg
= (unsigned int) -1;
884 HOST_WIDE_INT offset
= 0;
886 switch (GET_CODE (rtl
))
889 /* RA is in a register. */
890 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
894 /* RA is on the stack. */
896 switch (GET_CODE (rtl
))
899 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
905 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
907 offset
= INTVAL (XEXP (rtl
, 1));
911 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
913 offset
= -INTVAL (XEXP (rtl
, 1));
923 /* The return address is at some offset from any value we can
924 actually load. For instance, on the SPARC it is in %i7+8. Just
925 ignore the offset for now; it doesn't matter for unwinding frames. */
926 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
928 initial_return_save (XEXP (rtl
, 0));
935 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
938 /* Given a SET, calculate the amount of stack adjustment it
942 stack_adjust_offset (pattern
)
945 rtx src
= SET_SRC (pattern
);
946 rtx dest
= SET_DEST (pattern
);
947 HOST_WIDE_INT offset
= 0;
950 if (dest
== stack_pointer_rtx
)
952 /* (set (reg sp) (plus (reg sp) (const_int))) */
953 code
= GET_CODE (src
);
954 if (! (code
== PLUS
|| code
== MINUS
)
955 || XEXP (src
, 0) != stack_pointer_rtx
956 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
959 offset
= INTVAL (XEXP (src
, 1));
963 else if (GET_CODE (dest
) == MEM
)
965 /* (set (mem (pre_dec (reg sp))) (foo)) */
966 src
= XEXP (dest
, 0);
967 code
= GET_CODE (src
);
973 if (XEXP (src
, 0) == stack_pointer_rtx
)
975 rtx val
= XEXP (XEXP (src
, 1), 1);
976 /* We handle only adjustments by constant amount. */
977 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
978 GET_CODE (val
) != CONST_INT
)
980 offset
= -INTVAL (val
);
987 if (XEXP (src
, 0) == stack_pointer_rtx
)
989 offset
= GET_MODE_SIZE (GET_MODE (dest
));
996 if (XEXP (src
, 0) == stack_pointer_rtx
)
998 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1013 /* Check INSN to see if it looks like a push or a stack adjustment, and
1014 make a note of it if it does. EH uses this information to find out how
1015 much extra space it needs to pop off the stack. */
1018 dwarf2out_stack_adjust (insn
)
1021 HOST_WIDE_INT offset
;
1025 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1027 /* Extract the size of the args from the CALL rtx itself. */
1028 insn
= PATTERN (insn
);
1029 if (GET_CODE (insn
) == PARALLEL
)
1030 insn
= XVECEXP (insn
, 0, 0);
1031 if (GET_CODE (insn
) == SET
)
1032 insn
= SET_SRC (insn
);
1033 if (GET_CODE (insn
) != CALL
)
1036 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1040 /* If only calls can throw, and we have a frame pointer,
1041 save up adjustments until we see the CALL_INSN. */
1042 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1045 if (GET_CODE (insn
) == BARRIER
)
1047 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1048 the compiler will have already emitted a stack adjustment, but
1049 doesn't bother for calls to noreturn functions. */
1050 #ifdef STACK_GROWS_DOWNWARD
1051 offset
= -args_size
;
1056 else if (GET_CODE (PATTERN (insn
)) == SET
)
1057 offset
= stack_adjust_offset (PATTERN (insn
));
1058 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1059 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1061 /* There may be stack adjustments inside compound insns. Search
1063 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1064 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1065 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1073 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1074 cfa
.offset
+= offset
;
1076 #ifndef STACK_GROWS_DOWNWARD
1080 args_size
+= offset
;
1084 label
= dwarf2out_cfi_label ();
1085 def_cfa_1 (label
, &cfa
);
1086 dwarf2out_args_size (label
, args_size
);
1089 /* We delay emitting a register save until either (a) we reach the end
1090 of the prologue or (b) the register is clobbered. This clusters
1091 register saves so that there are fewer pc advances. */
1093 struct queued_reg_save
1095 struct queued_reg_save
*next
;
1100 static struct queued_reg_save
*queued_reg_saves
;
1101 static const char *last_reg_save_label
;
1104 queue_reg_save (label
, reg
, offset
)
1109 struct queued_reg_save
*q
= (struct queued_reg_save
*) xmalloc (sizeof (*q
));
1111 q
->next
= queued_reg_saves
;
1113 q
->cfa_offset
= offset
;
1114 queued_reg_saves
= q
;
1116 last_reg_save_label
= label
;
1120 flush_queued_reg_saves ()
1122 struct queued_reg_save
*q
, *next
;
1124 for (q
= queued_reg_saves
; q
; q
= next
)
1126 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1131 queued_reg_saves
= NULL
;
1132 last_reg_save_label
= NULL
;
1136 clobbers_queued_reg_save (insn
)
1139 struct queued_reg_save
*q
;
1141 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1142 if (modified_in_p (q
->reg
, insn
))
1149 /* A temporary register holding an integral value used in adjusting SP
1150 or setting up the store_reg. The "offset" field holds the integer
1151 value, not an offset. */
1152 static dw_cfa_location cfa_temp
;
1154 /* Record call frame debugging information for an expression EXPR,
1155 which either sets SP or FP (adjusting how we calculate the frame
1156 address) or saves a register to the stack. LABEL indicates the
1159 This function encodes a state machine mapping rtxes to actions on
1160 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1161 users need not read the source code.
1163 The High-Level Picture
1165 Changes in the register we use to calculate the CFA: Currently we
1166 assume that if you copy the CFA register into another register, we
1167 should take the other one as the new CFA register; this seems to
1168 work pretty well. If it's wrong for some target, it's simple
1169 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1171 Changes in the register we use for saving registers to the stack:
1172 This is usually SP, but not always. Again, we deduce that if you
1173 copy SP into another register (and SP is not the CFA register),
1174 then the new register is the one we will be using for register
1175 saves. This also seems to work.
1177 Register saves: There's not much guesswork about this one; if
1178 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1179 register save, and the register used to calculate the destination
1180 had better be the one we think we're using for this purpose.
1182 Except: If the register being saved is the CFA register, and the
1183 offset is nonzero, we are saving the CFA, so we assume we have to
1184 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1185 the intent is to save the value of SP from the previous frame.
1187 Invariants / Summaries of Rules
1189 cfa current rule for calculating the CFA. It usually
1190 consists of a register and an offset.
1191 cfa_store register used by prologue code to save things to the stack
1192 cfa_store.offset is the offset from the value of
1193 cfa_store.reg to the actual CFA
1194 cfa_temp register holding an integral value. cfa_temp.offset
1195 stores the value, which will be used to adjust the
1196 stack pointer. cfa_temp is also used like cfa_store,
1197 to track stores to the stack via fp or a temp reg.
1199 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1200 with cfa.reg as the first operand changes the cfa.reg and its
1201 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1204 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1205 expression yielding a constant. This sets cfa_temp.reg
1206 and cfa_temp.offset.
1208 Rule 5: Create a new register cfa_store used to save items to the
1211 Rules 10-14: Save a register to the stack. Define offset as the
1212 difference of the original location and cfa_store's
1213 location (or cfa_temp's location if cfa_temp is used).
1217 "{a,b}" indicates a choice of a xor b.
1218 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1221 (set <reg1> <reg2>:cfa.reg)
1222 effects: cfa.reg = <reg1>
1223 cfa.offset unchanged
1224 cfa_temp.reg = <reg1>
1225 cfa_temp.offset = cfa.offset
1228 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1229 {<const_int>,<reg>:cfa_temp.reg}))
1230 effects: cfa.reg = sp if fp used
1231 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1232 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1233 if cfa_store.reg==sp
1236 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1237 effects: cfa.reg = fp
1238 cfa_offset += +/- <const_int>
1241 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1242 constraints: <reg1> != fp
1244 effects: cfa.reg = <reg1>
1245 cfa_temp.reg = <reg1>
1246 cfa_temp.offset = cfa.offset
1249 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1250 constraints: <reg1> != fp
1252 effects: cfa_store.reg = <reg1>
1253 cfa_store.offset = cfa.offset - cfa_temp.offset
1256 (set <reg> <const_int>)
1257 effects: cfa_temp.reg = <reg>
1258 cfa_temp.offset = <const_int>
1261 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1262 effects: cfa_temp.reg = <reg1>
1263 cfa_temp.offset |= <const_int>
1266 (set <reg> (high <exp>))
1270 (set <reg> (lo_sum <exp> <const_int>))
1271 effects: cfa_temp.reg = <reg>
1272 cfa_temp.offset = <const_int>
1275 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1276 effects: cfa_store.offset -= <const_int>
1277 cfa.offset = cfa_store.offset if cfa.reg == sp
1279 cfa.base_offset = -cfa_store.offset
1282 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1283 effects: cfa_store.offset += -/+ mode_size(mem)
1284 cfa.offset = cfa_store.offset if cfa.reg == sp
1286 cfa.base_offset = -cfa_store.offset
1289 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1292 effects: cfa.reg = <reg1>
1293 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1296 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1297 effects: cfa.reg = <reg1>
1298 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1301 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1302 effects: cfa.reg = <reg1>
1303 cfa.base_offset = -cfa_temp.offset
1304 cfa_temp.offset -= mode_size(mem) */
1307 dwarf2out_frame_debug_expr (expr
, label
)
1312 HOST_WIDE_INT offset
;
1314 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1315 the PARALLEL independently. The first element is always processed if
1316 it is a SET. This is for backward compatibility. Other elements
1317 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1318 flag is set in them. */
1319 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1322 int limit
= XVECLEN (expr
, 0);
1324 for (par_index
= 0; par_index
< limit
; par_index
++)
1325 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1326 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1328 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1333 if (GET_CODE (expr
) != SET
)
1336 src
= SET_SRC (expr
);
1337 dest
= SET_DEST (expr
);
1339 switch (GET_CODE (dest
))
1343 /* Update the CFA rule wrt SP or FP. Make sure src is
1344 relative to the current CFA register. */
1345 switch (GET_CODE (src
))
1347 /* Setting FP from SP. */
1349 if (cfa
.reg
== (unsigned) REGNO (src
))
1355 /* We used to require that dest be either SP or FP, but the
1356 ARM copies SP to a temporary register, and from there to
1357 FP. So we just rely on the backends to only set
1358 RTX_FRAME_RELATED_P on appropriate insns. */
1359 cfa
.reg
= REGNO (dest
);
1360 cfa_temp
.reg
= cfa
.reg
;
1361 cfa_temp
.offset
= cfa
.offset
;
1367 if (dest
== stack_pointer_rtx
)
1371 switch (GET_CODE (XEXP (src
, 1)))
1374 offset
= INTVAL (XEXP (src
, 1));
1377 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1379 offset
= cfa_temp
.offset
;
1385 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1387 /* Restoring SP from FP in the epilogue. */
1388 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1390 cfa
.reg
= STACK_POINTER_REGNUM
;
1392 else if (GET_CODE (src
) == LO_SUM
)
1393 /* Assume we've set the source reg of the LO_SUM from sp. */
1395 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1398 if (GET_CODE (src
) != MINUS
)
1400 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1401 cfa
.offset
+= offset
;
1402 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1403 cfa_store
.offset
+= offset
;
1405 else if (dest
== hard_frame_pointer_rtx
)
1408 /* Either setting the FP from an offset of the SP,
1409 or adjusting the FP */
1410 if (! frame_pointer_needed
)
1413 if (GET_CODE (XEXP (src
, 0)) == REG
1414 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1415 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1417 offset
= INTVAL (XEXP (src
, 1));
1418 if (GET_CODE (src
) != MINUS
)
1420 cfa
.offset
+= offset
;
1421 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1428 if (GET_CODE (src
) == MINUS
)
1432 if (GET_CODE (XEXP (src
, 0)) == REG
1433 && REGNO (XEXP (src
, 0)) == cfa
.reg
1434 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1436 /* Setting a temporary CFA register that will be copied
1437 into the FP later on. */
1438 offset
= - INTVAL (XEXP (src
, 1));
1439 cfa
.offset
+= offset
;
1440 cfa
.reg
= REGNO (dest
);
1441 /* Or used to save regs to the stack. */
1442 cfa_temp
.reg
= cfa
.reg
;
1443 cfa_temp
.offset
= cfa
.offset
;
1447 else if (GET_CODE (XEXP (src
, 0)) == REG
1448 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1449 && XEXP (src
, 1) == stack_pointer_rtx
)
1451 /* Setting a scratch register that we will use instead
1452 of SP for saving registers to the stack. */
1453 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1455 cfa_store
.reg
= REGNO (dest
);
1456 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1460 else if (GET_CODE (src
) == LO_SUM
1461 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1463 cfa_temp
.reg
= REGNO (dest
);
1464 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1473 cfa_temp
.reg
= REGNO (dest
);
1474 cfa_temp
.offset
= INTVAL (src
);
1479 if (GET_CODE (XEXP (src
, 0)) != REG
1480 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1481 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1484 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1485 cfa_temp
.reg
= REGNO (dest
);
1486 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1489 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1490 which will fill in all of the bits. */
1499 def_cfa_1 (label
, &cfa
);
1503 if (GET_CODE (src
) != REG
)
1506 /* Saving a register to the stack. Make sure dest is relative to the
1508 switch (GET_CODE (XEXP (dest
, 0)))
1513 /* We can't handle variable size modifications. */
1514 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1516 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1518 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1519 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1522 cfa_store
.offset
+= offset
;
1523 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1524 cfa
.offset
= cfa_store
.offset
;
1526 offset
= -cfa_store
.offset
;
1532 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1533 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1536 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1537 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1540 cfa_store
.offset
+= offset
;
1541 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1542 cfa
.offset
= cfa_store
.offset
;
1544 offset
= -cfa_store
.offset
;
1548 /* With an offset. */
1552 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1554 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1555 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1558 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1559 offset
-= cfa_store
.offset
;
1560 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1561 offset
-= cfa_temp
.offset
;
1567 /* Without an offset. */
1569 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1570 offset
= -cfa_store
.offset
;
1571 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1572 offset
= -cfa_temp
.offset
;
1579 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1581 offset
= -cfa_temp
.offset
;
1582 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1589 if (REGNO (src
) != STACK_POINTER_REGNUM
1590 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1591 && (unsigned) REGNO (src
) == cfa
.reg
)
1593 /* We're storing the current CFA reg into the stack. */
1595 if (cfa
.offset
== 0)
1597 /* If the source register is exactly the CFA, assume
1598 we're saving SP like any other register; this happens
1600 def_cfa_1 (label
, &cfa
);
1601 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1606 /* Otherwise, we'll need to look in the stack to
1607 calculate the CFA. */
1608 rtx x
= XEXP (dest
, 0);
1610 if (GET_CODE (x
) != REG
)
1612 if (GET_CODE (x
) != REG
)
1615 cfa
.reg
= REGNO (x
);
1616 cfa
.base_offset
= offset
;
1618 def_cfa_1 (label
, &cfa
);
1623 def_cfa_1 (label
, &cfa
);
1624 queue_reg_save (label
, src
, offset
);
1632 /* Record call frame debugging information for INSN, which either
1633 sets SP or FP (adjusting how we calculate the frame address) or saves a
1634 register to the stack. If INSN is NULL_RTX, initialize our state. */
1637 dwarf2out_frame_debug (insn
)
1643 if (insn
== NULL_RTX
)
1645 /* Flush any queued register saves. */
1646 flush_queued_reg_saves ();
1648 /* Set up state for generating call frame debug info. */
1650 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1653 cfa
.reg
= STACK_POINTER_REGNUM
;
1656 cfa_temp
.offset
= 0;
1660 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1661 flush_queued_reg_saves ();
1663 if (! RTX_FRAME_RELATED_P (insn
))
1665 if (!ACCUMULATE_OUTGOING_ARGS
)
1666 dwarf2out_stack_adjust (insn
);
1671 label
= dwarf2out_cfi_label ();
1672 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1674 insn
= XEXP (src
, 0);
1676 insn
= PATTERN (insn
);
1678 dwarf2out_frame_debug_expr (insn
, label
);
1681 /* Output a Call Frame Information opcode and its operand(s). */
1684 output_cfi (cfi
, fde
, for_eh
)
1689 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1690 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1691 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1692 "DW_CFA_advance_loc 0x%lx",
1693 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1694 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1696 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1697 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1698 "DW_CFA_offset, column 0x%lx",
1699 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1700 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1702 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1703 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1704 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1705 "DW_CFA_restore, column 0x%lx",
1706 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1709 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1710 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1712 switch (cfi
->dw_cfi_opc
)
1714 case DW_CFA_set_loc
:
1716 dw2_asm_output_encoded_addr_rtx (
1717 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1718 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1721 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1722 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1725 case DW_CFA_advance_loc1
:
1726 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1727 fde
->dw_fde_current_label
, NULL
);
1728 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1731 case DW_CFA_advance_loc2
:
1732 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1733 fde
->dw_fde_current_label
, NULL
);
1734 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1737 case DW_CFA_advance_loc4
:
1738 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1739 fde
->dw_fde_current_label
, NULL
);
1740 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1743 case DW_CFA_MIPS_advance_loc8
:
1744 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1745 fde
->dw_fde_current_label
, NULL
);
1746 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1749 case DW_CFA_offset_extended
:
1750 case DW_CFA_def_cfa
:
1751 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1753 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1756 case DW_CFA_offset_extended_sf
:
1757 case DW_CFA_def_cfa_sf
:
1758 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1760 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1763 case DW_CFA_restore_extended
:
1764 case DW_CFA_undefined
:
1765 case DW_CFA_same_value
:
1766 case DW_CFA_def_cfa_register
:
1767 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1771 case DW_CFA_register
:
1772 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1774 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1778 case DW_CFA_def_cfa_offset
:
1779 case DW_CFA_GNU_args_size
:
1780 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1783 case DW_CFA_def_cfa_offset_sf
:
1784 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1787 case DW_CFA_GNU_window_save
:
1790 case DW_CFA_def_cfa_expression
:
1791 case DW_CFA_expression
:
1792 output_cfa_loc (cfi
);
1795 case DW_CFA_GNU_negative_offset_extended
:
1796 /* Obsoleted by DW_CFA_offset_extended_sf. */
1805 /* Output the call frame information used to used to record information
1806 that relates to calculating the frame pointer, and records the
1807 location of saved registers. */
1810 output_call_frame_info (for_eh
)
1816 char l1
[20], l2
[20], section_start_label
[20];
1817 int any_lsda_needed
= 0;
1818 char augmentation
[6];
1819 int augmentation_size
;
1820 int fde_encoding
= DW_EH_PE_absptr
;
1821 int per_encoding
= DW_EH_PE_absptr
;
1822 int lsda_encoding
= DW_EH_PE_absptr
;
1824 /* Don't emit a CIE if there won't be any FDEs. */
1825 if (fde_table_in_use
== 0)
1828 /* If we don't have any functions we'll want to unwind out of, don't emit any
1829 EH unwind information. */
1832 int any_eh_needed
= flag_asynchronous_unwind_tables
;
1834 for (i
= 0; i
< fde_table_in_use
; i
++)
1835 if (fde_table
[i
].uses_eh_lsda
)
1836 any_eh_needed
= any_lsda_needed
= 1;
1837 else if (! fde_table
[i
].nothrow
)
1840 if (! any_eh_needed
)
1844 /* We're going to be generating comments, so turn on app. */
1849 (*targetm
.asm_out
.eh_frame_section
) ();
1851 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1853 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1854 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1856 /* Output the CIE. */
1857 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1858 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1859 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1860 "Length of Common Information Entry");
1861 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1863 /* Now that the CIE pointer is PC-relative for EH,
1864 use 0 to identify the CIE. */
1865 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1866 (for_eh
? 0 : DW_CIE_ID
),
1867 "CIE Identifier Tag");
1869 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1871 augmentation
[0] = 0;
1872 augmentation_size
= 0;
1878 z Indicates that a uleb128 is present to size the
1879 augmentation section.
1880 L Indicates the encoding (and thus presence) of
1881 an LSDA pointer in the FDE augmentation.
1882 R Indicates a non-default pointer encoding for
1884 P Indicates the presence of an encoding + language
1885 personality routine in the CIE augmentation. */
1887 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1888 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1889 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1891 p
= augmentation
+ 1;
1892 if (eh_personality_libfunc
)
1895 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1897 if (any_lsda_needed
)
1900 augmentation_size
+= 1;
1902 if (fde_encoding
!= DW_EH_PE_absptr
)
1905 augmentation_size
+= 1;
1907 if (p
> augmentation
+ 1)
1909 augmentation
[0] = 'z';
1913 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1914 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1916 int offset
= ( 4 /* Length */
1918 + 1 /* CIE version */
1919 + strlen (augmentation
) + 1 /* Augmentation */
1920 + size_of_uleb128 (1) /* Code alignment */
1921 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1923 + 1 /* Augmentation size */
1924 + 1 /* Personality encoding */ );
1925 int pad
= -offset
& (PTR_SIZE
- 1);
1927 augmentation_size
+= pad
;
1929 /* Augmentations should be small, so there's scarce need to
1930 iterate for a solution. Die if we exceed one uleb128 byte. */
1931 if (size_of_uleb128 (augmentation_size
) != 1)
1936 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1937 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1938 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1939 "CIE Data Alignment Factor");
1940 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
1942 if (augmentation
[0])
1944 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
1945 if (eh_personality_libfunc
)
1947 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
1948 eh_data_format_name (per_encoding
));
1949 dw2_asm_output_encoded_addr_rtx (per_encoding
,
1950 eh_personality_libfunc
, NULL
);
1953 if (any_lsda_needed
)
1954 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
1955 eh_data_format_name (lsda_encoding
));
1957 if (fde_encoding
!= DW_EH_PE_absptr
)
1958 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
1959 eh_data_format_name (fde_encoding
));
1962 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1963 output_cfi (cfi
, NULL
, for_eh
);
1965 /* Pad the CIE out to an address sized boundary. */
1966 ASM_OUTPUT_ALIGN (asm_out_file
,
1967 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
1968 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1970 /* Loop through all of the FDE's. */
1971 for (i
= 0; i
< fde_table_in_use
; i
++)
1973 fde
= &fde_table
[i
];
1975 /* Don't emit EH unwind info for leaf functions that don't need it. */
1976 if (!flag_asynchronous_unwind_tables
&& for_eh
1977 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
1978 && !fde
->uses_eh_lsda
)
1981 (*targetm
.asm_out
.internal_label
) (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
1982 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1983 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1984 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1986 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1989 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
1991 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
1996 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
1997 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
1998 "FDE initial location");
1999 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2000 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2001 "FDE address range");
2005 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2006 "FDE initial location");
2007 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2008 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2009 "FDE address range");
2012 if (augmentation
[0])
2014 if (any_lsda_needed
)
2016 int size
= size_of_encoded_value (lsda_encoding
);
2018 if (lsda_encoding
== DW_EH_PE_aligned
)
2020 int offset
= ( 4 /* Length */
2021 + 4 /* CIE offset */
2022 + 2 * size_of_encoded_value (fde_encoding
)
2023 + 1 /* Augmentation size */ );
2024 int pad
= -offset
& (PTR_SIZE
- 1);
2027 if (size_of_uleb128 (size
) != 1)
2031 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2033 if (fde
->uses_eh_lsda
)
2035 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2036 fde
->funcdef_number
);
2037 dw2_asm_output_encoded_addr_rtx (
2038 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2039 "Language Specific Data Area");
2043 if (lsda_encoding
== DW_EH_PE_aligned
)
2044 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2046 (size_of_encoded_value (lsda_encoding
), 0,
2047 "Language Specific Data Area (none)");
2051 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2054 /* Loop through the Call Frame Instructions associated with
2056 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2057 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2058 output_cfi (cfi
, fde
, for_eh
);
2060 /* Pad the FDE out to an address sized boundary. */
2061 ASM_OUTPUT_ALIGN (asm_out_file
,
2062 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2063 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2066 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2067 dw2_asm_output_data (4, 0, "End of Table");
2068 #ifdef MIPS_DEBUGGING_INFO
2069 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2070 get a value of 0. Putting .align 0 after the label fixes it. */
2071 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2074 /* Turn off app to make assembly quicker. */
2079 /* Output a marker (i.e. a label) for the beginning of a function, before
2083 dwarf2out_begin_prologue (line
, file
)
2084 unsigned int line ATTRIBUTE_UNUSED
;
2085 const char *file ATTRIBUTE_UNUSED
;
2087 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2090 current_function_func_begin_label
= 0;
2092 #ifdef IA64_UNWIND_INFO
2093 /* ??? current_function_func_begin_label is also used by except.c
2094 for call-site information. We must emit this label if it might
2096 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2097 && ! dwarf2out_do_frame ())
2100 if (! dwarf2out_do_frame ())
2104 function_section (current_function_decl
);
2105 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2106 current_function_funcdef_no
);
2107 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2108 current_function_funcdef_no
);
2109 current_function_func_begin_label
= get_identifier (label
);
2111 #ifdef IA64_UNWIND_INFO
2112 /* We can elide the fde allocation if we're not emitting debug info. */
2113 if (! dwarf2out_do_frame ())
2117 /* Expand the fde table if necessary. */
2118 if (fde_table_in_use
== fde_table_allocated
)
2120 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2122 = (dw_fde_ref
) xrealloc (fde_table
,
2123 fde_table_allocated
* sizeof (dw_fde_node
));
2126 /* Record the FDE associated with this function. */
2127 current_funcdef_fde
= fde_table_in_use
;
2129 /* Add the new FDE at the end of the fde_table. */
2130 fde
= &fde_table
[fde_table_in_use
++];
2131 fde
->dw_fde_begin
= xstrdup (label
);
2132 fde
->dw_fde_current_label
= NULL
;
2133 fde
->dw_fde_end
= NULL
;
2134 fde
->dw_fde_cfi
= NULL
;
2135 fde
->funcdef_number
= current_function_funcdef_no
;
2136 fde
->nothrow
= current_function_nothrow
;
2137 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2138 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2140 args_size
= old_args_size
= 0;
2142 /* We only want to output line number information for the genuine dwarf2
2143 prologue case, not the eh frame case. */
2144 #ifdef DWARF2_DEBUGGING_INFO
2146 dwarf2out_source_line (line
, file
);
2150 /* Output a marker (i.e. a label) for the absolute end of the generated code
2151 for a function definition. This gets called *after* the epilogue code has
2155 dwarf2out_end_epilogue (line
, file
)
2156 unsigned int line ATTRIBUTE_UNUSED
;
2157 const char *file ATTRIBUTE_UNUSED
;
2160 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2162 /* Output a label to mark the endpoint of the code generated for this
2164 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2165 current_function_funcdef_no
);
2166 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2167 fde
= &fde_table
[fde_table_in_use
- 1];
2168 fde
->dw_fde_end
= xstrdup (label
);
2172 dwarf2out_frame_init ()
2174 /* Allocate the initial hunk of the fde_table. */
2175 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2176 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2177 fde_table_in_use
= 0;
2179 /* Generate the CFA instructions common to all FDE's. Do it now for the
2180 sake of lookup_cfa. */
2182 #ifdef DWARF2_UNWIND_INFO
2183 /* On entry, the Canonical Frame Address is at SP. */
2184 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2185 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2190 dwarf2out_frame_finish ()
2192 /* Output call frame information. */
2193 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2194 output_call_frame_info (0);
2196 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2197 output_call_frame_info (1);
2200 /* And now, the subset of the debugging information support code necessary
2201 for emitting location expressions. */
2203 /* We need some way to distinguish DW_OP_addr with a direct symbol
2204 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2205 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2208 typedef struct dw_val_struct
*dw_val_ref
;
2209 typedef struct die_struct
*dw_die_ref
;
2210 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2211 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2213 /* Each DIE may have a series of attribute/value pairs. Values
2214 can take on several forms. The forms that are used in this
2215 implementation are listed below. */
2220 dw_val_class_offset
,
2222 dw_val_class_loc_list
,
2223 dw_val_class_range_list
,
2225 dw_val_class_unsigned_const
,
2226 dw_val_class_long_long
,
2229 dw_val_class_die_ref
,
2230 dw_val_class_fde_ref
,
2231 dw_val_class_lbl_id
,
2232 dw_val_class_lbl_offset
,
2237 /* Describe a double word constant value. */
2238 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2240 typedef struct dw_long_long_struct
2247 /* Describe a floating point constant value. */
2249 typedef struct dw_fp_struct
2256 /* The dw_val_node describes an attribute's value, as it is
2257 represented internally. */
2259 typedef struct dw_val_struct
2261 dw_val_class val_class
;
2265 long unsigned val_offset
;
2266 dw_loc_list_ref val_loc_list
;
2267 dw_loc_descr_ref val_loc
;
2269 long unsigned val_unsigned
;
2270 dw_long_long_const val_long_long
;
2271 dw_float_const val_float
;
2277 unsigned val_fde_index
;
2278 struct indirect_string_node
*val_str
;
2280 unsigned char val_flag
;
2286 /* Locations in memory are described using a sequence of stack machine
2289 typedef struct dw_loc_descr_struct
2291 dw_loc_descr_ref dw_loc_next
;
2292 enum dwarf_location_atom dw_loc_opc
;
2293 dw_val_node dw_loc_oprnd1
;
2294 dw_val_node dw_loc_oprnd2
;
2299 /* Location lists are ranges + location descriptions for that range,
2300 so you can track variables that are in different places over
2301 their entire life. */
2302 typedef struct dw_loc_list_struct
2304 dw_loc_list_ref dw_loc_next
;
2305 const char *begin
; /* Label for begin address of range */
2306 const char *end
; /* Label for end address of range */
2307 char *ll_symbol
; /* Label for beginning of location list.
2308 Only on head of list */
2309 const char *section
; /* Section this loclist is relative to */
2310 dw_loc_descr_ref expr
;
2313 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2314 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2317 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2319 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2320 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2321 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2322 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2324 /* Convert a DWARF stack opcode into its string name. */
2327 dwarf_stack_op_name (op
)
2333 case INTERNAL_DW_OP_tls_addr
:
2334 return "DW_OP_addr";
2336 return "DW_OP_deref";
2338 return "DW_OP_const1u";
2340 return "DW_OP_const1s";
2342 return "DW_OP_const2u";
2344 return "DW_OP_const2s";
2346 return "DW_OP_const4u";
2348 return "DW_OP_const4s";
2350 return "DW_OP_const8u";
2352 return "DW_OP_const8s";
2354 return "DW_OP_constu";
2356 return "DW_OP_consts";
2360 return "DW_OP_drop";
2362 return "DW_OP_over";
2364 return "DW_OP_pick";
2366 return "DW_OP_swap";
2370 return "DW_OP_xderef";
2378 return "DW_OP_minus";
2390 return "DW_OP_plus";
2391 case DW_OP_plus_uconst
:
2392 return "DW_OP_plus_uconst";
2398 return "DW_OP_shra";
2416 return "DW_OP_skip";
2418 return "DW_OP_lit0";
2420 return "DW_OP_lit1";
2422 return "DW_OP_lit2";
2424 return "DW_OP_lit3";
2426 return "DW_OP_lit4";
2428 return "DW_OP_lit5";
2430 return "DW_OP_lit6";
2432 return "DW_OP_lit7";
2434 return "DW_OP_lit8";
2436 return "DW_OP_lit9";
2438 return "DW_OP_lit10";
2440 return "DW_OP_lit11";
2442 return "DW_OP_lit12";
2444 return "DW_OP_lit13";
2446 return "DW_OP_lit14";
2448 return "DW_OP_lit15";
2450 return "DW_OP_lit16";
2452 return "DW_OP_lit17";
2454 return "DW_OP_lit18";
2456 return "DW_OP_lit19";
2458 return "DW_OP_lit20";
2460 return "DW_OP_lit21";
2462 return "DW_OP_lit22";
2464 return "DW_OP_lit23";
2466 return "DW_OP_lit24";
2468 return "DW_OP_lit25";
2470 return "DW_OP_lit26";
2472 return "DW_OP_lit27";
2474 return "DW_OP_lit28";
2476 return "DW_OP_lit29";
2478 return "DW_OP_lit30";
2480 return "DW_OP_lit31";
2482 return "DW_OP_reg0";
2484 return "DW_OP_reg1";
2486 return "DW_OP_reg2";
2488 return "DW_OP_reg3";
2490 return "DW_OP_reg4";
2492 return "DW_OP_reg5";
2494 return "DW_OP_reg6";
2496 return "DW_OP_reg7";
2498 return "DW_OP_reg8";
2500 return "DW_OP_reg9";
2502 return "DW_OP_reg10";
2504 return "DW_OP_reg11";
2506 return "DW_OP_reg12";
2508 return "DW_OP_reg13";
2510 return "DW_OP_reg14";
2512 return "DW_OP_reg15";
2514 return "DW_OP_reg16";
2516 return "DW_OP_reg17";
2518 return "DW_OP_reg18";
2520 return "DW_OP_reg19";
2522 return "DW_OP_reg20";
2524 return "DW_OP_reg21";
2526 return "DW_OP_reg22";
2528 return "DW_OP_reg23";
2530 return "DW_OP_reg24";
2532 return "DW_OP_reg25";
2534 return "DW_OP_reg26";
2536 return "DW_OP_reg27";
2538 return "DW_OP_reg28";
2540 return "DW_OP_reg29";
2542 return "DW_OP_reg30";
2544 return "DW_OP_reg31";
2546 return "DW_OP_breg0";
2548 return "DW_OP_breg1";
2550 return "DW_OP_breg2";
2552 return "DW_OP_breg3";
2554 return "DW_OP_breg4";
2556 return "DW_OP_breg5";
2558 return "DW_OP_breg6";
2560 return "DW_OP_breg7";
2562 return "DW_OP_breg8";
2564 return "DW_OP_breg9";
2566 return "DW_OP_breg10";
2568 return "DW_OP_breg11";
2570 return "DW_OP_breg12";
2572 return "DW_OP_breg13";
2574 return "DW_OP_breg14";
2576 return "DW_OP_breg15";
2578 return "DW_OP_breg16";
2580 return "DW_OP_breg17";
2582 return "DW_OP_breg18";
2584 return "DW_OP_breg19";
2586 return "DW_OP_breg20";
2588 return "DW_OP_breg21";
2590 return "DW_OP_breg22";
2592 return "DW_OP_breg23";
2594 return "DW_OP_breg24";
2596 return "DW_OP_breg25";
2598 return "DW_OP_breg26";
2600 return "DW_OP_breg27";
2602 return "DW_OP_breg28";
2604 return "DW_OP_breg29";
2606 return "DW_OP_breg30";
2608 return "DW_OP_breg31";
2610 return "DW_OP_regx";
2612 return "DW_OP_fbreg";
2614 return "DW_OP_bregx";
2616 return "DW_OP_piece";
2617 case DW_OP_deref_size
:
2618 return "DW_OP_deref_size";
2619 case DW_OP_xderef_size
:
2620 return "DW_OP_xderef_size";
2623 case DW_OP_push_object_address
:
2624 return "DW_OP_push_object_address";
2626 return "DW_OP_call2";
2628 return "DW_OP_call4";
2629 case DW_OP_call_ref
:
2630 return "DW_OP_call_ref";
2631 case DW_OP_GNU_push_tls_address
:
2632 return "DW_OP_GNU_push_tls_address";
2634 return "OP_<unknown>";
2638 /* Return a pointer to a newly allocated location description. Location
2639 descriptions are simple expression terms that can be strung
2640 together to form more complicated location (address) descriptions. */
2642 static inline dw_loc_descr_ref
2643 new_loc_descr (op
, oprnd1
, oprnd2
)
2644 enum dwarf_location_atom op
;
2645 unsigned long oprnd1
;
2646 unsigned long oprnd2
;
2648 /* Use xcalloc here so we clear out all of the long_long constant in
2650 dw_loc_descr_ref descr
2651 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2653 descr
->dw_loc_opc
= op
;
2654 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2655 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2656 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2657 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2663 /* Add a location description term to a location description expression. */
2666 add_loc_descr (list_head
, descr
)
2667 dw_loc_descr_ref
*list_head
;
2668 dw_loc_descr_ref descr
;
2670 dw_loc_descr_ref
*d
;
2672 /* Find the end of the chain. */
2673 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2679 /* Return the size of a location descriptor. */
2681 static unsigned long
2682 size_of_loc_descr (loc
)
2683 dw_loc_descr_ref loc
;
2685 unsigned long size
= 1;
2687 switch (loc
->dw_loc_opc
)
2690 case INTERNAL_DW_OP_tls_addr
:
2691 size
+= DWARF2_ADDR_SIZE
;
2710 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2713 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2718 case DW_OP_plus_uconst
:
2719 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
);
2763 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2766 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2767 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2770 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2772 case DW_OP_deref_size
:
2773 case DW_OP_xderef_size
:
2782 case DW_OP_call_ref
:
2783 size
+= DWARF2_ADDR_SIZE
;
2792 /* Return the size of a series of location descriptors. */
2794 static unsigned long
2796 dw_loc_descr_ref loc
;
2800 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2802 loc
->dw_loc_addr
= size
;
2803 size
+= size_of_loc_descr (loc
);
2809 /* Output location description stack opcode's operands (if any). */
2812 output_loc_operands (loc
)
2813 dw_loc_descr_ref loc
;
2815 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2816 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2818 switch (loc
->dw_loc_opc
)
2820 #ifdef DWARF2_DEBUGGING_INFO
2822 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2826 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2830 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2834 if (HOST_BITS_PER_LONG
< 64)
2836 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2843 if (val1
->val_class
== dw_val_class_loc
)
2844 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2848 dw2_asm_output_data (2, offset
, NULL
);
2861 /* We currently don't make any attempt to make sure these are
2862 aligned properly like we do for the main unwind info, so
2863 don't support emitting things larger than a byte if we're
2864 only doing unwinding. */
2869 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2872 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2875 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2878 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2880 case DW_OP_plus_uconst
:
2881 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2915 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2918 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2921 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2924 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2925 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2928 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2930 case DW_OP_deref_size
:
2931 case DW_OP_xderef_size
:
2932 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2935 case INTERNAL_DW_OP_tls_addr
:
2936 #ifdef ASM_OUTPUT_DWARF_DTPREL
2937 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
2939 fputc ('\n', asm_out_file
);
2946 /* Other codes have no operands. */
2951 /* Output a sequence of location operations. */
2954 output_loc_sequence (loc
)
2955 dw_loc_descr_ref loc
;
2957 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2959 /* Output the opcode. */
2960 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2961 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2963 /* Output the operand(s) (if any). */
2964 output_loc_operands (loc
);
2968 /* This routine will generate the correct assembly data for a location
2969 description based on a cfi entry with a complex address. */
2972 output_cfa_loc (cfi
)
2975 dw_loc_descr_ref loc
;
2978 /* Output the size of the block. */
2979 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2980 size
= size_of_locs (loc
);
2981 dw2_asm_output_data_uleb128 (size
, NULL
);
2983 /* Now output the operations themselves. */
2984 output_loc_sequence (loc
);
2987 /* This function builds a dwarf location descriptor sequence from
2988 a dw_cfa_location. */
2990 static struct dw_loc_descr_struct
*
2992 dw_cfa_location
*cfa
;
2994 struct dw_loc_descr_struct
*head
, *tmp
;
2996 if (cfa
->indirect
== 0)
2999 if (cfa
->base_offset
)
3002 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3004 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3006 else if (cfa
->reg
<= 31)
3007 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3009 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3011 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3012 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3013 add_loc_descr (&head
, tmp
);
3014 if (cfa
->offset
!= 0)
3016 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3017 add_loc_descr (&head
, tmp
);
3023 /* This function fills in aa dw_cfa_location structure from a dwarf location
3024 descriptor sequence. */
3027 get_cfa_from_loc_descr (cfa
, loc
)
3028 dw_cfa_location
*cfa
;
3029 struct dw_loc_descr_struct
*loc
;
3031 struct dw_loc_descr_struct
*ptr
;
3033 cfa
->base_offset
= 0;
3037 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3039 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3075 cfa
->reg
= op
- DW_OP_reg0
;
3078 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3112 cfa
->reg
= op
- DW_OP_breg0
;
3113 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3116 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3117 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3122 case DW_OP_plus_uconst
:
3123 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3126 internal_error ("DW_LOC_OP %s not implemented\n",
3127 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3131 #endif /* .debug_frame support */
3133 /* And now, the support for symbolic debugging information. */
3134 #ifdef DWARF2_DEBUGGING_INFO
3136 /* .debug_str support. */
3137 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3138 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3139 hashnode
, const PTR
));
3142 static void dwarf2out_init
PARAMS ((const char *));
3143 static void dwarf2out_finish
PARAMS ((const char *));
3144 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3145 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3146 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3147 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3148 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3149 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3150 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3151 static void dwarf2out_global_decl
PARAMS ((tree
));
3152 static void dwarf2out_abstract_function
PARAMS ((tree
));
3154 /* The debug hooks structure. */
3156 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3162 dwarf2out_start_source_file
,
3163 dwarf2out_end_source_file
,
3164 dwarf2out_begin_block
,
3165 dwarf2out_end_block
,
3166 dwarf2out_ignore_block
,
3167 dwarf2out_source_line
,
3168 dwarf2out_begin_prologue
,
3169 debug_nothing_int_charstar
, /* end_prologue */
3170 dwarf2out_end_epilogue
,
3171 debug_nothing_tree
, /* begin_function */
3172 debug_nothing_int
, /* end_function */
3173 dwarf2out_decl
, /* function_decl */
3174 dwarf2out_global_decl
,
3175 debug_nothing_tree
, /* deferred_inline_function */
3176 /* The DWARF 2 backend tries to reduce debugging bloat by not
3177 emitting the abstract description of inline functions until
3178 something tries to reference them. */
3179 dwarf2out_abstract_function
, /* outlining_inline_function */
3180 debug_nothing_rtx
/* label */
3183 /* NOTE: In the comments in this file, many references are made to
3184 "Debugging Information Entries". This term is abbreviated as `DIE'
3185 throughout the remainder of this file. */
3187 /* An internal representation of the DWARF output is built, and then
3188 walked to generate the DWARF debugging info. The walk of the internal
3189 representation is done after the entire program has been compiled.
3190 The types below are used to describe the internal representation. */
3192 /* Various DIE's use offsets relative to the beginning of the
3193 .debug_info section to refer to each other. */
3195 typedef long int dw_offset
;
3197 /* Define typedefs here to avoid circular dependencies. */
3199 typedef struct dw_attr_struct
*dw_attr_ref
;
3200 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3201 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3202 typedef struct pubname_struct
*pubname_ref
;
3203 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3205 /* Each entry in the line_info_table maintains the file and
3206 line number associated with the label generated for that
3207 entry. The label gives the PC value associated with
3208 the line number entry. */
3210 typedef struct dw_line_info_struct
3212 unsigned long dw_file_num
;
3213 unsigned long dw_line_num
;
3217 /* Line information for functions in separate sections; each one gets its
3219 typedef struct dw_separate_line_info_struct
3221 unsigned long dw_file_num
;
3222 unsigned long dw_line_num
;
3223 unsigned long function
;
3225 dw_separate_line_info_entry
;
3227 /* Each DIE attribute has a field specifying the attribute kind,
3228 a link to the next attribute in the chain, and an attribute value.
3229 Attributes are typically linked below the DIE they modify. */
3231 typedef struct dw_attr_struct
3233 enum dwarf_attribute dw_attr
;
3234 dw_attr_ref dw_attr_next
;
3235 dw_val_node dw_attr_val
;
3239 /* The Debugging Information Entry (DIE) structure */
3241 typedef struct die_struct
3243 enum dwarf_tag die_tag
;
3245 dw_attr_ref die_attr
;
3246 dw_die_ref die_parent
;
3247 dw_die_ref die_child
;
3249 dw_offset die_offset
;
3250 unsigned long die_abbrev
;
3255 /* The pubname structure */
3257 typedef struct pubname_struct
3264 struct dw_ranges_struct
3269 /* The limbo die list structure. */
3270 typedef struct limbo_die_struct
3274 struct limbo_die_struct
*next
;
3278 /* How to start an assembler comment. */
3279 #ifndef ASM_COMMENT_START
3280 #define ASM_COMMENT_START ";#"
3283 /* Define a macro which returns nonzero for a TYPE_DECL which was
3284 implicitly generated for a tagged type.
3286 Note that unlike the gcc front end (which generates a NULL named
3287 TYPE_DECL node for each complete tagged type, each array type, and
3288 each function type node created) the g++ front end generates a
3289 _named_ TYPE_DECL node for each tagged type node created.
3290 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3291 generate a DW_TAG_typedef DIE for them. */
3293 #define TYPE_DECL_IS_STUB(decl) \
3294 (DECL_NAME (decl) == NULL_TREE \
3295 || (DECL_ARTIFICIAL (decl) \
3296 && is_tagged_type (TREE_TYPE (decl)) \
3297 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3298 /* This is necessary for stub decls that \
3299 appear in nested inline functions. */ \
3300 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3301 && (decl_ultimate_origin (decl) \
3302 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3304 /* Information concerning the compilation unit's programming
3305 language, and compiler version. */
3307 /* Fixed size portion of the DWARF compilation unit header. */
3308 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3310 /* Fixed size portion of public names info. */
3311 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3313 /* Fixed size portion of the address range info. */
3314 #define DWARF_ARANGES_HEADER_SIZE \
3315 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3316 - DWARF_OFFSET_SIZE)
3318 /* Size of padding portion in the address range info. It must be
3319 aligned to twice the pointer size. */
3320 #define DWARF_ARANGES_PAD_SIZE \
3321 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3322 - (2 * DWARF_OFFSET_SIZE + 4))
3324 /* Use assembler line directives if available. */
3325 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3326 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3327 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3329 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3333 /* Minimum line offset in a special line info. opcode.
3334 This value was chosen to give a reasonable range of values. */
3335 #define DWARF_LINE_BASE -10
3337 /* First special line opcode - leave room for the standard opcodes. */
3338 #define DWARF_LINE_OPCODE_BASE 10
3340 /* Range of line offsets in a special line info. opcode. */
3341 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3343 /* Flag that indicates the initial value of the is_stmt_start flag.
3344 In the present implementation, we do not mark any lines as
3345 the beginning of a source statement, because that information
3346 is not made available by the GCC front-end. */
3347 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3349 /* This location is used by calc_die_sizes() to keep track
3350 the offset of each DIE within the .debug_info section. */
3351 static unsigned long next_die_offset
;
3353 /* Record the root of the DIE's built for the current compilation unit. */
3354 static dw_die_ref comp_unit_die
;
3356 /* We need special handling in dwarf2out_start_source_file if it is
3358 static int is_main_source
;
3360 /* A list of DIEs with a NULL parent waiting to be relocated. */
3361 static limbo_die_node
*limbo_die_list
= 0;
3363 /* Structure used by lookup_filename to manage sets of filenames. */
3369 unsigned last_lookup_index
;
3372 /* Size (in elements) of increments by which we may expand the filename
3374 #define FILE_TABLE_INCREMENT 64
3376 /* Filenames referenced by this compilation unit. */
3377 static struct file_table file_table
;
3379 /* A pointer to the base of a table of references to DIE's that describe
3380 declarations. The table is indexed by DECL_UID() which is a unique
3381 number identifying each decl. */
3382 static dw_die_ref
*decl_die_table
;
3384 /* Number of elements currently allocated for the decl_die_table. */
3385 static unsigned decl_die_table_allocated
;
3387 /* Number of elements in decl_die_table currently in use. */
3388 static unsigned decl_die_table_in_use
;
3390 /* Size (in elements) of increments by which we may expand the
3392 #define DECL_DIE_TABLE_INCREMENT 256
3394 /* A pointer to the base of a list of references to DIE's that
3395 are uniquely identified by their tag, presence/absence of
3396 children DIE's, and list of attribute/value pairs. */
3397 static dw_die_ref
*abbrev_die_table
;
3399 /* Number of elements currently allocated for abbrev_die_table. */
3400 static unsigned abbrev_die_table_allocated
;
3402 /* Number of elements in type_die_table currently in use. */
3403 static unsigned abbrev_die_table_in_use
;
3405 /* Size (in elements) of increments by which we may expand the
3406 abbrev_die_table. */
3407 #define ABBREV_DIE_TABLE_INCREMENT 256
3409 /* A pointer to the base of a table that contains line information
3410 for each source code line in .text in the compilation unit. */
3411 static dw_line_info_ref line_info_table
;
3413 /* Number of elements currently allocated for line_info_table. */
3414 static unsigned line_info_table_allocated
;
3416 /* Number of elements in separate_line_info_table currently in use. */
3417 static unsigned separate_line_info_table_in_use
;
3419 /* A pointer to the base of a table that contains line information
3420 for each source code line outside of .text in the compilation unit. */
3421 static dw_separate_line_info_ref separate_line_info_table
;
3423 /* Number of elements currently allocated for separate_line_info_table. */
3424 static unsigned separate_line_info_table_allocated
;
3426 /* Number of elements in line_info_table currently in use. */
3427 static unsigned line_info_table_in_use
;
3429 /* Size (in elements) of increments by which we may expand the
3431 #define LINE_INFO_TABLE_INCREMENT 1024
3433 /* A pointer to the base of a table that contains a list of publicly
3434 accessible names. */
3435 static pubname_ref pubname_table
;
3437 /* Number of elements currently allocated for pubname_table. */
3438 static unsigned pubname_table_allocated
;
3440 /* Number of elements in pubname_table currently in use. */
3441 static unsigned pubname_table_in_use
;
3443 /* Size (in elements) of increments by which we may expand the
3445 #define PUBNAME_TABLE_INCREMENT 64
3447 /* Array of dies for which we should generate .debug_arange info. */
3448 static dw_die_ref
*arange_table
;
3450 /* Number of elements currently allocated for arange_table. */
3451 static unsigned arange_table_allocated
;
3453 /* Number of elements in arange_table currently in use. */
3454 static unsigned arange_table_in_use
;
3456 /* Size (in elements) of increments by which we may expand the
3458 #define ARANGE_TABLE_INCREMENT 64
3460 /* Array of dies for which we should generate .debug_ranges info. */
3461 static dw_ranges_ref ranges_table
;
3463 /* Number of elements currently allocated for ranges_table. */
3464 static unsigned ranges_table_allocated
;
3466 /* Number of elements in ranges_table currently in use. */
3467 static unsigned ranges_table_in_use
;
3469 /* Size (in elements) of increments by which we may expand the
3471 #define RANGES_TABLE_INCREMENT 64
3473 /* Whether we have location lists that need outputting */
3474 static unsigned have_location_lists
;
3476 /* Record whether the function being analyzed contains inlined functions. */
3477 static int current_function_has_inlines
;
3478 #if 0 && defined (MIPS_DEBUGGING_INFO)
3479 static int comp_unit_has_inlines
;
3482 /* Forward declarations for functions defined in this file. */
3484 static int is_pseudo_reg
PARAMS ((rtx
));
3485 static tree type_main_variant
PARAMS ((tree
));
3486 static int is_tagged_type
PARAMS ((tree
));
3487 static const char *dwarf_tag_name
PARAMS ((unsigned));
3488 static const char *dwarf_attr_name
PARAMS ((unsigned));
3489 static const char *dwarf_form_name
PARAMS ((unsigned));
3491 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3493 static tree decl_ultimate_origin
PARAMS ((tree
));
3494 static tree block_ultimate_origin
PARAMS ((tree
));
3495 static tree decl_class_context
PARAMS ((tree
));
3496 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3497 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3498 static void add_AT_flag
PARAMS ((dw_die_ref
,
3499 enum dwarf_attribute
,
3501 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3502 static void add_AT_int
PARAMS ((dw_die_ref
,
3503 enum dwarf_attribute
, long));
3504 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3505 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3506 enum dwarf_attribute
,
3508 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3509 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3510 enum dwarf_attribute
,
3513 static void add_AT_float
PARAMS ((dw_die_ref
,
3514 enum dwarf_attribute
,
3516 static void add_AT_string
PARAMS ((dw_die_ref
,
3517 enum dwarf_attribute
,
3519 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3520 static int AT_string_form
PARAMS ((dw_attr_ref
));
3521 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3522 enum dwarf_attribute
,
3524 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3525 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3526 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3527 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3528 enum dwarf_attribute
,
3530 static void add_AT_loc
PARAMS ((dw_die_ref
,
3531 enum dwarf_attribute
,
3533 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3534 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3535 enum dwarf_attribute
,
3537 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3538 static void add_AT_addr
PARAMS ((dw_die_ref
,
3539 enum dwarf_attribute
,
3541 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3542 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3543 enum dwarf_attribute
,
3545 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3546 enum dwarf_attribute
,
3548 static void add_AT_offset
PARAMS ((dw_die_ref
,
3549 enum dwarf_attribute
,
3551 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3552 enum dwarf_attribute
,
3554 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3555 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3556 enum dwarf_attribute
));
3557 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3558 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3559 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3560 enum dwarf_attribute
));
3561 static int get_AT_flag
PARAMS ((dw_die_ref
,
3562 enum dwarf_attribute
));
3563 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3564 enum dwarf_attribute
));
3565 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3566 enum dwarf_attribute
));
3567 static int is_c_family
PARAMS ((void));
3568 static int is_cxx
PARAMS ((void));
3569 static int is_java
PARAMS ((void));
3570 static int is_fortran
PARAMS ((void));
3571 static void remove_AT
PARAMS ((dw_die_ref
,
3572 enum dwarf_attribute
));
3573 static inline void free_die
PARAMS ((dw_die_ref
));
3574 static void remove_children
PARAMS ((dw_die_ref
));
3575 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3576 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3578 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3579 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3580 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3581 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3582 static void print_spaces
PARAMS ((FILE *));
3583 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3584 static void print_dwarf_line_table
PARAMS ((FILE *));
3585 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3586 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3587 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3588 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3589 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3591 static void attr_checksum
PARAMS ((dw_attr_ref
,
3594 static void die_checksum
PARAMS ((dw_die_ref
,
3597 static int same_loc_p
PARAMS ((dw_loc_descr_ref
,
3598 dw_loc_descr_ref
, int *));
3599 static int same_dw_val_p
PARAMS ((dw_val_node
*, dw_val_node
*,
3601 static int same_attr_p
PARAMS ((dw_attr_ref
, dw_attr_ref
, int *));
3602 static int same_die_p
PARAMS ((dw_die_ref
, dw_die_ref
, int *));
3603 static int same_die_p_wrap
PARAMS ((dw_die_ref
, dw_die_ref
));
3604 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3605 static int is_type_die
PARAMS ((dw_die_ref
));
3606 static int is_comdat_die
PARAMS ((dw_die_ref
));
3607 static int is_symbol_die
PARAMS ((dw_die_ref
));
3608 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3609 static void break_out_includes
PARAMS ((dw_die_ref
));
3610 static hashval_t htab_cu_hash
PARAMS ((const void *));
3611 static int htab_cu_eq
PARAMS ((const void *, const void *));
3612 static void htab_cu_del
PARAMS ((void *));
3613 static int check_duplicate_cu
PARAMS ((dw_die_ref
, htab_t
, unsigned *));
3614 static void record_comdat_symbol_number
PARAMS ((dw_die_ref
, htab_t
, unsigned));
3615 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3616 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3617 static void output_location_lists
PARAMS ((dw_die_ref
));
3618 static int constant_size
PARAMS ((long unsigned));
3619 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3620 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3621 static void mark_dies
PARAMS ((dw_die_ref
));
3622 static void unmark_dies
PARAMS ((dw_die_ref
));
3623 static void unmark_all_dies
PARAMS ((dw_die_ref
));
3624 static unsigned long size_of_pubnames
PARAMS ((void));
3625 static unsigned long size_of_aranges
PARAMS ((void));
3626 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3627 static void output_value_format
PARAMS ((dw_attr_ref
));
3628 static void output_abbrev_section
PARAMS ((void));
3629 static void output_die_symbol
PARAMS ((dw_die_ref
));
3630 static void output_die
PARAMS ((dw_die_ref
));
3631 static void output_compilation_unit_header
PARAMS ((void));
3632 static void output_comp_unit
PARAMS ((dw_die_ref
, int));
3633 static const char *dwarf2_name
PARAMS ((tree
, int));
3634 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3635 static void output_pubnames
PARAMS ((void));
3636 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3637 static void output_aranges
PARAMS ((void));
3638 static unsigned int add_ranges
PARAMS ((tree
));
3639 static void output_ranges
PARAMS ((void));
3640 static void output_line_info
PARAMS ((void));
3641 static void output_file_names
PARAMS ((void));
3642 static dw_die_ref base_type_die
PARAMS ((tree
));
3643 static tree root_type
PARAMS ((tree
));
3644 static int is_base_type
PARAMS ((tree
));
3645 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3646 static int type_is_enum
PARAMS ((tree
));
3647 static unsigned int reg_number
PARAMS ((rtx
));
3648 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3649 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3650 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3651 static int is_based_loc
PARAMS ((rtx
));
3652 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3653 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3654 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3655 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3656 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3657 static tree field_type
PARAMS ((tree
));
3658 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3659 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3660 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3661 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3662 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3663 enum dwarf_attribute
,
3665 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3666 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3667 static rtx rtl_for_decl_location
PARAMS ((tree
));
3668 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3669 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3670 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3671 static void add_bound_info
PARAMS ((dw_die_ref
,
3672 enum dwarf_attribute
, tree
));
3673 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3674 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3675 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3676 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3677 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3678 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3679 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3680 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3681 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3682 static void push_decl_scope
PARAMS ((tree
));
3683 static void pop_decl_scope
PARAMS ((void));
3684 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3685 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3686 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3687 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3689 static const char *type_tag
PARAMS ((tree
));
3690 static tree member_declared_type
PARAMS ((tree
));
3692 static const char *decl_start_label
PARAMS ((tree
));
3694 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3695 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3697 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3699 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3700 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3701 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3702 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3703 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3704 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3705 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3706 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3707 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3708 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3709 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3710 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3711 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3712 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3713 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3714 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3715 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3716 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3717 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3718 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3719 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3720 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3721 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3722 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3723 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3724 static int is_redundant_typedef
PARAMS ((tree
));
3725 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3726 static unsigned lookup_filename
PARAMS ((const char *));
3727 static void init_file_table
PARAMS ((void));
3728 static void retry_incomplete_types
PARAMS ((void));
3729 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3730 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3731 static int file_info_cmp
PARAMS ((const void *, const void *));
3732 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3733 const char *, const char *,
3734 const char *, unsigned));
3735 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3737 const char *, const char *, const char *));
3738 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3739 static char *gen_internal_sym
PARAMS ((const char *));
3740 static void mark_limbo_die_list
PARAMS ((void *));
3742 /* Section names used to hold DWARF debugging information. */
3743 #ifndef DEBUG_INFO_SECTION
3744 #define DEBUG_INFO_SECTION ".debug_info"
3746 #ifndef DEBUG_ABBREV_SECTION
3747 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3749 #ifndef DEBUG_ARANGES_SECTION
3750 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3752 #ifndef DEBUG_MACINFO_SECTION
3753 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3755 #ifndef DEBUG_LINE_SECTION
3756 #define DEBUG_LINE_SECTION ".debug_line"
3758 #ifndef DEBUG_LOC_SECTION
3759 #define DEBUG_LOC_SECTION ".debug_loc"
3761 #ifndef DEBUG_PUBNAMES_SECTION
3762 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3764 #ifndef DEBUG_STR_SECTION
3765 #define DEBUG_STR_SECTION ".debug_str"
3767 #ifndef DEBUG_RANGES_SECTION
3768 #define DEBUG_RANGES_SECTION ".debug_ranges"
3771 /* Standard ELF section names for compiled code and data. */
3772 #ifndef TEXT_SECTION_NAME
3773 #define TEXT_SECTION_NAME ".text"
3776 /* Section flags for .debug_str section. */
3777 #ifdef HAVE_GAS_SHF_MERGE
3778 #define DEBUG_STR_SECTION_FLAGS \
3779 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3781 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3784 /* Labels we insert at beginning sections we can reference instead of
3785 the section names themselves. */
3787 #ifndef TEXT_SECTION_LABEL
3788 #define TEXT_SECTION_LABEL "Ltext"
3790 #ifndef DEBUG_LINE_SECTION_LABEL
3791 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3793 #ifndef DEBUG_INFO_SECTION_LABEL
3794 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3796 #ifndef DEBUG_ABBREV_SECTION_LABEL
3797 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3799 #ifndef DEBUG_LOC_SECTION_LABEL
3800 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3802 #ifndef DEBUG_RANGES_SECTION_LABEL
3803 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3805 #ifndef DEBUG_MACINFO_SECTION_LABEL
3806 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3809 /* Definitions of defaults for formats and names of various special
3810 (artificial) labels which may be generated within this file (when the -g
3811 options is used and DWARF_DEBUGGING_INFO is in effect.
3812 If necessary, these may be overridden from within the tm.h file, but
3813 typically, overriding these defaults is unnecessary. */
3815 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3816 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3817 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3818 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3819 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3820 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3821 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3822 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3824 #ifndef TEXT_END_LABEL
3825 #define TEXT_END_LABEL "Letext"
3827 #ifndef BLOCK_BEGIN_LABEL
3828 #define BLOCK_BEGIN_LABEL "LBB"
3830 #ifndef BLOCK_END_LABEL
3831 #define BLOCK_END_LABEL "LBE"
3833 #ifndef LINE_CODE_LABEL
3834 #define LINE_CODE_LABEL "LM"
3836 #ifndef SEPARATE_LINE_CODE_LABEL
3837 #define SEPARATE_LINE_CODE_LABEL "LSM"
3840 /* We allow a language front-end to designate a function that is to be
3841 called to "demangle" any name before it it put into a DIE. */
3843 static const char *(*demangle_name_func
) PARAMS ((const char *));
3846 dwarf2out_set_demangle_name_func (func
)
3847 const char *(*func
) PARAMS ((const char *));
3849 demangle_name_func
= func
;
3852 /* Test if rtl node points to a pseudo register. */
3858 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3859 || (GET_CODE (rtl
) == SUBREG
3860 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3863 /* Return a reference to a type, with its const and volatile qualifiers
3867 type_main_variant (type
)
3870 type
= TYPE_MAIN_VARIANT (type
);
3872 /* ??? There really should be only one main variant among any group of
3873 variants of a given type (and all of the MAIN_VARIANT values for all
3874 members of the group should point to that one type) but sometimes the C
3875 front-end messes this up for array types, so we work around that bug
3877 if (TREE_CODE (type
) == ARRAY_TYPE
)
3878 while (type
!= TYPE_MAIN_VARIANT (type
))
3879 type
= TYPE_MAIN_VARIANT (type
);
3884 /* Return nonzero if the given type node represents a tagged type. */
3887 is_tagged_type (type
)
3890 enum tree_code code
= TREE_CODE (type
);
3892 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3893 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3896 /* Convert a DIE tag into its string name. */
3899 dwarf_tag_name (tag
)
3904 case DW_TAG_padding
:
3905 return "DW_TAG_padding";
3906 case DW_TAG_array_type
:
3907 return "DW_TAG_array_type";
3908 case DW_TAG_class_type
:
3909 return "DW_TAG_class_type";
3910 case DW_TAG_entry_point
:
3911 return "DW_TAG_entry_point";
3912 case DW_TAG_enumeration_type
:
3913 return "DW_TAG_enumeration_type";
3914 case DW_TAG_formal_parameter
:
3915 return "DW_TAG_formal_parameter";
3916 case DW_TAG_imported_declaration
:
3917 return "DW_TAG_imported_declaration";
3919 return "DW_TAG_label";
3920 case DW_TAG_lexical_block
:
3921 return "DW_TAG_lexical_block";
3923 return "DW_TAG_member";
3924 case DW_TAG_pointer_type
:
3925 return "DW_TAG_pointer_type";
3926 case DW_TAG_reference_type
:
3927 return "DW_TAG_reference_type";
3928 case DW_TAG_compile_unit
:
3929 return "DW_TAG_compile_unit";
3930 case DW_TAG_string_type
:
3931 return "DW_TAG_string_type";
3932 case DW_TAG_structure_type
:
3933 return "DW_TAG_structure_type";
3934 case DW_TAG_subroutine_type
:
3935 return "DW_TAG_subroutine_type";
3936 case DW_TAG_typedef
:
3937 return "DW_TAG_typedef";
3938 case DW_TAG_union_type
:
3939 return "DW_TAG_union_type";
3940 case DW_TAG_unspecified_parameters
:
3941 return "DW_TAG_unspecified_parameters";
3942 case DW_TAG_variant
:
3943 return "DW_TAG_variant";
3944 case DW_TAG_common_block
:
3945 return "DW_TAG_common_block";
3946 case DW_TAG_common_inclusion
:
3947 return "DW_TAG_common_inclusion";
3948 case DW_TAG_inheritance
:
3949 return "DW_TAG_inheritance";
3950 case DW_TAG_inlined_subroutine
:
3951 return "DW_TAG_inlined_subroutine";
3953 return "DW_TAG_module";
3954 case DW_TAG_ptr_to_member_type
:
3955 return "DW_TAG_ptr_to_member_type";
3956 case DW_TAG_set_type
:
3957 return "DW_TAG_set_type";
3958 case DW_TAG_subrange_type
:
3959 return "DW_TAG_subrange_type";
3960 case DW_TAG_with_stmt
:
3961 return "DW_TAG_with_stmt";
3962 case DW_TAG_access_declaration
:
3963 return "DW_TAG_access_declaration";
3964 case DW_TAG_base_type
:
3965 return "DW_TAG_base_type";
3966 case DW_TAG_catch_block
:
3967 return "DW_TAG_catch_block";
3968 case DW_TAG_const_type
:
3969 return "DW_TAG_const_type";
3970 case DW_TAG_constant
:
3971 return "DW_TAG_constant";
3972 case DW_TAG_enumerator
:
3973 return "DW_TAG_enumerator";
3974 case DW_TAG_file_type
:
3975 return "DW_TAG_file_type";
3977 return "DW_TAG_friend";
3978 case DW_TAG_namelist
:
3979 return "DW_TAG_namelist";
3980 case DW_TAG_namelist_item
:
3981 return "DW_TAG_namelist_item";
3982 case DW_TAG_packed_type
:
3983 return "DW_TAG_packed_type";
3984 case DW_TAG_subprogram
:
3985 return "DW_TAG_subprogram";
3986 case DW_TAG_template_type_param
:
3987 return "DW_TAG_template_type_param";
3988 case DW_TAG_template_value_param
:
3989 return "DW_TAG_template_value_param";
3990 case DW_TAG_thrown_type
:
3991 return "DW_TAG_thrown_type";
3992 case DW_TAG_try_block
:
3993 return "DW_TAG_try_block";
3994 case DW_TAG_variant_part
:
3995 return "DW_TAG_variant_part";
3996 case DW_TAG_variable
:
3997 return "DW_TAG_variable";
3998 case DW_TAG_volatile_type
:
3999 return "DW_TAG_volatile_type";
4000 case DW_TAG_MIPS_loop
:
4001 return "DW_TAG_MIPS_loop";
4002 case DW_TAG_format_label
:
4003 return "DW_TAG_format_label";
4004 case DW_TAG_function_template
:
4005 return "DW_TAG_function_template";
4006 case DW_TAG_class_template
:
4007 return "DW_TAG_class_template";
4008 case DW_TAG_GNU_BINCL
:
4009 return "DW_TAG_GNU_BINCL";
4010 case DW_TAG_GNU_EINCL
:
4011 return "DW_TAG_GNU_EINCL";
4013 return "DW_TAG_<unknown>";
4017 /* Convert a DWARF attribute code into its string name. */
4020 dwarf_attr_name (attr
)
4026 return "DW_AT_sibling";
4027 case DW_AT_location
:
4028 return "DW_AT_location";
4030 return "DW_AT_name";
4031 case DW_AT_ordering
:
4032 return "DW_AT_ordering";
4033 case DW_AT_subscr_data
:
4034 return "DW_AT_subscr_data";
4035 case DW_AT_byte_size
:
4036 return "DW_AT_byte_size";
4037 case DW_AT_bit_offset
:
4038 return "DW_AT_bit_offset";
4039 case DW_AT_bit_size
:
4040 return "DW_AT_bit_size";
4041 case DW_AT_element_list
:
4042 return "DW_AT_element_list";
4043 case DW_AT_stmt_list
:
4044 return "DW_AT_stmt_list";
4046 return "DW_AT_low_pc";
4048 return "DW_AT_high_pc";
4049 case DW_AT_language
:
4050 return "DW_AT_language";
4052 return "DW_AT_member";
4054 return "DW_AT_discr";
4055 case DW_AT_discr_value
:
4056 return "DW_AT_discr_value";
4057 case DW_AT_visibility
:
4058 return "DW_AT_visibility";
4060 return "DW_AT_import";
4061 case DW_AT_string_length
:
4062 return "DW_AT_string_length";
4063 case DW_AT_common_reference
:
4064 return "DW_AT_common_reference";
4065 case DW_AT_comp_dir
:
4066 return "DW_AT_comp_dir";
4067 case DW_AT_const_value
:
4068 return "DW_AT_const_value";
4069 case DW_AT_containing_type
:
4070 return "DW_AT_containing_type";
4071 case DW_AT_default_value
:
4072 return "DW_AT_default_value";
4074 return "DW_AT_inline";
4075 case DW_AT_is_optional
:
4076 return "DW_AT_is_optional";
4077 case DW_AT_lower_bound
:
4078 return "DW_AT_lower_bound";
4079 case DW_AT_producer
:
4080 return "DW_AT_producer";
4081 case DW_AT_prototyped
:
4082 return "DW_AT_prototyped";
4083 case DW_AT_return_addr
:
4084 return "DW_AT_return_addr";
4085 case DW_AT_start_scope
:
4086 return "DW_AT_start_scope";
4087 case DW_AT_stride_size
:
4088 return "DW_AT_stride_size";
4089 case DW_AT_upper_bound
:
4090 return "DW_AT_upper_bound";
4091 case DW_AT_abstract_origin
:
4092 return "DW_AT_abstract_origin";
4093 case DW_AT_accessibility
:
4094 return "DW_AT_accessibility";
4095 case DW_AT_address_class
:
4096 return "DW_AT_address_class";
4097 case DW_AT_artificial
:
4098 return "DW_AT_artificial";
4099 case DW_AT_base_types
:
4100 return "DW_AT_base_types";
4101 case DW_AT_calling_convention
:
4102 return "DW_AT_calling_convention";
4104 return "DW_AT_count";
4105 case DW_AT_data_member_location
:
4106 return "DW_AT_data_member_location";
4107 case DW_AT_decl_column
:
4108 return "DW_AT_decl_column";
4109 case DW_AT_decl_file
:
4110 return "DW_AT_decl_file";
4111 case DW_AT_decl_line
:
4112 return "DW_AT_decl_line";
4113 case DW_AT_declaration
:
4114 return "DW_AT_declaration";
4115 case DW_AT_discr_list
:
4116 return "DW_AT_discr_list";
4117 case DW_AT_encoding
:
4118 return "DW_AT_encoding";
4119 case DW_AT_external
:
4120 return "DW_AT_external";
4121 case DW_AT_frame_base
:
4122 return "DW_AT_frame_base";
4124 return "DW_AT_friend";
4125 case DW_AT_identifier_case
:
4126 return "DW_AT_identifier_case";
4127 case DW_AT_macro_info
:
4128 return "DW_AT_macro_info";
4129 case DW_AT_namelist_items
:
4130 return "DW_AT_namelist_items";
4131 case DW_AT_priority
:
4132 return "DW_AT_priority";
4134 return "DW_AT_segment";
4135 case DW_AT_specification
:
4136 return "DW_AT_specification";
4137 case DW_AT_static_link
:
4138 return "DW_AT_static_link";
4140 return "DW_AT_type";
4141 case DW_AT_use_location
:
4142 return "DW_AT_use_location";
4143 case DW_AT_variable_parameter
:
4144 return "DW_AT_variable_parameter";
4145 case DW_AT_virtuality
:
4146 return "DW_AT_virtuality";
4147 case DW_AT_vtable_elem_location
:
4148 return "DW_AT_vtable_elem_location";
4150 case DW_AT_allocated
:
4151 return "DW_AT_allocated";
4152 case DW_AT_associated
:
4153 return "DW_AT_associated";
4154 case DW_AT_data_location
:
4155 return "DW_AT_data_location";
4157 return "DW_AT_stride";
4158 case DW_AT_entry_pc
:
4159 return "DW_AT_entry_pc";
4160 case DW_AT_use_UTF8
:
4161 return "DW_AT_use_UTF8";
4162 case DW_AT_extension
:
4163 return "DW_AT_extension";
4165 return "DW_AT_ranges";
4166 case DW_AT_trampoline
:
4167 return "DW_AT_trampoline";
4168 case DW_AT_call_column
:
4169 return "DW_AT_call_column";
4170 case DW_AT_call_file
:
4171 return "DW_AT_call_file";
4172 case DW_AT_call_line
:
4173 return "DW_AT_call_line";
4175 case DW_AT_MIPS_fde
:
4176 return "DW_AT_MIPS_fde";
4177 case DW_AT_MIPS_loop_begin
:
4178 return "DW_AT_MIPS_loop_begin";
4179 case DW_AT_MIPS_tail_loop_begin
:
4180 return "DW_AT_MIPS_tail_loop_begin";
4181 case DW_AT_MIPS_epilog_begin
:
4182 return "DW_AT_MIPS_epilog_begin";
4183 case DW_AT_MIPS_loop_unroll_factor
:
4184 return "DW_AT_MIPS_loop_unroll_factor";
4185 case DW_AT_MIPS_software_pipeline_depth
:
4186 return "DW_AT_MIPS_software_pipeline_depth";
4187 case DW_AT_MIPS_linkage_name
:
4188 return "DW_AT_MIPS_linkage_name";
4189 case DW_AT_MIPS_stride
:
4190 return "DW_AT_MIPS_stride";
4191 case DW_AT_MIPS_abstract_name
:
4192 return "DW_AT_MIPS_abstract_name";
4193 case DW_AT_MIPS_clone_origin
:
4194 return "DW_AT_MIPS_clone_origin";
4195 case DW_AT_MIPS_has_inlines
:
4196 return "DW_AT_MIPS_has_inlines";
4198 case DW_AT_sf_names
:
4199 return "DW_AT_sf_names";
4200 case DW_AT_src_info
:
4201 return "DW_AT_src_info";
4202 case DW_AT_mac_info
:
4203 return "DW_AT_mac_info";
4204 case DW_AT_src_coords
:
4205 return "DW_AT_src_coords";
4206 case DW_AT_body_begin
:
4207 return "DW_AT_body_begin";
4208 case DW_AT_body_end
:
4209 return "DW_AT_body_end";
4210 case DW_AT_GNU_vector
:
4211 return "DW_AT_GNU_vector";
4213 case DW_AT_VMS_rtnbeg_pd_address
:
4214 return "DW_AT_VMS_rtnbeg_pd_address";
4217 return "DW_AT_<unknown>";
4221 /* Convert a DWARF value form code into its string name. */
4224 dwarf_form_name (form
)
4230 return "DW_FORM_addr";
4231 case DW_FORM_block2
:
4232 return "DW_FORM_block2";
4233 case DW_FORM_block4
:
4234 return "DW_FORM_block4";
4236 return "DW_FORM_data2";
4238 return "DW_FORM_data4";
4240 return "DW_FORM_data8";
4241 case DW_FORM_string
:
4242 return "DW_FORM_string";
4244 return "DW_FORM_block";
4245 case DW_FORM_block1
:
4246 return "DW_FORM_block1";
4248 return "DW_FORM_data1";
4250 return "DW_FORM_flag";
4252 return "DW_FORM_sdata";
4254 return "DW_FORM_strp";
4256 return "DW_FORM_udata";
4257 case DW_FORM_ref_addr
:
4258 return "DW_FORM_ref_addr";
4260 return "DW_FORM_ref1";
4262 return "DW_FORM_ref2";
4264 return "DW_FORM_ref4";
4266 return "DW_FORM_ref8";
4267 case DW_FORM_ref_udata
:
4268 return "DW_FORM_ref_udata";
4269 case DW_FORM_indirect
:
4270 return "DW_FORM_indirect";
4272 return "DW_FORM_<unknown>";
4276 /* Convert a DWARF type code into its string name. */
4280 dwarf_type_encoding_name (enc
)
4285 case DW_ATE_address
:
4286 return "DW_ATE_address";
4287 case DW_ATE_boolean
:
4288 return "DW_ATE_boolean";
4289 case DW_ATE_complex_float
:
4290 return "DW_ATE_complex_float";
4292 return "DW_ATE_float";
4294 return "DW_ATE_signed";
4295 case DW_ATE_signed_char
:
4296 return "DW_ATE_signed_char";
4297 case DW_ATE_unsigned
:
4298 return "DW_ATE_unsigned";
4299 case DW_ATE_unsigned_char
:
4300 return "DW_ATE_unsigned_char";
4302 return "DW_ATE_<unknown>";
4307 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4308 instance of an inlined instance of a decl which is local to an inline
4309 function, so we have to trace all of the way back through the origin chain
4310 to find out what sort of node actually served as the original seed for the
4314 decl_ultimate_origin (decl
)
4317 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4318 nodes in the function to point to themselves; ignore that if
4319 we're trying to output the abstract instance of this function. */
4320 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4323 #ifdef ENABLE_CHECKING
4324 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4325 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4326 most distant ancestor, this should never happen. */
4330 return DECL_ABSTRACT_ORIGIN (decl
);
4333 /* Determine the "ultimate origin" of a block. The block may be an inlined
4334 instance of an inlined instance of a block which is local to an inline
4335 function, so we have to trace all of the way back through the origin chain
4336 to find out what sort of node actually served as the original seed for the
4340 block_ultimate_origin (block
)
4343 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4345 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4346 nodes in the function to point to themselves; ignore that if
4347 we're trying to output the abstract instance of this function. */
4348 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4351 if (immediate_origin
== NULL_TREE
)
4356 tree lookahead
= immediate_origin
;
4360 ret_val
= lookahead
;
4361 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4362 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4364 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4370 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4371 of a virtual function may refer to a base class, so we check the 'this'
4375 decl_class_context (decl
)
4378 tree context
= NULL_TREE
;
4380 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4381 context
= DECL_CONTEXT (decl
);
4383 context
= TYPE_MAIN_VARIANT
4384 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4386 if (context
&& !TYPE_P (context
))
4387 context
= NULL_TREE
;
4392 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4393 addition order, and correct that in reverse_all_dies. */
4396 add_dwarf_attr (die
, attr
)
4400 if (die
!= NULL
&& attr
!= NULL
)
4402 attr
->dw_attr_next
= die
->die_attr
;
4403 die
->die_attr
= attr
;
4407 static inline dw_val_class
4411 return a
->dw_attr_val
.val_class
;
4414 /* Add a flag value attribute to a DIE. */
4417 add_AT_flag (die
, attr_kind
, flag
)
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_flag
;
4427 attr
->dw_attr_val
.v
.val_flag
= flag
;
4428 add_dwarf_attr (die
, attr
);
4431 static inline unsigned
4435 if (a
&& AT_class (a
) == dw_val_class_flag
)
4436 return a
->dw_attr_val
.v
.val_flag
;
4441 /* Add a signed integer attribute value to a DIE. */
4444 add_AT_int (die
, attr_kind
, int_val
)
4446 enum dwarf_attribute attr_kind
;
4449 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4451 attr
->dw_attr_next
= NULL
;
4452 attr
->dw_attr
= attr_kind
;
4453 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4454 attr
->dw_attr_val
.v
.val_int
= int_val
;
4455 add_dwarf_attr (die
, attr
);
4458 static inline long int
4462 if (a
&& AT_class (a
) == dw_val_class_const
)
4463 return a
->dw_attr_val
.v
.val_int
;
4468 /* Add an unsigned integer attribute value to a DIE. */
4471 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4473 enum dwarf_attribute attr_kind
;
4474 unsigned long unsigned_val
;
4476 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4478 attr
->dw_attr_next
= NULL
;
4479 attr
->dw_attr
= attr_kind
;
4480 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4481 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4482 add_dwarf_attr (die
, attr
);
4485 static inline unsigned long
4489 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4490 return a
->dw_attr_val
.v
.val_unsigned
;
4495 /* Add an unsigned double integer attribute value to a DIE. */
4498 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4500 enum dwarf_attribute attr_kind
;
4501 unsigned long val_hi
;
4502 unsigned long val_low
;
4504 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4506 attr
->dw_attr_next
= NULL
;
4507 attr
->dw_attr
= attr_kind
;
4508 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4509 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4510 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4511 add_dwarf_attr (die
, attr
);
4514 /* Add a floating point attribute value to a DIE and return it. */
4517 add_AT_float (die
, attr_kind
, length
, array
)
4519 enum dwarf_attribute attr_kind
;
4523 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4525 attr
->dw_attr_next
= NULL
;
4526 attr
->dw_attr
= attr_kind
;
4527 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4528 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4529 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4530 add_dwarf_attr (die
, attr
);
4533 /* Add a string attribute value to a DIE. */
4536 add_AT_string (die
, attr_kind
, str
)
4538 enum dwarf_attribute attr_kind
;
4541 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4542 struct indirect_string_node
*node
;
4544 if (! debug_str_hash
)
4546 debug_str_hash
= ht_create (10);
4547 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4550 node
= (struct indirect_string_node
*)
4551 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4552 strlen (str
), HT_ALLOC
);
4555 attr
->dw_attr_next
= NULL
;
4556 attr
->dw_attr
= attr_kind
;
4557 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4558 attr
->dw_attr_val
.v
.val_str
= node
;
4559 add_dwarf_attr (die
, attr
);
4562 static inline const char *
4566 if (a
&& AT_class (a
) == dw_val_class_str
)
4567 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4572 /* Find out whether a string should be output inline in DIE
4573 or out-of-line in .debug_str section. */
4579 if (a
&& AT_class (a
) == dw_val_class_str
)
4581 struct indirect_string_node
*node
;
4583 extern int const_labelno
;
4586 node
= a
->dw_attr_val
.v
.val_str
;
4590 len
= HT_LEN (&node
->id
) + 1;
4592 /* If the string is shorter or equal to the size of the reference, it is
4593 always better to put it inline. */
4594 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4595 return node
->form
= DW_FORM_string
;
4597 /* If we cannot expect the linker to merge strings in .debug_str
4598 section, only put it into .debug_str if it is worth even in this
4600 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4601 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4602 return node
->form
= DW_FORM_string
;
4604 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4606 node
->label
= xstrdup (label
);
4608 return node
->form
= DW_FORM_strp
;
4614 /* Add a DIE reference attribute value to a DIE. */
4617 add_AT_die_ref (die
, attr_kind
, targ_die
)
4619 enum dwarf_attribute attr_kind
;
4620 dw_die_ref targ_die
;
4622 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4624 attr
->dw_attr_next
= NULL
;
4625 attr
->dw_attr
= attr_kind
;
4626 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4627 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4628 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4629 add_dwarf_attr (die
, attr
);
4632 static inline dw_die_ref
4636 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4637 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4646 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4647 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4653 set_AT_ref_external (a
, i
)
4657 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4658 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4663 /* Add an FDE reference attribute value to a DIE. */
4666 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4668 enum dwarf_attribute attr_kind
;
4671 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4673 attr
->dw_attr_next
= NULL
;
4674 attr
->dw_attr
= attr_kind
;
4675 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4676 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4677 add_dwarf_attr (die
, attr
);
4680 /* Add a location description attribute value to a DIE. */
4683 add_AT_loc (die
, attr_kind
, loc
)
4685 enum dwarf_attribute attr_kind
;
4686 dw_loc_descr_ref loc
;
4688 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4690 attr
->dw_attr_next
= NULL
;
4691 attr
->dw_attr
= attr_kind
;
4692 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4693 attr
->dw_attr_val
.v
.val_loc
= loc
;
4694 add_dwarf_attr (die
, attr
);
4697 static inline dw_loc_descr_ref
4701 if (a
&& AT_class (a
) == dw_val_class_loc
)
4702 return a
->dw_attr_val
.v
.val_loc
;
4708 add_AT_loc_list (die
, attr_kind
, loc_list
)
4710 enum dwarf_attribute attr_kind
;
4711 dw_loc_list_ref loc_list
;
4713 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4715 attr
->dw_attr_next
= NULL
;
4716 attr
->dw_attr
= attr_kind
;
4717 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4718 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4719 add_dwarf_attr (die
, attr
);
4720 have_location_lists
= 1;
4723 static inline dw_loc_list_ref
4727 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4728 return a
->dw_attr_val
.v
.val_loc_list
;
4733 /* Add an address constant attribute value to a DIE. */
4736 add_AT_addr (die
, attr_kind
, addr
)
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_addr
;
4746 attr
->dw_attr_val
.v
.val_addr
= addr
;
4747 add_dwarf_attr (die
, attr
);
4754 if (a
&& AT_class (a
) == dw_val_class_addr
)
4755 return a
->dw_attr_val
.v
.val_addr
;
4760 /* Add a label identifier attribute value to a DIE. */
4763 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4765 enum dwarf_attribute attr_kind
;
4768 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4770 attr
->dw_attr_next
= NULL
;
4771 attr
->dw_attr
= attr_kind
;
4772 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4773 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4774 add_dwarf_attr (die
, attr
);
4777 /* Add a section offset attribute value to a DIE. */
4780 add_AT_lbl_offset (die
, attr_kind
, label
)
4782 enum dwarf_attribute attr_kind
;
4785 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4787 attr
->dw_attr_next
= NULL
;
4788 attr
->dw_attr
= attr_kind
;
4789 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4790 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4791 add_dwarf_attr (die
, attr
);
4794 /* Add an offset attribute value to a DIE. */
4797 add_AT_offset (die
, attr_kind
, offset
)
4799 enum dwarf_attribute attr_kind
;
4800 unsigned long offset
;
4802 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4804 attr
->dw_attr_next
= NULL
;
4805 attr
->dw_attr
= attr_kind
;
4806 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4807 attr
->dw_attr_val
.v
.val_offset
= offset
;
4808 add_dwarf_attr (die
, attr
);
4811 /* Add an range_list attribute value to a DIE. */
4814 add_AT_range_list (die
, attr_kind
, offset
)
4816 enum dwarf_attribute attr_kind
;
4817 unsigned long offset
;
4819 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4821 attr
->dw_attr_next
= NULL
;
4822 attr
->dw_attr
= attr_kind
;
4823 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4824 attr
->dw_attr_val
.v
.val_offset
= offset
;
4825 add_dwarf_attr (die
, attr
);
4828 static inline const char *
4832 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4833 || AT_class (a
) == dw_val_class_lbl_offset
))
4834 return a
->dw_attr_val
.v
.val_lbl_id
;
4839 /* Get the attribute of type attr_kind. */
4841 static inline dw_attr_ref
4842 get_AT (die
, attr_kind
)
4844 enum dwarf_attribute attr_kind
;
4847 dw_die_ref spec
= NULL
;
4851 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4852 if (a
->dw_attr
== attr_kind
)
4854 else if (a
->dw_attr
== DW_AT_specification
4855 || a
->dw_attr
== DW_AT_abstract_origin
)
4859 return get_AT (spec
, attr_kind
);
4865 /* Return the "low pc" attribute value, typically associated with a subprogram
4866 DIE. Return null if the "low pc" attribute is either not present, or if it
4867 cannot be represented as an assembler label identifier. */
4869 static inline const char *
4873 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4875 return a
? AT_lbl (a
) : NULL
;
4878 /* Return the "high pc" attribute value, typically associated with a subprogram
4879 DIE. Return null if the "high pc" attribute is either not present, or if it
4880 cannot be represented as an assembler label identifier. */
4882 static inline const char *
4886 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4888 return a
? AT_lbl (a
) : NULL
;
4891 /* Return the value of the string attribute designated by ATTR_KIND, or
4892 NULL if it is not present. */
4894 static inline const char *
4895 get_AT_string (die
, attr_kind
)
4897 enum dwarf_attribute attr_kind
;
4899 dw_attr_ref a
= get_AT (die
, attr_kind
);
4901 return a
? AT_string (a
) : NULL
;
4904 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4905 if it is not present. */
4908 get_AT_flag (die
, attr_kind
)
4910 enum dwarf_attribute attr_kind
;
4912 dw_attr_ref a
= get_AT (die
, attr_kind
);
4914 return a
? AT_flag (a
) : 0;
4917 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4918 if it is not present. */
4920 static inline unsigned
4921 get_AT_unsigned (die
, attr_kind
)
4923 enum dwarf_attribute attr_kind
;
4925 dw_attr_ref a
= get_AT (die
, attr_kind
);
4927 return a
? AT_unsigned (a
) : 0;
4930 static inline dw_die_ref
4931 get_AT_ref (die
, attr_kind
)
4933 enum dwarf_attribute attr_kind
;
4935 dw_attr_ref a
= get_AT (die
, attr_kind
);
4937 return a
? AT_ref (a
) : NULL
;
4943 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4945 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4946 || lang
== DW_LANG_C_plus_plus
);
4952 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4953 == DW_LANG_C_plus_plus
);
4959 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4961 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4967 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4969 return (lang
== DW_LANG_Java
);
4972 /* Free up the memory used by A. */
4974 static inline void free_AT
PARAMS ((dw_attr_ref
));
4979 switch (AT_class (a
))
4981 case dw_val_class_str
:
4982 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4983 a
->dw_attr_val
.v
.val_str
->refcount
--;
4986 case dw_val_class_lbl_id
:
4987 case dw_val_class_lbl_offset
:
4988 free (a
->dw_attr_val
.v
.val_lbl_id
);
4991 case dw_val_class_float
:
4992 free (a
->dw_attr_val
.v
.val_float
.array
);
5002 /* Remove the specified attribute if present. */
5005 remove_AT (die
, attr_kind
)
5007 enum dwarf_attribute attr_kind
;
5010 dw_attr_ref removed
= NULL
;
5014 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
5015 if ((*p
)->dw_attr
== attr_kind
)
5018 *p
= (*p
)->dw_attr_next
;
5027 /* Free up the memory used by DIE. */
5033 remove_children (die
);
5037 /* Discard the children of this DIE. */
5040 remove_children (die
)
5043 dw_die_ref child_die
= die
->die_child
;
5045 die
->die_child
= NULL
;
5047 while (child_die
!= NULL
)
5049 dw_die_ref tmp_die
= child_die
;
5052 child_die
= child_die
->die_sib
;
5054 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5056 dw_attr_ref tmp_a
= a
;
5058 a
= a
->dw_attr_next
;
5066 /* Add a child DIE below its parent. We build the lists up in reverse
5067 addition order, and correct that in reverse_all_dies. */
5070 add_child_die (die
, child_die
)
5072 dw_die_ref child_die
;
5074 if (die
!= NULL
&& child_die
!= NULL
)
5076 if (die
== child_die
)
5079 child_die
->die_parent
= die
;
5080 child_die
->die_sib
= die
->die_child
;
5081 die
->die_child
= child_die
;
5085 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5086 is the specification, to the front of PARENT's list of children. */
5089 splice_child_die (parent
, child
)
5090 dw_die_ref parent
, child
;
5094 /* We want the declaration DIE from inside the class, not the
5095 specification DIE at toplevel. */
5096 if (child
->die_parent
!= parent
)
5098 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5104 if (child
->die_parent
!= parent
5105 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5108 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5111 *p
= child
->die_sib
;
5115 child
->die_sib
= parent
->die_child
;
5116 parent
->die_child
= child
;
5119 /* Return a pointer to a newly created DIE node. */
5121 static inline dw_die_ref
5122 new_die (tag_value
, parent_die
, t
)
5123 enum dwarf_tag tag_value
;
5124 dw_die_ref parent_die
;
5127 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5129 die
->die_tag
= tag_value
;
5131 if (parent_die
!= NULL
)
5132 add_child_die (parent_die
, die
);
5135 limbo_die_node
*limbo_node
;
5137 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5138 limbo_node
->die
= die
;
5139 limbo_node
->created_for
= t
;
5140 limbo_node
->next
= limbo_die_list
;
5141 limbo_die_list
= limbo_node
;
5147 /* Return the DIE associated with the given type specifier. */
5149 static inline dw_die_ref
5150 lookup_type_die (type
)
5153 return TYPE_SYMTAB_DIE (type
);
5156 /* Equate a DIE to a given type specifier. */
5159 equate_type_number_to_die (type
, type_die
)
5161 dw_die_ref type_die
;
5163 TYPE_SYMTAB_DIE (type
) = type_die
;
5166 /* Return the DIE associated with a given declaration. */
5168 static inline dw_die_ref
5169 lookup_decl_die (decl
)
5172 unsigned decl_id
= DECL_UID (decl
);
5174 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5177 /* Equate a DIE to a particular declaration. */
5180 equate_decl_number_to_die (decl
, decl_die
)
5182 dw_die_ref decl_die
;
5184 unsigned int decl_id
= DECL_UID (decl
);
5185 unsigned int num_allocated
;
5187 if (decl_id
>= decl_die_table_allocated
)
5190 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5191 / DECL_DIE_TABLE_INCREMENT
)
5192 * DECL_DIE_TABLE_INCREMENT
;
5195 = (dw_die_ref
*) xrealloc (decl_die_table
,
5196 sizeof (dw_die_ref
) * num_allocated
);
5198 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5199 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5200 decl_die_table_allocated
= num_allocated
;
5203 if (decl_id
>= decl_die_table_in_use
)
5204 decl_die_table_in_use
= (decl_id
+ 1);
5206 decl_die_table
[decl_id
] = decl_die
;
5209 /* Keep track of the number of spaces used to indent the
5210 output of the debugging routines that print the structure of
5211 the DIE internal representation. */
5212 static int print_indent
;
5214 /* Indent the line the number of spaces given by print_indent. */
5217 print_spaces (outfile
)
5220 fprintf (outfile
, "%*s", print_indent
, "");
5223 /* Print the information associated with a given DIE, and its children.
5224 This routine is a debugging aid only. */
5227 print_die (die
, outfile
)
5234 print_spaces (outfile
);
5235 fprintf (outfile
, "DIE %4lu: %s\n",
5236 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5237 print_spaces (outfile
);
5238 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5239 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5241 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5243 print_spaces (outfile
);
5244 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5246 switch (AT_class (a
))
5248 case dw_val_class_addr
:
5249 fprintf (outfile
, "address");
5251 case dw_val_class_offset
:
5252 fprintf (outfile
, "offset");
5254 case dw_val_class_loc
:
5255 fprintf (outfile
, "location descriptor");
5257 case dw_val_class_loc_list
:
5258 fprintf (outfile
, "location list -> label:%s",
5259 AT_loc_list (a
)->ll_symbol
);
5261 case dw_val_class_range_list
:
5262 fprintf (outfile
, "range list");
5264 case dw_val_class_const
:
5265 fprintf (outfile
, "%ld", AT_int (a
));
5267 case dw_val_class_unsigned_const
:
5268 fprintf (outfile
, "%lu", AT_unsigned (a
));
5270 case dw_val_class_long_long
:
5271 fprintf (outfile
, "constant (%lu,%lu)",
5272 a
->dw_attr_val
.v
.val_long_long
.hi
,
5273 a
->dw_attr_val
.v
.val_long_long
.low
);
5275 case dw_val_class_float
:
5276 fprintf (outfile
, "floating-point constant");
5278 case dw_val_class_flag
:
5279 fprintf (outfile
, "%u", AT_flag (a
));
5281 case dw_val_class_die_ref
:
5282 if (AT_ref (a
) != NULL
)
5284 if (AT_ref (a
)->die_symbol
)
5285 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5287 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5290 fprintf (outfile
, "die -> <null>");
5292 case dw_val_class_lbl_id
:
5293 case dw_val_class_lbl_offset
:
5294 fprintf (outfile
, "label: %s", AT_lbl (a
));
5296 case dw_val_class_str
:
5297 if (AT_string (a
) != NULL
)
5298 fprintf (outfile
, "\"%s\"", AT_string (a
));
5300 fprintf (outfile
, "<null>");
5306 fprintf (outfile
, "\n");
5309 if (die
->die_child
!= NULL
)
5312 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5313 print_die (c
, outfile
);
5317 if (print_indent
== 0)
5318 fprintf (outfile
, "\n");
5321 /* Print the contents of the source code line number correspondence table.
5322 This routine is a debugging aid only. */
5325 print_dwarf_line_table (outfile
)
5329 dw_line_info_ref line_info
;
5331 fprintf (outfile
, "\n\nDWARF source line information\n");
5332 for (i
= 1; i
< line_info_table_in_use
; i
++)
5334 line_info
= &line_info_table
[i
];
5335 fprintf (outfile
, "%5d: ", i
);
5336 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5337 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5338 fprintf (outfile
, "\n");
5341 fprintf (outfile
, "\n\n");
5344 /* Print the information collected for a given DIE. */
5347 debug_dwarf_die (die
)
5350 print_die (die
, stderr
);
5353 /* Print all DWARF information collected for the compilation unit.
5354 This routine is a debugging aid only. */
5360 print_die (comp_unit_die
, stderr
);
5361 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5362 print_dwarf_line_table (stderr
);
5365 /* We build up the lists of children and attributes by pushing new ones
5366 onto the beginning of the list. Reverse the lists for DIE so that
5367 they are in order of addition. */
5370 reverse_die_lists (die
)
5373 dw_die_ref c
, cp
, cn
;
5374 dw_attr_ref a
, ap
, an
;
5376 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5378 an
= a
->dw_attr_next
;
5379 a
->dw_attr_next
= ap
;
5385 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5392 die
->die_child
= cp
;
5395 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5396 reverse all dies in add_sibling_attributes, which runs through all the dies,
5397 it would reverse all the dies. Now, however, since we don't call
5398 reverse_die_lists in add_sibling_attributes, we need a routine to
5399 recursively reverse all the dies. This is that routine. */
5402 reverse_all_dies (die
)
5407 reverse_die_lists (die
);
5409 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5410 reverse_all_dies (c
);
5413 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5414 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5415 DIE that marks the start of the DIEs for this include file. */
5418 push_new_compile_unit (old_unit
, bincl_die
)
5419 dw_die_ref old_unit
, bincl_die
;
5421 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5422 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5424 new_unit
->die_sib
= old_unit
;
5428 /* Close an include-file CU and reopen the enclosing one. */
5431 pop_compile_unit (old_unit
)
5432 dw_die_ref old_unit
;
5434 dw_die_ref new_unit
= old_unit
->die_sib
;
5436 old_unit
->die_sib
= NULL
;
5440 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5441 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5443 /* Calculate the checksum of a location expression. */
5446 loc_checksum (loc
, ctx
)
5447 dw_loc_descr_ref loc
;
5448 struct md5_ctx
*ctx
;
5450 CHECKSUM (loc
->dw_loc_opc
);
5451 CHECKSUM (loc
->dw_loc_oprnd1
);
5452 CHECKSUM (loc
->dw_loc_oprnd2
);
5455 /* Calculate the checksum of an attribute. */
5458 attr_checksum (at
, ctx
, mark
)
5460 struct md5_ctx
*ctx
;
5463 dw_loc_descr_ref loc
;
5466 CHECKSUM (at
->dw_attr
);
5468 /* We don't care about differences in file numbering. */
5469 if (at
->dw_attr
== DW_AT_decl_file
5470 /* Or that this was compiled with a different compiler snapshot; if
5471 the output is the same, that's what matters. */
5472 || at
->dw_attr
== DW_AT_producer
)
5475 switch (AT_class (at
))
5477 case dw_val_class_const
:
5478 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5480 case dw_val_class_unsigned_const
:
5481 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5483 case dw_val_class_long_long
:
5484 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5486 case dw_val_class_float
:
5487 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5489 case dw_val_class_flag
:
5490 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5492 case dw_val_class_str
:
5493 CHECKSUM_STRING (AT_string (at
));
5496 case dw_val_class_addr
:
5498 switch (GET_CODE (r
))
5501 CHECKSUM_STRING (XSTR (r
, 0));
5509 case dw_val_class_offset
:
5510 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5513 case dw_val_class_loc
:
5514 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5515 loc_checksum (loc
, ctx
);
5518 case dw_val_class_die_ref
:
5519 die_checksum (AT_ref (at
), ctx
, mark
);
5522 case dw_val_class_fde_ref
:
5523 case dw_val_class_lbl_id
:
5524 case dw_val_class_lbl_offset
:
5532 /* Calculate the checksum of a DIE. */
5535 die_checksum (die
, ctx
, mark
)
5537 struct md5_ctx
*ctx
;
5543 /* To avoid infinite recursion. */
5546 CHECKSUM (die
->die_mark
);
5549 die
->die_mark
= ++(*mark
);
5551 CHECKSUM (die
->die_tag
);
5553 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5554 attr_checksum (a
, ctx
, mark
);
5556 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5557 die_checksum (c
, ctx
, mark
);
5561 #undef CHECKSUM_STRING
5563 /* Do the location expressions look same? */
5565 same_loc_p (loc1
, loc2
, mark
)
5566 dw_loc_descr_ref loc1
;
5567 dw_loc_descr_ref loc2
;
5570 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5571 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5572 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5575 /* Do the values look the same? */
5577 same_dw_val_p (v1
, v2
, mark
)
5582 dw_loc_descr_ref loc1
, loc2
;
5586 if (v1
->val_class
!= v2
->val_class
)
5589 switch (v1
->val_class
)
5591 case dw_val_class_const
:
5592 return v1
->v
.val_int
== v2
->v
.val_int
;
5593 case dw_val_class_unsigned_const
:
5594 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5595 case dw_val_class_long_long
:
5596 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5597 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5598 case dw_val_class_float
:
5599 if (v1
->v
.val_float
.length
!= v2
->v
.val_float
.length
)
5601 for (i
= 0; i
< v1
->v
.val_float
.length
; i
++)
5602 if (v1
->v
.val_float
.array
[i
] != v2
->v
.val_float
.array
[i
])
5605 case dw_val_class_flag
:
5606 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5607 case dw_val_class_str
:
5608 return !strcmp((const char *) HT_STR (&v1
->v
.val_str
->id
),
5609 (const char *) HT_STR (&v2
->v
.val_str
->id
));
5611 case dw_val_class_addr
:
5612 r1
= v1
->v
.val_addr
;
5613 r2
= v2
->v
.val_addr
;
5614 if (GET_CODE (r1
) != GET_CODE (r2
))
5616 switch (GET_CODE (r1
))
5619 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5625 case dw_val_class_offset
:
5626 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5628 case dw_val_class_loc
:
5629 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5631 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5632 if (!same_loc_p (loc1
, loc2
, mark
))
5634 return !loc1
&& !loc2
;
5636 case dw_val_class_die_ref
:
5637 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5639 case dw_val_class_fde_ref
:
5640 case dw_val_class_lbl_id
:
5641 case dw_val_class_lbl_offset
:
5649 /* Do the attributes look the same? */
5652 same_attr_p (at1
, at2
, mark
)
5657 if (at1
->dw_attr
!= at2
->dw_attr
)
5660 /* We don't care about differences in file numbering. */
5661 if (at1
->dw_attr
== DW_AT_decl_file
5662 /* Or that this was compiled with a different compiler snapshot; if
5663 the output is the same, that's what matters. */
5664 || at1
->dw_attr
== DW_AT_producer
)
5667 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5670 /* Do the dies look the same? */
5673 same_die_p (die1
, die2
, mark
)
5681 /* To avoid infinite recursion. */
5683 return die1
->die_mark
== die2
->die_mark
;
5684 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5686 if (die1
->die_tag
!= die2
->die_tag
)
5689 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5691 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5692 if (!same_attr_p (a1
, a2
, mark
))
5697 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5699 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5700 if (!same_die_p (c1
, c2
, mark
))
5708 /* Do the dies look the same? Wrapper around same_die_p. */
5711 same_die_p_wrap (die1
, die2
)
5716 int ret
= same_die_p (die1
, die2
, &mark
);
5718 unmark_all_dies (die1
);
5719 unmark_all_dies (die2
);
5724 /* The prefix to attach to symbols on DIEs in the current comdat debug
5726 static char *comdat_symbol_id
;
5728 /* The index of the current symbol within the current comdat CU. */
5729 static unsigned int comdat_symbol_number
;
5731 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5732 children, and set comdat_symbol_id accordingly. */
5735 compute_section_prefix (unit_die
)
5736 dw_die_ref unit_die
;
5738 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5739 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5740 char *name
= (char *) alloca (strlen (base
) + 64);
5743 unsigned char checksum
[16];
5746 /* Compute the checksum of the DIE, then append part of it as hex digits to
5747 the name filename of the unit. */
5749 md5_init_ctx (&ctx
);
5751 die_checksum (unit_die
, &ctx
, &mark
);
5752 unmark_all_dies (unit_die
);
5753 md5_finish_ctx (&ctx
, checksum
);
5755 sprintf (name
, "%s.", base
);
5756 clean_symbol_name (name
);
5758 p
= name
+ strlen (name
);
5759 for (i
= 0; i
< 4; i
++)
5761 sprintf (p
, "%.2x", checksum
[i
]);
5765 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5766 comdat_symbol_number
= 0;
5769 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5775 switch (die
->die_tag
)
5777 case DW_TAG_array_type
:
5778 case DW_TAG_class_type
:
5779 case DW_TAG_enumeration_type
:
5780 case DW_TAG_pointer_type
:
5781 case DW_TAG_reference_type
:
5782 case DW_TAG_string_type
:
5783 case DW_TAG_structure_type
:
5784 case DW_TAG_subroutine_type
:
5785 case DW_TAG_union_type
:
5786 case DW_TAG_ptr_to_member_type
:
5787 case DW_TAG_set_type
:
5788 case DW_TAG_subrange_type
:
5789 case DW_TAG_base_type
:
5790 case DW_TAG_const_type
:
5791 case DW_TAG_file_type
:
5792 case DW_TAG_packed_type
:
5793 case DW_TAG_volatile_type
:
5794 case DW_TAG_typedef
:
5801 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5802 Basically, we want to choose the bits that are likely to be shared between
5803 compilations (types) and leave out the bits that are specific to individual
5804 compilations (functions). */
5810 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5811 we do for stabs. The advantage is a greater likelihood of sharing between
5812 objects that don't include headers in the same order (and therefore would
5813 put the base types in a different comdat). jason 8/28/00 */
5815 if (c
->die_tag
== DW_TAG_base_type
)
5818 if (c
->die_tag
== DW_TAG_pointer_type
5819 || c
->die_tag
== DW_TAG_reference_type
5820 || c
->die_tag
== DW_TAG_const_type
5821 || c
->die_tag
== DW_TAG_volatile_type
)
5823 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5825 return t
? is_comdat_die (t
) : 0;
5828 return is_type_die (c
);
5831 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5832 compilation unit. */
5838 return (is_type_die (c
)
5839 || (get_AT (c
, DW_AT_declaration
)
5840 && !get_AT (c
, DW_AT_specification
)));
5844 gen_internal_sym (prefix
)
5848 static int label_num
;
5850 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5851 return xstrdup (buf
);
5854 /* Assign symbols to all worthy DIEs under DIE. */
5857 assign_symbol_names (die
)
5862 if (is_symbol_die (die
))
5864 if (comdat_symbol_id
)
5866 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5868 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5869 comdat_symbol_id
, comdat_symbol_number
++);
5870 die
->die_symbol
= xstrdup (p
);
5873 die
->die_symbol
= gen_internal_sym ("LDIE");
5876 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5877 assign_symbol_names (c
);
5880 struct cu_hash_table_entry
5883 unsigned min_comdat_num
, max_comdat_num
;
5884 struct cu_hash_table_entry
*next
;
5887 /* Routines to manipulate hash table of CUs. */
5892 const struct cu_hash_table_entry
*entry
= of
;
5894 return htab_hash_string (entry
->cu
->die_symbol
);
5898 htab_cu_eq (of1
, of2
)
5902 const struct cu_hash_table_entry
*entry1
= of1
;
5903 const struct die_struct
*entry2
= of2
;
5905 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
5912 struct cu_hash_table_entry
*next
, *entry
= what
;
5922 /* Check whether we have already seen this CU and set up SYM_NUM
5925 check_duplicate_cu (cu
, htable
, sym_num
)
5930 struct cu_hash_table_entry dummy
;
5931 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
5933 dummy
.max_comdat_num
= 0;
5935 slot
= (struct cu_hash_table_entry
**)
5936 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5940 for (; entry
; last
= entry
, entry
= entry
->next
)
5942 if (same_die_p_wrap (cu
, entry
->cu
))
5948 *sym_num
= entry
->min_comdat_num
;
5952 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
5954 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
5955 entry
->next
= *slot
;
5961 /* Record SYM_NUM to record of CU in HTABLE. */
5963 record_comdat_symbol_number (cu
, htable
, sym_num
)
5968 struct cu_hash_table_entry
**slot
, *entry
;
5970 slot
= (struct cu_hash_table_entry
**)
5971 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5975 entry
->max_comdat_num
= sym_num
;
5978 /* Traverse the DIE (which is always comp_unit_die), and set up
5979 additional compilation units for each of the include files we see
5980 bracketed by BINCL/EINCL. */
5983 break_out_includes (die
)
5987 dw_die_ref unit
= NULL
;
5988 limbo_die_node
*node
, **pnode
;
5989 htab_t cu_hash_table
;
5991 for (ptr
= &(die
->die_child
); *ptr
;)
5993 dw_die_ref c
= *ptr
;
5995 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5996 || (unit
&& is_comdat_die (c
)))
5998 /* This DIE is for a secondary CU; remove it from the main one. */
6001 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6003 unit
= push_new_compile_unit (unit
, c
);
6006 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6008 unit
= pop_compile_unit (unit
);
6012 add_child_die (unit
, c
);
6016 /* Leave this DIE in the main CU. */
6017 ptr
= &(c
->die_sib
);
6023 /* We can only use this in debugging, since the frontend doesn't check
6024 to make sure that we leave every include file we enter. */
6029 assign_symbol_names (die
);
6030 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6031 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6037 compute_section_prefix (node
->die
);
6038 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6039 &comdat_symbol_number
);
6040 assign_symbol_names (node
->die
);
6042 *pnode
= node
->next
;
6045 pnode
= &node
->next
;
6046 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6047 comdat_symbol_number
);
6050 htab_delete (cu_hash_table
);
6053 /* Traverse the DIE and add a sibling attribute if it may have the
6054 effect of speeding up access to siblings. To save some space,
6055 avoid generating sibling attributes for DIE's without children. */
6058 add_sibling_attributes (die
)
6063 if (die
->die_tag
!= DW_TAG_compile_unit
6064 && die
->die_sib
&& die
->die_child
!= NULL
)
6065 /* Add the sibling link to the front of the attribute list. */
6066 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6068 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6069 add_sibling_attributes (c
);
6072 /* Output all location lists for the DIE and its children. */
6075 output_location_lists (die
)
6081 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6082 if (AT_class (d_attr
) == dw_val_class_loc_list
)
6083 output_loc_list (AT_loc_list (d_attr
));
6085 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6086 output_location_lists (c
);
6090 /* The format of each DIE (and its attribute value pairs) is encoded in an
6091 abbreviation table. This routine builds the abbreviation table and assigns
6092 a unique abbreviation id for each abbreviation entry. The children of each
6093 die are visited recursively. */
6096 build_abbrev_table (die
)
6099 unsigned long abbrev_id
;
6100 unsigned int n_alloc
;
6102 dw_attr_ref d_attr
, a_attr
;
6104 /* Scan the DIE references, and mark as external any that refer to
6105 DIEs from other CUs (i.e. those which are not marked). */
6106 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6107 if (AT_class (d_attr
) == dw_val_class_die_ref
6108 && AT_ref (d_attr
)->die_mark
== 0)
6110 if (AT_ref (d_attr
)->die_symbol
== 0)
6113 set_AT_ref_external (d_attr
, 1);
6116 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6118 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6120 if (abbrev
->die_tag
== die
->die_tag
)
6122 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6124 a_attr
= abbrev
->die_attr
;
6125 d_attr
= die
->die_attr
;
6127 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6129 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6130 || (value_format (a_attr
) != value_format (d_attr
)))
6133 a_attr
= a_attr
->dw_attr_next
;
6134 d_attr
= d_attr
->dw_attr_next
;
6137 if (a_attr
== NULL
&& d_attr
== NULL
)
6143 if (abbrev_id
>= abbrev_die_table_in_use
)
6145 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6147 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6149 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
6150 sizeof (dw_die_ref
) * n_alloc
);
6152 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
6153 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6154 abbrev_die_table_allocated
= n_alloc
;
6157 ++abbrev_die_table_in_use
;
6158 abbrev_die_table
[abbrev_id
] = die
;
6161 die
->die_abbrev
= abbrev_id
;
6162 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6163 build_abbrev_table (c
);
6166 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6169 constant_size (value
)
6170 long unsigned value
;
6177 log
= floor_log2 (value
);
6180 log
= 1 << (floor_log2 (log
) + 1);
6185 /* Return the size of a DIE as it is represented in the
6186 .debug_info section. */
6188 static unsigned long
6192 unsigned long size
= 0;
6195 size
+= size_of_uleb128 (die
->die_abbrev
);
6196 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6198 switch (AT_class (a
))
6200 case dw_val_class_addr
:
6201 size
+= DWARF2_ADDR_SIZE
;
6203 case dw_val_class_offset
:
6204 size
+= DWARF_OFFSET_SIZE
;
6206 case dw_val_class_loc
:
6208 unsigned long lsize
= size_of_locs (AT_loc (a
));
6211 size
+= constant_size (lsize
);
6215 case dw_val_class_loc_list
:
6216 size
+= DWARF_OFFSET_SIZE
;
6218 case dw_val_class_range_list
:
6219 size
+= DWARF_OFFSET_SIZE
;
6221 case dw_val_class_const
:
6222 size
+= size_of_sleb128 (AT_int (a
));
6224 case dw_val_class_unsigned_const
:
6225 size
+= constant_size (AT_unsigned (a
));
6227 case dw_val_class_long_long
:
6228 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6230 case dw_val_class_float
:
6231 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
6233 case dw_val_class_flag
:
6236 case dw_val_class_die_ref
:
6237 size
+= DWARF_OFFSET_SIZE
;
6239 case dw_val_class_fde_ref
:
6240 size
+= DWARF_OFFSET_SIZE
;
6242 case dw_val_class_lbl_id
:
6243 size
+= DWARF2_ADDR_SIZE
;
6245 case dw_val_class_lbl_offset
:
6246 size
+= DWARF_OFFSET_SIZE
;
6248 case dw_val_class_str
:
6249 if (AT_string_form (a
) == DW_FORM_strp
)
6250 size
+= DWARF_OFFSET_SIZE
;
6252 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
6262 /* Size the debugging information associated with a given DIE. Visits the
6263 DIE's children recursively. Updates the global variable next_die_offset, on
6264 each time through. Uses the current value of next_die_offset to update the
6265 die_offset field in each DIE. */
6268 calc_die_sizes (die
)
6273 die
->die_offset
= next_die_offset
;
6274 next_die_offset
+= size_of_die (die
);
6276 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6279 if (die
->die_child
!= NULL
)
6280 /* Count the null byte used to terminate sibling lists. */
6281 next_die_offset
+= 1;
6284 /* Set the marks for a die and its children. We do this so
6285 that we know whether or not a reference needs to use FORM_ref_addr; only
6286 DIEs in the same CU will be marked. We used to clear out the offset
6287 and use that as the flag, but ran into ordering problems. */
6299 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6303 /* Clear the marks for a die and its children. */
6315 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6319 /* Clear the marks for a die, its children and referred dies. */
6322 unmark_all_dies (die
)
6332 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6333 unmark_all_dies (c
);
6335 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6336 if (AT_class (a
) == dw_val_class_die_ref
)
6337 unmark_all_dies (AT_ref (a
));
6340 /* Return the size of the .debug_pubnames table generated for the
6341 compilation unit. */
6343 static unsigned long
6349 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6350 for (i
= 0; i
< pubname_table_in_use
; i
++)
6352 pubname_ref p
= &pubname_table
[i
];
6353 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6356 size
+= DWARF_OFFSET_SIZE
;
6360 /* Return the size of the information in the .debug_aranges section. */
6362 static unsigned long
6367 size
= DWARF_ARANGES_HEADER_SIZE
;
6369 /* Count the address/length pair for this compilation unit. */
6370 size
+= 2 * DWARF2_ADDR_SIZE
;
6371 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6373 /* Count the two zero words used to terminated the address range table. */
6374 size
+= 2 * DWARF2_ADDR_SIZE
;
6378 /* Select the encoding of an attribute value. */
6380 static enum dwarf_form
6384 switch (a
->dw_attr_val
.val_class
)
6386 case dw_val_class_addr
:
6387 return DW_FORM_addr
;
6388 case dw_val_class_range_list
:
6389 case dw_val_class_offset
:
6390 if (DWARF_OFFSET_SIZE
== 4)
6391 return DW_FORM_data4
;
6392 if (DWARF_OFFSET_SIZE
== 8)
6393 return DW_FORM_data8
;
6395 case dw_val_class_loc_list
:
6396 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6397 .debug_loc section */
6398 return DW_FORM_data4
;
6399 case dw_val_class_loc
:
6400 switch (constant_size (size_of_locs (AT_loc (a
))))
6403 return DW_FORM_block1
;
6405 return DW_FORM_block2
;
6409 case dw_val_class_const
:
6410 return DW_FORM_sdata
;
6411 case dw_val_class_unsigned_const
:
6412 switch (constant_size (AT_unsigned (a
)))
6415 return DW_FORM_data1
;
6417 return DW_FORM_data2
;
6419 return DW_FORM_data4
;
6421 return DW_FORM_data8
;
6425 case dw_val_class_long_long
:
6426 return DW_FORM_block1
;
6427 case dw_val_class_float
:
6428 return DW_FORM_block1
;
6429 case dw_val_class_flag
:
6430 return DW_FORM_flag
;
6431 case dw_val_class_die_ref
:
6432 if (AT_ref_external (a
))
6433 return DW_FORM_ref_addr
;
6436 case dw_val_class_fde_ref
:
6437 return DW_FORM_data
;
6438 case dw_val_class_lbl_id
:
6439 return DW_FORM_addr
;
6440 case dw_val_class_lbl_offset
:
6441 return DW_FORM_data
;
6442 case dw_val_class_str
:
6443 return AT_string_form (a
);
6450 /* Output the encoding of an attribute value. */
6453 output_value_format (a
)
6456 enum dwarf_form form
= value_format (a
);
6458 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6461 /* Output the .debug_abbrev section which defines the DIE abbreviation
6465 output_abbrev_section ()
6467 unsigned long abbrev_id
;
6471 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6473 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6475 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6476 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6477 dwarf_tag_name (abbrev
->die_tag
));
6479 if (abbrev
->die_child
!= NULL
)
6480 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6482 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6484 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6485 a_attr
= a_attr
->dw_attr_next
)
6487 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6488 dwarf_attr_name (a_attr
->dw_attr
));
6489 output_value_format (a_attr
);
6492 dw2_asm_output_data (1, 0, NULL
);
6493 dw2_asm_output_data (1, 0, NULL
);
6496 /* Terminate the table. */
6497 dw2_asm_output_data (1, 0, NULL
);
6500 /* Output a symbol we can use to refer to this DIE from another CU. */
6503 output_die_symbol (die
)
6506 char *sym
= die
->die_symbol
;
6511 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6512 /* We make these global, not weak; if the target doesn't support
6513 .linkonce, it doesn't support combining the sections, so debugging
6515 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, sym
);
6517 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6520 /* Return a new location list, given the begin and end range, and the
6521 expression. gensym tells us whether to generate a new internal symbol for
6522 this location list node, which is done for the head of the list only. */
6524 static inline dw_loc_list_ref
6525 new_loc_list (expr
, begin
, end
, section
, gensym
)
6526 dw_loc_descr_ref expr
;
6529 const char *section
;
6532 dw_loc_list_ref retlist
6533 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6535 retlist
->begin
= begin
;
6537 retlist
->expr
= expr
;
6538 retlist
->section
= section
;
6540 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6545 /* Add a location description expression to a location list */
6548 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6549 dw_loc_list_ref
*list_head
;
6550 dw_loc_descr_ref descr
;
6553 const char *section
;
6557 /* Find the end of the chain. */
6558 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6561 /* Add a new location list node to the list */
6562 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6565 /* Output the location list given to us */
6568 output_loc_list (list_head
)
6569 dw_loc_list_ref list_head
;
6571 dw_loc_list_ref curr
= list_head
;
6573 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6575 /* ??? This shouldn't be needed now that we've forced the
6576 compilation unit base address to zero when there is code
6577 in more than one section. */
6578 if (strcmp (curr
->section
, ".text") == 0)
6580 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6581 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6582 "Location list base address specifier fake entry");
6583 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6584 "Location list base address specifier base");
6587 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6591 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6592 "Location list begin address (%s)",
6593 list_head
->ll_symbol
);
6594 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6595 "Location list end address (%s)",
6596 list_head
->ll_symbol
);
6597 size
= size_of_locs (curr
->expr
);
6599 /* Output the block length for this list of location operations. */
6602 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6604 output_loc_sequence (curr
->expr
);
6607 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6608 "Location list terminator begin (%s)",
6609 list_head
->ll_symbol
);
6610 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6611 "Location list terminator end (%s)",
6612 list_head
->ll_symbol
);
6615 /* Output the DIE and its attributes. Called recursively to generate
6616 the definitions of each child DIE. */
6626 /* If someone in another CU might refer to us, set up a symbol for
6627 them to point to. */
6628 if (die
->die_symbol
)
6629 output_die_symbol (die
);
6631 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6632 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6634 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6636 const char *name
= dwarf_attr_name (a
->dw_attr
);
6638 switch (AT_class (a
))
6640 case dw_val_class_addr
:
6641 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6644 case dw_val_class_offset
:
6645 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6649 case dw_val_class_range_list
:
6651 char *p
= strchr (ranges_section_label
, '\0');
6653 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6654 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6660 case dw_val_class_loc
:
6661 size
= size_of_locs (AT_loc (a
));
6663 /* Output the block length for this list of location operations. */
6664 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6666 output_loc_sequence (AT_loc (a
));
6669 case dw_val_class_const
:
6670 /* ??? It would be slightly more efficient to use a scheme like is
6671 used for unsigned constants below, but gdb 4.x does not sign
6672 extend. Gdb 5.x does sign extend. */
6673 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6676 case dw_val_class_unsigned_const
:
6677 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6678 AT_unsigned (a
), "%s", name
);
6681 case dw_val_class_long_long
:
6683 unsigned HOST_WIDE_INT first
, second
;
6685 dw2_asm_output_data (1,
6686 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6689 if (WORDS_BIG_ENDIAN
)
6691 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6692 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6696 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6697 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6700 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6701 first
, "long long constant");
6702 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6707 case dw_val_class_float
:
6711 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6714 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6715 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6716 "fp constant word %u", i
);
6720 case dw_val_class_flag
:
6721 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6724 case dw_val_class_loc_list
:
6726 char *sym
= AT_loc_list (a
)->ll_symbol
;
6730 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6731 loc_section_label
, "%s", name
);
6735 case dw_val_class_die_ref
:
6736 if (AT_ref_external (a
))
6738 char *sym
= AT_ref (a
)->die_symbol
;
6742 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6744 else if (AT_ref (a
)->die_offset
== 0)
6747 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6751 case dw_val_class_fde_ref
:
6755 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6756 a
->dw_attr_val
.v
.val_fde_index
* 2);
6757 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6761 case dw_val_class_lbl_id
:
6762 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6765 case dw_val_class_lbl_offset
:
6766 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6769 case dw_val_class_str
:
6770 if (AT_string_form (a
) == DW_FORM_strp
)
6771 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6772 a
->dw_attr_val
.v
.val_str
->label
,
6773 "%s: \"%s\"", name
, AT_string (a
));
6775 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6783 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6786 /* Add null byte to terminate sibling list. */
6787 if (die
->die_child
!= NULL
)
6788 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6792 /* Output the compilation unit that appears at the beginning of the
6793 .debug_info section, and precedes the DIE descriptions. */
6796 output_compilation_unit_header ()
6798 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6799 "Length of Compilation Unit Info");
6800 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6801 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6802 "Offset Into Abbrev. Section");
6803 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6806 /* Output the compilation unit DIE and its children. */
6809 output_comp_unit (die
, output_if_empty
)
6811 int output_if_empty
;
6813 const char *secname
;
6816 /* Unless we are outputting main CU, we may throw away empty ones. */
6817 if (!output_if_empty
&& die
->die_child
== NULL
)
6820 /* Even if there are no children of this DIE, we must output the information
6821 about the compilation unit. Otherwise, on an empty translation unit, we
6822 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6823 will then complain when examining the file. First mark all the DIEs in
6824 this CU so we know which get local refs. */
6827 build_abbrev_table (die
);
6829 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6830 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6831 calc_die_sizes (die
);
6833 oldsym
= die
->die_symbol
;
6836 tmp
= (char *) alloca (strlen (oldsym
) + 24);
6838 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
6840 die
->die_symbol
= NULL
;
6843 secname
= (const char *) DEBUG_INFO_SECTION
;
6845 /* Output debugging information. */
6846 named_section_flags (secname
, SECTION_DEBUG
);
6847 output_compilation_unit_header ();
6850 /* Leave the marks on the main CU, so we can check them in
6855 die
->die_symbol
= oldsym
;
6859 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6860 output of lang_hooks.decl_printable_name for C++ looks like
6861 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6864 dwarf2_name (decl
, scope
)
6868 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6871 /* Add a new entry to .debug_pubnames if appropriate. */
6874 add_pubname (decl
, die
)
6880 if (! TREE_PUBLIC (decl
))
6883 if (pubname_table_in_use
== pubname_table_allocated
)
6885 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6887 = (pubname_ref
) xrealloc (pubname_table
,
6888 (pubname_table_allocated
6889 * sizeof (pubname_entry
)));
6892 p
= &pubname_table
[pubname_table_in_use
++];
6894 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6897 /* Output the public names table used to speed up access to externally
6898 visible names. For now, only generate entries for externally
6899 visible procedures. */
6905 unsigned long pubnames_length
= size_of_pubnames ();
6907 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6908 "Length of Public Names Info");
6909 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6910 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6911 "Offset of Compilation Unit Info");
6912 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6913 "Compilation Unit Length");
6915 for (i
= 0; i
< pubname_table_in_use
; i
++)
6917 pubname_ref pub
= &pubname_table
[i
];
6919 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6920 if (pub
->die
->die_mark
== 0)
6923 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6926 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6929 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6932 /* Add a new entry to .debug_aranges if appropriate. */
6935 add_arange (decl
, die
)
6939 if (! DECL_SECTION_NAME (decl
))
6942 if (arange_table_in_use
== arange_table_allocated
)
6944 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6945 arange_table
= (dw_die_ref
*)
6946 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6949 arange_table
[arange_table_in_use
++] = die
;
6952 /* Output the information that goes into the .debug_aranges table.
6953 Namely, define the beginning and ending address range of the
6954 text section generated for this compilation unit. */
6960 unsigned long aranges_length
= size_of_aranges ();
6962 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6963 "Length of Address Ranges Info");
6964 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6965 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6966 "Offset of Compilation Unit Info");
6967 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6968 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6970 /* We need to align to twice the pointer size here. */
6971 if (DWARF_ARANGES_PAD_SIZE
)
6973 /* Pad using a 2 byte words so that padding is correct for any
6975 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6976 2 * DWARF2_ADDR_SIZE
);
6977 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6978 dw2_asm_output_data (2, 0, NULL
);
6981 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6982 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6983 text_section_label
, "Length");
6985 for (i
= 0; i
< arange_table_in_use
; i
++)
6987 dw_die_ref die
= arange_table
[i
];
6989 /* We shouldn't see aranges for DIEs outside of the main CU. */
6990 if (die
->die_mark
== 0)
6993 if (die
->die_tag
== DW_TAG_subprogram
)
6995 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6997 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
6998 get_AT_low_pc (die
), "Length");
7002 /* A static variable; extract the symbol from DW_AT_location.
7003 Note that this code isn't currently hit, as we only emit
7004 aranges for functions (jason 9/23/99). */
7005 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7006 dw_loc_descr_ref loc
;
7008 if (! a
|| AT_class (a
) != dw_val_class_loc
)
7012 if (loc
->dw_loc_opc
!= DW_OP_addr
)
7015 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7016 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7017 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7018 get_AT_unsigned (die
, DW_AT_byte_size
),
7023 /* Output the terminator words. */
7024 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7025 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7028 /* Add a new entry to .debug_ranges. Return the offset at which it
7035 unsigned int in_use
= ranges_table_in_use
;
7037 if (in_use
== ranges_table_allocated
)
7039 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7040 ranges_table
= (dw_ranges_ref
)
7041 xrealloc (ranges_table
, (ranges_table_allocated
7042 * sizeof (struct dw_ranges_struct
)));
7045 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7046 ranges_table_in_use
= in_use
+ 1;
7048 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7055 static const char *const start_fmt
= "Offset 0x%x";
7056 const char *fmt
= start_fmt
;
7058 for (i
= 0; i
< ranges_table_in_use
; i
++)
7060 int block_num
= ranges_table
[i
].block_num
;
7064 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7065 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7067 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7068 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7070 /* If all code is in the text section, then the compilation
7071 unit base address defaults to DW_AT_low_pc, which is the
7072 base of the text section. */
7073 if (separate_line_info_table_in_use
== 0)
7075 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7077 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7078 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7079 text_section_label
, NULL
);
7082 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7083 compilation unit base address to zero, which allows us to
7084 use absolute addresses, and not worry about whether the
7085 target supports cross-section arithmetic. */
7088 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7089 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7090 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7097 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7098 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7104 /* Data structure containing information about input files. */
7107 char *path
; /* Complete file name. */
7108 char *fname
; /* File name part. */
7109 int length
; /* Length of entire string. */
7110 int file_idx
; /* Index in input file table. */
7111 int dir_idx
; /* Index in directory table. */
7114 /* Data structure containing information about directories with source
7118 char *path
; /* Path including directory name. */
7119 int length
; /* Path length. */
7120 int prefix
; /* Index of directory entry which is a prefix. */
7121 int count
; /* Number of files in this directory. */
7122 int dir_idx
; /* Index of directory used as base. */
7123 int used
; /* Used in the end? */
7126 /* Callback function for file_info comparison. We sort by looking at
7127 the directories in the path. */
7130 file_info_cmp (p1
, p2
)
7134 const struct file_info
*s1
= p1
;
7135 const struct file_info
*s2
= p2
;
7139 /* Take care of file names without directories. We need to make sure that
7140 we return consistent values to qsort since some will get confused if
7141 we return the same value when identical operands are passed in opposite
7142 orders. So if neither has a directory, return 0 and otherwise return
7143 1 or -1 depending on which one has the directory. */
7144 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7145 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7147 cp1
= (unsigned char *) s1
->path
;
7148 cp2
= (unsigned char *) s2
->path
;
7154 /* Reached the end of the first path? If so, handle like above. */
7155 if ((cp1
== (unsigned char *) s1
->fname
)
7156 || (cp2
== (unsigned char *) s2
->fname
))
7157 return ((cp2
== (unsigned char *) s2
->fname
)
7158 - (cp1
== (unsigned char *) s1
->fname
));
7160 /* Character of current path component the same? */
7161 else if (*cp1
!= *cp2
)
7166 /* Output the directory table and the file name table. We try to minimize
7167 the total amount of memory needed. A heuristic is used to avoid large
7168 slowdowns with many input files. */
7171 output_file_names ()
7173 struct file_info
*files
;
7174 struct dir_info
*dirs
;
7183 /* Allocate the various arrays we need. */
7184 files
= (struct file_info
*) alloca (file_table
.in_use
7185 * sizeof (struct file_info
));
7186 dirs
= (struct dir_info
*) alloca (file_table
.in_use
7187 * sizeof (struct dir_info
));
7189 /* Sort the file names. */
7190 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7194 /* Skip all leading "./". */
7195 f
= file_table
.table
[i
];
7196 while (f
[0] == '.' && f
[1] == '/')
7199 /* Create a new array entry. */
7201 files
[i
].length
= strlen (f
);
7202 files
[i
].file_idx
= i
;
7204 /* Search for the file name part. */
7205 f
= strrchr (f
, '/');
7206 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7209 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
7211 /* Find all the different directories used. */
7212 dirs
[0].path
= files
[1].path
;
7213 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7214 dirs
[0].prefix
= -1;
7216 dirs
[0].dir_idx
= 0;
7218 files
[1].dir_idx
= 0;
7221 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
7222 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7223 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7224 dirs
[ndirs
- 1].length
) == 0)
7226 /* Same directory as last entry. */
7227 files
[i
].dir_idx
= ndirs
- 1;
7228 ++dirs
[ndirs
- 1].count
;
7234 /* This is a new directory. */
7235 dirs
[ndirs
].path
= files
[i
].path
;
7236 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7237 dirs
[ndirs
].count
= 1;
7238 dirs
[ndirs
].dir_idx
= ndirs
;
7239 dirs
[ndirs
].used
= 0;
7240 files
[i
].dir_idx
= ndirs
;
7242 /* Search for a prefix. */
7243 dirs
[ndirs
].prefix
= -1;
7244 for (j
= 0; j
< ndirs
; j
++)
7245 if (dirs
[j
].length
< dirs
[ndirs
].length
7246 && dirs
[j
].length
> 1
7247 && (dirs
[ndirs
].prefix
== -1
7248 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7249 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7250 dirs
[ndirs
].prefix
= j
;
7255 /* Now to the actual work. We have to find a subset of the directories which
7256 allow expressing the file name using references to the directory table
7257 with the least amount of characters. We do not do an exhaustive search
7258 where we would have to check out every combination of every single
7259 possible prefix. Instead we use a heuristic which provides nearly optimal
7260 results in most cases and never is much off. */
7261 saved
= (int *) alloca (ndirs
* sizeof (int));
7262 savehere
= (int *) alloca (ndirs
* sizeof (int));
7264 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7265 for (i
= 0; i
< ndirs
; i
++)
7270 /* We can always save some space for the current directory. But this
7271 does not mean it will be enough to justify adding the directory. */
7272 savehere
[i
] = dirs
[i
].length
;
7273 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7275 for (j
= i
+ 1; j
< ndirs
; j
++)
7278 if (saved
[j
] < dirs
[i
].length
)
7280 /* Determine whether the dirs[i] path is a prefix of the
7285 while (k
!= -1 && k
!= i
)
7290 /* Yes it is. We can possibly safe some memory but
7291 writing the filenames in dirs[j] relative to
7293 savehere
[j
] = dirs
[i
].length
;
7294 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7299 /* Check whether we can safe enough to justify adding the dirs[i]
7301 if (total
> dirs
[i
].length
+ 1)
7303 /* It's worthwhile adding. */
7304 for (j
= i
; j
< ndirs
; j
++)
7305 if (savehere
[j
] > 0)
7307 /* Remember how much we saved for this directory so far. */
7308 saved
[j
] = savehere
[j
];
7310 /* Remember the prefix directory. */
7311 dirs
[j
].dir_idx
= i
;
7316 /* We have to emit them in the order they appear in the file_table array
7317 since the index is used in the debug info generation. To do this
7318 efficiently we generate a back-mapping of the indices first. */
7319 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
7320 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7322 backmap
[files
[i
].file_idx
] = i
;
7324 /* Mark this directory as used. */
7325 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7328 /* That was it. We are ready to emit the information. First emit the
7329 directory name table. We have to make sure the first actually emitted
7330 directory name has index one; zero is reserved for the current working
7331 directory. Make sure we do not confuse these indices with the one for the
7332 constructed table (even though most of the time they are identical). */
7334 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7335 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7336 if (dirs
[i
].used
!= 0)
7338 dirs
[i
].used
= idx
++;
7339 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7340 "Directory Entry: 0x%x", dirs
[i
].used
);
7343 dw2_asm_output_data (1, 0, "End directory table");
7345 /* Correct the index for the current working directory entry if it
7347 if (idx_offset
== 0)
7350 /* Now write all the file names. */
7351 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7353 int file_idx
= backmap
[i
];
7354 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7356 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7357 "File Entry: 0x%x", i
);
7359 /* Include directory index. */
7360 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7362 /* Modification time. */
7363 dw2_asm_output_data_uleb128 (0, NULL
);
7365 /* File length in bytes. */
7366 dw2_asm_output_data_uleb128 (0, NULL
);
7369 dw2_asm_output_data (1, 0, "End file name table");
7373 /* Output the source line number correspondence information. This
7374 information goes into the .debug_line section. */
7379 char l1
[20], l2
[20], p1
[20], p2
[20];
7380 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7381 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7384 unsigned long lt_index
;
7385 unsigned long current_line
;
7388 unsigned long current_file
;
7389 unsigned long function
;
7391 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7392 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7393 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7394 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7396 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7397 "Length of Source Line Info");
7398 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7400 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7401 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7402 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7404 /* Define the architecture-dependent minimum instruction length (in
7405 bytes). In this implementation of DWARF, this field is used for
7406 information purposes only. Since GCC generates assembly language,
7407 we have no a priori knowledge of how many instruction bytes are
7408 generated for each source line, and therefore can use only the
7409 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7410 commands. Accordingly, we fix this as `1', which is "correct
7411 enough" for all architectures, and don't let the target override. */
7412 dw2_asm_output_data (1, 1,
7413 "Minimum Instruction Length");
7415 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7416 "Default is_stmt_start flag");
7417 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7418 "Line Base Value (Special Opcodes)");
7419 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7420 "Line Range Value (Special Opcodes)");
7421 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7422 "Special Opcode Base");
7424 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7428 case DW_LNS_advance_pc
:
7429 case DW_LNS_advance_line
:
7430 case DW_LNS_set_file
:
7431 case DW_LNS_set_column
:
7432 case DW_LNS_fixed_advance_pc
:
7440 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7444 /* Write out the information about the files we use. */
7445 output_file_names ();
7446 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7448 /* We used to set the address register to the first location in the text
7449 section here, but that didn't accomplish anything since we already
7450 have a line note for the opening brace of the first function. */
7452 /* Generate the line number to PC correspondence table, encoded as
7453 a series of state machine operations. */
7456 strcpy (prev_line_label
, text_section_label
);
7457 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7459 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7462 /* Disable this optimization for now; GDB wants to see two line notes
7463 at the beginning of a function so it can find the end of the
7466 /* Don't emit anything for redundant notes. Just updating the
7467 address doesn't accomplish anything, because we already assume
7468 that anything after the last address is this line. */
7469 if (line_info
->dw_line_num
== current_line
7470 && line_info
->dw_file_num
== current_file
)
7474 /* Emit debug info for the address of the current line.
7476 Unfortunately, we have little choice here currently, and must always
7477 use the most general form. GCC does not know the address delta
7478 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7479 attributes which will give an upper bound on the address range. We
7480 could perhaps use length attributes to determine when it is safe to
7481 use DW_LNS_fixed_advance_pc. */
7483 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7486 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7487 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7488 "DW_LNS_fixed_advance_pc");
7489 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7493 /* This can handle any delta. This takes
7494 4+DWARF2_ADDR_SIZE bytes. */
7495 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7496 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7497 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7498 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7501 strcpy (prev_line_label
, line_label
);
7503 /* Emit debug info for the source file of the current line, if
7504 different from the previous line. */
7505 if (line_info
->dw_file_num
!= current_file
)
7507 current_file
= line_info
->dw_file_num
;
7508 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7509 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7510 file_table
.table
[current_file
]);
7513 /* Emit debug info for the current line number, choosing the encoding
7514 that uses the least amount of space. */
7515 if (line_info
->dw_line_num
!= current_line
)
7517 line_offset
= line_info
->dw_line_num
- current_line
;
7518 line_delta
= line_offset
- DWARF_LINE_BASE
;
7519 current_line
= line_info
->dw_line_num
;
7520 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7521 /* This can handle deltas from -10 to 234, using the current
7522 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7524 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7525 "line %lu", current_line
);
7528 /* This can handle any delta. This takes at least 4 bytes,
7529 depending on the value being encoded. */
7530 dw2_asm_output_data (1, DW_LNS_advance_line
,
7531 "advance to line %lu", current_line
);
7532 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7533 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7537 /* We still need to start a new row, so output a copy insn. */
7538 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7541 /* Emit debug info for the address of the end of the function. */
7544 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7545 "DW_LNS_fixed_advance_pc");
7546 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7550 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7551 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7552 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7553 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7556 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7557 dw2_asm_output_data_uleb128 (1, NULL
);
7558 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7563 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7565 dw_separate_line_info_ref line_info
7566 = &separate_line_info_table
[lt_index
];
7569 /* Don't emit anything for redundant notes. */
7570 if (line_info
->dw_line_num
== current_line
7571 && line_info
->dw_file_num
== current_file
7572 && line_info
->function
== function
)
7576 /* Emit debug info for the address of the current line. If this is
7577 a new function, or the first line of a function, then we need
7578 to handle it differently. */
7579 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7581 if (function
!= line_info
->function
)
7583 function
= line_info
->function
;
7585 /* Set the address register to the first line in the function */
7586 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7587 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7588 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7589 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7593 /* ??? See the DW_LNS_advance_pc comment above. */
7596 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7597 "DW_LNS_fixed_advance_pc");
7598 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7602 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7603 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7604 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7605 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7609 strcpy (prev_line_label
, line_label
);
7611 /* Emit debug info for the source file of the current line, if
7612 different from the previous line. */
7613 if (line_info
->dw_file_num
!= current_file
)
7615 current_file
= line_info
->dw_file_num
;
7616 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7617 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7618 file_table
.table
[current_file
]);
7621 /* Emit debug info for the current line number, choosing the encoding
7622 that uses the least amount of space. */
7623 if (line_info
->dw_line_num
!= current_line
)
7625 line_offset
= line_info
->dw_line_num
- current_line
;
7626 line_delta
= line_offset
- DWARF_LINE_BASE
;
7627 current_line
= line_info
->dw_line_num
;
7628 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7629 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7630 "line %lu", current_line
);
7633 dw2_asm_output_data (1, DW_LNS_advance_line
,
7634 "advance to line %lu", current_line
);
7635 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7636 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7640 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7648 /* If we're done with a function, end its sequence. */
7649 if (lt_index
== separate_line_info_table_in_use
7650 || separate_line_info_table
[lt_index
].function
!= function
)
7655 /* Emit debug info for the address of the end of the function. */
7656 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7659 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7660 "DW_LNS_fixed_advance_pc");
7661 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7665 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7666 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7667 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7668 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7671 /* Output the marker for the end of this sequence. */
7672 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7673 dw2_asm_output_data_uleb128 (1, NULL
);
7674 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7678 /* Output the marker for the end of the line number info. */
7679 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7682 /* Given a pointer to a tree node for some base type, return a pointer to
7683 a DIE that describes the given type.
7685 This routine must only be called for GCC type nodes that correspond to
7686 Dwarf base (fundamental) types. */
7689 base_type_die (type
)
7692 dw_die_ref base_type_result
;
7693 const char *type_name
;
7694 enum dwarf_type encoding
;
7695 tree name
= TYPE_NAME (type
);
7697 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7702 if (TREE_CODE (name
) == TYPE_DECL
)
7703 name
= DECL_NAME (name
);
7705 type_name
= IDENTIFIER_POINTER (name
);
7708 type_name
= "__unknown__";
7710 switch (TREE_CODE (type
))
7713 /* Carefully distinguish the C character types, without messing
7714 up if the language is not C. Note that we check only for the names
7715 that contain spaces; other names might occur by coincidence in other
7717 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7718 && (type
== char_type_node
7719 || ! strcmp (type_name
, "signed char")
7720 || ! strcmp (type_name
, "unsigned char"))))
7722 if (TREE_UNSIGNED (type
))
7723 encoding
= DW_ATE_unsigned
;
7725 encoding
= DW_ATE_signed
;
7728 /* else fall through. */
7731 /* GNU Pascal/Ada CHAR type. Not used in C. */
7732 if (TREE_UNSIGNED (type
))
7733 encoding
= DW_ATE_unsigned_char
;
7735 encoding
= DW_ATE_signed_char
;
7739 encoding
= DW_ATE_float
;
7742 /* Dwarf2 doesn't know anything about complex ints, so use
7743 a user defined type for it. */
7745 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7746 encoding
= DW_ATE_complex_float
;
7748 encoding
= DW_ATE_lo_user
;
7752 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7753 encoding
= DW_ATE_boolean
;
7757 /* No other TREE_CODEs are Dwarf fundamental types. */
7761 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7762 if (demangle_name_func
)
7763 type_name
= (*demangle_name_func
) (type_name
);
7765 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7766 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7767 int_size_in_bytes (type
));
7768 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7770 return base_type_result
;
7773 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7774 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7775 a given type is generally the same as the given type, except that if the
7776 given type is a pointer or reference type, then the root type of the given
7777 type is the root type of the "basis" type for the pointer or reference
7778 type. (This definition of the "root" type is recursive.) Also, the root
7779 type of a `const' qualified type or a `volatile' qualified type is the
7780 root type of the given type without the qualifiers. */
7786 if (TREE_CODE (type
) == ERROR_MARK
)
7787 return error_mark_node
;
7789 switch (TREE_CODE (type
))
7792 return error_mark_node
;
7795 case REFERENCE_TYPE
:
7796 return type_main_variant (root_type (TREE_TYPE (type
)));
7799 return type_main_variant (type
);
7803 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7804 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7810 switch (TREE_CODE (type
))
7825 case QUAL_UNION_TYPE
:
7830 case REFERENCE_TYPE
:
7844 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7845 node, return the size in bits for the type if it is a constant, or else
7846 return the alignment for the type if the type's size is not constant, or
7847 else return BITS_PER_WORD if the type actually turns out to be an
7850 static inline unsigned HOST_WIDE_INT
7851 simple_type_size_in_bits (type
)
7855 if (TREE_CODE (type
) == ERROR_MARK
)
7856 return BITS_PER_WORD
;
7857 else if (TYPE_SIZE (type
) == NULL_TREE
)
7859 else if (host_integerp (TYPE_SIZE (type
), 1))
7860 return tree_low_cst (TYPE_SIZE (type
), 1);
7862 return TYPE_ALIGN (type
);
7865 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7866 entry that chains various modifiers in front of the given type. */
7869 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7872 int is_volatile_type
;
7873 dw_die_ref context_die
;
7875 enum tree_code code
= TREE_CODE (type
);
7876 dw_die_ref mod_type_die
= NULL
;
7877 dw_die_ref sub_die
= NULL
;
7878 tree item_type
= NULL
;
7880 if (code
!= ERROR_MARK
)
7882 tree qualified_type
;
7884 /* See if we already have the appropriately qualified variant of
7887 = get_qualified_type (type
,
7888 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7890 ? TYPE_QUAL_VOLATILE
: 0)));
7892 /* If we do, then we can just use its DIE, if it exists. */
7895 mod_type_die
= lookup_type_die (qualified_type
);
7897 return mod_type_die
;
7900 /* Handle C typedef types. */
7901 if (qualified_type
&& TYPE_NAME (qualified_type
)
7902 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7903 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7905 tree type_name
= TYPE_NAME (qualified_type
);
7906 tree dtype
= TREE_TYPE (type_name
);
7908 if (qualified_type
== dtype
)
7910 /* For a named type, use the typedef. */
7911 gen_type_die (qualified_type
, context_die
);
7912 mod_type_die
= lookup_type_die (qualified_type
);
7914 else if (is_const_type
< TYPE_READONLY (dtype
)
7915 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7916 /* cv-unqualified version of named type. Just use the unnamed
7917 type to which it refers. */
7919 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7920 is_const_type
, is_volatile_type
,
7923 /* Else cv-qualified version of named type; fall through. */
7929 else if (is_const_type
)
7931 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7932 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7934 else if (is_volatile_type
)
7936 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7937 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7939 else if (code
== POINTER_TYPE
)
7941 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7942 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
7943 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
7945 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7947 item_type
= TREE_TYPE (type
);
7949 else if (code
== REFERENCE_TYPE
)
7951 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7952 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
7953 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
7955 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7957 item_type
= TREE_TYPE (type
);
7959 else if (is_base_type (type
))
7960 mod_type_die
= base_type_die (type
);
7963 gen_type_die (type
, context_die
);
7965 /* We have to get the type_main_variant here (and pass that to the
7966 `lookup_type_die' routine) because the ..._TYPE node we have
7967 might simply be a *copy* of some original type node (where the
7968 copy was created to help us keep track of typedef names) and
7969 that copy might have a different TYPE_UID from the original
7971 if (TREE_CODE (type
) != VECTOR_TYPE
)
7972 mod_type_die
= lookup_type_die (type_main_variant (type
));
7974 /* Vectors have the debugging information in the type,
7975 not the main variant. */
7976 mod_type_die
= lookup_type_die (type
);
7977 if (mod_type_die
== NULL
)
7981 /* We want to equate the qualified type to the die below. */
7982 type
= qualified_type
;
7986 equate_type_number_to_die (type
, mod_type_die
);
7988 /* We must do this after the equate_type_number_to_die call, in case
7989 this is a recursive type. This ensures that the modified_type_die
7990 recursion will terminate even if the type is recursive. Recursive
7991 types are possible in Ada. */
7992 sub_die
= modified_type_die (item_type
,
7993 TYPE_READONLY (item_type
),
7994 TYPE_VOLATILE (item_type
),
7997 if (sub_die
!= NULL
)
7998 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8000 return mod_type_die
;
8003 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8004 an enumerated type. */
8010 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8013 /* Return the register number described by a given RTL node. */
8019 unsigned regno
= REGNO (rtl
);
8021 if (regno
>= FIRST_PSEUDO_REGISTER
)
8024 return DBX_REGISTER_NUMBER (regno
);
8027 /* Return a location descriptor that designates a machine register or
8028 zero if there is no such. */
8030 static dw_loc_descr_ref
8031 reg_loc_descriptor (rtl
)
8034 dw_loc_descr_ref loc_result
= NULL
;
8037 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8040 reg
= reg_number (rtl
);
8042 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
8044 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
8049 /* Return a location descriptor that designates a constant. */
8051 static dw_loc_descr_ref
8052 int_loc_descriptor (i
)
8055 enum dwarf_location_atom op
;
8057 /* Pick the smallest representation of a constant, rather than just
8058 defaulting to the LEB encoding. */
8062 op
= DW_OP_lit0
+ i
;
8065 else if (i
<= 0xffff)
8067 else if (HOST_BITS_PER_WIDE_INT
== 32
8077 else if (i
>= -0x8000)
8079 else if (HOST_BITS_PER_WIDE_INT
== 32
8080 || i
>= -0x80000000)
8086 return new_loc_descr (op
, i
, 0);
8089 /* Return a location descriptor that designates a base+offset location. */
8091 static dw_loc_descr_ref
8092 based_loc_descr (reg
, offset
)
8096 dw_loc_descr_ref loc_result
;
8097 /* For the "frame base", we use the frame pointer or stack pointer
8098 registers, since the RTL for local variables is relative to one of
8100 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8101 ? HARD_FRAME_POINTER_REGNUM
8102 : STACK_POINTER_REGNUM
);
8105 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8107 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8109 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8114 /* Return true if this RTL expression describes a base+offset calculation. */
8120 return (GET_CODE (rtl
) == PLUS
8121 && ((GET_CODE (XEXP (rtl
, 0)) == REG
8122 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8123 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8126 /* The following routine converts the RTL for a variable or parameter
8127 (resident in memory) into an equivalent Dwarf representation of a
8128 mechanism for getting the address of that same variable onto the top of a
8129 hypothetical "address evaluation" stack.
8131 When creating memory location descriptors, we are effectively transforming
8132 the RTL for a memory-resident object into its Dwarf postfix expression
8133 equivalent. This routine recursively descends an RTL tree, turning
8134 it into Dwarf postfix code as it goes.
8136 MODE is the mode of the memory reference, needed to handle some
8137 autoincrement addressing modes.
8139 Return 0 if we can't represent the location. */
8141 static dw_loc_descr_ref
8142 mem_loc_descriptor (rtl
, mode
)
8144 enum machine_mode mode
;
8146 dw_loc_descr_ref mem_loc_result
= NULL
;
8148 /* Note that for a dynamically sized array, the location we will generate a
8149 description of here will be the lowest numbered location which is
8150 actually within the array. That's *not* necessarily the same as the
8151 zeroth element of the array. */
8153 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8154 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8157 switch (GET_CODE (rtl
))
8162 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8163 just fall into the SUBREG code. */
8165 /* ... fall through ... */
8168 /* The case of a subreg may arise when we have a local (register)
8169 variable or a formal (register) parameter which doesn't quite fill
8170 up an entire register. For now, just assume that it is
8171 legitimate to make the Dwarf info refer to the whole register which
8172 contains the given subreg. */
8173 rtl
= SUBREG_REG (rtl
);
8175 /* ... fall through ... */
8178 /* Whenever a register number forms a part of the description of the
8179 method for calculating the (dynamic) address of a memory resident
8180 object, DWARF rules require the register number be referred to as
8181 a "base register". This distinction is not based in any way upon
8182 what category of register the hardware believes the given register
8183 belongs to. This is strictly DWARF terminology we're dealing with
8184 here. Note that in cases where the location of a memory-resident
8185 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8186 OP_CONST (0)) the actual DWARF location descriptor that we generate
8187 may just be OP_BASEREG (basereg). This may look deceptively like
8188 the object in question was allocated to a register (rather than in
8189 memory) so DWARF consumers need to be aware of the subtle
8190 distinction between OP_REG and OP_BASEREG. */
8191 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8192 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
8196 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8197 if (mem_loc_result
!= 0)
8198 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8202 /* Some ports can transform a symbol ref into a label ref, because
8203 the symbol ref is too far away and has to be dumped into a constant
8207 /* Alternatively, the symbol in the constant pool might be referenced
8208 by a different symbol. */
8209 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8212 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8214 if (GET_CODE (tmp
) == SYMBOL_REF
)
8217 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8218 get_pool_constant_mark (tmp
, &marked
);
8223 /* If all references to this pool constant were optimized away,
8224 it was not output and thus we can't represent it.
8225 FIXME: might try to use DW_OP_const_value here, though
8226 DW_OP_piece complicates it. */
8231 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8232 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8233 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8234 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8238 /* Extract the PLUS expression nested inside and fall into
8240 rtl
= XEXP (rtl
, 1);
8245 /* Turn these into a PLUS expression and fall into the PLUS code
8247 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8248 GEN_INT (GET_CODE (rtl
) == PRE_INC
8249 ? GET_MODE_UNIT_SIZE (mode
)
8250 : -GET_MODE_UNIT_SIZE (mode
)));
8252 /* ... fall through ... */
8256 if (is_based_loc (rtl
))
8257 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
8258 INTVAL (XEXP (rtl
, 1)));
8261 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8262 if (mem_loc_result
== 0)
8265 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8266 && INTVAL (XEXP (rtl
, 1)) >= 0)
8267 add_loc_descr (&mem_loc_result
,
8268 new_loc_descr (DW_OP_plus_uconst
,
8269 INTVAL (XEXP (rtl
, 1)), 0));
8272 add_loc_descr (&mem_loc_result
,
8273 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8274 add_loc_descr (&mem_loc_result
,
8275 new_loc_descr (DW_OP_plus
, 0, 0));
8282 /* If a pseudo-reg is optimized away, it is possible for it to
8283 be replaced with a MEM containing a multiply. */
8284 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8285 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8287 if (op0
== 0 || op1
== 0)
8290 mem_loc_result
= op0
;
8291 add_loc_descr (&mem_loc_result
, op1
);
8292 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
8297 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8301 /* If this is a MEM, return its address. Otherwise, we can't
8303 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
8304 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
8312 return mem_loc_result
;
8315 /* Return a descriptor that describes the concatenation of two locations.
8316 This is typically a complex variable. */
8318 static dw_loc_descr_ref
8319 concat_loc_descriptor (x0
, x1
)
8322 dw_loc_descr_ref cc_loc_result
= NULL
;
8323 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8324 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8326 if (x0_ref
== 0 || x1_ref
== 0)
8329 cc_loc_result
= x0_ref
;
8330 add_loc_descr (&cc_loc_result
,
8331 new_loc_descr (DW_OP_piece
,
8332 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8334 add_loc_descr (&cc_loc_result
, x1_ref
);
8335 add_loc_descr (&cc_loc_result
,
8336 new_loc_descr (DW_OP_piece
,
8337 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8339 return cc_loc_result
;
8342 /* Output a proper Dwarf location descriptor for a variable or parameter
8343 which is either allocated in a register or in a memory location. For a
8344 register, we just generate an OP_REG and the register number. For a
8345 memory location we provide a Dwarf postfix expression describing how to
8346 generate the (dynamic) address of the object onto the address stack.
8348 If we don't know how to describe it, return 0. */
8350 static dw_loc_descr_ref
8351 loc_descriptor (rtl
)
8354 dw_loc_descr_ref loc_result
= NULL
;
8356 switch (GET_CODE (rtl
))
8359 /* The case of a subreg may arise when we have a local (register)
8360 variable or a formal (register) parameter which doesn't quite fill
8361 up an entire register. For now, just assume that it is
8362 legitimate to make the Dwarf info refer to the whole register which
8363 contains the given subreg. */
8364 rtl
= SUBREG_REG (rtl
);
8366 /* ... fall through ... */
8369 loc_result
= reg_loc_descriptor (rtl
);
8373 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8377 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8387 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8388 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8389 looking for an address. Otherwise, we return a value. If we can't make a
8390 descriptor, return 0. */
8392 static dw_loc_descr_ref
8393 loc_descriptor_from_tree (loc
, addressp
)
8397 dw_loc_descr_ref ret
, ret1
;
8399 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
8400 enum dwarf_location_atom op
;
8402 /* ??? Most of the time we do not take proper care for sign/zero
8403 extending the values properly. Hopefully this won't be a real
8406 switch (TREE_CODE (loc
))
8411 case WITH_RECORD_EXPR
:
8412 case PLACEHOLDER_EXPR
:
8413 /* This case involves extracting fields from an object to determine the
8414 position of other fields. We don't try to encode this here. The
8415 only user of this is Ada, which encodes the needed information using
8416 the names of types. */
8423 /* We can support this only if we can look through conversions and
8424 find an INDIRECT_EXPR. */
8425 for (loc
= TREE_OPERAND (loc
, 0);
8426 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8427 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8428 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8429 || TREE_CODE (loc
) == SAVE_EXPR
;
8430 loc
= TREE_OPERAND (loc
, 0))
8433 return (TREE_CODE (loc
) == INDIRECT_REF
8434 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8438 if (DECL_THREAD_LOCAL (loc
))
8442 #ifndef ASM_OUTPUT_DWARF_DTPREL
8443 /* If this is not defined, we have no way to emit the data. */
8447 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8448 look up addresses of objects in the current module. */
8449 if (DECL_EXTERNAL (loc
))
8452 rtl
= rtl_for_decl_location (loc
);
8453 if (rtl
== NULL_RTX
)
8456 if (GET_CODE (rtl
) != MEM
)
8458 rtl
= XEXP (rtl
, 0);
8459 if (! CONSTANT_P (rtl
))
8462 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8463 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8464 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8466 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8467 add_loc_descr (&ret
, ret1
);
8476 rtx rtl
= rtl_for_decl_location (loc
);
8478 if (rtl
== NULL_RTX
)
8480 else if (CONSTANT_P (rtl
))
8482 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8483 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8484 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8489 enum machine_mode mode
= GET_MODE (rtl
);
8491 if (GET_CODE (rtl
) == MEM
)
8494 rtl
= XEXP (rtl
, 0);
8497 ret
= mem_loc_descriptor (rtl
, mode
);
8503 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8508 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8512 case NON_LVALUE_EXPR
:
8513 case VIEW_CONVERT_EXPR
:
8515 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8520 case ARRAY_RANGE_REF
:
8523 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8524 enum machine_mode mode
;
8527 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8528 &unsignedp
, &volatilep
);
8533 ret
= loc_descriptor_from_tree (obj
, 1);
8535 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8538 if (offset
!= NULL_TREE
)
8540 /* Variable offset. */
8541 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8542 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8548 bytepos
= bitpos
/ BITS_PER_UNIT
;
8550 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8551 else if (bytepos
< 0)
8553 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8554 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8560 if (host_integerp (loc
, 0))
8561 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8566 case TRUTH_AND_EXPR
:
8567 case TRUTH_ANDIF_EXPR
:
8572 case TRUTH_XOR_EXPR
:
8578 case TRUTH_ORIF_EXPR
:
8583 case TRUNC_DIV_EXPR
:
8591 case TRUNC_MOD_EXPR
:
8604 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8608 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8609 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8611 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8615 add_loc_descr (&ret
,
8616 new_loc_descr (DW_OP_plus_uconst
,
8617 tree_low_cst (TREE_OPERAND (loc
, 1),
8627 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8634 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8641 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8648 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8663 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8664 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8665 if (ret
== 0 || ret1
== 0)
8668 add_loc_descr (&ret
, ret1
);
8669 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8672 case TRUTH_NOT_EXPR
:
8686 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8690 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8694 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8695 build (LT_EXPR
, integer_type_node
,
8696 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8697 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8699 /* ... fall through ... */
8703 dw_loc_descr_ref lhs
8704 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8705 dw_loc_descr_ref rhs
8706 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8707 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8709 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8710 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8713 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8714 add_loc_descr (&ret
, bra_node
);
8716 add_loc_descr (&ret
, rhs
);
8717 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8718 add_loc_descr (&ret
, jump_node
);
8720 add_loc_descr (&ret
, lhs
);
8721 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8722 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8724 /* ??? Need a node to point the skip at. Use a nop. */
8725 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8726 add_loc_descr (&ret
, tmp
);
8727 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8728 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8736 /* Show if we can't fill the request for an address. */
8737 if (addressp
&& indirect_p
== 0)
8740 /* If we've got an address and don't want one, dereference. */
8741 if (!addressp
&& indirect_p
> 0)
8743 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8745 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8747 else if (size
== DWARF2_ADDR_SIZE
)
8750 op
= DW_OP_deref_size
;
8752 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8758 /* Given a value, round it up to the lowest multiple of `boundary'
8759 which is not less than the value itself. */
8761 static inline HOST_WIDE_INT
8762 ceiling (value
, boundary
)
8763 HOST_WIDE_INT value
;
8764 unsigned int boundary
;
8766 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8769 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8770 pointer to the declared type for the relevant field variable, or return
8771 `integer_type_node' if the given node turns out to be an
8780 if (TREE_CODE (decl
) == ERROR_MARK
)
8781 return integer_type_node
;
8783 type
= DECL_BIT_FIELD_TYPE (decl
);
8784 if (type
== NULL_TREE
)
8785 type
= TREE_TYPE (decl
);
8790 /* Given a pointer to a tree node, return the alignment in bits for
8791 it, or else return BITS_PER_WORD if the node actually turns out to
8792 be an ERROR_MARK node. */
8794 static inline unsigned
8795 simple_type_align_in_bits (type
)
8798 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8801 static inline unsigned
8802 simple_decl_align_in_bits (decl
)
8805 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8808 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8809 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8810 or return 0 if we are unable to determine what that offset is, either
8811 because the argument turns out to be a pointer to an ERROR_MARK node, or
8812 because the offset is actually variable. (We can't handle the latter case
8815 static HOST_WIDE_INT
8816 field_byte_offset (decl
)
8819 unsigned int type_align_in_bits
;
8820 unsigned int decl_align_in_bits
;
8821 unsigned HOST_WIDE_INT type_size_in_bits
;
8822 HOST_WIDE_INT object_offset_in_bits
;
8824 tree field_size_tree
;
8825 HOST_WIDE_INT bitpos_int
;
8826 HOST_WIDE_INT deepest_bitpos
;
8827 unsigned HOST_WIDE_INT field_size_in_bits
;
8829 if (TREE_CODE (decl
) == ERROR_MARK
)
8831 else if (TREE_CODE (decl
) != FIELD_DECL
)
8834 type
= field_type (decl
);
8835 field_size_tree
= DECL_SIZE (decl
);
8837 /* The size could be unspecified if there was an error, or for
8838 a flexible array member. */
8839 if (! field_size_tree
)
8840 field_size_tree
= bitsize_zero_node
;
8842 /* We cannot yet cope with fields whose positions are variable, so
8843 for now, when we see such things, we simply return 0. Someday, we may
8844 be able to handle such cases, but it will be damn difficult. */
8845 if (! host_integerp (bit_position (decl
), 0))
8848 bitpos_int
= int_bit_position (decl
);
8850 /* If we don't know the size of the field, pretend it's a full word. */
8851 if (host_integerp (field_size_tree
, 1))
8852 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
8854 field_size_in_bits
= BITS_PER_WORD
;
8856 type_size_in_bits
= simple_type_size_in_bits (type
);
8857 type_align_in_bits
= simple_type_align_in_bits (type
);
8858 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
8860 /* The GCC front-end doesn't make any attempt to keep track of the starting
8861 bit offset (relative to the start of the containing structure type) of the
8862 hypothetical "containing object" for a bit-field. Thus, when computing
8863 the byte offset value for the start of the "containing object" of a
8864 bit-field, we must deduce this information on our own. This can be rather
8865 tricky to do in some cases. For example, handling the following structure
8866 type definition when compiling for an i386/i486 target (which only aligns
8867 long long's to 32-bit boundaries) can be very tricky:
8869 struct S { int field1; long long field2:31; };
8871 Fortunately, there is a simple rule-of-thumb which can be used in such
8872 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8873 structure shown above. It decides to do this based upon one simple rule
8874 for bit-field allocation. GCC allocates each "containing object" for each
8875 bit-field at the first (i.e. lowest addressed) legitimate alignment
8876 boundary (based upon the required minimum alignment for the declared type
8877 of the field) which it can possibly use, subject to the condition that
8878 there is still enough available space remaining in the containing object
8879 (when allocated at the selected point) to fully accommodate all of the
8880 bits of the bit-field itself.
8882 This simple rule makes it obvious why GCC allocates 8 bytes for each
8883 object of the structure type shown above. When looking for a place to
8884 allocate the "containing object" for `field2', the compiler simply tries
8885 to allocate a 64-bit "containing object" at each successive 32-bit
8886 boundary (starting at zero) until it finds a place to allocate that 64-
8887 bit field such that at least 31 contiguous (and previously unallocated)
8888 bits remain within that selected 64 bit field. (As it turns out, for the
8889 example above, the compiler finds it is OK to allocate the "containing
8890 object" 64-bit field at bit-offset zero within the structure type.)
8892 Here we attempt to work backwards from the limited set of facts we're
8893 given, and we try to deduce from those facts, where GCC must have believed
8894 that the containing object started (within the structure type). The value
8895 we deduce is then used (by the callers of this routine) to generate
8896 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8897 and, in the case of DW_AT_location, regular fields as well). */
8899 /* Figure out the bit-distance from the start of the structure to the
8900 "deepest" bit of the bit-field. */
8901 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
8903 /* This is the tricky part. Use some fancy footwork to deduce where the
8904 lowest addressed bit of the containing object must be. */
8905 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8907 /* Round up to type_align by default. This works best for bitfields. */
8908 object_offset_in_bits
+= type_align_in_bits
- 1;
8909 object_offset_in_bits
/= type_align_in_bits
;
8910 object_offset_in_bits
*= type_align_in_bits
;
8912 if (object_offset_in_bits
> bitpos_int
)
8914 /* Sigh, the decl must be packed. */
8915 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
8917 /* Round up to decl_align instead. */
8918 object_offset_in_bits
+= decl_align_in_bits
- 1;
8919 object_offset_in_bits
/= decl_align_in_bits
;
8920 object_offset_in_bits
*= decl_align_in_bits
;
8923 return object_offset_in_bits
/ BITS_PER_UNIT
;
8926 /* The following routines define various Dwarf attributes and any data
8927 associated with them. */
8929 /* Add a location description attribute value to a DIE.
8931 This emits location attributes suitable for whole variables and
8932 whole parameters. Note that the location attributes for struct fields are
8933 generated by the routine `data_member_location_attribute' below. */
8936 add_AT_location_description (die
, attr_kind
, descr
)
8938 enum dwarf_attribute attr_kind
;
8939 dw_loc_descr_ref descr
;
8942 add_AT_loc (die
, attr_kind
, descr
);
8945 /* Attach the specialized form of location attribute used for data members of
8946 struct and union types. In the special case of a FIELD_DECL node which
8947 represents a bit-field, the "offset" part of this special location
8948 descriptor must indicate the distance in bytes from the lowest-addressed
8949 byte of the containing struct or union type to the lowest-addressed byte of
8950 the "containing object" for the bit-field. (See the `field_byte_offset'
8953 For any given bit-field, the "containing object" is a hypothetical object
8954 (of some integral or enum type) within which the given bit-field lives. The
8955 type of this hypothetical "containing object" is always the same as the
8956 declared type of the individual bit-field itself (for GCC anyway... the
8957 DWARF spec doesn't actually mandate this). Note that it is the size (in
8958 bytes) of the hypothetical "containing object" which will be given in the
8959 DW_AT_byte_size attribute for this bit-field. (See the
8960 `byte_size_attribute' function below.) It is also used when calculating the
8961 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8965 add_data_member_location_attribute (die
, decl
)
8970 dw_loc_descr_ref loc_descr
= 0;
8972 if (TREE_CODE (decl
) == TREE_VEC
)
8974 /* We're working on the TAG_inheritance for a base class. */
8975 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
8977 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8978 aren't at a fixed offset from all (sub)objects of the same
8979 type. We need to extract the appropriate offset from our
8980 vtable. The following dwarf expression means
8982 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8984 This is specific to the V3 ABI, of course. */
8986 dw_loc_descr_ref tmp
;
8988 /* Make a copy of the object address. */
8989 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
8990 add_loc_descr (&loc_descr
, tmp
);
8992 /* Extract the vtable address. */
8993 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
8994 add_loc_descr (&loc_descr
, tmp
);
8996 /* Calculate the address of the offset. */
8997 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9001 tmp
= int_loc_descriptor (-offset
);
9002 add_loc_descr (&loc_descr
, tmp
);
9003 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9004 add_loc_descr (&loc_descr
, tmp
);
9006 /* Extract the offset. */
9007 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9008 add_loc_descr (&loc_descr
, tmp
);
9010 /* Add it to the object address. */
9011 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9012 add_loc_descr (&loc_descr
, tmp
);
9015 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9018 offset
= field_byte_offset (decl
);
9022 enum dwarf_location_atom op
;
9024 /* The DWARF2 standard says that we should assume that the structure
9025 address is already on the stack, so we can specify a structure field
9026 address by using DW_OP_plus_uconst. */
9028 #ifdef MIPS_DEBUGGING_INFO
9029 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9030 operator correctly. It works only if we leave the offset on the
9034 op
= DW_OP_plus_uconst
;
9037 loc_descr
= new_loc_descr (op
, offset
, 0);
9040 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9043 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
9044 does not have a "location" either in memory or in a register. These
9045 things can arise in GNU C when a constant is passed as an actual parameter
9046 to an inlined function. They can also arise in C++ where declared
9047 constants do not necessarily get memory "homes". */
9050 add_const_value_attribute (die
, rtl
)
9054 switch (GET_CODE (rtl
))
9057 /* Note that a CONST_INT rtx could represent either an integer
9058 or a floating-point constant. A CONST_INT is used whenever
9059 the constant will fit into a single word. In all such
9060 cases, the original mode of the constant value is wiped
9061 out, and the CONST_INT rtx is assigned VOIDmode. */
9063 HOST_WIDE_INT val
= INTVAL (rtl
);
9065 /* ??? We really should be using HOST_WIDE_INT throughout. */
9066 if (val
< 0 && (long) val
== val
)
9067 add_AT_int (die
, DW_AT_const_value
, (long) val
);
9068 else if ((unsigned long) val
== (unsigned HOST_WIDE_INT
) val
)
9069 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned long) val
);
9072 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
9073 add_AT_long_long (die
, DW_AT_const_value
,
9074 val
>> HOST_BITS_PER_LONG
, val
);
9083 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9084 floating-point constant. A CONST_DOUBLE is used whenever the
9085 constant requires more than one word in order to be adequately
9086 represented. We output CONST_DOUBLEs as blocks. */
9088 enum machine_mode mode
= GET_MODE (rtl
);
9090 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9092 unsigned length
= GET_MODE_SIZE (mode
) / 4;
9093 long *array
= (long *) xmalloc (sizeof (long) * length
);
9096 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9100 REAL_VALUE_TO_TARGET_SINGLE (rv
, array
[0]);
9104 REAL_VALUE_TO_TARGET_DOUBLE (rv
, array
);
9109 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv
, array
);
9116 add_AT_float (die
, DW_AT_const_value
, length
, array
);
9120 /* ??? We really should be using HOST_WIDE_INT throughout. */
9121 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
9124 add_AT_long_long (die
, DW_AT_const_value
,
9125 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9131 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9137 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9138 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
9142 /* In cases where an inlined instance of an inline function is passed
9143 the address of an `auto' variable (which is local to the caller) we
9144 can get a situation where the DECL_RTL of the artificial local
9145 variable (for the inlining) which acts as a stand-in for the
9146 corresponding formal parameter (of the inline function) will look
9147 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9148 exactly a compile-time constant expression, but it isn't the address
9149 of the (artificial) local variable either. Rather, it represents the
9150 *value* which the artificial local variable always has during its
9151 lifetime. We currently have no way to represent such quasi-constant
9152 values in Dwarf, so for now we just punt and generate nothing. */
9156 /* No other kinds of rtx should be possible here. */
9163 rtl_for_decl_location (decl
)
9168 /* Here we have to decide where we are going to say the parameter "lives"
9169 (as far as the debugger is concerned). We only have a couple of
9170 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9172 DECL_RTL normally indicates where the parameter lives during most of the
9173 activation of the function. If optimization is enabled however, this
9174 could be either NULL or else a pseudo-reg. Both of those cases indicate
9175 that the parameter doesn't really live anywhere (as far as the code
9176 generation parts of GCC are concerned) during most of the function's
9177 activation. That will happen (for example) if the parameter is never
9178 referenced within the function.
9180 We could just generate a location descriptor here for all non-NULL
9181 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9182 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9183 where DECL_RTL is NULL or is a pseudo-reg.
9185 Note however that we can only get away with using DECL_INCOMING_RTL as
9186 a backup substitute for DECL_RTL in certain limited cases. In cases
9187 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9188 we can be sure that the parameter was passed using the same type as it is
9189 declared to have within the function, and that its DECL_INCOMING_RTL
9190 points us to a place where a value of that type is passed.
9192 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9193 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9194 because in these cases DECL_INCOMING_RTL points us to a value of some
9195 type which is *different* from the type of the parameter itself. Thus,
9196 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9197 such cases, the debugger would end up (for example) trying to fetch a
9198 `float' from a place which actually contains the first part of a
9199 `double'. That would lead to really incorrect and confusing
9200 output at debug-time.
9202 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9203 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9204 are a couple of exceptions however. On little-endian machines we can
9205 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9206 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9207 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9208 when (on a little-endian machine) a non-prototyped function has a
9209 parameter declared to be of type `short' or `char'. In such cases,
9210 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9211 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9212 passed `int' value. If the debugger then uses that address to fetch
9213 a `short' or a `char' (on a little-endian machine) the result will be
9214 the correct data, so we allow for such exceptional cases below.
9216 Note that our goal here is to describe the place where the given formal
9217 parameter lives during most of the function's activation (i.e. between the
9218 end of the prologue and the start of the epilogue). We'll do that as best
9219 as we can. Note however that if the given formal parameter is modified
9220 sometime during the execution of the function, then a stack backtrace (at
9221 debug-time) will show the function as having been called with the *new*
9222 value rather than the value which was originally passed in. This happens
9223 rarely enough that it is not a major problem, but it *is* a problem, and
9226 A future version of dwarf2out.c may generate two additional attributes for
9227 any given DW_TAG_formal_parameter DIE which will describe the "passed
9228 type" and the "passed location" for the given formal parameter in addition
9229 to the attributes we now generate to indicate the "declared type" and the
9230 "active location" for each parameter. This additional set of attributes
9231 could be used by debuggers for stack backtraces. Separately, note that
9232 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9233 This happens (for example) for inlined-instances of inline function formal
9234 parameters which are never referenced. This really shouldn't be
9235 happening. All PARM_DECL nodes should get valid non-NULL
9236 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
9237 values for inlined instances of inline function parameters, so when we see
9238 such cases, we are just out-of-luck for the time being (until integrate.c
9241 /* Use DECL_RTL as the "location" unless we find something better. */
9242 rtl
= DECL_RTL_IF_SET (decl
);
9244 /* When generating abstract instances, ignore everything except
9245 constants and symbols living in memory. */
9246 if (! reload_completed
)
9249 && (CONSTANT_P (rtl
)
9250 || (GET_CODE (rtl
) == MEM
9251 && CONSTANT_P (XEXP (rtl
, 0)))))
9253 #ifdef ASM_SIMPLIFY_DWARF_ADDR
9254 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
9260 else if (TREE_CODE (decl
) == PARM_DECL
)
9262 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
9264 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
9265 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
9267 /* This decl represents a formal parameter which was optimized out.
9268 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9269 all cases where (rtl == NULL_RTX) just below. */
9270 if (declared_type
== passed_type
)
9271 rtl
= DECL_INCOMING_RTL (decl
);
9272 else if (! BYTES_BIG_ENDIAN
9273 && TREE_CODE (declared_type
) == INTEGER_TYPE
9274 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
9275 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
9276 rtl
= DECL_INCOMING_RTL (decl
);
9279 /* If the parm was passed in registers, but lives on the stack, then
9280 make a big endian correction if the mode of the type of the
9281 parameter is not the same as the mode of the rtl. */
9282 /* ??? This is the same series of checks that are made in dbxout.c before
9283 we reach the big endian correction code there. It isn't clear if all
9284 of these checks are necessary here, but keeping them all is the safe
9286 else if (GET_CODE (rtl
) == MEM
9287 && XEXP (rtl
, 0) != const0_rtx
9288 && ! CONSTANT_P (XEXP (rtl
, 0))
9289 /* Not passed in memory. */
9290 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
9291 /* Not passed by invisible reference. */
9292 && (GET_CODE (XEXP (rtl
, 0)) != REG
9293 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
9294 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
9295 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9296 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
9299 /* Big endian correction check. */
9301 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
9302 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
9305 int offset
= (UNITS_PER_WORD
9306 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
9308 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9309 plus_constant (XEXP (rtl
, 0), offset
));
9313 if (rtl
!= NULL_RTX
)
9315 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
9316 #ifdef LEAF_REG_REMAP
9317 if (current_function_uses_only_leaf_regs
)
9318 leaf_renumber_regs_insn (rtl
);
9322 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9323 and will have been substituted directly into all expressions that use it.
9324 C does not have such a concept, but C++ and other languages do. */
9325 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
9327 /* If a variable is initialized with a string constant without embedded
9328 zeros, build CONST_STRING. */
9329 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
9330 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9332 tree arrtype
= TREE_TYPE (decl
);
9333 tree enttype
= TREE_TYPE (arrtype
);
9334 tree domain
= TYPE_DOMAIN (arrtype
);
9335 tree init
= DECL_INITIAL (decl
);
9336 enum machine_mode mode
= TYPE_MODE (enttype
);
9338 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9340 && integer_zerop (TYPE_MIN_VALUE (domain
))
9341 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9342 TREE_STRING_LENGTH (init
) - 1) == 0
9343 && ((size_t) TREE_STRING_LENGTH (init
)
9344 == strlen (TREE_STRING_POINTER (init
)) + 1))
9345 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
9347 /* If the initializer is something that we know will expand into an
9348 immediate RTL constant, expand it now. Expanding anything else
9349 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9350 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
9351 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
9353 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
9354 EXPAND_INITIALIZER
);
9355 /* If expand_expr returns a MEM, it wasn't immediate. */
9356 if (rtl
&& GET_CODE (rtl
) == MEM
)
9361 #ifdef ASM_SIMPLIFY_DWARF_ADDR
9363 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
9366 /* If we don't look past the constant pool, we risk emitting a
9367 reference to a constant pool entry that isn't referenced from
9368 code, and thus is not emitted. */
9370 rtl
= avoid_constant_pool_reference (rtl
);
9375 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
9376 data attribute for a variable or a parameter. We generate the
9377 DW_AT_const_value attribute only in those cases where the given variable
9378 or parameter does not have a true "location" either in memory or in a
9379 register. This can happen (for example) when a constant is passed as an
9380 actual argument in a call to an inline function. (It's possible that
9381 these things can crop up in other ways also.) Note that one type of
9382 constant value which can be passed into an inlined function is a constant
9383 pointer. This can happen for example if an actual argument in an inlined
9384 function call evaluates to a compile-time constant address. */
9387 add_location_or_const_value_attribute (die
, decl
)
9392 dw_loc_descr_ref descr
;
9394 if (TREE_CODE (decl
) == ERROR_MARK
)
9396 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
)
9399 rtl
= rtl_for_decl_location (decl
);
9400 if (rtl
== NULL_RTX
)
9403 switch (GET_CODE (rtl
))
9406 /* The address of a variable that was optimized away;
9407 don't emit anything. */
9417 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9418 add_const_value_attribute (die
, rtl
);
9422 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
9424 /* Need loc_descriptor_from_tree since that's where we know
9425 how to handle TLS variables. Want the object's address
9426 since the top-level DW_AT_location assumes such. See
9427 the confusion in loc_descriptor for reference. */
9428 descr
= loc_descriptor_from_tree (decl
, 1);
9435 descr
= loc_descriptor (rtl
);
9437 add_AT_location_description (die
, DW_AT_location
, descr
);
9445 /* If we don't have a copy of this variable in memory for some reason (such
9446 as a C++ member constant that doesn't have an out-of-line definition),
9447 we should tell the debugger about the constant value. */
9450 tree_add_const_value_attribute (var_die
, decl
)
9454 tree init
= DECL_INITIAL (decl
);
9455 tree type
= TREE_TYPE (decl
);
9457 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
9458 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
9463 switch (TREE_CODE (type
))
9466 if (host_integerp (init
, 0))
9467 add_AT_unsigned (var_die
, DW_AT_const_value
,
9468 tree_low_cst (init
, 0));
9470 add_AT_long_long (var_die
, DW_AT_const_value
,
9471 TREE_INT_CST_HIGH (init
),
9472 TREE_INT_CST_LOW (init
));
9479 /* Generate an DW_AT_name attribute given some string value to be included as
9480 the value of the attribute. */
9483 add_name_attribute (die
, name_string
)
9485 const char *name_string
;
9487 if (name_string
!= NULL
&& *name_string
!= 0)
9489 if (demangle_name_func
)
9490 name_string
= (*demangle_name_func
) (name_string
);
9492 add_AT_string (die
, DW_AT_name
, name_string
);
9496 /* Given a tree node describing an array bound (either lower or upper) output
9497 a representation for that bound. */
9500 add_bound_info (subrange_die
, bound_attr
, bound
)
9501 dw_die_ref subrange_die
;
9502 enum dwarf_attribute bound_attr
;
9505 switch (TREE_CODE (bound
))
9510 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9512 if (! host_integerp (bound
, 0)
9513 || (bound_attr
== DW_AT_lower_bound
9514 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
9515 || (is_fortran () && integer_onep (bound
)))))
9516 /* use the default */
9519 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
9524 case NON_LVALUE_EXPR
:
9525 case VIEW_CONVERT_EXPR
:
9526 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
9530 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9531 access the upper bound values may be bogus. If they refer to a
9532 register, they may only describe how to get at these values at the
9533 points in the generated code right after they have just been
9534 computed. Worse yet, in the typical case, the upper bound values
9535 will not even *be* computed in the optimized code (though the
9536 number of elements will), so these SAVE_EXPRs are entirely
9537 bogus. In order to compensate for this fact, we check here to see
9538 if optimization is enabled, and if so, we don't add an attribute
9539 for the (unknown and unknowable) upper bound. This should not
9540 cause too much trouble for existing (stupid?) debuggers because
9541 they have to deal with empty upper bounds location descriptions
9542 anyway in order to be able to deal with incomplete array types.
9543 Of course an intelligent debugger (GDB?) should be able to
9544 comprehend that a missing upper bound specification in an array
9545 type used for a storage class `auto' local array variable
9546 indicates that the upper bound is both unknown (at compile- time)
9547 and unknowable (at run-time) due to optimization.
9549 We assume that a MEM rtx is safe because gcc wouldn't put the
9550 value there unless it was going to be used repeatedly in the
9551 function, i.e. for cleanups. */
9552 if (SAVE_EXPR_RTL (bound
)
9553 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
9555 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
9556 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9557 rtx loc
= SAVE_EXPR_RTL (bound
);
9559 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9560 it references an outer function's frame. */
9561 if (GET_CODE (loc
) == MEM
)
9563 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
9565 if (XEXP (loc
, 0) != new_addr
)
9566 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
9569 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9570 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9571 add_AT_location_description (decl_die
, DW_AT_location
,
9572 loc_descriptor (loc
));
9573 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9576 /* Else leave out the attribute. */
9582 dw_die_ref decl_die
= lookup_decl_die (bound
);
9584 /* ??? Can this happen, or should the variable have been bound
9585 first? Probably it can, since I imagine that we try to create
9586 the types of parameters in the order in which they exist in
9587 the list, and won't have created a forward reference to a
9589 if (decl_die
!= NULL
)
9590 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9596 /* Otherwise try to create a stack operation procedure to
9597 evaluate the value of the array bound. */
9599 dw_die_ref ctx
, decl_die
;
9600 dw_loc_descr_ref loc
;
9602 loc
= loc_descriptor_from_tree (bound
, 0);
9606 if (current_function_decl
== 0)
9607 ctx
= comp_unit_die
;
9609 ctx
= lookup_decl_die (current_function_decl
);
9611 /* If we weren't able to find a context, it's most likely the case
9612 that we are processing the return type of the function. So
9613 make a SAVE_EXPR to point to it and have the limbo DIE code
9614 find the proper die. The save_expr function doesn't always
9615 make a SAVE_EXPR, so do it ourselves. */
9617 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
9618 current_function_decl
, NULL_TREE
);
9620 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
9621 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
9622 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
9623 add_AT_loc (decl_die
, DW_AT_location
, loc
);
9625 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
9631 /* Note that the block of subscript information for an array type also
9632 includes information about the element type of type given array type. */
9635 add_subscript_info (type_die
, type
)
9636 dw_die_ref type_die
;
9639 #ifndef MIPS_DEBUGGING_INFO
9640 unsigned dimension_number
;
9643 dw_die_ref subrange_die
;
9645 /* The GNU compilers represent multidimensional array types as sequences of
9646 one dimensional array types whose element types are themselves array
9647 types. Here we squish that down, so that each multidimensional array
9648 type gets only one array_type DIE in the Dwarf debugging info. The draft
9649 Dwarf specification say that we are allowed to do this kind of
9650 compression in C (because there is no difference between an array or
9651 arrays and a multidimensional array in C) but for other source languages
9652 (e.g. Ada) we probably shouldn't do this. */
9654 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9655 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9656 We work around this by disabling this feature. See also
9657 gen_array_type_die. */
9658 #ifndef MIPS_DEBUGGING_INFO
9659 for (dimension_number
= 0;
9660 TREE_CODE (type
) == ARRAY_TYPE
;
9661 type
= TREE_TYPE (type
), dimension_number
++)
9664 tree domain
= TYPE_DOMAIN (type
);
9666 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9667 and (in GNU C only) variable bounds. Handle all three forms
9669 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
9672 /* We have an array type with specified bounds. */
9673 lower
= TYPE_MIN_VALUE (domain
);
9674 upper
= TYPE_MAX_VALUE (domain
);
9676 /* define the index type. */
9677 if (TREE_TYPE (domain
))
9679 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9680 TREE_TYPE field. We can't emit debug info for this
9681 because it is an unnamed integral type. */
9682 if (TREE_CODE (domain
) == INTEGER_TYPE
9683 && TYPE_NAME (domain
) == NULL_TREE
9684 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
9685 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
9688 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
9692 /* ??? If upper is NULL, the array has unspecified length,
9693 but it does have a lower bound. This happens with Fortran
9695 Since the debugger is definitely going to need to know N
9696 to produce useful results, go ahead and output the lower
9697 bound solo, and hope the debugger can cope. */
9699 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
9701 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
9704 /* Otherwise we have an array type with an unspecified length. The
9705 DWARF-2 spec does not say how to handle this; let's just leave out the
9711 add_byte_size_attribute (die
, tree_node
)
9717 switch (TREE_CODE (tree_node
))
9725 case QUAL_UNION_TYPE
:
9726 size
= int_size_in_bytes (tree_node
);
9729 /* For a data member of a struct or union, the DW_AT_byte_size is
9730 generally given as the number of bytes normally allocated for an
9731 object of the *declared* type of the member itself. This is true
9732 even for bit-fields. */
9733 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
9739 /* Note that `size' might be -1 when we get to this point. If it is, that
9740 indicates that the byte size of the entity in question is variable. We
9741 have no good way of expressing this fact in Dwarf at the present time,
9742 so just let the -1 pass on through. */
9743 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
9746 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9747 which specifies the distance in bits from the highest order bit of the
9748 "containing object" for the bit-field to the highest order bit of the
9751 For any given bit-field, the "containing object" is a hypothetical object
9752 (of some integral or enum type) within which the given bit-field lives. The
9753 type of this hypothetical "containing object" is always the same as the
9754 declared type of the individual bit-field itself. The determination of the
9755 exact location of the "containing object" for a bit-field is rather
9756 complicated. It's handled by the `field_byte_offset' function (above).
9758 Note that it is the size (in bytes) of the hypothetical "containing object"
9759 which will be given in the DW_AT_byte_size attribute for this bit-field.
9760 (See `byte_size_attribute' above). */
9763 add_bit_offset_attribute (die
, decl
)
9767 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
9768 tree type
= DECL_BIT_FIELD_TYPE (decl
);
9769 HOST_WIDE_INT bitpos_int
;
9770 HOST_WIDE_INT highest_order_object_bit_offset
;
9771 HOST_WIDE_INT highest_order_field_bit_offset
;
9772 HOST_WIDE_INT
unsigned bit_offset
;
9774 /* Must be a field and a bit field. */
9776 || TREE_CODE (decl
) != FIELD_DECL
)
9779 /* We can't yet handle bit-fields whose offsets are variable, so if we
9780 encounter such things, just return without generating any attribute
9781 whatsoever. Likewise for variable or too large size. */
9782 if (! host_integerp (bit_position (decl
), 0)
9783 || ! host_integerp (DECL_SIZE (decl
), 1))
9786 bitpos_int
= int_bit_position (decl
);
9788 /* Note that the bit offset is always the distance (in bits) from the
9789 highest-order bit of the "containing object" to the highest-order bit of
9790 the bit-field itself. Since the "high-order end" of any object or field
9791 is different on big-endian and little-endian machines, the computation
9792 below must take account of these differences. */
9793 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
9794 highest_order_field_bit_offset
= bitpos_int
;
9796 if (! BYTES_BIG_ENDIAN
)
9798 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
9799 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
9803 = (! BYTES_BIG_ENDIAN
9804 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
9805 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
9807 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
9810 /* For a FIELD_DECL node which represents a bit field, output an attribute
9811 which specifies the length in bits of the given field. */
9814 add_bit_size_attribute (die
, decl
)
9818 /* Must be a field and a bit field. */
9819 if (TREE_CODE (decl
) != FIELD_DECL
9820 || ! DECL_BIT_FIELD_TYPE (decl
))
9823 if (host_integerp (DECL_SIZE (decl
), 1))
9824 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
9827 /* If the compiled language is ANSI C, then add a 'prototyped'
9828 attribute, if arg types are given for the parameters of a function. */
9831 add_prototyped_attribute (die
, func_type
)
9835 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
9836 && TYPE_ARG_TYPES (func_type
) != NULL
)
9837 add_AT_flag (die
, DW_AT_prototyped
, 1);
9840 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9841 by looking in either the type declaration or object declaration
9845 add_abstract_origin_attribute (die
, origin
)
9849 dw_die_ref origin_die
= NULL
;
9851 if (TREE_CODE (origin
) != FUNCTION_DECL
)
9853 /* We may have gotten separated from the block for the inlined
9854 function, if we're in an exception handler or some such; make
9855 sure that the abstract function has been written out.
9857 Doing this for nested functions is wrong, however; functions are
9858 distinct units, and our context might not even be inline. */
9862 fn
= TYPE_STUB_DECL (fn
);
9864 fn
= decl_function_context (fn
);
9866 dwarf2out_abstract_function (fn
);
9869 if (DECL_P (origin
))
9870 origin_die
= lookup_decl_die (origin
);
9871 else if (TYPE_P (origin
))
9872 origin_die
= lookup_type_die (origin
);
9874 if (origin_die
== NULL
)
9877 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
9880 /* We do not currently support the pure_virtual attribute. */
9883 add_pure_or_virtual_attribute (die
, func_decl
)
9887 if (DECL_VINDEX (func_decl
))
9889 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
9891 if (host_integerp (DECL_VINDEX (func_decl
), 0))
9892 add_AT_loc (die
, DW_AT_vtable_elem_location
,
9893 new_loc_descr (DW_OP_constu
,
9894 tree_low_cst (DECL_VINDEX (func_decl
), 0),
9897 /* GNU extension: Record what type this method came from originally. */
9898 if (debug_info_level
> DINFO_LEVEL_TERSE
)
9899 add_AT_die_ref (die
, DW_AT_containing_type
,
9900 lookup_type_die (DECL_CONTEXT (func_decl
)));
9904 /* Add source coordinate attributes for the given decl. */
9907 add_src_coords_attributes (die
, decl
)
9911 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
9913 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
9914 add_AT_unsigned (die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
9917 /* Add an DW_AT_name attribute and source coordinate attribute for the
9918 given decl, but only if it actually has a name. */
9921 add_name_and_src_coords_attributes (die
, decl
)
9927 decl_name
= DECL_NAME (decl
);
9928 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
9930 add_name_attribute (die
, dwarf2_name (decl
, 0));
9931 if (! DECL_ARTIFICIAL (decl
))
9932 add_src_coords_attributes (die
, decl
);
9934 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
9935 && TREE_PUBLIC (decl
)
9936 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
9937 && !DECL_ABSTRACT (decl
))
9938 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
9939 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
9942 #ifdef VMS_DEBUGGING_INFO
9943 /* Get the function's name, as described by its RTL. This may be different
9944 from the DECL_NAME name used in the source file. */
9945 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
9947 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
9948 XEXP (DECL_RTL (decl
), 0));
9949 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
9954 /* Push a new declaration scope. */
9957 push_decl_scope (scope
)
9960 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
9963 /* Pop a declaration scope. */
9968 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
9971 VARRAY_POP (decl_scope_table
);
9974 /* Return the DIE for the scope that immediately contains this type.
9975 Non-named types get global scope. Named types nested in other
9976 types get their containing scope if it's open, or global scope
9977 otherwise. All other types (i.e. function-local named types) get
9978 the current active scope. */
9981 scope_die_for (t
, context_die
)
9983 dw_die_ref context_die
;
9985 dw_die_ref scope_die
= NULL
;
9986 tree containing_scope
;
9989 /* Non-types always go in the current scope. */
9993 containing_scope
= TYPE_CONTEXT (t
);
9995 /* Ignore namespaces for the moment. */
9996 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
9997 containing_scope
= NULL_TREE
;
9999 /* Ignore function type "scopes" from the C frontend. They mean that
10000 a tagged type is local to a parmlist of a function declarator, but
10001 that isn't useful to DWARF. */
10002 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
10003 containing_scope
= NULL_TREE
;
10005 if (containing_scope
== NULL_TREE
)
10006 scope_die
= comp_unit_die
;
10007 else if (TYPE_P (containing_scope
))
10009 /* For types, we can just look up the appropriate DIE. But
10010 first we check to see if we're in the middle of emitting it
10011 so we know where the new DIE should go. */
10012 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
10013 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
10018 if (debug_info_level
> DINFO_LEVEL_TERSE
10019 && !TREE_ASM_WRITTEN (containing_scope
))
10022 /* If none of the current dies are suitable, we get file scope. */
10023 scope_die
= comp_unit_die
;
10026 scope_die
= lookup_type_die (containing_scope
);
10029 scope_die
= context_die
;
10034 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10037 local_scope_p (context_die
)
10038 dw_die_ref context_die
;
10040 for (; context_die
; context_die
= context_die
->die_parent
)
10041 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10042 || context_die
->die_tag
== DW_TAG_subprogram
)
10048 /* Returns nonzero if CONTEXT_DIE is a class. */
10051 class_scope_p (context_die
)
10052 dw_die_ref context_die
;
10054 return (context_die
10055 && (context_die
->die_tag
== DW_TAG_structure_type
10056 || context_die
->die_tag
== DW_TAG_union_type
));
10059 /* Many forms of DIEs require a "type description" attribute. This
10060 routine locates the proper "type descriptor" die for the type given
10061 by 'type', and adds an DW_AT_type attribute below the given die. */
10064 add_type_attribute (object_die
, type
, decl_const
, decl_volatile
, context_die
)
10065 dw_die_ref object_die
;
10069 dw_die_ref context_die
;
10071 enum tree_code code
= TREE_CODE (type
);
10072 dw_die_ref type_die
= NULL
;
10074 /* ??? If this type is an unnamed subrange type of an integral or
10075 floating-point type, use the inner type. This is because we have no
10076 support for unnamed types in base_type_die. This can happen if this is
10077 an Ada subrange type. Correct solution is emit a subrange type die. */
10078 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10079 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10080 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
10082 if (code
== ERROR_MARK
10083 /* Handle a special case. For functions whose return type is void, we
10084 generate *no* type attribute. (Note that no object may have type
10085 `void', so this only applies to function return types). */
10086 || code
== VOID_TYPE
)
10089 type_die
= modified_type_die (type
,
10090 decl_const
|| TYPE_READONLY (type
),
10091 decl_volatile
|| TYPE_VOLATILE (type
),
10094 if (type_die
!= NULL
)
10095 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
10098 /* Given a tree pointer to a struct, class, union, or enum type node, return
10099 a pointer to the (string) tag name for the given type, or zero if the type
10100 was declared without a tag. */
10102 static const char *
10106 const char *name
= 0;
10108 if (TYPE_NAME (type
) != 0)
10112 /* Find the IDENTIFIER_NODE for the type name. */
10113 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
10114 t
= TYPE_NAME (type
);
10116 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10117 a TYPE_DECL node, regardless of whether or not a `typedef' was
10119 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10120 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
10121 t
= DECL_NAME (TYPE_NAME (type
));
10123 /* Now get the name as a string, or invent one. */
10125 name
= IDENTIFIER_POINTER (t
);
10128 return (name
== 0 || *name
== '\0') ? 0 : name
;
10131 /* Return the type associated with a data member, make a special check
10132 for bit field types. */
10135 member_declared_type (member
)
10138 return (DECL_BIT_FIELD_TYPE (member
)
10139 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
10142 /* Get the decl's label, as described by its RTL. This may be different
10143 from the DECL_NAME name used in the source file. */
10146 static const char *
10147 decl_start_label (decl
)
10151 const char *fnname
;
10153 x
= DECL_RTL (decl
);
10154 if (GET_CODE (x
) != MEM
)
10158 if (GET_CODE (x
) != SYMBOL_REF
)
10161 fnname
= XSTR (x
, 0);
10166 /* These routines generate the internal representation of the DIE's for
10167 the compilation unit. Debugging information is collected by walking
10168 the declaration trees passed in from dwarf2out_decl(). */
10171 gen_array_type_die (type
, context_die
)
10173 dw_die_ref context_die
;
10175 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
10176 dw_die_ref array_die
;
10179 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10180 the inner array type comes before the outer array type. Thus we must
10181 call gen_type_die before we call new_die. See below also. */
10182 #ifdef MIPS_DEBUGGING_INFO
10183 gen_type_die (TREE_TYPE (type
), context_die
);
10186 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
10187 add_name_attribute (array_die
, type_tag (type
));
10188 equate_type_number_to_die (type
, array_die
);
10190 if (TREE_CODE (type
) == VECTOR_TYPE
)
10192 /* The frontend feeds us a representation for the vector as a struct
10193 containing an array. Pull out the array type. */
10194 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
10195 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
10199 /* We default the array ordering. SDB will probably do
10200 the right things even if DW_AT_ordering is not present. It's not even
10201 an issue until we start to get into multidimensional arrays anyway. If
10202 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10203 then we'll have to put the DW_AT_ordering attribute back in. (But if
10204 and when we find out that we need to put these in, we will only do so
10205 for multidimensional arrays. */
10206 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
10209 #ifdef MIPS_DEBUGGING_INFO
10210 /* The SGI compilers handle arrays of unknown bound by setting
10211 AT_declaration and not emitting any subrange DIEs. */
10212 if (! TYPE_DOMAIN (type
))
10213 add_AT_unsigned (array_die
, DW_AT_declaration
, 1);
10216 add_subscript_info (array_die
, type
);
10218 /* Add representation of the type of the elements of this array type. */
10219 element_type
= TREE_TYPE (type
);
10221 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10222 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10223 We work around this by disabling this feature. See also
10224 add_subscript_info. */
10225 #ifndef MIPS_DEBUGGING_INFO
10226 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
10227 element_type
= TREE_TYPE (element_type
);
10229 gen_type_die (element_type
, context_die
);
10232 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
10236 gen_set_type_die (type
, context_die
)
10238 dw_die_ref context_die
;
10240 dw_die_ref type_die
10241 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
10243 equate_type_number_to_die (type
, type_die
);
10244 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
10249 gen_entry_point_die (decl
, context_die
)
10251 dw_die_ref context_die
;
10253 tree origin
= decl_ultimate_origin (decl
);
10254 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
10256 if (origin
!= NULL
)
10257 add_abstract_origin_attribute (decl_die
, origin
);
10260 add_name_and_src_coords_attributes (decl_die
, decl
);
10261 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
10262 0, 0, context_die
);
10265 if (DECL_ABSTRACT (decl
))
10266 equate_decl_number_to_die (decl
, decl_die
);
10268 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
10272 /* Walk through the list of incomplete types again, trying once more to
10273 emit full debugging info for them. */
10276 retry_incomplete_types ()
10280 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
10281 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
10284 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10287 gen_inlined_enumeration_type_die (type
, context_die
)
10289 dw_die_ref context_die
;
10291 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
10293 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10294 be incomplete and such types are not marked. */
10295 add_abstract_origin_attribute (type_die
, type
);
10298 /* Generate a DIE to represent an inlined instance of a structure type. */
10301 gen_inlined_structure_type_die (type
, context_die
)
10303 dw_die_ref context_die
;
10305 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
10307 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10308 be incomplete and such types are not marked. */
10309 add_abstract_origin_attribute (type_die
, type
);
10312 /* Generate a DIE to represent an inlined instance of a union type. */
10315 gen_inlined_union_type_die (type
, context_die
)
10317 dw_die_ref context_die
;
10319 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
10321 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10322 be incomplete and such types are not marked. */
10323 add_abstract_origin_attribute (type_die
, type
);
10326 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10327 include all of the information about the enumeration values also. Each
10328 enumerated type name/value is listed as a child of the enumerated type
10332 gen_enumeration_type_die (type
, context_die
)
10334 dw_die_ref context_die
;
10336 dw_die_ref type_die
= lookup_type_die (type
);
10338 if (type_die
== NULL
)
10340 type_die
= new_die (DW_TAG_enumeration_type
,
10341 scope_die_for (type
, context_die
), type
);
10342 equate_type_number_to_die (type
, type_die
);
10343 add_name_attribute (type_die
, type_tag (type
));
10345 else if (! TYPE_SIZE (type
))
10348 remove_AT (type_die
, DW_AT_declaration
);
10350 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10351 given enum type is incomplete, do not generate the DW_AT_byte_size
10352 attribute or the DW_AT_element_list attribute. */
10353 if (TYPE_SIZE (type
))
10357 TREE_ASM_WRITTEN (type
) = 1;
10358 add_byte_size_attribute (type_die
, type
);
10359 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10360 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10362 /* If the first reference to this type was as the return type of an
10363 inline function, then it may not have a parent. Fix this now. */
10364 if (type_die
->die_parent
== NULL
)
10365 add_child_die (scope_die_for (type
, context_die
), type_die
);
10367 for (link
= TYPE_FIELDS (type
);
10368 link
!= NULL
; link
= TREE_CHAIN (link
))
10370 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
10372 add_name_attribute (enum_die
,
10373 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
10375 if (host_integerp (TREE_VALUE (link
), 0))
10377 if (tree_int_cst_sgn (TREE_VALUE (link
)) < 0)
10378 add_AT_int (enum_die
, DW_AT_const_value
,
10379 tree_low_cst (TREE_VALUE (link
), 0));
10381 add_AT_unsigned (enum_die
, DW_AT_const_value
,
10382 tree_low_cst (TREE_VALUE (link
), 0));
10387 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10390 /* Generate a DIE to represent either a real live formal parameter decl or to
10391 represent just the type of some formal parameter position in some function
10394 Note that this routine is a bit unusual because its argument may be a
10395 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10396 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10397 node. If it's the former then this function is being called to output a
10398 DIE to represent a formal parameter object (or some inlining thereof). If
10399 it's the latter, then this function is only being called to output a
10400 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10401 argument type of some subprogram type. */
10404 gen_formal_parameter_die (node
, context_die
)
10406 dw_die_ref context_die
;
10408 dw_die_ref parm_die
10409 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
10412 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
10415 origin
= decl_ultimate_origin (node
);
10416 if (origin
!= NULL
)
10417 add_abstract_origin_attribute (parm_die
, origin
);
10420 add_name_and_src_coords_attributes (parm_die
, node
);
10421 add_type_attribute (parm_die
, TREE_TYPE (node
),
10422 TREE_READONLY (node
),
10423 TREE_THIS_VOLATILE (node
),
10425 if (DECL_ARTIFICIAL (node
))
10426 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10429 equate_decl_number_to_die (node
, parm_die
);
10430 if (! DECL_ABSTRACT (node
))
10431 add_location_or_const_value_attribute (parm_die
, node
);
10436 /* We were called with some kind of a ..._TYPE node. */
10437 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
10447 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10448 at the end of an (ANSI prototyped) formal parameters list. */
10451 gen_unspecified_parameters_die (decl_or_type
, context_die
)
10453 dw_die_ref context_die
;
10455 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
10458 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10459 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10460 parameters as specified in some function type specification (except for
10461 those which appear as part of a function *definition*). */
10464 gen_formal_types_die (function_or_method_type
, context_die
)
10465 tree function_or_method_type
;
10466 dw_die_ref context_die
;
10469 tree formal_type
= NULL
;
10470 tree first_parm_type
;
10473 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
10475 arg
= DECL_ARGUMENTS (function_or_method_type
);
10476 function_or_method_type
= TREE_TYPE (function_or_method_type
);
10481 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
10483 /* Make our first pass over the list of formal parameter types and output a
10484 DW_TAG_formal_parameter DIE for each one. */
10485 for (link
= first_parm_type
; link
; )
10487 dw_die_ref parm_die
;
10489 formal_type
= TREE_VALUE (link
);
10490 if (formal_type
== void_type_node
)
10493 /* Output a (nameless) DIE to represent the formal parameter itself. */
10494 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
10495 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
10496 && link
== first_parm_type
)
10497 || (arg
&& DECL_ARTIFICIAL (arg
)))
10498 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
10500 link
= TREE_CHAIN (link
);
10502 arg
= TREE_CHAIN (arg
);
10505 /* If this function type has an ellipsis, add a
10506 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10507 if (formal_type
!= void_type_node
)
10508 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
10510 /* Make our second (and final) pass over the list of formal parameter types
10511 and output DIEs to represent those types (as necessary). */
10512 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
10513 link
&& TREE_VALUE (link
);
10514 link
= TREE_CHAIN (link
))
10515 gen_type_die (TREE_VALUE (link
), context_die
);
10518 /* We want to generate the DIE for TYPE so that we can generate the
10519 die for MEMBER, which has been defined; we will need to refer back
10520 to the member declaration nested within TYPE. If we're trying to
10521 generate minimal debug info for TYPE, processing TYPE won't do the
10522 trick; we need to attach the member declaration by hand. */
10525 gen_type_die_for_member (type
, member
, context_die
)
10527 dw_die_ref context_die
;
10529 gen_type_die (type
, context_die
);
10531 /* If we're trying to avoid duplicate debug info, we may not have
10532 emitted the member decl for this function. Emit it now. */
10533 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
10534 && ! lookup_decl_die (member
))
10536 if (decl_ultimate_origin (member
))
10539 push_decl_scope (type
);
10540 if (TREE_CODE (member
) == FUNCTION_DECL
)
10541 gen_subprogram_die (member
, lookup_type_die (type
));
10543 gen_variable_die (member
, lookup_type_die (type
));
10549 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10550 may later generate inlined and/or out-of-line instances of. */
10553 dwarf2out_abstract_function (decl
)
10556 dw_die_ref old_die
;
10559 int was_abstract
= DECL_ABSTRACT (decl
);
10561 /* Make sure we have the actual abstract inline, not a clone. */
10562 decl
= DECL_ORIGIN (decl
);
10564 old_die
= lookup_decl_die (decl
);
10565 if (old_die
&& get_AT_unsigned (old_die
, DW_AT_inline
))
10566 /* We've already generated the abstract instance. */
10569 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10570 we don't get confused by DECL_ABSTRACT. */
10571 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10573 context
= decl_class_context (decl
);
10575 gen_type_die_for_member
10576 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
10579 /* Pretend we've just finished compiling this function. */
10580 save_fn
= current_function_decl
;
10581 current_function_decl
= decl
;
10583 set_decl_abstract_flags (decl
, 1);
10584 dwarf2out_decl (decl
);
10585 if (! was_abstract
)
10586 set_decl_abstract_flags (decl
, 0);
10588 current_function_decl
= save_fn
;
10591 /* Generate a DIE to represent a declared function (either file-scope or
10595 gen_subprogram_die (decl
, context_die
)
10597 dw_die_ref context_die
;
10599 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10600 tree origin
= decl_ultimate_origin (decl
);
10601 dw_die_ref subr_die
;
10605 dw_die_ref old_die
= lookup_decl_die (decl
);
10606 int declaration
= (current_function_decl
!= decl
10607 || class_scope_p (context_die
));
10609 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10610 started to generate the abstract instance of an inline, decided to output
10611 its containing class, and proceeded to emit the declaration of the inline
10612 from the member list for the class. If so, DECLARATION takes priority;
10613 we'll get back to the abstract instance when done with the class. */
10615 /* The class-scope declaration DIE must be the primary DIE. */
10616 if (origin
&& declaration
&& class_scope_p (context_die
))
10623 if (origin
!= NULL
)
10625 if (declaration
&& ! local_scope_p (context_die
))
10628 /* Fixup die_parent for the abstract instance of a nested
10629 inline function. */
10630 if (old_die
&& old_die
->die_parent
== NULL
)
10631 add_child_die (context_die
, old_die
);
10633 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10634 add_abstract_origin_attribute (subr_die
, origin
);
10638 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10640 if (!get_AT_flag (old_die
, DW_AT_declaration
)
10641 /* We can have a normal definition following an inline one in the
10642 case of redefinition of GNU C extern inlines.
10643 It seems reasonable to use AT_specification in this case. */
10644 && !get_AT_unsigned (old_die
, DW_AT_inline
))
10646 /* ??? This can happen if there is a bug in the program, for
10647 instance, if it has duplicate function definitions. Ideally,
10648 we should detect this case and ignore it. For now, if we have
10649 already reported an error, any error at all, then assume that
10650 we got here because of an input error, not a dwarf2 bug. */
10656 /* If the definition comes from the same place as the declaration,
10657 maybe use the old DIE. We always want the DIE for this function
10658 that has the *_pc attributes to be under comp_unit_die so the
10659 debugger can find it. We also need to do this for abstract
10660 instances of inlines, since the spec requires the out-of-line copy
10661 to have the same parent. For local class methods, this doesn't
10662 apply; we just use the old DIE. */
10663 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
10664 && (DECL_ARTIFICIAL (decl
)
10665 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
10666 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10667 == (unsigned) DECL_SOURCE_LINE (decl
)))))
10669 subr_die
= old_die
;
10671 /* Clear out the declaration attribute and the parm types. */
10672 remove_AT (subr_die
, DW_AT_declaration
);
10673 remove_children (subr_die
);
10677 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10678 add_AT_die_ref (subr_die
, DW_AT_specification
, old_die
);
10679 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10680 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
10681 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10682 != (unsigned) DECL_SOURCE_LINE (decl
))
10684 (subr_die
, DW_AT_decl_line
, DECL_SOURCE_LINE (decl
));
10689 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
10691 if (TREE_PUBLIC (decl
))
10692 add_AT_flag (subr_die
, DW_AT_external
, 1);
10694 add_name_and_src_coords_attributes (subr_die
, decl
);
10695 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10697 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
10698 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
10699 0, 0, context_die
);
10702 add_pure_or_virtual_attribute (subr_die
, decl
);
10703 if (DECL_ARTIFICIAL (decl
))
10704 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
10706 if (TREE_PROTECTED (decl
))
10707 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10708 else if (TREE_PRIVATE (decl
))
10709 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10714 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10716 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
10718 /* The first time we see a member function, it is in the context of
10719 the class to which it belongs. We make sure of this by emitting
10720 the class first. The next time is the definition, which is
10721 handled above. The two may come from the same source text. */
10722 if (DECL_CONTEXT (decl
) || DECL_ABSTRACT (decl
))
10723 equate_decl_number_to_die (decl
, subr_die
);
10726 else if (DECL_ABSTRACT (decl
))
10728 if (DECL_INLINE (decl
) && !flag_no_inline
)
10730 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10731 inline functions, but not for extern inline functions.
10732 We can't get this completely correct because information
10733 about whether the function was declared inline is not
10735 if (DECL_DEFER_OUTPUT (decl
))
10736 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
10738 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
10741 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
10743 equate_decl_number_to_die (decl
, subr_die
);
10745 else if (!DECL_EXTERNAL (decl
))
10747 if (!old_die
|| !get_AT_unsigned (old_die
, DW_AT_inline
))
10748 equate_decl_number_to_die (decl
, subr_die
);
10750 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
10751 current_function_funcdef_no
);
10752 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
10753 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10754 current_function_funcdef_no
);
10755 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
10757 add_pubname (decl
, subr_die
);
10758 add_arange (decl
, subr_die
);
10760 #ifdef MIPS_DEBUGGING_INFO
10761 /* Add a reference to the FDE for this routine. */
10762 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
10765 /* Define the "frame base" location for this routine. We use the
10766 frame pointer or stack pointer registers, since the RTL for local
10767 variables is relative to one of them. */
10769 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
10770 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
10773 /* ??? This fails for nested inline functions, because context_display
10774 is not part of the state saved/restored for inline functions. */
10775 if (current_function_needs_context
)
10776 add_AT_location_description (subr_die
, DW_AT_static_link
,
10777 loc_descriptor (lookup_static_chain (decl
)));
10781 /* Now output descriptions of the arguments for this function. This gets
10782 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10783 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10784 `...' at the end of the formal parameter list. In order to find out if
10785 there was a trailing ellipsis or not, we must instead look at the type
10786 associated with the FUNCTION_DECL. This will be a node of type
10787 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10788 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10789 an ellipsis at the end. */
10791 /* In the case where we are describing a mere function declaration, all we
10792 need to do here (and all we *can* do here) is to describe the *types* of
10793 its formal parameters. */
10794 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
10796 else if (declaration
)
10797 gen_formal_types_die (decl
, subr_die
);
10800 /* Generate DIEs to represent all known formal parameters */
10801 tree arg_decls
= DECL_ARGUMENTS (decl
);
10804 /* When generating DIEs, generate the unspecified_parameters DIE
10805 instead if we come across the arg "__builtin_va_alist" */
10806 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
10807 if (TREE_CODE (parm
) == PARM_DECL
)
10809 if (DECL_NAME (parm
)
10810 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
10811 "__builtin_va_alist"))
10812 gen_unspecified_parameters_die (parm
, subr_die
);
10814 gen_decl_die (parm
, subr_die
);
10817 /* Decide whether we need an unspecified_parameters DIE at the end.
10818 There are 2 more cases to do this for: 1) the ansi ... declaration -
10819 this is detectable when the end of the arg list is not a
10820 void_type_node 2) an unprototyped function declaration (not a
10821 definition). This just means that we have no info about the
10822 parameters at all. */
10823 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
10824 if (fn_arg_types
!= NULL
)
10826 /* this is the prototyped case, check for ... */
10827 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
10828 gen_unspecified_parameters_die (decl
, subr_die
);
10830 else if (DECL_INITIAL (decl
) == NULL_TREE
)
10831 gen_unspecified_parameters_die (decl
, subr_die
);
10834 /* Output Dwarf info for all of the stuff within the body of the function
10835 (if it has one - it may be just a declaration). */
10836 outer_scope
= DECL_INITIAL (decl
);
10838 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10839 a function. This BLOCK actually represents the outermost binding contour
10840 for the function, i.e. the contour in which the function's formal
10841 parameters and labels get declared. Curiously, it appears that the front
10842 end doesn't actually put the PARM_DECL nodes for the current function onto
10843 the BLOCK_VARS list for this outer scope, but are strung off of the
10844 DECL_ARGUMENTS list for the function instead.
10846 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10847 the LABEL_DECL nodes for the function however, and we output DWARF info
10848 for those in decls_for_scope. Just within the `outer_scope' there will be
10849 a BLOCK node representing the function's outermost pair of curly braces,
10850 and any blocks used for the base and member initializers of a C++
10851 constructor function. */
10852 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
10854 current_function_has_inlines
= 0;
10855 decls_for_scope (outer_scope
, subr_die
, 0);
10857 #if 0 && defined (MIPS_DEBUGGING_INFO)
10858 if (current_function_has_inlines
)
10860 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
10861 if (! comp_unit_has_inlines
)
10863 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
10864 comp_unit_has_inlines
= 1;
10871 /* Generate a DIE to represent a declared data object. */
10874 gen_variable_die (decl
, context_die
)
10876 dw_die_ref context_die
;
10878 tree origin
= decl_ultimate_origin (decl
);
10879 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
10881 dw_die_ref old_die
= lookup_decl_die (decl
);
10882 int declaration
= (DECL_EXTERNAL (decl
)
10883 || class_scope_p (context_die
));
10885 if (origin
!= NULL
)
10886 add_abstract_origin_attribute (var_die
, origin
);
10888 /* Loop unrolling can create multiple blocks that refer to the same
10889 static variable, so we must test for the DW_AT_declaration flag.
10891 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10892 copy decls and set the DECL_ABSTRACT flag on them instead of
10895 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10896 else if (old_die
&& TREE_STATIC (decl
)
10897 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
10899 /* This is a definition of a C++ class level static. */
10900 add_AT_die_ref (var_die
, DW_AT_specification
, old_die
);
10901 if (DECL_NAME (decl
))
10903 unsigned file_index
= lookup_filename (DECL_SOURCE_FILE (decl
));
10905 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
10906 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
10908 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
10909 != (unsigned) DECL_SOURCE_LINE (decl
))
10911 add_AT_unsigned (var_die
, DW_AT_decl_line
,
10912 DECL_SOURCE_LINE (decl
));
10917 add_name_and_src_coords_attributes (var_die
, decl
);
10918 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
10919 TREE_THIS_VOLATILE (decl
), context_die
);
10921 if (TREE_PUBLIC (decl
))
10922 add_AT_flag (var_die
, DW_AT_external
, 1);
10924 if (DECL_ARTIFICIAL (decl
))
10925 add_AT_flag (var_die
, DW_AT_artificial
, 1);
10927 if (TREE_PROTECTED (decl
))
10928 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
10929 else if (TREE_PRIVATE (decl
))
10930 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
10934 add_AT_flag (var_die
, DW_AT_declaration
, 1);
10936 if (class_scope_p (context_die
) || DECL_ABSTRACT (decl
))
10937 equate_decl_number_to_die (decl
, var_die
);
10939 if (! declaration
&& ! DECL_ABSTRACT (decl
))
10941 add_location_or_const_value_attribute (var_die
, decl
);
10942 add_pubname (decl
, var_die
);
10945 tree_add_const_value_attribute (var_die
, decl
);
10948 /* Generate a DIE to represent a label identifier. */
10951 gen_label_die (decl
, context_die
)
10953 dw_die_ref context_die
;
10955 tree origin
= decl_ultimate_origin (decl
);
10956 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
10958 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10960 if (origin
!= NULL
)
10961 add_abstract_origin_attribute (lbl_die
, origin
);
10963 add_name_and_src_coords_attributes (lbl_die
, decl
);
10965 if (DECL_ABSTRACT (decl
))
10966 equate_decl_number_to_die (decl
, lbl_die
);
10969 insn
= DECL_RTL (decl
);
10971 /* Deleted labels are programmer specified labels which have been
10972 eliminated because of various optimisations. We still emit them
10973 here so that it is possible to put breakpoints on them. */
10974 if (GET_CODE (insn
) == CODE_LABEL
10975 || ((GET_CODE (insn
) == NOTE
10976 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
)))
10978 /* When optimization is enabled (via -O) some parts of the compiler
10979 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10980 represent source-level labels which were explicitly declared by
10981 the user. This really shouldn't be happening though, so catch
10982 it if it ever does happen. */
10983 if (INSN_DELETED_P (insn
))
10986 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
10987 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
10992 /* Generate a DIE for a lexical block. */
10995 gen_lexical_block_die (stmt
, context_die
, depth
)
10997 dw_die_ref context_die
;
11000 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
11001 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11003 if (! BLOCK_ABSTRACT (stmt
))
11005 if (BLOCK_FRAGMENT_CHAIN (stmt
))
11009 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
11011 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
11014 add_ranges (chain
);
11015 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
11022 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11023 BLOCK_NUMBER (stmt
));
11024 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
11025 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11026 BLOCK_NUMBER (stmt
));
11027 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
11031 decls_for_scope (stmt
, stmt_die
, depth
);
11034 /* Generate a DIE for an inlined subprogram. */
11037 gen_inlined_subroutine_die (stmt
, context_die
, depth
)
11039 dw_die_ref context_die
;
11042 if (! BLOCK_ABSTRACT (stmt
))
11044 dw_die_ref subr_die
11045 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
11046 tree decl
= block_ultimate_origin (stmt
);
11047 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11049 /* Emit info for the abstract instance first, if we haven't yet. */
11050 dwarf2out_abstract_function (decl
);
11052 add_abstract_origin_attribute (subr_die
, decl
);
11053 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11054 BLOCK_NUMBER (stmt
));
11055 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
11056 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11057 BLOCK_NUMBER (stmt
));
11058 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
11059 decls_for_scope (stmt
, subr_die
, depth
);
11060 current_function_has_inlines
= 1;
11063 /* We may get here if we're the outer block of function A that was
11064 inlined into function B that was inlined into function C. When
11065 generating debugging info for C, dwarf2out_abstract_function(B)
11066 would mark all inlined blocks as abstract, including this one.
11067 So, we wouldn't (and shouldn't) expect labels to be generated
11068 for this one. Instead, just emit debugging info for
11069 declarations within the block. This is particularly important
11070 in the case of initializers of arguments passed from B to us:
11071 if they're statement expressions containing declarations, we
11072 wouldn't generate dies for their abstract variables, and then,
11073 when generating dies for the real variables, we'd die (pun
11075 gen_lexical_block_die (stmt
, context_die
, depth
);
11078 /* Generate a DIE for a field in a record, or structure. */
11081 gen_field_die (decl
, context_die
)
11083 dw_die_ref context_die
;
11085 dw_die_ref decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
11087 add_name_and_src_coords_attributes (decl_die
, decl
);
11088 add_type_attribute (decl_die
, member_declared_type (decl
),
11089 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
11092 if (DECL_BIT_FIELD_TYPE (decl
))
11094 add_byte_size_attribute (decl_die
, decl
);
11095 add_bit_size_attribute (decl_die
, decl
);
11096 add_bit_offset_attribute (decl_die
, decl
);
11099 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
11100 add_data_member_location_attribute (decl_die
, decl
);
11102 if (DECL_ARTIFICIAL (decl
))
11103 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11105 if (TREE_PROTECTED (decl
))
11106 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11107 else if (TREE_PRIVATE (decl
))
11108 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11112 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11113 Use modified_type_die instead.
11114 We keep this code here just in case these types of DIEs may be needed to
11115 represent certain things in other languages (e.g. Pascal) someday. */
11118 gen_pointer_type_die (type
, context_die
)
11120 dw_die_ref context_die
;
11123 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
11125 equate_type_number_to_die (type
, ptr_die
);
11126 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11127 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11130 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11131 Use modified_type_die instead.
11132 We keep this code here just in case these types of DIEs may be needed to
11133 represent certain things in other languages (e.g. Pascal) someday. */
11136 gen_reference_type_die (type
, context_die
)
11138 dw_die_ref context_die
;
11141 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
11143 equate_type_number_to_die (type
, ref_die
);
11144 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
11145 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11149 /* Generate a DIE for a pointer to a member type. */
11152 gen_ptr_to_mbr_type_die (type
, context_die
)
11154 dw_die_ref context_die
;
11157 = new_die (DW_TAG_ptr_to_member_type
,
11158 scope_die_for (type
, context_die
), type
);
11160 equate_type_number_to_die (type
, ptr_die
);
11161 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
11162 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
11163 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11166 /* Generate the DIE for the compilation unit. */
11169 gen_compile_unit_die (filename
)
11170 const char *filename
;
11173 char producer
[250];
11174 const char *wd
= getpwd ();
11175 const char *language_string
= lang_hooks
.name
;
11178 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
11179 add_name_attribute (die
, filename
);
11181 if (wd
!= NULL
&& filename
[0] != DIR_SEPARATOR
)
11182 add_AT_string (die
, DW_AT_comp_dir
, wd
);
11184 sprintf (producer
, "%s %s", language_string
, version_string
);
11186 #ifdef MIPS_DEBUGGING_INFO
11187 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11188 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11189 not appear in the producer string, the debugger reaches the conclusion
11190 that the object file is stripped and has no debugging information.
11191 To get the MIPS/SGI debugger to believe that there is debugging
11192 information in the object file, we add a -g to the producer string. */
11193 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11194 strcat (producer
, " -g");
11197 add_AT_string (die
, DW_AT_producer
, producer
);
11199 if (strcmp (language_string
, "GNU C++") == 0)
11200 language
= DW_LANG_C_plus_plus
;
11201 else if (strcmp (language_string
, "GNU Ada") == 0)
11202 language
= DW_LANG_Ada83
;
11203 else if (strcmp (language_string
, "GNU F77") == 0)
11204 language
= DW_LANG_Fortran77
;
11205 else if (strcmp (language_string
, "GNU Pascal") == 0)
11206 language
= DW_LANG_Pascal83
;
11207 else if (strcmp (language_string
, "GNU Java") == 0)
11208 language
= DW_LANG_Java
;
11210 language
= DW_LANG_C89
;
11212 add_AT_unsigned (die
, DW_AT_language
, language
);
11216 /* Generate a DIE for a string type. */
11219 gen_string_type_die (type
, context_die
)
11221 dw_die_ref context_die
;
11223 dw_die_ref type_die
11224 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
11226 equate_type_number_to_die (type
, type_die
);
11228 /* ??? Fudge the string length attribute for now.
11229 TODO: add string length info. */
11231 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
11232 bound_representation (upper_bound
, 0, 'u');
11236 /* Generate the DIE for a base class. */
11239 gen_inheritance_die (binfo
, context_die
)
11241 dw_die_ref context_die
;
11243 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
11245 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
11246 add_data_member_location_attribute (die
, binfo
);
11248 if (TREE_VIA_VIRTUAL (binfo
))
11249 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11251 if (TREE_VIA_PUBLIC (binfo
))
11252 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
11253 else if (TREE_VIA_PROTECTED (binfo
))
11254 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11257 /* Generate a DIE for a class member. */
11260 gen_member_die (type
, context_die
)
11262 dw_die_ref context_die
;
11267 /* If this is not an incomplete type, output descriptions of each of its
11268 members. Note that as we output the DIEs necessary to represent the
11269 members of this record or union type, we will also be trying to output
11270 DIEs to represent the *types* of those members. However the `type'
11271 function (above) will specifically avoid generating type DIEs for member
11272 types *within* the list of member DIEs for this (containing) type except
11273 for those types (of members) which are explicitly marked as also being
11274 members of this (containing) type themselves. The g++ front- end can
11275 force any given type to be treated as a member of some other (containing)
11276 type by setting the TYPE_CONTEXT of the given (member) type to point to
11277 the TREE node representing the appropriate (containing) type. */
11279 /* First output info about the base classes. */
11280 if (TYPE_BINFO (type
) && TYPE_BINFO_BASETYPES (type
))
11282 tree bases
= TYPE_BINFO_BASETYPES (type
);
11283 int n_bases
= TREE_VEC_LENGTH (bases
);
11286 for (i
= 0; i
< n_bases
; i
++)
11287 gen_inheritance_die (TREE_VEC_ELT (bases
, i
), context_die
);
11290 /* Now output info about the data members and type members. */
11291 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
11293 /* If we thought we were generating minimal debug info for TYPE
11294 and then changed our minds, some of the member declarations
11295 may have already been defined. Don't define them again, but
11296 do put them in the right order. */
11298 child
= lookup_decl_die (member
);
11300 splice_child_die (context_die
, child
);
11302 gen_decl_die (member
, context_die
);
11305 /* Now output info about the function members (if any). */
11306 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
11308 /* Don't include clones in the member list. */
11309 if (DECL_ABSTRACT_ORIGIN (member
))
11312 child
= lookup_decl_die (member
);
11314 splice_child_die (context_die
, child
);
11316 gen_decl_die (member
, context_die
);
11320 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11321 is set, we pretend that the type was never defined, so we only get the
11322 member DIEs needed by later specification DIEs. */
11325 gen_struct_or_union_type_die (type
, context_die
)
11327 dw_die_ref context_die
;
11329 dw_die_ref type_die
= lookup_type_die (type
);
11330 dw_die_ref scope_die
= 0;
11332 int complete
= (TYPE_SIZE (type
)
11333 && (! TYPE_STUB_DECL (type
)
11334 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
11336 if (type_die
&& ! complete
)
11339 if (TYPE_CONTEXT (type
) != NULL_TREE
11340 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
)))
11343 scope_die
= scope_die_for (type
, context_die
);
11345 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
11346 /* First occurrence of type or toplevel definition of nested class. */
11348 dw_die_ref old_die
= type_die
;
11350 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
11351 ? DW_TAG_structure_type
: DW_TAG_union_type
,
11353 equate_type_number_to_die (type
, type_die
);
11355 add_AT_die_ref (type_die
, DW_AT_specification
, old_die
);
11357 add_name_attribute (type_die
, type_tag (type
));
11360 remove_AT (type_die
, DW_AT_declaration
);
11362 /* If this type has been completed, then give it a byte_size attribute and
11363 then give a list of members. */
11366 /* Prevent infinite recursion in cases where the type of some member of
11367 this type is expressed in terms of this type itself. */
11368 TREE_ASM_WRITTEN (type
) = 1;
11369 add_byte_size_attribute (type_die
, type
);
11370 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11371 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11373 /* If the first reference to this type was as the return type of an
11374 inline function, then it may not have a parent. Fix this now. */
11375 if (type_die
->die_parent
== NULL
)
11376 add_child_die (scope_die
, type_die
);
11378 push_decl_scope (type
);
11379 gen_member_die (type
, type_die
);
11382 /* GNU extension: Record what type our vtable lives in. */
11383 if (TYPE_VFIELD (type
))
11385 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
11387 gen_type_die (vtype
, context_die
);
11388 add_AT_die_ref (type_die
, DW_AT_containing_type
,
11389 lookup_type_die (vtype
));
11394 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11396 /* We don't need to do this for function-local types. */
11397 if (TYPE_STUB_DECL (type
)
11398 && ! decl_function_context (TYPE_STUB_DECL (type
)))
11399 VARRAY_PUSH_TREE (incomplete_types
, type
);
11403 /* Generate a DIE for a subroutine _type_. */
11406 gen_subroutine_type_die (type
, context_die
)
11408 dw_die_ref context_die
;
11410 tree return_type
= TREE_TYPE (type
);
11411 dw_die_ref subr_die
11412 = new_die (DW_TAG_subroutine_type
,
11413 scope_die_for (type
, context_die
), type
);
11415 equate_type_number_to_die (type
, subr_die
);
11416 add_prototyped_attribute (subr_die
, type
);
11417 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
11418 gen_formal_types_die (type
, subr_die
);
11421 /* Generate a DIE for a type definition */
11424 gen_typedef_die (decl
, context_die
)
11426 dw_die_ref context_die
;
11428 dw_die_ref type_die
;
11431 if (TREE_ASM_WRITTEN (decl
))
11434 TREE_ASM_WRITTEN (decl
) = 1;
11435 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
11436 origin
= decl_ultimate_origin (decl
);
11437 if (origin
!= NULL
)
11438 add_abstract_origin_attribute (type_die
, origin
);
11443 add_name_and_src_coords_attributes (type_die
, decl
);
11444 if (DECL_ORIGINAL_TYPE (decl
))
11446 type
= DECL_ORIGINAL_TYPE (decl
);
11448 if (type
== TREE_TYPE (decl
))
11451 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
11454 type
= TREE_TYPE (decl
);
11456 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
11457 TREE_THIS_VOLATILE (decl
), context_die
);
11460 if (DECL_ABSTRACT (decl
))
11461 equate_decl_number_to_die (decl
, type_die
);
11464 /* Generate a type description DIE. */
11467 gen_type_die (type
, context_die
)
11469 dw_die_ref context_die
;
11473 if (type
== NULL_TREE
|| type
== error_mark_node
)
11476 /* We are going to output a DIE to represent the unqualified version
11477 of this type (i.e. without any const or volatile qualifiers) so
11478 get the main variant (i.e. the unqualified version) of this type
11479 now. (Vectors are special because the debugging info is in the
11480 cloned type itself). */
11481 if (TREE_CODE (type
) != VECTOR_TYPE
)
11482 type
= type_main_variant (type
);
11484 if (TREE_ASM_WRITTEN (type
))
11487 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
11488 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
11490 /* Prevent broken recursion; we can't hand off to the same type. */
11491 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
11494 TREE_ASM_WRITTEN (type
) = 1;
11495 gen_decl_die (TYPE_NAME (type
), context_die
);
11499 switch (TREE_CODE (type
))
11505 case REFERENCE_TYPE
:
11506 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11507 ensures that the gen_type_die recursion will terminate even if the
11508 type is recursive. Recursive types are possible in Ada. */
11509 /* ??? We could perhaps do this for all types before the switch
11511 TREE_ASM_WRITTEN (type
) = 1;
11513 /* For these types, all that is required is that we output a DIE (or a
11514 set of DIEs) to represent the "basis" type. */
11515 gen_type_die (TREE_TYPE (type
), context_die
);
11519 /* This code is used for C++ pointer-to-data-member types.
11520 Output a description of the relevant class type. */
11521 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
11523 /* Output a description of the type of the object pointed to. */
11524 gen_type_die (TREE_TYPE (type
), context_die
);
11526 /* Now output a DIE to represent this pointer-to-data-member type
11528 gen_ptr_to_mbr_type_die (type
, context_die
);
11532 gen_type_die (TYPE_DOMAIN (type
), context_die
);
11533 gen_set_type_die (type
, context_die
);
11537 gen_type_die (TREE_TYPE (type
), context_die
);
11538 abort (); /* No way to represent these in Dwarf yet! */
11541 case FUNCTION_TYPE
:
11542 /* Force out return type (in case it wasn't forced out already). */
11543 gen_type_die (TREE_TYPE (type
), context_die
);
11544 gen_subroutine_type_die (type
, context_die
);
11548 /* Force out return type (in case it wasn't forced out already). */
11549 gen_type_die (TREE_TYPE (type
), context_die
);
11550 gen_subroutine_type_die (type
, context_die
);
11554 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
11556 gen_type_die (TREE_TYPE (type
), context_die
);
11557 gen_string_type_die (type
, context_die
);
11560 gen_array_type_die (type
, context_die
);
11564 gen_array_type_die (type
, context_die
);
11567 case ENUMERAL_TYPE
:
11570 case QUAL_UNION_TYPE
:
11571 /* If this is a nested type whose containing class hasn't been written
11572 out yet, writing it out will cover this one, too. This does not apply
11573 to instantiations of member class templates; they need to be added to
11574 the containing class as they are generated. FIXME: This hurts the
11575 idea of combining type decls from multiple TUs, since we can't predict
11576 what set of template instantiations we'll get. */
11577 if (TYPE_CONTEXT (type
)
11578 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11579 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
11581 gen_type_die (TYPE_CONTEXT (type
), context_die
);
11583 if (TREE_ASM_WRITTEN (type
))
11586 /* If that failed, attach ourselves to the stub. */
11587 push_decl_scope (TYPE_CONTEXT (type
));
11588 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
11594 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
11595 gen_enumeration_type_die (type
, context_die
);
11597 gen_struct_or_union_type_die (type
, context_die
);
11602 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11603 it up if it is ever completed. gen_*_type_die will set it for us
11604 when appropriate. */
11613 /* No DIEs needed for fundamental types. */
11617 /* No Dwarf representation currently defined. */
11624 TREE_ASM_WRITTEN (type
) = 1;
11627 /* Generate a DIE for a tagged type instantiation. */
11630 gen_tagged_type_instantiation_die (type
, context_die
)
11632 dw_die_ref context_die
;
11634 if (type
== NULL_TREE
|| type
== error_mark_node
)
11637 /* We are going to output a DIE to represent the unqualified version of
11638 this type (i.e. without any const or volatile qualifiers) so make sure
11639 that we have the main variant (i.e. the unqualified version) of this
11641 if (type
!= type_main_variant (type
))
11644 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11645 an instance of an unresolved type. */
11647 switch (TREE_CODE (type
))
11652 case ENUMERAL_TYPE
:
11653 gen_inlined_enumeration_type_die (type
, context_die
);
11657 gen_inlined_structure_type_die (type
, context_die
);
11661 case QUAL_UNION_TYPE
:
11662 gen_inlined_union_type_die (type
, context_die
);
11670 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11671 things which are local to the given block. */
11674 gen_block_die (stmt
, context_die
, depth
)
11676 dw_die_ref context_die
;
11679 int must_output_die
= 0;
11682 enum tree_code origin_code
;
11684 /* Ignore blocks never really used to make RTL. */
11685 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
11686 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
11689 /* If the block is one fragment of a non-contiguous block, do not
11690 process the variables, since they will have been done by the
11691 origin block. Do process subblocks. */
11692 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
11696 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
11697 gen_block_die (sub
, context_die
, depth
+ 1);
11702 /* Determine the "ultimate origin" of this block. This block may be an
11703 inlined instance of an inlined instance of inline function, so we have
11704 to trace all of the way back through the origin chain to find out what
11705 sort of node actually served as the original seed for the creation of
11706 the current block. */
11707 origin
= block_ultimate_origin (stmt
);
11708 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
11710 /* Determine if we need to output any Dwarf DIEs at all to represent this
11712 if (origin_code
== FUNCTION_DECL
)
11713 /* The outer scopes for inlinings *must* always be represented. We
11714 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11715 must_output_die
= 1;
11718 /* In the case where the current block represents an inlining of the
11719 "body block" of an inline function, we must *NOT* output any DIE for
11720 this block because we have already output a DIE to represent the whole
11721 inlined function scope and the "body block" of any function doesn't
11722 really represent a different scope according to ANSI C rules. So we
11723 check here to make sure that this block does not represent a "body
11724 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11725 if (! is_body_block (origin
? origin
: stmt
))
11727 /* Determine if this block directly contains any "significant"
11728 local declarations which we will need to output DIEs for. */
11729 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11730 /* We are not in terse mode so *any* local declaration counts
11731 as being a "significant" one. */
11732 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
11734 /* We are in terse mode, so only local (nested) function
11735 definitions count as "significant" local declarations. */
11736 for (decl
= BLOCK_VARS (stmt
);
11737 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11738 if (TREE_CODE (decl
) == FUNCTION_DECL
11739 && DECL_INITIAL (decl
))
11741 must_output_die
= 1;
11747 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11748 DIE for any block which contains no significant local declarations at
11749 all. Rather, in such cases we just call `decls_for_scope' so that any
11750 needed Dwarf info for any sub-blocks will get properly generated. Note
11751 that in terse mode, our definition of what constitutes a "significant"
11752 local declaration gets restricted to include only inlined function
11753 instances and local (nested) function definitions. */
11754 if (must_output_die
)
11756 if (origin_code
== FUNCTION_DECL
)
11757 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
11759 gen_lexical_block_die (stmt
, context_die
, depth
);
11762 decls_for_scope (stmt
, context_die
, depth
);
11765 /* Generate all of the decls declared within a given scope and (recursively)
11766 all of its sub-blocks. */
11769 decls_for_scope (stmt
, context_die
, depth
)
11771 dw_die_ref context_die
;
11777 /* Ignore blocks never really used to make RTL. */
11778 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
11781 /* Output the DIEs to represent all of the data objects and typedefs
11782 declared directly within this block but not within any nested
11783 sub-blocks. Also, nested function and tag DIEs have been
11784 generated with a parent of NULL; fix that up now. */
11785 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
11789 if (TREE_CODE (decl
) == FUNCTION_DECL
)
11790 die
= lookup_decl_die (decl
);
11791 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
11792 die
= lookup_type_die (TREE_TYPE (decl
));
11796 if (die
!= NULL
&& die
->die_parent
== NULL
)
11797 add_child_die (context_die
, die
);
11799 gen_decl_die (decl
, context_die
);
11802 /* Output the DIEs to represent all sub-blocks (and the items declared
11803 therein) of this block. */
11804 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
11806 subblocks
= BLOCK_CHAIN (subblocks
))
11807 gen_block_die (subblocks
, context_die
, depth
+ 1);
11810 /* Is this a typedef we can avoid emitting? */
11813 is_redundant_typedef (decl
)
11816 if (TYPE_DECL_IS_STUB (decl
))
11819 if (DECL_ARTIFICIAL (decl
)
11820 && DECL_CONTEXT (decl
)
11821 && is_tagged_type (DECL_CONTEXT (decl
))
11822 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
11823 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
11824 /* Also ignore the artificial member typedef for the class name. */
11830 /* Generate Dwarf debug information for a decl described by DECL. */
11833 gen_decl_die (decl
, context_die
)
11835 dw_die_ref context_die
;
11839 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
11842 switch (TREE_CODE (decl
))
11848 /* The individual enumerators of an enum type get output when we output
11849 the Dwarf representation of the relevant enum type itself. */
11852 case FUNCTION_DECL
:
11853 /* Don't output any DIEs to represent mere function declarations,
11854 unless they are class members or explicit block externs. */
11855 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
11856 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
11859 /* If we're emitting a clone, emit info for the abstract instance. */
11860 if (DECL_ORIGIN (decl
) != decl
)
11861 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
11863 /* If we're emitting an out-of-line copy of an inline function,
11864 emit info for the abstract instance and set up to refer to it. */
11865 else if (DECL_INLINE (decl
) && ! DECL_ABSTRACT (decl
)
11866 && ! class_scope_p (context_die
)
11867 /* dwarf2out_abstract_function won't emit a die if this is just
11868 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11869 that case, because that works only if we have a die. */
11870 && DECL_INITIAL (decl
) != NULL_TREE
)
11872 dwarf2out_abstract_function (decl
);
11873 set_decl_origin_self (decl
);
11876 /* Otherwise we're emitting the primary DIE for this decl. */
11877 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
11879 /* Before we describe the FUNCTION_DECL itself, make sure that we
11880 have described its return type. */
11881 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
11883 /* And its virtual context. */
11884 if (DECL_VINDEX (decl
) != NULL_TREE
)
11885 gen_type_die (DECL_CONTEXT (decl
), context_die
);
11887 /* And its containing type. */
11888 origin
= decl_class_context (decl
);
11889 if (origin
!= NULL_TREE
)
11890 gen_type_die_for_member (origin
, decl
, context_die
);
11893 /* Now output a DIE to represent the function itself. */
11894 gen_subprogram_die (decl
, context_die
);
11898 /* If we are in terse mode, don't generate any DIEs to represent any
11899 actual typedefs. */
11900 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11903 /* In the special case of a TYPE_DECL node representing the declaration
11904 of some type tag, if the given TYPE_DECL is marked as having been
11905 instantiated from some other (original) TYPE_DECL node (e.g. one which
11906 was generated within the original definition of an inline function) we
11907 have to generate a special (abbreviated) DW_TAG_structure_type,
11908 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11909 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
11911 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
11915 if (is_redundant_typedef (decl
))
11916 gen_type_die (TREE_TYPE (decl
), context_die
);
11918 /* Output a DIE to represent the typedef itself. */
11919 gen_typedef_die (decl
, context_die
);
11923 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
11924 gen_label_die (decl
, context_die
);
11928 /* If we are in terse mode, don't generate any DIEs to represent any
11929 variable declarations or definitions. */
11930 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11933 /* Output any DIEs that are needed to specify the type of this data
11935 gen_type_die (TREE_TYPE (decl
), context_die
);
11937 /* And its containing type. */
11938 origin
= decl_class_context (decl
);
11939 if (origin
!= NULL_TREE
)
11940 gen_type_die_for_member (origin
, decl
, context_die
);
11942 /* Now output the DIE to represent the data object itself. This gets
11943 complicated because of the possibility that the VAR_DECL really
11944 represents an inlined instance of a formal parameter for an inline
11946 origin
= decl_ultimate_origin (decl
);
11947 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
11948 gen_formal_parameter_die (decl
, context_die
);
11950 gen_variable_die (decl
, context_die
);
11954 /* Ignore the nameless fields that are used to skip bits but handle C++
11955 anonymous unions. */
11956 if (DECL_NAME (decl
) != NULL_TREE
11957 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
)
11959 gen_type_die (member_declared_type (decl
), context_die
);
11960 gen_field_die (decl
, context_die
);
11965 gen_type_die (TREE_TYPE (decl
), context_die
);
11966 gen_formal_parameter_die (decl
, context_die
);
11969 case NAMESPACE_DECL
:
11970 /* Ignore for now. */
11979 mark_limbo_die_list (ptr
)
11980 void *ptr ATTRIBUTE_UNUSED
;
11982 limbo_die_node
*node
;
11983 for (node
= limbo_die_list
; node
; node
= node
->next
)
11984 ggc_mark_tree (node
->created_for
);
11987 /* Add Ada "use" clause information for SGI Workshop debugger. */
11990 dwarf2out_add_library_unit_info (filename
, context_list
)
11991 const char *filename
;
11992 const char *context_list
;
11994 unsigned int file_index
;
11996 if (filename
!= NULL
)
11998 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
11999 tree context_list_decl
12000 = build_decl (LABEL_DECL
, get_identifier (context_list
),
12003 TREE_PUBLIC (context_list_decl
) = TRUE
;
12004 add_name_attribute (unit_die
, context_list
);
12005 file_index
= lookup_filename (filename
);
12006 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
12007 add_pubname (context_list_decl
, unit_die
);
12011 /* Output debug information for global decl DECL. Called from toplev.c after
12012 compilation proper has finished. */
12015 dwarf2out_global_decl (decl
)
12018 /* Output DWARF2 information for file-scope tentative data object
12019 declarations, file-scope (extern) function declarations (which had no
12020 corresponding body) and file-scope tagged type declarations and
12021 definitions which have not yet been forced out. */
12022 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
12023 dwarf2out_decl (decl
);
12026 /* Write the debugging output for DECL. */
12029 dwarf2out_decl (decl
)
12032 dw_die_ref context_die
= comp_unit_die
;
12034 switch (TREE_CODE (decl
))
12039 case FUNCTION_DECL
:
12040 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
12041 builtin function. Explicit programmer-supplied declarations of
12042 these same functions should NOT be ignored however. */
12043 if (DECL_EXTERNAL (decl
) && DECL_BUILT_IN (decl
))
12046 /* What we would really like to do here is to filter out all mere
12047 file-scope declarations of file-scope functions which are never
12048 referenced later within this translation unit (and keep all of ones
12049 that *are* referenced later on) but we aren't clairvoyant, so we have
12050 no idea which functions will be referenced in the future (i.e. later
12051 on within the current translation unit). So here we just ignore all
12052 file-scope function declarations which are not also definitions. If
12053 and when the debugger needs to know something about these functions,
12054 it will have to hunt around and find the DWARF information associated
12055 with the definition of the function.
12057 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
12058 nodes represent definitions and which ones represent mere
12059 declarations. We have to check DECL_INITIAL instead. That's because
12060 the C front-end supports some weird semantics for "extern inline"
12061 function definitions. These can get inlined within the current
12062 translation unit (an thus, we need to generate Dwarf info for their
12063 abstract instances so that the Dwarf info for the concrete inlined
12064 instances can have something to refer to) but the compiler never
12065 generates any out-of-lines instances of such things (despite the fact
12066 that they *are* definitions).
12068 The important point is that the C front-end marks these "extern
12069 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
12070 them anyway. Note that the C++ front-end also plays some similar games
12071 for inline function definitions appearing within include files which
12072 also contain `#pragma interface' pragmas. */
12073 if (DECL_INITIAL (decl
) == NULL_TREE
)
12076 /* If we're a nested function, initially use a parent of NULL; if we're
12077 a plain function, this will be fixed up in decls_for_scope. If
12078 we're a method, it will be ignored, since we already have a DIE. */
12079 if (decl_function_context (decl
))
12080 context_die
= NULL
;
12084 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12085 declaration and if the declaration was never even referenced from
12086 within this entire compilation unit. We suppress these DIEs in
12087 order to save space in the .debug section (by eliminating entries
12088 which are probably useless). Note that we must not suppress
12089 block-local extern declarations (whether used or not) because that
12090 would screw-up the debugger's name lookup mechanism and cause it to
12091 miss things which really ought to be in scope at a given point. */
12092 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
12095 /* If we are in terse mode, don't generate any DIEs to represent any
12096 variable declarations or definitions. */
12097 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12102 /* Don't emit stubs for types unless they are needed by other DIEs. */
12103 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
12106 /* Don't bother trying to generate any DIEs to represent any of the
12107 normal built-in types for the language we are compiling. */
12108 if (DECL_SOURCE_LINE (decl
) == 0)
12110 /* OK, we need to generate one for `bool' so GDB knows what type
12111 comparisons have. */
12112 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
12113 == DW_LANG_C_plus_plus
)
12114 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
12115 && ! DECL_IGNORED_P (decl
))
12116 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
12121 /* If we are in terse mode, don't generate any DIEs for types. */
12122 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12125 /* If we're a function-scope tag, initially use a parent of NULL;
12126 this will be fixed up in decls_for_scope. */
12127 if (decl_function_context (decl
))
12128 context_die
= NULL
;
12136 gen_decl_die (decl
, context_die
);
12139 /* Output a marker (i.e. a label) for the beginning of the generated code for
12140 a lexical block. */
12143 dwarf2out_begin_block (line
, blocknum
)
12144 unsigned int line ATTRIBUTE_UNUSED
;
12145 unsigned int blocknum
;
12147 function_section (current_function_decl
);
12148 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
12151 /* Output a marker (i.e. a label) for the end of the generated code for a
12155 dwarf2out_end_block (line
, blocknum
)
12156 unsigned int line ATTRIBUTE_UNUSED
;
12157 unsigned int blocknum
;
12159 function_section (current_function_decl
);
12160 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
12163 /* Returns nonzero if it is appropriate not to emit any debugging
12164 information for BLOCK, because it doesn't contain any instructions.
12166 Don't allow this for blocks with nested functions or local classes
12167 as we would end up with orphans, and in the presence of scheduling
12168 we may end up calling them anyway. */
12171 dwarf2out_ignore_block (block
)
12176 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
12177 if (TREE_CODE (decl
) == FUNCTION_DECL
12178 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
12184 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12185 dwarf2out.c) and return its "index". The index of each (known) filename is
12186 just a unique number which is associated with only that one filename. We
12187 need such numbers for the sake of generating labels (in the .debug_sfnames
12188 section) and references to those files numbers (in the .debug_srcinfo
12189 and.debug_macinfo sections). If the filename given as an argument is not
12190 found in our current list, add it to the list and assign it the next
12191 available unique index number. In order to speed up searches, we remember
12192 the index of the filename was looked up last. This handles the majority of
12196 lookup_filename (file_name
)
12197 const char *file_name
;
12201 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
12202 if (strcmp (file_name
, "<internal>") == 0
12203 || strcmp (file_name
, "<built-in>") == 0)
12206 /* Check to see if the file name that was searched on the previous
12207 call matches this file name. If so, return the index. */
12208 if (file_table
.last_lookup_index
!= 0)
12209 if (0 == strcmp (file_name
,
12210 file_table
.table
[file_table
.last_lookup_index
]))
12211 return file_table
.last_lookup_index
;
12213 /* Didn't match the previous lookup, search the table */
12214 for (i
= 1; i
< file_table
.in_use
; i
++)
12215 if (strcmp (file_name
, file_table
.table
[i
]) == 0)
12217 file_table
.last_lookup_index
= i
;
12221 /* Prepare to add a new table entry by making sure there is enough space in
12222 the table to do so. If not, expand the current table. */
12223 if (i
== file_table
.allocated
)
12225 file_table
.allocated
= i
+ FILE_TABLE_INCREMENT
;
12226 file_table
.table
= (char **)
12227 xrealloc (file_table
.table
, file_table
.allocated
* sizeof (char *));
12230 /* Add the new entry to the end of the filename table. */
12231 file_table
.table
[i
] = xstrdup (file_name
);
12232 file_table
.in_use
= i
+ 1;
12233 file_table
.last_lookup_index
= i
;
12235 if (DWARF2_ASM_LINE_DEBUG_INFO
)
12237 fprintf (asm_out_file
, "\t.file %u ", i
);
12238 output_quoted_string (asm_out_file
, file_name
);
12239 fputc ('\n', asm_out_file
);
12248 /* Allocate the initial hunk of the file_table. */
12249 file_table
.table
= (char **) xcalloc (FILE_TABLE_INCREMENT
, sizeof (char *));
12250 file_table
.allocated
= FILE_TABLE_INCREMENT
;
12252 /* Skip the first entry - file numbers begin at 1. */
12253 file_table
.in_use
= 1;
12254 file_table
.last_lookup_index
= 0;
12257 /* Output a label to mark the beginning of a source code line entry
12258 and record information relating to this source line, in
12259 'line_info_table' for later output of the .debug_line section. */
12262 dwarf2out_source_line (line
, filename
)
12264 const char *filename
;
12266 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12268 function_section (current_function_decl
);
12270 /* If requested, emit something human-readable. */
12271 if (flag_debug_asm
)
12272 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
12275 if (DWARF2_ASM_LINE_DEBUG_INFO
)
12277 unsigned file_num
= lookup_filename (filename
);
12279 /* Emit the .loc directive understood by GNU as. */
12280 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
12282 /* Indicate that line number info exists. */
12283 line_info_table_in_use
++;
12285 /* Indicate that multiple line number tables exist. */
12286 if (DECL_SECTION_NAME (current_function_decl
))
12287 separate_line_info_table_in_use
++;
12289 else if (DECL_SECTION_NAME (current_function_decl
))
12291 dw_separate_line_info_ref line_info
;
12292 (*targetm
.asm_out
.internal_label
) (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
12293 separate_line_info_table_in_use
);
12295 /* expand the line info table if necessary */
12296 if (separate_line_info_table_in_use
12297 == separate_line_info_table_allocated
)
12299 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
12300 separate_line_info_table
12301 = (dw_separate_line_info_ref
)
12302 xrealloc (separate_line_info_table
,
12303 separate_line_info_table_allocated
12304 * sizeof (dw_separate_line_info_entry
));
12307 /* Add the new entry at the end of the line_info_table. */
12309 = &separate_line_info_table
[separate_line_info_table_in_use
++];
12310 line_info
->dw_file_num
= lookup_filename (filename
);
12311 line_info
->dw_line_num
= line
;
12312 line_info
->function
= current_function_funcdef_no
;
12316 dw_line_info_ref line_info
;
12318 (*targetm
.asm_out
.internal_label
) (asm_out_file
, LINE_CODE_LABEL
,
12319 line_info_table_in_use
);
12321 /* Expand the line info table if necessary. */
12322 if (line_info_table_in_use
== line_info_table_allocated
)
12324 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
12326 = (dw_line_info_ref
)
12327 xrealloc (line_info_table
,
12328 (line_info_table_allocated
12329 * sizeof (dw_line_info_entry
)));
12332 /* Add the new entry at the end of the line_info_table. */
12333 line_info
= &line_info_table
[line_info_table_in_use
++];
12334 line_info
->dw_file_num
= lookup_filename (filename
);
12335 line_info
->dw_line_num
= line
;
12340 /* Record the beginning of a new source file. */
12343 dwarf2out_start_source_file (lineno
, filename
)
12344 unsigned int lineno
;
12345 const char *filename
;
12347 if (flag_eliminate_dwarf2_dups
&& !is_main_source
)
12349 /* Record the beginning of the file for break_out_includes. */
12350 dw_die_ref bincl_die
;
12352 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
12353 add_AT_string (bincl_die
, DW_AT_name
, filename
);
12356 is_main_source
= 0;
12358 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12360 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12361 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
12362 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
12364 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
12365 "Filename we just started");
12369 /* Record the end of a source file. */
12372 dwarf2out_end_source_file (lineno
)
12373 unsigned int lineno ATTRIBUTE_UNUSED
;
12375 if (flag_eliminate_dwarf2_dups
)
12376 /* Record the end of the file for break_out_includes. */
12377 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
12379 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12381 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12382 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12386 /* Called from debug_define in toplev.c. The `buffer' parameter contains
12387 the tail part of the directive line, i.e. the part which is past the
12388 initial whitespace, #, whitespace, directive-name, whitespace part. */
12391 dwarf2out_define (lineno
, buffer
)
12392 unsigned lineno ATTRIBUTE_UNUSED
;
12393 const char *buffer ATTRIBUTE_UNUSED
;
12395 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12397 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12398 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
12399 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12400 dw2_asm_output_nstring (buffer
, -1, "The macro");
12404 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
12405 the tail part of the directive line, i.e. the part which is past the
12406 initial whitespace, #, whitespace, directive-name, whitespace part. */
12409 dwarf2out_undef (lineno
, buffer
)
12410 unsigned lineno ATTRIBUTE_UNUSED
;
12411 const char *buffer ATTRIBUTE_UNUSED
;
12413 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12415 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12416 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
12417 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
12418 dw2_asm_output_nstring (buffer
, -1, "The macro");
12422 /* Set up for Dwarf output at the start of compilation. */
12425 dwarf2out_init (main_input_filename
)
12426 const char *main_input_filename
;
12428 init_file_table ();
12430 /* Add the name of the primary input file to the file table first,
12431 under the assumption that we'll be emitting line number data for
12432 it first, which avoids having to add an initial DW_LNS_set_file. */
12433 lookup_filename (main_input_filename
);
12435 /* Allocate the initial hunk of the decl_die_table. */
12437 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
12438 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
12439 decl_die_table_in_use
= 0;
12441 /* Allocate the initial hunk of the decl_scope_table. */
12442 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
12444 /* Allocate the initial hunk of the abbrev_die_table. */
12446 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
12447 sizeof (dw_die_ref
));
12448 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
12449 /* Zero-th entry is allocated, but unused */
12450 abbrev_die_table_in_use
= 1;
12452 /* Allocate the initial hunk of the line_info_table. */
12454 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
12455 sizeof (dw_line_info_entry
));
12456 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12458 /* Zero-th entry is allocated, but unused */
12459 line_info_table_in_use
= 1;
12461 /* Generate the initial DIE for the .debug section. Note that the (string)
12462 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12463 will (typically) be a relative pathname and that this pathname should be
12464 taken as being relative to the directory from which the compiler was
12465 invoked when the given (base) source file was compiled. */
12466 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
12467 is_main_source
= 1;
12469 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12471 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12473 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
12475 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12476 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12477 DEBUG_ABBREV_SECTION_LABEL
, 0);
12478 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12479 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12481 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12483 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12484 DEBUG_INFO_SECTION_LABEL
, 0);
12485 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12486 DEBUG_LINE_SECTION_LABEL
, 0);
12487 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12488 DEBUG_RANGES_SECTION_LABEL
, 0);
12489 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12490 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12491 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12492 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12493 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12494 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12496 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12498 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12499 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12500 DEBUG_MACINFO_SECTION_LABEL
, 0);
12501 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12504 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12507 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12511 /* Allocate a string in .debug_str hash table. */
12514 indirect_string_alloc (tab
)
12515 hash_table
*tab ATTRIBUTE_UNUSED
;
12517 struct indirect_string_node
*node
;
12519 node
= xmalloc (sizeof (struct indirect_string_node
));
12520 node
->refcount
= 0;
12522 node
->label
= NULL
;
12524 return (hashnode
) node
;
12527 /* A helper function for dwarf2out_finish called through
12528 ht_forall. Emit one queued .debug_str string. */
12531 output_indirect_string (pfile
, h
, v
)
12532 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12534 const PTR v ATTRIBUTE_UNUSED
;
12536 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12538 if (node
->form
== DW_FORM_strp
)
12540 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12541 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12542 assemble_string ((const char *) HT_STR (&node
->id
),
12543 HT_LEN (&node
->id
) + 1);
12549 /* Output stuff that dwarf requires at the end of every file,
12550 and generate the DWARF-2 debugging info. */
12553 dwarf2out_finish (input_filename
)
12554 const char *input_filename ATTRIBUTE_UNUSED
;
12556 limbo_die_node
*node
, *next_node
;
12557 dw_die_ref die
= 0;
12559 /* Traverse the limbo die list, and add parent/child links. The only
12560 dies without parents that should be here are concrete instances of
12561 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12562 For concrete instances, we can get the parent die from the abstract
12564 for (node
= limbo_die_list
; node
; node
= next_node
)
12566 next_node
= node
->next
;
12569 if (die
->die_parent
== NULL
)
12571 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12575 add_child_die (origin
->die_parent
, die
);
12576 else if (die
== comp_unit_die
)
12578 /* If this was an expression for a bound involved in a function
12579 return type, it may be a SAVE_EXPR for which we weren't able
12580 to find a DIE previously. So try now. */
12581 else if (node
->created_for
12582 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12583 && 0 != (origin
= (lookup_decl_die
12585 (node
->created_for
)))))
12586 add_child_die (origin
, die
);
12587 else if (errorcount
> 0 || sorrycount
> 0)
12588 /* It's OK to be confused by errors in the input. */
12589 add_child_die (comp_unit_die
, die
);
12590 else if (node
->created_for
12591 && ((DECL_P (node
->created_for
)
12592 && (context
= DECL_CONTEXT (node
->created_for
)))
12593 || (TYPE_P (node
->created_for
)
12594 && (context
= TYPE_CONTEXT (node
->created_for
))))
12595 && TREE_CODE (context
) == FUNCTION_DECL
)
12597 /* In certain situations, the lexical block containing a
12598 nested function can be optimized away, which results
12599 in the nested function die being orphaned. Likewise
12600 with the return type of that nested function. Force
12601 this to be a child of the containing function. */
12602 origin
= lookup_decl_die (context
);
12605 add_child_die (origin
, die
);
12614 limbo_die_list
= NULL
;
12616 /* Walk through the list of incomplete types again, trying once more to
12617 emit full debugging info for them. */
12618 retry_incomplete_types ();
12620 /* We need to reverse all the dies before break_out_includes, or
12621 we'll see the end of an include file before the beginning. */
12622 reverse_all_dies (comp_unit_die
);
12624 /* Generate separate CUs for each of the include files we've seen.
12625 They will go into limbo_die_list. */
12626 if (flag_eliminate_dwarf2_dups
)
12627 break_out_includes (comp_unit_die
);
12629 /* Traverse the DIE's and add add sibling attributes to those DIE's
12630 that have children. */
12631 add_sibling_attributes (comp_unit_die
);
12632 for (node
= limbo_die_list
; node
; node
= node
->next
)
12633 add_sibling_attributes (node
->die
);
12635 /* Output a terminator label for the .text section. */
12637 (*targetm
.asm_out
.internal_label
) (asm_out_file
, TEXT_END_LABEL
, 0);
12639 /* Output the source line correspondence table. We must do this
12640 even if there is no line information. Otherwise, on an empty
12641 translation unit, we will generate a present, but empty,
12642 .debug_info section. IRIX 6.5 `nm' will then complain when
12643 examining the file. */
12644 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12646 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12647 output_line_info ();
12650 /* Output location list section if necessary. */
12651 if (have_location_lists
)
12653 /* Output the location lists info. */
12654 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12655 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12656 DEBUG_LOC_SECTION_LABEL
, 0);
12657 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12658 output_location_lists (die
);
12659 have_location_lists
= 0;
12662 /* We can only use the low/high_pc attributes if all of the code was
12664 if (separate_line_info_table_in_use
== 0)
12666 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12667 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12670 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12671 "base address". Use zero so that these addresses become absolute. */
12672 else if (have_location_lists
|| ranges_table_in_use
)
12673 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12675 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12676 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12677 debug_line_section_label
);
12679 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12680 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12682 /* Output all of the compilation units. We put the main one last so that
12683 the offsets are available to output_pubnames. */
12684 for (node
= limbo_die_list
; node
; node
= node
->next
)
12685 output_comp_unit (node
->die
, 0);
12687 output_comp_unit (comp_unit_die
, 0);
12689 /* Output the abbreviation table. */
12690 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12691 output_abbrev_section ();
12693 /* Output public names table if necessary. */
12694 if (pubname_table_in_use
)
12696 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12697 output_pubnames ();
12700 /* Output the address range information. We only put functions in the arange
12701 table, so don't write it out if we don't have any. */
12702 if (fde_table_in_use
)
12704 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12708 /* Output ranges section if necessary. */
12709 if (ranges_table_in_use
)
12711 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12712 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12716 /* Have to end the primary source file. */
12717 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12719 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12720 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12721 dw2_asm_output_data (1, 0, "End compilation unit");
12724 /* If we emitted any DW_FORM_strp form attribute, output the string
12726 if (debug_str_hash
)
12727 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12731 /* This should never be used, but its address is needed for comparisons. */
12732 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12734 #endif /* DWARF2_DEBUGGING_INFO */
12736 #include "gt-dwarf2out.h"