1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* TODO: Emit .debug_line header even when there are no functions, since
26 the file numbers are used by .debug_info. Alternately, leave
27 out locations for types and decls.
28 Avoid talking about ctors and op= for PODs.
29 Factor out common prologue sequences into multiple CIEs. */
31 /* The first part of this file deals with the DWARF 2 frame unwind
32 information, which is also used by the GCC efficient exception handling
33 mechanism. The second part, controlled only by an #ifdef
34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
39 #include "coretypes.h"
46 #include "hard-reg-set.h"
48 #include "insn-config.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
63 #include "diagnostic.h"
66 #include "langhooks.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 /* Decide whether we want to emit frame unwind information for the current
97 dwarf2out_do_frame (void)
99 return (write_symbols
== DWARF2_DEBUG
100 || write_symbols
== VMS_AND_DWARF2_DEBUG
101 #ifdef DWARF2_FRAME_INFO
104 #ifdef DWARF2_UNWIND_INFO
105 || flag_unwind_tables
106 || (flag_exceptions
&& ! USING_SJLJ_EXCEPTIONS
)
111 /* The size of the target's pointer type. */
113 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
116 /* Various versions of targetm.eh_frame_section. Note these must appear
117 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
119 /* Version of targetm.eh_frame_section for systems with named sections. */
121 named_section_eh_frame_section (void)
123 #ifdef EH_FRAME_SECTION_NAME
124 #ifdef HAVE_LD_RO_RW_SECTION_MIXING
125 int fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
126 int per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
127 int lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
131 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
132 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
133 && (per_encoding
& 0x70) != DW_EH_PE_absptr
134 && (per_encoding
& 0x70) != DW_EH_PE_aligned
135 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
136 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
138 named_section_flags (EH_FRAME_SECTION_NAME
, flags
);
140 named_section_flags (EH_FRAME_SECTION_NAME
, SECTION_WRITE
);
145 /* Version of targetm.eh_frame_section for systems using collect2. */
147 collect2_eh_frame_section (void)
149 tree label
= get_file_function_name ('F');
152 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
153 targetm
.asm_out
.globalize_label (asm_out_file
, IDENTIFIER_POINTER (label
));
154 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
157 /* Default version of targetm.eh_frame_section. */
159 default_eh_frame_section (void)
161 #ifdef EH_FRAME_SECTION_NAME
162 named_section_eh_frame_section ();
164 collect2_eh_frame_section ();
168 /* Array of RTXes referenced by the debugging information, which therefore
169 must be kept around forever. */
170 static GTY(()) varray_type used_rtx_varray
;
172 /* A pointer to the base of a list of incomplete types which might be
173 completed at some later time. incomplete_types_list needs to be a VARRAY
174 because we want to tell the garbage collector about it. */
175 static GTY(()) varray_type incomplete_types
;
177 /* A pointer to the base of a table of references to declaration
178 scopes. This table is a display which tracks the nesting
179 of declaration scopes at the current scope and containing
180 scopes. This table is used to find the proper place to
181 define type declaration DIE's. */
182 static GTY(()) varray_type decl_scope_table
;
184 /* How to start an assembler comment. */
185 #ifndef ASM_COMMENT_START
186 #define ASM_COMMENT_START ";#"
189 typedef struct dw_cfi_struct
*dw_cfi_ref
;
190 typedef struct dw_fde_struct
*dw_fde_ref
;
191 typedef union dw_cfi_oprnd_struct
*dw_cfi_oprnd_ref
;
193 /* Call frames are described using a sequence of Call Frame
194 Information instructions. The register number, offset
195 and address fields are provided as possible operands;
196 their use is selected by the opcode field. */
198 enum dw_cfi_oprnd_type
{
200 dw_cfi_oprnd_reg_num
,
206 typedef union dw_cfi_oprnd_struct
GTY(())
208 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num
;
209 HOST_WIDE_INT
GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset
;
210 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr
;
211 struct dw_loc_descr_struct
* GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc
;
215 typedef struct dw_cfi_struct
GTY(())
217 dw_cfi_ref dw_cfi_next
;
218 enum dwarf_call_frame_info dw_cfi_opc
;
219 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
221 dw_cfi_oprnd
GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
226 /* This is how we define the location of the CFA. We use to handle it
227 as REG + OFFSET all the time, but now it can be more complex.
228 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
229 Instead of passing around REG and OFFSET, we pass a copy
230 of this structure. */
231 typedef struct cfa_loc
GTY(())
234 HOST_WIDE_INT offset
;
235 HOST_WIDE_INT base_offset
;
236 int indirect
; /* 1 if CFA is accessed via a dereference. */
239 /* All call frame descriptions (FDE's) in the GCC generated DWARF
240 refer to a single Common Information Entry (CIE), defined at
241 the beginning of the .debug_frame section. This use of a single
242 CIE obviates the need to keep track of multiple CIE's
243 in the DWARF generation routines below. */
245 typedef struct dw_fde_struct
GTY(())
248 const char *dw_fde_begin
;
249 const char *dw_fde_current_label
;
250 const char *dw_fde_end
;
251 dw_cfi_ref dw_fde_cfi
;
252 unsigned funcdef_number
;
253 unsigned all_throwers_are_sibcalls
: 1;
254 unsigned nothrow
: 1;
255 unsigned uses_eh_lsda
: 1;
259 /* Maximum size (in bytes) of an artificially generated label. */
260 #define MAX_ARTIFICIAL_LABEL_BYTES 30
262 /* The size of addresses as they appear in the Dwarf 2 data.
263 Some architectures use word addresses to refer to code locations,
264 but Dwarf 2 info always uses byte addresses. On such machines,
265 Dwarf 2 addresses need to be larger than the architecture's
267 #ifndef DWARF2_ADDR_SIZE
268 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
271 /* The size in bytes of a DWARF field indicating an offset or length
272 relative to a debug info section, specified to be 4 bytes in the
273 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
276 #ifndef DWARF_OFFSET_SIZE
277 #define DWARF_OFFSET_SIZE 4
280 /* According to the (draft) DWARF 3 specification, the initial length
281 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
282 bytes are 0xffffffff, followed by the length stored in the next 8
285 However, the SGI/MIPS ABI uses an initial length which is equal to
286 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
288 #ifndef DWARF_INITIAL_LENGTH_SIZE
289 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
292 #define DWARF_VERSION 2
294 /* Round SIZE up to the nearest BOUNDARY. */
295 #define DWARF_ROUND(SIZE,BOUNDARY) \
296 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
298 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
299 #ifndef DWARF_CIE_DATA_ALIGNMENT
300 #ifdef STACK_GROWS_DOWNWARD
301 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
303 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
307 /* A pointer to the base of a table that contains frame description
308 information for each routine. */
309 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table
;
311 /* Number of elements currently allocated for fde_table. */
312 static GTY(()) unsigned fde_table_allocated
;
314 /* Number of elements in fde_table currently in use. */
315 static GTY(()) unsigned fde_table_in_use
;
317 /* Size (in elements) of increments by which we may expand the
319 #define FDE_TABLE_INCREMENT 256
321 /* A list of call frame insns for the CIE. */
322 static GTY(()) dw_cfi_ref cie_cfi_head
;
324 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
325 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
326 attribute that accelerates the lookup of the FDE associated
327 with the subprogram. This variable holds the table index of the FDE
328 associated with the current function (body) definition. */
329 static unsigned current_funcdef_fde
;
332 struct indirect_string_node
GTY(())
335 unsigned int refcount
;
340 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
342 static GTY(()) int dw2_string_counter
;
343 static GTY(()) unsigned long dwarf2out_cfi_label_num
;
345 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
347 /* Forward declarations for functions defined in this file. */
349 static char *stripattributes (const char *);
350 static const char *dwarf_cfi_name (unsigned);
351 static dw_cfi_ref
new_cfi (void);
352 static void add_cfi (dw_cfi_ref
*, dw_cfi_ref
);
353 static void add_fde_cfi (const char *, dw_cfi_ref
);
354 static void lookup_cfa_1 (dw_cfi_ref
, dw_cfa_location
*);
355 static void lookup_cfa (dw_cfa_location
*);
356 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT
);
357 static void initial_return_save (rtx
);
358 static HOST_WIDE_INT
stack_adjust_offset (rtx
);
359 static void output_cfi (dw_cfi_ref
, dw_fde_ref
, int);
360 static void output_call_frame_info (int);
361 static void dwarf2out_stack_adjust (rtx
);
362 static void queue_reg_save (const char *, rtx
, HOST_WIDE_INT
);
363 static void flush_queued_reg_saves (void);
364 static bool clobbers_queued_reg_save (rtx
);
365 static void dwarf2out_frame_debug_expr (rtx
, const char *);
367 /* Support for complex CFA locations. */
368 static void output_cfa_loc (dw_cfi_ref
);
369 static void get_cfa_from_loc_descr (dw_cfa_location
*,
370 struct dw_loc_descr_struct
*);
371 static struct dw_loc_descr_struct
*build_cfa_loc
373 static void def_cfa_1 (const char *, dw_cfa_location
*);
375 /* How to start an assembler comment. */
376 #ifndef ASM_COMMENT_START
377 #define ASM_COMMENT_START ";#"
380 /* Data and reference forms for relocatable data. */
381 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
382 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
384 #ifndef DEBUG_FRAME_SECTION
385 #define DEBUG_FRAME_SECTION ".debug_frame"
388 #ifndef FUNC_BEGIN_LABEL
389 #define FUNC_BEGIN_LABEL "LFB"
392 #ifndef FUNC_END_LABEL
393 #define FUNC_END_LABEL "LFE"
396 #ifndef FRAME_BEGIN_LABEL
397 #define FRAME_BEGIN_LABEL "Lframe"
399 #define CIE_AFTER_SIZE_LABEL "LSCIE"
400 #define CIE_END_LABEL "LECIE"
401 #define FDE_LABEL "LSFDE"
402 #define FDE_AFTER_SIZE_LABEL "LASFDE"
403 #define FDE_END_LABEL "LEFDE"
404 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
405 #define LINE_NUMBER_END_LABEL "LELT"
406 #define LN_PROLOG_AS_LABEL "LASLTP"
407 #define LN_PROLOG_END_LABEL "LELTP"
408 #define DIE_LABEL_PREFIX "DW"
410 /* The DWARF 2 CFA column which tracks the return address. Normally this
411 is the column for PC, or the first column after all of the hard
413 #ifndef DWARF_FRAME_RETURN_COLUMN
415 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
417 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
421 /* The mapping from gcc register number to DWARF 2 CFA column number. By
422 default, we just provide columns for all registers. */
423 #ifndef DWARF_FRAME_REGNUM
424 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
427 /* The offset from the incoming value of %sp to the top of the stack frame
428 for the current function. */
429 #ifndef INCOMING_FRAME_SP_OFFSET
430 #define INCOMING_FRAME_SP_OFFSET 0
433 /* Hook used by __throw. */
436 expand_builtin_dwarf_sp_column (void)
438 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
441 /* Return a pointer to a copy of the section string name S with all
442 attributes stripped off, and an asterisk prepended (for assemble_name). */
445 stripattributes (const char *s
)
447 char *stripped
= xmalloc (strlen (s
) + 2);
452 while (*s
&& *s
!= ',')
459 /* Generate code to initialize the register size table. */
462 expand_builtin_init_dwarf_reg_sizes (tree address
)
465 enum machine_mode mode
= TYPE_MODE (char_type_node
);
466 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
467 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
468 bool wrote_return_column
= false;
470 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
471 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
473 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
474 enum machine_mode save_mode
= reg_raw_mode
[i
];
477 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
478 save_mode
= choose_hard_reg_mode (i
, 1, true);
479 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
481 if (save_mode
== VOIDmode
)
483 wrote_return_column
= true;
485 size
= GET_MODE_SIZE (save_mode
);
489 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
492 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
493 if (! wrote_return_column
)
495 i
= DWARF_ALT_FRAME_RETURN_COLUMN
;
496 wrote_return_column
= false;
498 i
= DWARF_FRAME_RETURN_COLUMN
;
501 if (! wrote_return_column
)
503 enum machine_mode save_mode
= Pmode
;
504 HOST_WIDE_INT offset
= i
* GET_MODE_SIZE (mode
);
505 HOST_WIDE_INT size
= GET_MODE_SIZE (save_mode
);
506 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
510 /* Convert a DWARF call frame info. operation to its string name */
513 dwarf_cfi_name (unsigned int cfi_opc
)
517 case DW_CFA_advance_loc
:
518 return "DW_CFA_advance_loc";
520 return "DW_CFA_offset";
522 return "DW_CFA_restore";
526 return "DW_CFA_set_loc";
527 case DW_CFA_advance_loc1
:
528 return "DW_CFA_advance_loc1";
529 case DW_CFA_advance_loc2
:
530 return "DW_CFA_advance_loc2";
531 case DW_CFA_advance_loc4
:
532 return "DW_CFA_advance_loc4";
533 case DW_CFA_offset_extended
:
534 return "DW_CFA_offset_extended";
535 case DW_CFA_restore_extended
:
536 return "DW_CFA_restore_extended";
537 case DW_CFA_undefined
:
538 return "DW_CFA_undefined";
539 case DW_CFA_same_value
:
540 return "DW_CFA_same_value";
541 case DW_CFA_register
:
542 return "DW_CFA_register";
543 case DW_CFA_remember_state
:
544 return "DW_CFA_remember_state";
545 case DW_CFA_restore_state
:
546 return "DW_CFA_restore_state";
548 return "DW_CFA_def_cfa";
549 case DW_CFA_def_cfa_register
:
550 return "DW_CFA_def_cfa_register";
551 case DW_CFA_def_cfa_offset
:
552 return "DW_CFA_def_cfa_offset";
555 case DW_CFA_def_cfa_expression
:
556 return "DW_CFA_def_cfa_expression";
557 case DW_CFA_expression
:
558 return "DW_CFA_expression";
559 case DW_CFA_offset_extended_sf
:
560 return "DW_CFA_offset_extended_sf";
561 case DW_CFA_def_cfa_sf
:
562 return "DW_CFA_def_cfa_sf";
563 case DW_CFA_def_cfa_offset_sf
:
564 return "DW_CFA_def_cfa_offset_sf";
566 /* SGI/MIPS specific */
567 case DW_CFA_MIPS_advance_loc8
:
568 return "DW_CFA_MIPS_advance_loc8";
571 case DW_CFA_GNU_window_save
:
572 return "DW_CFA_GNU_window_save";
573 case DW_CFA_GNU_args_size
:
574 return "DW_CFA_GNU_args_size";
575 case DW_CFA_GNU_negative_offset_extended
:
576 return "DW_CFA_GNU_negative_offset_extended";
579 return "DW_CFA_<unknown>";
583 /* Return a pointer to a newly allocated Call Frame Instruction. */
585 static inline dw_cfi_ref
588 dw_cfi_ref cfi
= ggc_alloc (sizeof (dw_cfi_node
));
590 cfi
->dw_cfi_next
= NULL
;
591 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
592 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
597 /* Add a Call Frame Instruction to list of instructions. */
600 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
604 /* Find the end of the chain. */
605 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
611 /* Generate a new label for the CFI info to refer to. */
614 dwarf2out_cfi_label (void)
616 static char label
[20];
618 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
619 ASM_OUTPUT_LABEL (asm_out_file
, label
);
623 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
624 or to the CIE if LABEL is NULL. */
627 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
631 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
634 label
= dwarf2out_cfi_label ();
636 if (fde
->dw_fde_current_label
== NULL
637 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
641 fde
->dw_fde_current_label
= label
= xstrdup (label
);
643 /* Set the location counter to the new label. */
645 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
646 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
647 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
650 add_cfi (&fde
->dw_fde_cfi
, cfi
);
654 add_cfi (&cie_cfi_head
, cfi
);
657 /* Subroutine of lookup_cfa. */
660 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
662 switch (cfi
->dw_cfi_opc
)
664 case DW_CFA_def_cfa_offset
:
665 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
667 case DW_CFA_def_cfa_register
:
668 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
671 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
672 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
674 case DW_CFA_def_cfa_expression
:
675 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
682 /* Find the previous value for the CFA. */
685 lookup_cfa (dw_cfa_location
*loc
)
689 loc
->reg
= (unsigned long) -1;
692 loc
->base_offset
= 0;
694 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
695 lookup_cfa_1 (cfi
, loc
);
697 if (fde_table_in_use
)
699 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
700 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
701 lookup_cfa_1 (cfi
, loc
);
705 /* The current rule for calculating the DWARF2 canonical frame address. */
706 static dw_cfa_location cfa
;
708 /* The register used for saving registers to the stack, and its offset
710 static dw_cfa_location cfa_store
;
712 /* The running total of the size of arguments pushed onto the stack. */
713 static HOST_WIDE_INT args_size
;
715 /* The last args_size we actually output. */
716 static HOST_WIDE_INT old_args_size
;
718 /* Entry point to update the canonical frame address (CFA).
719 LABEL is passed to add_fde_cfi. The value of CFA is now to be
720 calculated from REG+OFFSET. */
723 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
730 def_cfa_1 (label
, &loc
);
733 /* This routine does the actual work. The CFA is now calculated from
734 the dw_cfa_location structure. */
737 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
740 dw_cfa_location old_cfa
, loc
;
745 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
746 cfa_store
.offset
= loc
.offset
;
748 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
749 lookup_cfa (&old_cfa
);
751 /* If nothing changed, no need to issue any call frame instructions. */
752 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
753 && loc
.indirect
== old_cfa
.indirect
754 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
759 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
761 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
762 indicating the CFA register did not change but the offset
764 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
765 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
768 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
769 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
772 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
773 indicating the CFA register has changed to <register> but the
774 offset has not changed. */
775 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
776 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
780 else if (loc
.indirect
== 0)
782 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
783 indicating the CFA register has changed to <register> with
784 the specified offset. */
785 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
786 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
787 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
791 /* Construct a DW_CFA_def_cfa_expression instruction to
792 calculate the CFA using a full location expression since no
793 register-offset pair is available. */
794 struct dw_loc_descr_struct
*loc_list
;
796 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
797 loc_list
= build_cfa_loc (&loc
);
798 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
801 add_fde_cfi (label
, cfi
);
804 /* Add the CFI for saving a register. REG is the CFA column number.
805 LABEL is passed to add_fde_cfi.
806 If SREG is -1, the register is saved at OFFSET from the CFA;
807 otherwise it is saved in SREG. */
810 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
812 dw_cfi_ref cfi
= new_cfi ();
814 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
816 /* The following comparison is correct. -1 is used to indicate that
817 the value isn't a register number. */
818 if (sreg
== (unsigned int) -1)
821 /* The register number won't fit in 6 bits, so we have to use
823 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
825 cfi
->dw_cfi_opc
= DW_CFA_offset
;
827 #ifdef ENABLE_CHECKING
829 /* If we get an offset that is not a multiple of
830 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
831 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
833 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
835 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
839 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
841 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
843 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
845 else if (sreg
== reg
)
846 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
850 cfi
->dw_cfi_opc
= DW_CFA_register
;
851 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
854 add_fde_cfi (label
, cfi
);
857 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
858 This CFI tells the unwinder that it needs to restore the window registers
859 from the previous frame's window save area.
861 ??? Perhaps we should note in the CIE where windows are saved (instead of
862 assuming 0(cfa)) and what registers are in the window. */
865 dwarf2out_window_save (const char *label
)
867 dw_cfi_ref cfi
= new_cfi ();
869 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
870 add_fde_cfi (label
, cfi
);
873 /* Add a CFI to update the running total of the size of arguments
874 pushed onto the stack. */
877 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
881 if (size
== old_args_size
)
884 old_args_size
= size
;
887 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
888 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
889 add_fde_cfi (label
, cfi
);
892 /* Entry point for saving a register to the stack. REG is the GCC register
893 number. LABEL and OFFSET are passed to reg_save. */
896 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
898 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
901 /* Entry point for saving the return address in the stack.
902 LABEL and OFFSET are passed to reg_save. */
905 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
907 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
910 /* Entry point for saving the return address in a register.
911 LABEL and SREG are passed to reg_save. */
914 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
916 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
919 /* Record the initial position of the return address. RTL is
920 INCOMING_RETURN_ADDR_RTX. */
923 initial_return_save (rtx rtl
)
925 unsigned int reg
= (unsigned int) -1;
926 HOST_WIDE_INT offset
= 0;
928 switch (GET_CODE (rtl
))
931 /* RA is in a register. */
932 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
936 /* RA is on the stack. */
938 switch (GET_CODE (rtl
))
941 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
947 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
949 offset
= INTVAL (XEXP (rtl
, 1));
953 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
955 offset
= -INTVAL (XEXP (rtl
, 1));
965 /* The return address is at some offset from any value we can
966 actually load. For instance, on the SPARC it is in %i7+8. Just
967 ignore the offset for now; it doesn't matter for unwinding frames. */
968 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
970 initial_return_save (XEXP (rtl
, 0));
977 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
980 /* Given a SET, calculate the amount of stack adjustment it
984 stack_adjust_offset (rtx pattern
)
986 rtx src
= SET_SRC (pattern
);
987 rtx dest
= SET_DEST (pattern
);
988 HOST_WIDE_INT offset
= 0;
991 if (dest
== stack_pointer_rtx
)
993 /* (set (reg sp) (plus (reg sp) (const_int))) */
994 code
= GET_CODE (src
);
995 if (! (code
== PLUS
|| code
== MINUS
)
996 || XEXP (src
, 0) != stack_pointer_rtx
997 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1000 offset
= INTVAL (XEXP (src
, 1));
1004 else if (GET_CODE (dest
) == MEM
)
1006 /* (set (mem (pre_dec (reg sp))) (foo)) */
1007 src
= XEXP (dest
, 0);
1008 code
= GET_CODE (src
);
1014 if (XEXP (src
, 0) == stack_pointer_rtx
)
1016 rtx val
= XEXP (XEXP (src
, 1), 1);
1017 /* We handle only adjustments by constant amount. */
1018 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
1019 GET_CODE (val
) != CONST_INT
)
1021 offset
= -INTVAL (val
);
1028 if (XEXP (src
, 0) == stack_pointer_rtx
)
1030 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1037 if (XEXP (src
, 0) == stack_pointer_rtx
)
1039 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1054 /* Check INSN to see if it looks like a push or a stack adjustment, and
1055 make a note of it if it does. EH uses this information to find out how
1056 much extra space it needs to pop off the stack. */
1059 dwarf2out_stack_adjust (rtx insn
)
1061 HOST_WIDE_INT offset
;
1065 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1066 with this function. Proper support would require all frame-related
1067 insns to be marked, and to be able to handle saving state around
1068 epilogues textually in the middle of the function. */
1069 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1072 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1074 /* Extract the size of the args from the CALL rtx itself. */
1075 insn
= PATTERN (insn
);
1076 if (GET_CODE (insn
) == PARALLEL
)
1077 insn
= XVECEXP (insn
, 0, 0);
1078 if (GET_CODE (insn
) == SET
)
1079 insn
= SET_SRC (insn
);
1080 if (GET_CODE (insn
) != CALL
)
1083 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1087 /* If only calls can throw, and we have a frame pointer,
1088 save up adjustments until we see the CALL_INSN. */
1089 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1092 if (GET_CODE (insn
) == BARRIER
)
1094 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1095 the compiler will have already emitted a stack adjustment, but
1096 doesn't bother for calls to noreturn functions. */
1097 #ifdef STACK_GROWS_DOWNWARD
1098 offset
= -args_size
;
1103 else if (GET_CODE (PATTERN (insn
)) == SET
)
1104 offset
= stack_adjust_offset (PATTERN (insn
));
1105 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1106 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1108 /* There may be stack adjustments inside compound insns. Search
1110 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1111 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1112 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1120 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1121 cfa
.offset
+= offset
;
1123 #ifndef STACK_GROWS_DOWNWARD
1127 args_size
+= offset
;
1131 label
= dwarf2out_cfi_label ();
1132 def_cfa_1 (label
, &cfa
);
1133 dwarf2out_args_size (label
, args_size
);
1138 /* We delay emitting a register save until either (a) we reach the end
1139 of the prologue or (b) the register is clobbered. This clusters
1140 register saves so that there are fewer pc advances. */
1142 struct queued_reg_save
GTY(())
1144 struct queued_reg_save
*next
;
1146 HOST_WIDE_INT cfa_offset
;
1149 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1151 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1152 static const char *last_reg_save_label
;
1155 queue_reg_save (const char *label
, rtx reg
, HOST_WIDE_INT offset
)
1157 struct queued_reg_save
*q
= ggc_alloc (sizeof (*q
));
1159 q
->next
= queued_reg_saves
;
1161 q
->cfa_offset
= offset
;
1162 queued_reg_saves
= q
;
1164 last_reg_save_label
= label
;
1168 flush_queued_reg_saves (void)
1170 struct queued_reg_save
*q
, *next
;
1172 for (q
= queued_reg_saves
; q
; q
= next
)
1174 dwarf2out_reg_save (last_reg_save_label
, REGNO (q
->reg
), q
->cfa_offset
);
1178 queued_reg_saves
= NULL
;
1179 last_reg_save_label
= NULL
;
1183 clobbers_queued_reg_save (rtx insn
)
1185 struct queued_reg_save
*q
;
1187 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1188 if (modified_in_p (q
->reg
, insn
))
1195 /* A temporary register holding an integral value used in adjusting SP
1196 or setting up the store_reg. The "offset" field holds the integer
1197 value, not an offset. */
1198 static dw_cfa_location cfa_temp
;
1200 /* Record call frame debugging information for an expression EXPR,
1201 which either sets SP or FP (adjusting how we calculate the frame
1202 address) or saves a register to the stack. LABEL indicates the
1205 This function encodes a state machine mapping rtxes to actions on
1206 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1207 users need not read the source code.
1209 The High-Level Picture
1211 Changes in the register we use to calculate the CFA: Currently we
1212 assume that if you copy the CFA register into another register, we
1213 should take the other one as the new CFA register; this seems to
1214 work pretty well. If it's wrong for some target, it's simple
1215 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1217 Changes in the register we use for saving registers to the stack:
1218 This is usually SP, but not always. Again, we deduce that if you
1219 copy SP into another register (and SP is not the CFA register),
1220 then the new register is the one we will be using for register
1221 saves. This also seems to work.
1223 Register saves: There's not much guesswork about this one; if
1224 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1225 register save, and the register used to calculate the destination
1226 had better be the one we think we're using for this purpose.
1228 Except: If the register being saved is the CFA register, and the
1229 offset is nonzero, we are saving the CFA, so we assume we have to
1230 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1231 the intent is to save the value of SP from the previous frame.
1233 Invariants / Summaries of Rules
1235 cfa current rule for calculating the CFA. It usually
1236 consists of a register and an offset.
1237 cfa_store register used by prologue code to save things to the stack
1238 cfa_store.offset is the offset from the value of
1239 cfa_store.reg to the actual CFA
1240 cfa_temp register holding an integral value. cfa_temp.offset
1241 stores the value, which will be used to adjust the
1242 stack pointer. cfa_temp is also used like cfa_store,
1243 to track stores to the stack via fp or a temp reg.
1245 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1246 with cfa.reg as the first operand changes the cfa.reg and its
1247 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1250 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1251 expression yielding a constant. This sets cfa_temp.reg
1252 and cfa_temp.offset.
1254 Rule 5: Create a new register cfa_store used to save items to the
1257 Rules 10-14: Save a register to the stack. Define offset as the
1258 difference of the original location and cfa_store's
1259 location (or cfa_temp's location if cfa_temp is used).
1263 "{a,b}" indicates a choice of a xor b.
1264 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1267 (set <reg1> <reg2>:cfa.reg)
1268 effects: cfa.reg = <reg1>
1269 cfa.offset unchanged
1270 cfa_temp.reg = <reg1>
1271 cfa_temp.offset = cfa.offset
1274 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1275 {<const_int>,<reg>:cfa_temp.reg}))
1276 effects: cfa.reg = sp if fp used
1277 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1278 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1279 if cfa_store.reg==sp
1282 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1283 effects: cfa.reg = fp
1284 cfa_offset += +/- <const_int>
1287 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1288 constraints: <reg1> != fp
1290 effects: cfa.reg = <reg1>
1291 cfa_temp.reg = <reg1>
1292 cfa_temp.offset = cfa.offset
1295 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1296 constraints: <reg1> != fp
1298 effects: cfa_store.reg = <reg1>
1299 cfa_store.offset = cfa.offset - cfa_temp.offset
1302 (set <reg> <const_int>)
1303 effects: cfa_temp.reg = <reg>
1304 cfa_temp.offset = <const_int>
1307 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1308 effects: cfa_temp.reg = <reg1>
1309 cfa_temp.offset |= <const_int>
1312 (set <reg> (high <exp>))
1316 (set <reg> (lo_sum <exp> <const_int>))
1317 effects: cfa_temp.reg = <reg>
1318 cfa_temp.offset = <const_int>
1321 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1322 effects: cfa_store.offset -= <const_int>
1323 cfa.offset = cfa_store.offset if cfa.reg == sp
1325 cfa.base_offset = -cfa_store.offset
1328 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1329 effects: cfa_store.offset += -/+ mode_size(mem)
1330 cfa.offset = cfa_store.offset if cfa.reg == sp
1332 cfa.base_offset = -cfa_store.offset
1335 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1338 effects: cfa.reg = <reg1>
1339 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1342 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1343 effects: cfa.reg = <reg1>
1344 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1347 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1348 effects: cfa.reg = <reg1>
1349 cfa.base_offset = -cfa_temp.offset
1350 cfa_temp.offset -= mode_size(mem) */
1353 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1356 HOST_WIDE_INT offset
;
1358 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1359 the PARALLEL independently. The first element is always processed if
1360 it is a SET. This is for backward compatibility. Other elements
1361 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1362 flag is set in them. */
1363 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1366 int limit
= XVECLEN (expr
, 0);
1368 for (par_index
= 0; par_index
< limit
; par_index
++)
1369 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1370 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1372 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1377 if (GET_CODE (expr
) != SET
)
1380 src
= SET_SRC (expr
);
1381 dest
= SET_DEST (expr
);
1383 switch (GET_CODE (dest
))
1387 /* Update the CFA rule wrt SP or FP. Make sure src is
1388 relative to the current CFA register. */
1389 switch (GET_CODE (src
))
1391 /* Setting FP from SP. */
1393 if (cfa
.reg
== (unsigned) REGNO (src
))
1399 /* We used to require that dest be either SP or FP, but the
1400 ARM copies SP to a temporary register, and from there to
1401 FP. So we just rely on the backends to only set
1402 RTX_FRAME_RELATED_P on appropriate insns. */
1403 cfa
.reg
= REGNO (dest
);
1404 cfa_temp
.reg
= cfa
.reg
;
1405 cfa_temp
.offset
= cfa
.offset
;
1411 if (dest
== stack_pointer_rtx
)
1415 switch (GET_CODE (XEXP (src
, 1)))
1418 offset
= INTVAL (XEXP (src
, 1));
1421 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1423 offset
= cfa_temp
.offset
;
1429 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1431 /* Restoring SP from FP in the epilogue. */
1432 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1434 cfa
.reg
= STACK_POINTER_REGNUM
;
1436 else if (GET_CODE (src
) == LO_SUM
)
1437 /* Assume we've set the source reg of the LO_SUM from sp. */
1439 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1442 if (GET_CODE (src
) != MINUS
)
1444 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1445 cfa
.offset
+= offset
;
1446 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1447 cfa_store
.offset
+= offset
;
1449 else if (dest
== hard_frame_pointer_rtx
)
1452 /* Either setting the FP from an offset of the SP,
1453 or adjusting the FP */
1454 if (! frame_pointer_needed
)
1457 if (REG_P (XEXP (src
, 0))
1458 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1459 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1461 offset
= INTVAL (XEXP (src
, 1));
1462 if (GET_CODE (src
) != MINUS
)
1464 cfa
.offset
+= offset
;
1465 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1472 if (GET_CODE (src
) == MINUS
)
1476 if (REG_P (XEXP (src
, 0))
1477 && REGNO (XEXP (src
, 0)) == cfa
.reg
1478 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1480 /* Setting a temporary CFA register that will be copied
1481 into the FP later on. */
1482 offset
= - INTVAL (XEXP (src
, 1));
1483 cfa
.offset
+= offset
;
1484 cfa
.reg
= REGNO (dest
);
1485 /* Or used to save regs to the stack. */
1486 cfa_temp
.reg
= cfa
.reg
;
1487 cfa_temp
.offset
= cfa
.offset
;
1491 else if (REG_P (XEXP (src
, 0))
1492 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1493 && XEXP (src
, 1) == stack_pointer_rtx
)
1495 /* Setting a scratch register that we will use instead
1496 of SP for saving registers to the stack. */
1497 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1499 cfa_store
.reg
= REGNO (dest
);
1500 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1504 else if (GET_CODE (src
) == LO_SUM
1505 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1507 cfa_temp
.reg
= REGNO (dest
);
1508 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1517 cfa_temp
.reg
= REGNO (dest
);
1518 cfa_temp
.offset
= INTVAL (src
);
1523 if (!REG_P (XEXP (src
, 0))
1524 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1525 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1528 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1529 cfa_temp
.reg
= REGNO (dest
);
1530 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1533 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1534 which will fill in all of the bits. */
1543 def_cfa_1 (label
, &cfa
);
1550 /* Saving a register to the stack. Make sure dest is relative to the
1552 switch (GET_CODE (XEXP (dest
, 0)))
1557 /* We can't handle variable size modifications. */
1558 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1560 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1562 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1563 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1566 cfa_store
.offset
+= offset
;
1567 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1568 cfa
.offset
= cfa_store
.offset
;
1570 offset
= -cfa_store
.offset
;
1576 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1577 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1580 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1581 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1584 cfa_store
.offset
+= offset
;
1585 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1586 cfa
.offset
= cfa_store
.offset
;
1588 offset
= -cfa_store
.offset
;
1592 /* With an offset. */
1596 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1598 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1599 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1602 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1603 offset
-= cfa_store
.offset
;
1604 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1605 offset
-= cfa_temp
.offset
;
1611 /* Without an offset. */
1613 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1614 offset
= -cfa_store
.offset
;
1615 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1616 offset
= -cfa_temp
.offset
;
1623 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1625 offset
= -cfa_temp
.offset
;
1626 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1633 if (REGNO (src
) != STACK_POINTER_REGNUM
1634 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1635 && (unsigned) REGNO (src
) == cfa
.reg
)
1637 /* We're storing the current CFA reg into the stack. */
1639 if (cfa
.offset
== 0)
1641 /* If the source register is exactly the CFA, assume
1642 we're saving SP like any other register; this happens
1644 def_cfa_1 (label
, &cfa
);
1645 queue_reg_save (label
, stack_pointer_rtx
, offset
);
1650 /* Otherwise, we'll need to look in the stack to
1651 calculate the CFA. */
1652 rtx x
= XEXP (dest
, 0);
1659 cfa
.reg
= REGNO (x
);
1660 cfa
.base_offset
= offset
;
1662 def_cfa_1 (label
, &cfa
);
1667 def_cfa_1 (label
, &cfa
);
1668 queue_reg_save (label
, src
, offset
);
1676 /* Record call frame debugging information for INSN, which either
1677 sets SP or FP (adjusting how we calculate the frame address) or saves a
1678 register to the stack. If INSN is NULL_RTX, initialize our state. */
1681 dwarf2out_frame_debug (rtx insn
)
1686 if (insn
== NULL_RTX
)
1688 /* Flush any queued register saves. */
1689 flush_queued_reg_saves ();
1691 /* Set up state for generating call frame debug info. */
1693 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1696 cfa
.reg
= STACK_POINTER_REGNUM
;
1699 cfa_temp
.offset
= 0;
1703 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1704 flush_queued_reg_saves ();
1706 if (! RTX_FRAME_RELATED_P (insn
))
1708 if (!ACCUMULATE_OUTGOING_ARGS
)
1709 dwarf2out_stack_adjust (insn
);
1714 label
= dwarf2out_cfi_label ();
1715 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1717 insn
= XEXP (src
, 0);
1719 insn
= PATTERN (insn
);
1721 dwarf2out_frame_debug_expr (insn
, label
);
1726 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1727 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1728 (enum dwarf_call_frame_info cfi
);
1730 static enum dw_cfi_oprnd_type
1731 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1736 case DW_CFA_GNU_window_save
:
1737 return dw_cfi_oprnd_unused
;
1739 case DW_CFA_set_loc
:
1740 case DW_CFA_advance_loc1
:
1741 case DW_CFA_advance_loc2
:
1742 case DW_CFA_advance_loc4
:
1743 case DW_CFA_MIPS_advance_loc8
:
1744 return dw_cfi_oprnd_addr
;
1747 case DW_CFA_offset_extended
:
1748 case DW_CFA_def_cfa
:
1749 case DW_CFA_offset_extended_sf
:
1750 case DW_CFA_def_cfa_sf
:
1751 case DW_CFA_restore_extended
:
1752 case DW_CFA_undefined
:
1753 case DW_CFA_same_value
:
1754 case DW_CFA_def_cfa_register
:
1755 case DW_CFA_register
:
1756 return dw_cfi_oprnd_reg_num
;
1758 case DW_CFA_def_cfa_offset
:
1759 case DW_CFA_GNU_args_size
:
1760 case DW_CFA_def_cfa_offset_sf
:
1761 return dw_cfi_oprnd_offset
;
1763 case DW_CFA_def_cfa_expression
:
1764 case DW_CFA_expression
:
1765 return dw_cfi_oprnd_loc
;
1772 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1773 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1774 (enum dwarf_call_frame_info cfi
);
1776 static enum dw_cfi_oprnd_type
1777 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1781 case DW_CFA_def_cfa
:
1782 case DW_CFA_def_cfa_sf
:
1784 case DW_CFA_offset_extended_sf
:
1785 case DW_CFA_offset_extended
:
1786 return dw_cfi_oprnd_offset
;
1788 case DW_CFA_register
:
1789 return dw_cfi_oprnd_reg_num
;
1792 return dw_cfi_oprnd_unused
;
1796 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1798 /* Map register numbers held in the call frame info that gcc has
1799 collected using DWARF_FRAME_REGNUM to those that should be output in
1800 .debug_frame and .eh_frame. */
1801 #ifndef DWARF2_FRAME_REG_OUT
1802 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1805 /* Output a Call Frame Information opcode and its operand(s). */
1808 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
1811 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1812 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1813 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1814 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
1815 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1816 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1818 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1819 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
1820 "DW_CFA_offset, column 0x%lx", r
);
1821 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1823 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1825 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1826 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
1827 "DW_CFA_restore, column 0x%lx", r
);
1831 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1832 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1834 switch (cfi
->dw_cfi_opc
)
1836 case DW_CFA_set_loc
:
1838 dw2_asm_output_encoded_addr_rtx (
1839 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1840 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1843 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1844 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1847 case DW_CFA_advance_loc1
:
1848 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1849 fde
->dw_fde_current_label
, NULL
);
1850 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1853 case DW_CFA_advance_loc2
:
1854 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1855 fde
->dw_fde_current_label
, NULL
);
1856 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1859 case DW_CFA_advance_loc4
:
1860 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1861 fde
->dw_fde_current_label
, NULL
);
1862 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1865 case DW_CFA_MIPS_advance_loc8
:
1866 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1867 fde
->dw_fde_current_label
, NULL
);
1868 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1871 case DW_CFA_offset_extended
:
1872 case DW_CFA_def_cfa
:
1873 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1874 dw2_asm_output_data_uleb128 (r
, NULL
);
1875 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1878 case DW_CFA_offset_extended_sf
:
1879 case DW_CFA_def_cfa_sf
:
1880 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1881 dw2_asm_output_data_uleb128 (r
, NULL
);
1882 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1885 case DW_CFA_restore_extended
:
1886 case DW_CFA_undefined
:
1887 case DW_CFA_same_value
:
1888 case DW_CFA_def_cfa_register
:
1889 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1890 dw2_asm_output_data_uleb128 (r
, NULL
);
1893 case DW_CFA_register
:
1894 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1895 dw2_asm_output_data_uleb128 (r
, NULL
);
1896 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
1897 dw2_asm_output_data_uleb128 (r
, NULL
);
1900 case DW_CFA_def_cfa_offset
:
1901 case DW_CFA_GNU_args_size
:
1902 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1905 case DW_CFA_def_cfa_offset_sf
:
1906 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
1909 case DW_CFA_GNU_window_save
:
1912 case DW_CFA_def_cfa_expression
:
1913 case DW_CFA_expression
:
1914 output_cfa_loc (cfi
);
1917 case DW_CFA_GNU_negative_offset_extended
:
1918 /* Obsoleted by DW_CFA_offset_extended_sf. */
1927 /* Output the call frame information used to record information
1928 that relates to calculating the frame pointer, and records the
1929 location of saved registers. */
1932 output_call_frame_info (int for_eh
)
1937 char l1
[20], l2
[20], section_start_label
[20];
1938 bool any_lsda_needed
= false;
1939 char augmentation
[6];
1940 int augmentation_size
;
1941 int fde_encoding
= DW_EH_PE_absptr
;
1942 int per_encoding
= DW_EH_PE_absptr
;
1943 int lsda_encoding
= DW_EH_PE_absptr
;
1945 /* Don't emit a CIE if there won't be any FDEs. */
1946 if (fde_table_in_use
== 0)
1949 /* If we make FDEs linkonce, we may have to emit an empty label for
1950 an FDE that wouldn't otherwise be emitted. We want to avoid
1951 having an FDE kept around when the function it refers to is
1952 discarded. (Example where this matters: a primary function
1953 template in C++ requires EH information, but an explicit
1954 specialization doesn't. */
1955 if (TARGET_USES_WEAK_UNWIND_INFO
1956 && ! flag_asynchronous_unwind_tables
1958 for (i
= 0; i
< fde_table_in_use
; i
++)
1959 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
1960 && !fde_table
[i
].uses_eh_lsda
1961 && ! DECL_ONE_ONLY (fde_table
[i
].decl
))
1962 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
1963 for_eh
, /* empty */ 1);
1965 /* If we don't have any functions we'll want to unwind out of, don't
1966 emit any EH unwind information. Note that if exceptions aren't
1967 enabled, we won't have collected nothrow information, and if we
1968 asked for asynchronous tables, we always want this info. */
1971 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
1973 for (i
= 0; i
< fde_table_in_use
; i
++)
1974 if (fde_table
[i
].uses_eh_lsda
)
1975 any_eh_needed
= any_lsda_needed
= true;
1976 else if (TARGET_USES_WEAK_UNWIND_INFO
1977 && DECL_ONE_ONLY (fde_table
[i
].decl
))
1979 else if (! fde_table
[i
].nothrow
1980 && ! fde_table
[i
].all_throwers_are_sibcalls
)
1981 any_eh_needed
= true;
1983 if (! any_eh_needed
)
1987 /* We're going to be generating comments, so turn on app. */
1992 targetm
.asm_out
.eh_frame_section ();
1994 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
1996 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
1997 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
1999 /* Output the CIE. */
2000 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2001 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2002 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2003 "Length of Common Information Entry");
2004 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2006 /* Now that the CIE pointer is PC-relative for EH,
2007 use 0 to identify the CIE. */
2008 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2009 (for_eh
? 0 : DW_CIE_ID
),
2010 "CIE Identifier Tag");
2012 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2014 augmentation
[0] = 0;
2015 augmentation_size
= 0;
2021 z Indicates that a uleb128 is present to size the
2022 augmentation section.
2023 L Indicates the encoding (and thus presence) of
2024 an LSDA pointer in the FDE augmentation.
2025 R Indicates a non-default pointer encoding for
2027 P Indicates the presence of an encoding + language
2028 personality routine in the CIE augmentation. */
2030 fde_encoding
= TARGET_USES_WEAK_UNWIND_INFO
2031 ? ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1)
2032 : ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2033 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2034 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2036 p
= augmentation
+ 1;
2037 if (eh_personality_libfunc
)
2040 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2042 if (any_lsda_needed
)
2045 augmentation_size
+= 1;
2047 if (fde_encoding
!= DW_EH_PE_absptr
)
2050 augmentation_size
+= 1;
2052 if (p
> augmentation
+ 1)
2054 augmentation
[0] = 'z';
2058 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2059 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2061 int offset
= ( 4 /* Length */
2063 + 1 /* CIE version */
2064 + strlen (augmentation
) + 1 /* Augmentation */
2065 + size_of_uleb128 (1) /* Code alignment */
2066 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2068 + 1 /* Augmentation size */
2069 + 1 /* Personality encoding */ );
2070 int pad
= -offset
& (PTR_SIZE
- 1);
2072 augmentation_size
+= pad
;
2074 /* Augmentations should be small, so there's scarce need to
2075 iterate for a solution. Die if we exceed one uleb128 byte. */
2076 if (size_of_uleb128 (augmentation_size
) != 1)
2081 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2082 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2083 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2084 "CIE Data Alignment Factor");
2086 if (DW_CIE_VERSION
== 1)
2087 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2089 dw2_asm_output_data_uleb128 (DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2091 if (augmentation
[0])
2093 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2094 if (eh_personality_libfunc
)
2096 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2097 eh_data_format_name (per_encoding
));
2098 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2099 eh_personality_libfunc
, NULL
);
2102 if (any_lsda_needed
)
2103 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2104 eh_data_format_name (lsda_encoding
));
2106 if (fde_encoding
!= DW_EH_PE_absptr
)
2107 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2108 eh_data_format_name (fde_encoding
));
2111 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2112 output_cfi (cfi
, NULL
, for_eh
);
2114 /* Pad the CIE out to an address sized boundary. */
2115 ASM_OUTPUT_ALIGN (asm_out_file
,
2116 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2117 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2119 /* Loop through all of the FDE's. */
2120 for (i
= 0; i
< fde_table_in_use
; i
++)
2122 fde
= &fde_table
[i
];
2124 /* Don't emit EH unwind info for leaf functions that don't need it. */
2125 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2126 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2127 && (! TARGET_USES_WEAK_UNWIND_INFO
|| ! DECL_ONE_ONLY (fde
->decl
))
2128 && !fde
->uses_eh_lsda
)
2131 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2132 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2133 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2134 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2135 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2137 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2140 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2142 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2147 if (TARGET_USES_WEAK_UNWIND_INFO
2148 && DECL_ONE_ONLY (fde
->decl
))
2149 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2150 gen_rtx_SYMBOL_REF (Pmode
, IDENTIFIER_POINTER
2151 (DECL_ASSEMBLER_NAME (fde
->decl
))),
2152 "FDE initial location");
2154 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2155 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
2156 "FDE initial location");
2157 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2158 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2159 "FDE address range");
2163 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2164 "FDE initial location");
2165 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2166 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2167 "FDE address range");
2170 if (augmentation
[0])
2172 if (any_lsda_needed
)
2174 int size
= size_of_encoded_value (lsda_encoding
);
2176 if (lsda_encoding
== DW_EH_PE_aligned
)
2178 int offset
= ( 4 /* Length */
2179 + 4 /* CIE offset */
2180 + 2 * size_of_encoded_value (fde_encoding
)
2181 + 1 /* Augmentation size */ );
2182 int pad
= -offset
& (PTR_SIZE
- 1);
2185 if (size_of_uleb128 (size
) != 1)
2189 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2191 if (fde
->uses_eh_lsda
)
2193 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2194 fde
->funcdef_number
);
2195 dw2_asm_output_encoded_addr_rtx (
2196 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2197 "Language Specific Data Area");
2201 if (lsda_encoding
== DW_EH_PE_aligned
)
2202 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2204 (size_of_encoded_value (lsda_encoding
), 0,
2205 "Language Specific Data Area (none)");
2209 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2212 /* Loop through the Call Frame Instructions associated with
2214 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2215 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2216 output_cfi (cfi
, fde
, for_eh
);
2218 /* Pad the FDE out to an address sized boundary. */
2219 ASM_OUTPUT_ALIGN (asm_out_file
,
2220 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2221 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2224 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2225 dw2_asm_output_data (4, 0, "End of Table");
2226 #ifdef MIPS_DEBUGGING_INFO
2227 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2228 get a value of 0. Putting .align 0 after the label fixes it. */
2229 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2232 /* Turn off app to make assembly quicker. */
2237 /* Output a marker (i.e. a label) for the beginning of a function, before
2241 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2242 const char *file ATTRIBUTE_UNUSED
)
2244 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2247 current_function_func_begin_label
= 0;
2249 #ifdef IA64_UNWIND_INFO
2250 /* ??? current_function_func_begin_label is also used by except.c
2251 for call-site information. We must emit this label if it might
2253 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2254 && ! dwarf2out_do_frame ())
2257 if (! dwarf2out_do_frame ())
2261 function_section (current_function_decl
);
2262 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2263 current_function_funcdef_no
);
2264 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2265 current_function_funcdef_no
);
2266 current_function_func_begin_label
= get_identifier (label
);
2268 #ifdef IA64_UNWIND_INFO
2269 /* We can elide the fde allocation if we're not emitting debug info. */
2270 if (! dwarf2out_do_frame ())
2274 /* Expand the fde table if necessary. */
2275 if (fde_table_in_use
== fde_table_allocated
)
2277 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2278 fde_table
= ggc_realloc (fde_table
,
2279 fde_table_allocated
* sizeof (dw_fde_node
));
2280 memset (fde_table
+ fde_table_in_use
, 0,
2281 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2284 /* Record the FDE associated with this function. */
2285 current_funcdef_fde
= fde_table_in_use
;
2287 /* Add the new FDE at the end of the fde_table. */
2288 fde
= &fde_table
[fde_table_in_use
++];
2289 fde
->decl
= current_function_decl
;
2290 fde
->dw_fde_begin
= xstrdup (label
);
2291 fde
->dw_fde_current_label
= NULL
;
2292 fde
->dw_fde_end
= NULL
;
2293 fde
->dw_fde_cfi
= NULL
;
2294 fde
->funcdef_number
= current_function_funcdef_no
;
2295 fde
->nothrow
= current_function_nothrow
;
2296 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2297 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2299 args_size
= old_args_size
= 0;
2301 /* We only want to output line number information for the genuine dwarf2
2302 prologue case, not the eh frame case. */
2303 #ifdef DWARF2_DEBUGGING_INFO
2305 dwarf2out_source_line (line
, file
);
2309 /* Output a marker (i.e. a label) for the absolute end of the generated code
2310 for a function definition. This gets called *after* the epilogue code has
2314 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2315 const char *file ATTRIBUTE_UNUSED
)
2318 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2320 /* Output a label to mark the endpoint of the code generated for this
2322 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2323 current_function_funcdef_no
);
2324 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2325 fde
= &fde_table
[fde_table_in_use
- 1];
2326 fde
->dw_fde_end
= xstrdup (label
);
2330 dwarf2out_frame_init (void)
2332 /* Allocate the initial hunk of the fde_table. */
2333 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2334 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2335 fde_table_in_use
= 0;
2337 /* Generate the CFA instructions common to all FDE's. Do it now for the
2338 sake of lookup_cfa. */
2340 #ifdef DWARF2_UNWIND_INFO
2341 /* On entry, the Canonical Frame Address is at SP. */
2342 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2343 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2348 dwarf2out_frame_finish (void)
2350 /* Output call frame information. */
2351 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2352 output_call_frame_info (0);
2354 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2355 output_call_frame_info (1);
2359 /* And now, the subset of the debugging information support code necessary
2360 for emitting location expressions. */
2362 /* We need some way to distinguish DW_OP_addr with a direct symbol
2363 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2364 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2367 typedef struct dw_val_struct
*dw_val_ref
;
2368 typedef struct die_struct
*dw_die_ref
;
2369 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2370 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2372 /* Each DIE may have a series of attribute/value pairs. Values
2373 can take on several forms. The forms that are used in this
2374 implementation are listed below. */
2379 dw_val_class_offset
,
2381 dw_val_class_loc_list
,
2382 dw_val_class_range_list
,
2384 dw_val_class_unsigned_const
,
2385 dw_val_class_long_long
,
2388 dw_val_class_die_ref
,
2389 dw_val_class_fde_ref
,
2390 dw_val_class_lbl_id
,
2391 dw_val_class_lbl_offset
,
2395 /* Describe a double word constant value. */
2396 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2398 typedef struct dw_long_long_struct
GTY(())
2405 /* Describe a floating point constant value, or a vector constant value. */
2407 typedef struct dw_vec_struct
GTY(())
2409 unsigned char * GTY((length ("%h.length"))) array
;
2415 /* The dw_val_node describes an attribute's value, as it is
2416 represented internally. */
2418 typedef struct dw_val_struct
GTY(())
2420 enum dw_val_class val_class
;
2421 union dw_val_struct_union
2423 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2424 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2425 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2426 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2427 HOST_WIDE_INT
GTY ((default)) val_int
;
2428 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2429 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2430 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2431 struct dw_val_die_union
2435 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2436 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2437 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2438 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2439 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2441 GTY ((desc ("%1.val_class"))) v
;
2445 /* Locations in memory are described using a sequence of stack machine
2448 typedef struct dw_loc_descr_struct
GTY(())
2450 dw_loc_descr_ref dw_loc_next
;
2451 enum dwarf_location_atom dw_loc_opc
;
2452 dw_val_node dw_loc_oprnd1
;
2453 dw_val_node dw_loc_oprnd2
;
2458 /* Location lists are ranges + location descriptions for that range,
2459 so you can track variables that are in different places over
2460 their entire life. */
2461 typedef struct dw_loc_list_struct
GTY(())
2463 dw_loc_list_ref dw_loc_next
;
2464 const char *begin
; /* Label for begin address of range */
2465 const char *end
; /* Label for end address of range */
2466 char *ll_symbol
; /* Label for beginning of location list.
2467 Only on head of list */
2468 const char *section
; /* Section this loclist is relative to */
2469 dw_loc_descr_ref expr
;
2472 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2474 static const char *dwarf_stack_op_name (unsigned);
2475 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2476 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2477 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2478 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2479 static unsigned long size_of_locs (dw_loc_descr_ref
);
2480 static void output_loc_operands (dw_loc_descr_ref
);
2481 static void output_loc_sequence (dw_loc_descr_ref
);
2483 /* Convert a DWARF stack opcode into its string name. */
2486 dwarf_stack_op_name (unsigned int op
)
2491 case INTERNAL_DW_OP_tls_addr
:
2492 return "DW_OP_addr";
2494 return "DW_OP_deref";
2496 return "DW_OP_const1u";
2498 return "DW_OP_const1s";
2500 return "DW_OP_const2u";
2502 return "DW_OP_const2s";
2504 return "DW_OP_const4u";
2506 return "DW_OP_const4s";
2508 return "DW_OP_const8u";
2510 return "DW_OP_const8s";
2512 return "DW_OP_constu";
2514 return "DW_OP_consts";
2518 return "DW_OP_drop";
2520 return "DW_OP_over";
2522 return "DW_OP_pick";
2524 return "DW_OP_swap";
2528 return "DW_OP_xderef";
2536 return "DW_OP_minus";
2548 return "DW_OP_plus";
2549 case DW_OP_plus_uconst
:
2550 return "DW_OP_plus_uconst";
2556 return "DW_OP_shra";
2574 return "DW_OP_skip";
2576 return "DW_OP_lit0";
2578 return "DW_OP_lit1";
2580 return "DW_OP_lit2";
2582 return "DW_OP_lit3";
2584 return "DW_OP_lit4";
2586 return "DW_OP_lit5";
2588 return "DW_OP_lit6";
2590 return "DW_OP_lit7";
2592 return "DW_OP_lit8";
2594 return "DW_OP_lit9";
2596 return "DW_OP_lit10";
2598 return "DW_OP_lit11";
2600 return "DW_OP_lit12";
2602 return "DW_OP_lit13";
2604 return "DW_OP_lit14";
2606 return "DW_OP_lit15";
2608 return "DW_OP_lit16";
2610 return "DW_OP_lit17";
2612 return "DW_OP_lit18";
2614 return "DW_OP_lit19";
2616 return "DW_OP_lit20";
2618 return "DW_OP_lit21";
2620 return "DW_OP_lit22";
2622 return "DW_OP_lit23";
2624 return "DW_OP_lit24";
2626 return "DW_OP_lit25";
2628 return "DW_OP_lit26";
2630 return "DW_OP_lit27";
2632 return "DW_OP_lit28";
2634 return "DW_OP_lit29";
2636 return "DW_OP_lit30";
2638 return "DW_OP_lit31";
2640 return "DW_OP_reg0";
2642 return "DW_OP_reg1";
2644 return "DW_OP_reg2";
2646 return "DW_OP_reg3";
2648 return "DW_OP_reg4";
2650 return "DW_OP_reg5";
2652 return "DW_OP_reg6";
2654 return "DW_OP_reg7";
2656 return "DW_OP_reg8";
2658 return "DW_OP_reg9";
2660 return "DW_OP_reg10";
2662 return "DW_OP_reg11";
2664 return "DW_OP_reg12";
2666 return "DW_OP_reg13";
2668 return "DW_OP_reg14";
2670 return "DW_OP_reg15";
2672 return "DW_OP_reg16";
2674 return "DW_OP_reg17";
2676 return "DW_OP_reg18";
2678 return "DW_OP_reg19";
2680 return "DW_OP_reg20";
2682 return "DW_OP_reg21";
2684 return "DW_OP_reg22";
2686 return "DW_OP_reg23";
2688 return "DW_OP_reg24";
2690 return "DW_OP_reg25";
2692 return "DW_OP_reg26";
2694 return "DW_OP_reg27";
2696 return "DW_OP_reg28";
2698 return "DW_OP_reg29";
2700 return "DW_OP_reg30";
2702 return "DW_OP_reg31";
2704 return "DW_OP_breg0";
2706 return "DW_OP_breg1";
2708 return "DW_OP_breg2";
2710 return "DW_OP_breg3";
2712 return "DW_OP_breg4";
2714 return "DW_OP_breg5";
2716 return "DW_OP_breg6";
2718 return "DW_OP_breg7";
2720 return "DW_OP_breg8";
2722 return "DW_OP_breg9";
2724 return "DW_OP_breg10";
2726 return "DW_OP_breg11";
2728 return "DW_OP_breg12";
2730 return "DW_OP_breg13";
2732 return "DW_OP_breg14";
2734 return "DW_OP_breg15";
2736 return "DW_OP_breg16";
2738 return "DW_OP_breg17";
2740 return "DW_OP_breg18";
2742 return "DW_OP_breg19";
2744 return "DW_OP_breg20";
2746 return "DW_OP_breg21";
2748 return "DW_OP_breg22";
2750 return "DW_OP_breg23";
2752 return "DW_OP_breg24";
2754 return "DW_OP_breg25";
2756 return "DW_OP_breg26";
2758 return "DW_OP_breg27";
2760 return "DW_OP_breg28";
2762 return "DW_OP_breg29";
2764 return "DW_OP_breg30";
2766 return "DW_OP_breg31";
2768 return "DW_OP_regx";
2770 return "DW_OP_fbreg";
2772 return "DW_OP_bregx";
2774 return "DW_OP_piece";
2775 case DW_OP_deref_size
:
2776 return "DW_OP_deref_size";
2777 case DW_OP_xderef_size
:
2778 return "DW_OP_xderef_size";
2781 case DW_OP_push_object_address
:
2782 return "DW_OP_push_object_address";
2784 return "DW_OP_call2";
2786 return "DW_OP_call4";
2787 case DW_OP_call_ref
:
2788 return "DW_OP_call_ref";
2789 case DW_OP_GNU_push_tls_address
:
2790 return "DW_OP_GNU_push_tls_address";
2792 return "OP_<unknown>";
2796 /* Return a pointer to a newly allocated location description. Location
2797 descriptions are simple expression terms that can be strung
2798 together to form more complicated location (address) descriptions. */
2800 static inline dw_loc_descr_ref
2801 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
2802 unsigned HOST_WIDE_INT oprnd2
)
2804 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
2806 descr
->dw_loc_opc
= op
;
2807 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2808 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2809 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2810 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2816 /* Add a location description term to a location description expression. */
2819 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
2821 dw_loc_descr_ref
*d
;
2823 /* Find the end of the chain. */
2824 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2830 /* Return the size of a location descriptor. */
2832 static unsigned long
2833 size_of_loc_descr (dw_loc_descr_ref loc
)
2835 unsigned long size
= 1;
2837 switch (loc
->dw_loc_opc
)
2840 case INTERNAL_DW_OP_tls_addr
:
2841 size
+= DWARF2_ADDR_SIZE
;
2860 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2863 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2868 case DW_OP_plus_uconst
:
2869 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2907 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2910 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2913 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2916 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2917 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
2920 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2922 case DW_OP_deref_size
:
2923 case DW_OP_xderef_size
:
2932 case DW_OP_call_ref
:
2933 size
+= DWARF2_ADDR_SIZE
;
2942 /* Return the size of a series of location descriptors. */
2944 static unsigned long
2945 size_of_locs (dw_loc_descr_ref loc
)
2949 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2951 loc
->dw_loc_addr
= size
;
2952 size
+= size_of_loc_descr (loc
);
2958 /* Output location description stack opcode's operands (if any). */
2961 output_loc_operands (dw_loc_descr_ref loc
)
2963 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2964 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2966 switch (loc
->dw_loc_opc
)
2968 #ifdef DWARF2_DEBUGGING_INFO
2970 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2974 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
2978 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
2982 if (HOST_BITS_PER_LONG
< 64)
2984 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
2991 if (val1
->val_class
== dw_val_class_loc
)
2992 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2996 dw2_asm_output_data (2, offset
, NULL
);
3009 /* We currently don't make any attempt to make sure these are
3010 aligned properly like we do for the main unwind info, so
3011 don't support emitting things larger than a byte if we're
3012 only doing unwinding. */
3017 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3020 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3023 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3026 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3028 case DW_OP_plus_uconst
:
3029 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3063 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3066 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3069 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3072 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3073 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3076 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3078 case DW_OP_deref_size
:
3079 case DW_OP_xderef_size
:
3080 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3083 case INTERNAL_DW_OP_tls_addr
:
3084 #ifdef ASM_OUTPUT_DWARF_DTPREL
3085 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
3087 fputc ('\n', asm_out_file
);
3094 /* Other codes have no operands. */
3099 /* Output a sequence of location operations. */
3102 output_loc_sequence (dw_loc_descr_ref loc
)
3104 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3106 /* Output the opcode. */
3107 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3108 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3110 /* Output the operand(s) (if any). */
3111 output_loc_operands (loc
);
3115 /* This routine will generate the correct assembly data for a location
3116 description based on a cfi entry with a complex address. */
3119 output_cfa_loc (dw_cfi_ref cfi
)
3121 dw_loc_descr_ref loc
;
3124 /* Output the size of the block. */
3125 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3126 size
= size_of_locs (loc
);
3127 dw2_asm_output_data_uleb128 (size
, NULL
);
3129 /* Now output the operations themselves. */
3130 output_loc_sequence (loc
);
3133 /* This function builds a dwarf location descriptor sequence from
3134 a dw_cfa_location. */
3136 static struct dw_loc_descr_struct
*
3137 build_cfa_loc (dw_cfa_location
*cfa
)
3139 struct dw_loc_descr_struct
*head
, *tmp
;
3141 if (cfa
->indirect
== 0)
3144 if (cfa
->base_offset
)
3147 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3149 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3151 else if (cfa
->reg
<= 31)
3152 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3154 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3156 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3157 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3158 add_loc_descr (&head
, tmp
);
3159 if (cfa
->offset
!= 0)
3161 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3162 add_loc_descr (&head
, tmp
);
3168 /* This function fills in aa dw_cfa_location structure from a dwarf location
3169 descriptor sequence. */
3172 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3174 struct dw_loc_descr_struct
*ptr
;
3176 cfa
->base_offset
= 0;
3180 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3182 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3218 cfa
->reg
= op
- DW_OP_reg0
;
3221 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3255 cfa
->reg
= op
- DW_OP_breg0
;
3256 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3259 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3260 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3265 case DW_OP_plus_uconst
:
3266 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3269 internal_error ("DW_LOC_OP %s not implemented\n",
3270 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3274 #endif /* .debug_frame support */
3276 /* And now, the support for symbolic debugging information. */
3277 #ifdef DWARF2_DEBUGGING_INFO
3279 /* .debug_str support. */
3280 static int output_indirect_string (void **, void *);
3282 static void dwarf2out_init (const char *);
3283 static void dwarf2out_finish (const char *);
3284 static void dwarf2out_define (unsigned int, const char *);
3285 static void dwarf2out_undef (unsigned int, const char *);
3286 static void dwarf2out_start_source_file (unsigned, const char *);
3287 static void dwarf2out_end_source_file (unsigned);
3288 static void dwarf2out_begin_block (unsigned, unsigned);
3289 static void dwarf2out_end_block (unsigned, unsigned);
3290 static bool dwarf2out_ignore_block (tree
);
3291 static void dwarf2out_global_decl (tree
);
3292 static void dwarf2out_type_decl (tree
, int);
3293 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3294 static void dwarf2out_abstract_function (tree
);
3295 static void dwarf2out_var_location (rtx
);
3296 static void dwarf2out_begin_function (tree
);
3298 /* The debug hooks structure. */
3300 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3306 dwarf2out_start_source_file
,
3307 dwarf2out_end_source_file
,
3308 dwarf2out_begin_block
,
3309 dwarf2out_end_block
,
3310 dwarf2out_ignore_block
,
3311 dwarf2out_source_line
,
3312 dwarf2out_begin_prologue
,
3313 debug_nothing_int_charstar
, /* end_prologue */
3314 dwarf2out_end_epilogue
,
3315 dwarf2out_begin_function
,
3316 debug_nothing_int
, /* end_function */
3317 dwarf2out_decl
, /* function_decl */
3318 dwarf2out_global_decl
,
3319 dwarf2out_type_decl
, /* type_decl */
3320 dwarf2out_imported_module_or_decl
,
3321 debug_nothing_tree
, /* deferred_inline_function */
3322 /* The DWARF 2 backend tries to reduce debugging bloat by not
3323 emitting the abstract description of inline functions until
3324 something tries to reference them. */
3325 dwarf2out_abstract_function
, /* outlining_inline_function */
3326 debug_nothing_rtx
, /* label */
3327 debug_nothing_int
, /* handle_pch */
3328 dwarf2out_var_location
3332 /* NOTE: In the comments in this file, many references are made to
3333 "Debugging Information Entries". This term is abbreviated as `DIE'
3334 throughout the remainder of this file. */
3336 /* An internal representation of the DWARF output is built, and then
3337 walked to generate the DWARF debugging info. The walk of the internal
3338 representation is done after the entire program has been compiled.
3339 The types below are used to describe the internal representation. */
3341 /* Various DIE's use offsets relative to the beginning of the
3342 .debug_info section to refer to each other. */
3344 typedef long int dw_offset
;
3346 /* Define typedefs here to avoid circular dependencies. */
3348 typedef struct dw_attr_struct
*dw_attr_ref
;
3349 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3350 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3351 typedef struct pubname_struct
*pubname_ref
;
3352 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3354 /* Each entry in the line_info_table maintains the file and
3355 line number associated with the label generated for that
3356 entry. The label gives the PC value associated with
3357 the line number entry. */
3359 typedef struct dw_line_info_struct
GTY(())
3361 unsigned long dw_file_num
;
3362 unsigned long dw_line_num
;
3366 /* Line information for functions in separate sections; each one gets its
3368 typedef struct dw_separate_line_info_struct
GTY(())
3370 unsigned long dw_file_num
;
3371 unsigned long dw_line_num
;
3372 unsigned long function
;
3374 dw_separate_line_info_entry
;
3376 /* Each DIE attribute has a field specifying the attribute kind,
3377 a link to the next attribute in the chain, and an attribute value.
3378 Attributes are typically linked below the DIE they modify. */
3380 typedef struct dw_attr_struct
GTY(())
3382 enum dwarf_attribute dw_attr
;
3383 dw_attr_ref dw_attr_next
;
3384 dw_val_node dw_attr_val
;
3388 /* The Debugging Information Entry (DIE) structure */
3390 typedef struct die_struct
GTY(())
3392 enum dwarf_tag die_tag
;
3394 dw_attr_ref die_attr
;
3395 dw_die_ref die_parent
;
3396 dw_die_ref die_child
;
3398 dw_die_ref die_definition
; /* ref from a specification to its definition */
3399 dw_offset die_offset
;
3400 unsigned long die_abbrev
;
3402 unsigned int decl_id
;
3406 /* The pubname structure */
3408 typedef struct pubname_struct
GTY(())
3415 struct dw_ranges_struct
GTY(())
3420 /* The limbo die list structure. */
3421 typedef struct limbo_die_struct
GTY(())
3425 struct limbo_die_struct
*next
;
3429 /* How to start an assembler comment. */
3430 #ifndef ASM_COMMENT_START
3431 #define ASM_COMMENT_START ";#"
3434 /* Define a macro which returns nonzero for a TYPE_DECL which was
3435 implicitly generated for a tagged type.
3437 Note that unlike the gcc front end (which generates a NULL named
3438 TYPE_DECL node for each complete tagged type, each array type, and
3439 each function type node created) the g++ front end generates a
3440 _named_ TYPE_DECL node for each tagged type node created.
3441 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3442 generate a DW_TAG_typedef DIE for them. */
3444 #define TYPE_DECL_IS_STUB(decl) \
3445 (DECL_NAME (decl) == NULL_TREE \
3446 || (DECL_ARTIFICIAL (decl) \
3447 && is_tagged_type (TREE_TYPE (decl)) \
3448 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3449 /* This is necessary for stub decls that \
3450 appear in nested inline functions. */ \
3451 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3452 && (decl_ultimate_origin (decl) \
3453 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3455 /* Information concerning the compilation unit's programming
3456 language, and compiler version. */
3458 /* Fixed size portion of the DWARF compilation unit header. */
3459 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3460 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3462 /* Fixed size portion of public names info. */
3463 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3465 /* Fixed size portion of the address range info. */
3466 #define DWARF_ARANGES_HEADER_SIZE \
3467 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3468 DWARF2_ADDR_SIZE * 2) \
3469 - DWARF_INITIAL_LENGTH_SIZE)
3471 /* Size of padding portion in the address range info. It must be
3472 aligned to twice the pointer size. */
3473 #define DWARF_ARANGES_PAD_SIZE \
3474 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3475 DWARF2_ADDR_SIZE * 2) \
3476 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3478 /* Use assembler line directives if available. */
3479 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3480 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3481 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3483 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3487 /* Minimum line offset in a special line info. opcode.
3488 This value was chosen to give a reasonable range of values. */
3489 #define DWARF_LINE_BASE -10
3491 /* First special line opcode - leave room for the standard opcodes. */
3492 #define DWARF_LINE_OPCODE_BASE 10
3494 /* Range of line offsets in a special line info. opcode. */
3495 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3497 /* Flag that indicates the initial value of the is_stmt_start flag.
3498 In the present implementation, we do not mark any lines as
3499 the beginning of a source statement, because that information
3500 is not made available by the GCC front-end. */
3501 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3503 #ifdef DWARF2_DEBUGGING_INFO
3504 /* This location is used by calc_die_sizes() to keep track
3505 the offset of each DIE within the .debug_info section. */
3506 static unsigned long next_die_offset
;
3509 /* Record the root of the DIE's built for the current compilation unit. */
3510 static GTY(()) dw_die_ref comp_unit_die
;
3512 /* A list of DIEs with a NULL parent waiting to be relocated. */
3513 static GTY(()) limbo_die_node
*limbo_die_list
;
3515 /* Filenames referenced by this compilation unit. */
3516 static GTY(()) varray_type file_table
;
3517 static GTY(()) varray_type file_table_emitted
;
3518 static GTY(()) size_t file_table_last_lookup_index
;
3520 /* A hash table of references to DIE's that describe declarations.
3521 The key is a DECL_UID() which is a unique number identifying each decl. */
3522 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3524 /* Node of the variable location list. */
3525 struct var_loc_node
GTY ((chain_next ("%h.next")))
3527 rtx
GTY (()) var_loc_note
;
3528 const char * GTY (()) label
;
3529 struct var_loc_node
* GTY (()) next
;
3532 /* Variable location list. */
3533 struct var_loc_list_def
GTY (())
3535 struct var_loc_node
* GTY (()) first
;
3537 /* Do not mark the last element of the chained list because
3538 it is marked through the chain. */
3539 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3541 /* DECL_UID of the variable decl. */
3542 unsigned int decl_id
;
3544 typedef struct var_loc_list_def var_loc_list
;
3547 /* Table of decl location linked lists. */
3548 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3550 /* A pointer to the base of a list of references to DIE's that
3551 are uniquely identified by their tag, presence/absence of
3552 children DIE's, and list of attribute/value pairs. */
3553 static GTY((length ("abbrev_die_table_allocated")))
3554 dw_die_ref
*abbrev_die_table
;
3556 /* Number of elements currently allocated for abbrev_die_table. */
3557 static GTY(()) unsigned abbrev_die_table_allocated
;
3559 /* Number of elements in type_die_table currently in use. */
3560 static GTY(()) unsigned abbrev_die_table_in_use
;
3562 /* Size (in elements) of increments by which we may expand the
3563 abbrev_die_table. */
3564 #define ABBREV_DIE_TABLE_INCREMENT 256
3566 /* A pointer to the base of a table that contains line information
3567 for each source code line in .text in the compilation unit. */
3568 static GTY((length ("line_info_table_allocated")))
3569 dw_line_info_ref line_info_table
;
3571 /* Number of elements currently allocated for line_info_table. */
3572 static GTY(()) unsigned line_info_table_allocated
;
3574 /* Number of elements in line_info_table currently in use. */
3575 static GTY(()) unsigned line_info_table_in_use
;
3577 /* A pointer to the base of a table that contains line information
3578 for each source code line outside of .text in the compilation unit. */
3579 static GTY ((length ("separate_line_info_table_allocated")))
3580 dw_separate_line_info_ref separate_line_info_table
;
3582 /* Number of elements currently allocated for separate_line_info_table. */
3583 static GTY(()) unsigned separate_line_info_table_allocated
;
3585 /* Number of elements in separate_line_info_table currently in use. */
3586 static GTY(()) unsigned separate_line_info_table_in_use
;
3588 /* Size (in elements) of increments by which we may expand the
3590 #define LINE_INFO_TABLE_INCREMENT 1024
3592 /* A pointer to the base of a table that contains a list of publicly
3593 accessible names. */
3594 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3596 /* Number of elements currently allocated for pubname_table. */
3597 static GTY(()) unsigned pubname_table_allocated
;
3599 /* Number of elements in pubname_table currently in use. */
3600 static GTY(()) unsigned pubname_table_in_use
;
3602 /* Size (in elements) of increments by which we may expand the
3604 #define PUBNAME_TABLE_INCREMENT 64
3606 /* Array of dies for which we should generate .debug_arange info. */
3607 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3609 /* Number of elements currently allocated for arange_table. */
3610 static GTY(()) unsigned arange_table_allocated
;
3612 /* Number of elements in arange_table currently in use. */
3613 static GTY(()) unsigned arange_table_in_use
;
3615 /* Size (in elements) of increments by which we may expand the
3617 #define ARANGE_TABLE_INCREMENT 64
3619 /* Array of dies for which we should generate .debug_ranges info. */
3620 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3622 /* Number of elements currently allocated for ranges_table. */
3623 static GTY(()) unsigned ranges_table_allocated
;
3625 /* Number of elements in ranges_table currently in use. */
3626 static GTY(()) unsigned ranges_table_in_use
;
3628 /* Size (in elements) of increments by which we may expand the
3630 #define RANGES_TABLE_INCREMENT 64
3632 /* Whether we have location lists that need outputting */
3633 static GTY(()) unsigned have_location_lists
;
3635 /* Unique label counter. */
3636 static GTY(()) unsigned int loclabel_num
;
3638 #ifdef DWARF2_DEBUGGING_INFO
3639 /* Record whether the function being analyzed contains inlined functions. */
3640 static int current_function_has_inlines
;
3642 #if 0 && defined (MIPS_DEBUGGING_INFO)
3643 static int comp_unit_has_inlines
;
3646 /* Number of file tables emitted in maybe_emit_file(). */
3647 static GTY(()) int emitcount
= 0;
3649 /* Number of internal labels generated by gen_internal_sym(). */
3650 static GTY(()) int label_num
;
3652 #ifdef DWARF2_DEBUGGING_INFO
3654 /* Forward declarations for functions defined in this file. */
3656 static int is_pseudo_reg (rtx
);
3657 static tree
type_main_variant (tree
);
3658 static int is_tagged_type (tree
);
3659 static const char *dwarf_tag_name (unsigned);
3660 static const char *dwarf_attr_name (unsigned);
3661 static const char *dwarf_form_name (unsigned);
3663 static const char *dwarf_type_encoding_name (unsigned);
3665 static tree
decl_ultimate_origin (tree
);
3666 static tree
block_ultimate_origin (tree
);
3667 static tree
decl_class_context (tree
);
3668 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3669 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3670 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3671 static inline unsigned AT_flag (dw_attr_ref
);
3672 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3673 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3674 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3675 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3676 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3678 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3679 unsigned int, unsigned char *);
3680 static hashval_t
debug_str_do_hash (const void *);
3681 static int debug_str_eq (const void *, const void *);
3682 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3683 static inline const char *AT_string (dw_attr_ref
);
3684 static int AT_string_form (dw_attr_ref
);
3685 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3686 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3687 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3688 static inline int AT_ref_external (dw_attr_ref
);
3689 static inline void set_AT_ref_external (dw_attr_ref
, int);
3690 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3691 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3692 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3693 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3695 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3696 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3697 static inline rtx
AT_addr (dw_attr_ref
);
3698 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3699 static void add_AT_lbl_offset (dw_die_ref
, enum dwarf_attribute
, const char *);
3700 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3701 unsigned HOST_WIDE_INT
);
3702 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3704 static inline const char *AT_lbl (dw_attr_ref
);
3705 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3706 static const char *get_AT_low_pc (dw_die_ref
);
3707 static const char *get_AT_hi_pc (dw_die_ref
);
3708 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3709 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3710 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3711 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3712 static bool is_c_family (void);
3713 static bool is_cxx (void);
3714 static bool is_java (void);
3715 static bool is_fortran (void);
3716 static bool is_ada (void);
3717 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3718 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3719 static inline void free_die (dw_die_ref
);
3720 static void remove_children (dw_die_ref
);
3721 static void add_child_die (dw_die_ref
, dw_die_ref
);
3722 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3723 static dw_die_ref
lookup_type_die (tree
);
3724 static void equate_type_number_to_die (tree
, dw_die_ref
);
3725 static hashval_t
decl_die_table_hash (const void *);
3726 static int decl_die_table_eq (const void *, const void *);
3727 static dw_die_ref
lookup_decl_die (tree
);
3728 static hashval_t
decl_loc_table_hash (const void *);
3729 static int decl_loc_table_eq (const void *, const void *);
3730 static var_loc_list
*lookup_decl_loc (tree
);
3731 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3732 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
3733 static void print_spaces (FILE *);
3734 static void print_die (dw_die_ref
, FILE *);
3735 static void print_dwarf_line_table (FILE *);
3736 static void reverse_die_lists (dw_die_ref
);
3737 static void reverse_all_dies (dw_die_ref
);
3738 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3739 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3740 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3741 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3742 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3743 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3744 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
3745 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3746 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3747 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3748 static void compute_section_prefix (dw_die_ref
);
3749 static int is_type_die (dw_die_ref
);
3750 static int is_comdat_die (dw_die_ref
);
3751 static int is_symbol_die (dw_die_ref
);
3752 static void assign_symbol_names (dw_die_ref
);
3753 static void break_out_includes (dw_die_ref
);
3754 static hashval_t
htab_cu_hash (const void *);
3755 static int htab_cu_eq (const void *, const void *);
3756 static void htab_cu_del (void *);
3757 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3758 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3759 static void add_sibling_attributes (dw_die_ref
);
3760 static void build_abbrev_table (dw_die_ref
);
3761 static void output_location_lists (dw_die_ref
);
3762 static int constant_size (long unsigned);
3763 static unsigned long size_of_die (dw_die_ref
);
3764 static void calc_die_sizes (dw_die_ref
);
3765 static void mark_dies (dw_die_ref
);
3766 static void unmark_dies (dw_die_ref
);
3767 static void unmark_all_dies (dw_die_ref
);
3768 static unsigned long size_of_pubnames (void);
3769 static unsigned long size_of_aranges (void);
3770 static enum dwarf_form
value_format (dw_attr_ref
);
3771 static void output_value_format (dw_attr_ref
);
3772 static void output_abbrev_section (void);
3773 static void output_die_symbol (dw_die_ref
);
3774 static void output_die (dw_die_ref
);
3775 static void output_compilation_unit_header (void);
3776 static void output_comp_unit (dw_die_ref
, int);
3777 static const char *dwarf2_name (tree
, int);
3778 static void add_pubname (tree
, dw_die_ref
);
3779 static void output_pubnames (void);
3780 static void add_arange (tree
, dw_die_ref
);
3781 static void output_aranges (void);
3782 static unsigned int add_ranges (tree
);
3783 static void output_ranges (void);
3784 static void output_line_info (void);
3785 static void output_file_names (void);
3786 static dw_die_ref
base_type_die (tree
);
3787 static tree
root_type (tree
);
3788 static int is_base_type (tree
);
3789 static bool is_subrange_type (tree
);
3790 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
3791 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3792 static int type_is_enum (tree
);
3793 static unsigned int dbx_reg_number (rtx
);
3794 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
3795 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
3796 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
3797 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3798 static dw_loc_descr_ref
based_loc_descr (unsigned, HOST_WIDE_INT
, bool);
3799 static int is_based_loc (rtx
);
3800 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
, bool);
3801 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
3802 static dw_loc_descr_ref
loc_descriptor (rtx
, bool);
3803 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3804 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3805 static tree
field_type (tree
);
3806 static unsigned int simple_type_align_in_bits (tree
);
3807 static unsigned int simple_decl_align_in_bits (tree
);
3808 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
3809 static HOST_WIDE_INT
field_byte_offset (tree
);
3810 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3812 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3813 static void add_const_value_attribute (dw_die_ref
, rtx
);
3814 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3815 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
3816 static void insert_float (rtx
, unsigned char *);
3817 static rtx
rtl_for_decl_location (tree
);
3818 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
3819 enum dwarf_attribute
);
3820 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
3821 static void add_name_attribute (dw_die_ref
, const char *);
3822 static void add_comp_dir_attribute (dw_die_ref
);
3823 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3824 static void add_subscript_info (dw_die_ref
, tree
);
3825 static void add_byte_size_attribute (dw_die_ref
, tree
);
3826 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3827 static void add_bit_size_attribute (dw_die_ref
, tree
);
3828 static void add_prototyped_attribute (dw_die_ref
, tree
);
3829 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3830 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3831 static void add_src_coords_attributes (dw_die_ref
, tree
);
3832 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3833 static void push_decl_scope (tree
);
3834 static void pop_decl_scope (void);
3835 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3836 static inline int local_scope_p (dw_die_ref
);
3837 static inline int class_or_namespace_scope_p (dw_die_ref
);
3838 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3839 static const char *type_tag (tree
);
3840 static tree
member_declared_type (tree
);
3842 static const char *decl_start_label (tree
);
3844 static void gen_array_type_die (tree
, dw_die_ref
);
3845 static void gen_set_type_die (tree
, dw_die_ref
);
3847 static void gen_entry_point_die (tree
, dw_die_ref
);
3849 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
3850 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
3851 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
3852 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3853 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
3854 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3855 static void gen_formal_types_die (tree
, dw_die_ref
);
3856 static void gen_subprogram_die (tree
, dw_die_ref
);
3857 static void gen_variable_die (tree
, dw_die_ref
);
3858 static void gen_label_die (tree
, dw_die_ref
);
3859 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3860 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3861 static void gen_field_die (tree
, dw_die_ref
);
3862 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3863 static dw_die_ref
gen_compile_unit_die (const char *);
3864 static void gen_string_type_die (tree
, dw_die_ref
);
3865 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3866 static void gen_member_die (tree
, dw_die_ref
);
3867 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
3868 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3869 static void gen_typedef_die (tree
, dw_die_ref
);
3870 static void gen_type_die (tree
, dw_die_ref
);
3871 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
3872 static void gen_block_die (tree
, dw_die_ref
, int);
3873 static void decls_for_scope (tree
, dw_die_ref
, int);
3874 static int is_redundant_typedef (tree
);
3875 static void gen_namespace_die (tree
);
3876 static void gen_decl_die (tree
, dw_die_ref
);
3877 static dw_die_ref
force_decl_die (tree
);
3878 static dw_die_ref
force_type_die (tree
);
3879 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3880 static void declare_in_namespace (tree
, dw_die_ref
);
3881 static unsigned lookup_filename (const char *);
3882 static void init_file_table (void);
3883 static void retry_incomplete_types (void);
3884 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3885 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3886 static int file_info_cmp (const void *, const void *);
3887 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3888 const char *, const char *, unsigned);
3889 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
3890 const char *, const char *,
3892 static void output_loc_list (dw_loc_list_ref
);
3893 static char *gen_internal_sym (const char *);
3895 static void prune_unmark_dies (dw_die_ref
);
3896 static void prune_unused_types_mark (dw_die_ref
, int);
3897 static void prune_unused_types_walk (dw_die_ref
);
3898 static void prune_unused_types_walk_attribs (dw_die_ref
);
3899 static void prune_unused_types_prune (dw_die_ref
);
3900 static void prune_unused_types (void);
3901 static int maybe_emit_file (int);
3903 /* Section names used to hold DWARF debugging information. */
3904 #ifndef DEBUG_INFO_SECTION
3905 #define DEBUG_INFO_SECTION ".debug_info"
3907 #ifndef DEBUG_ABBREV_SECTION
3908 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3910 #ifndef DEBUG_ARANGES_SECTION
3911 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3913 #ifndef DEBUG_MACINFO_SECTION
3914 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3916 #ifndef DEBUG_LINE_SECTION
3917 #define DEBUG_LINE_SECTION ".debug_line"
3919 #ifndef DEBUG_LOC_SECTION
3920 #define DEBUG_LOC_SECTION ".debug_loc"
3922 #ifndef DEBUG_PUBNAMES_SECTION
3923 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3925 #ifndef DEBUG_STR_SECTION
3926 #define DEBUG_STR_SECTION ".debug_str"
3928 #ifndef DEBUG_RANGES_SECTION
3929 #define DEBUG_RANGES_SECTION ".debug_ranges"
3932 /* Standard ELF section names for compiled code and data. */
3933 #ifndef TEXT_SECTION_NAME
3934 #define TEXT_SECTION_NAME ".text"
3937 /* Section flags for .debug_str section. */
3938 #define DEBUG_STR_SECTION_FLAGS \
3939 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
3940 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3943 /* Labels we insert at beginning sections we can reference instead of
3944 the section names themselves. */
3946 #ifndef TEXT_SECTION_LABEL
3947 #define TEXT_SECTION_LABEL "Ltext"
3949 #ifndef DEBUG_LINE_SECTION_LABEL
3950 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3952 #ifndef DEBUG_INFO_SECTION_LABEL
3953 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3955 #ifndef DEBUG_ABBREV_SECTION_LABEL
3956 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3958 #ifndef DEBUG_LOC_SECTION_LABEL
3959 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3961 #ifndef DEBUG_RANGES_SECTION_LABEL
3962 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3964 #ifndef DEBUG_MACINFO_SECTION_LABEL
3965 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3968 /* Definitions of defaults for formats and names of various special
3969 (artificial) labels which may be generated within this file (when the -g
3970 options is used and DWARF2_DEBUGGING_INFO is in effect.
3971 If necessary, these may be overridden from within the tm.h file, but
3972 typically, overriding these defaults is unnecessary. */
3974 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3975 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3976 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3977 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3978 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3979 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3980 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3981 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3983 #ifndef TEXT_END_LABEL
3984 #define TEXT_END_LABEL "Letext"
3986 #ifndef BLOCK_BEGIN_LABEL
3987 #define BLOCK_BEGIN_LABEL "LBB"
3989 #ifndef BLOCK_END_LABEL
3990 #define BLOCK_END_LABEL "LBE"
3992 #ifndef LINE_CODE_LABEL
3993 #define LINE_CODE_LABEL "LM"
3995 #ifndef SEPARATE_LINE_CODE_LABEL
3996 #define SEPARATE_LINE_CODE_LABEL "LSM"
3999 /* We allow a language front-end to designate a function that is to be
4000 called to "demangle" any name before it it put into a DIE. */
4002 static const char *(*demangle_name_func
) (const char *);
4005 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4007 demangle_name_func
= func
;
4010 /* Test if rtl node points to a pseudo register. */
4013 is_pseudo_reg (rtx rtl
)
4015 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4016 || (GET_CODE (rtl
) == SUBREG
4017 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4020 /* Return a reference to a type, with its const and volatile qualifiers
4024 type_main_variant (tree type
)
4026 type
= TYPE_MAIN_VARIANT (type
);
4028 /* ??? There really should be only one main variant among any group of
4029 variants of a given type (and all of the MAIN_VARIANT values for all
4030 members of the group should point to that one type) but sometimes the C
4031 front-end messes this up for array types, so we work around that bug
4033 if (TREE_CODE (type
) == ARRAY_TYPE
)
4034 while (type
!= TYPE_MAIN_VARIANT (type
))
4035 type
= TYPE_MAIN_VARIANT (type
);
4040 /* Return nonzero if the given type node represents a tagged type. */
4043 is_tagged_type (tree type
)
4045 enum tree_code code
= TREE_CODE (type
);
4047 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4048 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4051 /* Convert a DIE tag into its string name. */
4054 dwarf_tag_name (unsigned int tag
)
4058 case DW_TAG_padding
:
4059 return "DW_TAG_padding";
4060 case DW_TAG_array_type
:
4061 return "DW_TAG_array_type";
4062 case DW_TAG_class_type
:
4063 return "DW_TAG_class_type";
4064 case DW_TAG_entry_point
:
4065 return "DW_TAG_entry_point";
4066 case DW_TAG_enumeration_type
:
4067 return "DW_TAG_enumeration_type";
4068 case DW_TAG_formal_parameter
:
4069 return "DW_TAG_formal_parameter";
4070 case DW_TAG_imported_declaration
:
4071 return "DW_TAG_imported_declaration";
4073 return "DW_TAG_label";
4074 case DW_TAG_lexical_block
:
4075 return "DW_TAG_lexical_block";
4077 return "DW_TAG_member";
4078 case DW_TAG_pointer_type
:
4079 return "DW_TAG_pointer_type";
4080 case DW_TAG_reference_type
:
4081 return "DW_TAG_reference_type";
4082 case DW_TAG_compile_unit
:
4083 return "DW_TAG_compile_unit";
4084 case DW_TAG_string_type
:
4085 return "DW_TAG_string_type";
4086 case DW_TAG_structure_type
:
4087 return "DW_TAG_structure_type";
4088 case DW_TAG_subroutine_type
:
4089 return "DW_TAG_subroutine_type";
4090 case DW_TAG_typedef
:
4091 return "DW_TAG_typedef";
4092 case DW_TAG_union_type
:
4093 return "DW_TAG_union_type";
4094 case DW_TAG_unspecified_parameters
:
4095 return "DW_TAG_unspecified_parameters";
4096 case DW_TAG_variant
:
4097 return "DW_TAG_variant";
4098 case DW_TAG_common_block
:
4099 return "DW_TAG_common_block";
4100 case DW_TAG_common_inclusion
:
4101 return "DW_TAG_common_inclusion";
4102 case DW_TAG_inheritance
:
4103 return "DW_TAG_inheritance";
4104 case DW_TAG_inlined_subroutine
:
4105 return "DW_TAG_inlined_subroutine";
4107 return "DW_TAG_module";
4108 case DW_TAG_ptr_to_member_type
:
4109 return "DW_TAG_ptr_to_member_type";
4110 case DW_TAG_set_type
:
4111 return "DW_TAG_set_type";
4112 case DW_TAG_subrange_type
:
4113 return "DW_TAG_subrange_type";
4114 case DW_TAG_with_stmt
:
4115 return "DW_TAG_with_stmt";
4116 case DW_TAG_access_declaration
:
4117 return "DW_TAG_access_declaration";
4118 case DW_TAG_base_type
:
4119 return "DW_TAG_base_type";
4120 case DW_TAG_catch_block
:
4121 return "DW_TAG_catch_block";
4122 case DW_TAG_const_type
:
4123 return "DW_TAG_const_type";
4124 case DW_TAG_constant
:
4125 return "DW_TAG_constant";
4126 case DW_TAG_enumerator
:
4127 return "DW_TAG_enumerator";
4128 case DW_TAG_file_type
:
4129 return "DW_TAG_file_type";
4131 return "DW_TAG_friend";
4132 case DW_TAG_namelist
:
4133 return "DW_TAG_namelist";
4134 case DW_TAG_namelist_item
:
4135 return "DW_TAG_namelist_item";
4136 case DW_TAG_namespace
:
4137 return "DW_TAG_namespace";
4138 case DW_TAG_packed_type
:
4139 return "DW_TAG_packed_type";
4140 case DW_TAG_subprogram
:
4141 return "DW_TAG_subprogram";
4142 case DW_TAG_template_type_param
:
4143 return "DW_TAG_template_type_param";
4144 case DW_TAG_template_value_param
:
4145 return "DW_TAG_template_value_param";
4146 case DW_TAG_thrown_type
:
4147 return "DW_TAG_thrown_type";
4148 case DW_TAG_try_block
:
4149 return "DW_TAG_try_block";
4150 case DW_TAG_variant_part
:
4151 return "DW_TAG_variant_part";
4152 case DW_TAG_variable
:
4153 return "DW_TAG_variable";
4154 case DW_TAG_volatile_type
:
4155 return "DW_TAG_volatile_type";
4156 case DW_TAG_imported_module
:
4157 return "DW_TAG_imported_module";
4158 case DW_TAG_MIPS_loop
:
4159 return "DW_TAG_MIPS_loop";
4160 case DW_TAG_format_label
:
4161 return "DW_TAG_format_label";
4162 case DW_TAG_function_template
:
4163 return "DW_TAG_function_template";
4164 case DW_TAG_class_template
:
4165 return "DW_TAG_class_template";
4166 case DW_TAG_GNU_BINCL
:
4167 return "DW_TAG_GNU_BINCL";
4168 case DW_TAG_GNU_EINCL
:
4169 return "DW_TAG_GNU_EINCL";
4171 return "DW_TAG_<unknown>";
4175 /* Convert a DWARF attribute code into its string name. */
4178 dwarf_attr_name (unsigned int attr
)
4183 return "DW_AT_sibling";
4184 case DW_AT_location
:
4185 return "DW_AT_location";
4187 return "DW_AT_name";
4188 case DW_AT_ordering
:
4189 return "DW_AT_ordering";
4190 case DW_AT_subscr_data
:
4191 return "DW_AT_subscr_data";
4192 case DW_AT_byte_size
:
4193 return "DW_AT_byte_size";
4194 case DW_AT_bit_offset
:
4195 return "DW_AT_bit_offset";
4196 case DW_AT_bit_size
:
4197 return "DW_AT_bit_size";
4198 case DW_AT_element_list
:
4199 return "DW_AT_element_list";
4200 case DW_AT_stmt_list
:
4201 return "DW_AT_stmt_list";
4203 return "DW_AT_low_pc";
4205 return "DW_AT_high_pc";
4206 case DW_AT_language
:
4207 return "DW_AT_language";
4209 return "DW_AT_member";
4211 return "DW_AT_discr";
4212 case DW_AT_discr_value
:
4213 return "DW_AT_discr_value";
4214 case DW_AT_visibility
:
4215 return "DW_AT_visibility";
4217 return "DW_AT_import";
4218 case DW_AT_string_length
:
4219 return "DW_AT_string_length";
4220 case DW_AT_common_reference
:
4221 return "DW_AT_common_reference";
4222 case DW_AT_comp_dir
:
4223 return "DW_AT_comp_dir";
4224 case DW_AT_const_value
:
4225 return "DW_AT_const_value";
4226 case DW_AT_containing_type
:
4227 return "DW_AT_containing_type";
4228 case DW_AT_default_value
:
4229 return "DW_AT_default_value";
4231 return "DW_AT_inline";
4232 case DW_AT_is_optional
:
4233 return "DW_AT_is_optional";
4234 case DW_AT_lower_bound
:
4235 return "DW_AT_lower_bound";
4236 case DW_AT_producer
:
4237 return "DW_AT_producer";
4238 case DW_AT_prototyped
:
4239 return "DW_AT_prototyped";
4240 case DW_AT_return_addr
:
4241 return "DW_AT_return_addr";
4242 case DW_AT_start_scope
:
4243 return "DW_AT_start_scope";
4244 case DW_AT_stride_size
:
4245 return "DW_AT_stride_size";
4246 case DW_AT_upper_bound
:
4247 return "DW_AT_upper_bound";
4248 case DW_AT_abstract_origin
:
4249 return "DW_AT_abstract_origin";
4250 case DW_AT_accessibility
:
4251 return "DW_AT_accessibility";
4252 case DW_AT_address_class
:
4253 return "DW_AT_address_class";
4254 case DW_AT_artificial
:
4255 return "DW_AT_artificial";
4256 case DW_AT_base_types
:
4257 return "DW_AT_base_types";
4258 case DW_AT_calling_convention
:
4259 return "DW_AT_calling_convention";
4261 return "DW_AT_count";
4262 case DW_AT_data_member_location
:
4263 return "DW_AT_data_member_location";
4264 case DW_AT_decl_column
:
4265 return "DW_AT_decl_column";
4266 case DW_AT_decl_file
:
4267 return "DW_AT_decl_file";
4268 case DW_AT_decl_line
:
4269 return "DW_AT_decl_line";
4270 case DW_AT_declaration
:
4271 return "DW_AT_declaration";
4272 case DW_AT_discr_list
:
4273 return "DW_AT_discr_list";
4274 case DW_AT_encoding
:
4275 return "DW_AT_encoding";
4276 case DW_AT_external
:
4277 return "DW_AT_external";
4278 case DW_AT_frame_base
:
4279 return "DW_AT_frame_base";
4281 return "DW_AT_friend";
4282 case DW_AT_identifier_case
:
4283 return "DW_AT_identifier_case";
4284 case DW_AT_macro_info
:
4285 return "DW_AT_macro_info";
4286 case DW_AT_namelist_items
:
4287 return "DW_AT_namelist_items";
4288 case DW_AT_priority
:
4289 return "DW_AT_priority";
4291 return "DW_AT_segment";
4292 case DW_AT_specification
:
4293 return "DW_AT_specification";
4294 case DW_AT_static_link
:
4295 return "DW_AT_static_link";
4297 return "DW_AT_type";
4298 case DW_AT_use_location
:
4299 return "DW_AT_use_location";
4300 case DW_AT_variable_parameter
:
4301 return "DW_AT_variable_parameter";
4302 case DW_AT_virtuality
:
4303 return "DW_AT_virtuality";
4304 case DW_AT_vtable_elem_location
:
4305 return "DW_AT_vtable_elem_location";
4307 case DW_AT_allocated
:
4308 return "DW_AT_allocated";
4309 case DW_AT_associated
:
4310 return "DW_AT_associated";
4311 case DW_AT_data_location
:
4312 return "DW_AT_data_location";
4314 return "DW_AT_stride";
4315 case DW_AT_entry_pc
:
4316 return "DW_AT_entry_pc";
4317 case DW_AT_use_UTF8
:
4318 return "DW_AT_use_UTF8";
4319 case DW_AT_extension
:
4320 return "DW_AT_extension";
4322 return "DW_AT_ranges";
4323 case DW_AT_trampoline
:
4324 return "DW_AT_trampoline";
4325 case DW_AT_call_column
:
4326 return "DW_AT_call_column";
4327 case DW_AT_call_file
:
4328 return "DW_AT_call_file";
4329 case DW_AT_call_line
:
4330 return "DW_AT_call_line";
4332 case DW_AT_MIPS_fde
:
4333 return "DW_AT_MIPS_fde";
4334 case DW_AT_MIPS_loop_begin
:
4335 return "DW_AT_MIPS_loop_begin";
4336 case DW_AT_MIPS_tail_loop_begin
:
4337 return "DW_AT_MIPS_tail_loop_begin";
4338 case DW_AT_MIPS_epilog_begin
:
4339 return "DW_AT_MIPS_epilog_begin";
4340 case DW_AT_MIPS_loop_unroll_factor
:
4341 return "DW_AT_MIPS_loop_unroll_factor";
4342 case DW_AT_MIPS_software_pipeline_depth
:
4343 return "DW_AT_MIPS_software_pipeline_depth";
4344 case DW_AT_MIPS_linkage_name
:
4345 return "DW_AT_MIPS_linkage_name";
4346 case DW_AT_MIPS_stride
:
4347 return "DW_AT_MIPS_stride";
4348 case DW_AT_MIPS_abstract_name
:
4349 return "DW_AT_MIPS_abstract_name";
4350 case DW_AT_MIPS_clone_origin
:
4351 return "DW_AT_MIPS_clone_origin";
4352 case DW_AT_MIPS_has_inlines
:
4353 return "DW_AT_MIPS_has_inlines";
4355 case DW_AT_sf_names
:
4356 return "DW_AT_sf_names";
4357 case DW_AT_src_info
:
4358 return "DW_AT_src_info";
4359 case DW_AT_mac_info
:
4360 return "DW_AT_mac_info";
4361 case DW_AT_src_coords
:
4362 return "DW_AT_src_coords";
4363 case DW_AT_body_begin
:
4364 return "DW_AT_body_begin";
4365 case DW_AT_body_end
:
4366 return "DW_AT_body_end";
4367 case DW_AT_GNU_vector
:
4368 return "DW_AT_GNU_vector";
4370 case DW_AT_VMS_rtnbeg_pd_address
:
4371 return "DW_AT_VMS_rtnbeg_pd_address";
4374 return "DW_AT_<unknown>";
4378 /* Convert a DWARF value form code into its string name. */
4381 dwarf_form_name (unsigned int form
)
4386 return "DW_FORM_addr";
4387 case DW_FORM_block2
:
4388 return "DW_FORM_block2";
4389 case DW_FORM_block4
:
4390 return "DW_FORM_block4";
4392 return "DW_FORM_data2";
4394 return "DW_FORM_data4";
4396 return "DW_FORM_data8";
4397 case DW_FORM_string
:
4398 return "DW_FORM_string";
4400 return "DW_FORM_block";
4401 case DW_FORM_block1
:
4402 return "DW_FORM_block1";
4404 return "DW_FORM_data1";
4406 return "DW_FORM_flag";
4408 return "DW_FORM_sdata";
4410 return "DW_FORM_strp";
4412 return "DW_FORM_udata";
4413 case DW_FORM_ref_addr
:
4414 return "DW_FORM_ref_addr";
4416 return "DW_FORM_ref1";
4418 return "DW_FORM_ref2";
4420 return "DW_FORM_ref4";
4422 return "DW_FORM_ref8";
4423 case DW_FORM_ref_udata
:
4424 return "DW_FORM_ref_udata";
4425 case DW_FORM_indirect
:
4426 return "DW_FORM_indirect";
4428 return "DW_FORM_<unknown>";
4432 /* Convert a DWARF type code into its string name. */
4436 dwarf_type_encoding_name (unsigned enc
)
4440 case DW_ATE_address
:
4441 return "DW_ATE_address";
4442 case DW_ATE_boolean
:
4443 return "DW_ATE_boolean";
4444 case DW_ATE_complex_float
:
4445 return "DW_ATE_complex_float";
4447 return "DW_ATE_float";
4449 return "DW_ATE_signed";
4450 case DW_ATE_signed_char
:
4451 return "DW_ATE_signed_char";
4452 case DW_ATE_unsigned
:
4453 return "DW_ATE_unsigned";
4454 case DW_ATE_unsigned_char
:
4455 return "DW_ATE_unsigned_char";
4457 return "DW_ATE_<unknown>";
4462 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4463 instance of an inlined instance of a decl which is local to an inline
4464 function, so we have to trace all of the way back through the origin chain
4465 to find out what sort of node actually served as the original seed for the
4469 decl_ultimate_origin (tree decl
)
4471 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4472 nodes in the function to point to themselves; ignore that if
4473 we're trying to output the abstract instance of this function. */
4474 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4477 #ifdef ENABLE_CHECKING
4478 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4479 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4480 most distant ancestor, this should never happen. */
4484 return DECL_ABSTRACT_ORIGIN (decl
);
4487 /* Determine the "ultimate origin" of a block. The block may be an inlined
4488 instance of an inlined instance of a block which is local to an inline
4489 function, so we have to trace all of the way back through the origin chain
4490 to find out what sort of node actually served as the original seed for the
4494 block_ultimate_origin (tree block
)
4496 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4498 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4499 nodes in the function to point to themselves; ignore that if
4500 we're trying to output the abstract instance of this function. */
4501 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4504 if (immediate_origin
== NULL_TREE
)
4509 tree lookahead
= immediate_origin
;
4513 ret_val
= lookahead
;
4514 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4515 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4517 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4523 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4524 of a virtual function may refer to a base class, so we check the 'this'
4528 decl_class_context (tree decl
)
4530 tree context
= NULL_TREE
;
4532 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4533 context
= DECL_CONTEXT (decl
);
4535 context
= TYPE_MAIN_VARIANT
4536 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4538 if (context
&& !TYPE_P (context
))
4539 context
= NULL_TREE
;
4544 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4545 addition order, and correct that in reverse_all_dies. */
4548 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4550 if (die
!= NULL
&& attr
!= NULL
)
4552 attr
->dw_attr_next
= die
->die_attr
;
4553 die
->die_attr
= attr
;
4557 static inline enum dw_val_class
4558 AT_class (dw_attr_ref a
)
4560 return a
->dw_attr_val
.val_class
;
4563 /* Add a flag value attribute to a DIE. */
4566 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4568 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4570 attr
->dw_attr_next
= NULL
;
4571 attr
->dw_attr
= attr_kind
;
4572 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4573 attr
->dw_attr_val
.v
.val_flag
= flag
;
4574 add_dwarf_attr (die
, attr
);
4577 static inline unsigned
4578 AT_flag (dw_attr_ref a
)
4580 if (a
&& AT_class (a
) == dw_val_class_flag
)
4581 return a
->dw_attr_val
.v
.val_flag
;
4586 /* Add a signed integer attribute value to a DIE. */
4589 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4591 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4593 attr
->dw_attr_next
= NULL
;
4594 attr
->dw_attr
= attr_kind
;
4595 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4596 attr
->dw_attr_val
.v
.val_int
= int_val
;
4597 add_dwarf_attr (die
, attr
);
4600 static inline HOST_WIDE_INT
4601 AT_int (dw_attr_ref a
)
4603 if (a
&& AT_class (a
) == dw_val_class_const
)
4604 return a
->dw_attr_val
.v
.val_int
;
4609 /* Add an unsigned integer attribute value to a DIE. */
4612 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4613 unsigned HOST_WIDE_INT unsigned_val
)
4615 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4617 attr
->dw_attr_next
= NULL
;
4618 attr
->dw_attr
= attr_kind
;
4619 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4620 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4621 add_dwarf_attr (die
, attr
);
4624 static inline unsigned HOST_WIDE_INT
4625 AT_unsigned (dw_attr_ref a
)
4627 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4628 return a
->dw_attr_val
.v
.val_unsigned
;
4633 /* Add an unsigned double integer attribute value to a DIE. */
4636 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4637 long unsigned int val_hi
, long unsigned int val_low
)
4639 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4641 attr
->dw_attr_next
= NULL
;
4642 attr
->dw_attr
= attr_kind
;
4643 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4644 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4645 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4646 add_dwarf_attr (die
, attr
);
4649 /* Add a floating point attribute value to a DIE and return it. */
4652 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4653 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4655 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4657 attr
->dw_attr_next
= NULL
;
4658 attr
->dw_attr
= attr_kind
;
4659 attr
->dw_attr_val
.val_class
= dw_val_class_vec
;
4660 attr
->dw_attr_val
.v
.val_vec
.length
= length
;
4661 attr
->dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4662 attr
->dw_attr_val
.v
.val_vec
.array
= array
;
4663 add_dwarf_attr (die
, attr
);
4666 /* Hash and equality functions for debug_str_hash. */
4669 debug_str_do_hash (const void *x
)
4671 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4675 debug_str_eq (const void *x1
, const void *x2
)
4677 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4678 (const char *)x2
) == 0;
4681 /* Add a string attribute value to a DIE. */
4684 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4686 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4687 struct indirect_string_node
*node
;
4690 if (! debug_str_hash
)
4691 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4692 debug_str_eq
, NULL
);
4694 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4695 htab_hash_string (str
), INSERT
);
4697 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4698 node
= (struct indirect_string_node
*) *slot
;
4699 node
->str
= ggc_strdup (str
);
4702 attr
->dw_attr_next
= NULL
;
4703 attr
->dw_attr
= attr_kind
;
4704 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4705 attr
->dw_attr_val
.v
.val_str
= node
;
4706 add_dwarf_attr (die
, attr
);
4709 static inline const char *
4710 AT_string (dw_attr_ref a
)
4712 if (a
&& AT_class (a
) == dw_val_class_str
)
4713 return a
->dw_attr_val
.v
.val_str
->str
;
4718 /* Find out whether a string should be output inline in DIE
4719 or out-of-line in .debug_str section. */
4722 AT_string_form (dw_attr_ref a
)
4724 if (a
&& AT_class (a
) == dw_val_class_str
)
4726 struct indirect_string_node
*node
;
4730 node
= a
->dw_attr_val
.v
.val_str
;
4734 len
= strlen (node
->str
) + 1;
4736 /* If the string is shorter or equal to the size of the reference, it is
4737 always better to put it inline. */
4738 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4739 return node
->form
= DW_FORM_string
;
4741 /* If we cannot expect the linker to merge strings in .debug_str
4742 section, only put it into .debug_str if it is worth even in this
4744 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4745 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4746 return node
->form
= DW_FORM_string
;
4748 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4749 ++dw2_string_counter
;
4750 node
->label
= xstrdup (label
);
4752 return node
->form
= DW_FORM_strp
;
4758 /* Add a DIE reference attribute value to a DIE. */
4761 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4763 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4765 attr
->dw_attr_next
= NULL
;
4766 attr
->dw_attr
= attr_kind
;
4767 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4768 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4769 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4770 add_dwarf_attr (die
, attr
);
4773 /* Add an AT_specification attribute to a DIE, and also make the back
4774 pointer from the specification to the definition. */
4777 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4779 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4780 if (targ_die
->die_definition
)
4782 targ_die
->die_definition
= die
;
4785 static inline dw_die_ref
4786 AT_ref (dw_attr_ref a
)
4788 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4789 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4795 AT_ref_external (dw_attr_ref a
)
4797 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4798 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4804 set_AT_ref_external (dw_attr_ref a
, int i
)
4806 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4807 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4812 /* Add an FDE reference attribute value to a DIE. */
4815 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4817 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4819 attr
->dw_attr_next
= NULL
;
4820 attr
->dw_attr
= attr_kind
;
4821 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4822 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4823 add_dwarf_attr (die
, attr
);
4826 /* Add a location description attribute value to a DIE. */
4829 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4831 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4833 attr
->dw_attr_next
= NULL
;
4834 attr
->dw_attr
= attr_kind
;
4835 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4836 attr
->dw_attr_val
.v
.val_loc
= loc
;
4837 add_dwarf_attr (die
, attr
);
4840 static inline dw_loc_descr_ref
4841 AT_loc (dw_attr_ref a
)
4843 if (a
&& AT_class (a
) == dw_val_class_loc
)
4844 return a
->dw_attr_val
.v
.val_loc
;
4850 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4852 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4854 attr
->dw_attr_next
= NULL
;
4855 attr
->dw_attr
= attr_kind
;
4856 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4857 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4858 add_dwarf_attr (die
, attr
);
4859 have_location_lists
= 1;
4862 static inline dw_loc_list_ref
4863 AT_loc_list (dw_attr_ref a
)
4865 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4866 return a
->dw_attr_val
.v
.val_loc_list
;
4871 /* Add an address constant attribute value to a DIE. */
4874 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4876 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4878 attr
->dw_attr_next
= NULL
;
4879 attr
->dw_attr
= attr_kind
;
4880 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4881 attr
->dw_attr_val
.v
.val_addr
= addr
;
4882 add_dwarf_attr (die
, attr
);
4886 AT_addr (dw_attr_ref a
)
4888 if (a
&& AT_class (a
) == dw_val_class_addr
)
4889 return a
->dw_attr_val
.v
.val_addr
;
4894 /* Add a label identifier attribute value to a DIE. */
4897 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
4899 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4901 attr
->dw_attr_next
= NULL
;
4902 attr
->dw_attr
= attr_kind
;
4903 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4904 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4905 add_dwarf_attr (die
, attr
);
4908 /* Add a section offset attribute value to a DIE. */
4911 add_AT_lbl_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *label
)
4913 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4915 attr
->dw_attr_next
= NULL
;
4916 attr
->dw_attr
= attr_kind
;
4917 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
4918 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4919 add_dwarf_attr (die
, attr
);
4922 /* Add an offset attribute value to a DIE. */
4925 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4926 unsigned HOST_WIDE_INT offset
)
4928 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4930 attr
->dw_attr_next
= NULL
;
4931 attr
->dw_attr
= attr_kind
;
4932 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
4933 attr
->dw_attr_val
.v
.val_offset
= offset
;
4934 add_dwarf_attr (die
, attr
);
4937 /* Add an range_list attribute value to a DIE. */
4940 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4941 long unsigned int offset
)
4943 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4945 attr
->dw_attr_next
= NULL
;
4946 attr
->dw_attr
= attr_kind
;
4947 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
4948 attr
->dw_attr_val
.v
.val_offset
= offset
;
4949 add_dwarf_attr (die
, attr
);
4952 static inline const char *
4953 AT_lbl (dw_attr_ref a
)
4955 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
4956 || AT_class (a
) == dw_val_class_lbl_offset
))
4957 return a
->dw_attr_val
.v
.val_lbl_id
;
4962 /* Get the attribute of type attr_kind. */
4965 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4968 dw_die_ref spec
= NULL
;
4972 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
4973 if (a
->dw_attr
== attr_kind
)
4975 else if (a
->dw_attr
== DW_AT_specification
4976 || a
->dw_attr
== DW_AT_abstract_origin
)
4980 return get_AT (spec
, attr_kind
);
4986 /* Return the "low pc" attribute value, typically associated with a subprogram
4987 DIE. Return null if the "low pc" attribute is either not present, or if it
4988 cannot be represented as an assembler label identifier. */
4990 static inline const char *
4991 get_AT_low_pc (dw_die_ref die
)
4993 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4995 return a
? AT_lbl (a
) : NULL
;
4998 /* Return the "high pc" attribute value, typically associated with a subprogram
4999 DIE. Return null if the "high pc" attribute is either not present, or if it
5000 cannot be represented as an assembler label identifier. */
5002 static inline const char *
5003 get_AT_hi_pc (dw_die_ref die
)
5005 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5007 return a
? AT_lbl (a
) : NULL
;
5010 /* Return the value of the string attribute designated by ATTR_KIND, or
5011 NULL if it is not present. */
5013 static inline const char *
5014 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5016 dw_attr_ref a
= get_AT (die
, attr_kind
);
5018 return a
? AT_string (a
) : NULL
;
5021 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5022 if it is not present. */
5025 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5027 dw_attr_ref a
= get_AT (die
, attr_kind
);
5029 return a
? AT_flag (a
) : 0;
5032 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5033 if it is not present. */
5035 static inline unsigned
5036 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5038 dw_attr_ref a
= get_AT (die
, attr_kind
);
5040 return a
? AT_unsigned (a
) : 0;
5043 static inline dw_die_ref
5044 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5046 dw_attr_ref a
= get_AT (die
, attr_kind
);
5048 return a
? AT_ref (a
) : NULL
;
5051 /* Return TRUE if the language is C or C++. */
5056 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5058 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
5059 || lang
== DW_LANG_C_plus_plus
);
5062 /* Return TRUE if the language is C++. */
5067 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
5068 == DW_LANG_C_plus_plus
);
5071 /* Return TRUE if the language is Fortran. */
5076 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5078 return (lang
== DW_LANG_Fortran77
5079 || lang
== DW_LANG_Fortran90
5080 || lang
== DW_LANG_Fortran95
);
5083 /* Return TRUE if the language is Java. */
5088 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5090 return lang
== DW_LANG_Java
;
5093 /* Return TRUE if the language is Ada. */
5098 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5100 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5103 /* Free up the memory used by A. */
5105 static inline void free_AT (dw_attr_ref
);
5107 free_AT (dw_attr_ref a
)
5109 if (AT_class (a
) == dw_val_class_str
)
5110 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5111 a
->dw_attr_val
.v
.val_str
->refcount
--;
5114 /* Remove the specified attribute if present. */
5117 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5120 dw_attr_ref removed
= NULL
;
5124 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
5125 if ((*p
)->dw_attr
== attr_kind
)
5128 *p
= (*p
)->dw_attr_next
;
5137 /* Remove child die whose die_tag is specified tag. */
5140 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5142 dw_die_ref current
, prev
, next
;
5143 current
= die
->die_child
;
5145 while (current
!= NULL
)
5147 if (current
->die_tag
== tag
)
5149 next
= current
->die_sib
;
5151 die
->die_child
= next
;
5153 prev
->die_sib
= next
;
5160 current
= current
->die_sib
;
5165 /* Free up the memory used by DIE. */
5168 free_die (dw_die_ref die
)
5170 remove_children (die
);
5173 /* Discard the children of this DIE. */
5176 remove_children (dw_die_ref die
)
5178 dw_die_ref child_die
= die
->die_child
;
5180 die
->die_child
= NULL
;
5182 while (child_die
!= NULL
)
5184 dw_die_ref tmp_die
= child_die
;
5187 child_die
= child_die
->die_sib
;
5189 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5191 dw_attr_ref tmp_a
= a
;
5193 a
= a
->dw_attr_next
;
5201 /* Add a child DIE below its parent. We build the lists up in reverse
5202 addition order, and correct that in reverse_all_dies. */
5205 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5207 if (die
!= NULL
&& child_die
!= NULL
)
5209 if (die
== child_die
)
5212 child_die
->die_parent
= die
;
5213 child_die
->die_sib
= die
->die_child
;
5214 die
->die_child
= child_die
;
5218 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5219 is the specification, to the front of PARENT's list of children. */
5222 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5226 /* We want the declaration DIE from inside the class, not the
5227 specification DIE at toplevel. */
5228 if (child
->die_parent
!= parent
)
5230 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5236 if (child
->die_parent
!= parent
5237 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5240 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5243 *p
= child
->die_sib
;
5247 child
->die_parent
= parent
;
5248 child
->die_sib
= parent
->die_child
;
5249 parent
->die_child
= child
;
5252 /* Return a pointer to a newly created DIE node. */
5254 static inline dw_die_ref
5255 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5257 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5259 die
->die_tag
= tag_value
;
5261 if (parent_die
!= NULL
)
5262 add_child_die (parent_die
, die
);
5265 limbo_die_node
*limbo_node
;
5267 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5268 limbo_node
->die
= die
;
5269 limbo_node
->created_for
= t
;
5270 limbo_node
->next
= limbo_die_list
;
5271 limbo_die_list
= limbo_node
;
5277 /* Return the DIE associated with the given type specifier. */
5279 static inline dw_die_ref
5280 lookup_type_die (tree type
)
5282 return TYPE_SYMTAB_DIE (type
);
5285 /* Equate a DIE to a given type specifier. */
5288 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5290 TYPE_SYMTAB_DIE (type
) = type_die
;
5293 /* Returns a hash value for X (which really is a die_struct). */
5296 decl_die_table_hash (const void *x
)
5298 return (hashval_t
) ((const dw_die_ref
) x
)->decl_id
;
5301 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5304 decl_die_table_eq (const void *x
, const void *y
)
5306 return (((const dw_die_ref
) x
)->decl_id
== DECL_UID ((const tree
) y
));
5309 /* Return the DIE associated with a given declaration. */
5311 static inline dw_die_ref
5312 lookup_decl_die (tree decl
)
5314 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5317 /* Returns a hash value for X (which really is a var_loc_list). */
5320 decl_loc_table_hash (const void *x
)
5322 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5325 /* Return nonzero if decl_id of var_loc_list X is the same as
5329 decl_loc_table_eq (const void *x
, const void *y
)
5331 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const tree
) y
));
5334 /* Return the var_loc list associated with a given declaration. */
5336 static inline var_loc_list
*
5337 lookup_decl_loc (tree decl
)
5339 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5342 /* Equate a DIE to a particular declaration. */
5345 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5347 unsigned int decl_id
= DECL_UID (decl
);
5350 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5352 decl_die
->decl_id
= decl_id
;
5355 /* Add a variable location node to the linked list for DECL. */
5358 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5360 unsigned int decl_id
= DECL_UID (decl
);
5364 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5367 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5368 temp
->decl_id
= decl_id
;
5376 /* If the current location is the same as the end of the list,
5377 we have nothing to do. */
5378 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5379 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5381 /* Add LOC to the end of list and update LAST. */
5382 temp
->last
->next
= loc
;
5386 /* Do not add empty location to the beginning of the list. */
5387 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5394 /* Keep track of the number of spaces used to indent the
5395 output of the debugging routines that print the structure of
5396 the DIE internal representation. */
5397 static int print_indent
;
5399 /* Indent the line the number of spaces given by print_indent. */
5402 print_spaces (FILE *outfile
)
5404 fprintf (outfile
, "%*s", print_indent
, "");
5407 /* Print the information associated with a given DIE, and its children.
5408 This routine is a debugging aid only. */
5411 print_die (dw_die_ref die
, FILE *outfile
)
5416 print_spaces (outfile
);
5417 fprintf (outfile
, "DIE %4lu: %s\n",
5418 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5419 print_spaces (outfile
);
5420 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5421 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5423 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5425 print_spaces (outfile
);
5426 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5428 switch (AT_class (a
))
5430 case dw_val_class_addr
:
5431 fprintf (outfile
, "address");
5433 case dw_val_class_offset
:
5434 fprintf (outfile
, "offset");
5436 case dw_val_class_loc
:
5437 fprintf (outfile
, "location descriptor");
5439 case dw_val_class_loc_list
:
5440 fprintf (outfile
, "location list -> label:%s",
5441 AT_loc_list (a
)->ll_symbol
);
5443 case dw_val_class_range_list
:
5444 fprintf (outfile
, "range list");
5446 case dw_val_class_const
:
5447 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5449 case dw_val_class_unsigned_const
:
5450 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5452 case dw_val_class_long_long
:
5453 fprintf (outfile
, "constant (%lu,%lu)",
5454 a
->dw_attr_val
.v
.val_long_long
.hi
,
5455 a
->dw_attr_val
.v
.val_long_long
.low
);
5457 case dw_val_class_vec
:
5458 fprintf (outfile
, "floating-point or vector constant");
5460 case dw_val_class_flag
:
5461 fprintf (outfile
, "%u", AT_flag (a
));
5463 case dw_val_class_die_ref
:
5464 if (AT_ref (a
) != NULL
)
5466 if (AT_ref (a
)->die_symbol
)
5467 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5469 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5472 fprintf (outfile
, "die -> <null>");
5474 case dw_val_class_lbl_id
:
5475 case dw_val_class_lbl_offset
:
5476 fprintf (outfile
, "label: %s", AT_lbl (a
));
5478 case dw_val_class_str
:
5479 if (AT_string (a
) != NULL
)
5480 fprintf (outfile
, "\"%s\"", AT_string (a
));
5482 fprintf (outfile
, "<null>");
5488 fprintf (outfile
, "\n");
5491 if (die
->die_child
!= NULL
)
5494 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5495 print_die (c
, outfile
);
5499 if (print_indent
== 0)
5500 fprintf (outfile
, "\n");
5503 /* Print the contents of the source code line number correspondence table.
5504 This routine is a debugging aid only. */
5507 print_dwarf_line_table (FILE *outfile
)
5510 dw_line_info_ref line_info
;
5512 fprintf (outfile
, "\n\nDWARF source line information\n");
5513 for (i
= 1; i
< line_info_table_in_use
; i
++)
5515 line_info
= &line_info_table
[i
];
5516 fprintf (outfile
, "%5d: ", i
);
5517 fprintf (outfile
, "%-20s",
5518 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5519 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5520 fprintf (outfile
, "\n");
5523 fprintf (outfile
, "\n\n");
5526 /* Print the information collected for a given DIE. */
5529 debug_dwarf_die (dw_die_ref die
)
5531 print_die (die
, stderr
);
5534 /* Print all DWARF information collected for the compilation unit.
5535 This routine is a debugging aid only. */
5541 print_die (comp_unit_die
, stderr
);
5542 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5543 print_dwarf_line_table (stderr
);
5546 /* We build up the lists of children and attributes by pushing new ones
5547 onto the beginning of the list. Reverse the lists for DIE so that
5548 they are in order of addition. */
5551 reverse_die_lists (dw_die_ref die
)
5553 dw_die_ref c
, cp
, cn
;
5554 dw_attr_ref a
, ap
, an
;
5556 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5558 an
= a
->dw_attr_next
;
5559 a
->dw_attr_next
= ap
;
5565 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5572 die
->die_child
= cp
;
5575 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5576 reverse all dies in add_sibling_attributes, which runs through all the dies,
5577 it would reverse all the dies. Now, however, since we don't call
5578 reverse_die_lists in add_sibling_attributes, we need a routine to
5579 recursively reverse all the dies. This is that routine. */
5582 reverse_all_dies (dw_die_ref die
)
5586 reverse_die_lists (die
);
5588 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5589 reverse_all_dies (c
);
5592 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5593 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5594 DIE that marks the start of the DIEs for this include file. */
5597 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5599 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5600 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5602 new_unit
->die_sib
= old_unit
;
5606 /* Close an include-file CU and reopen the enclosing one. */
5609 pop_compile_unit (dw_die_ref old_unit
)
5611 dw_die_ref new_unit
= old_unit
->die_sib
;
5613 old_unit
->die_sib
= NULL
;
5617 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5618 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5620 /* Calculate the checksum of a location expression. */
5623 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5625 CHECKSUM (loc
->dw_loc_opc
);
5626 CHECKSUM (loc
->dw_loc_oprnd1
);
5627 CHECKSUM (loc
->dw_loc_oprnd2
);
5630 /* Calculate the checksum of an attribute. */
5633 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5635 dw_loc_descr_ref loc
;
5638 CHECKSUM (at
->dw_attr
);
5640 /* We don't care about differences in file numbering. */
5641 if (at
->dw_attr
== DW_AT_decl_file
5642 /* Or that this was compiled with a different compiler snapshot; if
5643 the output is the same, that's what matters. */
5644 || at
->dw_attr
== DW_AT_producer
)
5647 switch (AT_class (at
))
5649 case dw_val_class_const
:
5650 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5652 case dw_val_class_unsigned_const
:
5653 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5655 case dw_val_class_long_long
:
5656 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5658 case dw_val_class_vec
:
5659 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5661 case dw_val_class_flag
:
5662 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5664 case dw_val_class_str
:
5665 CHECKSUM_STRING (AT_string (at
));
5668 case dw_val_class_addr
:
5670 switch (GET_CODE (r
))
5673 CHECKSUM_STRING (XSTR (r
, 0));
5681 case dw_val_class_offset
:
5682 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5685 case dw_val_class_loc
:
5686 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5687 loc_checksum (loc
, ctx
);
5690 case dw_val_class_die_ref
:
5691 die_checksum (AT_ref (at
), ctx
, mark
);
5694 case dw_val_class_fde_ref
:
5695 case dw_val_class_lbl_id
:
5696 case dw_val_class_lbl_offset
:
5704 /* Calculate the checksum of a DIE. */
5707 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5712 /* To avoid infinite recursion. */
5715 CHECKSUM (die
->die_mark
);
5718 die
->die_mark
= ++(*mark
);
5720 CHECKSUM (die
->die_tag
);
5722 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5723 attr_checksum (a
, ctx
, mark
);
5725 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5726 die_checksum (c
, ctx
, mark
);
5730 #undef CHECKSUM_STRING
5732 /* Do the location expressions look same? */
5734 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5736 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5737 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5738 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5741 /* Do the values look the same? */
5743 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
5745 dw_loc_descr_ref loc1
, loc2
;
5748 if (v1
->val_class
!= v2
->val_class
)
5751 switch (v1
->val_class
)
5753 case dw_val_class_const
:
5754 return v1
->v
.val_int
== v2
->v
.val_int
;
5755 case dw_val_class_unsigned_const
:
5756 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5757 case dw_val_class_long_long
:
5758 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5759 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5760 case dw_val_class_vec
:
5761 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
5762 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
5764 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
5765 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
5768 case dw_val_class_flag
:
5769 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5770 case dw_val_class_str
:
5771 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5773 case dw_val_class_addr
:
5774 r1
= v1
->v
.val_addr
;
5775 r2
= v2
->v
.val_addr
;
5776 if (GET_CODE (r1
) != GET_CODE (r2
))
5778 switch (GET_CODE (r1
))
5781 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5787 case dw_val_class_offset
:
5788 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5790 case dw_val_class_loc
:
5791 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5793 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5794 if (!same_loc_p (loc1
, loc2
, mark
))
5796 return !loc1
&& !loc2
;
5798 case dw_val_class_die_ref
:
5799 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5801 case dw_val_class_fde_ref
:
5802 case dw_val_class_lbl_id
:
5803 case dw_val_class_lbl_offset
:
5811 /* Do the attributes look the same? */
5814 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5816 if (at1
->dw_attr
!= at2
->dw_attr
)
5819 /* We don't care about differences in file numbering. */
5820 if (at1
->dw_attr
== DW_AT_decl_file
5821 /* Or that this was compiled with a different compiler snapshot; if
5822 the output is the same, that's what matters. */
5823 || at1
->dw_attr
== DW_AT_producer
)
5826 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5829 /* Do the dies look the same? */
5832 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5837 /* To avoid infinite recursion. */
5839 return die1
->die_mark
== die2
->die_mark
;
5840 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5842 if (die1
->die_tag
!= die2
->die_tag
)
5845 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5847 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5848 if (!same_attr_p (a1
, a2
, mark
))
5853 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5855 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5856 if (!same_die_p (c1
, c2
, mark
))
5864 /* Do the dies look the same? Wrapper around same_die_p. */
5867 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5870 int ret
= same_die_p (die1
, die2
, &mark
);
5872 unmark_all_dies (die1
);
5873 unmark_all_dies (die2
);
5878 /* The prefix to attach to symbols on DIEs in the current comdat debug
5880 static char *comdat_symbol_id
;
5882 /* The index of the current symbol within the current comdat CU. */
5883 static unsigned int comdat_symbol_number
;
5885 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5886 children, and set comdat_symbol_id accordingly. */
5889 compute_section_prefix (dw_die_ref unit_die
)
5891 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
5892 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
5893 char *name
= alloca (strlen (base
) + 64);
5896 unsigned char checksum
[16];
5899 /* Compute the checksum of the DIE, then append part of it as hex digits to
5900 the name filename of the unit. */
5902 md5_init_ctx (&ctx
);
5904 die_checksum (unit_die
, &ctx
, &mark
);
5905 unmark_all_dies (unit_die
);
5906 md5_finish_ctx (&ctx
, checksum
);
5908 sprintf (name
, "%s.", base
);
5909 clean_symbol_name (name
);
5911 p
= name
+ strlen (name
);
5912 for (i
= 0; i
< 4; i
++)
5914 sprintf (p
, "%.2x", checksum
[i
]);
5918 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
5919 comdat_symbol_number
= 0;
5922 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5925 is_type_die (dw_die_ref die
)
5927 switch (die
->die_tag
)
5929 case DW_TAG_array_type
:
5930 case DW_TAG_class_type
:
5931 case DW_TAG_enumeration_type
:
5932 case DW_TAG_pointer_type
:
5933 case DW_TAG_reference_type
:
5934 case DW_TAG_string_type
:
5935 case DW_TAG_structure_type
:
5936 case DW_TAG_subroutine_type
:
5937 case DW_TAG_union_type
:
5938 case DW_TAG_ptr_to_member_type
:
5939 case DW_TAG_set_type
:
5940 case DW_TAG_subrange_type
:
5941 case DW_TAG_base_type
:
5942 case DW_TAG_const_type
:
5943 case DW_TAG_file_type
:
5944 case DW_TAG_packed_type
:
5945 case DW_TAG_volatile_type
:
5946 case DW_TAG_typedef
:
5953 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5954 Basically, we want to choose the bits that are likely to be shared between
5955 compilations (types) and leave out the bits that are specific to individual
5956 compilations (functions). */
5959 is_comdat_die (dw_die_ref c
)
5961 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5962 we do for stabs. The advantage is a greater likelihood of sharing between
5963 objects that don't include headers in the same order (and therefore would
5964 put the base types in a different comdat). jason 8/28/00 */
5966 if (c
->die_tag
== DW_TAG_base_type
)
5969 if (c
->die_tag
== DW_TAG_pointer_type
5970 || c
->die_tag
== DW_TAG_reference_type
5971 || c
->die_tag
== DW_TAG_const_type
5972 || c
->die_tag
== DW_TAG_volatile_type
)
5974 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
5976 return t
? is_comdat_die (t
) : 0;
5979 return is_type_die (c
);
5982 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5983 compilation unit. */
5986 is_symbol_die (dw_die_ref c
)
5988 return (is_type_die (c
)
5989 || (get_AT (c
, DW_AT_declaration
)
5990 && !get_AT (c
, DW_AT_specification
)));
5994 gen_internal_sym (const char *prefix
)
5998 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
5999 return xstrdup (buf
);
6002 /* Assign symbols to all worthy DIEs under DIE. */
6005 assign_symbol_names (dw_die_ref die
)
6009 if (is_symbol_die (die
))
6011 if (comdat_symbol_id
)
6013 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6015 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6016 comdat_symbol_id
, comdat_symbol_number
++);
6017 die
->die_symbol
= xstrdup (p
);
6020 die
->die_symbol
= gen_internal_sym ("LDIE");
6023 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6024 assign_symbol_names (c
);
6027 struct cu_hash_table_entry
6030 unsigned min_comdat_num
, max_comdat_num
;
6031 struct cu_hash_table_entry
*next
;
6034 /* Routines to manipulate hash table of CUs. */
6036 htab_cu_hash (const void *of
)
6038 const struct cu_hash_table_entry
*entry
= of
;
6040 return htab_hash_string (entry
->cu
->die_symbol
);
6044 htab_cu_eq (const void *of1
, const void *of2
)
6046 const struct cu_hash_table_entry
*entry1
= of1
;
6047 const struct die_struct
*entry2
= of2
;
6049 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6053 htab_cu_del (void *what
)
6055 struct cu_hash_table_entry
*next
, *entry
= what
;
6065 /* Check whether we have already seen this CU and set up SYM_NUM
6068 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6070 struct cu_hash_table_entry dummy
;
6071 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6073 dummy
.max_comdat_num
= 0;
6075 slot
= (struct cu_hash_table_entry
**)
6076 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6080 for (; entry
; last
= entry
, entry
= entry
->next
)
6082 if (same_die_p_wrap (cu
, entry
->cu
))
6088 *sym_num
= entry
->min_comdat_num
;
6092 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
6094 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6095 entry
->next
= *slot
;
6101 /* Record SYM_NUM to record of CU in HTABLE. */
6103 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6105 struct cu_hash_table_entry
**slot
, *entry
;
6107 slot
= (struct cu_hash_table_entry
**)
6108 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6112 entry
->max_comdat_num
= sym_num
;
6115 /* Traverse the DIE (which is always comp_unit_die), and set up
6116 additional compilation units for each of the include files we see
6117 bracketed by BINCL/EINCL. */
6120 break_out_includes (dw_die_ref die
)
6123 dw_die_ref unit
= NULL
;
6124 limbo_die_node
*node
, **pnode
;
6125 htab_t cu_hash_table
;
6127 for (ptr
= &(die
->die_child
); *ptr
;)
6129 dw_die_ref c
= *ptr
;
6131 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6132 || (unit
&& is_comdat_die (c
)))
6134 /* This DIE is for a secondary CU; remove it from the main one. */
6137 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6139 unit
= push_new_compile_unit (unit
, c
);
6142 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6144 unit
= pop_compile_unit (unit
);
6148 add_child_die (unit
, c
);
6152 /* Leave this DIE in the main CU. */
6153 ptr
= &(c
->die_sib
);
6159 /* We can only use this in debugging, since the frontend doesn't check
6160 to make sure that we leave every include file we enter. */
6165 assign_symbol_names (die
);
6166 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6167 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6173 compute_section_prefix (node
->die
);
6174 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6175 &comdat_symbol_number
);
6176 assign_symbol_names (node
->die
);
6178 *pnode
= node
->next
;
6181 pnode
= &node
->next
;
6182 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6183 comdat_symbol_number
);
6186 htab_delete (cu_hash_table
);
6189 /* Traverse the DIE and add a sibling attribute if it may have the
6190 effect of speeding up access to siblings. To save some space,
6191 avoid generating sibling attributes for DIE's without children. */
6194 add_sibling_attributes (dw_die_ref die
)
6198 if (die
->die_tag
!= DW_TAG_compile_unit
6199 && die
->die_sib
&& die
->die_child
!= NULL
)
6200 /* Add the sibling link to the front of the attribute list. */
6201 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6203 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6204 add_sibling_attributes (c
);
6207 /* Output all location lists for the DIE and its children. */
6210 output_location_lists (dw_die_ref die
)
6215 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6216 if (AT_class (d_attr
) == dw_val_class_loc_list
)
6217 output_loc_list (AT_loc_list (d_attr
));
6219 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6220 output_location_lists (c
);
6224 /* The format of each DIE (and its attribute value pairs) is encoded in an
6225 abbreviation table. This routine builds the abbreviation table and assigns
6226 a unique abbreviation id for each abbreviation entry. The children of each
6227 die are visited recursively. */
6230 build_abbrev_table (dw_die_ref die
)
6232 unsigned long abbrev_id
;
6233 unsigned int n_alloc
;
6235 dw_attr_ref d_attr
, a_attr
;
6237 /* Scan the DIE references, and mark as external any that refer to
6238 DIEs from other CUs (i.e. those which are not marked). */
6239 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6240 if (AT_class (d_attr
) == dw_val_class_die_ref
6241 && AT_ref (d_attr
)->die_mark
== 0)
6243 if (AT_ref (d_attr
)->die_symbol
== 0)
6246 set_AT_ref_external (d_attr
, 1);
6249 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6251 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6253 if (abbrev
->die_tag
== die
->die_tag
)
6255 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6257 a_attr
= abbrev
->die_attr
;
6258 d_attr
= die
->die_attr
;
6260 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6262 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6263 || (value_format (a_attr
) != value_format (d_attr
)))
6266 a_attr
= a_attr
->dw_attr_next
;
6267 d_attr
= d_attr
->dw_attr_next
;
6270 if (a_attr
== NULL
&& d_attr
== NULL
)
6276 if (abbrev_id
>= abbrev_die_table_in_use
)
6278 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6280 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6281 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6282 sizeof (dw_die_ref
) * n_alloc
);
6284 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6285 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6286 abbrev_die_table_allocated
= n_alloc
;
6289 ++abbrev_die_table_in_use
;
6290 abbrev_die_table
[abbrev_id
] = die
;
6293 die
->die_abbrev
= abbrev_id
;
6294 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6295 build_abbrev_table (c
);
6298 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6301 constant_size (long unsigned int value
)
6308 log
= floor_log2 (value
);
6311 log
= 1 << (floor_log2 (log
) + 1);
6316 /* Return the size of a DIE as it is represented in the
6317 .debug_info section. */
6319 static unsigned long
6320 size_of_die (dw_die_ref die
)
6322 unsigned long size
= 0;
6325 size
+= size_of_uleb128 (die
->die_abbrev
);
6326 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6328 switch (AT_class (a
))
6330 case dw_val_class_addr
:
6331 size
+= DWARF2_ADDR_SIZE
;
6333 case dw_val_class_offset
:
6334 size
+= DWARF_OFFSET_SIZE
;
6336 case dw_val_class_loc
:
6338 unsigned long lsize
= size_of_locs (AT_loc (a
));
6341 size
+= constant_size (lsize
);
6345 case dw_val_class_loc_list
:
6346 size
+= DWARF_OFFSET_SIZE
;
6348 case dw_val_class_range_list
:
6349 size
+= DWARF_OFFSET_SIZE
;
6351 case dw_val_class_const
:
6352 size
+= size_of_sleb128 (AT_int (a
));
6354 case dw_val_class_unsigned_const
:
6355 size
+= constant_size (AT_unsigned (a
));
6357 case dw_val_class_long_long
:
6358 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6360 case dw_val_class_vec
:
6361 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6362 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6364 case dw_val_class_flag
:
6367 case dw_val_class_die_ref
:
6368 if (AT_ref_external (a
))
6369 size
+= DWARF2_ADDR_SIZE
;
6371 size
+= DWARF_OFFSET_SIZE
;
6373 case dw_val_class_fde_ref
:
6374 size
+= DWARF_OFFSET_SIZE
;
6376 case dw_val_class_lbl_id
:
6377 size
+= DWARF2_ADDR_SIZE
;
6379 case dw_val_class_lbl_offset
:
6380 size
+= DWARF_OFFSET_SIZE
;
6382 case dw_val_class_str
:
6383 if (AT_string_form (a
) == DW_FORM_strp
)
6384 size
+= DWARF_OFFSET_SIZE
;
6386 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6396 /* Size the debugging information associated with a given DIE. Visits the
6397 DIE's children recursively. Updates the global variable next_die_offset, on
6398 each time through. Uses the current value of next_die_offset to update the
6399 die_offset field in each DIE. */
6402 calc_die_sizes (dw_die_ref die
)
6406 die
->die_offset
= next_die_offset
;
6407 next_die_offset
+= size_of_die (die
);
6409 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6412 if (die
->die_child
!= NULL
)
6413 /* Count the null byte used to terminate sibling lists. */
6414 next_die_offset
+= 1;
6417 /* Set the marks for a die and its children. We do this so
6418 that we know whether or not a reference needs to use FORM_ref_addr; only
6419 DIEs in the same CU will be marked. We used to clear out the offset
6420 and use that as the flag, but ran into ordering problems. */
6423 mark_dies (dw_die_ref die
)
6431 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6435 /* Clear the marks for a die and its children. */
6438 unmark_dies (dw_die_ref die
)
6446 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6450 /* Clear the marks for a die, its children and referred dies. */
6453 unmark_all_dies (dw_die_ref die
)
6462 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6463 unmark_all_dies (c
);
6465 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6466 if (AT_class (a
) == dw_val_class_die_ref
)
6467 unmark_all_dies (AT_ref (a
));
6470 /* Return the size of the .debug_pubnames table generated for the
6471 compilation unit. */
6473 static unsigned long
6474 size_of_pubnames (void)
6479 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6480 for (i
= 0; i
< pubname_table_in_use
; i
++)
6482 pubname_ref p
= &pubname_table
[i
];
6483 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6486 size
+= DWARF_OFFSET_SIZE
;
6490 /* Return the size of the information in the .debug_aranges section. */
6492 static unsigned long
6493 size_of_aranges (void)
6497 size
= DWARF_ARANGES_HEADER_SIZE
;
6499 /* Count the address/length pair for this compilation unit. */
6500 size
+= 2 * DWARF2_ADDR_SIZE
;
6501 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6503 /* Count the two zero words used to terminated the address range table. */
6504 size
+= 2 * DWARF2_ADDR_SIZE
;
6508 /* Select the encoding of an attribute value. */
6510 static enum dwarf_form
6511 value_format (dw_attr_ref a
)
6513 switch (a
->dw_attr_val
.val_class
)
6515 case dw_val_class_addr
:
6516 return DW_FORM_addr
;
6517 case dw_val_class_range_list
:
6518 case dw_val_class_offset
:
6519 if (DWARF_OFFSET_SIZE
== 4)
6520 return DW_FORM_data4
;
6521 if (DWARF_OFFSET_SIZE
== 8)
6522 return DW_FORM_data8
;
6524 case dw_val_class_loc_list
:
6525 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6526 .debug_loc section */
6527 return DW_FORM_data4
;
6528 case dw_val_class_loc
:
6529 switch (constant_size (size_of_locs (AT_loc (a
))))
6532 return DW_FORM_block1
;
6534 return DW_FORM_block2
;
6538 case dw_val_class_const
:
6539 return DW_FORM_sdata
;
6540 case dw_val_class_unsigned_const
:
6541 switch (constant_size (AT_unsigned (a
)))
6544 return DW_FORM_data1
;
6546 return DW_FORM_data2
;
6548 return DW_FORM_data4
;
6550 return DW_FORM_data8
;
6554 case dw_val_class_long_long
:
6555 return DW_FORM_block1
;
6556 case dw_val_class_vec
:
6557 return DW_FORM_block1
;
6558 case dw_val_class_flag
:
6559 return DW_FORM_flag
;
6560 case dw_val_class_die_ref
:
6561 if (AT_ref_external (a
))
6562 return DW_FORM_ref_addr
;
6565 case dw_val_class_fde_ref
:
6566 return DW_FORM_data
;
6567 case dw_val_class_lbl_id
:
6568 return DW_FORM_addr
;
6569 case dw_val_class_lbl_offset
:
6570 return DW_FORM_data
;
6571 case dw_val_class_str
:
6572 return AT_string_form (a
);
6579 /* Output the encoding of an attribute value. */
6582 output_value_format (dw_attr_ref a
)
6584 enum dwarf_form form
= value_format (a
);
6586 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6589 /* Output the .debug_abbrev section which defines the DIE abbreviation
6593 output_abbrev_section (void)
6595 unsigned long abbrev_id
;
6599 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6601 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6603 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6604 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6605 dwarf_tag_name (abbrev
->die_tag
));
6607 if (abbrev
->die_child
!= NULL
)
6608 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6610 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6612 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6613 a_attr
= a_attr
->dw_attr_next
)
6615 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6616 dwarf_attr_name (a_attr
->dw_attr
));
6617 output_value_format (a_attr
);
6620 dw2_asm_output_data (1, 0, NULL
);
6621 dw2_asm_output_data (1, 0, NULL
);
6624 /* Terminate the table. */
6625 dw2_asm_output_data (1, 0, NULL
);
6628 /* Output a symbol we can use to refer to this DIE from another CU. */
6631 output_die_symbol (dw_die_ref die
)
6633 char *sym
= die
->die_symbol
;
6638 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6639 /* We make these global, not weak; if the target doesn't support
6640 .linkonce, it doesn't support combining the sections, so debugging
6642 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
6644 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6647 /* Return a new location list, given the begin and end range, and the
6648 expression. gensym tells us whether to generate a new internal symbol for
6649 this location list node, which is done for the head of the list only. */
6651 static inline dw_loc_list_ref
6652 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6653 const char *section
, unsigned int gensym
)
6655 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6657 retlist
->begin
= begin
;
6659 retlist
->expr
= expr
;
6660 retlist
->section
= section
;
6662 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6667 /* Add a location description expression to a location list. */
6670 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6671 const char *begin
, const char *end
,
6672 const char *section
)
6676 /* Find the end of the chain. */
6677 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6680 /* Add a new location list node to the list. */
6681 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6684 /* Output the location list given to us. */
6687 output_loc_list (dw_loc_list_ref list_head
)
6689 dw_loc_list_ref curr
= list_head
;
6691 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6693 /* Walk the location list, and output each range + expression. */
6694 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6697 if (separate_line_info_table_in_use
== 0)
6699 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6700 "Location list begin address (%s)",
6701 list_head
->ll_symbol
);
6702 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6703 "Location list end address (%s)",
6704 list_head
->ll_symbol
);
6708 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
6709 "Location list begin address (%s)",
6710 list_head
->ll_symbol
);
6711 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
6712 "Location list end address (%s)",
6713 list_head
->ll_symbol
);
6715 size
= size_of_locs (curr
->expr
);
6717 /* Output the block length for this list of location operations. */
6720 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6722 output_loc_sequence (curr
->expr
);
6725 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6726 "Location list terminator begin (%s)",
6727 list_head
->ll_symbol
);
6728 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6729 "Location list terminator end (%s)",
6730 list_head
->ll_symbol
);
6733 /* Output the DIE and its attributes. Called recursively to generate
6734 the definitions of each child DIE. */
6737 output_die (dw_die_ref die
)
6743 /* If someone in another CU might refer to us, set up a symbol for
6744 them to point to. */
6745 if (die
->die_symbol
)
6746 output_die_symbol (die
);
6748 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6749 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6751 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6753 const char *name
= dwarf_attr_name (a
->dw_attr
);
6755 switch (AT_class (a
))
6757 case dw_val_class_addr
:
6758 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6761 case dw_val_class_offset
:
6762 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6766 case dw_val_class_range_list
:
6768 char *p
= strchr (ranges_section_label
, '\0');
6770 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
6771 a
->dw_attr_val
.v
.val_offset
);
6772 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6778 case dw_val_class_loc
:
6779 size
= size_of_locs (AT_loc (a
));
6781 /* Output the block length for this list of location operations. */
6782 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6784 output_loc_sequence (AT_loc (a
));
6787 case dw_val_class_const
:
6788 /* ??? It would be slightly more efficient to use a scheme like is
6789 used for unsigned constants below, but gdb 4.x does not sign
6790 extend. Gdb 5.x does sign extend. */
6791 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6794 case dw_val_class_unsigned_const
:
6795 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6796 AT_unsigned (a
), "%s", name
);
6799 case dw_val_class_long_long
:
6801 unsigned HOST_WIDE_INT first
, second
;
6803 dw2_asm_output_data (1,
6804 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6807 if (WORDS_BIG_ENDIAN
)
6809 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6810 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6814 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6815 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6818 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6819 first
, "long long constant");
6820 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6825 case dw_val_class_vec
:
6827 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
6828 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
6832 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
6833 if (elt_size
> sizeof (HOST_WIDE_INT
))
6838 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
6841 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
6842 "fp or vector constant word %u", i
);
6846 case dw_val_class_flag
:
6847 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6850 case dw_val_class_loc_list
:
6852 char *sym
= AT_loc_list (a
)->ll_symbol
;
6856 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, "%s", name
);
6860 case dw_val_class_die_ref
:
6861 if (AT_ref_external (a
))
6863 char *sym
= AT_ref (a
)->die_symbol
;
6867 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6869 else if (AT_ref (a
)->die_offset
== 0)
6872 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6876 case dw_val_class_fde_ref
:
6880 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6881 a
->dw_attr_val
.v
.val_fde_index
* 2);
6882 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6886 case dw_val_class_lbl_id
:
6887 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6890 case dw_val_class_lbl_offset
:
6891 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
6894 case dw_val_class_str
:
6895 if (AT_string_form (a
) == DW_FORM_strp
)
6896 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
6897 a
->dw_attr_val
.v
.val_str
->label
,
6898 "%s: \"%s\"", name
, AT_string (a
));
6900 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
6908 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6911 /* Add null byte to terminate sibling list. */
6912 if (die
->die_child
!= NULL
)
6913 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6917 /* Output the compilation unit that appears at the beginning of the
6918 .debug_info section, and precedes the DIE descriptions. */
6921 output_compilation_unit_header (void)
6923 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
6924 dw2_asm_output_data (4, 0xffffffff,
6925 "Initial length escape value indicating 64-bit DWARF extension");
6926 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
6927 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
6928 "Length of Compilation Unit Info");
6929 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
6930 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
6931 "Offset Into Abbrev. Section");
6932 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
6935 /* Output the compilation unit DIE and its children. */
6938 output_comp_unit (dw_die_ref die
, int output_if_empty
)
6940 const char *secname
;
6943 /* Unless we are outputting main CU, we may throw away empty ones. */
6944 if (!output_if_empty
&& die
->die_child
== NULL
)
6947 /* Even if there are no children of this DIE, we must output the information
6948 about the compilation unit. Otherwise, on an empty translation unit, we
6949 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6950 will then complain when examining the file. First mark all the DIEs in
6951 this CU so we know which get local refs. */
6954 build_abbrev_table (die
);
6956 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6957 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
6958 calc_die_sizes (die
);
6960 oldsym
= die
->die_symbol
;
6963 tmp
= alloca (strlen (oldsym
) + 24);
6965 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
6967 die
->die_symbol
= NULL
;
6970 secname
= (const char *) DEBUG_INFO_SECTION
;
6972 /* Output debugging information. */
6973 named_section_flags (secname
, SECTION_DEBUG
);
6974 output_compilation_unit_header ();
6977 /* Leave the marks on the main CU, so we can check them in
6982 die
->die_symbol
= oldsym
;
6986 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
6987 output of lang_hooks.decl_printable_name for C++ looks like
6988 "A::f(int)". Let's drop the argument list, and maybe the scope. */
6991 dwarf2_name (tree decl
, int scope
)
6993 return lang_hooks
.decl_printable_name (decl
, scope
? 1 : 0);
6996 /* Add a new entry to .debug_pubnames if appropriate. */
6999 add_pubname (tree decl
, dw_die_ref die
)
7003 if (! TREE_PUBLIC (decl
))
7006 if (pubname_table_in_use
== pubname_table_allocated
)
7008 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
7010 = ggc_realloc (pubname_table
,
7011 (pubname_table_allocated
* sizeof (pubname_entry
)));
7012 memset (pubname_table
+ pubname_table_in_use
, 0,
7013 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
7016 p
= &pubname_table
[pubname_table_in_use
++];
7018 p
->name
= xstrdup (dwarf2_name (decl
, 1));
7021 /* Output the public names table used to speed up access to externally
7022 visible names. For now, only generate entries for externally
7023 visible procedures. */
7026 output_pubnames (void)
7029 unsigned long pubnames_length
= size_of_pubnames ();
7031 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7032 dw2_asm_output_data (4, 0xffffffff,
7033 "Initial length escape value indicating 64-bit DWARF extension");
7034 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7035 "Length of Public Names Info");
7036 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7037 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7038 "Offset of Compilation Unit Info");
7039 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7040 "Compilation Unit Length");
7042 for (i
= 0; i
< pubname_table_in_use
; i
++)
7044 pubname_ref pub
= &pubname_table
[i
];
7046 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7047 if (pub
->die
->die_mark
== 0)
7050 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7053 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7056 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7059 /* Add a new entry to .debug_aranges if appropriate. */
7062 add_arange (tree decl
, dw_die_ref die
)
7064 if (! DECL_SECTION_NAME (decl
))
7067 if (arange_table_in_use
== arange_table_allocated
)
7069 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7070 arange_table
= ggc_realloc (arange_table
,
7071 (arange_table_allocated
7072 * sizeof (dw_die_ref
)));
7073 memset (arange_table
+ arange_table_in_use
, 0,
7074 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7077 arange_table
[arange_table_in_use
++] = die
;
7080 /* Output the information that goes into the .debug_aranges table.
7081 Namely, define the beginning and ending address range of the
7082 text section generated for this compilation unit. */
7085 output_aranges (void)
7088 unsigned long aranges_length
= size_of_aranges ();
7090 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7091 dw2_asm_output_data (4, 0xffffffff,
7092 "Initial length escape value indicating 64-bit DWARF extension");
7093 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7094 "Length of Address Ranges Info");
7095 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7096 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7097 "Offset of Compilation Unit Info");
7098 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7099 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7101 /* We need to align to twice the pointer size here. */
7102 if (DWARF_ARANGES_PAD_SIZE
)
7104 /* Pad using a 2 byte words so that padding is correct for any
7106 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7107 2 * DWARF2_ADDR_SIZE
);
7108 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7109 dw2_asm_output_data (2, 0, NULL
);
7112 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7113 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7114 text_section_label
, "Length");
7116 for (i
= 0; i
< arange_table_in_use
; i
++)
7118 dw_die_ref die
= arange_table
[i
];
7120 /* We shouldn't see aranges for DIEs outside of the main CU. */
7121 if (die
->die_mark
== 0)
7124 if (die
->die_tag
== DW_TAG_subprogram
)
7126 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7128 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7129 get_AT_low_pc (die
), "Length");
7133 /* A static variable; extract the symbol from DW_AT_location.
7134 Note that this code isn't currently hit, as we only emit
7135 aranges for functions (jason 9/23/99). */
7136 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7137 dw_loc_descr_ref loc
;
7139 if (! a
|| AT_class (a
) != dw_val_class_loc
)
7143 if (loc
->dw_loc_opc
!= DW_OP_addr
)
7146 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7147 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7148 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7149 get_AT_unsigned (die
, DW_AT_byte_size
),
7154 /* Output the terminator words. */
7155 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7156 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7159 /* Add a new entry to .debug_ranges. Return the offset at which it
7163 add_ranges (tree block
)
7165 unsigned int in_use
= ranges_table_in_use
;
7167 if (in_use
== ranges_table_allocated
)
7169 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7171 = ggc_realloc (ranges_table
, (ranges_table_allocated
7172 * sizeof (struct dw_ranges_struct
)));
7173 memset (ranges_table
+ ranges_table_in_use
, 0,
7174 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7177 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7178 ranges_table_in_use
= in_use
+ 1;
7180 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7184 output_ranges (void)
7187 static const char *const start_fmt
= "Offset 0x%x";
7188 const char *fmt
= start_fmt
;
7190 for (i
= 0; i
< ranges_table_in_use
; i
++)
7192 int block_num
= ranges_table
[i
].block_num
;
7196 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7197 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7199 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7200 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7202 /* If all code is in the text section, then the compilation
7203 unit base address defaults to DW_AT_low_pc, which is the
7204 base of the text section. */
7205 if (separate_line_info_table_in_use
== 0)
7207 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7209 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7210 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7211 text_section_label
, NULL
);
7214 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7215 compilation unit base address to zero, which allows us to
7216 use absolute addresses, and not worry about whether the
7217 target supports cross-section arithmetic. */
7220 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7221 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7222 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7229 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7230 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7236 /* Data structure containing information about input files. */
7239 char *path
; /* Complete file name. */
7240 char *fname
; /* File name part. */
7241 int length
; /* Length of entire string. */
7242 int file_idx
; /* Index in input file table. */
7243 int dir_idx
; /* Index in directory table. */
7246 /* Data structure containing information about directories with source
7250 char *path
; /* Path including directory name. */
7251 int length
; /* Path length. */
7252 int prefix
; /* Index of directory entry which is a prefix. */
7253 int count
; /* Number of files in this directory. */
7254 int dir_idx
; /* Index of directory used as base. */
7255 int used
; /* Used in the end? */
7258 /* Callback function for file_info comparison. We sort by looking at
7259 the directories in the path. */
7262 file_info_cmp (const void *p1
, const void *p2
)
7264 const struct file_info
*s1
= p1
;
7265 const struct file_info
*s2
= p2
;
7269 /* Take care of file names without directories. We need to make sure that
7270 we return consistent values to qsort since some will get confused if
7271 we return the same value when identical operands are passed in opposite
7272 orders. So if neither has a directory, return 0 and otherwise return
7273 1 or -1 depending on which one has the directory. */
7274 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7275 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7277 cp1
= (unsigned char *) s1
->path
;
7278 cp2
= (unsigned char *) s2
->path
;
7284 /* Reached the end of the first path? If so, handle like above. */
7285 if ((cp1
== (unsigned char *) s1
->fname
)
7286 || (cp2
== (unsigned char *) s2
->fname
))
7287 return ((cp2
== (unsigned char *) s2
->fname
)
7288 - (cp1
== (unsigned char *) s1
->fname
));
7290 /* Character of current path component the same? */
7291 else if (*cp1
!= *cp2
)
7296 /* Output the directory table and the file name table. We try to minimize
7297 the total amount of memory needed. A heuristic is used to avoid large
7298 slowdowns with many input files. */
7301 output_file_names (void)
7303 struct file_info
*files
;
7304 struct dir_info
*dirs
;
7313 /* Handle the case where file_table is empty. */
7314 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7316 dw2_asm_output_data (1, 0, "End directory table");
7317 dw2_asm_output_data (1, 0, "End file name table");
7321 /* Allocate the various arrays we need. */
7322 files
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct file_info
));
7323 dirs
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct dir_info
));
7325 /* Sort the file names. */
7326 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7330 /* Skip all leading "./". */
7331 f
= VARRAY_CHAR_PTR (file_table
, i
);
7332 while (f
[0] == '.' && f
[1] == '/')
7335 /* Create a new array entry. */
7337 files
[i
].length
= strlen (f
);
7338 files
[i
].file_idx
= i
;
7340 /* Search for the file name part. */
7341 f
= strrchr (f
, '/');
7342 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7345 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7346 sizeof (files
[0]), file_info_cmp
);
7348 /* Find all the different directories used. */
7349 dirs
[0].path
= files
[1].path
;
7350 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7351 dirs
[0].prefix
= -1;
7353 dirs
[0].dir_idx
= 0;
7355 files
[1].dir_idx
= 0;
7358 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7359 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7360 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7361 dirs
[ndirs
- 1].length
) == 0)
7363 /* Same directory as last entry. */
7364 files
[i
].dir_idx
= ndirs
- 1;
7365 ++dirs
[ndirs
- 1].count
;
7371 /* This is a new directory. */
7372 dirs
[ndirs
].path
= files
[i
].path
;
7373 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7374 dirs
[ndirs
].count
= 1;
7375 dirs
[ndirs
].dir_idx
= ndirs
;
7376 dirs
[ndirs
].used
= 0;
7377 files
[i
].dir_idx
= ndirs
;
7379 /* Search for a prefix. */
7380 dirs
[ndirs
].prefix
= -1;
7381 for (j
= 0; j
< ndirs
; j
++)
7382 if (dirs
[j
].length
< dirs
[ndirs
].length
7383 && dirs
[j
].length
> 1
7384 && (dirs
[ndirs
].prefix
== -1
7385 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7386 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7387 dirs
[ndirs
].prefix
= j
;
7392 /* Now to the actual work. We have to find a subset of the directories which
7393 allow expressing the file name using references to the directory table
7394 with the least amount of characters. We do not do an exhaustive search
7395 where we would have to check out every combination of every single
7396 possible prefix. Instead we use a heuristic which provides nearly optimal
7397 results in most cases and never is much off. */
7398 saved
= alloca (ndirs
* sizeof (int));
7399 savehere
= alloca (ndirs
* sizeof (int));
7401 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7402 for (i
= 0; i
< ndirs
; i
++)
7407 /* We can always save some space for the current directory. But this
7408 does not mean it will be enough to justify adding the directory. */
7409 savehere
[i
] = dirs
[i
].length
;
7410 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7412 for (j
= i
+ 1; j
< ndirs
; j
++)
7415 if (saved
[j
] < dirs
[i
].length
)
7417 /* Determine whether the dirs[i] path is a prefix of the
7422 while (k
!= -1 && k
!= (int) i
)
7427 /* Yes it is. We can possibly safe some memory but
7428 writing the filenames in dirs[j] relative to
7430 savehere
[j
] = dirs
[i
].length
;
7431 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7436 /* Check whether we can safe enough to justify adding the dirs[i]
7438 if (total
> dirs
[i
].length
+ 1)
7440 /* It's worthwhile adding. */
7441 for (j
= i
; j
< ndirs
; j
++)
7442 if (savehere
[j
] > 0)
7444 /* Remember how much we saved for this directory so far. */
7445 saved
[j
] = savehere
[j
];
7447 /* Remember the prefix directory. */
7448 dirs
[j
].dir_idx
= i
;
7453 /* We have to emit them in the order they appear in the file_table array
7454 since the index is used in the debug info generation. To do this
7455 efficiently we generate a back-mapping of the indices first. */
7456 backmap
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7457 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7459 backmap
[files
[i
].file_idx
] = i
;
7461 /* Mark this directory as used. */
7462 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7465 /* That was it. We are ready to emit the information. First emit the
7466 directory name table. We have to make sure the first actually emitted
7467 directory name has index one; zero is reserved for the current working
7468 directory. Make sure we do not confuse these indices with the one for the
7469 constructed table (even though most of the time they are identical). */
7471 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7472 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7473 if (dirs
[i
].used
!= 0)
7475 dirs
[i
].used
= idx
++;
7476 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7477 "Directory Entry: 0x%x", dirs
[i
].used
);
7480 dw2_asm_output_data (1, 0, "End directory table");
7482 /* Correct the index for the current working directory entry if it
7484 if (idx_offset
== 0)
7487 /* Now write all the file names. */
7488 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7490 int file_idx
= backmap
[i
];
7491 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7493 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7494 "File Entry: 0x%lx", (unsigned long) i
);
7496 /* Include directory index. */
7497 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7499 /* Modification time. */
7500 dw2_asm_output_data_uleb128 (0, NULL
);
7502 /* File length in bytes. */
7503 dw2_asm_output_data_uleb128 (0, NULL
);
7506 dw2_asm_output_data (1, 0, "End file name table");
7510 /* Output the source line number correspondence information. This
7511 information goes into the .debug_line section. */
7514 output_line_info (void)
7516 char l1
[20], l2
[20], p1
[20], p2
[20];
7517 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7518 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7521 unsigned long lt_index
;
7522 unsigned long current_line
;
7525 unsigned long current_file
;
7526 unsigned long function
;
7528 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7529 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7530 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7531 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7533 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7534 dw2_asm_output_data (4, 0xffffffff,
7535 "Initial length escape value indicating 64-bit DWARF extension");
7536 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7537 "Length of Source Line Info");
7538 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7540 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7541 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7542 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7544 /* Define the architecture-dependent minimum instruction length (in
7545 bytes). In this implementation of DWARF, this field is used for
7546 information purposes only. Since GCC generates assembly language,
7547 we have no a priori knowledge of how many instruction bytes are
7548 generated for each source line, and therefore can use only the
7549 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7550 commands. Accordingly, we fix this as `1', which is "correct
7551 enough" for all architectures, and don't let the target override. */
7552 dw2_asm_output_data (1, 1,
7553 "Minimum Instruction Length");
7555 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7556 "Default is_stmt_start flag");
7557 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7558 "Line Base Value (Special Opcodes)");
7559 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7560 "Line Range Value (Special Opcodes)");
7561 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7562 "Special Opcode Base");
7564 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7568 case DW_LNS_advance_pc
:
7569 case DW_LNS_advance_line
:
7570 case DW_LNS_set_file
:
7571 case DW_LNS_set_column
:
7572 case DW_LNS_fixed_advance_pc
:
7580 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7584 /* Write out the information about the files we use. */
7585 output_file_names ();
7586 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7588 /* We used to set the address register to the first location in the text
7589 section here, but that didn't accomplish anything since we already
7590 have a line note for the opening brace of the first function. */
7592 /* Generate the line number to PC correspondence table, encoded as
7593 a series of state machine operations. */
7596 strcpy (prev_line_label
, text_section_label
);
7597 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7599 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7602 /* Disable this optimization for now; GDB wants to see two line notes
7603 at the beginning of a function so it can find the end of the
7606 /* Don't emit anything for redundant notes. Just updating the
7607 address doesn't accomplish anything, because we already assume
7608 that anything after the last address is this line. */
7609 if (line_info
->dw_line_num
== current_line
7610 && line_info
->dw_file_num
== current_file
)
7614 /* Emit debug info for the address of the current line.
7616 Unfortunately, we have little choice here currently, and must always
7617 use the most general form. GCC does not know the address delta
7618 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7619 attributes which will give an upper bound on the address range. We
7620 could perhaps use length attributes to determine when it is safe to
7621 use DW_LNS_fixed_advance_pc. */
7623 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7626 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7627 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7628 "DW_LNS_fixed_advance_pc");
7629 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7633 /* This can handle any delta. This takes
7634 4+DWARF2_ADDR_SIZE bytes. */
7635 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7636 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7637 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7638 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7641 strcpy (prev_line_label
, line_label
);
7643 /* Emit debug info for the source file of the current line, if
7644 different from the previous line. */
7645 if (line_info
->dw_file_num
!= current_file
)
7647 current_file
= line_info
->dw_file_num
;
7648 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7649 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7650 VARRAY_CHAR_PTR (file_table
,
7654 /* Emit debug info for the current line number, choosing the encoding
7655 that uses the least amount of space. */
7656 if (line_info
->dw_line_num
!= current_line
)
7658 line_offset
= line_info
->dw_line_num
- current_line
;
7659 line_delta
= line_offset
- DWARF_LINE_BASE
;
7660 current_line
= line_info
->dw_line_num
;
7661 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7662 /* This can handle deltas from -10 to 234, using the current
7663 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7665 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7666 "line %lu", current_line
);
7669 /* This can handle any delta. This takes at least 4 bytes,
7670 depending on the value being encoded. */
7671 dw2_asm_output_data (1, DW_LNS_advance_line
,
7672 "advance to line %lu", current_line
);
7673 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7674 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7678 /* We still need to start a new row, so output a copy insn. */
7679 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7682 /* Emit debug info for the address of the end of the function. */
7685 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7686 "DW_LNS_fixed_advance_pc");
7687 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7691 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7692 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7693 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7694 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7697 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7698 dw2_asm_output_data_uleb128 (1, NULL
);
7699 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7704 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7706 dw_separate_line_info_ref line_info
7707 = &separate_line_info_table
[lt_index
];
7710 /* Don't emit anything for redundant notes. */
7711 if (line_info
->dw_line_num
== current_line
7712 && line_info
->dw_file_num
== current_file
7713 && line_info
->function
== function
)
7717 /* Emit debug info for the address of the current line. If this is
7718 a new function, or the first line of a function, then we need
7719 to handle it differently. */
7720 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7722 if (function
!= line_info
->function
)
7724 function
= line_info
->function
;
7726 /* Set the address register to the first line in the function. */
7727 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7728 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7729 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7730 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7734 /* ??? See the DW_LNS_advance_pc comment above. */
7737 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7738 "DW_LNS_fixed_advance_pc");
7739 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7743 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7744 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7745 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7746 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7750 strcpy (prev_line_label
, line_label
);
7752 /* Emit debug info for the source file of the current line, if
7753 different from the previous line. */
7754 if (line_info
->dw_file_num
!= current_file
)
7756 current_file
= line_info
->dw_file_num
;
7757 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7758 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7759 VARRAY_CHAR_PTR (file_table
,
7763 /* Emit debug info for the current line number, choosing the encoding
7764 that uses the least amount of space. */
7765 if (line_info
->dw_line_num
!= current_line
)
7767 line_offset
= line_info
->dw_line_num
- current_line
;
7768 line_delta
= line_offset
- DWARF_LINE_BASE
;
7769 current_line
= line_info
->dw_line_num
;
7770 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7771 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7772 "line %lu", current_line
);
7775 dw2_asm_output_data (1, DW_LNS_advance_line
,
7776 "advance to line %lu", current_line
);
7777 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7778 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7782 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7790 /* If we're done with a function, end its sequence. */
7791 if (lt_index
== separate_line_info_table_in_use
7792 || separate_line_info_table
[lt_index
].function
!= function
)
7797 /* Emit debug info for the address of the end of the function. */
7798 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7801 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7802 "DW_LNS_fixed_advance_pc");
7803 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7807 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7808 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7809 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7810 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7813 /* Output the marker for the end of this sequence. */
7814 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7815 dw2_asm_output_data_uleb128 (1, NULL
);
7816 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7820 /* Output the marker for the end of the line number info. */
7821 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7824 /* Given a pointer to a tree node for some base type, return a pointer to
7825 a DIE that describes the given type.
7827 This routine must only be called for GCC type nodes that correspond to
7828 Dwarf base (fundamental) types. */
7831 base_type_die (tree type
)
7833 dw_die_ref base_type_result
;
7834 const char *type_name
;
7835 enum dwarf_type encoding
;
7836 tree name
= TYPE_NAME (type
);
7838 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7843 if (TREE_CODE (name
) == TYPE_DECL
)
7844 name
= DECL_NAME (name
);
7846 type_name
= IDENTIFIER_POINTER (name
);
7849 type_name
= "__unknown__";
7851 switch (TREE_CODE (type
))
7854 /* Carefully distinguish the C character types, without messing
7855 up if the language is not C. Note that we check only for the names
7856 that contain spaces; other names might occur by coincidence in other
7858 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7859 && (type
== char_type_node
7860 || ! strcmp (type_name
, "signed char")
7861 || ! strcmp (type_name
, "unsigned char"))))
7863 if (TYPE_UNSIGNED (type
))
7864 encoding
= DW_ATE_unsigned
;
7866 encoding
= DW_ATE_signed
;
7869 /* else fall through. */
7872 /* GNU Pascal/Ada CHAR type. Not used in C. */
7873 if (TYPE_UNSIGNED (type
))
7874 encoding
= DW_ATE_unsigned_char
;
7876 encoding
= DW_ATE_signed_char
;
7880 encoding
= DW_ATE_float
;
7883 /* Dwarf2 doesn't know anything about complex ints, so use
7884 a user defined type for it. */
7886 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7887 encoding
= DW_ATE_complex_float
;
7889 encoding
= DW_ATE_lo_user
;
7893 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7894 encoding
= DW_ATE_boolean
;
7898 /* No other TREE_CODEs are Dwarf fundamental types. */
7902 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
7903 if (demangle_name_func
)
7904 type_name
= (*demangle_name_func
) (type_name
);
7906 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
7907 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
7908 int_size_in_bytes (type
));
7909 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
7911 return base_type_result
;
7914 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7915 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7916 a given type is generally the same as the given type, except that if the
7917 given type is a pointer or reference type, then the root type of the given
7918 type is the root type of the "basis" type for the pointer or reference
7919 type. (This definition of the "root" type is recursive.) Also, the root
7920 type of a `const' qualified type or a `volatile' qualified type is the
7921 root type of the given type without the qualifiers. */
7924 root_type (tree type
)
7926 if (TREE_CODE (type
) == ERROR_MARK
)
7927 return error_mark_node
;
7929 switch (TREE_CODE (type
))
7932 return error_mark_node
;
7935 case REFERENCE_TYPE
:
7936 return type_main_variant (root_type (TREE_TYPE (type
)));
7939 return type_main_variant (type
);
7943 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
7944 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7947 is_base_type (tree type
)
7949 switch (TREE_CODE (type
))
7964 case QUAL_UNION_TYPE
:
7969 case REFERENCE_TYPE
:
7983 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7984 node, return the size in bits for the type if it is a constant, or else
7985 return the alignment for the type if the type's size is not constant, or
7986 else return BITS_PER_WORD if the type actually turns out to be an
7989 static inline unsigned HOST_WIDE_INT
7990 simple_type_size_in_bits (tree type
)
7992 if (TREE_CODE (type
) == ERROR_MARK
)
7993 return BITS_PER_WORD
;
7994 else if (TYPE_SIZE (type
) == NULL_TREE
)
7996 else if (host_integerp (TYPE_SIZE (type
), 1))
7997 return tree_low_cst (TYPE_SIZE (type
), 1);
7999 return TYPE_ALIGN (type
);
8002 /* Return true if the debug information for the given type should be
8003 emitted as a subrange type. */
8006 is_subrange_type (tree type
)
8008 tree subtype
= TREE_TYPE (type
);
8010 /* Subrange types are identified by the fact that they are integer
8011 types, and that they have a subtype which is either an integer type
8012 or an enumeral type. */
8014 if (TREE_CODE (type
) != INTEGER_TYPE
8015 || subtype
== NULL_TREE
)
8018 if (TREE_CODE (subtype
) != INTEGER_TYPE
8019 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8022 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8023 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8024 && TYPE_MIN_VALUE (type
) != NULL
8025 && TYPE_MIN_VALUE (subtype
) != NULL
8026 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8027 && TYPE_MAX_VALUE (type
) != NULL
8028 && TYPE_MAX_VALUE (subtype
) != NULL
8029 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8031 /* The type and its subtype have the same representation. If in
8032 addition the two types also have the same name, then the given
8033 type is not a subrange type, but rather a plain base type. */
8034 /* FIXME: brobecker/2004-03-22:
8035 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8036 therefore be sufficient to check the TYPE_SIZE node pointers
8037 rather than checking the actual size. Unfortunately, we have
8038 found some cases, such as in the Ada "integer" type, where
8039 this is not the case. Until this problem is solved, we need to
8040 keep checking the actual size. */
8041 tree type_name
= TYPE_NAME (type
);
8042 tree subtype_name
= TYPE_NAME (subtype
);
8044 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8045 type_name
= DECL_NAME (type_name
);
8047 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8048 subtype_name
= DECL_NAME (subtype_name
);
8050 if (type_name
== subtype_name
)
8057 /* Given a pointer to a tree node for a subrange type, return a pointer
8058 to a DIE that describes the given type. */
8061 subrange_type_die (tree type
, dw_die_ref context_die
)
8063 dw_die_ref subtype_die
;
8064 dw_die_ref subrange_die
;
8065 tree name
= TYPE_NAME (type
);
8066 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8067 tree subtype
= TREE_TYPE (type
);
8069 if (context_die
== NULL
)
8070 context_die
= comp_unit_die
;
8072 if (TREE_CODE (subtype
) == ENUMERAL_TYPE
)
8073 subtype_die
= gen_enumeration_type_die (subtype
, context_die
);
8075 subtype_die
= base_type_die (subtype
);
8077 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8081 if (TREE_CODE (name
) == TYPE_DECL
)
8082 name
= DECL_NAME (name
);
8083 add_name_attribute (subrange_die
, IDENTIFIER_POINTER (name
));
8086 if (int_size_in_bytes (subtype
) != size_in_bytes
)
8088 /* The size of the subrange type and its base type do not match,
8089 so we need to generate a size attribute for the subrange type. */
8090 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8093 if (TYPE_MIN_VALUE (type
) != NULL
)
8094 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8095 TYPE_MIN_VALUE (type
));
8096 if (TYPE_MAX_VALUE (type
) != NULL
)
8097 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8098 TYPE_MAX_VALUE (type
));
8099 add_AT_die_ref (subrange_die
, DW_AT_type
, subtype_die
);
8101 return subrange_die
;
8104 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8105 entry that chains various modifiers in front of the given type. */
8108 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8109 dw_die_ref context_die
)
8111 enum tree_code code
= TREE_CODE (type
);
8112 dw_die_ref mod_type_die
= NULL
;
8113 dw_die_ref sub_die
= NULL
;
8114 tree item_type
= NULL
;
8116 if (code
!= ERROR_MARK
)
8118 tree qualified_type
;
8120 /* See if we already have the appropriately qualified variant of
8123 = get_qualified_type (type
,
8124 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8126 ? TYPE_QUAL_VOLATILE
: 0)));
8128 /* If we do, then we can just use its DIE, if it exists. */
8131 mod_type_die
= lookup_type_die (qualified_type
);
8133 return mod_type_die
;
8136 /* Handle C typedef types. */
8137 if (qualified_type
&& TYPE_NAME (qualified_type
)
8138 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
8139 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
8141 tree type_name
= TYPE_NAME (qualified_type
);
8142 tree dtype
= TREE_TYPE (type_name
);
8144 if (qualified_type
== dtype
)
8146 /* For a named type, use the typedef. */
8147 gen_type_die (qualified_type
, context_die
);
8148 mod_type_die
= lookup_type_die (qualified_type
);
8150 else if (is_const_type
< TYPE_READONLY (dtype
)
8151 || is_volatile_type
< TYPE_VOLATILE (dtype
))
8152 /* cv-unqualified version of named type. Just use the unnamed
8153 type to which it refers. */
8155 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
8156 is_const_type
, is_volatile_type
,
8159 /* Else cv-qualified version of named type; fall through. */
8165 else if (is_const_type
)
8167 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8168 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8170 else if (is_volatile_type
)
8172 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8173 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8175 else if (code
== POINTER_TYPE
)
8177 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8178 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8179 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8181 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
8183 item_type
= TREE_TYPE (type
);
8185 else if (code
== REFERENCE_TYPE
)
8187 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8188 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8189 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8191 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
8193 item_type
= TREE_TYPE (type
);
8195 else if (is_subrange_type (type
))
8196 mod_type_die
= subrange_type_die (type
, context_die
);
8197 else if (is_base_type (type
))
8198 mod_type_die
= base_type_die (type
);
8201 gen_type_die (type
, context_die
);
8203 /* We have to get the type_main_variant here (and pass that to the
8204 `lookup_type_die' routine) because the ..._TYPE node we have
8205 might simply be a *copy* of some original type node (where the
8206 copy was created to help us keep track of typedef names) and
8207 that copy might have a different TYPE_UID from the original
8209 if (TREE_CODE (type
) != VECTOR_TYPE
)
8210 mod_type_die
= lookup_type_die (type_main_variant (type
));
8212 /* Vectors have the debugging information in the type,
8213 not the main variant. */
8214 mod_type_die
= lookup_type_die (type
);
8215 if (mod_type_die
== NULL
)
8219 /* We want to equate the qualified type to the die below. */
8220 type
= qualified_type
;
8224 equate_type_number_to_die (type
, mod_type_die
);
8226 /* We must do this after the equate_type_number_to_die call, in case
8227 this is a recursive type. This ensures that the modified_type_die
8228 recursion will terminate even if the type is recursive. Recursive
8229 types are possible in Ada. */
8230 sub_die
= modified_type_die (item_type
,
8231 TYPE_READONLY (item_type
),
8232 TYPE_VOLATILE (item_type
),
8235 if (sub_die
!= NULL
)
8236 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8238 return mod_type_die
;
8241 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8242 an enumerated type. */
8245 type_is_enum (tree type
)
8247 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8250 /* Return the DBX register number described by a given RTL node. */
8253 dbx_reg_number (rtx rtl
)
8255 unsigned regno
= REGNO (rtl
);
8257 if (regno
>= FIRST_PSEUDO_REGISTER
)
8260 return DBX_REGISTER_NUMBER (regno
);
8263 /* Return a location descriptor that designates a machine register or
8264 zero if there is none. */
8266 static dw_loc_descr_ref
8267 reg_loc_descriptor (rtx rtl
)
8272 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8275 reg
= dbx_reg_number (rtl
);
8276 regs
= targetm
.dwarf_register_span (rtl
);
8278 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1
8280 return multiple_reg_loc_descriptor (rtl
, regs
);
8282 return one_reg_loc_descriptor (reg
);
8285 /* Return a location descriptor that designates a machine register for
8286 a given hard register number. */
8288 static dw_loc_descr_ref
8289 one_reg_loc_descriptor (unsigned int regno
)
8292 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8294 return new_loc_descr (DW_OP_regx
, regno
, 0);
8297 /* Given an RTL of a register, return a location descriptor that
8298 designates a value that spans more than one register. */
8300 static dw_loc_descr_ref
8301 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
8305 dw_loc_descr_ref loc_result
= NULL
;
8307 reg
= dbx_reg_number (rtl
);
8308 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8310 /* Simple, contiguous registers. */
8311 if (regs
== NULL_RTX
)
8313 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8320 t
= one_reg_loc_descriptor (reg
);
8321 add_loc_descr (&loc_result
, t
);
8322 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8328 /* Now onto stupid register sets in non contiguous locations. */
8330 if (GET_CODE (regs
) != PARALLEL
)
8333 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8336 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8340 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8341 add_loc_descr (&loc_result
, t
);
8342 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8343 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8348 /* Return a location descriptor that designates a constant. */
8350 static dw_loc_descr_ref
8351 int_loc_descriptor (HOST_WIDE_INT i
)
8353 enum dwarf_location_atom op
;
8355 /* Pick the smallest representation of a constant, rather than just
8356 defaulting to the LEB encoding. */
8360 op
= DW_OP_lit0
+ i
;
8363 else if (i
<= 0xffff)
8365 else if (HOST_BITS_PER_WIDE_INT
== 32
8375 else if (i
>= -0x8000)
8377 else if (HOST_BITS_PER_WIDE_INT
== 32
8378 || i
>= -0x80000000)
8384 return new_loc_descr (op
, i
, 0);
8387 /* Return a location descriptor that designates a base+offset location. */
8389 static dw_loc_descr_ref
8390 based_loc_descr (unsigned int reg
, HOST_WIDE_INT offset
, bool can_use_fbreg
)
8392 dw_loc_descr_ref loc_result
;
8393 /* For the "frame base", we use the frame pointer or stack pointer
8394 registers, since the RTL for local variables is relative to one of
8396 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8397 ? HARD_FRAME_POINTER_REGNUM
8398 : STACK_POINTER_REGNUM
);
8400 if (reg
== fp_reg
&& can_use_fbreg
)
8401 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8403 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8405 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8410 /* Return true if this RTL expression describes a base+offset calculation. */
8413 is_based_loc (rtx rtl
)
8415 return (GET_CODE (rtl
) == PLUS
8416 && ((REG_P (XEXP (rtl
, 0))
8417 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8418 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8421 /* The following routine converts the RTL for a variable or parameter
8422 (resident in memory) into an equivalent Dwarf representation of a
8423 mechanism for getting the address of that same variable onto the top of a
8424 hypothetical "address evaluation" stack.
8426 When creating memory location descriptors, we are effectively transforming
8427 the RTL for a memory-resident object into its Dwarf postfix expression
8428 equivalent. This routine recursively descends an RTL tree, turning
8429 it into Dwarf postfix code as it goes.
8431 MODE is the mode of the memory reference, needed to handle some
8432 autoincrement addressing modes.
8434 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location
8435 list for RTL. We can't use it when we are emitting location list for
8436 virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base)
8437 which describes how frame base changes when !frame_pointer_needed.
8439 Return 0 if we can't represent the location. */
8441 static dw_loc_descr_ref
8442 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
, bool can_use_fbreg
)
8444 dw_loc_descr_ref mem_loc_result
= NULL
;
8445 enum dwarf_location_atom op
;
8447 /* Note that for a dynamically sized array, the location we will generate a
8448 description of here will be the lowest numbered location which is
8449 actually within the array. That's *not* necessarily the same as the
8450 zeroth element of the array. */
8452 rtl
= targetm
.delegitimize_address (rtl
);
8454 switch (GET_CODE (rtl
))
8459 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8460 just fall into the SUBREG code. */
8462 /* ... fall through ... */
8465 /* The case of a subreg may arise when we have a local (register)
8466 variable or a formal (register) parameter which doesn't quite fill
8467 up an entire register. For now, just assume that it is
8468 legitimate to make the Dwarf info refer to the whole register which
8469 contains the given subreg. */
8470 rtl
= SUBREG_REG (rtl
);
8472 /* ... fall through ... */
8475 /* Whenever a register number forms a part of the description of the
8476 method for calculating the (dynamic) address of a memory resident
8477 object, DWARF rules require the register number be referred to as
8478 a "base register". This distinction is not based in any way upon
8479 what category of register the hardware believes the given register
8480 belongs to. This is strictly DWARF terminology we're dealing with
8481 here. Note that in cases where the location of a memory-resident
8482 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8483 OP_CONST (0)) the actual DWARF location descriptor that we generate
8484 may just be OP_BASEREG (basereg). This may look deceptively like
8485 the object in question was allocated to a register (rather than in
8486 memory) so DWARF consumers need to be aware of the subtle
8487 distinction between OP_REG and OP_BASEREG. */
8488 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8489 mem_loc_result
= based_loc_descr (dbx_reg_number (rtl
), 0,
8494 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
8496 if (mem_loc_result
!= 0)
8497 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8501 rtl
= XEXP (rtl
, 1);
8503 /* ... fall through ... */
8506 /* Some ports can transform a symbol ref into a label ref, because
8507 the symbol ref is too far away and has to be dumped into a constant
8511 /* Alternatively, the symbol in the constant pool might be referenced
8512 by a different symbol. */
8513 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8516 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8518 if (GET_CODE (tmp
) == SYMBOL_REF
)
8521 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8522 get_pool_constant_mark (tmp
, &marked
);
8527 /* If all references to this pool constant were optimized away,
8528 it was not output and thus we can't represent it.
8529 FIXME: might try to use DW_OP_const_value here, though
8530 DW_OP_piece complicates it. */
8535 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8536 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8537 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8538 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8542 /* Extract the PLUS expression nested inside and fall into
8544 rtl
= XEXP (rtl
, 1);
8549 /* Turn these into a PLUS expression and fall into the PLUS code
8551 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8552 GEN_INT (GET_CODE (rtl
) == PRE_INC
8553 ? GET_MODE_UNIT_SIZE (mode
)
8554 : -GET_MODE_UNIT_SIZE (mode
)));
8556 /* ... fall through ... */
8560 if (is_based_loc (rtl
))
8561 mem_loc_result
= based_loc_descr (dbx_reg_number (XEXP (rtl
, 0)),
8562 INTVAL (XEXP (rtl
, 1)),
8566 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
8568 if (mem_loc_result
== 0)
8571 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8572 && INTVAL (XEXP (rtl
, 1)) >= 0)
8573 add_loc_descr (&mem_loc_result
,
8574 new_loc_descr (DW_OP_plus_uconst
,
8575 INTVAL (XEXP (rtl
, 1)), 0));
8578 add_loc_descr (&mem_loc_result
,
8579 mem_loc_descriptor (XEXP (rtl
, 1), mode
,
8581 add_loc_descr (&mem_loc_result
,
8582 new_loc_descr (DW_OP_plus
, 0, 0));
8587 /* If a pseudo-reg is optimized away, it is possible for it to
8588 be replaced with a MEM containing a multiply or shift. */
8607 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
8609 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
8612 if (op0
== 0 || op1
== 0)
8615 mem_loc_result
= op0
;
8616 add_loc_descr (&mem_loc_result
, op1
);
8617 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
8622 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8626 /* If this is a MEM, return its address. Otherwise, we can't
8628 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
8629 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
,
8638 return mem_loc_result
;
8641 /* Return a descriptor that describes the concatenation of two locations.
8642 This is typically a complex variable. */
8644 static dw_loc_descr_ref
8645 concat_loc_descriptor (rtx x0
, rtx x1
)
8647 dw_loc_descr_ref cc_loc_result
= NULL
;
8648 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, true);
8649 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, true);
8651 if (x0_ref
== 0 || x1_ref
== 0)
8654 cc_loc_result
= x0_ref
;
8655 add_loc_descr (&cc_loc_result
,
8656 new_loc_descr (DW_OP_piece
,
8657 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8659 add_loc_descr (&cc_loc_result
, x1_ref
);
8660 add_loc_descr (&cc_loc_result
,
8661 new_loc_descr (DW_OP_piece
,
8662 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8664 return cc_loc_result
;
8667 /* Output a proper Dwarf location descriptor for a variable or parameter
8668 which is either allocated in a register or in a memory location. For a
8669 register, we just generate an OP_REG and the register number. For a
8670 memory location we provide a Dwarf postfix expression describing how to
8671 generate the (dynamic) address of the object onto the address stack.
8673 If we don't know how to describe it, return 0. */
8675 static dw_loc_descr_ref
8676 loc_descriptor (rtx rtl
, bool can_use_fbreg
)
8678 dw_loc_descr_ref loc_result
= NULL
;
8680 switch (GET_CODE (rtl
))
8683 /* The case of a subreg may arise when we have a local (register)
8684 variable or a formal (register) parameter which doesn't quite fill
8685 up an entire register. For now, just assume that it is
8686 legitimate to make the Dwarf info refer to the whole register which
8687 contains the given subreg. */
8688 rtl
= SUBREG_REG (rtl
);
8690 /* ... fall through ... */
8693 loc_result
= reg_loc_descriptor (rtl
);
8697 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
8702 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8707 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
8709 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), can_use_fbreg
);
8711 /* Multiple parts. */
8714 rtvec par_elems
= XVEC (XEXP (rtl
, 1), 0);
8715 int num_elem
= GET_NUM_ELEM (par_elems
);
8716 enum machine_mode mode
;
8719 /* Create the first one, so we have something to add to. */
8720 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
8722 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
8723 add_loc_descr (&loc_result
,
8724 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (mode
), 0));
8725 for (i
= 1; i
< num_elem
; i
++)
8727 dw_loc_descr_ref temp
;
8729 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
8731 add_loc_descr (&loc_result
, temp
);
8732 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
8733 add_loc_descr (&loc_result
,
8734 new_loc_descr (DW_OP_piece
,
8735 GET_MODE_SIZE (mode
), 0));
8747 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8748 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8749 looking for an address. Otherwise, we return a value. If we can't make a
8750 descriptor, return 0. */
8752 static dw_loc_descr_ref
8753 loc_descriptor_from_tree (tree loc
, int addressp
)
8755 dw_loc_descr_ref ret
, ret1
;
8757 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
8758 enum dwarf_location_atom op
;
8760 /* ??? Most of the time we do not take proper care for sign/zero
8761 extending the values properly. Hopefully this won't be a real
8764 switch (TREE_CODE (loc
))
8769 case PLACEHOLDER_EXPR
:
8770 /* This case involves extracting fields from an object to determine the
8771 position of other fields. We don't try to encode this here. The
8772 only user of this is Ada, which encodes the needed information using
8773 the names of types. */
8779 case PREINCREMENT_EXPR
:
8780 case PREDECREMENT_EXPR
:
8781 case POSTINCREMENT_EXPR
:
8782 case POSTDECREMENT_EXPR
:
8783 /* There are no opcodes for these operations. */
8787 /* We can support this only if we can look through conversions and
8788 find an INDIRECT_EXPR. */
8789 for (loc
= TREE_OPERAND (loc
, 0);
8790 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8791 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8792 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8793 || TREE_CODE (loc
) == SAVE_EXPR
;
8794 loc
= TREE_OPERAND (loc
, 0))
8797 return (TREE_CODE (loc
) == INDIRECT_REF
8798 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8802 if (DECL_THREAD_LOCAL (loc
))
8806 #ifndef ASM_OUTPUT_DWARF_DTPREL
8807 /* If this is not defined, we have no way to emit the data. */
8811 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8812 look up addresses of objects in the current module. */
8813 if (DECL_EXTERNAL (loc
))
8816 rtl
= rtl_for_decl_location (loc
);
8817 if (rtl
== NULL_RTX
)
8820 if (GET_CODE (rtl
) != MEM
)
8822 rtl
= XEXP (rtl
, 0);
8823 if (! CONSTANT_P (rtl
))
8826 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8827 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8828 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8830 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8831 add_loc_descr (&ret
, ret1
);
8841 rtx rtl
= rtl_for_decl_location (loc
);
8843 if (rtl
== NULL_RTX
)
8845 else if (CONSTANT_P (rtl
))
8847 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8848 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8849 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8854 enum machine_mode mode
= GET_MODE (rtl
);
8856 if (GET_CODE (rtl
) == MEM
)
8859 rtl
= XEXP (rtl
, 0);
8862 ret
= mem_loc_descriptor (rtl
, mode
, true);
8868 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8873 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8877 case NON_LVALUE_EXPR
:
8878 case VIEW_CONVERT_EXPR
:
8881 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8886 case ARRAY_RANGE_REF
:
8889 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
8890 enum machine_mode mode
;
8893 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
8894 &unsignedp
, &volatilep
);
8899 ret
= loc_descriptor_from_tree (obj
, 1);
8901 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
8904 if (offset
!= NULL_TREE
)
8906 /* Variable offset. */
8907 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
8908 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8914 bytepos
= bitpos
/ BITS_PER_UNIT
;
8916 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
8917 else if (bytepos
< 0)
8919 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
8920 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
8926 if (host_integerp (loc
, 0))
8927 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
8934 /* Get an RTL for this, if something has been emitted. */
8935 rtx rtl
= lookup_constant_def (loc
);
8936 enum machine_mode mode
;
8938 if (GET_CODE (rtl
) != MEM
)
8940 mode
= GET_MODE (rtl
);
8941 rtl
= XEXP (rtl
, 0);
8943 rtl
= targetm
.delegitimize_address (rtl
);
8946 ret
= mem_loc_descriptor (rtl
, mode
, true);
8950 case TRUTH_AND_EXPR
:
8951 case TRUTH_ANDIF_EXPR
:
8956 case TRUTH_XOR_EXPR
:
8962 case TRUTH_ORIF_EXPR
:
8967 case FLOOR_DIV_EXPR
:
8969 case ROUND_DIV_EXPR
:
8970 case TRUNC_DIV_EXPR
:
8978 case FLOOR_MOD_EXPR
:
8980 case ROUND_MOD_EXPR
:
8981 case TRUNC_MOD_EXPR
:
8994 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
8998 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
8999 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9001 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9005 add_loc_descr (&ret
,
9006 new_loc_descr (DW_OP_plus_uconst
,
9007 tree_low_cst (TREE_OPERAND (loc
, 1),
9017 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9024 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9031 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9038 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9053 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9054 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
9055 if (ret
== 0 || ret1
== 0)
9058 add_loc_descr (&ret
, ret1
);
9059 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9062 case TRUTH_NOT_EXPR
:
9076 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9080 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9086 const enum tree_code code
=
9087 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9089 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
9090 build (code
, integer_type_node
,
9091 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9092 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9095 /* ... fall through ... */
9099 dw_loc_descr_ref lhs
9100 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
9101 dw_loc_descr_ref rhs
9102 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
9103 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9105 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9106 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9109 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9110 add_loc_descr (&ret
, bra_node
);
9112 add_loc_descr (&ret
, rhs
);
9113 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9114 add_loc_descr (&ret
, jump_node
);
9116 add_loc_descr (&ret
, lhs
);
9117 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9118 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9120 /* ??? Need a node to point the skip at. Use a nop. */
9121 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9122 add_loc_descr (&ret
, tmp
);
9123 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9124 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9129 /* Leave front-end specific codes as simply unknown. This comes
9130 up, for instance, with the C STMT_EXPR. */
9131 if ((unsigned int) TREE_CODE (loc
)
9132 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9135 /* Otherwise this is a generic code; we should just lists all of
9136 these explicitly. Aborting means we forgot one. */
9140 /* Show if we can't fill the request for an address. */
9141 if (addressp
&& indirect_p
== 0)
9144 /* If we've got an address and don't want one, dereference. */
9145 if (!addressp
&& indirect_p
> 0)
9147 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9149 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9151 else if (size
== DWARF2_ADDR_SIZE
)
9154 op
= DW_OP_deref_size
;
9156 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9162 /* Given a value, round it up to the lowest multiple of `boundary'
9163 which is not less than the value itself. */
9165 static inline HOST_WIDE_INT
9166 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9168 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9171 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9172 pointer to the declared type for the relevant field variable, or return
9173 `integer_type_node' if the given node turns out to be an
9177 field_type (tree decl
)
9181 if (TREE_CODE (decl
) == ERROR_MARK
)
9182 return integer_type_node
;
9184 type
= DECL_BIT_FIELD_TYPE (decl
);
9185 if (type
== NULL_TREE
)
9186 type
= TREE_TYPE (decl
);
9191 /* Given a pointer to a tree node, return the alignment in bits for
9192 it, or else return BITS_PER_WORD if the node actually turns out to
9193 be an ERROR_MARK node. */
9195 static inline unsigned
9196 simple_type_align_in_bits (tree type
)
9198 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9201 static inline unsigned
9202 simple_decl_align_in_bits (tree decl
)
9204 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9207 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9208 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9209 or return 0 if we are unable to determine what that offset is, either
9210 because the argument turns out to be a pointer to an ERROR_MARK node, or
9211 because the offset is actually variable. (We can't handle the latter case
9214 static HOST_WIDE_INT
9215 field_byte_offset (tree decl
)
9217 unsigned int type_align_in_bits
;
9218 unsigned int decl_align_in_bits
;
9219 unsigned HOST_WIDE_INT type_size_in_bits
;
9220 HOST_WIDE_INT object_offset_in_bits
;
9222 tree field_size_tree
;
9223 HOST_WIDE_INT bitpos_int
;
9224 HOST_WIDE_INT deepest_bitpos
;
9225 unsigned HOST_WIDE_INT field_size_in_bits
;
9227 if (TREE_CODE (decl
) == ERROR_MARK
)
9229 else if (TREE_CODE (decl
) != FIELD_DECL
)
9232 type
= field_type (decl
);
9233 field_size_tree
= DECL_SIZE (decl
);
9235 /* The size could be unspecified if there was an error, or for
9236 a flexible array member. */
9237 if (! field_size_tree
)
9238 field_size_tree
= bitsize_zero_node
;
9240 /* We cannot yet cope with fields whose positions are variable, so
9241 for now, when we see such things, we simply return 0. Someday, we may
9242 be able to handle such cases, but it will be damn difficult. */
9243 if (! host_integerp (bit_position (decl
), 0))
9246 bitpos_int
= int_bit_position (decl
);
9248 /* If we don't know the size of the field, pretend it's a full word. */
9249 if (host_integerp (field_size_tree
, 1))
9250 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9252 field_size_in_bits
= BITS_PER_WORD
;
9254 type_size_in_bits
= simple_type_size_in_bits (type
);
9255 type_align_in_bits
= simple_type_align_in_bits (type
);
9256 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9258 /* The GCC front-end doesn't make any attempt to keep track of the starting
9259 bit offset (relative to the start of the containing structure type) of the
9260 hypothetical "containing object" for a bit-field. Thus, when computing
9261 the byte offset value for the start of the "containing object" of a
9262 bit-field, we must deduce this information on our own. This can be rather
9263 tricky to do in some cases. For example, handling the following structure
9264 type definition when compiling for an i386/i486 target (which only aligns
9265 long long's to 32-bit boundaries) can be very tricky:
9267 struct S { int field1; long long field2:31; };
9269 Fortunately, there is a simple rule-of-thumb which can be used in such
9270 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9271 structure shown above. It decides to do this based upon one simple rule
9272 for bit-field allocation. GCC allocates each "containing object" for each
9273 bit-field at the first (i.e. lowest addressed) legitimate alignment
9274 boundary (based upon the required minimum alignment for the declared type
9275 of the field) which it can possibly use, subject to the condition that
9276 there is still enough available space remaining in the containing object
9277 (when allocated at the selected point) to fully accommodate all of the
9278 bits of the bit-field itself.
9280 This simple rule makes it obvious why GCC allocates 8 bytes for each
9281 object of the structure type shown above. When looking for a place to
9282 allocate the "containing object" for `field2', the compiler simply tries
9283 to allocate a 64-bit "containing object" at each successive 32-bit
9284 boundary (starting at zero) until it finds a place to allocate that 64-
9285 bit field such that at least 31 contiguous (and previously unallocated)
9286 bits remain within that selected 64 bit field. (As it turns out, for the
9287 example above, the compiler finds it is OK to allocate the "containing
9288 object" 64-bit field at bit-offset zero within the structure type.)
9290 Here we attempt to work backwards from the limited set of facts we're
9291 given, and we try to deduce from those facts, where GCC must have believed
9292 that the containing object started (within the structure type). The value
9293 we deduce is then used (by the callers of this routine) to generate
9294 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9295 and, in the case of DW_AT_location, regular fields as well). */
9297 /* Figure out the bit-distance from the start of the structure to the
9298 "deepest" bit of the bit-field. */
9299 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
9301 /* This is the tricky part. Use some fancy footwork to deduce where the
9302 lowest addressed bit of the containing object must be. */
9303 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9305 /* Round up to type_align by default. This works best for bitfields. */
9306 object_offset_in_bits
+= type_align_in_bits
- 1;
9307 object_offset_in_bits
/= type_align_in_bits
;
9308 object_offset_in_bits
*= type_align_in_bits
;
9310 if (object_offset_in_bits
> bitpos_int
)
9312 /* Sigh, the decl must be packed. */
9313 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9315 /* Round up to decl_align instead. */
9316 object_offset_in_bits
+= decl_align_in_bits
- 1;
9317 object_offset_in_bits
/= decl_align_in_bits
;
9318 object_offset_in_bits
*= decl_align_in_bits
;
9321 return object_offset_in_bits
/ BITS_PER_UNIT
;
9324 /* The following routines define various Dwarf attributes and any data
9325 associated with them. */
9327 /* Add a location description attribute value to a DIE.
9329 This emits location attributes suitable for whole variables and
9330 whole parameters. Note that the location attributes for struct fields are
9331 generated by the routine `data_member_location_attribute' below. */
9334 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9335 dw_loc_descr_ref descr
)
9338 add_AT_loc (die
, attr_kind
, descr
);
9341 /* Attach the specialized form of location attribute used for data members of
9342 struct and union types. In the special case of a FIELD_DECL node which
9343 represents a bit-field, the "offset" part of this special location
9344 descriptor must indicate the distance in bytes from the lowest-addressed
9345 byte of the containing struct or union type to the lowest-addressed byte of
9346 the "containing object" for the bit-field. (See the `field_byte_offset'
9349 For any given bit-field, the "containing object" is a hypothetical object
9350 (of some integral or enum type) within which the given bit-field lives. The
9351 type of this hypothetical "containing object" is always the same as the
9352 declared type of the individual bit-field itself (for GCC anyway... the
9353 DWARF spec doesn't actually mandate this). Note that it is the size (in
9354 bytes) of the hypothetical "containing object" which will be given in the
9355 DW_AT_byte_size attribute for this bit-field. (See the
9356 `byte_size_attribute' function below.) It is also used when calculating the
9357 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9361 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
9363 HOST_WIDE_INT offset
;
9364 dw_loc_descr_ref loc_descr
= 0;
9366 if (TREE_CODE (decl
) == TREE_VEC
)
9368 /* We're working on the TAG_inheritance for a base class. */
9369 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
9371 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9372 aren't at a fixed offset from all (sub)objects of the same
9373 type. We need to extract the appropriate offset from our
9374 vtable. The following dwarf expression means
9376 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9378 This is specific to the V3 ABI, of course. */
9380 dw_loc_descr_ref tmp
;
9382 /* Make a copy of the object address. */
9383 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
9384 add_loc_descr (&loc_descr
, tmp
);
9386 /* Extract the vtable address. */
9387 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9388 add_loc_descr (&loc_descr
, tmp
);
9390 /* Calculate the address of the offset. */
9391 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9395 tmp
= int_loc_descriptor (-offset
);
9396 add_loc_descr (&loc_descr
, tmp
);
9397 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9398 add_loc_descr (&loc_descr
, tmp
);
9400 /* Extract the offset. */
9401 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9402 add_loc_descr (&loc_descr
, tmp
);
9404 /* Add it to the object address. */
9405 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9406 add_loc_descr (&loc_descr
, tmp
);
9409 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9412 offset
= field_byte_offset (decl
);
9416 enum dwarf_location_atom op
;
9418 /* The DWARF2 standard says that we should assume that the structure
9419 address is already on the stack, so we can specify a structure field
9420 address by using DW_OP_plus_uconst. */
9422 #ifdef MIPS_DEBUGGING_INFO
9423 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9424 operator correctly. It works only if we leave the offset on the
9428 op
= DW_OP_plus_uconst
;
9431 loc_descr
= new_loc_descr (op
, offset
, 0);
9434 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9437 /* Writes integer values to dw_vec_const array. */
9440 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
9444 *dest
++ = val
& 0xff;
9450 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9452 static HOST_WIDE_INT
9453 extract_int (const unsigned char *src
, unsigned int size
)
9455 HOST_WIDE_INT val
= 0;
9461 val
|= *--src
& 0xff;
9467 /* Writes floating point values to dw_vec_const array. */
9470 insert_float (rtx rtl
, unsigned char *array
)
9476 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9477 real_to_target (val
, &rv
, GET_MODE (rtl
));
9479 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9480 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
9482 insert_int (val
[i
], 4, array
);
9487 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9488 does not have a "location" either in memory or in a register. These
9489 things can arise in GNU C when a constant is passed as an actual parameter
9490 to an inlined function. They can also arise in C++ where declared
9491 constants do not necessarily get memory "homes". */
9494 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9496 switch (GET_CODE (rtl
))
9500 HOST_WIDE_INT val
= INTVAL (rtl
);
9503 add_AT_int (die
, DW_AT_const_value
, val
);
9505 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
9510 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9511 floating-point constant. A CONST_DOUBLE is used whenever the
9512 constant requires more than one word in order to be adequately
9513 represented. We output CONST_DOUBLEs as blocks. */
9515 enum machine_mode mode
= GET_MODE (rtl
);
9517 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9519 unsigned int length
= GET_MODE_SIZE (mode
);
9520 unsigned char *array
= ggc_alloc (length
);
9522 insert_float (rtl
, array
);
9523 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
9527 /* ??? We really should be using HOST_WIDE_INT throughout. */
9528 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
9531 add_AT_long_long (die
, DW_AT_const_value
,
9532 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9539 enum machine_mode mode
= GET_MODE (rtl
);
9540 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
9541 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
9542 unsigned char *array
= ggc_alloc (length
* elt_size
);
9546 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
9548 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9550 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9551 HOST_WIDE_INT lo
, hi
;
9552 if (GET_CODE (elt
) == CONST_INT
)
9557 else if (GET_CODE (elt
) == CONST_DOUBLE
)
9559 lo
= CONST_DOUBLE_LOW (elt
);
9560 hi
= CONST_DOUBLE_HIGH (elt
);
9565 if (elt_size
<= sizeof (HOST_WIDE_INT
))
9566 insert_int (lo
, elt_size
, p
);
9567 else if (elt_size
== 2 * sizeof (HOST_WIDE_INT
))
9569 unsigned char *p0
= p
;
9570 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
9572 if (WORDS_BIG_ENDIAN
)
9577 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
9578 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
9584 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
9586 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9588 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9589 insert_float (elt
, p
);
9595 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
9600 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9606 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9607 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
9611 /* In cases where an inlined instance of an inline function is passed
9612 the address of an `auto' variable (which is local to the caller) we
9613 can get a situation where the DECL_RTL of the artificial local
9614 variable (for the inlining) which acts as a stand-in for the
9615 corresponding formal parameter (of the inline function) will look
9616 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9617 exactly a compile-time constant expression, but it isn't the address
9618 of the (artificial) local variable either. Rather, it represents the
9619 *value* which the artificial local variable always has during its
9620 lifetime. We currently have no way to represent such quasi-constant
9621 values in Dwarf, so for now we just punt and generate nothing. */
9625 /* No other kinds of rtx should be possible here. */
9632 rtl_for_decl_location (tree decl
)
9636 /* Here we have to decide where we are going to say the parameter "lives"
9637 (as far as the debugger is concerned). We only have a couple of
9638 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9640 DECL_RTL normally indicates where the parameter lives during most of the
9641 activation of the function. If optimization is enabled however, this
9642 could be either NULL or else a pseudo-reg. Both of those cases indicate
9643 that the parameter doesn't really live anywhere (as far as the code
9644 generation parts of GCC are concerned) during most of the function's
9645 activation. That will happen (for example) if the parameter is never
9646 referenced within the function.
9648 We could just generate a location descriptor here for all non-NULL
9649 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9650 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9651 where DECL_RTL is NULL or is a pseudo-reg.
9653 Note however that we can only get away with using DECL_INCOMING_RTL as
9654 a backup substitute for DECL_RTL in certain limited cases. In cases
9655 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9656 we can be sure that the parameter was passed using the same type as it is
9657 declared to have within the function, and that its DECL_INCOMING_RTL
9658 points us to a place where a value of that type is passed.
9660 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9661 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9662 because in these cases DECL_INCOMING_RTL points us to a value of some
9663 type which is *different* from the type of the parameter itself. Thus,
9664 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9665 such cases, the debugger would end up (for example) trying to fetch a
9666 `float' from a place which actually contains the first part of a
9667 `double'. That would lead to really incorrect and confusing
9668 output at debug-time.
9670 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9671 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9672 are a couple of exceptions however. On little-endian machines we can
9673 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9674 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9675 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9676 when (on a little-endian machine) a non-prototyped function has a
9677 parameter declared to be of type `short' or `char'. In such cases,
9678 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9679 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9680 passed `int' value. If the debugger then uses that address to fetch
9681 a `short' or a `char' (on a little-endian machine) the result will be
9682 the correct data, so we allow for such exceptional cases below.
9684 Note that our goal here is to describe the place where the given formal
9685 parameter lives during most of the function's activation (i.e. between the
9686 end of the prologue and the start of the epilogue). We'll do that as best
9687 as we can. Note however that if the given formal parameter is modified
9688 sometime during the execution of the function, then a stack backtrace (at
9689 debug-time) will show the function as having been called with the *new*
9690 value rather than the value which was originally passed in. This happens
9691 rarely enough that it is not a major problem, but it *is* a problem, and
9694 A future version of dwarf2out.c may generate two additional attributes for
9695 any given DW_TAG_formal_parameter DIE which will describe the "passed
9696 type" and the "passed location" for the given formal parameter in addition
9697 to the attributes we now generate to indicate the "declared type" and the
9698 "active location" for each parameter. This additional set of attributes
9699 could be used by debuggers for stack backtraces. Separately, note that
9700 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9701 This happens (for example) for inlined-instances of inline function formal
9702 parameters which are never referenced. This really shouldn't be
9703 happening. All PARM_DECL nodes should get valid non-NULL
9704 DECL_INCOMING_RTL values. FIXME. */
9706 /* Use DECL_RTL as the "location" unless we find something better. */
9707 rtl
= DECL_RTL_IF_SET (decl
);
9709 /* When generating abstract instances, ignore everything except
9710 constants, symbols living in memory, and symbols living in
9712 if (! reload_completed
)
9715 && (CONSTANT_P (rtl
)
9716 || (GET_CODE (rtl
) == MEM
9717 && CONSTANT_P (XEXP (rtl
, 0)))
9719 && TREE_CODE (decl
) == VAR_DECL
9720 && TREE_STATIC (decl
))))
9722 rtl
= targetm
.delegitimize_address (rtl
);
9727 else if (TREE_CODE (decl
) == PARM_DECL
)
9729 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
9731 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
9732 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
9734 /* This decl represents a formal parameter which was optimized out.
9735 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9736 all cases where (rtl == NULL_RTX) just below. */
9737 if (declared_type
== passed_type
)
9738 rtl
= DECL_INCOMING_RTL (decl
);
9739 else if (! BYTES_BIG_ENDIAN
9740 && TREE_CODE (declared_type
) == INTEGER_TYPE
9741 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
9742 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
9743 rtl
= DECL_INCOMING_RTL (decl
);
9746 /* If the parm was passed in registers, but lives on the stack, then
9747 make a big endian correction if the mode of the type of the
9748 parameter is not the same as the mode of the rtl. */
9749 /* ??? This is the same series of checks that are made in dbxout.c before
9750 we reach the big endian correction code there. It isn't clear if all
9751 of these checks are necessary here, but keeping them all is the safe
9753 else if (GET_CODE (rtl
) == MEM
9754 && XEXP (rtl
, 0) != const0_rtx
9755 && ! CONSTANT_P (XEXP (rtl
, 0))
9756 /* Not passed in memory. */
9757 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
9758 /* Not passed by invisible reference. */
9759 && (!REG_P (XEXP (rtl
, 0))
9760 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
9761 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
9762 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9763 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
9766 /* Big endian correction check. */
9768 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
9769 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
9772 int offset
= (UNITS_PER_WORD
9773 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
9775 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9776 plus_constant (XEXP (rtl
, 0), offset
));
9779 else if (TREE_CODE (decl
) == VAR_DECL
9781 && GET_CODE (rtl
) == MEM
9782 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
9783 && BYTES_BIG_ENDIAN
)
9785 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
9786 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
9788 /* If a variable is declared "register" yet is smaller than
9789 a register, then if we store the variable to memory, it
9790 looks like we're storing a register-sized value, when in
9791 fact we are not. We need to adjust the offset of the
9792 storage location to reflect the actual value's bytes,
9793 else gdb will not be able to display it. */
9795 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9796 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
9799 if (rtl
!= NULL_RTX
)
9801 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
9802 #ifdef LEAF_REG_REMAP
9803 if (current_function_uses_only_leaf_regs
)
9804 leaf_renumber_regs_insn (rtl
);
9808 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9809 and will have been substituted directly into all expressions that use it.
9810 C does not have such a concept, but C++ and other languages do. */
9811 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
9813 /* If a variable is initialized with a string constant without embedded
9814 zeros, build CONST_STRING. */
9815 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
9816 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9818 tree arrtype
= TREE_TYPE (decl
);
9819 tree enttype
= TREE_TYPE (arrtype
);
9820 tree domain
= TYPE_DOMAIN (arrtype
);
9821 tree init
= DECL_INITIAL (decl
);
9822 enum machine_mode mode
= TYPE_MODE (enttype
);
9824 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9826 && integer_zerop (TYPE_MIN_VALUE (domain
))
9827 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9828 TREE_STRING_LENGTH (init
) - 1) == 0
9829 && ((size_t) TREE_STRING_LENGTH (init
)
9830 == strlen (TREE_STRING_POINTER (init
)) + 1))
9831 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
9833 /* If the initializer is something that we know will expand into an
9834 immediate RTL constant, expand it now. Expanding anything else
9835 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9836 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
9837 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
9839 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
9840 EXPAND_INITIALIZER
);
9841 /* If expand_expr returns a MEM, it wasn't immediate. */
9842 if (rtl
&& GET_CODE (rtl
) == MEM
)
9848 rtl
= targetm
.delegitimize_address (rtl
);
9850 /* If we don't look past the constant pool, we risk emitting a
9851 reference to a constant pool entry that isn't referenced from
9852 code, and thus is not emitted. */
9854 rtl
= avoid_constant_pool_reference (rtl
);
9859 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9860 data attribute for a variable or a parameter. We generate the
9861 DW_AT_const_value attribute only in those cases where the given variable
9862 or parameter does not have a true "location" either in memory or in a
9863 register. This can happen (for example) when a constant is passed as an
9864 actual argument in a call to an inline function. (It's possible that
9865 these things can crop up in other ways also.) Note that one type of
9866 constant value which can be passed into an inlined function is a constant
9867 pointer. This can happen for example if an actual argument in an inlined
9868 function call evaluates to a compile-time constant address. */
9871 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
9872 enum dwarf_attribute attr
)
9875 dw_loc_descr_ref descr
;
9876 var_loc_list
*loc_list
;
9878 if (TREE_CODE (decl
) == ERROR_MARK
)
9880 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
9881 && TREE_CODE (decl
) != RESULT_DECL
)
9884 /* See if we possibly have multiple locations for this variable. */
9885 loc_list
= lookup_decl_loc (decl
);
9887 /* If it truly has multiple locations, the first and last node will
9889 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
9891 const char *secname
;
9892 const char *endname
;
9893 dw_loc_list_ref list
;
9895 struct var_loc_node
*node
;
9897 /* We need to figure out what section we should use as the base
9898 for the address ranges where a given location is valid.
9899 1. If this particular DECL has a section associated with it,
9901 2. If this function has a section associated with it, use
9903 3. Otherwise, use the text section.
9904 XXX: If you split a variable across multiple sections, this
9907 if (DECL_SECTION_NAME (decl
))
9909 tree sectree
= DECL_SECTION_NAME (decl
);
9910 secname
= TREE_STRING_POINTER (sectree
);
9912 else if (current_function_decl
9913 && DECL_SECTION_NAME (current_function_decl
))
9915 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
9916 secname
= TREE_STRING_POINTER (sectree
);
9919 secname
= text_section_label
;
9921 /* Now that we know what section we are using for a base,
9922 actually construct the list of locations.
9923 The first location information is what is passed to the
9924 function that creates the location list, and the remaining
9925 locations just get added on to that list.
9926 Note that we only know the start address for a location
9927 (IE location changes), so to build the range, we use
9928 the range [current location start, next location start].
9929 This means we have to special case the last node, and generate
9930 a range of [last location start, end of function label]. */
9932 node
= loc_list
->first
;
9933 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
9934 list
= new_loc_list (loc_descriptor (varloc
, attr
!= DW_AT_frame_base
),
9935 node
->label
, node
->next
->label
, secname
, 1);
9938 for (; node
->next
; node
= node
->next
)
9939 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
9941 /* The variable has a location between NODE->LABEL and
9942 NODE->NEXT->LABEL. */
9943 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
9944 add_loc_descr_to_loc_list (&list
,
9945 loc_descriptor (varloc
,
9946 attr
!= DW_AT_frame_base
),
9947 node
->label
, node
->next
->label
, secname
);
9950 /* If the variable has a location at the last label
9951 it keeps its location until the end of function. */
9952 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
9954 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
9956 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
9957 if (!current_function_decl
)
9958 endname
= text_end_label
;
9961 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
9962 current_function_funcdef_no
);
9963 endname
= ggc_strdup (label_id
);
9965 add_loc_descr_to_loc_list (&list
,
9966 loc_descriptor (varloc
,
9967 attr
!= DW_AT_frame_base
),
9968 node
->label
, endname
, secname
);
9971 /* Finally, add the location list to the DIE, and we are done. */
9972 add_AT_loc_list (die
, attr
, list
);
9976 rtl
= rtl_for_decl_location (decl
);
9977 if (rtl
== NULL_RTX
)
9980 switch (GET_CODE (rtl
))
9983 /* The address of a variable that was optimized away;
9984 don't emit anything. */
9995 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9996 add_const_value_attribute (die
, rtl
);
10000 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
10002 /* Need loc_descriptor_from_tree since that's where we know
10003 how to handle TLS variables. Want the object's address
10004 since the top-level DW_AT_location assumes such. See
10005 the confusion in loc_descriptor for reference. */
10006 descr
= loc_descriptor_from_tree (decl
, 1);
10013 descr
= loc_descriptor (rtl
, true);
10015 add_AT_location_description (die
, attr
, descr
);
10020 rtvec par_elems
= XVEC (rtl
, 0);
10021 int num_elem
= GET_NUM_ELEM (par_elems
);
10022 enum machine_mode mode
;
10025 /* Create the first one, so we have something to add to. */
10026 descr
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0), true);
10027 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
10028 add_loc_descr (&descr
,
10029 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (mode
), 0));
10030 for (i
= 1; i
< num_elem
; i
++)
10032 dw_loc_descr_ref temp
;
10034 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0), true);
10035 add_loc_descr (&descr
, temp
);
10036 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
10037 add_loc_descr (&descr
,
10038 new_loc_descr (DW_OP_piece
,
10039 GET_MODE_SIZE (mode
), 0));
10042 add_AT_location_description (die
, DW_AT_location
, descr
);
10050 /* If we don't have a copy of this variable in memory for some reason (such
10051 as a C++ member constant that doesn't have an out-of-line definition),
10052 we should tell the debugger about the constant value. */
10055 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10057 tree init
= DECL_INITIAL (decl
);
10058 tree type
= TREE_TYPE (decl
);
10060 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
10061 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
10066 switch (TREE_CODE (type
))
10069 if (host_integerp (init
, 0))
10070 add_AT_unsigned (var_die
, DW_AT_const_value
,
10071 tree_low_cst (init
, 0));
10073 add_AT_long_long (var_die
, DW_AT_const_value
,
10074 TREE_INT_CST_HIGH (init
),
10075 TREE_INT_CST_LOW (init
));
10082 /* Generate a DW_AT_name attribute given some string value to be included as
10083 the value of the attribute. */
10086 add_name_attribute (dw_die_ref die
, const char *name_string
)
10088 if (name_string
!= NULL
&& *name_string
!= 0)
10090 if (demangle_name_func
)
10091 name_string
= (*demangle_name_func
) (name_string
);
10093 add_AT_string (die
, DW_AT_name
, name_string
);
10097 /* Generate a DW_AT_comp_dir attribute for DIE. */
10100 add_comp_dir_attribute (dw_die_ref die
)
10102 const char *wd
= get_src_pwd ();
10104 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10107 /* Given a tree node describing an array bound (either lower or upper) output
10108 a representation for that bound. */
10111 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
10113 switch (TREE_CODE (bound
))
10118 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10120 if (! host_integerp (bound
, 0)
10121 || (bound_attr
== DW_AT_lower_bound
10122 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
10123 || (is_fortran () && integer_onep (bound
)))))
10124 /* Use the default. */
10127 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
10132 case NON_LVALUE_EXPR
:
10133 case VIEW_CONVERT_EXPR
:
10134 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
10138 /* If optimization is turned on, the SAVE_EXPRs that describe how to
10139 access the upper bound values may be bogus. If they refer to a
10140 register, they may only describe how to get at these values at the
10141 points in the generated code right after they have just been
10142 computed. Worse yet, in the typical case, the upper bound values
10143 will not even *be* computed in the optimized code (though the
10144 number of elements will), so these SAVE_EXPRs are entirely
10145 bogus. In order to compensate for this fact, we check here to see
10146 if optimization is enabled, and if so, we don't add an attribute
10147 for the (unknown and unknowable) upper bound. This should not
10148 cause too much trouble for existing (stupid?) debuggers because
10149 they have to deal with empty upper bounds location descriptions
10150 anyway in order to be able to deal with incomplete array types.
10151 Of course an intelligent debugger (GDB?) should be able to
10152 comprehend that a missing upper bound specification in an array
10153 type used for a storage class `auto' local array variable
10154 indicates that the upper bound is both unknown (at compile- time)
10155 and unknowable (at run-time) due to optimization.
10157 We assume that a MEM rtx is safe because gcc wouldn't put the
10158 value there unless it was going to be used repeatedly in the
10159 function, i.e. for cleanups. */
10160 if (SAVE_EXPR_RTL (bound
)
10161 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
10163 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
10164 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10165 rtx loc
= SAVE_EXPR_RTL (bound
);
10167 /* If the RTL for the SAVE_EXPR is memory, handle the case where
10168 it references an outer function's frame. */
10169 if (GET_CODE (loc
) == MEM
)
10171 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
10173 if (XEXP (loc
, 0) != new_addr
)
10174 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
10177 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10178 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10179 add_AT_location_description (decl_die
, DW_AT_location
,
10180 loc_descriptor (loc
, true));
10181 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10184 /* Else leave out the attribute. */
10191 dw_die_ref decl_die
= lookup_decl_die (bound
);
10193 /* ??? Can this happen, or should the variable have been bound
10194 first? Probably it can, since I imagine that we try to create
10195 the types of parameters in the order in which they exist in
10196 the list, and won't have created a forward reference to a
10197 later parameter. */
10198 if (decl_die
!= NULL
)
10199 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10205 /* Otherwise try to create a stack operation procedure to
10206 evaluate the value of the array bound. */
10208 dw_die_ref ctx
, decl_die
;
10209 dw_loc_descr_ref loc
;
10211 loc
= loc_descriptor_from_tree (bound
, 0);
10215 if (current_function_decl
== 0)
10216 ctx
= comp_unit_die
;
10218 ctx
= lookup_decl_die (current_function_decl
);
10220 /* If we weren't able to find a context, it's most likely the case
10221 that we are processing the return type of the function. So
10222 make a SAVE_EXPR to point to it and have the limbo DIE code
10223 find the proper die. The save_expr function doesn't always
10224 make a SAVE_EXPR, so do it ourselves. */
10226 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
10227 current_function_decl
, NULL_TREE
);
10229 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10230 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10231 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10232 add_AT_loc (decl_die
, DW_AT_location
, loc
);
10234 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10240 /* Note that the block of subscript information for an array type also
10241 includes information about the element type of type given array type. */
10244 add_subscript_info (dw_die_ref type_die
, tree type
)
10246 #ifndef MIPS_DEBUGGING_INFO
10247 unsigned dimension_number
;
10250 dw_die_ref subrange_die
;
10252 /* The GNU compilers represent multidimensional array types as sequences of
10253 one dimensional array types whose element types are themselves array
10254 types. Here we squish that down, so that each multidimensional array
10255 type gets only one array_type DIE in the Dwarf debugging info. The draft
10256 Dwarf specification say that we are allowed to do this kind of
10257 compression in C (because there is no difference between an array or
10258 arrays and a multidimensional array in C) but for other source languages
10259 (e.g. Ada) we probably shouldn't do this. */
10261 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10262 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10263 We work around this by disabling this feature. See also
10264 gen_array_type_die. */
10265 #ifndef MIPS_DEBUGGING_INFO
10266 for (dimension_number
= 0;
10267 TREE_CODE (type
) == ARRAY_TYPE
;
10268 type
= TREE_TYPE (type
), dimension_number
++)
10271 tree domain
= TYPE_DOMAIN (type
);
10273 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10274 and (in GNU C only) variable bounds. Handle all three forms
10276 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
10279 /* We have an array type with specified bounds. */
10280 lower
= TYPE_MIN_VALUE (domain
);
10281 upper
= TYPE_MAX_VALUE (domain
);
10283 /* Define the index type. */
10284 if (TREE_TYPE (domain
))
10286 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10287 TREE_TYPE field. We can't emit debug info for this
10288 because it is an unnamed integral type. */
10289 if (TREE_CODE (domain
) == INTEGER_TYPE
10290 && TYPE_NAME (domain
) == NULL_TREE
10291 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
10292 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
10295 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
10299 /* ??? If upper is NULL, the array has unspecified length,
10300 but it does have a lower bound. This happens with Fortran
10302 Since the debugger is definitely going to need to know N
10303 to produce useful results, go ahead and output the lower
10304 bound solo, and hope the debugger can cope. */
10306 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
10308 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
10311 /* Otherwise we have an array type with an unspecified length. The
10312 DWARF-2 spec does not say how to handle this; let's just leave out the
10318 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
10322 switch (TREE_CODE (tree_node
))
10327 case ENUMERAL_TYPE
:
10330 case QUAL_UNION_TYPE
:
10331 size
= int_size_in_bytes (tree_node
);
10334 /* For a data member of a struct or union, the DW_AT_byte_size is
10335 generally given as the number of bytes normally allocated for an
10336 object of the *declared* type of the member itself. This is true
10337 even for bit-fields. */
10338 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
10344 /* Note that `size' might be -1 when we get to this point. If it is, that
10345 indicates that the byte size of the entity in question is variable. We
10346 have no good way of expressing this fact in Dwarf at the present time,
10347 so just let the -1 pass on through. */
10348 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
10351 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10352 which specifies the distance in bits from the highest order bit of the
10353 "containing object" for the bit-field to the highest order bit of the
10356 For any given bit-field, the "containing object" is a hypothetical object
10357 (of some integral or enum type) within which the given bit-field lives. The
10358 type of this hypothetical "containing object" is always the same as the
10359 declared type of the individual bit-field itself. The determination of the
10360 exact location of the "containing object" for a bit-field is rather
10361 complicated. It's handled by the `field_byte_offset' function (above).
10363 Note that it is the size (in bytes) of the hypothetical "containing object"
10364 which will be given in the DW_AT_byte_size attribute for this bit-field.
10365 (See `byte_size_attribute' above). */
10368 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
10370 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
10371 tree type
= DECL_BIT_FIELD_TYPE (decl
);
10372 HOST_WIDE_INT bitpos_int
;
10373 HOST_WIDE_INT highest_order_object_bit_offset
;
10374 HOST_WIDE_INT highest_order_field_bit_offset
;
10375 HOST_WIDE_INT
unsigned bit_offset
;
10377 /* Must be a field and a bit field. */
10379 || TREE_CODE (decl
) != FIELD_DECL
)
10382 /* We can't yet handle bit-fields whose offsets are variable, so if we
10383 encounter such things, just return without generating any attribute
10384 whatsoever. Likewise for variable or too large size. */
10385 if (! host_integerp (bit_position (decl
), 0)
10386 || ! host_integerp (DECL_SIZE (decl
), 1))
10389 bitpos_int
= int_bit_position (decl
);
10391 /* Note that the bit offset is always the distance (in bits) from the
10392 highest-order bit of the "containing object" to the highest-order bit of
10393 the bit-field itself. Since the "high-order end" of any object or field
10394 is different on big-endian and little-endian machines, the computation
10395 below must take account of these differences. */
10396 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
10397 highest_order_field_bit_offset
= bitpos_int
;
10399 if (! BYTES_BIG_ENDIAN
)
10401 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
10402 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
10406 = (! BYTES_BIG_ENDIAN
10407 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
10408 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
10410 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
10413 /* For a FIELD_DECL node which represents a bit field, output an attribute
10414 which specifies the length in bits of the given field. */
10417 add_bit_size_attribute (dw_die_ref die
, tree decl
)
10419 /* Must be a field and a bit field. */
10420 if (TREE_CODE (decl
) != FIELD_DECL
10421 || ! DECL_BIT_FIELD_TYPE (decl
))
10424 if (host_integerp (DECL_SIZE (decl
), 1))
10425 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
10428 /* If the compiled language is ANSI C, then add a 'prototyped'
10429 attribute, if arg types are given for the parameters of a function. */
10432 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
10434 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
10435 && TYPE_ARG_TYPES (func_type
) != NULL
)
10436 add_AT_flag (die
, DW_AT_prototyped
, 1);
10439 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10440 by looking in either the type declaration or object declaration
10444 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
10446 dw_die_ref origin_die
= NULL
;
10448 if (TREE_CODE (origin
) != FUNCTION_DECL
)
10450 /* We may have gotten separated from the block for the inlined
10451 function, if we're in an exception handler or some such; make
10452 sure that the abstract function has been written out.
10454 Doing this for nested functions is wrong, however; functions are
10455 distinct units, and our context might not even be inline. */
10459 fn
= TYPE_STUB_DECL (fn
);
10461 fn
= decl_function_context (fn
);
10463 dwarf2out_abstract_function (fn
);
10466 if (DECL_P (origin
))
10467 origin_die
= lookup_decl_die (origin
);
10468 else if (TYPE_P (origin
))
10469 origin_die
= lookup_type_die (origin
);
10471 if (origin_die
== NULL
)
10474 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
10477 /* We do not currently support the pure_virtual attribute. */
10480 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
10482 if (DECL_VINDEX (func_decl
))
10484 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10486 if (host_integerp (DECL_VINDEX (func_decl
), 0))
10487 add_AT_loc (die
, DW_AT_vtable_elem_location
,
10488 new_loc_descr (DW_OP_constu
,
10489 tree_low_cst (DECL_VINDEX (func_decl
), 0),
10492 /* GNU extension: Record what type this method came from originally. */
10493 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10494 add_AT_die_ref (die
, DW_AT_containing_type
,
10495 lookup_type_die (DECL_CONTEXT (func_decl
)));
10499 /* Add source coordinate attributes for the given decl. */
10502 add_src_coords_attributes (dw_die_ref die
, tree decl
)
10504 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
10505 unsigned file_index
= lookup_filename (s
.file
);
10507 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
10508 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
10511 /* Add a DW_AT_name attribute and source coordinate attribute for the
10512 given decl, but only if it actually has a name. */
10515 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
10519 decl_name
= DECL_NAME (decl
);
10520 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
10522 add_name_attribute (die
, dwarf2_name (decl
, 0));
10523 if (! DECL_ARTIFICIAL (decl
))
10524 add_src_coords_attributes (die
, decl
);
10526 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
10527 && TREE_PUBLIC (decl
)
10528 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
10529 && !DECL_ABSTRACT (decl
))
10530 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
10531 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
10534 #ifdef VMS_DEBUGGING_INFO
10535 /* Get the function's name, as described by its RTL. This may be different
10536 from the DECL_NAME name used in the source file. */
10537 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
10539 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
10540 XEXP (DECL_RTL (decl
), 0));
10541 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
10546 /* Push a new declaration scope. */
10549 push_decl_scope (tree scope
)
10551 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
10554 /* Pop a declaration scope. */
10557 pop_decl_scope (void)
10559 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
10562 VARRAY_POP (decl_scope_table
);
10565 /* Return the DIE for the scope that immediately contains this type.
10566 Non-named types get global scope. Named types nested in other
10567 types get their containing scope if it's open, or global scope
10568 otherwise. All other types (i.e. function-local named types) get
10569 the current active scope. */
10572 scope_die_for (tree t
, dw_die_ref context_die
)
10574 dw_die_ref scope_die
= NULL
;
10575 tree containing_scope
;
10578 /* Non-types always go in the current scope. */
10582 containing_scope
= TYPE_CONTEXT (t
);
10584 /* Use the containing namespace if it was passed in (for a declaration). */
10585 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
10587 if (context_die
== lookup_decl_die (containing_scope
))
10590 containing_scope
= NULL_TREE
;
10593 /* Ignore function type "scopes" from the C frontend. They mean that
10594 a tagged type is local to a parmlist of a function declarator, but
10595 that isn't useful to DWARF. */
10596 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
10597 containing_scope
= NULL_TREE
;
10599 if (containing_scope
== NULL_TREE
)
10600 scope_die
= comp_unit_die
;
10601 else if (TYPE_P (containing_scope
))
10603 /* For types, we can just look up the appropriate DIE. But
10604 first we check to see if we're in the middle of emitting it
10605 so we know where the new DIE should go. */
10606 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
10607 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
10612 if (debug_info_level
> DINFO_LEVEL_TERSE
10613 && !TREE_ASM_WRITTEN (containing_scope
))
10616 /* If none of the current dies are suitable, we get file scope. */
10617 scope_die
= comp_unit_die
;
10620 scope_die
= lookup_type_die (containing_scope
);
10623 scope_die
= context_die
;
10628 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10631 local_scope_p (dw_die_ref context_die
)
10633 for (; context_die
; context_die
= context_die
->die_parent
)
10634 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10635 || context_die
->die_tag
== DW_TAG_subprogram
)
10641 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10642 whether or not to treat a DIE in this context as a declaration. */
10645 class_or_namespace_scope_p (dw_die_ref context_die
)
10647 return (context_die
10648 && (context_die
->die_tag
== DW_TAG_structure_type
10649 || context_die
->die_tag
== DW_TAG_union_type
10650 || context_die
->die_tag
== DW_TAG_namespace
));
10653 /* Many forms of DIEs require a "type description" attribute. This
10654 routine locates the proper "type descriptor" die for the type given
10655 by 'type', and adds a DW_AT_type attribute below the given die. */
10658 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
10659 int decl_volatile
, dw_die_ref context_die
)
10661 enum tree_code code
= TREE_CODE (type
);
10662 dw_die_ref type_die
= NULL
;
10664 /* ??? If this type is an unnamed subrange type of an integral or
10665 floating-point type, use the inner type. This is because we have no
10666 support for unnamed types in base_type_die. This can happen if this is
10667 an Ada subrange type. Correct solution is emit a subrange type die. */
10668 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10669 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10670 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
10672 if (code
== ERROR_MARK
10673 /* Handle a special case. For functions whose return type is void, we
10674 generate *no* type attribute. (Note that no object may have type
10675 `void', so this only applies to function return types). */
10676 || code
== VOID_TYPE
)
10679 type_die
= modified_type_die (type
,
10680 decl_const
|| TYPE_READONLY (type
),
10681 decl_volatile
|| TYPE_VOLATILE (type
),
10684 if (type_die
!= NULL
)
10685 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
10688 /* Given a tree pointer to a struct, class, union, or enum type node, return
10689 a pointer to the (string) tag name for the given type, or zero if the type
10690 was declared without a tag. */
10692 static const char *
10693 type_tag (tree type
)
10695 const char *name
= 0;
10697 if (TYPE_NAME (type
) != 0)
10701 /* Find the IDENTIFIER_NODE for the type name. */
10702 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
10703 t
= TYPE_NAME (type
);
10705 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10706 a TYPE_DECL node, regardless of whether or not a `typedef' was
10708 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10709 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
10710 t
= DECL_NAME (TYPE_NAME (type
));
10712 /* Now get the name as a string, or invent one. */
10714 name
= IDENTIFIER_POINTER (t
);
10717 return (name
== 0 || *name
== '\0') ? 0 : name
;
10720 /* Return the type associated with a data member, make a special check
10721 for bit field types. */
10724 member_declared_type (tree member
)
10726 return (DECL_BIT_FIELD_TYPE (member
)
10727 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
10730 /* Get the decl's label, as described by its RTL. This may be different
10731 from the DECL_NAME name used in the source file. */
10734 static const char *
10735 decl_start_label (tree decl
)
10738 const char *fnname
;
10740 x
= DECL_RTL (decl
);
10741 if (GET_CODE (x
) != MEM
)
10745 if (GET_CODE (x
) != SYMBOL_REF
)
10748 fnname
= XSTR (x
, 0);
10753 /* These routines generate the internal representation of the DIE's for
10754 the compilation unit. Debugging information is collected by walking
10755 the declaration trees passed in from dwarf2out_decl(). */
10758 gen_array_type_die (tree type
, dw_die_ref context_die
)
10760 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
10761 dw_die_ref array_die
;
10764 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10765 the inner array type comes before the outer array type. Thus we must
10766 call gen_type_die before we call new_die. See below also. */
10767 #ifdef MIPS_DEBUGGING_INFO
10768 gen_type_die (TREE_TYPE (type
), context_die
);
10771 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
10772 add_name_attribute (array_die
, type_tag (type
));
10773 equate_type_number_to_die (type
, array_die
);
10775 if (TREE_CODE (type
) == VECTOR_TYPE
)
10777 /* The frontend feeds us a representation for the vector as a struct
10778 containing an array. Pull out the array type. */
10779 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
10780 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
10784 /* We default the array ordering. SDB will probably do
10785 the right things even if DW_AT_ordering is not present. It's not even
10786 an issue until we start to get into multidimensional arrays anyway. If
10787 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10788 then we'll have to put the DW_AT_ordering attribute back in. (But if
10789 and when we find out that we need to put these in, we will only do so
10790 for multidimensional arrays. */
10791 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
10794 #ifdef MIPS_DEBUGGING_INFO
10795 /* The SGI compilers handle arrays of unknown bound by setting
10796 AT_declaration and not emitting any subrange DIEs. */
10797 if (! TYPE_DOMAIN (type
))
10798 add_AT_flag (array_die
, DW_AT_declaration
, 1);
10801 add_subscript_info (array_die
, type
);
10803 /* Add representation of the type of the elements of this array type. */
10804 element_type
= TREE_TYPE (type
);
10806 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10807 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10808 We work around this by disabling this feature. See also
10809 add_subscript_info. */
10810 #ifndef MIPS_DEBUGGING_INFO
10811 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
10812 element_type
= TREE_TYPE (element_type
);
10814 gen_type_die (element_type
, context_die
);
10817 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
10821 gen_set_type_die (tree type
, dw_die_ref context_die
)
10823 dw_die_ref type_die
10824 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
10826 equate_type_number_to_die (type
, type_die
);
10827 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
10832 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
10834 tree origin
= decl_ultimate_origin (decl
);
10835 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
10837 if (origin
!= NULL
)
10838 add_abstract_origin_attribute (decl_die
, origin
);
10841 add_name_and_src_coords_attributes (decl_die
, decl
);
10842 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
10843 0, 0, context_die
);
10846 if (DECL_ABSTRACT (decl
))
10847 equate_decl_number_to_die (decl
, decl_die
);
10849 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
10853 /* Walk through the list of incomplete types again, trying once more to
10854 emit full debugging info for them. */
10857 retry_incomplete_types (void)
10861 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
10862 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
10865 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10868 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
10870 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
10872 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10873 be incomplete and such types are not marked. */
10874 add_abstract_origin_attribute (type_die
, type
);
10877 /* Generate a DIE to represent an inlined instance of a structure type. */
10880 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
10882 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
10884 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10885 be incomplete and such types are not marked. */
10886 add_abstract_origin_attribute (type_die
, type
);
10889 /* Generate a DIE to represent an inlined instance of a union type. */
10892 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
10894 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
10896 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10897 be incomplete and such types are not marked. */
10898 add_abstract_origin_attribute (type_die
, type
);
10901 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10902 include all of the information about the enumeration values also. Each
10903 enumerated type name/value is listed as a child of the enumerated type
10907 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
10909 dw_die_ref type_die
= lookup_type_die (type
);
10911 if (type_die
== NULL
)
10913 type_die
= new_die (DW_TAG_enumeration_type
,
10914 scope_die_for (type
, context_die
), type
);
10915 equate_type_number_to_die (type
, type_die
);
10916 add_name_attribute (type_die
, type_tag (type
));
10918 else if (! TYPE_SIZE (type
))
10921 remove_AT (type_die
, DW_AT_declaration
);
10923 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10924 given enum type is incomplete, do not generate the DW_AT_byte_size
10925 attribute or the DW_AT_element_list attribute. */
10926 if (TYPE_SIZE (type
))
10930 TREE_ASM_WRITTEN (type
) = 1;
10931 add_byte_size_attribute (type_die
, type
);
10932 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10933 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10935 /* If the first reference to this type was as the return type of an
10936 inline function, then it may not have a parent. Fix this now. */
10937 if (type_die
->die_parent
== NULL
)
10938 add_child_die (scope_die_for (type
, context_die
), type_die
);
10940 for (link
= TYPE_VALUES (type
);
10941 link
!= NULL
; link
= TREE_CHAIN (link
))
10943 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
10944 tree value
= TREE_VALUE (link
);
10946 add_name_attribute (enum_die
,
10947 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
10949 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
10950 /* DWARF2 does not provide a way of indicating whether or
10951 not enumeration constants are signed or unsigned. GDB
10952 always assumes the values are signed, so we output all
10953 values as if they were signed. That means that
10954 enumeration constants with very large unsigned values
10955 will appear to have negative values in the debugger. */
10956 add_AT_int (enum_die
, DW_AT_const_value
,
10957 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
10961 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10966 /* Generate a DIE to represent either a real live formal parameter decl or to
10967 represent just the type of some formal parameter position in some function
10970 Note that this routine is a bit unusual because its argument may be a
10971 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10972 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10973 node. If it's the former then this function is being called to output a
10974 DIE to represent a formal parameter object (or some inlining thereof). If
10975 it's the latter, then this function is only being called to output a
10976 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10977 argument type of some subprogram type. */
10980 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
10982 dw_die_ref parm_die
10983 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
10986 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
10989 origin
= decl_ultimate_origin (node
);
10990 if (origin
!= NULL
)
10991 add_abstract_origin_attribute (parm_die
, origin
);
10994 add_name_and_src_coords_attributes (parm_die
, node
);
10995 add_type_attribute (parm_die
, TREE_TYPE (node
),
10996 TREE_READONLY (node
),
10997 TREE_THIS_VOLATILE (node
),
10999 if (DECL_ARTIFICIAL (node
))
11000 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11003 equate_decl_number_to_die (node
, parm_die
);
11004 if (! DECL_ABSTRACT (node
))
11005 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
11010 /* We were called with some kind of a ..._TYPE node. */
11011 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
11021 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11022 at the end of an (ANSI prototyped) formal parameters list. */
11025 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
11027 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
11030 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11031 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11032 parameters as specified in some function type specification (except for
11033 those which appear as part of a function *definition*). */
11036 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
11039 tree formal_type
= NULL
;
11040 tree first_parm_type
;
11043 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
11045 arg
= DECL_ARGUMENTS (function_or_method_type
);
11046 function_or_method_type
= TREE_TYPE (function_or_method_type
);
11051 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
11053 /* Make our first pass over the list of formal parameter types and output a
11054 DW_TAG_formal_parameter DIE for each one. */
11055 for (link
= first_parm_type
; link
; )
11057 dw_die_ref parm_die
;
11059 formal_type
= TREE_VALUE (link
);
11060 if (formal_type
== void_type_node
)
11063 /* Output a (nameless) DIE to represent the formal parameter itself. */
11064 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
11065 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
11066 && link
== first_parm_type
)
11067 || (arg
&& DECL_ARTIFICIAL (arg
)))
11068 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11070 link
= TREE_CHAIN (link
);
11072 arg
= TREE_CHAIN (arg
);
11075 /* If this function type has an ellipsis, add a
11076 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11077 if (formal_type
!= void_type_node
)
11078 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
11080 /* Make our second (and final) pass over the list of formal parameter types
11081 and output DIEs to represent those types (as necessary). */
11082 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
11083 link
&& TREE_VALUE (link
);
11084 link
= TREE_CHAIN (link
))
11085 gen_type_die (TREE_VALUE (link
), context_die
);
11088 /* We want to generate the DIE for TYPE so that we can generate the
11089 die for MEMBER, which has been defined; we will need to refer back
11090 to the member declaration nested within TYPE. If we're trying to
11091 generate minimal debug info for TYPE, processing TYPE won't do the
11092 trick; we need to attach the member declaration by hand. */
11095 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
11097 gen_type_die (type
, context_die
);
11099 /* If we're trying to avoid duplicate debug info, we may not have
11100 emitted the member decl for this function. Emit it now. */
11101 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
11102 && ! lookup_decl_die (member
))
11104 if (decl_ultimate_origin (member
))
11107 push_decl_scope (type
);
11108 if (TREE_CODE (member
) == FUNCTION_DECL
)
11109 gen_subprogram_die (member
, lookup_type_die (type
));
11111 gen_variable_die (member
, lookup_type_die (type
));
11117 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11118 may later generate inlined and/or out-of-line instances of. */
11121 dwarf2out_abstract_function (tree decl
)
11123 dw_die_ref old_die
;
11126 int was_abstract
= DECL_ABSTRACT (decl
);
11128 /* Make sure we have the actual abstract inline, not a clone. */
11129 decl
= DECL_ORIGIN (decl
);
11131 old_die
= lookup_decl_die (decl
);
11132 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
11133 /* We've already generated the abstract instance. */
11136 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11137 we don't get confused by DECL_ABSTRACT. */
11138 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11140 context
= decl_class_context (decl
);
11142 gen_type_die_for_member
11143 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
11146 /* Pretend we've just finished compiling this function. */
11147 save_fn
= current_function_decl
;
11148 current_function_decl
= decl
;
11150 set_decl_abstract_flags (decl
, 1);
11151 dwarf2out_decl (decl
);
11152 if (! was_abstract
)
11153 set_decl_abstract_flags (decl
, 0);
11155 current_function_decl
= save_fn
;
11158 /* Generate a DIE to represent a declared function (either file-scope or
11162 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
11164 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11165 tree origin
= decl_ultimate_origin (decl
);
11166 dw_die_ref subr_die
;
11170 dw_die_ref old_die
= lookup_decl_die (decl
);
11171 int declaration
= (current_function_decl
!= decl
11172 || class_or_namespace_scope_p (context_die
));
11174 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11175 started to generate the abstract instance of an inline, decided to output
11176 its containing class, and proceeded to emit the declaration of the inline
11177 from the member list for the class. If so, DECLARATION takes priority;
11178 we'll get back to the abstract instance when done with the class. */
11180 /* The class-scope declaration DIE must be the primary DIE. */
11181 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
11188 if (origin
!= NULL
)
11190 if (declaration
&& ! local_scope_p (context_die
))
11193 /* Fixup die_parent for the abstract instance of a nested
11194 inline function. */
11195 if (old_die
&& old_die
->die_parent
== NULL
)
11196 add_child_die (context_die
, old_die
);
11198 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11199 add_abstract_origin_attribute (subr_die
, origin
);
11203 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11204 unsigned file_index
= lookup_filename (s
.file
);
11206 if (!get_AT_flag (old_die
, DW_AT_declaration
)
11207 /* We can have a normal definition following an inline one in the
11208 case of redefinition of GNU C extern inlines.
11209 It seems reasonable to use AT_specification in this case. */
11210 && !get_AT (old_die
, DW_AT_inline
))
11212 /* ??? This can happen if there is a bug in the program, for
11213 instance, if it has duplicate function definitions. Ideally,
11214 we should detect this case and ignore it. For now, if we have
11215 already reported an error, any error at all, then assume that
11216 we got here because of an input error, not a dwarf2 bug. */
11222 /* If the definition comes from the same place as the declaration,
11223 maybe use the old DIE. We always want the DIE for this function
11224 that has the *_pc attributes to be under comp_unit_die so the
11225 debugger can find it. We also need to do this for abstract
11226 instances of inlines, since the spec requires the out-of-line copy
11227 to have the same parent. For local class methods, this doesn't
11228 apply; we just use the old DIE. */
11229 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
11230 && (DECL_ARTIFICIAL (decl
)
11231 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
11232 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11233 == (unsigned) s
.line
))))
11235 subr_die
= old_die
;
11237 /* Clear out the declaration attribute and the formal parameters.
11238 Do not remove all children, because it is possible that this
11239 declaration die was forced using force_decl_die(). In such
11240 cases die that forced declaration die (e.g. TAG_imported_module)
11241 is one of the children that we do not want to remove. */
11242 remove_AT (subr_die
, DW_AT_declaration
);
11243 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
11247 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11248 add_AT_specification (subr_die
, old_die
);
11249 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11250 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
11251 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11252 != (unsigned) s
.line
)
11254 (subr_die
, DW_AT_decl_line
, s
.line
);
11259 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11261 if (TREE_PUBLIC (decl
))
11262 add_AT_flag (subr_die
, DW_AT_external
, 1);
11264 add_name_and_src_coords_attributes (subr_die
, decl
);
11265 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11267 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
11268 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
11269 0, 0, context_die
);
11272 add_pure_or_virtual_attribute (subr_die
, decl
);
11273 if (DECL_ARTIFICIAL (decl
))
11274 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
11276 if (TREE_PROTECTED (decl
))
11277 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11278 else if (TREE_PRIVATE (decl
))
11279 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11284 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11286 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
11288 /* The first time we see a member function, it is in the context of
11289 the class to which it belongs. We make sure of this by emitting
11290 the class first. The next time is the definition, which is
11291 handled above. The two may come from the same source text.
11293 Note that force_decl_die() forces function declaration die. It is
11294 later reused to represent definition. */
11295 equate_decl_number_to_die (decl
, subr_die
);
11298 else if (DECL_ABSTRACT (decl
))
11300 if (DECL_DECLARED_INLINE_P (decl
))
11302 if (cgraph_function_possibly_inlined_p (decl
))
11303 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
11305 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
11309 if (cgraph_function_possibly_inlined_p (decl
))
11310 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
11312 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
11315 equate_decl_number_to_die (decl
, subr_die
);
11317 else if (!DECL_EXTERNAL (decl
))
11319 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11320 equate_decl_number_to_die (decl
, subr_die
);
11322 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
11323 current_function_funcdef_no
);
11324 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
11325 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11326 current_function_funcdef_no
);
11327 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
11329 add_pubname (decl
, subr_die
);
11330 add_arange (decl
, subr_die
);
11332 #ifdef MIPS_DEBUGGING_INFO
11333 /* Add a reference to the FDE for this routine. */
11334 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
11337 /* Define the "frame base" location for this routine. We use the
11338 frame pointer or stack pointer registers, since the RTL for local
11339 variables is relative to one of them. */
11340 if (frame_base_decl
&& lookup_decl_loc (frame_base_decl
) != NULL
)
11342 add_location_or_const_value_attribute (subr_die
, frame_base_decl
,
11348 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
11349 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
11352 if (cfun
->static_chain_decl
)
11353 add_AT_location_description (subr_die
, DW_AT_static_link
,
11354 loc_descriptor_from_tree (cfun
->static_chain_decl
, 0));
11357 /* Now output descriptions of the arguments for this function. This gets
11358 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11359 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11360 `...' at the end of the formal parameter list. In order to find out if
11361 there was a trailing ellipsis or not, we must instead look at the type
11362 associated with the FUNCTION_DECL. This will be a node of type
11363 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11364 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11365 an ellipsis at the end. */
11367 /* In the case where we are describing a mere function declaration, all we
11368 need to do here (and all we *can* do here) is to describe the *types* of
11369 its formal parameters. */
11370 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11372 else if (declaration
)
11373 gen_formal_types_die (decl
, subr_die
);
11376 /* Generate DIEs to represent all known formal parameters. */
11377 tree arg_decls
= DECL_ARGUMENTS (decl
);
11380 /* When generating DIEs, generate the unspecified_parameters DIE
11381 instead if we come across the arg "__builtin_va_alist" */
11382 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
11383 if (TREE_CODE (parm
) == PARM_DECL
)
11385 if (DECL_NAME (parm
)
11386 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
11387 "__builtin_va_alist"))
11388 gen_unspecified_parameters_die (parm
, subr_die
);
11390 gen_decl_die (parm
, subr_die
);
11393 /* Decide whether we need an unspecified_parameters DIE at the end.
11394 There are 2 more cases to do this for: 1) the ansi ... declaration -
11395 this is detectable when the end of the arg list is not a
11396 void_type_node 2) an unprototyped function declaration (not a
11397 definition). This just means that we have no info about the
11398 parameters at all. */
11399 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
11400 if (fn_arg_types
!= NULL
)
11402 /* This is the prototyped case, check for.... */
11403 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
11404 gen_unspecified_parameters_die (decl
, subr_die
);
11406 else if (DECL_INITIAL (decl
) == NULL_TREE
)
11407 gen_unspecified_parameters_die (decl
, subr_die
);
11410 /* Output Dwarf info for all of the stuff within the body of the function
11411 (if it has one - it may be just a declaration). */
11412 outer_scope
= DECL_INITIAL (decl
);
11414 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11415 a function. This BLOCK actually represents the outermost binding contour
11416 for the function, i.e. the contour in which the function's formal
11417 parameters and labels get declared. Curiously, it appears that the front
11418 end doesn't actually put the PARM_DECL nodes for the current function onto
11419 the BLOCK_VARS list for this outer scope, but are strung off of the
11420 DECL_ARGUMENTS list for the function instead.
11422 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11423 the LABEL_DECL nodes for the function however, and we output DWARF info
11424 for those in decls_for_scope. Just within the `outer_scope' there will be
11425 a BLOCK node representing the function's outermost pair of curly braces,
11426 and any blocks used for the base and member initializers of a C++
11427 constructor function. */
11428 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
11430 /* Emit a DW_TAG_variable DIE for a named return value. */
11431 if (DECL_NAME (DECL_RESULT (decl
)))
11432 gen_decl_die (DECL_RESULT (decl
), subr_die
);
11434 current_function_has_inlines
= 0;
11435 decls_for_scope (outer_scope
, subr_die
, 0);
11437 #if 0 && defined (MIPS_DEBUGGING_INFO)
11438 if (current_function_has_inlines
)
11440 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
11441 if (! comp_unit_has_inlines
)
11443 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
11444 comp_unit_has_inlines
= 1;
11451 /* Generate a DIE to represent a declared data object. */
11454 gen_variable_die (tree decl
, dw_die_ref context_die
)
11456 tree origin
= decl_ultimate_origin (decl
);
11457 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
11459 dw_die_ref old_die
= lookup_decl_die (decl
);
11460 int declaration
= (DECL_EXTERNAL (decl
)
11461 || class_or_namespace_scope_p (context_die
));
11463 if (origin
!= NULL
)
11464 add_abstract_origin_attribute (var_die
, origin
);
11466 /* Loop unrolling can create multiple blocks that refer to the same
11467 static variable, so we must test for the DW_AT_declaration flag.
11469 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11470 copy decls and set the DECL_ABSTRACT flag on them instead of
11473 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
11474 else if (old_die
&& TREE_STATIC (decl
)
11475 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
11477 /* This is a definition of a C++ class level static. */
11478 add_AT_specification (var_die
, old_die
);
11479 if (DECL_NAME (decl
))
11481 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11482 unsigned file_index
= lookup_filename (s
.file
);
11484 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11485 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
11487 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11488 != (unsigned) s
.line
)
11490 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
11495 add_name_and_src_coords_attributes (var_die
, decl
);
11496 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
11497 TREE_THIS_VOLATILE (decl
), context_die
);
11499 if (TREE_PUBLIC (decl
))
11500 add_AT_flag (var_die
, DW_AT_external
, 1);
11502 if (DECL_ARTIFICIAL (decl
))
11503 add_AT_flag (var_die
, DW_AT_artificial
, 1);
11505 if (TREE_PROTECTED (decl
))
11506 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11507 else if (TREE_PRIVATE (decl
))
11508 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11512 add_AT_flag (var_die
, DW_AT_declaration
, 1);
11514 if (DECL_ABSTRACT (decl
) || declaration
)
11515 equate_decl_number_to_die (decl
, var_die
);
11517 if (! declaration
&& ! DECL_ABSTRACT (decl
))
11519 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
11520 add_pubname (decl
, var_die
);
11523 tree_add_const_value_attribute (var_die
, decl
);
11526 /* Generate a DIE to represent a label identifier. */
11529 gen_label_die (tree decl
, dw_die_ref context_die
)
11531 tree origin
= decl_ultimate_origin (decl
);
11532 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
11534 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11536 if (origin
!= NULL
)
11537 add_abstract_origin_attribute (lbl_die
, origin
);
11539 add_name_and_src_coords_attributes (lbl_die
, decl
);
11541 if (DECL_ABSTRACT (decl
))
11542 equate_decl_number_to_die (decl
, lbl_die
);
11545 insn
= DECL_RTL_IF_SET (decl
);
11547 /* Deleted labels are programmer specified labels which have been
11548 eliminated because of various optimizations. We still emit them
11549 here so that it is possible to put breakpoints on them. */
11551 && (GET_CODE (insn
) == CODE_LABEL
11552 || ((GET_CODE (insn
) == NOTE
11553 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
))))
11555 /* When optimization is enabled (via -O) some parts of the compiler
11556 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11557 represent source-level labels which were explicitly declared by
11558 the user. This really shouldn't be happening though, so catch
11559 it if it ever does happen. */
11560 if (INSN_DELETED_P (insn
))
11563 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
11564 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
11569 /* Generate a DIE for a lexical block. */
11572 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
11574 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
11575 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11577 if (! BLOCK_ABSTRACT (stmt
))
11579 if (BLOCK_FRAGMENT_CHAIN (stmt
))
11583 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
11585 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
11588 add_ranges (chain
);
11589 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
11596 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11597 BLOCK_NUMBER (stmt
));
11598 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
11599 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11600 BLOCK_NUMBER (stmt
));
11601 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
11605 decls_for_scope (stmt
, stmt_die
, depth
);
11608 /* Generate a DIE for an inlined subprogram. */
11611 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
11613 tree decl
= block_ultimate_origin (stmt
);
11615 /* Emit info for the abstract instance first, if we haven't yet. We
11616 must emit this even if the block is abstract, otherwise when we
11617 emit the block below (or elsewhere), we may end up trying to emit
11618 a die whose origin die hasn't been emitted, and crashing. */
11619 dwarf2out_abstract_function (decl
);
11621 if (! BLOCK_ABSTRACT (stmt
))
11623 dw_die_ref subr_die
11624 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
11625 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11627 add_abstract_origin_attribute (subr_die
, decl
);
11628 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11629 BLOCK_NUMBER (stmt
));
11630 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
11631 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11632 BLOCK_NUMBER (stmt
));
11633 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
11634 decls_for_scope (stmt
, subr_die
, depth
);
11635 current_function_has_inlines
= 1;
11638 /* We may get here if we're the outer block of function A that was
11639 inlined into function B that was inlined into function C. When
11640 generating debugging info for C, dwarf2out_abstract_function(B)
11641 would mark all inlined blocks as abstract, including this one.
11642 So, we wouldn't (and shouldn't) expect labels to be generated
11643 for this one. Instead, just emit debugging info for
11644 declarations within the block. This is particularly important
11645 in the case of initializers of arguments passed from B to us:
11646 if they're statement expressions containing declarations, we
11647 wouldn't generate dies for their abstract variables, and then,
11648 when generating dies for the real variables, we'd die (pun
11650 gen_lexical_block_die (stmt
, context_die
, depth
);
11653 /* Generate a DIE for a field in a record, or structure. */
11656 gen_field_die (tree decl
, dw_die_ref context_die
)
11658 dw_die_ref decl_die
;
11660 if (TREE_TYPE (decl
) == error_mark_node
)
11663 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
11664 add_name_and_src_coords_attributes (decl_die
, decl
);
11665 add_type_attribute (decl_die
, member_declared_type (decl
),
11666 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
11669 if (DECL_BIT_FIELD_TYPE (decl
))
11671 add_byte_size_attribute (decl_die
, decl
);
11672 add_bit_size_attribute (decl_die
, decl
);
11673 add_bit_offset_attribute (decl_die
, decl
);
11676 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
11677 add_data_member_location_attribute (decl_die
, decl
);
11679 if (DECL_ARTIFICIAL (decl
))
11680 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11682 if (TREE_PROTECTED (decl
))
11683 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11684 else if (TREE_PRIVATE (decl
))
11685 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11689 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11690 Use modified_type_die instead.
11691 We keep this code here just in case these types of DIEs may be needed to
11692 represent certain things in other languages (e.g. Pascal) someday. */
11695 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
11698 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
11700 equate_type_number_to_die (type
, ptr_die
);
11701 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11702 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11705 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11706 Use modified_type_die instead.
11707 We keep this code here just in case these types of DIEs may be needed to
11708 represent certain things in other languages (e.g. Pascal) someday. */
11711 gen_reference_type_die (tree type
, dw_die_ref context_die
)
11714 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
11716 equate_type_number_to_die (type
, ref_die
);
11717 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
11718 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11722 /* Generate a DIE for a pointer to a member type. */
11725 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
11728 = new_die (DW_TAG_ptr_to_member_type
,
11729 scope_die_for (type
, context_die
), type
);
11731 equate_type_number_to_die (type
, ptr_die
);
11732 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
11733 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
11734 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11737 /* Generate the DIE for the compilation unit. */
11740 gen_compile_unit_die (const char *filename
)
11743 char producer
[250];
11744 const char *language_string
= lang_hooks
.name
;
11747 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
11751 add_name_attribute (die
, filename
);
11752 /* Don't add cwd for <built-in>. */
11753 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
11754 add_comp_dir_attribute (die
);
11757 sprintf (producer
, "%s %s", language_string
, version_string
);
11759 #ifdef MIPS_DEBUGGING_INFO
11760 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11761 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11762 not appear in the producer string, the debugger reaches the conclusion
11763 that the object file is stripped and has no debugging information.
11764 To get the MIPS/SGI debugger to believe that there is debugging
11765 information in the object file, we add a -g to the producer string. */
11766 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11767 strcat (producer
, " -g");
11770 add_AT_string (die
, DW_AT_producer
, producer
);
11772 if (strcmp (language_string
, "GNU C++") == 0)
11773 language
= DW_LANG_C_plus_plus
;
11774 else if (strcmp (language_string
, "GNU Ada") == 0)
11775 language
= DW_LANG_Ada95
;
11776 else if (strcmp (language_string
, "GNU F77") == 0)
11777 language
= DW_LANG_Fortran77
;
11778 else if (strcmp (language_string
, "GNU F95") == 0)
11779 language
= DW_LANG_Fortran95
;
11780 else if (strcmp (language_string
, "GNU Pascal") == 0)
11781 language
= DW_LANG_Pascal83
;
11782 else if (strcmp (language_string
, "GNU Java") == 0)
11783 language
= DW_LANG_Java
;
11785 language
= DW_LANG_C89
;
11787 add_AT_unsigned (die
, DW_AT_language
, language
);
11791 /* Generate a DIE for a string type. */
11794 gen_string_type_die (tree type
, dw_die_ref context_die
)
11796 dw_die_ref type_die
11797 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
11799 equate_type_number_to_die (type
, type_die
);
11801 /* ??? Fudge the string length attribute for now.
11802 TODO: add string length info. */
11804 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
11805 bound_representation (upper_bound
, 0, 'u');
11809 /* Generate the DIE for a base class. */
11812 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
11814 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
11816 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
11817 add_data_member_location_attribute (die
, binfo
);
11819 if (TREE_VIA_VIRTUAL (binfo
))
11820 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11822 if (access
== access_public_node
)
11823 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
11824 else if (access
== access_protected_node
)
11825 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11828 /* Generate a DIE for a class member. */
11831 gen_member_die (tree type
, dw_die_ref context_die
)
11834 tree binfo
= TYPE_BINFO (type
);
11837 /* If this is not an incomplete type, output descriptions of each of its
11838 members. Note that as we output the DIEs necessary to represent the
11839 members of this record or union type, we will also be trying to output
11840 DIEs to represent the *types* of those members. However the `type'
11841 function (above) will specifically avoid generating type DIEs for member
11842 types *within* the list of member DIEs for this (containing) type except
11843 for those types (of members) which are explicitly marked as also being
11844 members of this (containing) type themselves. The g++ front- end can
11845 force any given type to be treated as a member of some other (containing)
11846 type by setting the TYPE_CONTEXT of the given (member) type to point to
11847 the TREE node representing the appropriate (containing) type. */
11849 /* First output info about the base classes. */
11850 if (binfo
&& BINFO_BASETYPES (binfo
))
11852 tree bases
= BINFO_BASETYPES (binfo
);
11853 tree accesses
= BINFO_BASEACCESSES (binfo
);
11854 int n_bases
= TREE_VEC_LENGTH (bases
);
11857 for (i
= 0; i
< n_bases
; i
++)
11858 gen_inheritance_die (TREE_VEC_ELT (bases
, i
),
11859 (accesses
? TREE_VEC_ELT (accesses
, i
)
11860 : access_public_node
), context_die
);
11863 /* Now output info about the data members and type members. */
11864 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
11866 /* If we thought we were generating minimal debug info for TYPE
11867 and then changed our minds, some of the member declarations
11868 may have already been defined. Don't define them again, but
11869 do put them in the right order. */
11871 child
= lookup_decl_die (member
);
11873 splice_child_die (context_die
, child
);
11875 gen_decl_die (member
, context_die
);
11878 /* Now output info about the function members (if any). */
11879 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
11881 /* Don't include clones in the member list. */
11882 if (DECL_ABSTRACT_ORIGIN (member
))
11885 child
= lookup_decl_die (member
);
11887 splice_child_die (context_die
, child
);
11889 gen_decl_die (member
, context_die
);
11893 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11894 is set, we pretend that the type was never defined, so we only get the
11895 member DIEs needed by later specification DIEs. */
11898 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
11900 dw_die_ref type_die
= lookup_type_die (type
);
11901 dw_die_ref scope_die
= 0;
11903 int complete
= (TYPE_SIZE (type
)
11904 && (! TYPE_STUB_DECL (type
)
11905 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
11906 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
11908 if (type_die
&& ! complete
)
11911 if (TYPE_CONTEXT (type
) != NULL_TREE
11912 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11913 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
11916 scope_die
= scope_die_for (type
, context_die
);
11918 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
11919 /* First occurrence of type or toplevel definition of nested class. */
11921 dw_die_ref old_die
= type_die
;
11923 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
11924 ? DW_TAG_structure_type
: DW_TAG_union_type
,
11926 equate_type_number_to_die (type
, type_die
);
11928 add_AT_specification (type_die
, old_die
);
11930 add_name_attribute (type_die
, type_tag (type
));
11933 remove_AT (type_die
, DW_AT_declaration
);
11935 /* If this type has been completed, then give it a byte_size attribute and
11936 then give a list of members. */
11937 if (complete
&& !ns_decl
)
11939 /* Prevent infinite recursion in cases where the type of some member of
11940 this type is expressed in terms of this type itself. */
11941 TREE_ASM_WRITTEN (type
) = 1;
11942 add_byte_size_attribute (type_die
, type
);
11943 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11944 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11946 /* If the first reference to this type was as the return type of an
11947 inline function, then it may not have a parent. Fix this now. */
11948 if (type_die
->die_parent
== NULL
)
11949 add_child_die (scope_die
, type_die
);
11951 push_decl_scope (type
);
11952 gen_member_die (type
, type_die
);
11955 /* GNU extension: Record what type our vtable lives in. */
11956 if (TYPE_VFIELD (type
))
11958 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
11960 gen_type_die (vtype
, context_die
);
11961 add_AT_die_ref (type_die
, DW_AT_containing_type
,
11962 lookup_type_die (vtype
));
11967 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11969 /* We don't need to do this for function-local types. */
11970 if (TYPE_STUB_DECL (type
)
11971 && ! decl_function_context (TYPE_STUB_DECL (type
)))
11972 VARRAY_PUSH_TREE (incomplete_types
, type
);
11976 /* Generate a DIE for a subroutine _type_. */
11979 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
11981 tree return_type
= TREE_TYPE (type
);
11982 dw_die_ref subr_die
11983 = new_die (DW_TAG_subroutine_type
,
11984 scope_die_for (type
, context_die
), type
);
11986 equate_type_number_to_die (type
, subr_die
);
11987 add_prototyped_attribute (subr_die
, type
);
11988 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
11989 gen_formal_types_die (type
, subr_die
);
11992 /* Generate a DIE for a type definition. */
11995 gen_typedef_die (tree decl
, dw_die_ref context_die
)
11997 dw_die_ref type_die
;
12000 if (TREE_ASM_WRITTEN (decl
))
12003 TREE_ASM_WRITTEN (decl
) = 1;
12004 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
12005 origin
= decl_ultimate_origin (decl
);
12006 if (origin
!= NULL
)
12007 add_abstract_origin_attribute (type_die
, origin
);
12012 add_name_and_src_coords_attributes (type_die
, decl
);
12013 if (DECL_ORIGINAL_TYPE (decl
))
12015 type
= DECL_ORIGINAL_TYPE (decl
);
12017 if (type
== TREE_TYPE (decl
))
12020 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
12023 type
= TREE_TYPE (decl
);
12025 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
12026 TREE_THIS_VOLATILE (decl
), context_die
);
12029 if (DECL_ABSTRACT (decl
))
12030 equate_decl_number_to_die (decl
, type_die
);
12033 /* Generate a type description DIE. */
12036 gen_type_die (tree type
, dw_die_ref context_die
)
12040 if (type
== NULL_TREE
|| type
== error_mark_node
)
12043 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12044 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
12046 if (TREE_ASM_WRITTEN (type
))
12049 /* Prevent broken recursion; we can't hand off to the same type. */
12050 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
12053 TREE_ASM_WRITTEN (type
) = 1;
12054 gen_decl_die (TYPE_NAME (type
), context_die
);
12058 /* We are going to output a DIE to represent the unqualified version
12059 of this type (i.e. without any const or volatile qualifiers) so
12060 get the main variant (i.e. the unqualified version) of this type
12061 now. (Vectors are special because the debugging info is in the
12062 cloned type itself). */
12063 if (TREE_CODE (type
) != VECTOR_TYPE
)
12064 type
= type_main_variant (type
);
12066 if (TREE_ASM_WRITTEN (type
))
12069 switch (TREE_CODE (type
))
12075 case REFERENCE_TYPE
:
12076 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12077 ensures that the gen_type_die recursion will terminate even if the
12078 type is recursive. Recursive types are possible in Ada. */
12079 /* ??? We could perhaps do this for all types before the switch
12081 TREE_ASM_WRITTEN (type
) = 1;
12083 /* For these types, all that is required is that we output a DIE (or a
12084 set of DIEs) to represent the "basis" type. */
12085 gen_type_die (TREE_TYPE (type
), context_die
);
12089 /* This code is used for C++ pointer-to-data-member types.
12090 Output a description of the relevant class type. */
12091 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
12093 /* Output a description of the type of the object pointed to. */
12094 gen_type_die (TREE_TYPE (type
), context_die
);
12096 /* Now output a DIE to represent this pointer-to-data-member type
12098 gen_ptr_to_mbr_type_die (type
, context_die
);
12102 gen_type_die (TYPE_DOMAIN (type
), context_die
);
12103 gen_set_type_die (type
, context_die
);
12107 gen_type_die (TREE_TYPE (type
), context_die
);
12108 abort (); /* No way to represent these in Dwarf yet! */
12111 case FUNCTION_TYPE
:
12112 /* Force out return type (in case it wasn't forced out already). */
12113 gen_type_die (TREE_TYPE (type
), context_die
);
12114 gen_subroutine_type_die (type
, context_die
);
12118 /* Force out return type (in case it wasn't forced out already). */
12119 gen_type_die (TREE_TYPE (type
), context_die
);
12120 gen_subroutine_type_die (type
, context_die
);
12124 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
12126 gen_type_die (TREE_TYPE (type
), context_die
);
12127 gen_string_type_die (type
, context_die
);
12130 gen_array_type_die (type
, context_die
);
12134 gen_array_type_die (type
, context_die
);
12137 case ENUMERAL_TYPE
:
12140 case QUAL_UNION_TYPE
:
12141 /* If this is a nested type whose containing class hasn't been written
12142 out yet, writing it out will cover this one, too. This does not apply
12143 to instantiations of member class templates; they need to be added to
12144 the containing class as they are generated. FIXME: This hurts the
12145 idea of combining type decls from multiple TUs, since we can't predict
12146 what set of template instantiations we'll get. */
12147 if (TYPE_CONTEXT (type
)
12148 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12149 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
12151 gen_type_die (TYPE_CONTEXT (type
), context_die
);
12153 if (TREE_ASM_WRITTEN (type
))
12156 /* If that failed, attach ourselves to the stub. */
12157 push_decl_scope (TYPE_CONTEXT (type
));
12158 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
12163 declare_in_namespace (type
, context_die
);
12167 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12168 gen_enumeration_type_die (type
, context_die
);
12170 gen_struct_or_union_type_die (type
, context_die
);
12175 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12176 it up if it is ever completed. gen_*_type_die will set it for us
12177 when appropriate. */
12186 /* No DIEs needed for fundamental types. */
12190 /* No Dwarf representation currently defined. */
12197 TREE_ASM_WRITTEN (type
) = 1;
12200 /* Generate a DIE for a tagged type instantiation. */
12203 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
12205 if (type
== NULL_TREE
|| type
== error_mark_node
)
12208 /* We are going to output a DIE to represent the unqualified version of
12209 this type (i.e. without any const or volatile qualifiers) so make sure
12210 that we have the main variant (i.e. the unqualified version) of this
12212 if (type
!= type_main_variant (type
))
12215 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12216 an instance of an unresolved type. */
12218 switch (TREE_CODE (type
))
12223 case ENUMERAL_TYPE
:
12224 gen_inlined_enumeration_type_die (type
, context_die
);
12228 gen_inlined_structure_type_die (type
, context_die
);
12232 case QUAL_UNION_TYPE
:
12233 gen_inlined_union_type_die (type
, context_die
);
12241 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12242 things which are local to the given block. */
12245 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12247 int must_output_die
= 0;
12250 enum tree_code origin_code
;
12252 /* Ignore blocks never really used to make RTL. */
12253 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
12254 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
12257 /* If the block is one fragment of a non-contiguous block, do not
12258 process the variables, since they will have been done by the
12259 origin block. Do process subblocks. */
12260 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
12264 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
12265 gen_block_die (sub
, context_die
, depth
+ 1);
12270 /* Determine the "ultimate origin" of this block. This block may be an
12271 inlined instance of an inlined instance of inline function, so we have
12272 to trace all of the way back through the origin chain to find out what
12273 sort of node actually served as the original seed for the creation of
12274 the current block. */
12275 origin
= block_ultimate_origin (stmt
);
12276 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
12278 /* Determine if we need to output any Dwarf DIEs at all to represent this
12280 if (origin_code
== FUNCTION_DECL
)
12281 /* The outer scopes for inlinings *must* always be represented. We
12282 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12283 must_output_die
= 1;
12286 /* In the case where the current block represents an inlining of the
12287 "body block" of an inline function, we must *NOT* output any DIE for
12288 this block because we have already output a DIE to represent the whole
12289 inlined function scope and the "body block" of any function doesn't
12290 really represent a different scope according to ANSI C rules. So we
12291 check here to make sure that this block does not represent a "body
12292 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12293 if (! is_body_block (origin
? origin
: stmt
))
12295 /* Determine if this block directly contains any "significant"
12296 local declarations which we will need to output DIEs for. */
12297 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12298 /* We are not in terse mode so *any* local declaration counts
12299 as being a "significant" one. */
12300 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
12302 /* We are in terse mode, so only local (nested) function
12303 definitions count as "significant" local declarations. */
12304 for (decl
= BLOCK_VARS (stmt
);
12305 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12306 if (TREE_CODE (decl
) == FUNCTION_DECL
12307 && DECL_INITIAL (decl
))
12309 must_output_die
= 1;
12315 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12316 DIE for any block which contains no significant local declarations at
12317 all. Rather, in such cases we just call `decls_for_scope' so that any
12318 needed Dwarf info for any sub-blocks will get properly generated. Note
12319 that in terse mode, our definition of what constitutes a "significant"
12320 local declaration gets restricted to include only inlined function
12321 instances and local (nested) function definitions. */
12322 if (must_output_die
)
12324 if (origin_code
== FUNCTION_DECL
)
12325 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
12327 gen_lexical_block_die (stmt
, context_die
, depth
);
12330 decls_for_scope (stmt
, context_die
, depth
);
12333 /* Generate all of the decls declared within a given scope and (recursively)
12334 all of its sub-blocks. */
12337 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
12342 /* Ignore blocks never really used to make RTL. */
12343 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
12346 /* Output the DIEs to represent all of the data objects and typedefs
12347 declared directly within this block but not within any nested
12348 sub-blocks. Also, nested function and tag DIEs have been
12349 generated with a parent of NULL; fix that up now. */
12350 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12354 if (TREE_CODE (decl
) == FUNCTION_DECL
)
12355 die
= lookup_decl_die (decl
);
12356 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
12357 die
= lookup_type_die (TREE_TYPE (decl
));
12361 if (die
!= NULL
&& die
->die_parent
== NULL
)
12362 add_child_die (context_die
, die
);
12364 gen_decl_die (decl
, context_die
);
12367 /* If we're at -g1, we're not interested in subblocks. */
12368 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12371 /* Output the DIEs to represent all sub-blocks (and the items declared
12372 therein) of this block. */
12373 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
12375 subblocks
= BLOCK_CHAIN (subblocks
))
12376 gen_block_die (subblocks
, context_die
, depth
+ 1);
12379 /* Is this a typedef we can avoid emitting? */
12382 is_redundant_typedef (tree decl
)
12384 if (TYPE_DECL_IS_STUB (decl
))
12387 if (DECL_ARTIFICIAL (decl
)
12388 && DECL_CONTEXT (decl
)
12389 && is_tagged_type (DECL_CONTEXT (decl
))
12390 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
12391 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
12392 /* Also ignore the artificial member typedef for the class name. */
12398 /* Returns the DIE for decl or aborts. */
12401 force_decl_die (tree decl
)
12403 dw_die_ref decl_die
;
12404 unsigned saved_external_flag
;
12405 tree save_fn
= NULL_TREE
;
12406 decl_die
= lookup_decl_die (decl
);
12409 dw_die_ref context_die
;
12410 tree decl_context
= DECL_CONTEXT (decl
);
12413 /* Find die that represents this context. */
12414 if (TYPE_P (decl_context
))
12415 context_die
= force_type_die (decl_context
);
12417 context_die
= force_decl_die (decl_context
);
12420 context_die
= comp_unit_die
;
12422 switch (TREE_CODE (decl
))
12424 case FUNCTION_DECL
:
12425 /* Clear current_function_decl, so that gen_subprogram_die thinks
12426 that this is a declaration. At this point, we just want to force
12427 declaration die. */
12428 save_fn
= current_function_decl
;
12429 current_function_decl
= NULL_TREE
;
12430 gen_subprogram_die (decl
, context_die
);
12431 current_function_decl
= save_fn
;
12435 /* Set external flag to force declaration die. Restore it after
12436 gen_decl_die() call. */
12437 saved_external_flag
= DECL_EXTERNAL (decl
);
12438 DECL_EXTERNAL (decl
) = 1;
12439 gen_decl_die (decl
, context_die
);
12440 DECL_EXTERNAL (decl
) = saved_external_flag
;
12443 case NAMESPACE_DECL
:
12444 dwarf2out_decl (decl
);
12451 /* See if we can find the die for this deci now.
12452 If not then abort. */
12454 decl_die
= lookup_decl_die (decl
);
12462 /* Returns the DIE for decl or aborts. */
12465 force_type_die (tree type
)
12467 dw_die_ref type_die
;
12469 type_die
= lookup_type_die (type
);
12472 dw_die_ref context_die
;
12473 if (TYPE_CONTEXT (type
))
12474 if (TYPE_P (TYPE_CONTEXT (type
)))
12475 context_die
= force_type_die (TYPE_CONTEXT (type
));
12477 context_die
= force_decl_die (TYPE_CONTEXT (type
));
12479 context_die
= comp_unit_die
;
12481 gen_type_die (type
, context_die
);
12482 type_die
= lookup_type_die (type
);
12489 /* Force out any required namespaces to be able to output DECL,
12490 and return the new context_die for it, if it's changed. */
12493 setup_namespace_context (tree thing
, dw_die_ref context_die
)
12495 tree context
= DECL_P (thing
) ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
);
12496 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
12497 /* Force out the namespace. */
12498 context_die
= force_decl_die (context
);
12500 return context_die
;
12503 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12504 type) within its namespace, if appropriate.
12506 For compatibility with older debuggers, namespace DIEs only contain
12507 declarations; all definitions are emitted at CU scope. */
12510 declare_in_namespace (tree thing
, dw_die_ref context_die
)
12512 dw_die_ref ns_context
;
12514 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12517 ns_context
= setup_namespace_context (thing
, context_die
);
12519 if (ns_context
!= context_die
)
12521 if (DECL_P (thing
))
12522 gen_decl_die (thing
, ns_context
);
12524 gen_type_die (thing
, ns_context
);
12528 /* Generate a DIE for a namespace or namespace alias. */
12531 gen_namespace_die (tree decl
)
12533 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
12535 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12536 they are an alias of. */
12537 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
12539 /* Output a real namespace. */
12540 dw_die_ref namespace_die
12541 = new_die (DW_TAG_namespace
, context_die
, decl
);
12542 add_name_and_src_coords_attributes (namespace_die
, decl
);
12543 equate_decl_number_to_die (decl
, namespace_die
);
12547 /* Output a namespace alias. */
12549 /* Force out the namespace we are an alias of, if necessary. */
12550 dw_die_ref origin_die
12551 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
12553 /* Now create the namespace alias DIE. */
12554 dw_die_ref namespace_die
12555 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
12556 add_name_and_src_coords_attributes (namespace_die
, decl
);
12557 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
12558 equate_decl_number_to_die (decl
, namespace_die
);
12562 /* Generate Dwarf debug information for a decl described by DECL. */
12565 gen_decl_die (tree decl
, dw_die_ref context_die
)
12569 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
12572 switch (TREE_CODE (decl
))
12578 /* The individual enumerators of an enum type get output when we output
12579 the Dwarf representation of the relevant enum type itself. */
12582 case FUNCTION_DECL
:
12583 /* Don't output any DIEs to represent mere function declarations,
12584 unless they are class members or explicit block externs. */
12585 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
12586 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
12591 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
12592 on local redeclarations of global functions. That seems broken. */
12593 if (current_function_decl
!= decl
)
12594 /* This is only a declaration. */;
12597 /* If we're emitting a clone, emit info for the abstract instance. */
12598 if (DECL_ORIGIN (decl
) != decl
)
12599 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
12601 /* If we're emitting an out-of-line copy of an inline function,
12602 emit info for the abstract instance and set up to refer to it. */
12603 else if (cgraph_function_possibly_inlined_p (decl
)
12604 && ! DECL_ABSTRACT (decl
)
12605 && ! class_or_namespace_scope_p (context_die
)
12606 /* dwarf2out_abstract_function won't emit a die if this is just
12607 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
12608 that case, because that works only if we have a die. */
12609 && DECL_INITIAL (decl
) != NULL_TREE
)
12611 dwarf2out_abstract_function (decl
);
12612 set_decl_origin_self (decl
);
12615 /* Otherwise we're emitting the primary DIE for this decl. */
12616 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
12618 /* Before we describe the FUNCTION_DECL itself, make sure that we
12619 have described its return type. */
12620 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
12622 /* And its virtual context. */
12623 if (DECL_VINDEX (decl
) != NULL_TREE
)
12624 gen_type_die (DECL_CONTEXT (decl
), context_die
);
12626 /* And its containing type. */
12627 origin
= decl_class_context (decl
);
12628 if (origin
!= NULL_TREE
)
12629 gen_type_die_for_member (origin
, decl
, context_die
);
12631 /* And its containing namespace. */
12632 declare_in_namespace (decl
, context_die
);
12635 /* Now output a DIE to represent the function itself. */
12636 gen_subprogram_die (decl
, context_die
);
12640 /* If we are in terse mode, don't generate any DIEs to represent any
12641 actual typedefs. */
12642 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12645 /* In the special case of a TYPE_DECL node representing the declaration
12646 of some type tag, if the given TYPE_DECL is marked as having been
12647 instantiated from some other (original) TYPE_DECL node (e.g. one which
12648 was generated within the original definition of an inline function) we
12649 have to generate a special (abbreviated) DW_TAG_structure_type,
12650 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
12651 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
12653 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
12657 if (is_redundant_typedef (decl
))
12658 gen_type_die (TREE_TYPE (decl
), context_die
);
12660 /* Output a DIE to represent the typedef itself. */
12661 gen_typedef_die (decl
, context_die
);
12665 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12666 gen_label_die (decl
, context_die
);
12671 /* If we are in terse mode, don't generate any DIEs to represent any
12672 variable declarations or definitions. */
12673 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12676 /* Output any DIEs that are needed to specify the type of this data
12678 gen_type_die (TREE_TYPE (decl
), context_die
);
12680 /* And its containing type. */
12681 origin
= decl_class_context (decl
);
12682 if (origin
!= NULL_TREE
)
12683 gen_type_die_for_member (origin
, decl
, context_die
);
12685 /* And its containing namespace. */
12686 declare_in_namespace (decl
, context_die
);
12688 /* Now output the DIE to represent the data object itself. This gets
12689 complicated because of the possibility that the VAR_DECL really
12690 represents an inlined instance of a formal parameter for an inline
12692 origin
= decl_ultimate_origin (decl
);
12693 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
12694 gen_formal_parameter_die (decl
, context_die
);
12696 gen_variable_die (decl
, context_die
);
12700 /* Ignore the nameless fields that are used to skip bits but handle C++
12701 anonymous unions and structs. */
12702 if (DECL_NAME (decl
) != NULL_TREE
12703 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
12704 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
12706 gen_type_die (member_declared_type (decl
), context_die
);
12707 gen_field_die (decl
, context_die
);
12712 gen_type_die (TREE_TYPE (decl
), context_die
);
12713 gen_formal_parameter_die (decl
, context_die
);
12716 case NAMESPACE_DECL
:
12717 gen_namespace_die (decl
);
12721 if ((int)TREE_CODE (decl
) > NUM_TREE_CODES
)
12722 /* Probably some frontend-internal decl. Assume we don't care. */
12728 /* Add Ada "use" clause information for SGI Workshop debugger. */
12731 dwarf2out_add_library_unit_info (const char *filename
, const char *context_list
)
12733 unsigned int file_index
;
12735 if (filename
!= NULL
)
12737 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
12738 tree context_list_decl
12739 = build_decl (LABEL_DECL
, get_identifier (context_list
),
12742 TREE_PUBLIC (context_list_decl
) = TRUE
;
12743 add_name_attribute (unit_die
, context_list
);
12744 file_index
= lookup_filename (filename
);
12745 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
12746 add_pubname (context_list_decl
, unit_die
);
12750 /* Output debug information for global decl DECL. Called from toplev.c after
12751 compilation proper has finished. */
12754 dwarf2out_global_decl (tree decl
)
12756 /* Output DWARF2 information for file-scope tentative data object
12757 declarations, file-scope (extern) function declarations (which had no
12758 corresponding body) and file-scope tagged type declarations and
12759 definitions which have not yet been forced out. */
12760 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
12761 dwarf2out_decl (decl
);
12764 /* Output debug information for type decl DECL. Called from toplev.c
12765 and from language front ends (to record built-in types). */
12767 dwarf2out_type_decl (tree decl
, int local
)
12770 dwarf2out_decl (decl
);
12773 /* Output debug information for imported module or decl. */
12776 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
12778 dw_die_ref imported_die
, at_import_die
;
12779 dw_die_ref scope_die
;
12780 unsigned file_index
;
12781 expanded_location xloc
;
12783 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12789 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
12790 We need decl DIE for reference and scope die. First, get DIE for the decl
12793 /* Get the scope die for decl context. Use comp_unit_die for global module
12794 or decl. If die is not found for non globals, force new die. */
12796 scope_die
= comp_unit_die
;
12797 else if (TYPE_P (context
))
12798 scope_die
= force_type_die (context
);
12800 scope_die
= force_decl_die (context
);
12802 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
12803 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
12804 at_import_die
= force_type_die (TREE_TYPE (decl
));
12806 at_import_die
= force_decl_die (decl
);
12808 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
12809 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
12810 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
12812 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
12814 xloc
= expand_location (input_location
);
12815 file_index
= lookup_filename (xloc
.file
);
12816 add_AT_unsigned (imported_die
, DW_AT_decl_file
, file_index
);
12817 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
12818 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
12821 /* Write the debugging output for DECL. */
12824 dwarf2out_decl (tree decl
)
12826 dw_die_ref context_die
= comp_unit_die
;
12828 switch (TREE_CODE (decl
))
12833 case FUNCTION_DECL
:
12834 /* What we would really like to do here is to filter out all mere
12835 file-scope declarations of file-scope functions which are never
12836 referenced later within this translation unit (and keep all of ones
12837 that *are* referenced later on) but we aren't clairvoyant, so we have
12838 no idea which functions will be referenced in the future (i.e. later
12839 on within the current translation unit). So here we just ignore all
12840 file-scope function declarations which are not also definitions. If
12841 and when the debugger needs to know something about these functions,
12842 it will have to hunt around and find the DWARF information associated
12843 with the definition of the function.
12845 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
12846 nodes represent definitions and which ones represent mere
12847 declarations. We have to check DECL_INITIAL instead. That's because
12848 the C front-end supports some weird semantics for "extern inline"
12849 function definitions. These can get inlined within the current
12850 translation unit (an thus, we need to generate Dwarf info for their
12851 abstract instances so that the Dwarf info for the concrete inlined
12852 instances can have something to refer to) but the compiler never
12853 generates any out-of-lines instances of such things (despite the fact
12854 that they *are* definitions).
12856 The important point is that the C front-end marks these "extern
12857 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
12858 them anyway. Note that the C++ front-end also plays some similar games
12859 for inline function definitions appearing within include files which
12860 also contain `#pragma interface' pragmas. */
12861 if (DECL_INITIAL (decl
) == NULL_TREE
)
12864 /* If we're a nested function, initially use a parent of NULL; if we're
12865 a plain function, this will be fixed up in decls_for_scope. If
12866 we're a method, it will be ignored, since we already have a DIE. */
12867 if (decl_function_context (decl
)
12868 /* But if we're in terse mode, we don't care about scope. */
12869 && debug_info_level
> DINFO_LEVEL_TERSE
)
12870 context_die
= NULL
;
12874 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12875 declaration and if the declaration was never even referenced from
12876 within this entire compilation unit. We suppress these DIEs in
12877 order to save space in the .debug section (by eliminating entries
12878 which are probably useless). Note that we must not suppress
12879 block-local extern declarations (whether used or not) because that
12880 would screw-up the debugger's name lookup mechanism and cause it to
12881 miss things which really ought to be in scope at a given point. */
12882 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
12885 /* If we are in terse mode, don't generate any DIEs to represent any
12886 variable declarations or definitions. */
12887 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12891 case NAMESPACE_DECL
:
12892 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12894 if (lookup_decl_die (decl
) != NULL
)
12899 /* Don't emit stubs for types unless they are needed by other DIEs. */
12900 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
12903 /* Don't bother trying to generate any DIEs to represent any of the
12904 normal built-in types for the language we are compiling. */
12905 if (DECL_IS_BUILTIN (decl
))
12907 /* OK, we need to generate one for `bool' so GDB knows what type
12908 comparisons have. */
12909 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
12910 == DW_LANG_C_plus_plus
)
12911 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
12912 && ! DECL_IGNORED_P (decl
))
12913 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
12918 /* If we are in terse mode, don't generate any DIEs for types. */
12919 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12922 /* If we're a function-scope tag, initially use a parent of NULL;
12923 this will be fixed up in decls_for_scope. */
12924 if (decl_function_context (decl
))
12925 context_die
= NULL
;
12933 gen_decl_die (decl
, context_die
);
12936 /* Output a marker (i.e. a label) for the beginning of the generated code for
12937 a lexical block. */
12940 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
12941 unsigned int blocknum
)
12943 function_section (current_function_decl
);
12944 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
12947 /* Output a marker (i.e. a label) for the end of the generated code for a
12951 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
12953 function_section (current_function_decl
);
12954 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
12957 /* Returns nonzero if it is appropriate not to emit any debugging
12958 information for BLOCK, because it doesn't contain any instructions.
12960 Don't allow this for blocks with nested functions or local classes
12961 as we would end up with orphans, and in the presence of scheduling
12962 we may end up calling them anyway. */
12965 dwarf2out_ignore_block (tree block
)
12969 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
12970 if (TREE_CODE (decl
) == FUNCTION_DECL
12971 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
12977 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12978 dwarf2out.c) and return its "index". The index of each (known) filename is
12979 just a unique number which is associated with only that one filename. We
12980 need such numbers for the sake of generating labels (in the .debug_sfnames
12981 section) and references to those files numbers (in the .debug_srcinfo
12982 and.debug_macinfo sections). If the filename given as an argument is not
12983 found in our current list, add it to the list and assign it the next
12984 available unique index number. In order to speed up searches, we remember
12985 the index of the filename was looked up last. This handles the majority of
12989 lookup_filename (const char *file_name
)
12992 char *save_file_name
;
12994 /* Check to see if the file name that was searched on the previous
12995 call matches this file name. If so, return the index. */
12996 if (file_table_last_lookup_index
!= 0)
12999 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
13000 if (strcmp (file_name
, last
) == 0)
13001 return file_table_last_lookup_index
;
13004 /* Didn't match the previous lookup, search the table */
13005 n
= VARRAY_ACTIVE_SIZE (file_table
);
13006 for (i
= 1; i
< n
; i
++)
13007 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
13009 file_table_last_lookup_index
= i
;
13013 /* Add the new entry to the end of the filename table. */
13014 file_table_last_lookup_index
= n
;
13015 save_file_name
= (char *) ggc_strdup (file_name
);
13016 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
13017 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13023 maybe_emit_file (int fileno
)
13025 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
13027 if (!VARRAY_UINT (file_table_emitted
, fileno
))
13029 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
13030 fprintf (asm_out_file
, "\t.file %u ",
13031 VARRAY_UINT (file_table_emitted
, fileno
));
13032 output_quoted_string (asm_out_file
,
13033 VARRAY_CHAR_PTR (file_table
, fileno
));
13034 fputc ('\n', asm_out_file
);
13036 return VARRAY_UINT (file_table_emitted
, fileno
);
13043 init_file_table (void)
13045 /* Allocate the initial hunk of the file_table. */
13046 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
13047 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
13049 /* Skip the first entry - file numbers begin at 1. */
13050 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
13051 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13052 file_table_last_lookup_index
= 0;
13055 /* Called by the final INSN scan whenever we see a var location. We
13056 use it to drop labels in the right places, and throw the location in
13057 our lookup table. */
13060 dwarf2out_var_location (rtx loc_note
)
13062 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
13063 struct var_loc_node
*newloc
;
13065 static rtx last_insn
;
13066 static const char *last_label
;
13068 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
13070 prev_insn
= PREV_INSN (loc_note
);
13072 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
13073 /* If the insn we processed last time is the previous insn
13074 and it is also a var location note, use the label we emitted
13076 if (last_insn
!= NULL_RTX
13077 && last_insn
== prev_insn
13078 && GET_CODE (prev_insn
) == NOTE
13079 && NOTE_LINE_NUMBER (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
13081 newloc
->label
= last_label
;
13085 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
13086 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
13088 newloc
->label
= ggc_strdup (loclabel
);
13090 newloc
->var_loc_note
= loc_note
;
13091 newloc
->next
= NULL
;
13093 last_insn
= loc_note
;
13094 last_label
= newloc
->label
;
13096 add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note
), newloc
);
13099 /* We need to reset the locations at the beginning of each
13100 function. We can't do this in the end_function hook, because the
13101 declarations that use the locations won't have been outputted when
13102 that hook is called. */
13105 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED
)
13107 htab_empty (decl_loc_table
);
13110 /* Output a label to mark the beginning of a source code line entry
13111 and record information relating to this source line, in
13112 'line_info_table' for later output of the .debug_line section. */
13115 dwarf2out_source_line (unsigned int line
, const char *filename
)
13117 if (debug_info_level
>= DINFO_LEVEL_NORMAL
13120 function_section (current_function_decl
);
13122 /* If requested, emit something human-readable. */
13123 if (flag_debug_asm
)
13124 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
13127 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13129 unsigned file_num
= lookup_filename (filename
);
13131 file_num
= maybe_emit_file (file_num
);
13133 /* Emit the .loc directive understood by GNU as. */
13134 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
13136 /* Indicate that line number info exists. */
13137 line_info_table_in_use
++;
13139 /* Indicate that multiple line number tables exist. */
13140 if (DECL_SECTION_NAME (current_function_decl
))
13141 separate_line_info_table_in_use
++;
13143 else if (DECL_SECTION_NAME (current_function_decl
))
13145 dw_separate_line_info_ref line_info
;
13146 targetm
.asm_out
.internal_label (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
13147 separate_line_info_table_in_use
);
13149 /* Expand the line info table if necessary. */
13150 if (separate_line_info_table_in_use
13151 == separate_line_info_table_allocated
)
13153 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13154 separate_line_info_table
13155 = ggc_realloc (separate_line_info_table
,
13156 separate_line_info_table_allocated
13157 * sizeof (dw_separate_line_info_entry
));
13158 memset (separate_line_info_table
13159 + separate_line_info_table_in_use
,
13161 (LINE_INFO_TABLE_INCREMENT
13162 * sizeof (dw_separate_line_info_entry
)));
13165 /* Add the new entry at the end of the line_info_table. */
13167 = &separate_line_info_table
[separate_line_info_table_in_use
++];
13168 line_info
->dw_file_num
= lookup_filename (filename
);
13169 line_info
->dw_line_num
= line
;
13170 line_info
->function
= current_function_funcdef_no
;
13174 dw_line_info_ref line_info
;
13176 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
13177 line_info_table_in_use
);
13179 /* Expand the line info table if necessary. */
13180 if (line_info_table_in_use
== line_info_table_allocated
)
13182 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13184 = ggc_realloc (line_info_table
,
13185 (line_info_table_allocated
13186 * sizeof (dw_line_info_entry
)));
13187 memset (line_info_table
+ line_info_table_in_use
, 0,
13188 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
13191 /* Add the new entry at the end of the line_info_table. */
13192 line_info
= &line_info_table
[line_info_table_in_use
++];
13193 line_info
->dw_file_num
= lookup_filename (filename
);
13194 line_info
->dw_line_num
= line
;
13199 /* Record the beginning of a new source file. */
13202 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
13204 if (flag_eliminate_dwarf2_dups
)
13206 /* Record the beginning of the file for break_out_includes. */
13207 dw_die_ref bincl_die
;
13209 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
13210 add_AT_string (bincl_die
, DW_AT_name
, filename
);
13213 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13215 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13216 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
13217 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
13219 maybe_emit_file (lookup_filename (filename
));
13220 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
13221 "Filename we just started");
13225 /* Record the end of a source file. */
13228 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
13230 if (flag_eliminate_dwarf2_dups
)
13231 /* Record the end of the file for break_out_includes. */
13232 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
13234 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13236 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13237 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13241 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13242 the tail part of the directive line, i.e. the part which is past the
13243 initial whitespace, #, whitespace, directive-name, whitespace part. */
13246 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
13247 const char *buffer ATTRIBUTE_UNUSED
)
13249 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13251 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13252 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
13253 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13254 dw2_asm_output_nstring (buffer
, -1, "The macro");
13258 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13259 the tail part of the directive line, i.e. the part which is past the
13260 initial whitespace, #, whitespace, directive-name, whitespace part. */
13263 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
13264 const char *buffer ATTRIBUTE_UNUSED
)
13266 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13268 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13269 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
13270 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13271 dw2_asm_output_nstring (buffer
, -1, "The macro");
13275 /* Set up for Dwarf output at the start of compilation. */
13278 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
13280 init_file_table ();
13282 /* Allocate the decl_die_table. */
13283 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
13284 decl_die_table_eq
, NULL
);
13286 /* Allocate the decl_loc_table. */
13287 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
13288 decl_loc_table_eq
, NULL
);
13290 /* Allocate the initial hunk of the decl_scope_table. */
13291 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
13293 /* Allocate the initial hunk of the abbrev_die_table. */
13294 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13295 * sizeof (dw_die_ref
));
13296 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
13297 /* Zero-th entry is allocated, but unused */
13298 abbrev_die_table_in_use
= 1;
13300 /* Allocate the initial hunk of the line_info_table. */
13301 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13302 * sizeof (dw_line_info_entry
));
13303 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
13305 /* Zero-th entry is allocated, but unused */
13306 line_info_table_in_use
= 1;
13308 /* Generate the initial DIE for the .debug section. Note that the (string)
13309 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13310 will (typically) be a relative pathname and that this pathname should be
13311 taken as being relative to the directory from which the compiler was
13312 invoked when the given (base) source file was compiled. We will fill
13313 in this value in dwarf2out_finish. */
13314 comp_unit_die
= gen_compile_unit_die (NULL
);
13316 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
13318 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
13320 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
13321 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
13322 DEBUG_ABBREV_SECTION_LABEL
, 0);
13323 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
13324 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
13326 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
13328 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
13329 DEBUG_INFO_SECTION_LABEL
, 0);
13330 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
13331 DEBUG_LINE_SECTION_LABEL
, 0);
13332 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
13333 DEBUG_RANGES_SECTION_LABEL
, 0);
13334 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
13335 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
13336 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
13337 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
13338 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
13339 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
13341 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13343 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13344 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
13345 DEBUG_MACINFO_SECTION_LABEL
, 0);
13346 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
13349 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
13352 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
13356 /* A helper function for dwarf2out_finish called through
13357 ht_forall. Emit one queued .debug_str string. */
13360 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
13362 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
13364 if (node
->form
== DW_FORM_strp
)
13366 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
13367 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
13368 assemble_string (node
->str
, strlen (node
->str
) + 1);
13376 /* Clear the marks for a die and its children.
13377 Be cool if the mark isn't set. */
13380 prune_unmark_dies (dw_die_ref die
)
13384 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13385 prune_unmark_dies (c
);
13389 /* Given DIE that we're marking as used, find any other dies
13390 it references as attributes and mark them as used. */
13393 prune_unused_types_walk_attribs (dw_die_ref die
)
13397 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
13399 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
13401 /* A reference to another DIE.
13402 Make sure that it will get emitted. */
13403 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
13405 else if (a
->dw_attr
== DW_AT_decl_file
)
13407 /* A reference to a file. Make sure the file name is emitted. */
13408 a
->dw_attr_val
.v
.val_unsigned
=
13409 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
13415 /* Mark DIE as being used. If DOKIDS is true, then walk down
13416 to DIE's children. */
13419 prune_unused_types_mark (dw_die_ref die
, int dokids
)
13423 if (die
->die_mark
== 0)
13425 /* We haven't done this node yet. Mark it as used. */
13428 /* We also have to mark its parents as used.
13429 (But we don't want to mark our parents' kids due to this.) */
13430 if (die
->die_parent
)
13431 prune_unused_types_mark (die
->die_parent
, 0);
13433 /* Mark any referenced nodes. */
13434 prune_unused_types_walk_attribs (die
);
13436 /* If this node is a specification,
13437 also mark the definition, if it exists. */
13438 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
13439 prune_unused_types_mark (die
->die_definition
, 1);
13442 if (dokids
&& die
->die_mark
!= 2)
13444 /* We need to walk the children, but haven't done so yet.
13445 Remember that we've walked the kids. */
13449 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13451 /* If this is an array type, we need to make sure our
13452 kids get marked, even if they're types. */
13453 if (die
->die_tag
== DW_TAG_array_type
)
13454 prune_unused_types_mark (c
, 1);
13456 prune_unused_types_walk (c
);
13462 /* Walk the tree DIE and mark types that we actually use. */
13465 prune_unused_types_walk (dw_die_ref die
)
13469 /* Don't do anything if this node is already marked. */
13473 switch (die
->die_tag
) {
13474 case DW_TAG_const_type
:
13475 case DW_TAG_packed_type
:
13476 case DW_TAG_pointer_type
:
13477 case DW_TAG_reference_type
:
13478 case DW_TAG_volatile_type
:
13479 case DW_TAG_typedef
:
13480 case DW_TAG_array_type
:
13481 case DW_TAG_structure_type
:
13482 case DW_TAG_union_type
:
13483 case DW_TAG_class_type
:
13484 case DW_TAG_friend
:
13485 case DW_TAG_variant_part
:
13486 case DW_TAG_enumeration_type
:
13487 case DW_TAG_subroutine_type
:
13488 case DW_TAG_string_type
:
13489 case DW_TAG_set_type
:
13490 case DW_TAG_subrange_type
:
13491 case DW_TAG_ptr_to_member_type
:
13492 case DW_TAG_file_type
:
13493 /* It's a type node --- don't mark it. */
13497 /* Mark everything else. */
13503 /* Now, mark any dies referenced from here. */
13504 prune_unused_types_walk_attribs (die
);
13506 /* Mark children. */
13507 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13508 prune_unused_types_walk (c
);
13512 /* Remove from the tree DIE any dies that aren't marked. */
13515 prune_unused_types_prune (dw_die_ref die
)
13517 dw_die_ref c
, p
, n
;
13518 if (!die
->die_mark
)
13522 for (c
= die
->die_child
; c
; c
= n
)
13527 prune_unused_types_prune (c
);
13535 die
->die_child
= n
;
13542 /* Remove dies representing declarations that we never use. */
13545 prune_unused_types (void)
13548 limbo_die_node
*node
;
13550 /* Clear all the marks. */
13551 prune_unmark_dies (comp_unit_die
);
13552 for (node
= limbo_die_list
; node
; node
= node
->next
)
13553 prune_unmark_dies (node
->die
);
13555 /* Set the mark on nodes that are actually used. */
13556 prune_unused_types_walk (comp_unit_die
);
13557 for (node
= limbo_die_list
; node
; node
= node
->next
)
13558 prune_unused_types_walk (node
->die
);
13560 /* Also set the mark on nodes referenced from the
13561 pubname_table or arange_table. */
13562 for (i
= 0; i
< pubname_table_in_use
; i
++)
13563 prune_unused_types_mark (pubname_table
[i
].die
, 1);
13564 for (i
= 0; i
< arange_table_in_use
; i
++)
13565 prune_unused_types_mark (arange_table
[i
], 1);
13567 /* Get rid of nodes that aren't marked. */
13568 prune_unused_types_prune (comp_unit_die
);
13569 for (node
= limbo_die_list
; node
; node
= node
->next
)
13570 prune_unused_types_prune (node
->die
);
13572 /* Leave the marks clear. */
13573 prune_unmark_dies (comp_unit_die
);
13574 for (node
= limbo_die_list
; node
; node
= node
->next
)
13575 prune_unmark_dies (node
->die
);
13578 /* Output stuff that dwarf requires at the end of every file,
13579 and generate the DWARF-2 debugging info. */
13582 dwarf2out_finish (const char *filename
)
13584 limbo_die_node
*node
, *next_node
;
13585 dw_die_ref die
= 0;
13587 /* Add the name for the main input file now. We delayed this from
13588 dwarf2out_init to avoid complications with PCH. */
13589 add_name_attribute (comp_unit_die
, filename
);
13590 if (filename
[0] != DIR_SEPARATOR
)
13591 add_comp_dir_attribute (comp_unit_die
);
13592 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
13595 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
13596 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
13597 /* Don't add cwd for <built-in>. */
13598 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
13600 add_comp_dir_attribute (comp_unit_die
);
13605 /* Traverse the limbo die list, and add parent/child links. The only
13606 dies without parents that should be here are concrete instances of
13607 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
13608 For concrete instances, we can get the parent die from the abstract
13610 for (node
= limbo_die_list
; node
; node
= next_node
)
13612 next_node
= node
->next
;
13615 if (die
->die_parent
== NULL
)
13617 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
13621 add_child_die (origin
->die_parent
, die
);
13622 else if (die
== comp_unit_die
)
13624 /* If this was an expression for a bound involved in a function
13625 return type, it may be a SAVE_EXPR for which we weren't able
13626 to find a DIE previously. So try now. */
13627 else if (node
->created_for
13628 && TREE_CODE (node
->created_for
) == SAVE_EXPR
13629 && 0 != (origin
= (lookup_decl_die
13631 (node
->created_for
)))))
13632 add_child_die (origin
, die
);
13633 else if (errorcount
> 0 || sorrycount
> 0)
13634 /* It's OK to be confused by errors in the input. */
13635 add_child_die (comp_unit_die
, die
);
13636 else if (node
->created_for
13637 && ((DECL_P (node
->created_for
)
13638 && (context
= DECL_CONTEXT (node
->created_for
)))
13639 || (TYPE_P (node
->created_for
)
13640 && (context
= TYPE_CONTEXT (node
->created_for
))))
13641 && TREE_CODE (context
) == FUNCTION_DECL
)
13643 /* In certain situations, the lexical block containing a
13644 nested function can be optimized away, which results
13645 in the nested function die being orphaned. Likewise
13646 with the return type of that nested function. Force
13647 this to be a child of the containing function. */
13648 origin
= lookup_decl_die (context
);
13651 add_child_die (origin
, die
);
13658 limbo_die_list
= NULL
;
13660 /* Walk through the list of incomplete types again, trying once more to
13661 emit full debugging info for them. */
13662 retry_incomplete_types ();
13664 /* We need to reverse all the dies before break_out_includes, or
13665 we'll see the end of an include file before the beginning. */
13666 reverse_all_dies (comp_unit_die
);
13668 if (flag_eliminate_unused_debug_types
)
13669 prune_unused_types ();
13671 /* Generate separate CUs for each of the include files we've seen.
13672 They will go into limbo_die_list. */
13673 if (flag_eliminate_dwarf2_dups
)
13674 break_out_includes (comp_unit_die
);
13676 /* Traverse the DIE's and add add sibling attributes to those DIE's
13677 that have children. */
13678 add_sibling_attributes (comp_unit_die
);
13679 for (node
= limbo_die_list
; node
; node
= node
->next
)
13680 add_sibling_attributes (node
->die
);
13682 /* Output a terminator label for the .text section. */
13684 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
13686 /* Output the source line correspondence table. We must do this
13687 even if there is no line information. Otherwise, on an empty
13688 translation unit, we will generate a present, but empty,
13689 .debug_info section. IRIX 6.5 `nm' will then complain when
13690 examining the file. */
13691 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
13693 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
13694 output_line_info ();
13697 /* Output location list section if necessary. */
13698 if (have_location_lists
)
13700 /* Output the location lists info. */
13701 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
13702 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
13703 DEBUG_LOC_SECTION_LABEL
, 0);
13704 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
13705 output_location_lists (die
);
13706 have_location_lists
= 0;
13709 /* We can only use the low/high_pc attributes if all of the code was
13711 if (separate_line_info_table_in_use
== 0)
13713 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
13714 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
13717 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
13718 "base address". Use zero so that these addresses become absolute. */
13719 else if (have_location_lists
|| ranges_table_in_use
)
13720 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
13722 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13723 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
13724 debug_line_section_label
);
13726 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13727 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
13729 /* Output all of the compilation units. We put the main one last so that
13730 the offsets are available to output_pubnames. */
13731 for (node
= limbo_die_list
; node
; node
= node
->next
)
13732 output_comp_unit (node
->die
, 0);
13734 output_comp_unit (comp_unit_die
, 0);
13736 /* Output the abbreviation table. */
13737 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
13738 output_abbrev_section ();
13740 /* Output public names table if necessary. */
13741 if (pubname_table_in_use
)
13743 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
13744 output_pubnames ();
13747 /* Output the address range information. We only put functions in the arange
13748 table, so don't write it out if we don't have any. */
13749 if (fde_table_in_use
)
13751 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
13755 /* Output ranges section if necessary. */
13756 if (ranges_table_in_use
)
13758 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
13759 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
13763 /* Have to end the primary source file. */
13764 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13766 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13767 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13768 dw2_asm_output_data (1, 0, "End compilation unit");
13771 /* If we emitted any DW_FORM_strp form attribute, output the string
13773 if (debug_str_hash
)
13774 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
13778 /* This should never be used, but its address is needed for comparisons. */
13779 const struct gcc_debug_hooks dwarf2_debug_hooks
;
13781 #endif /* DWARF2_DEBUGGING_INFO */
13783 #include "gt-dwarf2out.h"