1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
43 #include "hard-reg-set.h"
45 #include "insn-config.h"
53 #include "dwarf2out.h"
54 #include "dwarf2asm.h"
60 #include "diagnostic.h"
63 #include "langhooks.h"
64 #include "hashtable.h"
67 #ifdef DWARF2_DEBUGGING_INFO
68 static void dwarf2out_source_line
PARAMS ((unsigned int, const char *));
71 /* DWARF2 Abbreviation Glossary:
72 CFA = Canonical Frame Address
73 a fixed address on the stack which identifies a call frame.
74 We define it to be the value of SP just before the call insn.
75 The CFA register and offset, which may change during the course
76 of the function, are used to calculate its value at runtime.
77 CFI = Call Frame Instruction
78 an instruction for the DWARF2 abstract machine
79 CIE = Common Information Entry
80 information describing information common to one or more FDEs
81 DIE = Debugging Information Entry
82 FDE = Frame Description Entry
83 information describing the stack call frame, in particular,
84 how to restore registers
86 DW_CFA_... = DWARF2 CFA call frame instruction
87 DW_TAG_... = DWARF2 DIE tag */
89 /* Decide whether we want to emit frame unwind information for the current
95 return (write_symbols
== DWARF2_DEBUG
96 || write_symbols
== VMS_AND_DWARF2_DEBUG
97 #ifdef DWARF2_FRAME_INFO
100 #ifdef DWARF2_UNWIND_INFO
101 || flag_unwind_tables
102 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
107 /* The size of the target's pointer type. */
109 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
112 /* Default version of targetm.eh_frame_section. Note this must appear
113 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
117 default_eh_frame_section ()
119 #ifdef EH_FRAME_SECTION_NAME
120 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
121 int fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
122 int per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
123 int lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
127 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
128 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
129 && (per_encoding
& 0x70) != DW_EH_PE_absptr
130 && (per_encoding
& 0x70) != DW_EH_PE_aligned
131 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
132 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
134 named_section_flags (EH_FRAME_SECTION_NAME
, flags
);
136 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
139 tree label
= get_file_function_name ('F');
142 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
143 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, IDENTIFIER_POINTER (label
));
144 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
148 /* Array of RTXes referenced by the debugging information, which therefore
149 must be kept around forever. */
150 static GTY(()) varray_type used_rtx_varray
;
152 /* A pointer to the base of a list of incomplete types which might be
153 completed at some later time. incomplete_types_list needs to be a VARRAY
154 because we want to tell the garbage collector about it. */
155 static GTY(()) varray_type incomplete_types
;
157 /* A pointer to the base of a table of references to declaration
158 scopes. This table is a display which tracks the nesting
159 of declaration scopes at the current scope and containing
160 scopes. This table is used to find the proper place to
161 define type declaration DIE's. */
162 static GTY(()) varray_type decl_scope_table
;
164 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
166 /* How to start an assembler comment. */
167 #ifndef ASM_COMMENT_START
168 #define ASM_COMMENT_START ";#"
171 typedef struct dw_cfi_struct
*dw_cfi_ref
;
172 typedef struct dw_fde_struct
*dw_fde_ref
;
173 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
175 /* Call frames are described using a sequence of Call Frame
176 Information instructions. The register number, offset
177 and address fields are provided as possible operands;
178 their use is selected by the opcode field. */
180 typedef union dw_cfi_oprnd_struct
182 unsigned long dw_cfi_reg_num
;
183 long int dw_cfi_offset
;
184 const char *dw_cfi_addr
;
185 struct dw_loc_descr_struct
*dw_cfi_loc
;
189 typedef struct dw_cfi_struct
191 dw_cfi_ref dw_cfi_next
;
192 enum dwarf_call_frame_info dw_cfi_opc
;
193 dw_cfi_oprnd dw_cfi_oprnd1
;
194 dw_cfi_oprnd dw_cfi_oprnd2
;
198 /* This is how we define the location of the CFA. We use to handle it
199 as REG + OFFSET all the time, but now it can be more complex.
200 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
201 Instead of passing around REG and OFFSET, we pass a copy
202 of this structure. */
203 typedef struct cfa_loc
208 int indirect
; /* 1 if CFA is accessed via a dereference. */
211 /* All call frame descriptions (FDE's) in the GCC generated DWARF
212 refer to a single Common Information Entry (CIE), defined at
213 the beginning of the .debug_frame section. This use of a single
214 CIE obviates the need to keep track of multiple CIE's
215 in the DWARF generation routines below. */
217 typedef struct dw_fde_struct
219 const char *dw_fde_begin
;
220 const char *dw_fde_current_label
;
221 const char *dw_fde_end
;
222 dw_cfi_ref dw_fde_cfi
;
223 unsigned funcdef_number
;
224 unsigned all_throwers_are_sibcalls
: 1;
225 unsigned nothrow
: 1;
226 unsigned uses_eh_lsda
: 1;
230 /* Maximum size (in bytes) of an artificially generated label. */
231 #define MAX_ARTIFICIAL_LABEL_BYTES 30
233 /* The size of addresses as they appear in the Dwarf 2 data.
234 Some architectures use word addresses to refer to code locations,
235 but Dwarf 2 info always uses byte addresses. On such machines,
236 Dwarf 2 addresses need to be larger than the architecture's
238 #ifndef DWARF2_ADDR_SIZE
239 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
242 /* The size in bytes of a DWARF field indicating an offset or length
243 relative to a debug info section, specified to be 4 bytes in the
244 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
247 #ifndef DWARF_OFFSET_SIZE
248 #define DWARF_OFFSET_SIZE 4
251 #define DWARF_VERSION 2
253 /* Round SIZE up to the nearest BOUNDARY. */
254 #define DWARF_ROUND(SIZE,BOUNDARY) \
255 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
257 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
258 #ifndef DWARF_CIE_DATA_ALIGNMENT
259 #ifdef STACK_GROWS_DOWNWARD
260 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
262 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
266 /* A pointer to the base of a table that contains frame description
267 information for each routine. */
268 static dw_fde_ref fde_table
;
270 /* Number of elements currently allocated for fde_table. */
271 static unsigned fde_table_allocated
;
273 /* Number of elements in fde_table currently in use. */
274 static unsigned fde_table_in_use
;
276 /* Size (in elements) of increments by which we may expand the
278 #define FDE_TABLE_INCREMENT 256
280 /* A list of call frame insns for the CIE. */
281 static dw_cfi_ref cie_cfi_head
;
283 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
284 attribute that accelerates the lookup of the FDE associated
285 with the subprogram. This variable holds the table index of the FDE
286 associated with the current function (body) definition. */
287 static unsigned current_funcdef_fde
;
289 struct ht
*debug_str_hash
;
291 struct indirect_string_node
293 struct ht_identifier id
;
294 unsigned int refcount
;
299 /* Forward declarations for functions defined in this file. */
301 static char *stripattributes
PARAMS ((const char *));
302 static const char *dwarf_cfi_name
PARAMS ((unsigned));
303 static dw_cfi_ref new_cfi
PARAMS ((void));
304 static void add_cfi
PARAMS ((dw_cfi_ref
*, dw_cfi_ref
));
305 static void add_fde_cfi
PARAMS ((const char *, dw_cfi_ref
));
306 static void lookup_cfa_1
PARAMS ((dw_cfi_ref
,
308 static void lookup_cfa
PARAMS ((dw_cfa_location
*));
309 static void reg_save
PARAMS ((const char *, unsigned,
311 static void initial_return_save
PARAMS ((rtx
));
312 static long stack_adjust_offset
PARAMS ((rtx
));
313 static void output_cfi
PARAMS ((dw_cfi_ref
, dw_fde_ref
, int));
314 static void output_call_frame_info
PARAMS ((int));
315 static void dwarf2out_stack_adjust
PARAMS ((rtx
));
316 static void queue_reg_save
PARAMS ((const char *, rtx
, long));
317 static void flush_queued_reg_saves
PARAMS ((void));
318 static bool clobbers_queued_reg_save
PARAMS ((rtx
));
319 static void dwarf2out_frame_debug_expr
PARAMS ((rtx
, const char *));
321 /* Support for complex CFA locations. */
322 static void output_cfa_loc
PARAMS ((dw_cfi_ref
));
323 static void get_cfa_from_loc_descr
PARAMS ((dw_cfa_location
*,
324 struct dw_loc_descr_struct
*));
325 static struct dw_loc_descr_struct
*build_cfa_loc
326 PARAMS ((dw_cfa_location
*));
327 static void def_cfa_1
PARAMS ((const char *,
330 /* How to start an assembler comment. */
331 #ifndef ASM_COMMENT_START
332 #define ASM_COMMENT_START ";#"
335 /* Data and reference forms for relocatable data. */
336 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
337 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
339 #ifndef DEBUG_FRAME_SECTION
340 #define DEBUG_FRAME_SECTION ".debug_frame"
343 #ifndef FUNC_BEGIN_LABEL
344 #define FUNC_BEGIN_LABEL "LFB"
347 #ifndef FUNC_END_LABEL
348 #define FUNC_END_LABEL "LFE"
351 #define FRAME_BEGIN_LABEL "Lframe"
352 #define CIE_AFTER_SIZE_LABEL "LSCIE"
353 #define CIE_END_LABEL "LECIE"
354 #define FDE_LABEL "LSFDE"
355 #define FDE_AFTER_SIZE_LABEL "LASFDE"
356 #define FDE_END_LABEL "LEFDE"
357 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
358 #define LINE_NUMBER_END_LABEL "LELT"
359 #define LN_PROLOG_AS_LABEL "LASLTP"
360 #define LN_PROLOG_END_LABEL "LELTP"
361 #define DIE_LABEL_PREFIX "DW"
363 /* The DWARF 2 CFA column which tracks the return address. Normally this
364 is the column for PC, or the first column after all of the hard
366 #ifndef DWARF_FRAME_RETURN_COLUMN
368 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
370 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
374 /* The mapping from gcc register number to DWARF 2 CFA column number. By
375 default, we just provide columns for all registers. */
376 #ifndef DWARF_FRAME_REGNUM
377 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
380 /* The offset from the incoming value of %sp to the top of the stack frame
381 for the current function. */
382 #ifndef INCOMING_FRAME_SP_OFFSET
383 #define INCOMING_FRAME_SP_OFFSET 0
386 /* Hook used by __throw. */
389 expand_builtin_dwarf_fp_regnum ()
391 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
));
394 /* Return a pointer to a copy of the section string name S with all
395 attributes stripped off, and an asterisk prepended (for assemble_name). */
401 char *stripped
= xmalloc (strlen (s
) + 2);
406 while (*s
&& *s
!= ',')
413 /* Generate code to initialize the register size table. */
416 expand_builtin_init_dwarf_reg_sizes (address
)
420 enum machine_mode mode
= TYPE_MODE (char_type_node
);
421 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
422 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
424 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
425 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
427 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
428 HOST_WIDE_INT size
= GET_MODE_SIZE (reg_raw_mode
[i
]);
433 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
437 /* Convert a DWARF call frame info. operation to its string name */
440 dwarf_cfi_name (cfi_opc
)
445 case DW_CFA_advance_loc
:
446 return "DW_CFA_advance_loc";
448 return "DW_CFA_offset";
450 return "DW_CFA_restore";
454 return "DW_CFA_set_loc";
455 case DW_CFA_advance_loc1
:
456 return "DW_CFA_advance_loc1";
457 case DW_CFA_advance_loc2
:
458 return "DW_CFA_advance_loc2";
459 case DW_CFA_advance_loc4
:
460 return "DW_CFA_advance_loc4";
461 case DW_CFA_offset_extended
:
462 return "DW_CFA_offset_extended";
463 case DW_CFA_restore_extended
:
464 return "DW_CFA_restore_extended";
465 case DW_CFA_undefined
:
466 return "DW_CFA_undefined";
467 case DW_CFA_same_value
:
468 return "DW_CFA_same_value";
469 case DW_CFA_register
:
470 return "DW_CFA_register";
471 case DW_CFA_remember_state
:
472 return "DW_CFA_remember_state";
473 case DW_CFA_restore_state
:
474 return "DW_CFA_restore_state";
476 return "DW_CFA_def_cfa";
477 case DW_CFA_def_cfa_register
:
478 return "DW_CFA_def_cfa_register";
479 case DW_CFA_def_cfa_offset
:
480 return "DW_CFA_def_cfa_offset";
483 case DW_CFA_def_cfa_expression
:
484 return "DW_CFA_def_cfa_expression";
485 case DW_CFA_expression
:
486 return "DW_CFA_expression";
487 case DW_CFA_offset_extended_sf
:
488 return "DW_CFA_offset_extended_sf";
489 case DW_CFA_def_cfa_sf
:
490 return "DW_CFA_def_cfa_sf";
491 case DW_CFA_def_cfa_offset_sf
:
492 return "DW_CFA_def_cfa_offset_sf";
494 /* SGI/MIPS specific */
495 case DW_CFA_MIPS_advance_loc8
:
496 return "DW_CFA_MIPS_advance_loc8";
499 case DW_CFA_GNU_window_save
:
500 return "DW_CFA_GNU_window_save";
501 case DW_CFA_GNU_args_size
:
502 return "DW_CFA_GNU_args_size";
503 case DW_CFA_GNU_negative_offset_extended
:
504 return "DW_CFA_GNU_negative_offset_extended";
507 return "DW_CFA_<unknown>";
511 /* Return a pointer to a newly allocated Call Frame Instruction. */
513 static inline dw_cfi_ref
516 dw_cfi_ref cfi
= (dw_cfi_ref
) xmalloc (sizeof (dw_cfi_node
));
518 cfi
->dw_cfi_next
= NULL
;
519 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
520 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
525 /* Add a Call Frame Instruction to list of instructions. */
528 add_cfi (list_head
, cfi
)
529 dw_cfi_ref
*list_head
;
534 /* Find the end of the chain. */
535 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
541 /* Generate a new label for the CFI info to refer to. */
544 dwarf2out_cfi_label ()
546 static char label
[20];
547 static unsigned long label_num
= 0;
549 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", label_num
++);
550 ASM_OUTPUT_LABEL (asm_out_file
, label
);
554 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
555 or to the CIE if LABEL is NULL. */
558 add_fde_cfi (label
, cfi
)
564 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
567 label
= dwarf2out_cfi_label ();
569 if (fde
->dw_fde_current_label
== NULL
570 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
574 fde
->dw_fde_current_label
= label
= xstrdup (label
);
576 /* Set the location counter to the new label. */
578 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
579 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
580 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
583 add_cfi (&fde
->dw_fde_cfi
, cfi
);
587 add_cfi (&cie_cfi_head
, cfi
);
590 /* Subroutine of lookup_cfa. */
593 lookup_cfa_1 (cfi
, loc
)
595 dw_cfa_location
*loc
;
597 switch (cfi
->dw_cfi_opc
)
599 case DW_CFA_def_cfa_offset
:
600 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
602 case DW_CFA_def_cfa_register
:
603 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
606 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
607 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
609 case DW_CFA_def_cfa_expression
:
610 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
617 /* Find the previous value for the CFA. */
621 dw_cfa_location
*loc
;
625 loc
->reg
= (unsigned long) -1;
628 loc
->base_offset
= 0;
630 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
631 lookup_cfa_1 (cfi
, loc
);
633 if (fde_table_in_use
)
635 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
636 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
637 lookup_cfa_1 (cfi
, loc
);
641 /* The current rule for calculating the DWARF2 canonical frame address. */
642 static dw_cfa_location cfa
;
644 /* The register used for saving registers to the stack, and its offset
646 static dw_cfa_location cfa_store
;
648 /* The running total of the size of arguments pushed onto the stack. */
649 static long args_size
;
651 /* The last args_size we actually output. */
652 static long old_args_size
;
654 /* Entry point to update the canonical frame address (CFA).
655 LABEL is passed to add_fde_cfi. The value of CFA is now to be
656 calculated from REG+OFFSET. */
659 dwarf2out_def_cfa (label
, reg
, offset
)
669 def_cfa_1 (label
, &loc
);
672 /* This routine does the actual work. The CFA is now calculated from
673 the dw_cfa_location structure. */
676 def_cfa_1 (label
, loc_p
)
678 dw_cfa_location
*loc_p
;
681 dw_cfa_location old_cfa
, loc
;
686 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
687 cfa_store
.offset
= loc
.offset
;
689 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
690 lookup_cfa (&old_cfa
);
692 /* If nothing changed, no need to issue any call frame instructions. */
693 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
694 && loc
.indirect
== old_cfa
.indirect
695 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
700 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
702 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
703 indicating the CFA register did not change but the offset
705 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
706 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
709 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
710 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
713 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
714 indicating the CFA register has changed to <register> but the
715 offset has not changed. */
716 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
717 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
721 else if (loc
.indirect
== 0)
723 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
724 indicating the CFA register has changed to <register> with
725 the specified offset. */
726 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
727 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
728 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
732 /* Construct a DW_CFA_def_cfa_expression instruction to
733 calculate the CFA using a full location expression since no
734 register-offset pair is available. */
735 struct dw_loc_descr_struct
*loc_list
;
737 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
738 loc_list
= build_cfa_loc (&loc
);
739 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
742 add_fde_cfi (label
, cfi
);
745 /* Add the CFI for saving a register. REG is the CFA column number.
746 LABEL is passed to add_fde_cfi.
747 If SREG is -1, the register is saved at OFFSET from the CFA;
748 otherwise it is saved in SREG. */
751 reg_save (label
, reg
, sreg
, offset
)
757 dw_cfi_ref cfi
= new_cfi ();
759 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
761 /* The following comparison is correct. -1 is used to indicate that
762 the value isn't a register number. */
763 if (sreg
== (unsigned int) -1)
766 /* The register number won't fit in 6 bits, so we have to use
768 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
770 cfi
->dw_cfi_opc
= DW_CFA_offset
;
772 #ifdef ENABLE_CHECKING
774 /* If we get an offset that is not a multiple of
775 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
776 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
778 long check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
780 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
784 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
786 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
788 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
790 else if (sreg
== reg
)
791 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
795 cfi
->dw_cfi_opc
= DW_CFA_register
;
796 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
799 add_fde_cfi (label
, cfi
);
802 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
803 This CFI tells the unwinder that it needs to restore the window registers
804 from the previous frame's window save area.
806 ??? Perhaps we should note in the CIE where windows are saved (instead of
807 assuming 0(cfa)) and what registers are in the window. */
810 dwarf2out_window_save (label
)
813 dw_cfi_ref cfi
= new_cfi ();
815 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
816 add_fde_cfi (label
, cfi
);
819 /* Add a CFI to update the running total of the size of arguments
820 pushed onto the stack. */
823 dwarf2out_args_size (label
, size
)
829 if (size
== old_args_size
)
832 old_args_size
= size
;
835 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
836 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
837 add_fde_cfi (label
, cfi
);
840 /* Entry point for saving a register to the stack. REG is the GCC register
841 number. LABEL and OFFSET are passed to reg_save. */
844 dwarf2out_reg_save (label
, reg
, offset
)
849 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
852 /* Entry point for saving the return address in the stack.
853 LABEL and OFFSET are passed to reg_save. */
856 dwarf2out_return_save (label
, offset
)
860 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
863 /* Entry point for saving the return address in a register.
864 LABEL and SREG are passed to reg_save. */
867 dwarf2out_return_reg (label
, sreg
)
871 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
874 /* Record the initial position of the return address. RTL is
875 INCOMING_RETURN_ADDR_RTX. */
878 initial_return_save (rtl
)
881 unsigned int reg
= (unsigned int) -1;
882 HOST_WIDE_INT offset
= 0;
884 switch (GET_CODE (rtl
))
887 /* RA is in a register. */
888 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
892 /* RA is on the stack. */
894 switch (GET_CODE (rtl
))
897 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
903 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
905 offset
= INTVAL (XEXP (rtl
, 1));
909 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
911 offset
= -INTVAL (XEXP (rtl
, 1));
921 /* The return address is at some offset from any value we can
922 actually load. For instance, on the SPARC it is in %i7+8. Just
923 ignore the offset for now; it doesn't matter for unwinding frames. */
924 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
926 initial_return_save (XEXP (rtl
, 0));
933 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
936 /* Given a SET, calculate the amount of stack adjustment it
940 stack_adjust_offset (pattern
)
943 rtx src
= SET_SRC (pattern
);
944 rtx dest
= SET_DEST (pattern
);
945 HOST_WIDE_INT offset
= 0;
948 if (dest
== stack_pointer_rtx
)
950 /* (set (reg sp) (plus (reg sp) (const_int))) */
951 code
= GET_CODE (src
);
952 if (! (code
== PLUS
|| code
== MINUS
)
953 || XEXP (src
, 0) != stack_pointer_rtx
954 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
957 offset
= INTVAL (XEXP (src
, 1));
961 else if (GET_CODE (dest
) == MEM
)
963 /* (set (mem (pre_dec (reg sp))) (foo)) */
964 src
= XEXP (dest
, 0);
965 code
= GET_CODE (src
);
971 if (XEXP (src
, 0) == stack_pointer_rtx
)
973 rtx val
= XEXP (XEXP (src
, 1), 1);
974 /* We handle only adjustments by constant amount. */
975 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
976 GET_CODE (val
) != CONST_INT
)
978 offset
= -INTVAL (val
);
985 if (XEXP (src
, 0) == stack_pointer_rtx
)
987 offset
= GET_MODE_SIZE (GET_MODE (dest
));
994 if (XEXP (src
, 0) == stack_pointer_rtx
)
996 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1011 /* Check INSN to see if it looks like a push or a stack adjustment, and
1012 make a note of it if it does. EH uses this information to find out how
1013 much extra space it needs to pop off the stack. */
1016 dwarf2out_stack_adjust (insn
)
1019 HOST_WIDE_INT offset
;
1023 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1025 /* Extract the size of the args from the CALL rtx itself. */
1026 insn
= PATTERN (insn
);
1027 if (GET_CODE (insn
) == PARALLEL
)
1028 insn
= XVECEXP (insn
, 0, 0);
1029 if (GET_CODE (insn
) == SET
)
1030 insn
= SET_SRC (insn
);
1031 if (GET_CODE (insn
) != CALL
)
1034 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1038 /* If only calls can throw, and we have a frame pointer,
1039 save up adjustments until we see the CALL_INSN. */
1040 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1043 if (GET_CODE (insn
) == BARRIER
)
1045 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1046 the compiler will have already emitted a stack adjustment, but
1047 doesn't bother for calls to noreturn functions. */
1048 #ifdef STACK_GROWS_DOWNWARD
1049 offset
= -args_size
;
1054 else if (GET_CODE (PATTERN (insn
)) == SET
)
1055 offset
= stack_adjust_offset (PATTERN (insn
));
1056 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1057 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1059 /* There may be stack adjustments inside compound insns. Search
1061 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1062 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1063 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1071 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1072 cfa
.offset
+= offset
;
1074 #ifndef STACK_GROWS_DOWNWARD
1078 args_size
+= offset
;
1082 label
= dwarf2out_cfi_label ();
1083 def_cfa_1 (label
, &cfa
);
1084 dwarf2out_args_size (label
, args_size
);
1087 /* We delay emitting a register save until either (a) we reach the end
1088 of the prologue or (b) the register is clobbered. This clusters
1089 register saves so that there are fewer pc advances. */
1091 struct queued_reg_save
1093 struct queued_reg_save
*next
;
1098 static struct queued_reg_save
*queued_reg_saves
;
1099 static const char *last_reg_save_label
;
1102 queue_reg_save (label
, reg
, offset
)
1107 struct queued_reg_save
*q
= (struct queued_reg_save
*) xmalloc (sizeof (*q
));
1109 q
->next
= queued_reg_saves
;
1111 q
->cfa_offset
= offset
;
1112 queued_reg_saves
= q
;
1114 last_reg_save_label
= label
;
1118 flush_queued_reg_saves ()
1120 struct queued_reg_save
*q
, *next
;
1122 for (q
= queued_reg_saves
; q
; q
= next
)
1124 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1129 queued_reg_saves
= NULL
;
1130 last_reg_save_label
= NULL
;
1134 clobbers_queued_reg_save (insn
)
1137 struct queued_reg_save
*q
;
1139 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1140 if (modified_in_p (q
->reg
, insn
))
1147 /* A temporary register holding an integral value used in adjusting SP
1148 or setting up the store_reg. The "offset" field holds the integer
1149 value, not an offset. */
1150 static dw_cfa_location cfa_temp
;
1152 /* Record call frame debugging information for an expression EXPR,
1153 which either sets SP or FP (adjusting how we calculate the frame
1154 address) or saves a register to the stack. LABEL indicates the
1157 This function encodes a state machine mapping rtxes to actions on
1158 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1159 users need not read the source code.
1161 The High-Level Picture
1163 Changes in the register we use to calculate the CFA: Currently we
1164 assume that if you copy the CFA register into another register, we
1165 should take the other one as the new CFA register; this seems to
1166 work pretty well. If it's wrong for some target, it's simple
1167 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1169 Changes in the register we use for saving registers to the stack:
1170 This is usually SP, but not always. Again, we deduce that if you
1171 copy SP into another register (and SP is not the CFA register),
1172 then the new register is the one we will be using for register
1173 saves. This also seems to work.
1175 Register saves: There's not much guesswork about this one; if
1176 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1177 register save, and the register used to calculate the destination
1178 had better be the one we think we're using for this purpose.
1180 Except: If the register being saved is the CFA register, and the
1181 offset is nonzero, we are saving the CFA, so we assume we have to
1182 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1183 the intent is to save the value of SP from the previous frame.
1185 Invariants / Summaries of Rules
1187 cfa current rule for calculating the CFA. It usually
1188 consists of a register and an offset.
1189 cfa_store register used by prologue code to save things to the stack
1190 cfa_store.offset is the offset from the value of
1191 cfa_store.reg to the actual CFA
1192 cfa_temp register holding an integral value. cfa_temp.offset
1193 stores the value, which will be used to adjust the
1194 stack pointer. cfa_temp is also used like cfa_store,
1195 to track stores to the stack via fp or a temp reg.
1197 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1198 with cfa.reg as the first operand changes the cfa.reg and its
1199 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1202 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1203 expression yielding a constant. This sets cfa_temp.reg
1204 and cfa_temp.offset.
1206 Rule 5: Create a new register cfa_store used to save items to the
1209 Rules 10-14: Save a register to the stack. Define offset as the
1210 difference of the original location and cfa_store's
1211 location (or cfa_temp's location if cfa_temp is used).
1215 "{a,b}" indicates a choice of a xor b.
1216 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1219 (set <reg1> <reg2>:cfa.reg)
1220 effects: cfa.reg = <reg1>
1221 cfa.offset unchanged
1222 cfa_temp.reg = <reg1>
1223 cfa_temp.offset = cfa.offset
1226 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1227 {<const_int>,<reg>:cfa_temp.reg}))
1228 effects: cfa.reg = sp if fp used
1229 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1230 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1231 if cfa_store.reg==sp
1234 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1235 effects: cfa.reg = fp
1236 cfa_offset += +/- <const_int>
1239 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1240 constraints: <reg1> != fp
1242 effects: cfa.reg = <reg1>
1243 cfa_temp.reg = <reg1>
1244 cfa_temp.offset = cfa.offset
1247 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1248 constraints: <reg1> != fp
1250 effects: cfa_store.reg = <reg1>
1251 cfa_store.offset = cfa.offset - cfa_temp.offset
1254 (set <reg> <const_int>)
1255 effects: cfa_temp.reg = <reg>
1256 cfa_temp.offset = <const_int>
1259 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1260 effects: cfa_temp.reg = <reg1>
1261 cfa_temp.offset |= <const_int>
1264 (set <reg> (high <exp>))
1268 (set <reg> (lo_sum <exp> <const_int>))
1269 effects: cfa_temp.reg = <reg>
1270 cfa_temp.offset = <const_int>
1273 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1274 effects: cfa_store.offset -= <const_int>
1275 cfa.offset = cfa_store.offset if cfa.reg == sp
1277 cfa.base_offset = -cfa_store.offset
1280 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1281 effects: cfa_store.offset += -/+ mode_size(mem)
1282 cfa.offset = cfa_store.offset if cfa.reg == sp
1284 cfa.base_offset = -cfa_store.offset
1287 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1290 effects: cfa.reg = <reg1>
1291 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1294 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1295 effects: cfa.reg = <reg1>
1296 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1299 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1300 effects: cfa.reg = <reg1>
1301 cfa.base_offset = -cfa_temp.offset
1302 cfa_temp.offset -= mode_size(mem) */
1305 dwarf2out_frame_debug_expr (expr
, label
)
1310 HOST_WIDE_INT offset
;
1312 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1313 the PARALLEL independently. The first element is always processed if
1314 it is a SET. This is for backward compatibility. Other elements
1315 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1316 flag is set in them. */
1317 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1320 int limit
= XVECLEN (expr
, 0);
1322 for (par_index
= 0; par_index
< limit
; par_index
++)
1323 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1324 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1326 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1331 if (GET_CODE (expr
) != SET
)
1334 src
= SET_SRC (expr
);
1335 dest
= SET_DEST (expr
);
1337 switch (GET_CODE (dest
))
1341 /* Update the CFA rule wrt SP or FP. Make sure src is
1342 relative to the current CFA register. */
1343 switch (GET_CODE (src
))
1345 /* Setting FP from SP. */
1347 if (cfa
.reg
== (unsigned) REGNO (src
))
1353 /* We used to require that dest be either SP or FP, but the
1354 ARM copies SP to a temporary register, and from there to
1355 FP. So we just rely on the backends to only set
1356 RTX_FRAME_RELATED_P on appropriate insns. */
1357 cfa
.reg
= REGNO (dest
);
1358 cfa_temp
.reg
= cfa
.reg
;
1359 cfa_temp
.offset
= cfa
.offset
;
1365 if (dest
== stack_pointer_rtx
)
1369 switch (GET_CODE (XEXP (src
, 1)))
1372 offset
= INTVAL (XEXP (src
, 1));
1375 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1377 offset
= cfa_temp
.offset
;
1383 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1385 /* Restoring SP from FP in the epilogue. */
1386 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1388 cfa
.reg
= STACK_POINTER_REGNUM
;
1390 else if (GET_CODE (src
) == LO_SUM
)
1391 /* Assume we've set the source reg of the LO_SUM from sp. */
1393 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1396 if (GET_CODE (src
) != MINUS
)
1398 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1399 cfa
.offset
+= offset
;
1400 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1401 cfa_store
.offset
+= offset
;
1403 else if (dest
== hard_frame_pointer_rtx
)
1406 /* Either setting the FP from an offset of the SP,
1407 or adjusting the FP */
1408 if (! frame_pointer_needed
)
1411 if (GET_CODE (XEXP (src
, 0)) == REG
1412 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1413 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1415 offset
= INTVAL (XEXP (src
, 1));
1416 if (GET_CODE (src
) != MINUS
)
1418 cfa
.offset
+= offset
;
1419 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1426 if (GET_CODE (src
) == MINUS
)
1430 if (GET_CODE (XEXP (src
, 0)) == REG
1431 && REGNO (XEXP (src
, 0)) == cfa
.reg
1432 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1434 /* Setting a temporary CFA register that will be copied
1435 into the FP later on. */
1436 offset
= - INTVAL (XEXP (src
, 1));
1437 cfa
.offset
+= offset
;
1438 cfa
.reg
= REGNO (dest
);
1439 /* Or used to save regs to the stack. */
1440 cfa_temp
.reg
= cfa
.reg
;
1441 cfa_temp
.offset
= cfa
.offset
;
1445 else if (GET_CODE (XEXP (src
, 0)) == REG
1446 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1447 && XEXP (src
, 1) == stack_pointer_rtx
)
1449 /* Setting a scratch register that we will use instead
1450 of SP for saving registers to the stack. */
1451 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1453 cfa_store
.reg
= REGNO (dest
);
1454 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1458 else if (GET_CODE (src
) == LO_SUM
1459 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1461 cfa_temp
.reg
= REGNO (dest
);
1462 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1471 cfa_temp
.reg
= REGNO (dest
);
1472 cfa_temp
.offset
= INTVAL (src
);
1477 if (GET_CODE (XEXP (src
, 0)) != REG
1478 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1479 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1482 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1483 cfa_temp
.reg
= REGNO (dest
);
1484 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1487 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1488 which will fill in all of the bits. */
1497 def_cfa_1 (label
, &cfa
);
1501 if (GET_CODE (src
) != REG
)
1504 /* Saving a register to the stack. Make sure dest is relative to the
1506 switch (GET_CODE (XEXP (dest
, 0)))
1511 /* We can't handle variable size modifications. */
1512 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1514 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1516 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1517 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1520 cfa_store
.offset
+= offset
;
1521 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1522 cfa
.offset
= cfa_store
.offset
;
1524 offset
= -cfa_store
.offset
;
1530 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1531 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1534 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1535 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1538 cfa_store
.offset
+= offset
;
1539 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1540 cfa
.offset
= cfa_store
.offset
;
1542 offset
= -cfa_store
.offset
;
1546 /* With an offset. */
1550 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1552 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1553 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1556 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1557 offset
-= cfa_store
.offset
;
1558 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1559 offset
-= cfa_temp
.offset
;
1565 /* Without an offset. */
1567 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1568 offset
= -cfa_store
.offset
;
1569 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1570 offset
= -cfa_temp
.offset
;
1577 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1579 offset
= -cfa_temp
.offset
;
1580 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1587 if (REGNO (src
) != STACK_POINTER_REGNUM
1588 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1589 && (unsigned) REGNO (src
) == cfa
.reg
)
1591 /* We're storing the current CFA reg into the stack. */
1593 if (cfa
.offset
== 0)
1595 /* If the source register is exactly the CFA, assume
1596 we're saving SP like any other register; this happens
1598 def_cfa_1 (label
, &cfa
);
1599 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1604 /* Otherwise, we'll need to look in the stack to
1605 calculate the CFA. */
1606 rtx x
= XEXP (dest
, 0);
1608 if (GET_CODE (x
) != REG
)
1610 if (GET_CODE (x
) != REG
)
1613 cfa
.reg
= REGNO (x
);
1614 cfa
.base_offset
= offset
;
1616 def_cfa_1 (label
, &cfa
);
1621 def_cfa_1 (label
, &cfa
);
1622 queue_reg_save (label
, src
, offset
);
1630 /* Record call frame debugging information for INSN, which either
1631 sets SP or FP (adjusting how we calculate the frame address) or saves a
1632 register to the stack. If INSN is NULL_RTX, initialize our state. */
1635 dwarf2out_frame_debug (insn
)
1641 if (insn
== NULL_RTX
)
1643 /* Flush any queued register saves. */
1644 flush_queued_reg_saves ();
1646 /* Set up state for generating call frame debug info. */
1648 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1651 cfa
.reg
= STACK_POINTER_REGNUM
;
1654 cfa_temp
.offset
= 0;
1658 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1659 flush_queued_reg_saves ();
1661 if (! RTX_FRAME_RELATED_P (insn
))
1663 if (!ACCUMULATE_OUTGOING_ARGS
)
1664 dwarf2out_stack_adjust (insn
);
1669 label
= dwarf2out_cfi_label ();
1670 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1672 insn
= XEXP (src
, 0);
1674 insn
= PATTERN (insn
);
1676 dwarf2out_frame_debug_expr (insn
, label
);
1679 /* Output a Call Frame Information opcode and its operand(s). */
1682 output_cfi (cfi
, fde
, for_eh
)
1687 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1688 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1689 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1690 "DW_CFA_advance_loc 0x%lx",
1691 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1692 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1694 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1695 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1696 "DW_CFA_offset, column 0x%lx",
1697 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1698 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1700 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1701 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1702 | (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
& 0x3f)),
1703 "DW_CFA_restore, column 0x%lx",
1704 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
);
1707 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1708 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1710 switch (cfi
->dw_cfi_opc
)
1712 case DW_CFA_set_loc
:
1714 dw2_asm_output_encoded_addr_rtx (
1715 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1716 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1719 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1720 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1723 case DW_CFA_advance_loc1
:
1724 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1725 fde
->dw_fde_current_label
, NULL
);
1726 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1729 case DW_CFA_advance_loc2
:
1730 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1731 fde
->dw_fde_current_label
, NULL
);
1732 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1735 case DW_CFA_advance_loc4
:
1736 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1737 fde
->dw_fde_current_label
, NULL
);
1738 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1741 case DW_CFA_MIPS_advance_loc8
:
1742 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1743 fde
->dw_fde_current_label
, NULL
);
1744 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1747 case DW_CFA_offset_extended
:
1748 case DW_CFA_def_cfa
:
1749 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1751 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1754 case DW_CFA_offset_extended_sf
:
1755 case DW_CFA_def_cfa_sf
:
1756 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1758 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1761 case DW_CFA_restore_extended
:
1762 case DW_CFA_undefined
:
1763 case DW_CFA_same_value
:
1764 case DW_CFA_def_cfa_register
:
1765 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1769 case DW_CFA_register
:
1770 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
,
1772 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
,
1776 case DW_CFA_def_cfa_offset
:
1777 case DW_CFA_GNU_args_size
:
1778 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1781 case DW_CFA_def_cfa_offset_sf
:
1782 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1785 case DW_CFA_GNU_window_save
:
1788 case DW_CFA_def_cfa_expression
:
1789 case DW_CFA_expression
:
1790 output_cfa_loc (cfi
);
1793 case DW_CFA_GNU_negative_offset_extended
:
1794 /* Obsoleted by DW_CFA_offset_extended_sf. */
1803 /* Output the call frame information used to used to record information
1804 that relates to calculating the frame pointer, and records the
1805 location of saved registers. */
1808 output_call_frame_info (for_eh
)
1814 char l1
[20], l2
[20], section_start_label
[20];
1815 int any_lsda_needed
= 0;
1816 char augmentation
[6];
1817 int augmentation_size
;
1818 int fde_encoding
= DW_EH_PE_absptr
;
1819 int per_encoding
= DW_EH_PE_absptr
;
1820 int lsda_encoding
= DW_EH_PE_absptr
;
1822 /* Don't emit a CIE if there won't be any FDEs. */
1823 if (fde_table_in_use
== 0)
1826 /* If we don't have any functions we'll want to unwind out of, don't emit any
1827 EH unwind information. */
1830 int any_eh_needed
= flag_asynchronous_unwind_tables
;
1832 for (i
= 0; i
< fde_table_in_use
; i
++)
1833 if (fde_table
[i
].uses_eh_lsda
)
1834 any_eh_needed
= any_lsda_needed
= 1;
1835 else if (! fde_table
[i
].nothrow
)
1838 if (! any_eh_needed
)
1842 /* We're going to be generating comments, so turn on app. */
1847 (*targetm
.asm_out
.eh_frame_section
) ();
1849 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1851 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1852 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1854 /* Output the CIE. */
1855 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
1856 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
1857 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1858 "Length of Common Information Entry");
1859 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1861 /* Now that the CIE pointer is PC-relative for EH,
1862 use 0 to identify the CIE. */
1863 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
1864 (for_eh
? 0 : DW_CIE_ID
),
1865 "CIE Identifier Tag");
1867 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
1869 augmentation
[0] = 0;
1870 augmentation_size
= 0;
1876 z Indicates that a uleb128 is present to size the
1877 augmentation section.
1878 L Indicates the encoding (and thus presence) of
1879 an LSDA pointer in the FDE augmentation.
1880 R Indicates a non-default pointer encoding for
1882 P Indicates the presence of an encoding + language
1883 personality routine in the CIE augmentation. */
1885 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1886 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1887 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1889 p
= augmentation
+ 1;
1890 if (eh_personality_libfunc
)
1893 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
1895 if (any_lsda_needed
)
1898 augmentation_size
+= 1;
1900 if (fde_encoding
!= DW_EH_PE_absptr
)
1903 augmentation_size
+= 1;
1905 if (p
> augmentation
+ 1)
1907 augmentation
[0] = 'z';
1911 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1912 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
1914 int offset
= ( 4 /* Length */
1916 + 1 /* CIE version */
1917 + strlen (augmentation
) + 1 /* Augmentation */
1918 + size_of_uleb128 (1) /* Code alignment */
1919 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
1921 + 1 /* Augmentation size */
1922 + 1 /* Personality encoding */ );
1923 int pad
= -offset
& (PTR_SIZE
- 1);
1925 augmentation_size
+= pad
;
1927 /* Augmentations should be small, so there's scarce need to
1928 iterate for a solution. Die if we exceed one uleb128 byte. */
1929 if (size_of_uleb128 (augmentation_size
) != 1)
1934 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
1935 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1936 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
1937 "CIE Data Alignment Factor");
1938 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
1940 if (augmentation
[0])
1942 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
1943 if (eh_personality_libfunc
)
1945 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
1946 eh_data_format_name (per_encoding
));
1947 dw2_asm_output_encoded_addr_rtx (per_encoding
,
1948 eh_personality_libfunc
, NULL
);
1951 if (any_lsda_needed
)
1952 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
1953 eh_data_format_name (lsda_encoding
));
1955 if (fde_encoding
!= DW_EH_PE_absptr
)
1956 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
1957 eh_data_format_name (fde_encoding
));
1960 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
1961 output_cfi (cfi
, NULL
, for_eh
);
1963 /* Pad the CIE out to an address sized boundary. */
1964 ASM_OUTPUT_ALIGN (asm_out_file
,
1965 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
1966 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
1968 /* Loop through all of the FDE's. */
1969 for (i
= 0; i
< fde_table_in_use
; i
++)
1971 fde
= &fde_table
[i
];
1973 /* Don't emit EH unwind info for leaf functions that don't need it. */
1974 if (!flag_asynchronous_unwind_tables
&& for_eh
1975 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
1976 && !fde
->uses_eh_lsda
)
1979 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
1980 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
1981 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
1982 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
1984 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
1987 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
1989 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
1994 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
1995 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
1996 "FDE initial location");
1997 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
1998 fde
->dw_fde_end
, fde
->dw_fde_begin
,
1999 "FDE address range");
2003 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2004 "FDE initial location");
2005 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2006 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2007 "FDE address range");
2010 if (augmentation
[0])
2012 if (any_lsda_needed
)
2014 int size
= size_of_encoded_value (lsda_encoding
);
2016 if (lsda_encoding
== DW_EH_PE_aligned
)
2018 int offset
= ( 4 /* Length */
2019 + 4 /* CIE offset */
2020 + 2 * size_of_encoded_value (fde_encoding
)
2021 + 1 /* Augmentation size */ );
2022 int pad
= -offset
& (PTR_SIZE
- 1);
2025 if (size_of_uleb128 (size
) != 1)
2029 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2031 if (fde
->uses_eh_lsda
)
2033 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2034 fde
->funcdef_number
);
2035 dw2_asm_output_encoded_addr_rtx (
2036 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2037 "Language Specific Data Area");
2041 if (lsda_encoding
== DW_EH_PE_aligned
)
2042 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2044 (size_of_encoded_value (lsda_encoding
), 0,
2045 "Language Specific Data Area (none)");
2049 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2052 /* Loop through the Call Frame Instructions associated with
2054 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2055 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2056 output_cfi (cfi
, fde
, for_eh
);
2058 /* Pad the FDE out to an address sized boundary. */
2059 ASM_OUTPUT_ALIGN (asm_out_file
,
2060 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2061 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2064 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2065 dw2_asm_output_data (4, 0, "End of Table");
2066 #ifdef MIPS_DEBUGGING_INFO
2067 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2068 get a value of 0. Putting .align 0 after the label fixes it. */
2069 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2072 /* Turn off app to make assembly quicker. */
2077 /* Output a marker (i.e. a label) for the beginning of a function, before
2081 dwarf2out_begin_prologue (line
, file
)
2082 unsigned int line ATTRIBUTE_UNUSED
;
2083 const char *file ATTRIBUTE_UNUSED
;
2085 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2088 current_function_func_begin_label
= 0;
2090 #ifdef IA64_UNWIND_INFO
2091 /* ??? current_function_func_begin_label is also used by except.c
2092 for call-site information. We must emit this label if it might
2094 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2095 && ! dwarf2out_do_frame ())
2098 if (! dwarf2out_do_frame ())
2102 function_section (current_function_decl
);
2103 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2104 current_function_funcdef_no
);
2105 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2106 current_function_funcdef_no
);
2107 current_function_func_begin_label
= get_identifier (label
);
2109 #ifdef IA64_UNWIND_INFO
2110 /* We can elide the fde allocation if we're not emitting debug info. */
2111 if (! dwarf2out_do_frame ())
2115 /* Expand the fde table if necessary. */
2116 if (fde_table_in_use
== fde_table_allocated
)
2118 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2120 = (dw_fde_ref
) xrealloc (fde_table
,
2121 fde_table_allocated
* sizeof (dw_fde_node
));
2124 /* Record the FDE associated with this function. */
2125 current_funcdef_fde
= fde_table_in_use
;
2127 /* Add the new FDE at the end of the fde_table. */
2128 fde
= &fde_table
[fde_table_in_use
++];
2129 fde
->dw_fde_begin
= xstrdup (label
);
2130 fde
->dw_fde_current_label
= NULL
;
2131 fde
->dw_fde_end
= NULL
;
2132 fde
->dw_fde_cfi
= NULL
;
2133 fde
->funcdef_number
= current_function_funcdef_no
;
2134 fde
->nothrow
= current_function_nothrow
;
2135 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2136 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2138 args_size
= old_args_size
= 0;
2140 /* We only want to output line number information for the genuine dwarf2
2141 prologue case, not the eh frame case. */
2142 #ifdef DWARF2_DEBUGGING_INFO
2144 dwarf2out_source_line (line
, file
);
2148 /* Output a marker (i.e. a label) for the absolute end of the generated code
2149 for a function definition. This gets called *after* the epilogue code has
2153 dwarf2out_end_epilogue (line
, file
)
2154 unsigned int line ATTRIBUTE_UNUSED
;
2155 const char *file ATTRIBUTE_UNUSED
;
2158 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2160 /* Output a label to mark the endpoint of the code generated for this
2162 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2163 current_function_funcdef_no
);
2164 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2165 fde
= &fde_table
[fde_table_in_use
- 1];
2166 fde
->dw_fde_end
= xstrdup (label
);
2170 dwarf2out_frame_init ()
2172 /* Allocate the initial hunk of the fde_table. */
2173 fde_table
= (dw_fde_ref
) xcalloc (FDE_TABLE_INCREMENT
, sizeof (dw_fde_node
));
2174 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2175 fde_table_in_use
= 0;
2177 /* Generate the CFA instructions common to all FDE's. Do it now for the
2178 sake of lookup_cfa. */
2180 #ifdef DWARF2_UNWIND_INFO
2181 /* On entry, the Canonical Frame Address is at SP. */
2182 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2183 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2188 dwarf2out_frame_finish ()
2190 /* Output call frame information. */
2191 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2192 output_call_frame_info (0);
2194 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2195 output_call_frame_info (1);
2198 /* And now, the subset of the debugging information support code necessary
2199 for emitting location expressions. */
2201 /* We need some way to distinguish DW_OP_addr with a direct symbol
2202 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2203 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2206 typedef struct dw_val_struct
*dw_val_ref
;
2207 typedef struct die_struct
*dw_die_ref
;
2208 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2209 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2211 /* Each DIE may have a series of attribute/value pairs. Values
2212 can take on several forms. The forms that are used in this
2213 implementation are listed below. */
2218 dw_val_class_offset
,
2220 dw_val_class_loc_list
,
2221 dw_val_class_range_list
,
2223 dw_val_class_unsigned_const
,
2224 dw_val_class_long_long
,
2227 dw_val_class_die_ref
,
2228 dw_val_class_fde_ref
,
2229 dw_val_class_lbl_id
,
2230 dw_val_class_lbl_offset
,
2235 /* Describe a double word constant value. */
2236 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2238 typedef struct dw_long_long_struct
2245 /* Describe a floating point constant value. */
2247 typedef struct dw_fp_struct
2254 /* The dw_val_node describes an attribute's value, as it is
2255 represented internally. */
2257 typedef struct dw_val_struct
2259 dw_val_class val_class
;
2263 long unsigned val_offset
;
2264 dw_loc_list_ref val_loc_list
;
2265 dw_loc_descr_ref val_loc
;
2267 long unsigned val_unsigned
;
2268 dw_long_long_const val_long_long
;
2269 dw_float_const val_float
;
2275 unsigned val_fde_index
;
2276 struct indirect_string_node
*val_str
;
2278 unsigned char val_flag
;
2284 /* Locations in memory are described using a sequence of stack machine
2287 typedef struct dw_loc_descr_struct
2289 dw_loc_descr_ref dw_loc_next
;
2290 enum dwarf_location_atom dw_loc_opc
;
2291 dw_val_node dw_loc_oprnd1
;
2292 dw_val_node dw_loc_oprnd2
;
2297 /* Location lists are ranges + location descriptions for that range,
2298 so you can track variables that are in different places over
2299 their entire life. */
2300 typedef struct dw_loc_list_struct
2302 dw_loc_list_ref dw_loc_next
;
2303 const char *begin
; /* Label for begin address of range */
2304 const char *end
; /* Label for end address of range */
2305 char *ll_symbol
; /* Label for beginning of location list.
2306 Only on head of list */
2307 const char *section
; /* Section this loclist is relative to */
2308 dw_loc_descr_ref expr
;
2311 static const char *dwarf_stack_op_name
PARAMS ((unsigned));
2312 static dw_loc_descr_ref new_loc_descr
PARAMS ((enum dwarf_location_atom
,
2315 static void add_loc_descr
PARAMS ((dw_loc_descr_ref
*,
2317 static unsigned long size_of_loc_descr
PARAMS ((dw_loc_descr_ref
));
2318 static unsigned long size_of_locs
PARAMS ((dw_loc_descr_ref
));
2319 static void output_loc_operands
PARAMS ((dw_loc_descr_ref
));
2320 static void output_loc_sequence
PARAMS ((dw_loc_descr_ref
));
2322 /* Convert a DWARF stack opcode into its string name. */
2325 dwarf_stack_op_name (op
)
2331 case INTERNAL_DW_OP_tls_addr
:
2332 return "DW_OP_addr";
2334 return "DW_OP_deref";
2336 return "DW_OP_const1u";
2338 return "DW_OP_const1s";
2340 return "DW_OP_const2u";
2342 return "DW_OP_const2s";
2344 return "DW_OP_const4u";
2346 return "DW_OP_const4s";
2348 return "DW_OP_const8u";
2350 return "DW_OP_const8s";
2352 return "DW_OP_constu";
2354 return "DW_OP_consts";
2358 return "DW_OP_drop";
2360 return "DW_OP_over";
2362 return "DW_OP_pick";
2364 return "DW_OP_swap";
2368 return "DW_OP_xderef";
2376 return "DW_OP_minus";
2388 return "DW_OP_plus";
2389 case DW_OP_plus_uconst
:
2390 return "DW_OP_plus_uconst";
2396 return "DW_OP_shra";
2414 return "DW_OP_skip";
2416 return "DW_OP_lit0";
2418 return "DW_OP_lit1";
2420 return "DW_OP_lit2";
2422 return "DW_OP_lit3";
2424 return "DW_OP_lit4";
2426 return "DW_OP_lit5";
2428 return "DW_OP_lit6";
2430 return "DW_OP_lit7";
2432 return "DW_OP_lit8";
2434 return "DW_OP_lit9";
2436 return "DW_OP_lit10";
2438 return "DW_OP_lit11";
2440 return "DW_OP_lit12";
2442 return "DW_OP_lit13";
2444 return "DW_OP_lit14";
2446 return "DW_OP_lit15";
2448 return "DW_OP_lit16";
2450 return "DW_OP_lit17";
2452 return "DW_OP_lit18";
2454 return "DW_OP_lit19";
2456 return "DW_OP_lit20";
2458 return "DW_OP_lit21";
2460 return "DW_OP_lit22";
2462 return "DW_OP_lit23";
2464 return "DW_OP_lit24";
2466 return "DW_OP_lit25";
2468 return "DW_OP_lit26";
2470 return "DW_OP_lit27";
2472 return "DW_OP_lit28";
2474 return "DW_OP_lit29";
2476 return "DW_OP_lit30";
2478 return "DW_OP_lit31";
2480 return "DW_OP_reg0";
2482 return "DW_OP_reg1";
2484 return "DW_OP_reg2";
2486 return "DW_OP_reg3";
2488 return "DW_OP_reg4";
2490 return "DW_OP_reg5";
2492 return "DW_OP_reg6";
2494 return "DW_OP_reg7";
2496 return "DW_OP_reg8";
2498 return "DW_OP_reg9";
2500 return "DW_OP_reg10";
2502 return "DW_OP_reg11";
2504 return "DW_OP_reg12";
2506 return "DW_OP_reg13";
2508 return "DW_OP_reg14";
2510 return "DW_OP_reg15";
2512 return "DW_OP_reg16";
2514 return "DW_OP_reg17";
2516 return "DW_OP_reg18";
2518 return "DW_OP_reg19";
2520 return "DW_OP_reg20";
2522 return "DW_OP_reg21";
2524 return "DW_OP_reg22";
2526 return "DW_OP_reg23";
2528 return "DW_OP_reg24";
2530 return "DW_OP_reg25";
2532 return "DW_OP_reg26";
2534 return "DW_OP_reg27";
2536 return "DW_OP_reg28";
2538 return "DW_OP_reg29";
2540 return "DW_OP_reg30";
2542 return "DW_OP_reg31";
2544 return "DW_OP_breg0";
2546 return "DW_OP_breg1";
2548 return "DW_OP_breg2";
2550 return "DW_OP_breg3";
2552 return "DW_OP_breg4";
2554 return "DW_OP_breg5";
2556 return "DW_OP_breg6";
2558 return "DW_OP_breg7";
2560 return "DW_OP_breg8";
2562 return "DW_OP_breg9";
2564 return "DW_OP_breg10";
2566 return "DW_OP_breg11";
2568 return "DW_OP_breg12";
2570 return "DW_OP_breg13";
2572 return "DW_OP_breg14";
2574 return "DW_OP_breg15";
2576 return "DW_OP_breg16";
2578 return "DW_OP_breg17";
2580 return "DW_OP_breg18";
2582 return "DW_OP_breg19";
2584 return "DW_OP_breg20";
2586 return "DW_OP_breg21";
2588 return "DW_OP_breg22";
2590 return "DW_OP_breg23";
2592 return "DW_OP_breg24";
2594 return "DW_OP_breg25";
2596 return "DW_OP_breg26";
2598 return "DW_OP_breg27";
2600 return "DW_OP_breg28";
2602 return "DW_OP_breg29";
2604 return "DW_OP_breg30";
2606 return "DW_OP_breg31";
2608 return "DW_OP_regx";
2610 return "DW_OP_fbreg";
2612 return "DW_OP_bregx";
2614 return "DW_OP_piece";
2615 case DW_OP_deref_size
:
2616 return "DW_OP_deref_size";
2617 case DW_OP_xderef_size
:
2618 return "DW_OP_xderef_size";
2621 case DW_OP_push_object_address
:
2622 return "DW_OP_push_object_address";
2624 return "DW_OP_call2";
2626 return "DW_OP_call4";
2627 case DW_OP_call_ref
:
2628 return "DW_OP_call_ref";
2629 case DW_OP_GNU_push_tls_address
:
2630 return "DW_OP_GNU_push_tls_address";
2632 return "OP_<unknown>";
2636 /* Return a pointer to a newly allocated location description. Location
2637 descriptions are simple expression terms that can be strung
2638 together to form more complicated location (address) descriptions. */
2640 static inline dw_loc_descr_ref
2641 new_loc_descr (op
, oprnd1
, oprnd2
)
2642 enum dwarf_location_atom op
;
2643 unsigned long oprnd1
;
2644 unsigned long oprnd2
;
2646 /* Use xcalloc here so we clear out all of the long_long constant in
2648 dw_loc_descr_ref descr
2649 = (dw_loc_descr_ref
) xcalloc (1, sizeof (dw_loc_descr_node
));
2651 descr
->dw_loc_opc
= op
;
2652 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2653 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2654 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2655 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2661 /* Add a location description term to a location description expression. */
2664 add_loc_descr (list_head
, descr
)
2665 dw_loc_descr_ref
*list_head
;
2666 dw_loc_descr_ref descr
;
2668 dw_loc_descr_ref
*d
;
2670 /* Find the end of the chain. */
2671 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2677 /* Return the size of a location descriptor. */
2679 static unsigned long
2680 size_of_loc_descr (loc
)
2681 dw_loc_descr_ref loc
;
2683 unsigned long size
= 1;
2685 switch (loc
->dw_loc_opc
)
2688 case INTERNAL_DW_OP_tls_addr
:
2689 size
+= DWARF2_ADDR_SIZE
;
2708 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2711 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2716 case DW_OP_plus_uconst
:
2717 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2755 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2758 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2761 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2764 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2765 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2768 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2770 case DW_OP_deref_size
:
2771 case DW_OP_xderef_size
:
2780 case DW_OP_call_ref
:
2781 size
+= DWARF2_ADDR_SIZE
;
2790 /* Return the size of a series of location descriptors. */
2792 static unsigned long
2794 dw_loc_descr_ref loc
;
2798 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2800 loc
->dw_loc_addr
= size
;
2801 size
+= size_of_loc_descr (loc
);
2807 /* Output location description stack opcode's operands (if any). */
2810 output_loc_operands (loc
)
2811 dw_loc_descr_ref loc
;
2813 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2814 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2816 switch (loc
->dw_loc_opc
)
2818 #ifdef DWARF2_DEBUGGING_INFO
2820 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2824 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2828 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2832 if (HOST_BITS_PER_LONG
< 64)
2834 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2841 if (val1
->val_class
== dw_val_class_loc
)
2842 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2846 dw2_asm_output_data (2, offset
, NULL
);
2859 /* We currently don't make any attempt to make sure these are
2860 aligned properly like we do for the main unwind info, so
2861 don't support emitting things larger than a byte if we're
2862 only doing unwinding. */
2867 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2870 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2873 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2876 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2878 case DW_OP_plus_uconst
:
2879 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2913 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2916 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2919 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
2922 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2923 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2926 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2928 case DW_OP_deref_size
:
2929 case DW_OP_xderef_size
:
2930 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2933 case INTERNAL_DW_OP_tls_addr
:
2934 #ifdef ASM_OUTPUT_DWARF_DTPREL
2935 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
2937 fputc ('\n', asm_out_file
);
2944 /* Other codes have no operands. */
2949 /* Output a sequence of location operations. */
2952 output_loc_sequence (loc
)
2953 dw_loc_descr_ref loc
;
2955 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2957 /* Output the opcode. */
2958 dw2_asm_output_data (1, loc
->dw_loc_opc
,
2959 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
2961 /* Output the operand(s) (if any). */
2962 output_loc_operands (loc
);
2966 /* This routine will generate the correct assembly data for a location
2967 description based on a cfi entry with a complex address. */
2970 output_cfa_loc (cfi
)
2973 dw_loc_descr_ref loc
;
2976 /* Output the size of the block. */
2977 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
2978 size
= size_of_locs (loc
);
2979 dw2_asm_output_data_uleb128 (size
, NULL
);
2981 /* Now output the operations themselves. */
2982 output_loc_sequence (loc
);
2985 /* This function builds a dwarf location descriptor sequence from
2986 a dw_cfa_location. */
2988 static struct dw_loc_descr_struct
*
2990 dw_cfa_location
*cfa
;
2992 struct dw_loc_descr_struct
*head
, *tmp
;
2994 if (cfa
->indirect
== 0)
2997 if (cfa
->base_offset
)
3000 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3002 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3004 else if (cfa
->reg
<= 31)
3005 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3007 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3009 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3010 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3011 add_loc_descr (&head
, tmp
);
3012 if (cfa
->offset
!= 0)
3014 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3015 add_loc_descr (&head
, tmp
);
3021 /* This function fills in aa dw_cfa_location structure from a dwarf location
3022 descriptor sequence. */
3025 get_cfa_from_loc_descr (cfa
, loc
)
3026 dw_cfa_location
*cfa
;
3027 struct dw_loc_descr_struct
*loc
;
3029 struct dw_loc_descr_struct
*ptr
;
3031 cfa
->base_offset
= 0;
3035 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3037 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3073 cfa
->reg
= op
- DW_OP_reg0
;
3076 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3110 cfa
->reg
= op
- DW_OP_breg0
;
3111 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3114 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3115 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3120 case DW_OP_plus_uconst
:
3121 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3124 internal_error ("DW_LOC_OP %s not implemented\n",
3125 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3129 #endif /* .debug_frame support */
3131 /* And now, the support for symbolic debugging information. */
3132 #ifdef DWARF2_DEBUGGING_INFO
3134 /* .debug_str support. */
3135 static hashnode indirect_string_alloc
PARAMS ((hash_table
*));
3136 static int output_indirect_string
PARAMS ((struct cpp_reader
*,
3137 hashnode
, const PTR
));
3140 static void dwarf2out_init
PARAMS ((const char *));
3141 static void dwarf2out_finish
PARAMS ((const char *));
3142 static void dwarf2out_define
PARAMS ((unsigned int, const char *));
3143 static void dwarf2out_undef
PARAMS ((unsigned int, const char *));
3144 static void dwarf2out_start_source_file
PARAMS ((unsigned, const char *));
3145 static void dwarf2out_end_source_file
PARAMS ((unsigned));
3146 static void dwarf2out_begin_block
PARAMS ((unsigned, unsigned));
3147 static void dwarf2out_end_block
PARAMS ((unsigned, unsigned));
3148 static bool dwarf2out_ignore_block
PARAMS ((tree
));
3149 static void dwarf2out_global_decl
PARAMS ((tree
));
3150 static void dwarf2out_abstract_function
PARAMS ((tree
));
3152 /* The debug hooks structure. */
3154 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3160 dwarf2out_start_source_file
,
3161 dwarf2out_end_source_file
,
3162 dwarf2out_begin_block
,
3163 dwarf2out_end_block
,
3164 dwarf2out_ignore_block
,
3165 dwarf2out_source_line
,
3166 dwarf2out_begin_prologue
,
3167 debug_nothing_int_charstar
, /* end_prologue */
3168 dwarf2out_end_epilogue
,
3169 debug_nothing_tree
, /* begin_function */
3170 debug_nothing_int
, /* end_function */
3171 dwarf2out_decl
, /* function_decl */
3172 dwarf2out_global_decl
,
3173 debug_nothing_tree
, /* deferred_inline_function */
3174 /* The DWARF 2 backend tries to reduce debugging bloat by not
3175 emitting the abstract description of inline functions until
3176 something tries to reference them. */
3177 dwarf2out_abstract_function
, /* outlining_inline_function */
3178 debug_nothing_rtx
/* label */
3181 /* NOTE: In the comments in this file, many references are made to
3182 "Debugging Information Entries". This term is abbreviated as `DIE'
3183 throughout the remainder of this file. */
3185 /* An internal representation of the DWARF output is built, and then
3186 walked to generate the DWARF debugging info. The walk of the internal
3187 representation is done after the entire program has been compiled.
3188 The types below are used to describe the internal representation. */
3190 /* Various DIE's use offsets relative to the beginning of the
3191 .debug_info section to refer to each other. */
3193 typedef long int dw_offset
;
3195 /* Define typedefs here to avoid circular dependencies. */
3197 typedef struct dw_attr_struct
*dw_attr_ref
;
3198 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3199 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3200 typedef struct pubname_struct
*pubname_ref
;
3201 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3203 /* Each entry in the line_info_table maintains the file and
3204 line number associated with the label generated for that
3205 entry. The label gives the PC value associated with
3206 the line number entry. */
3208 typedef struct dw_line_info_struct
3210 unsigned long dw_file_num
;
3211 unsigned long dw_line_num
;
3215 /* Line information for functions in separate sections; each one gets its
3217 typedef struct dw_separate_line_info_struct
3219 unsigned long dw_file_num
;
3220 unsigned long dw_line_num
;
3221 unsigned long function
;
3223 dw_separate_line_info_entry
;
3225 /* Each DIE attribute has a field specifying the attribute kind,
3226 a link to the next attribute in the chain, and an attribute value.
3227 Attributes are typically linked below the DIE they modify. */
3229 typedef struct dw_attr_struct
3231 enum dwarf_attribute dw_attr
;
3232 dw_attr_ref dw_attr_next
;
3233 dw_val_node dw_attr_val
;
3237 /* The Debugging Information Entry (DIE) structure */
3239 typedef struct die_struct
3241 enum dwarf_tag die_tag
;
3243 dw_attr_ref die_attr
;
3244 dw_die_ref die_parent
;
3245 dw_die_ref die_child
;
3247 dw_offset die_offset
;
3248 unsigned long die_abbrev
;
3253 /* The pubname structure */
3255 typedef struct pubname_struct
3262 struct dw_ranges_struct
3267 /* The limbo die list structure. */
3268 typedef struct limbo_die_struct
3272 struct limbo_die_struct
*next
;
3276 /* How to start an assembler comment. */
3277 #ifndef ASM_COMMENT_START
3278 #define ASM_COMMENT_START ";#"
3281 /* Define a macro which returns nonzero for a TYPE_DECL which was
3282 implicitly generated for a tagged type.
3284 Note that unlike the gcc front end (which generates a NULL named
3285 TYPE_DECL node for each complete tagged type, each array type, and
3286 each function type node created) the g++ front end generates a
3287 _named_ TYPE_DECL node for each tagged type node created.
3288 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3289 generate a DW_TAG_typedef DIE for them. */
3291 #define TYPE_DECL_IS_STUB(decl) \
3292 (DECL_NAME (decl) == NULL_TREE \
3293 || (DECL_ARTIFICIAL (decl) \
3294 && is_tagged_type (TREE_TYPE (decl)) \
3295 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3296 /* This is necessary for stub decls that \
3297 appear in nested inline functions. */ \
3298 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3299 && (decl_ultimate_origin (decl) \
3300 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3302 /* Information concerning the compilation unit's programming
3303 language, and compiler version. */
3305 /* Fixed size portion of the DWARF compilation unit header. */
3306 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3308 /* Fixed size portion of public names info. */
3309 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3311 /* Fixed size portion of the address range info. */
3312 #define DWARF_ARANGES_HEADER_SIZE \
3313 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3314 - DWARF_OFFSET_SIZE)
3316 /* Size of padding portion in the address range info. It must be
3317 aligned to twice the pointer size. */
3318 #define DWARF_ARANGES_PAD_SIZE \
3319 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3320 - (2 * DWARF_OFFSET_SIZE + 4))
3322 /* Use assembler line directives if available. */
3323 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3324 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3325 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3327 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3331 /* Minimum line offset in a special line info. opcode.
3332 This value was chosen to give a reasonable range of values. */
3333 #define DWARF_LINE_BASE -10
3335 /* First special line opcode - leave room for the standard opcodes. */
3336 #define DWARF_LINE_OPCODE_BASE 10
3338 /* Range of line offsets in a special line info. opcode. */
3339 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3341 /* Flag that indicates the initial value of the is_stmt_start flag.
3342 In the present implementation, we do not mark any lines as
3343 the beginning of a source statement, because that information
3344 is not made available by the GCC front-end. */
3345 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3347 /* This location is used by calc_die_sizes() to keep track
3348 the offset of each DIE within the .debug_info section. */
3349 static unsigned long next_die_offset
;
3351 /* Record the root of the DIE's built for the current compilation unit. */
3352 static dw_die_ref comp_unit_die
;
3354 /* We need special handling in dwarf2out_start_source_file if it is
3356 static int is_main_source
;
3358 /* A list of DIEs with a NULL parent waiting to be relocated. */
3359 static limbo_die_node
*limbo_die_list
= 0;
3361 /* Structure used by lookup_filename to manage sets of filenames. */
3367 unsigned last_lookup_index
;
3370 /* Size (in elements) of increments by which we may expand the filename
3372 #define FILE_TABLE_INCREMENT 64
3374 /* Filenames referenced by this compilation unit. */
3375 static struct file_table file_table
;
3377 /* Local pointer to the name of the main input file. Initialized in
3379 static const char *primary_filename
;
3381 /* A pointer to the base of a table of references to DIE's that describe
3382 declarations. The table is indexed by DECL_UID() which is a unique
3383 number identifying each decl. */
3384 static dw_die_ref
*decl_die_table
;
3386 /* Number of elements currently allocated for the decl_die_table. */
3387 static unsigned decl_die_table_allocated
;
3389 /* Number of elements in decl_die_table currently in use. */
3390 static unsigned decl_die_table_in_use
;
3392 /* Size (in elements) of increments by which we may expand the
3394 #define DECL_DIE_TABLE_INCREMENT 256
3396 /* A pointer to the base of a list of references to DIE's that
3397 are uniquely identified by their tag, presence/absence of
3398 children DIE's, and list of attribute/value pairs. */
3399 static dw_die_ref
*abbrev_die_table
;
3401 /* Number of elements currently allocated for abbrev_die_table. */
3402 static unsigned abbrev_die_table_allocated
;
3404 /* Number of elements in type_die_table currently in use. */
3405 static unsigned abbrev_die_table_in_use
;
3407 /* Size (in elements) of increments by which we may expand the
3408 abbrev_die_table. */
3409 #define ABBREV_DIE_TABLE_INCREMENT 256
3411 /* A pointer to the base of a table that contains line information
3412 for each source code line in .text in the compilation unit. */
3413 static dw_line_info_ref line_info_table
;
3415 /* Number of elements currently allocated for line_info_table. */
3416 static unsigned line_info_table_allocated
;
3418 /* Number of elements in separate_line_info_table currently in use. */
3419 static unsigned separate_line_info_table_in_use
;
3421 /* A pointer to the base of a table that contains line information
3422 for each source code line outside of .text in the compilation unit. */
3423 static dw_separate_line_info_ref separate_line_info_table
;
3425 /* Number of elements currently allocated for separate_line_info_table. */
3426 static unsigned separate_line_info_table_allocated
;
3428 /* Number of elements in line_info_table currently in use. */
3429 static unsigned line_info_table_in_use
;
3431 /* Size (in elements) of increments by which we may expand the
3433 #define LINE_INFO_TABLE_INCREMENT 1024
3435 /* A pointer to the base of a table that contains a list of publicly
3436 accessible names. */
3437 static pubname_ref pubname_table
;
3439 /* Number of elements currently allocated for pubname_table. */
3440 static unsigned pubname_table_allocated
;
3442 /* Number of elements in pubname_table currently in use. */
3443 static unsigned pubname_table_in_use
;
3445 /* Size (in elements) of increments by which we may expand the
3447 #define PUBNAME_TABLE_INCREMENT 64
3449 /* Array of dies for which we should generate .debug_arange info. */
3450 static dw_die_ref
*arange_table
;
3452 /* Number of elements currently allocated for arange_table. */
3453 static unsigned arange_table_allocated
;
3455 /* Number of elements in arange_table currently in use. */
3456 static unsigned arange_table_in_use
;
3458 /* Size (in elements) of increments by which we may expand the
3460 #define ARANGE_TABLE_INCREMENT 64
3462 /* Array of dies for which we should generate .debug_ranges info. */
3463 static dw_ranges_ref ranges_table
;
3465 /* Number of elements currently allocated for ranges_table. */
3466 static unsigned ranges_table_allocated
;
3468 /* Number of elements in ranges_table currently in use. */
3469 static unsigned ranges_table_in_use
;
3471 /* Size (in elements) of increments by which we may expand the
3473 #define RANGES_TABLE_INCREMENT 64
3475 /* Whether we have location lists that need outputting */
3476 static unsigned have_location_lists
;
3478 /* Record whether the function being analyzed contains inlined functions. */
3479 static int current_function_has_inlines
;
3480 #if 0 && defined (MIPS_DEBUGGING_INFO)
3481 static int comp_unit_has_inlines
;
3484 /* Forward declarations for functions defined in this file. */
3486 static int is_pseudo_reg
PARAMS ((rtx
));
3487 static tree type_main_variant
PARAMS ((tree
));
3488 static int is_tagged_type
PARAMS ((tree
));
3489 static const char *dwarf_tag_name
PARAMS ((unsigned));
3490 static const char *dwarf_attr_name
PARAMS ((unsigned));
3491 static const char *dwarf_form_name
PARAMS ((unsigned));
3493 static const char *dwarf_type_encoding_name
PARAMS ((unsigned));
3495 static tree decl_ultimate_origin
PARAMS ((tree
));
3496 static tree block_ultimate_origin
PARAMS ((tree
));
3497 static tree decl_class_context
PARAMS ((tree
));
3498 static void add_dwarf_attr
PARAMS ((dw_die_ref
, dw_attr_ref
));
3499 static inline dw_val_class AT_class
PARAMS ((dw_attr_ref
));
3500 static void add_AT_flag
PARAMS ((dw_die_ref
,
3501 enum dwarf_attribute
,
3503 static inline unsigned AT_flag
PARAMS ((dw_attr_ref
));
3504 static void add_AT_int
PARAMS ((dw_die_ref
,
3505 enum dwarf_attribute
, long));
3506 static inline long int AT_int
PARAMS ((dw_attr_ref
));
3507 static void add_AT_unsigned
PARAMS ((dw_die_ref
,
3508 enum dwarf_attribute
,
3510 static inline unsigned long AT_unsigned
PARAMS ((dw_attr_ref
));
3511 static void add_AT_long_long
PARAMS ((dw_die_ref
,
3512 enum dwarf_attribute
,
3515 static void add_AT_float
PARAMS ((dw_die_ref
,
3516 enum dwarf_attribute
,
3518 static void add_AT_string
PARAMS ((dw_die_ref
,
3519 enum dwarf_attribute
,
3521 static inline const char *AT_string
PARAMS ((dw_attr_ref
));
3522 static int AT_string_form
PARAMS ((dw_attr_ref
));
3523 static void add_AT_die_ref
PARAMS ((dw_die_ref
,
3524 enum dwarf_attribute
,
3526 static inline dw_die_ref AT_ref
PARAMS ((dw_attr_ref
));
3527 static inline int AT_ref_external
PARAMS ((dw_attr_ref
));
3528 static inline void set_AT_ref_external
PARAMS ((dw_attr_ref
, int));
3529 static void add_AT_fde_ref
PARAMS ((dw_die_ref
,
3530 enum dwarf_attribute
,
3532 static void add_AT_loc
PARAMS ((dw_die_ref
,
3533 enum dwarf_attribute
,
3535 static inline dw_loc_descr_ref AT_loc
PARAMS ((dw_attr_ref
));
3536 static void add_AT_loc_list
PARAMS ((dw_die_ref
,
3537 enum dwarf_attribute
,
3539 static inline dw_loc_list_ref AT_loc_list
PARAMS ((dw_attr_ref
));
3540 static void add_AT_addr
PARAMS ((dw_die_ref
,
3541 enum dwarf_attribute
,
3543 static inline rtx AT_addr
PARAMS ((dw_attr_ref
));
3544 static void add_AT_lbl_id
PARAMS ((dw_die_ref
,
3545 enum dwarf_attribute
,
3547 static void add_AT_lbl_offset
PARAMS ((dw_die_ref
,
3548 enum dwarf_attribute
,
3550 static void add_AT_offset
PARAMS ((dw_die_ref
,
3551 enum dwarf_attribute
,
3553 static void add_AT_range_list
PARAMS ((dw_die_ref
,
3554 enum dwarf_attribute
,
3556 static inline const char *AT_lbl
PARAMS ((dw_attr_ref
));
3557 static dw_attr_ref get_AT
PARAMS ((dw_die_ref
,
3558 enum dwarf_attribute
));
3559 static const char *get_AT_low_pc
PARAMS ((dw_die_ref
));
3560 static const char *get_AT_hi_pc
PARAMS ((dw_die_ref
));
3561 static const char *get_AT_string
PARAMS ((dw_die_ref
,
3562 enum dwarf_attribute
));
3563 static int get_AT_flag
PARAMS ((dw_die_ref
,
3564 enum dwarf_attribute
));
3565 static unsigned get_AT_unsigned
PARAMS ((dw_die_ref
,
3566 enum dwarf_attribute
));
3567 static inline dw_die_ref get_AT_ref
PARAMS ((dw_die_ref
,
3568 enum dwarf_attribute
));
3569 static int is_c_family
PARAMS ((void));
3570 static int is_cxx
PARAMS ((void));
3571 static int is_java
PARAMS ((void));
3572 static int is_fortran
PARAMS ((void));
3573 static void remove_AT
PARAMS ((dw_die_ref
,
3574 enum dwarf_attribute
));
3575 static inline void free_die
PARAMS ((dw_die_ref
));
3576 static void remove_children
PARAMS ((dw_die_ref
));
3577 static void add_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3578 static dw_die_ref new_die
PARAMS ((enum dwarf_tag
, dw_die_ref
,
3580 static dw_die_ref lookup_type_die
PARAMS ((tree
));
3581 static void equate_type_number_to_die
PARAMS ((tree
, dw_die_ref
));
3582 static dw_die_ref lookup_decl_die
PARAMS ((tree
));
3583 static void equate_decl_number_to_die
PARAMS ((tree
, dw_die_ref
));
3584 static void print_spaces
PARAMS ((FILE *));
3585 static void print_die
PARAMS ((dw_die_ref
, FILE *));
3586 static void print_dwarf_line_table
PARAMS ((FILE *));
3587 static void reverse_die_lists
PARAMS ((dw_die_ref
));
3588 static void reverse_all_dies
PARAMS ((dw_die_ref
));
3589 static dw_die_ref push_new_compile_unit
PARAMS ((dw_die_ref
, dw_die_ref
));
3590 static dw_die_ref pop_compile_unit
PARAMS ((dw_die_ref
));
3591 static void loc_checksum
PARAMS ((dw_loc_descr_ref
,
3593 static void attr_checksum
PARAMS ((dw_attr_ref
,
3596 static void die_checksum
PARAMS ((dw_die_ref
,
3599 static int same_loc_p
PARAMS ((dw_loc_descr_ref
,
3600 dw_loc_descr_ref
, int *));
3601 static int same_dw_val_p
PARAMS ((dw_val_node
*, dw_val_node
*,
3603 static int same_attr_p
PARAMS ((dw_attr_ref
, dw_attr_ref
, int *));
3604 static int same_die_p
PARAMS ((dw_die_ref
, dw_die_ref
, int *));
3605 static int same_die_p_wrap
PARAMS ((dw_die_ref
, dw_die_ref
));
3606 static void compute_section_prefix
PARAMS ((dw_die_ref
));
3607 static int is_type_die
PARAMS ((dw_die_ref
));
3608 static int is_comdat_die
PARAMS ((dw_die_ref
));
3609 static int is_symbol_die
PARAMS ((dw_die_ref
));
3610 static void assign_symbol_names
PARAMS ((dw_die_ref
));
3611 static void break_out_includes
PARAMS ((dw_die_ref
));
3612 static hashval_t htab_cu_hash
PARAMS ((const void *));
3613 static int htab_cu_eq
PARAMS ((const void *, const void *));
3614 static void htab_cu_del
PARAMS ((void *));
3615 static int check_duplicate_cu
PARAMS ((dw_die_ref
, htab_t
, unsigned *));
3616 static void record_comdat_symbol_number
PARAMS ((dw_die_ref
, htab_t
, unsigned));
3617 static void add_sibling_attributes
PARAMS ((dw_die_ref
));
3618 static void build_abbrev_table
PARAMS ((dw_die_ref
));
3619 static void output_location_lists
PARAMS ((dw_die_ref
));
3620 static int constant_size
PARAMS ((long unsigned));
3621 static unsigned long size_of_die
PARAMS ((dw_die_ref
));
3622 static void calc_die_sizes
PARAMS ((dw_die_ref
));
3623 static void mark_dies
PARAMS ((dw_die_ref
));
3624 static void unmark_dies
PARAMS ((dw_die_ref
));
3625 static void unmark_all_dies
PARAMS ((dw_die_ref
));
3626 static unsigned long size_of_pubnames
PARAMS ((void));
3627 static unsigned long size_of_aranges
PARAMS ((void));
3628 static enum dwarf_form value_format
PARAMS ((dw_attr_ref
));
3629 static void output_value_format
PARAMS ((dw_attr_ref
));
3630 static void output_abbrev_section
PARAMS ((void));
3631 static void output_die_symbol
PARAMS ((dw_die_ref
));
3632 static void output_die
PARAMS ((dw_die_ref
));
3633 static void output_compilation_unit_header
PARAMS ((void));
3634 static void output_comp_unit
PARAMS ((dw_die_ref
, int));
3635 static const char *dwarf2_name
PARAMS ((tree
, int));
3636 static void add_pubname
PARAMS ((tree
, dw_die_ref
));
3637 static void output_pubnames
PARAMS ((void));
3638 static void add_arange
PARAMS ((tree
, dw_die_ref
));
3639 static void output_aranges
PARAMS ((void));
3640 static unsigned int add_ranges
PARAMS ((tree
));
3641 static void output_ranges
PARAMS ((void));
3642 static void output_line_info
PARAMS ((void));
3643 static void output_file_names
PARAMS ((void));
3644 static dw_die_ref base_type_die
PARAMS ((tree
));
3645 static tree root_type
PARAMS ((tree
));
3646 static int is_base_type
PARAMS ((tree
));
3647 static dw_die_ref modified_type_die
PARAMS ((tree
, int, int, dw_die_ref
));
3648 static int type_is_enum
PARAMS ((tree
));
3649 static unsigned int reg_number
PARAMS ((rtx
));
3650 static dw_loc_descr_ref reg_loc_descriptor
PARAMS ((rtx
));
3651 static dw_loc_descr_ref int_loc_descriptor
PARAMS ((HOST_WIDE_INT
));
3652 static dw_loc_descr_ref based_loc_descr
PARAMS ((unsigned, long));
3653 static int is_based_loc
PARAMS ((rtx
));
3654 static dw_loc_descr_ref mem_loc_descriptor
PARAMS ((rtx
, enum machine_mode mode
));
3655 static dw_loc_descr_ref concat_loc_descriptor
PARAMS ((rtx
, rtx
));
3656 static dw_loc_descr_ref loc_descriptor
PARAMS ((rtx
));
3657 static dw_loc_descr_ref loc_descriptor_from_tree
PARAMS ((tree
, int));
3658 static HOST_WIDE_INT ceiling
PARAMS ((HOST_WIDE_INT
, unsigned int));
3659 static tree field_type
PARAMS ((tree
));
3660 static unsigned int simple_type_align_in_bits
PARAMS ((tree
));
3661 static unsigned int simple_decl_align_in_bits
PARAMS ((tree
));
3662 static unsigned HOST_WIDE_INT simple_type_size_in_bits
PARAMS ((tree
));
3663 static HOST_WIDE_INT field_byte_offset
PARAMS ((tree
));
3664 static void add_AT_location_description
PARAMS ((dw_die_ref
,
3665 enum dwarf_attribute
,
3667 static void add_data_member_location_attribute
PARAMS ((dw_die_ref
, tree
));
3668 static void add_const_value_attribute
PARAMS ((dw_die_ref
, rtx
));
3669 static rtx rtl_for_decl_location
PARAMS ((tree
));
3670 static void add_location_or_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3671 static void tree_add_const_value_attribute
PARAMS ((dw_die_ref
, tree
));
3672 static void add_name_attribute
PARAMS ((dw_die_ref
, const char *));
3673 static void add_bound_info
PARAMS ((dw_die_ref
,
3674 enum dwarf_attribute
, tree
));
3675 static void add_subscript_info
PARAMS ((dw_die_ref
, tree
));
3676 static void add_byte_size_attribute
PARAMS ((dw_die_ref
, tree
));
3677 static void add_bit_offset_attribute
PARAMS ((dw_die_ref
, tree
));
3678 static void add_bit_size_attribute
PARAMS ((dw_die_ref
, tree
));
3679 static void add_prototyped_attribute
PARAMS ((dw_die_ref
, tree
));
3680 static void add_abstract_origin_attribute
PARAMS ((dw_die_ref
, tree
));
3681 static void add_pure_or_virtual_attribute
PARAMS ((dw_die_ref
, tree
));
3682 static void add_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3683 static void add_name_and_src_coords_attributes
PARAMS ((dw_die_ref
, tree
));
3684 static void push_decl_scope
PARAMS ((tree
));
3685 static void pop_decl_scope
PARAMS ((void));
3686 static dw_die_ref scope_die_for
PARAMS ((tree
, dw_die_ref
));
3687 static inline int local_scope_p
PARAMS ((dw_die_ref
));
3688 static inline int class_scope_p
PARAMS ((dw_die_ref
));
3689 static void add_type_attribute
PARAMS ((dw_die_ref
, tree
, int, int,
3691 static const char *type_tag
PARAMS ((tree
));
3692 static tree member_declared_type
PARAMS ((tree
));
3694 static const char *decl_start_label
PARAMS ((tree
));
3696 static void gen_array_type_die
PARAMS ((tree
, dw_die_ref
));
3697 static void gen_set_type_die
PARAMS ((tree
, dw_die_ref
));
3699 static void gen_entry_point_die
PARAMS ((tree
, dw_die_ref
));
3701 static void gen_inlined_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3702 static void gen_inlined_structure_type_die
PARAMS ((tree
, dw_die_ref
));
3703 static void gen_inlined_union_type_die
PARAMS ((tree
, dw_die_ref
));
3704 static void gen_enumeration_type_die
PARAMS ((tree
, dw_die_ref
));
3705 static dw_die_ref gen_formal_parameter_die
PARAMS ((tree
, dw_die_ref
));
3706 static void gen_unspecified_parameters_die
PARAMS ((tree
, dw_die_ref
));
3707 static void gen_formal_types_die
PARAMS ((tree
, dw_die_ref
));
3708 static void gen_subprogram_die
PARAMS ((tree
, dw_die_ref
));
3709 static void gen_variable_die
PARAMS ((tree
, dw_die_ref
));
3710 static void gen_label_die
PARAMS ((tree
, dw_die_ref
));
3711 static void gen_lexical_block_die
PARAMS ((tree
, dw_die_ref
, int));
3712 static void gen_inlined_subroutine_die
PARAMS ((tree
, dw_die_ref
, int));
3713 static void gen_field_die
PARAMS ((tree
, dw_die_ref
));
3714 static void gen_ptr_to_mbr_type_die
PARAMS ((tree
, dw_die_ref
));
3715 static dw_die_ref gen_compile_unit_die
PARAMS ((const char *));
3716 static void gen_string_type_die
PARAMS ((tree
, dw_die_ref
));
3717 static void gen_inheritance_die
PARAMS ((tree
, dw_die_ref
));
3718 static void gen_member_die
PARAMS ((tree
, dw_die_ref
));
3719 static void gen_struct_or_union_type_die
PARAMS ((tree
, dw_die_ref
));
3720 static void gen_subroutine_type_die
PARAMS ((tree
, dw_die_ref
));
3721 static void gen_typedef_die
PARAMS ((tree
, dw_die_ref
));
3722 static void gen_type_die
PARAMS ((tree
, dw_die_ref
));
3723 static void gen_tagged_type_instantiation_die
PARAMS ((tree
, dw_die_ref
));
3724 static void gen_block_die
PARAMS ((tree
, dw_die_ref
, int));
3725 static void decls_for_scope
PARAMS ((tree
, dw_die_ref
, int));
3726 static int is_redundant_typedef
PARAMS ((tree
));
3727 static void gen_decl_die
PARAMS ((tree
, dw_die_ref
));
3728 static unsigned lookup_filename
PARAMS ((const char *));
3729 static void init_file_table
PARAMS ((void));
3730 static void retry_incomplete_types
PARAMS ((void));
3731 static void gen_type_die_for_member
PARAMS ((tree
, tree
, dw_die_ref
));
3732 static void splice_child_die
PARAMS ((dw_die_ref
, dw_die_ref
));
3733 static int file_info_cmp
PARAMS ((const void *, const void *));
3734 static dw_loc_list_ref new_loc_list
PARAMS ((dw_loc_descr_ref
,
3735 const char *, const char *,
3736 const char *, unsigned));
3737 static void add_loc_descr_to_loc_list
PARAMS ((dw_loc_list_ref
*,
3739 const char *, const char *, const char *));
3740 static void output_loc_list
PARAMS ((dw_loc_list_ref
));
3741 static char *gen_internal_sym
PARAMS ((const char *));
3742 static void mark_limbo_die_list
PARAMS ((void *));
3744 /* Section names used to hold DWARF debugging information. */
3745 #ifndef DEBUG_INFO_SECTION
3746 #define DEBUG_INFO_SECTION ".debug_info"
3748 #ifndef DEBUG_ABBREV_SECTION
3749 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3751 #ifndef DEBUG_ARANGES_SECTION
3752 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3754 #ifndef DEBUG_MACINFO_SECTION
3755 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3757 #ifndef DEBUG_LINE_SECTION
3758 #define DEBUG_LINE_SECTION ".debug_line"
3760 #ifndef DEBUG_LOC_SECTION
3761 #define DEBUG_LOC_SECTION ".debug_loc"
3763 #ifndef DEBUG_PUBNAMES_SECTION
3764 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3766 #ifndef DEBUG_STR_SECTION
3767 #define DEBUG_STR_SECTION ".debug_str"
3769 #ifndef DEBUG_RANGES_SECTION
3770 #define DEBUG_RANGES_SECTION ".debug_ranges"
3773 /* Standard ELF section names for compiled code and data. */
3774 #ifndef TEXT_SECTION_NAME
3775 #define TEXT_SECTION_NAME ".text"
3778 /* Section flags for .debug_str section. */
3779 #ifdef HAVE_GAS_SHF_MERGE
3780 #define DEBUG_STR_SECTION_FLAGS \
3781 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3783 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3786 /* Labels we insert at beginning sections we can reference instead of
3787 the section names themselves. */
3789 #ifndef TEXT_SECTION_LABEL
3790 #define TEXT_SECTION_LABEL "Ltext"
3792 #ifndef DEBUG_LINE_SECTION_LABEL
3793 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3795 #ifndef DEBUG_INFO_SECTION_LABEL
3796 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3798 #ifndef DEBUG_ABBREV_SECTION_LABEL
3799 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3801 #ifndef DEBUG_LOC_SECTION_LABEL
3802 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3804 #ifndef DEBUG_RANGES_SECTION_LABEL
3805 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3807 #ifndef DEBUG_MACINFO_SECTION_LABEL
3808 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3811 /* Definitions of defaults for formats and names of various special
3812 (artificial) labels which may be generated within this file (when the -g
3813 options is used and DWARF_DEBUGGING_INFO is in effect.
3814 If necessary, these may be overridden from within the tm.h file, but
3815 typically, overriding these defaults is unnecessary. */
3817 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3818 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3819 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3820 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3821 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3822 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3823 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3824 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3826 #ifndef TEXT_END_LABEL
3827 #define TEXT_END_LABEL "Letext"
3829 #ifndef BLOCK_BEGIN_LABEL
3830 #define BLOCK_BEGIN_LABEL "LBB"
3832 #ifndef BLOCK_END_LABEL
3833 #define BLOCK_END_LABEL "LBE"
3835 #ifndef LINE_CODE_LABEL
3836 #define LINE_CODE_LABEL "LM"
3838 #ifndef SEPARATE_LINE_CODE_LABEL
3839 #define SEPARATE_LINE_CODE_LABEL "LSM"
3842 /* We allow a language front-end to designate a function that is to be
3843 called to "demangle" any name before it it put into a DIE. */
3845 static const char *(*demangle_name_func
) PARAMS ((const char *));
3848 dwarf2out_set_demangle_name_func (func
)
3849 const char *(*func
) PARAMS ((const char *));
3851 demangle_name_func
= func
;
3854 /* Test if rtl node points to a pseudo register. */
3860 return ((GET_CODE (rtl
) == REG
&& REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3861 || (GET_CODE (rtl
) == SUBREG
3862 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3865 /* Return a reference to a type, with its const and volatile qualifiers
3869 type_main_variant (type
)
3872 type
= TYPE_MAIN_VARIANT (type
);
3874 /* ??? There really should be only one main variant among any group of
3875 variants of a given type (and all of the MAIN_VARIANT values for all
3876 members of the group should point to that one type) but sometimes the C
3877 front-end messes this up for array types, so we work around that bug
3879 if (TREE_CODE (type
) == ARRAY_TYPE
)
3880 while (type
!= TYPE_MAIN_VARIANT (type
))
3881 type
= TYPE_MAIN_VARIANT (type
);
3886 /* Return nonzero if the given type node represents a tagged type. */
3889 is_tagged_type (type
)
3892 enum tree_code code
= TREE_CODE (type
);
3894 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3895 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3898 /* Convert a DIE tag into its string name. */
3901 dwarf_tag_name (tag
)
3906 case DW_TAG_padding
:
3907 return "DW_TAG_padding";
3908 case DW_TAG_array_type
:
3909 return "DW_TAG_array_type";
3910 case DW_TAG_class_type
:
3911 return "DW_TAG_class_type";
3912 case DW_TAG_entry_point
:
3913 return "DW_TAG_entry_point";
3914 case DW_TAG_enumeration_type
:
3915 return "DW_TAG_enumeration_type";
3916 case DW_TAG_formal_parameter
:
3917 return "DW_TAG_formal_parameter";
3918 case DW_TAG_imported_declaration
:
3919 return "DW_TAG_imported_declaration";
3921 return "DW_TAG_label";
3922 case DW_TAG_lexical_block
:
3923 return "DW_TAG_lexical_block";
3925 return "DW_TAG_member";
3926 case DW_TAG_pointer_type
:
3927 return "DW_TAG_pointer_type";
3928 case DW_TAG_reference_type
:
3929 return "DW_TAG_reference_type";
3930 case DW_TAG_compile_unit
:
3931 return "DW_TAG_compile_unit";
3932 case DW_TAG_string_type
:
3933 return "DW_TAG_string_type";
3934 case DW_TAG_structure_type
:
3935 return "DW_TAG_structure_type";
3936 case DW_TAG_subroutine_type
:
3937 return "DW_TAG_subroutine_type";
3938 case DW_TAG_typedef
:
3939 return "DW_TAG_typedef";
3940 case DW_TAG_union_type
:
3941 return "DW_TAG_union_type";
3942 case DW_TAG_unspecified_parameters
:
3943 return "DW_TAG_unspecified_parameters";
3944 case DW_TAG_variant
:
3945 return "DW_TAG_variant";
3946 case DW_TAG_common_block
:
3947 return "DW_TAG_common_block";
3948 case DW_TAG_common_inclusion
:
3949 return "DW_TAG_common_inclusion";
3950 case DW_TAG_inheritance
:
3951 return "DW_TAG_inheritance";
3952 case DW_TAG_inlined_subroutine
:
3953 return "DW_TAG_inlined_subroutine";
3955 return "DW_TAG_module";
3956 case DW_TAG_ptr_to_member_type
:
3957 return "DW_TAG_ptr_to_member_type";
3958 case DW_TAG_set_type
:
3959 return "DW_TAG_set_type";
3960 case DW_TAG_subrange_type
:
3961 return "DW_TAG_subrange_type";
3962 case DW_TAG_with_stmt
:
3963 return "DW_TAG_with_stmt";
3964 case DW_TAG_access_declaration
:
3965 return "DW_TAG_access_declaration";
3966 case DW_TAG_base_type
:
3967 return "DW_TAG_base_type";
3968 case DW_TAG_catch_block
:
3969 return "DW_TAG_catch_block";
3970 case DW_TAG_const_type
:
3971 return "DW_TAG_const_type";
3972 case DW_TAG_constant
:
3973 return "DW_TAG_constant";
3974 case DW_TAG_enumerator
:
3975 return "DW_TAG_enumerator";
3976 case DW_TAG_file_type
:
3977 return "DW_TAG_file_type";
3979 return "DW_TAG_friend";
3980 case DW_TAG_namelist
:
3981 return "DW_TAG_namelist";
3982 case DW_TAG_namelist_item
:
3983 return "DW_TAG_namelist_item";
3984 case DW_TAG_packed_type
:
3985 return "DW_TAG_packed_type";
3986 case DW_TAG_subprogram
:
3987 return "DW_TAG_subprogram";
3988 case DW_TAG_template_type_param
:
3989 return "DW_TAG_template_type_param";
3990 case DW_TAG_template_value_param
:
3991 return "DW_TAG_template_value_param";
3992 case DW_TAG_thrown_type
:
3993 return "DW_TAG_thrown_type";
3994 case DW_TAG_try_block
:
3995 return "DW_TAG_try_block";
3996 case DW_TAG_variant_part
:
3997 return "DW_TAG_variant_part";
3998 case DW_TAG_variable
:
3999 return "DW_TAG_variable";
4000 case DW_TAG_volatile_type
:
4001 return "DW_TAG_volatile_type";
4002 case DW_TAG_MIPS_loop
:
4003 return "DW_TAG_MIPS_loop";
4004 case DW_TAG_format_label
:
4005 return "DW_TAG_format_label";
4006 case DW_TAG_function_template
:
4007 return "DW_TAG_function_template";
4008 case DW_TAG_class_template
:
4009 return "DW_TAG_class_template";
4010 case DW_TAG_GNU_BINCL
:
4011 return "DW_TAG_GNU_BINCL";
4012 case DW_TAG_GNU_EINCL
:
4013 return "DW_TAG_GNU_EINCL";
4015 return "DW_TAG_<unknown>";
4019 /* Convert a DWARF attribute code into its string name. */
4022 dwarf_attr_name (attr
)
4028 return "DW_AT_sibling";
4029 case DW_AT_location
:
4030 return "DW_AT_location";
4032 return "DW_AT_name";
4033 case DW_AT_ordering
:
4034 return "DW_AT_ordering";
4035 case DW_AT_subscr_data
:
4036 return "DW_AT_subscr_data";
4037 case DW_AT_byte_size
:
4038 return "DW_AT_byte_size";
4039 case DW_AT_bit_offset
:
4040 return "DW_AT_bit_offset";
4041 case DW_AT_bit_size
:
4042 return "DW_AT_bit_size";
4043 case DW_AT_element_list
:
4044 return "DW_AT_element_list";
4045 case DW_AT_stmt_list
:
4046 return "DW_AT_stmt_list";
4048 return "DW_AT_low_pc";
4050 return "DW_AT_high_pc";
4051 case DW_AT_language
:
4052 return "DW_AT_language";
4054 return "DW_AT_member";
4056 return "DW_AT_discr";
4057 case DW_AT_discr_value
:
4058 return "DW_AT_discr_value";
4059 case DW_AT_visibility
:
4060 return "DW_AT_visibility";
4062 return "DW_AT_import";
4063 case DW_AT_string_length
:
4064 return "DW_AT_string_length";
4065 case DW_AT_common_reference
:
4066 return "DW_AT_common_reference";
4067 case DW_AT_comp_dir
:
4068 return "DW_AT_comp_dir";
4069 case DW_AT_const_value
:
4070 return "DW_AT_const_value";
4071 case DW_AT_containing_type
:
4072 return "DW_AT_containing_type";
4073 case DW_AT_default_value
:
4074 return "DW_AT_default_value";
4076 return "DW_AT_inline";
4077 case DW_AT_is_optional
:
4078 return "DW_AT_is_optional";
4079 case DW_AT_lower_bound
:
4080 return "DW_AT_lower_bound";
4081 case DW_AT_producer
:
4082 return "DW_AT_producer";
4083 case DW_AT_prototyped
:
4084 return "DW_AT_prototyped";
4085 case DW_AT_return_addr
:
4086 return "DW_AT_return_addr";
4087 case DW_AT_start_scope
:
4088 return "DW_AT_start_scope";
4089 case DW_AT_stride_size
:
4090 return "DW_AT_stride_size";
4091 case DW_AT_upper_bound
:
4092 return "DW_AT_upper_bound";
4093 case DW_AT_abstract_origin
:
4094 return "DW_AT_abstract_origin";
4095 case DW_AT_accessibility
:
4096 return "DW_AT_accessibility";
4097 case DW_AT_address_class
:
4098 return "DW_AT_address_class";
4099 case DW_AT_artificial
:
4100 return "DW_AT_artificial";
4101 case DW_AT_base_types
:
4102 return "DW_AT_base_types";
4103 case DW_AT_calling_convention
:
4104 return "DW_AT_calling_convention";
4106 return "DW_AT_count";
4107 case DW_AT_data_member_location
:
4108 return "DW_AT_data_member_location";
4109 case DW_AT_decl_column
:
4110 return "DW_AT_decl_column";
4111 case DW_AT_decl_file
:
4112 return "DW_AT_decl_file";
4113 case DW_AT_decl_line
:
4114 return "DW_AT_decl_line";
4115 case DW_AT_declaration
:
4116 return "DW_AT_declaration";
4117 case DW_AT_discr_list
:
4118 return "DW_AT_discr_list";
4119 case DW_AT_encoding
:
4120 return "DW_AT_encoding";
4121 case DW_AT_external
:
4122 return "DW_AT_external";
4123 case DW_AT_frame_base
:
4124 return "DW_AT_frame_base";
4126 return "DW_AT_friend";
4127 case DW_AT_identifier_case
:
4128 return "DW_AT_identifier_case";
4129 case DW_AT_macro_info
:
4130 return "DW_AT_macro_info";
4131 case DW_AT_namelist_items
:
4132 return "DW_AT_namelist_items";
4133 case DW_AT_priority
:
4134 return "DW_AT_priority";
4136 return "DW_AT_segment";
4137 case DW_AT_specification
:
4138 return "DW_AT_specification";
4139 case DW_AT_static_link
:
4140 return "DW_AT_static_link";
4142 return "DW_AT_type";
4143 case DW_AT_use_location
:
4144 return "DW_AT_use_location";
4145 case DW_AT_variable_parameter
:
4146 return "DW_AT_variable_parameter";
4147 case DW_AT_virtuality
:
4148 return "DW_AT_virtuality";
4149 case DW_AT_vtable_elem_location
:
4150 return "DW_AT_vtable_elem_location";
4152 case DW_AT_allocated
:
4153 return "DW_AT_allocated";
4154 case DW_AT_associated
:
4155 return "DW_AT_associated";
4156 case DW_AT_data_location
:
4157 return "DW_AT_data_location";
4159 return "DW_AT_stride";
4160 case DW_AT_entry_pc
:
4161 return "DW_AT_entry_pc";
4162 case DW_AT_use_UTF8
:
4163 return "DW_AT_use_UTF8";
4164 case DW_AT_extension
:
4165 return "DW_AT_extension";
4167 return "DW_AT_ranges";
4168 case DW_AT_trampoline
:
4169 return "DW_AT_trampoline";
4170 case DW_AT_call_column
:
4171 return "DW_AT_call_column";
4172 case DW_AT_call_file
:
4173 return "DW_AT_call_file";
4174 case DW_AT_call_line
:
4175 return "DW_AT_call_line";
4177 case DW_AT_MIPS_fde
:
4178 return "DW_AT_MIPS_fde";
4179 case DW_AT_MIPS_loop_begin
:
4180 return "DW_AT_MIPS_loop_begin";
4181 case DW_AT_MIPS_tail_loop_begin
:
4182 return "DW_AT_MIPS_tail_loop_begin";
4183 case DW_AT_MIPS_epilog_begin
:
4184 return "DW_AT_MIPS_epilog_begin";
4185 case DW_AT_MIPS_loop_unroll_factor
:
4186 return "DW_AT_MIPS_loop_unroll_factor";
4187 case DW_AT_MIPS_software_pipeline_depth
:
4188 return "DW_AT_MIPS_software_pipeline_depth";
4189 case DW_AT_MIPS_linkage_name
:
4190 return "DW_AT_MIPS_linkage_name";
4191 case DW_AT_MIPS_stride
:
4192 return "DW_AT_MIPS_stride";
4193 case DW_AT_MIPS_abstract_name
:
4194 return "DW_AT_MIPS_abstract_name";
4195 case DW_AT_MIPS_clone_origin
:
4196 return "DW_AT_MIPS_clone_origin";
4197 case DW_AT_MIPS_has_inlines
:
4198 return "DW_AT_MIPS_has_inlines";
4200 case DW_AT_sf_names
:
4201 return "DW_AT_sf_names";
4202 case DW_AT_src_info
:
4203 return "DW_AT_src_info";
4204 case DW_AT_mac_info
:
4205 return "DW_AT_mac_info";
4206 case DW_AT_src_coords
:
4207 return "DW_AT_src_coords";
4208 case DW_AT_body_begin
:
4209 return "DW_AT_body_begin";
4210 case DW_AT_body_end
:
4211 return "DW_AT_body_end";
4212 case DW_AT_GNU_vector
:
4213 return "DW_AT_GNU_vector";
4215 case DW_AT_VMS_rtnbeg_pd_address
:
4216 return "DW_AT_VMS_rtnbeg_pd_address";
4219 return "DW_AT_<unknown>";
4223 /* Convert a DWARF value form code into its string name. */
4226 dwarf_form_name (form
)
4232 return "DW_FORM_addr";
4233 case DW_FORM_block2
:
4234 return "DW_FORM_block2";
4235 case DW_FORM_block4
:
4236 return "DW_FORM_block4";
4238 return "DW_FORM_data2";
4240 return "DW_FORM_data4";
4242 return "DW_FORM_data8";
4243 case DW_FORM_string
:
4244 return "DW_FORM_string";
4246 return "DW_FORM_block";
4247 case DW_FORM_block1
:
4248 return "DW_FORM_block1";
4250 return "DW_FORM_data1";
4252 return "DW_FORM_flag";
4254 return "DW_FORM_sdata";
4256 return "DW_FORM_strp";
4258 return "DW_FORM_udata";
4259 case DW_FORM_ref_addr
:
4260 return "DW_FORM_ref_addr";
4262 return "DW_FORM_ref1";
4264 return "DW_FORM_ref2";
4266 return "DW_FORM_ref4";
4268 return "DW_FORM_ref8";
4269 case DW_FORM_ref_udata
:
4270 return "DW_FORM_ref_udata";
4271 case DW_FORM_indirect
:
4272 return "DW_FORM_indirect";
4274 return "DW_FORM_<unknown>";
4278 /* Convert a DWARF type code into its string name. */
4282 dwarf_type_encoding_name (enc
)
4287 case DW_ATE_address
:
4288 return "DW_ATE_address";
4289 case DW_ATE_boolean
:
4290 return "DW_ATE_boolean";
4291 case DW_ATE_complex_float
:
4292 return "DW_ATE_complex_float";
4294 return "DW_ATE_float";
4296 return "DW_ATE_signed";
4297 case DW_ATE_signed_char
:
4298 return "DW_ATE_signed_char";
4299 case DW_ATE_unsigned
:
4300 return "DW_ATE_unsigned";
4301 case DW_ATE_unsigned_char
:
4302 return "DW_ATE_unsigned_char";
4304 return "DW_ATE_<unknown>";
4309 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4310 instance of an inlined instance of a decl which is local to an inline
4311 function, so we have to trace all of the way back through the origin chain
4312 to find out what sort of node actually served as the original seed for the
4316 decl_ultimate_origin (decl
)
4319 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4320 nodes in the function to point to themselves; ignore that if
4321 we're trying to output the abstract instance of this function. */
4322 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4325 #ifdef ENABLE_CHECKING
4326 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4327 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4328 most distant ancestor, this should never happen. */
4332 return DECL_ABSTRACT_ORIGIN (decl
);
4335 /* Determine the "ultimate origin" of a block. The block may be an inlined
4336 instance of an inlined instance of a block which is local to an inline
4337 function, so we have to trace all of the way back through the origin chain
4338 to find out what sort of node actually served as the original seed for the
4342 block_ultimate_origin (block
)
4345 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4347 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4348 nodes in the function to point to themselves; ignore that if
4349 we're trying to output the abstract instance of this function. */
4350 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4353 if (immediate_origin
== NULL_TREE
)
4358 tree lookahead
= immediate_origin
;
4362 ret_val
= lookahead
;
4363 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4364 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4366 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4372 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4373 of a virtual function may refer to a base class, so we check the 'this'
4377 decl_class_context (decl
)
4380 tree context
= NULL_TREE
;
4382 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4383 context
= DECL_CONTEXT (decl
);
4385 context
= TYPE_MAIN_VARIANT
4386 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4388 if (context
&& !TYPE_P (context
))
4389 context
= NULL_TREE
;
4394 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4395 addition order, and correct that in reverse_all_dies. */
4398 add_dwarf_attr (die
, attr
)
4402 if (die
!= NULL
&& attr
!= NULL
)
4404 attr
->dw_attr_next
= die
->die_attr
;
4405 die
->die_attr
= attr
;
4409 static inline dw_val_class
4413 return a
->dw_attr_val
.val_class
;
4416 /* Add a flag value attribute to a DIE. */
4419 add_AT_flag (die
, attr_kind
, flag
)
4421 enum dwarf_attribute attr_kind
;
4424 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4426 attr
->dw_attr_next
= NULL
;
4427 attr
->dw_attr
= attr_kind
;
4428 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4429 attr
->dw_attr_val
.v
.val_flag
= flag
;
4430 add_dwarf_attr (die
, attr
);
4433 static inline unsigned
4437 if (a
&& AT_class (a
) == dw_val_class_flag
)
4438 return a
->dw_attr_val
.v
.val_flag
;
4443 /* Add a signed integer attribute value to a DIE. */
4446 add_AT_int (die
, attr_kind
, int_val
)
4448 enum dwarf_attribute attr_kind
;
4451 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4453 attr
->dw_attr_next
= NULL
;
4454 attr
->dw_attr
= attr_kind
;
4455 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4456 attr
->dw_attr_val
.v
.val_int
= int_val
;
4457 add_dwarf_attr (die
, attr
);
4460 static inline long int
4464 if (a
&& AT_class (a
) == dw_val_class_const
)
4465 return a
->dw_attr_val
.v
.val_int
;
4470 /* Add an unsigned integer attribute value to a DIE. */
4473 add_AT_unsigned (die
, attr_kind
, unsigned_val
)
4475 enum dwarf_attribute attr_kind
;
4476 unsigned long unsigned_val
;
4478 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4480 attr
->dw_attr_next
= NULL
;
4481 attr
->dw_attr
= attr_kind
;
4482 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4483 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4484 add_dwarf_attr (die
, attr
);
4487 static inline unsigned long
4491 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4492 return a
->dw_attr_val
.v
.val_unsigned
;
4497 /* Add an unsigned double integer attribute value to a DIE. */
4500 add_AT_long_long (die
, attr_kind
, val_hi
, val_low
)
4502 enum dwarf_attribute attr_kind
;
4503 unsigned long val_hi
;
4504 unsigned long val_low
;
4506 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4508 attr
->dw_attr_next
= NULL
;
4509 attr
->dw_attr
= attr_kind
;
4510 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4511 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4512 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4513 add_dwarf_attr (die
, attr
);
4516 /* Add a floating point attribute value to a DIE and return it. */
4519 add_AT_float (die
, attr_kind
, length
, array
)
4521 enum dwarf_attribute attr_kind
;
4525 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4527 attr
->dw_attr_next
= NULL
;
4528 attr
->dw_attr
= attr_kind
;
4529 attr
->dw_attr_val
.val_class
= dw_val_class_float
;
4530 attr
->dw_attr_val
.v
.val_float
.length
= length
;
4531 attr
->dw_attr_val
.v
.val_float
.array
= array
;
4532 add_dwarf_attr (die
, attr
);
4535 /* Add a string attribute value to a DIE. */
4538 add_AT_string (die
, attr_kind
, str
)
4540 enum dwarf_attribute attr_kind
;
4543 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4544 struct indirect_string_node
*node
;
4546 if (! debug_str_hash
)
4548 debug_str_hash
= ht_create (10);
4549 debug_str_hash
->alloc_node
= indirect_string_alloc
;
4552 node
= (struct indirect_string_node
*)
4553 ht_lookup (debug_str_hash
, (const unsigned char *) str
,
4554 strlen (str
), HT_ALLOC
);
4557 attr
->dw_attr_next
= NULL
;
4558 attr
->dw_attr
= attr_kind
;
4559 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4560 attr
->dw_attr_val
.v
.val_str
= node
;
4561 add_dwarf_attr (die
, attr
);
4564 static inline const char *
4568 if (a
&& AT_class (a
) == dw_val_class_str
)
4569 return (const char *) HT_STR (&a
->dw_attr_val
.v
.val_str
->id
);
4574 /* Find out whether a string should be output inline in DIE
4575 or out-of-line in .debug_str section. */
4581 if (a
&& AT_class (a
) == dw_val_class_str
)
4583 struct indirect_string_node
*node
;
4585 extern int const_labelno
;
4588 node
= a
->dw_attr_val
.v
.val_str
;
4592 len
= HT_LEN (&node
->id
) + 1;
4594 /* If the string is shorter or equal to the size of the reference, it is
4595 always better to put it inline. */
4596 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4597 return node
->form
= DW_FORM_string
;
4599 /* If we cannot expect the linker to merge strings in .debug_str
4600 section, only put it into .debug_str if it is worth even in this
4602 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4603 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4604 return node
->form
= DW_FORM_string
;
4606 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
4608 node
->label
= xstrdup (label
);
4610 return node
->form
= DW_FORM_strp
;
4616 /* Add a DIE reference attribute value to a DIE. */
4619 add_AT_die_ref (die
, attr_kind
, targ_die
)
4621 enum dwarf_attribute attr_kind
;
4622 dw_die_ref targ_die
;
4624 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4626 attr
->dw_attr_next
= NULL
;
4627 attr
->dw_attr
= attr_kind
;
4628 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4629 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4630 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4631 add_dwarf_attr (die
, attr
);
4634 static inline dw_die_ref
4638 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4639 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4648 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4649 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4655 set_AT_ref_external (a
, i
)
4659 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4660 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4665 /* Add an FDE reference attribute value to a DIE. */
4668 add_AT_fde_ref (die
, attr_kind
, targ_fde
)
4670 enum dwarf_attribute attr_kind
;
4673 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4675 attr
->dw_attr_next
= NULL
;
4676 attr
->dw_attr
= attr_kind
;
4677 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4678 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4679 add_dwarf_attr (die
, attr
);
4682 /* Add a location description attribute value to a DIE. */
4685 add_AT_loc (die
, attr_kind
, loc
)
4687 enum dwarf_attribute attr_kind
;
4688 dw_loc_descr_ref loc
;
4690 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4692 attr
->dw_attr_next
= NULL
;
4693 attr
->dw_attr
= attr_kind
;
4694 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4695 attr
->dw_attr_val
.v
.val_loc
= loc
;
4696 add_dwarf_attr (die
, attr
);
4699 static inline dw_loc_descr_ref
4703 if (a
&& AT_class (a
) == dw_val_class_loc
)
4704 return a
->dw_attr_val
.v
.val_loc
;
4710 add_AT_loc_list (die
, attr_kind
, loc_list
)
4712 enum dwarf_attribute attr_kind
;
4713 dw_loc_list_ref loc_list
;
4715 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4717 attr
->dw_attr_next
= NULL
;
4718 attr
->dw_attr
= attr_kind
;
4719 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4720 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4721 add_dwarf_attr (die
, attr
);
4722 have_location_lists
= 1;
4725 static inline dw_loc_list_ref
4729 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4730 return a
->dw_attr_val
.v
.val_loc_list
;
4735 /* Add an address constant attribute value to a DIE. */
4738 add_AT_addr (die
, attr_kind
, addr
)
4740 enum dwarf_attribute attr_kind
;
4743 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4745 attr
->dw_attr_next
= NULL
;
4746 attr
->dw_attr
= attr_kind
;
4747 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4748 attr
->dw_attr_val
.v
.val_addr
= addr
;
4749 add_dwarf_attr (die
, attr
);
4756 if (a
&& AT_class (a
) == dw_val_class_addr
)
4757 return a
->dw_attr_val
.v
.val_addr
;
4762 /* Add a label identifier attribute value to a DIE. */
4765 add_AT_lbl_id (die
, attr_kind
, lbl_id
)
4767 enum dwarf_attribute attr_kind
;
4770 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4772 attr
->dw_attr_next
= NULL
;
4773 attr
->dw_attr
= attr_kind
;
4774 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4775 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4776 add_dwarf_attr (die
, attr
);
4779 /* Add a section offset attribute value to a DIE. */
4782 add_AT_lbl_offset (die
, attr_kind
, label
)
4784 enum dwarf_attribute attr_kind
;
4787 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4789 attr
->dw_attr_next
= NULL
;
4790 attr
->dw_attr
= attr_kind
;
4791 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4792 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4793 add_dwarf_attr (die
, attr
);
4796 /* Add an offset attribute value to a DIE. */
4799 add_AT_offset (die
, attr_kind
, offset
)
4801 enum dwarf_attribute attr_kind
;
4802 unsigned long offset
;
4804 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4806 attr
->dw_attr_next
= NULL
;
4807 attr
->dw_attr
= attr_kind
;
4808 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4809 attr
->dw_attr_val
.v
.val_offset
= offset
;
4810 add_dwarf_attr (die
, attr
);
4813 /* Add an range_list attribute value to a DIE. */
4816 add_AT_range_list (die
, attr_kind
, offset
)
4818 enum dwarf_attribute attr_kind
;
4819 unsigned long offset
;
4821 dw_attr_ref attr
= (dw_attr_ref
) xmalloc (sizeof (dw_attr_node
));
4823 attr
->dw_attr_next
= NULL
;
4824 attr
->dw_attr
= attr_kind
;
4825 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4826 attr
->dw_attr_val
.v
.val_offset
= offset
;
4827 add_dwarf_attr (die
, attr
);
4830 static inline const char *
4834 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4835 || AT_class (a
) == dw_val_class_lbl_offset
))
4836 return a
->dw_attr_val
.v
.val_lbl_id
;
4841 /* Get the attribute of type attr_kind. */
4843 static inline dw_attr_ref
4844 get_AT (die
, attr_kind
)
4846 enum dwarf_attribute attr_kind
;
4849 dw_die_ref spec
= NULL
;
4853 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4854 if (a
->dw_attr
== attr_kind
)
4856 else if (a
->dw_attr
== DW_AT_specification
4857 || a
->dw_attr
== DW_AT_abstract_origin
)
4861 return get_AT (spec
, attr_kind
);
4867 /* Return the "low pc" attribute value, typically associated with a subprogram
4868 DIE. Return null if the "low pc" attribute is either not present, or if it
4869 cannot be represented as an assembler label identifier. */
4871 static inline const char *
4875 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4877 return a
? AT_lbl (a
) : NULL
;
4880 /* Return the "high pc" attribute value, typically associated with a subprogram
4881 DIE. Return null if the "high pc" attribute is either not present, or if it
4882 cannot be represented as an assembler label identifier. */
4884 static inline const char *
4888 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4890 return a
? AT_lbl (a
) : NULL
;
4893 /* Return the value of the string attribute designated by ATTR_KIND, or
4894 NULL if it is not present. */
4896 static inline const char *
4897 get_AT_string (die
, attr_kind
)
4899 enum dwarf_attribute attr_kind
;
4901 dw_attr_ref a
= get_AT (die
, attr_kind
);
4903 return a
? AT_string (a
) : NULL
;
4906 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4907 if it is not present. */
4910 get_AT_flag (die
, attr_kind
)
4912 enum dwarf_attribute attr_kind
;
4914 dw_attr_ref a
= get_AT (die
, attr_kind
);
4916 return a
? AT_flag (a
) : 0;
4919 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4920 if it is not present. */
4922 static inline unsigned
4923 get_AT_unsigned (die
, attr_kind
)
4925 enum dwarf_attribute attr_kind
;
4927 dw_attr_ref a
= get_AT (die
, attr_kind
);
4929 return a
? AT_unsigned (a
) : 0;
4932 static inline dw_die_ref
4933 get_AT_ref (die
, attr_kind
)
4935 enum dwarf_attribute attr_kind
;
4937 dw_attr_ref a
= get_AT (die
, attr_kind
);
4939 return a
? AT_ref (a
) : NULL
;
4945 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4947 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
4948 || lang
== DW_LANG_C_plus_plus
);
4954 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
4955 == DW_LANG_C_plus_plus
);
4961 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4963 return (lang
== DW_LANG_Fortran77
|| lang
== DW_LANG_Fortran90
);
4969 unsigned lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
4971 return (lang
== DW_LANG_Java
);
4974 /* Free up the memory used by A. */
4976 static inline void free_AT
PARAMS ((dw_attr_ref
));
4981 switch (AT_class (a
))
4983 case dw_val_class_str
:
4984 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4985 a
->dw_attr_val
.v
.val_str
->refcount
--;
4988 case dw_val_class_lbl_id
:
4989 case dw_val_class_lbl_offset
:
4990 free (a
->dw_attr_val
.v
.val_lbl_id
);
4993 case dw_val_class_float
:
4994 free (a
->dw_attr_val
.v
.val_float
.array
);
5004 /* Remove the specified attribute if present. */
5007 remove_AT (die
, attr_kind
)
5009 enum dwarf_attribute attr_kind
;
5012 dw_attr_ref removed
= NULL
;
5016 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
5017 if ((*p
)->dw_attr
== attr_kind
)
5020 *p
= (*p
)->dw_attr_next
;
5029 /* Free up the memory used by DIE. */
5035 remove_children (die
);
5039 /* Discard the children of this DIE. */
5042 remove_children (die
)
5045 dw_die_ref child_die
= die
->die_child
;
5047 die
->die_child
= NULL
;
5049 while (child_die
!= NULL
)
5051 dw_die_ref tmp_die
= child_die
;
5054 child_die
= child_die
->die_sib
;
5056 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5058 dw_attr_ref tmp_a
= a
;
5060 a
= a
->dw_attr_next
;
5068 /* Add a child DIE below its parent. We build the lists up in reverse
5069 addition order, and correct that in reverse_all_dies. */
5072 add_child_die (die
, child_die
)
5074 dw_die_ref child_die
;
5076 if (die
!= NULL
&& child_die
!= NULL
)
5078 if (die
== child_die
)
5081 child_die
->die_parent
= die
;
5082 child_die
->die_sib
= die
->die_child
;
5083 die
->die_child
= child_die
;
5087 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5088 is the specification, to the front of PARENT's list of children. */
5091 splice_child_die (parent
, child
)
5092 dw_die_ref parent
, child
;
5096 /* We want the declaration DIE from inside the class, not the
5097 specification DIE at toplevel. */
5098 if (child
->die_parent
!= parent
)
5100 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5106 if (child
->die_parent
!= parent
5107 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5110 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5113 *p
= child
->die_sib
;
5117 child
->die_sib
= parent
->die_child
;
5118 parent
->die_child
= child
;
5121 /* Return a pointer to a newly created DIE node. */
5123 static inline dw_die_ref
5124 new_die (tag_value
, parent_die
, t
)
5125 enum dwarf_tag tag_value
;
5126 dw_die_ref parent_die
;
5129 dw_die_ref die
= (dw_die_ref
) xcalloc (1, sizeof (die_node
));
5131 die
->die_tag
= tag_value
;
5133 if (parent_die
!= NULL
)
5134 add_child_die (parent_die
, die
);
5137 limbo_die_node
*limbo_node
;
5139 limbo_node
= (limbo_die_node
*) xmalloc (sizeof (limbo_die_node
));
5140 limbo_node
->die
= die
;
5141 limbo_node
->created_for
= t
;
5142 limbo_node
->next
= limbo_die_list
;
5143 limbo_die_list
= limbo_node
;
5149 /* Return the DIE associated with the given type specifier. */
5151 static inline dw_die_ref
5152 lookup_type_die (type
)
5155 return TYPE_SYMTAB_DIE (type
);
5158 /* Equate a DIE to a given type specifier. */
5161 equate_type_number_to_die (type
, type_die
)
5163 dw_die_ref type_die
;
5165 TYPE_SYMTAB_DIE (type
) = type_die
;
5168 /* Return the DIE associated with a given declaration. */
5170 static inline dw_die_ref
5171 lookup_decl_die (decl
)
5174 unsigned decl_id
= DECL_UID (decl
);
5176 return (decl_id
< decl_die_table_in_use
? decl_die_table
[decl_id
] : NULL
);
5179 /* Equate a DIE to a particular declaration. */
5182 equate_decl_number_to_die (decl
, decl_die
)
5184 dw_die_ref decl_die
;
5186 unsigned int decl_id
= DECL_UID (decl
);
5187 unsigned int num_allocated
;
5189 if (decl_id
>= decl_die_table_allocated
)
5192 = ((decl_id
+ 1 + DECL_DIE_TABLE_INCREMENT
- 1)
5193 / DECL_DIE_TABLE_INCREMENT
)
5194 * DECL_DIE_TABLE_INCREMENT
;
5197 = (dw_die_ref
*) xrealloc (decl_die_table
,
5198 sizeof (dw_die_ref
) * num_allocated
);
5200 memset ((char *) &decl_die_table
[decl_die_table_allocated
], 0,
5201 (num_allocated
- decl_die_table_allocated
) * sizeof (dw_die_ref
));
5202 decl_die_table_allocated
= num_allocated
;
5205 if (decl_id
>= decl_die_table_in_use
)
5206 decl_die_table_in_use
= (decl_id
+ 1);
5208 decl_die_table
[decl_id
] = decl_die
;
5211 /* Keep track of the number of spaces used to indent the
5212 output of the debugging routines that print the structure of
5213 the DIE internal representation. */
5214 static int print_indent
;
5216 /* Indent the line the number of spaces given by print_indent. */
5219 print_spaces (outfile
)
5222 fprintf (outfile
, "%*s", print_indent
, "");
5225 /* Print the information associated with a given DIE, and its children.
5226 This routine is a debugging aid only. */
5229 print_die (die
, outfile
)
5236 print_spaces (outfile
);
5237 fprintf (outfile
, "DIE %4lu: %s\n",
5238 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5239 print_spaces (outfile
);
5240 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5241 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5243 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5245 print_spaces (outfile
);
5246 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5248 switch (AT_class (a
))
5250 case dw_val_class_addr
:
5251 fprintf (outfile
, "address");
5253 case dw_val_class_offset
:
5254 fprintf (outfile
, "offset");
5256 case dw_val_class_loc
:
5257 fprintf (outfile
, "location descriptor");
5259 case dw_val_class_loc_list
:
5260 fprintf (outfile
, "location list -> label:%s",
5261 AT_loc_list (a
)->ll_symbol
);
5263 case dw_val_class_range_list
:
5264 fprintf (outfile
, "range list");
5266 case dw_val_class_const
:
5267 fprintf (outfile
, "%ld", AT_int (a
));
5269 case dw_val_class_unsigned_const
:
5270 fprintf (outfile
, "%lu", AT_unsigned (a
));
5272 case dw_val_class_long_long
:
5273 fprintf (outfile
, "constant (%lu,%lu)",
5274 a
->dw_attr_val
.v
.val_long_long
.hi
,
5275 a
->dw_attr_val
.v
.val_long_long
.low
);
5277 case dw_val_class_float
:
5278 fprintf (outfile
, "floating-point constant");
5280 case dw_val_class_flag
:
5281 fprintf (outfile
, "%u", AT_flag (a
));
5283 case dw_val_class_die_ref
:
5284 if (AT_ref (a
) != NULL
)
5286 if (AT_ref (a
)->die_symbol
)
5287 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5289 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5292 fprintf (outfile
, "die -> <null>");
5294 case dw_val_class_lbl_id
:
5295 case dw_val_class_lbl_offset
:
5296 fprintf (outfile
, "label: %s", AT_lbl (a
));
5298 case dw_val_class_str
:
5299 if (AT_string (a
) != NULL
)
5300 fprintf (outfile
, "\"%s\"", AT_string (a
));
5302 fprintf (outfile
, "<null>");
5308 fprintf (outfile
, "\n");
5311 if (die
->die_child
!= NULL
)
5314 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5315 print_die (c
, outfile
);
5319 if (print_indent
== 0)
5320 fprintf (outfile
, "\n");
5323 /* Print the contents of the source code line number correspondence table.
5324 This routine is a debugging aid only. */
5327 print_dwarf_line_table (outfile
)
5331 dw_line_info_ref line_info
;
5333 fprintf (outfile
, "\n\nDWARF source line information\n");
5334 for (i
= 1; i
< line_info_table_in_use
; i
++)
5336 line_info
= &line_info_table
[i
];
5337 fprintf (outfile
, "%5d: ", i
);
5338 fprintf (outfile
, "%-20s", file_table
.table
[line_info
->dw_file_num
]);
5339 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5340 fprintf (outfile
, "\n");
5343 fprintf (outfile
, "\n\n");
5346 /* Print the information collected for a given DIE. */
5349 debug_dwarf_die (die
)
5352 print_die (die
, stderr
);
5355 /* Print all DWARF information collected for the compilation unit.
5356 This routine is a debugging aid only. */
5362 print_die (comp_unit_die
, stderr
);
5363 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5364 print_dwarf_line_table (stderr
);
5367 /* We build up the lists of children and attributes by pushing new ones
5368 onto the beginning of the list. Reverse the lists for DIE so that
5369 they are in order of addition. */
5372 reverse_die_lists (die
)
5375 dw_die_ref c
, cp
, cn
;
5376 dw_attr_ref a
, ap
, an
;
5378 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5380 an
= a
->dw_attr_next
;
5381 a
->dw_attr_next
= ap
;
5387 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5394 die
->die_child
= cp
;
5397 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5398 reverse all dies in add_sibling_attributes, which runs through all the dies,
5399 it would reverse all the dies. Now, however, since we don't call
5400 reverse_die_lists in add_sibling_attributes, we need a routine to
5401 recursively reverse all the dies. This is that routine. */
5404 reverse_all_dies (die
)
5409 reverse_die_lists (die
);
5411 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5412 reverse_all_dies (c
);
5415 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5416 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5417 DIE that marks the start of the DIEs for this include file. */
5420 push_new_compile_unit (old_unit
, bincl_die
)
5421 dw_die_ref old_unit
, bincl_die
;
5423 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5424 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5426 new_unit
->die_sib
= old_unit
;
5430 /* Close an include-file CU and reopen the enclosing one. */
5433 pop_compile_unit (old_unit
)
5434 dw_die_ref old_unit
;
5436 dw_die_ref new_unit
= old_unit
->die_sib
;
5438 old_unit
->die_sib
= NULL
;
5442 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5443 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5445 /* Calculate the checksum of a location expression. */
5448 loc_checksum (loc
, ctx
)
5449 dw_loc_descr_ref loc
;
5450 struct md5_ctx
*ctx
;
5452 CHECKSUM (loc
->dw_loc_opc
);
5453 CHECKSUM (loc
->dw_loc_oprnd1
);
5454 CHECKSUM (loc
->dw_loc_oprnd2
);
5457 /* Calculate the checksum of an attribute. */
5460 attr_checksum (at
, ctx
, mark
)
5462 struct md5_ctx
*ctx
;
5465 dw_loc_descr_ref loc
;
5468 CHECKSUM (at
->dw_attr
);
5470 /* We don't care about differences in file numbering. */
5471 if (at
->dw_attr
== DW_AT_decl_file
5472 /* Or that this was compiled with a different compiler snapshot; if
5473 the output is the same, that's what matters. */
5474 || at
->dw_attr
== DW_AT_producer
)
5477 switch (AT_class (at
))
5479 case dw_val_class_const
:
5480 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5482 case dw_val_class_unsigned_const
:
5483 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5485 case dw_val_class_long_long
:
5486 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5488 case dw_val_class_float
:
5489 CHECKSUM (at
->dw_attr_val
.v
.val_float
);
5491 case dw_val_class_flag
:
5492 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5494 case dw_val_class_str
:
5495 CHECKSUM_STRING (AT_string (at
));
5498 case dw_val_class_addr
:
5500 switch (GET_CODE (r
))
5503 CHECKSUM_STRING (XSTR (r
, 0));
5511 case dw_val_class_offset
:
5512 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5515 case dw_val_class_loc
:
5516 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5517 loc_checksum (loc
, ctx
);
5520 case dw_val_class_die_ref
:
5521 die_checksum (AT_ref (at
), ctx
, mark
);
5524 case dw_val_class_fde_ref
:
5525 case dw_val_class_lbl_id
:
5526 case dw_val_class_lbl_offset
:
5534 /* Calculate the checksum of a DIE. */
5537 die_checksum (die
, ctx
, mark
)
5539 struct md5_ctx
*ctx
;
5545 /* To avoid infinite recursion. */
5548 CHECKSUM (die
->die_mark
);
5551 die
->die_mark
= ++(*mark
);
5553 CHECKSUM (die
->die_tag
);
5555 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5556 attr_checksum (a
, ctx
, mark
);
5558 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5559 die_checksum (c
, ctx
, mark
);
5563 #undef CHECKSUM_STRING
5565 /* Do the location expressions look same? */
5567 same_loc_p (loc1
, loc2
, mark
)
5568 dw_loc_descr_ref loc1
;
5569 dw_loc_descr_ref loc2
;
5572 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5573 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5574 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5577 /* Do the values look the same? */
5579 same_dw_val_p (v1
, v2
, mark
)
5584 dw_loc_descr_ref loc1
, loc2
;
5588 if (v1
->val_class
!= v2
->val_class
)
5591 switch (v1
->val_class
)
5593 case dw_val_class_const
:
5594 return v1
->v
.val_int
== v2
->v
.val_int
;
5595 case dw_val_class_unsigned_const
:
5596 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5597 case dw_val_class_long_long
:
5598 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5599 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5600 case dw_val_class_float
:
5601 if (v1
->v
.val_float
.length
!= v2
->v
.val_float
.length
)
5603 for (i
= 0; i
< v1
->v
.val_float
.length
; i
++)
5604 if (v1
->v
.val_float
.array
[i
] != v2
->v
.val_float
.array
[i
])
5607 case dw_val_class_flag
:
5608 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5609 case dw_val_class_str
:
5610 return !strcmp((const char *) HT_STR (&v1
->v
.val_str
->id
),
5611 (const char *) HT_STR (&v2
->v
.val_str
->id
));
5613 case dw_val_class_addr
:
5614 r1
= v1
->v
.val_addr
;
5615 r2
= v2
->v
.val_addr
;
5616 if (GET_CODE (r1
) != GET_CODE (r2
))
5618 switch (GET_CODE (r1
))
5621 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5627 case dw_val_class_offset
:
5628 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5630 case dw_val_class_loc
:
5631 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5633 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5634 if (!same_loc_p (loc1
, loc2
, mark
))
5636 return !loc1
&& !loc2
;
5638 case dw_val_class_die_ref
:
5639 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5641 case dw_val_class_fde_ref
:
5642 case dw_val_class_lbl_id
:
5643 case dw_val_class_lbl_offset
:
5651 /* Do the attributes look the same? */
5654 same_attr_p (at1
, at2
, mark
)
5659 if (at1
->dw_attr
!= at2
->dw_attr
)
5662 /* We don't care about differences in file numbering. */
5663 if (at1
->dw_attr
== DW_AT_decl_file
5664 /* Or that this was compiled with a different compiler snapshot; if
5665 the output is the same, that's what matters. */
5666 || at1
->dw_attr
== DW_AT_producer
)
5669 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5672 /* Do the dies look the same? */
5675 same_die_p (die1
, die2
, mark
)
5683 /* To avoid infinite recursion. */
5685 return die1
->die_mark
== die2
->die_mark
;
5686 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5688 if (die1
->die_tag
!= die2
->die_tag
)
5691 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5693 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5694 if (!same_attr_p (a1
, a2
, mark
))
5699 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5701 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5702 if (!same_die_p (c1
, c2
, mark
))
5710 /* Do the dies look the same? Wrapper around same_die_p. */
5713 same_die_p_wrap (die1
, die2
)
5718 int ret
= same_die_p (die1
, die2
, &mark
);
5720 unmark_all_dies (die1
);
5721 unmark_all_dies (die2
);
5726 /* The prefix to attach to symbols on DIEs in the current comdat debug
5728 static char *comdat_symbol_id
;
5730 /* The index of the current symbol within the current comdat CU. */
5731 static unsigned int comdat_symbol_number
;
5733 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5734 children, and set comdat_symbol_id accordingly. */
5737 compute_section_prefix (unit_die
)
5738 dw_die_ref unit_die
;
5740 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5741 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5742 char *name
= (char *) alloca (strlen (base
) + 64);
5745 unsigned char checksum
[16];
5748 /* Compute the checksum of the DIE, then append part of it as hex digits to
5749 the name filename of the unit. */
5751 md5_init_ctx (&ctx
);
5753 die_checksum (unit_die
, &ctx
, &mark
);
5754 unmark_all_dies (unit_die
);
5755 md5_finish_ctx (&ctx
, checksum
);
5757 sprintf (name
, "%s.", base
);
5758 clean_symbol_name (name
);
5760 p
= name
+ strlen (name
);
5761 for (i
= 0; i
< 4; i
++)
5763 sprintf (p
, "%.2x", checksum
[i
]);
5767 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5768 comdat_symbol_number
= 0;
5771 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5777 switch (die
->die_tag
)
5779 case DW_TAG_array_type
:
5780 case DW_TAG_class_type
:
5781 case DW_TAG_enumeration_type
:
5782 case DW_TAG_pointer_type
:
5783 case DW_TAG_reference_type
:
5784 case DW_TAG_string_type
:
5785 case DW_TAG_structure_type
:
5786 case DW_TAG_subroutine_type
:
5787 case DW_TAG_union_type
:
5788 case DW_TAG_ptr_to_member_type
:
5789 case DW_TAG_set_type
:
5790 case DW_TAG_subrange_type
:
5791 case DW_TAG_base_type
:
5792 case DW_TAG_const_type
:
5793 case DW_TAG_file_type
:
5794 case DW_TAG_packed_type
:
5795 case DW_TAG_volatile_type
:
5796 case DW_TAG_typedef
:
5803 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5804 Basically, we want to choose the bits that are likely to be shared between
5805 compilations (types) and leave out the bits that are specific to individual
5806 compilations (functions). */
5812 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5813 we do for stabs. The advantage is a greater likelihood of sharing between
5814 objects that don't include headers in the same order (and therefore would
5815 put the base types in a different comdat). jason 8/28/00 */
5817 if (c
->die_tag
== DW_TAG_base_type
)
5820 if (c
->die_tag
== DW_TAG_pointer_type
5821 || c
->die_tag
== DW_TAG_reference_type
5822 || c
->die_tag
== DW_TAG_const_type
5823 || c
->die_tag
== DW_TAG_volatile_type
)
5825 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5827 return t
? is_comdat_die (t
) : 0;
5830 return is_type_die (c
);
5833 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5834 compilation unit. */
5840 return (is_type_die (c
)
5841 || (get_AT (c
, DW_AT_declaration
)
5842 && !get_AT (c
, DW_AT_specification
)));
5846 gen_internal_sym (prefix
)
5850 static int label_num
;
5852 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5853 return xstrdup (buf
);
5856 /* Assign symbols to all worthy DIEs under DIE. */
5859 assign_symbol_names (die
)
5864 if (is_symbol_die (die
))
5866 if (comdat_symbol_id
)
5868 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
5870 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
5871 comdat_symbol_id
, comdat_symbol_number
++);
5872 die
->die_symbol
= xstrdup (p
);
5875 die
->die_symbol
= gen_internal_sym ("LDIE");
5878 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5879 assign_symbol_names (c
);
5882 struct cu_hash_table_entry
5885 unsigned min_comdat_num
, max_comdat_num
;
5886 struct cu_hash_table_entry
*next
;
5889 /* Routines to manipulate hash table of CUs. */
5894 const struct cu_hash_table_entry
*entry
= of
;
5896 return htab_hash_string (entry
->cu
->die_symbol
);
5900 htab_cu_eq (of1
, of2
)
5904 const struct cu_hash_table_entry
*entry1
= of1
;
5905 const struct die_struct
*entry2
= of2
;
5907 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
5914 struct cu_hash_table_entry
*next
, *entry
= what
;
5924 /* Check whether we have already seen this CU and set up SYM_NUM
5927 check_duplicate_cu (cu
, htable
, sym_num
)
5932 struct cu_hash_table_entry dummy
;
5933 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
5935 dummy
.max_comdat_num
= 0;
5937 slot
= (struct cu_hash_table_entry
**)
5938 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5942 for (; entry
; last
= entry
, entry
= entry
->next
)
5944 if (same_die_p_wrap (cu
, entry
->cu
))
5950 *sym_num
= entry
->min_comdat_num
;
5954 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
5956 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
5957 entry
->next
= *slot
;
5963 /* Record SYM_NUM to record of CU in HTABLE. */
5965 record_comdat_symbol_number (cu
, htable
, sym_num
)
5970 struct cu_hash_table_entry
**slot
, *entry
;
5972 slot
= (struct cu_hash_table_entry
**)
5973 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
5977 entry
->max_comdat_num
= sym_num
;
5980 /* Traverse the DIE (which is always comp_unit_die), and set up
5981 additional compilation units for each of the include files we see
5982 bracketed by BINCL/EINCL. */
5985 break_out_includes (die
)
5989 dw_die_ref unit
= NULL
;
5990 limbo_die_node
*node
, **pnode
;
5991 htab_t cu_hash_table
;
5993 for (ptr
= &(die
->die_child
); *ptr
;)
5995 dw_die_ref c
= *ptr
;
5997 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
5998 || (unit
&& is_comdat_die (c
)))
6000 /* This DIE is for a secondary CU; remove it from the main one. */
6003 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6005 unit
= push_new_compile_unit (unit
, c
);
6008 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6010 unit
= pop_compile_unit (unit
);
6014 add_child_die (unit
, c
);
6018 /* Leave this DIE in the main CU. */
6019 ptr
= &(c
->die_sib
);
6025 /* We can only use this in debugging, since the frontend doesn't check
6026 to make sure that we leave every include file we enter. */
6031 assign_symbol_names (die
);
6032 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6033 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6039 compute_section_prefix (node
->die
);
6040 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6041 &comdat_symbol_number
);
6042 assign_symbol_names (node
->die
);
6044 *pnode
= node
->next
;
6047 pnode
= &node
->next
;
6048 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6049 comdat_symbol_number
);
6052 htab_delete (cu_hash_table
);
6055 /* Traverse the DIE and add a sibling attribute if it may have the
6056 effect of speeding up access to siblings. To save some space,
6057 avoid generating sibling attributes for DIE's without children. */
6060 add_sibling_attributes (die
)
6065 if (die
->die_tag
!= DW_TAG_compile_unit
6066 && die
->die_sib
&& die
->die_child
!= NULL
)
6067 /* Add the sibling link to the front of the attribute list. */
6068 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6070 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6071 add_sibling_attributes (c
);
6074 /* Output all location lists for the DIE and its children. */
6077 output_location_lists (die
)
6083 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6084 if (AT_class (d_attr
) == dw_val_class_loc_list
)
6085 output_loc_list (AT_loc_list (d_attr
));
6087 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6088 output_location_lists (c
);
6092 /* The format of each DIE (and its attribute value pairs) is encoded in an
6093 abbreviation table. This routine builds the abbreviation table and assigns
6094 a unique abbreviation id for each abbreviation entry. The children of each
6095 die are visited recursively. */
6098 build_abbrev_table (die
)
6101 unsigned long abbrev_id
;
6102 unsigned int n_alloc
;
6104 dw_attr_ref d_attr
, a_attr
;
6106 /* Scan the DIE references, and mark as external any that refer to
6107 DIEs from other CUs (i.e. those which are not marked). */
6108 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6109 if (AT_class (d_attr
) == dw_val_class_die_ref
6110 && AT_ref (d_attr
)->die_mark
== 0)
6112 if (AT_ref (d_attr
)->die_symbol
== 0)
6115 set_AT_ref_external (d_attr
, 1);
6118 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6120 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6122 if (abbrev
->die_tag
== die
->die_tag
)
6124 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6126 a_attr
= abbrev
->die_attr
;
6127 d_attr
= die
->die_attr
;
6129 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6131 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6132 || (value_format (a_attr
) != value_format (d_attr
)))
6135 a_attr
= a_attr
->dw_attr_next
;
6136 d_attr
= d_attr
->dw_attr_next
;
6139 if (a_attr
== NULL
&& d_attr
== NULL
)
6145 if (abbrev_id
>= abbrev_die_table_in_use
)
6147 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6149 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6151 = (dw_die_ref
*) xrealloc (abbrev_die_table
,
6152 sizeof (dw_die_ref
) * n_alloc
);
6154 memset ((char *) &abbrev_die_table
[abbrev_die_table_allocated
], 0,
6155 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6156 abbrev_die_table_allocated
= n_alloc
;
6159 ++abbrev_die_table_in_use
;
6160 abbrev_die_table
[abbrev_id
] = die
;
6163 die
->die_abbrev
= abbrev_id
;
6164 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6165 build_abbrev_table (c
);
6168 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6171 constant_size (value
)
6172 long unsigned value
;
6179 log
= floor_log2 (value
);
6182 log
= 1 << (floor_log2 (log
) + 1);
6187 /* Return the size of a DIE as it is represented in the
6188 .debug_info section. */
6190 static unsigned long
6194 unsigned long size
= 0;
6197 size
+= size_of_uleb128 (die
->die_abbrev
);
6198 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6200 switch (AT_class (a
))
6202 case dw_val_class_addr
:
6203 size
+= DWARF2_ADDR_SIZE
;
6205 case dw_val_class_offset
:
6206 size
+= DWARF_OFFSET_SIZE
;
6208 case dw_val_class_loc
:
6210 unsigned long lsize
= size_of_locs (AT_loc (a
));
6213 size
+= constant_size (lsize
);
6217 case dw_val_class_loc_list
:
6218 size
+= DWARF_OFFSET_SIZE
;
6220 case dw_val_class_range_list
:
6221 size
+= DWARF_OFFSET_SIZE
;
6223 case dw_val_class_const
:
6224 size
+= size_of_sleb128 (AT_int (a
));
6226 case dw_val_class_unsigned_const
:
6227 size
+= constant_size (AT_unsigned (a
));
6229 case dw_val_class_long_long
:
6230 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6232 case dw_val_class_float
:
6233 size
+= 1 + a
->dw_attr_val
.v
.val_float
.length
* 4; /* block */
6235 case dw_val_class_flag
:
6238 case dw_val_class_die_ref
:
6239 size
+= DWARF_OFFSET_SIZE
;
6241 case dw_val_class_fde_ref
:
6242 size
+= DWARF_OFFSET_SIZE
;
6244 case dw_val_class_lbl_id
:
6245 size
+= DWARF2_ADDR_SIZE
;
6247 case dw_val_class_lbl_offset
:
6248 size
+= DWARF_OFFSET_SIZE
;
6250 case dw_val_class_str
:
6251 if (AT_string_form (a
) == DW_FORM_strp
)
6252 size
+= DWARF_OFFSET_SIZE
;
6254 size
+= HT_LEN (&a
->dw_attr_val
.v
.val_str
->id
) + 1;
6264 /* Size the debugging information associated with a given DIE. Visits the
6265 DIE's children recursively. Updates the global variable next_die_offset, on
6266 each time through. Uses the current value of next_die_offset to update the
6267 die_offset field in each DIE. */
6270 calc_die_sizes (die
)
6275 die
->die_offset
= next_die_offset
;
6276 next_die_offset
+= size_of_die (die
);
6278 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6281 if (die
->die_child
!= NULL
)
6282 /* Count the null byte used to terminate sibling lists. */
6283 next_die_offset
+= 1;
6286 /* Set the marks for a die and its children. We do this so
6287 that we know whether or not a reference needs to use FORM_ref_addr; only
6288 DIEs in the same CU will be marked. We used to clear out the offset
6289 and use that as the flag, but ran into ordering problems. */
6301 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6305 /* Clear the marks for a die and its children. */
6317 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6321 /* Clear the marks for a die, its children and referred dies. */
6324 unmark_all_dies (die
)
6334 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6335 unmark_all_dies (c
);
6337 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6338 if (AT_class (a
) == dw_val_class_die_ref
)
6339 unmark_all_dies (AT_ref (a
));
6342 /* Return the size of the .debug_pubnames table generated for the
6343 compilation unit. */
6345 static unsigned long
6351 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6352 for (i
= 0; i
< pubname_table_in_use
; i
++)
6354 pubname_ref p
= &pubname_table
[i
];
6355 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6358 size
+= DWARF_OFFSET_SIZE
;
6362 /* Return the size of the information in the .debug_aranges section. */
6364 static unsigned long
6369 size
= DWARF_ARANGES_HEADER_SIZE
;
6371 /* Count the address/length pair for this compilation unit. */
6372 size
+= 2 * DWARF2_ADDR_SIZE
;
6373 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6375 /* Count the two zero words used to terminated the address range table. */
6376 size
+= 2 * DWARF2_ADDR_SIZE
;
6380 /* Select the encoding of an attribute value. */
6382 static enum dwarf_form
6386 switch (a
->dw_attr_val
.val_class
)
6388 case dw_val_class_addr
:
6389 return DW_FORM_addr
;
6390 case dw_val_class_range_list
:
6391 case dw_val_class_offset
:
6392 if (DWARF_OFFSET_SIZE
== 4)
6393 return DW_FORM_data4
;
6394 if (DWARF_OFFSET_SIZE
== 8)
6395 return DW_FORM_data8
;
6397 case dw_val_class_loc_list
:
6398 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6399 .debug_loc section */
6400 return DW_FORM_data4
;
6401 case dw_val_class_loc
:
6402 switch (constant_size (size_of_locs (AT_loc (a
))))
6405 return DW_FORM_block1
;
6407 return DW_FORM_block2
;
6411 case dw_val_class_const
:
6412 return DW_FORM_sdata
;
6413 case dw_val_class_unsigned_const
:
6414 switch (constant_size (AT_unsigned (a
)))
6417 return DW_FORM_data1
;
6419 return DW_FORM_data2
;
6421 return DW_FORM_data4
;
6423 return DW_FORM_data8
;
6427 case dw_val_class_long_long
:
6428 return DW_FORM_block1
;
6429 case dw_val_class_float
:
6430 return DW_FORM_block1
;
6431 case dw_val_class_flag
:
6432 return DW_FORM_flag
;
6433 case dw_val_class_die_ref
:
6434 if (AT_ref_external (a
))
6435 return DW_FORM_ref_addr
;
6438 case dw_val_class_fde_ref
:
6439 return DW_FORM_data
;
6440 case dw_val_class_lbl_id
:
6441 return DW_FORM_addr
;
6442 case dw_val_class_lbl_offset
:
6443 return DW_FORM_data
;
6444 case dw_val_class_str
:
6445 return AT_string_form (a
);
6452 /* Output the encoding of an attribute value. */
6455 output_value_format (a
)
6458 enum dwarf_form form
= value_format (a
);
6460 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6463 /* Output the .debug_abbrev section which defines the DIE abbreviation
6467 output_abbrev_section ()
6469 unsigned long abbrev_id
;
6473 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6475 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6477 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6478 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6479 dwarf_tag_name (abbrev
->die_tag
));
6481 if (abbrev
->die_child
!= NULL
)
6482 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6484 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6486 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6487 a_attr
= a_attr
->dw_attr_next
)
6489 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6490 dwarf_attr_name (a_attr
->dw_attr
));
6491 output_value_format (a_attr
);
6494 dw2_asm_output_data (1, 0, NULL
);
6495 dw2_asm_output_data (1, 0, NULL
);
6498 /* Terminate the table. */
6499 dw2_asm_output_data (1, 0, NULL
);
6502 /* Output a symbol we can use to refer to this DIE from another CU. */
6505 output_die_symbol (die
)
6508 char *sym
= die
->die_symbol
;
6513 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6514 /* We make these global, not weak; if the target doesn't support
6515 .linkonce, it doesn't support combining the sections, so debugging
6517 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, sym
);
6519 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6522 /* Return a new location list, given the begin and end range, and the
6523 expression. gensym tells us whether to generate a new internal symbol for
6524 this location list node, which is done for the head of the list only. */
6526 static inline dw_loc_list_ref
6527 new_loc_list (expr
, begin
, end
, section
, gensym
)
6528 dw_loc_descr_ref expr
;
6531 const char *section
;
6534 dw_loc_list_ref retlist
6535 = (dw_loc_list_ref
) xcalloc (1, sizeof (dw_loc_list_node
));
6537 retlist
->begin
= begin
;
6539 retlist
->expr
= expr
;
6540 retlist
->section
= section
;
6542 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6547 /* Add a location description expression to a location list */
6550 add_loc_descr_to_loc_list (list_head
, descr
, begin
, end
, section
)
6551 dw_loc_list_ref
*list_head
;
6552 dw_loc_descr_ref descr
;
6555 const char *section
;
6559 /* Find the end of the chain. */
6560 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6563 /* Add a new location list node to the list */
6564 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6567 /* Output the location list given to us */
6570 output_loc_list (list_head
)
6571 dw_loc_list_ref list_head
;
6573 dw_loc_list_ref curr
= list_head
;
6575 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6577 /* ??? This shouldn't be needed now that we've forced the
6578 compilation unit base address to zero when there is code
6579 in more than one section. */
6580 if (strcmp (curr
->section
, ".text") == 0)
6582 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6583 dw2_asm_output_data (DWARF2_ADDR_SIZE
, ~(unsigned HOST_WIDE_INT
) 0,
6584 "Location list base address specifier fake entry");
6585 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, curr
->section
,
6586 "Location list base address specifier base");
6589 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6593 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6594 "Location list begin address (%s)",
6595 list_head
->ll_symbol
);
6596 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6597 "Location list end address (%s)",
6598 list_head
->ll_symbol
);
6599 size
= size_of_locs (curr
->expr
);
6601 /* Output the block length for this list of location operations. */
6604 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6606 output_loc_sequence (curr
->expr
);
6609 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6610 "Location list terminator begin (%s)",
6611 list_head
->ll_symbol
);
6612 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0,
6613 "Location list terminator end (%s)",
6614 list_head
->ll_symbol
);
6617 /* Output the DIE and its attributes. Called recursively to generate
6618 the definitions of each child DIE. */
6628 /* If someone in another CU might refer to us, set up a symbol for
6629 them to point to. */
6630 if (die
->die_symbol
)
6631 output_die_symbol (die
);
6633 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6634 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6636 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6638 const char *name
= dwarf_attr_name (a
->dw_attr
);
6640 switch (AT_class (a
))
6642 case dw_val_class_addr
:
6643 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6646 case dw_val_class_offset
:
6647 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6651 case dw_val_class_range_list
:
6653 char *p
= strchr (ranges_section_label
, '\0');
6655 sprintf (p
, "+0x%lx", a
->dw_attr_val
.v
.val_offset
);
6656 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6662 case dw_val_class_loc
:
6663 size
= size_of_locs (AT_loc (a
));
6665 /* Output the block length for this list of location operations. */
6666 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6668 output_loc_sequence (AT_loc (a
));
6671 case dw_val_class_const
:
6672 /* ??? It would be slightly more efficient to use a scheme like is
6673 used for unsigned constants below, but gdb 4.x does not sign
6674 extend. Gdb 5.x does sign extend. */
6675 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6678 case dw_val_class_unsigned_const
:
6679 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6680 AT_unsigned (a
), "%s", name
);
6683 case dw_val_class_long_long
:
6685 unsigned HOST_WIDE_INT first
, second
;
6687 dw2_asm_output_data (1,
6688 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6691 if (WORDS_BIG_ENDIAN
)
6693 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6694 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6698 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6699 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6702 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6703 first
, "long long constant");
6704 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6709 case dw_val_class_float
:
6713 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_float
.length
* 4,
6716 for (i
= 0; i
< a
->dw_attr_val
.v
.val_float
.length
; i
++)
6717 dw2_asm_output_data (4, a
->dw_attr_val
.v
.val_float
.array
[i
],
6718 "fp constant word %u", i
);
6722 case dw_val_class_flag
:
6723 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6726 case dw_val_class_loc_list
:
6728 char *sym
= AT_loc_list (a
)->ll_symbol
;
6732 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
,
6733 loc_section_label
, "%s", name
);
6737 case dw_val_class_die_ref
:
6738 if (AT_ref_external (a
))
6740 char *sym
= AT_ref (a
)->die_symbol
;
6744 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6746 else if (AT_ref (a
)->die_offset
== 0)
6749 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6753 case dw_val_class_fde_ref
:
6757 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6758 a
->dw_attr_val
.v
.val_fde_index
* 2);
6759 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6763 case dw_val_class_lbl_id
:
6764 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6767 case dw_val_class_lbl_offset
:
6768 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6771 case dw_val_class_str
:
6772 if (AT_string_form (a
) == DW_FORM_strp
)
6773 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6774 a
->dw_attr_val
.v
.val_str
->label
,
6775 "%s: \"%s\"", name
, AT_string (a
));
6777 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6785 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6788 /* Add null byte to terminate sibling list. */
6789 if (die
->die_child
!= NULL
)
6790 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6794 /* Output the compilation unit that appears at the beginning of the
6795 .debug_info section, and precedes the DIE descriptions. */
6798 output_compilation_unit_header ()
6800 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
- DWARF_OFFSET_SIZE
,
6801 "Length of Compilation Unit Info");
6802 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6803 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6804 "Offset Into Abbrev. Section");
6805 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6808 /* Output the compilation unit DIE and its children. */
6811 output_comp_unit (die
, output_if_empty
)
6813 int output_if_empty
;
6815 const char *secname
;
6818 /* Unless we are outputting main CU, we may throw away empty ones. */
6819 if (!output_if_empty
&& die
->die_child
== NULL
)
6822 /* Even if there are no children of this DIE, we must output the information
6823 about the compilation unit. Otherwise, on an empty translation unit, we
6824 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6825 will then complain when examining the file. First mark all the DIEs in
6826 this CU so we know which get local refs. */
6829 build_abbrev_table (die
);
6831 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6832 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6833 calc_die_sizes (die
);
6835 oldsym
= die
->die_symbol
;
6838 tmp
= (char *) alloca (strlen (oldsym
) + 24);
6840 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
6842 die
->die_symbol
= NULL
;
6845 secname
= (const char *) DEBUG_INFO_SECTION
;
6847 /* Output debugging information. */
6848 named_section_flags (secname
, SECTION_DEBUG
);
6849 output_compilation_unit_header ();
6852 /* Leave the marks on the main CU, so we can check them in
6857 die
->die_symbol
= oldsym
;
6861 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6862 output of lang_hooks.decl_printable_name for C++ looks like
6863 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6866 dwarf2_name (decl
, scope
)
6870 return (*lang_hooks
.decl_printable_name
) (decl
, scope
? 1 : 0);
6873 /* Add a new entry to .debug_pubnames if appropriate. */
6876 add_pubname (decl
, die
)
6882 if (! TREE_PUBLIC (decl
))
6885 if (pubname_table_in_use
== pubname_table_allocated
)
6887 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
6889 = (pubname_ref
) xrealloc (pubname_table
,
6890 (pubname_table_allocated
6891 * sizeof (pubname_entry
)));
6894 p
= &pubname_table
[pubname_table_in_use
++];
6896 p
->name
= xstrdup (dwarf2_name (decl
, 1));
6899 /* Output the public names table used to speed up access to externally
6900 visible names. For now, only generate entries for externally
6901 visible procedures. */
6907 unsigned long pubnames_length
= size_of_pubnames ();
6909 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
6910 "Length of Public Names Info");
6911 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6912 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6913 "Offset of Compilation Unit Info");
6914 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
6915 "Compilation Unit Length");
6917 for (i
= 0; i
< pubname_table_in_use
; i
++)
6919 pubname_ref pub
= &pubname_table
[i
];
6921 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6922 if (pub
->die
->die_mark
== 0)
6925 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
6928 dw2_asm_output_nstring (pub
->name
, -1, "external name");
6931 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
6934 /* Add a new entry to .debug_aranges if appropriate. */
6937 add_arange (decl
, die
)
6941 if (! DECL_SECTION_NAME (decl
))
6944 if (arange_table_in_use
== arange_table_allocated
)
6946 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
6947 arange_table
= (dw_die_ref
*)
6948 xrealloc (arange_table
, arange_table_allocated
* sizeof (dw_die_ref
));
6951 arange_table
[arange_table_in_use
++] = die
;
6954 /* Output the information that goes into the .debug_aranges table.
6955 Namely, define the beginning and ending address range of the
6956 text section generated for this compilation unit. */
6962 unsigned long aranges_length
= size_of_aranges ();
6964 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
6965 "Length of Address Ranges Info");
6966 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
6967 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
6968 "Offset of Compilation Unit Info");
6969 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
6970 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6972 /* We need to align to twice the pointer size here. */
6973 if (DWARF_ARANGES_PAD_SIZE
)
6975 /* Pad using a 2 byte words so that padding is correct for any
6977 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6978 2 * DWARF2_ADDR_SIZE
);
6979 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
6980 dw2_asm_output_data (2, 0, NULL
);
6983 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
6984 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
6985 text_section_label
, "Length");
6987 for (i
= 0; i
< arange_table_in_use
; i
++)
6989 dw_die_ref die
= arange_table
[i
];
6991 /* We shouldn't see aranges for DIEs outside of the main CU. */
6992 if (die
->die_mark
== 0)
6995 if (die
->die_tag
== DW_TAG_subprogram
)
6997 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
6999 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7000 get_AT_low_pc (die
), "Length");
7004 /* A static variable; extract the symbol from DW_AT_location.
7005 Note that this code isn't currently hit, as we only emit
7006 aranges for functions (jason 9/23/99). */
7007 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7008 dw_loc_descr_ref loc
;
7010 if (! a
|| AT_class (a
) != dw_val_class_loc
)
7014 if (loc
->dw_loc_opc
!= DW_OP_addr
)
7017 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7018 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7019 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7020 get_AT_unsigned (die
, DW_AT_byte_size
),
7025 /* Output the terminator words. */
7026 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7027 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7030 /* Add a new entry to .debug_ranges. Return the offset at which it
7037 unsigned int in_use
= ranges_table_in_use
;
7039 if (in_use
== ranges_table_allocated
)
7041 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7042 ranges_table
= (dw_ranges_ref
)
7043 xrealloc (ranges_table
, (ranges_table_allocated
7044 * sizeof (struct dw_ranges_struct
)));
7047 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7048 ranges_table_in_use
= in_use
+ 1;
7050 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7057 static const char *const start_fmt
= "Offset 0x%x";
7058 const char *fmt
= start_fmt
;
7060 for (i
= 0; i
< ranges_table_in_use
; i
++)
7062 int block_num
= ranges_table
[i
].block_num
;
7066 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7067 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7069 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7070 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7072 /* If all code is in the text section, then the compilation
7073 unit base address defaults to DW_AT_low_pc, which is the
7074 base of the text section. */
7075 if (separate_line_info_table_in_use
== 0)
7077 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7079 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7080 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7081 text_section_label
, NULL
);
7084 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7085 compilation unit base address to zero, which allows us to
7086 use absolute addresses, and not worry about whether the
7087 target supports cross-section arithmetic. */
7090 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7091 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7092 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7099 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7100 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7106 /* Data structure containing information about input files. */
7109 char *path
; /* Complete file name. */
7110 char *fname
; /* File name part. */
7111 int length
; /* Length of entire string. */
7112 int file_idx
; /* Index in input file table. */
7113 int dir_idx
; /* Index in directory table. */
7116 /* Data structure containing information about directories with source
7120 char *path
; /* Path including directory name. */
7121 int length
; /* Path length. */
7122 int prefix
; /* Index of directory entry which is a prefix. */
7123 int count
; /* Number of files in this directory. */
7124 int dir_idx
; /* Index of directory used as base. */
7125 int used
; /* Used in the end? */
7128 /* Callback function for file_info comparison. We sort by looking at
7129 the directories in the path. */
7132 file_info_cmp (p1
, p2
)
7136 const struct file_info
*s1
= p1
;
7137 const struct file_info
*s2
= p2
;
7141 /* Take care of file names without directories. We need to make sure that
7142 we return consistent values to qsort since some will get confused if
7143 we return the same value when identical operands are passed in opposite
7144 orders. So if neither has a directory, return 0 and otherwise return
7145 1 or -1 depending on which one has the directory. */
7146 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7147 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7149 cp1
= (unsigned char *) s1
->path
;
7150 cp2
= (unsigned char *) s2
->path
;
7156 /* Reached the end of the first path? If so, handle like above. */
7157 if ((cp1
== (unsigned char *) s1
->fname
)
7158 || (cp2
== (unsigned char *) s2
->fname
))
7159 return ((cp2
== (unsigned char *) s2
->fname
)
7160 - (cp1
== (unsigned char *) s1
->fname
));
7162 /* Character of current path component the same? */
7163 else if (*cp1
!= *cp2
)
7168 /* Output the directory table and the file name table. We try to minimize
7169 the total amount of memory needed. A heuristic is used to avoid large
7170 slowdowns with many input files. */
7173 output_file_names ()
7175 struct file_info
*files
;
7176 struct dir_info
*dirs
;
7185 /* Allocate the various arrays we need. */
7186 files
= (struct file_info
*) alloca (file_table
.in_use
7187 * sizeof (struct file_info
));
7188 dirs
= (struct dir_info
*) alloca (file_table
.in_use
7189 * sizeof (struct dir_info
));
7191 /* Sort the file names. */
7192 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7196 /* Skip all leading "./". */
7197 f
= file_table
.table
[i
];
7198 while (f
[0] == '.' && f
[1] == '/')
7201 /* Create a new array entry. */
7203 files
[i
].length
= strlen (f
);
7204 files
[i
].file_idx
= i
;
7206 /* Search for the file name part. */
7207 f
= strrchr (f
, '/');
7208 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7211 qsort (files
+ 1, file_table
.in_use
- 1, sizeof (files
[0]), file_info_cmp
);
7213 /* Find all the different directories used. */
7214 dirs
[0].path
= files
[1].path
;
7215 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7216 dirs
[0].prefix
= -1;
7218 dirs
[0].dir_idx
= 0;
7220 files
[1].dir_idx
= 0;
7223 for (i
= 2; i
< (int) file_table
.in_use
; i
++)
7224 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7225 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7226 dirs
[ndirs
- 1].length
) == 0)
7228 /* Same directory as last entry. */
7229 files
[i
].dir_idx
= ndirs
- 1;
7230 ++dirs
[ndirs
- 1].count
;
7236 /* This is a new directory. */
7237 dirs
[ndirs
].path
= files
[i
].path
;
7238 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7239 dirs
[ndirs
].count
= 1;
7240 dirs
[ndirs
].dir_idx
= ndirs
;
7241 dirs
[ndirs
].used
= 0;
7242 files
[i
].dir_idx
= ndirs
;
7244 /* Search for a prefix. */
7245 dirs
[ndirs
].prefix
= -1;
7246 for (j
= 0; j
< ndirs
; j
++)
7247 if (dirs
[j
].length
< dirs
[ndirs
].length
7248 && dirs
[j
].length
> 1
7249 && (dirs
[ndirs
].prefix
== -1
7250 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7251 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7252 dirs
[ndirs
].prefix
= j
;
7257 /* Now to the actual work. We have to find a subset of the directories which
7258 allow expressing the file name using references to the directory table
7259 with the least amount of characters. We do not do an exhaustive search
7260 where we would have to check out every combination of every single
7261 possible prefix. Instead we use a heuristic which provides nearly optimal
7262 results in most cases and never is much off. */
7263 saved
= (int *) alloca (ndirs
* sizeof (int));
7264 savehere
= (int *) alloca (ndirs
* sizeof (int));
7266 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7267 for (i
= 0; i
< ndirs
; i
++)
7272 /* We can always save some space for the current directory. But this
7273 does not mean it will be enough to justify adding the directory. */
7274 savehere
[i
] = dirs
[i
].length
;
7275 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7277 for (j
= i
+ 1; j
< ndirs
; j
++)
7280 if (saved
[j
] < dirs
[i
].length
)
7282 /* Determine whether the dirs[i] path is a prefix of the
7287 while (k
!= -1 && k
!= i
)
7292 /* Yes it is. We can possibly safe some memory but
7293 writing the filenames in dirs[j] relative to
7295 savehere
[j
] = dirs
[i
].length
;
7296 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7301 /* Check whether we can safe enough to justify adding the dirs[i]
7303 if (total
> dirs
[i
].length
+ 1)
7305 /* It's worthwhile adding. */
7306 for (j
= i
; j
< ndirs
; j
++)
7307 if (savehere
[j
] > 0)
7309 /* Remember how much we saved for this directory so far. */
7310 saved
[j
] = savehere
[j
];
7312 /* Remember the prefix directory. */
7313 dirs
[j
].dir_idx
= i
;
7318 /* We have to emit them in the order they appear in the file_table array
7319 since the index is used in the debug info generation. To do this
7320 efficiently we generate a back-mapping of the indices first. */
7321 backmap
= (int *) alloca (file_table
.in_use
* sizeof (int));
7322 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7324 backmap
[files
[i
].file_idx
] = i
;
7326 /* Mark this directory as used. */
7327 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7330 /* That was it. We are ready to emit the information. First emit the
7331 directory name table. We have to make sure the first actually emitted
7332 directory name has index one; zero is reserved for the current working
7333 directory. Make sure we do not confuse these indices with the one for the
7334 constructed table (even though most of the time they are identical). */
7336 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7337 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7338 if (dirs
[i
].used
!= 0)
7340 dirs
[i
].used
= idx
++;
7341 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7342 "Directory Entry: 0x%x", dirs
[i
].used
);
7345 dw2_asm_output_data (1, 0, "End directory table");
7347 /* Correct the index for the current working directory entry if it
7349 if (idx_offset
== 0)
7352 /* Now write all the file names. */
7353 for (i
= 1; i
< (int) file_table
.in_use
; i
++)
7355 int file_idx
= backmap
[i
];
7356 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7358 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7359 "File Entry: 0x%x", i
);
7361 /* Include directory index. */
7362 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7364 /* Modification time. */
7365 dw2_asm_output_data_uleb128 (0, NULL
);
7367 /* File length in bytes. */
7368 dw2_asm_output_data_uleb128 (0, NULL
);
7371 dw2_asm_output_data (1, 0, "End file name table");
7375 /* Output the source line number correspondence information. This
7376 information goes into the .debug_line section. */
7381 char l1
[20], l2
[20], p1
[20], p2
[20];
7382 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7383 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7386 unsigned long lt_index
;
7387 unsigned long current_line
;
7390 unsigned long current_file
;
7391 unsigned long function
;
7393 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7394 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7395 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7396 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7398 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7399 "Length of Source Line Info");
7400 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7402 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7403 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7404 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7406 /* Define the architecture-dependent minimum instruction length (in
7407 bytes). In this implementation of DWARF, this field is used for
7408 information purposes only. Since GCC generates assembly language,
7409 we have no a priori knowledge of how many instruction bytes are
7410 generated for each source line, and therefore can use only the
7411 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7412 commands. Accordingly, we fix this as `1', which is "correct
7413 enough" for all architectures, and don't let the target override. */
7414 dw2_asm_output_data (1, 1,
7415 "Minimum Instruction Length");
7417 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7418 "Default is_stmt_start flag");
7419 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7420 "Line Base Value (Special Opcodes)");
7421 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7422 "Line Range Value (Special Opcodes)");
7423 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7424 "Special Opcode Base");
7426 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7430 case DW_LNS_advance_pc
:
7431 case DW_LNS_advance_line
:
7432 case DW_LNS_set_file
:
7433 case DW_LNS_set_column
:
7434 case DW_LNS_fixed_advance_pc
:
7442 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7446 /* Write out the information about the files we use. */
7447 output_file_names ();
7448 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7450 /* We used to set the address register to the first location in the text
7451 section here, but that didn't accomplish anything since we already
7452 have a line note for the opening brace of the first function. */
7454 /* Generate the line number to PC correspondence table, encoded as
7455 a series of state machine operations. */
7458 strcpy (prev_line_label
, text_section_label
);
7459 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7461 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7464 /* Disable this optimization for now; GDB wants to see two line notes
7465 at the beginning of a function so it can find the end of the
7468 /* Don't emit anything for redundant notes. Just updating the
7469 address doesn't accomplish anything, because we already assume
7470 that anything after the last address is this line. */
7471 if (line_info
->dw_line_num
== current_line
7472 && line_info
->dw_file_num
== current_file
)
7476 /* Emit debug info for the address of the current line.
7478 Unfortunately, we have little choice here currently, and must always
7479 use the most general form. GCC does not know the address delta
7480 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7481 attributes which will give an upper bound on the address range. We
7482 could perhaps use length attributes to determine when it is safe to
7483 use DW_LNS_fixed_advance_pc. */
7485 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7488 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7489 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7490 "DW_LNS_fixed_advance_pc");
7491 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7495 /* This can handle any delta. This takes
7496 4+DWARF2_ADDR_SIZE bytes. */
7497 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7498 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7499 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7500 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7503 strcpy (prev_line_label
, line_label
);
7505 /* Emit debug info for the source file of the current line, if
7506 different from the previous line. */
7507 if (line_info
->dw_file_num
!= current_file
)
7509 current_file
= line_info
->dw_file_num
;
7510 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7511 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7512 file_table
.table
[current_file
]);
7515 /* Emit debug info for the current line number, choosing the encoding
7516 that uses the least amount of space. */
7517 if (line_info
->dw_line_num
!= current_line
)
7519 line_offset
= line_info
->dw_line_num
- current_line
;
7520 line_delta
= line_offset
- DWARF_LINE_BASE
;
7521 current_line
= line_info
->dw_line_num
;
7522 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7523 /* This can handle deltas from -10 to 234, using the current
7524 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7526 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7527 "line %lu", current_line
);
7530 /* This can handle any delta. This takes at least 4 bytes,
7531 depending on the value being encoded. */
7532 dw2_asm_output_data (1, DW_LNS_advance_line
,
7533 "advance to line %lu", current_line
);
7534 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7535 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7539 /* We still need to start a new row, so output a copy insn. */
7540 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7543 /* Emit debug info for the address of the end of the function. */
7546 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7547 "DW_LNS_fixed_advance_pc");
7548 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7552 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7553 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7554 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7555 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7558 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7559 dw2_asm_output_data_uleb128 (1, NULL
);
7560 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7565 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7567 dw_separate_line_info_ref line_info
7568 = &separate_line_info_table
[lt_index
];
7571 /* Don't emit anything for redundant notes. */
7572 if (line_info
->dw_line_num
== current_line
7573 && line_info
->dw_file_num
== current_file
7574 && line_info
->function
== function
)
7578 /* Emit debug info for the address of the current line. If this is
7579 a new function, or the first line of a function, then we need
7580 to handle it differently. */
7581 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7583 if (function
!= line_info
->function
)
7585 function
= line_info
->function
;
7587 /* Set the address register to the first line in the function */
7588 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7589 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7590 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7591 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7595 /* ??? See the DW_LNS_advance_pc comment above. */
7598 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7599 "DW_LNS_fixed_advance_pc");
7600 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7604 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7605 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7606 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7607 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7611 strcpy (prev_line_label
, line_label
);
7613 /* Emit debug info for the source file of the current line, if
7614 different from the previous line. */
7615 if (line_info
->dw_file_num
!= current_file
)
7617 current_file
= line_info
->dw_file_num
;
7618 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7619 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7620 file_table
.table
[current_file
]);
7623 /* Emit debug info for the current line number, choosing the encoding
7624 that uses the least amount of space. */
7625 if (line_info
->dw_line_num
!= current_line
)
7627 line_offset
= line_info
->dw_line_num
- current_line
;
7628 line_delta
= line_offset
- DWARF_LINE_BASE
;
7629 current_line
= line_info
->dw_line_num
;
7630 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7631 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7632 "line %lu", current_line
);
7635 dw2_asm_output_data (1, DW_LNS_advance_line
,
7636 "advance to line %lu", current_line
);
7637 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7638 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7642 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7650 /* If we're done with a function, end its sequence. */
7651 if (lt_index
== separate_line_info_table_in_use
7652 || separate_line_info_table
[lt_index
].function
!= function
)
7657 /* Emit debug info for the address of the end of the function. */
7658 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7661 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7662 "DW_LNS_fixed_advance_pc");
7663 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7667 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7668 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7669 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7670 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7673 /* Output the marker for the end of this sequence. */
7674 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7675 dw2_asm_output_data_uleb128 (1, NULL
);
7676 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7680 /* Output the marker for the end of the line number info. */
7681 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7684 /* Given a pointer to a tree node for some base type, return a pointer to
7685 a DIE that describes the given type.
7687 This routine must only be called for GCC type nodes that correspond to
7688 Dwarf base (fundamental) types. */
7691 base_type_die (type
)
7694 dw_die_ref base_type_result
;
7695 const char *type_name
;
7696 enum dwarf_type encoding
;
7697 tree name
= TYPE_NAME (type
);
7699 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7704 if (TREE_CODE (name
) == TYPE_DECL
)
7705 name
= DECL_NAME (name
);
7707 type_name
= IDENTIFIER_POINTER (name
);
7710 type_name
= "__unknown__";
7712 switch (TREE_CODE (type
))
7715 /* Carefully distinguish the C character types, without messing
7716 up if the language is not C. Note that we check only for the names
7717 that contain spaces; other names might occur by coincidence in other
7719 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7720 && (type
== char_type_node
7721 || ! strcmp (type_name
, "signed char")
7722 || ! strcmp (type_name
, "unsigned char"))))
7724 if (TREE_UNSIGNED (type
))
7725 encoding
= DW_ATE_unsigned
;
7727 encoding
= DW_ATE_signed
;
7730 /* else fall through. */
7733 /* GNU Pascal/Ada CHAR type. Not used in C. */
7734 if (TREE_UNSIGNED (type
))
7735 encoding
= DW_ATE_unsigned_char
;
7737 encoding
= DW_ATE_signed_char
;
7741 encoding
= DW_ATE_float
;
7744 /* Dwarf2 doesn't know anything about complex ints, so use
7745 a user defined type for it. */
7747 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7748 encoding
= DW_ATE_complex_float
;
7750 encoding
= DW_ATE_lo_user
;
7754 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7755 encoding
= DW_ATE_boolean
;
7759 /* No other TREE_CODEs are Dwarf fundamental types. */
7763 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7764 if (demangle_name_func
)
7765 type_name
= (*demangle_name_func
) (type_name
);
7767 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7768 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7769 int_size_in_bytes (type
));
7770 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7772 return base_type_result
;
7775 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7776 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7777 a given type is generally the same as the given type, except that if the
7778 given type is a pointer or reference type, then the root type of the given
7779 type is the root type of the "basis" type for the pointer or reference
7780 type. (This definition of the "root" type is recursive.) Also, the root
7781 type of a `const' qualified type or a `volatile' qualified type is the
7782 root type of the given type without the qualifiers. */
7788 if (TREE_CODE (type
) == ERROR_MARK
)
7789 return error_mark_node
;
7791 switch (TREE_CODE (type
))
7794 return error_mark_node
;
7797 case REFERENCE_TYPE
:
7798 return type_main_variant (root_type (TREE_TYPE (type
)));
7801 return type_main_variant (type
);
7805 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7806 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7812 switch (TREE_CODE (type
))
7827 case QUAL_UNION_TYPE
:
7832 case REFERENCE_TYPE
:
7846 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7847 entry that chains various modifiers in front of the given type. */
7850 modified_type_die (type
, is_const_type
, is_volatile_type
, context_die
)
7853 int is_volatile_type
;
7854 dw_die_ref context_die
;
7856 enum tree_code code
= TREE_CODE (type
);
7857 dw_die_ref mod_type_die
= NULL
;
7858 dw_die_ref sub_die
= NULL
;
7859 tree item_type
= NULL
;
7861 if (code
!= ERROR_MARK
)
7863 tree qualified_type
;
7865 /* See if we already have the appropriately qualified variant of
7868 = get_qualified_type (type
,
7869 ((is_const_type
? TYPE_QUAL_CONST
: 0)
7871 ? TYPE_QUAL_VOLATILE
: 0)));
7873 /* If we do, then we can just use its DIE, if it exists. */
7876 mod_type_die
= lookup_type_die (qualified_type
);
7878 return mod_type_die
;
7881 /* Handle C typedef types. */
7882 if (qualified_type
&& TYPE_NAME (qualified_type
)
7883 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
7884 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
7886 tree type_name
= TYPE_NAME (qualified_type
);
7887 tree dtype
= TREE_TYPE (type_name
);
7889 if (qualified_type
== dtype
)
7891 /* For a named type, use the typedef. */
7892 gen_type_die (qualified_type
, context_die
);
7893 mod_type_die
= lookup_type_die (qualified_type
);
7895 else if (is_const_type
< TYPE_READONLY (dtype
)
7896 || is_volatile_type
< TYPE_VOLATILE (dtype
))
7897 /* cv-unqualified version of named type. Just use the unnamed
7898 type to which it refers. */
7900 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
7901 is_const_type
, is_volatile_type
,
7904 /* Else cv-qualified version of named type; fall through. */
7910 else if (is_const_type
)
7912 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
7913 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
7915 else if (is_volatile_type
)
7917 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
7918 sub_die
= modified_type_die (type
, 0, 0, context_die
);
7920 else if (code
== POINTER_TYPE
)
7922 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
7923 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7925 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7927 item_type
= TREE_TYPE (type
);
7929 else if (code
== REFERENCE_TYPE
)
7931 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
7932 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
7934 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
7936 item_type
= TREE_TYPE (type
);
7938 else if (is_base_type (type
))
7939 mod_type_die
= base_type_die (type
);
7942 gen_type_die (type
, context_die
);
7944 /* We have to get the type_main_variant here (and pass that to the
7945 `lookup_type_die' routine) because the ..._TYPE node we have
7946 might simply be a *copy* of some original type node (where the
7947 copy was created to help us keep track of typedef names) and
7948 that copy might have a different TYPE_UID from the original
7950 if (TREE_CODE (type
) != VECTOR_TYPE
)
7951 mod_type_die
= lookup_type_die (type_main_variant (type
));
7953 /* Vectors have the debugging information in the type,
7954 not the main variant. */
7955 mod_type_die
= lookup_type_die (type
);
7956 if (mod_type_die
== NULL
)
7960 /* We want to equate the qualified type to the die below. */
7961 type
= qualified_type
;
7965 equate_type_number_to_die (type
, mod_type_die
);
7967 /* We must do this after the equate_type_number_to_die call, in case
7968 this is a recursive type. This ensures that the modified_type_die
7969 recursion will terminate even if the type is recursive. Recursive
7970 types are possible in Ada. */
7971 sub_die
= modified_type_die (item_type
,
7972 TYPE_READONLY (item_type
),
7973 TYPE_VOLATILE (item_type
),
7976 if (sub_die
!= NULL
)
7977 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
7979 return mod_type_die
;
7982 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7983 an enumerated type. */
7989 return TREE_CODE (type
) == ENUMERAL_TYPE
;
7992 /* Return the register number described by a given RTL node. */
7998 unsigned regno
= REGNO (rtl
);
8000 if (regno
>= FIRST_PSEUDO_REGISTER
)
8003 return DBX_REGISTER_NUMBER (regno
);
8006 /* Return a location descriptor that designates a machine register or
8007 zero if there is no such. */
8009 static dw_loc_descr_ref
8010 reg_loc_descriptor (rtl
)
8013 dw_loc_descr_ref loc_result
= NULL
;
8016 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8019 reg
= reg_number (rtl
);
8021 loc_result
= new_loc_descr (DW_OP_reg0
+ reg
, 0, 0);
8023 loc_result
= new_loc_descr (DW_OP_regx
, reg
, 0);
8028 /* Return a location descriptor that designates a constant. */
8030 static dw_loc_descr_ref
8031 int_loc_descriptor (i
)
8034 enum dwarf_location_atom op
;
8036 /* Pick the smallest representation of a constant, rather than just
8037 defaulting to the LEB encoding. */
8041 op
= DW_OP_lit0
+ i
;
8044 else if (i
<= 0xffff)
8046 else if (HOST_BITS_PER_WIDE_INT
== 32
8056 else if (i
>= -0x8000)
8058 else if (HOST_BITS_PER_WIDE_INT
== 32
8059 || i
>= -0x80000000)
8065 return new_loc_descr (op
, i
, 0);
8068 /* Return a location descriptor that designates a base+offset location. */
8070 static dw_loc_descr_ref
8071 based_loc_descr (reg
, offset
)
8075 dw_loc_descr_ref loc_result
;
8076 /* For the "frame base", we use the frame pointer or stack pointer
8077 registers, since the RTL for local variables is relative to one of
8079 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8080 ? HARD_FRAME_POINTER_REGNUM
8081 : STACK_POINTER_REGNUM
);
8084 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8086 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8088 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8093 /* Return true if this RTL expression describes a base+offset calculation. */
8099 return (GET_CODE (rtl
) == PLUS
8100 && ((GET_CODE (XEXP (rtl
, 0)) == REG
8101 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8102 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8105 /* The following routine converts the RTL for a variable or parameter
8106 (resident in memory) into an equivalent Dwarf representation of a
8107 mechanism for getting the address of that same variable onto the top of a
8108 hypothetical "address evaluation" stack.
8110 When creating memory location descriptors, we are effectively transforming
8111 the RTL for a memory-resident object into its Dwarf postfix expression
8112 equivalent. This routine recursively descends an RTL tree, turning
8113 it into Dwarf postfix code as it goes.
8115 MODE is the mode of the memory reference, needed to handle some
8116 autoincrement addressing modes.
8118 Return 0 if we can't represent the location. */
8120 static dw_loc_descr_ref
8121 mem_loc_descriptor (rtl
, mode
)
8123 enum machine_mode mode
;
8125 dw_loc_descr_ref mem_loc_result
= NULL
;
8127 /* Note that for a dynamically sized array, the location we will generate a
8128 description of here will be the lowest numbered location which is
8129 actually within the array. That's *not* necessarily the same as the
8130 zeroth element of the array. */
8132 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8133 rtl
= ASM_SIMPLIFY_DWARF_ADDR (rtl
);
8136 switch (GET_CODE (rtl
))
8141 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8142 just fall into the SUBREG code. */
8144 /* ... fall through ... */
8147 /* The case of a subreg may arise when we have a local (register)
8148 variable or a formal (register) parameter which doesn't quite fill
8149 up an entire register. For now, just assume that it is
8150 legitimate to make the Dwarf info refer to the whole register which
8151 contains the given subreg. */
8152 rtl
= SUBREG_REG (rtl
);
8154 /* ... fall through ... */
8157 /* Whenever a register number forms a part of the description of the
8158 method for calculating the (dynamic) address of a memory resident
8159 object, DWARF rules require the register number be referred to as
8160 a "base register". This distinction is not based in any way upon
8161 what category of register the hardware believes the given register
8162 belongs to. This is strictly DWARF terminology we're dealing with
8163 here. Note that in cases where the location of a memory-resident
8164 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8165 OP_CONST (0)) the actual DWARF location descriptor that we generate
8166 may just be OP_BASEREG (basereg). This may look deceptively like
8167 the object in question was allocated to a register (rather than in
8168 memory) so DWARF consumers need to be aware of the subtle
8169 distinction between OP_REG and OP_BASEREG. */
8170 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8171 mem_loc_result
= based_loc_descr (reg_number (rtl
), 0);
8175 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8176 if (mem_loc_result
!= 0)
8177 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8181 /* Some ports can transform a symbol ref into a label ref, because
8182 the symbol ref is too far away and has to be dumped into a constant
8186 /* Alternatively, the symbol in the constant pool might be referenced
8187 by a different symbol. */
8188 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8191 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8193 if (GET_CODE (tmp
) == SYMBOL_REF
)
8196 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8197 get_pool_constant_mark (tmp
, &marked
);
8202 /* If all references to this pool constant were optimized away,
8203 it was not output and thus we can't represent it.
8204 FIXME: might try to use DW_OP_const_value here, though
8205 DW_OP_piece complicates it. */
8210 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8211 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8212 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8213 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8217 /* Extract the PLUS expression nested inside and fall into
8219 rtl
= XEXP (rtl
, 1);
8224 /* Turn these into a PLUS expression and fall into the PLUS code
8226 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8227 GEN_INT (GET_CODE (rtl
) == PRE_INC
8228 ? GET_MODE_UNIT_SIZE (mode
)
8229 : -GET_MODE_UNIT_SIZE (mode
)));
8231 /* ... fall through ... */
8235 if (is_based_loc (rtl
))
8236 mem_loc_result
= based_loc_descr (reg_number (XEXP (rtl
, 0)),
8237 INTVAL (XEXP (rtl
, 1)));
8240 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8241 if (mem_loc_result
== 0)
8244 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8245 && INTVAL (XEXP (rtl
, 1)) >= 0)
8246 add_loc_descr (&mem_loc_result
,
8247 new_loc_descr (DW_OP_plus_uconst
,
8248 INTVAL (XEXP (rtl
, 1)), 0));
8251 add_loc_descr (&mem_loc_result
,
8252 mem_loc_descriptor (XEXP (rtl
, 1), mode
));
8253 add_loc_descr (&mem_loc_result
,
8254 new_loc_descr (DW_OP_plus
, 0, 0));
8261 /* If a pseudo-reg is optimized away, it is possible for it to
8262 be replaced with a MEM containing a multiply. */
8263 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
);
8264 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
);
8266 if (op0
== 0 || op1
== 0)
8269 mem_loc_result
= op0
;
8270 add_loc_descr (&mem_loc_result
, op1
);
8271 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
8276 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8280 /* If this is a MEM, return its address. Otherwise, we can't
8282 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
8283 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
);
8291 return mem_loc_result
;
8294 /* Return a descriptor that describes the concatenation of two locations.
8295 This is typically a complex variable. */
8297 static dw_loc_descr_ref
8298 concat_loc_descriptor (x0
, x1
)
8301 dw_loc_descr_ref cc_loc_result
= NULL
;
8302 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
);
8303 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
);
8305 if (x0_ref
== 0 || x1_ref
== 0)
8308 cc_loc_result
= x0_ref
;
8309 add_loc_descr (&cc_loc_result
,
8310 new_loc_descr (DW_OP_piece
,
8311 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8313 add_loc_descr (&cc_loc_result
, x1_ref
);
8314 add_loc_descr (&cc_loc_result
,
8315 new_loc_descr (DW_OP_piece
,
8316 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8318 return cc_loc_result
;
8321 /* Output a proper Dwarf location descriptor for a variable or parameter
8322 which is either allocated in a register or in a memory location. For a
8323 register, we just generate an OP_REG and the register number. For a
8324 memory location we provide a Dwarf postfix expression describing how to
8325 generate the (dynamic) address of the object onto the address stack.
8327 If we don't know how to describe it, return 0. */
8329 static dw_loc_descr_ref
8330 loc_descriptor (rtl
)
8333 dw_loc_descr_ref loc_result
= NULL
;
8335 switch (GET_CODE (rtl
))
8338 /* The case of a subreg may arise when we have a local (register)
8339 variable or a formal (register) parameter which doesn't quite fill
8340 up an entire register. For now, just assume that it is
8341 legitimate to make the Dwarf info refer to the whole register which
8342 contains the given subreg. */
8343 rtl
= SUBREG_REG (rtl
);
8345 /* ... fall through ... */
8348 loc_result
= reg_loc_descriptor (rtl
);
8352 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
));
8356 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8366 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8367 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8368 looking for an address. Otherwise, we return a value. If we can't make a
8369 descriptor, return 0. */
8371 static dw_loc_descr_ref
8372 loc_descriptor_from_tree (loc
, addressp
)
8376 dw_loc_descr_ref ret
, ret1
;
8378 int unsignedp
= TREE_UNSIGNED (TREE_TYPE (loc
));
8379 enum dwarf_location_atom op
;
8381 /* ??? Most of the time we do not take proper care for sign/zero
8382 extending the values properly. Hopefully this won't be a real
8385 switch (TREE_CODE (loc
))
8390 case WITH_RECORD_EXPR
:
8391 case PLACEHOLDER_EXPR
:
8392 /* This case involves extracting fields from an object to determine the
8393 position of other fields. We don't try to encode this here. The
8394 only user of this is Ada, which encodes the needed information using
8395 the names of types. */
8402 /* We can support this only if we can look through conversions and
8403 find an INDIRECT_EXPR. */
8404 for (loc
= TREE_OPERAND (loc
, 0);
8405 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8406 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8407 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8408 || TREE_CODE (loc
) == SAVE_EXPR
;
8409 loc
= TREE_OPERAND (loc
, 0))
8412 return (TREE_CODE (loc
) == INDIRECT_REF
8413 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8417 if (DECL_THREAD_LOCAL (loc
))
8421 #ifndef ASM_OUTPUT_DWARF_DTPREL
8422 /* If this is not defined, we have no way to emit the data. */
8426 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8427 look up addresses of objects in the current module. */
8428 if (DECL_EXTERNAL (loc
))
8431 rtl
= rtl_for_decl_location (loc
);
8432 if (rtl
== NULL_RTX
)
8435 if (GET_CODE (rtl
) != MEM
)
8437 rtl
= XEXP (rtl
, 0);
8438 if (! CONSTANT_P (rtl
))
8441 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8442 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8443 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8445 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8446 add_loc_descr (&ret
, ret1
);
8455 rtx rtl
= rtl_for_decl_location (loc
);
8457 if (rtl
== NULL_RTX
)
8459 else if (CONSTANT_P (rtl
))
8461 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8462 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8463 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8468 enum machine_mode mode
= GET_MODE (rtl
);
8470 if (GET_CODE (rtl
) == MEM
)
8473 rtl
= XEXP (rtl
, 0);
8476 ret
= mem_loc_descriptor (rtl
, mode
);
8482 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8487 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8491 case NON_LVALUE_EXPR
:
8492 case VIEW_CONVERT_EXPR
:
8494 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8499 case ARRAY_RANGE_REF
:
8502 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8503 enum machine_mode mode
;
8506 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8507 &unsignedp
, &volatilep
);
8512 ret
= loc_descriptor_from_tree (obj
, 1);
8514 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8517 if (offset
!= NULL_TREE
)
8519 /* Variable offset. */
8520 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8521 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8527 bytepos
= bitpos
/ BITS_PER_UNIT
;
8529 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8530 else if (bytepos
< 0)
8532 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8533 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8539 if (host_integerp (loc
, 0))
8540 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8545 case TRUTH_AND_EXPR
:
8546 case TRUTH_ANDIF_EXPR
:
8551 case TRUTH_XOR_EXPR
:
8557 case TRUTH_ORIF_EXPR
:
8562 case TRUNC_DIV_EXPR
:
8570 case TRUNC_MOD_EXPR
:
8583 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8587 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8588 && host_integerp (TREE_OPERAND (loc
, 1), 0))
8590 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8594 add_loc_descr (&ret
,
8595 new_loc_descr (DW_OP_plus_uconst
,
8596 tree_low_cst (TREE_OPERAND (loc
, 1),
8606 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8613 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8620 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8627 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
8642 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8643 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8644 if (ret
== 0 || ret1
== 0)
8647 add_loc_descr (&ret
, ret1
);
8648 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8651 case TRUTH_NOT_EXPR
:
8665 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8669 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
8673 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
8674 build (LT_EXPR
, integer_type_node
,
8675 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
8676 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
8678 /* ... fall through ... */
8682 dw_loc_descr_ref lhs
8683 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
8684 dw_loc_descr_ref rhs
8685 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
8686 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
8688 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8689 if (ret
== 0 || lhs
== 0 || rhs
== 0)
8692 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
8693 add_loc_descr (&ret
, bra_node
);
8695 add_loc_descr (&ret
, rhs
);
8696 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
8697 add_loc_descr (&ret
, jump_node
);
8699 add_loc_descr (&ret
, lhs
);
8700 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8701 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
8703 /* ??? Need a node to point the skip at. Use a nop. */
8704 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
8705 add_loc_descr (&ret
, tmp
);
8706 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
8707 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
8715 /* Show if we can't fill the request for an address. */
8716 if (addressp
&& indirect_p
== 0)
8719 /* If we've got an address and don't want one, dereference. */
8720 if (!addressp
&& indirect_p
> 0)
8722 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
8724 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
8726 else if (size
== DWARF2_ADDR_SIZE
)
8729 op
= DW_OP_deref_size
;
8731 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
8737 /* Given a value, round it up to the lowest multiple of `boundary'
8738 which is not less than the value itself. */
8740 static inline HOST_WIDE_INT
8741 ceiling (value
, boundary
)
8742 HOST_WIDE_INT value
;
8743 unsigned int boundary
;
8745 return (((value
+ boundary
- 1) / boundary
) * boundary
);
8748 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8749 pointer to the declared type for the relevant field variable, or return
8750 `integer_type_node' if the given node turns out to be an
8759 if (TREE_CODE (decl
) == ERROR_MARK
)
8760 return integer_type_node
;
8762 type
= DECL_BIT_FIELD_TYPE (decl
);
8763 if (type
== NULL_TREE
)
8764 type
= TREE_TYPE (decl
);
8769 /* Given a pointer to a tree node, return the alignment in bits for
8770 it, or else return BITS_PER_WORD if the node actually turns out to
8771 be an ERROR_MARK node. */
8773 static inline unsigned
8774 simple_type_align_in_bits (type
)
8777 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
8780 static inline unsigned
8781 simple_decl_align_in_bits (decl
)
8784 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
8787 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8788 node, return the size in bits for the type if it is a constant, or else
8789 return the alignment for the type if the type's size is not constant, or
8790 else return BITS_PER_WORD if the type actually turns out to be an
8793 static inline unsigned HOST_WIDE_INT
8794 simple_type_size_in_bits (type
)
8798 if (TREE_CODE (type
) == ERROR_MARK
)
8799 return BITS_PER_WORD
;
8800 else if (TYPE_SIZE (type
) == NULL_TREE
)
8802 else if (host_integerp (TYPE_SIZE (type
), 1))
8803 return tree_low_cst (TYPE_SIZE (type
), 1);
8805 return TYPE_ALIGN (type
);
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 ASM_OUTPUT_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 ASM_OUTPUT_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 /* Remember the name of the primary input file. */
12431 primary_filename
= main_input_filename
;
12433 /* Add it to the file table first, under the assumption that we'll
12434 be emitting line number data for it first, which avoids having
12435 to add an initial DW_LNS_set_file. */
12436 lookup_filename (main_input_filename
);
12438 /* Allocate the initial hunk of the decl_die_table. */
12440 = (dw_die_ref
*) xcalloc (DECL_DIE_TABLE_INCREMENT
, sizeof (dw_die_ref
));
12441 decl_die_table_allocated
= DECL_DIE_TABLE_INCREMENT
;
12442 decl_die_table_in_use
= 0;
12444 /* Allocate the initial hunk of the decl_scope_table. */
12445 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
12447 /* Allocate the initial hunk of the abbrev_die_table. */
12449 = (dw_die_ref
*) xcalloc (ABBREV_DIE_TABLE_INCREMENT
,
12450 sizeof (dw_die_ref
));
12451 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
12452 /* Zero-th entry is allocated, but unused */
12453 abbrev_die_table_in_use
= 1;
12455 /* Allocate the initial hunk of the line_info_table. */
12457 = (dw_line_info_ref
) xcalloc (LINE_INFO_TABLE_INCREMENT
,
12458 sizeof (dw_line_info_entry
));
12459 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
12461 /* Zero-th entry is allocated, but unused */
12462 line_info_table_in_use
= 1;
12464 /* Generate the initial DIE for the .debug section. Note that the (string)
12465 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12466 will (typically) be a relative pathname and that this pathname should be
12467 taken as being relative to the directory from which the compiler was
12468 invoked when the given (base) source file was compiled. */
12469 comp_unit_die
= gen_compile_unit_die (main_input_filename
);
12470 is_main_source
= 1;
12472 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
12474 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
12476 ggc_add_root (&limbo_die_list
, 1, 1, mark_limbo_die_list
);
12478 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
12479 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
12480 DEBUG_ABBREV_SECTION_LABEL
, 0);
12481 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12482 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
12484 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
12486 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
12487 DEBUG_INFO_SECTION_LABEL
, 0);
12488 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
12489 DEBUG_LINE_SECTION_LABEL
, 0);
12490 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
12491 DEBUG_RANGES_SECTION_LABEL
, 0);
12492 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12493 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
12494 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
12495 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
12496 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12497 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
12499 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12501 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12502 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
12503 DEBUG_MACINFO_SECTION_LABEL
, 0);
12504 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
12507 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
12510 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
12514 /* Allocate a string in .debug_str hash table. */
12517 indirect_string_alloc (tab
)
12518 hash_table
*tab ATTRIBUTE_UNUSED
;
12520 struct indirect_string_node
*node
;
12522 node
= xmalloc (sizeof (struct indirect_string_node
));
12523 node
->refcount
= 0;
12525 node
->label
= NULL
;
12527 return (hashnode
) node
;
12530 /* A helper function for dwarf2out_finish called through
12531 ht_forall. Emit one queued .debug_str string. */
12534 output_indirect_string (pfile
, h
, v
)
12535 struct cpp_reader
*pfile ATTRIBUTE_UNUSED
;
12537 const PTR v ATTRIBUTE_UNUSED
;
12539 struct indirect_string_node
*node
= (struct indirect_string_node
*) h
;
12541 if (node
->form
== DW_FORM_strp
)
12543 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
12544 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
12545 assemble_string ((const char *) HT_STR (&node
->id
),
12546 HT_LEN (&node
->id
) + 1);
12552 /* Output stuff that dwarf requires at the end of every file,
12553 and generate the DWARF-2 debugging info. */
12556 dwarf2out_finish (input_filename
)
12557 const char *input_filename ATTRIBUTE_UNUSED
;
12559 limbo_die_node
*node
, *next_node
;
12560 dw_die_ref die
= 0;
12562 /* Traverse the limbo die list, and add parent/child links. The only
12563 dies without parents that should be here are concrete instances of
12564 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12565 For concrete instances, we can get the parent die from the abstract
12567 for (node
= limbo_die_list
; node
; node
= next_node
)
12569 next_node
= node
->next
;
12572 if (die
->die_parent
== NULL
)
12574 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
12578 add_child_die (origin
->die_parent
, die
);
12579 else if (die
== comp_unit_die
)
12581 /* If this was an expression for a bound involved in a function
12582 return type, it may be a SAVE_EXPR for which we weren't able
12583 to find a DIE previously. So try now. */
12584 else if (node
->created_for
12585 && TREE_CODE (node
->created_for
) == SAVE_EXPR
12586 && 0 != (origin
= (lookup_decl_die
12588 (node
->created_for
)))))
12589 add_child_die (origin
, die
);
12590 else if (errorcount
> 0 || sorrycount
> 0)
12591 /* It's OK to be confused by errors in the input. */
12592 add_child_die (comp_unit_die
, die
);
12593 else if (node
->created_for
12594 && ((DECL_P (node
->created_for
)
12595 && (context
= DECL_CONTEXT (node
->created_for
)))
12596 || (TYPE_P (node
->created_for
)
12597 && (context
= TYPE_CONTEXT (node
->created_for
))))
12598 && TREE_CODE (context
) == FUNCTION_DECL
)
12600 /* In certain situations, the lexical block containing a
12601 nested function can be optimized away, which results
12602 in the nested function die being orphaned. Likewise
12603 with the return type of that nested function. Force
12604 this to be a child of the containing function. */
12605 origin
= lookup_decl_die (context
);
12608 add_child_die (origin
, die
);
12617 limbo_die_list
= NULL
;
12619 /* Walk through the list of incomplete types again, trying once more to
12620 emit full debugging info for them. */
12621 retry_incomplete_types ();
12623 /* We need to reverse all the dies before break_out_includes, or
12624 we'll see the end of an include file before the beginning. */
12625 reverse_all_dies (comp_unit_die
);
12627 /* Generate separate CUs for each of the include files we've seen.
12628 They will go into limbo_die_list. */
12629 if (flag_eliminate_dwarf2_dups
)
12630 break_out_includes (comp_unit_die
);
12632 /* Traverse the DIE's and add add sibling attributes to those DIE's
12633 that have children. */
12634 add_sibling_attributes (comp_unit_die
);
12635 for (node
= limbo_die_list
; node
; node
= node
->next
)
12636 add_sibling_attributes (node
->die
);
12638 /* Output a terminator label for the .text section. */
12640 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, TEXT_END_LABEL
, 0);
12642 /* Output the source line correspondence table. We must do this
12643 even if there is no line information. Otherwise, on an empty
12644 translation unit, we will generate a present, but empty,
12645 .debug_info section. IRIX 6.5 `nm' will then complain when
12646 examining the file. */
12647 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
12649 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
12650 output_line_info ();
12653 /* Output location list section if necessary. */
12654 if (have_location_lists
)
12656 /* Output the location lists info. */
12657 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
12658 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
12659 DEBUG_LOC_SECTION_LABEL
, 0);
12660 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
12661 output_location_lists (die
);
12662 have_location_lists
= 0;
12665 /* We can only use the low/high_pc attributes if all of the code was
12667 if (separate_line_info_table_in_use
== 0)
12669 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
12670 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
12673 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12674 "base address". Use zero so that these addresses become absolute. */
12675 else if (have_location_lists
|| ranges_table_in_use
)
12676 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
12678 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12679 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
12680 debug_line_section_label
);
12682 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12683 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
12685 /* Output all of the compilation units. We put the main one last so that
12686 the offsets are available to output_pubnames. */
12687 for (node
= limbo_die_list
; node
; node
= node
->next
)
12688 output_comp_unit (node
->die
, 0);
12690 output_comp_unit (comp_unit_die
, 0);
12692 /* Output the abbreviation table. */
12693 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
12694 output_abbrev_section ();
12696 /* Output public names table if necessary. */
12697 if (pubname_table_in_use
)
12699 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
12700 output_pubnames ();
12703 /* Output the address range information. We only put functions in the arange
12704 table, so don't write it out if we don't have any. */
12705 if (fde_table_in_use
)
12707 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
12711 /* Output ranges section if necessary. */
12712 if (ranges_table_in_use
)
12714 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
12715 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
12719 /* Have to end the primary source file. */
12720 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
12722 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
12723 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
12724 dw2_asm_output_data (1, 0, "End compilation unit");
12727 /* If we emitted any DW_FORM_strp form attribute, output the string
12729 if (debug_str_hash
)
12730 ht_forall (debug_str_hash
, output_indirect_string
, NULL
);
12734 /* This should never be used, but its address is needed for comparisons. */
12735 const struct gcc_debug_hooks dwarf2_debug_hooks
;
12737 #endif /* DWARF2_DEBUGGING_INFO */
12739 #include "gt-dwarf2out.h"