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 /* The following comparison is correct. -1 is used to indicate that
816 the value isn't a register number. */
817 if (sreg
== (unsigned int) -1)
820 /* The register number won't fit in 6 bits, so we have to use
822 cfi
->dw_cfi_opc
= DW_CFA_offset_extended
;
824 cfi
->dw_cfi_opc
= DW_CFA_offset
;
826 #ifdef ENABLE_CHECKING
828 /* If we get an offset that is not a multiple of
829 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
830 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
832 HOST_WIDE_INT check_offset
= offset
/ DWARF_CIE_DATA_ALIGNMENT
;
834 if (check_offset
* DWARF_CIE_DATA_ALIGNMENT
!= offset
)
838 offset
/= DWARF_CIE_DATA_ALIGNMENT
;
840 cfi
->dw_cfi_opc
= DW_CFA_offset_extended_sf
;
842 cfi
->dw_cfi_oprnd2
.dw_cfi_offset
= offset
;
844 else if (sreg
== reg
)
845 cfi
->dw_cfi_opc
= DW_CFA_same_value
;
848 cfi
->dw_cfi_opc
= DW_CFA_register
;
849 cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
= sreg
;
852 add_fde_cfi (label
, cfi
);
855 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
856 This CFI tells the unwinder that it needs to restore the window registers
857 from the previous frame's window save area.
859 ??? Perhaps we should note in the CIE where windows are saved (instead of
860 assuming 0(cfa)) and what registers are in the window. */
863 dwarf2out_window_save (const char *label
)
865 dw_cfi_ref cfi
= new_cfi ();
867 cfi
->dw_cfi_opc
= DW_CFA_GNU_window_save
;
868 add_fde_cfi (label
, cfi
);
871 /* Add a CFI to update the running total of the size of arguments
872 pushed onto the stack. */
875 dwarf2out_args_size (const char *label
, HOST_WIDE_INT size
)
879 if (size
== old_args_size
)
882 old_args_size
= size
;
885 cfi
->dw_cfi_opc
= DW_CFA_GNU_args_size
;
886 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
= size
;
887 add_fde_cfi (label
, cfi
);
890 /* Entry point for saving a register to the stack. REG is the GCC register
891 number. LABEL and OFFSET are passed to reg_save. */
894 dwarf2out_reg_save (const char *label
, unsigned int reg
, HOST_WIDE_INT offset
)
896 reg_save (label
, DWARF_FRAME_REGNUM (reg
), -1, offset
);
899 /* Entry point for saving the return address in the stack.
900 LABEL and OFFSET are passed to reg_save. */
903 dwarf2out_return_save (const char *label
, HOST_WIDE_INT offset
)
905 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, -1, offset
);
908 /* Entry point for saving the return address in a register.
909 LABEL and SREG are passed to reg_save. */
912 dwarf2out_return_reg (const char *label
, unsigned int sreg
)
914 reg_save (label
, DWARF_FRAME_RETURN_COLUMN
, sreg
, 0);
917 /* Record the initial position of the return address. RTL is
918 INCOMING_RETURN_ADDR_RTX. */
921 initial_return_save (rtx rtl
)
923 unsigned int reg
= (unsigned int) -1;
924 HOST_WIDE_INT offset
= 0;
926 switch (GET_CODE (rtl
))
929 /* RA is in a register. */
930 reg
= DWARF_FRAME_REGNUM (REGNO (rtl
));
934 /* RA is on the stack. */
936 switch (GET_CODE (rtl
))
939 if (REGNO (rtl
) != STACK_POINTER_REGNUM
)
945 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
947 offset
= INTVAL (XEXP (rtl
, 1));
951 if (REGNO (XEXP (rtl
, 0)) != STACK_POINTER_REGNUM
)
953 offset
= -INTVAL (XEXP (rtl
, 1));
963 /* The return address is at some offset from any value we can
964 actually load. For instance, on the SPARC it is in %i7+8. Just
965 ignore the offset for now; it doesn't matter for unwinding frames. */
966 if (GET_CODE (XEXP (rtl
, 1)) != CONST_INT
)
968 initial_return_save (XEXP (rtl
, 0));
975 if (reg
!= DWARF_FRAME_RETURN_COLUMN
)
976 reg_save (NULL
, DWARF_FRAME_RETURN_COLUMN
, reg
, offset
- cfa
.offset
);
979 /* Given a SET, calculate the amount of stack adjustment it
983 stack_adjust_offset (rtx pattern
)
985 rtx src
= SET_SRC (pattern
);
986 rtx dest
= SET_DEST (pattern
);
987 HOST_WIDE_INT offset
= 0;
990 if (dest
== stack_pointer_rtx
)
992 /* (set (reg sp) (plus (reg sp) (const_int))) */
993 code
= GET_CODE (src
);
994 if (! (code
== PLUS
|| code
== MINUS
)
995 || XEXP (src
, 0) != stack_pointer_rtx
996 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
999 offset
= INTVAL (XEXP (src
, 1));
1003 else if (GET_CODE (dest
) == MEM
)
1005 /* (set (mem (pre_dec (reg sp))) (foo)) */
1006 src
= XEXP (dest
, 0);
1007 code
= GET_CODE (src
);
1013 if (XEXP (src
, 0) == stack_pointer_rtx
)
1015 rtx val
= XEXP (XEXP (src
, 1), 1);
1016 /* We handle only adjustments by constant amount. */
1017 if (GET_CODE (XEXP (src
, 1)) != PLUS
||
1018 GET_CODE (val
) != CONST_INT
)
1020 offset
= -INTVAL (val
);
1027 if (XEXP (src
, 0) == stack_pointer_rtx
)
1029 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1036 if (XEXP (src
, 0) == stack_pointer_rtx
)
1038 offset
= -GET_MODE_SIZE (GET_MODE (dest
));
1053 /* Check INSN to see if it looks like a push or a stack adjustment, and
1054 make a note of it if it does. EH uses this information to find out how
1055 much extra space it needs to pop off the stack. */
1058 dwarf2out_stack_adjust (rtx insn
)
1060 HOST_WIDE_INT offset
;
1064 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1065 with this function. Proper support would require all frame-related
1066 insns to be marked, and to be able to handle saving state around
1067 epilogues textually in the middle of the function. */
1068 if (prologue_epilogue_contains (insn
) || sibcall_epilogue_contains (insn
))
1071 if (!flag_asynchronous_unwind_tables
&& GET_CODE (insn
) == CALL_INSN
)
1073 /* Extract the size of the args from the CALL rtx itself. */
1074 insn
= PATTERN (insn
);
1075 if (GET_CODE (insn
) == PARALLEL
)
1076 insn
= XVECEXP (insn
, 0, 0);
1077 if (GET_CODE (insn
) == SET
)
1078 insn
= SET_SRC (insn
);
1079 if (GET_CODE (insn
) != CALL
)
1082 dwarf2out_args_size ("", INTVAL (XEXP (insn
, 1)));
1086 /* If only calls can throw, and we have a frame pointer,
1087 save up adjustments until we see the CALL_INSN. */
1088 else if (!flag_asynchronous_unwind_tables
&& cfa
.reg
!= STACK_POINTER_REGNUM
)
1091 if (GET_CODE (insn
) == BARRIER
)
1093 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1094 the compiler will have already emitted a stack adjustment, but
1095 doesn't bother for calls to noreturn functions. */
1096 #ifdef STACK_GROWS_DOWNWARD
1097 offset
= -args_size
;
1102 else if (GET_CODE (PATTERN (insn
)) == SET
)
1103 offset
= stack_adjust_offset (PATTERN (insn
));
1104 else if (GET_CODE (PATTERN (insn
)) == PARALLEL
1105 || GET_CODE (PATTERN (insn
)) == SEQUENCE
)
1107 /* There may be stack adjustments inside compound insns. Search
1109 for (offset
= 0, i
= XVECLEN (PATTERN (insn
), 0) - 1; i
>= 0; i
--)
1110 if (GET_CODE (XVECEXP (PATTERN (insn
), 0, i
)) == SET
)
1111 offset
+= stack_adjust_offset (XVECEXP (PATTERN (insn
), 0, i
));
1119 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1120 cfa
.offset
+= offset
;
1122 #ifndef STACK_GROWS_DOWNWARD
1126 args_size
+= offset
;
1130 label
= dwarf2out_cfi_label ();
1131 def_cfa_1 (label
, &cfa
);
1132 dwarf2out_args_size (label
, args_size
);
1137 /* We delay emitting a register save until either (a) we reach the end
1138 of the prologue or (b) the register is clobbered. This clusters
1139 register saves so that there are fewer pc advances. */
1141 struct queued_reg_save
GTY(())
1143 struct queued_reg_save
*next
;
1145 HOST_WIDE_INT cfa_offset
;
1149 static GTY(()) struct queued_reg_save
*queued_reg_saves
;
1151 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1152 struct reg_saved_in_data
GTY(()) {
1157 /* A list of registers saved in other registers.
1158 The list intentionally has a small maximum capacity of 4; if your
1159 port needs more than that, you might consider implementing a
1160 more efficient data structure. */
1161 static GTY(()) struct reg_saved_in_data regs_saved_in_regs
[4];
1162 static GTY(()) size_t num_regs_saved_in_regs
;
1164 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1165 static const char *last_reg_save_label
;
1167 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1168 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1171 queue_reg_save (const char *label
, rtx reg
, rtx sreg
, HOST_WIDE_INT offset
)
1173 struct queued_reg_save
*q
;
1175 /* Duplicates waste space, but it's also necessary to remove them
1176 for correctness, since the queue gets output in reverse
1178 for (q
= queued_reg_saves
; q
!= NULL
; q
= q
->next
)
1179 if (REGNO (q
->reg
) == REGNO (reg
))
1184 q
= ggc_alloc (sizeof (*q
));
1185 q
->next
= queued_reg_saves
;
1186 queued_reg_saves
= q
;
1190 q
->cfa_offset
= offset
;
1191 q
->saved_reg
= sreg
;
1193 last_reg_save_label
= label
;
1196 /* Output all the entries in QUEUED_REG_SAVES. */
1199 flush_queued_reg_saves (void)
1201 struct queued_reg_save
*q
;
1203 for (q
= queued_reg_saves
; q
; q
= q
->next
)
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_save (last_reg_save_label
, REGNO (q
->reg
),
1222 q
->saved_reg
? REGNO (q
->saved_reg
) : -1U, q
->cfa_offset
);
1225 queued_reg_saves
= NULL
;
1226 last_reg_save_label
= NULL
;
1229 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1230 location for? Or, does it clobber a register which we've previously
1231 said that some other register is saved in, and for which we now
1232 have a new location for? */
1235 clobbers_queued_reg_save (rtx insn
)
1237 struct queued_reg_save
*q
;
1239 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1242 if (modified_in_p (q
->reg
, insn
))
1244 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1245 if (REGNO (q
->reg
) == REGNO (regs_saved_in_regs
[i
].orig_reg
)
1246 && modified_in_p (regs_saved_in_regs
[i
].saved_in_reg
, insn
))
1253 /* What register, if any, is currently saved in REG? */
1256 reg_saved_in (rtx reg
)
1258 unsigned int regn
= REGNO (reg
);
1260 struct queued_reg_save
*q
;
1262 for (q
= queued_reg_saves
; q
; q
= q
->next
)
1263 if (q
->saved_reg
&& regn
== REGNO (q
->saved_reg
))
1266 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1267 if (regs_saved_in_regs
[i
].saved_in_reg
1268 && regn
== REGNO (regs_saved_in_regs
[i
].saved_in_reg
))
1269 return regs_saved_in_regs
[i
].orig_reg
;
1275 /* A temporary register holding an integral value used in adjusting SP
1276 or setting up the store_reg. The "offset" field holds the integer
1277 value, not an offset. */
1278 static dw_cfa_location cfa_temp
;
1280 /* Record call frame debugging information for an expression EXPR,
1281 which either sets SP or FP (adjusting how we calculate the frame
1282 address) or saves a register to the stack or another register.
1283 LABEL indicates the address of EXPR.
1285 This function encodes a state machine mapping rtxes to actions on
1286 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1287 users need not read the source code.
1289 The High-Level Picture
1291 Changes in the register we use to calculate the CFA: Currently we
1292 assume that if you copy the CFA register into another register, we
1293 should take the other one as the new CFA register; this seems to
1294 work pretty well. If it's wrong for some target, it's simple
1295 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1297 Changes in the register we use for saving registers to the stack:
1298 This is usually SP, but not always. Again, we deduce that if you
1299 copy SP into another register (and SP is not the CFA register),
1300 then the new register is the one we will be using for register
1301 saves. This also seems to work.
1303 Register saves: There's not much guesswork about this one; if
1304 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1305 register save, and the register used to calculate the destination
1306 had better be the one we think we're using for this purpose.
1307 It's also assumed that a copy from a call-saved register to another
1308 register is saving that register if RTX_FRAME_RELATED_P is set on
1309 that instruction. If the copy is from a call-saved register to
1310 the *same* register, that means that the register is now the same
1311 value as in the caller.
1313 Except: If the register being saved is the CFA register, and the
1314 offset is nonzero, we are saving the CFA, so we assume we have to
1315 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1316 the intent is to save the value of SP from the previous frame.
1318 In addition, if a register has previously been saved to a different
1321 Invariants / Summaries of Rules
1323 cfa current rule for calculating the CFA. It usually
1324 consists of a register and an offset.
1325 cfa_store register used by prologue code to save things to the stack
1326 cfa_store.offset is the offset from the value of
1327 cfa_store.reg to the actual CFA
1328 cfa_temp register holding an integral value. cfa_temp.offset
1329 stores the value, which will be used to adjust the
1330 stack pointer. cfa_temp is also used like cfa_store,
1331 to track stores to the stack via fp or a temp reg.
1333 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1334 with cfa.reg as the first operand changes the cfa.reg and its
1335 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1338 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1339 expression yielding a constant. This sets cfa_temp.reg
1340 and cfa_temp.offset.
1342 Rule 5: Create a new register cfa_store used to save items to the
1345 Rules 10-14: Save a register to the stack. Define offset as the
1346 difference of the original location and cfa_store's
1347 location (or cfa_temp's location if cfa_temp is used).
1351 "{a,b}" indicates a choice of a xor b.
1352 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1355 (set <reg1> <reg2>:cfa.reg)
1356 effects: cfa.reg = <reg1>
1357 cfa.offset unchanged
1358 cfa_temp.reg = <reg1>
1359 cfa_temp.offset = cfa.offset
1362 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1363 {<const_int>,<reg>:cfa_temp.reg}))
1364 effects: cfa.reg = sp if fp used
1365 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1366 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1367 if cfa_store.reg==sp
1370 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1371 effects: cfa.reg = fp
1372 cfa_offset += +/- <const_int>
1375 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1376 constraints: <reg1> != fp
1378 effects: cfa.reg = <reg1>
1379 cfa_temp.reg = <reg1>
1380 cfa_temp.offset = cfa.offset
1383 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1384 constraints: <reg1> != fp
1386 effects: cfa_store.reg = <reg1>
1387 cfa_store.offset = cfa.offset - cfa_temp.offset
1390 (set <reg> <const_int>)
1391 effects: cfa_temp.reg = <reg>
1392 cfa_temp.offset = <const_int>
1395 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1396 effects: cfa_temp.reg = <reg1>
1397 cfa_temp.offset |= <const_int>
1400 (set <reg> (high <exp>))
1404 (set <reg> (lo_sum <exp> <const_int>))
1405 effects: cfa_temp.reg = <reg>
1406 cfa_temp.offset = <const_int>
1409 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1410 effects: cfa_store.offset -= <const_int>
1411 cfa.offset = cfa_store.offset if cfa.reg == sp
1413 cfa.base_offset = -cfa_store.offset
1416 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1417 effects: cfa_store.offset += -/+ mode_size(mem)
1418 cfa.offset = cfa_store.offset if cfa.reg == sp
1420 cfa.base_offset = -cfa_store.offset
1423 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1426 effects: cfa.reg = <reg1>
1427 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1430 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1431 effects: cfa.reg = <reg1>
1432 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1435 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1436 effects: cfa.reg = <reg1>
1437 cfa.base_offset = -cfa_temp.offset
1438 cfa_temp.offset -= mode_size(mem) */
1441 dwarf2out_frame_debug_expr (rtx expr
, const char *label
)
1444 HOST_WIDE_INT offset
;
1446 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1447 the PARALLEL independently. The first element is always processed if
1448 it is a SET. This is for backward compatibility. Other elements
1449 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1450 flag is set in them. */
1451 if (GET_CODE (expr
) == PARALLEL
|| GET_CODE (expr
) == SEQUENCE
)
1454 int limit
= XVECLEN (expr
, 0);
1456 for (par_index
= 0; par_index
< limit
; par_index
++)
1457 if (GET_CODE (XVECEXP (expr
, 0, par_index
)) == SET
1458 && (RTX_FRAME_RELATED_P (XVECEXP (expr
, 0, par_index
))
1460 dwarf2out_frame_debug_expr (XVECEXP (expr
, 0, par_index
), label
);
1465 if (GET_CODE (expr
) != SET
)
1468 src
= SET_SRC (expr
);
1469 dest
= SET_DEST (expr
);
1471 if (GET_CODE (src
) == REG
)
1473 rtx rsi
= reg_saved_in (src
);
1478 switch (GET_CODE (dest
))
1481 switch (GET_CODE (src
))
1483 /* Setting FP from SP. */
1485 if (cfa
.reg
== (unsigned) REGNO (src
))
1488 /* Update the CFA rule wrt SP or FP. Make sure src is
1489 relative to the current CFA register.
1491 We used to require that dest be either SP or FP, but the
1492 ARM copies SP to a temporary register, and from there to
1493 FP. So we just rely on the backends to only set
1494 RTX_FRAME_RELATED_P on appropriate insns. */
1495 cfa
.reg
= REGNO (dest
);
1496 cfa_temp
.reg
= cfa
.reg
;
1497 cfa_temp
.offset
= cfa
.offset
;
1499 else if (call_used_regs
[REGNO (dest
)]
1500 && ! fixed_regs
[REGNO (dest
)])
1502 /* Saving a register in a register. */
1503 queue_reg_save (label
, src
, dest
, 0);
1512 if (dest
== stack_pointer_rtx
)
1516 switch (GET_CODE (XEXP (src
, 1)))
1519 offset
= INTVAL (XEXP (src
, 1));
1522 if ((unsigned) REGNO (XEXP (src
, 1)) != cfa_temp
.reg
)
1524 offset
= cfa_temp
.offset
;
1530 if (XEXP (src
, 0) == hard_frame_pointer_rtx
)
1532 /* Restoring SP from FP in the epilogue. */
1533 if (cfa
.reg
!= (unsigned) HARD_FRAME_POINTER_REGNUM
)
1535 cfa
.reg
= STACK_POINTER_REGNUM
;
1537 else if (GET_CODE (src
) == LO_SUM
)
1538 /* Assume we've set the source reg of the LO_SUM from sp. */
1540 else if (XEXP (src
, 0) != stack_pointer_rtx
)
1543 if (GET_CODE (src
) != MINUS
)
1545 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1546 cfa
.offset
+= offset
;
1547 if (cfa_store
.reg
== STACK_POINTER_REGNUM
)
1548 cfa_store
.offset
+= offset
;
1550 else if (dest
== hard_frame_pointer_rtx
)
1553 /* Either setting the FP from an offset of the SP,
1554 or adjusting the FP */
1555 if (! frame_pointer_needed
)
1558 if (REG_P (XEXP (src
, 0))
1559 && (unsigned) REGNO (XEXP (src
, 0)) == cfa
.reg
1560 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1562 offset
= INTVAL (XEXP (src
, 1));
1563 if (GET_CODE (src
) != MINUS
)
1565 cfa
.offset
+= offset
;
1566 cfa
.reg
= HARD_FRAME_POINTER_REGNUM
;
1573 if (GET_CODE (src
) == MINUS
)
1577 if (REG_P (XEXP (src
, 0))
1578 && REGNO (XEXP (src
, 0)) == cfa
.reg
1579 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1581 /* Setting a temporary CFA register that will be copied
1582 into the FP later on. */
1583 offset
= - INTVAL (XEXP (src
, 1));
1584 cfa
.offset
+= offset
;
1585 cfa
.reg
= REGNO (dest
);
1586 /* Or used to save regs to the stack. */
1587 cfa_temp
.reg
= cfa
.reg
;
1588 cfa_temp
.offset
= cfa
.offset
;
1592 else if (REG_P (XEXP (src
, 0))
1593 && REGNO (XEXP (src
, 0)) == cfa_temp
.reg
1594 && XEXP (src
, 1) == stack_pointer_rtx
)
1596 /* Setting a scratch register that we will use instead
1597 of SP for saving registers to the stack. */
1598 if (cfa
.reg
!= STACK_POINTER_REGNUM
)
1600 cfa_store
.reg
= REGNO (dest
);
1601 cfa_store
.offset
= cfa
.offset
- cfa_temp
.offset
;
1605 else if (GET_CODE (src
) == LO_SUM
1606 && GET_CODE (XEXP (src
, 1)) == CONST_INT
)
1608 cfa_temp
.reg
= REGNO (dest
);
1609 cfa_temp
.offset
= INTVAL (XEXP (src
, 1));
1618 cfa_temp
.reg
= REGNO (dest
);
1619 cfa_temp
.offset
= INTVAL (src
);
1624 if (!REG_P (XEXP (src
, 0))
1625 || (unsigned) REGNO (XEXP (src
, 0)) != cfa_temp
.reg
1626 || GET_CODE (XEXP (src
, 1)) != CONST_INT
)
1629 if ((unsigned) REGNO (dest
) != cfa_temp
.reg
)
1630 cfa_temp
.reg
= REGNO (dest
);
1631 cfa_temp
.offset
|= INTVAL (XEXP (src
, 1));
1634 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1635 which will fill in all of the bits. */
1644 def_cfa_1 (label
, &cfa
);
1651 /* Saving a register to the stack. Make sure dest is relative to the
1653 switch (GET_CODE (XEXP (dest
, 0)))
1658 /* We can't handle variable size modifications. */
1659 if (GET_CODE (XEXP (XEXP (XEXP (dest
, 0), 1), 1)) != CONST_INT
)
1661 offset
= -INTVAL (XEXP (XEXP (XEXP (dest
, 0), 1), 1));
1663 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1664 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1667 cfa_store
.offset
+= offset
;
1668 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1669 cfa
.offset
= cfa_store
.offset
;
1671 offset
= -cfa_store
.offset
;
1677 offset
= GET_MODE_SIZE (GET_MODE (dest
));
1678 if (GET_CODE (XEXP (dest
, 0)) == PRE_INC
)
1681 if (REGNO (XEXP (XEXP (dest
, 0), 0)) != STACK_POINTER_REGNUM
1682 || cfa_store
.reg
!= STACK_POINTER_REGNUM
)
1685 cfa_store
.offset
+= offset
;
1686 if (cfa
.reg
== STACK_POINTER_REGNUM
)
1687 cfa
.offset
= cfa_store
.offset
;
1689 offset
= -cfa_store
.offset
;
1693 /* With an offset. */
1697 if (GET_CODE (XEXP (XEXP (dest
, 0), 1)) != CONST_INT
)
1699 offset
= INTVAL (XEXP (XEXP (dest
, 0), 1));
1700 if (GET_CODE (XEXP (dest
, 0)) == MINUS
)
1703 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1704 offset
-= cfa_store
.offset
;
1705 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1706 offset
-= cfa_temp
.offset
;
1712 /* Without an offset. */
1714 if (cfa_store
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1715 offset
= -cfa_store
.offset
;
1716 else if (cfa_temp
.reg
== (unsigned) REGNO (XEXP (dest
, 0)))
1717 offset
= -cfa_temp
.offset
;
1724 if (cfa_temp
.reg
!= (unsigned) REGNO (XEXP (XEXP (dest
, 0), 0)))
1726 offset
= -cfa_temp
.offset
;
1727 cfa_temp
.offset
-= GET_MODE_SIZE (GET_MODE (dest
));
1734 if (REGNO (src
) != STACK_POINTER_REGNUM
1735 && REGNO (src
) != HARD_FRAME_POINTER_REGNUM
1736 && (unsigned) REGNO (src
) == cfa
.reg
)
1738 /* We're storing the current CFA reg into the stack. */
1740 if (cfa
.offset
== 0)
1742 /* If the source register is exactly the CFA, assume
1743 we're saving SP like any other register; this happens
1745 def_cfa_1 (label
, &cfa
);
1746 queue_reg_save (label
, stack_pointer_rtx
, NULL_RTX
, offset
);
1751 /* Otherwise, we'll need to look in the stack to
1752 calculate the CFA. */
1753 rtx x
= XEXP (dest
, 0);
1760 cfa
.reg
= REGNO (x
);
1761 cfa
.base_offset
= offset
;
1763 def_cfa_1 (label
, &cfa
);
1768 def_cfa_1 (label
, &cfa
);
1769 queue_reg_save (label
, src
, NULL_RTX
, offset
);
1777 /* Record call frame debugging information for INSN, which either
1778 sets SP or FP (adjusting how we calculate the frame address) or saves a
1779 register to the stack. If INSN is NULL_RTX, initialize our state. */
1782 dwarf2out_frame_debug (rtx insn
)
1787 if (insn
== NULL_RTX
)
1791 /* Flush any queued register saves. */
1792 flush_queued_reg_saves ();
1794 /* Set up state for generating call frame debug info. */
1796 if (cfa
.reg
!= (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM
))
1799 cfa
.reg
= STACK_POINTER_REGNUM
;
1802 cfa_temp
.offset
= 0;
1804 for (i
= 0; i
< num_regs_saved_in_regs
; i
++)
1806 regs_saved_in_regs
[i
].orig_reg
= NULL_RTX
;
1807 regs_saved_in_regs
[i
].saved_in_reg
= NULL_RTX
;
1809 num_regs_saved_in_regs
= 0;
1813 if (GET_CODE (insn
) != INSN
|| clobbers_queued_reg_save (insn
))
1814 flush_queued_reg_saves ();
1816 if (! RTX_FRAME_RELATED_P (insn
))
1818 if (!ACCUMULATE_OUTGOING_ARGS
)
1819 dwarf2out_stack_adjust (insn
);
1824 label
= dwarf2out_cfi_label ();
1825 src
= find_reg_note (insn
, REG_FRAME_RELATED_EXPR
, NULL_RTX
);
1827 insn
= XEXP (src
, 0);
1829 insn
= PATTERN (insn
);
1831 dwarf2out_frame_debug_expr (insn
, label
);
1836 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1837 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1838 (enum dwarf_call_frame_info cfi
);
1840 static enum dw_cfi_oprnd_type
1841 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
1846 case DW_CFA_GNU_window_save
:
1847 return dw_cfi_oprnd_unused
;
1849 case DW_CFA_set_loc
:
1850 case DW_CFA_advance_loc1
:
1851 case DW_CFA_advance_loc2
:
1852 case DW_CFA_advance_loc4
:
1853 case DW_CFA_MIPS_advance_loc8
:
1854 return dw_cfi_oprnd_addr
;
1857 case DW_CFA_offset_extended
:
1858 case DW_CFA_def_cfa
:
1859 case DW_CFA_offset_extended_sf
:
1860 case DW_CFA_def_cfa_sf
:
1861 case DW_CFA_restore_extended
:
1862 case DW_CFA_undefined
:
1863 case DW_CFA_same_value
:
1864 case DW_CFA_def_cfa_register
:
1865 case DW_CFA_register
:
1866 return dw_cfi_oprnd_reg_num
;
1868 case DW_CFA_def_cfa_offset
:
1869 case DW_CFA_GNU_args_size
:
1870 case DW_CFA_def_cfa_offset_sf
:
1871 return dw_cfi_oprnd_offset
;
1873 case DW_CFA_def_cfa_expression
:
1874 case DW_CFA_expression
:
1875 return dw_cfi_oprnd_loc
;
1882 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1883 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1884 (enum dwarf_call_frame_info cfi
);
1886 static enum dw_cfi_oprnd_type
1887 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
1891 case DW_CFA_def_cfa
:
1892 case DW_CFA_def_cfa_sf
:
1894 case DW_CFA_offset_extended_sf
:
1895 case DW_CFA_offset_extended
:
1896 return dw_cfi_oprnd_offset
;
1898 case DW_CFA_register
:
1899 return dw_cfi_oprnd_reg_num
;
1902 return dw_cfi_oprnd_unused
;
1906 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1908 /* Map register numbers held in the call frame info that gcc has
1909 collected using DWARF_FRAME_REGNUM to those that should be output in
1910 .debug_frame and .eh_frame. */
1911 #ifndef DWARF2_FRAME_REG_OUT
1912 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1915 /* Output a Call Frame Information opcode and its operand(s). */
1918 output_cfi (dw_cfi_ref cfi
, dw_fde_ref fde
, int for_eh
)
1921 if (cfi
->dw_cfi_opc
== DW_CFA_advance_loc
)
1922 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
1923 | (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
& 0x3f)),
1924 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX
,
1925 cfi
->dw_cfi_oprnd1
.dw_cfi_offset
);
1926 else if (cfi
->dw_cfi_opc
== DW_CFA_offset
)
1928 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1929 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
1930 "DW_CFA_offset, column 0x%lx", r
);
1931 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1933 else if (cfi
->dw_cfi_opc
== DW_CFA_restore
)
1935 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1936 dw2_asm_output_data (1, (cfi
->dw_cfi_opc
| (r
& 0x3f)),
1937 "DW_CFA_restore, column 0x%lx", r
);
1941 dw2_asm_output_data (1, cfi
->dw_cfi_opc
,
1942 "%s", dwarf_cfi_name (cfi
->dw_cfi_opc
));
1944 switch (cfi
->dw_cfi_opc
)
1946 case DW_CFA_set_loc
:
1948 dw2_asm_output_encoded_addr_rtx (
1949 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1950 gen_rtx_SYMBOL_REF (Pmode
, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
),
1953 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
1954 cfi
->dw_cfi_oprnd1
.dw_cfi_addr
, NULL
);
1957 case DW_CFA_advance_loc1
:
1958 dw2_asm_output_delta (1, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1959 fde
->dw_fde_current_label
, NULL
);
1960 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1963 case DW_CFA_advance_loc2
:
1964 dw2_asm_output_delta (2, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1965 fde
->dw_fde_current_label
, NULL
);
1966 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1969 case DW_CFA_advance_loc4
:
1970 dw2_asm_output_delta (4, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1971 fde
->dw_fde_current_label
, NULL
);
1972 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1975 case DW_CFA_MIPS_advance_loc8
:
1976 dw2_asm_output_delta (8, cfi
->dw_cfi_oprnd1
.dw_cfi_addr
,
1977 fde
->dw_fde_current_label
, NULL
);
1978 fde
->dw_fde_current_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
1981 case DW_CFA_offset_extended
:
1982 case DW_CFA_def_cfa
:
1983 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1984 dw2_asm_output_data_uleb128 (r
, NULL
);
1985 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1988 case DW_CFA_offset_extended_sf
:
1989 case DW_CFA_def_cfa_sf
:
1990 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
1991 dw2_asm_output_data_uleb128 (r
, NULL
);
1992 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd2
.dw_cfi_offset
, NULL
);
1995 case DW_CFA_restore_extended
:
1996 case DW_CFA_undefined
:
1997 case DW_CFA_same_value
:
1998 case DW_CFA_def_cfa_register
:
1999 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2000 dw2_asm_output_data_uleb128 (r
, NULL
);
2003 case DW_CFA_register
:
2004 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd1
.dw_cfi_reg_num
, for_eh
);
2005 dw2_asm_output_data_uleb128 (r
, NULL
);
2006 r
= DWARF2_FRAME_REG_OUT (cfi
->dw_cfi_oprnd2
.dw_cfi_reg_num
, for_eh
);
2007 dw2_asm_output_data_uleb128 (r
, NULL
);
2010 case DW_CFA_def_cfa_offset
:
2011 case DW_CFA_GNU_args_size
:
2012 dw2_asm_output_data_uleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2015 case DW_CFA_def_cfa_offset_sf
:
2016 dw2_asm_output_data_sleb128 (cfi
->dw_cfi_oprnd1
.dw_cfi_offset
, NULL
);
2019 case DW_CFA_GNU_window_save
:
2022 case DW_CFA_def_cfa_expression
:
2023 case DW_CFA_expression
:
2024 output_cfa_loc (cfi
);
2027 case DW_CFA_GNU_negative_offset_extended
:
2028 /* Obsoleted by DW_CFA_offset_extended_sf. */
2037 /* Output the call frame information used to record information
2038 that relates to calculating the frame pointer, and records the
2039 location of saved registers. */
2042 output_call_frame_info (int for_eh
)
2047 char l1
[20], l2
[20], section_start_label
[20];
2048 bool any_lsda_needed
= false;
2049 char augmentation
[6];
2050 int augmentation_size
;
2051 int fde_encoding
= DW_EH_PE_absptr
;
2052 int per_encoding
= DW_EH_PE_absptr
;
2053 int lsda_encoding
= DW_EH_PE_absptr
;
2055 /* Don't emit a CIE if there won't be any FDEs. */
2056 if (fde_table_in_use
== 0)
2059 /* If we make FDEs linkonce, we may have to emit an empty label for
2060 an FDE that wouldn't otherwise be emitted. We want to avoid
2061 having an FDE kept around when the function it refers to is
2062 discarded. (Example where this matters: a primary function
2063 template in C++ requires EH information, but an explicit
2064 specialization doesn't. */
2065 if (TARGET_USES_WEAK_UNWIND_INFO
2066 && ! flag_asynchronous_unwind_tables
2068 for (i
= 0; i
< fde_table_in_use
; i
++)
2069 if ((fde_table
[i
].nothrow
|| fde_table
[i
].all_throwers_are_sibcalls
)
2070 && !fde_table
[i
].uses_eh_lsda
2071 && ! DECL_ONE_ONLY (fde_table
[i
].decl
))
2072 targetm
.asm_out
.unwind_label (asm_out_file
, fde_table
[i
].decl
,
2073 for_eh
, /* empty */ 1);
2075 /* If we don't have any functions we'll want to unwind out of, don't
2076 emit any EH unwind information. Note that if exceptions aren't
2077 enabled, we won't have collected nothrow information, and if we
2078 asked for asynchronous tables, we always want this info. */
2081 bool any_eh_needed
= !flag_exceptions
|| flag_asynchronous_unwind_tables
;
2083 for (i
= 0; i
< fde_table_in_use
; i
++)
2084 if (fde_table
[i
].uses_eh_lsda
)
2085 any_eh_needed
= any_lsda_needed
= true;
2086 else if (TARGET_USES_WEAK_UNWIND_INFO
2087 && DECL_ONE_ONLY (fde_table
[i
].decl
))
2089 else if (! fde_table
[i
].nothrow
2090 && ! fde_table
[i
].all_throwers_are_sibcalls
)
2091 any_eh_needed
= true;
2093 if (! any_eh_needed
)
2097 /* We're going to be generating comments, so turn on app. */
2102 targetm
.asm_out
.eh_frame_section ();
2104 named_section_flags (DEBUG_FRAME_SECTION
, SECTION_DEBUG
);
2106 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
2107 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
2109 /* Output the CIE. */
2110 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
2111 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
2112 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2113 "Length of Common Information Entry");
2114 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2116 /* Now that the CIE pointer is PC-relative for EH,
2117 use 0 to identify the CIE. */
2118 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
2119 (for_eh
? 0 : DW_CIE_ID
),
2120 "CIE Identifier Tag");
2122 dw2_asm_output_data (1, DW_CIE_VERSION
, "CIE Version");
2124 augmentation
[0] = 0;
2125 augmentation_size
= 0;
2131 z Indicates that a uleb128 is present to size the
2132 augmentation section.
2133 L Indicates the encoding (and thus presence) of
2134 an LSDA pointer in the FDE augmentation.
2135 R Indicates a non-default pointer encoding for
2137 P Indicates the presence of an encoding + language
2138 personality routine in the CIE augmentation. */
2140 fde_encoding
= TARGET_USES_WEAK_UNWIND_INFO
2141 ? ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1)
2142 : ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2143 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2144 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2146 p
= augmentation
+ 1;
2147 if (eh_personality_libfunc
)
2150 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
2152 if (any_lsda_needed
)
2155 augmentation_size
+= 1;
2157 if (fde_encoding
!= DW_EH_PE_absptr
)
2160 augmentation_size
+= 1;
2162 if (p
> augmentation
+ 1)
2164 augmentation
[0] = 'z';
2168 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2169 if (eh_personality_libfunc
&& per_encoding
== DW_EH_PE_aligned
)
2171 int offset
= ( 4 /* Length */
2173 + 1 /* CIE version */
2174 + strlen (augmentation
) + 1 /* Augmentation */
2175 + size_of_uleb128 (1) /* Code alignment */
2176 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
2178 + 1 /* Augmentation size */
2179 + 1 /* Personality encoding */ );
2180 int pad
= -offset
& (PTR_SIZE
- 1);
2182 augmentation_size
+= pad
;
2184 /* Augmentations should be small, so there's scarce need to
2185 iterate for a solution. Die if we exceed one uleb128 byte. */
2186 if (size_of_uleb128 (augmentation_size
) != 1)
2191 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
2192 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2193 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
2194 "CIE Data Alignment Factor");
2196 if (DW_CIE_VERSION
== 1)
2197 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2199 dw2_asm_output_data_uleb128 (DWARF_FRAME_RETURN_COLUMN
, "CIE RA Column");
2201 if (augmentation
[0])
2203 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
2204 if (eh_personality_libfunc
)
2206 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
2207 eh_data_format_name (per_encoding
));
2208 dw2_asm_output_encoded_addr_rtx (per_encoding
,
2209 eh_personality_libfunc
, NULL
);
2212 if (any_lsda_needed
)
2213 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
2214 eh_data_format_name (lsda_encoding
));
2216 if (fde_encoding
!= DW_EH_PE_absptr
)
2217 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
2218 eh_data_format_name (fde_encoding
));
2221 for (cfi
= cie_cfi_head
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2222 output_cfi (cfi
, NULL
, for_eh
);
2224 /* Pad the CIE out to an address sized boundary. */
2225 ASM_OUTPUT_ALIGN (asm_out_file
,
2226 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
2227 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2229 /* Loop through all of the FDE's. */
2230 for (i
= 0; i
< fde_table_in_use
; i
++)
2232 fde
= &fde_table
[i
];
2234 /* Don't emit EH unwind info for leaf functions that don't need it. */
2235 if (for_eh
&& !flag_asynchronous_unwind_tables
&& flag_exceptions
2236 && (fde
->nothrow
|| fde
->all_throwers_are_sibcalls
)
2237 && (! TARGET_USES_WEAK_UNWIND_INFO
|| ! DECL_ONE_ONLY (fde
->decl
))
2238 && !fde
->uses_eh_lsda
)
2241 targetm
.asm_out
.unwind_label (asm_out_file
, fde
->decl
, for_eh
, /* empty */ 0);
2242 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
, for_eh
+ i
* 2);
2243 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ i
* 2);
2244 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ i
* 2);
2245 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
2247 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
2250 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
2252 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
2257 if (TARGET_USES_WEAK_UNWIND_INFO
2258 && DECL_ONE_ONLY (fde
->decl
))
2259 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2260 gen_rtx_SYMBOL_REF (Pmode
, IDENTIFIER_POINTER
2261 (DECL_ASSEMBLER_NAME (fde
->decl
))),
2262 "FDE initial location");
2264 dw2_asm_output_encoded_addr_rtx (fde_encoding
,
2265 gen_rtx_SYMBOL_REF (Pmode
, fde
->dw_fde_begin
),
2266 "FDE initial location");
2267 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
2268 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2269 "FDE address range");
2273 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
2274 "FDE initial location");
2275 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
2276 fde
->dw_fde_end
, fde
->dw_fde_begin
,
2277 "FDE address range");
2280 if (augmentation
[0])
2282 if (any_lsda_needed
)
2284 int size
= size_of_encoded_value (lsda_encoding
);
2286 if (lsda_encoding
== DW_EH_PE_aligned
)
2288 int offset
= ( 4 /* Length */
2289 + 4 /* CIE offset */
2290 + 2 * size_of_encoded_value (fde_encoding
)
2291 + 1 /* Augmentation size */ );
2292 int pad
= -offset
& (PTR_SIZE
- 1);
2295 if (size_of_uleb128 (size
) != 1)
2299 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
2301 if (fde
->uses_eh_lsda
)
2303 ASM_GENERATE_INTERNAL_LABEL (l1
, "LLSDA",
2304 fde
->funcdef_number
);
2305 dw2_asm_output_encoded_addr_rtx (
2306 lsda_encoding
, gen_rtx_SYMBOL_REF (Pmode
, l1
),
2307 "Language Specific Data Area");
2311 if (lsda_encoding
== DW_EH_PE_aligned
)
2312 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
2314 (size_of_encoded_value (lsda_encoding
), 0,
2315 "Language Specific Data Area (none)");
2319 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2322 /* Loop through the Call Frame Instructions associated with
2324 fde
->dw_fde_current_label
= fde
->dw_fde_begin
;
2325 for (cfi
= fde
->dw_fde_cfi
; cfi
!= NULL
; cfi
= cfi
->dw_cfi_next
)
2326 output_cfi (cfi
, fde
, for_eh
);
2328 /* Pad the FDE out to an address sized boundary. */
2329 ASM_OUTPUT_ALIGN (asm_out_file
,
2330 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
2331 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
2334 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
2335 dw2_asm_output_data (4, 0, "End of Table");
2336 #ifdef MIPS_DEBUGGING_INFO
2337 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2338 get a value of 0. Putting .align 0 after the label fixes it. */
2339 ASM_OUTPUT_ALIGN (asm_out_file
, 0);
2342 /* Turn off app to make assembly quicker. */
2347 /* Output a marker (i.e. a label) for the beginning of a function, before
2351 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
2352 const char *file ATTRIBUTE_UNUSED
)
2354 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2357 current_function_func_begin_label
= 0;
2359 #ifdef IA64_UNWIND_INFO
2360 /* ??? current_function_func_begin_label is also used by except.c
2361 for call-site information. We must emit this label if it might
2363 if ((! flag_exceptions
|| USING_SJLJ_EXCEPTIONS
)
2364 && ! dwarf2out_do_frame ())
2367 if (! dwarf2out_do_frame ())
2371 function_section (current_function_decl
);
2372 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
2373 current_function_funcdef_no
);
2374 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
2375 current_function_funcdef_no
);
2376 current_function_func_begin_label
= get_identifier (label
);
2378 #ifdef IA64_UNWIND_INFO
2379 /* We can elide the fde allocation if we're not emitting debug info. */
2380 if (! dwarf2out_do_frame ())
2384 /* Expand the fde table if necessary. */
2385 if (fde_table_in_use
== fde_table_allocated
)
2387 fde_table_allocated
+= FDE_TABLE_INCREMENT
;
2388 fde_table
= ggc_realloc (fde_table
,
2389 fde_table_allocated
* sizeof (dw_fde_node
));
2390 memset (fde_table
+ fde_table_in_use
, 0,
2391 FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2394 /* Record the FDE associated with this function. */
2395 current_funcdef_fde
= fde_table_in_use
;
2397 /* Add the new FDE at the end of the fde_table. */
2398 fde
= &fde_table
[fde_table_in_use
++];
2399 fde
->decl
= current_function_decl
;
2400 fde
->dw_fde_begin
= xstrdup (label
);
2401 fde
->dw_fde_current_label
= NULL
;
2402 fde
->dw_fde_end
= NULL
;
2403 fde
->dw_fde_cfi
= NULL
;
2404 fde
->funcdef_number
= current_function_funcdef_no
;
2405 fde
->nothrow
= current_function_nothrow
;
2406 fde
->uses_eh_lsda
= cfun
->uses_eh_lsda
;
2407 fde
->all_throwers_are_sibcalls
= cfun
->all_throwers_are_sibcalls
;
2409 args_size
= old_args_size
= 0;
2411 /* We only want to output line number information for the genuine dwarf2
2412 prologue case, not the eh frame case. */
2413 #ifdef DWARF2_DEBUGGING_INFO
2415 dwarf2out_source_line (line
, file
);
2419 /* Output a marker (i.e. a label) for the absolute end of the generated code
2420 for a function definition. This gets called *after* the epilogue code has
2424 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
2425 const char *file ATTRIBUTE_UNUSED
)
2428 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
2430 /* Output a label to mark the endpoint of the code generated for this
2432 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
2433 current_function_funcdef_no
);
2434 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2435 fde
= &fde_table
[fde_table_in_use
- 1];
2436 fde
->dw_fde_end
= xstrdup (label
);
2440 dwarf2out_frame_init (void)
2442 /* Allocate the initial hunk of the fde_table. */
2443 fde_table
= ggc_alloc_cleared (FDE_TABLE_INCREMENT
* sizeof (dw_fde_node
));
2444 fde_table_allocated
= FDE_TABLE_INCREMENT
;
2445 fde_table_in_use
= 0;
2447 /* Generate the CFA instructions common to all FDE's. Do it now for the
2448 sake of lookup_cfa. */
2450 #ifdef DWARF2_UNWIND_INFO
2451 /* On entry, the Canonical Frame Address is at SP. */
2452 dwarf2out_def_cfa (NULL
, STACK_POINTER_REGNUM
, INCOMING_FRAME_SP_OFFSET
);
2453 initial_return_save (INCOMING_RETURN_ADDR_RTX
);
2458 dwarf2out_frame_finish (void)
2460 /* Output call frame information. */
2461 if (write_symbols
== DWARF2_DEBUG
|| write_symbols
== VMS_AND_DWARF2_DEBUG
)
2462 output_call_frame_info (0);
2464 if (! USING_SJLJ_EXCEPTIONS
&& (flag_unwind_tables
|| flag_exceptions
))
2465 output_call_frame_info (1);
2469 /* And now, the subset of the debugging information support code necessary
2470 for emitting location expressions. */
2472 /* We need some way to distinguish DW_OP_addr with a direct symbol
2473 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2474 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2477 typedef struct dw_val_struct
*dw_val_ref
;
2478 typedef struct die_struct
*dw_die_ref
;
2479 typedef struct dw_loc_descr_struct
*dw_loc_descr_ref
;
2480 typedef struct dw_loc_list_struct
*dw_loc_list_ref
;
2482 /* Each DIE may have a series of attribute/value pairs. Values
2483 can take on several forms. The forms that are used in this
2484 implementation are listed below. */
2489 dw_val_class_offset
,
2491 dw_val_class_loc_list
,
2492 dw_val_class_range_list
,
2494 dw_val_class_unsigned_const
,
2495 dw_val_class_long_long
,
2498 dw_val_class_die_ref
,
2499 dw_val_class_fde_ref
,
2500 dw_val_class_lbl_id
,
2501 dw_val_class_lbl_offset
,
2505 /* Describe a double word constant value. */
2506 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2508 typedef struct dw_long_long_struct
GTY(())
2515 /* Describe a floating point constant value, or a vector constant value. */
2517 typedef struct dw_vec_struct
GTY(())
2519 unsigned char * GTY((length ("%h.length"))) array
;
2525 /* The dw_val_node describes an attribute's value, as it is
2526 represented internally. */
2528 typedef struct dw_val_struct
GTY(())
2530 enum dw_val_class val_class
;
2531 union dw_val_struct_union
2533 rtx
GTY ((tag ("dw_val_class_addr"))) val_addr
;
2534 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_offset"))) val_offset
;
2535 dw_loc_list_ref
GTY ((tag ("dw_val_class_loc_list"))) val_loc_list
;
2536 dw_loc_descr_ref
GTY ((tag ("dw_val_class_loc"))) val_loc
;
2537 HOST_WIDE_INT
GTY ((default)) val_int
;
2538 unsigned HOST_WIDE_INT
GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned
;
2539 dw_long_long_const
GTY ((tag ("dw_val_class_long_long"))) val_long_long
;
2540 dw_vec_const
GTY ((tag ("dw_val_class_vec"))) val_vec
;
2541 struct dw_val_die_union
2545 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref
;
2546 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index
;
2547 struct indirect_string_node
* GTY ((tag ("dw_val_class_str"))) val_str
;
2548 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id
;
2549 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag
;
2551 GTY ((desc ("%1.val_class"))) v
;
2555 /* Locations in memory are described using a sequence of stack machine
2558 typedef struct dw_loc_descr_struct
GTY(())
2560 dw_loc_descr_ref dw_loc_next
;
2561 enum dwarf_location_atom dw_loc_opc
;
2562 dw_val_node dw_loc_oprnd1
;
2563 dw_val_node dw_loc_oprnd2
;
2568 /* Location lists are ranges + location descriptions for that range,
2569 so you can track variables that are in different places over
2570 their entire life. */
2571 typedef struct dw_loc_list_struct
GTY(())
2573 dw_loc_list_ref dw_loc_next
;
2574 const char *begin
; /* Label for begin address of range */
2575 const char *end
; /* Label for end address of range */
2576 char *ll_symbol
; /* Label for beginning of location list.
2577 Only on head of list */
2578 const char *section
; /* Section this loclist is relative to */
2579 dw_loc_descr_ref expr
;
2582 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2584 static const char *dwarf_stack_op_name (unsigned);
2585 static dw_loc_descr_ref
new_loc_descr (enum dwarf_location_atom
,
2586 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2587 static void add_loc_descr (dw_loc_descr_ref
*, dw_loc_descr_ref
);
2588 static unsigned long size_of_loc_descr (dw_loc_descr_ref
);
2589 static unsigned long size_of_locs (dw_loc_descr_ref
);
2590 static void output_loc_operands (dw_loc_descr_ref
);
2591 static void output_loc_sequence (dw_loc_descr_ref
);
2593 /* Convert a DWARF stack opcode into its string name. */
2596 dwarf_stack_op_name (unsigned int op
)
2601 case INTERNAL_DW_OP_tls_addr
:
2602 return "DW_OP_addr";
2604 return "DW_OP_deref";
2606 return "DW_OP_const1u";
2608 return "DW_OP_const1s";
2610 return "DW_OP_const2u";
2612 return "DW_OP_const2s";
2614 return "DW_OP_const4u";
2616 return "DW_OP_const4s";
2618 return "DW_OP_const8u";
2620 return "DW_OP_const8s";
2622 return "DW_OP_constu";
2624 return "DW_OP_consts";
2628 return "DW_OP_drop";
2630 return "DW_OP_over";
2632 return "DW_OP_pick";
2634 return "DW_OP_swap";
2638 return "DW_OP_xderef";
2646 return "DW_OP_minus";
2658 return "DW_OP_plus";
2659 case DW_OP_plus_uconst
:
2660 return "DW_OP_plus_uconst";
2666 return "DW_OP_shra";
2684 return "DW_OP_skip";
2686 return "DW_OP_lit0";
2688 return "DW_OP_lit1";
2690 return "DW_OP_lit2";
2692 return "DW_OP_lit3";
2694 return "DW_OP_lit4";
2696 return "DW_OP_lit5";
2698 return "DW_OP_lit6";
2700 return "DW_OP_lit7";
2702 return "DW_OP_lit8";
2704 return "DW_OP_lit9";
2706 return "DW_OP_lit10";
2708 return "DW_OP_lit11";
2710 return "DW_OP_lit12";
2712 return "DW_OP_lit13";
2714 return "DW_OP_lit14";
2716 return "DW_OP_lit15";
2718 return "DW_OP_lit16";
2720 return "DW_OP_lit17";
2722 return "DW_OP_lit18";
2724 return "DW_OP_lit19";
2726 return "DW_OP_lit20";
2728 return "DW_OP_lit21";
2730 return "DW_OP_lit22";
2732 return "DW_OP_lit23";
2734 return "DW_OP_lit24";
2736 return "DW_OP_lit25";
2738 return "DW_OP_lit26";
2740 return "DW_OP_lit27";
2742 return "DW_OP_lit28";
2744 return "DW_OP_lit29";
2746 return "DW_OP_lit30";
2748 return "DW_OP_lit31";
2750 return "DW_OP_reg0";
2752 return "DW_OP_reg1";
2754 return "DW_OP_reg2";
2756 return "DW_OP_reg3";
2758 return "DW_OP_reg4";
2760 return "DW_OP_reg5";
2762 return "DW_OP_reg6";
2764 return "DW_OP_reg7";
2766 return "DW_OP_reg8";
2768 return "DW_OP_reg9";
2770 return "DW_OP_reg10";
2772 return "DW_OP_reg11";
2774 return "DW_OP_reg12";
2776 return "DW_OP_reg13";
2778 return "DW_OP_reg14";
2780 return "DW_OP_reg15";
2782 return "DW_OP_reg16";
2784 return "DW_OP_reg17";
2786 return "DW_OP_reg18";
2788 return "DW_OP_reg19";
2790 return "DW_OP_reg20";
2792 return "DW_OP_reg21";
2794 return "DW_OP_reg22";
2796 return "DW_OP_reg23";
2798 return "DW_OP_reg24";
2800 return "DW_OP_reg25";
2802 return "DW_OP_reg26";
2804 return "DW_OP_reg27";
2806 return "DW_OP_reg28";
2808 return "DW_OP_reg29";
2810 return "DW_OP_reg30";
2812 return "DW_OP_reg31";
2814 return "DW_OP_breg0";
2816 return "DW_OP_breg1";
2818 return "DW_OP_breg2";
2820 return "DW_OP_breg3";
2822 return "DW_OP_breg4";
2824 return "DW_OP_breg5";
2826 return "DW_OP_breg6";
2828 return "DW_OP_breg7";
2830 return "DW_OP_breg8";
2832 return "DW_OP_breg9";
2834 return "DW_OP_breg10";
2836 return "DW_OP_breg11";
2838 return "DW_OP_breg12";
2840 return "DW_OP_breg13";
2842 return "DW_OP_breg14";
2844 return "DW_OP_breg15";
2846 return "DW_OP_breg16";
2848 return "DW_OP_breg17";
2850 return "DW_OP_breg18";
2852 return "DW_OP_breg19";
2854 return "DW_OP_breg20";
2856 return "DW_OP_breg21";
2858 return "DW_OP_breg22";
2860 return "DW_OP_breg23";
2862 return "DW_OP_breg24";
2864 return "DW_OP_breg25";
2866 return "DW_OP_breg26";
2868 return "DW_OP_breg27";
2870 return "DW_OP_breg28";
2872 return "DW_OP_breg29";
2874 return "DW_OP_breg30";
2876 return "DW_OP_breg31";
2878 return "DW_OP_regx";
2880 return "DW_OP_fbreg";
2882 return "DW_OP_bregx";
2884 return "DW_OP_piece";
2885 case DW_OP_deref_size
:
2886 return "DW_OP_deref_size";
2887 case DW_OP_xderef_size
:
2888 return "DW_OP_xderef_size";
2891 case DW_OP_push_object_address
:
2892 return "DW_OP_push_object_address";
2894 return "DW_OP_call2";
2896 return "DW_OP_call4";
2897 case DW_OP_call_ref
:
2898 return "DW_OP_call_ref";
2899 case DW_OP_GNU_push_tls_address
:
2900 return "DW_OP_GNU_push_tls_address";
2902 return "OP_<unknown>";
2906 /* Return a pointer to a newly allocated location description. Location
2907 descriptions are simple expression terms that can be strung
2908 together to form more complicated location (address) descriptions. */
2910 static inline dw_loc_descr_ref
2911 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
2912 unsigned HOST_WIDE_INT oprnd2
)
2914 dw_loc_descr_ref descr
= ggc_alloc_cleared (sizeof (dw_loc_descr_node
));
2916 descr
->dw_loc_opc
= op
;
2917 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
2918 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
2919 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
2920 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
2926 /* Add a location description term to a location description expression. */
2929 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
2931 dw_loc_descr_ref
*d
;
2933 /* Find the end of the chain. */
2934 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
2940 /* Return the size of a location descriptor. */
2942 static unsigned long
2943 size_of_loc_descr (dw_loc_descr_ref loc
)
2945 unsigned long size
= 1;
2947 switch (loc
->dw_loc_opc
)
2950 case INTERNAL_DW_OP_tls_addr
:
2951 size
+= DWARF2_ADDR_SIZE
;
2970 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
2973 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
2978 case DW_OP_plus_uconst
:
2979 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3017 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3020 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3023 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
3026 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3027 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
3030 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
3032 case DW_OP_deref_size
:
3033 case DW_OP_xderef_size
:
3042 case DW_OP_call_ref
:
3043 size
+= DWARF2_ADDR_SIZE
;
3052 /* Return the size of a series of location descriptors. */
3054 static unsigned long
3055 size_of_locs (dw_loc_descr_ref loc
)
3059 for (size
= 0; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3061 loc
->dw_loc_addr
= size
;
3062 size
+= size_of_loc_descr (loc
);
3068 /* Output location description stack opcode's operands (if any). */
3071 output_loc_operands (dw_loc_descr_ref loc
)
3073 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
3074 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
3076 switch (loc
->dw_loc_opc
)
3078 #ifdef DWARF2_DEBUGGING_INFO
3080 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
3084 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
3088 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
3092 if (HOST_BITS_PER_LONG
< 64)
3094 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
3101 if (val1
->val_class
== dw_val_class_loc
)
3102 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
3106 dw2_asm_output_data (2, offset
, NULL
);
3119 /* We currently don't make any attempt to make sure these are
3120 aligned properly like we do for the main unwind info, so
3121 don't support emitting things larger than a byte if we're
3122 only doing unwinding. */
3127 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3130 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3133 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3136 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3138 case DW_OP_plus_uconst
:
3139 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3173 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3176 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3179 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
3182 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3183 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
3186 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
3188 case DW_OP_deref_size
:
3189 case DW_OP_xderef_size
:
3190 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
3193 case INTERNAL_DW_OP_tls_addr
:
3194 #ifdef ASM_OUTPUT_DWARF_DTPREL
3195 ASM_OUTPUT_DWARF_DTPREL (asm_out_file
, DWARF2_ADDR_SIZE
,
3197 fputc ('\n', asm_out_file
);
3204 /* Other codes have no operands. */
3209 /* Output a sequence of location operations. */
3212 output_loc_sequence (dw_loc_descr_ref loc
)
3214 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
3216 /* Output the opcode. */
3217 dw2_asm_output_data (1, loc
->dw_loc_opc
,
3218 "%s", dwarf_stack_op_name (loc
->dw_loc_opc
));
3220 /* Output the operand(s) (if any). */
3221 output_loc_operands (loc
);
3225 /* This routine will generate the correct assembly data for a location
3226 description based on a cfi entry with a complex address. */
3229 output_cfa_loc (dw_cfi_ref cfi
)
3231 dw_loc_descr_ref loc
;
3234 /* Output the size of the block. */
3235 loc
= cfi
->dw_cfi_oprnd1
.dw_cfi_loc
;
3236 size
= size_of_locs (loc
);
3237 dw2_asm_output_data_uleb128 (size
, NULL
);
3239 /* Now output the operations themselves. */
3240 output_loc_sequence (loc
);
3243 /* This function builds a dwarf location descriptor sequence from
3244 a dw_cfa_location. */
3246 static struct dw_loc_descr_struct
*
3247 build_cfa_loc (dw_cfa_location
*cfa
)
3249 struct dw_loc_descr_struct
*head
, *tmp
;
3251 if (cfa
->indirect
== 0)
3254 if (cfa
->base_offset
)
3257 head
= new_loc_descr (DW_OP_breg0
+ cfa
->reg
, cfa
->base_offset
, 0);
3259 head
= new_loc_descr (DW_OP_bregx
, cfa
->reg
, cfa
->base_offset
);
3261 else if (cfa
->reg
<= 31)
3262 head
= new_loc_descr (DW_OP_reg0
+ cfa
->reg
, 0, 0);
3264 head
= new_loc_descr (DW_OP_regx
, cfa
->reg
, 0);
3266 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
3267 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
3268 add_loc_descr (&head
, tmp
);
3269 if (cfa
->offset
!= 0)
3271 tmp
= new_loc_descr (DW_OP_plus_uconst
, cfa
->offset
, 0);
3272 add_loc_descr (&head
, tmp
);
3278 /* This function fills in aa dw_cfa_location structure from a dwarf location
3279 descriptor sequence. */
3282 get_cfa_from_loc_descr (dw_cfa_location
*cfa
, struct dw_loc_descr_struct
*loc
)
3284 struct dw_loc_descr_struct
*ptr
;
3286 cfa
->base_offset
= 0;
3290 for (ptr
= loc
; ptr
!= NULL
; ptr
= ptr
->dw_loc_next
)
3292 enum dwarf_location_atom op
= ptr
->dw_loc_opc
;
3328 cfa
->reg
= op
- DW_OP_reg0
;
3331 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3365 cfa
->reg
= op
- DW_OP_breg0
;
3366 cfa
->base_offset
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3369 cfa
->reg
= ptr
->dw_loc_oprnd1
.v
.val_int
;
3370 cfa
->base_offset
= ptr
->dw_loc_oprnd2
.v
.val_int
;
3375 case DW_OP_plus_uconst
:
3376 cfa
->offset
= ptr
->dw_loc_oprnd1
.v
.val_unsigned
;
3379 internal_error ("DW_LOC_OP %s not implemented\n",
3380 dwarf_stack_op_name (ptr
->dw_loc_opc
));
3384 #endif /* .debug_frame support */
3386 /* And now, the support for symbolic debugging information. */
3387 #ifdef DWARF2_DEBUGGING_INFO
3389 /* .debug_str support. */
3390 static int output_indirect_string (void **, void *);
3392 static void dwarf2out_init (const char *);
3393 static void dwarf2out_finish (const char *);
3394 static void dwarf2out_define (unsigned int, const char *);
3395 static void dwarf2out_undef (unsigned int, const char *);
3396 static void dwarf2out_start_source_file (unsigned, const char *);
3397 static void dwarf2out_end_source_file (unsigned);
3398 static void dwarf2out_begin_block (unsigned, unsigned);
3399 static void dwarf2out_end_block (unsigned, unsigned);
3400 static bool dwarf2out_ignore_block (tree
);
3401 static void dwarf2out_global_decl (tree
);
3402 static void dwarf2out_type_decl (tree
, int);
3403 static void dwarf2out_imported_module_or_decl (tree
, tree
);
3404 static void dwarf2out_abstract_function (tree
);
3405 static void dwarf2out_var_location (rtx
);
3406 static void dwarf2out_begin_function (tree
);
3408 /* The debug hooks structure. */
3410 const struct gcc_debug_hooks dwarf2_debug_hooks
=
3416 dwarf2out_start_source_file
,
3417 dwarf2out_end_source_file
,
3418 dwarf2out_begin_block
,
3419 dwarf2out_end_block
,
3420 dwarf2out_ignore_block
,
3421 dwarf2out_source_line
,
3422 dwarf2out_begin_prologue
,
3423 debug_nothing_int_charstar
, /* end_prologue */
3424 dwarf2out_end_epilogue
,
3425 dwarf2out_begin_function
,
3426 debug_nothing_int
, /* end_function */
3427 dwarf2out_decl
, /* function_decl */
3428 dwarf2out_global_decl
,
3429 dwarf2out_type_decl
, /* type_decl */
3430 dwarf2out_imported_module_or_decl
,
3431 debug_nothing_tree
, /* deferred_inline_function */
3432 /* The DWARF 2 backend tries to reduce debugging bloat by not
3433 emitting the abstract description of inline functions until
3434 something tries to reference them. */
3435 dwarf2out_abstract_function
, /* outlining_inline_function */
3436 debug_nothing_rtx
, /* label */
3437 debug_nothing_int
, /* handle_pch */
3438 dwarf2out_var_location
3442 /* NOTE: In the comments in this file, many references are made to
3443 "Debugging Information Entries". This term is abbreviated as `DIE'
3444 throughout the remainder of this file. */
3446 /* An internal representation of the DWARF output is built, and then
3447 walked to generate the DWARF debugging info. The walk of the internal
3448 representation is done after the entire program has been compiled.
3449 The types below are used to describe the internal representation. */
3451 /* Various DIE's use offsets relative to the beginning of the
3452 .debug_info section to refer to each other. */
3454 typedef long int dw_offset
;
3456 /* Define typedefs here to avoid circular dependencies. */
3458 typedef struct dw_attr_struct
*dw_attr_ref
;
3459 typedef struct dw_line_info_struct
*dw_line_info_ref
;
3460 typedef struct dw_separate_line_info_struct
*dw_separate_line_info_ref
;
3461 typedef struct pubname_struct
*pubname_ref
;
3462 typedef struct dw_ranges_struct
*dw_ranges_ref
;
3464 /* Each entry in the line_info_table maintains the file and
3465 line number associated with the label generated for that
3466 entry. The label gives the PC value associated with
3467 the line number entry. */
3469 typedef struct dw_line_info_struct
GTY(())
3471 unsigned long dw_file_num
;
3472 unsigned long dw_line_num
;
3476 /* Line information for functions in separate sections; each one gets its
3478 typedef struct dw_separate_line_info_struct
GTY(())
3480 unsigned long dw_file_num
;
3481 unsigned long dw_line_num
;
3482 unsigned long function
;
3484 dw_separate_line_info_entry
;
3486 /* Each DIE attribute has a field specifying the attribute kind,
3487 a link to the next attribute in the chain, and an attribute value.
3488 Attributes are typically linked below the DIE they modify. */
3490 typedef struct dw_attr_struct
GTY(())
3492 enum dwarf_attribute dw_attr
;
3493 dw_attr_ref dw_attr_next
;
3494 dw_val_node dw_attr_val
;
3498 /* The Debugging Information Entry (DIE) structure */
3500 typedef struct die_struct
GTY(())
3502 enum dwarf_tag die_tag
;
3504 dw_attr_ref die_attr
;
3505 dw_die_ref die_parent
;
3506 dw_die_ref die_child
;
3508 dw_die_ref die_definition
; /* ref from a specification to its definition */
3509 dw_offset die_offset
;
3510 unsigned long die_abbrev
;
3512 unsigned int decl_id
;
3516 /* The pubname structure */
3518 typedef struct pubname_struct
GTY(())
3525 struct dw_ranges_struct
GTY(())
3530 /* The limbo die list structure. */
3531 typedef struct limbo_die_struct
GTY(())
3535 struct limbo_die_struct
*next
;
3539 /* How to start an assembler comment. */
3540 #ifndef ASM_COMMENT_START
3541 #define ASM_COMMENT_START ";#"
3544 /* Define a macro which returns nonzero for a TYPE_DECL which was
3545 implicitly generated for a tagged type.
3547 Note that unlike the gcc front end (which generates a NULL named
3548 TYPE_DECL node for each complete tagged type, each array type, and
3549 each function type node created) the g++ front end generates a
3550 _named_ TYPE_DECL node for each tagged type node created.
3551 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3552 generate a DW_TAG_typedef DIE for them. */
3554 #define TYPE_DECL_IS_STUB(decl) \
3555 (DECL_NAME (decl) == NULL_TREE \
3556 || (DECL_ARTIFICIAL (decl) \
3557 && is_tagged_type (TREE_TYPE (decl)) \
3558 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3559 /* This is necessary for stub decls that \
3560 appear in nested inline functions. */ \
3561 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3562 && (decl_ultimate_origin (decl) \
3563 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3565 /* Information concerning the compilation unit's programming
3566 language, and compiler version. */
3568 /* Fixed size portion of the DWARF compilation unit header. */
3569 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3570 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3572 /* Fixed size portion of public names info. */
3573 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3575 /* Fixed size portion of the address range info. */
3576 #define DWARF_ARANGES_HEADER_SIZE \
3577 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3578 DWARF2_ADDR_SIZE * 2) \
3579 - DWARF_INITIAL_LENGTH_SIZE)
3581 /* Size of padding portion in the address range info. It must be
3582 aligned to twice the pointer size. */
3583 #define DWARF_ARANGES_PAD_SIZE \
3584 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3585 DWARF2_ADDR_SIZE * 2) \
3586 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3588 /* Use assembler line directives if available. */
3589 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3590 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3591 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3593 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3597 /* Minimum line offset in a special line info. opcode.
3598 This value was chosen to give a reasonable range of values. */
3599 #define DWARF_LINE_BASE -10
3601 /* First special line opcode - leave room for the standard opcodes. */
3602 #define DWARF_LINE_OPCODE_BASE 10
3604 /* Range of line offsets in a special line info. opcode. */
3605 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3607 /* Flag that indicates the initial value of the is_stmt_start flag.
3608 In the present implementation, we do not mark any lines as
3609 the beginning of a source statement, because that information
3610 is not made available by the GCC front-end. */
3611 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3613 #ifdef DWARF2_DEBUGGING_INFO
3614 /* This location is used by calc_die_sizes() to keep track
3615 the offset of each DIE within the .debug_info section. */
3616 static unsigned long next_die_offset
;
3619 /* Record the root of the DIE's built for the current compilation unit. */
3620 static GTY(()) dw_die_ref comp_unit_die
;
3622 /* A list of DIEs with a NULL parent waiting to be relocated. */
3623 static GTY(()) limbo_die_node
*limbo_die_list
;
3625 /* Filenames referenced by this compilation unit. */
3626 static GTY(()) varray_type file_table
;
3627 static GTY(()) varray_type file_table_emitted
;
3628 static GTY(()) size_t file_table_last_lookup_index
;
3630 /* A hash table of references to DIE's that describe declarations.
3631 The key is a DECL_UID() which is a unique number identifying each decl. */
3632 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
3634 /* Node of the variable location list. */
3635 struct var_loc_node
GTY ((chain_next ("%h.next")))
3637 rtx
GTY (()) var_loc_note
;
3638 const char * GTY (()) label
;
3639 struct var_loc_node
* GTY (()) next
;
3642 /* Variable location list. */
3643 struct var_loc_list_def
GTY (())
3645 struct var_loc_node
* GTY (()) first
;
3647 /* Do not mark the last element of the chained list because
3648 it is marked through the chain. */
3649 struct var_loc_node
* GTY ((skip ("%h"))) last
;
3651 /* DECL_UID of the variable decl. */
3652 unsigned int decl_id
;
3654 typedef struct var_loc_list_def var_loc_list
;
3657 /* Table of decl location linked lists. */
3658 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
3660 /* A pointer to the base of a list of references to DIE's that
3661 are uniquely identified by their tag, presence/absence of
3662 children DIE's, and list of attribute/value pairs. */
3663 static GTY((length ("abbrev_die_table_allocated")))
3664 dw_die_ref
*abbrev_die_table
;
3666 /* Number of elements currently allocated for abbrev_die_table. */
3667 static GTY(()) unsigned abbrev_die_table_allocated
;
3669 /* Number of elements in type_die_table currently in use. */
3670 static GTY(()) unsigned abbrev_die_table_in_use
;
3672 /* Size (in elements) of increments by which we may expand the
3673 abbrev_die_table. */
3674 #define ABBREV_DIE_TABLE_INCREMENT 256
3676 /* A pointer to the base of a table that contains line information
3677 for each source code line in .text in the compilation unit. */
3678 static GTY((length ("line_info_table_allocated")))
3679 dw_line_info_ref line_info_table
;
3681 /* Number of elements currently allocated for line_info_table. */
3682 static GTY(()) unsigned line_info_table_allocated
;
3684 /* Number of elements in line_info_table currently in use. */
3685 static GTY(()) unsigned line_info_table_in_use
;
3687 /* A pointer to the base of a table that contains line information
3688 for each source code line outside of .text in the compilation unit. */
3689 static GTY ((length ("separate_line_info_table_allocated")))
3690 dw_separate_line_info_ref separate_line_info_table
;
3692 /* Number of elements currently allocated for separate_line_info_table. */
3693 static GTY(()) unsigned separate_line_info_table_allocated
;
3695 /* Number of elements in separate_line_info_table currently in use. */
3696 static GTY(()) unsigned separate_line_info_table_in_use
;
3698 /* Size (in elements) of increments by which we may expand the
3700 #define LINE_INFO_TABLE_INCREMENT 1024
3702 /* A pointer to the base of a table that contains a list of publicly
3703 accessible names. */
3704 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table
;
3706 /* Number of elements currently allocated for pubname_table. */
3707 static GTY(()) unsigned pubname_table_allocated
;
3709 /* Number of elements in pubname_table currently in use. */
3710 static GTY(()) unsigned pubname_table_in_use
;
3712 /* Size (in elements) of increments by which we may expand the
3714 #define PUBNAME_TABLE_INCREMENT 64
3716 /* Array of dies for which we should generate .debug_arange info. */
3717 static GTY((length ("arange_table_allocated"))) dw_die_ref
*arange_table
;
3719 /* Number of elements currently allocated for arange_table. */
3720 static GTY(()) unsigned arange_table_allocated
;
3722 /* Number of elements in arange_table currently in use. */
3723 static GTY(()) unsigned arange_table_in_use
;
3725 /* Size (in elements) of increments by which we may expand the
3727 #define ARANGE_TABLE_INCREMENT 64
3729 /* Array of dies for which we should generate .debug_ranges info. */
3730 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
3732 /* Number of elements currently allocated for ranges_table. */
3733 static GTY(()) unsigned ranges_table_allocated
;
3735 /* Number of elements in ranges_table currently in use. */
3736 static GTY(()) unsigned ranges_table_in_use
;
3738 /* Size (in elements) of increments by which we may expand the
3740 #define RANGES_TABLE_INCREMENT 64
3742 /* Whether we have location lists that need outputting */
3743 static GTY(()) unsigned have_location_lists
;
3745 /* Unique label counter. */
3746 static GTY(()) unsigned int loclabel_num
;
3748 #ifdef DWARF2_DEBUGGING_INFO
3749 /* Record whether the function being analyzed contains inlined functions. */
3750 static int current_function_has_inlines
;
3752 #if 0 && defined (MIPS_DEBUGGING_INFO)
3753 static int comp_unit_has_inlines
;
3756 /* Number of file tables emitted in maybe_emit_file(). */
3757 static GTY(()) int emitcount
= 0;
3759 /* Number of internal labels generated by gen_internal_sym(). */
3760 static GTY(()) int label_num
;
3762 #ifdef DWARF2_DEBUGGING_INFO
3764 /* Forward declarations for functions defined in this file. */
3766 static int is_pseudo_reg (rtx
);
3767 static tree
type_main_variant (tree
);
3768 static int is_tagged_type (tree
);
3769 static const char *dwarf_tag_name (unsigned);
3770 static const char *dwarf_attr_name (unsigned);
3771 static const char *dwarf_form_name (unsigned);
3773 static const char *dwarf_type_encoding_name (unsigned);
3775 static tree
decl_ultimate_origin (tree
);
3776 static tree
block_ultimate_origin (tree
);
3777 static tree
decl_class_context (tree
);
3778 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3779 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3780 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3781 static inline unsigned AT_flag (dw_attr_ref
);
3782 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3783 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3784 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3785 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3786 static void add_AT_long_long (dw_die_ref
, enum dwarf_attribute
, unsigned long,
3788 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3789 unsigned int, unsigned char *);
3790 static hashval_t
debug_str_do_hash (const void *);
3791 static int debug_str_eq (const void *, const void *);
3792 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3793 static inline const char *AT_string (dw_attr_ref
);
3794 static int AT_string_form (dw_attr_ref
);
3795 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3796 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3797 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3798 static inline int AT_ref_external (dw_attr_ref
);
3799 static inline void set_AT_ref_external (dw_attr_ref
, int);
3800 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3801 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3802 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3803 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3805 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3806 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
);
3807 static inline rtx
AT_addr (dw_attr_ref
);
3808 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3809 static void add_AT_lbl_offset (dw_die_ref
, enum dwarf_attribute
, const char *);
3810 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3811 unsigned HOST_WIDE_INT
);
3812 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3814 static inline const char *AT_lbl (dw_attr_ref
);
3815 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3816 static const char *get_AT_low_pc (dw_die_ref
);
3817 static const char *get_AT_hi_pc (dw_die_ref
);
3818 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3819 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3820 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3821 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3822 static bool is_c_family (void);
3823 static bool is_cxx (void);
3824 static bool is_java (void);
3825 static bool is_fortran (void);
3826 static bool is_ada (void);
3827 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3828 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3829 static inline void free_die (dw_die_ref
);
3830 static void remove_children (dw_die_ref
);
3831 static void add_child_die (dw_die_ref
, dw_die_ref
);
3832 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3833 static dw_die_ref
lookup_type_die (tree
);
3834 static void equate_type_number_to_die (tree
, dw_die_ref
);
3835 static hashval_t
decl_die_table_hash (const void *);
3836 static int decl_die_table_eq (const void *, const void *);
3837 static dw_die_ref
lookup_decl_die (tree
);
3838 static hashval_t
decl_loc_table_hash (const void *);
3839 static int decl_loc_table_eq (const void *, const void *);
3840 static var_loc_list
*lookup_decl_loc (tree
);
3841 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3842 static void add_var_loc_to_decl (tree
, struct var_loc_node
*);
3843 static void print_spaces (FILE *);
3844 static void print_die (dw_die_ref
, FILE *);
3845 static void print_dwarf_line_table (FILE *);
3846 static void reverse_die_lists (dw_die_ref
);
3847 static void reverse_all_dies (dw_die_ref
);
3848 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3849 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3850 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3851 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3852 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3853 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3854 static int same_dw_val_p (dw_val_node
*, dw_val_node
*, int *);
3855 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3856 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3857 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3858 static void compute_section_prefix (dw_die_ref
);
3859 static int is_type_die (dw_die_ref
);
3860 static int is_comdat_die (dw_die_ref
);
3861 static int is_symbol_die (dw_die_ref
);
3862 static void assign_symbol_names (dw_die_ref
);
3863 static void break_out_includes (dw_die_ref
);
3864 static hashval_t
htab_cu_hash (const void *);
3865 static int htab_cu_eq (const void *, const void *);
3866 static void htab_cu_del (void *);
3867 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3868 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3869 static void add_sibling_attributes (dw_die_ref
);
3870 static void build_abbrev_table (dw_die_ref
);
3871 static void output_location_lists (dw_die_ref
);
3872 static int constant_size (long unsigned);
3873 static unsigned long size_of_die (dw_die_ref
);
3874 static void calc_die_sizes (dw_die_ref
);
3875 static void mark_dies (dw_die_ref
);
3876 static void unmark_dies (dw_die_ref
);
3877 static void unmark_all_dies (dw_die_ref
);
3878 static unsigned long size_of_pubnames (void);
3879 static unsigned long size_of_aranges (void);
3880 static enum dwarf_form
value_format (dw_attr_ref
);
3881 static void output_value_format (dw_attr_ref
);
3882 static void output_abbrev_section (void);
3883 static void output_die_symbol (dw_die_ref
);
3884 static void output_die (dw_die_ref
);
3885 static void output_compilation_unit_header (void);
3886 static void output_comp_unit (dw_die_ref
, int);
3887 static const char *dwarf2_name (tree
, int);
3888 static void add_pubname (tree
, dw_die_ref
);
3889 static void output_pubnames (void);
3890 static void add_arange (tree
, dw_die_ref
);
3891 static void output_aranges (void);
3892 static unsigned int add_ranges (tree
);
3893 static void output_ranges (void);
3894 static void output_line_info (void);
3895 static void output_file_names (void);
3896 static dw_die_ref
base_type_die (tree
);
3897 static tree
root_type (tree
);
3898 static int is_base_type (tree
);
3899 static bool is_subrange_type (tree
);
3900 static dw_die_ref
subrange_type_die (tree
, dw_die_ref
);
3901 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3902 static int type_is_enum (tree
);
3903 static unsigned int dbx_reg_number (rtx
);
3904 static dw_loc_descr_ref
reg_loc_descriptor (rtx
);
3905 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int);
3906 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
);
3907 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
3908 static dw_loc_descr_ref
based_loc_descr (unsigned, HOST_WIDE_INT
, bool);
3909 static int is_based_loc (rtx
);
3910 static dw_loc_descr_ref
mem_loc_descriptor (rtx
, enum machine_mode mode
, bool);
3911 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
);
3912 static dw_loc_descr_ref
loc_descriptor (rtx
, bool);
3913 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3914 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3915 static tree
field_type (tree
);
3916 static unsigned int simple_type_align_in_bits (tree
);
3917 static unsigned int simple_decl_align_in_bits (tree
);
3918 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (tree
);
3919 static HOST_WIDE_INT
field_byte_offset (tree
);
3920 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3922 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3923 static void add_const_value_attribute (dw_die_ref
, rtx
);
3924 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3925 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
3926 static void insert_float (rtx
, unsigned char *);
3927 static rtx
rtl_for_decl_location (tree
);
3928 static void add_location_or_const_value_attribute (dw_die_ref
, tree
,
3929 enum dwarf_attribute
);
3930 static void tree_add_const_value_attribute (dw_die_ref
, tree
);
3931 static void add_name_attribute (dw_die_ref
, const char *);
3932 static void add_comp_dir_attribute (dw_die_ref
);
3933 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3934 static void add_subscript_info (dw_die_ref
, tree
);
3935 static void add_byte_size_attribute (dw_die_ref
, tree
);
3936 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3937 static void add_bit_size_attribute (dw_die_ref
, tree
);
3938 static void add_prototyped_attribute (dw_die_ref
, tree
);
3939 static void add_abstract_origin_attribute (dw_die_ref
, tree
);
3940 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3941 static void add_src_coords_attributes (dw_die_ref
, tree
);
3942 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3943 static void push_decl_scope (tree
);
3944 static void pop_decl_scope (void);
3945 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3946 static inline int local_scope_p (dw_die_ref
);
3947 static inline int class_or_namespace_scope_p (dw_die_ref
);
3948 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3949 static const char *type_tag (tree
);
3950 static tree
member_declared_type (tree
);
3952 static const char *decl_start_label (tree
);
3954 static void gen_array_type_die (tree
, dw_die_ref
);
3955 static void gen_set_type_die (tree
, dw_die_ref
);
3957 static void gen_entry_point_die (tree
, dw_die_ref
);
3959 static void gen_inlined_enumeration_type_die (tree
, dw_die_ref
);
3960 static void gen_inlined_structure_type_die (tree
, dw_die_ref
);
3961 static void gen_inlined_union_type_die (tree
, dw_die_ref
);
3962 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3963 static dw_die_ref
gen_formal_parameter_die (tree
, dw_die_ref
);
3964 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3965 static void gen_formal_types_die (tree
, dw_die_ref
);
3966 static void gen_subprogram_die (tree
, dw_die_ref
);
3967 static void gen_variable_die (tree
, dw_die_ref
);
3968 static void gen_label_die (tree
, dw_die_ref
);
3969 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3970 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3971 static void gen_field_die (tree
, dw_die_ref
);
3972 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3973 static dw_die_ref
gen_compile_unit_die (const char *);
3974 static void gen_string_type_die (tree
, dw_die_ref
);
3975 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3976 static void gen_member_die (tree
, dw_die_ref
);
3977 static void gen_struct_or_union_type_die (tree
, dw_die_ref
);
3978 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3979 static void gen_typedef_die (tree
, dw_die_ref
);
3980 static void gen_type_die (tree
, dw_die_ref
);
3981 static void gen_tagged_type_instantiation_die (tree
, dw_die_ref
);
3982 static void gen_block_die (tree
, dw_die_ref
, int);
3983 static void decls_for_scope (tree
, dw_die_ref
, int);
3984 static int is_redundant_typedef (tree
);
3985 static void gen_namespace_die (tree
);
3986 static void gen_decl_die (tree
, dw_die_ref
);
3987 static dw_die_ref
force_decl_die (tree
);
3988 static dw_die_ref
force_type_die (tree
);
3989 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3990 static void declare_in_namespace (tree
, dw_die_ref
);
3991 static unsigned lookup_filename (const char *);
3992 static void init_file_table (void);
3993 static void retry_incomplete_types (void);
3994 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3995 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3996 static int file_info_cmp (const void *, const void *);
3997 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3998 const char *, const char *, unsigned);
3999 static void add_loc_descr_to_loc_list (dw_loc_list_ref
*, dw_loc_descr_ref
,
4000 const char *, const char *,
4002 static void output_loc_list (dw_loc_list_ref
);
4003 static char *gen_internal_sym (const char *);
4005 static void prune_unmark_dies (dw_die_ref
);
4006 static void prune_unused_types_mark (dw_die_ref
, int);
4007 static void prune_unused_types_walk (dw_die_ref
);
4008 static void prune_unused_types_walk_attribs (dw_die_ref
);
4009 static void prune_unused_types_prune (dw_die_ref
);
4010 static void prune_unused_types (void);
4011 static int maybe_emit_file (int);
4013 /* Section names used to hold DWARF debugging information. */
4014 #ifndef DEBUG_INFO_SECTION
4015 #define DEBUG_INFO_SECTION ".debug_info"
4017 #ifndef DEBUG_ABBREV_SECTION
4018 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4020 #ifndef DEBUG_ARANGES_SECTION
4021 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4023 #ifndef DEBUG_MACINFO_SECTION
4024 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4026 #ifndef DEBUG_LINE_SECTION
4027 #define DEBUG_LINE_SECTION ".debug_line"
4029 #ifndef DEBUG_LOC_SECTION
4030 #define DEBUG_LOC_SECTION ".debug_loc"
4032 #ifndef DEBUG_PUBNAMES_SECTION
4033 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4035 #ifndef DEBUG_STR_SECTION
4036 #define DEBUG_STR_SECTION ".debug_str"
4038 #ifndef DEBUG_RANGES_SECTION
4039 #define DEBUG_RANGES_SECTION ".debug_ranges"
4042 /* Standard ELF section names for compiled code and data. */
4043 #ifndef TEXT_SECTION_NAME
4044 #define TEXT_SECTION_NAME ".text"
4047 /* Section flags for .debug_str section. */
4048 #define DEBUG_STR_SECTION_FLAGS \
4049 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4050 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4053 /* Labels we insert at beginning sections we can reference instead of
4054 the section names themselves. */
4056 #ifndef TEXT_SECTION_LABEL
4057 #define TEXT_SECTION_LABEL "Ltext"
4059 #ifndef DEBUG_LINE_SECTION_LABEL
4060 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4062 #ifndef DEBUG_INFO_SECTION_LABEL
4063 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4065 #ifndef DEBUG_ABBREV_SECTION_LABEL
4066 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4068 #ifndef DEBUG_LOC_SECTION_LABEL
4069 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4071 #ifndef DEBUG_RANGES_SECTION_LABEL
4072 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4074 #ifndef DEBUG_MACINFO_SECTION_LABEL
4075 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4078 /* Definitions of defaults for formats and names of various special
4079 (artificial) labels which may be generated within this file (when the -g
4080 options is used and DWARF2_DEBUGGING_INFO is in effect.
4081 If necessary, these may be overridden from within the tm.h file, but
4082 typically, overriding these defaults is unnecessary. */
4084 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4085 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4086 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4087 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4088 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4089 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4090 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
4091 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
4093 #ifndef TEXT_END_LABEL
4094 #define TEXT_END_LABEL "Letext"
4096 #ifndef BLOCK_BEGIN_LABEL
4097 #define BLOCK_BEGIN_LABEL "LBB"
4099 #ifndef BLOCK_END_LABEL
4100 #define BLOCK_END_LABEL "LBE"
4102 #ifndef LINE_CODE_LABEL
4103 #define LINE_CODE_LABEL "LM"
4105 #ifndef SEPARATE_LINE_CODE_LABEL
4106 #define SEPARATE_LINE_CODE_LABEL "LSM"
4109 /* We allow a language front-end to designate a function that is to be
4110 called to "demangle" any name before it it put into a DIE. */
4112 static const char *(*demangle_name_func
) (const char *);
4115 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
4117 demangle_name_func
= func
;
4120 /* Test if rtl node points to a pseudo register. */
4123 is_pseudo_reg (rtx rtl
)
4125 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
4126 || (GET_CODE (rtl
) == SUBREG
4127 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
4130 /* Return a reference to a type, with its const and volatile qualifiers
4134 type_main_variant (tree type
)
4136 type
= TYPE_MAIN_VARIANT (type
);
4138 /* ??? There really should be only one main variant among any group of
4139 variants of a given type (and all of the MAIN_VARIANT values for all
4140 members of the group should point to that one type) but sometimes the C
4141 front-end messes this up for array types, so we work around that bug
4143 if (TREE_CODE (type
) == ARRAY_TYPE
)
4144 while (type
!= TYPE_MAIN_VARIANT (type
))
4145 type
= TYPE_MAIN_VARIANT (type
);
4150 /* Return nonzero if the given type node represents a tagged type. */
4153 is_tagged_type (tree type
)
4155 enum tree_code code
= TREE_CODE (type
);
4157 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
4158 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
4161 /* Convert a DIE tag into its string name. */
4164 dwarf_tag_name (unsigned int tag
)
4168 case DW_TAG_padding
:
4169 return "DW_TAG_padding";
4170 case DW_TAG_array_type
:
4171 return "DW_TAG_array_type";
4172 case DW_TAG_class_type
:
4173 return "DW_TAG_class_type";
4174 case DW_TAG_entry_point
:
4175 return "DW_TAG_entry_point";
4176 case DW_TAG_enumeration_type
:
4177 return "DW_TAG_enumeration_type";
4178 case DW_TAG_formal_parameter
:
4179 return "DW_TAG_formal_parameter";
4180 case DW_TAG_imported_declaration
:
4181 return "DW_TAG_imported_declaration";
4183 return "DW_TAG_label";
4184 case DW_TAG_lexical_block
:
4185 return "DW_TAG_lexical_block";
4187 return "DW_TAG_member";
4188 case DW_TAG_pointer_type
:
4189 return "DW_TAG_pointer_type";
4190 case DW_TAG_reference_type
:
4191 return "DW_TAG_reference_type";
4192 case DW_TAG_compile_unit
:
4193 return "DW_TAG_compile_unit";
4194 case DW_TAG_string_type
:
4195 return "DW_TAG_string_type";
4196 case DW_TAG_structure_type
:
4197 return "DW_TAG_structure_type";
4198 case DW_TAG_subroutine_type
:
4199 return "DW_TAG_subroutine_type";
4200 case DW_TAG_typedef
:
4201 return "DW_TAG_typedef";
4202 case DW_TAG_union_type
:
4203 return "DW_TAG_union_type";
4204 case DW_TAG_unspecified_parameters
:
4205 return "DW_TAG_unspecified_parameters";
4206 case DW_TAG_variant
:
4207 return "DW_TAG_variant";
4208 case DW_TAG_common_block
:
4209 return "DW_TAG_common_block";
4210 case DW_TAG_common_inclusion
:
4211 return "DW_TAG_common_inclusion";
4212 case DW_TAG_inheritance
:
4213 return "DW_TAG_inheritance";
4214 case DW_TAG_inlined_subroutine
:
4215 return "DW_TAG_inlined_subroutine";
4217 return "DW_TAG_module";
4218 case DW_TAG_ptr_to_member_type
:
4219 return "DW_TAG_ptr_to_member_type";
4220 case DW_TAG_set_type
:
4221 return "DW_TAG_set_type";
4222 case DW_TAG_subrange_type
:
4223 return "DW_TAG_subrange_type";
4224 case DW_TAG_with_stmt
:
4225 return "DW_TAG_with_stmt";
4226 case DW_TAG_access_declaration
:
4227 return "DW_TAG_access_declaration";
4228 case DW_TAG_base_type
:
4229 return "DW_TAG_base_type";
4230 case DW_TAG_catch_block
:
4231 return "DW_TAG_catch_block";
4232 case DW_TAG_const_type
:
4233 return "DW_TAG_const_type";
4234 case DW_TAG_constant
:
4235 return "DW_TAG_constant";
4236 case DW_TAG_enumerator
:
4237 return "DW_TAG_enumerator";
4238 case DW_TAG_file_type
:
4239 return "DW_TAG_file_type";
4241 return "DW_TAG_friend";
4242 case DW_TAG_namelist
:
4243 return "DW_TAG_namelist";
4244 case DW_TAG_namelist_item
:
4245 return "DW_TAG_namelist_item";
4246 case DW_TAG_namespace
:
4247 return "DW_TAG_namespace";
4248 case DW_TAG_packed_type
:
4249 return "DW_TAG_packed_type";
4250 case DW_TAG_subprogram
:
4251 return "DW_TAG_subprogram";
4252 case DW_TAG_template_type_param
:
4253 return "DW_TAG_template_type_param";
4254 case DW_TAG_template_value_param
:
4255 return "DW_TAG_template_value_param";
4256 case DW_TAG_thrown_type
:
4257 return "DW_TAG_thrown_type";
4258 case DW_TAG_try_block
:
4259 return "DW_TAG_try_block";
4260 case DW_TAG_variant_part
:
4261 return "DW_TAG_variant_part";
4262 case DW_TAG_variable
:
4263 return "DW_TAG_variable";
4264 case DW_TAG_volatile_type
:
4265 return "DW_TAG_volatile_type";
4266 case DW_TAG_imported_module
:
4267 return "DW_TAG_imported_module";
4268 case DW_TAG_MIPS_loop
:
4269 return "DW_TAG_MIPS_loop";
4270 case DW_TAG_format_label
:
4271 return "DW_TAG_format_label";
4272 case DW_TAG_function_template
:
4273 return "DW_TAG_function_template";
4274 case DW_TAG_class_template
:
4275 return "DW_TAG_class_template";
4276 case DW_TAG_GNU_BINCL
:
4277 return "DW_TAG_GNU_BINCL";
4278 case DW_TAG_GNU_EINCL
:
4279 return "DW_TAG_GNU_EINCL";
4281 return "DW_TAG_<unknown>";
4285 /* Convert a DWARF attribute code into its string name. */
4288 dwarf_attr_name (unsigned int attr
)
4293 return "DW_AT_sibling";
4294 case DW_AT_location
:
4295 return "DW_AT_location";
4297 return "DW_AT_name";
4298 case DW_AT_ordering
:
4299 return "DW_AT_ordering";
4300 case DW_AT_subscr_data
:
4301 return "DW_AT_subscr_data";
4302 case DW_AT_byte_size
:
4303 return "DW_AT_byte_size";
4304 case DW_AT_bit_offset
:
4305 return "DW_AT_bit_offset";
4306 case DW_AT_bit_size
:
4307 return "DW_AT_bit_size";
4308 case DW_AT_element_list
:
4309 return "DW_AT_element_list";
4310 case DW_AT_stmt_list
:
4311 return "DW_AT_stmt_list";
4313 return "DW_AT_low_pc";
4315 return "DW_AT_high_pc";
4316 case DW_AT_language
:
4317 return "DW_AT_language";
4319 return "DW_AT_member";
4321 return "DW_AT_discr";
4322 case DW_AT_discr_value
:
4323 return "DW_AT_discr_value";
4324 case DW_AT_visibility
:
4325 return "DW_AT_visibility";
4327 return "DW_AT_import";
4328 case DW_AT_string_length
:
4329 return "DW_AT_string_length";
4330 case DW_AT_common_reference
:
4331 return "DW_AT_common_reference";
4332 case DW_AT_comp_dir
:
4333 return "DW_AT_comp_dir";
4334 case DW_AT_const_value
:
4335 return "DW_AT_const_value";
4336 case DW_AT_containing_type
:
4337 return "DW_AT_containing_type";
4338 case DW_AT_default_value
:
4339 return "DW_AT_default_value";
4341 return "DW_AT_inline";
4342 case DW_AT_is_optional
:
4343 return "DW_AT_is_optional";
4344 case DW_AT_lower_bound
:
4345 return "DW_AT_lower_bound";
4346 case DW_AT_producer
:
4347 return "DW_AT_producer";
4348 case DW_AT_prototyped
:
4349 return "DW_AT_prototyped";
4350 case DW_AT_return_addr
:
4351 return "DW_AT_return_addr";
4352 case DW_AT_start_scope
:
4353 return "DW_AT_start_scope";
4354 case DW_AT_stride_size
:
4355 return "DW_AT_stride_size";
4356 case DW_AT_upper_bound
:
4357 return "DW_AT_upper_bound";
4358 case DW_AT_abstract_origin
:
4359 return "DW_AT_abstract_origin";
4360 case DW_AT_accessibility
:
4361 return "DW_AT_accessibility";
4362 case DW_AT_address_class
:
4363 return "DW_AT_address_class";
4364 case DW_AT_artificial
:
4365 return "DW_AT_artificial";
4366 case DW_AT_base_types
:
4367 return "DW_AT_base_types";
4368 case DW_AT_calling_convention
:
4369 return "DW_AT_calling_convention";
4371 return "DW_AT_count";
4372 case DW_AT_data_member_location
:
4373 return "DW_AT_data_member_location";
4374 case DW_AT_decl_column
:
4375 return "DW_AT_decl_column";
4376 case DW_AT_decl_file
:
4377 return "DW_AT_decl_file";
4378 case DW_AT_decl_line
:
4379 return "DW_AT_decl_line";
4380 case DW_AT_declaration
:
4381 return "DW_AT_declaration";
4382 case DW_AT_discr_list
:
4383 return "DW_AT_discr_list";
4384 case DW_AT_encoding
:
4385 return "DW_AT_encoding";
4386 case DW_AT_external
:
4387 return "DW_AT_external";
4388 case DW_AT_frame_base
:
4389 return "DW_AT_frame_base";
4391 return "DW_AT_friend";
4392 case DW_AT_identifier_case
:
4393 return "DW_AT_identifier_case";
4394 case DW_AT_macro_info
:
4395 return "DW_AT_macro_info";
4396 case DW_AT_namelist_items
:
4397 return "DW_AT_namelist_items";
4398 case DW_AT_priority
:
4399 return "DW_AT_priority";
4401 return "DW_AT_segment";
4402 case DW_AT_specification
:
4403 return "DW_AT_specification";
4404 case DW_AT_static_link
:
4405 return "DW_AT_static_link";
4407 return "DW_AT_type";
4408 case DW_AT_use_location
:
4409 return "DW_AT_use_location";
4410 case DW_AT_variable_parameter
:
4411 return "DW_AT_variable_parameter";
4412 case DW_AT_virtuality
:
4413 return "DW_AT_virtuality";
4414 case DW_AT_vtable_elem_location
:
4415 return "DW_AT_vtable_elem_location";
4417 case DW_AT_allocated
:
4418 return "DW_AT_allocated";
4419 case DW_AT_associated
:
4420 return "DW_AT_associated";
4421 case DW_AT_data_location
:
4422 return "DW_AT_data_location";
4424 return "DW_AT_stride";
4425 case DW_AT_entry_pc
:
4426 return "DW_AT_entry_pc";
4427 case DW_AT_use_UTF8
:
4428 return "DW_AT_use_UTF8";
4429 case DW_AT_extension
:
4430 return "DW_AT_extension";
4432 return "DW_AT_ranges";
4433 case DW_AT_trampoline
:
4434 return "DW_AT_trampoline";
4435 case DW_AT_call_column
:
4436 return "DW_AT_call_column";
4437 case DW_AT_call_file
:
4438 return "DW_AT_call_file";
4439 case DW_AT_call_line
:
4440 return "DW_AT_call_line";
4442 case DW_AT_MIPS_fde
:
4443 return "DW_AT_MIPS_fde";
4444 case DW_AT_MIPS_loop_begin
:
4445 return "DW_AT_MIPS_loop_begin";
4446 case DW_AT_MIPS_tail_loop_begin
:
4447 return "DW_AT_MIPS_tail_loop_begin";
4448 case DW_AT_MIPS_epilog_begin
:
4449 return "DW_AT_MIPS_epilog_begin";
4450 case DW_AT_MIPS_loop_unroll_factor
:
4451 return "DW_AT_MIPS_loop_unroll_factor";
4452 case DW_AT_MIPS_software_pipeline_depth
:
4453 return "DW_AT_MIPS_software_pipeline_depth";
4454 case DW_AT_MIPS_linkage_name
:
4455 return "DW_AT_MIPS_linkage_name";
4456 case DW_AT_MIPS_stride
:
4457 return "DW_AT_MIPS_stride";
4458 case DW_AT_MIPS_abstract_name
:
4459 return "DW_AT_MIPS_abstract_name";
4460 case DW_AT_MIPS_clone_origin
:
4461 return "DW_AT_MIPS_clone_origin";
4462 case DW_AT_MIPS_has_inlines
:
4463 return "DW_AT_MIPS_has_inlines";
4465 case DW_AT_sf_names
:
4466 return "DW_AT_sf_names";
4467 case DW_AT_src_info
:
4468 return "DW_AT_src_info";
4469 case DW_AT_mac_info
:
4470 return "DW_AT_mac_info";
4471 case DW_AT_src_coords
:
4472 return "DW_AT_src_coords";
4473 case DW_AT_body_begin
:
4474 return "DW_AT_body_begin";
4475 case DW_AT_body_end
:
4476 return "DW_AT_body_end";
4477 case DW_AT_GNU_vector
:
4478 return "DW_AT_GNU_vector";
4480 case DW_AT_VMS_rtnbeg_pd_address
:
4481 return "DW_AT_VMS_rtnbeg_pd_address";
4484 return "DW_AT_<unknown>";
4488 /* Convert a DWARF value form code into its string name. */
4491 dwarf_form_name (unsigned int form
)
4496 return "DW_FORM_addr";
4497 case DW_FORM_block2
:
4498 return "DW_FORM_block2";
4499 case DW_FORM_block4
:
4500 return "DW_FORM_block4";
4502 return "DW_FORM_data2";
4504 return "DW_FORM_data4";
4506 return "DW_FORM_data8";
4507 case DW_FORM_string
:
4508 return "DW_FORM_string";
4510 return "DW_FORM_block";
4511 case DW_FORM_block1
:
4512 return "DW_FORM_block1";
4514 return "DW_FORM_data1";
4516 return "DW_FORM_flag";
4518 return "DW_FORM_sdata";
4520 return "DW_FORM_strp";
4522 return "DW_FORM_udata";
4523 case DW_FORM_ref_addr
:
4524 return "DW_FORM_ref_addr";
4526 return "DW_FORM_ref1";
4528 return "DW_FORM_ref2";
4530 return "DW_FORM_ref4";
4532 return "DW_FORM_ref8";
4533 case DW_FORM_ref_udata
:
4534 return "DW_FORM_ref_udata";
4535 case DW_FORM_indirect
:
4536 return "DW_FORM_indirect";
4538 return "DW_FORM_<unknown>";
4542 /* Convert a DWARF type code into its string name. */
4546 dwarf_type_encoding_name (unsigned enc
)
4550 case DW_ATE_address
:
4551 return "DW_ATE_address";
4552 case DW_ATE_boolean
:
4553 return "DW_ATE_boolean";
4554 case DW_ATE_complex_float
:
4555 return "DW_ATE_complex_float";
4557 return "DW_ATE_float";
4559 return "DW_ATE_signed";
4560 case DW_ATE_signed_char
:
4561 return "DW_ATE_signed_char";
4562 case DW_ATE_unsigned
:
4563 return "DW_ATE_unsigned";
4564 case DW_ATE_unsigned_char
:
4565 return "DW_ATE_unsigned_char";
4567 return "DW_ATE_<unknown>";
4572 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4573 instance of an inlined instance of a decl which is local to an inline
4574 function, so we have to trace all of the way back through the origin chain
4575 to find out what sort of node actually served as the original seed for the
4579 decl_ultimate_origin (tree decl
)
4581 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4582 nodes in the function to point to themselves; ignore that if
4583 we're trying to output the abstract instance of this function. */
4584 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
4587 #ifdef ENABLE_CHECKING
4588 if (DECL_FROM_INLINE (DECL_ORIGIN (decl
)))
4589 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4590 most distant ancestor, this should never happen. */
4594 return DECL_ABSTRACT_ORIGIN (decl
);
4597 /* Determine the "ultimate origin" of a block. The block may be an inlined
4598 instance of an inlined instance of a block which is local to an inline
4599 function, so we have to trace all of the way back through the origin chain
4600 to find out what sort of node actually served as the original seed for the
4604 block_ultimate_origin (tree block
)
4606 tree immediate_origin
= BLOCK_ABSTRACT_ORIGIN (block
);
4608 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4609 nodes in the function to point to themselves; ignore that if
4610 we're trying to output the abstract instance of this function. */
4611 if (BLOCK_ABSTRACT (block
) && immediate_origin
== block
)
4614 if (immediate_origin
== NULL_TREE
)
4619 tree lookahead
= immediate_origin
;
4623 ret_val
= lookahead
;
4624 lookahead
= (TREE_CODE (ret_val
) == BLOCK
4625 ? BLOCK_ABSTRACT_ORIGIN (ret_val
) : NULL
);
4627 while (lookahead
!= NULL
&& lookahead
!= ret_val
);
4633 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4634 of a virtual function may refer to a base class, so we check the 'this'
4638 decl_class_context (tree decl
)
4640 tree context
= NULL_TREE
;
4642 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
4643 context
= DECL_CONTEXT (decl
);
4645 context
= TYPE_MAIN_VARIANT
4646 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
4648 if (context
&& !TYPE_P (context
))
4649 context
= NULL_TREE
;
4654 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4655 addition order, and correct that in reverse_all_dies. */
4658 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
4660 if (die
!= NULL
&& attr
!= NULL
)
4662 attr
->dw_attr_next
= die
->die_attr
;
4663 die
->die_attr
= attr
;
4667 static inline enum dw_val_class
4668 AT_class (dw_attr_ref a
)
4670 return a
->dw_attr_val
.val_class
;
4673 /* Add a flag value attribute to a DIE. */
4676 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
4678 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4680 attr
->dw_attr_next
= NULL
;
4681 attr
->dw_attr
= attr_kind
;
4682 attr
->dw_attr_val
.val_class
= dw_val_class_flag
;
4683 attr
->dw_attr_val
.v
.val_flag
= flag
;
4684 add_dwarf_attr (die
, attr
);
4687 static inline unsigned
4688 AT_flag (dw_attr_ref a
)
4690 if (a
&& AT_class (a
) == dw_val_class_flag
)
4691 return a
->dw_attr_val
.v
.val_flag
;
4696 /* Add a signed integer attribute value to a DIE. */
4699 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
4701 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4703 attr
->dw_attr_next
= NULL
;
4704 attr
->dw_attr
= attr_kind
;
4705 attr
->dw_attr_val
.val_class
= dw_val_class_const
;
4706 attr
->dw_attr_val
.v
.val_int
= int_val
;
4707 add_dwarf_attr (die
, attr
);
4710 static inline HOST_WIDE_INT
4711 AT_int (dw_attr_ref a
)
4713 if (a
&& AT_class (a
) == dw_val_class_const
)
4714 return a
->dw_attr_val
.v
.val_int
;
4719 /* Add an unsigned integer attribute value to a DIE. */
4722 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4723 unsigned HOST_WIDE_INT unsigned_val
)
4725 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4727 attr
->dw_attr_next
= NULL
;
4728 attr
->dw_attr
= attr_kind
;
4729 attr
->dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
4730 attr
->dw_attr_val
.v
.val_unsigned
= unsigned_val
;
4731 add_dwarf_attr (die
, attr
);
4734 static inline unsigned HOST_WIDE_INT
4735 AT_unsigned (dw_attr_ref a
)
4737 if (a
&& AT_class (a
) == dw_val_class_unsigned_const
)
4738 return a
->dw_attr_val
.v
.val_unsigned
;
4743 /* Add an unsigned double integer attribute value to a DIE. */
4746 add_AT_long_long (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4747 long unsigned int val_hi
, long unsigned int val_low
)
4749 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4751 attr
->dw_attr_next
= NULL
;
4752 attr
->dw_attr
= attr_kind
;
4753 attr
->dw_attr_val
.val_class
= dw_val_class_long_long
;
4754 attr
->dw_attr_val
.v
.val_long_long
.hi
= val_hi
;
4755 attr
->dw_attr_val
.v
.val_long_long
.low
= val_low
;
4756 add_dwarf_attr (die
, attr
);
4759 /* Add a floating point attribute value to a DIE and return it. */
4762 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4763 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4765 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4767 attr
->dw_attr_next
= NULL
;
4768 attr
->dw_attr
= attr_kind
;
4769 attr
->dw_attr_val
.val_class
= dw_val_class_vec
;
4770 attr
->dw_attr_val
.v
.val_vec
.length
= length
;
4771 attr
->dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4772 attr
->dw_attr_val
.v
.val_vec
.array
= array
;
4773 add_dwarf_attr (die
, attr
);
4776 /* Hash and equality functions for debug_str_hash. */
4779 debug_str_do_hash (const void *x
)
4781 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
4785 debug_str_eq (const void *x1
, const void *x2
)
4787 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
4788 (const char *)x2
) == 0;
4791 /* Add a string attribute value to a DIE. */
4794 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4796 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4797 struct indirect_string_node
*node
;
4800 if (! debug_str_hash
)
4801 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
4802 debug_str_eq
, NULL
);
4804 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
4805 htab_hash_string (str
), INSERT
);
4807 *slot
= ggc_alloc_cleared (sizeof (struct indirect_string_node
));
4808 node
= (struct indirect_string_node
*) *slot
;
4809 node
->str
= ggc_strdup (str
);
4812 attr
->dw_attr_next
= NULL
;
4813 attr
->dw_attr
= attr_kind
;
4814 attr
->dw_attr_val
.val_class
= dw_val_class_str
;
4815 attr
->dw_attr_val
.v
.val_str
= node
;
4816 add_dwarf_attr (die
, attr
);
4819 static inline const char *
4820 AT_string (dw_attr_ref a
)
4822 if (a
&& AT_class (a
) == dw_val_class_str
)
4823 return a
->dw_attr_val
.v
.val_str
->str
;
4828 /* Find out whether a string should be output inline in DIE
4829 or out-of-line in .debug_str section. */
4832 AT_string_form (dw_attr_ref a
)
4834 if (a
&& AT_class (a
) == dw_val_class_str
)
4836 struct indirect_string_node
*node
;
4840 node
= a
->dw_attr_val
.v
.val_str
;
4844 len
= strlen (node
->str
) + 1;
4846 /* If the string is shorter or equal to the size of the reference, it is
4847 always better to put it inline. */
4848 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4849 return node
->form
= DW_FORM_string
;
4851 /* If we cannot expect the linker to merge strings in .debug_str
4852 section, only put it into .debug_str if it is worth even in this
4854 if ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) == 0
4855 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
)
4856 return node
->form
= DW_FORM_string
;
4858 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4859 ++dw2_string_counter
;
4860 node
->label
= xstrdup (label
);
4862 return node
->form
= DW_FORM_strp
;
4868 /* Add a DIE reference attribute value to a DIE. */
4871 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4873 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4875 attr
->dw_attr_next
= NULL
;
4876 attr
->dw_attr
= attr_kind
;
4877 attr
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
4878 attr
->dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4879 attr
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4880 add_dwarf_attr (die
, attr
);
4883 /* Add an AT_specification attribute to a DIE, and also make the back
4884 pointer from the specification to the definition. */
4887 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4889 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4890 if (targ_die
->die_definition
)
4892 targ_die
->die_definition
= die
;
4895 static inline dw_die_ref
4896 AT_ref (dw_attr_ref a
)
4898 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4899 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4905 AT_ref_external (dw_attr_ref a
)
4907 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4908 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4914 set_AT_ref_external (dw_attr_ref a
, int i
)
4916 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4917 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4922 /* Add an FDE reference attribute value to a DIE. */
4925 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4927 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4929 attr
->dw_attr_next
= NULL
;
4930 attr
->dw_attr
= attr_kind
;
4931 attr
->dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4932 attr
->dw_attr_val
.v
.val_fde_index
= targ_fde
;
4933 add_dwarf_attr (die
, attr
);
4936 /* Add a location description attribute value to a DIE. */
4939 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4941 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4943 attr
->dw_attr_next
= NULL
;
4944 attr
->dw_attr
= attr_kind
;
4945 attr
->dw_attr_val
.val_class
= dw_val_class_loc
;
4946 attr
->dw_attr_val
.v
.val_loc
= loc
;
4947 add_dwarf_attr (die
, attr
);
4950 static inline dw_loc_descr_ref
4951 AT_loc (dw_attr_ref a
)
4953 if (a
&& AT_class (a
) == dw_val_class_loc
)
4954 return a
->dw_attr_val
.v
.val_loc
;
4960 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4962 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4964 attr
->dw_attr_next
= NULL
;
4965 attr
->dw_attr
= attr_kind
;
4966 attr
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
4967 attr
->dw_attr_val
.v
.val_loc_list
= loc_list
;
4968 add_dwarf_attr (die
, attr
);
4969 have_location_lists
= 1;
4972 static inline dw_loc_list_ref
4973 AT_loc_list (dw_attr_ref a
)
4975 if (a
&& AT_class (a
) == dw_val_class_loc_list
)
4976 return a
->dw_attr_val
.v
.val_loc_list
;
4981 /* Add an address constant attribute value to a DIE. */
4984 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
)
4986 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
4988 attr
->dw_attr_next
= NULL
;
4989 attr
->dw_attr
= attr_kind
;
4990 attr
->dw_attr_val
.val_class
= dw_val_class_addr
;
4991 attr
->dw_attr_val
.v
.val_addr
= addr
;
4992 add_dwarf_attr (die
, attr
);
4996 AT_addr (dw_attr_ref a
)
4998 if (a
&& AT_class (a
) == dw_val_class_addr
)
4999 return a
->dw_attr_val
.v
.val_addr
;
5004 /* Add a label identifier attribute value to a DIE. */
5007 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *lbl_id
)
5009 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5011 attr
->dw_attr_next
= NULL
;
5012 attr
->dw_attr
= attr_kind
;
5013 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_id
;
5014 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
5015 add_dwarf_attr (die
, attr
);
5018 /* Add a section offset attribute value to a DIE. */
5021 add_AT_lbl_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *label
)
5023 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5025 attr
->dw_attr_next
= NULL
;
5026 attr
->dw_attr
= attr_kind
;
5027 attr
->dw_attr_val
.val_class
= dw_val_class_lbl_offset
;
5028 attr
->dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
5029 add_dwarf_attr (die
, attr
);
5032 /* Add an offset attribute value to a DIE. */
5035 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5036 unsigned HOST_WIDE_INT offset
)
5038 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5040 attr
->dw_attr_next
= NULL
;
5041 attr
->dw_attr
= attr_kind
;
5042 attr
->dw_attr_val
.val_class
= dw_val_class_offset
;
5043 attr
->dw_attr_val
.v
.val_offset
= offset
;
5044 add_dwarf_attr (die
, attr
);
5047 /* Add an range_list attribute value to a DIE. */
5050 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
5051 long unsigned int offset
)
5053 dw_attr_ref attr
= ggc_alloc (sizeof (dw_attr_node
));
5055 attr
->dw_attr_next
= NULL
;
5056 attr
->dw_attr
= attr_kind
;
5057 attr
->dw_attr_val
.val_class
= dw_val_class_range_list
;
5058 attr
->dw_attr_val
.v
.val_offset
= offset
;
5059 add_dwarf_attr (die
, attr
);
5062 static inline const char *
5063 AT_lbl (dw_attr_ref a
)
5065 if (a
&& (AT_class (a
) == dw_val_class_lbl_id
5066 || AT_class (a
) == dw_val_class_lbl_offset
))
5067 return a
->dw_attr_val
.v
.val_lbl_id
;
5072 /* Get the attribute of type attr_kind. */
5075 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5078 dw_die_ref spec
= NULL
;
5082 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5083 if (a
->dw_attr
== attr_kind
)
5085 else if (a
->dw_attr
== DW_AT_specification
5086 || a
->dw_attr
== DW_AT_abstract_origin
)
5090 return get_AT (spec
, attr_kind
);
5096 /* Return the "low pc" attribute value, typically associated with a subprogram
5097 DIE. Return null if the "low pc" attribute is either not present, or if it
5098 cannot be represented as an assembler label identifier. */
5100 static inline const char *
5101 get_AT_low_pc (dw_die_ref die
)
5103 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
5105 return a
? AT_lbl (a
) : NULL
;
5108 /* Return the "high pc" attribute value, typically associated with a subprogram
5109 DIE. Return null if the "high pc" attribute is either not present, or if it
5110 cannot be represented as an assembler label identifier. */
5112 static inline const char *
5113 get_AT_hi_pc (dw_die_ref die
)
5115 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
5117 return a
? AT_lbl (a
) : NULL
;
5120 /* Return the value of the string attribute designated by ATTR_KIND, or
5121 NULL if it is not present. */
5123 static inline const char *
5124 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5126 dw_attr_ref a
= get_AT (die
, attr_kind
);
5128 return a
? AT_string (a
) : NULL
;
5131 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5132 if it is not present. */
5135 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5137 dw_attr_ref a
= get_AT (die
, attr_kind
);
5139 return a
? AT_flag (a
) : 0;
5142 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5143 if it is not present. */
5145 static inline unsigned
5146 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5148 dw_attr_ref a
= get_AT (die
, attr_kind
);
5150 return a
? AT_unsigned (a
) : 0;
5153 static inline dw_die_ref
5154 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5156 dw_attr_ref a
= get_AT (die
, attr_kind
);
5158 return a
? AT_ref (a
) : NULL
;
5161 /* Return TRUE if the language is C or C++. */
5166 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5168 return (lang
== DW_LANG_C
|| lang
== DW_LANG_C89
5169 || lang
== DW_LANG_C_plus_plus
);
5172 /* Return TRUE if the language is C++. */
5177 return (get_AT_unsigned (comp_unit_die
, DW_AT_language
)
5178 == DW_LANG_C_plus_plus
);
5181 /* Return TRUE if the language is Fortran. */
5186 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5188 return (lang
== DW_LANG_Fortran77
5189 || lang
== DW_LANG_Fortran90
5190 || lang
== DW_LANG_Fortran95
);
5193 /* Return TRUE if the language is Java. */
5198 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5200 return lang
== DW_LANG_Java
;
5203 /* Return TRUE if the language is Ada. */
5208 unsigned int lang
= get_AT_unsigned (comp_unit_die
, DW_AT_language
);
5210 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
5213 /* Free up the memory used by A. */
5215 static inline void free_AT (dw_attr_ref
);
5217 free_AT (dw_attr_ref a
)
5219 if (AT_class (a
) == dw_val_class_str
)
5220 if (a
->dw_attr_val
.v
.val_str
->refcount
)
5221 a
->dw_attr_val
.v
.val_str
->refcount
--;
5224 /* Remove the specified attribute if present. */
5227 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
5230 dw_attr_ref removed
= NULL
;
5234 for (p
= &(die
->die_attr
); *p
; p
= &((*p
)->dw_attr_next
))
5235 if ((*p
)->dw_attr
== attr_kind
)
5238 *p
= (*p
)->dw_attr_next
;
5247 /* Remove child die whose die_tag is specified tag. */
5250 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
5252 dw_die_ref current
, prev
, next
;
5253 current
= die
->die_child
;
5255 while (current
!= NULL
)
5257 if (current
->die_tag
== tag
)
5259 next
= current
->die_sib
;
5261 die
->die_child
= next
;
5263 prev
->die_sib
= next
;
5270 current
= current
->die_sib
;
5275 /* Free up the memory used by DIE. */
5278 free_die (dw_die_ref die
)
5280 remove_children (die
);
5283 /* Discard the children of this DIE. */
5286 remove_children (dw_die_ref die
)
5288 dw_die_ref child_die
= die
->die_child
;
5290 die
->die_child
= NULL
;
5292 while (child_die
!= NULL
)
5294 dw_die_ref tmp_die
= child_die
;
5297 child_die
= child_die
->die_sib
;
5299 for (a
= tmp_die
->die_attr
; a
!= NULL
;)
5301 dw_attr_ref tmp_a
= a
;
5303 a
= a
->dw_attr_next
;
5311 /* Add a child DIE below its parent. We build the lists up in reverse
5312 addition order, and correct that in reverse_all_dies. */
5315 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
5317 if (die
!= NULL
&& child_die
!= NULL
)
5319 if (die
== child_die
)
5322 child_die
->die_parent
= die
;
5323 child_die
->die_sib
= die
->die_child
;
5324 die
->die_child
= child_die
;
5328 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5329 is the specification, to the front of PARENT's list of children. */
5332 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5336 /* We want the declaration DIE from inside the class, not the
5337 specification DIE at toplevel. */
5338 if (child
->die_parent
!= parent
)
5340 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5346 if (child
->die_parent
!= parent
5347 && child
->die_parent
!= get_AT_ref (parent
, DW_AT_specification
))
5350 for (p
= &(child
->die_parent
->die_child
); *p
; p
= &((*p
)->die_sib
))
5353 *p
= child
->die_sib
;
5357 child
->die_parent
= parent
;
5358 child
->die_sib
= parent
->die_child
;
5359 parent
->die_child
= child
;
5362 /* Return a pointer to a newly created DIE node. */
5364 static inline dw_die_ref
5365 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5367 dw_die_ref die
= ggc_alloc_cleared (sizeof (die_node
));
5369 die
->die_tag
= tag_value
;
5371 if (parent_die
!= NULL
)
5372 add_child_die (parent_die
, die
);
5375 limbo_die_node
*limbo_node
;
5377 limbo_node
= ggc_alloc_cleared (sizeof (limbo_die_node
));
5378 limbo_node
->die
= die
;
5379 limbo_node
->created_for
= t
;
5380 limbo_node
->next
= limbo_die_list
;
5381 limbo_die_list
= limbo_node
;
5387 /* Return the DIE associated with the given type specifier. */
5389 static inline dw_die_ref
5390 lookup_type_die (tree type
)
5392 return TYPE_SYMTAB_DIE (type
);
5395 /* Equate a DIE to a given type specifier. */
5398 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5400 TYPE_SYMTAB_DIE (type
) = type_die
;
5403 /* Returns a hash value for X (which really is a die_struct). */
5406 decl_die_table_hash (const void *x
)
5408 return (hashval_t
) ((const dw_die_ref
) x
)->decl_id
;
5411 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5414 decl_die_table_eq (const void *x
, const void *y
)
5416 return (((const dw_die_ref
) x
)->decl_id
== DECL_UID ((const tree
) y
));
5419 /* Return the DIE associated with a given declaration. */
5421 static inline dw_die_ref
5422 lookup_decl_die (tree decl
)
5424 return htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
5427 /* Returns a hash value for X (which really is a var_loc_list). */
5430 decl_loc_table_hash (const void *x
)
5432 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
5435 /* Return nonzero if decl_id of var_loc_list X is the same as
5439 decl_loc_table_eq (const void *x
, const void *y
)
5441 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const tree
) y
));
5444 /* Return the var_loc list associated with a given declaration. */
5446 static inline var_loc_list
*
5447 lookup_decl_loc (tree decl
)
5449 return htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
5452 /* Equate a DIE to a particular declaration. */
5455 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5457 unsigned int decl_id
= DECL_UID (decl
);
5460 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
5462 decl_die
->decl_id
= decl_id
;
5465 /* Add a variable location node to the linked list for DECL. */
5468 add_var_loc_to_decl (tree decl
, struct var_loc_node
*loc
)
5470 unsigned int decl_id
= DECL_UID (decl
);
5474 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5477 temp
= ggc_alloc_cleared (sizeof (var_loc_list
));
5478 temp
->decl_id
= decl_id
;
5486 /* If the current location is the same as the end of the list,
5487 we have nothing to do. */
5488 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->last
->var_loc_note
),
5489 NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
)))
5491 /* Add LOC to the end of list and update LAST. */
5492 temp
->last
->next
= loc
;
5496 /* Do not add empty location to the beginning of the list. */
5497 else if (NOTE_VAR_LOCATION_LOC (loc
->var_loc_note
) != NULL_RTX
)
5504 /* Keep track of the number of spaces used to indent the
5505 output of the debugging routines that print the structure of
5506 the DIE internal representation. */
5507 static int print_indent
;
5509 /* Indent the line the number of spaces given by print_indent. */
5512 print_spaces (FILE *outfile
)
5514 fprintf (outfile
, "%*s", print_indent
, "");
5517 /* Print the information associated with a given DIE, and its children.
5518 This routine is a debugging aid only. */
5521 print_die (dw_die_ref die
, FILE *outfile
)
5526 print_spaces (outfile
);
5527 fprintf (outfile
, "DIE %4lu: %s\n",
5528 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
5529 print_spaces (outfile
);
5530 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5531 fprintf (outfile
, " offset: %lu\n", die
->die_offset
);
5533 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
5535 print_spaces (outfile
);
5536 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5538 switch (AT_class (a
))
5540 case dw_val_class_addr
:
5541 fprintf (outfile
, "address");
5543 case dw_val_class_offset
:
5544 fprintf (outfile
, "offset");
5546 case dw_val_class_loc
:
5547 fprintf (outfile
, "location descriptor");
5549 case dw_val_class_loc_list
:
5550 fprintf (outfile
, "location list -> label:%s",
5551 AT_loc_list (a
)->ll_symbol
);
5553 case dw_val_class_range_list
:
5554 fprintf (outfile
, "range list");
5556 case dw_val_class_const
:
5557 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5559 case dw_val_class_unsigned_const
:
5560 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5562 case dw_val_class_long_long
:
5563 fprintf (outfile
, "constant (%lu,%lu)",
5564 a
->dw_attr_val
.v
.val_long_long
.hi
,
5565 a
->dw_attr_val
.v
.val_long_long
.low
);
5567 case dw_val_class_vec
:
5568 fprintf (outfile
, "floating-point or vector constant");
5570 case dw_val_class_flag
:
5571 fprintf (outfile
, "%u", AT_flag (a
));
5573 case dw_val_class_die_ref
:
5574 if (AT_ref (a
) != NULL
)
5576 if (AT_ref (a
)->die_symbol
)
5577 fprintf (outfile
, "die -> label: %s", AT_ref (a
)->die_symbol
);
5579 fprintf (outfile
, "die -> %lu", AT_ref (a
)->die_offset
);
5582 fprintf (outfile
, "die -> <null>");
5584 case dw_val_class_lbl_id
:
5585 case dw_val_class_lbl_offset
:
5586 fprintf (outfile
, "label: %s", AT_lbl (a
));
5588 case dw_val_class_str
:
5589 if (AT_string (a
) != NULL
)
5590 fprintf (outfile
, "\"%s\"", AT_string (a
));
5592 fprintf (outfile
, "<null>");
5598 fprintf (outfile
, "\n");
5601 if (die
->die_child
!= NULL
)
5604 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
5605 print_die (c
, outfile
);
5609 if (print_indent
== 0)
5610 fprintf (outfile
, "\n");
5613 /* Print the contents of the source code line number correspondence table.
5614 This routine is a debugging aid only. */
5617 print_dwarf_line_table (FILE *outfile
)
5620 dw_line_info_ref line_info
;
5622 fprintf (outfile
, "\n\nDWARF source line information\n");
5623 for (i
= 1; i
< line_info_table_in_use
; i
++)
5625 line_info
= &line_info_table
[i
];
5626 fprintf (outfile
, "%5d: ", i
);
5627 fprintf (outfile
, "%-20s",
5628 VARRAY_CHAR_PTR (file_table
, line_info
->dw_file_num
));
5629 fprintf (outfile
, "%6ld", line_info
->dw_line_num
);
5630 fprintf (outfile
, "\n");
5633 fprintf (outfile
, "\n\n");
5636 /* Print the information collected for a given DIE. */
5639 debug_dwarf_die (dw_die_ref die
)
5641 print_die (die
, stderr
);
5644 /* Print all DWARF information collected for the compilation unit.
5645 This routine is a debugging aid only. */
5651 print_die (comp_unit_die
, stderr
);
5652 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
5653 print_dwarf_line_table (stderr
);
5656 /* We build up the lists of children and attributes by pushing new ones
5657 onto the beginning of the list. Reverse the lists for DIE so that
5658 they are in order of addition. */
5661 reverse_die_lists (dw_die_ref die
)
5663 dw_die_ref c
, cp
, cn
;
5664 dw_attr_ref a
, ap
, an
;
5666 for (a
= die
->die_attr
, ap
= 0; a
; a
= an
)
5668 an
= a
->dw_attr_next
;
5669 a
->dw_attr_next
= ap
;
5675 for (c
= die
->die_child
, cp
= 0; c
; c
= cn
)
5682 die
->die_child
= cp
;
5685 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5686 reverse all dies in add_sibling_attributes, which runs through all the dies,
5687 it would reverse all the dies. Now, however, since we don't call
5688 reverse_die_lists in add_sibling_attributes, we need a routine to
5689 recursively reverse all the dies. This is that routine. */
5692 reverse_all_dies (dw_die_ref die
)
5696 reverse_die_lists (die
);
5698 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5699 reverse_all_dies (c
);
5702 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5703 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5704 DIE that marks the start of the DIEs for this include file. */
5707 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5709 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5710 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5712 new_unit
->die_sib
= old_unit
;
5716 /* Close an include-file CU and reopen the enclosing one. */
5719 pop_compile_unit (dw_die_ref old_unit
)
5721 dw_die_ref new_unit
= old_unit
->die_sib
;
5723 old_unit
->die_sib
= NULL
;
5727 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5728 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5730 /* Calculate the checksum of a location expression. */
5733 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5735 CHECKSUM (loc
->dw_loc_opc
);
5736 CHECKSUM (loc
->dw_loc_oprnd1
);
5737 CHECKSUM (loc
->dw_loc_oprnd2
);
5740 /* Calculate the checksum of an attribute. */
5743 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5745 dw_loc_descr_ref loc
;
5748 CHECKSUM (at
->dw_attr
);
5750 /* We don't care about differences in file numbering. */
5751 if (at
->dw_attr
== DW_AT_decl_file
5752 /* Or that this was compiled with a different compiler snapshot; if
5753 the output is the same, that's what matters. */
5754 || at
->dw_attr
== DW_AT_producer
)
5757 switch (AT_class (at
))
5759 case dw_val_class_const
:
5760 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5762 case dw_val_class_unsigned_const
:
5763 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5765 case dw_val_class_long_long
:
5766 CHECKSUM (at
->dw_attr_val
.v
.val_long_long
);
5768 case dw_val_class_vec
:
5769 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5771 case dw_val_class_flag
:
5772 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5774 case dw_val_class_str
:
5775 CHECKSUM_STRING (AT_string (at
));
5778 case dw_val_class_addr
:
5780 switch (GET_CODE (r
))
5783 CHECKSUM_STRING (XSTR (r
, 0));
5791 case dw_val_class_offset
:
5792 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5795 case dw_val_class_loc
:
5796 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5797 loc_checksum (loc
, ctx
);
5800 case dw_val_class_die_ref
:
5801 die_checksum (AT_ref (at
), ctx
, mark
);
5804 case dw_val_class_fde_ref
:
5805 case dw_val_class_lbl_id
:
5806 case dw_val_class_lbl_offset
:
5814 /* Calculate the checksum of a DIE. */
5817 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5822 /* To avoid infinite recursion. */
5825 CHECKSUM (die
->die_mark
);
5828 die
->die_mark
= ++(*mark
);
5830 CHECKSUM (die
->die_tag
);
5832 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
5833 attr_checksum (a
, ctx
, mark
);
5835 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
5836 die_checksum (c
, ctx
, mark
);
5840 #undef CHECKSUM_STRING
5842 /* Do the location expressions look same? */
5844 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
5846 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
5847 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
5848 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
5851 /* Do the values look the same? */
5853 same_dw_val_p (dw_val_node
*v1
, dw_val_node
*v2
, int *mark
)
5855 dw_loc_descr_ref loc1
, loc2
;
5858 if (v1
->val_class
!= v2
->val_class
)
5861 switch (v1
->val_class
)
5863 case dw_val_class_const
:
5864 return v1
->v
.val_int
== v2
->v
.val_int
;
5865 case dw_val_class_unsigned_const
:
5866 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
5867 case dw_val_class_long_long
:
5868 return v1
->v
.val_long_long
.hi
== v2
->v
.val_long_long
.hi
5869 && v1
->v
.val_long_long
.low
== v2
->v
.val_long_long
.low
;
5870 case dw_val_class_vec
:
5871 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
5872 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
5874 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
5875 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
5878 case dw_val_class_flag
:
5879 return v1
->v
.val_flag
== v2
->v
.val_flag
;
5880 case dw_val_class_str
:
5881 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
5883 case dw_val_class_addr
:
5884 r1
= v1
->v
.val_addr
;
5885 r2
= v2
->v
.val_addr
;
5886 if (GET_CODE (r1
) != GET_CODE (r2
))
5888 switch (GET_CODE (r1
))
5891 return !strcmp (XSTR (r1
, 0), XSTR (r2
, 0));
5897 case dw_val_class_offset
:
5898 return v1
->v
.val_offset
== v2
->v
.val_offset
;
5900 case dw_val_class_loc
:
5901 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
5903 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
5904 if (!same_loc_p (loc1
, loc2
, mark
))
5906 return !loc1
&& !loc2
;
5908 case dw_val_class_die_ref
:
5909 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
5911 case dw_val_class_fde_ref
:
5912 case dw_val_class_lbl_id
:
5913 case dw_val_class_lbl_offset
:
5921 /* Do the attributes look the same? */
5924 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
5926 if (at1
->dw_attr
!= at2
->dw_attr
)
5929 /* We don't care about differences in file numbering. */
5930 if (at1
->dw_attr
== DW_AT_decl_file
5931 /* Or that this was compiled with a different compiler snapshot; if
5932 the output is the same, that's what matters. */
5933 || at1
->dw_attr
== DW_AT_producer
)
5936 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
5939 /* Do the dies look the same? */
5942 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
5947 /* To avoid infinite recursion. */
5949 return die1
->die_mark
== die2
->die_mark
;
5950 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
5952 if (die1
->die_tag
!= die2
->die_tag
)
5955 for (a1
= die1
->die_attr
, a2
= die2
->die_attr
;
5957 a1
= a1
->dw_attr_next
, a2
= a2
->dw_attr_next
)
5958 if (!same_attr_p (a1
, a2
, mark
))
5963 for (c1
= die1
->die_child
, c2
= die2
->die_child
;
5965 c1
= c1
->die_sib
, c2
= c2
->die_sib
)
5966 if (!same_die_p (c1
, c2
, mark
))
5974 /* Do the dies look the same? Wrapper around same_die_p. */
5977 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
5980 int ret
= same_die_p (die1
, die2
, &mark
);
5982 unmark_all_dies (die1
);
5983 unmark_all_dies (die2
);
5988 /* The prefix to attach to symbols on DIEs in the current comdat debug
5990 static char *comdat_symbol_id
;
5992 /* The index of the current symbol within the current comdat CU. */
5993 static unsigned int comdat_symbol_number
;
5995 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5996 children, and set comdat_symbol_id accordingly. */
5999 compute_section_prefix (dw_die_ref unit_die
)
6001 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6002 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6003 char *name
= alloca (strlen (base
) + 64);
6006 unsigned char checksum
[16];
6009 /* Compute the checksum of the DIE, then append part of it as hex digits to
6010 the name filename of the unit. */
6012 md5_init_ctx (&ctx
);
6014 die_checksum (unit_die
, &ctx
, &mark
);
6015 unmark_all_dies (unit_die
);
6016 md5_finish_ctx (&ctx
, checksum
);
6018 sprintf (name
, "%s.", base
);
6019 clean_symbol_name (name
);
6021 p
= name
+ strlen (name
);
6022 for (i
= 0; i
< 4; i
++)
6024 sprintf (p
, "%.2x", checksum
[i
]);
6028 comdat_symbol_id
= unit_die
->die_symbol
= xstrdup (name
);
6029 comdat_symbol_number
= 0;
6032 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6035 is_type_die (dw_die_ref die
)
6037 switch (die
->die_tag
)
6039 case DW_TAG_array_type
:
6040 case DW_TAG_class_type
:
6041 case DW_TAG_enumeration_type
:
6042 case DW_TAG_pointer_type
:
6043 case DW_TAG_reference_type
:
6044 case DW_TAG_string_type
:
6045 case DW_TAG_structure_type
:
6046 case DW_TAG_subroutine_type
:
6047 case DW_TAG_union_type
:
6048 case DW_TAG_ptr_to_member_type
:
6049 case DW_TAG_set_type
:
6050 case DW_TAG_subrange_type
:
6051 case DW_TAG_base_type
:
6052 case DW_TAG_const_type
:
6053 case DW_TAG_file_type
:
6054 case DW_TAG_packed_type
:
6055 case DW_TAG_volatile_type
:
6056 case DW_TAG_typedef
:
6063 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6064 Basically, we want to choose the bits that are likely to be shared between
6065 compilations (types) and leave out the bits that are specific to individual
6066 compilations (functions). */
6069 is_comdat_die (dw_die_ref c
)
6071 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6072 we do for stabs. The advantage is a greater likelihood of sharing between
6073 objects that don't include headers in the same order (and therefore would
6074 put the base types in a different comdat). jason 8/28/00 */
6076 if (c
->die_tag
== DW_TAG_base_type
)
6079 if (c
->die_tag
== DW_TAG_pointer_type
6080 || c
->die_tag
== DW_TAG_reference_type
6081 || c
->die_tag
== DW_TAG_const_type
6082 || c
->die_tag
== DW_TAG_volatile_type
)
6084 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6086 return t
? is_comdat_die (t
) : 0;
6089 return is_type_die (c
);
6092 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6093 compilation unit. */
6096 is_symbol_die (dw_die_ref c
)
6098 return (is_type_die (c
)
6099 || (get_AT (c
, DW_AT_declaration
)
6100 && !get_AT (c
, DW_AT_specification
)));
6104 gen_internal_sym (const char *prefix
)
6108 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6109 return xstrdup (buf
);
6112 /* Assign symbols to all worthy DIEs under DIE. */
6115 assign_symbol_names (dw_die_ref die
)
6119 if (is_symbol_die (die
))
6121 if (comdat_symbol_id
)
6123 char *p
= alloca (strlen (comdat_symbol_id
) + 64);
6125 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6126 comdat_symbol_id
, comdat_symbol_number
++);
6127 die
->die_symbol
= xstrdup (p
);
6130 die
->die_symbol
= gen_internal_sym ("LDIE");
6133 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6134 assign_symbol_names (c
);
6137 struct cu_hash_table_entry
6140 unsigned min_comdat_num
, max_comdat_num
;
6141 struct cu_hash_table_entry
*next
;
6144 /* Routines to manipulate hash table of CUs. */
6146 htab_cu_hash (const void *of
)
6148 const struct cu_hash_table_entry
*entry
= of
;
6150 return htab_hash_string (entry
->cu
->die_symbol
);
6154 htab_cu_eq (const void *of1
, const void *of2
)
6156 const struct cu_hash_table_entry
*entry1
= of1
;
6157 const struct die_struct
*entry2
= of2
;
6159 return !strcmp (entry1
->cu
->die_symbol
, entry2
->die_symbol
);
6163 htab_cu_del (void *what
)
6165 struct cu_hash_table_entry
*next
, *entry
= what
;
6175 /* Check whether we have already seen this CU and set up SYM_NUM
6178 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6180 struct cu_hash_table_entry dummy
;
6181 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6183 dummy
.max_comdat_num
= 0;
6185 slot
= (struct cu_hash_table_entry
**)
6186 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6190 for (; entry
; last
= entry
, entry
= entry
->next
)
6192 if (same_die_p_wrap (cu
, entry
->cu
))
6198 *sym_num
= entry
->min_comdat_num
;
6202 entry
= xcalloc (1, sizeof (struct cu_hash_table_entry
));
6204 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6205 entry
->next
= *slot
;
6211 /* Record SYM_NUM to record of CU in HTABLE. */
6213 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6215 struct cu_hash_table_entry
**slot
, *entry
;
6217 slot
= (struct cu_hash_table_entry
**)
6218 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_symbol
),
6222 entry
->max_comdat_num
= sym_num
;
6225 /* Traverse the DIE (which is always comp_unit_die), and set up
6226 additional compilation units for each of the include files we see
6227 bracketed by BINCL/EINCL. */
6230 break_out_includes (dw_die_ref die
)
6233 dw_die_ref unit
= NULL
;
6234 limbo_die_node
*node
, **pnode
;
6235 htab_t cu_hash_table
;
6237 for (ptr
= &(die
->die_child
); *ptr
;)
6239 dw_die_ref c
= *ptr
;
6241 if (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6242 || (unit
&& is_comdat_die (c
)))
6244 /* This DIE is for a secondary CU; remove it from the main one. */
6247 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6249 unit
= push_new_compile_unit (unit
, c
);
6252 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6254 unit
= pop_compile_unit (unit
);
6258 add_child_die (unit
, c
);
6262 /* Leave this DIE in the main CU. */
6263 ptr
= &(c
->die_sib
);
6269 /* We can only use this in debugging, since the frontend doesn't check
6270 to make sure that we leave every include file we enter. */
6275 assign_symbol_names (die
);
6276 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6277 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6283 compute_section_prefix (node
->die
);
6284 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6285 &comdat_symbol_number
);
6286 assign_symbol_names (node
->die
);
6288 *pnode
= node
->next
;
6291 pnode
= &node
->next
;
6292 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6293 comdat_symbol_number
);
6296 htab_delete (cu_hash_table
);
6299 /* Traverse the DIE and add a sibling attribute if it may have the
6300 effect of speeding up access to siblings. To save some space,
6301 avoid generating sibling attributes for DIE's without children. */
6304 add_sibling_attributes (dw_die_ref die
)
6308 if (die
->die_tag
!= DW_TAG_compile_unit
6309 && die
->die_sib
&& die
->die_child
!= NULL
)
6310 /* Add the sibling link to the front of the attribute list. */
6311 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
6313 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6314 add_sibling_attributes (c
);
6317 /* Output all location lists for the DIE and its children. */
6320 output_location_lists (dw_die_ref die
)
6325 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6326 if (AT_class (d_attr
) == dw_val_class_loc_list
)
6327 output_loc_list (AT_loc_list (d_attr
));
6329 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6330 output_location_lists (c
);
6334 /* The format of each DIE (and its attribute value pairs) is encoded in an
6335 abbreviation table. This routine builds the abbreviation table and assigns
6336 a unique abbreviation id for each abbreviation entry. The children of each
6337 die are visited recursively. */
6340 build_abbrev_table (dw_die_ref die
)
6342 unsigned long abbrev_id
;
6343 unsigned int n_alloc
;
6345 dw_attr_ref d_attr
, a_attr
;
6347 /* Scan the DIE references, and mark as external any that refer to
6348 DIEs from other CUs (i.e. those which are not marked). */
6349 for (d_attr
= die
->die_attr
; d_attr
; d_attr
= d_attr
->dw_attr_next
)
6350 if (AT_class (d_attr
) == dw_val_class_die_ref
6351 && AT_ref (d_attr
)->die_mark
== 0)
6353 if (AT_ref (d_attr
)->die_symbol
== 0)
6356 set_AT_ref_external (d_attr
, 1);
6359 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6361 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6363 if (abbrev
->die_tag
== die
->die_tag
)
6365 if ((abbrev
->die_child
!= NULL
) == (die
->die_child
!= NULL
))
6367 a_attr
= abbrev
->die_attr
;
6368 d_attr
= die
->die_attr
;
6370 while (a_attr
!= NULL
&& d_attr
!= NULL
)
6372 if ((a_attr
->dw_attr
!= d_attr
->dw_attr
)
6373 || (value_format (a_attr
) != value_format (d_attr
)))
6376 a_attr
= a_attr
->dw_attr_next
;
6377 d_attr
= d_attr
->dw_attr_next
;
6380 if (a_attr
== NULL
&& d_attr
== NULL
)
6386 if (abbrev_id
>= abbrev_die_table_in_use
)
6388 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
6390 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
6391 abbrev_die_table
= ggc_realloc (abbrev_die_table
,
6392 sizeof (dw_die_ref
) * n_alloc
);
6394 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
6395 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
6396 abbrev_die_table_allocated
= n_alloc
;
6399 ++abbrev_die_table_in_use
;
6400 abbrev_die_table
[abbrev_id
] = die
;
6403 die
->die_abbrev
= abbrev_id
;
6404 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6405 build_abbrev_table (c
);
6408 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6411 constant_size (long unsigned int value
)
6418 log
= floor_log2 (value
);
6421 log
= 1 << (floor_log2 (log
) + 1);
6426 /* Return the size of a DIE as it is represented in the
6427 .debug_info section. */
6429 static unsigned long
6430 size_of_die (dw_die_ref die
)
6432 unsigned long size
= 0;
6435 size
+= size_of_uleb128 (die
->die_abbrev
);
6436 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6438 switch (AT_class (a
))
6440 case dw_val_class_addr
:
6441 size
+= DWARF2_ADDR_SIZE
;
6443 case dw_val_class_offset
:
6444 size
+= DWARF_OFFSET_SIZE
;
6446 case dw_val_class_loc
:
6448 unsigned long lsize
= size_of_locs (AT_loc (a
));
6451 size
+= constant_size (lsize
);
6455 case dw_val_class_loc_list
:
6456 size
+= DWARF_OFFSET_SIZE
;
6458 case dw_val_class_range_list
:
6459 size
+= DWARF_OFFSET_SIZE
;
6461 case dw_val_class_const
:
6462 size
+= size_of_sleb128 (AT_int (a
));
6464 case dw_val_class_unsigned_const
:
6465 size
+= constant_size (AT_unsigned (a
));
6467 case dw_val_class_long_long
:
6468 size
+= 1 + 2*HOST_BITS_PER_LONG
/HOST_BITS_PER_CHAR
; /* block */
6470 case dw_val_class_vec
:
6471 size
+= 1 + (a
->dw_attr_val
.v
.val_vec
.length
6472 * a
->dw_attr_val
.v
.val_vec
.elt_size
); /* block */
6474 case dw_val_class_flag
:
6477 case dw_val_class_die_ref
:
6478 if (AT_ref_external (a
))
6479 size
+= DWARF2_ADDR_SIZE
;
6481 size
+= DWARF_OFFSET_SIZE
;
6483 case dw_val_class_fde_ref
:
6484 size
+= DWARF_OFFSET_SIZE
;
6486 case dw_val_class_lbl_id
:
6487 size
+= DWARF2_ADDR_SIZE
;
6489 case dw_val_class_lbl_offset
:
6490 size
+= DWARF_OFFSET_SIZE
;
6492 case dw_val_class_str
:
6493 if (AT_string_form (a
) == DW_FORM_strp
)
6494 size
+= DWARF_OFFSET_SIZE
;
6496 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
6506 /* Size the debugging information associated with a given DIE. Visits the
6507 DIE's children recursively. Updates the global variable next_die_offset, on
6508 each time through. Uses the current value of next_die_offset to update the
6509 die_offset field in each DIE. */
6512 calc_die_sizes (dw_die_ref die
)
6516 die
->die_offset
= next_die_offset
;
6517 next_die_offset
+= size_of_die (die
);
6519 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
6522 if (die
->die_child
!= NULL
)
6523 /* Count the null byte used to terminate sibling lists. */
6524 next_die_offset
+= 1;
6527 /* Set the marks for a die and its children. We do this so
6528 that we know whether or not a reference needs to use FORM_ref_addr; only
6529 DIEs in the same CU will be marked. We used to clear out the offset
6530 and use that as the flag, but ran into ordering problems. */
6533 mark_dies (dw_die_ref die
)
6541 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6545 /* Clear the marks for a die and its children. */
6548 unmark_dies (dw_die_ref die
)
6556 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6560 /* Clear the marks for a die, its children and referred dies. */
6563 unmark_all_dies (dw_die_ref die
)
6572 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
6573 unmark_all_dies (c
);
6575 for (a
= die
->die_attr
; a
; a
= a
->dw_attr_next
)
6576 if (AT_class (a
) == dw_val_class_die_ref
)
6577 unmark_all_dies (AT_ref (a
));
6580 /* Return the size of the .debug_pubnames table generated for the
6581 compilation unit. */
6583 static unsigned long
6584 size_of_pubnames (void)
6589 size
= DWARF_PUBNAMES_HEADER_SIZE
;
6590 for (i
= 0; i
< pubname_table_in_use
; i
++)
6592 pubname_ref p
= &pubname_table
[i
];
6593 size
+= DWARF_OFFSET_SIZE
+ strlen (p
->name
) + 1;
6596 size
+= DWARF_OFFSET_SIZE
;
6600 /* Return the size of the information in the .debug_aranges section. */
6602 static unsigned long
6603 size_of_aranges (void)
6607 size
= DWARF_ARANGES_HEADER_SIZE
;
6609 /* Count the address/length pair for this compilation unit. */
6610 size
+= 2 * DWARF2_ADDR_SIZE
;
6611 size
+= 2 * DWARF2_ADDR_SIZE
* arange_table_in_use
;
6613 /* Count the two zero words used to terminated the address range table. */
6614 size
+= 2 * DWARF2_ADDR_SIZE
;
6618 /* Select the encoding of an attribute value. */
6620 static enum dwarf_form
6621 value_format (dw_attr_ref a
)
6623 switch (a
->dw_attr_val
.val_class
)
6625 case dw_val_class_addr
:
6626 return DW_FORM_addr
;
6627 case dw_val_class_range_list
:
6628 case dw_val_class_offset
:
6629 if (DWARF_OFFSET_SIZE
== 4)
6630 return DW_FORM_data4
;
6631 if (DWARF_OFFSET_SIZE
== 8)
6632 return DW_FORM_data8
;
6634 case dw_val_class_loc_list
:
6635 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6636 .debug_loc section */
6637 return DW_FORM_data4
;
6638 case dw_val_class_loc
:
6639 switch (constant_size (size_of_locs (AT_loc (a
))))
6642 return DW_FORM_block1
;
6644 return DW_FORM_block2
;
6648 case dw_val_class_const
:
6649 return DW_FORM_sdata
;
6650 case dw_val_class_unsigned_const
:
6651 switch (constant_size (AT_unsigned (a
)))
6654 return DW_FORM_data1
;
6656 return DW_FORM_data2
;
6658 return DW_FORM_data4
;
6660 return DW_FORM_data8
;
6664 case dw_val_class_long_long
:
6665 return DW_FORM_block1
;
6666 case dw_val_class_vec
:
6667 return DW_FORM_block1
;
6668 case dw_val_class_flag
:
6669 return DW_FORM_flag
;
6670 case dw_val_class_die_ref
:
6671 if (AT_ref_external (a
))
6672 return DW_FORM_ref_addr
;
6675 case dw_val_class_fde_ref
:
6676 return DW_FORM_data
;
6677 case dw_val_class_lbl_id
:
6678 return DW_FORM_addr
;
6679 case dw_val_class_lbl_offset
:
6680 return DW_FORM_data
;
6681 case dw_val_class_str
:
6682 return AT_string_form (a
);
6689 /* Output the encoding of an attribute value. */
6692 output_value_format (dw_attr_ref a
)
6694 enum dwarf_form form
= value_format (a
);
6696 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
6699 /* Output the .debug_abbrev section which defines the DIE abbreviation
6703 output_abbrev_section (void)
6705 unsigned long abbrev_id
;
6709 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
6711 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
6713 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
6714 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
6715 dwarf_tag_name (abbrev
->die_tag
));
6717 if (abbrev
->die_child
!= NULL
)
6718 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
6720 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
6722 for (a_attr
= abbrev
->die_attr
; a_attr
!= NULL
;
6723 a_attr
= a_attr
->dw_attr_next
)
6725 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
6726 dwarf_attr_name (a_attr
->dw_attr
));
6727 output_value_format (a_attr
);
6730 dw2_asm_output_data (1, 0, NULL
);
6731 dw2_asm_output_data (1, 0, NULL
);
6734 /* Terminate the table. */
6735 dw2_asm_output_data (1, 0, NULL
);
6738 /* Output a symbol we can use to refer to this DIE from another CU. */
6741 output_die_symbol (dw_die_ref die
)
6743 char *sym
= die
->die_symbol
;
6748 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
6749 /* We make these global, not weak; if the target doesn't support
6750 .linkonce, it doesn't support combining the sections, so debugging
6752 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
6754 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
6757 /* Return a new location list, given the begin and end range, and the
6758 expression. gensym tells us whether to generate a new internal symbol for
6759 this location list node, which is done for the head of the list only. */
6761 static inline dw_loc_list_ref
6762 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
6763 const char *section
, unsigned int gensym
)
6765 dw_loc_list_ref retlist
= ggc_alloc_cleared (sizeof (dw_loc_list_node
));
6767 retlist
->begin
= begin
;
6769 retlist
->expr
= expr
;
6770 retlist
->section
= section
;
6772 retlist
->ll_symbol
= gen_internal_sym ("LLST");
6777 /* Add a location description expression to a location list. */
6780 add_loc_descr_to_loc_list (dw_loc_list_ref
*list_head
, dw_loc_descr_ref descr
,
6781 const char *begin
, const char *end
,
6782 const char *section
)
6786 /* Find the end of the chain. */
6787 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
6790 /* Add a new location list node to the list. */
6791 *d
= new_loc_list (descr
, begin
, end
, section
, 0);
6794 /* Output the location list given to us. */
6797 output_loc_list (dw_loc_list_ref list_head
)
6799 dw_loc_list_ref curr
= list_head
;
6801 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
6803 /* Walk the location list, and output each range + expression. */
6804 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
6807 if (separate_line_info_table_in_use
== 0)
6809 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
6810 "Location list begin address (%s)",
6811 list_head
->ll_symbol
);
6812 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
6813 "Location list end address (%s)",
6814 list_head
->ll_symbol
);
6818 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
6819 "Location list begin address (%s)",
6820 list_head
->ll_symbol
);
6821 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
6822 "Location list end address (%s)",
6823 list_head
->ll_symbol
);
6825 size
= size_of_locs (curr
->expr
);
6827 /* Output the block length for this list of location operations. */
6830 dw2_asm_output_data (2, size
, "%s", "Location expression size");
6832 output_loc_sequence (curr
->expr
);
6835 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6836 "Location list terminator begin (%s)",
6837 list_head
->ll_symbol
);
6838 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
6839 "Location list terminator end (%s)",
6840 list_head
->ll_symbol
);
6843 /* Output the DIE and its attributes. Called recursively to generate
6844 the definitions of each child DIE. */
6847 output_die (dw_die_ref die
)
6853 /* If someone in another CU might refer to us, set up a symbol for
6854 them to point to. */
6855 if (die
->die_symbol
)
6856 output_die_symbol (die
);
6858 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (0x%lx) %s)",
6859 die
->die_offset
, dwarf_tag_name (die
->die_tag
));
6861 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
6863 const char *name
= dwarf_attr_name (a
->dw_attr
);
6865 switch (AT_class (a
))
6867 case dw_val_class_addr
:
6868 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
6871 case dw_val_class_offset
:
6872 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
6876 case dw_val_class_range_list
:
6878 char *p
= strchr (ranges_section_label
, '\0');
6880 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
,
6881 a
->dw_attr_val
.v
.val_offset
);
6882 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
6888 case dw_val_class_loc
:
6889 size
= size_of_locs (AT_loc (a
));
6891 /* Output the block length for this list of location operations. */
6892 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
6894 output_loc_sequence (AT_loc (a
));
6897 case dw_val_class_const
:
6898 /* ??? It would be slightly more efficient to use a scheme like is
6899 used for unsigned constants below, but gdb 4.x does not sign
6900 extend. Gdb 5.x does sign extend. */
6901 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
6904 case dw_val_class_unsigned_const
:
6905 dw2_asm_output_data (constant_size (AT_unsigned (a
)),
6906 AT_unsigned (a
), "%s", name
);
6909 case dw_val_class_long_long
:
6911 unsigned HOST_WIDE_INT first
, second
;
6913 dw2_asm_output_data (1,
6914 2 * HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6917 if (WORDS_BIG_ENDIAN
)
6919 first
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6920 second
= a
->dw_attr_val
.v
.val_long_long
.low
;
6924 first
= a
->dw_attr_val
.v
.val_long_long
.low
;
6925 second
= a
->dw_attr_val
.v
.val_long_long
.hi
;
6928 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6929 first
, "long long constant");
6930 dw2_asm_output_data (HOST_BITS_PER_LONG
/ HOST_BITS_PER_CHAR
,
6935 case dw_val_class_vec
:
6937 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
6938 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
6942 dw2_asm_output_data (1, len
* elt_size
, "%s", name
);
6943 if (elt_size
> sizeof (HOST_WIDE_INT
))
6948 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
6951 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
6952 "fp or vector constant word %u", i
);
6956 case dw_val_class_flag
:
6957 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
6960 case dw_val_class_loc_list
:
6962 char *sym
= AT_loc_list (a
)->ll_symbol
;
6966 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, "%s", name
);
6970 case dw_val_class_die_ref
:
6971 if (AT_ref_external (a
))
6973 char *sym
= AT_ref (a
)->die_symbol
;
6977 dw2_asm_output_offset (DWARF2_ADDR_SIZE
, sym
, "%s", name
);
6979 else if (AT_ref (a
)->die_offset
== 0)
6982 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
6986 case dw_val_class_fde_ref
:
6990 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
6991 a
->dw_attr_val
.v
.val_fde_index
* 2);
6992 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, "%s", name
);
6996 case dw_val_class_lbl_id
:
6997 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
7000 case dw_val_class_lbl_offset
:
7001 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
), "%s", name
);
7004 case dw_val_class_str
:
7005 if (AT_string_form (a
) == DW_FORM_strp
)
7006 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
7007 a
->dw_attr_val
.v
.val_str
->label
,
7008 "%s: \"%s\"", name
, AT_string (a
));
7010 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
7018 for (c
= die
->die_child
; c
!= NULL
; c
= c
->die_sib
)
7021 /* Add null byte to terminate sibling list. */
7022 if (die
->die_child
!= NULL
)
7023 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7027 /* Output the compilation unit that appears at the beginning of the
7028 .debug_info section, and precedes the DIE descriptions. */
7031 output_compilation_unit_header (void)
7033 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7034 dw2_asm_output_data (4, 0xffffffff,
7035 "Initial length escape value indicating 64-bit DWARF extension");
7036 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
7037 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
7038 "Length of Compilation Unit Info");
7039 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF version number");
7040 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
7041 "Offset Into Abbrev. Section");
7042 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
7045 /* Output the compilation unit DIE and its children. */
7048 output_comp_unit (dw_die_ref die
, int output_if_empty
)
7050 const char *secname
;
7053 /* Unless we are outputting main CU, we may throw away empty ones. */
7054 if (!output_if_empty
&& die
->die_child
== NULL
)
7057 /* Even if there are no children of this DIE, we must output the information
7058 about the compilation unit. Otherwise, on an empty translation unit, we
7059 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7060 will then complain when examining the file. First mark all the DIEs in
7061 this CU so we know which get local refs. */
7064 build_abbrev_table (die
);
7066 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7067 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7068 calc_die_sizes (die
);
7070 oldsym
= die
->die_symbol
;
7073 tmp
= alloca (strlen (oldsym
) + 24);
7075 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
7077 die
->die_symbol
= NULL
;
7080 secname
= (const char *) DEBUG_INFO_SECTION
;
7082 /* Output debugging information. */
7083 named_section_flags (secname
, SECTION_DEBUG
);
7084 output_compilation_unit_header ();
7087 /* Leave the marks on the main CU, so we can check them in
7092 die
->die_symbol
= oldsym
;
7096 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7097 output of lang_hooks.decl_printable_name for C++ looks like
7098 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7101 dwarf2_name (tree decl
, int scope
)
7103 return lang_hooks
.decl_printable_name (decl
, scope
? 1 : 0);
7106 /* Add a new entry to .debug_pubnames if appropriate. */
7109 add_pubname (tree decl
, dw_die_ref die
)
7113 if (! TREE_PUBLIC (decl
))
7116 if (pubname_table_in_use
== pubname_table_allocated
)
7118 pubname_table_allocated
+= PUBNAME_TABLE_INCREMENT
;
7120 = ggc_realloc (pubname_table
,
7121 (pubname_table_allocated
* sizeof (pubname_entry
)));
7122 memset (pubname_table
+ pubname_table_in_use
, 0,
7123 PUBNAME_TABLE_INCREMENT
* sizeof (pubname_entry
));
7126 p
= &pubname_table
[pubname_table_in_use
++];
7128 p
->name
= xstrdup (dwarf2_name (decl
, 1));
7131 /* Output the public names table used to speed up access to externally
7132 visible names. For now, only generate entries for externally
7133 visible procedures. */
7136 output_pubnames (void)
7139 unsigned long pubnames_length
= size_of_pubnames ();
7141 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7142 dw2_asm_output_data (4, 0xffffffff,
7143 "Initial length escape value indicating 64-bit DWARF extension");
7144 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
7145 "Length of Public Names Info");
7146 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7147 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7148 "Offset of Compilation Unit Info");
7149 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
7150 "Compilation Unit Length");
7152 for (i
= 0; i
< pubname_table_in_use
; i
++)
7154 pubname_ref pub
= &pubname_table
[i
];
7156 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7157 if (pub
->die
->die_mark
== 0)
7160 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pub
->die
->die_offset
,
7163 dw2_asm_output_nstring (pub
->name
, -1, "external name");
7166 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
7169 /* Add a new entry to .debug_aranges if appropriate. */
7172 add_arange (tree decl
, dw_die_ref die
)
7174 if (! DECL_SECTION_NAME (decl
))
7177 if (arange_table_in_use
== arange_table_allocated
)
7179 arange_table_allocated
+= ARANGE_TABLE_INCREMENT
;
7180 arange_table
= ggc_realloc (arange_table
,
7181 (arange_table_allocated
7182 * sizeof (dw_die_ref
)));
7183 memset (arange_table
+ arange_table_in_use
, 0,
7184 ARANGE_TABLE_INCREMENT
* sizeof (dw_die_ref
));
7187 arange_table
[arange_table_in_use
++] = die
;
7190 /* Output the information that goes into the .debug_aranges table.
7191 Namely, define the beginning and ending address range of the
7192 text section generated for this compilation unit. */
7195 output_aranges (void)
7198 unsigned long aranges_length
= size_of_aranges ();
7200 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7201 dw2_asm_output_data (4, 0xffffffff,
7202 "Initial length escape value indicating 64-bit DWARF extension");
7203 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
7204 "Length of Address Ranges Info");
7205 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7206 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
7207 "Offset of Compilation Unit Info");
7208 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
7209 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7211 /* We need to align to twice the pointer size here. */
7212 if (DWARF_ARANGES_PAD_SIZE
)
7214 /* Pad using a 2 byte words so that padding is correct for any
7216 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7217 2 * DWARF2_ADDR_SIZE
);
7218 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
7219 dw2_asm_output_data (2, 0, NULL
);
7222 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
7223 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
7224 text_section_label
, "Length");
7226 for (i
= 0; i
< arange_table_in_use
; i
++)
7228 dw_die_ref die
= arange_table
[i
];
7230 /* We shouldn't see aranges for DIEs outside of the main CU. */
7231 if (die
->die_mark
== 0)
7234 if (die
->die_tag
== DW_TAG_subprogram
)
7236 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, get_AT_low_pc (die
),
7238 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, get_AT_hi_pc (die
),
7239 get_AT_low_pc (die
), "Length");
7243 /* A static variable; extract the symbol from DW_AT_location.
7244 Note that this code isn't currently hit, as we only emit
7245 aranges for functions (jason 9/23/99). */
7246 dw_attr_ref a
= get_AT (die
, DW_AT_location
);
7247 dw_loc_descr_ref loc
;
7249 if (! a
|| AT_class (a
) != dw_val_class_loc
)
7253 if (loc
->dw_loc_opc
!= DW_OP_addr
)
7256 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
,
7257 loc
->dw_loc_oprnd1
.v
.val_addr
, "Address");
7258 dw2_asm_output_data (DWARF2_ADDR_SIZE
,
7259 get_AT_unsigned (die
, DW_AT_byte_size
),
7264 /* Output the terminator words. */
7265 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7266 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7269 /* Add a new entry to .debug_ranges. Return the offset at which it
7273 add_ranges (tree block
)
7275 unsigned int in_use
= ranges_table_in_use
;
7277 if (in_use
== ranges_table_allocated
)
7279 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
7281 = ggc_realloc (ranges_table
, (ranges_table_allocated
7282 * sizeof (struct dw_ranges_struct
)));
7283 memset (ranges_table
+ ranges_table_in_use
, 0,
7284 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
7287 ranges_table
[in_use
].block_num
= (block
? BLOCK_NUMBER (block
) : 0);
7288 ranges_table_in_use
= in_use
+ 1;
7290 return in_use
* 2 * DWARF2_ADDR_SIZE
;
7294 output_ranges (void)
7297 static const char *const start_fmt
= "Offset 0x%x";
7298 const char *fmt
= start_fmt
;
7300 for (i
= 0; i
< ranges_table_in_use
; i
++)
7302 int block_num
= ranges_table
[i
].block_num
;
7306 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7307 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
7309 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
7310 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
7312 /* If all code is in the text section, then the compilation
7313 unit base address defaults to DW_AT_low_pc, which is the
7314 base of the text section. */
7315 if (separate_line_info_table_in_use
== 0)
7317 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
7319 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7320 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
7321 text_section_label
, NULL
);
7324 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7325 compilation unit base address to zero, which allows us to
7326 use absolute addresses, and not worry about whether the
7327 target supports cross-section arithmetic. */
7330 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
7331 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
7332 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
7339 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7340 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
7346 /* Data structure containing information about input files. */
7349 char *path
; /* Complete file name. */
7350 char *fname
; /* File name part. */
7351 int length
; /* Length of entire string. */
7352 int file_idx
; /* Index in input file table. */
7353 int dir_idx
; /* Index in directory table. */
7356 /* Data structure containing information about directories with source
7360 char *path
; /* Path including directory name. */
7361 int length
; /* Path length. */
7362 int prefix
; /* Index of directory entry which is a prefix. */
7363 int count
; /* Number of files in this directory. */
7364 int dir_idx
; /* Index of directory used as base. */
7365 int used
; /* Used in the end? */
7368 /* Callback function for file_info comparison. We sort by looking at
7369 the directories in the path. */
7372 file_info_cmp (const void *p1
, const void *p2
)
7374 const struct file_info
*s1
= p1
;
7375 const struct file_info
*s2
= p2
;
7379 /* Take care of file names without directories. We need to make sure that
7380 we return consistent values to qsort since some will get confused if
7381 we return the same value when identical operands are passed in opposite
7382 orders. So if neither has a directory, return 0 and otherwise return
7383 1 or -1 depending on which one has the directory. */
7384 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
7385 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
7387 cp1
= (unsigned char *) s1
->path
;
7388 cp2
= (unsigned char *) s2
->path
;
7394 /* Reached the end of the first path? If so, handle like above. */
7395 if ((cp1
== (unsigned char *) s1
->fname
)
7396 || (cp2
== (unsigned char *) s2
->fname
))
7397 return ((cp2
== (unsigned char *) s2
->fname
)
7398 - (cp1
== (unsigned char *) s1
->fname
));
7400 /* Character of current path component the same? */
7401 else if (*cp1
!= *cp2
)
7406 /* Output the directory table and the file name table. We try to minimize
7407 the total amount of memory needed. A heuristic is used to avoid large
7408 slowdowns with many input files. */
7411 output_file_names (void)
7413 struct file_info
*files
;
7414 struct dir_info
*dirs
;
7423 /* Handle the case where file_table is empty. */
7424 if (VARRAY_ACTIVE_SIZE (file_table
) <= 1)
7426 dw2_asm_output_data (1, 0, "End directory table");
7427 dw2_asm_output_data (1, 0, "End file name table");
7431 /* Allocate the various arrays we need. */
7432 files
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct file_info
));
7433 dirs
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (struct dir_info
));
7435 /* Sort the file names. */
7436 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7440 /* Skip all leading "./". */
7441 f
= VARRAY_CHAR_PTR (file_table
, i
);
7442 while (f
[0] == '.' && f
[1] == '/')
7445 /* Create a new array entry. */
7447 files
[i
].length
= strlen (f
);
7448 files
[i
].file_idx
= i
;
7450 /* Search for the file name part. */
7451 f
= strrchr (f
, '/');
7452 files
[i
].fname
= f
== NULL
? files
[i
].path
: f
+ 1;
7455 qsort (files
+ 1, VARRAY_ACTIVE_SIZE (file_table
) - 1,
7456 sizeof (files
[0]), file_info_cmp
);
7458 /* Find all the different directories used. */
7459 dirs
[0].path
= files
[1].path
;
7460 dirs
[0].length
= files
[1].fname
- files
[1].path
;
7461 dirs
[0].prefix
= -1;
7463 dirs
[0].dir_idx
= 0;
7465 files
[1].dir_idx
= 0;
7468 for (i
= 2; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7469 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
7470 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
7471 dirs
[ndirs
- 1].length
) == 0)
7473 /* Same directory as last entry. */
7474 files
[i
].dir_idx
= ndirs
- 1;
7475 ++dirs
[ndirs
- 1].count
;
7481 /* This is a new directory. */
7482 dirs
[ndirs
].path
= files
[i
].path
;
7483 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
7484 dirs
[ndirs
].count
= 1;
7485 dirs
[ndirs
].dir_idx
= ndirs
;
7486 dirs
[ndirs
].used
= 0;
7487 files
[i
].dir_idx
= ndirs
;
7489 /* Search for a prefix. */
7490 dirs
[ndirs
].prefix
= -1;
7491 for (j
= 0; j
< ndirs
; j
++)
7492 if (dirs
[j
].length
< dirs
[ndirs
].length
7493 && dirs
[j
].length
> 1
7494 && (dirs
[ndirs
].prefix
== -1
7495 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
7496 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
7497 dirs
[ndirs
].prefix
= j
;
7502 /* Now to the actual work. We have to find a subset of the directories which
7503 allow expressing the file name using references to the directory table
7504 with the least amount of characters. We do not do an exhaustive search
7505 where we would have to check out every combination of every single
7506 possible prefix. Instead we use a heuristic which provides nearly optimal
7507 results in most cases and never is much off. */
7508 saved
= alloca (ndirs
* sizeof (int));
7509 savehere
= alloca (ndirs
* sizeof (int));
7511 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
7512 for (i
= 0; i
< ndirs
; i
++)
7517 /* We can always save some space for the current directory. But this
7518 does not mean it will be enough to justify adding the directory. */
7519 savehere
[i
] = dirs
[i
].length
;
7520 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
7522 for (j
= i
+ 1; j
< ndirs
; j
++)
7525 if (saved
[j
] < dirs
[i
].length
)
7527 /* Determine whether the dirs[i] path is a prefix of the
7532 while (k
!= -1 && k
!= (int) i
)
7537 /* Yes it is. We can possibly safe some memory but
7538 writing the filenames in dirs[j] relative to
7540 savehere
[j
] = dirs
[i
].length
;
7541 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
7546 /* Check whether we can safe enough to justify adding the dirs[i]
7548 if (total
> dirs
[i
].length
+ 1)
7550 /* It's worthwhile adding. */
7551 for (j
= i
; j
< ndirs
; j
++)
7552 if (savehere
[j
] > 0)
7554 /* Remember how much we saved for this directory so far. */
7555 saved
[j
] = savehere
[j
];
7557 /* Remember the prefix directory. */
7558 dirs
[j
].dir_idx
= i
;
7563 /* We have to emit them in the order they appear in the file_table array
7564 since the index is used in the debug info generation. To do this
7565 efficiently we generate a back-mapping of the indices first. */
7566 backmap
= alloca (VARRAY_ACTIVE_SIZE (file_table
) * sizeof (int));
7567 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7569 backmap
[files
[i
].file_idx
] = i
;
7571 /* Mark this directory as used. */
7572 dirs
[dirs
[files
[i
].dir_idx
].dir_idx
].used
= 1;
7575 /* That was it. We are ready to emit the information. First emit the
7576 directory name table. We have to make sure the first actually emitted
7577 directory name has index one; zero is reserved for the current working
7578 directory. Make sure we do not confuse these indices with the one for the
7579 constructed table (even though most of the time they are identical). */
7581 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
7582 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
7583 if (dirs
[i
].used
!= 0)
7585 dirs
[i
].used
= idx
++;
7586 dw2_asm_output_nstring (dirs
[i
].path
, dirs
[i
].length
- 1,
7587 "Directory Entry: 0x%x", dirs
[i
].used
);
7590 dw2_asm_output_data (1, 0, "End directory table");
7592 /* Correct the index for the current working directory entry if it
7594 if (idx_offset
== 0)
7597 /* Now write all the file names. */
7598 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
7600 int file_idx
= backmap
[i
];
7601 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
7603 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
7604 "File Entry: 0x%lx", (unsigned long) i
);
7606 /* Include directory index. */
7607 dw2_asm_output_data_uleb128 (dirs
[dir_idx
].used
, NULL
);
7609 /* Modification time. */
7610 dw2_asm_output_data_uleb128 (0, NULL
);
7612 /* File length in bytes. */
7613 dw2_asm_output_data_uleb128 (0, NULL
);
7616 dw2_asm_output_data (1, 0, "End file name table");
7620 /* Output the source line number correspondence information. This
7621 information goes into the .debug_line section. */
7624 output_line_info (void)
7626 char l1
[20], l2
[20], p1
[20], p2
[20];
7627 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7628 char prev_line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
7631 unsigned long lt_index
;
7632 unsigned long current_line
;
7635 unsigned long current_file
;
7636 unsigned long function
;
7638 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
7639 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
7640 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
7641 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
7643 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
7644 dw2_asm_output_data (4, 0xffffffff,
7645 "Initial length escape value indicating 64-bit DWARF extension");
7646 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
7647 "Length of Source Line Info");
7648 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
7650 dw2_asm_output_data (2, DWARF_VERSION
, "DWARF Version");
7651 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
7652 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
7654 /* Define the architecture-dependent minimum instruction length (in
7655 bytes). In this implementation of DWARF, this field is used for
7656 information purposes only. Since GCC generates assembly language,
7657 we have no a priori knowledge of how many instruction bytes are
7658 generated for each source line, and therefore can use only the
7659 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7660 commands. Accordingly, we fix this as `1', which is "correct
7661 enough" for all architectures, and don't let the target override. */
7662 dw2_asm_output_data (1, 1,
7663 "Minimum Instruction Length");
7665 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
7666 "Default is_stmt_start flag");
7667 dw2_asm_output_data (1, DWARF_LINE_BASE
,
7668 "Line Base Value (Special Opcodes)");
7669 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
7670 "Line Range Value (Special Opcodes)");
7671 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
7672 "Special Opcode Base");
7674 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
7678 case DW_LNS_advance_pc
:
7679 case DW_LNS_advance_line
:
7680 case DW_LNS_set_file
:
7681 case DW_LNS_set_column
:
7682 case DW_LNS_fixed_advance_pc
:
7690 dw2_asm_output_data (1, n_op_args
, "opcode: 0x%x has %d args",
7694 /* Write out the information about the files we use. */
7695 output_file_names ();
7696 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
7698 /* We used to set the address register to the first location in the text
7699 section here, but that didn't accomplish anything since we already
7700 have a line note for the opening brace of the first function. */
7702 /* Generate the line number to PC correspondence table, encoded as
7703 a series of state machine operations. */
7706 strcpy (prev_line_label
, text_section_label
);
7707 for (lt_index
= 1; lt_index
< line_info_table_in_use
; ++lt_index
)
7709 dw_line_info_ref line_info
= &line_info_table
[lt_index
];
7712 /* Disable this optimization for now; GDB wants to see two line notes
7713 at the beginning of a function so it can find the end of the
7716 /* Don't emit anything for redundant notes. Just updating the
7717 address doesn't accomplish anything, because we already assume
7718 that anything after the last address is this line. */
7719 if (line_info
->dw_line_num
== current_line
7720 && line_info
->dw_file_num
== current_file
)
7724 /* Emit debug info for the address of the current line.
7726 Unfortunately, we have little choice here currently, and must always
7727 use the most general form. GCC does not know the address delta
7728 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7729 attributes which will give an upper bound on the address range. We
7730 could perhaps use length attributes to determine when it is safe to
7731 use DW_LNS_fixed_advance_pc. */
7733 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, lt_index
);
7736 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7737 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7738 "DW_LNS_fixed_advance_pc");
7739 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7743 /* This can handle any delta. This takes
7744 4+DWARF2_ADDR_SIZE bytes. */
7745 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7746 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7747 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7748 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7751 strcpy (prev_line_label
, line_label
);
7753 /* Emit debug info for the source file of the current line, if
7754 different from the previous line. */
7755 if (line_info
->dw_file_num
!= current_file
)
7757 current_file
= line_info
->dw_file_num
;
7758 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7759 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7760 VARRAY_CHAR_PTR (file_table
,
7764 /* Emit debug info for the current line number, choosing the encoding
7765 that uses the least amount of space. */
7766 if (line_info
->dw_line_num
!= current_line
)
7768 line_offset
= line_info
->dw_line_num
- current_line
;
7769 line_delta
= line_offset
- DWARF_LINE_BASE
;
7770 current_line
= line_info
->dw_line_num
;
7771 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7772 /* This can handle deltas from -10 to 234, using the current
7773 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7775 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7776 "line %lu", current_line
);
7779 /* This can handle any delta. This takes at least 4 bytes,
7780 depending on the value being encoded. */
7781 dw2_asm_output_data (1, DW_LNS_advance_line
,
7782 "advance to line %lu", current_line
);
7783 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7784 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7788 /* We still need to start a new row, so output a copy insn. */
7789 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7792 /* Emit debug info for the address of the end of the function. */
7795 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7796 "DW_LNS_fixed_advance_pc");
7797 dw2_asm_output_delta (2, text_end_label
, prev_line_label
, NULL
);
7801 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7802 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7803 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7804 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_end_label
, NULL
);
7807 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7808 dw2_asm_output_data_uleb128 (1, NULL
);
7809 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7814 for (lt_index
= 0; lt_index
< separate_line_info_table_in_use
;)
7816 dw_separate_line_info_ref line_info
7817 = &separate_line_info_table
[lt_index
];
7820 /* Don't emit anything for redundant notes. */
7821 if (line_info
->dw_line_num
== current_line
7822 && line_info
->dw_file_num
== current_file
7823 && line_info
->function
== function
)
7827 /* Emit debug info for the address of the current line. If this is
7828 a new function, or the first line of a function, then we need
7829 to handle it differently. */
7830 ASM_GENERATE_INTERNAL_LABEL (line_label
, SEPARATE_LINE_CODE_LABEL
,
7832 if (function
!= line_info
->function
)
7834 function
= line_info
->function
;
7836 /* Set the address register to the first line in the function. */
7837 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7838 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7839 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7840 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7844 /* ??? See the DW_LNS_advance_pc comment above. */
7847 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7848 "DW_LNS_fixed_advance_pc");
7849 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7853 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7854 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7855 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7856 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7860 strcpy (prev_line_label
, line_label
);
7862 /* Emit debug info for the source file of the current line, if
7863 different from the previous line. */
7864 if (line_info
->dw_file_num
!= current_file
)
7866 current_file
= line_info
->dw_file_num
;
7867 dw2_asm_output_data (1, DW_LNS_set_file
, "DW_LNS_set_file");
7868 dw2_asm_output_data_uleb128 (current_file
, "(\"%s\")",
7869 VARRAY_CHAR_PTR (file_table
,
7873 /* Emit debug info for the current line number, choosing the encoding
7874 that uses the least amount of space. */
7875 if (line_info
->dw_line_num
!= current_line
)
7877 line_offset
= line_info
->dw_line_num
- current_line
;
7878 line_delta
= line_offset
- DWARF_LINE_BASE
;
7879 current_line
= line_info
->dw_line_num
;
7880 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
7881 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
7882 "line %lu", current_line
);
7885 dw2_asm_output_data (1, DW_LNS_advance_line
,
7886 "advance to line %lu", current_line
);
7887 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
7888 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7892 dw2_asm_output_data (1, DW_LNS_copy
, "DW_LNS_copy");
7900 /* If we're done with a function, end its sequence. */
7901 if (lt_index
== separate_line_info_table_in_use
7902 || separate_line_info_table
[lt_index
].function
!= function
)
7907 /* Emit debug info for the address of the end of the function. */
7908 ASM_GENERATE_INTERNAL_LABEL (line_label
, FUNC_END_LABEL
, function
);
7911 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc
,
7912 "DW_LNS_fixed_advance_pc");
7913 dw2_asm_output_delta (2, line_label
, prev_line_label
, NULL
);
7917 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7918 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
7919 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
7920 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
7923 /* Output the marker for the end of this sequence. */
7924 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7925 dw2_asm_output_data_uleb128 (1, NULL
);
7926 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
7930 /* Output the marker for the end of the line number info. */
7931 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
7934 /* Given a pointer to a tree node for some base type, return a pointer to
7935 a DIE that describes the given type.
7937 This routine must only be called for GCC type nodes that correspond to
7938 Dwarf base (fundamental) types. */
7941 base_type_die (tree type
)
7943 dw_die_ref base_type_result
;
7944 const char *type_name
;
7945 enum dwarf_type encoding
;
7946 tree name
= TYPE_NAME (type
);
7948 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
7953 if (TREE_CODE (name
) == TYPE_DECL
)
7954 name
= DECL_NAME (name
);
7956 type_name
= IDENTIFIER_POINTER (name
);
7959 type_name
= "__unknown__";
7961 switch (TREE_CODE (type
))
7964 /* Carefully distinguish the C character types, without messing
7965 up if the language is not C. Note that we check only for the names
7966 that contain spaces; other names might occur by coincidence in other
7968 if (! (TYPE_PRECISION (type
) == CHAR_TYPE_SIZE
7969 && (type
== char_type_node
7970 || ! strcmp (type_name
, "signed char")
7971 || ! strcmp (type_name
, "unsigned char"))))
7973 if (TYPE_UNSIGNED (type
))
7974 encoding
= DW_ATE_unsigned
;
7976 encoding
= DW_ATE_signed
;
7979 /* else fall through. */
7982 /* GNU Pascal/Ada CHAR type. Not used in C. */
7983 if (TYPE_UNSIGNED (type
))
7984 encoding
= DW_ATE_unsigned_char
;
7986 encoding
= DW_ATE_signed_char
;
7990 encoding
= DW_ATE_float
;
7993 /* Dwarf2 doesn't know anything about complex ints, so use
7994 a user defined type for it. */
7996 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
7997 encoding
= DW_ATE_complex_float
;
7999 encoding
= DW_ATE_lo_user
;
8003 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8004 encoding
= DW_ATE_boolean
;
8008 /* No other TREE_CODEs are Dwarf fundamental types. */
8012 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die
, type
);
8013 if (demangle_name_func
)
8014 type_name
= (*demangle_name_func
) (type_name
);
8016 add_AT_string (base_type_result
, DW_AT_name
, type_name
);
8017 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
8018 int_size_in_bytes (type
));
8019 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
8021 return base_type_result
;
8024 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8025 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8026 a given type is generally the same as the given type, except that if the
8027 given type is a pointer or reference type, then the root type of the given
8028 type is the root type of the "basis" type for the pointer or reference
8029 type. (This definition of the "root" type is recursive.) Also, the root
8030 type of a `const' qualified type or a `volatile' qualified type is the
8031 root type of the given type without the qualifiers. */
8034 root_type (tree type
)
8036 if (TREE_CODE (type
) == ERROR_MARK
)
8037 return error_mark_node
;
8039 switch (TREE_CODE (type
))
8042 return error_mark_node
;
8045 case REFERENCE_TYPE
:
8046 return type_main_variant (root_type (TREE_TYPE (type
)));
8049 return type_main_variant (type
);
8053 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8054 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8057 is_base_type (tree type
)
8059 switch (TREE_CODE (type
))
8074 case QUAL_UNION_TYPE
:
8079 case REFERENCE_TYPE
:
8093 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8094 node, return the size in bits for the type if it is a constant, or else
8095 return the alignment for the type if the type's size is not constant, or
8096 else return BITS_PER_WORD if the type actually turns out to be an
8099 static inline unsigned HOST_WIDE_INT
8100 simple_type_size_in_bits (tree type
)
8102 if (TREE_CODE (type
) == ERROR_MARK
)
8103 return BITS_PER_WORD
;
8104 else if (TYPE_SIZE (type
) == NULL_TREE
)
8106 else if (host_integerp (TYPE_SIZE (type
), 1))
8107 return tree_low_cst (TYPE_SIZE (type
), 1);
8109 return TYPE_ALIGN (type
);
8112 /* Return true if the debug information for the given type should be
8113 emitted as a subrange type. */
8116 is_subrange_type (tree type
)
8118 tree subtype
= TREE_TYPE (type
);
8120 /* Subrange types are identified by the fact that they are integer
8121 types, and that they have a subtype which is either an integer type
8122 or an enumeral type. */
8124 if (TREE_CODE (type
) != INTEGER_TYPE
8125 || subtype
== NULL_TREE
)
8128 if (TREE_CODE (subtype
) != INTEGER_TYPE
8129 && TREE_CODE (subtype
) != ENUMERAL_TYPE
)
8132 if (TREE_CODE (type
) == TREE_CODE (subtype
)
8133 && int_size_in_bytes (type
) == int_size_in_bytes (subtype
)
8134 && TYPE_MIN_VALUE (type
) != NULL
8135 && TYPE_MIN_VALUE (subtype
) != NULL
8136 && tree_int_cst_equal (TYPE_MIN_VALUE (type
), TYPE_MIN_VALUE (subtype
))
8137 && TYPE_MAX_VALUE (type
) != NULL
8138 && TYPE_MAX_VALUE (subtype
) != NULL
8139 && tree_int_cst_equal (TYPE_MAX_VALUE (type
), TYPE_MAX_VALUE (subtype
)))
8141 /* The type and its subtype have the same representation. If in
8142 addition the two types also have the same name, then the given
8143 type is not a subrange type, but rather a plain base type. */
8144 /* FIXME: brobecker/2004-03-22:
8145 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8146 therefore be sufficient to check the TYPE_SIZE node pointers
8147 rather than checking the actual size. Unfortunately, we have
8148 found some cases, such as in the Ada "integer" type, where
8149 this is not the case. Until this problem is solved, we need to
8150 keep checking the actual size. */
8151 tree type_name
= TYPE_NAME (type
);
8152 tree subtype_name
= TYPE_NAME (subtype
);
8154 if (type_name
!= NULL
&& TREE_CODE (type_name
) == TYPE_DECL
)
8155 type_name
= DECL_NAME (type_name
);
8157 if (subtype_name
!= NULL
&& TREE_CODE (subtype_name
) == TYPE_DECL
)
8158 subtype_name
= DECL_NAME (subtype_name
);
8160 if (type_name
== subtype_name
)
8167 /* Given a pointer to a tree node for a subrange type, return a pointer
8168 to a DIE that describes the given type. */
8171 subrange_type_die (tree type
, dw_die_ref context_die
)
8173 dw_die_ref subtype_die
;
8174 dw_die_ref subrange_die
;
8175 tree name
= TYPE_NAME (type
);
8176 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
8177 tree subtype
= TREE_TYPE (type
);
8179 if (context_die
== NULL
)
8180 context_die
= comp_unit_die
;
8182 if (TREE_CODE (subtype
) == ENUMERAL_TYPE
)
8183 subtype_die
= gen_enumeration_type_die (subtype
, context_die
);
8185 subtype_die
= base_type_die (subtype
);
8187 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
8191 if (TREE_CODE (name
) == TYPE_DECL
)
8192 name
= DECL_NAME (name
);
8193 add_name_attribute (subrange_die
, IDENTIFIER_POINTER (name
));
8196 if (int_size_in_bytes (subtype
) != size_in_bytes
)
8198 /* The size of the subrange type and its base type do not match,
8199 so we need to generate a size attribute for the subrange type. */
8200 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
8203 if (TYPE_MIN_VALUE (type
) != NULL
)
8204 add_bound_info (subrange_die
, DW_AT_lower_bound
,
8205 TYPE_MIN_VALUE (type
));
8206 if (TYPE_MAX_VALUE (type
) != NULL
)
8207 add_bound_info (subrange_die
, DW_AT_upper_bound
,
8208 TYPE_MAX_VALUE (type
));
8209 add_AT_die_ref (subrange_die
, DW_AT_type
, subtype_die
);
8211 return subrange_die
;
8214 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8215 entry that chains various modifiers in front of the given type. */
8218 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
8219 dw_die_ref context_die
)
8221 enum tree_code code
= TREE_CODE (type
);
8222 dw_die_ref mod_type_die
= NULL
;
8223 dw_die_ref sub_die
= NULL
;
8224 tree item_type
= NULL
;
8226 if (code
!= ERROR_MARK
)
8228 tree qualified_type
;
8230 /* See if we already have the appropriately qualified variant of
8233 = get_qualified_type (type
,
8234 ((is_const_type
? TYPE_QUAL_CONST
: 0)
8236 ? TYPE_QUAL_VOLATILE
: 0)));
8238 /* If we do, then we can just use its DIE, if it exists. */
8241 mod_type_die
= lookup_type_die (qualified_type
);
8243 return mod_type_die
;
8246 /* Handle C typedef types. */
8247 if (qualified_type
&& TYPE_NAME (qualified_type
)
8248 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
8249 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type
)))
8251 tree type_name
= TYPE_NAME (qualified_type
);
8252 tree dtype
= TREE_TYPE (type_name
);
8254 if (qualified_type
== dtype
)
8256 /* For a named type, use the typedef. */
8257 gen_type_die (qualified_type
, context_die
);
8258 mod_type_die
= lookup_type_die (qualified_type
);
8260 else if (is_const_type
< TYPE_READONLY (dtype
)
8261 || is_volatile_type
< TYPE_VOLATILE (dtype
))
8262 /* cv-unqualified version of named type. Just use the unnamed
8263 type to which it refers. */
8265 = modified_type_die (DECL_ORIGINAL_TYPE (type_name
),
8266 is_const_type
, is_volatile_type
,
8269 /* Else cv-qualified version of named type; fall through. */
8275 else if (is_const_type
)
8277 mod_type_die
= new_die (DW_TAG_const_type
, comp_unit_die
, type
);
8278 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
8280 else if (is_volatile_type
)
8282 mod_type_die
= new_die (DW_TAG_volatile_type
, comp_unit_die
, type
);
8283 sub_die
= modified_type_die (type
, 0, 0, context_die
);
8285 else if (code
== POINTER_TYPE
)
8287 mod_type_die
= new_die (DW_TAG_pointer_type
, comp_unit_die
, type
);
8288 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8289 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8291 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
8293 item_type
= TREE_TYPE (type
);
8295 else if (code
== REFERENCE_TYPE
)
8297 mod_type_die
= new_die (DW_TAG_reference_type
, comp_unit_die
, type
);
8298 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
8299 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
8301 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, 0);
8303 item_type
= TREE_TYPE (type
);
8305 else if (is_subrange_type (type
))
8306 mod_type_die
= subrange_type_die (type
, context_die
);
8307 else if (is_base_type (type
))
8308 mod_type_die
= base_type_die (type
);
8311 gen_type_die (type
, context_die
);
8313 /* We have to get the type_main_variant here (and pass that to the
8314 `lookup_type_die' routine) because the ..._TYPE node we have
8315 might simply be a *copy* of some original type node (where the
8316 copy was created to help us keep track of typedef names) and
8317 that copy might have a different TYPE_UID from the original
8319 if (TREE_CODE (type
) != VECTOR_TYPE
)
8320 mod_type_die
= lookup_type_die (type_main_variant (type
));
8322 /* Vectors have the debugging information in the type,
8323 not the main variant. */
8324 mod_type_die
= lookup_type_die (type
);
8325 if (mod_type_die
== NULL
)
8329 /* We want to equate the qualified type to the die below. */
8330 type
= qualified_type
;
8334 equate_type_number_to_die (type
, mod_type_die
);
8336 /* We must do this after the equate_type_number_to_die call, in case
8337 this is a recursive type. This ensures that the modified_type_die
8338 recursion will terminate even if the type is recursive. Recursive
8339 types are possible in Ada. */
8340 sub_die
= modified_type_die (item_type
,
8341 TYPE_READONLY (item_type
),
8342 TYPE_VOLATILE (item_type
),
8345 if (sub_die
!= NULL
)
8346 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
8348 return mod_type_die
;
8351 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8352 an enumerated type. */
8355 type_is_enum (tree type
)
8357 return TREE_CODE (type
) == ENUMERAL_TYPE
;
8360 /* Return the DBX register number described by a given RTL node. */
8363 dbx_reg_number (rtx rtl
)
8365 unsigned regno
= REGNO (rtl
);
8367 if (regno
>= FIRST_PSEUDO_REGISTER
)
8370 return DBX_REGISTER_NUMBER (regno
);
8373 /* Return a location descriptor that designates a machine register or
8374 zero if there is none. */
8376 static dw_loc_descr_ref
8377 reg_loc_descriptor (rtx rtl
)
8382 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
8385 reg
= dbx_reg_number (rtl
);
8386 regs
= targetm
.dwarf_register_span (rtl
);
8388 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1
8390 return multiple_reg_loc_descriptor (rtl
, regs
);
8392 return one_reg_loc_descriptor (reg
);
8395 /* Return a location descriptor that designates a machine register for
8396 a given hard register number. */
8398 static dw_loc_descr_ref
8399 one_reg_loc_descriptor (unsigned int regno
)
8402 return new_loc_descr (DW_OP_reg0
+ regno
, 0, 0);
8404 return new_loc_descr (DW_OP_regx
, regno
, 0);
8407 /* Given an RTL of a register, return a location descriptor that
8408 designates a value that spans more than one register. */
8410 static dw_loc_descr_ref
8411 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
)
8415 dw_loc_descr_ref loc_result
= NULL
;
8417 reg
= dbx_reg_number (rtl
);
8418 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
8420 /* Simple, contiguous registers. */
8421 if (regs
== NULL_RTX
)
8423 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
8430 t
= one_reg_loc_descriptor (reg
);
8431 add_loc_descr (&loc_result
, t
);
8432 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8438 /* Now onto stupid register sets in non contiguous locations. */
8440 if (GET_CODE (regs
) != PARALLEL
)
8443 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8446 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
8450 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)));
8451 add_loc_descr (&loc_result
, t
);
8452 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
8453 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_piece
, size
, 0));
8458 /* Return a location descriptor that designates a constant. */
8460 static dw_loc_descr_ref
8461 int_loc_descriptor (HOST_WIDE_INT i
)
8463 enum dwarf_location_atom op
;
8465 /* Pick the smallest representation of a constant, rather than just
8466 defaulting to the LEB encoding. */
8470 op
= DW_OP_lit0
+ i
;
8473 else if (i
<= 0xffff)
8475 else if (HOST_BITS_PER_WIDE_INT
== 32
8485 else if (i
>= -0x8000)
8487 else if (HOST_BITS_PER_WIDE_INT
== 32
8488 || i
>= -0x80000000)
8494 return new_loc_descr (op
, i
, 0);
8497 /* Return a location descriptor that designates a base+offset location. */
8499 static dw_loc_descr_ref
8500 based_loc_descr (unsigned int reg
, HOST_WIDE_INT offset
, bool can_use_fbreg
)
8502 dw_loc_descr_ref loc_result
;
8503 /* For the "frame base", we use the frame pointer or stack pointer
8504 registers, since the RTL for local variables is relative to one of
8506 unsigned fp_reg
= DBX_REGISTER_NUMBER (frame_pointer_needed
8507 ? HARD_FRAME_POINTER_REGNUM
8508 : STACK_POINTER_REGNUM
);
8510 if (reg
== fp_reg
&& can_use_fbreg
)
8511 loc_result
= new_loc_descr (DW_OP_fbreg
, offset
, 0);
8513 loc_result
= new_loc_descr (DW_OP_breg0
+ reg
, offset
, 0);
8515 loc_result
= new_loc_descr (DW_OP_bregx
, reg
, offset
);
8520 /* Return true if this RTL expression describes a base+offset calculation. */
8523 is_based_loc (rtx rtl
)
8525 return (GET_CODE (rtl
) == PLUS
8526 && ((REG_P (XEXP (rtl
, 0))
8527 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
8528 && GET_CODE (XEXP (rtl
, 1)) == CONST_INT
)));
8531 /* The following routine converts the RTL for a variable or parameter
8532 (resident in memory) into an equivalent Dwarf representation of a
8533 mechanism for getting the address of that same variable onto the top of a
8534 hypothetical "address evaluation" stack.
8536 When creating memory location descriptors, we are effectively transforming
8537 the RTL for a memory-resident object into its Dwarf postfix expression
8538 equivalent. This routine recursively descends an RTL tree, turning
8539 it into Dwarf postfix code as it goes.
8541 MODE is the mode of the memory reference, needed to handle some
8542 autoincrement addressing modes.
8544 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location
8545 list for RTL. We can't use it when we are emitting location list for
8546 virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base)
8547 which describes how frame base changes when !frame_pointer_needed.
8549 Return 0 if we can't represent the location. */
8551 static dw_loc_descr_ref
8552 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
, bool can_use_fbreg
)
8554 dw_loc_descr_ref mem_loc_result
= NULL
;
8555 enum dwarf_location_atom op
;
8557 /* Note that for a dynamically sized array, the location we will generate a
8558 description of here will be the lowest numbered location which is
8559 actually within the array. That's *not* necessarily the same as the
8560 zeroth element of the array. */
8562 rtl
= targetm
.delegitimize_address (rtl
);
8564 switch (GET_CODE (rtl
))
8569 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8570 just fall into the SUBREG code. */
8572 /* ... fall through ... */
8575 /* The case of a subreg may arise when we have a local (register)
8576 variable or a formal (register) parameter which doesn't quite fill
8577 up an entire register. For now, just assume that it is
8578 legitimate to make the Dwarf info refer to the whole register which
8579 contains the given subreg. */
8580 rtl
= SUBREG_REG (rtl
);
8582 /* ... fall through ... */
8585 /* Whenever a register number forms a part of the description of the
8586 method for calculating the (dynamic) address of a memory resident
8587 object, DWARF rules require the register number be referred to as
8588 a "base register". This distinction is not based in any way upon
8589 what category of register the hardware believes the given register
8590 belongs to. This is strictly DWARF terminology we're dealing with
8591 here. Note that in cases where the location of a memory-resident
8592 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8593 OP_CONST (0)) the actual DWARF location descriptor that we generate
8594 may just be OP_BASEREG (basereg). This may look deceptively like
8595 the object in question was allocated to a register (rather than in
8596 memory) so DWARF consumers need to be aware of the subtle
8597 distinction between OP_REG and OP_BASEREG. */
8598 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
8599 mem_loc_result
= based_loc_descr (dbx_reg_number (rtl
), 0,
8604 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
8606 if (mem_loc_result
!= 0)
8607 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
8611 rtl
= XEXP (rtl
, 1);
8613 /* ... fall through ... */
8616 /* Some ports can transform a symbol ref into a label ref, because
8617 the symbol ref is too far away and has to be dumped into a constant
8621 /* Alternatively, the symbol in the constant pool might be referenced
8622 by a different symbol. */
8623 if (GET_CODE (rtl
) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (rtl
))
8626 rtx tmp
= get_pool_constant_mark (rtl
, &marked
);
8628 if (GET_CODE (tmp
) == SYMBOL_REF
)
8631 if (CONSTANT_POOL_ADDRESS_P (tmp
))
8632 get_pool_constant_mark (tmp
, &marked
);
8637 /* If all references to this pool constant were optimized away,
8638 it was not output and thus we can't represent it.
8639 FIXME: might try to use DW_OP_const_value here, though
8640 DW_OP_piece complicates it. */
8645 mem_loc_result
= new_loc_descr (DW_OP_addr
, 0, 0);
8646 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8647 mem_loc_result
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8648 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
8652 /* Extract the PLUS expression nested inside and fall into
8654 rtl
= XEXP (rtl
, 1);
8659 /* Turn these into a PLUS expression and fall into the PLUS code
8661 rtl
= gen_rtx_PLUS (word_mode
, XEXP (rtl
, 0),
8662 GEN_INT (GET_CODE (rtl
) == PRE_INC
8663 ? GET_MODE_UNIT_SIZE (mode
)
8664 : -GET_MODE_UNIT_SIZE (mode
)));
8666 /* ... fall through ... */
8670 if (is_based_loc (rtl
))
8671 mem_loc_result
= based_loc_descr (dbx_reg_number (XEXP (rtl
, 0)),
8672 INTVAL (XEXP (rtl
, 1)),
8676 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
8678 if (mem_loc_result
== 0)
8681 if (GET_CODE (XEXP (rtl
, 1)) == CONST_INT
8682 && INTVAL (XEXP (rtl
, 1)) >= 0)
8683 add_loc_descr (&mem_loc_result
,
8684 new_loc_descr (DW_OP_plus_uconst
,
8685 INTVAL (XEXP (rtl
, 1)), 0));
8688 add_loc_descr (&mem_loc_result
,
8689 mem_loc_descriptor (XEXP (rtl
, 1), mode
,
8691 add_loc_descr (&mem_loc_result
,
8692 new_loc_descr (DW_OP_plus
, 0, 0));
8697 /* If a pseudo-reg is optimized away, it is possible for it to
8698 be replaced with a MEM containing a multiply or shift. */
8717 dw_loc_descr_ref op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
,
8719 dw_loc_descr_ref op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
,
8722 if (op0
== 0 || op1
== 0)
8725 mem_loc_result
= op0
;
8726 add_loc_descr (&mem_loc_result
, op1
);
8727 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
8732 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
8736 /* If this is a MEM, return its address. Otherwise, we can't
8738 if (GET_CODE (XEXP (rtl
, 0)) == MEM
)
8739 return mem_loc_descriptor (XEXP (XEXP (rtl
, 0), 0), mode
,
8748 return mem_loc_result
;
8751 /* Return a descriptor that describes the concatenation of two locations.
8752 This is typically a complex variable. */
8754 static dw_loc_descr_ref
8755 concat_loc_descriptor (rtx x0
, rtx x1
)
8757 dw_loc_descr_ref cc_loc_result
= NULL
;
8758 dw_loc_descr_ref x0_ref
= loc_descriptor (x0
, true);
8759 dw_loc_descr_ref x1_ref
= loc_descriptor (x1
, true);
8761 if (x0_ref
== 0 || x1_ref
== 0)
8764 cc_loc_result
= x0_ref
;
8765 add_loc_descr (&cc_loc_result
,
8766 new_loc_descr (DW_OP_piece
,
8767 GET_MODE_SIZE (GET_MODE (x0
)), 0));
8769 add_loc_descr (&cc_loc_result
, x1_ref
);
8770 add_loc_descr (&cc_loc_result
,
8771 new_loc_descr (DW_OP_piece
,
8772 GET_MODE_SIZE (GET_MODE (x1
)), 0));
8774 return cc_loc_result
;
8777 /* Output a proper Dwarf location descriptor for a variable or parameter
8778 which is either allocated in a register or in a memory location. For a
8779 register, we just generate an OP_REG and the register number. For a
8780 memory location we provide a Dwarf postfix expression describing how to
8781 generate the (dynamic) address of the object onto the address stack.
8783 If we don't know how to describe it, return 0. */
8785 static dw_loc_descr_ref
8786 loc_descriptor (rtx rtl
, bool can_use_fbreg
)
8788 dw_loc_descr_ref loc_result
= NULL
;
8790 switch (GET_CODE (rtl
))
8793 /* The case of a subreg may arise when we have a local (register)
8794 variable or a formal (register) parameter which doesn't quite fill
8795 up an entire register. For now, just assume that it is
8796 legitimate to make the Dwarf info refer to the whole register which
8797 contains the given subreg. */
8798 rtl
= SUBREG_REG (rtl
);
8800 /* ... fall through ... */
8803 loc_result
= reg_loc_descriptor (rtl
);
8807 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (rtl
),
8812 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1));
8817 if (GET_CODE (XEXP (rtl
, 1)) != PARALLEL
)
8819 loc_result
= loc_descriptor (XEXP (XEXP (rtl
, 1), 0), can_use_fbreg
);
8821 /* Multiple parts. */
8824 rtvec par_elems
= XVEC (XEXP (rtl
, 1), 0);
8825 int num_elem
= GET_NUM_ELEM (par_elems
);
8826 enum machine_mode mode
;
8829 /* Create the first one, so we have something to add to. */
8830 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
8832 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
8833 add_loc_descr (&loc_result
,
8834 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (mode
), 0));
8835 for (i
= 1; i
< num_elem
; i
++)
8837 dw_loc_descr_ref temp
;
8839 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
8841 add_loc_descr (&loc_result
, temp
);
8842 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
8843 add_loc_descr (&loc_result
,
8844 new_loc_descr (DW_OP_piece
,
8845 GET_MODE_SIZE (mode
), 0));
8857 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8858 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
8859 looking for an address. Otherwise, we return a value. If we can't make a
8860 descriptor, return 0. */
8862 static dw_loc_descr_ref
8863 loc_descriptor_from_tree (tree loc
, int addressp
)
8865 dw_loc_descr_ref ret
, ret1
;
8867 int unsignedp
= TYPE_UNSIGNED (TREE_TYPE (loc
));
8868 enum dwarf_location_atom op
;
8870 /* ??? Most of the time we do not take proper care for sign/zero
8871 extending the values properly. Hopefully this won't be a real
8874 switch (TREE_CODE (loc
))
8879 case PLACEHOLDER_EXPR
:
8880 /* This case involves extracting fields from an object to determine the
8881 position of other fields. We don't try to encode this here. The
8882 only user of this is Ada, which encodes the needed information using
8883 the names of types. */
8889 case PREINCREMENT_EXPR
:
8890 case PREDECREMENT_EXPR
:
8891 case POSTINCREMENT_EXPR
:
8892 case POSTDECREMENT_EXPR
:
8893 /* There are no opcodes for these operations. */
8897 /* We can support this only if we can look through conversions and
8898 find an INDIRECT_EXPR. */
8899 for (loc
= TREE_OPERAND (loc
, 0);
8900 TREE_CODE (loc
) == CONVERT_EXPR
|| TREE_CODE (loc
) == NOP_EXPR
8901 || TREE_CODE (loc
) == NON_LVALUE_EXPR
8902 || TREE_CODE (loc
) == VIEW_CONVERT_EXPR
8903 || TREE_CODE (loc
) == SAVE_EXPR
;
8904 loc
= TREE_OPERAND (loc
, 0))
8907 return (TREE_CODE (loc
) == INDIRECT_REF
8908 ? loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
)
8912 if (DECL_THREAD_LOCAL (loc
))
8916 #ifndef ASM_OUTPUT_DWARF_DTPREL
8917 /* If this is not defined, we have no way to emit the data. */
8921 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8922 look up addresses of objects in the current module. */
8923 if (DECL_EXTERNAL (loc
))
8926 rtl
= rtl_for_decl_location (loc
);
8927 if (rtl
== NULL_RTX
)
8930 if (GET_CODE (rtl
) != MEM
)
8932 rtl
= XEXP (rtl
, 0);
8933 if (! CONSTANT_P (rtl
))
8936 ret
= new_loc_descr (INTERNAL_DW_OP_tls_addr
, 0, 0);
8937 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
8938 ret
->dw_loc_oprnd1
.v
.val_addr
= rtl
;
8940 ret1
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
8941 add_loc_descr (&ret
, ret1
);
8951 rtx rtl
= rtl_for_decl_location (loc
);
8953 if (rtl
== NULL_RTX
)
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
;
8964 enum machine_mode mode
= GET_MODE (rtl
);
8966 if (GET_CODE (rtl
) == MEM
)
8969 rtl
= XEXP (rtl
, 0);
8972 ret
= mem_loc_descriptor (rtl
, mode
, true);
8978 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
8983 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), addressp
);
8987 case NON_LVALUE_EXPR
:
8988 case VIEW_CONVERT_EXPR
:
8991 return loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), addressp
);
8996 case ARRAY_RANGE_REF
:
8999 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
9000 enum machine_mode mode
;
9003 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
9004 &unsignedp
, &volatilep
);
9009 ret
= loc_descriptor_from_tree (obj
, 1);
9011 || bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
9014 if (offset
!= NULL_TREE
)
9016 /* Variable offset. */
9017 add_loc_descr (&ret
, loc_descriptor_from_tree (offset
, 0));
9018 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));
9036 if (host_integerp (loc
, 0))
9037 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
9044 /* Get an RTL for this, if something has been emitted. */
9045 rtx rtl
= lookup_constant_def (loc
);
9046 enum machine_mode mode
;
9048 if (GET_CODE (rtl
) != MEM
)
9050 mode
= GET_MODE (rtl
);
9051 rtl
= XEXP (rtl
, 0);
9053 rtl
= targetm
.delegitimize_address (rtl
);
9056 ret
= mem_loc_descriptor (rtl
, mode
, true);
9060 case TRUTH_AND_EXPR
:
9061 case TRUTH_ANDIF_EXPR
:
9066 case TRUTH_XOR_EXPR
:
9072 case TRUTH_ORIF_EXPR
:
9077 case FLOOR_DIV_EXPR
:
9079 case ROUND_DIV_EXPR
:
9080 case TRUNC_DIV_EXPR
:
9088 case FLOOR_MOD_EXPR
:
9090 case ROUND_MOD_EXPR
:
9091 case TRUNC_MOD_EXPR
:
9104 op
= (unsignedp
? DW_OP_shr
: DW_OP_shra
);
9108 if (TREE_CODE (TREE_OPERAND (loc
, 1)) == INTEGER_CST
9109 && host_integerp (TREE_OPERAND (loc
, 1), 0))
9111 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9115 add_loc_descr (&ret
,
9116 new_loc_descr (DW_OP_plus_uconst
,
9117 tree_low_cst (TREE_OPERAND (loc
, 1),
9127 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9134 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9141 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9148 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
9163 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9164 ret1
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
9165 if (ret
== 0 || ret1
== 0)
9168 add_loc_descr (&ret
, ret1
);
9169 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9172 case TRUTH_NOT_EXPR
:
9186 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9190 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
9196 const enum tree_code code
=
9197 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
9199 loc
= build (COND_EXPR
, TREE_TYPE (loc
),
9200 build (code
, integer_type_node
,
9201 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
9202 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
9205 /* ... fall through ... */
9209 dw_loc_descr_ref lhs
9210 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
9211 dw_loc_descr_ref rhs
9212 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 2), 0);
9213 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
9215 ret
= loc_descriptor_from_tree (TREE_OPERAND (loc
, 0), 0);
9216 if (ret
== 0 || lhs
== 0 || rhs
== 0)
9219 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
9220 add_loc_descr (&ret
, bra_node
);
9222 add_loc_descr (&ret
, rhs
);
9223 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
9224 add_loc_descr (&ret
, jump_node
);
9226 add_loc_descr (&ret
, lhs
);
9227 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9228 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
9230 /* ??? Need a node to point the skip at. Use a nop. */
9231 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
9232 add_loc_descr (&ret
, tmp
);
9233 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
9234 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
9239 /* Leave front-end specific codes as simply unknown. This comes
9240 up, for instance, with the C STMT_EXPR. */
9241 if ((unsigned int) TREE_CODE (loc
)
9242 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
9245 /* Otherwise this is a generic code; we should just lists all of
9246 these explicitly. Aborting means we forgot one. */
9250 /* Show if we can't fill the request for an address. */
9251 if (addressp
&& indirect_p
== 0)
9254 /* If we've got an address and don't want one, dereference. */
9255 if (!addressp
&& indirect_p
> 0)
9257 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
9259 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
9261 else if (size
== DWARF2_ADDR_SIZE
)
9264 op
= DW_OP_deref_size
;
9266 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
9272 /* Given a value, round it up to the lowest multiple of `boundary'
9273 which is not less than the value itself. */
9275 static inline HOST_WIDE_INT
9276 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
9278 return (((value
+ boundary
- 1) / boundary
) * boundary
);
9281 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9282 pointer to the declared type for the relevant field variable, or return
9283 `integer_type_node' if the given node turns out to be an
9287 field_type (tree decl
)
9291 if (TREE_CODE (decl
) == ERROR_MARK
)
9292 return integer_type_node
;
9294 type
= DECL_BIT_FIELD_TYPE (decl
);
9295 if (type
== NULL_TREE
)
9296 type
= TREE_TYPE (decl
);
9301 /* Given a pointer to a tree node, return the alignment in bits for
9302 it, or else return BITS_PER_WORD if the node actually turns out to
9303 be an ERROR_MARK node. */
9305 static inline unsigned
9306 simple_type_align_in_bits (tree type
)
9308 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
9311 static inline unsigned
9312 simple_decl_align_in_bits (tree decl
)
9314 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
9317 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9318 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9319 or return 0 if we are unable to determine what that offset is, either
9320 because the argument turns out to be a pointer to an ERROR_MARK node, or
9321 because the offset is actually variable. (We can't handle the latter case
9324 static HOST_WIDE_INT
9325 field_byte_offset (tree decl
)
9327 unsigned int type_align_in_bits
;
9328 unsigned int decl_align_in_bits
;
9329 unsigned HOST_WIDE_INT type_size_in_bits
;
9330 HOST_WIDE_INT object_offset_in_bits
;
9332 tree field_size_tree
;
9333 HOST_WIDE_INT bitpos_int
;
9334 HOST_WIDE_INT deepest_bitpos
;
9335 unsigned HOST_WIDE_INT field_size_in_bits
;
9337 if (TREE_CODE (decl
) == ERROR_MARK
)
9339 else if (TREE_CODE (decl
) != FIELD_DECL
)
9342 type
= field_type (decl
);
9343 field_size_tree
= DECL_SIZE (decl
);
9345 /* The size could be unspecified if there was an error, or for
9346 a flexible array member. */
9347 if (! field_size_tree
)
9348 field_size_tree
= bitsize_zero_node
;
9350 /* We cannot yet cope with fields whose positions are variable, so
9351 for now, when we see such things, we simply return 0. Someday, we may
9352 be able to handle such cases, but it will be damn difficult. */
9353 if (! host_integerp (bit_position (decl
), 0))
9356 bitpos_int
= int_bit_position (decl
);
9358 /* If we don't know the size of the field, pretend it's a full word. */
9359 if (host_integerp (field_size_tree
, 1))
9360 field_size_in_bits
= tree_low_cst (field_size_tree
, 1);
9362 field_size_in_bits
= BITS_PER_WORD
;
9364 type_size_in_bits
= simple_type_size_in_bits (type
);
9365 type_align_in_bits
= simple_type_align_in_bits (type
);
9366 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
9368 /* The GCC front-end doesn't make any attempt to keep track of the starting
9369 bit offset (relative to the start of the containing structure type) of the
9370 hypothetical "containing object" for a bit-field. Thus, when computing
9371 the byte offset value for the start of the "containing object" of a
9372 bit-field, we must deduce this information on our own. This can be rather
9373 tricky to do in some cases. For example, handling the following structure
9374 type definition when compiling for an i386/i486 target (which only aligns
9375 long long's to 32-bit boundaries) can be very tricky:
9377 struct S { int field1; long long field2:31; };
9379 Fortunately, there is a simple rule-of-thumb which can be used in such
9380 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9381 structure shown above. It decides to do this based upon one simple rule
9382 for bit-field allocation. GCC allocates each "containing object" for each
9383 bit-field at the first (i.e. lowest addressed) legitimate alignment
9384 boundary (based upon the required minimum alignment for the declared type
9385 of the field) which it can possibly use, subject to the condition that
9386 there is still enough available space remaining in the containing object
9387 (when allocated at the selected point) to fully accommodate all of the
9388 bits of the bit-field itself.
9390 This simple rule makes it obvious why GCC allocates 8 bytes for each
9391 object of the structure type shown above. When looking for a place to
9392 allocate the "containing object" for `field2', the compiler simply tries
9393 to allocate a 64-bit "containing object" at each successive 32-bit
9394 boundary (starting at zero) until it finds a place to allocate that 64-
9395 bit field such that at least 31 contiguous (and previously unallocated)
9396 bits remain within that selected 64 bit field. (As it turns out, for the
9397 example above, the compiler finds it is OK to allocate the "containing
9398 object" 64-bit field at bit-offset zero within the structure type.)
9400 Here we attempt to work backwards from the limited set of facts we're
9401 given, and we try to deduce from those facts, where GCC must have believed
9402 that the containing object started (within the structure type). The value
9403 we deduce is then used (by the callers of this routine) to generate
9404 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9405 and, in the case of DW_AT_location, regular fields as well). */
9407 /* Figure out the bit-distance from the start of the structure to the
9408 "deepest" bit of the bit-field. */
9409 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
9411 /* This is the tricky part. Use some fancy footwork to deduce where the
9412 lowest addressed bit of the containing object must be. */
9413 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9415 /* Round up to type_align by default. This works best for bitfields. */
9416 object_offset_in_bits
+= type_align_in_bits
- 1;
9417 object_offset_in_bits
/= type_align_in_bits
;
9418 object_offset_in_bits
*= type_align_in_bits
;
9420 if (object_offset_in_bits
> bitpos_int
)
9422 /* Sigh, the decl must be packed. */
9423 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
9425 /* Round up to decl_align instead. */
9426 object_offset_in_bits
+= decl_align_in_bits
- 1;
9427 object_offset_in_bits
/= decl_align_in_bits
;
9428 object_offset_in_bits
*= decl_align_in_bits
;
9431 return object_offset_in_bits
/ BITS_PER_UNIT
;
9434 /* The following routines define various Dwarf attributes and any data
9435 associated with them. */
9437 /* Add a location description attribute value to a DIE.
9439 This emits location attributes suitable for whole variables and
9440 whole parameters. Note that the location attributes for struct fields are
9441 generated by the routine `data_member_location_attribute' below. */
9444 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9445 dw_loc_descr_ref descr
)
9448 add_AT_loc (die
, attr_kind
, descr
);
9451 /* Attach the specialized form of location attribute used for data members of
9452 struct and union types. In the special case of a FIELD_DECL node which
9453 represents a bit-field, the "offset" part of this special location
9454 descriptor must indicate the distance in bytes from the lowest-addressed
9455 byte of the containing struct or union type to the lowest-addressed byte of
9456 the "containing object" for the bit-field. (See the `field_byte_offset'
9459 For any given bit-field, the "containing object" is a hypothetical object
9460 (of some integral or enum type) within which the given bit-field lives. The
9461 type of this hypothetical "containing object" is always the same as the
9462 declared type of the individual bit-field itself (for GCC anyway... the
9463 DWARF spec doesn't actually mandate this). Note that it is the size (in
9464 bytes) of the hypothetical "containing object" which will be given in the
9465 DW_AT_byte_size attribute for this bit-field. (See the
9466 `byte_size_attribute' function below.) It is also used when calculating the
9467 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9471 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
9473 HOST_WIDE_INT offset
;
9474 dw_loc_descr_ref loc_descr
= 0;
9476 if (TREE_CODE (decl
) == TREE_VEC
)
9478 /* We're working on the TAG_inheritance for a base class. */
9479 if (TREE_VIA_VIRTUAL (decl
) && is_cxx ())
9481 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9482 aren't at a fixed offset from all (sub)objects of the same
9483 type. We need to extract the appropriate offset from our
9484 vtable. The following dwarf expression means
9486 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9488 This is specific to the V3 ABI, of course. */
9490 dw_loc_descr_ref tmp
;
9492 /* Make a copy of the object address. */
9493 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
9494 add_loc_descr (&loc_descr
, tmp
);
9496 /* Extract the vtable address. */
9497 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9498 add_loc_descr (&loc_descr
, tmp
);
9500 /* Calculate the address of the offset. */
9501 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
9505 tmp
= int_loc_descriptor (-offset
);
9506 add_loc_descr (&loc_descr
, tmp
);
9507 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
9508 add_loc_descr (&loc_descr
, tmp
);
9510 /* Extract the offset. */
9511 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
9512 add_loc_descr (&loc_descr
, tmp
);
9514 /* Add it to the object address. */
9515 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
9516 add_loc_descr (&loc_descr
, tmp
);
9519 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
9522 offset
= field_byte_offset (decl
);
9526 enum dwarf_location_atom op
;
9528 /* The DWARF2 standard says that we should assume that the structure
9529 address is already on the stack, so we can specify a structure field
9530 address by using DW_OP_plus_uconst. */
9532 #ifdef MIPS_DEBUGGING_INFO
9533 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9534 operator correctly. It works only if we leave the offset on the
9538 op
= DW_OP_plus_uconst
;
9541 loc_descr
= new_loc_descr (op
, offset
, 0);
9544 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
9547 /* Writes integer values to dw_vec_const array. */
9550 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
9554 *dest
++ = val
& 0xff;
9560 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9562 static HOST_WIDE_INT
9563 extract_int (const unsigned char *src
, unsigned int size
)
9565 HOST_WIDE_INT val
= 0;
9571 val
|= *--src
& 0xff;
9577 /* Writes floating point values to dw_vec_const array. */
9580 insert_float (rtx rtl
, unsigned char *array
)
9586 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
9587 real_to_target (val
, &rv
, GET_MODE (rtl
));
9589 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9590 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
9592 insert_int (val
[i
], 4, array
);
9597 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9598 does not have a "location" either in memory or in a register. These
9599 things can arise in GNU C when a constant is passed as an actual parameter
9600 to an inlined function. They can also arise in C++ where declared
9601 constants do not necessarily get memory "homes". */
9604 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
9606 switch (GET_CODE (rtl
))
9610 HOST_WIDE_INT val
= INTVAL (rtl
);
9613 add_AT_int (die
, DW_AT_const_value
, val
);
9615 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
9620 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9621 floating-point constant. A CONST_DOUBLE is used whenever the
9622 constant requires more than one word in order to be adequately
9623 represented. We output CONST_DOUBLEs as blocks. */
9625 enum machine_mode mode
= GET_MODE (rtl
);
9627 if (GET_MODE_CLASS (mode
) == MODE_FLOAT
)
9629 unsigned int length
= GET_MODE_SIZE (mode
);
9630 unsigned char *array
= ggc_alloc (length
);
9632 insert_float (rtl
, array
);
9633 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
9637 /* ??? We really should be using HOST_WIDE_INT throughout. */
9638 if (HOST_BITS_PER_LONG
!= HOST_BITS_PER_WIDE_INT
)
9641 add_AT_long_long (die
, DW_AT_const_value
,
9642 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
9649 enum machine_mode mode
= GET_MODE (rtl
);
9650 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
9651 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
9652 unsigned char *array
= ggc_alloc (length
* elt_size
);
9656 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
9658 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9660 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9661 HOST_WIDE_INT lo
, hi
;
9662 if (GET_CODE (elt
) == CONST_INT
)
9667 else if (GET_CODE (elt
) == CONST_DOUBLE
)
9669 lo
= CONST_DOUBLE_LOW (elt
);
9670 hi
= CONST_DOUBLE_HIGH (elt
);
9675 if (elt_size
<= sizeof (HOST_WIDE_INT
))
9676 insert_int (lo
, elt_size
, p
);
9677 else if (elt_size
== 2 * sizeof (HOST_WIDE_INT
))
9679 unsigned char *p0
= p
;
9680 unsigned char *p1
= p
+ sizeof (HOST_WIDE_INT
);
9682 if (WORDS_BIG_ENDIAN
)
9687 insert_int (lo
, sizeof (HOST_WIDE_INT
), p0
);
9688 insert_int (hi
, sizeof (HOST_WIDE_INT
), p1
);
9694 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
9696 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
9698 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
9699 insert_float (elt
, p
);
9705 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
9710 add_AT_string (die
, DW_AT_const_value
, XSTR (rtl
, 0));
9716 add_AT_addr (die
, DW_AT_const_value
, rtl
);
9717 VARRAY_PUSH_RTX (used_rtx_varray
, rtl
);
9721 /* In cases where an inlined instance of an inline function is passed
9722 the address of an `auto' variable (which is local to the caller) we
9723 can get a situation where the DECL_RTL of the artificial local
9724 variable (for the inlining) which acts as a stand-in for the
9725 corresponding formal parameter (of the inline function) will look
9726 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9727 exactly a compile-time constant expression, but it isn't the address
9728 of the (artificial) local variable either. Rather, it represents the
9729 *value* which the artificial local variable always has during its
9730 lifetime. We currently have no way to represent such quasi-constant
9731 values in Dwarf, so for now we just punt and generate nothing. */
9735 /* No other kinds of rtx should be possible here. */
9742 rtl_for_decl_location (tree decl
)
9746 /* Here we have to decide where we are going to say the parameter "lives"
9747 (as far as the debugger is concerned). We only have a couple of
9748 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9750 DECL_RTL normally indicates where the parameter lives during most of the
9751 activation of the function. If optimization is enabled however, this
9752 could be either NULL or else a pseudo-reg. Both of those cases indicate
9753 that the parameter doesn't really live anywhere (as far as the code
9754 generation parts of GCC are concerned) during most of the function's
9755 activation. That will happen (for example) if the parameter is never
9756 referenced within the function.
9758 We could just generate a location descriptor here for all non-NULL
9759 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9760 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9761 where DECL_RTL is NULL or is a pseudo-reg.
9763 Note however that we can only get away with using DECL_INCOMING_RTL as
9764 a backup substitute for DECL_RTL in certain limited cases. In cases
9765 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9766 we can be sure that the parameter was passed using the same type as it is
9767 declared to have within the function, and that its DECL_INCOMING_RTL
9768 points us to a place where a value of that type is passed.
9770 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9771 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9772 because in these cases DECL_INCOMING_RTL points us to a value of some
9773 type which is *different* from the type of the parameter itself. Thus,
9774 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9775 such cases, the debugger would end up (for example) trying to fetch a
9776 `float' from a place which actually contains the first part of a
9777 `double'. That would lead to really incorrect and confusing
9778 output at debug-time.
9780 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9781 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9782 are a couple of exceptions however. On little-endian machines we can
9783 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9784 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9785 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9786 when (on a little-endian machine) a non-prototyped function has a
9787 parameter declared to be of type `short' or `char'. In such cases,
9788 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9789 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9790 passed `int' value. If the debugger then uses that address to fetch
9791 a `short' or a `char' (on a little-endian machine) the result will be
9792 the correct data, so we allow for such exceptional cases below.
9794 Note that our goal here is to describe the place where the given formal
9795 parameter lives during most of the function's activation (i.e. between the
9796 end of the prologue and the start of the epilogue). We'll do that as best
9797 as we can. Note however that if the given formal parameter is modified
9798 sometime during the execution of the function, then a stack backtrace (at
9799 debug-time) will show the function as having been called with the *new*
9800 value rather than the value which was originally passed in. This happens
9801 rarely enough that it is not a major problem, but it *is* a problem, and
9804 A future version of dwarf2out.c may generate two additional attributes for
9805 any given DW_TAG_formal_parameter DIE which will describe the "passed
9806 type" and the "passed location" for the given formal parameter in addition
9807 to the attributes we now generate to indicate the "declared type" and the
9808 "active location" for each parameter. This additional set of attributes
9809 could be used by debuggers for stack backtraces. Separately, note that
9810 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9811 This happens (for example) for inlined-instances of inline function formal
9812 parameters which are never referenced. This really shouldn't be
9813 happening. All PARM_DECL nodes should get valid non-NULL
9814 DECL_INCOMING_RTL values. FIXME. */
9816 /* Use DECL_RTL as the "location" unless we find something better. */
9817 rtl
= DECL_RTL_IF_SET (decl
);
9819 /* When generating abstract instances, ignore everything except
9820 constants, symbols living in memory, and symbols living in
9822 if (! reload_completed
)
9825 && (CONSTANT_P (rtl
)
9826 || (GET_CODE (rtl
) == MEM
9827 && CONSTANT_P (XEXP (rtl
, 0)))
9829 && TREE_CODE (decl
) == VAR_DECL
9830 && TREE_STATIC (decl
))))
9832 rtl
= targetm
.delegitimize_address (rtl
);
9837 else if (TREE_CODE (decl
) == PARM_DECL
)
9839 if (rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
9841 tree declared_type
= type_main_variant (TREE_TYPE (decl
));
9842 tree passed_type
= type_main_variant (DECL_ARG_TYPE (decl
));
9844 /* This decl represents a formal parameter which was optimized out.
9845 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
9846 all cases where (rtl == NULL_RTX) just below. */
9847 if (declared_type
== passed_type
)
9848 rtl
= DECL_INCOMING_RTL (decl
);
9849 else if (! BYTES_BIG_ENDIAN
9850 && TREE_CODE (declared_type
) == INTEGER_TYPE
9851 && (GET_MODE_SIZE (TYPE_MODE (declared_type
))
9852 <= GET_MODE_SIZE (TYPE_MODE (passed_type
))))
9853 rtl
= DECL_INCOMING_RTL (decl
);
9856 /* If the parm was passed in registers, but lives on the stack, then
9857 make a big endian correction if the mode of the type of the
9858 parameter is not the same as the mode of the rtl. */
9859 /* ??? This is the same series of checks that are made in dbxout.c before
9860 we reach the big endian correction code there. It isn't clear if all
9861 of these checks are necessary here, but keeping them all is the safe
9863 else if (GET_CODE (rtl
) == MEM
9864 && XEXP (rtl
, 0) != const0_rtx
9865 && ! CONSTANT_P (XEXP (rtl
, 0))
9866 /* Not passed in memory. */
9867 && GET_CODE (DECL_INCOMING_RTL (decl
)) != MEM
9868 /* Not passed by invisible reference. */
9869 && (!REG_P (XEXP (rtl
, 0))
9870 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
9871 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
9872 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
9873 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
9876 /* Big endian correction check. */
9878 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
9879 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
9882 int offset
= (UNITS_PER_WORD
9883 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
9885 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9886 plus_constant (XEXP (rtl
, 0), offset
));
9889 else if (TREE_CODE (decl
) == VAR_DECL
9891 && GET_CODE (rtl
) == MEM
9892 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
9893 && BYTES_BIG_ENDIAN
)
9895 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
9896 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
9898 /* If a variable is declared "register" yet is smaller than
9899 a register, then if we store the variable to memory, it
9900 looks like we're storing a register-sized value, when in
9901 fact we are not. We need to adjust the offset of the
9902 storage location to reflect the actual value's bytes,
9903 else gdb will not be able to display it. */
9905 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
9906 plus_constant (XEXP (rtl
, 0), rsize
-dsize
));
9909 if (rtl
!= NULL_RTX
)
9911 rtl
= eliminate_regs (rtl
, 0, NULL_RTX
);
9912 #ifdef LEAF_REG_REMAP
9913 if (current_function_uses_only_leaf_regs
)
9914 leaf_renumber_regs_insn (rtl
);
9918 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
9919 and will have been substituted directly into all expressions that use it.
9920 C does not have such a concept, but C++ and other languages do. */
9921 else if (TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
9923 /* If a variable is initialized with a string constant without embedded
9924 zeros, build CONST_STRING. */
9925 if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
9926 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
9928 tree arrtype
= TREE_TYPE (decl
);
9929 tree enttype
= TREE_TYPE (arrtype
);
9930 tree domain
= TYPE_DOMAIN (arrtype
);
9931 tree init
= DECL_INITIAL (decl
);
9932 enum machine_mode mode
= TYPE_MODE (enttype
);
9934 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
9936 && integer_zerop (TYPE_MIN_VALUE (domain
))
9937 && compare_tree_int (TYPE_MAX_VALUE (domain
),
9938 TREE_STRING_LENGTH (init
) - 1) == 0
9939 && ((size_t) TREE_STRING_LENGTH (init
)
9940 == strlen (TREE_STRING_POINTER (init
)) + 1))
9941 rtl
= gen_rtx_CONST_STRING (VOIDmode
, TREE_STRING_POINTER (init
));
9943 /* If the initializer is something that we know will expand into an
9944 immediate RTL constant, expand it now. Expanding anything else
9945 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9946 else if (TREE_CODE (DECL_INITIAL (decl
)) == INTEGER_CST
9947 || TREE_CODE (DECL_INITIAL (decl
)) == REAL_CST
)
9949 rtl
= expand_expr (DECL_INITIAL (decl
), NULL_RTX
, VOIDmode
,
9950 EXPAND_INITIALIZER
);
9951 /* If expand_expr returns a MEM, it wasn't immediate. */
9952 if (rtl
&& GET_CODE (rtl
) == MEM
)
9958 rtl
= targetm
.delegitimize_address (rtl
);
9960 /* If we don't look past the constant pool, we risk emitting a
9961 reference to a constant pool entry that isn't referenced from
9962 code, and thus is not emitted. */
9964 rtl
= avoid_constant_pool_reference (rtl
);
9969 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
9970 data attribute for a variable or a parameter. We generate the
9971 DW_AT_const_value attribute only in those cases where the given variable
9972 or parameter does not have a true "location" either in memory or in a
9973 register. This can happen (for example) when a constant is passed as an
9974 actual argument in a call to an inline function. (It's possible that
9975 these things can crop up in other ways also.) Note that one type of
9976 constant value which can be passed into an inlined function is a constant
9977 pointer. This can happen for example if an actual argument in an inlined
9978 function call evaluates to a compile-time constant address. */
9981 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
,
9982 enum dwarf_attribute attr
)
9985 dw_loc_descr_ref descr
;
9986 var_loc_list
*loc_list
;
9988 if (TREE_CODE (decl
) == ERROR_MARK
)
9990 else if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != PARM_DECL
9991 && TREE_CODE (decl
) != RESULT_DECL
)
9994 /* See if we possibly have multiple locations for this variable. */
9995 loc_list
= lookup_decl_loc (decl
);
9997 /* If it truly has multiple locations, the first and last node will
9999 if (loc_list
&& loc_list
->first
!= loc_list
->last
)
10001 const char *secname
;
10002 const char *endname
;
10003 dw_loc_list_ref list
;
10005 struct var_loc_node
*node
;
10007 /* We need to figure out what section we should use as the base
10008 for the address ranges where a given location is valid.
10009 1. If this particular DECL has a section associated with it,
10011 2. If this function has a section associated with it, use
10013 3. Otherwise, use the text section.
10014 XXX: If you split a variable across multiple sections, this
10017 if (DECL_SECTION_NAME (decl
))
10019 tree sectree
= DECL_SECTION_NAME (decl
);
10020 secname
= TREE_STRING_POINTER (sectree
);
10022 else if (current_function_decl
10023 && DECL_SECTION_NAME (current_function_decl
))
10025 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
10026 secname
= TREE_STRING_POINTER (sectree
);
10029 secname
= text_section_label
;
10031 /* Now that we know what section we are using for a base,
10032 actually construct the list of locations.
10033 The first location information is what is passed to the
10034 function that creates the location list, and the remaining
10035 locations just get added on to that list.
10036 Note that we only know the start address for a location
10037 (IE location changes), so to build the range, we use
10038 the range [current location start, next location start].
10039 This means we have to special case the last node, and generate
10040 a range of [last location start, end of function label]. */
10042 node
= loc_list
->first
;
10043 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10044 list
= new_loc_list (loc_descriptor (varloc
, attr
!= DW_AT_frame_base
),
10045 node
->label
, node
->next
->label
, secname
, 1);
10048 for (; node
->next
; node
= node
->next
)
10049 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10051 /* The variable has a location between NODE->LABEL and
10052 NODE->NEXT->LABEL. */
10053 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10054 add_loc_descr_to_loc_list (&list
,
10055 loc_descriptor (varloc
,
10056 attr
!= DW_AT_frame_base
),
10057 node
->label
, node
->next
->label
, secname
);
10060 /* If the variable has a location at the last label
10061 it keeps its location until the end of function. */
10062 if (NOTE_VAR_LOCATION_LOC (node
->var_loc_note
) != NULL_RTX
)
10064 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
10066 varloc
= NOTE_VAR_LOCATION (node
->var_loc_note
);
10067 if (!current_function_decl
)
10068 endname
= text_end_label
;
10071 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
10072 current_function_funcdef_no
);
10073 endname
= ggc_strdup (label_id
);
10075 add_loc_descr_to_loc_list (&list
,
10076 loc_descriptor (varloc
,
10077 attr
!= DW_AT_frame_base
),
10078 node
->label
, endname
, secname
);
10081 /* Finally, add the location list to the DIE, and we are done. */
10082 add_AT_loc_list (die
, attr
, list
);
10086 rtl
= rtl_for_decl_location (decl
);
10087 if (rtl
== NULL_RTX
)
10090 switch (GET_CODE (rtl
))
10093 /* The address of a variable that was optimized away;
10094 don't emit anything. */
10105 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
10106 add_const_value_attribute (die
, rtl
);
10110 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
10112 /* Need loc_descriptor_from_tree since that's where we know
10113 how to handle TLS variables. Want the object's address
10114 since the top-level DW_AT_location assumes such. See
10115 the confusion in loc_descriptor for reference. */
10116 descr
= loc_descriptor_from_tree (decl
, 1);
10123 descr
= loc_descriptor (rtl
, true);
10125 add_AT_location_description (die
, attr
, descr
);
10130 rtvec par_elems
= XVEC (rtl
, 0);
10131 int num_elem
= GET_NUM_ELEM (par_elems
);
10132 enum machine_mode mode
;
10135 /* Create the first one, so we have something to add to. */
10136 descr
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0), true);
10137 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
10138 add_loc_descr (&descr
,
10139 new_loc_descr (DW_OP_piece
, GET_MODE_SIZE (mode
), 0));
10140 for (i
= 1; i
< num_elem
; i
++)
10142 dw_loc_descr_ref temp
;
10144 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0), true);
10145 add_loc_descr (&descr
, temp
);
10146 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
10147 add_loc_descr (&descr
,
10148 new_loc_descr (DW_OP_piece
,
10149 GET_MODE_SIZE (mode
), 0));
10152 add_AT_location_description (die
, DW_AT_location
, descr
);
10160 /* If we don't have a copy of this variable in memory for some reason (such
10161 as a C++ member constant that doesn't have an out-of-line definition),
10162 we should tell the debugger about the constant value. */
10165 tree_add_const_value_attribute (dw_die_ref var_die
, tree decl
)
10167 tree init
= DECL_INITIAL (decl
);
10168 tree type
= TREE_TYPE (decl
);
10170 if (TREE_READONLY (decl
) && ! TREE_THIS_VOLATILE (decl
) && init
10171 && initializer_constant_valid_p (init
, type
) == null_pointer_node
)
10176 switch (TREE_CODE (type
))
10179 if (host_integerp (init
, 0))
10180 add_AT_unsigned (var_die
, DW_AT_const_value
,
10181 tree_low_cst (init
, 0));
10183 add_AT_long_long (var_die
, DW_AT_const_value
,
10184 TREE_INT_CST_HIGH (init
),
10185 TREE_INT_CST_LOW (init
));
10192 /* Generate a DW_AT_name attribute given some string value to be included as
10193 the value of the attribute. */
10196 add_name_attribute (dw_die_ref die
, const char *name_string
)
10198 if (name_string
!= NULL
&& *name_string
!= 0)
10200 if (demangle_name_func
)
10201 name_string
= (*demangle_name_func
) (name_string
);
10203 add_AT_string (die
, DW_AT_name
, name_string
);
10207 /* Generate a DW_AT_comp_dir attribute for DIE. */
10210 add_comp_dir_attribute (dw_die_ref die
)
10212 const char *wd
= get_src_pwd ();
10214 add_AT_string (die
, DW_AT_comp_dir
, wd
);
10217 /* Given a tree node describing an array bound (either lower or upper) output
10218 a representation for that bound. */
10221 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
10223 switch (TREE_CODE (bound
))
10228 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10230 if (! host_integerp (bound
, 0)
10231 || (bound_attr
== DW_AT_lower_bound
10232 && (((is_c_family () || is_java ()) && integer_zerop (bound
))
10233 || (is_fortran () && integer_onep (bound
)))))
10234 /* Use the default. */
10237 add_AT_unsigned (subrange_die
, bound_attr
, tree_low_cst (bound
, 0));
10242 case NON_LVALUE_EXPR
:
10243 case VIEW_CONVERT_EXPR
:
10244 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
10248 /* If optimization is turned on, the SAVE_EXPRs that describe how to
10249 access the upper bound values may be bogus. If they refer to a
10250 register, they may only describe how to get at these values at the
10251 points in the generated code right after they have just been
10252 computed. Worse yet, in the typical case, the upper bound values
10253 will not even *be* computed in the optimized code (though the
10254 number of elements will), so these SAVE_EXPRs are entirely
10255 bogus. In order to compensate for this fact, we check here to see
10256 if optimization is enabled, and if so, we don't add an attribute
10257 for the (unknown and unknowable) upper bound. This should not
10258 cause too much trouble for existing (stupid?) debuggers because
10259 they have to deal with empty upper bounds location descriptions
10260 anyway in order to be able to deal with incomplete array types.
10261 Of course an intelligent debugger (GDB?) should be able to
10262 comprehend that a missing upper bound specification in an array
10263 type used for a storage class `auto' local array variable
10264 indicates that the upper bound is both unknown (at compile- time)
10265 and unknowable (at run-time) due to optimization.
10267 We assume that a MEM rtx is safe because gcc wouldn't put the
10268 value there unless it was going to be used repeatedly in the
10269 function, i.e. for cleanups. */
10270 if (SAVE_EXPR_RTL (bound
)
10271 && (! optimize
|| GET_CODE (SAVE_EXPR_RTL (bound
)) == MEM
))
10273 dw_die_ref ctx
= lookup_decl_die (current_function_decl
);
10274 dw_die_ref decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10275 rtx loc
= SAVE_EXPR_RTL (bound
);
10277 /* If the RTL for the SAVE_EXPR is memory, handle the case where
10278 it references an outer function's frame. */
10279 if (GET_CODE (loc
) == MEM
)
10281 rtx new_addr
= fix_lexical_addr (XEXP (loc
, 0), bound
);
10283 if (XEXP (loc
, 0) != new_addr
)
10284 loc
= gen_rtx_MEM (GET_MODE (loc
), new_addr
);
10287 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10288 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10289 add_AT_location_description (decl_die
, DW_AT_location
,
10290 loc_descriptor (loc
, true));
10291 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10294 /* Else leave out the attribute. */
10301 dw_die_ref decl_die
= lookup_decl_die (bound
);
10303 /* ??? Can this happen, or should the variable have been bound
10304 first? Probably it can, since I imagine that we try to create
10305 the types of parameters in the order in which they exist in
10306 the list, and won't have created a forward reference to a
10307 later parameter. */
10308 if (decl_die
!= NULL
)
10309 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10315 /* Otherwise try to create a stack operation procedure to
10316 evaluate the value of the array bound. */
10318 dw_die_ref ctx
, decl_die
;
10319 dw_loc_descr_ref loc
;
10321 loc
= loc_descriptor_from_tree (bound
, 0);
10325 if (current_function_decl
== 0)
10326 ctx
= comp_unit_die
;
10328 ctx
= lookup_decl_die (current_function_decl
);
10330 /* If we weren't able to find a context, it's most likely the case
10331 that we are processing the return type of the function. So
10332 make a SAVE_EXPR to point to it and have the limbo DIE code
10333 find the proper die. The save_expr function doesn't always
10334 make a SAVE_EXPR, so do it ourselves. */
10336 bound
= build (SAVE_EXPR
, TREE_TYPE (bound
), bound
,
10337 current_function_decl
, NULL_TREE
);
10339 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
10340 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
10341 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
10342 add_AT_loc (decl_die
, DW_AT_location
, loc
);
10344 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
10350 /* Note that the block of subscript information for an array type also
10351 includes information about the element type of type given array type. */
10354 add_subscript_info (dw_die_ref type_die
, tree type
)
10356 #ifndef MIPS_DEBUGGING_INFO
10357 unsigned dimension_number
;
10360 dw_die_ref subrange_die
;
10362 /* The GNU compilers represent multidimensional array types as sequences of
10363 one dimensional array types whose element types are themselves array
10364 types. Here we squish that down, so that each multidimensional array
10365 type gets only one array_type DIE in the Dwarf debugging info. The draft
10366 Dwarf specification say that we are allowed to do this kind of
10367 compression in C (because there is no difference between an array or
10368 arrays and a multidimensional array in C) but for other source languages
10369 (e.g. Ada) we probably shouldn't do this. */
10371 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10372 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10373 We work around this by disabling this feature. See also
10374 gen_array_type_die. */
10375 #ifndef MIPS_DEBUGGING_INFO
10376 for (dimension_number
= 0;
10377 TREE_CODE (type
) == ARRAY_TYPE
;
10378 type
= TREE_TYPE (type
), dimension_number
++)
10381 tree domain
= TYPE_DOMAIN (type
);
10383 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10384 and (in GNU C only) variable bounds. Handle all three forms
10386 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
10389 /* We have an array type with specified bounds. */
10390 lower
= TYPE_MIN_VALUE (domain
);
10391 upper
= TYPE_MAX_VALUE (domain
);
10393 /* Define the index type. */
10394 if (TREE_TYPE (domain
))
10396 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10397 TREE_TYPE field. We can't emit debug info for this
10398 because it is an unnamed integral type. */
10399 if (TREE_CODE (domain
) == INTEGER_TYPE
10400 && TYPE_NAME (domain
) == NULL_TREE
10401 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
10402 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
10405 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
10409 /* ??? If upper is NULL, the array has unspecified length,
10410 but it does have a lower bound. This happens with Fortran
10412 Since the debugger is definitely going to need to know N
10413 to produce useful results, go ahead and output the lower
10414 bound solo, and hope the debugger can cope. */
10416 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
10418 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
10421 /* Otherwise we have an array type with an unspecified length. The
10422 DWARF-2 spec does not say how to handle this; let's just leave out the
10428 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
10432 switch (TREE_CODE (tree_node
))
10437 case ENUMERAL_TYPE
:
10440 case QUAL_UNION_TYPE
:
10441 size
= int_size_in_bytes (tree_node
);
10444 /* For a data member of a struct or union, the DW_AT_byte_size is
10445 generally given as the number of bytes normally allocated for an
10446 object of the *declared* type of the member itself. This is true
10447 even for bit-fields. */
10448 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
10454 /* Note that `size' might be -1 when we get to this point. If it is, that
10455 indicates that the byte size of the entity in question is variable. We
10456 have no good way of expressing this fact in Dwarf at the present time,
10457 so just let the -1 pass on through. */
10458 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
10461 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10462 which specifies the distance in bits from the highest order bit of the
10463 "containing object" for the bit-field to the highest order bit of the
10466 For any given bit-field, the "containing object" is a hypothetical object
10467 (of some integral or enum type) within which the given bit-field lives. The
10468 type of this hypothetical "containing object" is always the same as the
10469 declared type of the individual bit-field itself. The determination of the
10470 exact location of the "containing object" for a bit-field is rather
10471 complicated. It's handled by the `field_byte_offset' function (above).
10473 Note that it is the size (in bytes) of the hypothetical "containing object"
10474 which will be given in the DW_AT_byte_size attribute for this bit-field.
10475 (See `byte_size_attribute' above). */
10478 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
10480 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
10481 tree type
= DECL_BIT_FIELD_TYPE (decl
);
10482 HOST_WIDE_INT bitpos_int
;
10483 HOST_WIDE_INT highest_order_object_bit_offset
;
10484 HOST_WIDE_INT highest_order_field_bit_offset
;
10485 HOST_WIDE_INT
unsigned bit_offset
;
10487 /* Must be a field and a bit field. */
10489 || TREE_CODE (decl
) != FIELD_DECL
)
10492 /* We can't yet handle bit-fields whose offsets are variable, so if we
10493 encounter such things, just return without generating any attribute
10494 whatsoever. Likewise for variable or too large size. */
10495 if (! host_integerp (bit_position (decl
), 0)
10496 || ! host_integerp (DECL_SIZE (decl
), 1))
10499 bitpos_int
= int_bit_position (decl
);
10501 /* Note that the bit offset is always the distance (in bits) from the
10502 highest-order bit of the "containing object" to the highest-order bit of
10503 the bit-field itself. Since the "high-order end" of any object or field
10504 is different on big-endian and little-endian machines, the computation
10505 below must take account of these differences. */
10506 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
10507 highest_order_field_bit_offset
= bitpos_int
;
10509 if (! BYTES_BIG_ENDIAN
)
10511 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
10512 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
10516 = (! BYTES_BIG_ENDIAN
10517 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
10518 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
10520 add_AT_unsigned (die
, DW_AT_bit_offset
, bit_offset
);
10523 /* For a FIELD_DECL node which represents a bit field, output an attribute
10524 which specifies the length in bits of the given field. */
10527 add_bit_size_attribute (dw_die_ref die
, tree decl
)
10529 /* Must be a field and a bit field. */
10530 if (TREE_CODE (decl
) != FIELD_DECL
10531 || ! DECL_BIT_FIELD_TYPE (decl
))
10534 if (host_integerp (DECL_SIZE (decl
), 1))
10535 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
10538 /* If the compiled language is ANSI C, then add a 'prototyped'
10539 attribute, if arg types are given for the parameters of a function. */
10542 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
10544 if (get_AT_unsigned (comp_unit_die
, DW_AT_language
) == DW_LANG_C89
10545 && TYPE_ARG_TYPES (func_type
) != NULL
)
10546 add_AT_flag (die
, DW_AT_prototyped
, 1);
10549 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10550 by looking in either the type declaration or object declaration
10554 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
10556 dw_die_ref origin_die
= NULL
;
10558 if (TREE_CODE (origin
) != FUNCTION_DECL
)
10560 /* We may have gotten separated from the block for the inlined
10561 function, if we're in an exception handler or some such; make
10562 sure that the abstract function has been written out.
10564 Doing this for nested functions is wrong, however; functions are
10565 distinct units, and our context might not even be inline. */
10569 fn
= TYPE_STUB_DECL (fn
);
10571 fn
= decl_function_context (fn
);
10573 dwarf2out_abstract_function (fn
);
10576 if (DECL_P (origin
))
10577 origin_die
= lookup_decl_die (origin
);
10578 else if (TYPE_P (origin
))
10579 origin_die
= lookup_type_die (origin
);
10581 if (origin_die
== NULL
)
10584 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
10587 /* We do not currently support the pure_virtual attribute. */
10590 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
10592 if (DECL_VINDEX (func_decl
))
10594 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
10596 if (host_integerp (DECL_VINDEX (func_decl
), 0))
10597 add_AT_loc (die
, DW_AT_vtable_elem_location
,
10598 new_loc_descr (DW_OP_constu
,
10599 tree_low_cst (DECL_VINDEX (func_decl
), 0),
10602 /* GNU extension: Record what type this method came from originally. */
10603 if (debug_info_level
> DINFO_LEVEL_TERSE
)
10604 add_AT_die_ref (die
, DW_AT_containing_type
,
10605 lookup_type_die (DECL_CONTEXT (func_decl
)));
10609 /* Add source coordinate attributes for the given decl. */
10612 add_src_coords_attributes (dw_die_ref die
, tree decl
)
10614 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
10615 unsigned file_index
= lookup_filename (s
.file
);
10617 add_AT_unsigned (die
, DW_AT_decl_file
, file_index
);
10618 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
10621 /* Add a DW_AT_name attribute and source coordinate attribute for the
10622 given decl, but only if it actually has a name. */
10625 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
10629 decl_name
= DECL_NAME (decl
);
10630 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
10632 add_name_attribute (die
, dwarf2_name (decl
, 0));
10633 if (! DECL_ARTIFICIAL (decl
))
10634 add_src_coords_attributes (die
, decl
);
10636 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
10637 && TREE_PUBLIC (decl
)
10638 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
10639 && !DECL_ABSTRACT (decl
))
10640 add_AT_string (die
, DW_AT_MIPS_linkage_name
,
10641 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
10644 #ifdef VMS_DEBUGGING_INFO
10645 /* Get the function's name, as described by its RTL. This may be different
10646 from the DECL_NAME name used in the source file. */
10647 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
10649 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
10650 XEXP (DECL_RTL (decl
), 0));
10651 VARRAY_PUSH_RTX (used_rtx_varray
, XEXP (DECL_RTL (decl
), 0));
10656 /* Push a new declaration scope. */
10659 push_decl_scope (tree scope
)
10661 VARRAY_PUSH_TREE (decl_scope_table
, scope
);
10664 /* Pop a declaration scope. */
10667 pop_decl_scope (void)
10669 if (VARRAY_ACTIVE_SIZE (decl_scope_table
) <= 0)
10672 VARRAY_POP (decl_scope_table
);
10675 /* Return the DIE for the scope that immediately contains this type.
10676 Non-named types get global scope. Named types nested in other
10677 types get their containing scope if it's open, or global scope
10678 otherwise. All other types (i.e. function-local named types) get
10679 the current active scope. */
10682 scope_die_for (tree t
, dw_die_ref context_die
)
10684 dw_die_ref scope_die
= NULL
;
10685 tree containing_scope
;
10688 /* Non-types always go in the current scope. */
10692 containing_scope
= TYPE_CONTEXT (t
);
10694 /* Use the containing namespace if it was passed in (for a declaration). */
10695 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
10697 if (context_die
== lookup_decl_die (containing_scope
))
10700 containing_scope
= NULL_TREE
;
10703 /* Ignore function type "scopes" from the C frontend. They mean that
10704 a tagged type is local to a parmlist of a function declarator, but
10705 that isn't useful to DWARF. */
10706 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
10707 containing_scope
= NULL_TREE
;
10709 if (containing_scope
== NULL_TREE
)
10710 scope_die
= comp_unit_die
;
10711 else if (TYPE_P (containing_scope
))
10713 /* For types, we can just look up the appropriate DIE. But
10714 first we check to see if we're in the middle of emitting it
10715 so we know where the new DIE should go. */
10716 for (i
= VARRAY_ACTIVE_SIZE (decl_scope_table
) - 1; i
>= 0; --i
)
10717 if (VARRAY_TREE (decl_scope_table
, i
) == containing_scope
)
10722 if (debug_info_level
> DINFO_LEVEL_TERSE
10723 && !TREE_ASM_WRITTEN (containing_scope
))
10726 /* If none of the current dies are suitable, we get file scope. */
10727 scope_die
= comp_unit_die
;
10730 scope_die
= lookup_type_die (containing_scope
);
10733 scope_die
= context_die
;
10738 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10741 local_scope_p (dw_die_ref context_die
)
10743 for (; context_die
; context_die
= context_die
->die_parent
)
10744 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
10745 || context_die
->die_tag
== DW_TAG_subprogram
)
10751 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10752 whether or not to treat a DIE in this context as a declaration. */
10755 class_or_namespace_scope_p (dw_die_ref context_die
)
10757 return (context_die
10758 && (context_die
->die_tag
== DW_TAG_structure_type
10759 || context_die
->die_tag
== DW_TAG_union_type
10760 || context_die
->die_tag
== DW_TAG_namespace
));
10763 /* Many forms of DIEs require a "type description" attribute. This
10764 routine locates the proper "type descriptor" die for the type given
10765 by 'type', and adds a DW_AT_type attribute below the given die. */
10768 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
10769 int decl_volatile
, dw_die_ref context_die
)
10771 enum tree_code code
= TREE_CODE (type
);
10772 dw_die_ref type_die
= NULL
;
10774 /* ??? If this type is an unnamed subrange type of an integral or
10775 floating-point type, use the inner type. This is because we have no
10776 support for unnamed types in base_type_die. This can happen if this is
10777 an Ada subrange type. Correct solution is emit a subrange type die. */
10778 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
)
10779 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
10780 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
10782 if (code
== ERROR_MARK
10783 /* Handle a special case. For functions whose return type is void, we
10784 generate *no* type attribute. (Note that no object may have type
10785 `void', so this only applies to function return types). */
10786 || code
== VOID_TYPE
)
10789 type_die
= modified_type_die (type
,
10790 decl_const
|| TYPE_READONLY (type
),
10791 decl_volatile
|| TYPE_VOLATILE (type
),
10794 if (type_die
!= NULL
)
10795 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
10798 /* Given a tree pointer to a struct, class, union, or enum type node, return
10799 a pointer to the (string) tag name for the given type, or zero if the type
10800 was declared without a tag. */
10802 static const char *
10803 type_tag (tree type
)
10805 const char *name
= 0;
10807 if (TYPE_NAME (type
) != 0)
10811 /* Find the IDENTIFIER_NODE for the type name. */
10812 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
10813 t
= TYPE_NAME (type
);
10815 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10816 a TYPE_DECL node, regardless of whether or not a `typedef' was
10818 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10819 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
10820 t
= DECL_NAME (TYPE_NAME (type
));
10822 /* Now get the name as a string, or invent one. */
10824 name
= IDENTIFIER_POINTER (t
);
10827 return (name
== 0 || *name
== '\0') ? 0 : name
;
10830 /* Return the type associated with a data member, make a special check
10831 for bit field types. */
10834 member_declared_type (tree member
)
10836 return (DECL_BIT_FIELD_TYPE (member
)
10837 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
10840 /* Get the decl's label, as described by its RTL. This may be different
10841 from the DECL_NAME name used in the source file. */
10844 static const char *
10845 decl_start_label (tree decl
)
10848 const char *fnname
;
10850 x
= DECL_RTL (decl
);
10851 if (GET_CODE (x
) != MEM
)
10855 if (GET_CODE (x
) != SYMBOL_REF
)
10858 fnname
= XSTR (x
, 0);
10863 /* These routines generate the internal representation of the DIE's for
10864 the compilation unit. Debugging information is collected by walking
10865 the declaration trees passed in from dwarf2out_decl(). */
10868 gen_array_type_die (tree type
, dw_die_ref context_die
)
10870 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
10871 dw_die_ref array_die
;
10874 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10875 the inner array type comes before the outer array type. Thus we must
10876 call gen_type_die before we call new_die. See below also. */
10877 #ifdef MIPS_DEBUGGING_INFO
10878 gen_type_die (TREE_TYPE (type
), context_die
);
10881 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
10882 add_name_attribute (array_die
, type_tag (type
));
10883 equate_type_number_to_die (type
, array_die
);
10885 if (TREE_CODE (type
) == VECTOR_TYPE
)
10887 /* The frontend feeds us a representation for the vector as a struct
10888 containing an array. Pull out the array type. */
10889 type
= TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type
)));
10890 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
10894 /* We default the array ordering. SDB will probably do
10895 the right things even if DW_AT_ordering is not present. It's not even
10896 an issue until we start to get into multidimensional arrays anyway. If
10897 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10898 then we'll have to put the DW_AT_ordering attribute back in. (But if
10899 and when we find out that we need to put these in, we will only do so
10900 for multidimensional arrays. */
10901 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
10904 #ifdef MIPS_DEBUGGING_INFO
10905 /* The SGI compilers handle arrays of unknown bound by setting
10906 AT_declaration and not emitting any subrange DIEs. */
10907 if (! TYPE_DOMAIN (type
))
10908 add_AT_flag (array_die
, DW_AT_declaration
, 1);
10911 add_subscript_info (array_die
, type
);
10913 /* Add representation of the type of the elements of this array type. */
10914 element_type
= TREE_TYPE (type
);
10916 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10917 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10918 We work around this by disabling this feature. See also
10919 add_subscript_info. */
10920 #ifndef MIPS_DEBUGGING_INFO
10921 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
10922 element_type
= TREE_TYPE (element_type
);
10924 gen_type_die (element_type
, context_die
);
10927 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
10931 gen_set_type_die (tree type
, dw_die_ref context_die
)
10933 dw_die_ref type_die
10934 = new_die (DW_TAG_set_type
, scope_die_for (type
, context_die
), type
);
10936 equate_type_number_to_die (type
, type_die
);
10937 add_type_attribute (type_die
, TREE_TYPE (type
), 0, 0, context_die
);
10942 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
10944 tree origin
= decl_ultimate_origin (decl
);
10945 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
10947 if (origin
!= NULL
)
10948 add_abstract_origin_attribute (decl_die
, origin
);
10951 add_name_and_src_coords_attributes (decl_die
, decl
);
10952 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
10953 0, 0, context_die
);
10956 if (DECL_ABSTRACT (decl
))
10957 equate_decl_number_to_die (decl
, decl_die
);
10959 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
10963 /* Walk through the list of incomplete types again, trying once more to
10964 emit full debugging info for them. */
10967 retry_incomplete_types (void)
10971 for (i
= VARRAY_ACTIVE_SIZE (incomplete_types
) - 1; i
>= 0; i
--)
10972 gen_type_die (VARRAY_TREE (incomplete_types
, i
), comp_unit_die
);
10975 /* Generate a DIE to represent an inlined instance of an enumeration type. */
10978 gen_inlined_enumeration_type_die (tree type
, dw_die_ref context_die
)
10980 dw_die_ref type_die
= new_die (DW_TAG_enumeration_type
, context_die
, type
);
10982 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10983 be incomplete and such types are not marked. */
10984 add_abstract_origin_attribute (type_die
, type
);
10987 /* Generate a DIE to represent an inlined instance of a structure type. */
10990 gen_inlined_structure_type_die (tree type
, dw_die_ref context_die
)
10992 dw_die_ref type_die
= new_die (DW_TAG_structure_type
, context_die
, type
);
10994 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
10995 be incomplete and such types are not marked. */
10996 add_abstract_origin_attribute (type_die
, type
);
10999 /* Generate a DIE to represent an inlined instance of a union type. */
11002 gen_inlined_union_type_die (tree type
, dw_die_ref context_die
)
11004 dw_die_ref type_die
= new_die (DW_TAG_union_type
, context_die
, type
);
11006 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11007 be incomplete and such types are not marked. */
11008 add_abstract_origin_attribute (type_die
, type
);
11011 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11012 include all of the information about the enumeration values also. Each
11013 enumerated type name/value is listed as a child of the enumerated type
11017 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
11019 dw_die_ref type_die
= lookup_type_die (type
);
11021 if (type_die
== NULL
)
11023 type_die
= new_die (DW_TAG_enumeration_type
,
11024 scope_die_for (type
, context_die
), type
);
11025 equate_type_number_to_die (type
, type_die
);
11026 add_name_attribute (type_die
, type_tag (type
));
11028 else if (! TYPE_SIZE (type
))
11031 remove_AT (type_die
, DW_AT_declaration
);
11033 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11034 given enum type is incomplete, do not generate the DW_AT_byte_size
11035 attribute or the DW_AT_element_list attribute. */
11036 if (TYPE_SIZE (type
))
11040 TREE_ASM_WRITTEN (type
) = 1;
11041 add_byte_size_attribute (type_die
, type
);
11042 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
11043 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
11045 /* If the first reference to this type was as the return type of an
11046 inline function, then it may not have a parent. Fix this now. */
11047 if (type_die
->die_parent
== NULL
)
11048 add_child_die (scope_die_for (type
, context_die
), type_die
);
11050 for (link
= TYPE_VALUES (type
);
11051 link
!= NULL
; link
= TREE_CHAIN (link
))
11053 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
11054 tree value
= TREE_VALUE (link
);
11056 add_name_attribute (enum_die
,
11057 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
11059 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
11060 /* DWARF2 does not provide a way of indicating whether or
11061 not enumeration constants are signed or unsigned. GDB
11062 always assumes the values are signed, so we output all
11063 values as if they were signed. That means that
11064 enumeration constants with very large unsigned values
11065 will appear to have negative values in the debugger. */
11066 add_AT_int (enum_die
, DW_AT_const_value
,
11067 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
11071 add_AT_flag (type_die
, DW_AT_declaration
, 1);
11076 /* Generate a DIE to represent either a real live formal parameter decl or to
11077 represent just the type of some formal parameter position in some function
11080 Note that this routine is a bit unusual because its argument may be a
11081 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11082 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11083 node. If it's the former then this function is being called to output a
11084 DIE to represent a formal parameter object (or some inlining thereof). If
11085 it's the latter, then this function is only being called to output a
11086 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11087 argument type of some subprogram type. */
11090 gen_formal_parameter_die (tree node
, dw_die_ref context_die
)
11092 dw_die_ref parm_die
11093 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
11096 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
11099 origin
= decl_ultimate_origin (node
);
11100 if (origin
!= NULL
)
11101 add_abstract_origin_attribute (parm_die
, origin
);
11104 add_name_and_src_coords_attributes (parm_die
, node
);
11105 add_type_attribute (parm_die
, TREE_TYPE (node
),
11106 TREE_READONLY (node
),
11107 TREE_THIS_VOLATILE (node
),
11109 if (DECL_ARTIFICIAL (node
))
11110 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11113 equate_decl_number_to_die (node
, parm_die
);
11114 if (! DECL_ABSTRACT (node
))
11115 add_location_or_const_value_attribute (parm_die
, node
, DW_AT_location
);
11120 /* We were called with some kind of a ..._TYPE node. */
11121 add_type_attribute (parm_die
, node
, 0, 0, context_die
);
11131 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11132 at the end of an (ANSI prototyped) formal parameters list. */
11135 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
11137 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
11140 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11141 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11142 parameters as specified in some function type specification (except for
11143 those which appear as part of a function *definition*). */
11146 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
11149 tree formal_type
= NULL
;
11150 tree first_parm_type
;
11153 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
11155 arg
= DECL_ARGUMENTS (function_or_method_type
);
11156 function_or_method_type
= TREE_TYPE (function_or_method_type
);
11161 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
11163 /* Make our first pass over the list of formal parameter types and output a
11164 DW_TAG_formal_parameter DIE for each one. */
11165 for (link
= first_parm_type
; link
; )
11167 dw_die_ref parm_die
;
11169 formal_type
= TREE_VALUE (link
);
11170 if (formal_type
== void_type_node
)
11173 /* Output a (nameless) DIE to represent the formal parameter itself. */
11174 parm_die
= gen_formal_parameter_die (formal_type
, context_die
);
11175 if ((TREE_CODE (function_or_method_type
) == METHOD_TYPE
11176 && link
== first_parm_type
)
11177 || (arg
&& DECL_ARTIFICIAL (arg
)))
11178 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
11180 link
= TREE_CHAIN (link
);
11182 arg
= TREE_CHAIN (arg
);
11185 /* If this function type has an ellipsis, add a
11186 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11187 if (formal_type
!= void_type_node
)
11188 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
11190 /* Make our second (and final) pass over the list of formal parameter types
11191 and output DIEs to represent those types (as necessary). */
11192 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
11193 link
&& TREE_VALUE (link
);
11194 link
= TREE_CHAIN (link
))
11195 gen_type_die (TREE_VALUE (link
), context_die
);
11198 /* We want to generate the DIE for TYPE so that we can generate the
11199 die for MEMBER, which has been defined; we will need to refer back
11200 to the member declaration nested within TYPE. If we're trying to
11201 generate minimal debug info for TYPE, processing TYPE won't do the
11202 trick; we need to attach the member declaration by hand. */
11205 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
11207 gen_type_die (type
, context_die
);
11209 /* If we're trying to avoid duplicate debug info, we may not have
11210 emitted the member decl for this function. Emit it now. */
11211 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
11212 && ! lookup_decl_die (member
))
11214 if (decl_ultimate_origin (member
))
11217 push_decl_scope (type
);
11218 if (TREE_CODE (member
) == FUNCTION_DECL
)
11219 gen_subprogram_die (member
, lookup_type_die (type
));
11221 gen_variable_die (member
, lookup_type_die (type
));
11227 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11228 may later generate inlined and/or out-of-line instances of. */
11231 dwarf2out_abstract_function (tree decl
)
11233 dw_die_ref old_die
;
11236 int was_abstract
= DECL_ABSTRACT (decl
);
11238 /* Make sure we have the actual abstract inline, not a clone. */
11239 decl
= DECL_ORIGIN (decl
);
11241 old_die
= lookup_decl_die (decl
);
11242 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
11243 /* We've already generated the abstract instance. */
11246 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11247 we don't get confused by DECL_ABSTRACT. */
11248 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11250 context
= decl_class_context (decl
);
11252 gen_type_die_for_member
11253 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die
);
11256 /* Pretend we've just finished compiling this function. */
11257 save_fn
= current_function_decl
;
11258 current_function_decl
= decl
;
11260 set_decl_abstract_flags (decl
, 1);
11261 dwarf2out_decl (decl
);
11262 if (! was_abstract
)
11263 set_decl_abstract_flags (decl
, 0);
11265 current_function_decl
= save_fn
;
11268 /* Generate a DIE to represent a declared function (either file-scope or
11272 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
11274 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
11275 tree origin
= decl_ultimate_origin (decl
);
11276 dw_die_ref subr_die
;
11280 dw_die_ref old_die
= lookup_decl_die (decl
);
11281 int declaration
= (current_function_decl
!= decl
11282 || class_or_namespace_scope_p (context_die
));
11284 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11285 started to generate the abstract instance of an inline, decided to output
11286 its containing class, and proceeded to emit the declaration of the inline
11287 from the member list for the class. If so, DECLARATION takes priority;
11288 we'll get back to the abstract instance when done with the class. */
11290 /* The class-scope declaration DIE must be the primary DIE. */
11291 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
11298 if (origin
!= NULL
)
11300 if (declaration
&& ! local_scope_p (context_die
))
11303 /* Fixup die_parent for the abstract instance of a nested
11304 inline function. */
11305 if (old_die
&& old_die
->die_parent
== NULL
)
11306 add_child_die (context_die
, old_die
);
11308 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11309 add_abstract_origin_attribute (subr_die
, origin
);
11313 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11314 unsigned file_index
= lookup_filename (s
.file
);
11316 if (!get_AT_flag (old_die
, DW_AT_declaration
)
11317 /* We can have a normal definition following an inline one in the
11318 case of redefinition of GNU C extern inlines.
11319 It seems reasonable to use AT_specification in this case. */
11320 && !get_AT (old_die
, DW_AT_inline
))
11322 /* ??? This can happen if there is a bug in the program, for
11323 instance, if it has duplicate function definitions. Ideally,
11324 we should detect this case and ignore it. For now, if we have
11325 already reported an error, any error at all, then assume that
11326 we got here because of an input error, not a dwarf2 bug. */
11332 /* If the definition comes from the same place as the declaration,
11333 maybe use the old DIE. We always want the DIE for this function
11334 that has the *_pc attributes to be under comp_unit_die so the
11335 debugger can find it. We also need to do this for abstract
11336 instances of inlines, since the spec requires the out-of-line copy
11337 to have the same parent. For local class methods, this doesn't
11338 apply; we just use the old DIE. */
11339 if ((old_die
->die_parent
== comp_unit_die
|| context_die
== NULL
)
11340 && (DECL_ARTIFICIAL (decl
)
11341 || (get_AT_unsigned (old_die
, DW_AT_decl_file
) == file_index
11342 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11343 == (unsigned) s
.line
))))
11345 subr_die
= old_die
;
11347 /* Clear out the declaration attribute and the formal parameters.
11348 Do not remove all children, because it is possible that this
11349 declaration die was forced using force_decl_die(). In such
11350 cases die that forced declaration die (e.g. TAG_imported_module)
11351 is one of the children that we do not want to remove. */
11352 remove_AT (subr_die
, DW_AT_declaration
);
11353 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
11357 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11358 add_AT_specification (subr_die
, old_die
);
11359 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11360 add_AT_unsigned (subr_die
, DW_AT_decl_file
, file_index
);
11361 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11362 != (unsigned) s
.line
)
11364 (subr_die
, DW_AT_decl_line
, s
.line
);
11369 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
11371 if (TREE_PUBLIC (decl
))
11372 add_AT_flag (subr_die
, DW_AT_external
, 1);
11374 add_name_and_src_coords_attributes (subr_die
, decl
);
11375 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11377 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
11378 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
11379 0, 0, context_die
);
11382 add_pure_or_virtual_attribute (subr_die
, decl
);
11383 if (DECL_ARTIFICIAL (decl
))
11384 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
11386 if (TREE_PROTECTED (decl
))
11387 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11388 else if (TREE_PRIVATE (decl
))
11389 add_AT_unsigned (subr_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11394 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11396 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
11398 /* The first time we see a member function, it is in the context of
11399 the class to which it belongs. We make sure of this by emitting
11400 the class first. The next time is the definition, which is
11401 handled above. The two may come from the same source text.
11403 Note that force_decl_die() forces function declaration die. It is
11404 later reused to represent definition. */
11405 equate_decl_number_to_die (decl
, subr_die
);
11408 else if (DECL_ABSTRACT (decl
))
11410 if (DECL_DECLARED_INLINE_P (decl
))
11412 if (cgraph_function_possibly_inlined_p (decl
))
11413 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
11415 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
11419 if (cgraph_function_possibly_inlined_p (decl
))
11420 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
11422 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
11425 equate_decl_number_to_die (decl
, subr_die
);
11427 else if (!DECL_EXTERNAL (decl
))
11429 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
11430 equate_decl_number_to_die (decl
, subr_die
);
11432 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_BEGIN_LABEL
,
11433 current_function_funcdef_no
);
11434 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label_id
);
11435 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
11436 current_function_funcdef_no
);
11437 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label_id
);
11439 add_pubname (decl
, subr_die
);
11440 add_arange (decl
, subr_die
);
11442 #ifdef MIPS_DEBUGGING_INFO
11443 /* Add a reference to the FDE for this routine. */
11444 add_AT_fde_ref (subr_die
, DW_AT_MIPS_fde
, current_funcdef_fde
);
11447 /* Define the "frame base" location for this routine. We use the
11448 frame pointer or stack pointer registers, since the RTL for local
11449 variables is relative to one of them. */
11450 if (frame_base_decl
&& lookup_decl_loc (frame_base_decl
) != NULL
)
11452 add_location_or_const_value_attribute (subr_die
, frame_base_decl
,
11458 = frame_pointer_needed
? hard_frame_pointer_rtx
: stack_pointer_rtx
;
11459 add_AT_loc (subr_die
, DW_AT_frame_base
, reg_loc_descriptor (fp_reg
));
11462 if (cfun
->static_chain_decl
)
11463 add_AT_location_description (subr_die
, DW_AT_static_link
,
11464 loc_descriptor_from_tree (cfun
->static_chain_decl
, 0));
11467 /* Now output descriptions of the arguments for this function. This gets
11468 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11469 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11470 `...' at the end of the formal parameter list. In order to find out if
11471 there was a trailing ellipsis or not, we must instead look at the type
11472 associated with the FUNCTION_DECL. This will be a node of type
11473 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11474 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11475 an ellipsis at the end. */
11477 /* In the case where we are describing a mere function declaration, all we
11478 need to do here (and all we *can* do here) is to describe the *types* of
11479 its formal parameters. */
11480 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
11482 else if (declaration
)
11483 gen_formal_types_die (decl
, subr_die
);
11486 /* Generate DIEs to represent all known formal parameters. */
11487 tree arg_decls
= DECL_ARGUMENTS (decl
);
11490 /* When generating DIEs, generate the unspecified_parameters DIE
11491 instead if we come across the arg "__builtin_va_alist" */
11492 for (parm
= arg_decls
; parm
; parm
= TREE_CHAIN (parm
))
11493 if (TREE_CODE (parm
) == PARM_DECL
)
11495 if (DECL_NAME (parm
)
11496 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm
)),
11497 "__builtin_va_alist"))
11498 gen_unspecified_parameters_die (parm
, subr_die
);
11500 gen_decl_die (parm
, subr_die
);
11503 /* Decide whether we need an unspecified_parameters DIE at the end.
11504 There are 2 more cases to do this for: 1) the ansi ... declaration -
11505 this is detectable when the end of the arg list is not a
11506 void_type_node 2) an unprototyped function declaration (not a
11507 definition). This just means that we have no info about the
11508 parameters at all. */
11509 fn_arg_types
= TYPE_ARG_TYPES (TREE_TYPE (decl
));
11510 if (fn_arg_types
!= NULL
)
11512 /* This is the prototyped case, check for.... */
11513 if (TREE_VALUE (tree_last (fn_arg_types
)) != void_type_node
)
11514 gen_unspecified_parameters_die (decl
, subr_die
);
11516 else if (DECL_INITIAL (decl
) == NULL_TREE
)
11517 gen_unspecified_parameters_die (decl
, subr_die
);
11520 /* Output Dwarf info for all of the stuff within the body of the function
11521 (if it has one - it may be just a declaration). */
11522 outer_scope
= DECL_INITIAL (decl
);
11524 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11525 a function. This BLOCK actually represents the outermost binding contour
11526 for the function, i.e. the contour in which the function's formal
11527 parameters and labels get declared. Curiously, it appears that the front
11528 end doesn't actually put the PARM_DECL nodes for the current function onto
11529 the BLOCK_VARS list for this outer scope, but are strung off of the
11530 DECL_ARGUMENTS list for the function instead.
11532 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11533 the LABEL_DECL nodes for the function however, and we output DWARF info
11534 for those in decls_for_scope. Just within the `outer_scope' there will be
11535 a BLOCK node representing the function's outermost pair of curly braces,
11536 and any blocks used for the base and member initializers of a C++
11537 constructor function. */
11538 if (! declaration
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
11540 /* Emit a DW_TAG_variable DIE for a named return value. */
11541 if (DECL_NAME (DECL_RESULT (decl
)))
11542 gen_decl_die (DECL_RESULT (decl
), subr_die
);
11544 current_function_has_inlines
= 0;
11545 decls_for_scope (outer_scope
, subr_die
, 0);
11547 #if 0 && defined (MIPS_DEBUGGING_INFO)
11548 if (current_function_has_inlines
)
11550 add_AT_flag (subr_die
, DW_AT_MIPS_has_inlines
, 1);
11551 if (! comp_unit_has_inlines
)
11553 add_AT_flag (comp_unit_die
, DW_AT_MIPS_has_inlines
, 1);
11554 comp_unit_has_inlines
= 1;
11561 /* Generate a DIE to represent a declared data object. */
11564 gen_variable_die (tree decl
, dw_die_ref context_die
)
11566 tree origin
= decl_ultimate_origin (decl
);
11567 dw_die_ref var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
11569 dw_die_ref old_die
= lookup_decl_die (decl
);
11570 int declaration
= (DECL_EXTERNAL (decl
)
11571 || class_or_namespace_scope_p (context_die
));
11573 if (origin
!= NULL
)
11574 add_abstract_origin_attribute (var_die
, origin
);
11576 /* Loop unrolling can create multiple blocks that refer to the same
11577 static variable, so we must test for the DW_AT_declaration flag.
11579 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11580 copy decls and set the DECL_ABSTRACT flag on them instead of
11583 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
11584 else if (old_die
&& TREE_STATIC (decl
)
11585 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
11587 /* This is a definition of a C++ class level static. */
11588 add_AT_specification (var_die
, old_die
);
11589 if (DECL_NAME (decl
))
11591 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
11592 unsigned file_index
= lookup_filename (s
.file
);
11594 if (get_AT_unsigned (old_die
, DW_AT_decl_file
) != file_index
)
11595 add_AT_unsigned (var_die
, DW_AT_decl_file
, file_index
);
11597 if (get_AT_unsigned (old_die
, DW_AT_decl_line
)
11598 != (unsigned) s
.line
)
11600 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
11605 add_name_and_src_coords_attributes (var_die
, decl
);
11606 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
11607 TREE_THIS_VOLATILE (decl
), context_die
);
11609 if (TREE_PUBLIC (decl
))
11610 add_AT_flag (var_die
, DW_AT_external
, 1);
11612 if (DECL_ARTIFICIAL (decl
))
11613 add_AT_flag (var_die
, DW_AT_artificial
, 1);
11615 if (TREE_PROTECTED (decl
))
11616 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11617 else if (TREE_PRIVATE (decl
))
11618 add_AT_unsigned (var_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11622 add_AT_flag (var_die
, DW_AT_declaration
, 1);
11624 if (DECL_ABSTRACT (decl
) || declaration
)
11625 equate_decl_number_to_die (decl
, var_die
);
11627 if (! declaration
&& ! DECL_ABSTRACT (decl
))
11629 add_location_or_const_value_attribute (var_die
, decl
, DW_AT_location
);
11630 add_pubname (decl
, var_die
);
11633 tree_add_const_value_attribute (var_die
, decl
);
11636 /* Generate a DIE to represent a label identifier. */
11639 gen_label_die (tree decl
, dw_die_ref context_die
)
11641 tree origin
= decl_ultimate_origin (decl
);
11642 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
11644 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11646 if (origin
!= NULL
)
11647 add_abstract_origin_attribute (lbl_die
, origin
);
11649 add_name_and_src_coords_attributes (lbl_die
, decl
);
11651 if (DECL_ABSTRACT (decl
))
11652 equate_decl_number_to_die (decl
, lbl_die
);
11655 insn
= DECL_RTL_IF_SET (decl
);
11657 /* Deleted labels are programmer specified labels which have been
11658 eliminated because of various optimizations. We still emit them
11659 here so that it is possible to put breakpoints on them. */
11661 && (GET_CODE (insn
) == CODE_LABEL
11662 || ((GET_CODE (insn
) == NOTE
11663 && NOTE_LINE_NUMBER (insn
) == NOTE_INSN_DELETED_LABEL
))))
11665 /* When optimization is enabled (via -O) some parts of the compiler
11666 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11667 represent source-level labels which were explicitly declared by
11668 the user. This really shouldn't be happening though, so catch
11669 it if it ever does happen. */
11670 if (INSN_DELETED_P (insn
))
11673 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
11674 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
11679 /* Generate a DIE for a lexical block. */
11682 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
11684 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
11685 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11687 if (! BLOCK_ABSTRACT (stmt
))
11689 if (BLOCK_FRAGMENT_CHAIN (stmt
))
11693 add_AT_range_list (stmt_die
, DW_AT_ranges
, add_ranges (stmt
));
11695 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
11698 add_ranges (chain
);
11699 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
11706 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11707 BLOCK_NUMBER (stmt
));
11708 add_AT_lbl_id (stmt_die
, DW_AT_low_pc
, label
);
11709 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11710 BLOCK_NUMBER (stmt
));
11711 add_AT_lbl_id (stmt_die
, DW_AT_high_pc
, label
);
11715 decls_for_scope (stmt
, stmt_die
, depth
);
11718 /* Generate a DIE for an inlined subprogram. */
11721 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
11723 tree decl
= block_ultimate_origin (stmt
);
11725 /* Emit info for the abstract instance first, if we haven't yet. We
11726 must emit this even if the block is abstract, otherwise when we
11727 emit the block below (or elsewhere), we may end up trying to emit
11728 a die whose origin die hasn't been emitted, and crashing. */
11729 dwarf2out_abstract_function (decl
);
11731 if (! BLOCK_ABSTRACT (stmt
))
11733 dw_die_ref subr_die
11734 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
11735 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
11737 add_abstract_origin_attribute (subr_die
, decl
);
11738 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
11739 BLOCK_NUMBER (stmt
));
11740 add_AT_lbl_id (subr_die
, DW_AT_low_pc
, label
);
11741 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_END_LABEL
,
11742 BLOCK_NUMBER (stmt
));
11743 add_AT_lbl_id (subr_die
, DW_AT_high_pc
, label
);
11744 decls_for_scope (stmt
, subr_die
, depth
);
11745 current_function_has_inlines
= 1;
11748 /* We may get here if we're the outer block of function A that was
11749 inlined into function B that was inlined into function C. When
11750 generating debugging info for C, dwarf2out_abstract_function(B)
11751 would mark all inlined blocks as abstract, including this one.
11752 So, we wouldn't (and shouldn't) expect labels to be generated
11753 for this one. Instead, just emit debugging info for
11754 declarations within the block. This is particularly important
11755 in the case of initializers of arguments passed from B to us:
11756 if they're statement expressions containing declarations, we
11757 wouldn't generate dies for their abstract variables, and then,
11758 when generating dies for the real variables, we'd die (pun
11760 gen_lexical_block_die (stmt
, context_die
, depth
);
11763 /* Generate a DIE for a field in a record, or structure. */
11766 gen_field_die (tree decl
, dw_die_ref context_die
)
11768 dw_die_ref decl_die
;
11770 if (TREE_TYPE (decl
) == error_mark_node
)
11773 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
11774 add_name_and_src_coords_attributes (decl_die
, decl
);
11775 add_type_attribute (decl_die
, member_declared_type (decl
),
11776 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
11779 if (DECL_BIT_FIELD_TYPE (decl
))
11781 add_byte_size_attribute (decl_die
, decl
);
11782 add_bit_size_attribute (decl_die
, decl
);
11783 add_bit_offset_attribute (decl_die
, decl
);
11786 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
11787 add_data_member_location_attribute (decl_die
, decl
);
11789 if (DECL_ARTIFICIAL (decl
))
11790 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
11792 if (TREE_PROTECTED (decl
))
11793 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11794 else if (TREE_PRIVATE (decl
))
11795 add_AT_unsigned (decl_die
, DW_AT_accessibility
, DW_ACCESS_private
);
11799 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11800 Use modified_type_die instead.
11801 We keep this code here just in case these types of DIEs may be needed to
11802 represent certain things in other languages (e.g. Pascal) someday. */
11805 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
11808 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
11810 equate_type_number_to_die (type
, ptr_die
);
11811 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11812 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11815 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11816 Use modified_type_die instead.
11817 We keep this code here just in case these types of DIEs may be needed to
11818 represent certain things in other languages (e.g. Pascal) someday. */
11821 gen_reference_type_die (tree type
, dw_die_ref context_die
)
11824 = new_die (DW_TAG_reference_type
, scope_die_for (type
, context_die
), type
);
11826 equate_type_number_to_die (type
, ref_die
);
11827 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
11828 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
11832 /* Generate a DIE for a pointer to a member type. */
11835 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
11838 = new_die (DW_TAG_ptr_to_member_type
,
11839 scope_die_for (type
, context_die
), type
);
11841 equate_type_number_to_die (type
, ptr_die
);
11842 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
11843 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
11844 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
11847 /* Generate the DIE for the compilation unit. */
11850 gen_compile_unit_die (const char *filename
)
11853 char producer
[250];
11854 const char *language_string
= lang_hooks
.name
;
11857 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
11861 add_name_attribute (die
, filename
);
11862 /* Don't add cwd for <built-in>. */
11863 if (filename
[0] != DIR_SEPARATOR
&& filename
[0] != '<')
11864 add_comp_dir_attribute (die
);
11867 sprintf (producer
, "%s %s", language_string
, version_string
);
11869 #ifdef MIPS_DEBUGGING_INFO
11870 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11871 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11872 not appear in the producer string, the debugger reaches the conclusion
11873 that the object file is stripped and has no debugging information.
11874 To get the MIPS/SGI debugger to believe that there is debugging
11875 information in the object file, we add a -g to the producer string. */
11876 if (debug_info_level
> DINFO_LEVEL_TERSE
)
11877 strcat (producer
, " -g");
11880 add_AT_string (die
, DW_AT_producer
, producer
);
11882 if (strcmp (language_string
, "GNU C++") == 0)
11883 language
= DW_LANG_C_plus_plus
;
11884 else if (strcmp (language_string
, "GNU Ada") == 0)
11885 language
= DW_LANG_Ada95
;
11886 else if (strcmp (language_string
, "GNU F77") == 0)
11887 language
= DW_LANG_Fortran77
;
11888 else if (strcmp (language_string
, "GNU F95") == 0)
11889 language
= DW_LANG_Fortran95
;
11890 else if (strcmp (language_string
, "GNU Pascal") == 0)
11891 language
= DW_LANG_Pascal83
;
11892 else if (strcmp (language_string
, "GNU Java") == 0)
11893 language
= DW_LANG_Java
;
11895 language
= DW_LANG_C89
;
11897 add_AT_unsigned (die
, DW_AT_language
, language
);
11901 /* Generate a DIE for a string type. */
11904 gen_string_type_die (tree type
, dw_die_ref context_die
)
11906 dw_die_ref type_die
11907 = new_die (DW_TAG_string_type
, scope_die_for (type
, context_die
), type
);
11909 equate_type_number_to_die (type
, type_die
);
11911 /* ??? Fudge the string length attribute for now.
11912 TODO: add string length info. */
11914 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
11915 bound_representation (upper_bound
, 0, 'u');
11919 /* Generate the DIE for a base class. */
11922 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
11924 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
11926 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
11927 add_data_member_location_attribute (die
, binfo
);
11929 if (TREE_VIA_VIRTUAL (binfo
))
11930 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
11932 if (access
== access_public_node
)
11933 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
11934 else if (access
== access_protected_node
)
11935 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
11938 /* Generate a DIE for a class member. */
11941 gen_member_die (tree type
, dw_die_ref context_die
)
11944 tree binfo
= TYPE_BINFO (type
);
11947 /* If this is not an incomplete type, output descriptions of each of its
11948 members. Note that as we output the DIEs necessary to represent the
11949 members of this record or union type, we will also be trying to output
11950 DIEs to represent the *types* of those members. However the `type'
11951 function (above) will specifically avoid generating type DIEs for member
11952 types *within* the list of member DIEs for this (containing) type except
11953 for those types (of members) which are explicitly marked as also being
11954 members of this (containing) type themselves. The g++ front- end can
11955 force any given type to be treated as a member of some other (containing)
11956 type by setting the TYPE_CONTEXT of the given (member) type to point to
11957 the TREE node representing the appropriate (containing) type. */
11959 /* First output info about the base classes. */
11960 if (binfo
&& BINFO_BASETYPES (binfo
))
11962 tree bases
= BINFO_BASETYPES (binfo
);
11963 tree accesses
= BINFO_BASEACCESSES (binfo
);
11964 int n_bases
= TREE_VEC_LENGTH (bases
);
11967 for (i
= 0; i
< n_bases
; i
++)
11968 gen_inheritance_die (TREE_VEC_ELT (bases
, i
),
11969 (accesses
? TREE_VEC_ELT (accesses
, i
)
11970 : access_public_node
), context_die
);
11973 /* Now output info about the data members and type members. */
11974 for (member
= TYPE_FIELDS (type
); member
; member
= TREE_CHAIN (member
))
11976 /* If we thought we were generating minimal debug info for TYPE
11977 and then changed our minds, some of the member declarations
11978 may have already been defined. Don't define them again, but
11979 do put them in the right order. */
11981 child
= lookup_decl_die (member
);
11983 splice_child_die (context_die
, child
);
11985 gen_decl_die (member
, context_die
);
11988 /* Now output info about the function members (if any). */
11989 for (member
= TYPE_METHODS (type
); member
; member
= TREE_CHAIN (member
))
11991 /* Don't include clones in the member list. */
11992 if (DECL_ABSTRACT_ORIGIN (member
))
11995 child
= lookup_decl_die (member
);
11997 splice_child_die (context_die
, child
);
11999 gen_decl_die (member
, context_die
);
12003 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12004 is set, we pretend that the type was never defined, so we only get the
12005 member DIEs needed by later specification DIEs. */
12008 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
)
12010 dw_die_ref type_die
= lookup_type_die (type
);
12011 dw_die_ref scope_die
= 0;
12013 int complete
= (TYPE_SIZE (type
)
12014 && (! TYPE_STUB_DECL (type
)
12015 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
12016 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
12018 if (type_die
&& ! complete
)
12021 if (TYPE_CONTEXT (type
) != NULL_TREE
12022 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12023 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
12026 scope_die
= scope_die_for (type
, context_die
);
12028 if (! type_die
|| (nested
&& scope_die
== comp_unit_die
))
12029 /* First occurrence of type or toplevel definition of nested class. */
12031 dw_die_ref old_die
= type_die
;
12033 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
12034 ? DW_TAG_structure_type
: DW_TAG_union_type
,
12036 equate_type_number_to_die (type
, type_die
);
12038 add_AT_specification (type_die
, old_die
);
12040 add_name_attribute (type_die
, type_tag (type
));
12043 remove_AT (type_die
, DW_AT_declaration
);
12045 /* If this type has been completed, then give it a byte_size attribute and
12046 then give a list of members. */
12047 if (complete
&& !ns_decl
)
12049 /* Prevent infinite recursion in cases where the type of some member of
12050 this type is expressed in terms of this type itself. */
12051 TREE_ASM_WRITTEN (type
) = 1;
12052 add_byte_size_attribute (type_die
, type
);
12053 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
12054 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
12056 /* If the first reference to this type was as the return type of an
12057 inline function, then it may not have a parent. Fix this now. */
12058 if (type_die
->die_parent
== NULL
)
12059 add_child_die (scope_die
, type_die
);
12061 push_decl_scope (type
);
12062 gen_member_die (type
, type_die
);
12065 /* GNU extension: Record what type our vtable lives in. */
12066 if (TYPE_VFIELD (type
))
12068 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
12070 gen_type_die (vtype
, context_die
);
12071 add_AT_die_ref (type_die
, DW_AT_containing_type
,
12072 lookup_type_die (vtype
));
12077 add_AT_flag (type_die
, DW_AT_declaration
, 1);
12079 /* We don't need to do this for function-local types. */
12080 if (TYPE_STUB_DECL (type
)
12081 && ! decl_function_context (TYPE_STUB_DECL (type
)))
12082 VARRAY_PUSH_TREE (incomplete_types
, type
);
12086 /* Generate a DIE for a subroutine _type_. */
12089 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
12091 tree return_type
= TREE_TYPE (type
);
12092 dw_die_ref subr_die
12093 = new_die (DW_TAG_subroutine_type
,
12094 scope_die_for (type
, context_die
), type
);
12096 equate_type_number_to_die (type
, subr_die
);
12097 add_prototyped_attribute (subr_die
, type
);
12098 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
12099 gen_formal_types_die (type
, subr_die
);
12102 /* Generate a DIE for a type definition. */
12105 gen_typedef_die (tree decl
, dw_die_ref context_die
)
12107 dw_die_ref type_die
;
12110 if (TREE_ASM_WRITTEN (decl
))
12113 TREE_ASM_WRITTEN (decl
) = 1;
12114 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
12115 origin
= decl_ultimate_origin (decl
);
12116 if (origin
!= NULL
)
12117 add_abstract_origin_attribute (type_die
, origin
);
12122 add_name_and_src_coords_attributes (type_die
, decl
);
12123 if (DECL_ORIGINAL_TYPE (decl
))
12125 type
= DECL_ORIGINAL_TYPE (decl
);
12127 if (type
== TREE_TYPE (decl
))
12130 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
12133 type
= TREE_TYPE (decl
);
12135 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
12136 TREE_THIS_VOLATILE (decl
), context_die
);
12139 if (DECL_ABSTRACT (decl
))
12140 equate_decl_number_to_die (decl
, type_die
);
12143 /* Generate a type description DIE. */
12146 gen_type_die (tree type
, dw_die_ref context_die
)
12150 if (type
== NULL_TREE
|| type
== error_mark_node
)
12153 if (TYPE_NAME (type
) && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
12154 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
12156 if (TREE_ASM_WRITTEN (type
))
12159 /* Prevent broken recursion; we can't hand off to the same type. */
12160 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) == type
)
12163 TREE_ASM_WRITTEN (type
) = 1;
12164 gen_decl_die (TYPE_NAME (type
), context_die
);
12168 /* We are going to output a DIE to represent the unqualified version
12169 of this type (i.e. without any const or volatile qualifiers) so
12170 get the main variant (i.e. the unqualified version) of this type
12171 now. (Vectors are special because the debugging info is in the
12172 cloned type itself). */
12173 if (TREE_CODE (type
) != VECTOR_TYPE
)
12174 type
= type_main_variant (type
);
12176 if (TREE_ASM_WRITTEN (type
))
12179 switch (TREE_CODE (type
))
12185 case REFERENCE_TYPE
:
12186 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12187 ensures that the gen_type_die recursion will terminate even if the
12188 type is recursive. Recursive types are possible in Ada. */
12189 /* ??? We could perhaps do this for all types before the switch
12191 TREE_ASM_WRITTEN (type
) = 1;
12193 /* For these types, all that is required is that we output a DIE (or a
12194 set of DIEs) to represent the "basis" type. */
12195 gen_type_die (TREE_TYPE (type
), context_die
);
12199 /* This code is used for C++ pointer-to-data-member types.
12200 Output a description of the relevant class type. */
12201 gen_type_die (TYPE_OFFSET_BASETYPE (type
), context_die
);
12203 /* Output a description of the type of the object pointed to. */
12204 gen_type_die (TREE_TYPE (type
), context_die
);
12206 /* Now output a DIE to represent this pointer-to-data-member type
12208 gen_ptr_to_mbr_type_die (type
, context_die
);
12212 gen_type_die (TYPE_DOMAIN (type
), context_die
);
12213 gen_set_type_die (type
, context_die
);
12217 gen_type_die (TREE_TYPE (type
), context_die
);
12218 abort (); /* No way to represent these in Dwarf yet! */
12221 case FUNCTION_TYPE
:
12222 /* Force out return type (in case it wasn't forced out already). */
12223 gen_type_die (TREE_TYPE (type
), context_die
);
12224 gen_subroutine_type_die (type
, context_die
);
12228 /* Force out return type (in case it wasn't forced out already). */
12229 gen_type_die (TREE_TYPE (type
), context_die
);
12230 gen_subroutine_type_die (type
, context_die
);
12234 if (TYPE_STRING_FLAG (type
) && TREE_CODE (TREE_TYPE (type
)) == CHAR_TYPE
)
12236 gen_type_die (TREE_TYPE (type
), context_die
);
12237 gen_string_type_die (type
, context_die
);
12240 gen_array_type_die (type
, context_die
);
12244 gen_array_type_die (type
, context_die
);
12247 case ENUMERAL_TYPE
:
12250 case QUAL_UNION_TYPE
:
12251 /* If this is a nested type whose containing class hasn't been written
12252 out yet, writing it out will cover this one, too. This does not apply
12253 to instantiations of member class templates; they need to be added to
12254 the containing class as they are generated. FIXME: This hurts the
12255 idea of combining type decls from multiple TUs, since we can't predict
12256 what set of template instantiations we'll get. */
12257 if (TYPE_CONTEXT (type
)
12258 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
12259 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
12261 gen_type_die (TYPE_CONTEXT (type
), context_die
);
12263 if (TREE_ASM_WRITTEN (type
))
12266 /* If that failed, attach ourselves to the stub. */
12267 push_decl_scope (TYPE_CONTEXT (type
));
12268 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
12273 declare_in_namespace (type
, context_die
);
12277 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
12278 gen_enumeration_type_die (type
, context_die
);
12280 gen_struct_or_union_type_die (type
, context_die
);
12285 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12286 it up if it is ever completed. gen_*_type_die will set it for us
12287 when appropriate. */
12296 /* No DIEs needed for fundamental types. */
12300 /* No Dwarf representation currently defined. */
12307 TREE_ASM_WRITTEN (type
) = 1;
12310 /* Generate a DIE for a tagged type instantiation. */
12313 gen_tagged_type_instantiation_die (tree type
, dw_die_ref context_die
)
12315 if (type
== NULL_TREE
|| type
== error_mark_node
)
12318 /* We are going to output a DIE to represent the unqualified version of
12319 this type (i.e. without any const or volatile qualifiers) so make sure
12320 that we have the main variant (i.e. the unqualified version) of this
12322 if (type
!= type_main_variant (type
))
12325 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12326 an instance of an unresolved type. */
12328 switch (TREE_CODE (type
))
12333 case ENUMERAL_TYPE
:
12334 gen_inlined_enumeration_type_die (type
, context_die
);
12338 gen_inlined_structure_type_die (type
, context_die
);
12342 case QUAL_UNION_TYPE
:
12343 gen_inlined_union_type_die (type
, context_die
);
12351 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12352 things which are local to the given block. */
12355 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
12357 int must_output_die
= 0;
12360 enum tree_code origin_code
;
12362 /* Ignore blocks never really used to make RTL. */
12363 if (stmt
== NULL_TREE
|| !TREE_USED (stmt
)
12364 || (!TREE_ASM_WRITTEN (stmt
) && !BLOCK_ABSTRACT (stmt
)))
12367 /* If the block is one fragment of a non-contiguous block, do not
12368 process the variables, since they will have been done by the
12369 origin block. Do process subblocks. */
12370 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
12374 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
12375 gen_block_die (sub
, context_die
, depth
+ 1);
12380 /* Determine the "ultimate origin" of this block. This block may be an
12381 inlined instance of an inlined instance of inline function, so we have
12382 to trace all of the way back through the origin chain to find out what
12383 sort of node actually served as the original seed for the creation of
12384 the current block. */
12385 origin
= block_ultimate_origin (stmt
);
12386 origin_code
= (origin
!= NULL
) ? TREE_CODE (origin
) : ERROR_MARK
;
12388 /* Determine if we need to output any Dwarf DIEs at all to represent this
12390 if (origin_code
== FUNCTION_DECL
)
12391 /* The outer scopes for inlinings *must* always be represented. We
12392 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12393 must_output_die
= 1;
12396 /* In the case where the current block represents an inlining of the
12397 "body block" of an inline function, we must *NOT* output any DIE for
12398 this block because we have already output a DIE to represent the whole
12399 inlined function scope and the "body block" of any function doesn't
12400 really represent a different scope according to ANSI C rules. So we
12401 check here to make sure that this block does not represent a "body
12402 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12403 if (! is_body_block (origin
? origin
: stmt
))
12405 /* Determine if this block directly contains any "significant"
12406 local declarations which we will need to output DIEs for. */
12407 if (debug_info_level
> DINFO_LEVEL_TERSE
)
12408 /* We are not in terse mode so *any* local declaration counts
12409 as being a "significant" one. */
12410 must_output_die
= (BLOCK_VARS (stmt
) != NULL
);
12412 /* We are in terse mode, so only local (nested) function
12413 definitions count as "significant" local declarations. */
12414 for (decl
= BLOCK_VARS (stmt
);
12415 decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12416 if (TREE_CODE (decl
) == FUNCTION_DECL
12417 && DECL_INITIAL (decl
))
12419 must_output_die
= 1;
12425 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12426 DIE for any block which contains no significant local declarations at
12427 all. Rather, in such cases we just call `decls_for_scope' so that any
12428 needed Dwarf info for any sub-blocks will get properly generated. Note
12429 that in terse mode, our definition of what constitutes a "significant"
12430 local declaration gets restricted to include only inlined function
12431 instances and local (nested) function definitions. */
12432 if (must_output_die
)
12434 if (origin_code
== FUNCTION_DECL
)
12435 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
12437 gen_lexical_block_die (stmt
, context_die
, depth
);
12440 decls_for_scope (stmt
, context_die
, depth
);
12443 /* Generate all of the decls declared within a given scope and (recursively)
12444 all of its sub-blocks. */
12447 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
12452 /* Ignore blocks never really used to make RTL. */
12453 if (stmt
== NULL_TREE
|| ! TREE_USED (stmt
))
12456 /* Output the DIEs to represent all of the data objects and typedefs
12457 declared directly within this block but not within any nested
12458 sub-blocks. Also, nested function and tag DIEs have been
12459 generated with a parent of NULL; fix that up now. */
12460 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= TREE_CHAIN (decl
))
12464 if (TREE_CODE (decl
) == FUNCTION_DECL
)
12465 die
= lookup_decl_die (decl
);
12466 else if (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
))
12467 die
= lookup_type_die (TREE_TYPE (decl
));
12471 if (die
!= NULL
&& die
->die_parent
== NULL
)
12472 add_child_die (context_die
, die
);
12474 gen_decl_die (decl
, context_die
);
12477 /* If we're at -g1, we're not interested in subblocks. */
12478 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12481 /* Output the DIEs to represent all sub-blocks (and the items declared
12482 therein) of this block. */
12483 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
12485 subblocks
= BLOCK_CHAIN (subblocks
))
12486 gen_block_die (subblocks
, context_die
, depth
+ 1);
12489 /* Is this a typedef we can avoid emitting? */
12492 is_redundant_typedef (tree decl
)
12494 if (TYPE_DECL_IS_STUB (decl
))
12497 if (DECL_ARTIFICIAL (decl
)
12498 && DECL_CONTEXT (decl
)
12499 && is_tagged_type (DECL_CONTEXT (decl
))
12500 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
12501 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
12502 /* Also ignore the artificial member typedef for the class name. */
12508 /* Returns the DIE for decl or aborts. */
12511 force_decl_die (tree decl
)
12513 dw_die_ref decl_die
;
12514 unsigned saved_external_flag
;
12515 tree save_fn
= NULL_TREE
;
12516 decl_die
= lookup_decl_die (decl
);
12519 dw_die_ref context_die
;
12520 tree decl_context
= DECL_CONTEXT (decl
);
12523 /* Find die that represents this context. */
12524 if (TYPE_P (decl_context
))
12525 context_die
= force_type_die (decl_context
);
12527 context_die
= force_decl_die (decl_context
);
12530 context_die
= comp_unit_die
;
12532 switch (TREE_CODE (decl
))
12534 case FUNCTION_DECL
:
12535 /* Clear current_function_decl, so that gen_subprogram_die thinks
12536 that this is a declaration. At this point, we just want to force
12537 declaration die. */
12538 save_fn
= current_function_decl
;
12539 current_function_decl
= NULL_TREE
;
12540 gen_subprogram_die (decl
, context_die
);
12541 current_function_decl
= save_fn
;
12545 /* Set external flag to force declaration die. Restore it after
12546 gen_decl_die() call. */
12547 saved_external_flag
= DECL_EXTERNAL (decl
);
12548 DECL_EXTERNAL (decl
) = 1;
12549 gen_decl_die (decl
, context_die
);
12550 DECL_EXTERNAL (decl
) = saved_external_flag
;
12553 case NAMESPACE_DECL
:
12554 dwarf2out_decl (decl
);
12561 /* See if we can find the die for this deci now.
12562 If not then abort. */
12564 decl_die
= lookup_decl_die (decl
);
12572 /* Returns the DIE for decl or aborts. */
12575 force_type_die (tree type
)
12577 dw_die_ref type_die
;
12579 type_die
= lookup_type_die (type
);
12582 dw_die_ref context_die
;
12583 if (TYPE_CONTEXT (type
))
12584 if (TYPE_P (TYPE_CONTEXT (type
)))
12585 context_die
= force_type_die (TYPE_CONTEXT (type
));
12587 context_die
= force_decl_die (TYPE_CONTEXT (type
));
12589 context_die
= comp_unit_die
;
12591 gen_type_die (type
, context_die
);
12592 type_die
= lookup_type_die (type
);
12599 /* Force out any required namespaces to be able to output DECL,
12600 and return the new context_die for it, if it's changed. */
12603 setup_namespace_context (tree thing
, dw_die_ref context_die
)
12605 tree context
= DECL_P (thing
) ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
);
12606 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
12607 /* Force out the namespace. */
12608 context_die
= force_decl_die (context
);
12610 return context_die
;
12613 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12614 type) within its namespace, if appropriate.
12616 For compatibility with older debuggers, namespace DIEs only contain
12617 declarations; all definitions are emitted at CU scope. */
12620 declare_in_namespace (tree thing
, dw_die_ref context_die
)
12622 dw_die_ref ns_context
;
12624 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12627 ns_context
= setup_namespace_context (thing
, context_die
);
12629 if (ns_context
!= context_die
)
12631 if (DECL_P (thing
))
12632 gen_decl_die (thing
, ns_context
);
12634 gen_type_die (thing
, ns_context
);
12638 /* Generate a DIE for a namespace or namespace alias. */
12641 gen_namespace_die (tree decl
)
12643 dw_die_ref context_die
= setup_namespace_context (decl
, comp_unit_die
);
12645 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12646 they are an alias of. */
12647 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
12649 /* Output a real namespace. */
12650 dw_die_ref namespace_die
12651 = new_die (DW_TAG_namespace
, context_die
, decl
);
12652 add_name_and_src_coords_attributes (namespace_die
, decl
);
12653 equate_decl_number_to_die (decl
, namespace_die
);
12657 /* Output a namespace alias. */
12659 /* Force out the namespace we are an alias of, if necessary. */
12660 dw_die_ref origin_die
12661 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
12663 /* Now create the namespace alias DIE. */
12664 dw_die_ref namespace_die
12665 = new_die (DW_TAG_imported_declaration
, context_die
, decl
);
12666 add_name_and_src_coords_attributes (namespace_die
, decl
);
12667 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
12668 equate_decl_number_to_die (decl
, namespace_die
);
12672 /* Generate Dwarf debug information for a decl described by DECL. */
12675 gen_decl_die (tree decl
, dw_die_ref context_die
)
12679 if (DECL_P (decl
) && DECL_IGNORED_P (decl
))
12682 switch (TREE_CODE (decl
))
12688 /* The individual enumerators of an enum type get output when we output
12689 the Dwarf representation of the relevant enum type itself. */
12692 case FUNCTION_DECL
:
12693 /* Don't output any DIEs to represent mere function declarations,
12694 unless they are class members or explicit block externs. */
12695 if (DECL_INITIAL (decl
) == NULL_TREE
&& DECL_CONTEXT (decl
) == NULL_TREE
12696 && (current_function_decl
== NULL_TREE
|| DECL_ARTIFICIAL (decl
)))
12701 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
12702 on local redeclarations of global functions. That seems broken. */
12703 if (current_function_decl
!= decl
)
12704 /* This is only a declaration. */;
12707 /* If we're emitting a clone, emit info for the abstract instance. */
12708 if (DECL_ORIGIN (decl
) != decl
)
12709 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl
));
12711 /* If we're emitting an out-of-line copy of an inline function,
12712 emit info for the abstract instance and set up to refer to it. */
12713 else if (cgraph_function_possibly_inlined_p (decl
)
12714 && ! DECL_ABSTRACT (decl
)
12715 && ! class_or_namespace_scope_p (context_die
)
12716 /* dwarf2out_abstract_function won't emit a die if this is just
12717 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
12718 that case, because that works only if we have a die. */
12719 && DECL_INITIAL (decl
) != NULL_TREE
)
12721 dwarf2out_abstract_function (decl
);
12722 set_decl_origin_self (decl
);
12725 /* Otherwise we're emitting the primary DIE for this decl. */
12726 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
12728 /* Before we describe the FUNCTION_DECL itself, make sure that we
12729 have described its return type. */
12730 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
12732 /* And its virtual context. */
12733 if (DECL_VINDEX (decl
) != NULL_TREE
)
12734 gen_type_die (DECL_CONTEXT (decl
), context_die
);
12736 /* And its containing type. */
12737 origin
= decl_class_context (decl
);
12738 if (origin
!= NULL_TREE
)
12739 gen_type_die_for_member (origin
, decl
, context_die
);
12741 /* And its containing namespace. */
12742 declare_in_namespace (decl
, context_die
);
12745 /* Now output a DIE to represent the function itself. */
12746 gen_subprogram_die (decl
, context_die
);
12750 /* If we are in terse mode, don't generate any DIEs to represent any
12751 actual typedefs. */
12752 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12755 /* In the special case of a TYPE_DECL node representing the declaration
12756 of some type tag, if the given TYPE_DECL is marked as having been
12757 instantiated from some other (original) TYPE_DECL node (e.g. one which
12758 was generated within the original definition of an inline function) we
12759 have to generate a special (abbreviated) DW_TAG_structure_type,
12760 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
12761 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
12763 gen_tagged_type_instantiation_die (TREE_TYPE (decl
), context_die
);
12767 if (is_redundant_typedef (decl
))
12768 gen_type_die (TREE_TYPE (decl
), context_die
);
12770 /* Output a DIE to represent the typedef itself. */
12771 gen_typedef_die (decl
, context_die
);
12775 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
12776 gen_label_die (decl
, context_die
);
12781 /* If we are in terse mode, don't generate any DIEs to represent any
12782 variable declarations or definitions. */
12783 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12786 /* Output any DIEs that are needed to specify the type of this data
12788 gen_type_die (TREE_TYPE (decl
), context_die
);
12790 /* And its containing type. */
12791 origin
= decl_class_context (decl
);
12792 if (origin
!= NULL_TREE
)
12793 gen_type_die_for_member (origin
, decl
, context_die
);
12795 /* And its containing namespace. */
12796 declare_in_namespace (decl
, context_die
);
12798 /* Now output the DIE to represent the data object itself. This gets
12799 complicated because of the possibility that the VAR_DECL really
12800 represents an inlined instance of a formal parameter for an inline
12802 origin
= decl_ultimate_origin (decl
);
12803 if (origin
!= NULL_TREE
&& TREE_CODE (origin
) == PARM_DECL
)
12804 gen_formal_parameter_die (decl
, context_die
);
12806 gen_variable_die (decl
, context_die
);
12810 /* Ignore the nameless fields that are used to skip bits but handle C++
12811 anonymous unions and structs. */
12812 if (DECL_NAME (decl
) != NULL_TREE
12813 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
12814 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
12816 gen_type_die (member_declared_type (decl
), context_die
);
12817 gen_field_die (decl
, context_die
);
12822 gen_type_die (TREE_TYPE (decl
), context_die
);
12823 gen_formal_parameter_die (decl
, context_die
);
12826 case NAMESPACE_DECL
:
12827 gen_namespace_die (decl
);
12831 if ((int)TREE_CODE (decl
) > NUM_TREE_CODES
)
12832 /* Probably some frontend-internal decl. Assume we don't care. */
12838 /* Add Ada "use" clause information for SGI Workshop debugger. */
12841 dwarf2out_add_library_unit_info (const char *filename
, const char *context_list
)
12843 unsigned int file_index
;
12845 if (filename
!= NULL
)
12847 dw_die_ref unit_die
= new_die (DW_TAG_module
, comp_unit_die
, NULL
);
12848 tree context_list_decl
12849 = build_decl (LABEL_DECL
, get_identifier (context_list
),
12852 TREE_PUBLIC (context_list_decl
) = TRUE
;
12853 add_name_attribute (unit_die
, context_list
);
12854 file_index
= lookup_filename (filename
);
12855 add_AT_unsigned (unit_die
, DW_AT_decl_file
, file_index
);
12856 add_pubname (context_list_decl
, unit_die
);
12860 /* Output debug information for global decl DECL. Called from toplev.c after
12861 compilation proper has finished. */
12864 dwarf2out_global_decl (tree decl
)
12866 /* Output DWARF2 information for file-scope tentative data object
12867 declarations, file-scope (extern) function declarations (which had no
12868 corresponding body) and file-scope tagged type declarations and
12869 definitions which have not yet been forced out. */
12870 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
12871 dwarf2out_decl (decl
);
12874 /* Output debug information for type decl DECL. Called from toplev.c
12875 and from language front ends (to record built-in types). */
12877 dwarf2out_type_decl (tree decl
, int local
)
12880 dwarf2out_decl (decl
);
12883 /* Output debug information for imported module or decl. */
12886 dwarf2out_imported_module_or_decl (tree decl
, tree context
)
12888 dw_die_ref imported_die
, at_import_die
;
12889 dw_die_ref scope_die
;
12890 unsigned file_index
;
12891 expanded_location xloc
;
12893 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
12899 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
12900 We need decl DIE for reference and scope die. First, get DIE for the decl
12903 /* Get the scope die for decl context. Use comp_unit_die for global module
12904 or decl. If die is not found for non globals, force new die. */
12906 scope_die
= comp_unit_die
;
12907 else if (TYPE_P (context
))
12908 scope_die
= force_type_die (context
);
12910 scope_die
= force_decl_die (context
);
12912 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
12913 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
12914 at_import_die
= force_type_die (TREE_TYPE (decl
));
12916 at_import_die
= force_decl_die (decl
);
12918 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
12919 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
12920 imported_die
= new_die (DW_TAG_imported_module
, scope_die
, context
);
12922 imported_die
= new_die (DW_TAG_imported_declaration
, scope_die
, context
);
12924 xloc
= expand_location (input_location
);
12925 file_index
= lookup_filename (xloc
.file
);
12926 add_AT_unsigned (imported_die
, DW_AT_decl_file
, file_index
);
12927 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
12928 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
12931 /* Write the debugging output for DECL. */
12934 dwarf2out_decl (tree decl
)
12936 dw_die_ref context_die
= comp_unit_die
;
12938 switch (TREE_CODE (decl
))
12943 case FUNCTION_DECL
:
12944 /* What we would really like to do here is to filter out all mere
12945 file-scope declarations of file-scope functions which are never
12946 referenced later within this translation unit (and keep all of ones
12947 that *are* referenced later on) but we aren't clairvoyant, so we have
12948 no idea which functions will be referenced in the future (i.e. later
12949 on within the current translation unit). So here we just ignore all
12950 file-scope function declarations which are not also definitions. If
12951 and when the debugger needs to know something about these functions,
12952 it will have to hunt around and find the DWARF information associated
12953 with the definition of the function.
12955 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
12956 nodes represent definitions and which ones represent mere
12957 declarations. We have to check DECL_INITIAL instead. That's because
12958 the C front-end supports some weird semantics for "extern inline"
12959 function definitions. These can get inlined within the current
12960 translation unit (an thus, we need to generate Dwarf info for their
12961 abstract instances so that the Dwarf info for the concrete inlined
12962 instances can have something to refer to) but the compiler never
12963 generates any out-of-lines instances of such things (despite the fact
12964 that they *are* definitions).
12966 The important point is that the C front-end marks these "extern
12967 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
12968 them anyway. Note that the C++ front-end also plays some similar games
12969 for inline function definitions appearing within include files which
12970 also contain `#pragma interface' pragmas. */
12971 if (DECL_INITIAL (decl
) == NULL_TREE
)
12974 /* If we're a nested function, initially use a parent of NULL; if we're
12975 a plain function, this will be fixed up in decls_for_scope. If
12976 we're a method, it will be ignored, since we already have a DIE. */
12977 if (decl_function_context (decl
)
12978 /* But if we're in terse mode, we don't care about scope. */
12979 && debug_info_level
> DINFO_LEVEL_TERSE
)
12980 context_die
= NULL
;
12984 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
12985 declaration and if the declaration was never even referenced from
12986 within this entire compilation unit. We suppress these DIEs in
12987 order to save space in the .debug section (by eliminating entries
12988 which are probably useless). Note that we must not suppress
12989 block-local extern declarations (whether used or not) because that
12990 would screw-up the debugger's name lookup mechanism and cause it to
12991 miss things which really ought to be in scope at a given point. */
12992 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
12995 /* If we are in terse mode, don't generate any DIEs to represent any
12996 variable declarations or definitions. */
12997 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13001 case NAMESPACE_DECL
:
13002 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13004 if (lookup_decl_die (decl
) != NULL
)
13009 /* Don't emit stubs for types unless they are needed by other DIEs. */
13010 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
13013 /* Don't bother trying to generate any DIEs to represent any of the
13014 normal built-in types for the language we are compiling. */
13015 if (DECL_IS_BUILTIN (decl
))
13017 /* OK, we need to generate one for `bool' so GDB knows what type
13018 comparisons have. */
13019 if ((get_AT_unsigned (comp_unit_die
, DW_AT_language
)
13020 == DW_LANG_C_plus_plus
)
13021 && TREE_CODE (TREE_TYPE (decl
)) == BOOLEAN_TYPE
13022 && ! DECL_IGNORED_P (decl
))
13023 modified_type_die (TREE_TYPE (decl
), 0, 0, NULL
);
13028 /* If we are in terse mode, don't generate any DIEs for types. */
13029 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
13032 /* If we're a function-scope tag, initially use a parent of NULL;
13033 this will be fixed up in decls_for_scope. */
13034 if (decl_function_context (decl
))
13035 context_die
= NULL
;
13043 gen_decl_die (decl
, context_die
);
13046 /* Output a marker (i.e. a label) for the beginning of the generated code for
13047 a lexical block. */
13050 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
13051 unsigned int blocknum
)
13053 function_section (current_function_decl
);
13054 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
13057 /* Output a marker (i.e. a label) for the end of the generated code for a
13061 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
13063 function_section (current_function_decl
);
13064 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
13067 /* Returns nonzero if it is appropriate not to emit any debugging
13068 information for BLOCK, because it doesn't contain any instructions.
13070 Don't allow this for blocks with nested functions or local classes
13071 as we would end up with orphans, and in the presence of scheduling
13072 we may end up calling them anyway. */
13075 dwarf2out_ignore_block (tree block
)
13079 for (decl
= BLOCK_VARS (block
); decl
; decl
= TREE_CHAIN (decl
))
13080 if (TREE_CODE (decl
) == FUNCTION_DECL
13081 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
13087 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13088 dwarf2out.c) and return its "index". The index of each (known) filename is
13089 just a unique number which is associated with only that one filename. We
13090 need such numbers for the sake of generating labels (in the .debug_sfnames
13091 section) and references to those files numbers (in the .debug_srcinfo
13092 and.debug_macinfo sections). If the filename given as an argument is not
13093 found in our current list, add it to the list and assign it the next
13094 available unique index number. In order to speed up searches, we remember
13095 the index of the filename was looked up last. This handles the majority of
13099 lookup_filename (const char *file_name
)
13102 char *save_file_name
;
13104 /* Check to see if the file name that was searched on the previous
13105 call matches this file name. If so, return the index. */
13106 if (file_table_last_lookup_index
!= 0)
13109 = VARRAY_CHAR_PTR (file_table
, file_table_last_lookup_index
);
13110 if (strcmp (file_name
, last
) == 0)
13111 return file_table_last_lookup_index
;
13114 /* Didn't match the previous lookup, search the table */
13115 n
= VARRAY_ACTIVE_SIZE (file_table
);
13116 for (i
= 1; i
< n
; i
++)
13117 if (strcmp (file_name
, VARRAY_CHAR_PTR (file_table
, i
)) == 0)
13119 file_table_last_lookup_index
= i
;
13123 /* Add the new entry to the end of the filename table. */
13124 file_table_last_lookup_index
= n
;
13125 save_file_name
= (char *) ggc_strdup (file_name
);
13126 VARRAY_PUSH_CHAR_PTR (file_table
, save_file_name
);
13127 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13133 maybe_emit_file (int fileno
)
13135 if (DWARF2_ASM_LINE_DEBUG_INFO
&& fileno
> 0)
13137 if (!VARRAY_UINT (file_table_emitted
, fileno
))
13139 VARRAY_UINT (file_table_emitted
, fileno
) = ++emitcount
;
13140 fprintf (asm_out_file
, "\t.file %u ",
13141 VARRAY_UINT (file_table_emitted
, fileno
));
13142 output_quoted_string (asm_out_file
,
13143 VARRAY_CHAR_PTR (file_table
, fileno
));
13144 fputc ('\n', asm_out_file
);
13146 return VARRAY_UINT (file_table_emitted
, fileno
);
13153 init_file_table (void)
13155 /* Allocate the initial hunk of the file_table. */
13156 VARRAY_CHAR_PTR_INIT (file_table
, 64, "file_table");
13157 VARRAY_UINT_INIT (file_table_emitted
, 64, "file_table_emitted");
13159 /* Skip the first entry - file numbers begin at 1. */
13160 VARRAY_PUSH_CHAR_PTR (file_table
, NULL
);
13161 VARRAY_PUSH_UINT (file_table_emitted
, 0);
13162 file_table_last_lookup_index
= 0;
13165 /* Called by the final INSN scan whenever we see a var location. We
13166 use it to drop labels in the right places, and throw the location in
13167 our lookup table. */
13170 dwarf2out_var_location (rtx loc_note
)
13172 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
13173 struct var_loc_node
*newloc
;
13175 static rtx last_insn
;
13176 static const char *last_label
;
13178 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
13180 prev_insn
= PREV_INSN (loc_note
);
13182 newloc
= ggc_alloc_cleared (sizeof (struct var_loc_node
));
13183 /* If the insn we processed last time is the previous insn
13184 and it is also a var location note, use the label we emitted
13186 if (last_insn
!= NULL_RTX
13187 && last_insn
== prev_insn
13188 && GET_CODE (prev_insn
) == NOTE
13189 && NOTE_LINE_NUMBER (prev_insn
) == NOTE_INSN_VAR_LOCATION
)
13191 newloc
->label
= last_label
;
13195 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
13196 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
13198 newloc
->label
= ggc_strdup (loclabel
);
13200 newloc
->var_loc_note
= loc_note
;
13201 newloc
->next
= NULL
;
13203 last_insn
= loc_note
;
13204 last_label
= newloc
->label
;
13206 add_var_loc_to_decl (NOTE_VAR_LOCATION_DECL (loc_note
), newloc
);
13209 /* We need to reset the locations at the beginning of each
13210 function. We can't do this in the end_function hook, because the
13211 declarations that use the locations won't have been outputted when
13212 that hook is called. */
13215 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED
)
13217 htab_empty (decl_loc_table
);
13220 /* Output a label to mark the beginning of a source code line entry
13221 and record information relating to this source line, in
13222 'line_info_table' for later output of the .debug_line section. */
13225 dwarf2out_source_line (unsigned int line
, const char *filename
)
13227 if (debug_info_level
>= DINFO_LEVEL_NORMAL
13230 function_section (current_function_decl
);
13232 /* If requested, emit something human-readable. */
13233 if (flag_debug_asm
)
13234 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
,
13237 if (DWARF2_ASM_LINE_DEBUG_INFO
)
13239 unsigned file_num
= lookup_filename (filename
);
13241 file_num
= maybe_emit_file (file_num
);
13243 /* Emit the .loc directive understood by GNU as. */
13244 fprintf (asm_out_file
, "\t.loc %d %d 0\n", file_num
, line
);
13246 /* Indicate that line number info exists. */
13247 line_info_table_in_use
++;
13249 /* Indicate that multiple line number tables exist. */
13250 if (DECL_SECTION_NAME (current_function_decl
))
13251 separate_line_info_table_in_use
++;
13253 else if (DECL_SECTION_NAME (current_function_decl
))
13255 dw_separate_line_info_ref line_info
;
13256 targetm
.asm_out
.internal_label (asm_out_file
, SEPARATE_LINE_CODE_LABEL
,
13257 separate_line_info_table_in_use
);
13259 /* Expand the line info table if necessary. */
13260 if (separate_line_info_table_in_use
13261 == separate_line_info_table_allocated
)
13263 separate_line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13264 separate_line_info_table
13265 = ggc_realloc (separate_line_info_table
,
13266 separate_line_info_table_allocated
13267 * sizeof (dw_separate_line_info_entry
));
13268 memset (separate_line_info_table
13269 + separate_line_info_table_in_use
,
13271 (LINE_INFO_TABLE_INCREMENT
13272 * sizeof (dw_separate_line_info_entry
)));
13275 /* Add the new entry at the end of the line_info_table. */
13277 = &separate_line_info_table
[separate_line_info_table_in_use
++];
13278 line_info
->dw_file_num
= lookup_filename (filename
);
13279 line_info
->dw_line_num
= line
;
13280 line_info
->function
= current_function_funcdef_no
;
13284 dw_line_info_ref line_info
;
13286 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
,
13287 line_info_table_in_use
);
13289 /* Expand the line info table if necessary. */
13290 if (line_info_table_in_use
== line_info_table_allocated
)
13292 line_info_table_allocated
+= LINE_INFO_TABLE_INCREMENT
;
13294 = ggc_realloc (line_info_table
,
13295 (line_info_table_allocated
13296 * sizeof (dw_line_info_entry
)));
13297 memset (line_info_table
+ line_info_table_in_use
, 0,
13298 LINE_INFO_TABLE_INCREMENT
* sizeof (dw_line_info_entry
));
13301 /* Add the new entry at the end of the line_info_table. */
13302 line_info
= &line_info_table
[line_info_table_in_use
++];
13303 line_info
->dw_file_num
= lookup_filename (filename
);
13304 line_info
->dw_line_num
= line
;
13309 /* Record the beginning of a new source file. */
13312 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
13314 if (flag_eliminate_dwarf2_dups
)
13316 /* Record the beginning of the file for break_out_includes. */
13317 dw_die_ref bincl_die
;
13319 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die
, NULL
);
13320 add_AT_string (bincl_die
, DW_AT_name
, filename
);
13323 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13325 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13326 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
13327 dw2_asm_output_data_uleb128 (lineno
, "Included from line number %d",
13329 maybe_emit_file (lookup_filename (filename
));
13330 dw2_asm_output_data_uleb128 (lookup_filename (filename
),
13331 "Filename we just started");
13335 /* Record the end of a source file. */
13338 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
13340 if (flag_eliminate_dwarf2_dups
)
13341 /* Record the end of the file for break_out_includes. */
13342 new_die (DW_TAG_GNU_EINCL
, comp_unit_die
, NULL
);
13344 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13346 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13347 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13351 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13352 the tail part of the directive line, i.e. the part which is past the
13353 initial whitespace, #, whitespace, directive-name, whitespace part. */
13356 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
13357 const char *buffer ATTRIBUTE_UNUSED
)
13359 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13361 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13362 dw2_asm_output_data (1, DW_MACINFO_define
, "Define macro");
13363 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13364 dw2_asm_output_nstring (buffer
, -1, "The macro");
13368 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13369 the tail part of the directive line, i.e. the part which is past the
13370 initial whitespace, #, whitespace, directive-name, whitespace part. */
13373 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
13374 const char *buffer ATTRIBUTE_UNUSED
)
13376 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13378 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13379 dw2_asm_output_data (1, DW_MACINFO_undef
, "Undefine macro");
13380 dw2_asm_output_data_uleb128 (lineno
, "At line number %d", lineno
);
13381 dw2_asm_output_nstring (buffer
, -1, "The macro");
13385 /* Set up for Dwarf output at the start of compilation. */
13388 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
13390 init_file_table ();
13392 /* Allocate the decl_die_table. */
13393 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
13394 decl_die_table_eq
, NULL
);
13396 /* Allocate the decl_loc_table. */
13397 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
13398 decl_loc_table_eq
, NULL
);
13400 /* Allocate the initial hunk of the decl_scope_table. */
13401 VARRAY_TREE_INIT (decl_scope_table
, 256, "decl_scope_table");
13403 /* Allocate the initial hunk of the abbrev_die_table. */
13404 abbrev_die_table
= ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13405 * sizeof (dw_die_ref
));
13406 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
13407 /* Zero-th entry is allocated, but unused */
13408 abbrev_die_table_in_use
= 1;
13410 /* Allocate the initial hunk of the line_info_table. */
13411 line_info_table
= ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13412 * sizeof (dw_line_info_entry
));
13413 line_info_table_allocated
= LINE_INFO_TABLE_INCREMENT
;
13415 /* Zero-th entry is allocated, but unused */
13416 line_info_table_in_use
= 1;
13418 /* Generate the initial DIE for the .debug section. Note that the (string)
13419 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13420 will (typically) be a relative pathname and that this pathname should be
13421 taken as being relative to the directory from which the compiler was
13422 invoked when the given (base) source file was compiled. We will fill
13423 in this value in dwarf2out_finish. */
13424 comp_unit_die
= gen_compile_unit_die (NULL
);
13426 VARRAY_TREE_INIT (incomplete_types
, 64, "incomplete_types");
13428 VARRAY_RTX_INIT (used_rtx_varray
, 32, "used_rtx_varray");
13430 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
13431 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
13432 DEBUG_ABBREV_SECTION_LABEL
, 0);
13433 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
13434 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
13436 strcpy (text_section_label
, stripattributes (TEXT_SECTION_NAME
));
13438 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
13439 DEBUG_INFO_SECTION_LABEL
, 0);
13440 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
13441 DEBUG_LINE_SECTION_LABEL
, 0);
13442 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
13443 DEBUG_RANGES_SECTION_LABEL
, 0);
13444 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
13445 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
13446 named_section_flags (DEBUG_INFO_SECTION
, SECTION_DEBUG
);
13447 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
13448 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
13449 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
13451 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13453 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13454 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
13455 DEBUG_MACINFO_SECTION_LABEL
, 0);
13456 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
13459 if (DWARF2_GENERATE_TEXT_SECTION_LABEL
)
13462 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
13466 /* A helper function for dwarf2out_finish called through
13467 ht_forall. Emit one queued .debug_str string. */
13470 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
13472 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
13474 if (node
->form
== DW_FORM_strp
)
13476 named_section_flags (DEBUG_STR_SECTION
, DEBUG_STR_SECTION_FLAGS
);
13477 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
13478 assemble_string (node
->str
, strlen (node
->str
) + 1);
13486 /* Clear the marks for a die and its children.
13487 Be cool if the mark isn't set. */
13490 prune_unmark_dies (dw_die_ref die
)
13494 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13495 prune_unmark_dies (c
);
13499 /* Given DIE that we're marking as used, find any other dies
13500 it references as attributes and mark them as used. */
13503 prune_unused_types_walk_attribs (dw_die_ref die
)
13507 for (a
= die
->die_attr
; a
!= NULL
; a
= a
->dw_attr_next
)
13509 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
13511 /* A reference to another DIE.
13512 Make sure that it will get emitted. */
13513 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
13515 else if (a
->dw_attr
== DW_AT_decl_file
)
13517 /* A reference to a file. Make sure the file name is emitted. */
13518 a
->dw_attr_val
.v
.val_unsigned
=
13519 maybe_emit_file (a
->dw_attr_val
.v
.val_unsigned
);
13525 /* Mark DIE as being used. If DOKIDS is true, then walk down
13526 to DIE's children. */
13529 prune_unused_types_mark (dw_die_ref die
, int dokids
)
13533 if (die
->die_mark
== 0)
13535 /* We haven't done this node yet. Mark it as used. */
13538 /* We also have to mark its parents as used.
13539 (But we don't want to mark our parents' kids due to this.) */
13540 if (die
->die_parent
)
13541 prune_unused_types_mark (die
->die_parent
, 0);
13543 /* Mark any referenced nodes. */
13544 prune_unused_types_walk_attribs (die
);
13546 /* If this node is a specification,
13547 also mark the definition, if it exists. */
13548 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
13549 prune_unused_types_mark (die
->die_definition
, 1);
13552 if (dokids
&& die
->die_mark
!= 2)
13554 /* We need to walk the children, but haven't done so yet.
13555 Remember that we've walked the kids. */
13559 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13561 /* If this is an array type, we need to make sure our
13562 kids get marked, even if they're types. */
13563 if (die
->die_tag
== DW_TAG_array_type
)
13564 prune_unused_types_mark (c
, 1);
13566 prune_unused_types_walk (c
);
13572 /* Walk the tree DIE and mark types that we actually use. */
13575 prune_unused_types_walk (dw_die_ref die
)
13579 /* Don't do anything if this node is already marked. */
13583 switch (die
->die_tag
) {
13584 case DW_TAG_const_type
:
13585 case DW_TAG_packed_type
:
13586 case DW_TAG_pointer_type
:
13587 case DW_TAG_reference_type
:
13588 case DW_TAG_volatile_type
:
13589 case DW_TAG_typedef
:
13590 case DW_TAG_array_type
:
13591 case DW_TAG_structure_type
:
13592 case DW_TAG_union_type
:
13593 case DW_TAG_class_type
:
13594 case DW_TAG_friend
:
13595 case DW_TAG_variant_part
:
13596 case DW_TAG_enumeration_type
:
13597 case DW_TAG_subroutine_type
:
13598 case DW_TAG_string_type
:
13599 case DW_TAG_set_type
:
13600 case DW_TAG_subrange_type
:
13601 case DW_TAG_ptr_to_member_type
:
13602 case DW_TAG_file_type
:
13603 /* It's a type node --- don't mark it. */
13607 /* Mark everything else. */
13613 /* Now, mark any dies referenced from here. */
13614 prune_unused_types_walk_attribs (die
);
13616 /* Mark children. */
13617 for (c
= die
->die_child
; c
; c
= c
->die_sib
)
13618 prune_unused_types_walk (c
);
13622 /* Remove from the tree DIE any dies that aren't marked. */
13625 prune_unused_types_prune (dw_die_ref die
)
13627 dw_die_ref c
, p
, n
;
13628 if (!die
->die_mark
)
13632 for (c
= die
->die_child
; c
; c
= n
)
13637 prune_unused_types_prune (c
);
13645 die
->die_child
= n
;
13652 /* Remove dies representing declarations that we never use. */
13655 prune_unused_types (void)
13658 limbo_die_node
*node
;
13660 /* Clear all the marks. */
13661 prune_unmark_dies (comp_unit_die
);
13662 for (node
= limbo_die_list
; node
; node
= node
->next
)
13663 prune_unmark_dies (node
->die
);
13665 /* Set the mark on nodes that are actually used. */
13666 prune_unused_types_walk (comp_unit_die
);
13667 for (node
= limbo_die_list
; node
; node
= node
->next
)
13668 prune_unused_types_walk (node
->die
);
13670 /* Also set the mark on nodes referenced from the
13671 pubname_table or arange_table. */
13672 for (i
= 0; i
< pubname_table_in_use
; i
++)
13673 prune_unused_types_mark (pubname_table
[i
].die
, 1);
13674 for (i
= 0; i
< arange_table_in_use
; i
++)
13675 prune_unused_types_mark (arange_table
[i
], 1);
13677 /* Get rid of nodes that aren't marked. */
13678 prune_unused_types_prune (comp_unit_die
);
13679 for (node
= limbo_die_list
; node
; node
= node
->next
)
13680 prune_unused_types_prune (node
->die
);
13682 /* Leave the marks clear. */
13683 prune_unmark_dies (comp_unit_die
);
13684 for (node
= limbo_die_list
; node
; node
= node
->next
)
13685 prune_unmark_dies (node
->die
);
13688 /* Output stuff that dwarf requires at the end of every file,
13689 and generate the DWARF-2 debugging info. */
13692 dwarf2out_finish (const char *filename
)
13694 limbo_die_node
*node
, *next_node
;
13695 dw_die_ref die
= 0;
13697 /* Add the name for the main input file now. We delayed this from
13698 dwarf2out_init to avoid complications with PCH. */
13699 add_name_attribute (comp_unit_die
, filename
);
13700 if (filename
[0] != DIR_SEPARATOR
)
13701 add_comp_dir_attribute (comp_unit_die
);
13702 else if (get_AT (comp_unit_die
, DW_AT_comp_dir
) == NULL
)
13705 for (i
= 1; i
< VARRAY_ACTIVE_SIZE (file_table
); i
++)
13706 if (VARRAY_CHAR_PTR (file_table
, i
)[0] != DIR_SEPARATOR
13707 /* Don't add cwd for <built-in>. */
13708 && VARRAY_CHAR_PTR (file_table
, i
)[0] != '<')
13710 add_comp_dir_attribute (comp_unit_die
);
13715 /* Traverse the limbo die list, and add parent/child links. The only
13716 dies without parents that should be here are concrete instances of
13717 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
13718 For concrete instances, we can get the parent die from the abstract
13720 for (node
= limbo_die_list
; node
; node
= next_node
)
13722 next_node
= node
->next
;
13725 if (die
->die_parent
== NULL
)
13727 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
13731 add_child_die (origin
->die_parent
, die
);
13732 else if (die
== comp_unit_die
)
13734 /* If this was an expression for a bound involved in a function
13735 return type, it may be a SAVE_EXPR for which we weren't able
13736 to find a DIE previously. So try now. */
13737 else if (node
->created_for
13738 && TREE_CODE (node
->created_for
) == SAVE_EXPR
13739 && 0 != (origin
= (lookup_decl_die
13741 (node
->created_for
)))))
13742 add_child_die (origin
, die
);
13743 else if (errorcount
> 0 || sorrycount
> 0)
13744 /* It's OK to be confused by errors in the input. */
13745 add_child_die (comp_unit_die
, die
);
13746 else if (node
->created_for
13747 && ((DECL_P (node
->created_for
)
13748 && (context
= DECL_CONTEXT (node
->created_for
)))
13749 || (TYPE_P (node
->created_for
)
13750 && (context
= TYPE_CONTEXT (node
->created_for
))))
13751 && TREE_CODE (context
) == FUNCTION_DECL
)
13753 /* In certain situations, the lexical block containing a
13754 nested function can be optimized away, which results
13755 in the nested function die being orphaned. Likewise
13756 with the return type of that nested function. Force
13757 this to be a child of the containing function. */
13758 origin
= lookup_decl_die (context
);
13761 add_child_die (origin
, die
);
13768 limbo_die_list
= NULL
;
13770 /* Walk through the list of incomplete types again, trying once more to
13771 emit full debugging info for them. */
13772 retry_incomplete_types ();
13774 /* We need to reverse all the dies before break_out_includes, or
13775 we'll see the end of an include file before the beginning. */
13776 reverse_all_dies (comp_unit_die
);
13778 if (flag_eliminate_unused_debug_types
)
13779 prune_unused_types ();
13781 /* Generate separate CUs for each of the include files we've seen.
13782 They will go into limbo_die_list. */
13783 if (flag_eliminate_dwarf2_dups
)
13784 break_out_includes (comp_unit_die
);
13786 /* Traverse the DIE's and add add sibling attributes to those DIE's
13787 that have children. */
13788 add_sibling_attributes (comp_unit_die
);
13789 for (node
= limbo_die_list
; node
; node
= node
->next
)
13790 add_sibling_attributes (node
->die
);
13792 /* Output a terminator label for the .text section. */
13794 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
13796 /* Output the source line correspondence table. We must do this
13797 even if there is no line information. Otherwise, on an empty
13798 translation unit, we will generate a present, but empty,
13799 .debug_info section. IRIX 6.5 `nm' will then complain when
13800 examining the file. */
13801 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
13803 named_section_flags (DEBUG_LINE_SECTION
, SECTION_DEBUG
);
13804 output_line_info ();
13807 /* Output location list section if necessary. */
13808 if (have_location_lists
)
13810 /* Output the location lists info. */
13811 named_section_flags (DEBUG_LOC_SECTION
, SECTION_DEBUG
);
13812 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
,
13813 DEBUG_LOC_SECTION_LABEL
, 0);
13814 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
13815 output_location_lists (die
);
13816 have_location_lists
= 0;
13819 /* We can only use the low/high_pc attributes if all of the code was
13821 if (separate_line_info_table_in_use
== 0)
13823 add_AT_lbl_id (comp_unit_die
, DW_AT_low_pc
, text_section_label
);
13824 add_AT_lbl_id (comp_unit_die
, DW_AT_high_pc
, text_end_label
);
13827 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
13828 "base address". Use zero so that these addresses become absolute. */
13829 else if (have_location_lists
|| ranges_table_in_use
)
13830 add_AT_addr (comp_unit_die
, DW_AT_entry_pc
, const0_rtx
);
13832 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
13833 add_AT_lbl_offset (comp_unit_die
, DW_AT_stmt_list
,
13834 debug_line_section_label
);
13836 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13837 add_AT_lbl_offset (comp_unit_die
, DW_AT_macro_info
, macinfo_section_label
);
13839 /* Output all of the compilation units. We put the main one last so that
13840 the offsets are available to output_pubnames. */
13841 for (node
= limbo_die_list
; node
; node
= node
->next
)
13842 output_comp_unit (node
->die
, 0);
13844 output_comp_unit (comp_unit_die
, 0);
13846 /* Output the abbreviation table. */
13847 named_section_flags (DEBUG_ABBREV_SECTION
, SECTION_DEBUG
);
13848 output_abbrev_section ();
13850 /* Output public names table if necessary. */
13851 if (pubname_table_in_use
)
13853 named_section_flags (DEBUG_PUBNAMES_SECTION
, SECTION_DEBUG
);
13854 output_pubnames ();
13857 /* Output the address range information. We only put functions in the arange
13858 table, so don't write it out if we don't have any. */
13859 if (fde_table_in_use
)
13861 named_section_flags (DEBUG_ARANGES_SECTION
, SECTION_DEBUG
);
13865 /* Output ranges section if necessary. */
13866 if (ranges_table_in_use
)
13868 named_section_flags (DEBUG_RANGES_SECTION
, SECTION_DEBUG
);
13869 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
13873 /* Have to end the primary source file. */
13874 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
13876 named_section_flags (DEBUG_MACINFO_SECTION
, SECTION_DEBUG
);
13877 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
13878 dw2_asm_output_data (1, 0, "End compilation unit");
13881 /* If we emitted any DW_FORM_strp form attribute, output the string
13883 if (debug_str_hash
)
13884 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
13888 /* This should never be used, but its address is needed for comparisons. */
13889 const struct gcc_debug_hooks dwarf2_debug_hooks
;
13891 #endif /* DWARF2_DEBUGGING_INFO */
13893 #include "gt-dwarf2out.h"