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 flush_queued_reg_saves (void);
363 static bool clobbers_queued_reg_save (rtx
);
364 static void dwarf2out_frame_debug_expr (rtx
, const char *);
366 /* Support for complex CFA locations. */
367 static void output_cfa_loc (dw_cfi_ref
);
368 static void get_cfa_from_loc_descr (dw_cfa_location
*,
369 struct dw_loc_descr_struct
*);
370 static struct dw_loc_descr_struct
*build_cfa_loc
372 static void def_cfa_1 (const char *, dw_cfa_location
*);
374 /* How to start an assembler comment. */
375 #ifndef ASM_COMMENT_START
376 #define ASM_COMMENT_START ";#"
379 /* Data and reference forms for relocatable data. */
380 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
381 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
383 #ifndef DEBUG_FRAME_SECTION
384 #define DEBUG_FRAME_SECTION ".debug_frame"
387 #ifndef FUNC_BEGIN_LABEL
388 #define FUNC_BEGIN_LABEL "LFB"
391 #ifndef FUNC_END_LABEL
392 #define FUNC_END_LABEL "LFE"
395 #ifndef FRAME_BEGIN_LABEL
396 #define FRAME_BEGIN_LABEL "Lframe"
398 #define CIE_AFTER_SIZE_LABEL "LSCIE"
399 #define CIE_END_LABEL "LECIE"
400 #define FDE_LABEL "LSFDE"
401 #define FDE_AFTER_SIZE_LABEL "LASFDE"
402 #define FDE_END_LABEL "LEFDE"
403 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
404 #define LINE_NUMBER_END_LABEL "LELT"
405 #define LN_PROLOG_AS_LABEL "LASLTP"
406 #define LN_PROLOG_END_LABEL "LELTP"
407 #define DIE_LABEL_PREFIX "DW"
409 /* The DWARF 2 CFA column which tracks the return address. Normally this
410 is the column for PC, or the first column after all of the hard
412 #ifndef DWARF_FRAME_RETURN_COLUMN
414 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
416 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
420 /* The mapping from gcc register number to DWARF 2 CFA column number. By
421 default, we just provide columns for all registers. */
422 #ifndef DWARF_FRAME_REGNUM
423 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
426 /* The offset from the incoming value of %sp to the top of the stack frame
427 for the current function. */
428 #ifndef INCOMING_FRAME_SP_OFFSET
429 #define INCOMING_FRAME_SP_OFFSET 0
432 /* Hook used by __throw. */
435 expand_builtin_dwarf_sp_column (void)
437 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
));
440 /* Return a pointer to a copy of the section string name S with all
441 attributes stripped off, and an asterisk prepended (for assemble_name). */
444 stripattributes (const char *s
)
446 char *stripped
= xmalloc (strlen (s
) + 2);
451 while (*s
&& *s
!= ',')
458 /* Generate code to initialize the register size table. */
461 expand_builtin_init_dwarf_reg_sizes (tree address
)
464 enum machine_mode mode
= TYPE_MODE (char_type_node
);
465 rtx addr
= expand_expr (address
, NULL_RTX
, VOIDmode
, 0);
466 rtx mem
= gen_rtx_MEM (BLKmode
, addr
);
467 bool wrote_return_column
= false;
469 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
470 if (DWARF_FRAME_REGNUM (i
) < DWARF_FRAME_REGISTERS
)
472 HOST_WIDE_INT offset
= DWARF_FRAME_REGNUM (i
) * GET_MODE_SIZE (mode
);
473 enum machine_mode save_mode
= reg_raw_mode
[i
];
476 if (HARD_REGNO_CALL_PART_CLOBBERED (i
, save_mode
))
477 save_mode
= choose_hard_reg_mode (i
, 1, true);
478 if (DWARF_FRAME_REGNUM (i
) == DWARF_FRAME_RETURN_COLUMN
)
480 if (save_mode
== VOIDmode
)
482 wrote_return_column
= true;
484 size
= GET_MODE_SIZE (save_mode
);
488 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
491 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
492 if (! wrote_return_column
)
494 i
= DWARF_ALT_FRAME_RETURN_COLUMN
;
495 wrote_return_column
= false;
497 i
= DWARF_FRAME_RETURN_COLUMN
;
500 if (! wrote_return_column
)
502 enum machine_mode save_mode
= Pmode
;
503 HOST_WIDE_INT offset
= i
* GET_MODE_SIZE (mode
);
504 HOST_WIDE_INT size
= GET_MODE_SIZE (save_mode
);
505 emit_move_insn (adjust_address (mem
, mode
, offset
), GEN_INT (size
));
509 /* Convert a DWARF call frame info. operation to its string name */
512 dwarf_cfi_name (unsigned int cfi_opc
)
516 case DW_CFA_advance_loc
:
517 return "DW_CFA_advance_loc";
519 return "DW_CFA_offset";
521 return "DW_CFA_restore";
525 return "DW_CFA_set_loc";
526 case DW_CFA_advance_loc1
:
527 return "DW_CFA_advance_loc1";
528 case DW_CFA_advance_loc2
:
529 return "DW_CFA_advance_loc2";
530 case DW_CFA_advance_loc4
:
531 return "DW_CFA_advance_loc4";
532 case DW_CFA_offset_extended
:
533 return "DW_CFA_offset_extended";
534 case DW_CFA_restore_extended
:
535 return "DW_CFA_restore_extended";
536 case DW_CFA_undefined
:
537 return "DW_CFA_undefined";
538 case DW_CFA_same_value
:
539 return "DW_CFA_same_value";
540 case DW_CFA_register
:
541 return "DW_CFA_register";
542 case DW_CFA_remember_state
:
543 return "DW_CFA_remember_state";
544 case DW_CFA_restore_state
:
545 return "DW_CFA_restore_state";
547 return "DW_CFA_def_cfa";
548 case DW_CFA_def_cfa_register
:
549 return "DW_CFA_def_cfa_register";
550 case DW_CFA_def_cfa_offset
:
551 return "DW_CFA_def_cfa_offset";
554 case DW_CFA_def_cfa_expression
:
555 return "DW_CFA_def_cfa_expression";
556 case DW_CFA_expression
:
557 return "DW_CFA_expression";
558 case DW_CFA_offset_extended_sf
:
559 return "DW_CFA_offset_extended_sf";
560 case DW_CFA_def_cfa_sf
:
561 return "DW_CFA_def_cfa_sf";
562 case DW_CFA_def_cfa_offset_sf
:
563 return "DW_CFA_def_cfa_offset_sf";
565 /* SGI/MIPS specific */
566 case DW_CFA_MIPS_advance_loc8
:
567 return "DW_CFA_MIPS_advance_loc8";
570 case DW_CFA_GNU_window_save
:
571 return "DW_CFA_GNU_window_save";
572 case DW_CFA_GNU_args_size
:
573 return "DW_CFA_GNU_args_size";
574 case DW_CFA_GNU_negative_offset_extended
:
575 return "DW_CFA_GNU_negative_offset_extended";
578 return "DW_CFA_<unknown>";
582 /* Return a pointer to a newly allocated Call Frame Instruction. */
584 static inline dw_cfi_ref
587 dw_cfi_ref cfi
= ggc_alloc (sizeof (dw_cfi_node
));
589 cfi
->dw_cfi_next
= NULL
;
590 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= 0;
591 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= 0;
596 /* Add a Call Frame Instruction to list of instructions. */
599 add_cfi (dw_cfi_ref
*list_head
, dw_cfi_ref cfi
)
603 /* Find the end of the chain. */
604 for (p
= list_head
; (*p
) != NULL
; p
= &(*p
)->dw_cfi_next
)
610 /* Generate a new label for the CFI info to refer to. */
613 dwarf2out_cfi_label (void)
615 static char label
[20];
617 ASM_GENERATE_INTERNAL_LABEL (label
, "LCFI", dwarf2out_cfi_label_num
++);
618 ASM_OUTPUT_LABEL (asm_out_file
, label
);
622 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
623 or to the CIE if LABEL is NULL. */
626 add_fde_cfi (const char *label
, dw_cfi_ref cfi
)
630 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
633 label
= dwarf2out_cfi_label ();
635 if (fde
->dw_fde_current_label
== NULL
636 || strcmp (label
, fde
->dw_fde_current_label
) != 0)
640 fde
->dw_fde_current_label
= label
= xstrdup (label
);
642 /* Set the location counter to the new label. */
644 xcfi
->dw_cfi_opc
= DW_CFA_advance_loc4
;
645 xcfi
->dw_cfi_oprnd1
.dw_cfi_addr
= label
;
646 add_cfi (&fde
->dw_fde_cfi
, xcfi
);
649 add_cfi (&fde
->dw_fde_cfi
, cfi
);
653 add_cfi (&cie_cfi_head
, cfi
);
656 /* Subroutine of lookup_cfa. */
659 lookup_cfa_1 (dw_cfi_ref cfi
, dw_cfa_location
*loc
)
661 switch (cfi
->dw_cfi_opc
)
663 case DW_CFA_def_cfa_offset
:
664 loc
->offset
= cfi
->dw_cfi_oprnd1
.dw_cfi_offset
;
666 case DW_CFA_def_cfa_register
:
667 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
670 loc
->reg
= cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
;
671 loc
->offset
= cfi
->dw_cfi_oprnd2
.dw_cfi_offset
;
673 case DW_CFA_def_cfa_expression
:
674 get_cfa_from_loc_descr (loc
, cfi
->dw_cfi_oprnd1
.dw_cfi_loc
);
681 /* Find the previous value for the CFA. */
684 lookup_cfa (dw_cfa_location
*loc
)
688 loc
->reg
= (unsigned long) -1;
691 loc
->base_offset
= 0;
693 for (cfi
= cie_cfi_head
; cfi
; cfi
= cfi
->dw_cfi_next
)
694 lookup_cfa_1 (cfi
, loc
);
696 if (fde_table_in_use
)
698 dw_fde_ref fde
= &fde_table
[fde_table_in_use
- 1];
699 for (cfi
= fde
->dw_fde_cfi
; cfi
; cfi
= cfi
->dw_cfi_next
)
700 lookup_cfa_1 (cfi
, loc
);
704 /* The current rule for calculating the DWARF2 canonical frame address. */
705 static dw_cfa_location cfa
;
707 /* The register used for saving registers to the stack, and its offset
709 static dw_cfa_location cfa_store
;
711 /* The running total of the size of arguments pushed onto the stack. */
712 static HOST_WIDE_INT args_size
;
714 /* The last args_size we actually output. */
715 static HOST_WIDE_INT old_args_size
;
717 /* Entry point to update the canonical frame address (CFA).
718 LABEL is passed to add_fde_cfi. The value of CFA is now to be
719 calculated from REG+OFFSET. */
722 dwarf2out_def_cfa (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
729 def_cfa_1 (label
, &loc
);
732 /* This routine does the actual work. The CFA is now calculated from
733 the dw_cfa_location structure. */
736 def_cfa_1 (const char *label
, dw_cfa_location
*loc_p
)
739 dw_cfa_location old_cfa
, loc
;
744 if (cfa_store
.reg
== loc
.reg
&& loc
.indirect
== 0)
745 cfa_store
.offset
= loc
.offset
;
747 loc
.reg
= DWARF_FRAME_REGNUM (loc
.reg
);
748 lookup_cfa (&old_cfa
);
750 /* If nothing changed, no need to issue any call frame instructions. */
751 if (loc
.reg
== old_cfa
.reg
&& loc
.offset
== old_cfa
.offset
752 && loc
.indirect
== old_cfa
.indirect
753 && (loc
.indirect
== 0 || loc
.base_offset
== old_cfa
.base_offset
))
758 if (loc
.reg
== old_cfa
.reg
&& !loc
.indirect
)
760 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
761 indicating the CFA register did not change but the offset
763 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_offset
;
764 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= loc
.offset
;
767 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
768 else if (loc
.offset
== old_cfa
.offset
&& old_cfa
.reg
!= (unsigned long) -1
771 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
772 indicating the CFA register has changed to <register> but the
773 offset has not changed. */
774 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_register
;
775 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
779 else if (loc
.indirect
== 0)
781 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
782 indicating the CFA register has changed to <register> with
783 the specified offset. */
784 cfi
->dw_cfi_opc
= DW_CFA_def_cfa
;
785 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= loc
.reg
;
786 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= loc
.offset
;
790 /* Construct a DW_CFA_def_cfa_expression instruction to
791 calculate the CFA using a full location expression since no
792 register-offset pair is available. */
793 struct dw_loc_descr_struct
*loc_list
;
795 cfi
->dw_cfi_opc
= DW_CFA_def_cfa_expression
;
796 loc_list
= build_cfa_loc (&loc
);
797 cfi
->dw_cfi_oprnd1
.dw_cfi_loc
= loc_list
;
800 add_fde_cfi (label
, cfi
);
803 /* Add the CFI for saving a register. REG is the CFA column number.
804 LABEL is passed to add_fde_cfi.
805 If SREG is -1, the register is saved at OFFSET from the CFA;
806 otherwise it is saved in SREG. */
809 reg_save (const char *label
, unsigned int reg
, unsigned int sreg
, HOST_WIDE_INT offset
)
811 dw_cfi_ref cfi
= new_cfi ();
813 cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
= reg
;
815 if (sreg
== INVALID_REGNUM
)
818 /* The register number won't fit in 6 bits, so we have to use
820 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
822 cfi
->dw_cfi_opc
= DW_CFA_offset
;
824 #ifdef ENABLE_CHECKING
826 /* If we get an offset that is not a multiple of
827 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
828 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
830 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
832 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
836 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
838 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
840 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
842 else if (sreg
== reg
)
843 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
846 cfi
->dw_cfi_opc
= DW_CFA_register
;
847 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
850 add_fde_cfi (label
, cfi
);
853 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
854 This CFI tells the unwinder that it needs to restore the window registers
855 from the previous frame's window save area.
857 ??? Perhaps we should note in the CIE where windows are saved (instead of
858 assuming 0(cfa)) and what registers are in the window. */
861 dwarf2out_window_save (const char *label
)
863 dw_cfi_ref cfi
= new_cfi ();
865 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
866 add_fde_cfi (label
, cfi
);
869 /* Add a CFI to update the running total of the size of arguments
870 pushed onto the stack. */
873 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
877 if (size
== old_args_size
)
880 old_args_size
= size
;
883 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
884 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
885 add_fde_cfi (label
, cfi
);
888 /* Entry point for saving a register to the stack. REG is the GCC register
889 number. LABEL and OFFSET are passed to reg_save. */
892 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
894 reg_save (label
, DWARF_FRAME_REGNUM (reg
), INVALID_REGNUM
, offset
);
897 /* Entry point for saving the return address in the stack.
898 LABEL and OFFSET are passed to reg_save. */
901 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
903 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, INVALID_REGNUM
, offset
);
906 /* Entry point for saving the return address in a register.
907 LABEL and SREG are passed to reg_save. */
910 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
912 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, DWARF_FRAME_REGNUM (sreg
), 0);
915 /* Record the initial position of the return address. RTL is
916 INCOMING_RETURN_ADDR_RTX. */
919 initial_return_save (rtx rtl
)
921 unsigned int reg
= INVALID_REGNUM
;
922 HOST_WIDE_INT offset
= 0;
924 switch (GET_CODE (rtl
))
927 /* RA is in a register. */
928 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
932 /* RA is on the stack. */
934 switch (GET_CODE (rtl
))
937 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
943 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
945 offset
= INTVAL (XEXP (rtl
, 1));
949 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
951 offset
= -INTVAL (XEXP (rtl
, 1));
961 /* The return address is at some offset from any value we can
962 actually load. For instance, on the SPARC it is in %i7+8. Just
963 ignore the offset for now; it doesn't matter for unwinding frames. */
964 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
966 initial_return_save (XEXP (rtl
, 0));
973 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
974 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
977 /* Given a SET, calculate the amount of stack adjustment it
981 stack_adjust_offset (rtx pattern
)
983 rtx src
= SET_SRC (pattern
);
984 rtx dest
= SET_DEST (pattern
);
985 HOST_WIDE_INT offset
= 0;
988 if (dest
== stack_pointer_rtx
)
990 /* (set (reg sp) (plus (reg sp) (const_int))) */
991 code
= GET_CODE (src
);
992 if (! (code
== PLUS
|| code
== MINUS
)
993 || XEXP (src
, 0) != stack_pointer_rtx
994 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
997 offset
= INTVAL (XEXP (src
, 1));
1001 else if (MEM_P (dest
))
1003 /* (set (mem (pre_dec (reg sp))) (foo)) */
1004 src
= XEXP (dest
, 0);
1005 code
= GET_CODE (src
);
1011 if (XEXP (src
, 0) == stack_pointer_rtx
)
1013 rtx val
= XEXP (XEXP (src
, 1), 1);
1014 /* We handle only adjustments by constant amount. */
1015 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
1016 GET_CODE (val
) != CONST_INT
)
1018 offset
= -INTVAL (val
);
1025 if (XEXP (src
, 0) == stack_pointer_rtx
)
1027 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1034 if (XEXP (src
, 0) == stack_pointer_rtx
)
1036 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1051 /* Check INSN to see if it looks like a push or a stack adjustment, and
1052 make a note of it if it does. EH uses this information to find out how
1053 much extra space it needs to pop off the stack. */
1056 dwarf2out_stack_adjust (rtx insn
)
1058 HOST_WIDE_INT offset
;
1062 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1063 with this function. Proper support would require all frame-related
1064 insns to be marked, and to be able to handle saving state around
1065 epilogues textually in the middle of the function. */
1066 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1069 if (!flag_asynchronous_unwind_tables
&& CALL_P (insn
))
1071 /* Extract the size of the args from the CALL rtx itself. */
1072 insn
= PATTERN (insn
);
1073 if (GET_CODE (insn
) == PARALLEL
)
1074 insn
= XVECEXP (insn
, 0, 0);
1075 if (GET_CODE (insn
) == SET
)
1076 insn
= SET_SRC (insn
);
1077 if (GET_CODE (insn
) != CALL
)
1080 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1084 /* If only calls can throw, and we have a frame pointer,
1085 save up adjustments until we see the CALL_INSN. */
1086 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1089 if (BARRIER_P (insn
))
1091 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1092 the compiler will have already emitted a stack adjustment, but
1093 doesn't bother for calls to noreturn functions. */
1094 #ifdef STACK_GROWS_DOWNWARD
1095 offset
= -args_size
;
1100 else if (GET_CODE (PATTERN (insn
)) == SET
)
1101 offset
= stack_adjust_offset (PATTERN (insn
));
1102 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1103 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1105 /* There may be stack adjustments inside compound insns. Search
1107 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1108 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1109 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1117 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1118 cfa
.offset
+= offset
;
1120 #ifndef STACK_GROWS_DOWNWARD
1124 args_size
+= offset
;
1128 label
= dwarf2out_cfi_label ();
1129 def_cfa_1 (label
, &cfa
);
1130 dwarf2out_args_size (label
, args_size
);
1135 /* We delay emitting a register save until either (a) we reach the end
1136 of the prologue or (b) the register is clobbered. This clusters
1137 register saves so that there are fewer pc advances. */
1139 struct queued_reg_save
GTY(())
1141 struct queued_reg_save
*next
;
1143 HOST_WIDE_INT cfa_offset
;
1147 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1149 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1150 struct reg_saved_in_data
GTY(()) {
1155 /* A list of registers saved in other registers.
1156 The list intentionally has a small maximum capacity of 4; if your
1157 port needs more than that, you might consider implementing a
1158 more efficient data structure. */
1159 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1160 static GTY(()) size_t num_regs_saved_in_regs
;
1162 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1163 static const char *last_reg_save_label
;
1165 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1166 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1169 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1171 struct queued_reg_save
*q
;
1173 /* Duplicates waste space, but it's also necessary to remove them
1174 for correctness, since the queue gets output in reverse
1176 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1177 if (REGNO (q
->reg
) == REGNO (reg
))
1182 q
= ggc_alloc (sizeof (*q
));
1183 q
->next
= queued_reg_saves
;
1184 queued_reg_saves
= q
;
1188 q
->cfa_offset
= offset
;
1189 q
->saved_reg
= sreg
;
1191 last_reg_save_label
= label
;
1194 /* Output all the entries in QUEUED_REG_SAVES. */
1197 flush_queued_reg_saves (void)
1199 struct queued_reg_save
*q
;
1201 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1204 unsigned int reg
, sreg
;
1206 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1207 if (REGNO (regs_saved_in_regs
[i
].orig_reg
) == REGNO (q
->reg
))
1209 if (q
->saved_reg
&& i
== num_regs_saved_in_regs
)
1211 if (i
== ARRAY_SIZE (regs_saved_in_regs
))
1213 num_regs_saved_in_regs
++;
1215 if (i
!= num_regs_saved_in_regs
)
1217 regs_saved_in_regs
[i
].orig_reg
= q
->reg
;
1218 regs_saved_in_regs
[i
].saved_in_reg
= q
->saved_reg
;
1221 reg
= DWARF_FRAME_REGNUM (REGNO (q
->reg
));
1223 sreg
= DWARF_FRAME_REGNUM (REGNO (q
->saved_reg
));
1225 sreg
= INVALID_REGNUM
;
1226 reg_save (last_reg_save_label
, reg
, sreg
, q
->cfa_offset
);
1229 queued_reg_saves
= NULL
;
1230 last_reg_save_label
= NULL
;
1233 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1234 location for? Or, does it clobber a register which we've previously
1235 said that some other register is saved in, and for which we now
1236 have a new location for? */
1239 clobbers_queued_reg_save (rtx insn
)
1241 struct queued_reg_save
*q
;
1243 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1246 if (modified_in_p (q
->reg
, insn
))
1248 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1249 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1250 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1257 /* What register, if any, is currently saved in REG? */
1260 reg_saved_in (rtx reg
)
1262 unsigned int regn
= REGNO (reg
);
1264 struct queued_reg_save
*q
;
1266 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1267 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1270 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1271 if (regs_saved_in_regs
[i
].saved_in_reg
1272 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1273 return regs_saved_in_regs
[i
].orig_reg
;
1279 /* A temporary register holding an integral value used in adjusting SP
1280 or setting up the store_reg. The "offset" field holds the integer
1281 value, not an offset. */
1282 static dw_cfa_location cfa_temp
;
1284 /* Record call frame debugging information for an expression EXPR,
1285 which either sets SP or FP (adjusting how we calculate the frame
1286 address) or saves a register to the stack or another register.
1287 LABEL indicates the address of EXPR.
1289 This function encodes a state machine mapping rtxes to actions on
1290 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1291 users need not read the source code.
1293 The High-Level Picture
1295 Changes in the register we use to calculate the CFA: Currently we
1296 assume that if you copy the CFA register into another register, we
1297 should take the other one as the new CFA register; this seems to
1298 work pretty well. If it's wrong for some target, it's simple
1299 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1301 Changes in the register we use for saving registers to the stack:
1302 This is usually SP, but not always. Again, we deduce that if you
1303 copy SP into another register (and SP is not the CFA register),
1304 then the new register is the one we will be using for register
1305 saves. This also seems to work.
1307 Register saves: There's not much guesswork about this one; if
1308 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1309 register save, and the register used to calculate the destination
1310 had better be the one we think we're using for this purpose.
1311 It's also assumed that a copy from a call-saved register to another
1312 register is saving that register if RTX_FRAME_RELATED_P is set on
1313 that instruction. If the copy is from a call-saved register to
1314 the *same* register, that means that the register is now the same
1315 value as in the caller.
1317 Except: If the register being saved is the CFA register, and the
1318 offset is nonzero, we are saving the CFA, so we assume we have to
1319 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1320 the intent is to save the value of SP from the previous frame.
1322 In addition, if a register has previously been saved to a different
1325 Invariants / Summaries of Rules
1327 cfa current rule for calculating the CFA. It usually
1328 consists of a register and an offset.
1329 cfa_store register used by prologue code to save things to the stack
1330 cfa_store.offset is the offset from the value of
1331 cfa_store.reg to the actual CFA
1332 cfa_temp register holding an integral value. cfa_temp.offset
1333 stores the value, which will be used to adjust the
1334 stack pointer. cfa_temp is also used like cfa_store,
1335 to track stores to the stack via fp or a temp reg.
1337 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1338 with cfa.reg as the first operand changes the cfa.reg and its
1339 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1342 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1343 expression yielding a constant. This sets cfa_temp.reg
1344 and cfa_temp.offset.
1346 Rule 5: Create a new register cfa_store used to save items to the
1349 Rules 10-14: Save a register to the stack. Define offset as the
1350 difference of the original location and cfa_store's
1351 location (or cfa_temp's location if cfa_temp is used).
1355 "{a,b}" indicates a choice of a xor b.
1356 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1359 (set <reg1> <reg2>:cfa.reg)
1360 effects: cfa.reg = <reg1>
1361 cfa.offset unchanged
1362 cfa_temp.reg = <reg1>
1363 cfa_temp.offset = cfa.offset
1366 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1367 {<const_int>,<reg>:cfa_temp.reg}))
1368 effects: cfa.reg = sp if fp used
1369 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1370 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1371 if cfa_store.reg==sp
1374 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1375 effects: cfa.reg = fp
1376 cfa_offset += +/- <const_int>
1379 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1380 constraints: <reg1> != fp
1382 effects: cfa.reg = <reg1>
1383 cfa_temp.reg = <reg1>
1384 cfa_temp.offset = cfa.offset
1387 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1388 constraints: <reg1> != fp
1390 effects: cfa_store.reg = <reg1>
1391 cfa_store.offset = cfa.offset - cfa_temp.offset
1394 (set <reg> <const_int>)
1395 effects: cfa_temp.reg = <reg>
1396 cfa_temp.offset = <const_int>
1399 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1400 effects: cfa_temp.reg = <reg1>
1401 cfa_temp.offset |= <const_int>
1404 (set <reg> (high <exp>))
1408 (set <reg> (lo_sum <exp> <const_int>))
1409 effects: cfa_temp.reg = <reg>
1410 cfa_temp.offset = <const_int>
1413 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1414 effects: cfa_store.offset -= <const_int>
1415 cfa.offset = cfa_store.offset if cfa.reg == sp
1417 cfa.base_offset = -cfa_store.offset
1420 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1421 effects: cfa_store.offset += -/+ mode_size(mem)
1422 cfa.offset = cfa_store.offset if cfa.reg == sp
1424 cfa.base_offset = -cfa_store.offset
1427 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1430 effects: cfa.reg = <reg1>
1431 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1434 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1435 effects: cfa.reg = <reg1>
1436 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1439 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1440 effects: cfa.reg = <reg1>
1441 cfa.base_offset = -cfa_temp.offset
1442 cfa_temp.offset -= mode_size(mem) */
1445 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1448 HOST_WIDE_INT offset
;
1450 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1451 the PARALLEL independently. The first element is always processed if
1452 it is a SET. This is for backward compatibility. Other elements
1453 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1454 flag is set in them. */
1455 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1458 int limit
= XVECLEN (expr
, 0);
1460 for (par_index
= 0; par_index
< limit
; par_index
++)
1461 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1462 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1464 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1469 if (GET_CODE (expr
) != SET
)
1472 src
= SET_SRC (expr
);
1473 dest
= SET_DEST (expr
);
1475 if (GET_CODE (src
) == REG
)
1477 rtx rsi
= reg_saved_in (src
);
1482 switch (GET_CODE (dest
))
1485 switch (GET_CODE (src
))
1487 /* Setting FP from SP. */
1489 if (cfa
.reg
== (unsigned) REGNO (src
))
1492 /* Update the CFA rule wrt SP or FP. Make sure src is
1493 relative to the current CFA register.
1495 We used to require that dest be either SP or FP, but the
1496 ARM copies SP to a temporary register, and from there to
1497 FP. So we just rely on the backends to only set
1498 RTX_FRAME_RELATED_P on appropriate insns. */
1499 cfa
.reg
= REGNO (dest
);
1500 cfa_temp
.reg
= cfa
.reg
;
1501 cfa_temp
.offset
= cfa
.offset
;
1503 else if (call_used_regs
[REGNO (dest
)]
1504 && ! fixed_regs
[REGNO (dest
)])
1506 /* Saving a register in a register. */
1507 queue_reg_save (label
, src
, dest
, 0);
1516 if (dest
== stack_pointer_rtx
)
1520 switch (GET_CODE (XEXP (src
, 1)))
1523 offset
= INTVAL (XEXP (src
, 1));
1526 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1528 offset
= cfa_temp
.offset
;
1534 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1536 /* Restoring SP from FP in the epilogue. */
1537 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1539 cfa
.reg
= STACK_POINTER_REGNUM
;
1541 else if (GET_CODE (src
) == LO_SUM
)
1542 /* Assume we've set the source reg of the LO_SUM from sp. */
1544 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1547 if (GET_CODE (src
) != MINUS
)
1549 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1550 cfa
.offset
+= offset
;
1551 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1552 cfa_store
.offset
+= offset
;
1554 else if (dest
== hard_frame_pointer_rtx
)
1557 /* Either setting the FP from an offset of the SP,
1558 or adjusting the FP */
1559 if (! frame_pointer_needed
)
1562 if (REG_P (XEXP (src
, 0))
1563 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1564 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1566 offset
= INTVAL (XEXP (src
, 1));
1567 if (GET_CODE (src
) != MINUS
)
1569 cfa
.offset
+= offset
;
1570 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1577 if (GET_CODE (src
) == MINUS
)
1581 if (REG_P (XEXP (src
, 0))
1582 && REGNO (XEXP (src
, 0)) == cfa
.reg
1583 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1585 /* Setting a temporary CFA register that will be copied
1586 into the FP later on. */
1587 offset
= - INTVAL (XEXP (src
, 1));
1588 cfa
.offset
+= offset
;
1589 cfa
.reg
= REGNO (dest
);
1590 /* Or used to save regs to the stack. */
1591 cfa_temp
.reg
= cfa
.reg
;
1592 cfa_temp
.offset
= cfa
.offset
;
1596 else if (REG_P (XEXP (src
, 0))
1597 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1598 && XEXP (src
, 1) == stack_pointer_rtx
)
1600 /* Setting a scratch register that we will use instead
1601 of SP for saving registers to the stack. */
1602 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1604 cfa_store
.reg
= REGNO (dest
);
1605 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1609 else if (GET_CODE (src
) == LO_SUM
1610 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1612 cfa_temp
.reg
= REGNO (dest
);
1613 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1622 cfa_temp
.reg
= REGNO (dest
);
1623 cfa_temp
.offset
= INTVAL (src
);
1628 if (!REG_P (XEXP (src
, 0))
1629 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1630 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1633 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1634 cfa_temp
.reg
= REGNO (dest
);
1635 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1638 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1639 which will fill in all of the bits. */
1648 def_cfa_1 (label
, &cfa
);
1655 /* Saving a register to the stack. Make sure dest is relative to the
1657 switch (GET_CODE (XEXP (dest
, 0)))
1662 /* We can't handle variable size modifications. */
1663 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1665 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1667 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1668 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1671 cfa_store
.offset
+= offset
;
1672 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1673 cfa
.offset
= cfa_store
.offset
;
1675 offset
= -cfa_store
.offset
;
1681 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1682 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1685 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1686 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1689 cfa_store
.offset
+= offset
;
1690 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1691 cfa
.offset
= cfa_store
.offset
;
1693 offset
= -cfa_store
.offset
;
1697 /* With an offset. */
1701 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1703 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1704 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1707 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1708 offset
-= cfa_store
.offset
;
1709 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1710 offset
-= cfa_temp
.offset
;
1716 /* Without an offset. */
1718 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1719 offset
= -cfa_store
.offset
;
1720 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1721 offset
= -cfa_temp
.offset
;
1728 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1730 offset
= -cfa_temp
.offset
;
1731 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1738 if (REGNO (src
) != STACK_POINTER_REGNUM
1739 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1740 && (unsigned) REGNO (src
) == cfa
.reg
)
1742 /* We're storing the current CFA reg into the stack. */
1744 if (cfa
.offset
== 0)
1746 /* If the source register is exactly the CFA, assume
1747 we're saving SP like any other register; this happens
1749 def_cfa_1 (label
, &cfa
);
1750 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
1755 /* Otherwise, we'll need to look in the stack to
1756 calculate the CFA. */
1757 rtx x
= XEXP (dest
, 0);
1764 cfa
.reg
= REGNO (x
);
1765 cfa
.base_offset
= offset
;
1767 def_cfa_1 (label
, &cfa
);
1772 def_cfa_1 (label
, &cfa
);
1773 queue_reg_save (label
, src
, NULL_RTX
, offset
);
1781 /* Record call frame debugging information for INSN, which either
1782 sets SP or FP (adjusting how we calculate the frame address) or saves a
1783 register to the stack. If INSN is NULL_RTX, initialize our state. */
1786 dwarf2out_frame_debug (rtx insn
)
1791 if (insn
== NULL_RTX
)
1795 /* Flush any queued register saves. */
1796 flush_queued_reg_saves ();
1798 /* Set up state for generating call frame debug info. */
1800 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1803 cfa
.reg
= STACK_POINTER_REGNUM
;
1806 cfa_temp
.offset
= 0;
1808 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1810 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
1811 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
1813 num_regs_saved_in_regs
= 0;
1817 if (!NONJUMP_INSN_P (insn
) || clobbers_queued_reg_save (insn
))
1818 flush_queued_reg_saves ();
1820 if (! RTX_FRAME_RELATED_P (insn
))
1822 if (!ACCUMULATE_OUTGOING_ARGS
)
1823 dwarf2out_stack_adjust (insn
);
1828 label
= dwarf2out_cfi_label ();
1829 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1831 insn
= XEXP (src
, 0);
1833 insn
= PATTERN (insn
);
1835 dwarf2out_frame_debug_expr (insn
, label
);
1840 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1841 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1842 (enum dwarf_call_frame_info cfi
);
1844 static enum dw_cfi_oprnd_type
1845 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1850 case DW_CFA_GNU_window_save
:
1851 return dw_cfi_oprnd_unused
;
1853 case DW_CFA_set_loc
:
1854 case DW_CFA_advance_loc1
:
1855 case DW_CFA_advance_loc2
:
1856 case DW_CFA_advance_loc4
:
1857 case DW_CFA_MIPS_advance_loc8
:
1858 return dw_cfi_oprnd_addr
;
1861 case DW_CFA_offset_extended
:
1862 case DW_CFA_def_cfa
:
1863 case DW_CFA_offset_extended_sf
:
1864 case DW_CFA_def_cfa_sf
:
1865 case DW_CFA_restore_extended
:
1866 case DW_CFA_undefined
:
1867 case DW_CFA_same_value
:
1868 case DW_CFA_def_cfa_register
:
1869 case DW_CFA_register
:
1870 return dw_cfi_oprnd_reg_num
;
1872 case DW_CFA_def_cfa_offset
:
1873 case DW_CFA_GNU_args_size
:
1874 case DW_CFA_def_cfa_offset_sf
:
1875 return dw_cfi_oprnd_offset
;
1877 case DW_CFA_def_cfa_expression
:
1878 case DW_CFA_expression
:
1879 return dw_cfi_oprnd_loc
;
1886 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1887 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1888 (enum dwarf_call_frame_info cfi
);
1890 static enum dw_cfi_oprnd_type
1891 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1895 case DW_CFA_def_cfa
:
1896 case DW_CFA_def_cfa_sf
:
1898 case DW_CFA_offset_extended_sf
:
1899 case DW_CFA_offset_extended
:
1900 return dw_cfi_oprnd_offset
;
1902 case DW_CFA_register
:
1903 return dw_cfi_oprnd_reg_num
;
1906 return dw_cfi_oprnd_unused
;
1910 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1912 /* Map register numbers held in the call frame info that gcc has
1913 collected using DWARF_FRAME_REGNUM to those that should be output in
1914 .debug_frame and .eh_frame. */
1915 #ifndef DWARF2_FRAME_REG_OUT
1916 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1919 /* Output a Call Frame Information opcode and its operand(s). */
1922 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
1925 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1926 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1927 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1928 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
1929 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1930 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1932 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1933 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
1934 "DW_CFA_offset, column 0x%lx", r
);
1935 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1937 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1939 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1940 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
1941 "DW_CFA_restore, column 0x%lx", r
);
1945 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1946 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1948 switch (cfi
->dw_cfi_opc
)
1950 case DW_CFA_set_loc
:
1952 dw2_asm_output_encoded_addr_rtx (
1953 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1954 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1957 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1958 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1961 case DW_CFA_advance_loc1
:
1962 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1963 fde
->dw_fde_current_label
, NULL
);
1964 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1967 case DW_CFA_advance_loc2
:
1968 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1969 fde
->dw_fde_current_label
, NULL
);
1970 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1973 case DW_CFA_advance_loc4
:
1974 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1975 fde
->dw_fde_current_label
, NULL
);
1976 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1979 case DW_CFA_MIPS_advance_loc8
:
1980 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1981 fde
->dw_fde_current_label
, NULL
);
1982 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1985 case DW_CFA_offset_extended
:
1986 case DW_CFA_def_cfa
:
1987 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1988 dw2_asm_output_data_uleb128 (r
, NULL
);
1989 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1992 case DW_CFA_offset_extended_sf
:
1993 case DW_CFA_def_cfa_sf
:
1994 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1995 dw2_asm_output_data_uleb128 (r
, NULL
);
1996 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1999 case DW_CFA_restore_extended
:
2000 case DW_CFA_undefined
:
2001 case DW_CFA_same_value
:
2002 case DW_CFA_def_cfa_register
:
2003 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2004 dw2_asm_output_data_uleb128 (r
, NULL
);
2007 case DW_CFA_register
:
2008 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2009 dw2_asm_output_data_uleb128 (r
, NULL
);
2010 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2011 dw2_asm_output_data_uleb128 (r
, NULL
);
2014 case DW_CFA_def_cfa_offset
:
2015 case DW_CFA_GNU_args_size
:
2016 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2019 case DW_CFA_def_cfa_offset_sf
:
2020 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2023 case DW_CFA_GNU_window_save
:
2026 case DW_CFA_def_cfa_expression
:
2027 case DW_CFA_expression
:
2028 output_cfa_loc (cfi
);
2031 case DW_CFA_GNU_negative_offset_extended
:
2032 /* Obsoleted by DW_CFA_offset_extended_sf. */
2041 /* Output the call frame information used to record information
2042 that relates to calculating the frame pointer, and records the
2043 location of saved registers. */
2046 output_call_frame_info (int for_eh
)
2051 char l1
[20], l2
[20], section_start_label
[20];
2052 bool any_lsda_needed
= false;
2053 char augmentation
[6];
2054 int augmentation_size
;
2055 int fde_encoding
= DW_EH_PE_absptr
;
2056 int per_encoding
= DW_EH_PE_absptr
;
2057 int lsda_encoding
= DW_EH_PE_absptr
;
2059 /* Don't emit a CIE if there won't be any FDEs. */
2060 if (fde_table_in_use
== 0)
2063 /* If we make FDEs linkonce, we may have to emit an empty label for
2064 an FDE that wouldn't otherwise be emitted. We want to avoid
2065 having an FDE kept around when the function it refers to is
2066 discarded. (Example where this matters: a primary function
2067 template in C++ requires EH information, but an explicit
2068 specialization doesn't. */
2069 if (TARGET_USES_WEAK_UNWIND_INFO
2070 && ! flag_asynchronous_unwind_tables
2072 for (i
= 0; i
< fde_table_in_use
; i
++)
2073 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2074 && !fde_table
[i
].uses_eh_lsda
2075 && ! DECL_ONE_ONLY (fde_table
[i
].decl
))
2076 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2077 for_eh
, /* empty */ 1);
2079 /* If we don't have any functions we'll want to unwind out of, don't
2080 emit any EH unwind information. Note that if exceptions aren't
2081 enabled, we won't have collected nothrow information, and if we
2082 asked for asynchronous tables, we always want this info. */
2085 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2087 for (i
= 0; i
< fde_table_in_use
; i
++)
2088 if (fde_table
[i
].uses_eh_lsda
)
2089 any_eh_needed
= any_lsda_needed
= true;
2090 else if (TARGET_USES_WEAK_UNWIND_INFO
2091 && DECL_ONE_ONLY (fde_table
[i
].decl
))
2092 any_eh_needed
= true;
2093 else if (! fde_table
[i
].nothrow
2094 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2095 any_eh_needed
= true;
2097 if (! any_eh_needed
)
2101 /* We're going to be generating comments, so turn on app. */
2106 targetm
.asm_out
.eh_frame_section ();
2108 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
2110 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2111 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2113 /* Output the CIE. */
2114 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2115 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2116 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2117 "Length of Common Information Entry");
2118 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2120 /* Now that the CIE pointer is PC-relative for EH,
2121 use 0 to identify the CIE. */
2122 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2123 (for_eh
? 0 : DW_CIE_ID
),
2124 "CIE Identifier Tag");
2126 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2128 augmentation
[0] = 0;
2129 augmentation_size
= 0;
2135 z Indicates that a uleb128 is present to size the
2136 augmentation section.
2137 L Indicates the encoding (and thus presence) of
2138 an LSDA pointer in the FDE augmentation.
2139 R Indicates a non-default pointer encoding for
2141 P Indicates the presence of an encoding + language
2142 personality routine in the CIE augmentation. */
2144 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2145 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2146 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2148 p
= augmentation
+ 1;
2149 if (eh_personality_libfunc
)
2152 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2154 if (any_lsda_needed
)
2157 augmentation_size
+= 1;
2159 if (fde_encoding
!= DW_EH_PE_absptr
)
2162 augmentation_size
+= 1;
2164 if (p
> augmentation
+ 1)
2166 augmentation
[0] = 'z';
2170 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2171 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2173 int offset
= ( 4 /* Length */
2175 + 1 /* CIE version */
2176 + strlen (augmentation
) + 1 /* Augmentation */
2177 + size_of_uleb128 (1) /* Code alignment */
2178 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2180 + 1 /* Augmentation size */
2181 + 1 /* Personality encoding */ );
2182 int pad
= -offset
& (PTR_SIZE
- 1);
2184 augmentation_size
+= pad
;
2186 /* Augmentations should be small, so there's scarce need to
2187 iterate for a solution. Die if we exceed one uleb128 byte. */
2188 if (size_of_uleb128 (augmentation_size
) != 1)
2193 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2194 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2195 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2196 "CIE Data Alignment Factor");
2198 if (DW_CIE_VERSION
== 1)
2199 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2201 dw2_asm_output_data_uleb128 (DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2203 if (augmentation
[0])
2205 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2206 if (eh_personality_libfunc
)
2208 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2209 eh_data_format_name (per_encoding
));
2210 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2211 eh_personality_libfunc
, NULL
);
2214 if (any_lsda_needed
)
2215 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2216 eh_data_format_name (lsda_encoding
));
2218 if (fde_encoding
!= DW_EH_PE_absptr
)
2219 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2220 eh_data_format_name (fde_encoding
));
2223 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2224 output_cfi (cfi
, NULL
, for_eh
);
2226 /* Pad the CIE out to an address sized boundary. */
2227 ASM_OUTPUT_ALIGN (asm_out_file
,
2228 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2229 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2231 /* Loop through all of the FDE's. */
2232 for (i
= 0; i
< fde_table_in_use
; i
++)
2234 fde
= &fde_table
[i
];
2236 /* Don't emit EH unwind info for leaf functions that don't need it. */
2237 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2238 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2239 && (! TARGET_USES_WEAK_UNWIND_INFO
|| ! DECL_ONE_ONLY (fde
->decl
))
2240 && !fde
->uses_eh_lsda
)
2243 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2244 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2245 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2246 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2247 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2249 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2252 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2254 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2259 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
);
2260 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
2261 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2263 "FDE initial location");
2264 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2265 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2266 "FDE address range");
2270 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2271 "FDE initial location");
2272 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2273 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2274 "FDE address range");
2277 if (augmentation
[0])
2279 if (any_lsda_needed
)
2281 int size
= size_of_encoded_value (lsda_encoding
);
2283 if (lsda_encoding
== DW_EH_PE_aligned
)
2285 int offset
= ( 4 /* Length */
2286 + 4 /* CIE offset */
2287 + 2 * size_of_encoded_value (fde_encoding
)
2288 + 1 /* Augmentation size */ );
2289 int pad
= -offset
& (PTR_SIZE
- 1);
2292 if (size_of_uleb128 (size
) != 1)
2296 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2298 if (fde
->uses_eh_lsda
)
2300 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2301 fde
->funcdef_number
);
2302 dw2_asm_output_encoded_addr_rtx (
2303 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2304 "Language Specific Data Area");
2308 if (lsda_encoding
== DW_EH_PE_aligned
)
2309 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2311 (size_of_encoded_value (lsda_encoding
), 0,
2312 "Language Specific Data Area (none)");
2316 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2319 /* Loop through the Call Frame Instructions associated with
2321 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2322 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2323 output_cfi (cfi
, fde
, for_eh
);
2325 /* Pad the FDE out to an address sized boundary. */
2326 ASM_OUTPUT_ALIGN (asm_out_file
,
2327 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2328 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2331 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2332 dw2_asm_output_data (4, 0, "End of Table");
2333 #ifdef MIPS_DEBUGGING_INFO
2334 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2335 get a value of 0. Putting .align 0 after the label fixes it. */
2336 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2339 /* Turn off app to make assembly quicker. */
2344 /* Output a marker (i.e. a label) for the beginning of a function, before
2348 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2349 const char *file ATTRIBUTE_UNUSED
)
2351 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2354 current_function_func_begin_label
= 0;
2356 #ifdef TARGET_UNWIND_INFO
2357 /* ??? current_function_func_begin_label is also used by except.c
2358 for call-site information. We must emit this label if it might
2360 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2361 && ! dwarf2out_do_frame ())
2364 if (! dwarf2out_do_frame ())
2368 function_section (current_function_decl
);
2369 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2370 current_function_funcdef_no
);
2371 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2372 current_function_funcdef_no
);
2373 current_function_func_begin_label
= get_identifier (label
);
2375 #ifdef TARGET_UNWIND_INFO
2376 /* We can elide the fde allocation if we're not emitting debug info. */
2377 if (! dwarf2out_do_frame ())
2381 /* Expand the fde table if necessary. */
2382 if (fde_table_in_use
== fde_table_allocated
)
2384 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2385 fde_table
= ggc_realloc (fde_table
,
2386 fde_table_allocated
* sizeof (dw_fde_node
));
2387 memset (fde_table
+ fde_table_in_use
, 0,
2388 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2391 /* Record the FDE associated with this function. */
2392 current_funcdef_fde
= fde_table_in_use
;
2394 /* Add the new FDE at the end of the fde_table. */
2395 fde
= &fde_table
[fde_table_in_use
++];
2396 fde
->decl
= current_function_decl
;
2397 fde
->dw_fde_begin
= xstrdup (label
);
2398 fde
->dw_fde_current_label
= NULL
;
2399 fde
->dw_fde_end
= NULL
;
2400 fde
->dw_fde_cfi
= NULL
;
2401 fde
->funcdef_number
= current_function_funcdef_no
;
2402 fde
->nothrow
= TREE_NOTHROW (current_function_decl
);
2403 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2404 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2406 args_size
= old_args_size
= 0;
2408 /* We only want to output line number information for the genuine dwarf2
2409 prologue case, not the eh frame case. */
2410 #ifdef DWARF2_DEBUGGING_INFO
2412 dwarf2out_source_line (line
, file
);
2416 /* Output a marker (i.e. a label) for the absolute end of the generated code
2417 for a function definition. This gets called *after* the epilogue code has
2421 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2422 const char *file ATTRIBUTE_UNUSED
)
2425 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2427 /* Output a label to mark the endpoint of the code generated for this
2429 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2430 current_function_funcdef_no
);
2431 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2432 fde
= &fde_table
[fde_table_in_use
- 1];
2433 fde
->dw_fde_end
= xstrdup (label
);
2437 dwarf2out_frame_init (void)
2439 /* Allocate the initial hunk of the fde_table. */
2440 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2441 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2442 fde_table_in_use
= 0;
2444 /* Generate the CFA instructions common to all FDE's. Do it now for the
2445 sake of lookup_cfa. */
2447 #ifdef DWARF2_UNWIND_INFO
2448 /* On entry, the Canonical Frame Address is at SP. */
2449 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2450 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2455 dwarf2out_frame_finish (void)
2457 /* Output call frame information. */
2458 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2459 output_call_frame_info (0);
2461 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2462 output_call_frame_info (1);
2466 /* And now, the subset of the debugging information support code necessary
2467 for emitting location expressions. */
2469 /* We need some way to distinguish DW_OP_addr with a direct symbol
2470 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2471 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2474 typedef struct dw_val_struct
*dw_val_ref
;
2475 typedef struct die_struct
*dw_die_ref
;
2476 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2477 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2479 /* Each DIE may have a series of attribute/value pairs. Values
2480 can take on several forms. The forms that are used in this
2481 implementation are listed below. */
2486 dw_val_class_offset
,
2488 dw_val_class_loc_list
,
2489 dw_val_class_range_list
,
2491 dw_val_class_unsigned_const
,
2492 dw_val_class_long_long
,
2495 dw_val_class_die_ref
,
2496 dw_val_class_fde_ref
,
2497 dw_val_class_lbl_id
,
2498 dw_val_class_lbl_offset
,
2502 /* Describe a double word constant value. */
2503 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2505 typedef struct dw_long_long_struct
GTY(())
2512 /* Describe a floating point constant value, or a vector constant value. */
2514 typedef struct dw_vec_struct
GTY(())
2516 unsigned char * GTY((length ("%h.length"))) array
;
2522 /* The dw_val_node describes an attribute's value, as it is
2523 represented internally. */
2525 typedef struct dw_val_struct
GTY(())
2527 enum dw_val_class val_class
;
2528 union dw_val_struct_union
2530 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2531 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2532 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2533 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2534 HOST_WIDE_INT
GTY ((default)) val_int
;
2535 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2536 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2537 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2538 struct dw_val_die_union
2542 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2543 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2544 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2545 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2546 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2548 GTY ((desc ("%1.val_class"))) v
;
2552 /* Locations in memory are described using a sequence of stack machine
2555 typedef struct dw_loc_descr_struct
GTY(())
2557 dw_loc_descr_ref dw_loc_next
;
2558 enum dwarf_location_atom dw_loc_opc
;
2559 dw_val_node dw_loc_oprnd1
;
2560 dw_val_node dw_loc_oprnd2
;
2565 /* Location lists are ranges + location descriptions for that range,
2566 so you can track variables that are in different places over
2567 their entire life. */
2568 typedef struct dw_loc_list_struct
GTY(())
2570 dw_loc_list_ref dw_loc_next
;
2571 const char *begin
; /* Label for begin address of range */
2572 const char *end
; /* Label for end address of range */
2573 char *ll_symbol
; /* Label for beginning of location list.
2574 Only on head of list */
2575 const char *section
; /* Section this loclist is relative to */
2576 dw_loc_descr_ref expr
;
2579 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2581 static const char *dwarf_stack_op_name (unsigned);
2582 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2583 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2584 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2585 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2586 static unsigned long size_of_locs (dw_loc_descr_ref
);
2587 static void output_loc_operands (dw_loc_descr_ref
);
2588 static void output_loc_sequence (dw_loc_descr_ref
);
2590 /* Convert a DWARF stack opcode into its string name. */
2593 dwarf_stack_op_name (unsigned int op
)
2598 case INTERNAL_DW_OP_tls_addr
:
2599 return "DW_OP_addr";
2601 return "DW_OP_deref";
2603 return "DW_OP_const1u";
2605 return "DW_OP_const1s";
2607 return "DW_OP_const2u";
2609 return "DW_OP_const2s";
2611 return "DW_OP_const4u";
2613 return "DW_OP_const4s";
2615 return "DW_OP_const8u";
2617 return "DW_OP_const8s";
2619 return "DW_OP_constu";
2621 return "DW_OP_consts";
2625 return "DW_OP_drop";
2627 return "DW_OP_over";
2629 return "DW_OP_pick";
2631 return "DW_OP_swap";
2635 return "DW_OP_xderef";
2643 return "DW_OP_minus";
2655 return "DW_OP_plus";
2656 case DW_OP_plus_uconst
:
2657 return "DW_OP_plus_uconst";
2663 return "DW_OP_shra";
2681 return "DW_OP_skip";
2683 return "DW_OP_lit0";
2685 return "DW_OP_lit1";
2687 return "DW_OP_lit2";
2689 return "DW_OP_lit3";
2691 return "DW_OP_lit4";
2693 return "DW_OP_lit5";
2695 return "DW_OP_lit6";
2697 return "DW_OP_lit7";
2699 return "DW_OP_lit8";
2701 return "DW_OP_lit9";
2703 return "DW_OP_lit10";
2705 return "DW_OP_lit11";
2707 return "DW_OP_lit12";
2709 return "DW_OP_lit13";
2711 return "DW_OP_lit14";
2713 return "DW_OP_lit15";
2715 return "DW_OP_lit16";
2717 return "DW_OP_lit17";
2719 return "DW_OP_lit18";
2721 return "DW_OP_lit19";
2723 return "DW_OP_lit20";
2725 return "DW_OP_lit21";
2727 return "DW_OP_lit22";
2729 return "DW_OP_lit23";
2731 return "DW_OP_lit24";
2733 return "DW_OP_lit25";
2735 return "DW_OP_lit26";
2737 return "DW_OP_lit27";
2739 return "DW_OP_lit28";
2741 return "DW_OP_lit29";
2743 return "DW_OP_lit30";
2745 return "DW_OP_lit31";
2747 return "DW_OP_reg0";
2749 return "DW_OP_reg1";
2751 return "DW_OP_reg2";
2753 return "DW_OP_reg3";
2755 return "DW_OP_reg4";
2757 return "DW_OP_reg5";
2759 return "DW_OP_reg6";
2761 return "DW_OP_reg7";
2763 return "DW_OP_reg8";
2765 return "DW_OP_reg9";
2767 return "DW_OP_reg10";
2769 return "DW_OP_reg11";
2771 return "DW_OP_reg12";
2773 return "DW_OP_reg13";
2775 return "DW_OP_reg14";
2777 return "DW_OP_reg15";
2779 return "DW_OP_reg16";
2781 return "DW_OP_reg17";
2783 return "DW_OP_reg18";
2785 return "DW_OP_reg19";
2787 return "DW_OP_reg20";
2789 return "DW_OP_reg21";
2791 return "DW_OP_reg22";
2793 return "DW_OP_reg23";
2795 return "DW_OP_reg24";
2797 return "DW_OP_reg25";
2799 return "DW_OP_reg26";
2801 return "DW_OP_reg27";
2803 return "DW_OP_reg28";
2805 return "DW_OP_reg29";
2807 return "DW_OP_reg30";
2809 return "DW_OP_reg31";
2811 return "DW_OP_breg0";
2813 return "DW_OP_breg1";
2815 return "DW_OP_breg2";
2817 return "DW_OP_breg3";
2819 return "DW_OP_breg4";
2821 return "DW_OP_breg5";
2823 return "DW_OP_breg6";
2825 return "DW_OP_breg7";
2827 return "DW_OP_breg8";
2829 return "DW_OP_breg9";
2831 return "DW_OP_breg10";
2833 return "DW_OP_breg11";
2835 return "DW_OP_breg12";
2837 return "DW_OP_breg13";
2839 return "DW_OP_breg14";
2841 return "DW_OP_breg15";
2843 return "DW_OP_breg16";
2845 return "DW_OP_breg17";
2847 return "DW_OP_breg18";
2849 return "DW_OP_breg19";
2851 return "DW_OP_breg20";
2853 return "DW_OP_breg21";
2855 return "DW_OP_breg22";
2857 return "DW_OP_breg23";
2859 return "DW_OP_breg24";
2861 return "DW_OP_breg25";
2863 return "DW_OP_breg26";
2865 return "DW_OP_breg27";
2867 return "DW_OP_breg28";
2869 return "DW_OP_breg29";
2871 return "DW_OP_breg30";
2873 return "DW_OP_breg31";
2875 return "DW_OP_regx";
2877 return "DW_OP_fbreg";
2879 return "DW_OP_bregx";
2881 return "DW_OP_piece";
2882 case DW_OP_deref_size
:
2883 return "DW_OP_deref_size";
2884 case DW_OP_xderef_size
:
2885 return "DW_OP_xderef_size";
2888 case DW_OP_push_object_address
:
2889 return "DW_OP_push_object_address";
2891 return "DW_OP_call2";
2893 return "DW_OP_call4";
2894 case DW_OP_call_ref
:
2895 return "DW_OP_call_ref";
2896 case DW_OP_GNU_push_tls_address
:
2897 return "DW_OP_GNU_push_tls_address";
2899 return "OP_<unknown>";
2903 /* Return a pointer to a newly allocated location description. Location
2904 descriptions are simple expression terms that can be strung
2905 together to form more complicated location (address) descriptions. */
2907 static inline dw_loc_descr_ref
2908 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
2909 unsigned HOST_WIDE_INT oprnd2
)
2911 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
2913 descr
->dw_loc_opc
= op
;
2914 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2915 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2916 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2917 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2923 /* Add a location description term to a location description expression. */
2926 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
2928 dw_loc_descr_ref
*d
;
2930 /* Find the end of the chain. */
2931 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2937 /* Return the size of a location descriptor. */
2939 static unsigned long
2940 size_of_loc_descr (dw_loc_descr_ref loc
)
2942 unsigned long size
= 1;
2944 switch (loc
->dw_loc_opc
)
2947 case INTERNAL_DW_OP_tls_addr
:
2948 size
+= DWARF2_ADDR_SIZE
;
2967 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2970 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2975 case DW_OP_plus_uconst
:
2976 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3014 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3017 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3020 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3023 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3024 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3027 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3029 case DW_OP_deref_size
:
3030 case DW_OP_xderef_size
:
3039 case DW_OP_call_ref
:
3040 size
+= DWARF2_ADDR_SIZE
;
3049 /* Return the size of a series of location descriptors. */
3051 static unsigned long
3052 size_of_locs (dw_loc_descr_ref loc
)
3056 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3058 loc
->dw_loc_addr
= size
;
3059 size
+= size_of_loc_descr (loc
);
3065 /* Output location description stack opcode's operands (if any). */
3068 output_loc_operands (dw_loc_descr_ref loc
)
3070 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3071 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3073 switch (loc
->dw_loc_opc
)
3075 #ifdef DWARF2_DEBUGGING_INFO
3077 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3081 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3085 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3089 if (HOST_BITS_PER_LONG
< 64)
3091 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3098 if (val1
->val_class
== dw_val_class_loc
)
3099 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3103 dw2_asm_output_data (2, offset
, NULL
);
3116 /* We currently don't make any attempt to make sure these are
3117 aligned properly like we do for the main unwind info, so
3118 don't support emitting things larger than a byte if we're
3119 only doing unwinding. */
3124 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3127 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3130 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3133 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3135 case DW_OP_plus_uconst
:
3136 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3170 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3173 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3176 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3179 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3180 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3183 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3185 case DW_OP_deref_size
:
3186 case DW_OP_xderef_size
:
3187 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3190 case INTERNAL_DW_OP_tls_addr
:
3191 #ifdef ASM_OUTPUT_DWARF_DTPREL
3192 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
3194 fputc ('\n', asm_out_file
);
3201 /* Other codes have no operands. */
3206 /* Output a sequence of location operations. */
3209 output_loc_sequence (dw_loc_descr_ref loc
)
3211 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3213 /* Output the opcode. */
3214 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3215 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3217 /* Output the operand(s) (if any). */
3218 output_loc_operands (loc
);
3222 /* This routine will generate the correct assembly data for a location
3223 description based on a cfi entry with a complex address. */
3226 output_cfa_loc (dw_cfi_ref cfi
)
3228 dw_loc_descr_ref loc
;
3231 /* Output the size of the block. */
3232 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3233 size
= size_of_locs (loc
);
3234 dw2_asm_output_data_uleb128 (size
, NULL
);
3236 /* Now output the operations themselves. */
3237 output_loc_sequence (loc
);
3240 /* This function builds a dwarf location descriptor sequence from
3241 a dw_cfa_location. */
3243 static struct dw_loc_descr_struct
*
3244 build_cfa_loc (dw_cfa_location
*cfa
)
3246 struct dw_loc_descr_struct
*head
, *tmp
;
3248 if (cfa
->indirect
== 0)
3251 if (cfa
->base_offset
)
3254 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3256 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3258 else if (cfa
->reg
<= 31)
3259 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3261 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3263 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3264 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3265 add_loc_descr (&head
, tmp
);
3266 if (cfa
->offset
!= 0)
3268 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3269 add_loc_descr (&head
, tmp
);
3275 /* This function fills in aa dw_cfa_location structure from a dwarf location
3276 descriptor sequence. */
3279 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3281 struct dw_loc_descr_struct
*ptr
;
3283 cfa
->base_offset
= 0;
3287 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3289 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3325 cfa
->reg
= op
- DW_OP_reg0
;
3328 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3362 cfa
->reg
= op
- DW_OP_breg0
;
3363 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3366 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3367 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3372 case DW_OP_plus_uconst
:
3373 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3376 internal_error ("DW_LOC_OP %s not implemented\n",
3377 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3381 #endif /* .debug_frame support */
3383 /* And now, the support for symbolic debugging information. */
3384 #ifdef DWARF2_DEBUGGING_INFO
3386 /* .debug_str support. */
3387 static int output_indirect_string (void **, void *);
3389 static void dwarf2out_init (const char *);
3390 static void dwarf2out_finish (const char *);
3391 static void dwarf2out_define (unsigned int, const char *);
3392 static void dwarf2out_undef (unsigned int, const char *);
3393 static void dwarf2out_start_source_file (unsigned, const char *);
3394 static void dwarf2out_end_source_file (unsigned);
3395 static void dwarf2out_begin_block (unsigned, unsigned);
3396 static void dwarf2out_end_block (unsigned, unsigned);
3397 static bool dwarf2out_ignore_block (tree
);
3398 static void dwarf2out_global_decl (tree
);
3399 static void dwarf2out_type_decl (tree
, int);
3400 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3401 static void dwarf2out_abstract_function (tree
);
3402 static void dwarf2out_var_location (rtx
);
3403 static void dwarf2out_begin_function (tree
);
3405 /* The debug hooks structure. */
3407 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3413 dwarf2out_start_source_file
,
3414 dwarf2out_end_source_file
,
3415 dwarf2out_begin_block
,
3416 dwarf2out_end_block
,
3417 dwarf2out_ignore_block
,
3418 dwarf2out_source_line
,
3419 dwarf2out_begin_prologue
,
3420 debug_nothing_int_charstar
, /* end_prologue */
3421 dwarf2out_end_epilogue
,
3422 dwarf2out_begin_function
,
3423 debug_nothing_int
, /* end_function */
3424 dwarf2out_decl
, /* function_decl */
3425 dwarf2out_global_decl
,
3426 dwarf2out_type_decl
, /* type_decl */
3427 dwarf2out_imported_module_or_decl
,
3428 debug_nothing_tree
, /* deferred_inline_function */
3429 /* The DWARF 2 backend tries to reduce debugging bloat by not
3430 emitting the abstract description of inline functions until
3431 something tries to reference them. */
3432 dwarf2out_abstract_function
, /* outlining_inline_function */
3433 debug_nothing_rtx
, /* label */
3434 debug_nothing_int
, /* handle_pch */
3435 dwarf2out_var_location
3439 /* NOTE: In the comments in this file, many references are made to
3440 "Debugging Information Entries". This term is abbreviated as `DIE'
3441 throughout the remainder of this file. */
3443 /* An internal representation of the DWARF output is built, and then
3444 walked to generate the DWARF debugging info. The walk of the internal
3445 representation is done after the entire program has been compiled.
3446 The types below are used to describe the internal representation. */
3448 /* Various DIE's use offsets relative to the beginning of the
3449 .debug_info section to refer to each other. */
3451 typedef long int dw_offset
;
3453 /* Define typedefs here to avoid circular dependencies. */
3455 typedef struct dw_attr_struct
*dw_attr_ref
;
3456 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3457 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3458 typedef struct pubname_struct
*pubname_ref
;
3459 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3461 /* Each entry in the line_info_table maintains the file and
3462 line number associated with the label generated for that
3463 entry. The label gives the PC value associated with
3464 the line number entry. */
3466 typedef struct dw_line_info_struct
GTY(())
3468 unsigned long dw_file_num
;
3469 unsigned long dw_line_num
;
3473 /* Line information for functions in separate sections; each one gets its
3475 typedef struct dw_separate_line_info_struct
GTY(())
3477 unsigned long dw_file_num
;
3478 unsigned long dw_line_num
;
3479 unsigned long function
;
3481 dw_separate_line_info_entry
;
3483 /* Each DIE attribute has a field specifying the attribute kind,
3484 a link to the next attribute in the chain, and an attribute value.
3485 Attributes are typically linked below the DIE they modify. */
3487 typedef struct dw_attr_struct
GTY(())
3489 enum dwarf_attribute dw_attr
;
3490 dw_attr_ref dw_attr_next
;
3491 dw_val_node dw_attr_val
;
3495 /* The Debugging Information Entry (DIE) structure */
3497 typedef struct die_struct
GTY(())
3499 enum dwarf_tag die_tag
;
3501 dw_attr_ref die_attr
;
3502 dw_die_ref die_parent
;
3503 dw_die_ref die_child
;
3505 dw_die_ref die_definition
; /* ref from a specification to its definition */
3506 dw_offset die_offset
;
3507 unsigned long die_abbrev
;
3509 unsigned int decl_id
;
3513 /* The pubname structure */
3515 typedef struct pubname_struct
GTY(())
3522 struct dw_ranges_struct
GTY(())
3527 /* The limbo die list structure. */
3528 typedef struct limbo_die_struct
GTY(())
3532 struct limbo_die_struct
*next
;
3536 /* How to start an assembler comment. */
3537 #ifndef ASM_COMMENT_START
3538 #define ASM_COMMENT_START ";#"
3541 /* Define a macro which returns nonzero for a TYPE_DECL which was
3542 implicitly generated for a tagged type.
3544 Note that unlike the gcc front end (which generates a NULL named
3545 TYPE_DECL node for each complete tagged type, each array type, and
3546 each function type node created) the g++ front end generates a
3547 _named_ TYPE_DECL node for each tagged type node created.
3548 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3549 generate a DW_TAG_typedef DIE for them. */
3551 #define TYPE_DECL_IS_STUB(decl) \
3552 (DECL_NAME (decl) == NULL_TREE \
3553 || (DECL_ARTIFICIAL (decl) \
3554 && is_tagged_type (TREE_TYPE (decl)) \
3555 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3556 /* This is necessary for stub decls that \
3557 appear in nested inline functions. */ \
3558 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3559 && (decl_ultimate_origin (decl) \
3560 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3562 /* Information concerning the compilation unit's programming
3563 language, and compiler version. */
3565 /* Fixed size portion of the DWARF compilation unit header. */
3566 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3567 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3569 /* Fixed size portion of public names info. */
3570 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3572 /* Fixed size portion of the address range info. */
3573 #define DWARF_ARANGES_HEADER_SIZE \
3574 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3575 DWARF2_ADDR_SIZE * 2) \
3576 - DWARF_INITIAL_LENGTH_SIZE)
3578 /* Size of padding portion in the address range info. It must be
3579 aligned to twice the pointer size. */
3580 #define DWARF_ARANGES_PAD_SIZE \
3581 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3582 DWARF2_ADDR_SIZE * 2) \
3583 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3585 /* Use assembler line directives if available. */
3586 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3587 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3588 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3590 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3594 /* Minimum line offset in a special line info. opcode.
3595 This value was chosen to give a reasonable range of values. */
3596 #define DWARF_LINE_BASE -10
3598 /* First special line opcode - leave room for the standard opcodes. */
3599 #define DWARF_LINE_OPCODE_BASE 10
3601 /* Range of line offsets in a special line info. opcode. */
3602 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3604 /* Flag that indicates the initial value of the is_stmt_start flag.
3605 In the present implementation, we do not mark any lines as
3606 the beginning of a source statement, because that information
3607 is not made available by the GCC front-end. */
3608 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3610 #ifdef DWARF2_DEBUGGING_INFO
3611 /* This location is used by calc_die_sizes() to keep track
3612 the offset of each DIE within the .debug_info section. */
3613 static unsigned long next_die_offset
;
3616 /* Record the root of the DIE's built for the current compilation unit. */
3617 static GTY(()) dw_die_ref comp_unit_die
;
3619 /* A list of DIEs with a NULL parent waiting to be relocated. */
3620 static GTY(()) limbo_die_node
*limbo_die_list
;
3622 /* Filenames referenced by this compilation unit. */
3623 static GTY(()) varray_type file_table
;
3624 static GTY(()) varray_type file_table_emitted
;
3625 static GTY(()) size_t file_table_last_lookup_index
;
3627 /* A hash table of references to DIE's that describe declarations.
3628 The key is a DECL_UID() which is a unique number identifying each decl. */
3629 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3631 /* Node of the variable location list. */
3632 struct var_loc_node
GTY ((chain_next ("%h.next")))
3634 rtx
GTY (()) var_loc_note
;
3635 const char * GTY (()) label
;
3636 struct var_loc_node
* GTY (()) next
;
3639 /* Variable location list. */
3640 struct var_loc_list_def
GTY (())
3642 struct var_loc_node
* GTY (()) first
;
3644 /* Do not mark the last element of the chained list because
3645 it is marked through the chain. */
3646 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3648 /* DECL_UID of the variable decl. */
3649 unsigned int decl_id
;
3651 typedef struct var_loc_list_def var_loc_list
;
3654 /* Table of decl location linked lists. */
3655 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3657 /* A pointer to the base of a list of references to DIE's that
3658 are uniquely identified by their tag, presence/absence of
3659 children DIE's, and list of attribute/value pairs. */
3660 static GTY((length ("abbrev_die_table_allocated")))
3661 dw_die_ref
*abbrev_die_table
;
3663 /* Number of elements currently allocated for abbrev_die_table. */
3664 static GTY(()) unsigned abbrev_die_table_allocated
;
3666 /* Number of elements in type_die_table currently in use. */
3667 static GTY(()) unsigned abbrev_die_table_in_use
;
3669 /* Size (in elements) of increments by which we may expand the
3670 abbrev_die_table. */
3671 #define ABBREV_DIE_TABLE_INCREMENT 256
3673 /* A pointer to the base of a table that contains line information
3674 for each source code line in .text in the compilation unit. */
3675 static GTY((length ("line_info_table_allocated")))
3676 dw_line_info_ref line_info_table
;
3678 /* Number of elements currently allocated for line_info_table. */
3679 static GTY(()) unsigned line_info_table_allocated
;
3681 /* Number of elements in line_info_table currently in use. */
3682 static GTY(()) unsigned line_info_table_in_use
;
3684 /* A pointer to the base of a table that contains line information
3685 for each source code line outside of .text in the compilation unit. */
3686 static GTY ((length ("separate_line_info_table_allocated")))
3687 dw_separate_line_info_ref separate_line_info_table
;
3689 /* Number of elements currently allocated for separate_line_info_table. */
3690 static GTY(()) unsigned separate_line_info_table_allocated
;
3692 /* Number of elements in separate_line_info_table currently in use. */
3693 static GTY(()) unsigned separate_line_info_table_in_use
;
3695 /* Size (in elements) of increments by which we may expand the
3697 #define LINE_INFO_TABLE_INCREMENT 1024
3699 /* A pointer to the base of a table that contains a list of publicly
3700 accessible names. */
3701 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3703 /* Number of elements currently allocated for pubname_table. */
3704 static GTY(()) unsigned pubname_table_allocated
;
3706 /* Number of elements in pubname_table currently in use. */
3707 static GTY(()) unsigned pubname_table_in_use
;
3709 /* Size (in elements) of increments by which we may expand the
3711 #define PUBNAME_TABLE_INCREMENT 64
3713 /* Array of dies for which we should generate .debug_arange info. */
3714 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3716 /* Number of elements currently allocated for arange_table. */
3717 static GTY(()) unsigned arange_table_allocated
;
3719 /* Number of elements in arange_table currently in use. */
3720 static GTY(()) unsigned arange_table_in_use
;
3722 /* Size (in elements) of increments by which we may expand the
3724 #define ARANGE_TABLE_INCREMENT 64
3726 /* Array of dies for which we should generate .debug_ranges info. */
3727 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3729 /* Number of elements currently allocated for ranges_table. */
3730 static GTY(()) unsigned ranges_table_allocated
;
3732 /* Number of elements in ranges_table currently in use. */
3733 static GTY(()) unsigned ranges_table_in_use
;
3735 /* Size (in elements) of increments by which we may expand the
3737 #define RANGES_TABLE_INCREMENT 64
3739 /* Whether we have location lists that need outputting */
3740 static GTY(()) unsigned have_location_lists
;
3742 /* Unique label counter. */
3743 static GTY(()) unsigned int loclabel_num
;
3745 #ifdef DWARF2_DEBUGGING_INFO
3746 /* Record whether the function being analyzed contains inlined functions. */
3747 static int current_function_has_inlines
;
3749 #if 0 && defined (MIPS_DEBUGGING_INFO)
3750 static int comp_unit_has_inlines
;
3753 /* Number of file tables emitted in maybe_emit_file(). */
3754 static GTY(()) int emitcount
= 0;
3756 /* Number of internal labels generated by gen_internal_sym(). */
3757 static GTY(()) int label_num
;
3759 #ifdef DWARF2_DEBUGGING_INFO
3761 /* Forward declarations for functions defined in this file. */
3763 static int is_pseudo_reg (rtx
);
3764 static tree
type_main_variant (tree
);
3765 static int is_tagged_type (tree
);
3766 static const char *dwarf_tag_name (unsigned);
3767 static const char *dwarf_attr_name (unsigned);
3768 static const char *dwarf_form_name (unsigned);
3770 static const char *dwarf_type_encoding_name (unsigned);
3772 static tree
decl_ultimate_origin (tree
);
3773 static tree
block_ultimate_origin (tree
);
3774 static tree
decl_class_context (tree
);
3775 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3776 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3777 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3778 static inline unsigned AT_flag (dw_attr_ref
);
3779 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3780 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3781 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3782 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3783 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3785 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3786 unsigned int, unsigned char *);
3787 static hashval_t
debug_str_do_hash (const void *);
3788 static int debug_str_eq (const void *, const void *);
3789 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3790 static inline const char *AT_string (dw_attr_ref
);
3791 static int AT_string_form (dw_attr_ref
);
3792 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3793 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3794 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3795 static inline int AT_ref_external (dw_attr_ref
);
3796 static inline void set_AT_ref_external (dw_attr_ref
, int);
3797 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3798 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3799 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3800 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3802 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3803 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3804 static inline rtx
AT_addr (dw_attr_ref
);
3805 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3806 static void add_AT_lbl_offset (dw_die_ref
, enum dwarf_attribute
, const char *);
3807 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3808 unsigned HOST_WIDE_INT
);
3809 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3811 static inline const char *AT_lbl (dw_attr_ref
);
3812 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3813 static const char *get_AT_low_pc (dw_die_ref
);
3814 static const char *get_AT_hi_pc (dw_die_ref
);
3815 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3816 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3817 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3818 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3819 static bool is_c_family (void);
3820 static bool is_cxx (void);
3821 static bool is_java (void);
3822 static bool is_fortran (void);
3823 static bool is_ada (void);
3824 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3825 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3826 static inline void free_die (dw_die_ref
);
3827 static void remove_children (dw_die_ref
);
3828 static void add_child_die (dw_die_ref
, dw_die_ref
);
3829 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3830 static dw_die_ref
lookup_type_die (tree
);
3831 static void equate_type_number_to_die (tree
, dw_die_ref
);
3832 static hashval_t
decl_die_table_hash (const void *);
3833 static int decl_die_table_eq (const void *, const void *);
3834 static dw_die_ref
lookup_decl_die (tree
);
3835 static hashval_t
decl_loc_table_hash (const void *);
3836 static int decl_loc_table_eq (const void *, const void *);
3837 static var_loc_list
*lookup_decl_loc (tree
);
3838 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3839 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
3840 static void print_spaces (FILE *);
3841 static void print_die (dw_die_ref
, FILE *);
3842 static void print_dwarf_line_table (FILE *);
3843 static void reverse_die_lists (dw_die_ref
);
3844 static void reverse_all_dies (dw_die_ref
);
3845 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3846 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3847 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3848 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3849 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3850 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3851 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
3852 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3853 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3854 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3855 static void compute_section_prefix (dw_die_ref
);
3856 static int is_type_die (dw_die_ref
);
3857 static int is_comdat_die (dw_die_ref
);
3858 static int is_symbol_die (dw_die_ref
);
3859 static void assign_symbol_names (dw_die_ref
);
3860 static void break_out_includes (dw_die_ref
);
3861 static hashval_t
htab_cu_hash (const void *);
3862 static int htab_cu_eq (const void *, const void *);
3863 static void htab_cu_del (void *);
3864 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3865 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3866 static void add_sibling_attributes (dw_die_ref
);
3867 static void build_abbrev_table (dw_die_ref
);
3868 static void output_location_lists (dw_die_ref
);
3869 static int constant_size (long unsigned);
3870 static unsigned long size_of_die (dw_die_ref
);
3871 static void calc_die_sizes (dw_die_ref
);
3872 static void mark_dies (dw_die_ref
);
3873 static void unmark_dies (dw_die_ref
);
3874 static void unmark_all_dies (dw_die_ref
);
3875 static unsigned long size_of_pubnames (void);
3876 static unsigned long size_of_aranges (void);
3877 static enum dwarf_form
value_format (dw_attr_ref
);
3878 static void output_value_format (dw_attr_ref
);
3879 static void output_abbrev_section (void);
3880 static void output_die_symbol (dw_die_ref
);
3881 static void output_die (dw_die_ref
);
3882 static void output_compilation_unit_header (void);
3883 static void output_comp_unit (dw_die_ref
, int);
3884 static const char *dwarf2_name (tree
, int);
3885 static void add_pubname (tree
, dw_die_ref
);
3886 static void output_pubnames (void);
3887 static void add_arange (tree
, dw_die_ref
);
3888 static void output_aranges (void);
3889 static unsigned int add_ranges (tree
);
3890 static void output_ranges (void);
3891 static void output_line_info (void);
3892 static void output_file_names (void);
3893 static dw_die_ref
base_type_die (tree
);
3894 static tree
root_type (tree
);
3895 static int is_base_type (tree
);
3896 static bool is_subrange_type (tree
);
3897 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
3898 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3899 static int type_is_enum (tree
);
3900 static unsigned int dbx_reg_number (rtx
);
3901 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
3902 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
3903 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
3904 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3905 static dw_loc_descr_ref
based_loc_descr (unsigned, HOST_WIDE_INT
, bool);
3906 static int is_based_loc (rtx
);
3907 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
, bool);
3908 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
3909 static dw_loc_descr_ref
loc_descriptor (rtx
, bool);
3910 static dw_loc_descr_ref
loc_descriptor_from_tree_1 (tree
, int);
3911 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
);
3912 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3913 static tree
field_type (tree
);
3914 static unsigned int simple_type_align_in_bits (tree
);
3915 static unsigned int simple_decl_align_in_bits (tree
);
3916 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
3917 static HOST_WIDE_INT
field_byte_offset (tree
);
3918 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3920 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3921 static void add_const_value_attribute (dw_die_ref
, rtx
);
3922 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3923 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
3924 static void insert_float (rtx
, unsigned char *);
3925 static rtx
rtl_for_decl_location (tree
);
3926 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
3927 enum dwarf_attribute
);
3928 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
3929 static void add_name_attribute (dw_die_ref
, const char *);
3930 static void add_comp_dir_attribute (dw_die_ref
);
3931 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3932 static void add_subscript_info (dw_die_ref
, tree
);
3933 static void add_byte_size_attribute (dw_die_ref
, tree
);
3934 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3935 static void add_bit_size_attribute (dw_die_ref
, tree
);
3936 static void add_prototyped_attribute (dw_die_ref
, tree
);
3937 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3938 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3939 static void add_src_coords_attributes (dw_die_ref
, tree
);
3940 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3941 static void push_decl_scope (tree
);
3942 static void pop_decl_scope (void);
3943 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3944 static inline int local_scope_p (dw_die_ref
);
3945 static inline int class_or_namespace_scope_p (dw_die_ref
);
3946 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3947 static const char *type_tag (tree
);
3948 static tree
member_declared_type (tree
);
3950 static const char *decl_start_label (tree
);
3952 static void gen_array_type_die (tree
, dw_die_ref
);
3953 static void gen_set_type_die (tree
, dw_die_ref
);
3955 static void gen_entry_point_die (tree
, dw_die_ref
);
3957 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
3958 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
3959 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
3960 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3961 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
3962 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3963 static void gen_formal_types_die (tree
, dw_die_ref
);
3964 static void gen_subprogram_die (tree
, dw_die_ref
);
3965 static void gen_variable_die (tree
, dw_die_ref
);
3966 static void gen_label_die (tree
, dw_die_ref
);
3967 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3968 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3969 static void gen_field_die (tree
, dw_die_ref
);
3970 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3971 static dw_die_ref
gen_compile_unit_die (const char *);
3972 static void gen_string_type_die (tree
, dw_die_ref
);
3973 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3974 static void gen_member_die (tree
, dw_die_ref
);
3975 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
3976 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3977 static void gen_typedef_die (tree
, dw_die_ref
);
3978 static void gen_type_die (tree
, dw_die_ref
);
3979 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
3980 static void gen_block_die (tree
, dw_die_ref
, int);
3981 static void decls_for_scope (tree
, dw_die_ref
, int);
3982 static int is_redundant_typedef (tree
);
3983 static void gen_namespace_die (tree
);
3984 static void gen_decl_die (tree
, dw_die_ref
);
3985 static dw_die_ref
force_decl_die (tree
);
3986 static dw_die_ref
force_type_die (tree
);
3987 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3988 static void declare_in_namespace (tree
, dw_die_ref
);
3989 static unsigned lookup_filename (const char *);
3990 static void init_file_table (void);
3991 static void retry_incomplete_types (void);
3992 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3993 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3994 static int file_info_cmp (const void *, const void *);
3995 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3996 const char *, const char *, unsigned);
3997 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
3998 const char *, const char *,
4000 static void output_loc_list (dw_loc_list_ref
);
4001 static char *gen_internal_sym (const char *);
4003 static void prune_unmark_dies (dw_die_ref
);
4004 static void prune_unused_types_mark (dw_die_ref
, int);
4005 static void prune_unused_types_walk (dw_die_ref
);
4006 static void prune_unused_types_walk_attribs (dw_die_ref
);
4007 static void prune_unused_types_prune (dw_die_ref
);
4008 static void prune_unused_types (void);
4009 static int maybe_emit_file (int);
4011 /* Section names used to hold DWARF debugging information. */
4012 #ifndef DEBUG_INFO_SECTION
4013 #define DEBUG_INFO_SECTION ".debug_info"
4015 #ifndef DEBUG_ABBREV_SECTION
4016 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4018 #ifndef DEBUG_ARANGES_SECTION
4019 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4021 #ifndef DEBUG_MACINFO_SECTION
4022 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4024 #ifndef DEBUG_LINE_SECTION
4025 #define DEBUG_LINE_SECTION ".debug_line"
4027 #ifndef DEBUG_LOC_SECTION
4028 #define DEBUG_LOC_SECTION ".debug_loc"
4030 #ifndef DEBUG_PUBNAMES_SECTION
4031 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4033 #ifndef DEBUG_STR_SECTION
4034 #define DEBUG_STR_SECTION ".debug_str"
4036 #ifndef DEBUG_RANGES_SECTION
4037 #define DEBUG_RANGES_SECTION ".debug_ranges"
4040 /* Standard ELF section names for compiled code and data. */
4041 #ifndef TEXT_SECTION_NAME
4042 #define TEXT_SECTION_NAME ".text"
4045 /* Section flags for .debug_str section. */
4046 #define DEBUG_STR_SECTION_FLAGS \
4047 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4048 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4051 /* Labels we insert at beginning sections we can reference instead of
4052 the section names themselves. */
4054 #ifndef TEXT_SECTION_LABEL
4055 #define TEXT_SECTION_LABEL "Ltext"
4057 #ifndef DEBUG_LINE_SECTION_LABEL
4058 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4060 #ifndef DEBUG_INFO_SECTION_LABEL
4061 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4063 #ifndef DEBUG_ABBREV_SECTION_LABEL
4064 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4066 #ifndef DEBUG_LOC_SECTION_LABEL
4067 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4069 #ifndef DEBUG_RANGES_SECTION_LABEL
4070 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4072 #ifndef DEBUG_MACINFO_SECTION_LABEL
4073 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4076 /* Definitions of defaults for formats and names of various special
4077 (artificial) labels which may be generated within this file (when the -g
4078 options is used and DWARF2_DEBUGGING_INFO is in effect.
4079 If necessary, these may be overridden from within the tm.h file, but
4080 typically, overriding these defaults is unnecessary. */
4082 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4083 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4084 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4085 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4086 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4087 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4088 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4089 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4091 #ifndef TEXT_END_LABEL
4092 #define TEXT_END_LABEL "Letext"
4094 #ifndef BLOCK_BEGIN_LABEL
4095 #define BLOCK_BEGIN_LABEL "LBB"
4097 #ifndef BLOCK_END_LABEL
4098 #define BLOCK_END_LABEL "LBE"
4100 #ifndef LINE_CODE_LABEL
4101 #define LINE_CODE_LABEL "LM"
4103 #ifndef SEPARATE_LINE_CODE_LABEL
4104 #define SEPARATE_LINE_CODE_LABEL "LSM"
4107 /* We allow a language front-end to designate a function that is to be
4108 called to "demangle" any name before it it put into a DIE. */
4110 static const char *(*demangle_name_func
) (const char *);
4113 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4115 demangle_name_func
= func
;
4118 /* Test if rtl node points to a pseudo register. */
4121 is_pseudo_reg (rtx rtl
)
4123 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4124 || (GET_CODE (rtl
) == SUBREG
4125 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4128 /* Return a reference to a type, with its const and volatile qualifiers
4132 type_main_variant (tree type
)
4134 type
= TYPE_MAIN_VARIANT (type
);
4136 /* ??? There really should be only one main variant among any group of
4137 variants of a given type (and all of the MAIN_VARIANT values for all
4138 members of the group should point to that one type) but sometimes the C
4139 front-end messes this up for array types, so we work around that bug
4141 if (TREE_CODE (type
) == ARRAY_TYPE
)
4142 while (type
!= TYPE_MAIN_VARIANT (type
))
4143 type
= TYPE_MAIN_VARIANT (type
);
4148 /* Return nonzero if the given type node represents a tagged type. */
4151 is_tagged_type (tree type
)
4153 enum tree_code code
= TREE_CODE (type
);
4155 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4156 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4159 /* Convert a DIE tag into its string name. */
4162 dwarf_tag_name (unsigned int tag
)
4166 case DW_TAG_padding
:
4167 return "DW_TAG_padding";
4168 case DW_TAG_array_type
:
4169 return "DW_TAG_array_type";
4170 case DW_TAG_class_type
:
4171 return "DW_TAG_class_type";
4172 case DW_TAG_entry_point
:
4173 return "DW_TAG_entry_point";
4174 case DW_TAG_enumeration_type
:
4175 return "DW_TAG_enumeration_type";
4176 case DW_TAG_formal_parameter
:
4177 return "DW_TAG_formal_parameter";
4178 case DW_TAG_imported_declaration
:
4179 return "DW_TAG_imported_declaration";
4181 return "DW_TAG_label";
4182 case DW_TAG_lexical_block
:
4183 return "DW_TAG_lexical_block";
4185 return "DW_TAG_member";
4186 case DW_TAG_pointer_type
:
4187 return "DW_TAG_pointer_type";
4188 case DW_TAG_reference_type
:
4189 return "DW_TAG_reference_type";
4190 case DW_TAG_compile_unit
:
4191 return "DW_TAG_compile_unit";
4192 case DW_TAG_string_type
:
4193 return "DW_TAG_string_type";
4194 case DW_TAG_structure_type
:
4195 return "DW_TAG_structure_type";
4196 case DW_TAG_subroutine_type
:
4197 return "DW_TAG_subroutine_type";
4198 case DW_TAG_typedef
:
4199 return "DW_TAG_typedef";
4200 case DW_TAG_union_type
:
4201 return "DW_TAG_union_type";
4202 case DW_TAG_unspecified_parameters
:
4203 return "DW_TAG_unspecified_parameters";
4204 case DW_TAG_variant
:
4205 return "DW_TAG_variant";
4206 case DW_TAG_common_block
:
4207 return "DW_TAG_common_block";
4208 case DW_TAG_common_inclusion
:
4209 return "DW_TAG_common_inclusion";
4210 case DW_TAG_inheritance
:
4211 return "DW_TAG_inheritance";
4212 case DW_TAG_inlined_subroutine
:
4213 return "DW_TAG_inlined_subroutine";
4215 return "DW_TAG_module";
4216 case DW_TAG_ptr_to_member_type
:
4217 return "DW_TAG_ptr_to_member_type";
4218 case DW_TAG_set_type
:
4219 return "DW_TAG_set_type";
4220 case DW_TAG_subrange_type
:
4221 return "DW_TAG_subrange_type";
4222 case DW_TAG_with_stmt
:
4223 return "DW_TAG_with_stmt";
4224 case DW_TAG_access_declaration
:
4225 return "DW_TAG_access_declaration";
4226 case DW_TAG_base_type
:
4227 return "DW_TAG_base_type";
4228 case DW_TAG_catch_block
:
4229 return "DW_TAG_catch_block";
4230 case DW_TAG_const_type
:
4231 return "DW_TAG_const_type";
4232 case DW_TAG_constant
:
4233 return "DW_TAG_constant";
4234 case DW_TAG_enumerator
:
4235 return "DW_TAG_enumerator";
4236 case DW_TAG_file_type
:
4237 return "DW_TAG_file_type";
4239 return "DW_TAG_friend";
4240 case DW_TAG_namelist
:
4241 return "DW_TAG_namelist";
4242 case DW_TAG_namelist_item
:
4243 return "DW_TAG_namelist_item";
4244 case DW_TAG_namespace
:
4245 return "DW_TAG_namespace";
4246 case DW_TAG_packed_type
:
4247 return "DW_TAG_packed_type";
4248 case DW_TAG_subprogram
:
4249 return "DW_TAG_subprogram";
4250 case DW_TAG_template_type_param
:
4251 return "DW_TAG_template_type_param";
4252 case DW_TAG_template_value_param
:
4253 return "DW_TAG_template_value_param";
4254 case DW_TAG_thrown_type
:
4255 return "DW_TAG_thrown_type";
4256 case DW_TAG_try_block
:
4257 return "DW_TAG_try_block";
4258 case DW_TAG_variant_part
:
4259 return "DW_TAG_variant_part";
4260 case DW_TAG_variable
:
4261 return "DW_TAG_variable";
4262 case DW_TAG_volatile_type
:
4263 return "DW_TAG_volatile_type";
4264 case DW_TAG_imported_module
:
4265 return "DW_TAG_imported_module";
4266 case DW_TAG_MIPS_loop
:
4267 return "DW_TAG_MIPS_loop";
4268 case DW_TAG_format_label
:
4269 return "DW_TAG_format_label";
4270 case DW_TAG_function_template
:
4271 return "DW_TAG_function_template";
4272 case DW_TAG_class_template
:
4273 return "DW_TAG_class_template";
4274 case DW_TAG_GNU_BINCL
:
4275 return "DW_TAG_GNU_BINCL";
4276 case DW_TAG_GNU_EINCL
:
4277 return "DW_TAG_GNU_EINCL";
4279 return "DW_TAG_<unknown>";
4283 /* Convert a DWARF attribute code into its string name. */
4286 dwarf_attr_name (unsigned int attr
)
4291 return "DW_AT_sibling";
4292 case DW_AT_location
:
4293 return "DW_AT_location";
4295 return "DW_AT_name";
4296 case DW_AT_ordering
:
4297 return "DW_AT_ordering";
4298 case DW_AT_subscr_data
:
4299 return "DW_AT_subscr_data";
4300 case DW_AT_byte_size
:
4301 return "DW_AT_byte_size";
4302 case DW_AT_bit_offset
:
4303 return "DW_AT_bit_offset";
4304 case DW_AT_bit_size
:
4305 return "DW_AT_bit_size";
4306 case DW_AT_element_list
:
4307 return "DW_AT_element_list";
4308 case DW_AT_stmt_list
:
4309 return "DW_AT_stmt_list";
4311 return "DW_AT_low_pc";
4313 return "DW_AT_high_pc";
4314 case DW_AT_language
:
4315 return "DW_AT_language";
4317 return "DW_AT_member";
4319 return "DW_AT_discr";
4320 case DW_AT_discr_value
:
4321 return "DW_AT_discr_value";
4322 case DW_AT_visibility
:
4323 return "DW_AT_visibility";
4325 return "DW_AT_import";
4326 case DW_AT_string_length
:
4327 return "DW_AT_string_length";
4328 case DW_AT_common_reference
:
4329 return "DW_AT_common_reference";
4330 case DW_AT_comp_dir
:
4331 return "DW_AT_comp_dir";
4332 case DW_AT_const_value
:
4333 return "DW_AT_const_value";
4334 case DW_AT_containing_type
:
4335 return "DW_AT_containing_type";
4336 case DW_AT_default_value
:
4337 return "DW_AT_default_value";
4339 return "DW_AT_inline";
4340 case DW_AT_is_optional
:
4341 return "DW_AT_is_optional";
4342 case DW_AT_lower_bound
:
4343 return "DW_AT_lower_bound";
4344 case DW_AT_producer
:
4345 return "DW_AT_producer";
4346 case DW_AT_prototyped
:
4347 return "DW_AT_prototyped";
4348 case DW_AT_return_addr
:
4349 return "DW_AT_return_addr";
4350 case DW_AT_start_scope
:
4351 return "DW_AT_start_scope";
4352 case DW_AT_stride_size
:
4353 return "DW_AT_stride_size";
4354 case DW_AT_upper_bound
:
4355 return "DW_AT_upper_bound";
4356 case DW_AT_abstract_origin
:
4357 return "DW_AT_abstract_origin";
4358 case DW_AT_accessibility
:
4359 return "DW_AT_accessibility";
4360 case DW_AT_address_class
:
4361 return "DW_AT_address_class";
4362 case DW_AT_artificial
:
4363 return "DW_AT_artificial";
4364 case DW_AT_base_types
:
4365 return "DW_AT_base_types";
4366 case DW_AT_calling_convention
:
4367 return "DW_AT_calling_convention";
4369 return "DW_AT_count";
4370 case DW_AT_data_member_location
:
4371 return "DW_AT_data_member_location";
4372 case DW_AT_decl_column
:
4373 return "DW_AT_decl_column";
4374 case DW_AT_decl_file
:
4375 return "DW_AT_decl_file";
4376 case DW_AT_decl_line
:
4377 return "DW_AT_decl_line";
4378 case DW_AT_declaration
:
4379 return "DW_AT_declaration";
4380 case DW_AT_discr_list
:
4381 return "DW_AT_discr_list";
4382 case DW_AT_encoding
:
4383 return "DW_AT_encoding";
4384 case DW_AT_external
:
4385 return "DW_AT_external";
4386 case DW_AT_frame_base
:
4387 return "DW_AT_frame_base";
4389 return "DW_AT_friend";
4390 case DW_AT_identifier_case
:
4391 return "DW_AT_identifier_case";
4392 case DW_AT_macro_info
:
4393 return "DW_AT_macro_info";
4394 case DW_AT_namelist_items
:
4395 return "DW_AT_namelist_items";
4396 case DW_AT_priority
:
4397 return "DW_AT_priority";
4399 return "DW_AT_segment";
4400 case DW_AT_specification
:
4401 return "DW_AT_specification";
4402 case DW_AT_static_link
:
4403 return "DW_AT_static_link";
4405 return "DW_AT_type";
4406 case DW_AT_use_location
:
4407 return "DW_AT_use_location";
4408 case DW_AT_variable_parameter
:
4409 return "DW_AT_variable_parameter";
4410 case DW_AT_virtuality
:
4411 return "DW_AT_virtuality";
4412 case DW_AT_vtable_elem_location
:
4413 return "DW_AT_vtable_elem_location";
4415 case DW_AT_allocated
:
4416 return "DW_AT_allocated";
4417 case DW_AT_associated
:
4418 return "DW_AT_associated";
4419 case DW_AT_data_location
:
4420 return "DW_AT_data_location";
4422 return "DW_AT_stride";
4423 case DW_AT_entry_pc
:
4424 return "DW_AT_entry_pc";
4425 case DW_AT_use_UTF8
:
4426 return "DW_AT_use_UTF8";
4427 case DW_AT_extension
:
4428 return "DW_AT_extension";
4430 return "DW_AT_ranges";
4431 case DW_AT_trampoline
:
4432 return "DW_AT_trampoline";
4433 case DW_AT_call_column
:
4434 return "DW_AT_call_column";
4435 case DW_AT_call_file
:
4436 return "DW_AT_call_file";
4437 case DW_AT_call_line
:
4438 return "DW_AT_call_line";
4440 case DW_AT_MIPS_fde
:
4441 return "DW_AT_MIPS_fde";
4442 case DW_AT_MIPS_loop_begin
:
4443 return "DW_AT_MIPS_loop_begin";
4444 case DW_AT_MIPS_tail_loop_begin
:
4445 return "DW_AT_MIPS_tail_loop_begin";
4446 case DW_AT_MIPS_epilog_begin
:
4447 return "DW_AT_MIPS_epilog_begin";
4448 case DW_AT_MIPS_loop_unroll_factor
:
4449 return "DW_AT_MIPS_loop_unroll_factor";
4450 case DW_AT_MIPS_software_pipeline_depth
:
4451 return "DW_AT_MIPS_software_pipeline_depth";
4452 case DW_AT_MIPS_linkage_name
:
4453 return "DW_AT_MIPS_linkage_name";
4454 case DW_AT_MIPS_stride
:
4455 return "DW_AT_MIPS_stride";
4456 case DW_AT_MIPS_abstract_name
:
4457 return "DW_AT_MIPS_abstract_name";
4458 case DW_AT_MIPS_clone_origin
:
4459 return "DW_AT_MIPS_clone_origin";
4460 case DW_AT_MIPS_has_inlines
:
4461 return "DW_AT_MIPS_has_inlines";
4463 case DW_AT_sf_names
:
4464 return "DW_AT_sf_names";
4465 case DW_AT_src_info
:
4466 return "DW_AT_src_info";
4467 case DW_AT_mac_info
:
4468 return "DW_AT_mac_info";
4469 case DW_AT_src_coords
:
4470 return "DW_AT_src_coords";
4471 case DW_AT_body_begin
:
4472 return "DW_AT_body_begin";
4473 case DW_AT_body_end
:
4474 return "DW_AT_body_end";
4475 case DW_AT_GNU_vector
:
4476 return "DW_AT_GNU_vector";
4478 case DW_AT_VMS_rtnbeg_pd_address
:
4479 return "DW_AT_VMS_rtnbeg_pd_address";
4482 return "DW_AT_<unknown>";
4486 /* Convert a DWARF value form code into its string name. */
4489 dwarf_form_name (unsigned int form
)
4494 return "DW_FORM_addr";
4495 case DW_FORM_block2
:
4496 return "DW_FORM_block2";
4497 case DW_FORM_block4
:
4498 return "DW_FORM_block4";
4500 return "DW_FORM_data2";
4502 return "DW_FORM_data4";
4504 return "DW_FORM_data8";
4505 case DW_FORM_string
:
4506 return "DW_FORM_string";
4508 return "DW_FORM_block";
4509 case DW_FORM_block1
:
4510 return "DW_FORM_block1";
4512 return "DW_FORM_data1";
4514 return "DW_FORM_flag";
4516 return "DW_FORM_sdata";
4518 return "DW_FORM_strp";
4520 return "DW_FORM_udata";
4521 case DW_FORM_ref_addr
:
4522 return "DW_FORM_ref_addr";
4524 return "DW_FORM_ref1";
4526 return "DW_FORM_ref2";
4528 return "DW_FORM_ref4";
4530 return "DW_FORM_ref8";
4531 case DW_FORM_ref_udata
:
4532 return "DW_FORM_ref_udata";
4533 case DW_FORM_indirect
:
4534 return "DW_FORM_indirect";
4536 return "DW_FORM_<unknown>";
4540 /* Convert a DWARF type code into its string name. */
4544 dwarf_type_encoding_name (unsigned enc
)
4548 case DW_ATE_address
:
4549 return "DW_ATE_address";
4550 case DW_ATE_boolean
:
4551 return "DW_ATE_boolean";
4552 case DW_ATE_complex_float
:
4553 return "DW_ATE_complex_float";
4555 return "DW_ATE_float";
4557 return "DW_ATE_signed";
4558 case DW_ATE_signed_char
:
4559 return "DW_ATE_signed_char";
4560 case DW_ATE_unsigned
:
4561 return "DW_ATE_unsigned";
4562 case DW_ATE_unsigned_char
:
4563 return "DW_ATE_unsigned_char";
4565 return "DW_ATE_<unknown>";
4570 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4571 instance of an inlined instance of a decl which is local to an inline
4572 function, so we have to trace all of the way back through the origin chain
4573 to find out what sort of node actually served as the original seed for the
4577 decl_ultimate_origin (tree decl
)
4579 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4580 nodes in the function to point to themselves; ignore that if
4581 we're trying to output the abstract instance of this function. */
4582 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4585 #ifdef ENABLE_CHECKING
4586 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4587 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4588 most distant ancestor, this should never happen. */
4592 return DECL_ABSTRACT_ORIGIN (decl
);
4595 /* Determine the "ultimate origin" of a block. The block may be an inlined
4596 instance of an inlined instance of a block which is local to an inline
4597 function, so we have to trace all of the way back through the origin chain
4598 to find out what sort of node actually served as the original seed for the
4602 block_ultimate_origin (tree block
)
4604 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4606 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4607 nodes in the function to point to themselves; ignore that if
4608 we're trying to output the abstract instance of this function. */
4609 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4612 if (immediate_origin
== NULL_TREE
)
4617 tree lookahead
= immediate_origin
;
4621 ret_val
= lookahead
;
4622 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4623 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4625 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4631 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4632 of a virtual function may refer to a base class, so we check the 'this'
4636 decl_class_context (tree decl
)
4638 tree context
= NULL_TREE
;
4640 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4641 context
= DECL_CONTEXT (decl
);
4643 context
= TYPE_MAIN_VARIANT
4644 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4646 if (context
&& !TYPE_P (context
))
4647 context
= NULL_TREE
;
4652 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4653 addition order, and correct that in reverse_all_dies. */
4656 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4658 if (die
!= NULL
&& attr
!= NULL
)
4660 attr
->dw_attr_next
= die
->die_attr
;
4661 die
->die_attr
= attr
;
4665 static inline enum dw_val_class
4666 AT_class (dw_attr_ref a
)
4668 return a
->dw_attr_val
.val_class
;
4671 /* Add a flag value attribute to a DIE. */
4674 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4676 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4678 attr
->dw_attr_next
= NULL
;
4679 attr
->dw_attr
= attr_kind
;
4680 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4681 attr
->dw_attr_val
.v
.val_flag
= flag
;
4682 add_dwarf_attr (die
, attr
);
4685 static inline unsigned
4686 AT_flag (dw_attr_ref a
)
4688 if (a
&& AT_class (a
) == dw_val_class_flag
)
4689 return a
->dw_attr_val
.v
.val_flag
;
4694 /* Add a signed integer attribute value to a DIE. */
4697 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4699 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4701 attr
->dw_attr_next
= NULL
;
4702 attr
->dw_attr
= attr_kind
;
4703 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4704 attr
->dw_attr_val
.v
.val_int
= int_val
;
4705 add_dwarf_attr (die
, attr
);
4708 static inline HOST_WIDE_INT
4709 AT_int (dw_attr_ref a
)
4711 if (a
&& AT_class (a
) == dw_val_class_const
)
4712 return a
->dw_attr_val
.v
.val_int
;
4717 /* Add an unsigned integer attribute value to a DIE. */
4720 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4721 unsigned HOST_WIDE_INT unsigned_val
)
4723 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4725 attr
->dw_attr_next
= NULL
;
4726 attr
->dw_attr
= attr_kind
;
4727 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4728 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4729 add_dwarf_attr (die
, attr
);
4732 static inline unsigned HOST_WIDE_INT
4733 AT_unsigned (dw_attr_ref a
)
4735 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4736 return a
->dw_attr_val
.v
.val_unsigned
;
4741 /* Add an unsigned double integer attribute value to a DIE. */
4744 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4745 long unsigned int val_hi
, long unsigned int val_low
)
4747 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4749 attr
->dw_attr_next
= NULL
;
4750 attr
->dw_attr
= attr_kind
;
4751 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4752 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4753 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4754 add_dwarf_attr (die
, attr
);
4757 /* Add a floating point attribute value to a DIE and return it. */
4760 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4761 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
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_vec
;
4768 attr
->dw_attr_val
.v
.val_vec
.length
= length
;
4769 attr
->dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4770 attr
->dw_attr_val
.v
.val_vec
.array
= array
;
4771 add_dwarf_attr (die
, attr
);
4774 /* Hash and equality functions for debug_str_hash. */
4777 debug_str_do_hash (const void *x
)
4779 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4783 debug_str_eq (const void *x1
, const void *x2
)
4785 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4786 (const char *)x2
) == 0;
4789 /* Add a string attribute value to a DIE. */
4792 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4794 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4795 struct indirect_string_node
*node
;
4798 if (! debug_str_hash
)
4799 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4800 debug_str_eq
, NULL
);
4802 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4803 htab_hash_string (str
), INSERT
);
4805 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4806 node
= (struct indirect_string_node
*) *slot
;
4807 node
->str
= ggc_strdup (str
);
4810 attr
->dw_attr_next
= NULL
;
4811 attr
->dw_attr
= attr_kind
;
4812 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4813 attr
->dw_attr_val
.v
.val_str
= node
;
4814 add_dwarf_attr (die
, attr
);
4817 static inline const char *
4818 AT_string (dw_attr_ref a
)
4820 if (a
&& AT_class (a
) == dw_val_class_str
)
4821 return a
->dw_attr_val
.v
.val_str
->str
;
4826 /* Find out whether a string should be output inline in DIE
4827 or out-of-line in .debug_str section. */
4830 AT_string_form (dw_attr_ref a
)
4832 if (a
&& AT_class (a
) == dw_val_class_str
)
4834 struct indirect_string_node
*node
;
4838 node
= a
->dw_attr_val
.v
.val_str
;
4842 len
= strlen (node
->str
) + 1;
4844 /* If the string is shorter or equal to the size of the reference, it is
4845 always better to put it inline. */
4846 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4847 return node
->form
= DW_FORM_string
;
4849 /* If we cannot expect the linker to merge strings in .debug_str
4850 section, only put it into .debug_str if it is worth even in this
4852 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4853 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4854 return node
->form
= DW_FORM_string
;
4856 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4857 ++dw2_string_counter
;
4858 node
->label
= xstrdup (label
);
4860 return node
->form
= DW_FORM_strp
;
4866 /* Add a DIE reference attribute value to a DIE. */
4869 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4871 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4873 attr
->dw_attr_next
= NULL
;
4874 attr
->dw_attr
= attr_kind
;
4875 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4876 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4877 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4878 add_dwarf_attr (die
, attr
);
4881 /* Add an AT_specification attribute to a DIE, and also make the back
4882 pointer from the specification to the definition. */
4885 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4887 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4888 if (targ_die
->die_definition
)
4890 targ_die
->die_definition
= die
;
4893 static inline dw_die_ref
4894 AT_ref (dw_attr_ref a
)
4896 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4897 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4903 AT_ref_external (dw_attr_ref a
)
4905 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4906 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4912 set_AT_ref_external (dw_attr_ref a
, int i
)
4914 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4915 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4920 /* Add an FDE reference attribute value to a DIE. */
4923 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4925 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4927 attr
->dw_attr_next
= NULL
;
4928 attr
->dw_attr
= attr_kind
;
4929 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4930 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4931 add_dwarf_attr (die
, attr
);
4934 /* Add a location description attribute value to a DIE. */
4937 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4939 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4941 attr
->dw_attr_next
= NULL
;
4942 attr
->dw_attr
= attr_kind
;
4943 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4944 attr
->dw_attr_val
.v
.val_loc
= loc
;
4945 add_dwarf_attr (die
, attr
);
4948 static inline dw_loc_descr_ref
4949 AT_loc (dw_attr_ref a
)
4951 if (a
&& AT_class (a
) == dw_val_class_loc
)
4952 return a
->dw_attr_val
.v
.val_loc
;
4958 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4960 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4962 attr
->dw_attr_next
= NULL
;
4963 attr
->dw_attr
= attr_kind
;
4964 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4965 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4966 add_dwarf_attr (die
, attr
);
4967 have_location_lists
= 1;
4970 static inline dw_loc_list_ref
4971 AT_loc_list (dw_attr_ref a
)
4973 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4974 return a
->dw_attr_val
.v
.val_loc_list
;
4979 /* Add an address constant attribute value to a DIE. */
4982 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4984 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4986 attr
->dw_attr_next
= NULL
;
4987 attr
->dw_attr
= attr_kind
;
4988 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4989 attr
->dw_attr_val
.v
.val_addr
= addr
;
4990 add_dwarf_attr (die
, attr
);
4994 AT_addr (dw_attr_ref a
)
4996 if (a
&& AT_class (a
) == dw_val_class_addr
)
4997 return a
->dw_attr_val
.v
.val_addr
;
5002 /* Add a label identifier attribute value to a DIE. */
5005 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5007 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5009 attr
->dw_attr_next
= NULL
;
5010 attr
->dw_attr
= attr_kind
;
5011 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5012 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5013 add_dwarf_attr (die
, attr
);
5016 /* Add a section offset attribute value to a DIE. */
5019 add_AT_lbl_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *label
)
5021 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5023 attr
->dw_attr_next
= NULL
;
5024 attr
->dw_attr
= attr_kind
;
5025 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
5026 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5027 add_dwarf_attr (die
, attr
);
5030 /* Add an offset attribute value to a DIE. */
5033 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5034 unsigned HOST_WIDE_INT offset
)
5036 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5038 attr
->dw_attr_next
= NULL
;
5039 attr
->dw_attr
= attr_kind
;
5040 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
5041 attr
->dw_attr_val
.v
.val_offset
= offset
;
5042 add_dwarf_attr (die
, attr
);
5045 /* Add an range_list attribute value to a DIE. */
5048 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5049 long unsigned int offset
)
5051 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5053 attr
->dw_attr_next
= NULL
;
5054 attr
->dw_attr
= attr_kind
;
5055 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
5056 attr
->dw_attr_val
.v
.val_offset
= offset
;
5057 add_dwarf_attr (die
, attr
);
5060 static inline const char *
5061 AT_lbl (dw_attr_ref a
)
5063 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
5064 || AT_class (a
) == dw_val_class_lbl_offset
))
5065 return a
->dw_attr_val
.v
.val_lbl_id
;
5070 /* Get the attribute of type attr_kind. */
5073 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5076 dw_die_ref spec
= NULL
;
5080 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5081 if (a
->dw_attr
== attr_kind
)
5083 else if (a
->dw_attr
== DW_AT_specification
5084 || a
->dw_attr
== DW_AT_abstract_origin
)
5088 return get_AT (spec
, attr_kind
);
5094 /* Return the "low pc" attribute value, typically associated with a subprogram
5095 DIE. Return null if the "low pc" attribute is either not present, or if it
5096 cannot be represented as an assembler label identifier. */
5098 static inline const char *
5099 get_AT_low_pc (dw_die_ref die
)
5101 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5103 return a
? AT_lbl (a
) : NULL
;
5106 /* Return the "high pc" attribute value, typically associated with a subprogram
5107 DIE. Return null if the "high pc" attribute is either not present, or if it
5108 cannot be represented as an assembler label identifier. */
5110 static inline const char *
5111 get_AT_hi_pc (dw_die_ref die
)
5113 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5115 return a
? AT_lbl (a
) : NULL
;
5118 /* Return the value of the string attribute designated by ATTR_KIND, or
5119 NULL if it is not present. */
5121 static inline const char *
5122 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5124 dw_attr_ref a
= get_AT (die
, attr_kind
);
5126 return a
? AT_string (a
) : NULL
;
5129 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5130 if it is not present. */
5133 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5135 dw_attr_ref a
= get_AT (die
, attr_kind
);
5137 return a
? AT_flag (a
) : 0;
5140 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5141 if it is not present. */
5143 static inline unsigned
5144 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5146 dw_attr_ref a
= get_AT (die
, attr_kind
);
5148 return a
? AT_unsigned (a
) : 0;
5151 static inline dw_die_ref
5152 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5154 dw_attr_ref a
= get_AT (die
, attr_kind
);
5156 return a
? AT_ref (a
) : NULL
;
5159 /* Return TRUE if the language is C or C++. */
5164 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5166 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
5167 || lang
== DW_LANG_C_plus_plus
);
5170 /* Return TRUE if the language is C++. */
5175 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
5176 == DW_LANG_C_plus_plus
);
5179 /* Return TRUE if the language is Fortran. */
5184 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5186 return (lang
== DW_LANG_Fortran77
5187 || lang
== DW_LANG_Fortran90
5188 || lang
== DW_LANG_Fortran95
);
5191 /* Return TRUE if the language is Java. */
5196 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5198 return lang
== DW_LANG_Java
;
5201 /* Return TRUE if the language is Ada. */
5206 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5208 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5211 /* Free up the memory used by A. */
5213 static inline void free_AT (dw_attr_ref
);
5215 free_AT (dw_attr_ref a
)
5217 if (AT_class (a
) == dw_val_class_str
)
5218 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5219 a
->dw_attr_val
.v
.val_str
->refcount
--;
5222 /* Remove the specified attribute if present. */
5225 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5228 dw_attr_ref removed
= NULL
;
5232 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
5233 if ((*p
)->dw_attr
== attr_kind
)
5236 *p
= (*p
)->dw_attr_next
;
5245 /* Remove child die whose die_tag is specified tag. */
5248 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5250 dw_die_ref current
, prev
, next
;
5251 current
= die
->die_child
;
5253 while (current
!= NULL
)
5255 if (current
->die_tag
== tag
)
5257 next
= current
->die_sib
;
5259 die
->die_child
= next
;
5261 prev
->die_sib
= next
;
5268 current
= current
->die_sib
;
5273 /* Free up the memory used by DIE. */
5276 free_die (dw_die_ref die
)
5278 remove_children (die
);
5281 /* Discard the children of this DIE. */
5284 remove_children (dw_die_ref die
)
5286 dw_die_ref child_die
= die
->die_child
;
5288 die
->die_child
= NULL
;
5290 while (child_die
!= NULL
)
5292 dw_die_ref tmp_die
= child_die
;
5295 child_die
= child_die
->die_sib
;
5297 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5299 dw_attr_ref tmp_a
= a
;
5301 a
= a
->dw_attr_next
;
5309 /* Add a child DIE below its parent. We build the lists up in reverse
5310 addition order, and correct that in reverse_all_dies. */
5313 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5315 if (die
!= NULL
&& child_die
!= NULL
)
5317 if (die
== child_die
)
5320 child_die
->die_parent
= die
;
5321 child_die
->die_sib
= die
->die_child
;
5322 die
->die_child
= child_die
;
5326 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5327 is the specification, to the front of PARENT's list of children. */
5330 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5334 /* We want the declaration DIE from inside the class, not the
5335 specification DIE at toplevel. */
5336 if (child
->die_parent
!= parent
)
5338 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5344 if (child
->die_parent
!= parent
5345 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5348 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5351 *p
= child
->die_sib
;
5355 child
->die_parent
= parent
;
5356 child
->die_sib
= parent
->die_child
;
5357 parent
->die_child
= child
;
5360 /* Return a pointer to a newly created DIE node. */
5362 static inline dw_die_ref
5363 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5365 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5367 die
->die_tag
= tag_value
;
5369 if (parent_die
!= NULL
)
5370 add_child_die (parent_die
, die
);
5373 limbo_die_node
*limbo_node
;
5375 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5376 limbo_node
->die
= die
;
5377 limbo_node
->created_for
= t
;
5378 limbo_node
->next
= limbo_die_list
;
5379 limbo_die_list
= limbo_node
;
5385 /* Return the DIE associated with the given type specifier. */
5387 static inline dw_die_ref
5388 lookup_type_die (tree type
)
5390 return TYPE_SYMTAB_DIE (type
);
5393 /* Equate a DIE to a given type specifier. */
5396 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5398 TYPE_SYMTAB_DIE (type
) = type_die
;
5401 /* Returns a hash value for X (which really is a die_struct). */
5404 decl_die_table_hash (const void *x
)
5406 return (hashval_t
) ((const dw_die_ref
) x
)->decl_id
;
5409 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5412 decl_die_table_eq (const void *x
, const void *y
)
5414 return (((const dw_die_ref
) x
)->decl_id
== DECL_UID ((const tree
) y
));
5417 /* Return the DIE associated with a given declaration. */
5419 static inline dw_die_ref
5420 lookup_decl_die (tree decl
)
5422 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5425 /* Returns a hash value for X (which really is a var_loc_list). */
5428 decl_loc_table_hash (const void *x
)
5430 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5433 /* Return nonzero if decl_id of var_loc_list X is the same as
5437 decl_loc_table_eq (const void *x
, const void *y
)
5439 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const tree
) y
));
5442 /* Return the var_loc list associated with a given declaration. */
5444 static inline var_loc_list
*
5445 lookup_decl_loc (tree decl
)
5447 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5450 /* Equate a DIE to a particular declaration. */
5453 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5455 unsigned int decl_id
= DECL_UID (decl
);
5458 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5460 decl_die
->decl_id
= decl_id
;
5463 /* Add a variable location node to the linked list for DECL. */
5466 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5468 unsigned int decl_id
= DECL_UID (decl
);
5472 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5475 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5476 temp
->decl_id
= decl_id
;
5484 /* If the current location is the same as the end of the list,
5485 we have nothing to do. */
5486 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5487 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5489 /* Add LOC to the end of list and update LAST. */
5490 temp
->last
->next
= loc
;
5494 /* Do not add empty location to the beginning of the list. */
5495 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5502 /* Keep track of the number of spaces used to indent the
5503 output of the debugging routines that print the structure of
5504 the DIE internal representation. */
5505 static int print_indent
;
5507 /* Indent the line the number of spaces given by print_indent. */
5510 print_spaces (FILE *outfile
)
5512 fprintf (outfile
, "%*s", print_indent
, "");
5515 /* Print the information associated with a given DIE, and its children.
5516 This routine is a debugging aid only. */
5519 print_die (dw_die_ref die
, FILE *outfile
)
5524 print_spaces (outfile
);
5525 fprintf (outfile
, "DIE %4lu: %s\n",
5526 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5527 print_spaces (outfile
);
5528 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5529 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5531 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5533 print_spaces (outfile
);
5534 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5536 switch (AT_class (a
))
5538 case dw_val_class_addr
:
5539 fprintf (outfile
, "address");
5541 case dw_val_class_offset
:
5542 fprintf (outfile
, "offset");
5544 case dw_val_class_loc
:
5545 fprintf (outfile
, "location descriptor");
5547 case dw_val_class_loc_list
:
5548 fprintf (outfile
, "location list -> label:%s",
5549 AT_loc_list (a
)->ll_symbol
);
5551 case dw_val_class_range_list
:
5552 fprintf (outfile
, "range list");
5554 case dw_val_class_const
:
5555 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5557 case dw_val_class_unsigned_const
:
5558 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5560 case dw_val_class_long_long
:
5561 fprintf (outfile
, "constant (%lu,%lu)",
5562 a
->dw_attr_val
.v
.val_long_long
.hi
,
5563 a
->dw_attr_val
.v
.val_long_long
.low
);
5565 case dw_val_class_vec
:
5566 fprintf (outfile
, "floating-point or vector constant");
5568 case dw_val_class_flag
:
5569 fprintf (outfile
, "%u", AT_flag (a
));
5571 case dw_val_class_die_ref
:
5572 if (AT_ref (a
) != NULL
)
5574 if (AT_ref (a
)->die_symbol
)
5575 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5577 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5580 fprintf (outfile
, "die -> <null>");
5582 case dw_val_class_lbl_id
:
5583 case dw_val_class_lbl_offset
:
5584 fprintf (outfile
, "label: %s", AT_lbl (a
));
5586 case dw_val_class_str
:
5587 if (AT_string (a
) != NULL
)
5588 fprintf (outfile
, "\"%s\"", AT_string (a
));
5590 fprintf (outfile
, "<null>");
5596 fprintf (outfile
, "\n");
5599 if (die
->die_child
!= NULL
)
5602 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5603 print_die (c
, outfile
);
5607 if (print_indent
== 0)
5608 fprintf (outfile
, "\n");
5611 /* Print the contents of the source code line number correspondence table.
5612 This routine is a debugging aid only. */
5615 print_dwarf_line_table (FILE *outfile
)
5618 dw_line_info_ref line_info
;
5620 fprintf (outfile
, "\n\nDWARF source line information\n");
5621 for (i
= 1; i
< line_info_table_in_use
; i
++)
5623 line_info
= &line_info_table
[i
];
5624 fprintf (outfile
, "%5d: ", i
);
5625 fprintf (outfile
, "%-20s",
5626 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5627 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5628 fprintf (outfile
, "\n");
5631 fprintf (outfile
, "\n\n");
5634 /* Print the information collected for a given DIE. */
5637 debug_dwarf_die (dw_die_ref die
)
5639 print_die (die
, stderr
);
5642 /* Print all DWARF information collected for the compilation unit.
5643 This routine is a debugging aid only. */
5649 print_die (comp_unit_die
, stderr
);
5650 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5651 print_dwarf_line_table (stderr
);
5654 /* We build up the lists of children and attributes by pushing new ones
5655 onto the beginning of the list. Reverse the lists for DIE so that
5656 they are in order of addition. */
5659 reverse_die_lists (dw_die_ref die
)
5661 dw_die_ref c
, cp
, cn
;
5662 dw_attr_ref a
, ap
, an
;
5664 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5666 an
= a
->dw_attr_next
;
5667 a
->dw_attr_next
= ap
;
5673 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5680 die
->die_child
= cp
;
5683 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5684 reverse all dies in add_sibling_attributes, which runs through all the dies,
5685 it would reverse all the dies. Now, however, since we don't call
5686 reverse_die_lists in add_sibling_attributes, we need a routine to
5687 recursively reverse all the dies. This is that routine. */
5690 reverse_all_dies (dw_die_ref die
)
5694 reverse_die_lists (die
);
5696 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5697 reverse_all_dies (c
);
5700 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5701 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5702 DIE that marks the start of the DIEs for this include file. */
5705 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5707 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5708 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5710 new_unit
->die_sib
= old_unit
;
5714 /* Close an include-file CU and reopen the enclosing one. */
5717 pop_compile_unit (dw_die_ref old_unit
)
5719 dw_die_ref new_unit
= old_unit
->die_sib
;
5721 old_unit
->die_sib
= NULL
;
5725 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5726 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5728 /* Calculate the checksum of a location expression. */
5731 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5733 CHECKSUM (loc
->dw_loc_opc
);
5734 CHECKSUM (loc
->dw_loc_oprnd1
);
5735 CHECKSUM (loc
->dw_loc_oprnd2
);
5738 /* Calculate the checksum of an attribute. */
5741 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5743 dw_loc_descr_ref loc
;
5746 CHECKSUM (at
->dw_attr
);
5748 /* We don't care about differences in file numbering. */
5749 if (at
->dw_attr
== DW_AT_decl_file
5750 /* Or that this was compiled with a different compiler snapshot; if
5751 the output is the same, that's what matters. */
5752 || at
->dw_attr
== DW_AT_producer
)
5755 switch (AT_class (at
))
5757 case dw_val_class_const
:
5758 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5760 case dw_val_class_unsigned_const
:
5761 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5763 case dw_val_class_long_long
:
5764 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5766 case dw_val_class_vec
:
5767 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5769 case dw_val_class_flag
:
5770 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5772 case dw_val_class_str
:
5773 CHECKSUM_STRING (AT_string (at
));
5776 case dw_val_class_addr
:
5778 switch (GET_CODE (r
))
5781 CHECKSUM_STRING (XSTR (r
, 0));
5789 case dw_val_class_offset
:
5790 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5793 case dw_val_class_loc
:
5794 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5795 loc_checksum (loc
, ctx
);
5798 case dw_val_class_die_ref
:
5799 die_checksum (AT_ref (at
), ctx
, mark
);
5802 case dw_val_class_fde_ref
:
5803 case dw_val_class_lbl_id
:
5804 case dw_val_class_lbl_offset
:
5812 /* Calculate the checksum of a DIE. */
5815 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5820 /* To avoid infinite recursion. */
5823 CHECKSUM (die
->die_mark
);
5826 die
->die_mark
= ++(*mark
);
5828 CHECKSUM (die
->die_tag
);
5830 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5831 attr_checksum (a
, ctx
, mark
);
5833 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5834 die_checksum (c
, ctx
, mark
);
5838 #undef CHECKSUM_STRING
5840 /* Do the location expressions look same? */
5842 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5844 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5845 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5846 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5849 /* Do the values look the same? */
5851 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
5853 dw_loc_descr_ref loc1
, loc2
;
5856 if (v1
->val_class
!= v2
->val_class
)
5859 switch (v1
->val_class
)
5861 case dw_val_class_const
:
5862 return v1
->v
.val_int
== v2
->v
.val_int
;
5863 case dw_val_class_unsigned_const
:
5864 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5865 case dw_val_class_long_long
:
5866 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5867 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5868 case dw_val_class_vec
:
5869 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
5870 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
5872 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
5873 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
5876 case dw_val_class_flag
:
5877 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5878 case dw_val_class_str
:
5879 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5881 case dw_val_class_addr
:
5882 r1
= v1
->v
.val_addr
;
5883 r2
= v2
->v
.val_addr
;
5884 if (GET_CODE (r1
) != GET_CODE (r2
))
5886 switch (GET_CODE (r1
))
5889 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5895 case dw_val_class_offset
:
5896 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5898 case dw_val_class_loc
:
5899 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5901 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5902 if (!same_loc_p (loc1
, loc2
, mark
))
5904 return !loc1
&& !loc2
;
5906 case dw_val_class_die_ref
:
5907 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5909 case dw_val_class_fde_ref
:
5910 case dw_val_class_lbl_id
:
5911 case dw_val_class_lbl_offset
:
5919 /* Do the attributes look the same? */
5922 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5924 if (at1
->dw_attr
!= at2
->dw_attr
)
5927 /* We don't care about differences in file numbering. */
5928 if (at1
->dw_attr
== DW_AT_decl_file
5929 /* Or that this was compiled with a different compiler snapshot; if
5930 the output is the same, that's what matters. */
5931 || at1
->dw_attr
== DW_AT_producer
)
5934 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5937 /* Do the dies look the same? */
5940 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5945 /* To avoid infinite recursion. */
5947 return die1
->die_mark
== die2
->die_mark
;
5948 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5950 if (die1
->die_tag
!= die2
->die_tag
)
5953 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5955 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5956 if (!same_attr_p (a1
, a2
, mark
))
5961 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5963 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5964 if (!same_die_p (c1
, c2
, mark
))
5972 /* Do the dies look the same? Wrapper around same_die_p. */
5975 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5978 int ret
= same_die_p (die1
, die2
, &mark
);
5980 unmark_all_dies (die1
);
5981 unmark_all_dies (die2
);
5986 /* The prefix to attach to symbols on DIEs in the current comdat debug
5988 static char *comdat_symbol_id
;
5990 /* The index of the current symbol within the current comdat CU. */
5991 static unsigned int comdat_symbol_number
;
5993 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5994 children, and set comdat_symbol_id accordingly. */
5997 compute_section_prefix (dw_die_ref unit_die
)
5999 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6000 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6001 char *name
= alloca (strlen (base
) + 64);
6004 unsigned char checksum
[16];
6007 /* Compute the checksum of the DIE, then append part of it as hex digits to
6008 the name filename of the unit. */
6010 md5_init_ctx (&ctx
);
6012 die_checksum (unit_die
, &ctx
, &mark
);
6013 unmark_all_dies (unit_die
);
6014 md5_finish_ctx (&ctx
, checksum
);
6016 sprintf (name
, "%s.", base
);
6017 clean_symbol_name (name
);
6019 p
= name
+ strlen (name
);
6020 for (i
= 0; i
< 4; i
++)
6022 sprintf (p
, "%.2x", checksum
[i
]);
6026 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6027 comdat_symbol_number
= 0;
6030 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6033 is_type_die (dw_die_ref die
)
6035 switch (die
->die_tag
)
6037 case DW_TAG_array_type
:
6038 case DW_TAG_class_type
:
6039 case DW_TAG_enumeration_type
:
6040 case DW_TAG_pointer_type
:
6041 case DW_TAG_reference_type
:
6042 case DW_TAG_string_type
:
6043 case DW_TAG_structure_type
:
6044 case DW_TAG_subroutine_type
:
6045 case DW_TAG_union_type
:
6046 case DW_TAG_ptr_to_member_type
:
6047 case DW_TAG_set_type
:
6048 case DW_TAG_subrange_type
:
6049 case DW_TAG_base_type
:
6050 case DW_TAG_const_type
:
6051 case DW_TAG_file_type
:
6052 case DW_TAG_packed_type
:
6053 case DW_TAG_volatile_type
:
6054 case DW_TAG_typedef
:
6061 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6062 Basically, we want to choose the bits that are likely to be shared between
6063 compilations (types) and leave out the bits that are specific to individual
6064 compilations (functions). */
6067 is_comdat_die (dw_die_ref c
)
6069 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6070 we do for stabs. The advantage is a greater likelihood of sharing between
6071 objects that don't include headers in the same order (and therefore would
6072 put the base types in a different comdat). jason 8/28/00 */
6074 if (c
->die_tag
== DW_TAG_base_type
)
6077 if (c
->die_tag
== DW_TAG_pointer_type
6078 || c
->die_tag
== DW_TAG_reference_type
6079 || c
->die_tag
== DW_TAG_const_type
6080 || c
->die_tag
== DW_TAG_volatile_type
)
6082 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6084 return t
? is_comdat_die (t
) : 0;
6087 return is_type_die (c
);
6090 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6091 compilation unit. */
6094 is_symbol_die (dw_die_ref c
)
6096 return (is_type_die (c
)
6097 || (get_AT (c
, DW_AT_declaration
)
6098 && !get_AT (c
, DW_AT_specification
)));
6102 gen_internal_sym (const char *prefix
)
6106 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6107 return xstrdup (buf
);
6110 /* Assign symbols to all worthy DIEs under DIE. */
6113 assign_symbol_names (dw_die_ref die
)
6117 if (is_symbol_die (die
))
6119 if (comdat_symbol_id
)
6121 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6123 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6124 comdat_symbol_id
, comdat_symbol_number
++);
6125 die
->die_symbol
= xstrdup (p
);
6128 die
->die_symbol
= gen_internal_sym ("LDIE");
6131 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6132 assign_symbol_names (c
);
6135 struct cu_hash_table_entry
6138 unsigned min_comdat_num
, max_comdat_num
;
6139 struct cu_hash_table_entry
*next
;
6142 /* Routines to manipulate hash table of CUs. */
6144 htab_cu_hash (const void *of
)
6146 const struct cu_hash_table_entry
*entry
= of
;
6148 return htab_hash_string (entry
->cu
->die_symbol
);
6152 htab_cu_eq (const void *of1
, const void *of2
)
6154 const struct cu_hash_table_entry
*entry1
= of1
;
6155 const struct die_struct
*entry2
= of2
;
6157 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6161 htab_cu_del (void *what
)
6163 struct cu_hash_table_entry
*next
, *entry
= what
;
6173 /* Check whether we have already seen this CU and set up SYM_NUM
6176 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6178 struct cu_hash_table_entry dummy
;
6179 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6181 dummy
.max_comdat_num
= 0;
6183 slot
= (struct cu_hash_table_entry
**)
6184 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6188 for (; entry
; last
= entry
, entry
= entry
->next
)
6190 if (same_die_p_wrap (cu
, entry
->cu
))
6196 *sym_num
= entry
->min_comdat_num
;
6200 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
6202 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6203 entry
->next
= *slot
;
6209 /* Record SYM_NUM to record of CU in HTABLE. */
6211 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6213 struct cu_hash_table_entry
**slot
, *entry
;
6215 slot
= (struct cu_hash_table_entry
**)
6216 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6220 entry
->max_comdat_num
= sym_num
;
6223 /* Traverse the DIE (which is always comp_unit_die), and set up
6224 additional compilation units for each of the include files we see
6225 bracketed by BINCL/EINCL. */
6228 break_out_includes (dw_die_ref die
)
6231 dw_die_ref unit
= NULL
;
6232 limbo_die_node
*node
, **pnode
;
6233 htab_t cu_hash_table
;
6235 for (ptr
= &(die
->die_child
); *ptr
;)
6237 dw_die_ref c
= *ptr
;
6239 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6240 || (unit
&& is_comdat_die (c
)))
6242 /* This DIE is for a secondary CU; remove it from the main one. */
6245 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6247 unit
= push_new_compile_unit (unit
, c
);
6250 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6252 unit
= pop_compile_unit (unit
);
6256 add_child_die (unit
, c
);
6260 /* Leave this DIE in the main CU. */
6261 ptr
= &(c
->die_sib
);
6267 /* We can only use this in debugging, since the frontend doesn't check
6268 to make sure that we leave every include file we enter. */
6273 assign_symbol_names (die
);
6274 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6275 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6281 compute_section_prefix (node
->die
);
6282 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6283 &comdat_symbol_number
);
6284 assign_symbol_names (node
->die
);
6286 *pnode
= node
->next
;
6289 pnode
= &node
->next
;
6290 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6291 comdat_symbol_number
);
6294 htab_delete (cu_hash_table
);
6297 /* Traverse the DIE and add a sibling attribute if it may have the
6298 effect of speeding up access to siblings. To save some space,
6299 avoid generating sibling attributes for DIE's without children. */
6302 add_sibling_attributes (dw_die_ref die
)
6306 if (die
->die_tag
!= DW_TAG_compile_unit
6307 && die
->die_sib
&& die
->die_child
!= NULL
)
6308 /* Add the sibling link to the front of the attribute list. */
6309 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6311 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6312 add_sibling_attributes (c
);
6315 /* Output all location lists for the DIE and its children. */
6318 output_location_lists (dw_die_ref die
)
6323 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6324 if (AT_class (d_attr
) == dw_val_class_loc_list
)
6325 output_loc_list (AT_loc_list (d_attr
));
6327 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6328 output_location_lists (c
);
6332 /* The format of each DIE (and its attribute value pairs) is encoded in an
6333 abbreviation table. This routine builds the abbreviation table and assigns
6334 a unique abbreviation id for each abbreviation entry. The children of each
6335 die are visited recursively. */
6338 build_abbrev_table (dw_die_ref die
)
6340 unsigned long abbrev_id
;
6341 unsigned int n_alloc
;
6343 dw_attr_ref d_attr
, a_attr
;
6345 /* Scan the DIE references, and mark as external any that refer to
6346 DIEs from other CUs (i.e. those which are not marked). */
6347 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6348 if (AT_class (d_attr
) == dw_val_class_die_ref
6349 && AT_ref (d_attr
)->die_mark
== 0)
6351 if (AT_ref (d_attr
)->die_symbol
== 0)
6354 set_AT_ref_external (d_attr
, 1);
6357 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6359 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6361 if (abbrev
->die_tag
== die
->die_tag
)
6363 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6365 a_attr
= abbrev
->die_attr
;
6366 d_attr
= die
->die_attr
;
6368 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6370 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6371 || (value_format (a_attr
) != value_format (d_attr
)))
6374 a_attr
= a_attr
->dw_attr_next
;
6375 d_attr
= d_attr
->dw_attr_next
;
6378 if (a_attr
== NULL
&& d_attr
== NULL
)
6384 if (abbrev_id
>= abbrev_die_table_in_use
)
6386 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6388 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6389 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6390 sizeof (dw_die_ref
) * n_alloc
);
6392 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6393 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6394 abbrev_die_table_allocated
= n_alloc
;
6397 ++abbrev_die_table_in_use
;
6398 abbrev_die_table
[abbrev_id
] = die
;
6401 die
->die_abbrev
= abbrev_id
;
6402 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6403 build_abbrev_table (c
);
6406 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6409 constant_size (long unsigned int value
)
6416 log
= floor_log2 (value
);
6419 log
= 1 << (floor_log2 (log
) + 1);
6424 /* Return the size of a DIE as it is represented in the
6425 .debug_info section. */
6427 static unsigned long
6428 size_of_die (dw_die_ref die
)
6430 unsigned long size
= 0;
6433 size
+= size_of_uleb128 (die
->die_abbrev
);
6434 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6436 switch (AT_class (a
))
6438 case dw_val_class_addr
:
6439 size
+= DWARF2_ADDR_SIZE
;
6441 case dw_val_class_offset
:
6442 size
+= DWARF_OFFSET_SIZE
;
6444 case dw_val_class_loc
:
6446 unsigned long lsize
= size_of_locs (AT_loc (a
));
6449 size
+= constant_size (lsize
);
6453 case dw_val_class_loc_list
:
6454 size
+= DWARF_OFFSET_SIZE
;
6456 case dw_val_class_range_list
:
6457 size
+= DWARF_OFFSET_SIZE
;
6459 case dw_val_class_const
:
6460 size
+= size_of_sleb128 (AT_int (a
));
6462 case dw_val_class_unsigned_const
:
6463 size
+= constant_size (AT_unsigned (a
));
6465 case dw_val_class_long_long
:
6466 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6468 case dw_val_class_vec
:
6469 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6470 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6472 case dw_val_class_flag
:
6475 case dw_val_class_die_ref
:
6476 if (AT_ref_external (a
))
6477 size
+= DWARF2_ADDR_SIZE
;
6479 size
+= DWARF_OFFSET_SIZE
;
6481 case dw_val_class_fde_ref
:
6482 size
+= DWARF_OFFSET_SIZE
;
6484 case dw_val_class_lbl_id
:
6485 size
+= DWARF2_ADDR_SIZE
;
6487 case dw_val_class_lbl_offset
:
6488 size
+= DWARF_OFFSET_SIZE
;
6490 case dw_val_class_str
:
6491 if (AT_string_form (a
) == DW_FORM_strp
)
6492 size
+= DWARF_OFFSET_SIZE
;
6494 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6504 /* Size the debugging information associated with a given DIE. Visits the
6505 DIE's children recursively. Updates the global variable next_die_offset, on
6506 each time through. Uses the current value of next_die_offset to update the
6507 die_offset field in each DIE. */
6510 calc_die_sizes (dw_die_ref die
)
6514 die
->die_offset
= next_die_offset
;
6515 next_die_offset
+= size_of_die (die
);
6517 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6520 if (die
->die_child
!= NULL
)
6521 /* Count the null byte used to terminate sibling lists. */
6522 next_die_offset
+= 1;
6525 /* Set the marks for a die and its children. We do this so
6526 that we know whether or not a reference needs to use FORM_ref_addr; only
6527 DIEs in the same CU will be marked. We used to clear out the offset
6528 and use that as the flag, but ran into ordering problems. */
6531 mark_dies (dw_die_ref die
)
6539 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6543 /* Clear the marks for a die and its children. */
6546 unmark_dies (dw_die_ref die
)
6554 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6558 /* Clear the marks for a die, its children and referred dies. */
6561 unmark_all_dies (dw_die_ref die
)
6570 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6571 unmark_all_dies (c
);
6573 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6574 if (AT_class (a
) == dw_val_class_die_ref
)
6575 unmark_all_dies (AT_ref (a
));
6578 /* Return the size of the .debug_pubnames table generated for the
6579 compilation unit. */
6581 static unsigned long
6582 size_of_pubnames (void)
6587 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6588 for (i
= 0; i
< pubname_table_in_use
; i
++)
6590 pubname_ref p
= &pubname_table
[i
];
6591 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6594 size
+= DWARF_OFFSET_SIZE
;
6598 /* Return the size of the information in the .debug_aranges section. */
6600 static unsigned long
6601 size_of_aranges (void)
6605 size
= DWARF_ARANGES_HEADER_SIZE
;
6607 /* Count the address/length pair for this compilation unit. */
6608 size
+= 2 * DWARF2_ADDR_SIZE
;
6609 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6611 /* Count the two zero words used to terminated the address range table. */
6612 size
+= 2 * DWARF2_ADDR_SIZE
;
6616 /* Select the encoding of an attribute value. */
6618 static enum dwarf_form
6619 value_format (dw_attr_ref a
)
6621 switch (a
->dw_attr_val
.val_class
)
6623 case dw_val_class_addr
:
6624 return DW_FORM_addr
;
6625 case dw_val_class_range_list
:
6626 case dw_val_class_offset
:
6627 if (DWARF_OFFSET_SIZE
== 4)
6628 return DW_FORM_data4
;
6629 if (DWARF_OFFSET_SIZE
== 8)
6630 return DW_FORM_data8
;
6632 case dw_val_class_loc_list
:
6633 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6634 .debug_loc section */
6635 return DW_FORM_data4
;
6636 case dw_val_class_loc
:
6637 switch (constant_size (size_of_locs (AT_loc (a
))))
6640 return DW_FORM_block1
;
6642 return DW_FORM_block2
;
6646 case dw_val_class_const
:
6647 return DW_FORM_sdata
;
6648 case dw_val_class_unsigned_const
:
6649 switch (constant_size (AT_unsigned (a
)))
6652 return DW_FORM_data1
;
6654 return DW_FORM_data2
;
6656 return DW_FORM_data4
;
6658 return DW_FORM_data8
;
6662 case dw_val_class_long_long
:
6663 return DW_FORM_block1
;
6664 case dw_val_class_vec
:
6665 return DW_FORM_block1
;
6666 case dw_val_class_flag
:
6667 return DW_FORM_flag
;
6668 case dw_val_class_die_ref
:
6669 if (AT_ref_external (a
))
6670 return DW_FORM_ref_addr
;
6673 case dw_val_class_fde_ref
:
6674 return DW_FORM_data
;
6675 case dw_val_class_lbl_id
:
6676 return DW_FORM_addr
;
6677 case dw_val_class_lbl_offset
:
6678 return DW_FORM_data
;
6679 case dw_val_class_str
:
6680 return AT_string_form (a
);
6687 /* Output the encoding of an attribute value. */
6690 output_value_format (dw_attr_ref a
)
6692 enum dwarf_form form
= value_format (a
);
6694 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6697 /* Output the .debug_abbrev section which defines the DIE abbreviation
6701 output_abbrev_section (void)
6703 unsigned long abbrev_id
;
6707 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6709 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6711 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6712 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6713 dwarf_tag_name (abbrev
->die_tag
));
6715 if (abbrev
->die_child
!= NULL
)
6716 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6718 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6720 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6721 a_attr
= a_attr
->dw_attr_next
)
6723 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6724 dwarf_attr_name (a_attr
->dw_attr
));
6725 output_value_format (a_attr
);
6728 dw2_asm_output_data (1, 0, NULL
);
6729 dw2_asm_output_data (1, 0, NULL
);
6732 /* Terminate the table. */
6733 dw2_asm_output_data (1, 0, NULL
);
6736 /* Output a symbol we can use to refer to this DIE from another CU. */
6739 output_die_symbol (dw_die_ref die
)
6741 char *sym
= die
->die_symbol
;
6746 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6747 /* We make these global, not weak; if the target doesn't support
6748 .linkonce, it doesn't support combining the sections, so debugging
6750 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
6752 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6755 /* Return a new location list, given the begin and end range, and the
6756 expression. gensym tells us whether to generate a new internal symbol for
6757 this location list node, which is done for the head of the list only. */
6759 static inline dw_loc_list_ref
6760 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6761 const char *section
, unsigned int gensym
)
6763 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6765 retlist
->begin
= begin
;
6767 retlist
->expr
= expr
;
6768 retlist
->section
= section
;
6770 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6775 /* Add a location description expression to a location list. */
6778 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6779 const char *begin
, const char *end
,
6780 const char *section
)
6784 /* Find the end of the chain. */
6785 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6788 /* Add a new location list node to the list. */
6789 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6792 /* Output the location list given to us. */
6795 output_loc_list (dw_loc_list_ref list_head
)
6797 dw_loc_list_ref curr
= list_head
;
6799 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6801 /* Walk the location list, and output each range + expression. */
6802 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6805 if (separate_line_info_table_in_use
== 0)
6807 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6808 "Location list begin address (%s)",
6809 list_head
->ll_symbol
);
6810 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6811 "Location list end address (%s)",
6812 list_head
->ll_symbol
);
6816 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
6817 "Location list begin address (%s)",
6818 list_head
->ll_symbol
);
6819 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
6820 "Location list end address (%s)",
6821 list_head
->ll_symbol
);
6823 size
= size_of_locs (curr
->expr
);
6825 /* Output the block length for this list of location operations. */
6828 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6830 output_loc_sequence (curr
->expr
);
6833 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6834 "Location list terminator begin (%s)",
6835 list_head
->ll_symbol
);
6836 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6837 "Location list terminator end (%s)",
6838 list_head
->ll_symbol
);
6841 /* Output the DIE and its attributes. Called recursively to generate
6842 the definitions of each child DIE. */
6845 output_die (dw_die_ref die
)
6851 /* If someone in another CU might refer to us, set up a symbol for
6852 them to point to. */
6853 if (die
->die_symbol
)
6854 output_die_symbol (die
);
6856 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6857 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6859 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6861 const char *name
= dwarf_attr_name (a
->dw_attr
);
6863 switch (AT_class (a
))
6865 case dw_val_class_addr
:
6866 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6869 case dw_val_class_offset
:
6870 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6874 case dw_val_class_range_list
:
6876 char *p
= strchr (ranges_section_label
, '\0');
6878 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
6879 a
->dw_attr_val
.v
.val_offset
);
6880 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6886 case dw_val_class_loc
:
6887 size
= size_of_locs (AT_loc (a
));
6889 /* Output the block length for this list of location operations. */
6890 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6892 output_loc_sequence (AT_loc (a
));
6895 case dw_val_class_const
:
6896 /* ??? It would be slightly more efficient to use a scheme like is
6897 used for unsigned constants below, but gdb 4.x does not sign
6898 extend. Gdb 5.x does sign extend. */
6899 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6902 case dw_val_class_unsigned_const
:
6903 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6904 AT_unsigned (a
), "%s", name
);
6907 case dw_val_class_long_long
:
6909 unsigned HOST_WIDE_INT first
, second
;
6911 dw2_asm_output_data (1,
6912 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6915 if (WORDS_BIG_ENDIAN
)
6917 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6918 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6922 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6923 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6926 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6927 first
, "long long constant");
6928 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6933 case dw_val_class_vec
:
6935 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
6936 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
6940 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
6941 if (elt_size
> sizeof (HOST_WIDE_INT
))
6946 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
6949 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
6950 "fp or vector constant word %u", i
);
6954 case dw_val_class_flag
:
6955 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6958 case dw_val_class_loc_list
:
6960 char *sym
= AT_loc_list (a
)->ll_symbol
;
6964 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, "%s", name
);
6968 case dw_val_class_die_ref
:
6969 if (AT_ref_external (a
))
6971 char *sym
= AT_ref (a
)->die_symbol
;
6975 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6977 else if (AT_ref (a
)->die_offset
== 0)
6980 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6984 case dw_val_class_fde_ref
:
6988 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6989 a
->dw_attr_val
.v
.val_fde_index
* 2);
6990 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6994 case dw_val_class_lbl_id
:
6995 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
6998 case dw_val_class_lbl_offset
:
6999 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
7002 case dw_val_class_str
:
7003 if (AT_string_form (a
) == DW_FORM_strp
)
7004 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7005 a
->dw_attr_val
.v
.val_str
->label
,
7006 "%s: \"%s\"", name
, AT_string (a
));
7008 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7016 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
7019 /* Add null byte to terminate sibling list. */
7020 if (die
->die_child
!= NULL
)
7021 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7025 /* Output the compilation unit that appears at the beginning of the
7026 .debug_info section, and precedes the DIE descriptions. */
7029 output_compilation_unit_header (void)
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
,
7035 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7036 "Length of Compilation Unit Info");
7037 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7038 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7039 "Offset Into Abbrev. Section");
7040 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7043 /* Output the compilation unit DIE and its children. */
7046 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7048 const char *secname
;
7051 /* Unless we are outputting main CU, we may throw away empty ones. */
7052 if (!output_if_empty
&& die
->die_child
== NULL
)
7055 /* Even if there are no children of this DIE, we must output the information
7056 about the compilation unit. Otherwise, on an empty translation unit, we
7057 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7058 will then complain when examining the file. First mark all the DIEs in
7059 this CU so we know which get local refs. */
7062 build_abbrev_table (die
);
7064 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7065 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7066 calc_die_sizes (die
);
7068 oldsym
= die
->die_symbol
;
7071 tmp
= alloca (strlen (oldsym
) + 24);
7073 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7075 die
->die_symbol
= NULL
;
7078 secname
= (const char *) DEBUG_INFO_SECTION
;
7080 /* Output debugging information. */
7081 named_section_flags (secname
, SECTION_DEBUG
);
7082 output_compilation_unit_header ();
7085 /* Leave the marks on the main CU, so we can check them in
7090 die
->die_symbol
= oldsym
;
7094 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7095 output of lang_hooks.decl_printable_name for C++ looks like
7096 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7099 dwarf2_name (tree decl
, int scope
)
7101 return lang_hooks
.decl_printable_name (decl
, scope
? 1 : 0);
7104 /* Add a new entry to .debug_pubnames if appropriate. */
7107 add_pubname (tree decl
, dw_die_ref die
)
7111 if (! TREE_PUBLIC (decl
))
7114 if (pubname_table_in_use
== pubname_table_allocated
)
7116 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
7118 = ggc_realloc (pubname_table
,
7119 (pubname_table_allocated
* sizeof (pubname_entry
)));
7120 memset (pubname_table
+ pubname_table_in_use
, 0,
7121 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
7124 p
= &pubname_table
[pubname_table_in_use
++];
7126 p
->name
= xstrdup (dwarf2_name (decl
, 1));
7129 /* Output the public names table used to speed up access to externally
7130 visible names. For now, only generate entries for externally
7131 visible procedures. */
7134 output_pubnames (void)
7137 unsigned long pubnames_length
= size_of_pubnames ();
7139 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7140 dw2_asm_output_data (4, 0xffffffff,
7141 "Initial length escape value indicating 64-bit DWARF extension");
7142 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7143 "Length of Public Names Info");
7144 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7145 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7146 "Offset of Compilation Unit Info");
7147 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7148 "Compilation Unit Length");
7150 for (i
= 0; i
< pubname_table_in_use
; i
++)
7152 pubname_ref pub
= &pubname_table
[i
];
7154 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7155 if (pub
->die
->die_mark
== 0)
7158 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7161 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7164 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7167 /* Add a new entry to .debug_aranges if appropriate. */
7170 add_arange (tree decl
, dw_die_ref die
)
7172 if (! DECL_SECTION_NAME (decl
))
7175 if (arange_table_in_use
== arange_table_allocated
)
7177 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7178 arange_table
= ggc_realloc (arange_table
,
7179 (arange_table_allocated
7180 * sizeof (dw_die_ref
)));
7181 memset (arange_table
+ arange_table_in_use
, 0,
7182 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7185 arange_table
[arange_table_in_use
++] = die
;
7188 /* Output the information that goes into the .debug_aranges table.
7189 Namely, define the beginning and ending address range of the
7190 text section generated for this compilation unit. */
7193 output_aranges (void)
7196 unsigned long aranges_length
= size_of_aranges ();
7198 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7199 dw2_asm_output_data (4, 0xffffffff,
7200 "Initial length escape value indicating 64-bit DWARF extension");
7201 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7202 "Length of Address Ranges Info");
7203 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7204 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7205 "Offset of Compilation Unit Info");
7206 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7207 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7209 /* We need to align to twice the pointer size here. */
7210 if (DWARF_ARANGES_PAD_SIZE
)
7212 /* Pad using a 2 byte words so that padding is correct for any
7214 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7215 2 * DWARF2_ADDR_SIZE
);
7216 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7217 dw2_asm_output_data (2, 0, NULL
);
7220 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7221 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7222 text_section_label
, "Length");
7224 for (i
= 0; i
< arange_table_in_use
; i
++)
7226 dw_die_ref die
= arange_table
[i
];
7228 /* We shouldn't see aranges for DIEs outside of the main CU. */
7229 if (die
->die_mark
== 0)
7232 if (die
->die_tag
== DW_TAG_subprogram
)
7234 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7236 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7237 get_AT_low_pc (die
), "Length");
7241 /* A static variable; extract the symbol from DW_AT_location.
7242 Note that this code isn't currently hit, as we only emit
7243 aranges for functions (jason 9/23/99). */
7244 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7245 dw_loc_descr_ref loc
;
7247 if (! a
|| AT_class (a
) != dw_val_class_loc
)
7251 if (loc
->dw_loc_opc
!= DW_OP_addr
)
7254 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7255 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7256 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7257 get_AT_unsigned (die
, DW_AT_byte_size
),
7262 /* Output the terminator words. */
7263 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7264 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7267 /* Add a new entry to .debug_ranges. Return the offset at which it
7271 add_ranges (tree block
)
7273 unsigned int in_use
= ranges_table_in_use
;
7275 if (in_use
== ranges_table_allocated
)
7277 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7279 = ggc_realloc (ranges_table
, (ranges_table_allocated
7280 * sizeof (struct dw_ranges_struct
)));
7281 memset (ranges_table
+ ranges_table_in_use
, 0,
7282 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7285 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7286 ranges_table_in_use
= in_use
+ 1;
7288 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7292 output_ranges (void)
7295 static const char *const start_fmt
= "Offset 0x%x";
7296 const char *fmt
= start_fmt
;
7298 for (i
= 0; i
< ranges_table_in_use
; i
++)
7300 int block_num
= ranges_table
[i
].block_num
;
7304 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7305 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7307 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7308 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7310 /* If all code is in the text section, then the compilation
7311 unit base address defaults to DW_AT_low_pc, which is the
7312 base of the text section. */
7313 if (separate_line_info_table_in_use
== 0)
7315 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7317 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7318 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7319 text_section_label
, NULL
);
7322 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7323 compilation unit base address to zero, which allows us to
7324 use absolute addresses, and not worry about whether the
7325 target supports cross-section arithmetic. */
7328 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7329 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7330 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7337 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7338 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7344 /* Data structure containing information about input files. */
7347 char *path
; /* Complete file name. */
7348 char *fname
; /* File name part. */
7349 int length
; /* Length of entire string. */
7350 int file_idx
; /* Index in input file table. */
7351 int dir_idx
; /* Index in directory table. */
7354 /* Data structure containing information about directories with source
7358 char *path
; /* Path including directory name. */
7359 int length
; /* Path length. */
7360 int prefix
; /* Index of directory entry which is a prefix. */
7361 int count
; /* Number of files in this directory. */
7362 int dir_idx
; /* Index of directory used as base. */
7363 int used
; /* Used in the end? */
7366 /* Callback function for file_info comparison. We sort by looking at
7367 the directories in the path. */
7370 file_info_cmp (const void *p1
, const void *p2
)
7372 const struct file_info
*s1
= p1
;
7373 const struct file_info
*s2
= p2
;
7377 /* Take care of file names without directories. We need to make sure that
7378 we return consistent values to qsort since some will get confused if
7379 we return the same value when identical operands are passed in opposite
7380 orders. So if neither has a directory, return 0 and otherwise return
7381 1 or -1 depending on which one has the directory. */
7382 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7383 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7385 cp1
= (unsigned char *) s1
->path
;
7386 cp2
= (unsigned char *) s2
->path
;
7392 /* Reached the end of the first path? If so, handle like above. */
7393 if ((cp1
== (unsigned char *) s1
->fname
)
7394 || (cp2
== (unsigned char *) s2
->fname
))
7395 return ((cp2
== (unsigned char *) s2
->fname
)
7396 - (cp1
== (unsigned char *) s1
->fname
));
7398 /* Character of current path component the same? */
7399 else if (*cp1
!= *cp2
)
7404 /* Output the directory table and the file name table. We try to minimize
7405 the total amount of memory needed. A heuristic is used to avoid large
7406 slowdowns with many input files. */
7409 output_file_names (void)
7411 struct file_info
*files
;
7412 struct dir_info
*dirs
;
7421 /* Handle the case where file_table is empty. */
7422 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7424 dw2_asm_output_data (1, 0, "End directory table");
7425 dw2_asm_output_data (1, 0, "End file name table");
7429 /* Allocate the various arrays we need. */
7430 files
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct file_info
));
7431 dirs
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct dir_info
));
7433 /* Sort the file names. */
7434 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7438 /* Skip all leading "./". */
7439 f
= VARRAY_CHAR_PTR (file_table
, i
);
7440 while (f
[0] == '.' && f
[1] == '/')
7443 /* Create a new array entry. */
7445 files
[i
].length
= strlen (f
);
7446 files
[i
].file_idx
= i
;
7448 /* Search for the file name part. */
7449 f
= strrchr (f
, '/');
7450 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7453 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7454 sizeof (files
[0]), file_info_cmp
);
7456 /* Find all the different directories used. */
7457 dirs
[0].path
= files
[1].path
;
7458 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7459 dirs
[0].prefix
= -1;
7461 dirs
[0].dir_idx
= 0;
7463 files
[1].dir_idx
= 0;
7466 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7467 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7468 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7469 dirs
[ndirs
- 1].length
) == 0)
7471 /* Same directory as last entry. */
7472 files
[i
].dir_idx
= ndirs
- 1;
7473 ++dirs
[ndirs
- 1].count
;
7479 /* This is a new directory. */
7480 dirs
[ndirs
].path
= files
[i
].path
;
7481 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7482 dirs
[ndirs
].count
= 1;
7483 dirs
[ndirs
].dir_idx
= ndirs
;
7484 dirs
[ndirs
].used
= 0;
7485 files
[i
].dir_idx
= ndirs
;
7487 /* Search for a prefix. */
7488 dirs
[ndirs
].prefix
= -1;
7489 for (j
= 0; j
< ndirs
; j
++)
7490 if (dirs
[j
].length
< dirs
[ndirs
].length
7491 && dirs
[j
].length
> 1
7492 && (dirs
[ndirs
].prefix
== -1
7493 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7494 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7495 dirs
[ndirs
].prefix
= j
;
7500 /* Now to the actual work. We have to find a subset of the directories which
7501 allow expressing the file name using references to the directory table
7502 with the least amount of characters. We do not do an exhaustive search
7503 where we would have to check out every combination of every single
7504 possible prefix. Instead we use a heuristic which provides nearly optimal
7505 results in most cases and never is much off. */
7506 saved
= alloca (ndirs
* sizeof (int));
7507 savehere
= alloca (ndirs
* sizeof (int));
7509 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7510 for (i
= 0; i
< ndirs
; i
++)
7515 /* We can always save some space for the current directory. But this
7516 does not mean it will be enough to justify adding the directory. */
7517 savehere
[i
] = dirs
[i
].length
;
7518 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7520 for (j
= i
+ 1; j
< ndirs
; j
++)
7523 if (saved
[j
] < dirs
[i
].length
)
7525 /* Determine whether the dirs[i] path is a prefix of the
7530 while (k
!= -1 && k
!= (int) i
)
7535 /* Yes it is. We can possibly safe some memory but
7536 writing the filenames in dirs[j] relative to
7538 savehere
[j
] = dirs
[i
].length
;
7539 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7544 /* Check whether we can safe enough to justify adding the dirs[i]
7546 if (total
> dirs
[i
].length
+ 1)
7548 /* It's worthwhile adding. */
7549 for (j
= i
; j
< ndirs
; j
++)
7550 if (savehere
[j
] > 0)
7552 /* Remember how much we saved for this directory so far. */
7553 saved
[j
] = savehere
[j
];
7555 /* Remember the prefix directory. */
7556 dirs
[j
].dir_idx
= i
;
7561 /* We have to emit them in the order they appear in the file_table array
7562 since the index is used in the debug info generation. To do this
7563 efficiently we generate a back-mapping of the indices first. */
7564 backmap
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7565 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7567 backmap
[files
[i
].file_idx
] = i
;
7569 /* Mark this directory as used. */
7570 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7573 /* That was it. We are ready to emit the information. First emit the
7574 directory name table. We have to make sure the first actually emitted
7575 directory name has index one; zero is reserved for the current working
7576 directory. Make sure we do not confuse these indices with the one for the
7577 constructed table (even though most of the time they are identical). */
7579 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7580 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7581 if (dirs
[i
].used
!= 0)
7583 dirs
[i
].used
= idx
++;
7584 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7585 "Directory Entry: 0x%x", dirs
[i
].used
);
7588 dw2_asm_output_data (1, 0, "End directory table");
7590 /* Correct the index for the current working directory entry if it
7592 if (idx_offset
== 0)
7595 /* Now write all the file names. */
7596 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7598 int file_idx
= backmap
[i
];
7599 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7601 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7602 "File Entry: 0x%lx", (unsigned long) i
);
7604 /* Include directory index. */
7605 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7607 /* Modification time. */
7608 dw2_asm_output_data_uleb128 (0, NULL
);
7610 /* File length in bytes. */
7611 dw2_asm_output_data_uleb128 (0, NULL
);
7614 dw2_asm_output_data (1, 0, "End file name table");
7618 /* Output the source line number correspondence information. This
7619 information goes into the .debug_line section. */
7622 output_line_info (void)
7624 char l1
[20], l2
[20], p1
[20], p2
[20];
7625 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7626 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7629 unsigned long lt_index
;
7630 unsigned long current_line
;
7633 unsigned long current_file
;
7634 unsigned long function
;
7636 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7637 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7638 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7639 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7641 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7642 dw2_asm_output_data (4, 0xffffffff,
7643 "Initial length escape value indicating 64-bit DWARF extension");
7644 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7645 "Length of Source Line Info");
7646 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7648 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7649 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7650 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7652 /* Define the architecture-dependent minimum instruction length (in
7653 bytes). In this implementation of DWARF, this field is used for
7654 information purposes only. Since GCC generates assembly language,
7655 we have no a priori knowledge of how many instruction bytes are
7656 generated for each source line, and therefore can use only the
7657 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7658 commands. Accordingly, we fix this as `1', which is "correct
7659 enough" for all architectures, and don't let the target override. */
7660 dw2_asm_output_data (1, 1,
7661 "Minimum Instruction Length");
7663 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7664 "Default is_stmt_start flag");
7665 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7666 "Line Base Value (Special Opcodes)");
7667 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7668 "Line Range Value (Special Opcodes)");
7669 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7670 "Special Opcode Base");
7672 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7676 case DW_LNS_advance_pc
:
7677 case DW_LNS_advance_line
:
7678 case DW_LNS_set_file
:
7679 case DW_LNS_set_column
:
7680 case DW_LNS_fixed_advance_pc
:
7688 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7692 /* Write out the information about the files we use. */
7693 output_file_names ();
7694 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7696 /* We used to set the address register to the first location in the text
7697 section here, but that didn't accomplish anything since we already
7698 have a line note for the opening brace of the first function. */
7700 /* Generate the line number to PC correspondence table, encoded as
7701 a series of state machine operations. */
7704 strcpy (prev_line_label
, text_section_label
);
7705 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7707 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7710 /* Disable this optimization for now; GDB wants to see two line notes
7711 at the beginning of a function so it can find the end of the
7714 /* Don't emit anything for redundant notes. Just updating the
7715 address doesn't accomplish anything, because we already assume
7716 that anything after the last address is this line. */
7717 if (line_info
->dw_line_num
== current_line
7718 && line_info
->dw_file_num
== current_file
)
7722 /* Emit debug info for the address of the current line.
7724 Unfortunately, we have little choice here currently, and must always
7725 use the most general form. GCC does not know the address delta
7726 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7727 attributes which will give an upper bound on the address range. We
7728 could perhaps use length attributes to determine when it is safe to
7729 use DW_LNS_fixed_advance_pc. */
7731 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7734 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7735 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7736 "DW_LNS_fixed_advance_pc");
7737 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7741 /* This can handle any delta. This takes
7742 4+DWARF2_ADDR_SIZE bytes. */
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
);
7749 strcpy (prev_line_label
, line_label
);
7751 /* Emit debug info for the source file of the current line, if
7752 different from the previous line. */
7753 if (line_info
->dw_file_num
!= current_file
)
7755 current_file
= line_info
->dw_file_num
;
7756 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7757 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7758 VARRAY_CHAR_PTR (file_table
,
7762 /* Emit debug info for the current line number, choosing the encoding
7763 that uses the least amount of space. */
7764 if (line_info
->dw_line_num
!= current_line
)
7766 line_offset
= line_info
->dw_line_num
- current_line
;
7767 line_delta
= line_offset
- DWARF_LINE_BASE
;
7768 current_line
= line_info
->dw_line_num
;
7769 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7770 /* This can handle deltas from -10 to 234, using the current
7771 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7773 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7774 "line %lu", current_line
);
7777 /* This can handle any delta. This takes at least 4 bytes,
7778 depending on the value being encoded. */
7779 dw2_asm_output_data (1, DW_LNS_advance_line
,
7780 "advance to line %lu", current_line
);
7781 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7782 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7786 /* We still need to start a new row, so output a copy insn. */
7787 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7790 /* Emit debug info for the address of the end of the function. */
7793 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7794 "DW_LNS_fixed_advance_pc");
7795 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7799 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7800 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7801 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7802 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7805 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7806 dw2_asm_output_data_uleb128 (1, NULL
);
7807 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7812 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7814 dw_separate_line_info_ref line_info
7815 = &separate_line_info_table
[lt_index
];
7818 /* Don't emit anything for redundant notes. */
7819 if (line_info
->dw_line_num
== current_line
7820 && line_info
->dw_file_num
== current_file
7821 && line_info
->function
== function
)
7825 /* Emit debug info for the address of the current line. If this is
7826 a new function, or the first line of a function, then we need
7827 to handle it differently. */
7828 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7830 if (function
!= line_info
->function
)
7832 function
= line_info
->function
;
7834 /* Set the address register to the first line in the function. */
7835 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7836 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7837 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7838 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7842 /* ??? See the DW_LNS_advance_pc comment above. */
7845 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7846 "DW_LNS_fixed_advance_pc");
7847 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7851 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7852 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7853 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7854 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7858 strcpy (prev_line_label
, line_label
);
7860 /* Emit debug info for the source file of the current line, if
7861 different from the previous line. */
7862 if (line_info
->dw_file_num
!= current_file
)
7864 current_file
= line_info
->dw_file_num
;
7865 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7866 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7867 VARRAY_CHAR_PTR (file_table
,
7871 /* Emit debug info for the current line number, choosing the encoding
7872 that uses the least amount of space. */
7873 if (line_info
->dw_line_num
!= current_line
)
7875 line_offset
= line_info
->dw_line_num
- current_line
;
7876 line_delta
= line_offset
- DWARF_LINE_BASE
;
7877 current_line
= line_info
->dw_line_num
;
7878 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7879 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7880 "line %lu", current_line
);
7883 dw2_asm_output_data (1, DW_LNS_advance_line
,
7884 "advance to line %lu", current_line
);
7885 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7886 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7890 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7898 /* If we're done with a function, end its sequence. */
7899 if (lt_index
== separate_line_info_table_in_use
7900 || separate_line_info_table
[lt_index
].function
!= function
)
7905 /* Emit debug info for the address of the end of the function. */
7906 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7909 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7910 "DW_LNS_fixed_advance_pc");
7911 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7915 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7916 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7917 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7918 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7921 /* Output the marker for the end of this sequence. */
7922 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7923 dw2_asm_output_data_uleb128 (1, NULL
);
7924 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7928 /* Output the marker for the end of the line number info. */
7929 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7932 /* Given a pointer to a tree node for some base type, return a pointer to
7933 a DIE that describes the given type.
7935 This routine must only be called for GCC type nodes that correspond to
7936 Dwarf base (fundamental) types. */
7939 base_type_die (tree type
)
7941 dw_die_ref base_type_result
;
7942 const char *type_name
;
7943 enum dwarf_type encoding
;
7944 tree name
= TYPE_NAME (type
);
7946 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7951 if (TREE_CODE (name
) == TYPE_DECL
)
7952 name
= DECL_NAME (name
);
7954 type_name
= IDENTIFIER_POINTER (name
);
7957 type_name
= "__unknown__";
7959 switch (TREE_CODE (type
))
7962 /* Carefully distinguish the C character types, without messing
7963 up if the language is not C. Note that we check only for the names
7964 that contain spaces; other names might occur by coincidence in other
7966 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7967 && (type
== char_type_node
7968 || ! strcmp (type_name
, "signed char")
7969 || ! strcmp (type_name
, "unsigned char"))))
7971 if (TYPE_UNSIGNED (type
))
7972 encoding
= DW_ATE_unsigned
;
7974 encoding
= DW_ATE_signed
;
7977 /* else fall through. */
7980 /* GNU Pascal/Ada CHAR type. Not used in C. */
7981 if (TYPE_UNSIGNED (type
))
7982 encoding
= DW_ATE_unsigned_char
;
7984 encoding
= DW_ATE_signed_char
;
7988 encoding
= DW_ATE_float
;
7991 /* Dwarf2 doesn't know anything about complex ints, so use
7992 a user defined type for it. */
7994 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7995 encoding
= DW_ATE_complex_float
;
7997 encoding
= DW_ATE_lo_user
;
8001 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8002 encoding
= DW_ATE_boolean
;
8006 /* No other TREE_CODEs are Dwarf fundamental types. */
8010 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8011 if (demangle_name_func
)
8012 type_name
= (*demangle_name_func
) (type_name
);
8014 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
8015 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8016 int_size_in_bytes (type
));
8017 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8019 return base_type_result
;
8022 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8023 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8024 a given type is generally the same as the given type, except that if the
8025 given type is a pointer or reference type, then the root type of the given
8026 type is the root type of the "basis" type for the pointer or reference
8027 type. (This definition of the "root" type is recursive.) Also, the root
8028 type of a `const' qualified type or a `volatile' qualified type is the
8029 root type of the given type without the qualifiers. */
8032 root_type (tree type
)
8034 if (TREE_CODE (type
) == ERROR_MARK
)
8035 return error_mark_node
;
8037 switch (TREE_CODE (type
))
8040 return error_mark_node
;
8043 case REFERENCE_TYPE
:
8044 return type_main_variant (root_type (TREE_TYPE (type
)));
8047 return type_main_variant (type
);
8051 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8052 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8055 is_base_type (tree type
)
8057 switch (TREE_CODE (type
))
8072 case QUAL_UNION_TYPE
:
8077 case REFERENCE_TYPE
:
8091 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8092 node, return the size in bits for the type if it is a constant, or else
8093 return the alignment for the type if the type's size is not constant, or
8094 else return BITS_PER_WORD if the type actually turns out to be an
8097 static inline unsigned HOST_WIDE_INT
8098 simple_type_size_in_bits (tree type
)
8100 if (TREE_CODE (type
) == ERROR_MARK
)
8101 return BITS_PER_WORD
;
8102 else if (TYPE_SIZE (type
) == NULL_TREE
)
8104 else if (host_integerp (TYPE_SIZE (type
), 1))
8105 return tree_low_cst (TYPE_SIZE (type
), 1);
8107 return TYPE_ALIGN (type
);
8110 /* Return true if the debug information for the given type should be
8111 emitted as a subrange type. */
8114 is_subrange_type (tree type
)
8116 tree subtype
= TREE_TYPE (type
);
8118 /* Subrange types are identified by the fact that they are integer
8119 types, and that they have a subtype which is either an integer type
8120 or an enumeral type. */
8122 if (TREE_CODE (type
) != INTEGER_TYPE
8123 || subtype
== NULL_TREE
)
8126 if (TREE_CODE (subtype
) != INTEGER_TYPE
8127 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8130 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8131 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8132 && TYPE_MIN_VALUE (type
) != NULL
8133 && TYPE_MIN_VALUE (subtype
) != NULL
8134 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8135 && TYPE_MAX_VALUE (type
) != NULL
8136 && TYPE_MAX_VALUE (subtype
) != NULL
8137 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8139 /* The type and its subtype have the same representation. If in
8140 addition the two types also have the same name, then the given
8141 type is not a subrange type, but rather a plain base type. */
8142 /* FIXME: brobecker/2004-03-22:
8143 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8144 therefore be sufficient to check the TYPE_SIZE node pointers
8145 rather than checking the actual size. Unfortunately, we have
8146 found some cases, such as in the Ada "integer" type, where
8147 this is not the case. Until this problem is solved, we need to
8148 keep checking the actual size. */
8149 tree type_name
= TYPE_NAME (type
);
8150 tree subtype_name
= TYPE_NAME (subtype
);
8152 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8153 type_name
= DECL_NAME (type_name
);
8155 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8156 subtype_name
= DECL_NAME (subtype_name
);
8158 if (type_name
== subtype_name
)
8165 /* Given a pointer to a tree node for a subrange type, return a pointer
8166 to a DIE that describes the given type. */
8169 subrange_type_die (tree type
, dw_die_ref context_die
)
8171 dw_die_ref subtype_die
;
8172 dw_die_ref subrange_die
;
8173 tree name
= TYPE_NAME (type
);
8174 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8175 tree subtype
= TREE_TYPE (type
);
8177 if (context_die
== NULL
)
8178 context_die
= comp_unit_die
;
8180 if (TREE_CODE (subtype
) == ENUMERAL_TYPE
)
8181 subtype_die
= gen_enumeration_type_die (subtype
, context_die
);
8183 subtype_die
= base_type_die (subtype
);
8185 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8189 if (TREE_CODE (name
) == TYPE_DECL
)
8190 name
= DECL_NAME (name
);
8191 add_name_attribute (subrange_die
, IDENTIFIER_POINTER (name
));
8194 if (int_size_in_bytes (subtype
) != size_in_bytes
)
8196 /* The size of the subrange type and its base type do not match,
8197 so we need to generate a size attribute for the subrange type. */
8198 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8201 if (TYPE_MIN_VALUE (type
) != NULL
)
8202 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8203 TYPE_MIN_VALUE (type
));
8204 if (TYPE_MAX_VALUE (type
) != NULL
)
8205 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8206 TYPE_MAX_VALUE (type
));
8207 add_AT_die_ref (subrange_die
, DW_AT_type
, subtype_die
);
8209 return subrange_die
;
8212 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8213 entry that chains various modifiers in front of the given type. */
8216 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8217 dw_die_ref context_die
)
8219 enum tree_code code
= TREE_CODE (type
);
8220 dw_die_ref mod_type_die
= NULL
;
8221 dw_die_ref sub_die
= NULL
;
8222 tree item_type
= NULL
;
8224 if (code
!= ERROR_MARK
)
8226 tree qualified_type
;
8228 /* See if we already have the appropriately qualified variant of
8231 = get_qualified_type (type
,
8232 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8234 ? TYPE_QUAL_VOLATILE
: 0)));
8236 /* If we do, then we can just use its DIE, if it exists. */
8239 mod_type_die
= lookup_type_die (qualified_type
);
8241 return mod_type_die
;
8244 /* Handle C typedef types. */
8245 if (qualified_type
&& TYPE_NAME (qualified_type
)
8246 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
8247 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
8249 tree type_name
= TYPE_NAME (qualified_type
);
8250 tree dtype
= TREE_TYPE (type_name
);
8252 if (qualified_type
== dtype
)
8254 /* For a named type, use the typedef. */
8255 gen_type_die (qualified_type
, context_die
);
8256 mod_type_die
= lookup_type_die (qualified_type
);
8258 else if (is_const_type
< TYPE_READONLY (dtype
)
8259 || is_volatile_type
< TYPE_VOLATILE (dtype
))
8260 /* cv-unqualified version of named type. Just use the unnamed
8261 type to which it refers. */
8263 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
8264 is_const_type
, is_volatile_type
,
8267 /* Else cv-qualified version of named type; fall through. */
8273 else if (is_const_type
)
8275 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8276 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8278 else if (is_volatile_type
)
8280 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8281 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8283 else if (code
== POINTER_TYPE
)
8285 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8286 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8287 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8289 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
8291 item_type
= TREE_TYPE (type
);
8293 else if (code
== REFERENCE_TYPE
)
8295 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8296 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8297 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8299 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
8301 item_type
= TREE_TYPE (type
);
8303 else if (is_subrange_type (type
))
8304 mod_type_die
= subrange_type_die (type
, context_die
);
8305 else if (is_base_type (type
))
8306 mod_type_die
= base_type_die (type
);
8309 gen_type_die (type
, context_die
);
8311 /* We have to get the type_main_variant here (and pass that to the
8312 `lookup_type_die' routine) because the ..._TYPE node we have
8313 might simply be a *copy* of some original type node (where the
8314 copy was created to help us keep track of typedef names) and
8315 that copy might have a different TYPE_UID from the original
8317 if (TREE_CODE (type
) != VECTOR_TYPE
)
8318 mod_type_die
= lookup_type_die (type_main_variant (type
));
8320 /* Vectors have the debugging information in the type,
8321 not the main variant. */
8322 mod_type_die
= lookup_type_die (type
);
8323 if (mod_type_die
== NULL
)
8327 /* We want to equate the qualified type to the die below. */
8328 type
= qualified_type
;
8332 equate_type_number_to_die (type
, mod_type_die
);
8334 /* We must do this after the equate_type_number_to_die call, in case
8335 this is a recursive type. This ensures that the modified_type_die
8336 recursion will terminate even if the type is recursive. Recursive
8337 types are possible in Ada. */
8338 sub_die
= modified_type_die (item_type
,
8339 TYPE_READONLY (item_type
),
8340 TYPE_VOLATILE (item_type
),
8343 if (sub_die
!= NULL
)
8344 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8346 return mod_type_die
;
8349 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8350 an enumerated type. */
8353 type_is_enum (tree type
)
8355 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8358 /* Return the DBX register number described by a given RTL node. */
8361 dbx_reg_number (rtx rtl
)
8363 unsigned regno
= REGNO (rtl
);
8365 if (regno
>= FIRST_PSEUDO_REGISTER
)
8368 return DBX_REGISTER_NUMBER (regno
);
8371 /* Return a location descriptor that designates a machine register or
8372 zero if there is none. */
8374 static dw_loc_descr_ref
8375 reg_loc_descriptor (rtx rtl
)
8380 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8383 reg
= dbx_reg_number (rtl
);
8384 regs
= targetm
.dwarf_register_span (rtl
);
8386 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1
8388 return multiple_reg_loc_descriptor (rtl
, regs
);
8390 return one_reg_loc_descriptor (reg
);
8393 /* Return a location descriptor that designates a machine register for
8394 a given hard register number. */
8396 static dw_loc_descr_ref
8397 one_reg_loc_descriptor (unsigned int regno
)
8400 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8402 return new_loc_descr (DW_OP_regx
, regno
, 0);
8405 /* Given an RTL of a register, return a location descriptor that
8406 designates a value that spans more than one register. */
8408 static dw_loc_descr_ref
8409 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
8413 dw_loc_descr_ref loc_result
= NULL
;
8415 reg
= dbx_reg_number (rtl
);
8416 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8418 /* Simple, contiguous registers. */
8419 if (regs
== NULL_RTX
)
8421 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8428 t
= one_reg_loc_descriptor (reg
);
8429 add_loc_descr (&loc_result
, t
);
8430 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8436 /* Now onto stupid register sets in non contiguous locations. */
8438 if (GET_CODE (regs
) != PARALLEL
)
8441 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8444 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8448 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8449 add_loc_descr (&loc_result
, t
);
8450 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8451 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8456 /* Return a location descriptor that designates a constant. */
8458 static dw_loc_descr_ref
8459 int_loc_descriptor (HOST_WIDE_INT i
)
8461 enum dwarf_location_atom op
;
8463 /* Pick the smallest representation of a constant, rather than just
8464 defaulting to the LEB encoding. */
8468 op
= DW_OP_lit0
+ i
;
8471 else if (i
<= 0xffff)
8473 else if (HOST_BITS_PER_WIDE_INT
== 32
8483 else if (i
>= -0x8000)
8485 else if (HOST_BITS_PER_WIDE_INT
== 32
8486 || i
>= -0x80000000)
8492 return new_loc_descr (op
, i
, 0);
8495 /* Return a location descriptor that designates a base+offset location. */
8497 static dw_loc_descr_ref
8498 based_loc_descr (unsigned int reg
, HOST_WIDE_INT offset
, bool can_use_fbreg
)
8500 dw_loc_descr_ref loc_result
;
8501 /* For the "frame base", we use the frame pointer or stack pointer
8502 registers, since the RTL for local variables is relative to one of
8504 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8505 ? HARD_FRAME_POINTER_REGNUM
8506 : STACK_POINTER_REGNUM
);
8508 if (reg
== fp_reg
&& can_use_fbreg
)
8509 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8511 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8513 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8518 /* Return true if this RTL expression describes a base+offset calculation. */
8521 is_based_loc (rtx rtl
)
8523 return (GET_CODE (rtl
) == PLUS
8524 && ((REG_P (XEXP (rtl
, 0))
8525 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8526 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8529 /* The following routine converts the RTL for a variable or parameter
8530 (resident in memory) into an equivalent Dwarf representation of a
8531 mechanism for getting the address of that same variable onto the top of a
8532 hypothetical "address evaluation" stack.
8534 When creating memory location descriptors, we are effectively transforming
8535 the RTL for a memory-resident object into its Dwarf postfix expression
8536 equivalent. This routine recursively descends an RTL tree, turning
8537 it into Dwarf postfix code as it goes.
8539 MODE is the mode of the memory reference, needed to handle some
8540 autoincrement addressing modes.
8542 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location
8543 list for RTL. We can't use it when we are emitting location list for
8544 virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base)
8545 which describes how frame base changes when !frame_pointer_needed.
8547 Return 0 if we can't represent the location. */
8549 static dw_loc_descr_ref
8550 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
, bool can_use_fbreg
)
8552 dw_loc_descr_ref mem_loc_result
= NULL
;
8553 enum dwarf_location_atom op
;
8555 /* Note that for a dynamically sized array, the location we will generate a
8556 description of here will be the lowest numbered location which is
8557 actually within the array. That's *not* necessarily the same as the
8558 zeroth element of the array. */
8560 rtl
= targetm
.delegitimize_address (rtl
);
8562 switch (GET_CODE (rtl
))
8567 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8568 just fall into the SUBREG code. */
8570 /* ... fall through ... */
8573 /* The case of a subreg may arise when we have a local (register)
8574 variable or a formal (register) parameter which doesn't quite fill
8575 up an entire register. For now, just assume that it is
8576 legitimate to make the Dwarf info refer to the whole register which
8577 contains the given subreg. */
8578 rtl
= SUBREG_REG (rtl
);
8580 /* ... fall through ... */
8583 /* Whenever a register number forms a part of the description of the
8584 method for calculating the (dynamic) address of a memory resident
8585 object, DWARF rules require the register number be referred to as
8586 a "base register". This distinction is not based in any way upon
8587 what category of register the hardware believes the given register
8588 belongs to. This is strictly DWARF terminology we're dealing with
8589 here. Note that in cases where the location of a memory-resident
8590 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8591 OP_CONST (0)) the actual DWARF location descriptor that we generate
8592 may just be OP_BASEREG (basereg). This may look deceptively like
8593 the object in question was allocated to a register (rather than in
8594 memory) so DWARF consumers need to be aware of the subtle
8595 distinction between OP_REG and OP_BASEREG. */
8596 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8597 mem_loc_result
= based_loc_descr (dbx_reg_number (rtl
), 0,
8602 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
8604 if (mem_loc_result
!= 0)
8605 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8609 rtl
= XEXP (rtl
, 1);
8611 /* ... fall through ... */
8614 /* Some ports can transform a symbol ref into a label ref, because
8615 the symbol ref is too far away and has to be dumped into a constant
8619 /* Alternatively, the symbol in the constant pool might be referenced
8620 by a different symbol. */
8621 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8624 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8626 if (GET_CODE (tmp
) == SYMBOL_REF
)
8629 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8630 get_pool_constant_mark (tmp
, &marked
);
8635 /* If all references to this pool constant were optimized away,
8636 it was not output and thus we can't represent it.
8637 FIXME: might try to use DW_OP_const_value here, though
8638 DW_OP_piece complicates it. */
8643 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8644 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8645 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8646 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8650 /* Extract the PLUS expression nested inside and fall into
8652 rtl
= XEXP (rtl
, 1);
8657 /* Turn these into a PLUS expression and fall into the PLUS code
8659 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8660 GEN_INT (GET_CODE (rtl
) == PRE_INC
8661 ? GET_MODE_UNIT_SIZE (mode
)
8662 : -GET_MODE_UNIT_SIZE (mode
)));
8664 /* ... fall through ... */
8668 if (is_based_loc (rtl
))
8669 mem_loc_result
= based_loc_descr (dbx_reg_number (XEXP (rtl
, 0)),
8670 INTVAL (XEXP (rtl
, 1)),
8674 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
8676 if (mem_loc_result
== 0)
8679 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8680 && INTVAL (XEXP (rtl
, 1)) >= 0)
8681 add_loc_descr (&mem_loc_result
,
8682 new_loc_descr (DW_OP_plus_uconst
,
8683 INTVAL (XEXP (rtl
, 1)), 0));
8686 add_loc_descr (&mem_loc_result
,
8687 mem_loc_descriptor (XEXP (rtl
, 1), mode
,
8689 add_loc_descr (&mem_loc_result
,
8690 new_loc_descr (DW_OP_plus
, 0, 0));
8695 /* If a pseudo-reg is optimized away, it is possible for it to
8696 be replaced with a MEM containing a multiply or shift. */
8715 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
8717 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
8720 if (op0
== 0 || op1
== 0)
8723 mem_loc_result
= op0
;
8724 add_loc_descr (&mem_loc_result
, op1
);
8725 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
8730 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8737 return mem_loc_result
;
8740 /* Return a descriptor that describes the concatenation of two locations.
8741 This is typically a complex variable. */
8743 static dw_loc_descr_ref
8744 concat_loc_descriptor (rtx x0
, rtx x1
)
8746 dw_loc_descr_ref cc_loc_result
= NULL
;
8747 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, true);
8748 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, true);
8750 if (x0_ref
== 0 || x1_ref
== 0)
8753 cc_loc_result
= x0_ref
;
8754 add_loc_descr (&cc_loc_result
,
8755 new_loc_descr (DW_OP_piece
,
8756 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8758 add_loc_descr (&cc_loc_result
, x1_ref
);
8759 add_loc_descr (&cc_loc_result
,
8760 new_loc_descr (DW_OP_piece
,
8761 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8763 return cc_loc_result
;
8766 /* Output a proper Dwarf location descriptor for a variable or parameter
8767 which is either allocated in a register or in a memory location. For a
8768 register, we just generate an OP_REG and the register number. For a
8769 memory location we provide a Dwarf postfix expression describing how to
8770 generate the (dynamic) address of the object onto the address stack.
8772 If we don't know how to describe it, return 0. */
8774 static dw_loc_descr_ref
8775 loc_descriptor (rtx rtl
, bool can_use_fbreg
)
8777 dw_loc_descr_ref loc_result
= NULL
;
8779 switch (GET_CODE (rtl
))
8782 /* The case of a subreg may arise when we have a local (register)
8783 variable or a formal (register) parameter which doesn't quite fill
8784 up an entire register. For now, just assume that it is
8785 legitimate to make the Dwarf info refer to the whole register which
8786 contains the given subreg. */
8787 rtl
= SUBREG_REG (rtl
);
8789 /* ... fall through ... */
8792 loc_result
= reg_loc_descriptor (rtl
);
8796 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
8801 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8806 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
8808 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), can_use_fbreg
);
8812 rtl
= XEXP (rtl
, 1);
8817 rtvec par_elems
= XVEC (rtl
, 0);
8818 int num_elem
= GET_NUM_ELEM (par_elems
);
8819 enum machine_mode mode
;
8822 /* Create the first one, so we have something to add to. */
8823 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
8825 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
8826 add_loc_descr (&loc_result
,
8827 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (mode
), 0));
8828 for (i
= 1; i
< num_elem
; i
++)
8830 dw_loc_descr_ref temp
;
8832 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
8834 add_loc_descr (&loc_result
, temp
);
8835 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
8836 add_loc_descr (&loc_result
,
8837 new_loc_descr (DW_OP_piece
,
8838 GET_MODE_SIZE (mode
), 0));
8850 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8851 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
8852 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
8853 top-level invocation, and we require the address of LOC; is 0 if we require
8854 the value of LOC. */
8856 static dw_loc_descr_ref
8857 loc_descriptor_from_tree_1 (tree loc
, int want_address
)
8859 dw_loc_descr_ref ret
, ret1
;
8860 int have_address
= 0;
8861 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
8862 enum dwarf_location_atom op
;
8864 /* ??? Most of the time we do not take proper care for sign/zero
8865 extending the values properly. Hopefully this won't be a real
8868 switch (TREE_CODE (loc
))
8873 case PLACEHOLDER_EXPR
:
8874 /* This case involves extracting fields from an object to determine the
8875 position of other fields. We don't try to encode this here. The
8876 only user of this is Ada, which encodes the needed information using
8877 the names of types. */
8883 case PREINCREMENT_EXPR
:
8884 case PREDECREMENT_EXPR
:
8885 case POSTINCREMENT_EXPR
:
8886 case POSTDECREMENT_EXPR
:
8887 /* There are no opcodes for these operations. */
8891 /* If we already want an address, there's nothing we can do. */
8895 /* Otherwise, process the argument and look for the address. */
8896 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 1);
8899 if (DECL_THREAD_LOCAL (loc
))
8903 #ifndef ASM_OUTPUT_DWARF_DTPREL
8904 /* If this is not defined, we have no way to emit the data. */
8908 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8909 look up addresses of objects in the current module. */
8910 if (DECL_EXTERNAL (loc
))
8913 rtl
= rtl_for_decl_location (loc
);
8914 if (rtl
== NULL_RTX
)
8919 rtl
= XEXP (rtl
, 0);
8920 if (! CONSTANT_P (rtl
))
8923 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8924 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8925 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8927 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8928 add_loc_descr (&ret
, ret1
);
8936 if (DECL_VALUE_EXPR (loc
))
8937 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc
), want_address
);
8942 rtx rtl
= rtl_for_decl_location (loc
);
8944 if (rtl
== NULL_RTX
)
8946 else if (GET_CODE (rtl
) == CONST_INT
)
8948 HOST_WIDE_INT val
= INTVAL (rtl
);
8949 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
8950 val
&= GET_MODE_MASK (DECL_MODE (loc
));
8951 ret
= int_loc_descriptor (val
);
8953 else if (GET_CODE (rtl
) == CONST_STRING
)
8955 else if (CONSTANT_P (rtl
))
8957 ret
= new_loc_descr (DW_OP_addr
, 0, 0);
8958 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8959 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8963 enum machine_mode mode
;
8965 /* Certain constructs can only be represented at top-level. */
8966 if (want_address
== 2)
8967 return loc_descriptor (rtl
, true);
8969 mode
= GET_MODE (rtl
);
8972 rtl
= XEXP (rtl
, 0);
8975 ret
= mem_loc_descriptor (rtl
, mode
, true);
8981 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
8986 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
);
8990 case NON_LVALUE_EXPR
:
8991 case VIEW_CONVERT_EXPR
:
8994 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
);
8999 case ARRAY_RANGE_REF
:
9002 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
9003 enum machine_mode mode
;
9006 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
9007 &unsignedp
, &volatilep
);
9012 ret
= loc_descriptor_from_tree_1 (obj
, 1);
9014 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
9017 if (offset
!= NULL_TREE
)
9019 /* Variable offset. */
9020 add_loc_descr (&ret
, loc_descriptor_from_tree_1 (offset
, 0));
9021 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9024 bytepos
= bitpos
/ BITS_PER_UNIT
;
9026 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
9027 else if (bytepos
< 0)
9029 add_loc_descr (&ret
, int_loc_descriptor (bytepos
));
9030 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus
, 0, 0));
9038 if (host_integerp (loc
, 0))
9039 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
9046 /* Get an RTL for this, if something has been emitted. */
9047 rtx rtl
= lookup_constant_def (loc
);
9048 enum machine_mode mode
;
9050 if (!rtl
|| !MEM_P (rtl
))
9052 mode
= GET_MODE (rtl
);
9053 rtl
= XEXP (rtl
, 0);
9054 ret
= mem_loc_descriptor (rtl
, mode
, true);
9059 case TRUTH_AND_EXPR
:
9060 case TRUTH_ANDIF_EXPR
:
9065 case TRUTH_XOR_EXPR
:
9071 case TRUTH_ORIF_EXPR
:
9076 case FLOOR_DIV_EXPR
:
9078 case ROUND_DIV_EXPR
:
9079 case TRUNC_DIV_EXPR
:
9087 case FLOOR_MOD_EXPR
:
9089 case ROUND_MOD_EXPR
:
9090 case TRUNC_MOD_EXPR
:
9103 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
9107 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
9108 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9110 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9114 add_loc_descr (&ret
,
9115 new_loc_descr (DW_OP_plus_uconst
,
9116 tree_low_cst (TREE_OPERAND (loc
, 1),
9126 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9133 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9140 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9147 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9162 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9163 ret1
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9164 if (ret
== 0 || ret1
== 0)
9167 add_loc_descr (&ret
, ret1
);
9168 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9171 case TRUTH_NOT_EXPR
:
9185 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9189 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9195 const enum tree_code code
=
9196 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9198 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
9199 build2 (code
, integer_type_node
,
9200 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9201 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9204 /* ... fall through ... */
9208 dw_loc_descr_ref lhs
9209 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 1), 0);
9210 dw_loc_descr_ref rhs
9211 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 2), 0);
9212 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9214 ret
= loc_descriptor_from_tree_1 (TREE_OPERAND (loc
, 0), 0);
9215 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9218 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9219 add_loc_descr (&ret
, bra_node
);
9221 add_loc_descr (&ret
, rhs
);
9222 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9223 add_loc_descr (&ret
, jump_node
);
9225 add_loc_descr (&ret
, lhs
);
9226 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9227 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9229 /* ??? Need a node to point the skip at. Use a nop. */
9230 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9231 add_loc_descr (&ret
, tmp
);
9232 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9233 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9238 /* Leave front-end specific codes as simply unknown. This comes
9239 up, for instance, with the C STMT_EXPR. */
9240 if ((unsigned int) TREE_CODE (loc
)
9241 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9244 /* Otherwise this is a generic code; we should just lists all of
9245 these explicitly. Aborting means we forgot one. */
9249 /* Show if we can't fill the request for an address. */
9250 if (want_address
&& !have_address
)
9253 /* If we've got an address and don't want one, dereference. */
9254 if (!want_address
&& have_address
)
9256 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9258 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9260 else if (size
== DWARF2_ADDR_SIZE
)
9263 op
= DW_OP_deref_size
;
9265 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9271 static inline dw_loc_descr_ref
9272 loc_descriptor_from_tree (tree loc
)
9274 return loc_descriptor_from_tree_1 (loc
, 2);
9277 /* Given a value, round it up to the lowest multiple of `boundary'
9278 which is not less than the value itself. */
9280 static inline HOST_WIDE_INT
9281 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9283 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9286 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9287 pointer to the declared type for the relevant field variable, or return
9288 `integer_type_node' if the given node turns out to be an
9292 field_type (tree decl
)
9296 if (TREE_CODE (decl
) == ERROR_MARK
)
9297 return integer_type_node
;
9299 type
= DECL_BIT_FIELD_TYPE (decl
);
9300 if (type
== NULL_TREE
)
9301 type
= TREE_TYPE (decl
);
9306 /* Given a pointer to a tree node, return the alignment in bits for
9307 it, or else return BITS_PER_WORD if the node actually turns out to
9308 be an ERROR_MARK node. */
9310 static inline unsigned
9311 simple_type_align_in_bits (tree type
)
9313 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9316 static inline unsigned
9317 simple_decl_align_in_bits (tree decl
)
9319 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9322 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9323 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9324 or return 0 if we are unable to determine what that offset is, either
9325 because the argument turns out to be a pointer to an ERROR_MARK node, or
9326 because the offset is actually variable. (We can't handle the latter case
9329 static HOST_WIDE_INT
9330 field_byte_offset (tree decl
)
9332 unsigned int type_align_in_bits
;
9333 unsigned int decl_align_in_bits
;
9334 unsigned HOST_WIDE_INT type_size_in_bits
;
9335 HOST_WIDE_INT object_offset_in_bits
;
9337 tree field_size_tree
;
9338 HOST_WIDE_INT bitpos_int
;
9339 HOST_WIDE_INT deepest_bitpos
;
9340 unsigned HOST_WIDE_INT field_size_in_bits
;
9342 if (TREE_CODE (decl
) == ERROR_MARK
)
9344 else if (TREE_CODE (decl
) != FIELD_DECL
)
9347 type
= field_type (decl
);
9348 field_size_tree
= DECL_SIZE (decl
);
9350 /* The size could be unspecified if there was an error, or for
9351 a flexible array member. */
9352 if (! field_size_tree
)
9353 field_size_tree
= bitsize_zero_node
;
9355 /* We cannot yet cope with fields whose positions are variable, so
9356 for now, when we see such things, we simply return 0. Someday, we may
9357 be able to handle such cases, but it will be damn difficult. */
9358 if (! host_integerp (bit_position (decl
), 0))
9361 bitpos_int
= int_bit_position (decl
);
9363 /* If we don't know the size of the field, pretend it's a full word. */
9364 if (host_integerp (field_size_tree
, 1))
9365 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9367 field_size_in_bits
= BITS_PER_WORD
;
9369 type_size_in_bits
= simple_type_size_in_bits (type
);
9370 type_align_in_bits
= simple_type_align_in_bits (type
);
9371 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9373 /* The GCC front-end doesn't make any attempt to keep track of the starting
9374 bit offset (relative to the start of the containing structure type) of the
9375 hypothetical "containing object" for a bit-field. Thus, when computing
9376 the byte offset value for the start of the "containing object" of a
9377 bit-field, we must deduce this information on our own. This can be rather
9378 tricky to do in some cases. For example, handling the following structure
9379 type definition when compiling for an i386/i486 target (which only aligns
9380 long long's to 32-bit boundaries) can be very tricky:
9382 struct S { int field1; long long field2:31; };
9384 Fortunately, there is a simple rule-of-thumb which can be used in such
9385 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9386 structure shown above. It decides to do this based upon one simple rule
9387 for bit-field allocation. GCC allocates each "containing object" for each
9388 bit-field at the first (i.e. lowest addressed) legitimate alignment
9389 boundary (based upon the required minimum alignment for the declared type
9390 of the field) which it can possibly use, subject to the condition that
9391 there is still enough available space remaining in the containing object
9392 (when allocated at the selected point) to fully accommodate all of the
9393 bits of the bit-field itself.
9395 This simple rule makes it obvious why GCC allocates 8 bytes for each
9396 object of the structure type shown above. When looking for a place to
9397 allocate the "containing object" for `field2', the compiler simply tries
9398 to allocate a 64-bit "containing object" at each successive 32-bit
9399 boundary (starting at zero) until it finds a place to allocate that 64-
9400 bit field such that at least 31 contiguous (and previously unallocated)
9401 bits remain within that selected 64 bit field. (As it turns out, for the
9402 example above, the compiler finds it is OK to allocate the "containing
9403 object" 64-bit field at bit-offset zero within the structure type.)
9405 Here we attempt to work backwards from the limited set of facts we're
9406 given, and we try to deduce from those facts, where GCC must have believed
9407 that the containing object started (within the structure type). The value
9408 we deduce is then used (by the callers of this routine) to generate
9409 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9410 and, in the case of DW_AT_location, regular fields as well). */
9412 /* Figure out the bit-distance from the start of the structure to the
9413 "deepest" bit of the bit-field. */
9414 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
9416 /* This is the tricky part. Use some fancy footwork to deduce where the
9417 lowest addressed bit of the containing object must be. */
9418 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9420 /* Round up to type_align by default. This works best for bitfields. */
9421 object_offset_in_bits
+= type_align_in_bits
- 1;
9422 object_offset_in_bits
/= type_align_in_bits
;
9423 object_offset_in_bits
*= type_align_in_bits
;
9425 if (object_offset_in_bits
> bitpos_int
)
9427 /* Sigh, the decl must be packed. */
9428 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9430 /* Round up to decl_align instead. */
9431 object_offset_in_bits
+= decl_align_in_bits
- 1;
9432 object_offset_in_bits
/= decl_align_in_bits
;
9433 object_offset_in_bits
*= decl_align_in_bits
;
9436 return object_offset_in_bits
/ BITS_PER_UNIT
;
9439 /* The following routines define various Dwarf attributes and any data
9440 associated with them. */
9442 /* Add a location description attribute value to a DIE.
9444 This emits location attributes suitable for whole variables and
9445 whole parameters. Note that the location attributes for struct fields are
9446 generated by the routine `data_member_location_attribute' below. */
9449 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9450 dw_loc_descr_ref descr
)
9453 add_AT_loc (die
, attr_kind
, descr
);
9456 /* Attach the specialized form of location attribute used for data members of
9457 struct and union types. In the special case of a FIELD_DECL node which
9458 represents a bit-field, the "offset" part of this special location
9459 descriptor must indicate the distance in bytes from the lowest-addressed
9460 byte of the containing struct or union type to the lowest-addressed byte of
9461 the "containing object" for the bit-field. (See the `field_byte_offset'
9464 For any given bit-field, the "containing object" is a hypothetical object
9465 (of some integral or enum type) within which the given bit-field lives. The
9466 type of this hypothetical "containing object" is always the same as the
9467 declared type of the individual bit-field itself (for GCC anyway... the
9468 DWARF spec doesn't actually mandate this). Note that it is the size (in
9469 bytes) of the hypothetical "containing object" which will be given in the
9470 DW_AT_byte_size attribute for this bit-field. (See the
9471 `byte_size_attribute' function below.) It is also used when calculating the
9472 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9476 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
9478 HOST_WIDE_INT offset
;
9479 dw_loc_descr_ref loc_descr
= 0;
9481 if (TREE_CODE (decl
) == TREE_BINFO
)
9483 /* We're working on the TAG_inheritance for a base class. */
9484 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
9486 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9487 aren't at a fixed offset from all (sub)objects of the same
9488 type. We need to extract the appropriate offset from our
9489 vtable. The following dwarf expression means
9491 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9493 This is specific to the V3 ABI, of course. */
9495 dw_loc_descr_ref tmp
;
9497 /* Make a copy of the object address. */
9498 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
9499 add_loc_descr (&loc_descr
, tmp
);
9501 /* Extract the vtable address. */
9502 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9503 add_loc_descr (&loc_descr
, tmp
);
9505 /* Calculate the address of the offset. */
9506 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9510 tmp
= int_loc_descriptor (-offset
);
9511 add_loc_descr (&loc_descr
, tmp
);
9512 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9513 add_loc_descr (&loc_descr
, tmp
);
9515 /* Extract the offset. */
9516 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9517 add_loc_descr (&loc_descr
, tmp
);
9519 /* Add it to the object address. */
9520 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9521 add_loc_descr (&loc_descr
, tmp
);
9524 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9527 offset
= field_byte_offset (decl
);
9531 enum dwarf_location_atom op
;
9533 /* The DWARF2 standard says that we should assume that the structure
9534 address is already on the stack, so we can specify a structure field
9535 address by using DW_OP_plus_uconst. */
9537 #ifdef MIPS_DEBUGGING_INFO
9538 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9539 operator correctly. It works only if we leave the offset on the
9543 op
= DW_OP_plus_uconst
;
9546 loc_descr
= new_loc_descr (op
, offset
, 0);
9549 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9552 /* Writes integer values to dw_vec_const array. */
9555 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
9559 *dest
++ = val
& 0xff;
9565 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9567 static HOST_WIDE_INT
9568 extract_int (const unsigned char *src
, unsigned int size
)
9570 HOST_WIDE_INT val
= 0;
9576 val
|= *--src
& 0xff;
9582 /* Writes floating point values to dw_vec_const array. */
9585 insert_float (rtx rtl
, unsigned char *array
)
9591 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9592 real_to_target (val
, &rv
, GET_MODE (rtl
));
9594 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9595 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
9597 insert_int (val
[i
], 4, array
);
9602 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9603 does not have a "location" either in memory or in a register. These
9604 things can arise in GNU C when a constant is passed as an actual parameter
9605 to an inlined function. They can also arise in C++ where declared
9606 constants do not necessarily get memory "homes". */
9609 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9611 switch (GET_CODE (rtl
))
9615 HOST_WIDE_INT val
= INTVAL (rtl
);
9618 add_AT_int (die
, DW_AT_const_value
, val
);
9620 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
9625 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9626 floating-point constant. A CONST_DOUBLE is used whenever the
9627 constant requires more than one word in order to be adequately
9628 represented. We output CONST_DOUBLEs as blocks. */
9630 enum machine_mode mode
= GET_MODE (rtl
);
9632 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9634 unsigned int length
= GET_MODE_SIZE (mode
);
9635 unsigned char *array
= ggc_alloc (length
);
9637 insert_float (rtl
, array
);
9638 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
9642 /* ??? We really should be using HOST_WIDE_INT throughout. */
9643 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
9646 add_AT_long_long (die
, DW_AT_const_value
,
9647 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9654 enum machine_mode mode
= GET_MODE (rtl
);
9655 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
9656 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
9657 unsigned char *array
= ggc_alloc (length
* elt_size
);
9661 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
9663 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9665 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9666 HOST_WIDE_INT lo
, hi
;
9667 if (GET_CODE (elt
) == CONST_INT
)
9672 else if (GET_CODE (elt
) == CONST_DOUBLE
)
9674 lo
= CONST_DOUBLE_LOW (elt
);
9675 hi
= CONST_DOUBLE_HIGH (elt
);
9680 if (elt_size
<= sizeof (HOST_WIDE_INT
))
9681 insert_int (lo
, elt_size
, p
);
9682 else if (elt_size
== 2 * sizeof (HOST_WIDE_INT
))
9684 unsigned char *p0
= p
;
9685 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
9687 if (WORDS_BIG_ENDIAN
)
9692 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
9693 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
9699 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
9701 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9703 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9704 insert_float (elt
, p
);
9710 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
9715 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9721 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9722 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
9726 /* In cases where an inlined instance of an inline function is passed
9727 the address of an `auto' variable (which is local to the caller) we
9728 can get a situation where the DECL_RTL of the artificial local
9729 variable (for the inlining) which acts as a stand-in for the
9730 corresponding formal parameter (of the inline function) will look
9731 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9732 exactly a compile-time constant expression, but it isn't the address
9733 of the (artificial) local variable either. Rather, it represents the
9734 *value* which the artificial local variable always has during its
9735 lifetime. We currently have no way to represent such quasi-constant
9736 values in Dwarf, so for now we just punt and generate nothing. */
9740 /* No other kinds of rtx should be possible here. */
9747 rtl_for_decl_location (tree decl
)
9751 /* Here we have to decide where we are going to say the parameter "lives"
9752 (as far as the debugger is concerned). We only have a couple of
9753 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9755 DECL_RTL normally indicates where the parameter lives during most of the
9756 activation of the function. If optimization is enabled however, this
9757 could be either NULL or else a pseudo-reg. Both of those cases indicate
9758 that the parameter doesn't really live anywhere (as far as the code
9759 generation parts of GCC are concerned) during most of the function's
9760 activation. That will happen (for example) if the parameter is never
9761 referenced within the function.
9763 We could just generate a location descriptor here for all non-NULL
9764 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9765 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9766 where DECL_RTL is NULL or is a pseudo-reg.
9768 Note however that we can only get away with using DECL_INCOMING_RTL as
9769 a backup substitute for DECL_RTL in certain limited cases. In cases
9770 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9771 we can be sure that the parameter was passed using the same type as it is
9772 declared to have within the function, and that its DECL_INCOMING_RTL
9773 points us to a place where a value of that type is passed.
9775 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9776 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9777 because in these cases DECL_INCOMING_RTL points us to a value of some
9778 type which is *different* from the type of the parameter itself. Thus,
9779 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9780 such cases, the debugger would end up (for example) trying to fetch a
9781 `float' from a place which actually contains the first part of a
9782 `double'. That would lead to really incorrect and confusing
9783 output at debug-time.
9785 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9786 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9787 are a couple of exceptions however. On little-endian machines we can
9788 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9789 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9790 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9791 when (on a little-endian machine) a non-prototyped function has a
9792 parameter declared to be of type `short' or `char'. In such cases,
9793 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9794 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9795 passed `int' value. If the debugger then uses that address to fetch
9796 a `short' or a `char' (on a little-endian machine) the result will be
9797 the correct data, so we allow for such exceptional cases below.
9799 Note that our goal here is to describe the place where the given formal
9800 parameter lives during most of the function's activation (i.e. between the
9801 end of the prologue and the start of the epilogue). We'll do that as best
9802 as we can. Note however that if the given formal parameter is modified
9803 sometime during the execution of the function, then a stack backtrace (at
9804 debug-time) will show the function as having been called with the *new*
9805 value rather than the value which was originally passed in. This happens
9806 rarely enough that it is not a major problem, but it *is* a problem, and
9809 A future version of dwarf2out.c may generate two additional attributes for
9810 any given DW_TAG_formal_parameter DIE which will describe the "passed
9811 type" and the "passed location" for the given formal parameter in addition
9812 to the attributes we now generate to indicate the "declared type" and the
9813 "active location" for each parameter. This additional set of attributes
9814 could be used by debuggers for stack backtraces. Separately, note that
9815 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9816 This happens (for example) for inlined-instances of inline function formal
9817 parameters which are never referenced. This really shouldn't be
9818 happening. All PARM_DECL nodes should get valid non-NULL
9819 DECL_INCOMING_RTL values. FIXME. */
9821 /* Use DECL_RTL as the "location" unless we find something better. */
9822 rtl
= DECL_RTL_IF_SET (decl
);
9824 /* When generating abstract instances, ignore everything except
9825 constants, symbols living in memory, and symbols living in
9827 if (! reload_completed
)
9830 && (CONSTANT_P (rtl
)
9832 && CONSTANT_P (XEXP (rtl
, 0)))
9834 && TREE_CODE (decl
) == VAR_DECL
9835 && TREE_STATIC (decl
))))
9837 rtl
= targetm
.delegitimize_address (rtl
);
9842 else if (TREE_CODE (decl
) == PARM_DECL
)
9844 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
9846 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
9847 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
9849 /* This decl represents a formal parameter which was optimized out.
9850 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9851 all cases where (rtl == NULL_RTX) just below. */
9852 if (declared_type
== passed_type
)
9853 rtl
= DECL_INCOMING_RTL (decl
);
9854 else if (! BYTES_BIG_ENDIAN
9855 && TREE_CODE (declared_type
) == INTEGER_TYPE
9856 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
9857 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
9858 rtl
= DECL_INCOMING_RTL (decl
);
9861 /* If the parm was passed in registers, but lives on the stack, then
9862 make a big endian correction if the mode of the type of the
9863 parameter is not the same as the mode of the rtl. */
9864 /* ??? This is the same series of checks that are made in dbxout.c before
9865 we reach the big endian correction code there. It isn't clear if all
9866 of these checks are necessary here, but keeping them all is the safe
9868 else if (MEM_P (rtl
)
9869 && XEXP (rtl
, 0) != const0_rtx
9870 && ! CONSTANT_P (XEXP (rtl
, 0))
9871 /* Not passed in memory. */
9872 && !MEM_P (DECL_INCOMING_RTL (decl
))
9873 /* Not passed by invisible reference. */
9874 && (!REG_P (XEXP (rtl
, 0))
9875 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
9876 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
9877 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9878 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
9881 /* Big endian correction check. */
9883 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
9884 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
9887 int offset
= (UNITS_PER_WORD
9888 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
9890 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9891 plus_constant (XEXP (rtl
, 0), offset
));
9894 else if (TREE_CODE (decl
) == VAR_DECL
9897 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
9898 && BYTES_BIG_ENDIAN
)
9900 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
9901 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
9903 /* If a variable is declared "register" yet is smaller than
9904 a register, then if we store the variable to memory, it
9905 looks like we're storing a register-sized value, when in
9906 fact we are not. We need to adjust the offset of the
9907 storage location to reflect the actual value's bytes,
9908 else gdb will not be able to display it. */
9910 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9911 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
9914 if (rtl
!= NULL_RTX
)
9916 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
9917 #ifdef LEAF_REG_REMAP
9918 if (current_function_uses_only_leaf_regs
)
9919 leaf_renumber_regs_insn (rtl
);
9923 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9924 and will have been substituted directly into all expressions that use it.
9925 C does not have such a concept, but C++ and other languages do. */
9926 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
9928 /* If a variable is initialized with a string constant without embedded
9929 zeros, build CONST_STRING. */
9930 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
9931 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9933 tree arrtype
= TREE_TYPE (decl
);
9934 tree enttype
= TREE_TYPE (arrtype
);
9935 tree domain
= TYPE_DOMAIN (arrtype
);
9936 tree init
= DECL_INITIAL (decl
);
9937 enum machine_mode mode
= TYPE_MODE (enttype
);
9939 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9941 && integer_zerop (TYPE_MIN_VALUE (domain
))
9942 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9943 TREE_STRING_LENGTH (init
) - 1) == 0
9944 && ((size_t) TREE_STRING_LENGTH (init
)
9945 == strlen (TREE_STRING_POINTER (init
)) + 1))
9946 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
9948 /* If the initializer is something that we know will expand into an
9949 immediate RTL constant, expand it now. Expanding anything else
9950 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9951 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
9952 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
9954 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
9955 EXPAND_INITIALIZER
);
9956 /* If expand_expr returns a MEM, it wasn't immediate. */
9957 if (rtl
&& MEM_P (rtl
))
9963 rtl
= targetm
.delegitimize_address (rtl
);
9965 /* If we don't look past the constant pool, we risk emitting a
9966 reference to a constant pool entry that isn't referenced from
9967 code, and thus is not emitted. */
9969 rtl
= avoid_constant_pool_reference (rtl
);
9974 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9975 data attribute for a variable or a parameter. We generate the
9976 DW_AT_const_value attribute only in those cases where the given variable
9977 or parameter does not have a true "location" either in memory or in a
9978 register. This can happen (for example) when a constant is passed as an
9979 actual argument in a call to an inline function. (It's possible that
9980 these things can crop up in other ways also.) Note that one type of
9981 constant value which can be passed into an inlined function is a constant
9982 pointer. This can happen for example if an actual argument in an inlined
9983 function call evaluates to a compile-time constant address. */
9986 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
9987 enum dwarf_attribute attr
)
9990 dw_loc_descr_ref descr
;
9991 var_loc_list
*loc_list
;
9993 if (TREE_CODE (decl
) == ERROR_MARK
)
9995 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
9996 && TREE_CODE (decl
) != RESULT_DECL
)
9999 /* See if we possibly have multiple locations for this variable. */
10000 loc_list
= lookup_decl_loc (decl
);
10002 /* If it truly has multiple locations, the first and last node will
10004 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
10006 const char *secname
;
10007 const char *endname
;
10008 dw_loc_list_ref list
;
10010 struct var_loc_node
*node
;
10012 /* We need to figure out what section we should use as the base
10013 for the address ranges where a given location is valid.
10014 1. If this particular DECL has a section associated with it,
10016 2. If this function has a section associated with it, use
10018 3. Otherwise, use the text section.
10019 XXX: If you split a variable across multiple sections, this
10022 if (DECL_SECTION_NAME (decl
))
10024 tree sectree
= DECL_SECTION_NAME (decl
);
10025 secname
= TREE_STRING_POINTER (sectree
);
10027 else if (current_function_decl
10028 && DECL_SECTION_NAME (current_function_decl
))
10030 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
10031 secname
= TREE_STRING_POINTER (sectree
);
10034 secname
= text_section_label
;
10036 /* Now that we know what section we are using for a base,
10037 actually construct the list of locations.
10038 The first location information is what is passed to the
10039 function that creates the location list, and the remaining
10040 locations just get added on to that list.
10041 Note that we only know the start address for a location
10042 (IE location changes), so to build the range, we use
10043 the range [current location start, next location start].
10044 This means we have to special case the last node, and generate
10045 a range of [last location start, end of function label]. */
10047 node
= loc_list
->first
;
10048 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10049 list
= new_loc_list (loc_descriptor (varloc
, attr
!= DW_AT_frame_base
),
10050 node
->label
, node
->next
->label
, secname
, 1);
10053 for (; node
->next
; node
= node
->next
)
10054 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10056 /* The variable has a location between NODE->LABEL and
10057 NODE->NEXT->LABEL. */
10058 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10059 add_loc_descr_to_loc_list (&list
,
10060 loc_descriptor (varloc
,
10061 attr
!= DW_AT_frame_base
),
10062 node
->label
, node
->next
->label
, secname
);
10065 /* If the variable has a location at the last label
10066 it keeps its location until the end of function. */
10067 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10069 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10071 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10072 if (!current_function_decl
)
10073 endname
= text_end_label
;
10076 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10077 current_function_funcdef_no
);
10078 endname
= ggc_strdup (label_id
);
10080 add_loc_descr_to_loc_list (&list
,
10081 loc_descriptor (varloc
,
10082 attr
!= DW_AT_frame_base
),
10083 node
->label
, endname
, secname
);
10086 /* Finally, add the location list to the DIE, and we are done. */
10087 add_AT_loc_list (die
, attr
, list
);
10091 rtl
= rtl_for_decl_location (decl
);
10092 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
))
10094 add_const_value_attribute (die
, rtl
);
10098 descr
= loc_descriptor_from_tree (decl
);
10100 add_AT_location_description (die
, attr
, descr
);
10103 /* If we don't have a copy of this variable in memory for some reason (such
10104 as a C++ member constant that doesn't have an out-of-line definition),
10105 we should tell the debugger about the constant value. */
10108 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10110 tree init
= DECL_INITIAL (decl
);
10111 tree type
= TREE_TYPE (decl
);
10113 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
10114 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
10119 switch (TREE_CODE (type
))
10122 if (host_integerp (init
, 0))
10123 add_AT_unsigned (var_die
, DW_AT_const_value
,
10124 tree_low_cst (init
, 0));
10126 add_AT_long_long (var_die
, DW_AT_const_value
,
10127 TREE_INT_CST_HIGH (init
),
10128 TREE_INT_CST_LOW (init
));
10135 /* Generate a DW_AT_name attribute given some string value to be included as
10136 the value of the attribute. */
10139 add_name_attribute (dw_die_ref die
, const char *name_string
)
10141 if (name_string
!= NULL
&& *name_string
!= 0)
10143 if (demangle_name_func
)
10144 name_string
= (*demangle_name_func
) (name_string
);
10146 add_AT_string (die
, DW_AT_name
, name_string
);
10150 /* Generate a DW_AT_comp_dir attribute for DIE. */
10153 add_comp_dir_attribute (dw_die_ref die
)
10155 const char *wd
= get_src_pwd ();
10157 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10160 /* Given a tree node describing an array bound (either lower or upper) output
10161 a representation for that bound. */
10164 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
10166 switch (TREE_CODE (bound
))
10171 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10173 if (! host_integerp (bound
, 0)
10174 || (bound_attr
== DW_AT_lower_bound
10175 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
10176 || (is_fortran () && integer_onep (bound
)))))
10177 /* Use the default. */
10180 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
10185 case NON_LVALUE_EXPR
:
10186 case VIEW_CONVERT_EXPR
:
10187 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
10197 dw_die_ref decl_die
= lookup_decl_die (bound
);
10199 /* ??? Can this happen, or should the variable have been bound
10200 first? Probably it can, since I imagine that we try to create
10201 the types of parameters in the order in which they exist in
10202 the list, and won't have created a forward reference to a
10203 later parameter. */
10204 if (decl_die
!= NULL
)
10205 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10211 /* Otherwise try to create a stack operation procedure to
10212 evaluate the value of the array bound. */
10214 dw_die_ref ctx
, decl_die
;
10215 dw_loc_descr_ref loc
;
10217 loc
= loc_descriptor_from_tree (bound
);
10221 if (current_function_decl
== 0)
10222 ctx
= comp_unit_die
;
10224 ctx
= lookup_decl_die (current_function_decl
);
10226 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10227 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10228 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10229 add_AT_loc (decl_die
, DW_AT_location
, loc
);
10231 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10237 /* Note that the block of subscript information for an array type also
10238 includes information about the element type of type given array type. */
10241 add_subscript_info (dw_die_ref type_die
, tree type
)
10243 #ifndef MIPS_DEBUGGING_INFO
10244 unsigned dimension_number
;
10247 dw_die_ref subrange_die
;
10249 /* The GNU compilers represent multidimensional array types as sequences of
10250 one dimensional array types whose element types are themselves array
10251 types. Here we squish that down, so that each multidimensional array
10252 type gets only one array_type DIE in the Dwarf debugging info. The draft
10253 Dwarf specification say that we are allowed to do this kind of
10254 compression in C (because there is no difference between an array or
10255 arrays and a multidimensional array in C) but for other source languages
10256 (e.g. Ada) we probably shouldn't do this. */
10258 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10259 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10260 We work around this by disabling this feature. See also
10261 gen_array_type_die. */
10262 #ifndef MIPS_DEBUGGING_INFO
10263 for (dimension_number
= 0;
10264 TREE_CODE (type
) == ARRAY_TYPE
;
10265 type
= TREE_TYPE (type
), dimension_number
++)
10268 tree domain
= TYPE_DOMAIN (type
);
10270 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10271 and (in GNU C only) variable bounds. Handle all three forms
10273 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
10276 /* We have an array type with specified bounds. */
10277 lower
= TYPE_MIN_VALUE (domain
);
10278 upper
= TYPE_MAX_VALUE (domain
);
10280 /* Define the index type. */
10281 if (TREE_TYPE (domain
))
10283 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10284 TREE_TYPE field. We can't emit debug info for this
10285 because it is an unnamed integral type. */
10286 if (TREE_CODE (domain
) == INTEGER_TYPE
10287 && TYPE_NAME (domain
) == NULL_TREE
10288 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
10289 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
10292 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
10296 /* ??? If upper is NULL, the array has unspecified length,
10297 but it does have a lower bound. This happens with Fortran
10299 Since the debugger is definitely going to need to know N
10300 to produce useful results, go ahead and output the lower
10301 bound solo, and hope the debugger can cope. */
10303 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
10305 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
10308 /* Otherwise we have an array type with an unspecified length. The
10309 DWARF-2 spec does not say how to handle this; let's just leave out the
10315 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
10319 switch (TREE_CODE (tree_node
))
10324 case ENUMERAL_TYPE
:
10327 case QUAL_UNION_TYPE
:
10328 size
= int_size_in_bytes (tree_node
);
10331 /* For a data member of a struct or union, the DW_AT_byte_size is
10332 generally given as the number of bytes normally allocated for an
10333 object of the *declared* type of the member itself. This is true
10334 even for bit-fields. */
10335 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
10341 /* Note that `size' might be -1 when we get to this point. If it is, that
10342 indicates that the byte size of the entity in question is variable. We
10343 have no good way of expressing this fact in Dwarf at the present time,
10344 so just let the -1 pass on through. */
10345 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
10348 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10349 which specifies the distance in bits from the highest order bit of the
10350 "containing object" for the bit-field to the highest order bit of the
10353 For any given bit-field, the "containing object" is a hypothetical object
10354 (of some integral or enum type) within which the given bit-field lives. The
10355 type of this hypothetical "containing object" is always the same as the
10356 declared type of the individual bit-field itself. The determination of the
10357 exact location of the "containing object" for a bit-field is rather
10358 complicated. It's handled by the `field_byte_offset' function (above).
10360 Note that it is the size (in bytes) of the hypothetical "containing object"
10361 which will be given in the DW_AT_byte_size attribute for this bit-field.
10362 (See `byte_size_attribute' above). */
10365 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
10367 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
10368 tree type
= DECL_BIT_FIELD_TYPE (decl
);
10369 HOST_WIDE_INT bitpos_int
;
10370 HOST_WIDE_INT highest_order_object_bit_offset
;
10371 HOST_WIDE_INT highest_order_field_bit_offset
;
10372 HOST_WIDE_INT
unsigned bit_offset
;
10374 /* Must be a field and a bit field. */
10376 || TREE_CODE (decl
) != FIELD_DECL
)
10379 /* We can't yet handle bit-fields whose offsets are variable, so if we
10380 encounter such things, just return without generating any attribute
10381 whatsoever. Likewise for variable or too large size. */
10382 if (! host_integerp (bit_position (decl
), 0)
10383 || ! host_integerp (DECL_SIZE (decl
), 1))
10386 bitpos_int
= int_bit_position (decl
);
10388 /* Note that the bit offset is always the distance (in bits) from the
10389 highest-order bit of the "containing object" to the highest-order bit of
10390 the bit-field itself. Since the "high-order end" of any object or field
10391 is different on big-endian and little-endian machines, the computation
10392 below must take account of these differences. */
10393 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
10394 highest_order_field_bit_offset
= bitpos_int
;
10396 if (! BYTES_BIG_ENDIAN
)
10398 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
10399 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
10403 = (! BYTES_BIG_ENDIAN
10404 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
10405 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
10407 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
10410 /* For a FIELD_DECL node which represents a bit field, output an attribute
10411 which specifies the length in bits of the given field. */
10414 add_bit_size_attribute (dw_die_ref die
, tree decl
)
10416 /* Must be a field and a bit field. */
10417 if (TREE_CODE (decl
) != FIELD_DECL
10418 || ! DECL_BIT_FIELD_TYPE (decl
))
10421 if (host_integerp (DECL_SIZE (decl
), 1))
10422 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
10425 /* If the compiled language is ANSI C, then add a 'prototyped'
10426 attribute, if arg types are given for the parameters of a function. */
10429 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
10431 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
10432 && TYPE_ARG_TYPES (func_type
) != NULL
)
10433 add_AT_flag (die
, DW_AT_prototyped
, 1);
10436 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10437 by looking in either the type declaration or object declaration
10441 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
10443 dw_die_ref origin_die
= NULL
;
10445 if (TREE_CODE (origin
) != FUNCTION_DECL
)
10447 /* We may have gotten separated from the block for the inlined
10448 function, if we're in an exception handler or some such; make
10449 sure that the abstract function has been written out.
10451 Doing this for nested functions is wrong, however; functions are
10452 distinct units, and our context might not even be inline. */
10456 fn
= TYPE_STUB_DECL (fn
);
10458 fn
= decl_function_context (fn
);
10460 dwarf2out_abstract_function (fn
);
10463 if (DECL_P (origin
))
10464 origin_die
= lookup_decl_die (origin
);
10465 else if (TYPE_P (origin
))
10466 origin_die
= lookup_type_die (origin
);
10468 if (origin_die
== NULL
)
10471 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
10474 /* We do not currently support the pure_virtual attribute. */
10477 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
10479 if (DECL_VINDEX (func_decl
))
10481 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10483 if (host_integerp (DECL_VINDEX (func_decl
), 0))
10484 add_AT_loc (die
, DW_AT_vtable_elem_location
,
10485 new_loc_descr (DW_OP_constu
,
10486 tree_low_cst (DECL_VINDEX (func_decl
), 0),
10489 /* GNU extension: Record what type this method came from originally. */
10490 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10491 add_AT_die_ref (die
, DW_AT_containing_type
,
10492 lookup_type_die (DECL_CONTEXT (func_decl
)));
10496 /* Add source coordinate attributes for the given decl. */
10499 add_src_coords_attributes (dw_die_ref die
, tree decl
)
10501 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
10502 unsigned file_index
= lookup_filename (s
.file
);
10504 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
10505 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
10508 /* Add a DW_AT_name attribute and source coordinate attribute for the
10509 given decl, but only if it actually has a name. */
10512 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
10516 decl_name
= DECL_NAME (decl
);
10517 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
10519 add_name_attribute (die
, dwarf2_name (decl
, 0));
10520 if (! DECL_ARTIFICIAL (decl
))
10521 add_src_coords_attributes (die
, decl
);
10523 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
10524 && TREE_PUBLIC (decl
)
10525 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
10526 && !DECL_ABSTRACT (decl
))
10527 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
10528 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
10531 #ifdef VMS_DEBUGGING_INFO
10532 /* Get the function's name, as described by its RTL. This may be different
10533 from the DECL_NAME name used in the source file. */
10534 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
10536 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
10537 XEXP (DECL_RTL (decl
), 0));
10538 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
10543 /* Push a new declaration scope. */
10546 push_decl_scope (tree scope
)
10548 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
10551 /* Pop a declaration scope. */
10554 pop_decl_scope (void)
10556 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
10559 VARRAY_POP (decl_scope_table
);
10562 /* Return the DIE for the scope that immediately contains this type.
10563 Non-named types get global scope. Named types nested in other
10564 types get their containing scope if it's open, or global scope
10565 otherwise. All other types (i.e. function-local named types) get
10566 the current active scope. */
10569 scope_die_for (tree t
, dw_die_ref context_die
)
10571 dw_die_ref scope_die
= NULL
;
10572 tree containing_scope
;
10575 /* Non-types always go in the current scope. */
10579 containing_scope
= TYPE_CONTEXT (t
);
10581 /* Use the containing namespace if it was passed in (for a declaration). */
10582 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
10584 if (context_die
== lookup_decl_die (containing_scope
))
10587 containing_scope
= NULL_TREE
;
10590 /* Ignore function type "scopes" from the C frontend. They mean that
10591 a tagged type is local to a parmlist of a function declarator, but
10592 that isn't useful to DWARF. */
10593 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
10594 containing_scope
= NULL_TREE
;
10596 if (containing_scope
== NULL_TREE
)
10597 scope_die
= comp_unit_die
;
10598 else if (TYPE_P (containing_scope
))
10600 /* For types, we can just look up the appropriate DIE. But
10601 first we check to see if we're in the middle of emitting it
10602 so we know where the new DIE should go. */
10603 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
10604 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
10609 if (debug_info_level
> DINFO_LEVEL_TERSE
10610 && !TREE_ASM_WRITTEN (containing_scope
))
10613 /* If none of the current dies are suitable, we get file scope. */
10614 scope_die
= comp_unit_die
;
10617 scope_die
= lookup_type_die (containing_scope
);
10620 scope_die
= context_die
;
10625 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10628 local_scope_p (dw_die_ref context_die
)
10630 for (; context_die
; context_die
= context_die
->die_parent
)
10631 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10632 || context_die
->die_tag
== DW_TAG_subprogram
)
10638 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10639 whether or not to treat a DIE in this context as a declaration. */
10642 class_or_namespace_scope_p (dw_die_ref context_die
)
10644 return (context_die
10645 && (context_die
->die_tag
== DW_TAG_structure_type
10646 || context_die
->die_tag
== DW_TAG_union_type
10647 || context_die
->die_tag
== DW_TAG_namespace
));
10650 /* Many forms of DIEs require a "type description" attribute. This
10651 routine locates the proper "type descriptor" die for the type given
10652 by 'type', and adds a DW_AT_type attribute below the given die. */
10655 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
10656 int decl_volatile
, dw_die_ref context_die
)
10658 enum tree_code code
= TREE_CODE (type
);
10659 dw_die_ref type_die
= NULL
;
10661 /* ??? If this type is an unnamed subrange type of an integral or
10662 floating-point type, use the inner type. This is because we have no
10663 support for unnamed types in base_type_die. This can happen if this is
10664 an Ada subrange type. Correct solution is emit a subrange type die. */
10665 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10666 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10667 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
10669 if (code
== ERROR_MARK
10670 /* Handle a special case. For functions whose return type is void, we
10671 generate *no* type attribute. (Note that no object may have type
10672 `void', so this only applies to function return types). */
10673 || code
== VOID_TYPE
)
10676 type_die
= modified_type_die (type
,
10677 decl_const
|| TYPE_READONLY (type
),
10678 decl_volatile
|| TYPE_VOLATILE (type
),
10681 if (type_die
!= NULL
)
10682 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
10685 /* Given a tree pointer to a struct, class, union, or enum type node, return
10686 a pointer to the (string) tag name for the given type, or zero if the type
10687 was declared without a tag. */
10689 static const char *
10690 type_tag (tree type
)
10692 const char *name
= 0;
10694 if (TYPE_NAME (type
) != 0)
10698 /* Find the IDENTIFIER_NODE for the type name. */
10699 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
10700 t
= TYPE_NAME (type
);
10702 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10703 a TYPE_DECL node, regardless of whether or not a `typedef' was
10705 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10706 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
10707 t
= DECL_NAME (TYPE_NAME (type
));
10709 /* Now get the name as a string, or invent one. */
10711 name
= IDENTIFIER_POINTER (t
);
10714 return (name
== 0 || *name
== '\0') ? 0 : name
;
10717 /* Return the type associated with a data member, make a special check
10718 for bit field types. */
10721 member_declared_type (tree member
)
10723 return (DECL_BIT_FIELD_TYPE (member
)
10724 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
10727 /* Get the decl's label, as described by its RTL. This may be different
10728 from the DECL_NAME name used in the source file. */
10731 static const char *
10732 decl_start_label (tree decl
)
10735 const char *fnname
;
10737 x
= DECL_RTL (decl
);
10742 if (GET_CODE (x
) != SYMBOL_REF
)
10745 fnname
= XSTR (x
, 0);
10750 /* These routines generate the internal representation of the DIE's for
10751 the compilation unit. Debugging information is collected by walking
10752 the declaration trees passed in from dwarf2out_decl(). */
10755 gen_array_type_die (tree type
, dw_die_ref context_die
)
10757 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
10758 dw_die_ref array_die
;
10761 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10762 the inner array type comes before the outer array type. Thus we must
10763 call gen_type_die before we call new_die. See below also. */
10764 #ifdef MIPS_DEBUGGING_INFO
10765 gen_type_die (TREE_TYPE (type
), context_die
);
10768 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
10769 add_name_attribute (array_die
, type_tag (type
));
10770 equate_type_number_to_die (type
, array_die
);
10772 if (TREE_CODE (type
) == VECTOR_TYPE
)
10774 /* The frontend feeds us a representation for the vector as a struct
10775 containing an array. Pull out the array type. */
10776 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
10777 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
10781 /* We default the array ordering. SDB will probably do
10782 the right things even if DW_AT_ordering is not present. It's not even
10783 an issue until we start to get into multidimensional arrays anyway. If
10784 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10785 then we'll have to put the DW_AT_ordering attribute back in. (But if
10786 and when we find out that we need to put these in, we will only do so
10787 for multidimensional arrays. */
10788 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
10791 #ifdef MIPS_DEBUGGING_INFO
10792 /* The SGI compilers handle arrays of unknown bound by setting
10793 AT_declaration and not emitting any subrange DIEs. */
10794 if (! TYPE_DOMAIN (type
))
10795 add_AT_flag (array_die
, DW_AT_declaration
, 1);
10798 add_subscript_info (array_die
, type
);
10800 /* Add representation of the type of the elements of this array type. */
10801 element_type
= TREE_TYPE (type
);
10803 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10804 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10805 We work around this by disabling this feature. See also
10806 add_subscript_info. */
10807 #ifndef MIPS_DEBUGGING_INFO
10808 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
10809 element_type
= TREE_TYPE (element_type
);
10811 gen_type_die (element_type
, context_die
);
10814 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
10818 gen_set_type_die (tree type
, dw_die_ref context_die
)
10820 dw_die_ref type_die
10821 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
10823 equate_type_number_to_die (type
, type_die
);
10824 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
10829 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
10831 tree origin
= decl_ultimate_origin (decl
);
10832 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
10834 if (origin
!= NULL
)
10835 add_abstract_origin_attribute (decl_die
, origin
);
10838 add_name_and_src_coords_attributes (decl_die
, decl
);
10839 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
10840 0, 0, context_die
);
10843 if (DECL_ABSTRACT (decl
))
10844 equate_decl_number_to_die (decl
, decl_die
);
10846 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
10850 /* Walk through the list of incomplete types again, trying once more to
10851 emit full debugging info for them. */
10854 retry_incomplete_types (void)
10858 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
10859 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
10862 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10865 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
10867 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
10869 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10870 be incomplete and such types are not marked. */
10871 add_abstract_origin_attribute (type_die
, type
);
10874 /* Generate a DIE to represent an inlined instance of a structure type. */
10877 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
10879 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
10881 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10882 be incomplete and such types are not marked. */
10883 add_abstract_origin_attribute (type_die
, type
);
10886 /* Generate a DIE to represent an inlined instance of a union type. */
10889 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
10891 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
10893 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10894 be incomplete and such types are not marked. */
10895 add_abstract_origin_attribute (type_die
, type
);
10898 /* Generate a DIE to represent an enumeration type. Note that these DIEs
10899 include all of the information about the enumeration values also. Each
10900 enumerated type name/value is listed as a child of the enumerated type
10904 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
10906 dw_die_ref type_die
= lookup_type_die (type
);
10908 if (type_die
== NULL
)
10910 type_die
= new_die (DW_TAG_enumeration_type
,
10911 scope_die_for (type
, context_die
), type
);
10912 equate_type_number_to_die (type
, type_die
);
10913 add_name_attribute (type_die
, type_tag (type
));
10915 else if (! TYPE_SIZE (type
))
10918 remove_AT (type_die
, DW_AT_declaration
);
10920 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
10921 given enum type is incomplete, do not generate the DW_AT_byte_size
10922 attribute or the DW_AT_element_list attribute. */
10923 if (TYPE_SIZE (type
))
10927 TREE_ASM_WRITTEN (type
) = 1;
10928 add_byte_size_attribute (type_die
, type
);
10929 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
10930 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
10932 /* If the first reference to this type was as the return type of an
10933 inline function, then it may not have a parent. Fix this now. */
10934 if (type_die
->die_parent
== NULL
)
10935 add_child_die (scope_die_for (type
, context_die
), type_die
);
10937 for (link
= TYPE_VALUES (type
);
10938 link
!= NULL
; link
= TREE_CHAIN (link
))
10940 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
10941 tree value
= TREE_VALUE (link
);
10943 add_name_attribute (enum_die
,
10944 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
10946 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
10947 /* DWARF2 does not provide a way of indicating whether or
10948 not enumeration constants are signed or unsigned. GDB
10949 always assumes the values are signed, so we output all
10950 values as if they were signed. That means that
10951 enumeration constants with very large unsigned values
10952 will appear to have negative values in the debugger. */
10953 add_AT_int (enum_die
, DW_AT_const_value
,
10954 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
10958 add_AT_flag (type_die
, DW_AT_declaration
, 1);
10963 /* Generate a DIE to represent either a real live formal parameter decl or to
10964 represent just the type of some formal parameter position in some function
10967 Note that this routine is a bit unusual because its argument may be a
10968 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
10969 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
10970 node. If it's the former then this function is being called to output a
10971 DIE to represent a formal parameter object (or some inlining thereof). If
10972 it's the latter, then this function is only being called to output a
10973 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
10974 argument type of some subprogram type. */
10977 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
10979 dw_die_ref parm_die
10980 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
10983 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
10986 origin
= decl_ultimate_origin (node
);
10987 if (origin
!= NULL
)
10988 add_abstract_origin_attribute (parm_die
, origin
);
10991 add_name_and_src_coords_attributes (parm_die
, node
);
10992 add_type_attribute (parm_die
, TREE_TYPE (node
),
10993 TREE_READONLY (node
),
10994 TREE_THIS_VOLATILE (node
),
10996 if (DECL_ARTIFICIAL (node
))
10997 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11000 equate_decl_number_to_die (node
, parm_die
);
11001 if (! DECL_ABSTRACT (node
))
11002 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
11007 /* We were called with some kind of a ..._TYPE node. */
11008 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
11018 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11019 at the end of an (ANSI prototyped) formal parameters list. */
11022 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
11024 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
11027 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11028 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11029 parameters as specified in some function type specification (except for
11030 those which appear as part of a function *definition*). */
11033 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
11036 tree formal_type
= NULL
;
11037 tree first_parm_type
;
11040 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
11042 arg
= DECL_ARGUMENTS (function_or_method_type
);
11043 function_or_method_type
= TREE_TYPE (function_or_method_type
);
11048 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
11050 /* Make our first pass over the list of formal parameter types and output a
11051 DW_TAG_formal_parameter DIE for each one. */
11052 for (link
= first_parm_type
; link
; )
11054 dw_die_ref parm_die
;
11056 formal_type
= TREE_VALUE (link
);
11057 if (formal_type
== void_type_node
)
11060 /* Output a (nameless) DIE to represent the formal parameter itself. */
11061 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
11062 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
11063 && link
== first_parm_type
)
11064 || (arg
&& DECL_ARTIFICIAL (arg
)))
11065 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11067 link
= TREE_CHAIN (link
);
11069 arg
= TREE_CHAIN (arg
);
11072 /* If this function type has an ellipsis, add a
11073 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11074 if (formal_type
!= void_type_node
)
11075 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
11077 /* Make our second (and final) pass over the list of formal parameter types
11078 and output DIEs to represent those types (as necessary). */
11079 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
11080 link
&& TREE_VALUE (link
);
11081 link
= TREE_CHAIN (link
))
11082 gen_type_die (TREE_VALUE (link
), context_die
);
11085 /* We want to generate the DIE for TYPE so that we can generate the
11086 die for MEMBER, which has been defined; we will need to refer back
11087 to the member declaration nested within TYPE. If we're trying to
11088 generate minimal debug info for TYPE, processing TYPE won't do the
11089 trick; we need to attach the member declaration by hand. */
11092 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
11094 gen_type_die (type
, context_die
);
11096 /* If we're trying to avoid duplicate debug info, we may not have
11097 emitted the member decl for this function. Emit it now. */
11098 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
11099 && ! lookup_decl_die (member
))
11101 if (decl_ultimate_origin (member
))
11104 push_decl_scope (type
);
11105 if (TREE_CODE (member
) == FUNCTION_DECL
)
11106 gen_subprogram_die (member
, lookup_type_die (type
));
11108 gen_variable_die (member
, lookup_type_die (type
));
11114 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11115 may later generate inlined and/or out-of-line instances of. */
11118 dwarf2out_abstract_function (tree decl
)
11120 dw_die_ref old_die
;
11123 int was_abstract
= DECL_ABSTRACT (decl
);
11125 /* Make sure we have the actual abstract inline, not a clone. */
11126 decl
= DECL_ORIGIN (decl
);
11128 old_die
= lookup_decl_die (decl
);
11129 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
11130 /* We've already generated the abstract instance. */
11133 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11134 we don't get confused by DECL_ABSTRACT. */
11135 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11137 context
= decl_class_context (decl
);
11139 gen_type_die_for_member
11140 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
11143 /* Pretend we've just finished compiling this function. */
11144 save_fn
= current_function_decl
;
11145 current_function_decl
= decl
;
11147 set_decl_abstract_flags (decl
, 1);
11148 dwarf2out_decl (decl
);
11149 if (! was_abstract
)
11150 set_decl_abstract_flags (decl
, 0);
11152 current_function_decl
= save_fn
;
11155 /* Generate a DIE to represent a declared function (either file-scope or
11159 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
11161 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11162 tree origin
= decl_ultimate_origin (decl
);
11163 dw_die_ref subr_die
;
11167 dw_die_ref old_die
= lookup_decl_die (decl
);
11168 int declaration
= (current_function_decl
!= decl
11169 || class_or_namespace_scope_p (context_die
));
11171 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11172 started to generate the abstract instance of an inline, decided to output
11173 its containing class, and proceeded to emit the declaration of the inline
11174 from the member list for the class. If so, DECLARATION takes priority;
11175 we'll get back to the abstract instance when done with the class. */
11177 /* The class-scope declaration DIE must be the primary DIE. */
11178 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
11185 if (origin
!= NULL
)
11187 if (declaration
&& ! local_scope_p (context_die
))
11190 /* Fixup die_parent for the abstract instance of a nested
11191 inline function. */
11192 if (old_die
&& old_die
->die_parent
== NULL
)
11193 add_child_die (context_die
, old_die
);
11195 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11196 add_abstract_origin_attribute (subr_die
, origin
);
11200 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11201 unsigned file_index
= lookup_filename (s
.file
);
11203 if (!get_AT_flag (old_die
, DW_AT_declaration
)
11204 /* We can have a normal definition following an inline one in the
11205 case of redefinition of GNU C extern inlines.
11206 It seems reasonable to use AT_specification in this case. */
11207 && !get_AT (old_die
, DW_AT_inline
))
11209 /* ??? This can happen if there is a bug in the program, for
11210 instance, if it has duplicate function definitions. Ideally,
11211 we should detect this case and ignore it. For now, if we have
11212 already reported an error, any error at all, then assume that
11213 we got here because of an input error, not a dwarf2 bug. */
11219 /* If the definition comes from the same place as the declaration,
11220 maybe use the old DIE. We always want the DIE for this function
11221 that has the *_pc attributes to be under comp_unit_die so the
11222 debugger can find it. We also need to do this for abstract
11223 instances of inlines, since the spec requires the out-of-line copy
11224 to have the same parent. For local class methods, this doesn't
11225 apply; we just use the old DIE. */
11226 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
11227 && (DECL_ARTIFICIAL (decl
)
11228 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
11229 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11230 == (unsigned) s
.line
))))
11232 subr_die
= old_die
;
11234 /* Clear out the declaration attribute and the formal parameters.
11235 Do not remove all children, because it is possible that this
11236 declaration die was forced using force_decl_die(). In such
11237 cases die that forced declaration die (e.g. TAG_imported_module)
11238 is one of the children that we do not want to remove. */
11239 remove_AT (subr_die
, DW_AT_declaration
);
11240 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
11244 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11245 add_AT_specification (subr_die
, old_die
);
11246 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11247 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
11248 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11249 != (unsigned) s
.line
)
11251 (subr_die
, DW_AT_decl_line
, s
.line
);
11256 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11258 if (TREE_PUBLIC (decl
))
11259 add_AT_flag (subr_die
, DW_AT_external
, 1);
11261 add_name_and_src_coords_attributes (subr_die
, decl
);
11262 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11264 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
11265 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
11266 0, 0, context_die
);
11269 add_pure_or_virtual_attribute (subr_die
, decl
);
11270 if (DECL_ARTIFICIAL (decl
))
11271 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
11273 if (TREE_PROTECTED (decl
))
11274 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11275 else if (TREE_PRIVATE (decl
))
11276 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11281 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11283 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
11285 /* The first time we see a member function, it is in the context of
11286 the class to which it belongs. We make sure of this by emitting
11287 the class first. The next time is the definition, which is
11288 handled above. The two may come from the same source text.
11290 Note that force_decl_die() forces function declaration die. It is
11291 later reused to represent definition. */
11292 equate_decl_number_to_die (decl
, subr_die
);
11295 else if (DECL_ABSTRACT (decl
))
11297 if (DECL_DECLARED_INLINE_P (decl
))
11299 if (cgraph_function_possibly_inlined_p (decl
))
11300 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
11302 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
11306 if (cgraph_function_possibly_inlined_p (decl
))
11307 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
11309 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
11312 equate_decl_number_to_die (decl
, subr_die
);
11314 else if (!DECL_EXTERNAL (decl
))
11316 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11317 equate_decl_number_to_die (decl
, subr_die
);
11319 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
11320 current_function_funcdef_no
);
11321 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
11322 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11323 current_function_funcdef_no
);
11324 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
11326 add_pubname (decl
, subr_die
);
11327 add_arange (decl
, subr_die
);
11329 #ifdef MIPS_DEBUGGING_INFO
11330 /* Add a reference to the FDE for this routine. */
11331 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
11334 /* Define the "frame base" location for this routine. We use the
11335 frame pointer or stack pointer registers, since the RTL for local
11336 variables is relative to one of them. */
11337 if (frame_base_decl
&& lookup_decl_loc (frame_base_decl
) != NULL
)
11339 add_location_or_const_value_attribute (subr_die
, frame_base_decl
,
11345 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
11346 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
11349 if (cfun
->static_chain_decl
)
11350 add_AT_location_description (subr_die
, DW_AT_static_link
,
11351 loc_descriptor_from_tree (cfun
->static_chain_decl
));
11354 /* Now output descriptions of the arguments for this function. This gets
11355 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11356 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11357 `...' at the end of the formal parameter list. In order to find out if
11358 there was a trailing ellipsis or not, we must instead look at the type
11359 associated with the FUNCTION_DECL. This will be a node of type
11360 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11361 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11362 an ellipsis at the end. */
11364 /* In the case where we are describing a mere function declaration, all we
11365 need to do here (and all we *can* do here) is to describe the *types* of
11366 its formal parameters. */
11367 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11369 else if (declaration
)
11370 gen_formal_types_die (decl
, subr_die
);
11373 /* Generate DIEs to represent all known formal parameters. */
11374 tree arg_decls
= DECL_ARGUMENTS (decl
);
11377 /* When generating DIEs, generate the unspecified_parameters DIE
11378 instead if we come across the arg "__builtin_va_alist" */
11379 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
11380 if (TREE_CODE (parm
) == PARM_DECL
)
11382 if (DECL_NAME (parm
)
11383 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
11384 "__builtin_va_alist"))
11385 gen_unspecified_parameters_die (parm
, subr_die
);
11387 gen_decl_die (parm
, subr_die
);
11390 /* Decide whether we need an unspecified_parameters DIE at the end.
11391 There are 2 more cases to do this for: 1) the ansi ... declaration -
11392 this is detectable when the end of the arg list is not a
11393 void_type_node 2) an unprototyped function declaration (not a
11394 definition). This just means that we have no info about the
11395 parameters at all. */
11396 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
11397 if (fn_arg_types
!= NULL
)
11399 /* This is the prototyped case, check for.... */
11400 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
11401 gen_unspecified_parameters_die (decl
, subr_die
);
11403 else if (DECL_INITIAL (decl
) == NULL_TREE
)
11404 gen_unspecified_parameters_die (decl
, subr_die
);
11407 /* Output Dwarf info for all of the stuff within the body of the function
11408 (if it has one - it may be just a declaration). */
11409 outer_scope
= DECL_INITIAL (decl
);
11411 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11412 a function. This BLOCK actually represents the outermost binding contour
11413 for the function, i.e. the contour in which the function's formal
11414 parameters and labels get declared. Curiously, it appears that the front
11415 end doesn't actually put the PARM_DECL nodes for the current function onto
11416 the BLOCK_VARS list for this outer scope, but are strung off of the
11417 DECL_ARGUMENTS list for the function instead.
11419 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11420 the LABEL_DECL nodes for the function however, and we output DWARF info
11421 for those in decls_for_scope. Just within the `outer_scope' there will be
11422 a BLOCK node representing the function's outermost pair of curly braces,
11423 and any blocks used for the base and member initializers of a C++
11424 constructor function. */
11425 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
11427 /* Emit a DW_TAG_variable DIE for a named return value. */
11428 if (DECL_NAME (DECL_RESULT (decl
)))
11429 gen_decl_die (DECL_RESULT (decl
), subr_die
);
11431 current_function_has_inlines
= 0;
11432 decls_for_scope (outer_scope
, subr_die
, 0);
11434 #if 0 && defined (MIPS_DEBUGGING_INFO)
11435 if (current_function_has_inlines
)
11437 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
11438 if (! comp_unit_has_inlines
)
11440 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
11441 comp_unit_has_inlines
= 1;
11448 /* Generate a DIE to represent a declared data object. */
11451 gen_variable_die (tree decl
, dw_die_ref context_die
)
11453 tree origin
= decl_ultimate_origin (decl
);
11454 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
11456 dw_die_ref old_die
= lookup_decl_die (decl
);
11457 int declaration
= (DECL_EXTERNAL (decl
)
11458 || class_or_namespace_scope_p (context_die
));
11460 if (origin
!= NULL
)
11461 add_abstract_origin_attribute (var_die
, origin
);
11463 /* Loop unrolling can create multiple blocks that refer to the same
11464 static variable, so we must test for the DW_AT_declaration flag.
11466 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11467 copy decls and set the DECL_ABSTRACT flag on them instead of
11470 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
11471 else if (old_die
&& TREE_STATIC (decl
)
11472 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
11474 /* This is a definition of a C++ class level static. */
11475 add_AT_specification (var_die
, old_die
);
11476 if (DECL_NAME (decl
))
11478 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11479 unsigned file_index
= lookup_filename (s
.file
);
11481 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11482 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
11484 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11485 != (unsigned) s
.line
)
11487 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
11492 add_name_and_src_coords_attributes (var_die
, decl
);
11493 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
11494 TREE_THIS_VOLATILE (decl
), context_die
);
11496 if (TREE_PUBLIC (decl
))
11497 add_AT_flag (var_die
, DW_AT_external
, 1);
11499 if (DECL_ARTIFICIAL (decl
))
11500 add_AT_flag (var_die
, DW_AT_artificial
, 1);
11502 if (TREE_PROTECTED (decl
))
11503 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11504 else if (TREE_PRIVATE (decl
))
11505 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11509 add_AT_flag (var_die
, DW_AT_declaration
, 1);
11511 if (DECL_ABSTRACT (decl
) || declaration
)
11512 equate_decl_number_to_die (decl
, var_die
);
11514 if (! declaration
&& ! DECL_ABSTRACT (decl
))
11516 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
11517 add_pubname (decl
, var_die
);
11520 tree_add_const_value_attribute (var_die
, decl
);
11523 /* Generate a DIE to represent a label identifier. */
11526 gen_label_die (tree decl
, dw_die_ref context_die
)
11528 tree origin
= decl_ultimate_origin (decl
);
11529 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
11531 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11533 if (origin
!= NULL
)
11534 add_abstract_origin_attribute (lbl_die
, origin
);
11536 add_name_and_src_coords_attributes (lbl_die
, decl
);
11538 if (DECL_ABSTRACT (decl
))
11539 equate_decl_number_to_die (decl
, lbl_die
);
11542 insn
= DECL_RTL_IF_SET (decl
);
11544 /* Deleted labels are programmer specified labels which have been
11545 eliminated because of various optimizations. We still emit them
11546 here so that it is possible to put breakpoints on them. */
11550 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
))))
11552 /* When optimization is enabled (via -O) some parts of the compiler
11553 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11554 represent source-level labels which were explicitly declared by
11555 the user. This really shouldn't be happening though, so catch
11556 it if it ever does happen. */
11557 if (INSN_DELETED_P (insn
))
11560 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
11561 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
11566 /* Generate a DIE for a lexical block. */
11569 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
11571 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
11572 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11574 if (! BLOCK_ABSTRACT (stmt
))
11576 if (BLOCK_FRAGMENT_CHAIN (stmt
))
11580 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
11582 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
11585 add_ranges (chain
);
11586 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
11593 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11594 BLOCK_NUMBER (stmt
));
11595 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
11596 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11597 BLOCK_NUMBER (stmt
));
11598 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
11602 decls_for_scope (stmt
, stmt_die
, depth
);
11605 /* Generate a DIE for an inlined subprogram. */
11608 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
11610 tree decl
= block_ultimate_origin (stmt
);
11612 /* Emit info for the abstract instance first, if we haven't yet. We
11613 must emit this even if the block is abstract, otherwise when we
11614 emit the block below (or elsewhere), we may end up trying to emit
11615 a die whose origin die hasn't been emitted, and crashing. */
11616 dwarf2out_abstract_function (decl
);
11618 if (! BLOCK_ABSTRACT (stmt
))
11620 dw_die_ref subr_die
11621 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
11622 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11624 add_abstract_origin_attribute (subr_die
, decl
);
11625 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11626 BLOCK_NUMBER (stmt
));
11627 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
11628 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11629 BLOCK_NUMBER (stmt
));
11630 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
11631 decls_for_scope (stmt
, subr_die
, depth
);
11632 current_function_has_inlines
= 1;
11635 /* We may get here if we're the outer block of function A that was
11636 inlined into function B that was inlined into function C. When
11637 generating debugging info for C, dwarf2out_abstract_function(B)
11638 would mark all inlined blocks as abstract, including this one.
11639 So, we wouldn't (and shouldn't) expect labels to be generated
11640 for this one. Instead, just emit debugging info for
11641 declarations within the block. This is particularly important
11642 in the case of initializers of arguments passed from B to us:
11643 if they're statement expressions containing declarations, we
11644 wouldn't generate dies for their abstract variables, and then,
11645 when generating dies for the real variables, we'd die (pun
11647 gen_lexical_block_die (stmt
, context_die
, depth
);
11650 /* Generate a DIE for a field in a record, or structure. */
11653 gen_field_die (tree decl
, dw_die_ref context_die
)
11655 dw_die_ref decl_die
;
11657 if (TREE_TYPE (decl
) == error_mark_node
)
11660 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
11661 add_name_and_src_coords_attributes (decl_die
, decl
);
11662 add_type_attribute (decl_die
, member_declared_type (decl
),
11663 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
11666 if (DECL_BIT_FIELD_TYPE (decl
))
11668 add_byte_size_attribute (decl_die
, decl
);
11669 add_bit_size_attribute (decl_die
, decl
);
11670 add_bit_offset_attribute (decl_die
, decl
);
11673 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
11674 add_data_member_location_attribute (decl_die
, decl
);
11676 if (DECL_ARTIFICIAL (decl
))
11677 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11679 if (TREE_PROTECTED (decl
))
11680 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11681 else if (TREE_PRIVATE (decl
))
11682 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11686 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11687 Use modified_type_die instead.
11688 We keep this code here just in case these types of DIEs may be needed to
11689 represent certain things in other languages (e.g. Pascal) someday. */
11692 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
11695 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
11697 equate_type_number_to_die (type
, ptr_die
);
11698 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11699 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11702 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11703 Use modified_type_die instead.
11704 We keep this code here just in case these types of DIEs may be needed to
11705 represent certain things in other languages (e.g. Pascal) someday. */
11708 gen_reference_type_die (tree type
, dw_die_ref context_die
)
11711 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
11713 equate_type_number_to_die (type
, ref_die
);
11714 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
11715 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11719 /* Generate a DIE for a pointer to a member type. */
11722 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
11725 = new_die (DW_TAG_ptr_to_member_type
,
11726 scope_die_for (type
, context_die
), type
);
11728 equate_type_number_to_die (type
, ptr_die
);
11729 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
11730 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
11731 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11734 /* Generate the DIE for the compilation unit. */
11737 gen_compile_unit_die (const char *filename
)
11740 char producer
[250];
11741 const char *language_string
= lang_hooks
.name
;
11744 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
11748 add_name_attribute (die
, filename
);
11749 /* Don't add cwd for <built-in>. */
11750 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
11751 add_comp_dir_attribute (die
);
11754 sprintf (producer
, "%s %s", language_string
, version_string
);
11756 #ifdef MIPS_DEBUGGING_INFO
11757 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11758 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11759 not appear in the producer string, the debugger reaches the conclusion
11760 that the object file is stripped and has no debugging information.
11761 To get the MIPS/SGI debugger to believe that there is debugging
11762 information in the object file, we add a -g to the producer string. */
11763 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11764 strcat (producer
, " -g");
11767 add_AT_string (die
, DW_AT_producer
, producer
);
11769 if (strcmp (language_string
, "GNU C++") == 0)
11770 language
= DW_LANG_C_plus_plus
;
11771 else if (strcmp (language_string
, "GNU Ada") == 0)
11772 language
= DW_LANG_Ada95
;
11773 else if (strcmp (language_string
, "GNU F77") == 0)
11774 language
= DW_LANG_Fortran77
;
11775 else if (strcmp (language_string
, "GNU F95") == 0)
11776 language
= DW_LANG_Fortran95
;
11777 else if (strcmp (language_string
, "GNU Pascal") == 0)
11778 language
= DW_LANG_Pascal83
;
11779 else if (strcmp (language_string
, "GNU Java") == 0)
11780 language
= DW_LANG_Java
;
11782 language
= DW_LANG_C89
;
11784 add_AT_unsigned (die
, DW_AT_language
, language
);
11788 /* Generate a DIE for a string type. */
11791 gen_string_type_die (tree type
, dw_die_ref context_die
)
11793 dw_die_ref type_die
11794 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
11796 equate_type_number_to_die (type
, type_die
);
11798 /* ??? Fudge the string length attribute for now.
11799 TODO: add string length info. */
11801 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
11802 bound_representation (upper_bound
, 0, 'u');
11806 /* Generate the DIE for a base class. */
11809 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
11811 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
11813 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
11814 add_data_member_location_attribute (die
, binfo
);
11816 if (BINFO_VIRTUAL_P (binfo
))
11817 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11819 if (access
== access_public_node
)
11820 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
11821 else if (access
== access_protected_node
)
11822 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11825 /* Generate a DIE for a class member. */
11828 gen_member_die (tree type
, dw_die_ref context_die
)
11831 tree binfo
= TYPE_BINFO (type
);
11834 /* If this is not an incomplete type, output descriptions of each of its
11835 members. Note that as we output the DIEs necessary to represent the
11836 members of this record or union type, we will also be trying to output
11837 DIEs to represent the *types* of those members. However the `type'
11838 function (above) will specifically avoid generating type DIEs for member
11839 types *within* the list of member DIEs for this (containing) type except
11840 for those types (of members) which are explicitly marked as also being
11841 members of this (containing) type themselves. The g++ front- end can
11842 force any given type to be treated as a member of some other (containing)
11843 type by setting the TYPE_CONTEXT of the given (member) type to point to
11844 the TREE node representing the appropriate (containing) type. */
11846 /* First output info about the base classes. */
11849 VEC (tree
) *accesses
= BINFO_BASE_ACCESSES (binfo
);
11853 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
11854 gen_inheritance_die (base
,
11855 (accesses
? VEC_index (tree
, accesses
, i
)
11856 : access_public_node
), context_die
);
11859 /* Now output info about the data members and type members. */
11860 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
11862 /* If we thought we were generating minimal debug info for TYPE
11863 and then changed our minds, some of the member declarations
11864 may have already been defined. Don't define them again, but
11865 do put them in the right order. */
11867 child
= lookup_decl_die (member
);
11869 splice_child_die (context_die
, child
);
11871 gen_decl_die (member
, context_die
);
11874 /* Now output info about the function members (if any). */
11875 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
11877 /* Don't include clones in the member list. */
11878 if (DECL_ABSTRACT_ORIGIN (member
))
11881 child
= lookup_decl_die (member
);
11883 splice_child_die (context_die
, child
);
11885 gen_decl_die (member
, context_die
);
11889 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
11890 is set, we pretend that the type was never defined, so we only get the
11891 member DIEs needed by later specification DIEs. */
11894 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
11896 dw_die_ref type_die
= lookup_type_die (type
);
11897 dw_die_ref scope_die
= 0;
11899 int complete
= (TYPE_SIZE (type
)
11900 && (! TYPE_STUB_DECL (type
)
11901 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
11902 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
11904 if (type_die
&& ! complete
)
11907 if (TYPE_CONTEXT (type
) != NULL_TREE
11908 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
11909 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
11912 scope_die
= scope_die_for (type
, context_die
);
11914 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
11915 /* First occurrence of type or toplevel definition of nested class. */
11917 dw_die_ref old_die
= type_die
;
11919 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
11920 ? DW_TAG_structure_type
: DW_TAG_union_type
,
11922 equate_type_number_to_die (type
, type_die
);
11924 add_AT_specification (type_die
, old_die
);
11926 add_name_attribute (type_die
, type_tag (type
));
11929 remove_AT (type_die
, DW_AT_declaration
);
11931 /* If this type has been completed, then give it a byte_size attribute and
11932 then give a list of members. */
11933 if (complete
&& !ns_decl
)
11935 /* Prevent infinite recursion in cases where the type of some member of
11936 this type is expressed in terms of this type itself. */
11937 TREE_ASM_WRITTEN (type
) = 1;
11938 add_byte_size_attribute (type_die
, type
);
11939 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11940 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11942 /* If the first reference to this type was as the return type of an
11943 inline function, then it may not have a parent. Fix this now. */
11944 if (type_die
->die_parent
== NULL
)
11945 add_child_die (scope_die
, type_die
);
11947 push_decl_scope (type
);
11948 gen_member_die (type
, type_die
);
11951 /* GNU extension: Record what type our vtable lives in. */
11952 if (TYPE_VFIELD (type
))
11954 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
11956 gen_type_die (vtype
, context_die
);
11957 add_AT_die_ref (type_die
, DW_AT_containing_type
,
11958 lookup_type_die (vtype
));
11963 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11965 /* We don't need to do this for function-local types. */
11966 if (TYPE_STUB_DECL (type
)
11967 && ! decl_function_context (TYPE_STUB_DECL (type
)))
11968 VARRAY_PUSH_TREE (incomplete_types
, type
);
11972 /* Generate a DIE for a subroutine _type_. */
11975 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
11977 tree return_type
= TREE_TYPE (type
);
11978 dw_die_ref subr_die
11979 = new_die (DW_TAG_subroutine_type
,
11980 scope_die_for (type
, context_die
), type
);
11982 equate_type_number_to_die (type
, subr_die
);
11983 add_prototyped_attribute (subr_die
, type
);
11984 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
11985 gen_formal_types_die (type
, subr_die
);
11988 /* Generate a DIE for a type definition. */
11991 gen_typedef_die (tree decl
, dw_die_ref context_die
)
11993 dw_die_ref type_die
;
11996 if (TREE_ASM_WRITTEN (decl
))
11999 TREE_ASM_WRITTEN (decl
) = 1;
12000 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
12001 origin
= decl_ultimate_origin (decl
);
12002 if (origin
!= NULL
)
12003 add_abstract_origin_attribute (type_die
, origin
);
12008 add_name_and_src_coords_attributes (type_die
, decl
);
12009 if (DECL_ORIGINAL_TYPE (decl
))
12011 type
= DECL_ORIGINAL_TYPE (decl
);
12013 if (type
== TREE_TYPE (decl
))
12016 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
12019 type
= TREE_TYPE (decl
);
12021 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
12022 TREE_THIS_VOLATILE (decl
), context_die
);
12025 if (DECL_ABSTRACT (decl
))
12026 equate_decl_number_to_die (decl
, type_die
);
12029 /* Generate a type description DIE. */
12032 gen_type_die (tree type
, dw_die_ref context_die
)
12036 if (type
== NULL_TREE
|| type
== error_mark_node
)
12039 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12040 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
12042 if (TREE_ASM_WRITTEN (type
))
12045 /* Prevent broken recursion; we can't hand off to the same type. */
12046 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
12049 TREE_ASM_WRITTEN (type
) = 1;
12050 gen_decl_die (TYPE_NAME (type
), context_die
);
12054 /* We are going to output a DIE to represent the unqualified version
12055 of this type (i.e. without any const or volatile qualifiers) so
12056 get the main variant (i.e. the unqualified version) of this type
12057 now. (Vectors are special because the debugging info is in the
12058 cloned type itself). */
12059 if (TREE_CODE (type
) != VECTOR_TYPE
)
12060 type
= type_main_variant (type
);
12062 if (TREE_ASM_WRITTEN (type
))
12065 switch (TREE_CODE (type
))
12071 case REFERENCE_TYPE
:
12072 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12073 ensures that the gen_type_die recursion will terminate even if the
12074 type is recursive. Recursive types are possible in Ada. */
12075 /* ??? We could perhaps do this for all types before the switch
12077 TREE_ASM_WRITTEN (type
) = 1;
12079 /* For these types, all that is required is that we output a DIE (or a
12080 set of DIEs) to represent the "basis" type. */
12081 gen_type_die (TREE_TYPE (type
), context_die
);
12085 /* This code is used for C++ pointer-to-data-member types.
12086 Output a description of the relevant class type. */
12087 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
12089 /* Output a description of the type of the object pointed to. */
12090 gen_type_die (TREE_TYPE (type
), context_die
);
12092 /* Now output a DIE to represent this pointer-to-data-member type
12094 gen_ptr_to_mbr_type_die (type
, context_die
);
12098 gen_type_die (TYPE_DOMAIN (type
), context_die
);
12099 gen_set_type_die (type
, context_die
);
12103 gen_type_die (TREE_TYPE (type
), context_die
);
12104 abort (); /* No way to represent these in Dwarf yet! */
12107 case FUNCTION_TYPE
:
12108 /* Force out return type (in case it wasn't forced out already). */
12109 gen_type_die (TREE_TYPE (type
), context_die
);
12110 gen_subroutine_type_die (type
, context_die
);
12114 /* Force out return type (in case it wasn't forced out already). */
12115 gen_type_die (TREE_TYPE (type
), context_die
);
12116 gen_subroutine_type_die (type
, context_die
);
12120 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
12122 gen_type_die (TREE_TYPE (type
), context_die
);
12123 gen_string_type_die (type
, context_die
);
12126 gen_array_type_die (type
, context_die
);
12130 gen_array_type_die (type
, context_die
);
12133 case ENUMERAL_TYPE
:
12136 case QUAL_UNION_TYPE
:
12137 /* If this is a nested type whose containing class hasn't been written
12138 out yet, writing it out will cover this one, too. This does not apply
12139 to instantiations of member class templates; they need to be added to
12140 the containing class as they are generated. FIXME: This hurts the
12141 idea of combining type decls from multiple TUs, since we can't predict
12142 what set of template instantiations we'll get. */
12143 if (TYPE_CONTEXT (type
)
12144 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12145 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
12147 gen_type_die (TYPE_CONTEXT (type
), context_die
);
12149 if (TREE_ASM_WRITTEN (type
))
12152 /* If that failed, attach ourselves to the stub. */
12153 push_decl_scope (TYPE_CONTEXT (type
));
12154 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
12159 declare_in_namespace (type
, context_die
);
12163 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12164 gen_enumeration_type_die (type
, context_die
);
12166 gen_struct_or_union_type_die (type
, context_die
);
12171 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12172 it up if it is ever completed. gen_*_type_die will set it for us
12173 when appropriate. */
12182 /* No DIEs needed for fundamental types. */
12186 /* No Dwarf representation currently defined. */
12193 TREE_ASM_WRITTEN (type
) = 1;
12196 /* Generate a DIE for a tagged type instantiation. */
12199 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
12201 if (type
== NULL_TREE
|| type
== error_mark_node
)
12204 /* We are going to output a DIE to represent the unqualified version of
12205 this type (i.e. without any const or volatile qualifiers) so make sure
12206 that we have the main variant (i.e. the unqualified version) of this
12208 if (type
!= type_main_variant (type
))
12211 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12212 an instance of an unresolved type. */
12214 switch (TREE_CODE (type
))
12219 case ENUMERAL_TYPE
:
12220 gen_inlined_enumeration_type_die (type
, context_die
);
12224 gen_inlined_structure_type_die (type
, context_die
);
12228 case QUAL_UNION_TYPE
:
12229 gen_inlined_union_type_die (type
, context_die
);
12237 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12238 things which are local to the given block. */
12241 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12243 int must_output_die
= 0;
12246 enum tree_code origin_code
;
12248 /* Ignore blocks never really used to make RTL. */
12249 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
12250 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
12253 /* If the block is one fragment of a non-contiguous block, do not
12254 process the variables, since they will have been done by the
12255 origin block. Do process subblocks. */
12256 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
12260 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
12261 gen_block_die (sub
, context_die
, depth
+ 1);
12266 /* Determine the "ultimate origin" of this block. This block may be an
12267 inlined instance of an inlined instance of inline function, so we have
12268 to trace all of the way back through the origin chain to find out what
12269 sort of node actually served as the original seed for the creation of
12270 the current block. */
12271 origin
= block_ultimate_origin (stmt
);
12272 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
12274 /* Determine if we need to output any Dwarf DIEs at all to represent this
12276 if (origin_code
== FUNCTION_DECL
)
12277 /* The outer scopes for inlinings *must* always be represented. We
12278 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12279 must_output_die
= 1;
12282 /* In the case where the current block represents an inlining of the
12283 "body block" of an inline function, we must *NOT* output any DIE for
12284 this block because we have already output a DIE to represent the whole
12285 inlined function scope and the "body block" of any function doesn't
12286 really represent a different scope according to ANSI C rules. So we
12287 check here to make sure that this block does not represent a "body
12288 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12289 if (! is_body_block (origin
? origin
: stmt
))
12291 /* Determine if this block directly contains any "significant"
12292 local declarations which we will need to output DIEs for. */
12293 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12294 /* We are not in terse mode so *any* local declaration counts
12295 as being a "significant" one. */
12296 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
12298 /* We are in terse mode, so only local (nested) function
12299 definitions count as "significant" local declarations. */
12300 for (decl
= BLOCK_VARS (stmt
);
12301 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12302 if (TREE_CODE (decl
) == FUNCTION_DECL
12303 && DECL_INITIAL (decl
))
12305 must_output_die
= 1;
12311 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12312 DIE for any block which contains no significant local declarations at
12313 all. Rather, in such cases we just call `decls_for_scope' so that any
12314 needed Dwarf info for any sub-blocks will get properly generated. Note
12315 that in terse mode, our definition of what constitutes a "significant"
12316 local declaration gets restricted to include only inlined function
12317 instances and local (nested) function definitions. */
12318 if (must_output_die
)
12320 if (origin_code
== FUNCTION_DECL
)
12321 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
12323 gen_lexical_block_die (stmt
, context_die
, depth
);
12326 decls_for_scope (stmt
, context_die
, depth
);
12329 /* Generate all of the decls declared within a given scope and (recursively)
12330 all of its sub-blocks. */
12333 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
12338 /* Ignore blocks never really used to make RTL. */
12339 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
12342 /* Output the DIEs to represent all of the data objects and typedefs
12343 declared directly within this block but not within any nested
12344 sub-blocks. Also, nested function and tag DIEs have been
12345 generated with a parent of NULL; fix that up now. */
12346 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12350 if (TREE_CODE (decl
) == FUNCTION_DECL
)
12351 die
= lookup_decl_die (decl
);
12352 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
12353 die
= lookup_type_die (TREE_TYPE (decl
));
12357 if (die
!= NULL
&& die
->die_parent
== NULL
)
12358 add_child_die (context_die
, die
);
12360 gen_decl_die (decl
, context_die
);
12363 /* If we're at -g1, we're not interested in subblocks. */
12364 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12367 /* Output the DIEs to represent all sub-blocks (and the items declared
12368 therein) of this block. */
12369 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
12371 subblocks
= BLOCK_CHAIN (subblocks
))
12372 gen_block_die (subblocks
, context_die
, depth
+ 1);
12375 /* Is this a typedef we can avoid emitting? */
12378 is_redundant_typedef (tree decl
)
12380 if (TYPE_DECL_IS_STUB (decl
))
12383 if (DECL_ARTIFICIAL (decl
)
12384 && DECL_CONTEXT (decl
)
12385 && is_tagged_type (DECL_CONTEXT (decl
))
12386 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
12387 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
12388 /* Also ignore the artificial member typedef for the class name. */
12394 /* Returns the DIE for decl or aborts. */
12397 force_decl_die (tree decl
)
12399 dw_die_ref decl_die
;
12400 unsigned saved_external_flag
;
12401 tree save_fn
= NULL_TREE
;
12402 decl_die
= lookup_decl_die (decl
);
12405 dw_die_ref context_die
;
12406 tree decl_context
= DECL_CONTEXT (decl
);
12409 /* Find die that represents this context. */
12410 if (TYPE_P (decl_context
))
12411 context_die
= force_type_die (decl_context
);
12413 context_die
= force_decl_die (decl_context
);
12416 context_die
= comp_unit_die
;
12418 switch (TREE_CODE (decl
))
12420 case FUNCTION_DECL
:
12421 /* Clear current_function_decl, so that gen_subprogram_die thinks
12422 that this is a declaration. At this point, we just want to force
12423 declaration die. */
12424 save_fn
= current_function_decl
;
12425 current_function_decl
= NULL_TREE
;
12426 gen_subprogram_die (decl
, context_die
);
12427 current_function_decl
= save_fn
;
12431 /* Set external flag to force declaration die. Restore it after
12432 gen_decl_die() call. */
12433 saved_external_flag
= DECL_EXTERNAL (decl
);
12434 DECL_EXTERNAL (decl
) = 1;
12435 gen_decl_die (decl
, context_die
);
12436 DECL_EXTERNAL (decl
) = saved_external_flag
;
12439 case NAMESPACE_DECL
:
12440 dwarf2out_decl (decl
);
12447 /* See if we can find the die for this deci now.
12448 If not then abort. */
12450 decl_die
= lookup_decl_die (decl
);
12458 /* Returns the DIE for decl or aborts. */
12461 force_type_die (tree type
)
12463 dw_die_ref type_die
;
12465 type_die
= lookup_type_die (type
);
12468 dw_die_ref context_die
;
12469 if (TYPE_CONTEXT (type
))
12470 if (TYPE_P (TYPE_CONTEXT (type
)))
12471 context_die
= force_type_die (TYPE_CONTEXT (type
));
12473 context_die
= force_decl_die (TYPE_CONTEXT (type
));
12475 context_die
= comp_unit_die
;
12477 gen_type_die (type
, context_die
);
12478 type_die
= lookup_type_die (type
);
12485 /* Force out any required namespaces to be able to output DECL,
12486 and return the new context_die for it, if it's changed. */
12489 setup_namespace_context (tree thing
, dw_die_ref context_die
)
12491 tree context
= DECL_P (thing
) ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
);
12492 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
12493 /* Force out the namespace. */
12494 context_die
= force_decl_die (context
);
12496 return context_die
;
12499 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12500 type) within its namespace, if appropriate.
12502 For compatibility with older debuggers, namespace DIEs only contain
12503 declarations; all definitions are emitted at CU scope. */
12506 declare_in_namespace (tree thing
, dw_die_ref context_die
)
12508 dw_die_ref ns_context
;
12510 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12513 ns_context
= setup_namespace_context (thing
, context_die
);
12515 if (ns_context
!= context_die
)
12517 if (DECL_P (thing
))
12518 gen_decl_die (thing
, ns_context
);
12520 gen_type_die (thing
, ns_context
);
12524 /* Generate a DIE for a namespace or namespace alias. */
12527 gen_namespace_die (tree decl
)
12529 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
12531 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12532 they are an alias of. */
12533 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
12535 /* Output a real namespace. */
12536 dw_die_ref namespace_die
12537 = new_die (DW_TAG_namespace
, context_die
, decl
);
12538 add_name_and_src_coords_attributes (namespace_die
, decl
);
12539 equate_decl_number_to_die (decl
, namespace_die
);
12543 /* Output a namespace alias. */
12545 /* Force out the namespace we are an alias of, if necessary. */
12546 dw_die_ref origin_die
12547 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
12549 /* Now create the namespace alias DIE. */
12550 dw_die_ref namespace_die
12551 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
12552 add_name_and_src_coords_attributes (namespace_die
, decl
);
12553 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
12554 equate_decl_number_to_die (decl
, namespace_die
);
12558 /* Generate Dwarf debug information for a decl described by DECL. */
12561 gen_decl_die (tree decl
, dw_die_ref context_die
)
12565 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
12568 switch (TREE_CODE (decl
))
12574 /* The individual enumerators of an enum type get output when we output
12575 the Dwarf representation of the relevant enum type itself. */
12578 case FUNCTION_DECL
:
12579 /* Don't output any DIEs to represent mere function declarations,
12580 unless they are class members or explicit block externs. */
12581 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
12582 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
12587 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
12588 on local redeclarations of global functions. That seems broken. */
12589 if (current_function_decl
!= decl
)
12590 /* This is only a declaration. */;
12593 /* If we're emitting a clone, emit info for the abstract instance. */
12594 if (DECL_ORIGIN (decl
) != decl
)
12595 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
12597 /* If we're emitting an out-of-line copy of an inline function,
12598 emit info for the abstract instance and set up to refer to it. */
12599 else if (cgraph_function_possibly_inlined_p (decl
)
12600 && ! DECL_ABSTRACT (decl
)
12601 && ! class_or_namespace_scope_p (context_die
)
12602 /* dwarf2out_abstract_function won't emit a die if this is just
12603 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
12604 that case, because that works only if we have a die. */
12605 && DECL_INITIAL (decl
) != NULL_TREE
)
12607 dwarf2out_abstract_function (decl
);
12608 set_decl_origin_self (decl
);
12611 /* Otherwise we're emitting the primary DIE for this decl. */
12612 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
12614 /* Before we describe the FUNCTION_DECL itself, make sure that we
12615 have described its return type. */
12616 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
12618 /* And its virtual context. */
12619 if (DECL_VINDEX (decl
) != NULL_TREE
)
12620 gen_type_die (DECL_CONTEXT (decl
), context_die
);
12622 /* And its containing type. */
12623 origin
= decl_class_context (decl
);
12624 if (origin
!= NULL_TREE
)
12625 gen_type_die_for_member (origin
, decl
, context_die
);
12627 /* And its containing namespace. */
12628 declare_in_namespace (decl
, context_die
);
12631 /* Now output a DIE to represent the function itself. */
12632 gen_subprogram_die (decl
, context_die
);
12636 /* If we are in terse mode, don't generate any DIEs to represent any
12637 actual typedefs. */
12638 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12641 /* In the special case of a TYPE_DECL node representing the declaration
12642 of some type tag, if the given TYPE_DECL is marked as having been
12643 instantiated from some other (original) TYPE_DECL node (e.g. one which
12644 was generated within the original definition of an inline function) we
12645 have to generate a special (abbreviated) DW_TAG_structure_type,
12646 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
12647 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
12649 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
12653 if (is_redundant_typedef (decl
))
12654 gen_type_die (TREE_TYPE (decl
), context_die
);
12656 /* Output a DIE to represent the typedef itself. */
12657 gen_typedef_die (decl
, context_die
);
12661 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12662 gen_label_die (decl
, context_die
);
12667 /* If we are in terse mode, don't generate any DIEs to represent any
12668 variable declarations or definitions. */
12669 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12672 /* Output any DIEs that are needed to specify the type of this data
12674 gen_type_die (TREE_TYPE (decl
), context_die
);
12676 /* And its containing type. */
12677 origin
= decl_class_context (decl
);
12678 if (origin
!= NULL_TREE
)
12679 gen_type_die_for_member (origin
, decl
, context_die
);
12681 /* And its containing namespace. */
12682 declare_in_namespace (decl
, context_die
);
12684 /* Now output the DIE to represent the data object itself. This gets
12685 complicated because of the possibility that the VAR_DECL really
12686 represents an inlined instance of a formal parameter for an inline
12688 origin
= decl_ultimate_origin (decl
);
12689 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
12690 gen_formal_parameter_die (decl
, context_die
);
12692 gen_variable_die (decl
, context_die
);
12696 /* Ignore the nameless fields that are used to skip bits but handle C++
12697 anonymous unions and structs. */
12698 if (DECL_NAME (decl
) != NULL_TREE
12699 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
12700 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
12702 gen_type_die (member_declared_type (decl
), context_die
);
12703 gen_field_die (decl
, context_die
);
12708 gen_type_die (TREE_TYPE (decl
), context_die
);
12709 gen_formal_parameter_die (decl
, context_die
);
12712 case NAMESPACE_DECL
:
12713 gen_namespace_die (decl
);
12717 if ((int)TREE_CODE (decl
) > NUM_TREE_CODES
)
12718 /* Probably some frontend-internal decl. Assume we don't care. */
12724 /* Add Ada "use" clause information for SGI Workshop debugger. */
12727 dwarf2out_add_library_unit_info (const char *filename
, const char *context_list
)
12729 unsigned int file_index
;
12731 if (filename
!= NULL
)
12733 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
12734 tree context_list_decl
12735 = build_decl (LABEL_DECL
, get_identifier (context_list
),
12738 TREE_PUBLIC (context_list_decl
) = TRUE
;
12739 add_name_attribute (unit_die
, context_list
);
12740 file_index
= lookup_filename (filename
);
12741 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
12742 add_pubname (context_list_decl
, unit_die
);
12746 /* Output debug information for global decl DECL. Called from toplev.c after
12747 compilation proper has finished. */
12750 dwarf2out_global_decl (tree decl
)
12752 /* Output DWARF2 information for file-scope tentative data object
12753 declarations, file-scope (extern) function declarations (which had no
12754 corresponding body) and file-scope tagged type declarations and
12755 definitions which have not yet been forced out. */
12756 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
12757 dwarf2out_decl (decl
);
12760 /* Output debug information for type decl DECL. Called from toplev.c
12761 and from language front ends (to record built-in types). */
12763 dwarf2out_type_decl (tree decl
, int local
)
12766 dwarf2out_decl (decl
);
12769 /* Output debug information for imported module or decl. */
12772 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
12774 dw_die_ref imported_die
, at_import_die
;
12775 dw_die_ref scope_die
;
12776 unsigned file_index
;
12777 expanded_location xloc
;
12779 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12785 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
12786 We need decl DIE for reference and scope die. First, get DIE for the decl
12789 /* Get the scope die for decl context. Use comp_unit_die for global module
12790 or decl. If die is not found for non globals, force new die. */
12792 scope_die
= comp_unit_die
;
12793 else if (TYPE_P (context
))
12794 scope_die
= force_type_die (context
);
12796 scope_die
= force_decl_die (context
);
12798 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
12799 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
12800 at_import_die
= force_type_die (TREE_TYPE (decl
));
12802 at_import_die
= force_decl_die (decl
);
12804 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
12805 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
12806 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
12808 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
12810 xloc
= expand_location (input_location
);
12811 file_index
= lookup_filename (xloc
.file
);
12812 add_AT_unsigned (imported_die
, DW_AT_decl_file
, file_index
);
12813 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
12814 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
12817 /* Write the debugging output for DECL. */
12820 dwarf2out_decl (tree decl
)
12822 dw_die_ref context_die
= comp_unit_die
;
12824 switch (TREE_CODE (decl
))
12829 case FUNCTION_DECL
:
12830 /* What we would really like to do here is to filter out all mere
12831 file-scope declarations of file-scope functions which are never
12832 referenced later within this translation unit (and keep all of ones
12833 that *are* referenced later on) but we aren't clairvoyant, so we have
12834 no idea which functions will be referenced in the future (i.e. later
12835 on within the current translation unit). So here we just ignore all
12836 file-scope function declarations which are not also definitions. If
12837 and when the debugger needs to know something about these functions,
12838 it will have to hunt around and find the DWARF information associated
12839 with the definition of the function.
12841 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
12842 nodes represent definitions and which ones represent mere
12843 declarations. We have to check DECL_INITIAL instead. That's because
12844 the C front-end supports some weird semantics for "extern inline"
12845 function definitions. These can get inlined within the current
12846 translation unit (an thus, we need to generate Dwarf info for their
12847 abstract instances so that the Dwarf info for the concrete inlined
12848 instances can have something to refer to) but the compiler never
12849 generates any out-of-lines instances of such things (despite the fact
12850 that they *are* definitions).
12852 The important point is that the C front-end marks these "extern
12853 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
12854 them anyway. Note that the C++ front-end also plays some similar games
12855 for inline function definitions appearing within include files which
12856 also contain `#pragma interface' pragmas. */
12857 if (DECL_INITIAL (decl
) == NULL_TREE
)
12860 /* If we're a nested function, initially use a parent of NULL; if we're
12861 a plain function, this will be fixed up in decls_for_scope. If
12862 we're a method, it will be ignored, since we already have a DIE. */
12863 if (decl_function_context (decl
)
12864 /* But if we're in terse mode, we don't care about scope. */
12865 && debug_info_level
> DINFO_LEVEL_TERSE
)
12866 context_die
= NULL
;
12870 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12871 declaration and if the declaration was never even referenced from
12872 within this entire compilation unit. We suppress these DIEs in
12873 order to save space in the .debug section (by eliminating entries
12874 which are probably useless). Note that we must not suppress
12875 block-local extern declarations (whether used or not) because that
12876 would screw-up the debugger's name lookup mechanism and cause it to
12877 miss things which really ought to be in scope at a given point. */
12878 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
12881 /* If we are in terse mode, don't generate any DIEs to represent any
12882 variable declarations or definitions. */
12883 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12887 case NAMESPACE_DECL
:
12888 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12890 if (lookup_decl_die (decl
) != NULL
)
12895 /* Don't emit stubs for types unless they are needed by other DIEs. */
12896 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
12899 /* Don't bother trying to generate any DIEs to represent any of the
12900 normal built-in types for the language we are compiling. */
12901 if (DECL_IS_BUILTIN (decl
))
12903 /* OK, we need to generate one for `bool' so GDB knows what type
12904 comparisons have. */
12905 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
12906 == DW_LANG_C_plus_plus
)
12907 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
12908 && ! DECL_IGNORED_P (decl
))
12909 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
12914 /* If we are in terse mode, don't generate any DIEs for types. */
12915 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12918 /* If we're a function-scope tag, initially use a parent of NULL;
12919 this will be fixed up in decls_for_scope. */
12920 if (decl_function_context (decl
))
12921 context_die
= NULL
;
12929 gen_decl_die (decl
, context_die
);
12932 /* Output a marker (i.e. a label) for the beginning of the generated code for
12933 a lexical block. */
12936 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
12937 unsigned int blocknum
)
12939 function_section (current_function_decl
);
12940 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
12943 /* Output a marker (i.e. a label) for the end of the generated code for a
12947 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
12949 function_section (current_function_decl
);
12950 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
12953 /* Returns nonzero if it is appropriate not to emit any debugging
12954 information for BLOCK, because it doesn't contain any instructions.
12956 Don't allow this for blocks with nested functions or local classes
12957 as we would end up with orphans, and in the presence of scheduling
12958 we may end up calling them anyway. */
12961 dwarf2out_ignore_block (tree block
)
12965 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
12966 if (TREE_CODE (decl
) == FUNCTION_DECL
12967 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
12973 /* Lookup FILE_NAME (in the list of filenames that we know about here in
12974 dwarf2out.c) and return its "index". The index of each (known) filename is
12975 just a unique number which is associated with only that one filename. We
12976 need such numbers for the sake of generating labels (in the .debug_sfnames
12977 section) and references to those files numbers (in the .debug_srcinfo
12978 and.debug_macinfo sections). If the filename given as an argument is not
12979 found in our current list, add it to the list and assign it the next
12980 available unique index number. In order to speed up searches, we remember
12981 the index of the filename was looked up last. This handles the majority of
12985 lookup_filename (const char *file_name
)
12988 char *save_file_name
;
12990 /* Check to see if the file name that was searched on the previous
12991 call matches this file name. If so, return the index. */
12992 if (file_table_last_lookup_index
!= 0)
12995 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
12996 if (strcmp (file_name
, last
) == 0)
12997 return file_table_last_lookup_index
;
13000 /* Didn't match the previous lookup, search the table */
13001 n
= VARRAY_ACTIVE_SIZE (file_table
);
13002 for (i
= 1; i
< n
; i
++)
13003 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
13005 file_table_last_lookup_index
= i
;
13009 /* Add the new entry to the end of the filename table. */
13010 file_table_last_lookup_index
= n
;
13011 save_file_name
= (char *) ggc_strdup (file_name
);
13012 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
13013 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13019 maybe_emit_file (int fileno
)
13021 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
13023 if (!VARRAY_UINT (file_table_emitted
, fileno
))
13025 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
13026 fprintf (asm_out_file
, "\t.file %u ",
13027 VARRAY_UINT (file_table_emitted
, fileno
));
13028 output_quoted_string (asm_out_file
,
13029 VARRAY_CHAR_PTR (file_table
, fileno
));
13030 fputc ('\n', asm_out_file
);
13032 return VARRAY_UINT (file_table_emitted
, fileno
);
13039 init_file_table (void)
13041 /* Allocate the initial hunk of the file_table. */
13042 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
13043 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
13045 /* Skip the first entry - file numbers begin at 1. */
13046 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
13047 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13048 file_table_last_lookup_index
= 0;
13051 /* Called by the final INSN scan whenever we see a var location. We
13052 use it to drop labels in the right places, and throw the location in
13053 our lookup table. */
13056 dwarf2out_var_location (rtx loc_note
)
13058 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
13059 struct var_loc_node
*newloc
;
13061 static rtx last_insn
;
13062 static const char *last_label
;
13064 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
13066 prev_insn
= PREV_INSN (loc_note
);
13068 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
13069 /* If the insn we processed last time is the previous insn
13070 and it is also a var location note, use the label we emitted
13072 if (last_insn
!= NULL_RTX
13073 && last_insn
== prev_insn
13074 && NOTE_P (prev_insn
)
13075 && NOTE_LINE_NUMBER (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
13077 newloc
->label
= last_label
;
13081 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
13082 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
13084 newloc
->label
= ggc_strdup (loclabel
);
13086 newloc
->var_loc_note
= loc_note
;
13087 newloc
->next
= NULL
;
13089 last_insn
= loc_note
;
13090 last_label
= newloc
->label
;
13092 add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note
), newloc
);
13095 /* We need to reset the locations at the beginning of each
13096 function. We can't do this in the end_function hook, because the
13097 declarations that use the locations won't have been outputted when
13098 that hook is called. */
13101 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED
)
13103 htab_empty (decl_loc_table
);
13106 /* Output a label to mark the beginning of a source code line entry
13107 and record information relating to this source line, in
13108 'line_info_table' for later output of the .debug_line section. */
13111 dwarf2out_source_line (unsigned int line
, const char *filename
)
13113 if (debug_info_level
>= DINFO_LEVEL_NORMAL
13116 function_section (current_function_decl
);
13118 /* If requested, emit something human-readable. */
13119 if (flag_debug_asm
)
13120 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
13123 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13125 unsigned file_num
= lookup_filename (filename
);
13127 file_num
= maybe_emit_file (file_num
);
13129 /* Emit the .loc directive understood by GNU as. */
13130 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
13132 /* Indicate that line number info exists. */
13133 line_info_table_in_use
++;
13135 /* Indicate that multiple line number tables exist. */
13136 if (DECL_SECTION_NAME (current_function_decl
))
13137 separate_line_info_table_in_use
++;
13139 else if (DECL_SECTION_NAME (current_function_decl
))
13141 dw_separate_line_info_ref line_info
;
13142 targetm
.asm_out
.internal_label (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
13143 separate_line_info_table_in_use
);
13145 /* Expand the line info table if necessary. */
13146 if (separate_line_info_table_in_use
13147 == separate_line_info_table_allocated
)
13149 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13150 separate_line_info_table
13151 = ggc_realloc (separate_line_info_table
,
13152 separate_line_info_table_allocated
13153 * sizeof (dw_separate_line_info_entry
));
13154 memset (separate_line_info_table
13155 + separate_line_info_table_in_use
,
13157 (LINE_INFO_TABLE_INCREMENT
13158 * sizeof (dw_separate_line_info_entry
)));
13161 /* Add the new entry at the end of the line_info_table. */
13163 = &separate_line_info_table
[separate_line_info_table_in_use
++];
13164 line_info
->dw_file_num
= lookup_filename (filename
);
13165 line_info
->dw_line_num
= line
;
13166 line_info
->function
= current_function_funcdef_no
;
13170 dw_line_info_ref line_info
;
13172 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
13173 line_info_table_in_use
);
13175 /* Expand the line info table if necessary. */
13176 if (line_info_table_in_use
== line_info_table_allocated
)
13178 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13180 = ggc_realloc (line_info_table
,
13181 (line_info_table_allocated
13182 * sizeof (dw_line_info_entry
)));
13183 memset (line_info_table
+ line_info_table_in_use
, 0,
13184 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
13187 /* Add the new entry at the end of the line_info_table. */
13188 line_info
= &line_info_table
[line_info_table_in_use
++];
13189 line_info
->dw_file_num
= lookup_filename (filename
);
13190 line_info
->dw_line_num
= line
;
13195 /* Record the beginning of a new source file. */
13198 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
13200 if (flag_eliminate_dwarf2_dups
)
13202 /* Record the beginning of the file for break_out_includes. */
13203 dw_die_ref bincl_die
;
13205 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
13206 add_AT_string (bincl_die
, DW_AT_name
, filename
);
13209 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13211 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13212 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
13213 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
13215 maybe_emit_file (lookup_filename (filename
));
13216 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
13217 "Filename we just started");
13221 /* Record the end of a source file. */
13224 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
13226 if (flag_eliminate_dwarf2_dups
)
13227 /* Record the end of the file for break_out_includes. */
13228 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
13230 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13232 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13233 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13237 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13238 the tail part of the directive line, i.e. the part which is past the
13239 initial whitespace, #, whitespace, directive-name, whitespace part. */
13242 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
13243 const char *buffer ATTRIBUTE_UNUSED
)
13245 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13247 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13248 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
13249 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13250 dw2_asm_output_nstring (buffer
, -1, "The macro");
13254 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13255 the tail part of the directive line, i.e. the part which is past the
13256 initial whitespace, #, whitespace, directive-name, whitespace part. */
13259 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
13260 const char *buffer ATTRIBUTE_UNUSED
)
13262 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13264 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13265 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
13266 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13267 dw2_asm_output_nstring (buffer
, -1, "The macro");
13271 /* Set up for Dwarf output at the start of compilation. */
13274 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
13276 init_file_table ();
13278 /* Allocate the decl_die_table. */
13279 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
13280 decl_die_table_eq
, NULL
);
13282 /* Allocate the decl_loc_table. */
13283 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
13284 decl_loc_table_eq
, NULL
);
13286 /* Allocate the initial hunk of the decl_scope_table. */
13287 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
13289 /* Allocate the initial hunk of the abbrev_die_table. */
13290 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13291 * sizeof (dw_die_ref
));
13292 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
13293 /* Zero-th entry is allocated, but unused */
13294 abbrev_die_table_in_use
= 1;
13296 /* Allocate the initial hunk of the line_info_table. */
13297 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13298 * sizeof (dw_line_info_entry
));
13299 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
13301 /* Zero-th entry is allocated, but unused */
13302 line_info_table_in_use
= 1;
13304 /* Generate the initial DIE for the .debug section. Note that the (string)
13305 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13306 will (typically) be a relative pathname and that this pathname should be
13307 taken as being relative to the directory from which the compiler was
13308 invoked when the given (base) source file was compiled. We will fill
13309 in this value in dwarf2out_finish. */
13310 comp_unit_die
= gen_compile_unit_die (NULL
);
13312 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
13314 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
13316 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
13317 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
13318 DEBUG_ABBREV_SECTION_LABEL
, 0);
13319 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
13320 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
13322 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
13324 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
13325 DEBUG_INFO_SECTION_LABEL
, 0);
13326 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
13327 DEBUG_LINE_SECTION_LABEL
, 0);
13328 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
13329 DEBUG_RANGES_SECTION_LABEL
, 0);
13330 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
13331 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
13332 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
13333 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
13334 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
13335 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
13337 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13339 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13340 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
13341 DEBUG_MACINFO_SECTION_LABEL
, 0);
13342 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
13345 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
13348 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
13352 /* A helper function for dwarf2out_finish called through
13353 ht_forall. Emit one queued .debug_str string. */
13356 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
13358 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
13360 if (node
->form
== DW_FORM_strp
)
13362 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
13363 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
13364 assemble_string (node
->str
, strlen (node
->str
) + 1);
13372 /* Clear the marks for a die and its children.
13373 Be cool if the mark isn't set. */
13376 prune_unmark_dies (dw_die_ref die
)
13380 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13381 prune_unmark_dies (c
);
13385 /* Given DIE that we're marking as used, find any other dies
13386 it references as attributes and mark them as used. */
13389 prune_unused_types_walk_attribs (dw_die_ref die
)
13393 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
13395 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
13397 /* A reference to another DIE.
13398 Make sure that it will get emitted. */
13399 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
13401 else if (a
->dw_attr
== DW_AT_decl_file
)
13403 /* A reference to a file. Make sure the file name is emitted. */
13404 a
->dw_attr_val
.v
.val_unsigned
=
13405 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
13411 /* Mark DIE as being used. If DOKIDS is true, then walk down
13412 to DIE's children. */
13415 prune_unused_types_mark (dw_die_ref die
, int dokids
)
13419 if (die
->die_mark
== 0)
13421 /* We haven't done this node yet. Mark it as used. */
13424 /* We also have to mark its parents as used.
13425 (But we don't want to mark our parents' kids due to this.) */
13426 if (die
->die_parent
)
13427 prune_unused_types_mark (die
->die_parent
, 0);
13429 /* Mark any referenced nodes. */
13430 prune_unused_types_walk_attribs (die
);
13432 /* If this node is a specification,
13433 also mark the definition, if it exists. */
13434 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
13435 prune_unused_types_mark (die
->die_definition
, 1);
13438 if (dokids
&& die
->die_mark
!= 2)
13440 /* We need to walk the children, but haven't done so yet.
13441 Remember that we've walked the kids. */
13445 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13447 /* If this is an array type, we need to make sure our
13448 kids get marked, even if they're types. */
13449 if (die
->die_tag
== DW_TAG_array_type
)
13450 prune_unused_types_mark (c
, 1);
13452 prune_unused_types_walk (c
);
13458 /* Walk the tree DIE and mark types that we actually use. */
13461 prune_unused_types_walk (dw_die_ref die
)
13465 /* Don't do anything if this node is already marked. */
13469 switch (die
->die_tag
) {
13470 case DW_TAG_const_type
:
13471 case DW_TAG_packed_type
:
13472 case DW_TAG_pointer_type
:
13473 case DW_TAG_reference_type
:
13474 case DW_TAG_volatile_type
:
13475 case DW_TAG_typedef
:
13476 case DW_TAG_array_type
:
13477 case DW_TAG_structure_type
:
13478 case DW_TAG_union_type
:
13479 case DW_TAG_class_type
:
13480 case DW_TAG_friend
:
13481 case DW_TAG_variant_part
:
13482 case DW_TAG_enumeration_type
:
13483 case DW_TAG_subroutine_type
:
13484 case DW_TAG_string_type
:
13485 case DW_TAG_set_type
:
13486 case DW_TAG_subrange_type
:
13487 case DW_TAG_ptr_to_member_type
:
13488 case DW_TAG_file_type
:
13489 /* It's a type node --- don't mark it. */
13493 /* Mark everything else. */
13499 /* Now, mark any dies referenced from here. */
13500 prune_unused_types_walk_attribs (die
);
13502 /* Mark children. */
13503 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13504 prune_unused_types_walk (c
);
13508 /* Remove from the tree DIE any dies that aren't marked. */
13511 prune_unused_types_prune (dw_die_ref die
)
13513 dw_die_ref c
, p
, n
;
13514 if (!die
->die_mark
)
13518 for (c
= die
->die_child
; c
; c
= n
)
13523 prune_unused_types_prune (c
);
13531 die
->die_child
= n
;
13538 /* Remove dies representing declarations that we never use. */
13541 prune_unused_types (void)
13544 limbo_die_node
*node
;
13546 /* Clear all the marks. */
13547 prune_unmark_dies (comp_unit_die
);
13548 for (node
= limbo_die_list
; node
; node
= node
->next
)
13549 prune_unmark_dies (node
->die
);
13551 /* Set the mark on nodes that are actually used. */
13552 prune_unused_types_walk (comp_unit_die
);
13553 for (node
= limbo_die_list
; node
; node
= node
->next
)
13554 prune_unused_types_walk (node
->die
);
13556 /* Also set the mark on nodes referenced from the
13557 pubname_table or arange_table. */
13558 for (i
= 0; i
< pubname_table_in_use
; i
++)
13559 prune_unused_types_mark (pubname_table
[i
].die
, 1);
13560 for (i
= 0; i
< arange_table_in_use
; i
++)
13561 prune_unused_types_mark (arange_table
[i
], 1);
13563 /* Get rid of nodes that aren't marked. */
13564 prune_unused_types_prune (comp_unit_die
);
13565 for (node
= limbo_die_list
; node
; node
= node
->next
)
13566 prune_unused_types_prune (node
->die
);
13568 /* Leave the marks clear. */
13569 prune_unmark_dies (comp_unit_die
);
13570 for (node
= limbo_die_list
; node
; node
= node
->next
)
13571 prune_unmark_dies (node
->die
);
13574 /* Output stuff that dwarf requires at the end of every file,
13575 and generate the DWARF-2 debugging info. */
13578 dwarf2out_finish (const char *filename
)
13580 limbo_die_node
*node
, *next_node
;
13581 dw_die_ref die
= 0;
13583 /* Add the name for the main input file now. We delayed this from
13584 dwarf2out_init to avoid complications with PCH. */
13585 add_name_attribute (comp_unit_die
, filename
);
13586 if (filename
[0] != DIR_SEPARATOR
)
13587 add_comp_dir_attribute (comp_unit_die
);
13588 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
13591 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
13592 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
13593 /* Don't add cwd for <built-in>. */
13594 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
13596 add_comp_dir_attribute (comp_unit_die
);
13601 /* Traverse the limbo die list, and add parent/child links. The only
13602 dies without parents that should be here are concrete instances of
13603 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
13604 For concrete instances, we can get the parent die from the abstract
13606 for (node
= limbo_die_list
; node
; node
= next_node
)
13608 next_node
= node
->next
;
13611 if (die
->die_parent
== NULL
)
13613 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
13617 add_child_die (origin
->die_parent
, die
);
13618 else if (die
== comp_unit_die
)
13620 else if (errorcount
> 0 || sorrycount
> 0)
13621 /* It's OK to be confused by errors in the input. */
13622 add_child_die (comp_unit_die
, die
);
13623 else if (node
->created_for
13624 && ((DECL_P (node
->created_for
)
13625 && (context
= DECL_CONTEXT (node
->created_for
)))
13626 || (TYPE_P (node
->created_for
)
13627 && (context
= TYPE_CONTEXT (node
->created_for
))))
13628 && TREE_CODE (context
) == FUNCTION_DECL
)
13630 /* In certain situations, the lexical block containing a
13631 nested function can be optimized away, which results
13632 in the nested function die being orphaned. Likewise
13633 with the return type of that nested function. Force
13634 this to be a child of the containing function. */
13635 origin
= lookup_decl_die (context
);
13638 add_child_die (origin
, die
);
13645 limbo_die_list
= NULL
;
13647 /* Walk through the list of incomplete types again, trying once more to
13648 emit full debugging info for them. */
13649 retry_incomplete_types ();
13651 /* We need to reverse all the dies before break_out_includes, or
13652 we'll see the end of an include file before the beginning. */
13653 reverse_all_dies (comp_unit_die
);
13655 if (flag_eliminate_unused_debug_types
)
13656 prune_unused_types ();
13658 /* Generate separate CUs for each of the include files we've seen.
13659 They will go into limbo_die_list. */
13660 if (flag_eliminate_dwarf2_dups
)
13661 break_out_includes (comp_unit_die
);
13663 /* Traverse the DIE's and add add sibling attributes to those DIE's
13664 that have children. */
13665 add_sibling_attributes (comp_unit_die
);
13666 for (node
= limbo_die_list
; node
; node
= node
->next
)
13667 add_sibling_attributes (node
->die
);
13669 /* Output a terminator label for the .text section. */
13671 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
13673 /* Output the source line correspondence table. We must do this
13674 even if there is no line information. Otherwise, on an empty
13675 translation unit, we will generate a present, but empty,
13676 .debug_info section. IRIX 6.5 `nm' will then complain when
13677 examining the file. */
13678 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
13680 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
13681 output_line_info ();
13684 /* Output location list section if necessary. */
13685 if (have_location_lists
)
13687 /* Output the location lists info. */
13688 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
13689 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
13690 DEBUG_LOC_SECTION_LABEL
, 0);
13691 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
13692 output_location_lists (die
);
13693 have_location_lists
= 0;
13696 /* We can only use the low/high_pc attributes if all of the code was
13698 if (separate_line_info_table_in_use
== 0)
13700 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
13701 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
13704 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
13705 "base address". Use zero so that these addresses become absolute. */
13706 else if (have_location_lists
|| ranges_table_in_use
)
13707 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
13709 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13710 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
13711 debug_line_section_label
);
13713 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13714 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
13716 /* Output all of the compilation units. We put the main one last so that
13717 the offsets are available to output_pubnames. */
13718 for (node
= limbo_die_list
; node
; node
= node
->next
)
13719 output_comp_unit (node
->die
, 0);
13721 output_comp_unit (comp_unit_die
, 0);
13723 /* Output the abbreviation table. */
13724 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
13725 output_abbrev_section ();
13727 /* Output public names table if necessary. */
13728 if (pubname_table_in_use
)
13730 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
13731 output_pubnames ();
13734 /* Output the address range information. We only put functions in the arange
13735 table, so don't write it out if we don't have any. */
13736 if (fde_table_in_use
)
13738 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
13742 /* Output ranges section if necessary. */
13743 if (ranges_table_in_use
)
13745 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
13746 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
13750 /* Have to end the primary source file. */
13751 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13753 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13754 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13755 dw2_asm_output_data (1, 0, "End compilation unit");
13758 /* If we emitted any DW_FORM_strp form attribute, output the string
13760 if (debug_str_hash
)
13761 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
13765 /* This should never be used, but its address is needed for comparisons. */
13766 const struct gcc_debug_hooks dwarf2_debug_hooks
;
13768 #endif /* DWARF2_DEBUGGING_INFO */
13770 #include "gt-dwarf2out.h"