2011-04-04 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / gcc / dwarf2out.c
blob700f7c64bd3a4b38b5fcbe12503219a2910c7849
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, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Gary Funck (gary@intrepid.com).
6 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
7 Extensively modified by Jason Merrill (jason@cygnus.com).
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
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
35 information. */
37 /* DWARF2 Abbreviation Glossary:
39 CFA = Canonical Frame Address
40 a fixed address on the stack which identifies a call frame.
41 We define it to be the value of SP just before the call insn.
42 The CFA register and offset, which may change during the course
43 of the function, are used to calculate its value at runtime.
45 CFI = Call Frame Instruction
46 an instruction for the DWARF2 abstract machine
48 CIE = Common Information Entry
49 information describing information common to one or more FDEs
51 DIE = Debugging Information Entry
53 FDE = Frame Description Entry
54 information describing the stack call frame, in particular,
55 how to restore registers
57 DW_CFA_... = DWARF2 CFA call frame instruction
58 DW_TAG_... = DWARF2 DIE tag */
60 #include "config.h"
61 #include "system.h"
62 #include "coretypes.h"
63 #include "tm.h"
64 #include "tree.h"
65 #include "version.h"
66 #include "flags.h"
67 #include "rtl.h"
68 #include "hard-reg-set.h"
69 #include "regs.h"
70 #include "insn-config.h"
71 #include "reload.h"
72 #include "function.h"
73 #include "output.h"
74 #include "expr.h"
75 #include "libfuncs.h"
76 #include "except.h"
77 #include "dwarf2.h"
78 #include "dwarf2out.h"
79 #include "dwarf2asm.h"
80 #include "toplev.h"
81 #include "ggc.h"
82 #include "md5.h"
83 #include "tm_p.h"
84 #include "diagnostic.h"
85 #include "tree-pretty-print.h"
86 #include "debug.h"
87 #include "target.h"
88 #include "langhooks.h"
89 #include "hashtab.h"
90 #include "cgraph.h"
91 #include "input.h"
92 #include "gimple.h"
93 #include "tree-pass.h"
94 #include "tree-flow.h"
95 #include "cfglayout.h"
97 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
98 static rtx last_var_location_insn;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
111 #else
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
114 #endif
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
122 #endif
124 #ifndef INCOMING_RETURN_ADDR_RTX
125 #define INCOMING_RETURN_ADDR_RTX (gcc_unreachable (), NULL_RTX)
126 #endif
128 /* Map register numbers held in the call frame info that gcc has
129 collected using DWARF_FRAME_REGNUM to those that should be output in
130 .debug_frame and .eh_frame. */
131 #ifndef DWARF2_FRAME_REG_OUT
132 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
133 #endif
135 /* Save the result of dwarf2out_do_frame across PCH. */
136 static GTY(()) bool saved_do_cfi_asm = 0;
138 /* Decide whether we want to emit frame unwind information for the current
139 translation unit. */
142 dwarf2out_do_frame (void)
144 /* We want to emit correct CFA location expressions or lists, so we
145 have to return true if we're going to output debug info, even if
146 we're not going to output frame or unwind info. */
147 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
148 return true;
150 if (saved_do_cfi_asm)
151 return true;
153 if (targetm.debug_unwind_info () == UI_DWARF2)
154 return true;
156 if ((flag_unwind_tables || flag_exceptions)
157 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
158 return true;
160 return false;
163 /* Decide whether to emit frame unwind via assembler directives. */
166 dwarf2out_do_cfi_asm (void)
168 int enc;
170 #ifdef MIPS_DEBUGGING_INFO
171 return false;
172 #endif
173 if (saved_do_cfi_asm)
174 return true;
175 if (!flag_dwarf2_cfi_asm || !dwarf2out_do_frame ())
176 return false;
177 if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE)
178 return false;
180 /* Make sure the personality encoding is one the assembler can support.
181 In particular, aligned addresses can't be handled. */
182 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,/*global=*/1);
183 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
184 return false;
185 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,/*global=*/0);
186 if ((enc & 0x70) != 0 && (enc & 0x70) != DW_EH_PE_pcrel)
187 return false;
189 /* If we can't get the assembler to emit only .debug_frame, and we don't need
190 dwarf2 unwind info for exceptions, then emit .debug_frame by hand. */
191 if (!HAVE_GAS_CFI_SECTIONS_DIRECTIVE
192 && !flag_unwind_tables && !flag_exceptions
193 && targetm.except_unwind_info (&global_options) != UI_DWARF2)
194 return false;
196 saved_do_cfi_asm = true;
197 return true;
200 /* The size of the target's pointer type. */
201 #ifndef PTR_SIZE
202 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
203 #endif
205 /* Array of RTXes referenced by the debugging information, which therefore
206 must be kept around forever. */
207 static GTY(()) VEC(rtx,gc) *used_rtx_array;
209 /* A pointer to the base of a list of incomplete types which might be
210 completed at some later time. incomplete_types_list needs to be a
211 VEC(tree,gc) because we want to tell the garbage collector about
212 it. */
213 static GTY(()) VEC(tree,gc) *incomplete_types;
215 /* A pointer to the base of a table of references to declaration
216 scopes. This table is a display which tracks the nesting
217 of declaration scopes at the current scope and containing
218 scopes. This table is used to find the proper place to
219 define type declaration DIE's. */
220 static GTY(()) VEC(tree,gc) *decl_scope_table;
222 /* Pointers to various DWARF2 sections. */
223 static GTY(()) section *debug_info_section;
224 static GTY(()) section *debug_abbrev_section;
225 static GTY(()) section *debug_aranges_section;
226 static GTY(()) section *debug_macinfo_section;
227 static GTY(()) section *debug_line_section;
228 static GTY(()) section *debug_loc_section;
229 static GTY(()) section *debug_pubnames_section;
230 static GTY(()) section *debug_pubtypes_section;
231 static GTY(()) section *debug_str_section;
232 static GTY(()) section *debug_ranges_section;
233 static GTY(()) section *debug_frame_section;
235 /* Personality decl of current unit. Used only when assembler does not support
236 personality CFI. */
237 static GTY(()) rtx current_unit_personality;
239 /* How to start an assembler comment. */
240 #ifndef ASM_COMMENT_START
241 #define ASM_COMMENT_START ";#"
242 #endif
244 typedef struct dw_cfi_struct *dw_cfi_ref;
245 typedef struct dw_fde_struct *dw_fde_ref;
246 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
248 /* Call frames are described using a sequence of Call Frame
249 Information instructions. The register number, offset
250 and address fields are provided as possible operands;
251 their use is selected by the opcode field. */
253 enum dw_cfi_oprnd_type {
254 dw_cfi_oprnd_unused,
255 dw_cfi_oprnd_reg_num,
256 dw_cfi_oprnd_offset,
257 dw_cfi_oprnd_addr,
258 dw_cfi_oprnd_loc
261 typedef union GTY(()) dw_cfi_oprnd_struct {
262 unsigned int GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
263 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
264 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
265 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
267 dw_cfi_oprnd;
269 typedef struct GTY(()) dw_cfi_struct {
270 dw_cfi_ref dw_cfi_next;
271 enum dwarf_call_frame_info dw_cfi_opc;
272 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
273 dw_cfi_oprnd1;
274 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
275 dw_cfi_oprnd2;
277 dw_cfi_node;
279 /* This is how we define the location of the CFA. We use to handle it
280 as REG + OFFSET all the time, but now it can be more complex.
281 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
282 Instead of passing around REG and OFFSET, we pass a copy
283 of this structure. */
284 typedef struct cfa_loc {
285 HOST_WIDE_INT offset;
286 HOST_WIDE_INT base_offset;
287 unsigned int reg;
288 BOOL_BITFIELD indirect : 1; /* 1 if CFA is accessed via a dereference. */
289 BOOL_BITFIELD in_use : 1; /* 1 if a saved cfa is stored here. */
290 } dw_cfa_location;
292 /* All call frame descriptions (FDE's) in the GCC generated DWARF
293 refer to a single Common Information Entry (CIE), defined at
294 the beginning of the .debug_frame section. This use of a single
295 CIE obviates the need to keep track of multiple CIE's
296 in the DWARF generation routines below. */
298 typedef struct GTY(()) dw_fde_struct {
299 tree decl;
300 const char *dw_fde_begin;
301 const char *dw_fde_current_label;
302 const char *dw_fde_end;
303 const char *dw_fde_vms_end_prologue;
304 const char *dw_fde_vms_begin_epilogue;
305 const char *dw_fde_second_begin;
306 const char *dw_fde_second_end;
307 dw_cfi_ref dw_fde_cfi;
308 dw_cfi_ref dw_fde_switch_cfi; /* Last CFI before switching sections. */
309 HOST_WIDE_INT stack_realignment;
310 unsigned funcdef_number;
311 /* Dynamic realign argument pointer register. */
312 unsigned int drap_reg;
313 /* Virtual dynamic realign argument pointer register. */
314 unsigned int vdrap_reg;
315 /* These 3 flags are copied from rtl_data in function.h. */
316 unsigned all_throwers_are_sibcalls : 1;
317 unsigned uses_eh_lsda : 1;
318 unsigned nothrow : 1;
319 /* Whether we did stack realign in this call frame. */
320 unsigned stack_realign : 1;
321 /* Whether dynamic realign argument pointer register has been saved. */
322 unsigned drap_reg_saved: 1;
323 /* True iff dw_fde_begin label is in text_section or cold_text_section. */
324 unsigned in_std_section : 1;
325 /* True iff dw_fde_second_begin label is in text_section or
326 cold_text_section. */
327 unsigned second_in_std_section : 1;
329 dw_fde_node;
331 /* Maximum size (in bytes) of an artificially generated label. */
332 #define MAX_ARTIFICIAL_LABEL_BYTES 30
334 /* The size of addresses as they appear in the Dwarf 2 data.
335 Some architectures use word addresses to refer to code locations,
336 but Dwarf 2 info always uses byte addresses. On such machines,
337 Dwarf 2 addresses need to be larger than the architecture's
338 pointers. */
339 #ifndef DWARF2_ADDR_SIZE
340 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
341 #endif
343 /* The size in bytes of a DWARF field indicating an offset or length
344 relative to a debug info section, specified to be 4 bytes in the
345 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
346 as PTR_SIZE. */
348 #ifndef DWARF_OFFSET_SIZE
349 #define DWARF_OFFSET_SIZE 4
350 #endif
352 /* The size in bytes of a DWARF 4 type signature. */
354 #ifndef DWARF_TYPE_SIGNATURE_SIZE
355 #define DWARF_TYPE_SIGNATURE_SIZE 8
356 #endif
358 /* According to the (draft) DWARF 3 specification, the initial length
359 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
360 bytes are 0xffffffff, followed by the length stored in the next 8
361 bytes.
363 However, the SGI/MIPS ABI uses an initial length which is equal to
364 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
366 #ifndef DWARF_INITIAL_LENGTH_SIZE
367 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
368 #endif
370 /* Round SIZE up to the nearest BOUNDARY. */
371 #define DWARF_ROUND(SIZE,BOUNDARY) \
372 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
374 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
375 #ifndef DWARF_CIE_DATA_ALIGNMENT
376 #ifdef STACK_GROWS_DOWNWARD
377 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
378 #else
379 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
380 #endif
381 #endif
383 /* CIE identifier. */
384 #if HOST_BITS_PER_WIDE_INT >= 64
385 #define DWARF_CIE_ID \
386 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
387 #else
388 #define DWARF_CIE_ID DW_CIE_ID
389 #endif
391 /* A pointer to the base of a table that contains frame description
392 information for each routine. */
393 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
395 /* Number of elements currently allocated for fde_table. */
396 static GTY(()) unsigned fde_table_allocated;
398 /* Number of elements in fde_table currently in use. */
399 static GTY(()) unsigned fde_table_in_use;
401 /* Size (in elements) of increments by which we may expand the
402 fde_table. */
403 #define FDE_TABLE_INCREMENT 256
405 /* Get the current fde_table entry we should use. */
407 static inline dw_fde_ref
408 current_fde (void)
410 return fde_table_in_use ? &fde_table[fde_table_in_use - 1] : NULL;
413 /* A list of call frame insns for the CIE. */
414 static GTY(()) dw_cfi_ref cie_cfi_head;
416 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
417 attribute that accelerates the lookup of the FDE associated
418 with the subprogram. This variable holds the table index of the FDE
419 associated with the current function (body) definition. */
420 static unsigned current_funcdef_fde;
422 struct GTY(()) indirect_string_node {
423 const char *str;
424 unsigned int refcount;
425 enum dwarf_form form;
426 char *label;
429 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
431 /* True if the compilation unit has location entries that reference
432 debug strings. */
433 static GTY(()) bool debug_str_hash_forced = false;
435 static GTY(()) int dw2_string_counter;
436 static GTY(()) unsigned long dwarf2out_cfi_label_num;
438 /* True if the compilation unit places functions in more than one section. */
439 static GTY(()) bool have_multiple_function_sections = false;
441 /* Whether the default text and cold text sections have been used at all. */
443 static GTY(()) bool text_section_used = false;
444 static GTY(()) bool cold_text_section_used = false;
446 /* The default cold text section. */
447 static GTY(()) section *cold_text_section;
449 /* Forward declarations for functions defined in this file. */
451 static char *stripattributes (const char *);
452 static const char *dwarf_cfi_name (unsigned);
453 static dw_cfi_ref new_cfi (void);
454 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
455 static void add_fde_cfi (const char *, dw_cfi_ref);
456 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *, dw_cfa_location *);
457 static void lookup_cfa (dw_cfa_location *);
458 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
459 static void initial_return_save (rtx);
460 static HOST_WIDE_INT stack_adjust_offset (const_rtx, HOST_WIDE_INT,
461 HOST_WIDE_INT);
462 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
463 static void output_cfi_directive (dw_cfi_ref);
464 static void output_call_frame_info (int);
465 static void dwarf2out_note_section_used (void);
466 static bool clobbers_queued_reg_save (const_rtx);
467 static void dwarf2out_frame_debug_expr (rtx, const char *);
469 /* Support for complex CFA locations. */
470 static void output_cfa_loc (dw_cfi_ref, int);
471 static void output_cfa_loc_raw (dw_cfi_ref);
472 static void get_cfa_from_loc_descr (dw_cfa_location *,
473 struct dw_loc_descr_struct *);
474 static struct dw_loc_descr_struct *build_cfa_loc
475 (dw_cfa_location *, HOST_WIDE_INT);
476 static struct dw_loc_descr_struct *build_cfa_aligned_loc
477 (HOST_WIDE_INT, HOST_WIDE_INT);
478 static void def_cfa_1 (const char *, dw_cfa_location *);
479 static struct dw_loc_descr_struct *mem_loc_descriptor
480 (rtx, enum machine_mode mode, enum var_init_status);
482 /* How to start an assembler comment. */
483 #ifndef ASM_COMMENT_START
484 #define ASM_COMMENT_START ";#"
485 #endif
487 /* Data and reference forms for relocatable data. */
488 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
489 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
491 #ifndef DEBUG_FRAME_SECTION
492 #define DEBUG_FRAME_SECTION ".debug_frame"
493 #endif
495 #ifndef FUNC_BEGIN_LABEL
496 #define FUNC_BEGIN_LABEL "LFB"
497 #endif
499 #ifndef FUNC_END_LABEL
500 #define FUNC_END_LABEL "LFE"
501 #endif
503 #ifndef PROLOGUE_END_LABEL
504 #define PROLOGUE_END_LABEL "LPE"
505 #endif
507 #ifndef EPILOGUE_BEGIN_LABEL
508 #define EPILOGUE_BEGIN_LABEL "LEB"
509 #endif
511 #ifndef FRAME_BEGIN_LABEL
512 #define FRAME_BEGIN_LABEL "Lframe"
513 #endif
514 #define CIE_AFTER_SIZE_LABEL "LSCIE"
515 #define CIE_END_LABEL "LECIE"
516 #define FDE_LABEL "LSFDE"
517 #define FDE_AFTER_SIZE_LABEL "LASFDE"
518 #define FDE_END_LABEL "LEFDE"
519 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
520 #define LINE_NUMBER_END_LABEL "LELT"
521 #define LN_PROLOG_AS_LABEL "LASLTP"
522 #define LN_PROLOG_END_LABEL "LELTP"
523 #define DIE_LABEL_PREFIX "DW"
525 /* The DWARF 2 CFA column which tracks the return address. Normally this
526 is the column for PC, or the first column after all of the hard
527 registers. */
528 #ifndef DWARF_FRAME_RETURN_COLUMN
529 #ifdef PC_REGNUM
530 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
531 #else
532 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
533 #endif
534 #endif
536 /* The mapping from gcc register number to DWARF 2 CFA column number. By
537 default, we just provide columns for all registers. */
538 #ifndef DWARF_FRAME_REGNUM
539 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
540 #endif
542 /* Match the base name of a file to the base name of a compilation unit. */
544 static int
545 matches_main_base (const char *path)
547 /* Cache the last query. */
548 static const char *last_path = NULL;
549 static int last_match = 0;
550 if (path != last_path)
552 const char *base;
553 int length = base_of_path (path, &base);
554 last_path = path;
555 last_match = (length == main_input_baselength
556 && memcmp (base, main_input_basename, length) == 0);
558 return last_match;
561 #ifdef DEBUG_DEBUG_STRUCT
563 static int
564 dump_struct_debug (tree type, enum debug_info_usage usage,
565 enum debug_struct_file criterion, int generic,
566 int matches, int result)
568 /* Find the type name. */
569 tree type_decl = TYPE_STUB_DECL (type);
570 tree t = type_decl;
571 const char *name = 0;
572 if (TREE_CODE (t) == TYPE_DECL)
573 t = DECL_NAME (t);
574 if (t)
575 name = IDENTIFIER_POINTER (t);
577 fprintf (stderr, " struct %d %s %s %s %s %d %p %s\n",
578 criterion,
579 DECL_IN_SYSTEM_HEADER (type_decl) ? "sys" : "usr",
580 matches ? "bas" : "hdr",
581 generic ? "gen" : "ord",
582 usage == DINFO_USAGE_DFN ? ";" :
583 usage == DINFO_USAGE_DIR_USE ? "." : "*",
584 result,
585 (void*) type_decl, name);
586 return result;
588 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
589 dump_struct_debug (type, usage, criterion, generic, matches, result)
591 #else
593 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
594 (result)
596 #endif
598 static bool
599 should_emit_struct_debug (tree type, enum debug_info_usage usage)
601 enum debug_struct_file criterion;
602 tree type_decl;
603 bool generic = lang_hooks.types.generic_p (type);
605 if (generic)
606 criterion = debug_struct_generic[usage];
607 else
608 criterion = debug_struct_ordinary[usage];
610 if (criterion == DINFO_STRUCT_FILE_NONE)
611 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
612 if (criterion == DINFO_STRUCT_FILE_ANY)
613 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
615 type_decl = TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type));
617 if (criterion == DINFO_STRUCT_FILE_SYS && DECL_IN_SYSTEM_HEADER (type_decl))
618 return DUMP_GSTRUCT (type, usage, criterion, generic, false, true);
620 if (matches_main_base (DECL_SOURCE_FILE (type_decl)))
621 return DUMP_GSTRUCT (type, usage, criterion, generic, true, true);
622 return DUMP_GSTRUCT (type, usage, criterion, generic, false, false);
625 /* Hook used by __throw. */
628 expand_builtin_dwarf_sp_column (void)
630 unsigned int dwarf_regnum = DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM);
631 return GEN_INT (DWARF2_FRAME_REG_OUT (dwarf_regnum, 1));
634 /* Return a pointer to a copy of the section string name S with all
635 attributes stripped off, and an asterisk prepended (for assemble_name). */
637 static inline char *
638 stripattributes (const char *s)
640 char *stripped = XNEWVEC (char, strlen (s) + 2);
641 char *p = stripped;
643 *p++ = '*';
645 while (*s && *s != ',')
646 *p++ = *s++;
648 *p = '\0';
649 return stripped;
652 /* MEM is a memory reference for the register size table, each element of
653 which has mode MODE. Initialize column C as a return address column. */
655 static void
656 init_return_column_size (enum machine_mode mode, rtx mem, unsigned int c)
658 HOST_WIDE_INT offset = c * GET_MODE_SIZE (mode);
659 HOST_WIDE_INT size = GET_MODE_SIZE (Pmode);
660 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
663 /* Divide OFF by DWARF_CIE_DATA_ALIGNMENT, asserting no remainder. */
665 static inline HOST_WIDE_INT
666 div_data_align (HOST_WIDE_INT off)
668 HOST_WIDE_INT r = off / DWARF_CIE_DATA_ALIGNMENT;
669 gcc_assert (r * DWARF_CIE_DATA_ALIGNMENT == off);
670 return r;
673 /* Return true if we need a signed version of a given opcode
674 (e.g. DW_CFA_offset_extended_sf vs DW_CFA_offset_extended). */
676 static inline bool
677 need_data_align_sf_opcode (HOST_WIDE_INT off)
679 return DWARF_CIE_DATA_ALIGNMENT < 0 ? off > 0 : off < 0;
682 /* Generate code to initialize the register size table. */
684 void
685 expand_builtin_init_dwarf_reg_sizes (tree address)
687 unsigned int i;
688 enum machine_mode mode = TYPE_MODE (char_type_node);
689 rtx addr = expand_normal (address);
690 rtx mem = gen_rtx_MEM (BLKmode, addr);
691 bool wrote_return_column = false;
693 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
695 int rnum = DWARF2_FRAME_REG_OUT (DWARF_FRAME_REGNUM (i), 1);
697 if (rnum < DWARF_FRAME_REGISTERS)
699 HOST_WIDE_INT offset = rnum * GET_MODE_SIZE (mode);
700 enum machine_mode save_mode = reg_raw_mode[i];
701 HOST_WIDE_INT size;
703 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
704 save_mode = choose_hard_reg_mode (i, 1, true);
705 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
707 if (save_mode == VOIDmode)
708 continue;
709 wrote_return_column = true;
711 size = GET_MODE_SIZE (save_mode);
712 if (offset < 0)
713 continue;
715 emit_move_insn (adjust_address (mem, mode, offset),
716 gen_int_mode (size, mode));
720 if (!wrote_return_column)
721 init_return_column_size (mode, mem, DWARF_FRAME_RETURN_COLUMN);
723 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
724 init_return_column_size (mode, mem, DWARF_ALT_FRAME_RETURN_COLUMN);
725 #endif
727 targetm.init_dwarf_reg_sizes_extra (address);
730 /* Convert a DWARF call frame info. operation to its string name */
732 static const char *
733 dwarf_cfi_name (unsigned int cfi_opc)
735 switch (cfi_opc)
737 case DW_CFA_advance_loc:
738 return "DW_CFA_advance_loc";
739 case DW_CFA_offset:
740 return "DW_CFA_offset";
741 case DW_CFA_restore:
742 return "DW_CFA_restore";
743 case DW_CFA_nop:
744 return "DW_CFA_nop";
745 case DW_CFA_set_loc:
746 return "DW_CFA_set_loc";
747 case DW_CFA_advance_loc1:
748 return "DW_CFA_advance_loc1";
749 case DW_CFA_advance_loc2:
750 return "DW_CFA_advance_loc2";
751 case DW_CFA_advance_loc4:
752 return "DW_CFA_advance_loc4";
753 case DW_CFA_offset_extended:
754 return "DW_CFA_offset_extended";
755 case DW_CFA_restore_extended:
756 return "DW_CFA_restore_extended";
757 case DW_CFA_undefined:
758 return "DW_CFA_undefined";
759 case DW_CFA_same_value:
760 return "DW_CFA_same_value";
761 case DW_CFA_register:
762 return "DW_CFA_register";
763 case DW_CFA_remember_state:
764 return "DW_CFA_remember_state";
765 case DW_CFA_restore_state:
766 return "DW_CFA_restore_state";
767 case DW_CFA_def_cfa:
768 return "DW_CFA_def_cfa";
769 case DW_CFA_def_cfa_register:
770 return "DW_CFA_def_cfa_register";
771 case DW_CFA_def_cfa_offset:
772 return "DW_CFA_def_cfa_offset";
774 /* DWARF 3 */
775 case DW_CFA_def_cfa_expression:
776 return "DW_CFA_def_cfa_expression";
777 case DW_CFA_expression:
778 return "DW_CFA_expression";
779 case DW_CFA_offset_extended_sf:
780 return "DW_CFA_offset_extended_sf";
781 case DW_CFA_def_cfa_sf:
782 return "DW_CFA_def_cfa_sf";
783 case DW_CFA_def_cfa_offset_sf:
784 return "DW_CFA_def_cfa_offset_sf";
786 /* SGI/MIPS specific */
787 case DW_CFA_MIPS_advance_loc8:
788 return "DW_CFA_MIPS_advance_loc8";
790 /* GNU extensions */
791 case DW_CFA_GNU_window_save:
792 return "DW_CFA_GNU_window_save";
793 case DW_CFA_GNU_args_size:
794 return "DW_CFA_GNU_args_size";
795 case DW_CFA_GNU_negative_offset_extended:
796 return "DW_CFA_GNU_negative_offset_extended";
798 default:
799 return "DW_CFA_<unknown>";
803 /* Return a pointer to a newly allocated Call Frame Instruction. */
805 static inline dw_cfi_ref
806 new_cfi (void)
808 dw_cfi_ref cfi = ggc_alloc_dw_cfi_node ();
810 cfi->dw_cfi_next = NULL;
811 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
812 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
814 return cfi;
817 /* Add a Call Frame Instruction to list of instructions. */
819 static inline void
820 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
822 dw_cfi_ref *p;
823 dw_fde_ref fde = current_fde ();
825 /* When DRAP is used, CFA is defined with an expression. Redefine
826 CFA may lead to a different CFA value. */
827 /* ??? Of course, this heuristic fails when we're annotating epilogues,
828 because of course we'll always want to redefine the CFA back to the
829 stack pointer on the way out. Where should we move this check? */
830 if (0 && fde && fde->drap_reg != INVALID_REGNUM)
831 switch (cfi->dw_cfi_opc)
833 case DW_CFA_def_cfa_register:
834 case DW_CFA_def_cfa_offset:
835 case DW_CFA_def_cfa_offset_sf:
836 case DW_CFA_def_cfa:
837 case DW_CFA_def_cfa_sf:
838 gcc_unreachable ();
840 default:
841 break;
844 /* Find the end of the chain. */
845 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
848 *p = cfi;
851 /* Generate a new label for the CFI info to refer to. FORCE is true
852 if a label needs to be output even when using .cfi_* directives. */
854 char *
855 dwarf2out_cfi_label (bool force)
857 static char label[20];
859 if (!force && dwarf2out_do_cfi_asm ())
861 /* In this case, we will be emitting the asm directive instead of
862 the label, so just return a placeholder to keep the rest of the
863 interfaces happy. */
864 strcpy (label, "<do not output>");
866 else
868 int num = dwarf2out_cfi_label_num++;
869 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", num);
870 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LCFI", num);
873 return label;
876 /* True if remember_state should be emitted before following CFI directive. */
877 static bool emit_cfa_remember;
879 /* True if any CFI directives were emitted at the current insn. */
880 static bool any_cfis_emitted;
882 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
883 or to the CIE if LABEL is NULL. */
885 static void
886 add_fde_cfi (const char *label, dw_cfi_ref cfi)
888 dw_cfi_ref *list_head;
890 if (emit_cfa_remember)
892 dw_cfi_ref cfi_remember;
894 /* Emit the state save. */
895 emit_cfa_remember = false;
896 cfi_remember = new_cfi ();
897 cfi_remember->dw_cfi_opc = DW_CFA_remember_state;
898 add_fde_cfi (label, cfi_remember);
901 list_head = &cie_cfi_head;
903 if (dwarf2out_do_cfi_asm ())
905 if (label)
907 dw_fde_ref fde = current_fde ();
909 gcc_assert (fde != NULL);
911 /* We still have to add the cfi to the list so that lookup_cfa
912 works later on. When -g2 and above we even need to force
913 emitting of CFI labels and add to list a DW_CFA_set_loc for
914 convert_cfa_to_fb_loc_list purposes. If we're generating
915 DWARF3 output we use DW_OP_call_frame_cfa and so don't use
916 convert_cfa_to_fb_loc_list. */
917 if (dwarf_version == 2
918 && debug_info_level > DINFO_LEVEL_TERSE
919 && (write_symbols == DWARF2_DEBUG
920 || write_symbols == VMS_AND_DWARF2_DEBUG))
922 switch (cfi->dw_cfi_opc)
924 case DW_CFA_def_cfa_offset:
925 case DW_CFA_def_cfa_offset_sf:
926 case DW_CFA_def_cfa_register:
927 case DW_CFA_def_cfa:
928 case DW_CFA_def_cfa_sf:
929 case DW_CFA_def_cfa_expression:
930 case DW_CFA_restore_state:
931 if (*label == 0 || strcmp (label, "<do not output>") == 0)
932 label = dwarf2out_cfi_label (true);
934 if (fde->dw_fde_current_label == NULL
935 || strcmp (label, fde->dw_fde_current_label) != 0)
937 dw_cfi_ref xcfi;
939 label = xstrdup (label);
941 /* Set the location counter to the new label. */
942 xcfi = new_cfi ();
943 /* It doesn't metter whether DW_CFA_set_loc
944 or DW_CFA_advance_loc4 is added here, those aren't
945 emitted into assembly, only looked up by
946 convert_cfa_to_fb_loc_list. */
947 xcfi->dw_cfi_opc = DW_CFA_set_loc;
948 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
949 add_cfi (&fde->dw_fde_cfi, xcfi);
950 fde->dw_fde_current_label = label;
952 break;
953 default:
954 break;
958 output_cfi_directive (cfi);
960 list_head = &fde->dw_fde_cfi;
961 any_cfis_emitted = true;
963 /* ??? If this is a CFI for the CIE, we don't emit. This
964 assumes that the standard CIE contents that the assembler
965 uses matches the standard CIE contents that the compiler
966 uses. This is probably a bad assumption. I'm not quite
967 sure how to address this for now. */
969 else if (label)
971 dw_fde_ref fde = current_fde ();
973 gcc_assert (fde != NULL);
975 if (*label == 0)
976 label = dwarf2out_cfi_label (false);
978 if (fde->dw_fde_current_label == NULL
979 || strcmp (label, fde->dw_fde_current_label) != 0)
981 dw_cfi_ref xcfi;
983 label = xstrdup (label);
985 /* Set the location counter to the new label. */
986 xcfi = new_cfi ();
987 /* If we have a current label, advance from there, otherwise
988 set the location directly using set_loc. */
989 xcfi->dw_cfi_opc = fde->dw_fde_current_label
990 ? DW_CFA_advance_loc4
991 : DW_CFA_set_loc;
992 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
993 add_cfi (&fde->dw_fde_cfi, xcfi);
995 fde->dw_fde_current_label = label;
998 list_head = &fde->dw_fde_cfi;
999 any_cfis_emitted = true;
1002 add_cfi (list_head, cfi);
1005 /* Subroutine of lookup_cfa. */
1007 static void
1008 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc, dw_cfa_location *remember)
1010 switch (cfi->dw_cfi_opc)
1012 case DW_CFA_def_cfa_offset:
1013 case DW_CFA_def_cfa_offset_sf:
1014 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
1015 break;
1016 case DW_CFA_def_cfa_register:
1017 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1018 break;
1019 case DW_CFA_def_cfa:
1020 case DW_CFA_def_cfa_sf:
1021 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
1022 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
1023 break;
1024 case DW_CFA_def_cfa_expression:
1025 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
1026 break;
1028 case DW_CFA_remember_state:
1029 gcc_assert (!remember->in_use);
1030 *remember = *loc;
1031 remember->in_use = 1;
1032 break;
1033 case DW_CFA_restore_state:
1034 gcc_assert (remember->in_use);
1035 *loc = *remember;
1036 remember->in_use = 0;
1037 break;
1039 default:
1040 break;
1044 /* Find the previous value for the CFA. */
1046 static void
1047 lookup_cfa (dw_cfa_location *loc)
1049 dw_cfi_ref cfi;
1050 dw_fde_ref fde;
1051 dw_cfa_location remember;
1053 memset (loc, 0, sizeof (*loc));
1054 loc->reg = INVALID_REGNUM;
1055 remember = *loc;
1057 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
1058 lookup_cfa_1 (cfi, loc, &remember);
1060 fde = current_fde ();
1061 if (fde)
1062 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
1063 lookup_cfa_1 (cfi, loc, &remember);
1066 /* The current rule for calculating the DWARF2 canonical frame address. */
1067 static dw_cfa_location cfa;
1069 /* The register used for saving registers to the stack, and its offset
1070 from the CFA. */
1071 static dw_cfa_location cfa_store;
1073 /* The current save location around an epilogue. */
1074 static dw_cfa_location cfa_remember;
1076 /* The running total of the size of arguments pushed onto the stack. */
1077 static HOST_WIDE_INT args_size;
1079 /* The last args_size we actually output. */
1080 static HOST_WIDE_INT old_args_size;
1082 /* Entry point to update the canonical frame address (CFA).
1083 LABEL is passed to add_fde_cfi. The value of CFA is now to be
1084 calculated from REG+OFFSET. */
1086 void
1087 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1089 dw_cfa_location loc;
1090 loc.indirect = 0;
1091 loc.base_offset = 0;
1092 loc.reg = reg;
1093 loc.offset = offset;
1094 def_cfa_1 (label, &loc);
1097 /* Determine if two dw_cfa_location structures define the same data. */
1099 static bool
1100 cfa_equal_p (const dw_cfa_location *loc1, const dw_cfa_location *loc2)
1102 return (loc1->reg == loc2->reg
1103 && loc1->offset == loc2->offset
1104 && loc1->indirect == loc2->indirect
1105 && (loc1->indirect == 0
1106 || loc1->base_offset == loc2->base_offset));
1109 /* This routine does the actual work. The CFA is now calculated from
1110 the dw_cfa_location structure. */
1112 static void
1113 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
1115 dw_cfi_ref cfi;
1116 dw_cfa_location old_cfa, loc;
1118 cfa = *loc_p;
1119 loc = *loc_p;
1121 if (cfa_store.reg == loc.reg && loc.indirect == 0)
1122 cfa_store.offset = loc.offset;
1124 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
1125 lookup_cfa (&old_cfa);
1127 /* If nothing changed, no need to issue any call frame instructions. */
1128 if (cfa_equal_p (&loc, &old_cfa))
1129 return;
1131 cfi = new_cfi ();
1133 if (loc.reg == old_cfa.reg && !loc.indirect && !old_cfa.indirect)
1135 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, indicating
1136 the CFA register did not change but the offset did. The data
1137 factoring for DW_CFA_def_cfa_offset_sf happens in output_cfi, or
1138 in the assembler via the .cfi_def_cfa_offset directive. */
1139 if (loc.offset < 0)
1140 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset_sf;
1141 else
1142 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
1143 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
1146 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
1147 else if (loc.offset == old_cfa.offset
1148 && old_cfa.reg != INVALID_REGNUM
1149 && !loc.indirect
1150 && !old_cfa.indirect)
1152 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
1153 indicating the CFA register has changed to <register> but the
1154 offset has not changed. */
1155 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
1156 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1158 #endif
1160 else if (loc.indirect == 0)
1162 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
1163 indicating the CFA register has changed to <register> with
1164 the specified offset. The data factoring for DW_CFA_def_cfa_sf
1165 happens in output_cfi, or in the assembler via the .cfi_def_cfa
1166 directive. */
1167 if (loc.offset < 0)
1168 cfi->dw_cfi_opc = DW_CFA_def_cfa_sf;
1169 else
1170 cfi->dw_cfi_opc = DW_CFA_def_cfa;
1171 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
1172 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
1174 else
1176 /* Construct a DW_CFA_def_cfa_expression instruction to
1177 calculate the CFA using a full location expression since no
1178 register-offset pair is available. */
1179 struct dw_loc_descr_struct *loc_list;
1181 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
1182 loc_list = build_cfa_loc (&loc, 0);
1183 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
1186 add_fde_cfi (label, cfi);
1189 /* Add the CFI for saving a register. REG is the CFA column number.
1190 LABEL is passed to add_fde_cfi.
1191 If SREG is -1, the register is saved at OFFSET from the CFA;
1192 otherwise it is saved in SREG. */
1194 static void
1195 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
1197 dw_cfi_ref cfi = new_cfi ();
1198 dw_fde_ref fde = current_fde ();
1200 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1202 /* When stack is aligned, store REG using DW_CFA_expression with
1203 FP. */
1204 if (fde
1205 && fde->stack_realign
1206 && sreg == INVALID_REGNUM)
1208 cfi->dw_cfi_opc = DW_CFA_expression;
1209 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
1210 cfi->dw_cfi_oprnd2.dw_cfi_loc
1211 = build_cfa_aligned_loc (offset, fde->stack_realignment);
1213 else if (sreg == INVALID_REGNUM)
1215 if (need_data_align_sf_opcode (offset))
1216 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
1217 else if (reg & ~0x3f)
1218 cfi->dw_cfi_opc = DW_CFA_offset_extended;
1219 else
1220 cfi->dw_cfi_opc = DW_CFA_offset;
1221 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
1223 else if (sreg == reg)
1224 cfi->dw_cfi_opc = DW_CFA_same_value;
1225 else
1227 cfi->dw_cfi_opc = DW_CFA_register;
1228 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
1231 add_fde_cfi (label, cfi);
1234 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
1235 This CFI tells the unwinder that it needs to restore the window registers
1236 from the previous frame's window save area.
1238 ??? Perhaps we should note in the CIE where windows are saved (instead of
1239 assuming 0(cfa)) and what registers are in the window. */
1241 void
1242 dwarf2out_window_save (const char *label)
1244 dw_cfi_ref cfi = new_cfi ();
1246 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
1247 add_fde_cfi (label, cfi);
1250 /* Entry point for saving a register to the stack. REG is the GCC register
1251 number. LABEL and OFFSET are passed to reg_save. */
1253 void
1254 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
1256 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
1259 /* Entry point for saving the return address in the stack.
1260 LABEL and OFFSET are passed to reg_save. */
1262 void
1263 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
1265 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
1268 /* Entry point for saving the return address in a register.
1269 LABEL and SREG are passed to reg_save. */
1271 void
1272 dwarf2out_return_reg (const char *label, unsigned int sreg)
1274 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
1277 /* Record the initial position of the return address. RTL is
1278 INCOMING_RETURN_ADDR_RTX. */
1280 static void
1281 initial_return_save (rtx rtl)
1283 unsigned int reg = INVALID_REGNUM;
1284 HOST_WIDE_INT offset = 0;
1286 switch (GET_CODE (rtl))
1288 case REG:
1289 /* RA is in a register. */
1290 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
1291 break;
1293 case MEM:
1294 /* RA is on the stack. */
1295 rtl = XEXP (rtl, 0);
1296 switch (GET_CODE (rtl))
1298 case REG:
1299 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
1300 offset = 0;
1301 break;
1303 case PLUS:
1304 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1305 offset = INTVAL (XEXP (rtl, 1));
1306 break;
1308 case MINUS:
1309 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
1310 offset = -INTVAL (XEXP (rtl, 1));
1311 break;
1313 default:
1314 gcc_unreachable ();
1317 break;
1319 case PLUS:
1320 /* The return address is at some offset from any value we can
1321 actually load. For instance, on the SPARC it is in %i7+8. Just
1322 ignore the offset for now; it doesn't matter for unwinding frames. */
1323 gcc_assert (CONST_INT_P (XEXP (rtl, 1)));
1324 initial_return_save (XEXP (rtl, 0));
1325 return;
1327 default:
1328 gcc_unreachable ();
1331 if (reg != DWARF_FRAME_RETURN_COLUMN)
1332 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
1335 /* Given a SET, calculate the amount of stack adjustment it
1336 contains. */
1338 static HOST_WIDE_INT
1339 stack_adjust_offset (const_rtx pattern, HOST_WIDE_INT cur_args_size,
1340 HOST_WIDE_INT cur_offset)
1342 const_rtx src = SET_SRC (pattern);
1343 const_rtx dest = SET_DEST (pattern);
1344 HOST_WIDE_INT offset = 0;
1345 enum rtx_code code;
1347 if (dest == stack_pointer_rtx)
1349 code = GET_CODE (src);
1351 /* Assume (set (reg sp) (reg whatever)) sets args_size
1352 level to 0. */
1353 if (code == REG && src != stack_pointer_rtx)
1355 offset = -cur_args_size;
1356 #ifndef STACK_GROWS_DOWNWARD
1357 offset = -offset;
1358 #endif
1359 return offset - cur_offset;
1362 if (! (code == PLUS || code == MINUS)
1363 || XEXP (src, 0) != stack_pointer_rtx
1364 || !CONST_INT_P (XEXP (src, 1)))
1365 return 0;
1367 /* (set (reg sp) (plus (reg sp) (const_int))) */
1368 offset = INTVAL (XEXP (src, 1));
1369 if (code == PLUS)
1370 offset = -offset;
1371 return offset;
1374 if (MEM_P (src) && !MEM_P (dest))
1375 dest = src;
1376 if (MEM_P (dest))
1378 /* (set (mem (pre_dec (reg sp))) (foo)) */
1379 src = XEXP (dest, 0);
1380 code = GET_CODE (src);
1382 switch (code)
1384 case PRE_MODIFY:
1385 case POST_MODIFY:
1386 if (XEXP (src, 0) == stack_pointer_rtx)
1388 rtx val = XEXP (XEXP (src, 1), 1);
1389 /* We handle only adjustments by constant amount. */
1390 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1391 && CONST_INT_P (val));
1392 offset = -INTVAL (val);
1393 break;
1395 return 0;
1397 case PRE_DEC:
1398 case POST_DEC:
1399 if (XEXP (src, 0) == stack_pointer_rtx)
1401 offset = GET_MODE_SIZE (GET_MODE (dest));
1402 break;
1404 return 0;
1406 case PRE_INC:
1407 case POST_INC:
1408 if (XEXP (src, 0) == stack_pointer_rtx)
1410 offset = -GET_MODE_SIZE (GET_MODE (dest));
1411 break;
1413 return 0;
1415 default:
1416 return 0;
1419 else
1420 return 0;
1422 return offset;
1425 /* Precomputed args_size for CODE_LABELs and BARRIERs preceeding them,
1426 indexed by INSN_UID. */
1428 static HOST_WIDE_INT *barrier_args_size;
1430 /* Helper function for compute_barrier_args_size. Handle one insn. */
1432 static HOST_WIDE_INT
1433 compute_barrier_args_size_1 (rtx insn, HOST_WIDE_INT cur_args_size,
1434 VEC (rtx, heap) **next)
1436 HOST_WIDE_INT offset = 0;
1437 int i;
1439 if (! RTX_FRAME_RELATED_P (insn))
1441 if (prologue_epilogue_contains (insn))
1442 /* Nothing */;
1443 else if (GET_CODE (PATTERN (insn)) == SET)
1444 offset = stack_adjust_offset (PATTERN (insn), cur_args_size, 0);
1445 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1446 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1448 /* There may be stack adjustments inside compound insns. Search
1449 for them. */
1450 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1451 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1452 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1453 cur_args_size, offset);
1456 else
1458 rtx expr = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1460 if (expr)
1462 expr = XEXP (expr, 0);
1463 if (GET_CODE (expr) == PARALLEL
1464 || GET_CODE (expr) == SEQUENCE)
1465 for (i = 1; i < XVECLEN (expr, 0); i++)
1467 rtx elem = XVECEXP (expr, 0, i);
1469 if (GET_CODE (elem) == SET && !RTX_FRAME_RELATED_P (elem))
1470 offset += stack_adjust_offset (elem, cur_args_size, offset);
1475 #ifndef STACK_GROWS_DOWNWARD
1476 offset = -offset;
1477 #endif
1479 cur_args_size += offset;
1480 if (cur_args_size < 0)
1481 cur_args_size = 0;
1483 if (JUMP_P (insn))
1485 rtx dest = JUMP_LABEL (insn);
1487 if (dest)
1489 if (barrier_args_size [INSN_UID (dest)] < 0)
1491 barrier_args_size [INSN_UID (dest)] = cur_args_size;
1492 VEC_safe_push (rtx, heap, *next, dest);
1497 return cur_args_size;
1500 /* Walk the whole function and compute args_size on BARRIERs. */
1502 static void
1503 compute_barrier_args_size (void)
1505 int max_uid = get_max_uid (), i;
1506 rtx insn;
1507 VEC (rtx, heap) *worklist, *next, *tmp;
1509 barrier_args_size = XNEWVEC (HOST_WIDE_INT, max_uid);
1510 for (i = 0; i < max_uid; i++)
1511 barrier_args_size[i] = -1;
1513 worklist = VEC_alloc (rtx, heap, 20);
1514 next = VEC_alloc (rtx, heap, 20);
1515 insn = get_insns ();
1516 barrier_args_size[INSN_UID (insn)] = 0;
1517 VEC_quick_push (rtx, worklist, insn);
1518 for (;;)
1520 while (!VEC_empty (rtx, worklist))
1522 rtx prev, body, first_insn;
1523 HOST_WIDE_INT cur_args_size;
1525 first_insn = insn = VEC_pop (rtx, worklist);
1526 cur_args_size = barrier_args_size[INSN_UID (insn)];
1527 prev = prev_nonnote_insn (insn);
1528 if (prev && BARRIER_P (prev))
1529 barrier_args_size[INSN_UID (prev)] = cur_args_size;
1531 for (; insn; insn = NEXT_INSN (insn))
1533 if (INSN_DELETED_P (insn) || NOTE_P (insn))
1534 continue;
1535 if (BARRIER_P (insn))
1536 break;
1538 if (LABEL_P (insn))
1540 if (insn == first_insn)
1541 continue;
1542 else if (barrier_args_size[INSN_UID (insn)] < 0)
1544 barrier_args_size[INSN_UID (insn)] = cur_args_size;
1545 continue;
1547 else
1549 /* The insns starting with this label have been
1550 already scanned or are in the worklist. */
1551 break;
1555 body = PATTERN (insn);
1556 if (GET_CODE (body) == SEQUENCE)
1558 HOST_WIDE_INT dest_args_size = cur_args_size;
1559 for (i = 1; i < XVECLEN (body, 0); i++)
1560 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0))
1561 && INSN_FROM_TARGET_P (XVECEXP (body, 0, i)))
1562 dest_args_size
1563 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1564 dest_args_size, &next);
1565 else
1566 cur_args_size
1567 = compute_barrier_args_size_1 (XVECEXP (body, 0, i),
1568 cur_args_size, &next);
1570 if (INSN_ANNULLED_BRANCH_P (XVECEXP (body, 0, 0)))
1571 compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1572 dest_args_size, &next);
1573 else
1574 cur_args_size
1575 = compute_barrier_args_size_1 (XVECEXP (body, 0, 0),
1576 cur_args_size, &next);
1578 else
1579 cur_args_size
1580 = compute_barrier_args_size_1 (insn, cur_args_size, &next);
1584 if (VEC_empty (rtx, next))
1585 break;
1587 /* Swap WORKLIST with NEXT and truncate NEXT for next iteration. */
1588 tmp = next;
1589 next = worklist;
1590 worklist = tmp;
1591 VEC_truncate (rtx, next, 0);
1594 VEC_free (rtx, heap, worklist);
1595 VEC_free (rtx, heap, next);
1598 /* Add a CFI to update the running total of the size of arguments
1599 pushed onto the stack. */
1601 static void
1602 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
1604 dw_cfi_ref cfi;
1606 if (size == old_args_size)
1607 return;
1609 old_args_size = size;
1611 cfi = new_cfi ();
1612 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
1613 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
1614 add_fde_cfi (label, cfi);
1617 /* Record a stack adjustment of OFFSET bytes. */
1619 static void
1620 dwarf2out_stack_adjust (HOST_WIDE_INT offset, const char *label)
1622 if (cfa.reg == STACK_POINTER_REGNUM)
1623 cfa.offset += offset;
1625 if (cfa_store.reg == STACK_POINTER_REGNUM)
1626 cfa_store.offset += offset;
1628 if (ACCUMULATE_OUTGOING_ARGS)
1629 return;
1631 #ifndef STACK_GROWS_DOWNWARD
1632 offset = -offset;
1633 #endif
1635 args_size += offset;
1636 if (args_size < 0)
1637 args_size = 0;
1639 def_cfa_1 (label, &cfa);
1640 if (flag_asynchronous_unwind_tables)
1641 dwarf2out_args_size (label, args_size);
1644 /* Check INSN to see if it looks like a push or a stack adjustment, and
1645 make a note of it if it does. EH uses this information to find out
1646 how much extra space it needs to pop off the stack. */
1648 static void
1649 dwarf2out_notice_stack_adjust (rtx insn, bool after_p)
1651 HOST_WIDE_INT offset;
1652 const char *label;
1653 int i;
1655 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1656 with this function. Proper support would require all frame-related
1657 insns to be marked, and to be able to handle saving state around
1658 epilogues textually in the middle of the function. */
1659 if (prologue_epilogue_contains (insn))
1660 return;
1662 /* If INSN is an instruction from target of an annulled branch, the
1663 effects are for the target only and so current argument size
1664 shouldn't change at all. */
1665 if (final_sequence
1666 && INSN_ANNULLED_BRANCH_P (XVECEXP (final_sequence, 0, 0))
1667 && INSN_FROM_TARGET_P (insn))
1668 return;
1670 /* If only calls can throw, and we have a frame pointer,
1671 save up adjustments until we see the CALL_INSN. */
1672 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1674 if (CALL_P (insn) && !after_p)
1676 /* Extract the size of the args from the CALL rtx itself. */
1677 insn = PATTERN (insn);
1678 if (GET_CODE (insn) == PARALLEL)
1679 insn = XVECEXP (insn, 0, 0);
1680 if (GET_CODE (insn) == SET)
1681 insn = SET_SRC (insn);
1682 gcc_assert (GET_CODE (insn) == CALL);
1683 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1685 return;
1688 if (CALL_P (insn) && !after_p)
1690 if (!flag_asynchronous_unwind_tables)
1691 dwarf2out_args_size ("", args_size);
1692 return;
1694 else if (BARRIER_P (insn))
1696 /* Don't call compute_barrier_args_size () if the only
1697 BARRIER is at the end of function. */
1698 if (barrier_args_size == NULL && next_nonnote_insn (insn))
1699 compute_barrier_args_size ();
1700 if (barrier_args_size == NULL)
1701 offset = 0;
1702 else
1704 offset = barrier_args_size[INSN_UID (insn)];
1705 if (offset < 0)
1706 offset = 0;
1709 offset -= args_size;
1710 #ifndef STACK_GROWS_DOWNWARD
1711 offset = -offset;
1712 #endif
1714 else if (GET_CODE (PATTERN (insn)) == SET)
1715 offset = stack_adjust_offset (PATTERN (insn), args_size, 0);
1716 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1717 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1719 /* There may be stack adjustments inside compound insns. Search
1720 for them. */
1721 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1722 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1723 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i),
1724 args_size, offset);
1726 else
1727 return;
1729 if (offset == 0)
1730 return;
1732 label = dwarf2out_cfi_label (false);
1733 dwarf2out_stack_adjust (offset, label);
1736 /* We delay emitting a register save until either (a) we reach the end
1737 of the prologue or (b) the register is clobbered. This clusters
1738 register saves so that there are fewer pc advances. */
1740 struct GTY(()) queued_reg_save {
1741 struct queued_reg_save *next;
1742 rtx reg;
1743 HOST_WIDE_INT cfa_offset;
1744 rtx saved_reg;
1747 static GTY(()) struct queued_reg_save *queued_reg_saves;
1749 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1750 struct GTY(()) reg_saved_in_data {
1751 rtx orig_reg;
1752 rtx saved_in_reg;
1755 /* A list of registers saved in other registers.
1756 The list intentionally has a small maximum capacity of 4; if your
1757 port needs more than that, you might consider implementing a
1758 more efficient data structure. */
1759 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1760 static GTY(()) size_t num_regs_saved_in_regs;
1762 static const char *last_reg_save_label;
1764 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1765 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1767 static void
1768 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1770 struct queued_reg_save *q;
1772 /* Duplicates waste space, but it's also necessary to remove them
1773 for correctness, since the queue gets output in reverse
1774 order. */
1775 for (q = queued_reg_saves; q != NULL; q = q->next)
1776 if (REGNO (q->reg) == REGNO (reg))
1777 break;
1779 if (q == NULL)
1781 q = ggc_alloc_queued_reg_save ();
1782 q->next = queued_reg_saves;
1783 queued_reg_saves = q;
1786 q->reg = reg;
1787 q->cfa_offset = offset;
1788 q->saved_reg = sreg;
1790 last_reg_save_label = label;
1793 /* Output all the entries in QUEUED_REG_SAVES. */
1795 void
1796 dwarf2out_flush_queued_reg_saves (void)
1798 struct queued_reg_save *q;
1800 for (q = queued_reg_saves; q; q = q->next)
1802 size_t i;
1803 unsigned int reg, sreg;
1805 for (i = 0; i < num_regs_saved_in_regs; i++)
1806 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1807 break;
1808 if (q->saved_reg && i == num_regs_saved_in_regs)
1810 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1811 num_regs_saved_in_regs++;
1813 if (i != num_regs_saved_in_regs)
1815 regs_saved_in_regs[i].orig_reg = q->reg;
1816 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1819 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1820 if (q->saved_reg)
1821 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1822 else
1823 sreg = INVALID_REGNUM;
1824 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1827 queued_reg_saves = NULL;
1828 last_reg_save_label = NULL;
1831 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1832 location for? Or, does it clobber a register which we've previously
1833 said that some other register is saved in, and for which we now
1834 have a new location for? */
1836 static bool
1837 clobbers_queued_reg_save (const_rtx insn)
1839 struct queued_reg_save *q;
1841 for (q = queued_reg_saves; q; q = q->next)
1843 size_t i;
1844 if (modified_in_p (q->reg, insn))
1845 return true;
1846 for (i = 0; i < num_regs_saved_in_regs; i++)
1847 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1848 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1849 return true;
1852 return false;
1855 /* Entry point for saving the first register into the second. */
1857 void
1858 dwarf2out_reg_save_reg (const char *label, rtx reg, rtx sreg)
1860 size_t i;
1861 unsigned int regno, sregno;
1863 for (i = 0; i < num_regs_saved_in_regs; i++)
1864 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (reg))
1865 break;
1866 if (i == num_regs_saved_in_regs)
1868 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1869 num_regs_saved_in_regs++;
1871 regs_saved_in_regs[i].orig_reg = reg;
1872 regs_saved_in_regs[i].saved_in_reg = sreg;
1874 regno = DWARF_FRAME_REGNUM (REGNO (reg));
1875 sregno = DWARF_FRAME_REGNUM (REGNO (sreg));
1876 reg_save (label, regno, sregno, 0);
1879 /* What register, if any, is currently saved in REG? */
1881 static rtx
1882 reg_saved_in (rtx reg)
1884 unsigned int regn = REGNO (reg);
1885 size_t i;
1886 struct queued_reg_save *q;
1888 for (q = queued_reg_saves; q; q = q->next)
1889 if (q->saved_reg && regn == REGNO (q->saved_reg))
1890 return q->reg;
1892 for (i = 0; i < num_regs_saved_in_regs; i++)
1893 if (regs_saved_in_regs[i].saved_in_reg
1894 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1895 return regs_saved_in_regs[i].orig_reg;
1897 return NULL_RTX;
1901 /* A temporary register holding an integral value used in adjusting SP
1902 or setting up the store_reg. The "offset" field holds the integer
1903 value, not an offset. */
1904 static dw_cfa_location cfa_temp;
1906 /* A subroutine of dwarf2out_frame_debug, process a REG_DEF_CFA note. */
1908 static void
1909 dwarf2out_frame_debug_def_cfa (rtx pat, const char *label)
1911 memset (&cfa, 0, sizeof (cfa));
1913 switch (GET_CODE (pat))
1915 case PLUS:
1916 cfa.reg = REGNO (XEXP (pat, 0));
1917 cfa.offset = INTVAL (XEXP (pat, 1));
1918 break;
1920 case REG:
1921 cfa.reg = REGNO (pat);
1922 break;
1924 case MEM:
1925 cfa.indirect = 1;
1926 pat = XEXP (pat, 0);
1927 if (GET_CODE (pat) == PLUS)
1929 cfa.base_offset = INTVAL (XEXP (pat, 1));
1930 pat = XEXP (pat, 0);
1932 cfa.reg = REGNO (pat);
1933 break;
1935 default:
1936 /* Recurse and define an expression. */
1937 gcc_unreachable ();
1940 def_cfa_1 (label, &cfa);
1943 /* A subroutine of dwarf2out_frame_debug, process a REG_ADJUST_CFA note. */
1945 static void
1946 dwarf2out_frame_debug_adjust_cfa (rtx pat, const char *label)
1948 rtx src, dest;
1950 gcc_assert (GET_CODE (pat) == SET);
1951 dest = XEXP (pat, 0);
1952 src = XEXP (pat, 1);
1954 switch (GET_CODE (src))
1956 case PLUS:
1957 gcc_assert (REGNO (XEXP (src, 0)) == cfa.reg);
1958 cfa.offset -= INTVAL (XEXP (src, 1));
1959 break;
1961 case REG:
1962 break;
1964 default:
1965 gcc_unreachable ();
1968 cfa.reg = REGNO (dest);
1969 gcc_assert (cfa.indirect == 0);
1971 def_cfa_1 (label, &cfa);
1974 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_OFFSET note. */
1976 static void
1977 dwarf2out_frame_debug_cfa_offset (rtx set, const char *label)
1979 HOST_WIDE_INT offset;
1980 rtx src, addr, span;
1982 src = XEXP (set, 1);
1983 addr = XEXP (set, 0);
1984 gcc_assert (MEM_P (addr));
1985 addr = XEXP (addr, 0);
1987 /* As documented, only consider extremely simple addresses. */
1988 switch (GET_CODE (addr))
1990 case REG:
1991 gcc_assert (REGNO (addr) == cfa.reg);
1992 offset = -cfa.offset;
1993 break;
1994 case PLUS:
1995 gcc_assert (REGNO (XEXP (addr, 0)) == cfa.reg);
1996 offset = INTVAL (XEXP (addr, 1)) - cfa.offset;
1997 break;
1998 default:
1999 gcc_unreachable ();
2002 span = targetm.dwarf_register_span (src);
2004 /* ??? We'd like to use queue_reg_save, but we need to come up with
2005 a different flushing heuristic for epilogues. */
2006 if (!span)
2007 reg_save (label, DWARF_FRAME_REGNUM (REGNO (src)), INVALID_REGNUM, offset);
2008 else
2010 /* We have a PARALLEL describing where the contents of SRC live.
2011 Queue register saves for each piece of the PARALLEL. */
2012 int par_index;
2013 int limit;
2014 HOST_WIDE_INT span_offset = offset;
2016 gcc_assert (GET_CODE (span) == PARALLEL);
2018 limit = XVECLEN (span, 0);
2019 for (par_index = 0; par_index < limit; par_index++)
2021 rtx elem = XVECEXP (span, 0, par_index);
2023 reg_save (label, DWARF_FRAME_REGNUM (REGNO (elem)),
2024 INVALID_REGNUM, span_offset);
2025 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2030 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_REGISTER note. */
2032 static void
2033 dwarf2out_frame_debug_cfa_register (rtx set, const char *label)
2035 rtx src, dest;
2036 unsigned sregno, dregno;
2038 src = XEXP (set, 1);
2039 dest = XEXP (set, 0);
2041 if (src == pc_rtx)
2042 sregno = DWARF_FRAME_RETURN_COLUMN;
2043 else
2044 sregno = DWARF_FRAME_REGNUM (REGNO (src));
2046 dregno = DWARF_FRAME_REGNUM (REGNO (dest));
2048 /* ??? We'd like to use queue_reg_save, but we need to come up with
2049 a different flushing heuristic for epilogues. */
2050 reg_save (label, sregno, dregno, 0);
2053 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_EXPRESSION note. */
2055 static void
2056 dwarf2out_frame_debug_cfa_expression (rtx set, const char *label)
2058 rtx src, dest, span;
2059 dw_cfi_ref cfi = new_cfi ();
2061 dest = SET_DEST (set);
2062 src = SET_SRC (set);
2064 gcc_assert (REG_P (src));
2065 gcc_assert (MEM_P (dest));
2067 span = targetm.dwarf_register_span (src);
2068 gcc_assert (!span);
2070 cfi->dw_cfi_opc = DW_CFA_expression;
2071 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = DWARF_FRAME_REGNUM (REGNO (src));
2072 cfi->dw_cfi_oprnd2.dw_cfi_loc
2073 = mem_loc_descriptor (XEXP (dest, 0), GET_MODE (dest),
2074 VAR_INIT_STATUS_INITIALIZED);
2076 /* ??? We'd like to use queue_reg_save, were the interface different,
2077 and, as above, we could manage flushing for epilogues. */
2078 add_fde_cfi (label, cfi);
2081 /* A subroutine of dwarf2out_frame_debug, process a REG_CFA_RESTORE note. */
2083 static void
2084 dwarf2out_frame_debug_cfa_restore (rtx reg, const char *label)
2086 dw_cfi_ref cfi = new_cfi ();
2087 unsigned int regno = DWARF_FRAME_REGNUM (REGNO (reg));
2089 cfi->dw_cfi_opc = (regno & ~0x3f ? DW_CFA_restore_extended : DW_CFA_restore);
2090 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = regno;
2092 add_fde_cfi (label, cfi);
2095 /* Record call frame debugging information for an expression EXPR,
2096 which either sets SP or FP (adjusting how we calculate the frame
2097 address) or saves a register to the stack or another register.
2098 LABEL indicates the address of EXPR.
2100 This function encodes a state machine mapping rtxes to actions on
2101 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
2102 users need not read the source code.
2104 The High-Level Picture
2106 Changes in the register we use to calculate the CFA: Currently we
2107 assume that if you copy the CFA register into another register, we
2108 should take the other one as the new CFA register; this seems to
2109 work pretty well. If it's wrong for some target, it's simple
2110 enough not to set RTX_FRAME_RELATED_P on the insn in question.
2112 Changes in the register we use for saving registers to the stack:
2113 This is usually SP, but not always. Again, we deduce that if you
2114 copy SP into another register (and SP is not the CFA register),
2115 then the new register is the one we will be using for register
2116 saves. This also seems to work.
2118 Register saves: There's not much guesswork about this one; if
2119 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
2120 register save, and the register used to calculate the destination
2121 had better be the one we think we're using for this purpose.
2122 It's also assumed that a copy from a call-saved register to another
2123 register is saving that register if RTX_FRAME_RELATED_P is set on
2124 that instruction. If the copy is from a call-saved register to
2125 the *same* register, that means that the register is now the same
2126 value as in the caller.
2128 Except: If the register being saved is the CFA register, and the
2129 offset is nonzero, we are saving the CFA, so we assume we have to
2130 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
2131 the intent is to save the value of SP from the previous frame.
2133 In addition, if a register has previously been saved to a different
2134 register,
2136 Invariants / Summaries of Rules
2138 cfa current rule for calculating the CFA. It usually
2139 consists of a register and an offset.
2140 cfa_store register used by prologue code to save things to the stack
2141 cfa_store.offset is the offset from the value of
2142 cfa_store.reg to the actual CFA
2143 cfa_temp register holding an integral value. cfa_temp.offset
2144 stores the value, which will be used to adjust the
2145 stack pointer. cfa_temp is also used like cfa_store,
2146 to track stores to the stack via fp or a temp reg.
2148 Rules 1- 4: Setting a register's value to cfa.reg or an expression
2149 with cfa.reg as the first operand changes the cfa.reg and its
2150 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
2151 cfa_temp.offset.
2153 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
2154 expression yielding a constant. This sets cfa_temp.reg
2155 and cfa_temp.offset.
2157 Rule 5: Create a new register cfa_store used to save items to the
2158 stack.
2160 Rules 10-14: Save a register to the stack. Define offset as the
2161 difference of the original location and cfa_store's
2162 location (or cfa_temp's location if cfa_temp is used).
2164 Rules 16-20: If AND operation happens on sp in prologue, we assume
2165 stack is realigned. We will use a group of DW_OP_XXX
2166 expressions to represent the location of the stored
2167 register instead of CFA+offset.
2169 The Rules
2171 "{a,b}" indicates a choice of a xor b.
2172 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
2174 Rule 1:
2175 (set <reg1> <reg2>:cfa.reg)
2176 effects: cfa.reg = <reg1>
2177 cfa.offset unchanged
2178 cfa_temp.reg = <reg1>
2179 cfa_temp.offset = cfa.offset
2181 Rule 2:
2182 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
2183 {<const_int>,<reg>:cfa_temp.reg}))
2184 effects: cfa.reg = sp if fp used
2185 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
2186 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
2187 if cfa_store.reg==sp
2189 Rule 3:
2190 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
2191 effects: cfa.reg = fp
2192 cfa_offset += +/- <const_int>
2194 Rule 4:
2195 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
2196 constraints: <reg1> != fp
2197 <reg1> != sp
2198 effects: cfa.reg = <reg1>
2199 cfa_temp.reg = <reg1>
2200 cfa_temp.offset = cfa.offset
2202 Rule 5:
2203 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
2204 constraints: <reg1> != fp
2205 <reg1> != sp
2206 effects: cfa_store.reg = <reg1>
2207 cfa_store.offset = cfa.offset - cfa_temp.offset
2209 Rule 6:
2210 (set <reg> <const_int>)
2211 effects: cfa_temp.reg = <reg>
2212 cfa_temp.offset = <const_int>
2214 Rule 7:
2215 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
2216 effects: cfa_temp.reg = <reg1>
2217 cfa_temp.offset |= <const_int>
2219 Rule 8:
2220 (set <reg> (high <exp>))
2221 effects: none
2223 Rule 9:
2224 (set <reg> (lo_sum <exp> <const_int>))
2225 effects: cfa_temp.reg = <reg>
2226 cfa_temp.offset = <const_int>
2228 Rule 10:
2229 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
2230 effects: cfa_store.offset -= <const_int>
2231 cfa.offset = cfa_store.offset if cfa.reg == sp
2232 cfa.reg = sp
2233 cfa.base_offset = -cfa_store.offset
2235 Rule 11:
2236 (set (mem ({pre_inc,pre_dec,post_dec} sp:cfa_store.reg)) <reg>)
2237 effects: cfa_store.offset += -/+ mode_size(mem)
2238 cfa.offset = cfa_store.offset if cfa.reg == sp
2239 cfa.reg = sp
2240 cfa.base_offset = -cfa_store.offset
2242 Rule 12:
2243 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
2245 <reg2>)
2246 effects: cfa.reg = <reg1>
2247 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
2249 Rule 13:
2250 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
2251 effects: cfa.reg = <reg1>
2252 cfa.base_offset = -{cfa_store,cfa_temp}.offset
2254 Rule 14:
2255 (set (mem (post_inc <reg1>:cfa_temp <const_int>)) <reg2>)
2256 effects: cfa.reg = <reg1>
2257 cfa.base_offset = -cfa_temp.offset
2258 cfa_temp.offset -= mode_size(mem)
2260 Rule 15:
2261 (set <reg> {unspec, unspec_volatile})
2262 effects: target-dependent
2264 Rule 16:
2265 (set sp (and: sp <const_int>))
2266 constraints: cfa_store.reg == sp
2267 effects: current_fde.stack_realign = 1
2268 cfa_store.offset = 0
2269 fde->drap_reg = cfa.reg if cfa.reg != sp and cfa.reg != fp
2271 Rule 17:
2272 (set (mem ({pre_inc, pre_dec} sp)) (mem (plus (cfa.reg) (const_int))))
2273 effects: cfa_store.offset += -/+ mode_size(mem)
2275 Rule 18:
2276 (set (mem ({pre_inc, pre_dec} sp)) fp)
2277 constraints: fde->stack_realign == 1
2278 effects: cfa_store.offset = 0
2279 cfa.reg != HARD_FRAME_POINTER_REGNUM
2281 Rule 19:
2282 (set (mem ({pre_inc, pre_dec} sp)) cfa.reg)
2283 constraints: fde->stack_realign == 1
2284 && cfa.offset == 0
2285 && cfa.indirect == 0
2286 && cfa.reg != HARD_FRAME_POINTER_REGNUM
2287 effects: Use DW_CFA_def_cfa_expression to define cfa
2288 cfa.reg == fde->drap_reg */
2290 static void
2291 dwarf2out_frame_debug_expr (rtx expr, const char *label)
2293 rtx src, dest, span;
2294 HOST_WIDE_INT offset;
2295 dw_fde_ref fde;
2297 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
2298 the PARALLEL independently. The first element is always processed if
2299 it is a SET. This is for backward compatibility. Other elements
2300 are processed only if they are SETs and the RTX_FRAME_RELATED_P
2301 flag is set in them. */
2302 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
2304 int par_index;
2305 int limit = XVECLEN (expr, 0);
2306 rtx elem;
2308 /* PARALLELs have strict read-modify-write semantics, so we
2309 ought to evaluate every rvalue before changing any lvalue.
2310 It's cumbersome to do that in general, but there's an
2311 easy approximation that is enough for all current users:
2312 handle register saves before register assignments. */
2313 if (GET_CODE (expr) == PARALLEL)
2314 for (par_index = 0; par_index < limit; par_index++)
2316 elem = XVECEXP (expr, 0, par_index);
2317 if (GET_CODE (elem) == SET
2318 && MEM_P (SET_DEST (elem))
2319 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2320 dwarf2out_frame_debug_expr (elem, label);
2323 for (par_index = 0; par_index < limit; par_index++)
2325 elem = XVECEXP (expr, 0, par_index);
2326 if (GET_CODE (elem) == SET
2327 && (!MEM_P (SET_DEST (elem)) || GET_CODE (expr) == SEQUENCE)
2328 && (RTX_FRAME_RELATED_P (elem) || par_index == 0))
2329 dwarf2out_frame_debug_expr (elem, label);
2330 else if (GET_CODE (elem) == SET
2331 && par_index != 0
2332 && !RTX_FRAME_RELATED_P (elem))
2334 /* Stack adjustment combining might combine some post-prologue
2335 stack adjustment into a prologue stack adjustment. */
2336 HOST_WIDE_INT offset = stack_adjust_offset (elem, args_size, 0);
2338 if (offset != 0)
2339 dwarf2out_stack_adjust (offset, label);
2342 return;
2345 gcc_assert (GET_CODE (expr) == SET);
2347 src = SET_SRC (expr);
2348 dest = SET_DEST (expr);
2350 if (REG_P (src))
2352 rtx rsi = reg_saved_in (src);
2353 if (rsi)
2354 src = rsi;
2357 fde = current_fde ();
2359 switch (GET_CODE (dest))
2361 case REG:
2362 switch (GET_CODE (src))
2364 /* Setting FP from SP. */
2365 case REG:
2366 if (cfa.reg == (unsigned) REGNO (src))
2368 /* Rule 1 */
2369 /* Update the CFA rule wrt SP or FP. Make sure src is
2370 relative to the current CFA register.
2372 We used to require that dest be either SP or FP, but the
2373 ARM copies SP to a temporary register, and from there to
2374 FP. So we just rely on the backends to only set
2375 RTX_FRAME_RELATED_P on appropriate insns. */
2376 cfa.reg = REGNO (dest);
2377 cfa_temp.reg = cfa.reg;
2378 cfa_temp.offset = cfa.offset;
2380 else
2382 /* Saving a register in a register. */
2383 gcc_assert (!fixed_regs [REGNO (dest)]
2384 /* For the SPARC and its register window. */
2385 || (DWARF_FRAME_REGNUM (REGNO (src))
2386 == DWARF_FRAME_RETURN_COLUMN));
2388 /* After stack is aligned, we can only save SP in FP
2389 if drap register is used. In this case, we have
2390 to restore stack pointer with the CFA value and we
2391 don't generate this DWARF information. */
2392 if (fde
2393 && fde->stack_realign
2394 && REGNO (src) == STACK_POINTER_REGNUM)
2395 gcc_assert (REGNO (dest) == HARD_FRAME_POINTER_REGNUM
2396 && fde->drap_reg != INVALID_REGNUM
2397 && cfa.reg != REGNO (src));
2398 else
2399 queue_reg_save (label, src, dest, 0);
2401 break;
2403 case PLUS:
2404 case MINUS:
2405 case LO_SUM:
2406 if (dest == stack_pointer_rtx)
2408 /* Rule 2 */
2409 /* Adjusting SP. */
2410 switch (GET_CODE (XEXP (src, 1)))
2412 case CONST_INT:
2413 offset = INTVAL (XEXP (src, 1));
2414 break;
2415 case REG:
2416 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
2417 == cfa_temp.reg);
2418 offset = cfa_temp.offset;
2419 break;
2420 default:
2421 gcc_unreachable ();
2424 if (XEXP (src, 0) == hard_frame_pointer_rtx)
2426 /* Restoring SP from FP in the epilogue. */
2427 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
2428 cfa.reg = STACK_POINTER_REGNUM;
2430 else if (GET_CODE (src) == LO_SUM)
2431 /* Assume we've set the source reg of the LO_SUM from sp. */
2433 else
2434 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
2436 if (GET_CODE (src) != MINUS)
2437 offset = -offset;
2438 if (cfa.reg == STACK_POINTER_REGNUM)
2439 cfa.offset += offset;
2440 if (cfa_store.reg == STACK_POINTER_REGNUM)
2441 cfa_store.offset += offset;
2443 else if (dest == hard_frame_pointer_rtx)
2445 /* Rule 3 */
2446 /* Either setting the FP from an offset of the SP,
2447 or adjusting the FP */
2448 gcc_assert (frame_pointer_needed);
2450 gcc_assert (REG_P (XEXP (src, 0))
2451 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
2452 && CONST_INT_P (XEXP (src, 1)));
2453 offset = INTVAL (XEXP (src, 1));
2454 if (GET_CODE (src) != MINUS)
2455 offset = -offset;
2456 cfa.offset += offset;
2457 cfa.reg = HARD_FRAME_POINTER_REGNUM;
2459 else
2461 gcc_assert (GET_CODE (src) != MINUS);
2463 /* Rule 4 */
2464 if (REG_P (XEXP (src, 0))
2465 && REGNO (XEXP (src, 0)) == cfa.reg
2466 && CONST_INT_P (XEXP (src, 1)))
2468 /* Setting a temporary CFA register that will be copied
2469 into the FP later on. */
2470 offset = - INTVAL (XEXP (src, 1));
2471 cfa.offset += offset;
2472 cfa.reg = REGNO (dest);
2473 /* Or used to save regs to the stack. */
2474 cfa_temp.reg = cfa.reg;
2475 cfa_temp.offset = cfa.offset;
2478 /* Rule 5 */
2479 else if (REG_P (XEXP (src, 0))
2480 && REGNO (XEXP (src, 0)) == cfa_temp.reg
2481 && XEXP (src, 1) == stack_pointer_rtx)
2483 /* Setting a scratch register that we will use instead
2484 of SP for saving registers to the stack. */
2485 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
2486 cfa_store.reg = REGNO (dest);
2487 cfa_store.offset = cfa.offset - cfa_temp.offset;
2490 /* Rule 9 */
2491 else if (GET_CODE (src) == LO_SUM
2492 && CONST_INT_P (XEXP (src, 1)))
2494 cfa_temp.reg = REGNO (dest);
2495 cfa_temp.offset = INTVAL (XEXP (src, 1));
2497 else
2498 gcc_unreachable ();
2500 break;
2502 /* Rule 6 */
2503 case CONST_INT:
2504 cfa_temp.reg = REGNO (dest);
2505 cfa_temp.offset = INTVAL (src);
2506 break;
2508 /* Rule 7 */
2509 case IOR:
2510 gcc_assert (REG_P (XEXP (src, 0))
2511 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
2512 && CONST_INT_P (XEXP (src, 1)));
2514 if ((unsigned) REGNO (dest) != cfa_temp.reg)
2515 cfa_temp.reg = REGNO (dest);
2516 cfa_temp.offset |= INTVAL (XEXP (src, 1));
2517 break;
2519 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
2520 which will fill in all of the bits. */
2521 /* Rule 8 */
2522 case HIGH:
2523 break;
2525 /* Rule 15 */
2526 case UNSPEC:
2527 case UNSPEC_VOLATILE:
2528 gcc_assert (targetm.dwarf_handle_frame_unspec);
2529 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
2530 return;
2532 /* Rule 16 */
2533 case AND:
2534 /* If this AND operation happens on stack pointer in prologue,
2535 we assume the stack is realigned and we extract the
2536 alignment. */
2537 if (fde && XEXP (src, 0) == stack_pointer_rtx)
2539 /* We interpret reg_save differently with stack_realign set.
2540 Thus we must flush whatever we have queued first. */
2541 dwarf2out_flush_queued_reg_saves ();
2543 gcc_assert (cfa_store.reg == REGNO (XEXP (src, 0)));
2544 fde->stack_realign = 1;
2545 fde->stack_realignment = INTVAL (XEXP (src, 1));
2546 cfa_store.offset = 0;
2548 if (cfa.reg != STACK_POINTER_REGNUM
2549 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2550 fde->drap_reg = cfa.reg;
2552 return;
2554 default:
2555 gcc_unreachable ();
2558 def_cfa_1 (label, &cfa);
2559 break;
2561 case MEM:
2563 /* Saving a register to the stack. Make sure dest is relative to the
2564 CFA register. */
2565 switch (GET_CODE (XEXP (dest, 0)))
2567 /* Rule 10 */
2568 /* With a push. */
2569 case PRE_MODIFY:
2570 /* We can't handle variable size modifications. */
2571 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
2572 == CONST_INT);
2573 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
2575 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
2576 && cfa_store.reg == STACK_POINTER_REGNUM);
2578 cfa_store.offset += offset;
2579 if (cfa.reg == STACK_POINTER_REGNUM)
2580 cfa.offset = cfa_store.offset;
2582 offset = -cfa_store.offset;
2583 break;
2585 /* Rule 11 */
2586 case PRE_INC:
2587 case PRE_DEC:
2588 case POST_DEC:
2589 offset = GET_MODE_SIZE (GET_MODE (dest));
2590 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
2591 offset = -offset;
2593 gcc_assert ((REGNO (XEXP (XEXP (dest, 0), 0))
2594 == STACK_POINTER_REGNUM)
2595 && cfa_store.reg == STACK_POINTER_REGNUM);
2597 cfa_store.offset += offset;
2599 /* Rule 18: If stack is aligned, we will use FP as a
2600 reference to represent the address of the stored
2601 regiser. */
2602 if (fde
2603 && fde->stack_realign
2604 && src == hard_frame_pointer_rtx)
2606 gcc_assert (cfa.reg != HARD_FRAME_POINTER_REGNUM);
2607 cfa_store.offset = 0;
2610 if (cfa.reg == STACK_POINTER_REGNUM)
2611 cfa.offset = cfa_store.offset;
2613 if (GET_CODE (XEXP (dest, 0)) == POST_DEC)
2614 offset += -cfa_store.offset;
2615 else
2616 offset = -cfa_store.offset;
2617 break;
2619 /* Rule 12 */
2620 /* With an offset. */
2621 case PLUS:
2622 case MINUS:
2623 case LO_SUM:
2625 int regno;
2627 gcc_assert (CONST_INT_P (XEXP (XEXP (dest, 0), 1))
2628 && REG_P (XEXP (XEXP (dest, 0), 0)));
2629 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
2630 if (GET_CODE (XEXP (dest, 0)) == MINUS)
2631 offset = -offset;
2633 regno = REGNO (XEXP (XEXP (dest, 0), 0));
2635 if (cfa.reg == (unsigned) regno)
2636 offset -= cfa.offset;
2637 else if (cfa_store.reg == (unsigned) regno)
2638 offset -= cfa_store.offset;
2639 else
2641 gcc_assert (cfa_temp.reg == (unsigned) regno);
2642 offset -= cfa_temp.offset;
2645 break;
2647 /* Rule 13 */
2648 /* Without an offset. */
2649 case REG:
2651 int regno = REGNO (XEXP (dest, 0));
2653 if (cfa.reg == (unsigned) regno)
2654 offset = -cfa.offset;
2655 else if (cfa_store.reg == (unsigned) regno)
2656 offset = -cfa_store.offset;
2657 else
2659 gcc_assert (cfa_temp.reg == (unsigned) regno);
2660 offset = -cfa_temp.offset;
2663 break;
2665 /* Rule 14 */
2666 case POST_INC:
2667 gcc_assert (cfa_temp.reg
2668 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
2669 offset = -cfa_temp.offset;
2670 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
2671 break;
2673 default:
2674 gcc_unreachable ();
2677 /* Rule 17 */
2678 /* If the source operand of this MEM operation is not a
2679 register, basically the source is return address. Here
2680 we only care how much stack grew and we don't save it. */
2681 if (!REG_P (src))
2682 break;
2684 if (REGNO (src) != STACK_POINTER_REGNUM
2685 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
2686 && (unsigned) REGNO (src) == cfa.reg)
2688 /* We're storing the current CFA reg into the stack. */
2690 if (cfa.offset == 0)
2692 /* Rule 19 */
2693 /* If stack is aligned, putting CFA reg into stack means
2694 we can no longer use reg + offset to represent CFA.
2695 Here we use DW_CFA_def_cfa_expression instead. The
2696 result of this expression equals to the original CFA
2697 value. */
2698 if (fde
2699 && fde->stack_realign
2700 && cfa.indirect == 0
2701 && cfa.reg != HARD_FRAME_POINTER_REGNUM)
2703 dw_cfa_location cfa_exp;
2705 gcc_assert (fde->drap_reg == cfa.reg);
2707 cfa_exp.indirect = 1;
2708 cfa_exp.reg = HARD_FRAME_POINTER_REGNUM;
2709 cfa_exp.base_offset = offset;
2710 cfa_exp.offset = 0;
2712 fde->drap_reg_saved = 1;
2714 def_cfa_1 (label, &cfa_exp);
2715 break;
2718 /* If the source register is exactly the CFA, assume
2719 we're saving SP like any other register; this happens
2720 on the ARM. */
2721 def_cfa_1 (label, &cfa);
2722 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
2723 break;
2725 else
2727 /* Otherwise, we'll need to look in the stack to
2728 calculate the CFA. */
2729 rtx x = XEXP (dest, 0);
2731 if (!REG_P (x))
2732 x = XEXP (x, 0);
2733 gcc_assert (REG_P (x));
2735 cfa.reg = REGNO (x);
2736 cfa.base_offset = offset;
2737 cfa.indirect = 1;
2738 def_cfa_1 (label, &cfa);
2739 break;
2743 def_cfa_1 (label, &cfa);
2745 span = targetm.dwarf_register_span (src);
2747 if (!span)
2748 queue_reg_save (label, src, NULL_RTX, offset);
2749 else
2751 /* We have a PARALLEL describing where the contents of SRC
2752 live. Queue register saves for each piece of the
2753 PARALLEL. */
2754 int par_index;
2755 int limit;
2756 HOST_WIDE_INT span_offset = offset;
2758 gcc_assert (GET_CODE (span) == PARALLEL);
2760 limit = XVECLEN (span, 0);
2761 for (par_index = 0; par_index < limit; par_index++)
2763 rtx elem = XVECEXP (span, 0, par_index);
2765 queue_reg_save (label, elem, NULL_RTX, span_offset);
2766 span_offset += GET_MODE_SIZE (GET_MODE (elem));
2770 break;
2772 default:
2773 gcc_unreachable ();
2777 /* Record call frame debugging information for INSN, which either
2778 sets SP or FP (adjusting how we calculate the frame address) or saves a
2779 register to the stack. If INSN is NULL_RTX, initialize our state.
2781 If AFTER_P is false, we're being called before the insn is emitted,
2782 otherwise after. Call instructions get invoked twice. */
2784 void
2785 dwarf2out_frame_debug (rtx insn, bool after_p)
2787 const char *label;
2788 rtx note, n;
2789 bool handled_one = false;
2791 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
2792 dwarf2out_flush_queued_reg_saves ();
2794 if (!RTX_FRAME_RELATED_P (insn))
2796 /* ??? This should be done unconditionally since stack adjustments
2797 matter if the stack pointer is not the CFA register anymore but
2798 is still used to save registers. */
2799 if (!ACCUMULATE_OUTGOING_ARGS)
2800 dwarf2out_notice_stack_adjust (insn, after_p);
2801 return;
2804 label = dwarf2out_cfi_label (false);
2805 any_cfis_emitted = false;
2807 for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
2808 switch (REG_NOTE_KIND (note))
2810 case REG_FRAME_RELATED_EXPR:
2811 insn = XEXP (note, 0);
2812 goto found;
2814 case REG_CFA_DEF_CFA:
2815 dwarf2out_frame_debug_def_cfa (XEXP (note, 0), label);
2816 handled_one = true;
2817 break;
2819 case REG_CFA_ADJUST_CFA:
2820 n = XEXP (note, 0);
2821 if (n == NULL)
2823 n = PATTERN (insn);
2824 if (GET_CODE (n) == PARALLEL)
2825 n = XVECEXP (n, 0, 0);
2827 dwarf2out_frame_debug_adjust_cfa (n, label);
2828 handled_one = true;
2829 break;
2831 case REG_CFA_OFFSET:
2832 n = XEXP (note, 0);
2833 if (n == NULL)
2834 n = single_set (insn);
2835 dwarf2out_frame_debug_cfa_offset (n, label);
2836 handled_one = true;
2837 break;
2839 case REG_CFA_REGISTER:
2840 n = XEXP (note, 0);
2841 if (n == NULL)
2843 n = PATTERN (insn);
2844 if (GET_CODE (n) == PARALLEL)
2845 n = XVECEXP (n, 0, 0);
2847 dwarf2out_frame_debug_cfa_register (n, label);
2848 handled_one = true;
2849 break;
2851 case REG_CFA_EXPRESSION:
2852 n = XEXP (note, 0);
2853 if (n == NULL)
2854 n = single_set (insn);
2855 dwarf2out_frame_debug_cfa_expression (n, label);
2856 handled_one = true;
2857 break;
2859 case REG_CFA_RESTORE:
2860 n = XEXP (note, 0);
2861 if (n == NULL)
2863 n = PATTERN (insn);
2864 if (GET_CODE (n) == PARALLEL)
2865 n = XVECEXP (n, 0, 0);
2866 n = XEXP (n, 0);
2868 dwarf2out_frame_debug_cfa_restore (n, label);
2869 handled_one = true;
2870 break;
2872 case REG_CFA_SET_VDRAP:
2873 n = XEXP (note, 0);
2874 if (REG_P (n))
2876 dw_fde_ref fde = current_fde ();
2877 if (fde)
2879 gcc_assert (fde->vdrap_reg == INVALID_REGNUM);
2880 if (REG_P (n))
2881 fde->vdrap_reg = REGNO (n);
2884 handled_one = true;
2885 break;
2887 default:
2888 break;
2890 if (handled_one)
2892 if (any_cfis_emitted)
2893 dwarf2out_flush_queued_reg_saves ();
2894 return;
2897 insn = PATTERN (insn);
2898 found:
2899 dwarf2out_frame_debug_expr (insn, label);
2901 /* Check again. A parallel can save and update the same register.
2902 We could probably check just once, here, but this is safer than
2903 removing the check above. */
2904 if (any_cfis_emitted || clobbers_queued_reg_save (insn))
2905 dwarf2out_flush_queued_reg_saves ();
2908 /* Called once at the start of final to initialize some data for the
2909 current function. */
2910 void
2911 dwarf2out_frame_debug_init (void)
2913 size_t i;
2915 /* Flush any queued register saves. */
2916 dwarf2out_flush_queued_reg_saves ();
2918 /* Set up state for generating call frame debug info. */
2919 lookup_cfa (&cfa);
2920 gcc_assert (cfa.reg
2921 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
2923 cfa.reg = STACK_POINTER_REGNUM;
2924 cfa_store = cfa;
2925 cfa_temp.reg = -1;
2926 cfa_temp.offset = 0;
2928 for (i = 0; i < num_regs_saved_in_regs; i++)
2930 regs_saved_in_regs[i].orig_reg = NULL_RTX;
2931 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
2933 num_regs_saved_in_regs = 0;
2935 if (barrier_args_size)
2937 XDELETEVEC (barrier_args_size);
2938 barrier_args_size = NULL;
2942 /* Determine if we need to save and restore CFI information around this
2943 epilogue. If SIBCALL is true, then this is a sibcall epilogue. If
2944 we do need to save/restore, then emit the save now, and insert a
2945 NOTE_INSN_CFA_RESTORE_STATE at the appropriate place in the stream. */
2947 void
2948 dwarf2out_cfi_begin_epilogue (rtx insn)
2950 bool saw_frp = false;
2951 rtx i;
2953 /* Scan forward to the return insn, noticing if there are possible
2954 frame related insns. */
2955 for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
2957 if (!INSN_P (i))
2958 continue;
2960 /* Look for both regular and sibcalls to end the block. */
2961 if (returnjump_p (i))
2962 break;
2963 if (CALL_P (i) && SIBLING_CALL_P (i))
2964 break;
2966 if (GET_CODE (PATTERN (i)) == SEQUENCE)
2968 int idx;
2969 rtx seq = PATTERN (i);
2971 if (returnjump_p (XVECEXP (seq, 0, 0)))
2972 break;
2973 if (CALL_P (XVECEXP (seq, 0, 0))
2974 && SIBLING_CALL_P (XVECEXP (seq, 0, 0)))
2975 break;
2977 for (idx = 0; idx < XVECLEN (seq, 0); idx++)
2978 if (RTX_FRAME_RELATED_P (XVECEXP (seq, 0, idx)))
2979 saw_frp = true;
2982 if (RTX_FRAME_RELATED_P (i))
2983 saw_frp = true;
2986 /* If the port doesn't emit epilogue unwind info, we don't need a
2987 save/restore pair. */
2988 if (!saw_frp)
2989 return;
2991 /* Otherwise, search forward to see if the return insn was the last
2992 basic block of the function. If so, we don't need save/restore. */
2993 gcc_assert (i != NULL);
2994 i = next_real_insn (i);
2995 if (i == NULL)
2996 return;
2998 /* Insert the restore before that next real insn in the stream, and before
2999 a potential NOTE_INSN_EPILOGUE_BEG -- we do need these notes to be
3000 properly nested. This should be after any label or alignment. This
3001 will be pushed into the CFI stream by the function below. */
3002 while (1)
3004 rtx p = PREV_INSN (i);
3005 if (!NOTE_P (p))
3006 break;
3007 if (NOTE_KIND (p) == NOTE_INSN_BASIC_BLOCK)
3008 break;
3009 i = p;
3011 emit_note_before (NOTE_INSN_CFA_RESTORE_STATE, i);
3013 emit_cfa_remember = true;
3015 /* And emulate the state save. */
3016 gcc_assert (!cfa_remember.in_use);
3017 cfa_remember = cfa;
3018 cfa_remember.in_use = 1;
3021 /* A "subroutine" of dwarf2out_cfi_begin_epilogue. Emit the restore
3022 required. */
3024 void
3025 dwarf2out_frame_debug_restore_state (void)
3027 dw_cfi_ref cfi = new_cfi ();
3028 const char *label = dwarf2out_cfi_label (false);
3030 cfi->dw_cfi_opc = DW_CFA_restore_state;
3031 add_fde_cfi (label, cfi);
3033 gcc_assert (cfa_remember.in_use);
3034 cfa = cfa_remember;
3035 cfa_remember.in_use = 0;
3038 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
3039 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
3040 (enum dwarf_call_frame_info cfi);
3042 static enum dw_cfi_oprnd_type
3043 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
3045 switch (cfi)
3047 case DW_CFA_nop:
3048 case DW_CFA_GNU_window_save:
3049 case DW_CFA_remember_state:
3050 case DW_CFA_restore_state:
3051 return dw_cfi_oprnd_unused;
3053 case DW_CFA_set_loc:
3054 case DW_CFA_advance_loc1:
3055 case DW_CFA_advance_loc2:
3056 case DW_CFA_advance_loc4:
3057 case DW_CFA_MIPS_advance_loc8:
3058 return dw_cfi_oprnd_addr;
3060 case DW_CFA_offset:
3061 case DW_CFA_offset_extended:
3062 case DW_CFA_def_cfa:
3063 case DW_CFA_offset_extended_sf:
3064 case DW_CFA_def_cfa_sf:
3065 case DW_CFA_restore:
3066 case DW_CFA_restore_extended:
3067 case DW_CFA_undefined:
3068 case DW_CFA_same_value:
3069 case DW_CFA_def_cfa_register:
3070 case DW_CFA_register:
3071 case DW_CFA_expression:
3072 return dw_cfi_oprnd_reg_num;
3074 case DW_CFA_def_cfa_offset:
3075 case DW_CFA_GNU_args_size:
3076 case DW_CFA_def_cfa_offset_sf:
3077 return dw_cfi_oprnd_offset;
3079 case DW_CFA_def_cfa_expression:
3080 return dw_cfi_oprnd_loc;
3082 default:
3083 gcc_unreachable ();
3087 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
3088 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
3089 (enum dwarf_call_frame_info cfi);
3091 static enum dw_cfi_oprnd_type
3092 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
3094 switch (cfi)
3096 case DW_CFA_def_cfa:
3097 case DW_CFA_def_cfa_sf:
3098 case DW_CFA_offset:
3099 case DW_CFA_offset_extended_sf:
3100 case DW_CFA_offset_extended:
3101 return dw_cfi_oprnd_offset;
3103 case DW_CFA_register:
3104 return dw_cfi_oprnd_reg_num;
3106 case DW_CFA_expression:
3107 return dw_cfi_oprnd_loc;
3109 default:
3110 return dw_cfi_oprnd_unused;
3114 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
3115 switch to the data section instead, and write out a synthetic start label
3116 for collect2 the first time around. */
3118 static void
3119 switch_to_eh_frame_section (bool back)
3121 tree label;
3123 #ifdef EH_FRAME_SECTION_NAME
3124 if (eh_frame_section == 0)
3126 int flags;
3128 if (EH_TABLES_CAN_BE_READ_ONLY)
3130 int fde_encoding;
3131 int per_encoding;
3132 int lsda_encoding;
3134 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
3135 /*global=*/0);
3136 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
3137 /*global=*/1);
3138 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
3139 /*global=*/0);
3140 flags = ((! flag_pic
3141 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
3142 && (fde_encoding & 0x70) != DW_EH_PE_aligned
3143 && (per_encoding & 0x70) != DW_EH_PE_absptr
3144 && (per_encoding & 0x70) != DW_EH_PE_aligned
3145 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
3146 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
3147 ? 0 : SECTION_WRITE);
3149 else
3150 flags = SECTION_WRITE;
3151 eh_frame_section = get_section (EH_FRAME_SECTION_NAME, flags, NULL);
3153 #endif /* EH_FRAME_SECTION_NAME */
3155 if (eh_frame_section)
3156 switch_to_section (eh_frame_section);
3157 else
3159 /* We have no special eh_frame section. Put the information in
3160 the data section and emit special labels to guide collect2. */
3161 switch_to_section (data_section);
3163 if (!back)
3165 label = get_file_function_name ("F");
3166 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3167 targetm.asm_out.globalize_label (asm_out_file,
3168 IDENTIFIER_POINTER (label));
3169 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
3174 /* Switch [BACK] to the eh or debug frame table section, depending on
3175 FOR_EH. */
3177 static void
3178 switch_to_frame_table_section (int for_eh, bool back)
3180 if (for_eh)
3181 switch_to_eh_frame_section (back);
3182 else
3184 if (!debug_frame_section)
3185 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
3186 SECTION_DEBUG, NULL);
3187 switch_to_section (debug_frame_section);
3191 /* Output a Call Frame Information opcode and its operand(s). */
3193 static void
3194 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
3196 unsigned long r;
3197 HOST_WIDE_INT off;
3199 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
3200 dw2_asm_output_data (1, (cfi->dw_cfi_opc
3201 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
3202 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
3203 ((unsigned HOST_WIDE_INT)
3204 cfi->dw_cfi_oprnd1.dw_cfi_offset));
3205 else if (cfi->dw_cfi_opc == DW_CFA_offset)
3207 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3208 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3209 "DW_CFA_offset, column %#lx", r);
3210 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3211 dw2_asm_output_data_uleb128 (off, NULL);
3213 else if (cfi->dw_cfi_opc == DW_CFA_restore)
3215 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3216 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
3217 "DW_CFA_restore, column %#lx", r);
3219 else
3221 dw2_asm_output_data (1, cfi->dw_cfi_opc,
3222 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
3224 switch (cfi->dw_cfi_opc)
3226 case DW_CFA_set_loc:
3227 if (for_eh)
3228 dw2_asm_output_encoded_addr_rtx (
3229 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
3230 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
3231 false, NULL);
3232 else
3233 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
3234 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
3235 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3236 break;
3238 case DW_CFA_advance_loc1:
3239 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3240 fde->dw_fde_current_label, NULL);
3241 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3242 break;
3244 case DW_CFA_advance_loc2:
3245 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3246 fde->dw_fde_current_label, NULL);
3247 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3248 break;
3250 case DW_CFA_advance_loc4:
3251 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3252 fde->dw_fde_current_label, NULL);
3253 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3254 break;
3256 case DW_CFA_MIPS_advance_loc8:
3257 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
3258 fde->dw_fde_current_label, NULL);
3259 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
3260 break;
3262 case DW_CFA_offset_extended:
3263 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3264 dw2_asm_output_data_uleb128 (r, NULL);
3265 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3266 dw2_asm_output_data_uleb128 (off, NULL);
3267 break;
3269 case DW_CFA_def_cfa:
3270 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3271 dw2_asm_output_data_uleb128 (r, NULL);
3272 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
3273 break;
3275 case DW_CFA_offset_extended_sf:
3276 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3277 dw2_asm_output_data_uleb128 (r, NULL);
3278 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3279 dw2_asm_output_data_sleb128 (off, NULL);
3280 break;
3282 case DW_CFA_def_cfa_sf:
3283 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3284 dw2_asm_output_data_uleb128 (r, NULL);
3285 off = div_data_align (cfi->dw_cfi_oprnd2.dw_cfi_offset);
3286 dw2_asm_output_data_sleb128 (off, NULL);
3287 break;
3289 case DW_CFA_restore_extended:
3290 case DW_CFA_undefined:
3291 case DW_CFA_same_value:
3292 case DW_CFA_def_cfa_register:
3293 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3294 dw2_asm_output_data_uleb128 (r, NULL);
3295 break;
3297 case DW_CFA_register:
3298 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
3299 dw2_asm_output_data_uleb128 (r, NULL);
3300 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
3301 dw2_asm_output_data_uleb128 (r, NULL);
3302 break;
3304 case DW_CFA_def_cfa_offset:
3305 case DW_CFA_GNU_args_size:
3306 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
3307 break;
3309 case DW_CFA_def_cfa_offset_sf:
3310 off = div_data_align (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3311 dw2_asm_output_data_sleb128 (off, NULL);
3312 break;
3314 case DW_CFA_GNU_window_save:
3315 break;
3317 case DW_CFA_def_cfa_expression:
3318 case DW_CFA_expression:
3319 output_cfa_loc (cfi, for_eh);
3320 break;
3322 case DW_CFA_GNU_negative_offset_extended:
3323 /* Obsoleted by DW_CFA_offset_extended_sf. */
3324 gcc_unreachable ();
3326 default:
3327 break;
3332 /* Similar, but do it via assembler directives instead. */
3334 static void
3335 output_cfi_directive (dw_cfi_ref cfi)
3337 unsigned long r, r2;
3339 switch (cfi->dw_cfi_opc)
3341 case DW_CFA_advance_loc:
3342 case DW_CFA_advance_loc1:
3343 case DW_CFA_advance_loc2:
3344 case DW_CFA_advance_loc4:
3345 case DW_CFA_MIPS_advance_loc8:
3346 case DW_CFA_set_loc:
3347 /* Should only be created by add_fde_cfi in a code path not
3348 followed when emitting via directives. The assembler is
3349 going to take care of this for us. */
3350 gcc_unreachable ();
3352 case DW_CFA_offset:
3353 case DW_CFA_offset_extended:
3354 case DW_CFA_offset_extended_sf:
3355 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3356 fprintf (asm_out_file, "\t.cfi_offset %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3357 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3358 break;
3360 case DW_CFA_restore:
3361 case DW_CFA_restore_extended:
3362 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3363 fprintf (asm_out_file, "\t.cfi_restore %lu\n", r);
3364 break;
3366 case DW_CFA_undefined:
3367 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3368 fprintf (asm_out_file, "\t.cfi_undefined %lu\n", r);
3369 break;
3371 case DW_CFA_same_value:
3372 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3373 fprintf (asm_out_file, "\t.cfi_same_value %lu\n", r);
3374 break;
3376 case DW_CFA_def_cfa:
3377 case DW_CFA_def_cfa_sf:
3378 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3379 fprintf (asm_out_file, "\t.cfi_def_cfa %lu, "HOST_WIDE_INT_PRINT_DEC"\n",
3380 r, cfi->dw_cfi_oprnd2.dw_cfi_offset);
3381 break;
3383 case DW_CFA_def_cfa_register:
3384 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3385 fprintf (asm_out_file, "\t.cfi_def_cfa_register %lu\n", r);
3386 break;
3388 case DW_CFA_register:
3389 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
3390 r2 = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1);
3391 fprintf (asm_out_file, "\t.cfi_register %lu, %lu\n", r, r2);
3392 break;
3394 case DW_CFA_def_cfa_offset:
3395 case DW_CFA_def_cfa_offset_sf:
3396 fprintf (asm_out_file, "\t.cfi_def_cfa_offset "
3397 HOST_WIDE_INT_PRINT_DEC"\n",
3398 cfi->dw_cfi_oprnd1.dw_cfi_offset);
3399 break;
3401 case DW_CFA_remember_state:
3402 fprintf (asm_out_file, "\t.cfi_remember_state\n");
3403 break;
3404 case DW_CFA_restore_state:
3405 fprintf (asm_out_file, "\t.cfi_restore_state\n");
3406 break;
3408 case DW_CFA_GNU_args_size:
3409 fprintf (asm_out_file, "\t.cfi_escape %#x,", DW_CFA_GNU_args_size);
3410 dw2_asm_output_data_uleb128_raw (cfi->dw_cfi_oprnd1.dw_cfi_offset);
3411 if (flag_debug_asm)
3412 fprintf (asm_out_file, "\t%s args_size "HOST_WIDE_INT_PRINT_DEC,
3413 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
3414 fputc ('\n', asm_out_file);
3415 break;
3417 case DW_CFA_GNU_window_save:
3418 fprintf (asm_out_file, "\t.cfi_window_save\n");
3419 break;
3421 case DW_CFA_def_cfa_expression:
3422 case DW_CFA_expression:
3423 fprintf (asm_out_file, "\t.cfi_escape %#x,", cfi->dw_cfi_opc);
3424 output_cfa_loc_raw (cfi);
3425 fputc ('\n', asm_out_file);
3426 break;
3428 default:
3429 gcc_unreachable ();
3433 DEF_VEC_P (dw_cfi_ref);
3434 DEF_VEC_ALLOC_P (dw_cfi_ref, heap);
3436 /* Output CFIs to bring current FDE to the same state as after executing
3437 CFIs in CFI chain. DO_CFI_ASM is true if .cfi_* directives shall
3438 be emitted, false otherwise. If it is false, FDE and FOR_EH are the
3439 other arguments to pass to output_cfi. */
3441 static void
3442 output_cfis (dw_cfi_ref cfi, bool do_cfi_asm, dw_fde_ref fde, bool for_eh)
3444 struct dw_cfi_struct cfi_buf;
3445 dw_cfi_ref cfi2;
3446 dw_cfi_ref cfi_args_size = NULL, cfi_cfa = NULL, cfi_cfa_offset = NULL;
3447 VEC (dw_cfi_ref, heap) *regs = VEC_alloc (dw_cfi_ref, heap, 32);
3448 unsigned int len, idx;
3450 for (;; cfi = cfi->dw_cfi_next)
3451 switch (cfi ? cfi->dw_cfi_opc : DW_CFA_nop)
3453 case DW_CFA_advance_loc:
3454 case DW_CFA_advance_loc1:
3455 case DW_CFA_advance_loc2:
3456 case DW_CFA_advance_loc4:
3457 case DW_CFA_MIPS_advance_loc8:
3458 case DW_CFA_set_loc:
3459 /* All advances should be ignored. */
3460 break;
3461 case DW_CFA_remember_state:
3463 dw_cfi_ref args_size = cfi_args_size;
3465 /* Skip everything between .cfi_remember_state and
3466 .cfi_restore_state. */
3467 for (cfi2 = cfi->dw_cfi_next; cfi2; cfi2 = cfi2->dw_cfi_next)
3468 if (cfi2->dw_cfi_opc == DW_CFA_restore_state)
3469 break;
3470 else if (cfi2->dw_cfi_opc == DW_CFA_GNU_args_size)
3471 args_size = cfi2;
3472 else
3473 gcc_assert (cfi2->dw_cfi_opc != DW_CFA_remember_state);
3475 if (cfi2 == NULL)
3476 goto flush_all;
3477 else
3479 cfi = cfi2;
3480 cfi_args_size = args_size;
3482 break;
3484 case DW_CFA_GNU_args_size:
3485 cfi_args_size = cfi;
3486 break;
3487 case DW_CFA_GNU_window_save:
3488 goto flush_all;
3489 case DW_CFA_offset:
3490 case DW_CFA_offset_extended:
3491 case DW_CFA_offset_extended_sf:
3492 case DW_CFA_restore:
3493 case DW_CFA_restore_extended:
3494 case DW_CFA_undefined:
3495 case DW_CFA_same_value:
3496 case DW_CFA_register:
3497 case DW_CFA_val_offset:
3498 case DW_CFA_val_offset_sf:
3499 case DW_CFA_expression:
3500 case DW_CFA_val_expression:
3501 case DW_CFA_GNU_negative_offset_extended:
3502 if (VEC_length (dw_cfi_ref, regs) <= cfi->dw_cfi_oprnd1.dw_cfi_reg_num)
3503 VEC_safe_grow_cleared (dw_cfi_ref, heap, regs,
3504 cfi->dw_cfi_oprnd1.dw_cfi_reg_num + 1);
3505 VEC_replace (dw_cfi_ref, regs, cfi->dw_cfi_oprnd1.dw_cfi_reg_num, cfi);
3506 break;
3507 case DW_CFA_def_cfa:
3508 case DW_CFA_def_cfa_sf:
3509 case DW_CFA_def_cfa_expression:
3510 cfi_cfa = cfi;
3511 cfi_cfa_offset = cfi;
3512 break;
3513 case DW_CFA_def_cfa_register:
3514 cfi_cfa = cfi;
3515 break;
3516 case DW_CFA_def_cfa_offset:
3517 case DW_CFA_def_cfa_offset_sf:
3518 cfi_cfa_offset = cfi;
3519 break;
3520 case DW_CFA_nop:
3521 gcc_assert (cfi == NULL);
3522 flush_all:
3523 len = VEC_length (dw_cfi_ref, regs);
3524 for (idx = 0; idx < len; idx++)
3526 cfi2 = VEC_replace (dw_cfi_ref, regs, idx, NULL);
3527 if (cfi2 != NULL
3528 && cfi2->dw_cfi_opc != DW_CFA_restore
3529 && cfi2->dw_cfi_opc != DW_CFA_restore_extended)
3531 if (do_cfi_asm)
3532 output_cfi_directive (cfi2);
3533 else
3534 output_cfi (cfi2, fde, for_eh);
3537 if (cfi_cfa && cfi_cfa_offset && cfi_cfa_offset != cfi_cfa)
3539 gcc_assert (cfi_cfa->dw_cfi_opc != DW_CFA_def_cfa_expression);
3540 cfi_buf = *cfi_cfa;
3541 switch (cfi_cfa_offset->dw_cfi_opc)
3543 case DW_CFA_def_cfa_offset:
3544 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa;
3545 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3546 break;
3547 case DW_CFA_def_cfa_offset_sf:
3548 cfi_buf.dw_cfi_opc = DW_CFA_def_cfa_sf;
3549 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd1;
3550 break;
3551 case DW_CFA_def_cfa:
3552 case DW_CFA_def_cfa_sf:
3553 cfi_buf.dw_cfi_opc = cfi_cfa_offset->dw_cfi_opc;
3554 cfi_buf.dw_cfi_oprnd2 = cfi_cfa_offset->dw_cfi_oprnd2;
3555 break;
3556 default:
3557 gcc_unreachable ();
3559 cfi_cfa = &cfi_buf;
3561 else if (cfi_cfa_offset)
3562 cfi_cfa = cfi_cfa_offset;
3563 if (cfi_cfa)
3565 if (do_cfi_asm)
3566 output_cfi_directive (cfi_cfa);
3567 else
3568 output_cfi (cfi_cfa, fde, for_eh);
3570 cfi_cfa = NULL;
3571 cfi_cfa_offset = NULL;
3572 if (cfi_args_size
3573 && cfi_args_size->dw_cfi_oprnd1.dw_cfi_offset)
3575 if (do_cfi_asm)
3576 output_cfi_directive (cfi_args_size);
3577 else
3578 output_cfi (cfi_args_size, fde, for_eh);
3580 cfi_args_size = NULL;
3581 if (cfi == NULL)
3583 VEC_free (dw_cfi_ref, heap, regs);
3584 return;
3586 else if (do_cfi_asm)
3587 output_cfi_directive (cfi);
3588 else
3589 output_cfi (cfi, fde, for_eh);
3590 break;
3591 default:
3592 gcc_unreachable ();
3596 /* Output one FDE. */
3598 static void
3599 output_fde (dw_fde_ref fde, bool for_eh, bool second,
3600 char *section_start_label, int fde_encoding, char *augmentation,
3601 bool any_lsda_needed, int lsda_encoding)
3603 const char *begin, *end;
3604 static unsigned int j;
3605 char l1[20], l2[20];
3606 dw_cfi_ref cfi;
3608 targetm.asm_out.emit_unwind_label (asm_out_file, fde->decl, for_eh,
3609 /* empty */ 0);
3610 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL,
3611 for_eh + j);
3612 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + j);
3613 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + j);
3614 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3615 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
3616 " indicating 64-bit DWARF extension");
3617 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3618 "FDE Length");
3619 ASM_OUTPUT_LABEL (asm_out_file, l1);
3621 if (for_eh)
3622 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
3623 else
3624 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
3625 debug_frame_section, "FDE CIE offset");
3627 begin = second ? fde->dw_fde_second_begin : fde->dw_fde_begin;
3628 end = second ? fde->dw_fde_second_end : fde->dw_fde_end;
3630 if (for_eh)
3632 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, begin);
3633 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
3634 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref, false,
3635 "FDE initial location");
3636 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
3637 end, begin, "FDE address range");
3639 else
3641 dw2_asm_output_addr (DWARF2_ADDR_SIZE, begin, "FDE initial location");
3642 dw2_asm_output_delta (DWARF2_ADDR_SIZE, end, begin, "FDE address range");
3645 if (augmentation[0])
3647 if (any_lsda_needed)
3649 int size = size_of_encoded_value (lsda_encoding);
3651 if (lsda_encoding == DW_EH_PE_aligned)
3653 int offset = ( 4 /* Length */
3654 + 4 /* CIE offset */
3655 + 2 * size_of_encoded_value (fde_encoding)
3656 + 1 /* Augmentation size */ );
3657 int pad = -offset & (PTR_SIZE - 1);
3659 size += pad;
3660 gcc_assert (size_of_uleb128 (size) == 1);
3663 dw2_asm_output_data_uleb128 (size, "Augmentation size");
3665 if (fde->uses_eh_lsda)
3667 ASM_GENERATE_INTERNAL_LABEL (l1, second ? "LLSDAC" : "LLSDA",
3668 fde->funcdef_number);
3669 dw2_asm_output_encoded_addr_rtx (lsda_encoding,
3670 gen_rtx_SYMBOL_REF (Pmode, l1),
3671 false,
3672 "Language Specific Data Area");
3674 else
3676 if (lsda_encoding == DW_EH_PE_aligned)
3677 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
3678 dw2_asm_output_data (size_of_encoded_value (lsda_encoding), 0,
3679 "Language Specific Data Area (none)");
3682 else
3683 dw2_asm_output_data_uleb128 (0, "Augmentation size");
3686 /* Loop through the Call Frame Instructions associated with
3687 this FDE. */
3688 fde->dw_fde_current_label = begin;
3689 if (fde->dw_fde_second_begin == NULL)
3690 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3691 output_cfi (cfi, fde, for_eh);
3692 else if (!second)
3694 if (fde->dw_fde_switch_cfi)
3695 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
3697 output_cfi (cfi, fde, for_eh);
3698 if (cfi == fde->dw_fde_switch_cfi)
3699 break;
3702 else
3704 dw_cfi_ref cfi_next = fde->dw_fde_cfi;
3706 if (fde->dw_fde_switch_cfi)
3708 cfi_next = fde->dw_fde_switch_cfi->dw_cfi_next;
3709 fde->dw_fde_switch_cfi->dw_cfi_next = NULL;
3710 output_cfis (fde->dw_fde_cfi, false, fde, for_eh);
3711 fde->dw_fde_switch_cfi->dw_cfi_next = cfi_next;
3713 for (cfi = cfi_next; cfi != NULL; cfi = cfi->dw_cfi_next)
3714 output_cfi (cfi, fde, for_eh);
3717 /* If we are to emit a ref/link from function bodies to their frame tables,
3718 do it now. This is typically performed to make sure that tables
3719 associated with functions are dragged with them and not discarded in
3720 garbage collecting links. We need to do this on a per function basis to
3721 cope with -ffunction-sections. */
3723 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
3724 /* Switch to the function section, emit the ref to the tables, and
3725 switch *back* into the table section. */
3726 switch_to_section (function_section (fde->decl));
3727 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label);
3728 switch_to_frame_table_section (for_eh, true);
3729 #endif
3731 /* Pad the FDE out to an address sized boundary. */
3732 ASM_OUTPUT_ALIGN (asm_out_file,
3733 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
3734 ASM_OUTPUT_LABEL (asm_out_file, l2);
3736 j += 2;
3739 /* Return true if frame description entry FDE is needed for EH. */
3741 static bool
3742 fde_needed_for_eh_p (dw_fde_ref fde)
3744 if (flag_asynchronous_unwind_tables)
3745 return true;
3747 if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde->decl))
3748 return true;
3750 if (fde->uses_eh_lsda)
3751 return true;
3753 /* If exceptions are enabled, we have collected nothrow info. */
3754 if (flag_exceptions && (fde->all_throwers_are_sibcalls || fde->nothrow))
3755 return false;
3757 return true;
3760 /* Output the call frame information used to record information
3761 that relates to calculating the frame pointer, and records the
3762 location of saved registers. */
3764 static void
3765 output_call_frame_info (int for_eh)
3767 unsigned int i;
3768 dw_fde_ref fde;
3769 dw_cfi_ref cfi;
3770 char l1[20], l2[20], section_start_label[20];
3771 bool any_lsda_needed = false;
3772 char augmentation[6];
3773 int augmentation_size;
3774 int fde_encoding = DW_EH_PE_absptr;
3775 int per_encoding = DW_EH_PE_absptr;
3776 int lsda_encoding = DW_EH_PE_absptr;
3777 int return_reg;
3778 rtx personality = NULL;
3779 int dw_cie_version;
3781 /* Don't emit a CIE if there won't be any FDEs. */
3782 if (fde_table_in_use == 0)
3783 return;
3785 /* Nothing to do if the assembler's doing it all. */
3786 if (dwarf2out_do_cfi_asm ())
3787 return;
3789 /* If we don't have any functions we'll want to unwind out of, don't emit
3790 any EH unwind information. If we make FDEs linkonce, we may have to
3791 emit an empty label for an FDE that wouldn't otherwise be emitted. We
3792 want to avoid having an FDE kept around when the function it refers to
3793 is discarded. Example where this matters: a primary function template
3794 in C++ requires EH information, an explicit specialization doesn't. */
3795 if (for_eh)
3797 bool any_eh_needed = false;
3799 for (i = 0; i < fde_table_in_use; i++)
3800 if (fde_table[i].uses_eh_lsda)
3801 any_eh_needed = any_lsda_needed = true;
3802 else if (fde_needed_for_eh_p (&fde_table[i]))
3803 any_eh_needed = true;
3804 else if (TARGET_USES_WEAK_UNWIND_INFO)
3805 targetm.asm_out.emit_unwind_label (asm_out_file, fde_table[i].decl,
3806 1, 1);
3808 if (!any_eh_needed)
3809 return;
3812 /* We're going to be generating comments, so turn on app. */
3813 if (flag_debug_asm)
3814 app_enable ();
3816 /* Switch to the proper frame section, first time. */
3817 switch_to_frame_table_section (for_eh, false);
3819 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
3820 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
3822 /* Output the CIE. */
3823 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
3824 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
3825 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4 && !for_eh)
3826 dw2_asm_output_data (4, 0xffffffff,
3827 "Initial length escape value indicating 64-bit DWARF extension");
3828 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
3829 "Length of Common Information Entry");
3830 ASM_OUTPUT_LABEL (asm_out_file, l1);
3832 /* Now that the CIE pointer is PC-relative for EH,
3833 use 0 to identify the CIE. */
3834 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
3835 (for_eh ? 0 : DWARF_CIE_ID),
3836 "CIE Identifier Tag");
3838 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
3839 use CIE version 1, unless that would produce incorrect results
3840 due to overflowing the return register column. */
3841 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
3842 dw_cie_version = 1;
3843 if (return_reg >= 256 || dwarf_version > 2)
3844 dw_cie_version = 3;
3845 dw2_asm_output_data (1, dw_cie_version, "CIE Version");
3847 augmentation[0] = 0;
3848 augmentation_size = 0;
3850 personality = current_unit_personality;
3851 if (for_eh)
3853 char *p;
3855 /* Augmentation:
3856 z Indicates that a uleb128 is present to size the
3857 augmentation section.
3858 L Indicates the encoding (and thus presence) of
3859 an LSDA pointer in the FDE augmentation.
3860 R Indicates a non-default pointer encoding for
3861 FDE code pointers.
3862 P Indicates the presence of an encoding + language
3863 personality routine in the CIE augmentation. */
3865 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
3866 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
3867 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
3869 p = augmentation + 1;
3870 if (personality)
3872 *p++ = 'P';
3873 augmentation_size += 1 + size_of_encoded_value (per_encoding);
3874 assemble_external_libcall (personality);
3876 if (any_lsda_needed)
3878 *p++ = 'L';
3879 augmentation_size += 1;
3881 if (fde_encoding != DW_EH_PE_absptr)
3883 *p++ = 'R';
3884 augmentation_size += 1;
3886 if (p > augmentation + 1)
3888 augmentation[0] = 'z';
3889 *p = '\0';
3892 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
3893 if (personality && per_encoding == DW_EH_PE_aligned)
3895 int offset = ( 4 /* Length */
3896 + 4 /* CIE Id */
3897 + 1 /* CIE version */
3898 + strlen (augmentation) + 1 /* Augmentation */
3899 + size_of_uleb128 (1) /* Code alignment */
3900 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
3901 + 1 /* RA column */
3902 + 1 /* Augmentation size */
3903 + 1 /* Personality encoding */ );
3904 int pad = -offset & (PTR_SIZE - 1);
3906 augmentation_size += pad;
3908 /* Augmentations should be small, so there's scarce need to
3909 iterate for a solution. Die if we exceed one uleb128 byte. */
3910 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
3914 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
3915 if (dw_cie_version >= 4)
3917 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "CIE Address Size");
3918 dw2_asm_output_data (1, 0, "CIE Segment Size");
3920 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
3921 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
3922 "CIE Data Alignment Factor");
3924 if (dw_cie_version == 1)
3925 dw2_asm_output_data (1, return_reg, "CIE RA Column");
3926 else
3927 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
3929 if (augmentation[0])
3931 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
3932 if (personality)
3934 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
3935 eh_data_format_name (per_encoding));
3936 dw2_asm_output_encoded_addr_rtx (per_encoding,
3937 personality,
3938 true, NULL);
3941 if (any_lsda_needed)
3942 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
3943 eh_data_format_name (lsda_encoding));
3945 if (fde_encoding != DW_EH_PE_absptr)
3946 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
3947 eh_data_format_name (fde_encoding));
3950 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
3951 output_cfi (cfi, NULL, for_eh);
3953 /* Pad the CIE out to an address sized boundary. */
3954 ASM_OUTPUT_ALIGN (asm_out_file,
3955 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
3956 ASM_OUTPUT_LABEL (asm_out_file, l2);
3958 /* Loop through all of the FDE's. */
3959 for (i = 0; i < fde_table_in_use; i++)
3961 unsigned int k;
3962 fde = &fde_table[i];
3964 /* Don't emit EH unwind info for leaf functions that don't need it. */
3965 if (for_eh && !fde_needed_for_eh_p (fde))
3966 continue;
3968 for (k = 0; k < (fde->dw_fde_second_begin ? 2 : 1); k++)
3969 output_fde (fde, for_eh, k, section_start_label, fde_encoding,
3970 augmentation, any_lsda_needed, lsda_encoding);
3973 if (for_eh && targetm.terminate_dw2_eh_frame_info)
3974 dw2_asm_output_data (4, 0, "End of Table");
3975 #ifdef MIPS_DEBUGGING_INFO
3976 /* Work around Irix 6 assembler bug whereby labels at the end of a section
3977 get a value of 0. Putting .align 0 after the label fixes it. */
3978 ASM_OUTPUT_ALIGN (asm_out_file, 0);
3979 #endif
3981 /* Turn off app to make assembly quicker. */
3982 if (flag_debug_asm)
3983 app_disable ();
3986 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
3988 static void
3989 dwarf2out_do_cfi_startproc (bool second)
3991 int enc;
3992 rtx ref;
3993 rtx personality = get_personality_function (current_function_decl);
3995 fprintf (asm_out_file, "\t.cfi_startproc\n");
3997 if (personality)
3999 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
4000 ref = personality;
4002 /* ??? The GAS support isn't entirely consistent. We have to
4003 handle indirect support ourselves, but PC-relative is done
4004 in the assembler. Further, the assembler can't handle any
4005 of the weirder relocation types. */
4006 if (enc & DW_EH_PE_indirect)
4007 ref = dw2_force_const_mem (ref, true);
4009 fprintf (asm_out_file, "\t.cfi_personality %#x,", enc);
4010 output_addr_const (asm_out_file, ref);
4011 fputc ('\n', asm_out_file);
4014 if (crtl->uses_eh_lsda)
4016 char lab[20];
4018 enc = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
4019 ASM_GENERATE_INTERNAL_LABEL (lab, second ? "LLSDAC" : "LLSDA",
4020 current_function_funcdef_no);
4021 ref = gen_rtx_SYMBOL_REF (Pmode, lab);
4022 SYMBOL_REF_FLAGS (ref) = SYMBOL_FLAG_LOCAL;
4024 if (enc & DW_EH_PE_indirect)
4025 ref = dw2_force_const_mem (ref, true);
4027 fprintf (asm_out_file, "\t.cfi_lsda %#x,", enc);
4028 output_addr_const (asm_out_file, ref);
4029 fputc ('\n', asm_out_file);
4033 /* Output a marker (i.e. a label) for the beginning of a function, before
4034 the prologue. */
4036 void
4037 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
4038 const char *file ATTRIBUTE_UNUSED)
4040 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4041 char * dup_label;
4042 dw_fde_ref fde;
4043 section *fnsec;
4044 bool do_frame;
4046 current_function_func_begin_label = NULL;
4048 do_frame = dwarf2out_do_frame ();
4050 /* ??? current_function_func_begin_label is also used by except.c for
4051 call-site information. We must emit this label if it might be used. */
4052 if (!do_frame
4053 && (!flag_exceptions
4054 || targetm.except_unwind_info (&global_options) != UI_TARGET))
4055 return;
4057 fnsec = function_section (current_function_decl);
4058 switch_to_section (fnsec);
4059 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
4060 current_function_funcdef_no);
4061 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
4062 current_function_funcdef_no);
4063 dup_label = xstrdup (label);
4064 current_function_func_begin_label = dup_label;
4066 /* We can elide the fde allocation if we're not emitting debug info. */
4067 if (!do_frame)
4068 return;
4070 /* Expand the fde table if necessary. */
4071 if (fde_table_in_use == fde_table_allocated)
4073 fde_table_allocated += FDE_TABLE_INCREMENT;
4074 fde_table = GGC_RESIZEVEC (dw_fde_node, fde_table, fde_table_allocated);
4075 memset (fde_table + fde_table_in_use, 0,
4076 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
4079 /* Record the FDE associated with this function. */
4080 current_funcdef_fde = fde_table_in_use;
4082 /* Add the new FDE at the end of the fde_table. */
4083 fde = &fde_table[fde_table_in_use++];
4084 fde->decl = current_function_decl;
4085 fde->dw_fde_begin = dup_label;
4086 fde->dw_fde_end = NULL;
4087 fde->dw_fde_current_label = dup_label;
4088 fde->dw_fde_second_begin = NULL;
4089 fde->dw_fde_second_end = NULL;
4090 fde->dw_fde_vms_end_prologue = NULL;
4091 fde->dw_fde_vms_begin_epilogue = NULL;
4092 fde->dw_fde_cfi = NULL;
4093 fde->dw_fde_switch_cfi = NULL;
4094 fde->funcdef_number = current_function_funcdef_no;
4095 fde->all_throwers_are_sibcalls = crtl->all_throwers_are_sibcalls;
4096 fde->uses_eh_lsda = crtl->uses_eh_lsda;
4097 fde->nothrow = crtl->nothrow;
4098 fde->drap_reg = INVALID_REGNUM;
4099 fde->vdrap_reg = INVALID_REGNUM;
4100 fde->in_std_section = (fnsec == text_section
4101 || (cold_text_section && fnsec == cold_text_section));
4102 fde->second_in_std_section = 0;
4104 args_size = old_args_size = 0;
4106 /* We only want to output line number information for the genuine dwarf2
4107 prologue case, not the eh frame case. */
4108 #ifdef DWARF2_DEBUGGING_INFO
4109 if (file)
4110 dwarf2out_source_line (line, file, 0, true);
4111 #endif
4113 if (dwarf2out_do_cfi_asm ())
4114 dwarf2out_do_cfi_startproc (false);
4115 else
4117 rtx personality = get_personality_function (current_function_decl);
4118 if (!current_unit_personality)
4119 current_unit_personality = personality;
4121 /* We cannot keep a current personality per function as without CFI
4122 asm, at the point where we emit the CFI data, there is no current
4123 function anymore. */
4124 if (personality && current_unit_personality != personality)
4125 sorry ("multiple EH personalities are supported only with assemblers "
4126 "supporting .cfi_personality directive");
4130 /* Output a marker (i.e. a label) for the end of the generated code
4131 for a function prologue. This gets called *after* the prologue code has
4132 been generated. */
4134 void
4135 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED,
4136 const char *file ATTRIBUTE_UNUSED)
4138 dw_fde_ref fde;
4139 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4141 /* Output a label to mark the endpoint of the code generated for this
4142 function. */
4143 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
4144 current_function_funcdef_no);
4145 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, PROLOGUE_END_LABEL,
4146 current_function_funcdef_no);
4147 fde = &fde_table[fde_table_in_use - 1];
4148 fde->dw_fde_vms_end_prologue = xstrdup (label);
4151 /* Output a marker (i.e. a label) for the beginning of the generated code
4152 for a function epilogue. This gets called *before* the prologue code has
4153 been generated. */
4155 void
4156 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4157 const char *file ATTRIBUTE_UNUSED)
4159 dw_fde_ref fde;
4160 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4162 fde = &fde_table[fde_table_in_use - 1];
4163 if (fde->dw_fde_vms_begin_epilogue)
4164 return;
4166 /* Output a label to mark the endpoint of the code generated for this
4167 function. */
4168 ASM_GENERATE_INTERNAL_LABEL (label, EPILOGUE_BEGIN_LABEL,
4169 current_function_funcdef_no);
4170 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, EPILOGUE_BEGIN_LABEL,
4171 current_function_funcdef_no);
4172 fde->dw_fde_vms_begin_epilogue = xstrdup (label);
4175 /* Output a marker (i.e. a label) for the absolute end of the generated code
4176 for a function definition. This gets called *after* the epilogue code has
4177 been generated. */
4179 void
4180 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
4181 const char *file ATTRIBUTE_UNUSED)
4183 dw_fde_ref fde;
4184 char label[MAX_ARTIFICIAL_LABEL_BYTES];
4186 last_var_location_insn = NULL_RTX;
4188 if (dwarf2out_do_cfi_asm ())
4189 fprintf (asm_out_file, "\t.cfi_endproc\n");
4191 /* Output a label to mark the endpoint of the code generated for this
4192 function. */
4193 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
4194 current_function_funcdef_no);
4195 ASM_OUTPUT_LABEL (asm_out_file, label);
4196 fde = current_fde ();
4197 gcc_assert (fde != NULL);
4198 if (fde->dw_fde_second_begin == NULL)
4199 fde->dw_fde_end = xstrdup (label);
4202 void
4203 dwarf2out_frame_init (void)
4205 /* Allocate the initial hunk of the fde_table. */
4206 fde_table = ggc_alloc_cleared_vec_dw_fde_node (FDE_TABLE_INCREMENT);
4207 fde_table_allocated = FDE_TABLE_INCREMENT;
4208 fde_table_in_use = 0;
4210 /* Generate the CFA instructions common to all FDE's. Do it now for the
4211 sake of lookup_cfa. */
4213 /* On entry, the Canonical Frame Address is at SP. */
4214 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
4216 if (targetm.debug_unwind_info () == UI_DWARF2
4217 || targetm.except_unwind_info (&global_options) == UI_DWARF2)
4218 initial_return_save (INCOMING_RETURN_ADDR_RTX);
4221 void
4222 dwarf2out_frame_finish (void)
4224 /* Output call frame information. */
4225 if (targetm.debug_unwind_info () == UI_DWARF2)
4226 output_call_frame_info (0);
4228 /* Output another copy for the unwinder. */
4229 if ((flag_unwind_tables || flag_exceptions)
4230 && targetm.except_unwind_info (&global_options) == UI_DWARF2)
4231 output_call_frame_info (1);
4234 /* Note that the current function section is being used for code. */
4236 static void
4237 dwarf2out_note_section_used (void)
4239 section *sec = current_function_section ();
4240 if (sec == text_section)
4241 text_section_used = true;
4242 else if (sec == cold_text_section)
4243 cold_text_section_used = true;
4246 static void var_location_switch_text_section (void);
4247 static void set_cur_line_info_table (section *);
4249 void
4250 dwarf2out_switch_text_section (void)
4252 section *sect;
4253 dw_fde_ref fde = current_fde ();
4254 dw_cfi_ref cfi;
4256 gcc_assert (cfun && fde && fde->dw_fde_second_begin == NULL);
4258 if (!in_cold_section_p)
4260 fde->dw_fde_end = crtl->subsections.cold_section_end_label;
4261 fde->dw_fde_second_begin = crtl->subsections.hot_section_label;
4262 fde->dw_fde_second_end = crtl->subsections.hot_section_end_label;
4264 else
4266 fde->dw_fde_end = crtl->subsections.hot_section_end_label;
4267 fde->dw_fde_second_begin = crtl->subsections.cold_section_label;
4268 fde->dw_fde_second_end = crtl->subsections.cold_section_end_label;
4270 have_multiple_function_sections = true;
4272 /* Reset the current label on switching text sections, so that we
4273 don't attempt to advance_loc4 between labels in different sections. */
4274 fde->dw_fde_current_label = NULL;
4276 /* There is no need to mark used sections when not debugging. */
4277 if (cold_text_section != NULL)
4278 dwarf2out_note_section_used ();
4280 if (dwarf2out_do_cfi_asm ())
4281 fprintf (asm_out_file, "\t.cfi_endproc\n");
4283 /* Now do the real section switch. */
4284 sect = current_function_section ();
4285 switch_to_section (sect);
4287 fde->second_in_std_section
4288 = (sect == text_section
4289 || (cold_text_section && sect == cold_text_section));
4291 if (dwarf2out_do_cfi_asm ())
4293 dwarf2out_do_cfi_startproc (true);
4294 /* As this is a different FDE, insert all current CFI instructions
4295 again. */
4296 output_cfis (fde->dw_fde_cfi, true, fde, true);
4298 cfi = fde->dw_fde_cfi;
4299 if (cfi)
4300 while (cfi->dw_cfi_next != NULL)
4301 cfi = cfi->dw_cfi_next;
4302 fde->dw_fde_switch_cfi = cfi;
4303 var_location_switch_text_section ();
4305 set_cur_line_info_table (sect);
4308 /* And now, the subset of the debugging information support code necessary
4309 for emitting location expressions. */
4311 /* Data about a single source file. */
4312 struct GTY(()) dwarf_file_data {
4313 const char * filename;
4314 int emitted_number;
4317 typedef struct dw_val_struct *dw_val_ref;
4318 typedef struct die_struct *dw_die_ref;
4319 typedef const struct die_struct *const_dw_die_ref;
4320 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
4321 typedef struct dw_loc_list_struct *dw_loc_list_ref;
4323 typedef struct GTY(()) deferred_locations_struct
4325 tree variable;
4326 dw_die_ref die;
4327 } deferred_locations;
4329 DEF_VEC_O(deferred_locations);
4330 DEF_VEC_ALLOC_O(deferred_locations,gc);
4332 static GTY(()) VEC(deferred_locations, gc) *deferred_locations_list;
4334 DEF_VEC_P(dw_die_ref);
4335 DEF_VEC_ALLOC_P(dw_die_ref,heap);
4337 /* Each DIE may have a series of attribute/value pairs. Values
4338 can take on several forms. The forms that are used in this
4339 implementation are listed below. */
4341 enum dw_val_class
4343 dw_val_class_addr,
4344 dw_val_class_offset,
4345 dw_val_class_loc,
4346 dw_val_class_loc_list,
4347 dw_val_class_range_list,
4348 dw_val_class_const,
4349 dw_val_class_unsigned_const,
4350 dw_val_class_const_double,
4351 dw_val_class_vec,
4352 dw_val_class_flag,
4353 dw_val_class_die_ref,
4354 dw_val_class_fde_ref,
4355 dw_val_class_lbl_id,
4356 dw_val_class_lineptr,
4357 dw_val_class_str,
4358 dw_val_class_macptr,
4359 dw_val_class_file,
4360 dw_val_class_data8,
4361 dw_val_class_decl_ref,
4362 dw_val_class_vms_delta
4365 /* Describe a floating point constant value, or a vector constant value. */
4367 typedef struct GTY(()) dw_vec_struct {
4368 unsigned char * GTY((length ("%h.length"))) array;
4369 unsigned length;
4370 unsigned elt_size;
4372 dw_vec_const;
4374 /* The dw_val_node describes an attribute's value, as it is
4375 represented internally. */
4377 typedef struct GTY(()) dw_val_struct {
4378 enum dw_val_class val_class;
4379 union dw_val_struct_union
4381 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
4382 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
4383 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
4384 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
4385 HOST_WIDE_INT GTY ((default)) val_int;
4386 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
4387 double_int GTY ((tag ("dw_val_class_const_double"))) val_double;
4388 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
4389 struct dw_val_die_union
4391 dw_die_ref die;
4392 int external;
4393 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
4394 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
4395 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
4396 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
4397 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
4398 struct dwarf_file_data * GTY ((tag ("dw_val_class_file"))) val_file;
4399 unsigned char GTY ((tag ("dw_val_class_data8"))) val_data8[8];
4400 tree GTY ((tag ("dw_val_class_decl_ref"))) val_decl_ref;
4401 struct dw_val_vms_delta_union
4403 char * lbl1;
4404 char * lbl2;
4405 } GTY ((tag ("dw_val_class_vms_delta"))) val_vms_delta;
4407 GTY ((desc ("%1.val_class"))) v;
4409 dw_val_node;
4411 /* Locations in memory are described using a sequence of stack machine
4412 operations. */
4414 typedef struct GTY(()) dw_loc_descr_struct {
4415 dw_loc_descr_ref dw_loc_next;
4416 ENUM_BITFIELD (dwarf_location_atom) dw_loc_opc : 8;
4417 /* Used to distinguish DW_OP_addr with a direct symbol relocation
4418 from DW_OP_addr with a dtp-relative symbol relocation. */
4419 unsigned int dtprel : 1;
4420 int dw_loc_addr;
4421 dw_val_node dw_loc_oprnd1;
4422 dw_val_node dw_loc_oprnd2;
4424 dw_loc_descr_node;
4426 /* Location lists are ranges + location descriptions for that range,
4427 so you can track variables that are in different places over
4428 their entire life. */
4429 typedef struct GTY(()) dw_loc_list_struct {
4430 dw_loc_list_ref dw_loc_next;
4431 const char *begin; /* Label for begin address of range */
4432 const char *end; /* Label for end address of range */
4433 char *ll_symbol; /* Label for beginning of location list.
4434 Only on head of list */
4435 const char *section; /* Section this loclist is relative to */
4436 dw_loc_descr_ref expr;
4437 hashval_t hash;
4438 /* True if all addresses in this and subsequent lists are known to be
4439 resolved. */
4440 bool resolved_addr;
4441 /* True if this list has been replaced by dw_loc_next. */
4442 bool replaced;
4443 bool emitted;
4444 } dw_loc_list_node;
4446 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
4448 /* Convert a DWARF stack opcode into its string name. */
4450 static const char *
4451 dwarf_stack_op_name (unsigned int op)
4453 switch (op)
4455 case DW_OP_addr:
4456 return "DW_OP_addr";
4457 case DW_OP_deref:
4458 return "DW_OP_deref";
4459 case DW_OP_const1u:
4460 return "DW_OP_const1u";
4461 case DW_OP_const1s:
4462 return "DW_OP_const1s";
4463 case DW_OP_const2u:
4464 return "DW_OP_const2u";
4465 case DW_OP_const2s:
4466 return "DW_OP_const2s";
4467 case DW_OP_const4u:
4468 return "DW_OP_const4u";
4469 case DW_OP_const4s:
4470 return "DW_OP_const4s";
4471 case DW_OP_const8u:
4472 return "DW_OP_const8u";
4473 case DW_OP_const8s:
4474 return "DW_OP_const8s";
4475 case DW_OP_constu:
4476 return "DW_OP_constu";
4477 case DW_OP_consts:
4478 return "DW_OP_consts";
4479 case DW_OP_dup:
4480 return "DW_OP_dup";
4481 case DW_OP_drop:
4482 return "DW_OP_drop";
4483 case DW_OP_over:
4484 return "DW_OP_over";
4485 case DW_OP_pick:
4486 return "DW_OP_pick";
4487 case DW_OP_swap:
4488 return "DW_OP_swap";
4489 case DW_OP_rot:
4490 return "DW_OP_rot";
4491 case DW_OP_xderef:
4492 return "DW_OP_xderef";
4493 case DW_OP_abs:
4494 return "DW_OP_abs";
4495 case DW_OP_and:
4496 return "DW_OP_and";
4497 case DW_OP_div:
4498 return "DW_OP_div";
4499 case DW_OP_minus:
4500 return "DW_OP_minus";
4501 case DW_OP_mod:
4502 return "DW_OP_mod";
4503 case DW_OP_mul:
4504 return "DW_OP_mul";
4505 case DW_OP_neg:
4506 return "DW_OP_neg";
4507 case DW_OP_not:
4508 return "DW_OP_not";
4509 case DW_OP_or:
4510 return "DW_OP_or";
4511 case DW_OP_plus:
4512 return "DW_OP_plus";
4513 case DW_OP_plus_uconst:
4514 return "DW_OP_plus_uconst";
4515 case DW_OP_shl:
4516 return "DW_OP_shl";
4517 case DW_OP_shr:
4518 return "DW_OP_shr";
4519 case DW_OP_shra:
4520 return "DW_OP_shra";
4521 case DW_OP_xor:
4522 return "DW_OP_xor";
4523 case DW_OP_bra:
4524 return "DW_OP_bra";
4525 case DW_OP_eq:
4526 return "DW_OP_eq";
4527 case DW_OP_ge:
4528 return "DW_OP_ge";
4529 case DW_OP_gt:
4530 return "DW_OP_gt";
4531 case DW_OP_le:
4532 return "DW_OP_le";
4533 case DW_OP_lt:
4534 return "DW_OP_lt";
4535 case DW_OP_ne:
4536 return "DW_OP_ne";
4537 case DW_OP_skip:
4538 return "DW_OP_skip";
4539 case DW_OP_lit0:
4540 return "DW_OP_lit0";
4541 case DW_OP_lit1:
4542 return "DW_OP_lit1";
4543 case DW_OP_lit2:
4544 return "DW_OP_lit2";
4545 case DW_OP_lit3:
4546 return "DW_OP_lit3";
4547 case DW_OP_lit4:
4548 return "DW_OP_lit4";
4549 case DW_OP_lit5:
4550 return "DW_OP_lit5";
4551 case DW_OP_lit6:
4552 return "DW_OP_lit6";
4553 case DW_OP_lit7:
4554 return "DW_OP_lit7";
4555 case DW_OP_lit8:
4556 return "DW_OP_lit8";
4557 case DW_OP_lit9:
4558 return "DW_OP_lit9";
4559 case DW_OP_lit10:
4560 return "DW_OP_lit10";
4561 case DW_OP_lit11:
4562 return "DW_OP_lit11";
4563 case DW_OP_lit12:
4564 return "DW_OP_lit12";
4565 case DW_OP_lit13:
4566 return "DW_OP_lit13";
4567 case DW_OP_lit14:
4568 return "DW_OP_lit14";
4569 case DW_OP_lit15:
4570 return "DW_OP_lit15";
4571 case DW_OP_lit16:
4572 return "DW_OP_lit16";
4573 case DW_OP_lit17:
4574 return "DW_OP_lit17";
4575 case DW_OP_lit18:
4576 return "DW_OP_lit18";
4577 case DW_OP_lit19:
4578 return "DW_OP_lit19";
4579 case DW_OP_lit20:
4580 return "DW_OP_lit20";
4581 case DW_OP_lit21:
4582 return "DW_OP_lit21";
4583 case DW_OP_lit22:
4584 return "DW_OP_lit22";
4585 case DW_OP_lit23:
4586 return "DW_OP_lit23";
4587 case DW_OP_lit24:
4588 return "DW_OP_lit24";
4589 case DW_OP_lit25:
4590 return "DW_OP_lit25";
4591 case DW_OP_lit26:
4592 return "DW_OP_lit26";
4593 case DW_OP_lit27:
4594 return "DW_OP_lit27";
4595 case DW_OP_lit28:
4596 return "DW_OP_lit28";
4597 case DW_OP_lit29:
4598 return "DW_OP_lit29";
4599 case DW_OP_lit30:
4600 return "DW_OP_lit30";
4601 case DW_OP_lit31:
4602 return "DW_OP_lit31";
4603 case DW_OP_reg0:
4604 return "DW_OP_reg0";
4605 case DW_OP_reg1:
4606 return "DW_OP_reg1";
4607 case DW_OP_reg2:
4608 return "DW_OP_reg2";
4609 case DW_OP_reg3:
4610 return "DW_OP_reg3";
4611 case DW_OP_reg4:
4612 return "DW_OP_reg4";
4613 case DW_OP_reg5:
4614 return "DW_OP_reg5";
4615 case DW_OP_reg6:
4616 return "DW_OP_reg6";
4617 case DW_OP_reg7:
4618 return "DW_OP_reg7";
4619 case DW_OP_reg8:
4620 return "DW_OP_reg8";
4621 case DW_OP_reg9:
4622 return "DW_OP_reg9";
4623 case DW_OP_reg10:
4624 return "DW_OP_reg10";
4625 case DW_OP_reg11:
4626 return "DW_OP_reg11";
4627 case DW_OP_reg12:
4628 return "DW_OP_reg12";
4629 case DW_OP_reg13:
4630 return "DW_OP_reg13";
4631 case DW_OP_reg14:
4632 return "DW_OP_reg14";
4633 case DW_OP_reg15:
4634 return "DW_OP_reg15";
4635 case DW_OP_reg16:
4636 return "DW_OP_reg16";
4637 case DW_OP_reg17:
4638 return "DW_OP_reg17";
4639 case DW_OP_reg18:
4640 return "DW_OP_reg18";
4641 case DW_OP_reg19:
4642 return "DW_OP_reg19";
4643 case DW_OP_reg20:
4644 return "DW_OP_reg20";
4645 case DW_OP_reg21:
4646 return "DW_OP_reg21";
4647 case DW_OP_reg22:
4648 return "DW_OP_reg22";
4649 case DW_OP_reg23:
4650 return "DW_OP_reg23";
4651 case DW_OP_reg24:
4652 return "DW_OP_reg24";
4653 case DW_OP_reg25:
4654 return "DW_OP_reg25";
4655 case DW_OP_reg26:
4656 return "DW_OP_reg26";
4657 case DW_OP_reg27:
4658 return "DW_OP_reg27";
4659 case DW_OP_reg28:
4660 return "DW_OP_reg28";
4661 case DW_OP_reg29:
4662 return "DW_OP_reg29";
4663 case DW_OP_reg30:
4664 return "DW_OP_reg30";
4665 case DW_OP_reg31:
4666 return "DW_OP_reg31";
4667 case DW_OP_breg0:
4668 return "DW_OP_breg0";
4669 case DW_OP_breg1:
4670 return "DW_OP_breg1";
4671 case DW_OP_breg2:
4672 return "DW_OP_breg2";
4673 case DW_OP_breg3:
4674 return "DW_OP_breg3";
4675 case DW_OP_breg4:
4676 return "DW_OP_breg4";
4677 case DW_OP_breg5:
4678 return "DW_OP_breg5";
4679 case DW_OP_breg6:
4680 return "DW_OP_breg6";
4681 case DW_OP_breg7:
4682 return "DW_OP_breg7";
4683 case DW_OP_breg8:
4684 return "DW_OP_breg8";
4685 case DW_OP_breg9:
4686 return "DW_OP_breg9";
4687 case DW_OP_breg10:
4688 return "DW_OP_breg10";
4689 case DW_OP_breg11:
4690 return "DW_OP_breg11";
4691 case DW_OP_breg12:
4692 return "DW_OP_breg12";
4693 case DW_OP_breg13:
4694 return "DW_OP_breg13";
4695 case DW_OP_breg14:
4696 return "DW_OP_breg14";
4697 case DW_OP_breg15:
4698 return "DW_OP_breg15";
4699 case DW_OP_breg16:
4700 return "DW_OP_breg16";
4701 case DW_OP_breg17:
4702 return "DW_OP_breg17";
4703 case DW_OP_breg18:
4704 return "DW_OP_breg18";
4705 case DW_OP_breg19:
4706 return "DW_OP_breg19";
4707 case DW_OP_breg20:
4708 return "DW_OP_breg20";
4709 case DW_OP_breg21:
4710 return "DW_OP_breg21";
4711 case DW_OP_breg22:
4712 return "DW_OP_breg22";
4713 case DW_OP_breg23:
4714 return "DW_OP_breg23";
4715 case DW_OP_breg24:
4716 return "DW_OP_breg24";
4717 case DW_OP_breg25:
4718 return "DW_OP_breg25";
4719 case DW_OP_breg26:
4720 return "DW_OP_breg26";
4721 case DW_OP_breg27:
4722 return "DW_OP_breg27";
4723 case DW_OP_breg28:
4724 return "DW_OP_breg28";
4725 case DW_OP_breg29:
4726 return "DW_OP_breg29";
4727 case DW_OP_breg30:
4728 return "DW_OP_breg30";
4729 case DW_OP_breg31:
4730 return "DW_OP_breg31";
4731 case DW_OP_regx:
4732 return "DW_OP_regx";
4733 case DW_OP_fbreg:
4734 return "DW_OP_fbreg";
4735 case DW_OP_bregx:
4736 return "DW_OP_bregx";
4737 case DW_OP_piece:
4738 return "DW_OP_piece";
4739 case DW_OP_deref_size:
4740 return "DW_OP_deref_size";
4741 case DW_OP_xderef_size:
4742 return "DW_OP_xderef_size";
4743 case DW_OP_nop:
4744 return "DW_OP_nop";
4746 case DW_OP_push_object_address:
4747 return "DW_OP_push_object_address";
4748 case DW_OP_call2:
4749 return "DW_OP_call2";
4750 case DW_OP_call4:
4751 return "DW_OP_call4";
4752 case DW_OP_call_ref:
4753 return "DW_OP_call_ref";
4754 case DW_OP_implicit_value:
4755 return "DW_OP_implicit_value";
4756 case DW_OP_stack_value:
4757 return "DW_OP_stack_value";
4758 case DW_OP_form_tls_address:
4759 return "DW_OP_form_tls_address";
4760 case DW_OP_call_frame_cfa:
4761 return "DW_OP_call_frame_cfa";
4762 case DW_OP_bit_piece:
4763 return "DW_OP_bit_piece";
4765 case DW_OP_GNU_push_tls_address:
4766 return "DW_OP_GNU_push_tls_address";
4767 case DW_OP_GNU_uninit:
4768 return "DW_OP_GNU_uninit";
4769 case DW_OP_GNU_encoded_addr:
4770 return "DW_OP_GNU_encoded_addr";
4771 case DW_OP_GNU_implicit_pointer:
4772 return "DW_OP_GNU_implicit_pointer";
4773 case DW_OP_GNU_entry_value:
4774 return "DW_OP_GNU_entry_value";
4776 default:
4777 return "OP_<unknown>";
4781 /* Return a pointer to a newly allocated location description. Location
4782 descriptions are simple expression terms that can be strung
4783 together to form more complicated location (address) descriptions. */
4785 static inline dw_loc_descr_ref
4786 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
4787 unsigned HOST_WIDE_INT oprnd2)
4789 dw_loc_descr_ref descr = ggc_alloc_cleared_dw_loc_descr_node ();
4791 descr->dw_loc_opc = op;
4792 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4793 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4794 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4795 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4797 return descr;
4800 /* Return a pointer to a newly allocated location description for
4801 REG and OFFSET. */
4803 static inline dw_loc_descr_ref
4804 new_reg_loc_descr (unsigned int reg, unsigned HOST_WIDE_INT offset)
4806 if (reg <= 31)
4807 return new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + reg),
4808 offset, 0);
4809 else
4810 return new_loc_descr (DW_OP_bregx, reg, offset);
4813 /* Add a location description term to a location description expression. */
4815 static inline void
4816 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
4818 dw_loc_descr_ref *d;
4820 /* Find the end of the chain. */
4821 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4824 *d = descr;
4827 /* Add a constant OFFSET to a location expression. */
4829 static void
4830 loc_descr_plus_const (dw_loc_descr_ref *list_head, HOST_WIDE_INT offset)
4832 dw_loc_descr_ref loc;
4833 HOST_WIDE_INT *p;
4835 gcc_assert (*list_head != NULL);
4837 if (!offset)
4838 return;
4840 /* Find the end of the chain. */
4841 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
4844 p = NULL;
4845 if (loc->dw_loc_opc == DW_OP_fbreg
4846 || (loc->dw_loc_opc >= DW_OP_breg0 && loc->dw_loc_opc <= DW_OP_breg31))
4847 p = &loc->dw_loc_oprnd1.v.val_int;
4848 else if (loc->dw_loc_opc == DW_OP_bregx)
4849 p = &loc->dw_loc_oprnd2.v.val_int;
4851 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
4852 offset. Don't optimize if an signed integer overflow would happen. */
4853 if (p != NULL
4854 && ((offset > 0 && *p <= INTTYPE_MAXIMUM (HOST_WIDE_INT) - offset)
4855 || (offset < 0 && *p >= INTTYPE_MINIMUM (HOST_WIDE_INT) - offset)))
4856 *p += offset;
4858 else if (offset > 0)
4859 loc->dw_loc_next = new_loc_descr (DW_OP_plus_uconst, offset, 0);
4861 else
4863 loc->dw_loc_next = int_loc_descriptor (-offset);
4864 add_loc_descr (&loc->dw_loc_next, new_loc_descr (DW_OP_minus, 0, 0));
4868 /* Add a constant OFFSET to a location list. */
4870 static void
4871 loc_list_plus_const (dw_loc_list_ref list_head, HOST_WIDE_INT offset)
4873 dw_loc_list_ref d;
4874 for (d = list_head; d != NULL; d = d->dw_loc_next)
4875 loc_descr_plus_const (&d->expr, offset);
4878 #define DWARF_REF_SIZE \
4879 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
4881 static unsigned long size_of_locs (dw_loc_descr_ref);
4883 /* Return the size of a location descriptor. */
4885 static unsigned long
4886 size_of_loc_descr (dw_loc_descr_ref loc)
4888 unsigned long size = 1;
4890 switch (loc->dw_loc_opc)
4892 case DW_OP_addr:
4893 size += DWARF2_ADDR_SIZE;
4894 break;
4895 case DW_OP_const1u:
4896 case DW_OP_const1s:
4897 size += 1;
4898 break;
4899 case DW_OP_const2u:
4900 case DW_OP_const2s:
4901 size += 2;
4902 break;
4903 case DW_OP_const4u:
4904 case DW_OP_const4s:
4905 size += 4;
4906 break;
4907 case DW_OP_const8u:
4908 case DW_OP_const8s:
4909 size += 8;
4910 break;
4911 case DW_OP_constu:
4912 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4913 break;
4914 case DW_OP_consts:
4915 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4916 break;
4917 case DW_OP_pick:
4918 size += 1;
4919 break;
4920 case DW_OP_plus_uconst:
4921 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4922 break;
4923 case DW_OP_skip:
4924 case DW_OP_bra:
4925 size += 2;
4926 break;
4927 case DW_OP_breg0:
4928 case DW_OP_breg1:
4929 case DW_OP_breg2:
4930 case DW_OP_breg3:
4931 case DW_OP_breg4:
4932 case DW_OP_breg5:
4933 case DW_OP_breg6:
4934 case DW_OP_breg7:
4935 case DW_OP_breg8:
4936 case DW_OP_breg9:
4937 case DW_OP_breg10:
4938 case DW_OP_breg11:
4939 case DW_OP_breg12:
4940 case DW_OP_breg13:
4941 case DW_OP_breg14:
4942 case DW_OP_breg15:
4943 case DW_OP_breg16:
4944 case DW_OP_breg17:
4945 case DW_OP_breg18:
4946 case DW_OP_breg19:
4947 case DW_OP_breg20:
4948 case DW_OP_breg21:
4949 case DW_OP_breg22:
4950 case DW_OP_breg23:
4951 case DW_OP_breg24:
4952 case DW_OP_breg25:
4953 case DW_OP_breg26:
4954 case DW_OP_breg27:
4955 case DW_OP_breg28:
4956 case DW_OP_breg29:
4957 case DW_OP_breg30:
4958 case DW_OP_breg31:
4959 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4960 break;
4961 case DW_OP_regx:
4962 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4963 break;
4964 case DW_OP_fbreg:
4965 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4966 break;
4967 case DW_OP_bregx:
4968 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4969 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4970 break;
4971 case DW_OP_piece:
4972 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4973 break;
4974 case DW_OP_bit_piece:
4975 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4976 size += size_of_uleb128 (loc->dw_loc_oprnd2.v.val_unsigned);
4977 break;
4978 case DW_OP_deref_size:
4979 case DW_OP_xderef_size:
4980 size += 1;
4981 break;
4982 case DW_OP_call2:
4983 size += 2;
4984 break;
4985 case DW_OP_call4:
4986 size += 4;
4987 break;
4988 case DW_OP_call_ref:
4989 size += DWARF_REF_SIZE;
4990 break;
4991 case DW_OP_implicit_value:
4992 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned)
4993 + loc->dw_loc_oprnd1.v.val_unsigned;
4994 break;
4995 case DW_OP_GNU_implicit_pointer:
4996 size += DWARF_REF_SIZE + size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4997 break;
4998 case DW_OP_GNU_entry_value:
5000 unsigned long op_size = size_of_locs (loc->dw_loc_oprnd1.v.val_loc);
5001 size += size_of_uleb128 (op_size) + op_size;
5002 break;
5004 default:
5005 break;
5008 return size;
5011 /* Return the size of a series of location descriptors. */
5013 static unsigned long
5014 size_of_locs (dw_loc_descr_ref loc)
5016 dw_loc_descr_ref l;
5017 unsigned long size;
5019 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
5020 field, to avoid writing to a PCH file. */
5021 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5023 if (l->dw_loc_opc == DW_OP_skip || l->dw_loc_opc == DW_OP_bra)
5024 break;
5025 size += size_of_loc_descr (l);
5027 if (! l)
5028 return size;
5030 for (size = 0, l = loc; l != NULL; l = l->dw_loc_next)
5032 l->dw_loc_addr = size;
5033 size += size_of_loc_descr (l);
5036 return size;
5039 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
5040 static void get_ref_die_offset_label (char *, dw_die_ref);
5041 static void output_loc_sequence (dw_loc_descr_ref, int);
5043 /* Output location description stack opcode's operands (if any).
5044 The for_eh_or_skip parameter controls whether register numbers are
5045 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5046 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5047 info). This should be suppressed for the cases that have not been converted
5048 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5050 static void
5051 output_loc_operands (dw_loc_descr_ref loc, int for_eh_or_skip)
5053 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5054 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5056 switch (loc->dw_loc_opc)
5058 #ifdef DWARF2_DEBUGGING_INFO
5059 case DW_OP_const2u:
5060 case DW_OP_const2s:
5061 dw2_asm_output_data (2, val1->v.val_int, NULL);
5062 break;
5063 case DW_OP_const4u:
5064 if (loc->dtprel)
5066 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5067 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 4,
5068 val1->v.val_addr);
5069 fputc ('\n', asm_out_file);
5070 break;
5072 /* FALLTHRU */
5073 case DW_OP_const4s:
5074 dw2_asm_output_data (4, val1->v.val_int, NULL);
5075 break;
5076 case DW_OP_const8u:
5077 if (loc->dtprel)
5079 gcc_assert (targetm.asm_out.output_dwarf_dtprel);
5080 targetm.asm_out.output_dwarf_dtprel (asm_out_file, 8,
5081 val1->v.val_addr);
5082 fputc ('\n', asm_out_file);
5083 break;
5085 /* FALLTHRU */
5086 case DW_OP_const8s:
5087 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5088 dw2_asm_output_data (8, val1->v.val_int, NULL);
5089 break;
5090 case DW_OP_skip:
5091 case DW_OP_bra:
5093 int offset;
5095 gcc_assert (val1->val_class == dw_val_class_loc);
5096 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5098 dw2_asm_output_data (2, offset, NULL);
5100 break;
5101 case DW_OP_implicit_value:
5102 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5103 switch (val2->val_class)
5105 case dw_val_class_const:
5106 dw2_asm_output_data (val1->v.val_unsigned, val2->v.val_int, NULL);
5107 break;
5108 case dw_val_class_vec:
5110 unsigned int elt_size = val2->v.val_vec.elt_size;
5111 unsigned int len = val2->v.val_vec.length;
5112 unsigned int i;
5113 unsigned char *p;
5115 if (elt_size > sizeof (HOST_WIDE_INT))
5117 elt_size /= 2;
5118 len *= 2;
5120 for (i = 0, p = val2->v.val_vec.array;
5121 i < len;
5122 i++, p += elt_size)
5123 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
5124 "fp or vector constant word %u", i);
5126 break;
5127 case dw_val_class_const_double:
5129 unsigned HOST_WIDE_INT first, second;
5131 if (WORDS_BIG_ENDIAN)
5133 first = val2->v.val_double.high;
5134 second = val2->v.val_double.low;
5136 else
5138 first = val2->v.val_double.low;
5139 second = val2->v.val_double.high;
5141 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5142 first, NULL);
5143 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
5144 second, NULL);
5146 break;
5147 case dw_val_class_addr:
5148 gcc_assert (val1->v.val_unsigned == DWARF2_ADDR_SIZE);
5149 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val2->v.val_addr, NULL);
5150 break;
5151 default:
5152 gcc_unreachable ();
5154 break;
5155 #else
5156 case DW_OP_const2u:
5157 case DW_OP_const2s:
5158 case DW_OP_const4u:
5159 case DW_OP_const4s:
5160 case DW_OP_const8u:
5161 case DW_OP_const8s:
5162 case DW_OP_skip:
5163 case DW_OP_bra:
5164 case DW_OP_implicit_value:
5165 /* We currently don't make any attempt to make sure these are
5166 aligned properly like we do for the main unwind info, so
5167 don't support emitting things larger than a byte if we're
5168 only doing unwinding. */
5169 gcc_unreachable ();
5170 #endif
5171 case DW_OP_const1u:
5172 case DW_OP_const1s:
5173 dw2_asm_output_data (1, val1->v.val_int, NULL);
5174 break;
5175 case DW_OP_constu:
5176 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5177 break;
5178 case DW_OP_consts:
5179 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5180 break;
5181 case DW_OP_pick:
5182 dw2_asm_output_data (1, val1->v.val_int, NULL);
5183 break;
5184 case DW_OP_plus_uconst:
5185 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5186 break;
5187 case DW_OP_breg0:
5188 case DW_OP_breg1:
5189 case DW_OP_breg2:
5190 case DW_OP_breg3:
5191 case DW_OP_breg4:
5192 case DW_OP_breg5:
5193 case DW_OP_breg6:
5194 case DW_OP_breg7:
5195 case DW_OP_breg8:
5196 case DW_OP_breg9:
5197 case DW_OP_breg10:
5198 case DW_OP_breg11:
5199 case DW_OP_breg12:
5200 case DW_OP_breg13:
5201 case DW_OP_breg14:
5202 case DW_OP_breg15:
5203 case DW_OP_breg16:
5204 case DW_OP_breg17:
5205 case DW_OP_breg18:
5206 case DW_OP_breg19:
5207 case DW_OP_breg20:
5208 case DW_OP_breg21:
5209 case DW_OP_breg22:
5210 case DW_OP_breg23:
5211 case DW_OP_breg24:
5212 case DW_OP_breg25:
5213 case DW_OP_breg26:
5214 case DW_OP_breg27:
5215 case DW_OP_breg28:
5216 case DW_OP_breg29:
5217 case DW_OP_breg30:
5218 case DW_OP_breg31:
5219 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5220 break;
5221 case DW_OP_regx:
5223 unsigned r = val1->v.val_unsigned;
5224 if (for_eh_or_skip >= 0)
5225 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5226 gcc_assert (size_of_uleb128 (r)
5227 == size_of_uleb128 (val1->v.val_unsigned));
5228 dw2_asm_output_data_uleb128 (r, NULL);
5230 break;
5231 case DW_OP_fbreg:
5232 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
5233 break;
5234 case DW_OP_bregx:
5236 unsigned r = val1->v.val_unsigned;
5237 if (for_eh_or_skip >= 0)
5238 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5239 gcc_assert (size_of_uleb128 (r)
5240 == size_of_uleb128 (val1->v.val_unsigned));
5241 dw2_asm_output_data_uleb128 (r, NULL);
5242 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5244 break;
5245 case DW_OP_piece:
5246 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5247 break;
5248 case DW_OP_bit_piece:
5249 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
5250 dw2_asm_output_data_uleb128 (val2->v.val_unsigned, NULL);
5251 break;
5252 case DW_OP_deref_size:
5253 case DW_OP_xderef_size:
5254 dw2_asm_output_data (1, val1->v.val_int, NULL);
5255 break;
5257 case DW_OP_addr:
5258 if (loc->dtprel)
5260 if (targetm.asm_out.output_dwarf_dtprel)
5262 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
5263 DWARF2_ADDR_SIZE,
5264 val1->v.val_addr);
5265 fputc ('\n', asm_out_file);
5267 else
5268 gcc_unreachable ();
5270 else
5272 #ifdef DWARF2_DEBUGGING_INFO
5273 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
5274 #else
5275 gcc_unreachable ();
5276 #endif
5278 break;
5280 case DW_OP_GNU_implicit_pointer:
5282 char label[MAX_ARTIFICIAL_LABEL_BYTES
5283 + HOST_BITS_PER_WIDE_INT / 2 + 2];
5284 gcc_assert (val1->val_class == dw_val_class_die_ref);
5285 get_ref_die_offset_label (label, val1->v.val_die_ref.die);
5286 dw2_asm_output_offset (DWARF_REF_SIZE, label, debug_info_section, NULL);
5287 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
5289 break;
5291 case DW_OP_GNU_entry_value:
5292 dw2_asm_output_data_uleb128 (size_of_locs (val1->v.val_loc), NULL);
5293 output_loc_sequence (val1->v.val_loc, for_eh_or_skip);
5294 break;
5296 default:
5297 /* Other codes have no operands. */
5298 break;
5302 /* Output a sequence of location operations.
5303 The for_eh_or_skip parameter controls whether register numbers are
5304 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
5305 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
5306 info). This should be suppressed for the cases that have not been converted
5307 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
5309 static void
5310 output_loc_sequence (dw_loc_descr_ref loc, int for_eh_or_skip)
5312 for (; loc != NULL; loc = loc->dw_loc_next)
5314 enum dwarf_location_atom opc = loc->dw_loc_opc;
5315 /* Output the opcode. */
5316 if (for_eh_or_skip >= 0
5317 && opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5319 unsigned r = (opc - DW_OP_breg0);
5320 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5321 gcc_assert (r <= 31);
5322 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5324 else if (for_eh_or_skip >= 0
5325 && opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5327 unsigned r = (opc - DW_OP_reg0);
5328 r = DWARF2_FRAME_REG_OUT (r, for_eh_or_skip);
5329 gcc_assert (r <= 31);
5330 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5333 dw2_asm_output_data (1, opc,
5334 "%s", dwarf_stack_op_name (opc));
5336 /* Output the operand(s) (if any). */
5337 output_loc_operands (loc, for_eh_or_skip);
5341 /* Output location description stack opcode's operands (if any).
5342 The output is single bytes on a line, suitable for .cfi_escape. */
5344 static void
5345 output_loc_operands_raw (dw_loc_descr_ref loc)
5347 dw_val_ref val1 = &loc->dw_loc_oprnd1;
5348 dw_val_ref val2 = &loc->dw_loc_oprnd2;
5350 switch (loc->dw_loc_opc)
5352 case DW_OP_addr:
5353 case DW_OP_implicit_value:
5354 /* We cannot output addresses in .cfi_escape, only bytes. */
5355 gcc_unreachable ();
5357 case DW_OP_const1u:
5358 case DW_OP_const1s:
5359 case DW_OP_pick:
5360 case DW_OP_deref_size:
5361 case DW_OP_xderef_size:
5362 fputc (',', asm_out_file);
5363 dw2_asm_output_data_raw (1, val1->v.val_int);
5364 break;
5366 case DW_OP_const2u:
5367 case DW_OP_const2s:
5368 fputc (',', asm_out_file);
5369 dw2_asm_output_data_raw (2, val1->v.val_int);
5370 break;
5372 case DW_OP_const4u:
5373 case DW_OP_const4s:
5374 fputc (',', asm_out_file);
5375 dw2_asm_output_data_raw (4, val1->v.val_int);
5376 break;
5378 case DW_OP_const8u:
5379 case DW_OP_const8s:
5380 gcc_assert (HOST_BITS_PER_WIDE_INT >= 64);
5381 fputc (',', asm_out_file);
5382 dw2_asm_output_data_raw (8, val1->v.val_int);
5383 break;
5385 case DW_OP_skip:
5386 case DW_OP_bra:
5388 int offset;
5390 gcc_assert (val1->val_class == dw_val_class_loc);
5391 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
5393 fputc (',', asm_out_file);
5394 dw2_asm_output_data_raw (2, offset);
5396 break;
5398 case DW_OP_regx:
5400 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5401 gcc_assert (size_of_uleb128 (r)
5402 == size_of_uleb128 (val1->v.val_unsigned));
5403 fputc (',', asm_out_file);
5404 dw2_asm_output_data_uleb128_raw (r);
5406 break;
5408 case DW_OP_constu:
5409 case DW_OP_plus_uconst:
5410 case DW_OP_piece:
5411 fputc (',', asm_out_file);
5412 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5413 break;
5415 case DW_OP_bit_piece:
5416 fputc (',', asm_out_file);
5417 dw2_asm_output_data_uleb128_raw (val1->v.val_unsigned);
5418 dw2_asm_output_data_uleb128_raw (val2->v.val_unsigned);
5419 break;
5421 case DW_OP_consts:
5422 case DW_OP_breg0:
5423 case DW_OP_breg1:
5424 case DW_OP_breg2:
5425 case DW_OP_breg3:
5426 case DW_OP_breg4:
5427 case DW_OP_breg5:
5428 case DW_OP_breg6:
5429 case DW_OP_breg7:
5430 case DW_OP_breg8:
5431 case DW_OP_breg9:
5432 case DW_OP_breg10:
5433 case DW_OP_breg11:
5434 case DW_OP_breg12:
5435 case DW_OP_breg13:
5436 case DW_OP_breg14:
5437 case DW_OP_breg15:
5438 case DW_OP_breg16:
5439 case DW_OP_breg17:
5440 case DW_OP_breg18:
5441 case DW_OP_breg19:
5442 case DW_OP_breg20:
5443 case DW_OP_breg21:
5444 case DW_OP_breg22:
5445 case DW_OP_breg23:
5446 case DW_OP_breg24:
5447 case DW_OP_breg25:
5448 case DW_OP_breg26:
5449 case DW_OP_breg27:
5450 case DW_OP_breg28:
5451 case DW_OP_breg29:
5452 case DW_OP_breg30:
5453 case DW_OP_breg31:
5454 case DW_OP_fbreg:
5455 fputc (',', asm_out_file);
5456 dw2_asm_output_data_sleb128_raw (val1->v.val_int);
5457 break;
5459 case DW_OP_bregx:
5461 unsigned r = DWARF2_FRAME_REG_OUT (val1->v.val_unsigned, 1);
5462 gcc_assert (size_of_uleb128 (r)
5463 == size_of_uleb128 (val1->v.val_unsigned));
5464 fputc (',', asm_out_file);
5465 dw2_asm_output_data_uleb128_raw (r);
5466 fputc (',', asm_out_file);
5467 dw2_asm_output_data_sleb128_raw (val2->v.val_int);
5469 break;
5471 case DW_OP_GNU_implicit_pointer:
5472 case DW_OP_GNU_entry_value:
5473 gcc_unreachable ();
5474 break;
5476 default:
5477 /* Other codes have no operands. */
5478 break;
5482 static void
5483 output_loc_sequence_raw (dw_loc_descr_ref loc)
5485 while (1)
5487 enum dwarf_location_atom opc = loc->dw_loc_opc;
5488 /* Output the opcode. */
5489 if (opc >= DW_OP_breg0 && opc <= DW_OP_breg31)
5491 unsigned r = (opc - DW_OP_breg0);
5492 r = DWARF2_FRAME_REG_OUT (r, 1);
5493 gcc_assert (r <= 31);
5494 opc = (enum dwarf_location_atom) (DW_OP_breg0 + r);
5496 else if (opc >= DW_OP_reg0 && opc <= DW_OP_reg31)
5498 unsigned r = (opc - DW_OP_reg0);
5499 r = DWARF2_FRAME_REG_OUT (r, 1);
5500 gcc_assert (r <= 31);
5501 opc = (enum dwarf_location_atom) (DW_OP_reg0 + r);
5503 /* Output the opcode. */
5504 fprintf (asm_out_file, "%#x", opc);
5505 output_loc_operands_raw (loc);
5507 if (!loc->dw_loc_next)
5508 break;
5509 loc = loc->dw_loc_next;
5511 fputc (',', asm_out_file);
5515 /* This routine will generate the correct assembly data for a location
5516 description based on a cfi entry with a complex address. */
5518 static void
5519 output_cfa_loc (dw_cfi_ref cfi, int for_eh)
5521 dw_loc_descr_ref loc;
5522 unsigned long size;
5524 if (cfi->dw_cfi_opc == DW_CFA_expression)
5526 unsigned r =
5527 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
5528 dw2_asm_output_data (1, r, NULL);
5529 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5531 else
5532 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5534 /* Output the size of the block. */
5535 size = size_of_locs (loc);
5536 dw2_asm_output_data_uleb128 (size, NULL);
5538 /* Now output the operations themselves. */
5539 output_loc_sequence (loc, for_eh);
5542 /* Similar, but used for .cfi_escape. */
5544 static void
5545 output_cfa_loc_raw (dw_cfi_ref cfi)
5547 dw_loc_descr_ref loc;
5548 unsigned long size;
5550 if (cfi->dw_cfi_opc == DW_CFA_expression)
5552 unsigned r =
5553 DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1);
5554 fprintf (asm_out_file, "%#x,", r);
5555 loc = cfi->dw_cfi_oprnd2.dw_cfi_loc;
5557 else
5558 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
5560 /* Output the size of the block. */
5561 size = size_of_locs (loc);
5562 dw2_asm_output_data_uleb128_raw (size);
5563 fputc (',', asm_out_file);
5565 /* Now output the operations themselves. */
5566 output_loc_sequence_raw (loc);
5569 /* This function builds a dwarf location descriptor sequence from a
5570 dw_cfa_location, adding the given OFFSET to the result of the
5571 expression. */
5573 static struct dw_loc_descr_struct *
5574 build_cfa_loc (dw_cfa_location *cfa, HOST_WIDE_INT offset)
5576 struct dw_loc_descr_struct *head, *tmp;
5578 offset += cfa->offset;
5580 if (cfa->indirect)
5582 head = new_reg_loc_descr (cfa->reg, cfa->base_offset);
5583 head->dw_loc_oprnd1.val_class = dw_val_class_const;
5584 tmp = new_loc_descr (DW_OP_deref, 0, 0);
5585 add_loc_descr (&head, tmp);
5586 if (offset != 0)
5588 tmp = new_loc_descr (DW_OP_plus_uconst, offset, 0);
5589 add_loc_descr (&head, tmp);
5592 else
5593 head = new_reg_loc_descr (cfa->reg, offset);
5595 return head;
5598 /* This function builds a dwarf location descriptor sequence for
5599 the address at OFFSET from the CFA when stack is aligned to
5600 ALIGNMENT byte. */
5602 static struct dw_loc_descr_struct *
5603 build_cfa_aligned_loc (HOST_WIDE_INT offset, HOST_WIDE_INT alignment)
5605 struct dw_loc_descr_struct *head;
5606 unsigned int dwarf_fp
5607 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM);
5609 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
5610 if (cfa.reg == HARD_FRAME_POINTER_REGNUM && cfa.indirect == 0)
5612 head = new_reg_loc_descr (dwarf_fp, 0);
5613 add_loc_descr (&head, int_loc_descriptor (alignment));
5614 add_loc_descr (&head, new_loc_descr (DW_OP_and, 0, 0));
5615 loc_descr_plus_const (&head, offset);
5617 else
5618 head = new_reg_loc_descr (dwarf_fp, offset);
5619 return head;
5622 /* This function fills in aa dw_cfa_location structure from a dwarf location
5623 descriptor sequence. */
5625 static void
5626 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
5628 struct dw_loc_descr_struct *ptr;
5629 cfa->offset = 0;
5630 cfa->base_offset = 0;
5631 cfa->indirect = 0;
5632 cfa->reg = -1;
5634 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
5636 enum dwarf_location_atom op = ptr->dw_loc_opc;
5638 switch (op)
5640 case DW_OP_reg0:
5641 case DW_OP_reg1:
5642 case DW_OP_reg2:
5643 case DW_OP_reg3:
5644 case DW_OP_reg4:
5645 case DW_OP_reg5:
5646 case DW_OP_reg6:
5647 case DW_OP_reg7:
5648 case DW_OP_reg8:
5649 case DW_OP_reg9:
5650 case DW_OP_reg10:
5651 case DW_OP_reg11:
5652 case DW_OP_reg12:
5653 case DW_OP_reg13:
5654 case DW_OP_reg14:
5655 case DW_OP_reg15:
5656 case DW_OP_reg16:
5657 case DW_OP_reg17:
5658 case DW_OP_reg18:
5659 case DW_OP_reg19:
5660 case DW_OP_reg20:
5661 case DW_OP_reg21:
5662 case DW_OP_reg22:
5663 case DW_OP_reg23:
5664 case DW_OP_reg24:
5665 case DW_OP_reg25:
5666 case DW_OP_reg26:
5667 case DW_OP_reg27:
5668 case DW_OP_reg28:
5669 case DW_OP_reg29:
5670 case DW_OP_reg30:
5671 case DW_OP_reg31:
5672 cfa->reg = op - DW_OP_reg0;
5673 break;
5674 case DW_OP_regx:
5675 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5676 break;
5677 case DW_OP_breg0:
5678 case DW_OP_breg1:
5679 case DW_OP_breg2:
5680 case DW_OP_breg3:
5681 case DW_OP_breg4:
5682 case DW_OP_breg5:
5683 case DW_OP_breg6:
5684 case DW_OP_breg7:
5685 case DW_OP_breg8:
5686 case DW_OP_breg9:
5687 case DW_OP_breg10:
5688 case DW_OP_breg11:
5689 case DW_OP_breg12:
5690 case DW_OP_breg13:
5691 case DW_OP_breg14:
5692 case DW_OP_breg15:
5693 case DW_OP_breg16:
5694 case DW_OP_breg17:
5695 case DW_OP_breg18:
5696 case DW_OP_breg19:
5697 case DW_OP_breg20:
5698 case DW_OP_breg21:
5699 case DW_OP_breg22:
5700 case DW_OP_breg23:
5701 case DW_OP_breg24:
5702 case DW_OP_breg25:
5703 case DW_OP_breg26:
5704 case DW_OP_breg27:
5705 case DW_OP_breg28:
5706 case DW_OP_breg29:
5707 case DW_OP_breg30:
5708 case DW_OP_breg31:
5709 cfa->reg = op - DW_OP_breg0;
5710 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
5711 break;
5712 case DW_OP_bregx:
5713 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
5714 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
5715 break;
5716 case DW_OP_deref:
5717 cfa->indirect = 1;
5718 break;
5719 case DW_OP_plus_uconst:
5720 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
5721 break;
5722 default:
5723 internal_error ("DW_LOC_OP %s not implemented",
5724 dwarf_stack_op_name (ptr->dw_loc_opc));
5729 /* And now, the support for symbolic debugging information. */
5731 /* .debug_str support. */
5732 static int output_indirect_string (void **, void *);
5734 static void dwarf2out_init (const char *);
5735 static void dwarf2out_finish (const char *);
5736 static void dwarf2out_assembly_start (void);
5737 static void dwarf2out_define (unsigned int, const char *);
5738 static void dwarf2out_undef (unsigned int, const char *);
5739 static void dwarf2out_start_source_file (unsigned, const char *);
5740 static void dwarf2out_end_source_file (unsigned);
5741 static void dwarf2out_function_decl (tree);
5742 static void dwarf2out_begin_block (unsigned, unsigned);
5743 static void dwarf2out_end_block (unsigned, unsigned);
5744 static bool dwarf2out_ignore_block (const_tree);
5745 static void dwarf2out_global_decl (tree);
5746 static void dwarf2out_type_decl (tree, int);
5747 static void dwarf2out_imported_module_or_decl (tree, tree, tree, bool);
5748 static void dwarf2out_imported_module_or_decl_1 (tree, tree, tree,
5749 dw_die_ref);
5750 static void dwarf2out_abstract_function (tree);
5751 static void dwarf2out_var_location (rtx);
5752 static void dwarf2out_begin_function (tree);
5753 static void dwarf2out_set_name (tree, tree);
5755 /* The debug hooks structure. */
5757 const struct gcc_debug_hooks dwarf2_debug_hooks =
5759 dwarf2out_init,
5760 dwarf2out_finish,
5761 dwarf2out_assembly_start,
5762 dwarf2out_define,
5763 dwarf2out_undef,
5764 dwarf2out_start_source_file,
5765 dwarf2out_end_source_file,
5766 dwarf2out_begin_block,
5767 dwarf2out_end_block,
5768 dwarf2out_ignore_block,
5769 dwarf2out_source_line,
5770 dwarf2out_begin_prologue,
5771 #if VMS_DEBUGGING_INFO
5772 dwarf2out_vms_end_prologue,
5773 dwarf2out_vms_begin_epilogue,
5774 #else
5775 debug_nothing_int_charstar,
5776 debug_nothing_int_charstar,
5777 #endif
5778 dwarf2out_end_epilogue,
5779 dwarf2out_begin_function,
5780 debug_nothing_int, /* end_function */
5781 dwarf2out_function_decl, /* function_decl */
5782 dwarf2out_global_decl,
5783 dwarf2out_type_decl, /* type_decl */
5784 dwarf2out_imported_module_or_decl,
5785 debug_nothing_tree, /* deferred_inline_function */
5786 /* The DWARF 2 backend tries to reduce debugging bloat by not
5787 emitting the abstract description of inline functions until
5788 something tries to reference them. */
5789 dwarf2out_abstract_function, /* outlining_inline_function */
5790 debug_nothing_rtx, /* label */
5791 debug_nothing_int, /* handle_pch */
5792 dwarf2out_var_location,
5793 dwarf2out_switch_text_section,
5794 dwarf2out_set_name,
5795 1, /* start_end_main_source_file */
5796 TYPE_SYMTAB_IS_DIE /* tree_type_symtab_field */
5799 /* NOTE: In the comments in this file, many references are made to
5800 "Debugging Information Entries". This term is abbreviated as `DIE'
5801 throughout the remainder of this file. */
5803 /* An internal representation of the DWARF output is built, and then
5804 walked to generate the DWARF debugging info. The walk of the internal
5805 representation is done after the entire program has been compiled.
5806 The types below are used to describe the internal representation. */
5808 /* Whether to put type DIEs into their own section .debug_types instead
5809 of making them part of the .debug_info section. Only supported for
5810 Dwarf V4 or higher and the user didn't disable them through
5811 -fno-debug-types-section. It is more efficient to put them in a
5812 separate comdat sections since the linker will then be able to
5813 remove duplicates. But not all tools support .debug_types sections
5814 yet. */
5816 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
5818 /* Various DIE's use offsets relative to the beginning of the
5819 .debug_info section to refer to each other. */
5821 typedef long int dw_offset;
5823 /* Define typedefs here to avoid circular dependencies. */
5825 typedef struct dw_attr_struct *dw_attr_ref;
5826 typedef struct dw_line_info_struct *dw_line_info_ref;
5827 typedef struct pubname_struct *pubname_ref;
5828 typedef struct dw_ranges_struct *dw_ranges_ref;
5829 typedef struct dw_ranges_by_label_struct *dw_ranges_by_label_ref;
5830 typedef struct comdat_type_struct *comdat_type_node_ref;
5832 /* The entries in the line_info table more-or-less mirror the opcodes
5833 that are used in the real dwarf line table. Arrays of these entries
5834 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
5835 supported. */
5837 enum dw_line_info_opcode {
5838 /* Emit DW_LNE_set_address; the operand is the label index. */
5839 LI_set_address,
5841 /* Emit a row to the matrix with the given line. This may be done
5842 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
5843 special opcodes. */
5844 LI_set_line,
5846 /* Emit a DW_LNS_set_file. */
5847 LI_set_file,
5849 /* Emit a DW_LNS_set_column. */
5850 LI_set_column,
5852 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
5853 LI_negate_stmt,
5855 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
5856 LI_set_prologue_end,
5857 LI_set_epilogue_begin,
5859 /* Emit a DW_LNE_set_discriminator. */
5860 LI_set_discriminator
5863 typedef struct GTY(()) dw_line_info_struct {
5864 enum dw_line_info_opcode opcode;
5865 unsigned int val;
5866 } dw_line_info_entry;
5868 DEF_VEC_O(dw_line_info_entry);
5869 DEF_VEC_ALLOC_O(dw_line_info_entry, gc);
5871 typedef struct GTY(()) dw_line_info_table_struct {
5872 /* The label that marks the end of this section. */
5873 const char *end_label;
5875 /* The values for the last row of the matrix, as collected in the table.
5876 These are used to minimize the changes to the next row. */
5877 unsigned int file_num;
5878 unsigned int line_num;
5879 unsigned int column_num;
5880 int discrim_num;
5881 bool is_stmt;
5882 bool in_use;
5884 VEC(dw_line_info_entry, gc) *entries;
5885 } dw_line_info_table;
5887 typedef dw_line_info_table *dw_line_info_table_p;
5889 DEF_VEC_P(dw_line_info_table_p);
5890 DEF_VEC_ALLOC_P(dw_line_info_table_p, gc);
5892 /* Each DIE attribute has a field specifying the attribute kind,
5893 a link to the next attribute in the chain, and an attribute value.
5894 Attributes are typically linked below the DIE they modify. */
5896 typedef struct GTY(()) dw_attr_struct {
5897 enum dwarf_attribute dw_attr;
5898 dw_val_node dw_attr_val;
5900 dw_attr_node;
5902 DEF_VEC_O(dw_attr_node);
5903 DEF_VEC_ALLOC_O(dw_attr_node,gc);
5905 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
5906 The children of each node form a circular list linked by
5907 die_sib. die_child points to the node *before* the "first" child node. */
5909 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct {
5910 union die_symbol_or_type_node
5912 char * GTY ((tag ("0"))) die_symbol;
5913 comdat_type_node_ref GTY ((tag ("1"))) die_type_node;
5915 GTY ((desc ("use_debug_types"))) die_id;
5916 VEC(dw_attr_node,gc) * die_attr;
5917 dw_die_ref die_parent;
5918 dw_die_ref die_child;
5919 dw_die_ref die_sib;
5920 dw_die_ref die_definition; /* ref from a specification to its definition */
5921 dw_offset die_offset;
5922 unsigned long die_abbrev;
5923 int die_mark;
5924 /* Die is used and must not be pruned as unused. */
5925 int die_perennial_p;
5926 unsigned int decl_id;
5927 enum dwarf_tag die_tag;
5929 die_node;
5931 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
5932 #define FOR_EACH_CHILD(die, c, expr) do { \
5933 c = die->die_child; \
5934 if (c) do { \
5935 c = c->die_sib; \
5936 expr; \
5937 } while (c != die->die_child); \
5938 } while (0)
5940 /* The pubname structure */
5942 typedef struct GTY(()) pubname_struct {
5943 dw_die_ref die;
5944 const char *name;
5946 pubname_entry;
5948 DEF_VEC_O(pubname_entry);
5949 DEF_VEC_ALLOC_O(pubname_entry, gc);
5951 struct GTY(()) dw_ranges_struct {
5952 /* If this is positive, it's a block number, otherwise it's a
5953 bitwise-negated index into dw_ranges_by_label. */
5954 int num;
5957 /* A structure to hold a macinfo entry. */
5959 typedef struct GTY(()) macinfo_struct {
5960 unsigned HOST_WIDE_INT code;
5961 unsigned HOST_WIDE_INT lineno;
5962 const char *info;
5964 macinfo_entry;
5966 DEF_VEC_O(macinfo_entry);
5967 DEF_VEC_ALLOC_O(macinfo_entry, gc);
5969 struct GTY(()) dw_ranges_by_label_struct {
5970 const char *begin;
5971 const char *end;
5974 /* The comdat type node structure. */
5975 typedef struct GTY(()) comdat_type_struct
5977 dw_die_ref root_die;
5978 dw_die_ref type_die;
5979 char signature[DWARF_TYPE_SIGNATURE_SIZE];
5980 struct comdat_type_struct *next;
5982 comdat_type_node;
5984 /* The limbo die list structure. */
5985 typedef struct GTY(()) limbo_die_struct {
5986 dw_die_ref die;
5987 tree created_for;
5988 struct limbo_die_struct *next;
5990 limbo_die_node;
5992 typedef struct skeleton_chain_struct
5994 dw_die_ref old_die;
5995 dw_die_ref new_die;
5996 struct skeleton_chain_struct *parent;
5998 skeleton_chain_node;
6000 /* How to start an assembler comment. */
6001 #ifndef ASM_COMMENT_START
6002 #define ASM_COMMENT_START ";#"
6003 #endif
6005 /* Define a macro which returns nonzero for a TYPE_DECL which was
6006 implicitly generated for a tagged type.
6008 Note that unlike the gcc front end (which generates a NULL named
6009 TYPE_DECL node for each complete tagged type, each array type, and
6010 each function type node created) the g++ front end generates a
6011 _named_ TYPE_DECL node for each tagged type node created.
6012 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
6013 generate a DW_TAG_typedef DIE for them. */
6015 #define TYPE_DECL_IS_STUB(decl) \
6016 (DECL_NAME (decl) == NULL_TREE \
6017 || (DECL_ARTIFICIAL (decl) \
6018 && is_tagged_type (TREE_TYPE (decl)) \
6019 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
6020 /* This is necessary for stub decls that \
6021 appear in nested inline functions. */ \
6022 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
6023 && (decl_ultimate_origin (decl) \
6024 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
6026 /* Information concerning the compilation unit's programming
6027 language, and compiler version. */
6029 /* Fixed size portion of the DWARF compilation unit header. */
6030 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
6031 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
6033 /* Fixed size portion of the DWARF comdat type unit header. */
6034 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
6035 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
6036 + DWARF_OFFSET_SIZE)
6038 /* Fixed size portion of public names info. */
6039 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
6041 /* Fixed size portion of the address range info. */
6042 #define DWARF_ARANGES_HEADER_SIZE \
6043 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6044 DWARF2_ADDR_SIZE * 2) \
6045 - DWARF_INITIAL_LENGTH_SIZE)
6047 /* Size of padding portion in the address range info. It must be
6048 aligned to twice the pointer size. */
6049 #define DWARF_ARANGES_PAD_SIZE \
6050 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
6051 DWARF2_ADDR_SIZE * 2) \
6052 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
6054 /* Use assembler line directives if available. */
6055 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
6056 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
6057 #define DWARF2_ASM_LINE_DEBUG_INFO 1
6058 #else
6059 #define DWARF2_ASM_LINE_DEBUG_INFO 0
6060 #endif
6061 #endif
6063 /* Minimum line offset in a special line info. opcode.
6064 This value was chosen to give a reasonable range of values. */
6065 #define DWARF_LINE_BASE -10
6067 /* First special line opcode - leave room for the standard opcodes. */
6068 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
6070 /* Range of line offsets in a special line info. opcode. */
6071 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
6073 /* Flag that indicates the initial value of the is_stmt_start flag.
6074 In the present implementation, we do not mark any lines as
6075 the beginning of a source statement, because that information
6076 is not made available by the GCC front-end. */
6077 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
6079 /* Maximum number of operations per instruction bundle. */
6080 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
6081 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
6082 #endif
6084 /* This location is used by calc_die_sizes() to keep track
6085 the offset of each DIE within the .debug_info section. */
6086 static unsigned long next_die_offset;
6088 /* Record the root of the DIE's built for the current compilation unit. */
6089 static GTY(()) dw_die_ref single_comp_unit_die;
6091 /* A list of type DIEs that have been separated into comdat sections. */
6092 static GTY(()) comdat_type_node *comdat_type_list;
6094 /* A list of DIEs with a NULL parent waiting to be relocated. */
6095 static GTY(()) limbo_die_node *limbo_die_list;
6097 /* A list of DIEs for which we may have to generate
6098 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
6099 static GTY(()) limbo_die_node *deferred_asm_name;
6101 /* Filenames referenced by this compilation unit. */
6102 static GTY((param_is (struct dwarf_file_data))) htab_t file_table;
6104 /* A hash table of references to DIE's that describe declarations.
6105 The key is a DECL_UID() which is a unique number identifying each decl. */
6106 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
6108 /* A hash table of references to DIE's that describe COMMON blocks.
6109 The key is DECL_UID() ^ die_parent. */
6110 static GTY ((param_is (struct die_struct))) htab_t common_block_die_table;
6112 typedef struct GTY(()) die_arg_entry_struct {
6113 dw_die_ref die;
6114 tree arg;
6115 } die_arg_entry;
6117 DEF_VEC_O(die_arg_entry);
6118 DEF_VEC_ALLOC_O(die_arg_entry,gc);
6120 /* Node of the variable location list. */
6121 struct GTY ((chain_next ("%h.next"))) var_loc_node {
6122 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
6123 EXPR_LIST chain. For small bitsizes, bitsize is encoded
6124 in mode of the EXPR_LIST node and first EXPR_LIST operand
6125 is either NOTE_INSN_VAR_LOCATION for a piece with a known
6126 location or NULL for padding. For larger bitsizes,
6127 mode is 0 and first operand is a CONCAT with bitsize
6128 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
6129 NULL as second operand. */
6130 rtx GTY (()) loc;
6131 const char * GTY (()) label;
6132 struct var_loc_node * GTY (()) next;
6135 /* Variable location list. */
6136 struct GTY (()) var_loc_list_def {
6137 struct var_loc_node * GTY (()) first;
6139 /* Pointer to the last but one or last element of the
6140 chained list. If the list is empty, both first and
6141 last are NULL, if the list contains just one node
6142 or the last node certainly is not redundant, it points
6143 to the last node, otherwise points to the last but one.
6144 Do not mark it for GC because it is marked through the chain. */
6145 struct var_loc_node * GTY ((skip ("%h"))) last;
6147 /* Pointer to the last element before section switch,
6148 if NULL, either sections weren't switched or first
6149 is after section switch. */
6150 struct var_loc_node * GTY ((skip ("%h"))) last_before_switch;
6152 /* DECL_UID of the variable decl. */
6153 unsigned int decl_id;
6155 typedef struct var_loc_list_def var_loc_list;
6157 /* Call argument location list. */
6158 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node {
6159 rtx GTY (()) call_arg_loc_note;
6160 const char * GTY (()) label;
6161 tree GTY (()) block;
6162 bool tail_call_p;
6163 rtx GTY (()) symbol_ref;
6164 struct call_arg_loc_node * GTY (()) next;
6168 /* Table of decl location linked lists. */
6169 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
6171 /* Head and tail of call_arg_loc chain. */
6172 static GTY (()) struct call_arg_loc_node *call_arg_locations;
6173 static struct call_arg_loc_node *call_arg_loc_last;
6175 /* Number of call sites in the current function. */
6176 static int call_site_count = -1;
6177 /* Number of tail call sites in the current function. */
6178 static int tail_call_site_count = -1;
6180 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
6181 DIEs. */
6182 static VEC (dw_die_ref, heap) *block_map;
6184 /* A cached location list. */
6185 struct GTY (()) cached_dw_loc_list_def {
6186 /* The DECL_UID of the decl that this entry describes. */
6187 unsigned int decl_id;
6189 /* The cached location list. */
6190 dw_loc_list_ref loc_list;
6192 typedef struct cached_dw_loc_list_def cached_dw_loc_list;
6194 /* Table of cached location lists. */
6195 static GTY ((param_is (cached_dw_loc_list))) htab_t cached_dw_loc_list_table;
6197 /* A pointer to the base of a list of references to DIE's that
6198 are uniquely identified by their tag, presence/absence of
6199 children DIE's, and list of attribute/value pairs. */
6200 static GTY((length ("abbrev_die_table_allocated")))
6201 dw_die_ref *abbrev_die_table;
6203 /* Number of elements currently allocated for abbrev_die_table. */
6204 static GTY(()) unsigned abbrev_die_table_allocated;
6206 /* Number of elements in type_die_table currently in use. */
6207 static GTY(()) unsigned abbrev_die_table_in_use;
6209 /* Size (in elements) of increments by which we may expand the
6210 abbrev_die_table. */
6211 #define ABBREV_DIE_TABLE_INCREMENT 256
6213 /* A global counter for generating labels for line number data. */
6214 static unsigned int line_info_label_num;
6216 /* The current table to which we should emit line number information
6217 for the current function. This will be set up at the beginning of
6218 assembly for the function. */
6219 static dw_line_info_table *cur_line_info_table;
6221 /* The two default tables of line number info. */
6222 static GTY(()) dw_line_info_table *text_section_line_info;
6223 static GTY(()) dw_line_info_table *cold_text_section_line_info;
6225 /* The set of all non-default tables of line number info. */
6226 static GTY(()) VEC (dw_line_info_table_p, gc) *separate_line_info;
6228 /* A flag to tell pubnames/types export if there is an info section to
6229 refer to. */
6230 static bool info_section_emitted;
6232 /* A pointer to the base of a table that contains a list of publicly
6233 accessible names. */
6234 static GTY (()) VEC (pubname_entry, gc) * pubname_table;
6236 /* A pointer to the base of a table that contains a list of publicly
6237 accessible types. */
6238 static GTY (()) VEC (pubname_entry, gc) * pubtype_table;
6240 /* A pointer to the base of a table that contains a list of macro
6241 defines/undefines (and file start/end markers). */
6242 static GTY (()) VEC (macinfo_entry, gc) * macinfo_table;
6244 /* Array of dies for which we should generate .debug_ranges info. */
6245 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
6247 /* Number of elements currently allocated for ranges_table. */
6248 static GTY(()) unsigned ranges_table_allocated;
6250 /* Number of elements in ranges_table currently in use. */
6251 static GTY(()) unsigned ranges_table_in_use;
6253 /* Array of pairs of labels referenced in ranges_table. */
6254 static GTY ((length ("ranges_by_label_allocated")))
6255 dw_ranges_by_label_ref ranges_by_label;
6257 /* Number of elements currently allocated for ranges_by_label. */
6258 static GTY(()) unsigned ranges_by_label_allocated;
6260 /* Number of elements in ranges_by_label currently in use. */
6261 static GTY(()) unsigned ranges_by_label_in_use;
6263 /* Size (in elements) of increments by which we may expand the
6264 ranges_table. */
6265 #define RANGES_TABLE_INCREMENT 64
6267 /* Whether we have location lists that need outputting */
6268 static GTY(()) bool have_location_lists;
6270 /* Unique label counter. */
6271 static GTY(()) unsigned int loclabel_num;
6273 /* Unique label counter for point-of-call tables. */
6274 static GTY(()) unsigned int poc_label_num;
6276 /* Record whether the function being analyzed contains inlined functions. */
6277 static int current_function_has_inlines;
6279 /* The last file entry emitted by maybe_emit_file(). */
6280 static GTY(()) struct dwarf_file_data * last_emitted_file;
6282 /* Number of internal labels generated by gen_internal_sym(). */
6283 static GTY(()) int label_num;
6285 /* Cached result of previous call to lookup_filename. */
6286 static GTY(()) struct dwarf_file_data * file_table_last_lookup;
6288 static GTY(()) VEC(die_arg_entry,gc) *tmpl_value_parm_die_table;
6290 /* Instances of generic types for which we need to generate debug
6291 info that describe their generic parameters and arguments. That
6292 generation needs to happen once all types are properly laid out so
6293 we do it at the end of compilation. */
6294 static GTY(()) VEC(tree,gc) *generic_type_instances;
6296 /* Offset from the "steady-state frame pointer" to the frame base,
6297 within the current function. */
6298 static HOST_WIDE_INT frame_pointer_fb_offset;
6300 /* Forward declarations for functions defined in this file. */
6302 static int is_pseudo_reg (const_rtx);
6303 static tree type_main_variant (tree);
6304 static int is_tagged_type (const_tree);
6305 static const char *dwarf_tag_name (unsigned);
6306 static const char *dwarf_attr_name (unsigned);
6307 static const char *dwarf_form_name (unsigned);
6308 static tree decl_ultimate_origin (const_tree);
6309 static tree decl_class_context (tree);
6310 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
6311 static inline enum dw_val_class AT_class (dw_attr_ref);
6312 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
6313 static inline unsigned AT_flag (dw_attr_ref);
6314 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
6315 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
6316 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
6317 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
6318 static void add_AT_double (dw_die_ref, enum dwarf_attribute,
6319 HOST_WIDE_INT, unsigned HOST_WIDE_INT);
6320 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
6321 unsigned int, unsigned char *);
6322 static void add_AT_data8 (dw_die_ref, enum dwarf_attribute, unsigned char *);
6323 static hashval_t debug_str_do_hash (const void *);
6324 static int debug_str_eq (const void *, const void *);
6325 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
6326 static inline const char *AT_string (dw_attr_ref);
6327 static enum dwarf_form AT_string_form (dw_attr_ref);
6328 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
6329 static void add_AT_specification (dw_die_ref, dw_die_ref);
6330 static inline dw_die_ref AT_ref (dw_attr_ref);
6331 static inline int AT_ref_external (dw_attr_ref);
6332 static inline void set_AT_ref_external (dw_attr_ref, int);
6333 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
6334 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
6335 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
6336 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
6337 dw_loc_list_ref);
6338 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
6339 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
6340 static inline rtx AT_addr (dw_attr_ref);
6341 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
6342 static void add_AT_lineptr (dw_die_ref, enum dwarf_attribute, const char *);
6343 static void add_AT_macptr (dw_die_ref, enum dwarf_attribute, const char *);
6344 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
6345 unsigned HOST_WIDE_INT);
6346 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
6347 unsigned long);
6348 static inline const char *AT_lbl (dw_attr_ref);
6349 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
6350 static const char *get_AT_low_pc (dw_die_ref);
6351 static const char *get_AT_hi_pc (dw_die_ref);
6352 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
6353 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
6354 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
6355 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
6356 static bool is_cxx (void);
6357 static bool is_fortran (void);
6358 static bool is_ada (void);
6359 static void remove_AT (dw_die_ref, enum dwarf_attribute);
6360 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
6361 static void add_child_die (dw_die_ref, dw_die_ref);
6362 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
6363 static dw_die_ref lookup_type_die (tree);
6364 static dw_die_ref strip_naming_typedef (tree, dw_die_ref);
6365 static dw_die_ref lookup_type_die_strip_naming_typedef (tree);
6366 static void equate_type_number_to_die (tree, dw_die_ref);
6367 static hashval_t decl_die_table_hash (const void *);
6368 static int decl_die_table_eq (const void *, const void *);
6369 static dw_die_ref lookup_decl_die (tree);
6370 static hashval_t common_block_die_table_hash (const void *);
6371 static int common_block_die_table_eq (const void *, const void *);
6372 static hashval_t decl_loc_table_hash (const void *);
6373 static int decl_loc_table_eq (const void *, const void *);
6374 static var_loc_list *lookup_decl_loc (const_tree);
6375 static void equate_decl_number_to_die (tree, dw_die_ref);
6376 static struct var_loc_node *add_var_loc_to_decl (tree, rtx, const char *);
6377 static void print_spaces (FILE *);
6378 static void print_die (dw_die_ref, FILE *);
6379 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
6380 static dw_die_ref pop_compile_unit (dw_die_ref);
6381 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
6382 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
6383 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
6384 static void checksum_sleb128 (HOST_WIDE_INT, struct md5_ctx *);
6385 static void checksum_uleb128 (unsigned HOST_WIDE_INT, struct md5_ctx *);
6386 static void loc_checksum_ordered (dw_loc_descr_ref, struct md5_ctx *);
6387 static void attr_checksum_ordered (enum dwarf_tag, dw_attr_ref,
6388 struct md5_ctx *, int *);
6389 struct checksum_attributes;
6390 static void collect_checksum_attributes (struct checksum_attributes *, dw_die_ref);
6391 static void die_checksum_ordered (dw_die_ref, struct md5_ctx *, int *);
6392 static void checksum_die_context (dw_die_ref, struct md5_ctx *);
6393 static void generate_type_signature (dw_die_ref, comdat_type_node *);
6394 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
6395 static int same_dw_val_p (const dw_val_node *, const dw_val_node *, int *);
6396 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
6397 static int same_die_p (dw_die_ref, dw_die_ref, int *);
6398 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
6399 static void compute_section_prefix (dw_die_ref);
6400 static int is_type_die (dw_die_ref);
6401 static int is_comdat_die (dw_die_ref);
6402 static int is_symbol_die (dw_die_ref);
6403 static void assign_symbol_names (dw_die_ref);
6404 static void break_out_includes (dw_die_ref);
6405 static int is_declaration_die (dw_die_ref);
6406 static int should_move_die_to_comdat (dw_die_ref);
6407 static dw_die_ref clone_as_declaration (dw_die_ref);
6408 static dw_die_ref clone_die (dw_die_ref);
6409 static dw_die_ref clone_tree (dw_die_ref);
6410 static void copy_declaration_context (dw_die_ref, dw_die_ref);
6411 static void generate_skeleton_ancestor_tree (skeleton_chain_node *);
6412 static void generate_skeleton_bottom_up (skeleton_chain_node *);
6413 static dw_die_ref generate_skeleton (dw_die_ref);
6414 static dw_die_ref remove_child_or_replace_with_skeleton (dw_die_ref,
6415 dw_die_ref);
6416 static void break_out_comdat_types (dw_die_ref);
6417 static dw_die_ref copy_ancestor_tree (dw_die_ref, dw_die_ref, htab_t);
6418 static void copy_decls_walk (dw_die_ref, dw_die_ref, htab_t);
6419 static void copy_decls_for_unworthy_types (dw_die_ref);
6421 static hashval_t htab_cu_hash (const void *);
6422 static int htab_cu_eq (const void *, const void *);
6423 static void htab_cu_del (void *);
6424 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
6425 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
6426 static void add_sibling_attributes (dw_die_ref);
6427 static void build_abbrev_table (dw_die_ref);
6428 static void output_location_lists (dw_die_ref);
6429 static int constant_size (unsigned HOST_WIDE_INT);
6430 static unsigned long size_of_die (dw_die_ref);
6431 static void calc_die_sizes (dw_die_ref);
6432 static void mark_dies (dw_die_ref);
6433 static void unmark_dies (dw_die_ref);
6434 static void unmark_all_dies (dw_die_ref);
6435 static unsigned long size_of_pubnames (VEC (pubname_entry,gc) *);
6436 static unsigned long size_of_aranges (void);
6437 static enum dwarf_form value_format (dw_attr_ref);
6438 static void output_value_format (dw_attr_ref);
6439 static void output_abbrev_section (void);
6440 static void output_die_symbol (dw_die_ref);
6441 static void output_die (dw_die_ref);
6442 static void output_compilation_unit_header (void);
6443 static void output_comp_unit (dw_die_ref, int);
6444 static void output_comdat_type_unit (comdat_type_node *);
6445 static const char *dwarf2_name (tree, int);
6446 static void add_pubname (tree, dw_die_ref);
6447 static void add_pubname_string (const char *, dw_die_ref);
6448 static void add_pubtype (tree, dw_die_ref);
6449 static void output_pubnames (VEC (pubname_entry,gc) *);
6450 static void output_aranges (unsigned long);
6451 static unsigned int add_ranges_num (int);
6452 static unsigned int add_ranges (const_tree);
6453 static void add_ranges_by_labels (dw_die_ref, const char *, const char *,
6454 bool *);
6455 static void output_ranges (void);
6456 static dw_line_info_table *new_line_info_table (void);
6457 static void output_line_info (void);
6458 static void output_file_names (void);
6459 static dw_die_ref base_type_die (tree);
6460 static int is_base_type (tree);
6461 static dw_die_ref subrange_type_die (tree, tree, tree, dw_die_ref);
6462 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
6463 static dw_die_ref generic_parameter_die (tree, tree, bool, dw_die_ref);
6464 static dw_die_ref template_parameter_pack_die (tree, tree, dw_die_ref);
6465 static int type_is_enum (const_tree);
6466 static unsigned int dbx_reg_number (const_rtx);
6467 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
6468 static dw_loc_descr_ref reg_loc_descriptor (rtx, enum var_init_status);
6469 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int,
6470 enum var_init_status);
6471 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx,
6472 enum var_init_status);
6473 static dw_loc_descr_ref based_loc_descr (rtx, HOST_WIDE_INT,
6474 enum var_init_status);
6475 static int is_based_loc (const_rtx);
6476 static int resolve_one_addr (rtx *, void *);
6477 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx,
6478 enum var_init_status);
6479 static dw_loc_descr_ref loc_descriptor (rtx, enum machine_mode mode,
6480 enum var_init_status);
6481 static dw_loc_list_ref loc_list_from_tree (tree, int);
6482 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int);
6483 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
6484 static tree field_type (const_tree);
6485 static unsigned int simple_type_align_in_bits (const_tree);
6486 static unsigned int simple_decl_align_in_bits (const_tree);
6487 static unsigned HOST_WIDE_INT simple_type_size_in_bits (const_tree);
6488 static HOST_WIDE_INT field_byte_offset (const_tree);
6489 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
6490 dw_loc_list_ref);
6491 static void add_data_member_location_attribute (dw_die_ref, tree);
6492 static bool add_const_value_attribute (dw_die_ref, rtx);
6493 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
6494 static void insert_double (double_int, unsigned char *);
6495 static void insert_float (const_rtx, unsigned char *);
6496 static rtx rtl_for_decl_location (tree);
6497 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool,
6498 enum dwarf_attribute);
6499 static bool tree_add_const_value_attribute (dw_die_ref, tree);
6500 static bool tree_add_const_value_attribute_for_decl (dw_die_ref, tree);
6501 static void add_name_attribute (dw_die_ref, const char *);
6502 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
6503 static void add_comp_dir_attribute (dw_die_ref);
6504 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
6505 static void add_subscript_info (dw_die_ref, tree, bool);
6506 static void add_byte_size_attribute (dw_die_ref, tree);
6507 static void add_bit_offset_attribute (dw_die_ref, tree);
6508 static void add_bit_size_attribute (dw_die_ref, tree);
6509 static void add_prototyped_attribute (dw_die_ref, tree);
6510 static dw_die_ref add_abstract_origin_attribute (dw_die_ref, tree);
6511 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
6512 static void add_src_coords_attributes (dw_die_ref, tree);
6513 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
6514 static void push_decl_scope (tree);
6515 static void pop_decl_scope (void);
6516 static dw_die_ref scope_die_for (tree, dw_die_ref);
6517 static inline int local_scope_p (dw_die_ref);
6518 static inline int class_scope_p (dw_die_ref);
6519 static inline int class_or_namespace_scope_p (dw_die_ref);
6520 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
6521 static void add_calling_convention_attribute (dw_die_ref, tree);
6522 static const char *type_tag (const_tree);
6523 static tree member_declared_type (const_tree);
6524 #if 0
6525 static const char *decl_start_label (tree);
6526 #endif
6527 static void gen_array_type_die (tree, dw_die_ref);
6528 static void gen_descr_array_type_die (tree, struct array_descr_info *, dw_die_ref);
6529 #if 0
6530 static void gen_entry_point_die (tree, dw_die_ref);
6531 #endif
6532 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
6533 static dw_die_ref gen_formal_parameter_die (tree, tree, bool, dw_die_ref);
6534 static dw_die_ref gen_formal_parameter_pack_die (tree, tree, dw_die_ref, tree*);
6535 static void gen_unspecified_parameters_die (tree, dw_die_ref);
6536 static void gen_formal_types_die (tree, dw_die_ref);
6537 static void gen_subprogram_die (tree, dw_die_ref);
6538 static void gen_variable_die (tree, tree, dw_die_ref);
6539 static void gen_const_die (tree, dw_die_ref);
6540 static void gen_label_die (tree, dw_die_ref);
6541 static void gen_lexical_block_die (tree, dw_die_ref, int);
6542 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
6543 static void gen_field_die (tree, dw_die_ref);
6544 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
6545 static dw_die_ref gen_compile_unit_die (const char *);
6546 static void gen_inheritance_die (tree, tree, dw_die_ref);
6547 static void gen_member_die (tree, dw_die_ref);
6548 static void gen_struct_or_union_type_die (tree, dw_die_ref,
6549 enum debug_info_usage);
6550 static void gen_subroutine_type_die (tree, dw_die_ref);
6551 static void gen_typedef_die (tree, dw_die_ref);
6552 static void gen_type_die (tree, dw_die_ref);
6553 static void gen_block_die (tree, dw_die_ref, int);
6554 static void decls_for_scope (tree, dw_die_ref, int);
6555 static int is_redundant_typedef (const_tree);
6556 static bool is_naming_typedef_decl (const_tree);
6557 static inline dw_die_ref get_context_die (tree);
6558 static void gen_namespace_die (tree, dw_die_ref);
6559 static dw_die_ref gen_decl_die (tree, tree, dw_die_ref);
6560 static dw_die_ref force_decl_die (tree);
6561 static dw_die_ref force_type_die (tree);
6562 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
6563 static dw_die_ref declare_in_namespace (tree, dw_die_ref);
6564 static struct dwarf_file_data * lookup_filename (const char *);
6565 static void retry_incomplete_types (void);
6566 static void gen_type_die_for_member (tree, tree, dw_die_ref);
6567 static void gen_generic_params_dies (tree);
6568 static void gen_tagged_type_die (tree, dw_die_ref, enum debug_info_usage);
6569 static void gen_type_die_with_usage (tree, dw_die_ref, enum debug_info_usage);
6570 static void splice_child_die (dw_die_ref, dw_die_ref);
6571 static int file_info_cmp (const void *, const void *);
6572 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
6573 const char *, const char *);
6574 static void output_loc_list (dw_loc_list_ref);
6575 static char *gen_internal_sym (const char *);
6577 static void prune_unmark_dies (dw_die_ref);
6578 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref);
6579 static void prune_unused_types_mark (dw_die_ref, int);
6580 static void prune_unused_types_walk (dw_die_ref);
6581 static void prune_unused_types_walk_attribs (dw_die_ref);
6582 static void prune_unused_types_prune (dw_die_ref);
6583 static void prune_unused_types (void);
6584 static int maybe_emit_file (struct dwarf_file_data *fd);
6585 static inline const char *AT_vms_delta1 (dw_attr_ref);
6586 static inline const char *AT_vms_delta2 (dw_attr_ref);
6587 static inline void add_AT_vms_delta (dw_die_ref, enum dwarf_attribute,
6588 const char *, const char *);
6589 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref, tree);
6590 static void gen_remaining_tmpl_value_param_die_attribute (void);
6591 static bool generic_type_p (tree);
6592 static void schedule_generic_params_dies_gen (tree t);
6593 static void gen_scheduled_generic_parms_dies (void);
6595 /* Section names used to hold DWARF debugging information. */
6596 #ifndef DEBUG_INFO_SECTION
6597 #define DEBUG_INFO_SECTION ".debug_info"
6598 #endif
6599 #ifndef DEBUG_ABBREV_SECTION
6600 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
6601 #endif
6602 #ifndef DEBUG_ARANGES_SECTION
6603 #define DEBUG_ARANGES_SECTION ".debug_aranges"
6604 #endif
6605 #ifndef DEBUG_MACINFO_SECTION
6606 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
6607 #endif
6608 #ifndef DEBUG_LINE_SECTION
6609 #define DEBUG_LINE_SECTION ".debug_line"
6610 #endif
6611 #ifndef DEBUG_LOC_SECTION
6612 #define DEBUG_LOC_SECTION ".debug_loc"
6613 #endif
6614 #ifndef DEBUG_PUBNAMES_SECTION
6615 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
6616 #endif
6617 #ifndef DEBUG_PUBTYPES_SECTION
6618 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
6619 #endif
6620 #ifndef DEBUG_STR_SECTION
6621 #define DEBUG_STR_SECTION ".debug_str"
6622 #endif
6623 #ifndef DEBUG_RANGES_SECTION
6624 #define DEBUG_RANGES_SECTION ".debug_ranges"
6625 #endif
6627 /* Standard ELF section names for compiled code and data. */
6628 #ifndef TEXT_SECTION_NAME
6629 #define TEXT_SECTION_NAME ".text"
6630 #endif
6632 /* Section flags for .debug_str section. */
6633 #define DEBUG_STR_SECTION_FLAGS \
6634 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
6635 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
6636 : SECTION_DEBUG)
6638 /* Labels we insert at beginning sections we can reference instead of
6639 the section names themselves. */
6641 #ifndef TEXT_SECTION_LABEL
6642 #define TEXT_SECTION_LABEL "Ltext"
6643 #endif
6644 #ifndef COLD_TEXT_SECTION_LABEL
6645 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
6646 #endif
6647 #ifndef DEBUG_LINE_SECTION_LABEL
6648 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
6649 #endif
6650 #ifndef DEBUG_INFO_SECTION_LABEL
6651 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
6652 #endif
6653 #ifndef DEBUG_ABBREV_SECTION_LABEL
6654 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
6655 #endif
6656 #ifndef DEBUG_LOC_SECTION_LABEL
6657 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
6658 #endif
6659 #ifndef DEBUG_RANGES_SECTION_LABEL
6660 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
6661 #endif
6662 #ifndef DEBUG_MACINFO_SECTION_LABEL
6663 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
6664 #endif
6667 /* Definitions of defaults for formats and names of various special
6668 (artificial) labels which may be generated within this file (when the -g
6669 options is used and DWARF2_DEBUGGING_INFO is in effect.
6670 If necessary, these may be overridden from within the tm.h file, but
6671 typically, overriding these defaults is unnecessary. */
6673 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6674 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6675 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6676 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
6677 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6678 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6679 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6680 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6681 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
6682 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
6684 #ifndef TEXT_END_LABEL
6685 #define TEXT_END_LABEL "Letext"
6686 #endif
6687 #ifndef COLD_END_LABEL
6688 #define COLD_END_LABEL "Letext_cold"
6689 #endif
6690 #ifndef BLOCK_BEGIN_LABEL
6691 #define BLOCK_BEGIN_LABEL "LBB"
6692 #endif
6693 #ifndef BLOCK_END_LABEL
6694 #define BLOCK_END_LABEL "LBE"
6695 #endif
6696 #ifndef LINE_CODE_LABEL
6697 #define LINE_CODE_LABEL "LM"
6698 #endif
6701 /* Return the root of the DIE's built for the current compilation unit. */
6702 static dw_die_ref
6703 comp_unit_die (void)
6705 if (!single_comp_unit_die)
6706 single_comp_unit_die = gen_compile_unit_die (NULL);
6707 return single_comp_unit_die;
6710 /* We allow a language front-end to designate a function that is to be
6711 called to "demangle" any name before it is put into a DIE. */
6713 static const char *(*demangle_name_func) (const char *);
6715 void
6716 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
6718 demangle_name_func = func;
6721 /* Test if rtl node points to a pseudo register. */
6723 static inline int
6724 is_pseudo_reg (const_rtx rtl)
6726 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
6727 || (GET_CODE (rtl) == SUBREG
6728 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
6731 /* Return a reference to a type, with its const and volatile qualifiers
6732 removed. */
6734 static inline tree
6735 type_main_variant (tree type)
6737 type = TYPE_MAIN_VARIANT (type);
6739 /* ??? There really should be only one main variant among any group of
6740 variants of a given type (and all of the MAIN_VARIANT values for all
6741 members of the group should point to that one type) but sometimes the C
6742 front-end messes this up for array types, so we work around that bug
6743 here. */
6744 if (TREE_CODE (type) == ARRAY_TYPE)
6745 while (type != TYPE_MAIN_VARIANT (type))
6746 type = TYPE_MAIN_VARIANT (type);
6748 return type;
6751 /* Return nonzero if the given type node represents a tagged type. */
6753 static inline int
6754 is_tagged_type (const_tree type)
6756 enum tree_code code = TREE_CODE (type);
6758 return (code == RECORD_TYPE || code == UNION_TYPE
6759 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
6762 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
6764 static void
6765 get_ref_die_offset_label (char *label, dw_die_ref ref)
6767 sprintf (label, "%s+%ld", debug_info_section_label, ref->die_offset);
6770 /* Convert a DIE tag into its string name. */
6772 static const char *
6773 dwarf_tag_name (unsigned int tag)
6775 switch (tag)
6777 case DW_TAG_padding:
6778 return "DW_TAG_padding";
6779 case DW_TAG_array_type:
6780 return "DW_TAG_array_type";
6781 case DW_TAG_class_type:
6782 return "DW_TAG_class_type";
6783 case DW_TAG_entry_point:
6784 return "DW_TAG_entry_point";
6785 case DW_TAG_enumeration_type:
6786 return "DW_TAG_enumeration_type";
6787 case DW_TAG_formal_parameter:
6788 return "DW_TAG_formal_parameter";
6789 case DW_TAG_imported_declaration:
6790 return "DW_TAG_imported_declaration";
6791 case DW_TAG_label:
6792 return "DW_TAG_label";
6793 case DW_TAG_lexical_block:
6794 return "DW_TAG_lexical_block";
6795 case DW_TAG_member:
6796 return "DW_TAG_member";
6797 case DW_TAG_pointer_type:
6798 return "DW_TAG_pointer_type";
6799 case DW_TAG_reference_type:
6800 return "DW_TAG_reference_type";
6801 case DW_TAG_compile_unit:
6802 return "DW_TAG_compile_unit";
6803 case DW_TAG_string_type:
6804 return "DW_TAG_string_type";
6805 case DW_TAG_structure_type:
6806 return "DW_TAG_structure_type";
6807 case DW_TAG_subroutine_type:
6808 return "DW_TAG_subroutine_type";
6809 case DW_TAG_typedef:
6810 return "DW_TAG_typedef";
6811 case DW_TAG_union_type:
6812 return "DW_TAG_union_type";
6813 case DW_TAG_unspecified_parameters:
6814 return "DW_TAG_unspecified_parameters";
6815 case DW_TAG_variant:
6816 return "DW_TAG_variant";
6817 case DW_TAG_common_block:
6818 return "DW_TAG_common_block";
6819 case DW_TAG_common_inclusion:
6820 return "DW_TAG_common_inclusion";
6821 case DW_TAG_inheritance:
6822 return "DW_TAG_inheritance";
6823 case DW_TAG_inlined_subroutine:
6824 return "DW_TAG_inlined_subroutine";
6825 case DW_TAG_module:
6826 return "DW_TAG_module";
6827 case DW_TAG_ptr_to_member_type:
6828 return "DW_TAG_ptr_to_member_type";
6829 case DW_TAG_set_type:
6830 return "DW_TAG_set_type";
6831 case DW_TAG_subrange_type:
6832 return "DW_TAG_subrange_type";
6833 case DW_TAG_with_stmt:
6834 return "DW_TAG_with_stmt";
6835 case DW_TAG_access_declaration:
6836 return "DW_TAG_access_declaration";
6837 case DW_TAG_base_type:
6838 return "DW_TAG_base_type";
6839 case DW_TAG_catch_block:
6840 return "DW_TAG_catch_block";
6841 case DW_TAG_const_type:
6842 return "DW_TAG_const_type";
6843 case DW_TAG_constant:
6844 return "DW_TAG_constant";
6845 case DW_TAG_enumerator:
6846 return "DW_TAG_enumerator";
6847 case DW_TAG_file_type:
6848 return "DW_TAG_file_type";
6849 case DW_TAG_friend:
6850 return "DW_TAG_friend";
6851 case DW_TAG_namelist:
6852 return "DW_TAG_namelist";
6853 case DW_TAG_namelist_item:
6854 return "DW_TAG_namelist_item";
6855 case DW_TAG_packed_type:
6856 return "DW_TAG_packed_type";
6857 case DW_TAG_subprogram:
6858 return "DW_TAG_subprogram";
6859 case DW_TAG_template_type_param:
6860 return "DW_TAG_template_type_param";
6861 case DW_TAG_template_value_param:
6862 return "DW_TAG_template_value_param";
6863 case DW_TAG_thrown_type:
6864 return "DW_TAG_thrown_type";
6865 case DW_TAG_try_block:
6866 return "DW_TAG_try_block";
6867 case DW_TAG_variant_part:
6868 return "DW_TAG_variant_part";
6869 case DW_TAG_variable:
6870 return "DW_TAG_variable";
6871 case DW_TAG_volatile_type:
6872 return "DW_TAG_volatile_type";
6873 case DW_TAG_dwarf_procedure:
6874 return "DW_TAG_dwarf_procedure";
6875 case DW_TAG_restrict_type:
6876 return "DW_TAG_restrict_type";
6877 case DW_TAG_interface_type:
6878 return "DW_TAG_interface_type";
6879 case DW_TAG_namespace:
6880 return "DW_TAG_namespace";
6881 case DW_TAG_imported_module:
6882 return "DW_TAG_imported_module";
6883 case DW_TAG_unspecified_type:
6884 return "DW_TAG_unspecified_type";
6885 case DW_TAG_partial_unit:
6886 return "DW_TAG_partial_unit";
6887 case DW_TAG_imported_unit:
6888 return "DW_TAG_imported_unit";
6889 case DW_TAG_condition:
6890 return "DW_TAG_condition";
6891 case DW_TAG_shared_type:
6892 return "DW_TAG_shared_type";
6893 case DW_TAG_type_unit:
6894 return "DW_TAG_type_unit";
6895 case DW_TAG_rvalue_reference_type:
6896 return "DW_TAG_rvalue_reference_type";
6897 case DW_TAG_template_alias:
6898 return "DW_TAG_template_alias";
6899 case DW_TAG_GNU_template_parameter_pack:
6900 return "DW_TAG_GNU_template_parameter_pack";
6901 case DW_TAG_GNU_formal_parameter_pack:
6902 return "DW_TAG_GNU_formal_parameter_pack";
6903 case DW_TAG_MIPS_loop:
6904 return "DW_TAG_MIPS_loop";
6905 case DW_TAG_format_label:
6906 return "DW_TAG_format_label";
6907 case DW_TAG_function_template:
6908 return "DW_TAG_function_template";
6909 case DW_TAG_class_template:
6910 return "DW_TAG_class_template";
6911 case DW_TAG_GNU_BINCL:
6912 return "DW_TAG_GNU_BINCL";
6913 case DW_TAG_GNU_EINCL:
6914 return "DW_TAG_GNU_EINCL";
6915 case DW_TAG_GNU_template_template_param:
6916 return "DW_TAG_GNU_template_template_param";
6917 case DW_TAG_GNU_call_site:
6918 return "DW_TAG_GNU_call_site";
6919 case DW_TAG_GNU_call_site_parameter:
6920 return "DW_TAG_GNU_call_site_parameter";
6921 default:
6922 return "DW_TAG_<unknown>";
6926 /* Convert a DWARF attribute code into its string name. */
6928 static const char *
6929 dwarf_attr_name (unsigned int attr)
6931 switch (attr)
6933 case DW_AT_sibling:
6934 return "DW_AT_sibling";
6935 case DW_AT_location:
6936 return "DW_AT_location";
6937 case DW_AT_name:
6938 return "DW_AT_name";
6939 case DW_AT_ordering:
6940 return "DW_AT_ordering";
6941 case DW_AT_subscr_data:
6942 return "DW_AT_subscr_data";
6943 case DW_AT_byte_size:
6944 return "DW_AT_byte_size";
6945 case DW_AT_bit_offset:
6946 return "DW_AT_bit_offset";
6947 case DW_AT_bit_size:
6948 return "DW_AT_bit_size";
6949 case DW_AT_element_list:
6950 return "DW_AT_element_list";
6951 case DW_AT_stmt_list:
6952 return "DW_AT_stmt_list";
6953 case DW_AT_low_pc:
6954 return "DW_AT_low_pc";
6955 case DW_AT_high_pc:
6956 return "DW_AT_high_pc";
6957 case DW_AT_language:
6958 return "DW_AT_language";
6959 case DW_AT_member:
6960 return "DW_AT_member";
6961 case DW_AT_discr:
6962 return "DW_AT_discr";
6963 case DW_AT_discr_value:
6964 return "DW_AT_discr_value";
6965 case DW_AT_visibility:
6966 return "DW_AT_visibility";
6967 case DW_AT_import:
6968 return "DW_AT_import";
6969 case DW_AT_string_length:
6970 return "DW_AT_string_length";
6971 case DW_AT_common_reference:
6972 return "DW_AT_common_reference";
6973 case DW_AT_comp_dir:
6974 return "DW_AT_comp_dir";
6975 case DW_AT_const_value:
6976 return "DW_AT_const_value";
6977 case DW_AT_containing_type:
6978 return "DW_AT_containing_type";
6979 case DW_AT_default_value:
6980 return "DW_AT_default_value";
6981 case DW_AT_inline:
6982 return "DW_AT_inline";
6983 case DW_AT_is_optional:
6984 return "DW_AT_is_optional";
6985 case DW_AT_lower_bound:
6986 return "DW_AT_lower_bound";
6987 case DW_AT_producer:
6988 return "DW_AT_producer";
6989 case DW_AT_prototyped:
6990 return "DW_AT_prototyped";
6991 case DW_AT_return_addr:
6992 return "DW_AT_return_addr";
6993 case DW_AT_start_scope:
6994 return "DW_AT_start_scope";
6995 case DW_AT_bit_stride:
6996 return "DW_AT_bit_stride";
6997 case DW_AT_upper_bound:
6998 return "DW_AT_upper_bound";
6999 case DW_AT_abstract_origin:
7000 return "DW_AT_abstract_origin";
7001 case DW_AT_accessibility:
7002 return "DW_AT_accessibility";
7003 case DW_AT_address_class:
7004 return "DW_AT_address_class";
7005 case DW_AT_artificial:
7006 return "DW_AT_artificial";
7007 case DW_AT_base_types:
7008 return "DW_AT_base_types";
7009 case DW_AT_calling_convention:
7010 return "DW_AT_calling_convention";
7011 case DW_AT_count:
7012 return "DW_AT_count";
7013 case DW_AT_data_member_location:
7014 return "DW_AT_data_member_location";
7015 case DW_AT_decl_column:
7016 return "DW_AT_decl_column";
7017 case DW_AT_decl_file:
7018 return "DW_AT_decl_file";
7019 case DW_AT_decl_line:
7020 return "DW_AT_decl_line";
7021 case DW_AT_declaration:
7022 return "DW_AT_declaration";
7023 case DW_AT_discr_list:
7024 return "DW_AT_discr_list";
7025 case DW_AT_encoding:
7026 return "DW_AT_encoding";
7027 case DW_AT_external:
7028 return "DW_AT_external";
7029 case DW_AT_explicit:
7030 return "DW_AT_explicit";
7031 case DW_AT_frame_base:
7032 return "DW_AT_frame_base";
7033 case DW_AT_friend:
7034 return "DW_AT_friend";
7035 case DW_AT_identifier_case:
7036 return "DW_AT_identifier_case";
7037 case DW_AT_macro_info:
7038 return "DW_AT_macro_info";
7039 case DW_AT_namelist_items:
7040 return "DW_AT_namelist_items";
7041 case DW_AT_priority:
7042 return "DW_AT_priority";
7043 case DW_AT_segment:
7044 return "DW_AT_segment";
7045 case DW_AT_specification:
7046 return "DW_AT_specification";
7047 case DW_AT_static_link:
7048 return "DW_AT_static_link";
7049 case DW_AT_type:
7050 return "DW_AT_type";
7051 case DW_AT_use_location:
7052 return "DW_AT_use_location";
7053 case DW_AT_variable_parameter:
7054 return "DW_AT_variable_parameter";
7055 case DW_AT_virtuality:
7056 return "DW_AT_virtuality";
7057 case DW_AT_vtable_elem_location:
7058 return "DW_AT_vtable_elem_location";
7060 case DW_AT_allocated:
7061 return "DW_AT_allocated";
7062 case DW_AT_associated:
7063 return "DW_AT_associated";
7064 case DW_AT_data_location:
7065 return "DW_AT_data_location";
7066 case DW_AT_byte_stride:
7067 return "DW_AT_byte_stride";
7068 case DW_AT_entry_pc:
7069 return "DW_AT_entry_pc";
7070 case DW_AT_use_UTF8:
7071 return "DW_AT_use_UTF8";
7072 case DW_AT_extension:
7073 return "DW_AT_extension";
7074 case DW_AT_ranges:
7075 return "DW_AT_ranges";
7076 case DW_AT_trampoline:
7077 return "DW_AT_trampoline";
7078 case DW_AT_call_column:
7079 return "DW_AT_call_column";
7080 case DW_AT_call_file:
7081 return "DW_AT_call_file";
7082 case DW_AT_call_line:
7083 return "DW_AT_call_line";
7084 case DW_AT_object_pointer:
7085 return "DW_AT_object_pointer";
7087 case DW_AT_signature:
7088 return "DW_AT_signature";
7089 case DW_AT_main_subprogram:
7090 return "DW_AT_main_subprogram";
7091 case DW_AT_data_bit_offset:
7092 return "DW_AT_data_bit_offset";
7093 case DW_AT_const_expr:
7094 return "DW_AT_const_expr";
7095 case DW_AT_enum_class:
7096 return "DW_AT_enum_class";
7097 case DW_AT_linkage_name:
7098 return "DW_AT_linkage_name";
7100 case DW_AT_MIPS_fde:
7101 return "DW_AT_MIPS_fde";
7102 case DW_AT_MIPS_loop_begin:
7103 return "DW_AT_MIPS_loop_begin";
7104 case DW_AT_MIPS_tail_loop_begin:
7105 return "DW_AT_MIPS_tail_loop_begin";
7106 case DW_AT_MIPS_epilog_begin:
7107 return "DW_AT_MIPS_epilog_begin";
7108 #if VMS_DEBUGGING_INFO
7109 case DW_AT_HP_prologue:
7110 return "DW_AT_HP_prologue";
7111 #else
7112 case DW_AT_MIPS_loop_unroll_factor:
7113 return "DW_AT_MIPS_loop_unroll_factor";
7114 #endif
7115 case DW_AT_MIPS_software_pipeline_depth:
7116 return "DW_AT_MIPS_software_pipeline_depth";
7117 case DW_AT_MIPS_linkage_name:
7118 return "DW_AT_MIPS_linkage_name";
7119 #if VMS_DEBUGGING_INFO
7120 case DW_AT_HP_epilogue:
7121 return "DW_AT_HP_epilogue";
7122 #else
7123 case DW_AT_MIPS_stride:
7124 return "DW_AT_MIPS_stride";
7125 #endif
7126 case DW_AT_MIPS_abstract_name:
7127 return "DW_AT_MIPS_abstract_name";
7128 case DW_AT_MIPS_clone_origin:
7129 return "DW_AT_MIPS_clone_origin";
7130 case DW_AT_MIPS_has_inlines:
7131 return "DW_AT_MIPS_has_inlines";
7133 case DW_AT_sf_names:
7134 return "DW_AT_sf_names";
7135 case DW_AT_src_info:
7136 return "DW_AT_src_info";
7137 case DW_AT_mac_info:
7138 return "DW_AT_mac_info";
7139 case DW_AT_src_coords:
7140 return "DW_AT_src_coords";
7141 case DW_AT_body_begin:
7142 return "DW_AT_body_begin";
7143 case DW_AT_body_end:
7144 return "DW_AT_body_end";
7146 case DW_AT_GNU_vector:
7147 return "DW_AT_GNU_vector";
7148 case DW_AT_GNU_guarded_by:
7149 return "DW_AT_GNU_guarded_by";
7150 case DW_AT_GNU_pt_guarded_by:
7151 return "DW_AT_GNU_pt_guarded_by";
7152 case DW_AT_GNU_guarded:
7153 return "DW_AT_GNU_guarded";
7154 case DW_AT_GNU_pt_guarded:
7155 return "DW_AT_GNU_pt_guarded";
7156 case DW_AT_GNU_locks_excluded:
7157 return "DW_AT_GNU_locks_excluded";
7158 case DW_AT_GNU_exclusive_locks_required:
7159 return "DW_AT_GNU_exclusive_locks_required";
7160 case DW_AT_GNU_shared_locks_required:
7161 return "DW_AT_GNU_shared_locks_required";
7162 case DW_AT_GNU_odr_signature:
7163 return "DW_AT_GNU_odr_signature";
7164 case DW_AT_GNU_template_name:
7165 return "DW_AT_GNU_template_name";
7166 case DW_AT_GNU_call_site_value:
7167 return "DW_AT_GNU_call_site_value";
7168 case DW_AT_GNU_call_site_data_value:
7169 return "DW_AT_GNU_call_site_data_value";
7170 case DW_AT_GNU_call_site_target:
7171 return "DW_AT_GNU_call_site_target";
7172 case DW_AT_GNU_call_site_target_clobbered:
7173 return "DW_AT_GNU_call_site_target_clobbered";
7174 case DW_AT_GNU_tail_call:
7175 return "DW_AT_GNU_tail_call";
7176 case DW_AT_GNU_all_tail_call_sites:
7177 return "DW_AT_GNU_all_tail_call_sites";
7178 case DW_AT_GNU_all_call_sites:
7179 return "DW_AT_GNU_all_call_sites";
7180 case DW_AT_GNU_all_source_call_sites:
7181 return "DW_AT_GNU_all_source_call_sites";
7183 case DW_AT_GNAT_descriptive_type:
7184 return "DW_AT_GNAT_descriptive_type";
7186 case DW_AT_VMS_rtnbeg_pd_address:
7187 return "DW_AT_VMS_rtnbeg_pd_address";
7189 default:
7190 return "DW_AT_<unknown>";
7194 /* Convert a DWARF value form code into its string name. */
7196 static const char *
7197 dwarf_form_name (unsigned int form)
7199 switch (form)
7201 case DW_FORM_addr:
7202 return "DW_FORM_addr";
7203 case DW_FORM_block2:
7204 return "DW_FORM_block2";
7205 case DW_FORM_block4:
7206 return "DW_FORM_block4";
7207 case DW_FORM_data2:
7208 return "DW_FORM_data2";
7209 case DW_FORM_data4:
7210 return "DW_FORM_data4";
7211 case DW_FORM_data8:
7212 return "DW_FORM_data8";
7213 case DW_FORM_string:
7214 return "DW_FORM_string";
7215 case DW_FORM_block:
7216 return "DW_FORM_block";
7217 case DW_FORM_block1:
7218 return "DW_FORM_block1";
7219 case DW_FORM_data1:
7220 return "DW_FORM_data1";
7221 case DW_FORM_flag:
7222 return "DW_FORM_flag";
7223 case DW_FORM_sdata:
7224 return "DW_FORM_sdata";
7225 case DW_FORM_strp:
7226 return "DW_FORM_strp";
7227 case DW_FORM_udata:
7228 return "DW_FORM_udata";
7229 case DW_FORM_ref_addr:
7230 return "DW_FORM_ref_addr";
7231 case DW_FORM_ref1:
7232 return "DW_FORM_ref1";
7233 case DW_FORM_ref2:
7234 return "DW_FORM_ref2";
7235 case DW_FORM_ref4:
7236 return "DW_FORM_ref4";
7237 case DW_FORM_ref8:
7238 return "DW_FORM_ref8";
7239 case DW_FORM_ref_udata:
7240 return "DW_FORM_ref_udata";
7241 case DW_FORM_indirect:
7242 return "DW_FORM_indirect";
7243 case DW_FORM_sec_offset:
7244 return "DW_FORM_sec_offset";
7245 case DW_FORM_exprloc:
7246 return "DW_FORM_exprloc";
7247 case DW_FORM_flag_present:
7248 return "DW_FORM_flag_present";
7249 case DW_FORM_ref_sig8:
7250 return "DW_FORM_ref_sig8";
7251 default:
7252 return "DW_FORM_<unknown>";
7256 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
7257 instance of an inlined instance of a decl which is local to an inline
7258 function, so we have to trace all of the way back through the origin chain
7259 to find out what sort of node actually served as the original seed for the
7260 given block. */
7262 static tree
7263 decl_ultimate_origin (const_tree decl)
7265 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
7266 return NULL_TREE;
7268 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
7269 nodes in the function to point to themselves; ignore that if
7270 we're trying to output the abstract instance of this function. */
7271 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
7272 return NULL_TREE;
7274 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
7275 most distant ancestor, this should never happen. */
7276 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
7278 return DECL_ABSTRACT_ORIGIN (decl);
7281 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
7282 of a virtual function may refer to a base class, so we check the 'this'
7283 parameter. */
7285 static tree
7286 decl_class_context (tree decl)
7288 tree context = NULL_TREE;
7290 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
7291 context = DECL_CONTEXT (decl);
7292 else
7293 context = TYPE_MAIN_VARIANT
7294 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
7296 if (context && !TYPE_P (context))
7297 context = NULL_TREE;
7299 return context;
7302 /* Add an attribute/value pair to a DIE. */
7304 static inline void
7305 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
7307 /* Maybe this should be an assert? */
7308 if (die == NULL)
7309 return;
7311 if (die->die_attr == NULL)
7312 die->die_attr = VEC_alloc (dw_attr_node, gc, 1);
7313 VEC_safe_push (dw_attr_node, gc, die->die_attr, attr);
7316 static inline enum dw_val_class
7317 AT_class (dw_attr_ref a)
7319 return a->dw_attr_val.val_class;
7322 /* Add a flag value attribute to a DIE. */
7324 static inline void
7325 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
7327 dw_attr_node attr;
7329 attr.dw_attr = attr_kind;
7330 attr.dw_attr_val.val_class = dw_val_class_flag;
7331 attr.dw_attr_val.v.val_flag = flag;
7332 add_dwarf_attr (die, &attr);
7335 static inline unsigned
7336 AT_flag (dw_attr_ref a)
7338 gcc_assert (a && AT_class (a) == dw_val_class_flag);
7339 return a->dw_attr_val.v.val_flag;
7342 /* Add a signed integer attribute value to a DIE. */
7344 static inline void
7345 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
7347 dw_attr_node attr;
7349 attr.dw_attr = attr_kind;
7350 attr.dw_attr_val.val_class = dw_val_class_const;
7351 attr.dw_attr_val.v.val_int = int_val;
7352 add_dwarf_attr (die, &attr);
7355 static inline HOST_WIDE_INT
7356 AT_int (dw_attr_ref a)
7358 gcc_assert (a && AT_class (a) == dw_val_class_const);
7359 return a->dw_attr_val.v.val_int;
7362 /* Add an unsigned integer attribute value to a DIE. */
7364 static inline void
7365 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
7366 unsigned HOST_WIDE_INT unsigned_val)
7368 dw_attr_node attr;
7370 attr.dw_attr = attr_kind;
7371 attr.dw_attr_val.val_class = dw_val_class_unsigned_const;
7372 attr.dw_attr_val.v.val_unsigned = unsigned_val;
7373 add_dwarf_attr (die, &attr);
7376 static inline unsigned HOST_WIDE_INT
7377 AT_unsigned (dw_attr_ref a)
7379 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
7380 return a->dw_attr_val.v.val_unsigned;
7383 /* Add an unsigned double integer attribute value to a DIE. */
7385 static inline void
7386 add_AT_double (dw_die_ref die, enum dwarf_attribute attr_kind,
7387 HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
7389 dw_attr_node attr;
7391 attr.dw_attr = attr_kind;
7392 attr.dw_attr_val.val_class = dw_val_class_const_double;
7393 attr.dw_attr_val.v.val_double.high = high;
7394 attr.dw_attr_val.v.val_double.low = low;
7395 add_dwarf_attr (die, &attr);
7398 /* Add a floating point attribute value to a DIE and return it. */
7400 static inline void
7401 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
7402 unsigned int length, unsigned int elt_size, unsigned char *array)
7404 dw_attr_node attr;
7406 attr.dw_attr = attr_kind;
7407 attr.dw_attr_val.val_class = dw_val_class_vec;
7408 attr.dw_attr_val.v.val_vec.length = length;
7409 attr.dw_attr_val.v.val_vec.elt_size = elt_size;
7410 attr.dw_attr_val.v.val_vec.array = array;
7411 add_dwarf_attr (die, &attr);
7414 /* Add an 8-byte data attribute value to a DIE. */
7416 static inline void
7417 add_AT_data8 (dw_die_ref die, enum dwarf_attribute attr_kind,
7418 unsigned char data8[8])
7420 dw_attr_node attr;
7422 attr.dw_attr = attr_kind;
7423 attr.dw_attr_val.val_class = dw_val_class_data8;
7424 memcpy (attr.dw_attr_val.v.val_data8, data8, 8);
7425 add_dwarf_attr (die, &attr);
7428 /* Hash and equality functions for debug_str_hash. */
7430 static hashval_t
7431 debug_str_do_hash (const void *x)
7433 return htab_hash_string (((const struct indirect_string_node *)x)->str);
7436 static int
7437 debug_str_eq (const void *x1, const void *x2)
7439 return strcmp ((((const struct indirect_string_node *)x1)->str),
7440 (const char *)x2) == 0;
7443 /* Add STR to the indirect string hash table. */
7445 static struct indirect_string_node *
7446 find_AT_string (const char *str)
7448 struct indirect_string_node *node;
7449 void **slot;
7451 if (! debug_str_hash)
7452 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
7453 debug_str_eq, NULL);
7455 slot = htab_find_slot_with_hash (debug_str_hash, str,
7456 htab_hash_string (str), INSERT);
7457 if (*slot == NULL)
7459 node = ggc_alloc_cleared_indirect_string_node ();
7460 node->str = ggc_strdup (str);
7461 *slot = node;
7463 else
7464 node = (struct indirect_string_node *) *slot;
7466 node->refcount++;
7467 return node;
7470 /* Add a string attribute value to a DIE. */
7472 static inline void
7473 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
7475 dw_attr_node attr;
7476 struct indirect_string_node *node;
7478 node = find_AT_string (str);
7480 attr.dw_attr = attr_kind;
7481 attr.dw_attr_val.val_class = dw_val_class_str;
7482 attr.dw_attr_val.v.val_str = node;
7483 add_dwarf_attr (die, &attr);
7486 /* Create a label for an indirect string node, ensuring it is going to
7487 be output, unless its reference count goes down to zero. */
7489 static inline void
7490 gen_label_for_indirect_string (struct indirect_string_node *node)
7492 char label[32];
7494 if (node->label)
7495 return;
7497 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
7498 ++dw2_string_counter;
7499 node->label = xstrdup (label);
7502 /* Create a SYMBOL_REF rtx whose value is the initial address of a
7503 debug string STR. */
7505 static inline rtx
7506 get_debug_string_label (const char *str)
7508 struct indirect_string_node *node = find_AT_string (str);
7510 debug_str_hash_forced = true;
7512 gen_label_for_indirect_string (node);
7514 return gen_rtx_SYMBOL_REF (Pmode, node->label);
7517 static inline const char *
7518 AT_string (dw_attr_ref a)
7520 gcc_assert (a && AT_class (a) == dw_val_class_str);
7521 return a->dw_attr_val.v.val_str->str;
7524 /* Find out whether a string should be output inline in DIE
7525 or out-of-line in .debug_str section. */
7527 static enum dwarf_form
7528 AT_string_form (dw_attr_ref a)
7530 struct indirect_string_node *node;
7531 unsigned int len;
7533 gcc_assert (a && AT_class (a) == dw_val_class_str);
7535 node = a->dw_attr_val.v.val_str;
7536 if (node->form)
7537 return node->form;
7539 len = strlen (node->str) + 1;
7541 /* If the string is shorter or equal to the size of the reference, it is
7542 always better to put it inline. */
7543 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
7544 return node->form = DW_FORM_string;
7546 /* If we cannot expect the linker to merge strings in .debug_str
7547 section, only put it into .debug_str if it is worth even in this
7548 single module. */
7549 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
7550 || ((debug_str_section->common.flags & SECTION_MERGE) == 0
7551 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len))
7552 return node->form = DW_FORM_string;
7554 gen_label_for_indirect_string (node);
7556 return node->form = DW_FORM_strp;
7559 /* Add a DIE reference attribute value to a DIE. */
7561 static inline void
7562 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
7564 dw_attr_node attr;
7566 #ifdef ENABLE_CHECKING
7567 gcc_assert (targ_die != NULL);
7568 #else
7569 /* With LTO we can end up trying to reference something we didn't create
7570 a DIE for. Avoid crashing later on a NULL referenced DIE. */
7571 if (targ_die == NULL)
7572 return;
7573 #endif
7575 attr.dw_attr = attr_kind;
7576 attr.dw_attr_val.val_class = dw_val_class_die_ref;
7577 attr.dw_attr_val.v.val_die_ref.die = targ_die;
7578 attr.dw_attr_val.v.val_die_ref.external = 0;
7579 add_dwarf_attr (die, &attr);
7582 /* Add an AT_specification attribute to a DIE, and also make the back
7583 pointer from the specification to the definition. */
7585 static inline void
7586 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
7588 add_AT_die_ref (die, DW_AT_specification, targ_die);
7589 gcc_assert (!targ_die->die_definition);
7590 targ_die->die_definition = die;
7593 static inline dw_die_ref
7594 AT_ref (dw_attr_ref a)
7596 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7597 return a->dw_attr_val.v.val_die_ref.die;
7600 static inline int
7601 AT_ref_external (dw_attr_ref a)
7603 if (a && AT_class (a) == dw_val_class_die_ref)
7604 return a->dw_attr_val.v.val_die_ref.external;
7606 return 0;
7609 static inline void
7610 set_AT_ref_external (dw_attr_ref a, int i)
7612 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
7613 a->dw_attr_val.v.val_die_ref.external = i;
7616 /* Add an FDE reference attribute value to a DIE. */
7618 static inline void
7619 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
7621 dw_attr_node attr;
7623 attr.dw_attr = attr_kind;
7624 attr.dw_attr_val.val_class = dw_val_class_fde_ref;
7625 attr.dw_attr_val.v.val_fde_index = targ_fde;
7626 add_dwarf_attr (die, &attr);
7629 /* Add a location description attribute value to a DIE. */
7631 static inline void
7632 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
7634 dw_attr_node attr;
7636 attr.dw_attr = attr_kind;
7637 attr.dw_attr_val.val_class = dw_val_class_loc;
7638 attr.dw_attr_val.v.val_loc = loc;
7639 add_dwarf_attr (die, &attr);
7642 static inline dw_loc_descr_ref
7643 AT_loc (dw_attr_ref a)
7645 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7646 return a->dw_attr_val.v.val_loc;
7649 static inline void
7650 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
7652 dw_attr_node attr;
7654 attr.dw_attr = attr_kind;
7655 attr.dw_attr_val.val_class = dw_val_class_loc_list;
7656 attr.dw_attr_val.v.val_loc_list = loc_list;
7657 add_dwarf_attr (die, &attr);
7658 have_location_lists = true;
7661 static inline dw_loc_list_ref
7662 AT_loc_list (dw_attr_ref a)
7664 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7665 return a->dw_attr_val.v.val_loc_list;
7668 static inline dw_loc_list_ref *
7669 AT_loc_list_ptr (dw_attr_ref a)
7671 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
7672 return &a->dw_attr_val.v.val_loc_list;
7675 /* Add an address constant attribute value to a DIE. */
7677 static inline void
7678 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
7680 dw_attr_node attr;
7682 attr.dw_attr = attr_kind;
7683 attr.dw_attr_val.val_class = dw_val_class_addr;
7684 attr.dw_attr_val.v.val_addr = addr;
7685 add_dwarf_attr (die, &attr);
7688 /* Get the RTX from to an address DIE attribute. */
7690 static inline rtx
7691 AT_addr (dw_attr_ref a)
7693 gcc_assert (a && AT_class (a) == dw_val_class_addr);
7694 return a->dw_attr_val.v.val_addr;
7697 /* Add a file attribute value to a DIE. */
7699 static inline void
7700 add_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind,
7701 struct dwarf_file_data *fd)
7703 dw_attr_node attr;
7705 attr.dw_attr = attr_kind;
7706 attr.dw_attr_val.val_class = dw_val_class_file;
7707 attr.dw_attr_val.v.val_file = fd;
7708 add_dwarf_attr (die, &attr);
7711 /* Get the dwarf_file_data from a file DIE attribute. */
7713 static inline struct dwarf_file_data *
7714 AT_file (dw_attr_ref a)
7716 gcc_assert (a && AT_class (a) == dw_val_class_file);
7717 return a->dw_attr_val.v.val_file;
7720 /* Add a vms delta attribute value to a DIE. */
7722 static inline void
7723 add_AT_vms_delta (dw_die_ref die, enum dwarf_attribute attr_kind,
7724 const char *lbl1, const char *lbl2)
7726 dw_attr_node attr;
7728 attr.dw_attr = attr_kind;
7729 attr.dw_attr_val.val_class = dw_val_class_vms_delta;
7730 attr.dw_attr_val.v.val_vms_delta.lbl1 = xstrdup (lbl1);
7731 attr.dw_attr_val.v.val_vms_delta.lbl2 = xstrdup (lbl2);
7732 add_dwarf_attr (die, &attr);
7735 /* Add a label identifier attribute value to a DIE. */
7737 static inline void
7738 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
7740 dw_attr_node attr;
7742 attr.dw_attr = attr_kind;
7743 attr.dw_attr_val.val_class = dw_val_class_lbl_id;
7744 attr.dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
7745 add_dwarf_attr (die, &attr);
7748 /* Add a section offset attribute value to a DIE, an offset into the
7749 debug_line section. */
7751 static inline void
7752 add_AT_lineptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7753 const char *label)
7755 dw_attr_node attr;
7757 attr.dw_attr = attr_kind;
7758 attr.dw_attr_val.val_class = dw_val_class_lineptr;
7759 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7760 add_dwarf_attr (die, &attr);
7763 /* Add a section offset attribute value to a DIE, an offset into the
7764 debug_macinfo section. */
7766 static inline void
7767 add_AT_macptr (dw_die_ref die, enum dwarf_attribute attr_kind,
7768 const char *label)
7770 dw_attr_node attr;
7772 attr.dw_attr = attr_kind;
7773 attr.dw_attr_val.val_class = dw_val_class_macptr;
7774 attr.dw_attr_val.v.val_lbl_id = xstrdup (label);
7775 add_dwarf_attr (die, &attr);
7778 /* Add an offset attribute value to a DIE. */
7780 static inline void
7781 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
7782 unsigned HOST_WIDE_INT offset)
7784 dw_attr_node attr;
7786 attr.dw_attr = attr_kind;
7787 attr.dw_attr_val.val_class = dw_val_class_offset;
7788 attr.dw_attr_val.v.val_offset = offset;
7789 add_dwarf_attr (die, &attr);
7792 /* Add an range_list attribute value to a DIE. */
7794 static void
7795 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
7796 long unsigned int offset)
7798 dw_attr_node attr;
7800 attr.dw_attr = attr_kind;
7801 attr.dw_attr_val.val_class = dw_val_class_range_list;
7802 attr.dw_attr_val.v.val_offset = offset;
7803 add_dwarf_attr (die, &attr);
7806 /* Return the start label of a delta attribute. */
7808 static inline const char *
7809 AT_vms_delta1 (dw_attr_ref a)
7811 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7812 return a->dw_attr_val.v.val_vms_delta.lbl1;
7815 /* Return the end label of a delta attribute. */
7817 static inline const char *
7818 AT_vms_delta2 (dw_attr_ref a)
7820 gcc_assert (a && (AT_class (a) == dw_val_class_vms_delta));
7821 return a->dw_attr_val.v.val_vms_delta.lbl2;
7824 static inline const char *
7825 AT_lbl (dw_attr_ref a)
7827 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
7828 || AT_class (a) == dw_val_class_lineptr
7829 || AT_class (a) == dw_val_class_macptr));
7830 return a->dw_attr_val.v.val_lbl_id;
7833 /* Get the attribute of type attr_kind. */
7835 static dw_attr_ref
7836 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7838 dw_attr_ref a;
7839 unsigned ix;
7840 dw_die_ref spec = NULL;
7842 if (! die)
7843 return NULL;
7845 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7846 if (a->dw_attr == attr_kind)
7847 return a;
7848 else if (a->dw_attr == DW_AT_specification
7849 || a->dw_attr == DW_AT_abstract_origin)
7850 spec = AT_ref (a);
7852 if (spec)
7853 return get_AT (spec, attr_kind);
7855 return NULL;
7858 /* Return the "low pc" attribute value, typically associated with a subprogram
7859 DIE. Return null if the "low pc" attribute is either not present, or if it
7860 cannot be represented as an assembler label identifier. */
7862 static inline const char *
7863 get_AT_low_pc (dw_die_ref die)
7865 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
7867 return a ? AT_lbl (a) : NULL;
7870 /* Return the "high pc" attribute value, typically associated with a subprogram
7871 DIE. Return null if the "high pc" attribute is either not present, or if it
7872 cannot be represented as an assembler label identifier. */
7874 static inline const char *
7875 get_AT_hi_pc (dw_die_ref die)
7877 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
7879 return a ? AT_lbl (a) : NULL;
7882 /* Return the value of the string attribute designated by ATTR_KIND, or
7883 NULL if it is not present. */
7885 static inline const char *
7886 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
7888 dw_attr_ref a = get_AT (die, attr_kind);
7890 return a ? AT_string (a) : NULL;
7893 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
7894 if it is not present. */
7896 static inline int
7897 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
7899 dw_attr_ref a = get_AT (die, attr_kind);
7901 return a ? AT_flag (a) : 0;
7904 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
7905 if it is not present. */
7907 static inline unsigned
7908 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
7910 dw_attr_ref a = get_AT (die, attr_kind);
7912 return a ? AT_unsigned (a) : 0;
7915 static inline dw_die_ref
7916 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
7918 dw_attr_ref a = get_AT (die, attr_kind);
7920 return a ? AT_ref (a) : NULL;
7923 static inline struct dwarf_file_data *
7924 get_AT_file (dw_die_ref die, enum dwarf_attribute attr_kind)
7926 dw_attr_ref a = get_AT (die, attr_kind);
7928 return a ? AT_file (a) : NULL;
7931 /* Return TRUE if the language is C++. */
7933 static inline bool
7934 is_cxx (void)
7936 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7938 return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus;
7941 /* Return TRUE if the language is Fortran. */
7943 static inline bool
7944 is_fortran (void)
7946 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7948 return (lang == DW_LANG_Fortran77
7949 || lang == DW_LANG_Fortran90
7950 || lang == DW_LANG_Fortran95);
7953 /* Return TRUE if the language is Ada. */
7955 static inline bool
7956 is_ada (void)
7958 unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language);
7960 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
7963 /* Remove the specified attribute if present. */
7965 static void
7966 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
7968 dw_attr_ref a;
7969 unsigned ix;
7971 if (! die)
7972 return;
7974 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
7975 if (a->dw_attr == attr_kind)
7977 if (AT_class (a) == dw_val_class_str)
7978 if (a->dw_attr_val.v.val_str->refcount)
7979 a->dw_attr_val.v.val_str->refcount--;
7981 /* VEC_ordered_remove should help reduce the number of abbrevs
7982 that are needed. */
7983 VEC_ordered_remove (dw_attr_node, die->die_attr, ix);
7984 return;
7988 /* Remove CHILD from its parent. PREV must have the property that
7989 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
7991 static void
7992 remove_child_with_prev (dw_die_ref child, dw_die_ref prev)
7994 gcc_assert (child->die_parent == prev->die_parent);
7995 gcc_assert (prev->die_sib == child);
7996 if (prev == child)
7998 gcc_assert (child->die_parent->die_child == child);
7999 prev = NULL;
8001 else
8002 prev->die_sib = child->die_sib;
8003 if (child->die_parent->die_child == child)
8004 child->die_parent->die_child = prev;
8007 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
8008 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
8010 static void
8011 replace_child (dw_die_ref old_child, dw_die_ref new_child, dw_die_ref prev)
8013 dw_die_ref parent = old_child->die_parent;
8015 gcc_assert (parent == prev->die_parent);
8016 gcc_assert (prev->die_sib == old_child);
8018 new_child->die_parent = parent;
8019 if (prev == old_child)
8021 gcc_assert (parent->die_child == old_child);
8022 new_child->die_sib = new_child;
8024 else
8026 prev->die_sib = new_child;
8027 new_child->die_sib = old_child->die_sib;
8029 if (old_child->die_parent->die_child == old_child)
8030 old_child->die_parent->die_child = new_child;
8033 /* Move all children from OLD_PARENT to NEW_PARENT. */
8035 static void
8036 move_all_children (dw_die_ref old_parent, dw_die_ref new_parent)
8038 dw_die_ref c;
8039 new_parent->die_child = old_parent->die_child;
8040 old_parent->die_child = NULL;
8041 FOR_EACH_CHILD (new_parent, c, c->die_parent = new_parent);
8044 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
8045 matches TAG. */
8047 static void
8048 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
8050 dw_die_ref c;
8052 c = die->die_child;
8053 if (c) do {
8054 dw_die_ref prev = c;
8055 c = c->die_sib;
8056 while (c->die_tag == tag)
8058 remove_child_with_prev (c, prev);
8059 /* Might have removed every child. */
8060 if (c == c->die_sib)
8061 return;
8062 c = c->die_sib;
8064 } while (c != die->die_child);
8067 /* Add a CHILD_DIE as the last child of DIE. */
8069 static void
8070 add_child_die (dw_die_ref die, dw_die_ref child_die)
8072 /* FIXME this should probably be an assert. */
8073 if (! die || ! child_die)
8074 return;
8075 gcc_assert (die != child_die);
8077 child_die->die_parent = die;
8078 if (die->die_child)
8080 child_die->die_sib = die->die_child->die_sib;
8081 die->die_child->die_sib = child_die;
8083 else
8084 child_die->die_sib = child_die;
8085 die->die_child = child_die;
8088 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
8089 is the specification, to the end of PARENT's list of children.
8090 This is done by removing and re-adding it. */
8092 static void
8093 splice_child_die (dw_die_ref parent, dw_die_ref child)
8095 dw_die_ref p;
8097 /* We want the declaration DIE from inside the class, not the
8098 specification DIE at toplevel. */
8099 if (child->die_parent != parent)
8101 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
8103 if (tmp)
8104 child = tmp;
8107 gcc_assert (child->die_parent == parent
8108 || (child->die_parent
8109 == get_AT_ref (parent, DW_AT_specification)));
8111 for (p = child->die_parent->die_child; ; p = p->die_sib)
8112 if (p->die_sib == child)
8114 remove_child_with_prev (child, p);
8115 break;
8118 add_child_die (parent, child);
8121 /* Return a pointer to a newly created DIE node. */
8123 static inline dw_die_ref
8124 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
8126 dw_die_ref die = ggc_alloc_cleared_die_node ();
8128 die->die_tag = tag_value;
8130 if (parent_die != NULL)
8131 add_child_die (parent_die, die);
8132 else
8134 limbo_die_node *limbo_node;
8136 limbo_node = ggc_alloc_cleared_limbo_die_node ();
8137 limbo_node->die = die;
8138 limbo_node->created_for = t;
8139 limbo_node->next = limbo_die_list;
8140 limbo_die_list = limbo_node;
8143 return die;
8146 /* Return the DIE associated with the given type specifier. */
8148 static inline dw_die_ref
8149 lookup_type_die (tree type)
8151 return TYPE_SYMTAB_DIE (type);
8154 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
8155 anonymous type named by the typedef TYPE_DIE, return the DIE of the
8156 anonymous type instead the one of the naming typedef. */
8158 static inline dw_die_ref
8159 strip_naming_typedef (tree type, dw_die_ref type_die)
8161 if (type
8162 && TREE_CODE (type) == RECORD_TYPE
8163 && type_die
8164 && type_die->die_tag == DW_TAG_typedef
8165 && is_naming_typedef_decl (TYPE_NAME (type)))
8166 type_die = get_AT_ref (type_die, DW_AT_type);
8167 return type_die;
8170 /* Like lookup_type_die, but if type is an anonymous type named by a
8171 typedef[1], return the DIE of the anonymous type instead the one of
8172 the naming typedef. This is because in gen_typedef_die, we did
8173 equate the anonymous struct named by the typedef with the DIE of
8174 the naming typedef. So by default, lookup_type_die on an anonymous
8175 struct yields the DIE of the naming typedef.
8177 [1]: Read the comment of is_naming_typedef_decl to learn about what
8178 a naming typedef is. */
8180 static inline dw_die_ref
8181 lookup_type_die_strip_naming_typedef (tree type)
8183 dw_die_ref die = lookup_type_die (type);
8184 return strip_naming_typedef (type, die);
8187 /* Equate a DIE to a given type specifier. */
8189 static inline void
8190 equate_type_number_to_die (tree type, dw_die_ref type_die)
8192 TYPE_SYMTAB_DIE (type) = type_die;
8195 /* Returns a hash value for X (which really is a die_struct). */
8197 static hashval_t
8198 decl_die_table_hash (const void *x)
8200 return (hashval_t) ((const_dw_die_ref) x)->decl_id;
8203 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
8205 static int
8206 decl_die_table_eq (const void *x, const void *y)
8208 return (((const_dw_die_ref) x)->decl_id == DECL_UID ((const_tree) y));
8211 /* Return the DIE associated with a given declaration. */
8213 static inline dw_die_ref
8214 lookup_decl_die (tree decl)
8216 return (dw_die_ref) htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
8219 /* Returns a hash value for X (which really is a var_loc_list). */
8221 static hashval_t
8222 decl_loc_table_hash (const void *x)
8224 return (hashval_t) ((const var_loc_list *) x)->decl_id;
8227 /* Return nonzero if decl_id of var_loc_list X is the same as
8228 UID of decl *Y. */
8230 static int
8231 decl_loc_table_eq (const void *x, const void *y)
8233 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const_tree) y));
8236 /* Return the var_loc list associated with a given declaration. */
8238 static inline var_loc_list *
8239 lookup_decl_loc (const_tree decl)
8241 if (!decl_loc_table)
8242 return NULL;
8243 return (var_loc_list *)
8244 htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
8247 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
8249 static hashval_t
8250 cached_dw_loc_list_table_hash (const void *x)
8252 return (hashval_t) ((const cached_dw_loc_list *) x)->decl_id;
8255 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
8256 UID of decl *Y. */
8258 static int
8259 cached_dw_loc_list_table_eq (const void *x, const void *y)
8261 return (((const cached_dw_loc_list *) x)->decl_id
8262 == DECL_UID ((const_tree) y));
8265 /* Equate a DIE to a particular declaration. */
8267 static void
8268 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
8270 unsigned int decl_id = DECL_UID (decl);
8271 void **slot;
8273 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
8274 *slot = decl_die;
8275 decl_die->decl_id = decl_id;
8278 /* Return how many bits covers PIECE EXPR_LIST. */
8280 static int
8281 decl_piece_bitsize (rtx piece)
8283 int ret = (int) GET_MODE (piece);
8284 if (ret)
8285 return ret;
8286 gcc_assert (GET_CODE (XEXP (piece, 0)) == CONCAT
8287 && CONST_INT_P (XEXP (XEXP (piece, 0), 0)));
8288 return INTVAL (XEXP (XEXP (piece, 0), 0));
8291 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
8293 static rtx *
8294 decl_piece_varloc_ptr (rtx piece)
8296 if ((int) GET_MODE (piece))
8297 return &XEXP (piece, 0);
8298 else
8299 return &XEXP (XEXP (piece, 0), 1);
8302 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
8303 Next is the chain of following piece nodes. */
8305 static rtx
8306 decl_piece_node (rtx loc_note, HOST_WIDE_INT bitsize, rtx next)
8308 if (bitsize <= (int) MAX_MACHINE_MODE)
8309 return alloc_EXPR_LIST (bitsize, loc_note, next);
8310 else
8311 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode,
8312 GEN_INT (bitsize),
8313 loc_note), next);
8316 /* Return rtx that should be stored into loc field for
8317 LOC_NOTE and BITPOS/BITSIZE. */
8319 static rtx
8320 construct_piece_list (rtx loc_note, HOST_WIDE_INT bitpos,
8321 HOST_WIDE_INT bitsize)
8323 if (bitsize != -1)
8325 loc_note = decl_piece_node (loc_note, bitsize, NULL_RTX);
8326 if (bitpos != 0)
8327 loc_note = decl_piece_node (NULL_RTX, bitpos, loc_note);
8329 return loc_note;
8332 /* This function either modifies location piece list *DEST in
8333 place (if SRC and INNER is NULL), or copies location piece list
8334 *SRC to *DEST while modifying it. Location BITPOS is modified
8335 to contain LOC_NOTE, any pieces overlapping it are removed resp.
8336 not copied and if needed some padding around it is added.
8337 When modifying in place, DEST should point to EXPR_LIST where
8338 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
8339 to the start of the whole list and INNER points to the EXPR_LIST
8340 where earlier pieces cover PIECE_BITPOS bits. */
8342 static void
8343 adjust_piece_list (rtx *dest, rtx *src, rtx *inner,
8344 HOST_WIDE_INT bitpos, HOST_WIDE_INT piece_bitpos,
8345 HOST_WIDE_INT bitsize, rtx loc_note)
8347 int diff;
8348 bool copy = inner != NULL;
8350 if (copy)
8352 /* First copy all nodes preceeding the current bitpos. */
8353 while (src != inner)
8355 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8356 decl_piece_bitsize (*src), NULL_RTX);
8357 dest = &XEXP (*dest, 1);
8358 src = &XEXP (*src, 1);
8361 /* Add padding if needed. */
8362 if (bitpos != piece_bitpos)
8364 *dest = decl_piece_node (NULL_RTX, bitpos - piece_bitpos,
8365 copy ? NULL_RTX : *dest);
8366 dest = &XEXP (*dest, 1);
8368 else if (*dest && decl_piece_bitsize (*dest) == bitsize)
8370 gcc_assert (!copy);
8371 /* A piece with correct bitpos and bitsize already exist,
8372 just update the location for it and return. */
8373 *decl_piece_varloc_ptr (*dest) = loc_note;
8374 return;
8376 /* Add the piece that changed. */
8377 *dest = decl_piece_node (loc_note, bitsize, copy ? NULL_RTX : *dest);
8378 dest = &XEXP (*dest, 1);
8379 /* Skip over pieces that overlap it. */
8380 diff = bitpos - piece_bitpos + bitsize;
8381 if (!copy)
8382 src = dest;
8383 while (diff > 0 && *src)
8385 rtx piece = *src;
8386 diff -= decl_piece_bitsize (piece);
8387 if (copy)
8388 src = &XEXP (piece, 1);
8389 else
8391 *src = XEXP (piece, 1);
8392 free_EXPR_LIST_node (piece);
8395 /* Add padding if needed. */
8396 if (diff < 0 && *src)
8398 if (!copy)
8399 dest = src;
8400 *dest = decl_piece_node (NULL_RTX, -diff, copy ? NULL_RTX : *dest);
8401 dest = &XEXP (*dest, 1);
8403 if (!copy)
8404 return;
8405 /* Finally copy all nodes following it. */
8406 while (*src)
8408 *dest = decl_piece_node (*decl_piece_varloc_ptr (*src),
8409 decl_piece_bitsize (*src), NULL_RTX);
8410 dest = &XEXP (*dest, 1);
8411 src = &XEXP (*src, 1);
8415 /* Add a variable location node to the linked list for DECL. */
8417 static struct var_loc_node *
8418 add_var_loc_to_decl (tree decl, rtx loc_note, const char *label)
8420 unsigned int decl_id;
8421 var_loc_list *temp;
8422 void **slot;
8423 struct var_loc_node *loc = NULL;
8424 HOST_WIDE_INT bitsize = -1, bitpos = -1;
8426 if (DECL_DEBUG_EXPR_IS_FROM (decl))
8428 tree realdecl = DECL_DEBUG_EXPR (decl);
8429 if (realdecl && handled_component_p (realdecl))
8431 HOST_WIDE_INT maxsize;
8432 tree innerdecl;
8433 innerdecl
8434 = get_ref_base_and_extent (realdecl, &bitpos, &bitsize, &maxsize);
8435 if (!DECL_P (innerdecl)
8436 || DECL_IGNORED_P (innerdecl)
8437 || TREE_STATIC (innerdecl)
8438 || bitsize <= 0
8439 || bitpos + bitsize > 256
8440 || bitsize != maxsize)
8441 return NULL;
8442 decl = innerdecl;
8446 decl_id = DECL_UID (decl);
8447 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
8448 if (*slot == NULL)
8450 temp = ggc_alloc_cleared_var_loc_list ();
8451 temp->decl_id = decl_id;
8452 *slot = temp;
8454 else
8455 temp = (var_loc_list *) *slot;
8457 if (temp->last)
8459 struct var_loc_node *last = temp->last, *unused = NULL;
8460 rtx *piece_loc = NULL, last_loc_note;
8461 int piece_bitpos = 0;
8462 if (last->next)
8464 last = last->next;
8465 gcc_assert (last->next == NULL);
8467 if (bitsize != -1 && GET_CODE (last->loc) == EXPR_LIST)
8469 piece_loc = &last->loc;
8472 int cur_bitsize = decl_piece_bitsize (*piece_loc);
8473 if (piece_bitpos + cur_bitsize > bitpos)
8474 break;
8475 piece_bitpos += cur_bitsize;
8476 piece_loc = &XEXP (*piece_loc, 1);
8478 while (*piece_loc);
8480 /* TEMP->LAST here is either pointer to the last but one or
8481 last element in the chained list, LAST is pointer to the
8482 last element. */
8483 if (label && strcmp (last->label, label) == 0)
8485 /* For SRA optimized variables if there weren't any real
8486 insns since last note, just modify the last node. */
8487 if (piece_loc != NULL)
8489 adjust_piece_list (piece_loc, NULL, NULL,
8490 bitpos, piece_bitpos, bitsize, loc_note);
8491 return NULL;
8493 /* If the last note doesn't cover any instructions, remove it. */
8494 if (temp->last != last)
8496 temp->last->next = NULL;
8497 unused = last;
8498 last = temp->last;
8499 gcc_assert (strcmp (last->label, label) != 0);
8501 else
8503 gcc_assert (temp->first == temp->last);
8504 memset (temp->last, '\0', sizeof (*temp->last));
8505 temp->last->loc = construct_piece_list (loc_note, bitpos, bitsize);
8506 return temp->last;
8509 if (bitsize == -1 && NOTE_P (last->loc))
8510 last_loc_note = last->loc;
8511 else if (piece_loc != NULL
8512 && *piece_loc != NULL_RTX
8513 && piece_bitpos == bitpos
8514 && decl_piece_bitsize (*piece_loc) == bitsize)
8515 last_loc_note = *decl_piece_varloc_ptr (*piece_loc);
8516 else
8517 last_loc_note = NULL_RTX;
8518 /* If the current location is the same as the end of the list,
8519 and either both or neither of the locations is uninitialized,
8520 we have nothing to do. */
8521 if (last_loc_note == NULL_RTX
8522 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note),
8523 NOTE_VAR_LOCATION_LOC (loc_note)))
8524 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8525 != NOTE_VAR_LOCATION_STATUS (loc_note))
8526 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note)
8527 == VAR_INIT_STATUS_UNINITIALIZED)
8528 || (NOTE_VAR_LOCATION_STATUS (loc_note)
8529 == VAR_INIT_STATUS_UNINITIALIZED))))
8531 /* Add LOC to the end of list and update LAST. If the last
8532 element of the list has been removed above, reuse its
8533 memory for the new node, otherwise allocate a new one. */
8534 if (unused)
8536 loc = unused;
8537 memset (loc, '\0', sizeof (*loc));
8539 else
8540 loc = ggc_alloc_cleared_var_loc_node ();
8541 if (bitsize == -1 || piece_loc == NULL)
8542 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8543 else
8544 adjust_piece_list (&loc->loc, &last->loc, piece_loc,
8545 bitpos, piece_bitpos, bitsize, loc_note);
8546 last->next = loc;
8547 /* Ensure TEMP->LAST will point either to the new last but one
8548 element of the chain, or to the last element in it. */
8549 if (last != temp->last)
8550 temp->last = last;
8552 else if (unused)
8553 ggc_free (unused);
8555 else
8557 loc = ggc_alloc_cleared_var_loc_node ();
8558 temp->first = loc;
8559 temp->last = loc;
8560 loc->loc = construct_piece_list (loc_note, bitpos, bitsize);
8562 return loc;
8565 /* Keep track of the number of spaces used to indent the
8566 output of the debugging routines that print the structure of
8567 the DIE internal representation. */
8568 static int print_indent;
8570 /* Indent the line the number of spaces given by print_indent. */
8572 static inline void
8573 print_spaces (FILE *outfile)
8575 fprintf (outfile, "%*s", print_indent, "");
8578 /* Print a type signature in hex. */
8580 static inline void
8581 print_signature (FILE *outfile, char *sig)
8583 int i;
8585 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
8586 fprintf (outfile, "%02x", sig[i] & 0xff);
8589 /* Print the information associated with a given DIE, and its children.
8590 This routine is a debugging aid only. */
8592 static void
8593 print_die (dw_die_ref die, FILE *outfile)
8595 dw_attr_ref a;
8596 dw_die_ref c;
8597 unsigned ix;
8599 print_spaces (outfile);
8600 fprintf (outfile, "DIE %4ld: %s (%p)\n",
8601 die->die_offset, dwarf_tag_name (die->die_tag),
8602 (void*) die);
8603 print_spaces (outfile);
8604 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
8605 fprintf (outfile, " offset: %ld", die->die_offset);
8606 fprintf (outfile, " mark: %d\n", die->die_mark);
8608 if (use_debug_types && die->die_id.die_type_node)
8610 print_spaces (outfile);
8611 fprintf (outfile, " signature: ");
8612 print_signature (outfile, die->die_id.die_type_node->signature);
8613 fprintf (outfile, "\n");
8616 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8618 print_spaces (outfile);
8619 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
8621 switch (AT_class (a))
8623 case dw_val_class_addr:
8624 fprintf (outfile, "address");
8625 break;
8626 case dw_val_class_offset:
8627 fprintf (outfile, "offset");
8628 break;
8629 case dw_val_class_loc:
8630 fprintf (outfile, "location descriptor");
8631 break;
8632 case dw_val_class_loc_list:
8633 fprintf (outfile, "location list -> label:%s",
8634 AT_loc_list (a)->ll_symbol);
8635 break;
8636 case dw_val_class_range_list:
8637 fprintf (outfile, "range list");
8638 break;
8639 case dw_val_class_const:
8640 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
8641 break;
8642 case dw_val_class_unsigned_const:
8643 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
8644 break;
8645 case dw_val_class_const_double:
8646 fprintf (outfile, "constant ("HOST_WIDE_INT_PRINT_DEC","\
8647 HOST_WIDE_INT_PRINT_UNSIGNED")",
8648 a->dw_attr_val.v.val_double.high,
8649 a->dw_attr_val.v.val_double.low);
8650 break;
8651 case dw_val_class_vec:
8652 fprintf (outfile, "floating-point or vector constant");
8653 break;
8654 case dw_val_class_flag:
8655 fprintf (outfile, "%u", AT_flag (a));
8656 break;
8657 case dw_val_class_die_ref:
8658 if (AT_ref (a) != NULL)
8660 if (use_debug_types && AT_ref (a)->die_id.die_type_node)
8662 fprintf (outfile, "die -> signature: ");
8663 print_signature (outfile,
8664 AT_ref (a)->die_id.die_type_node->signature);
8666 else if (! use_debug_types && AT_ref (a)->die_id.die_symbol)
8667 fprintf (outfile, "die -> label: %s",
8668 AT_ref (a)->die_id.die_symbol);
8669 else
8670 fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
8671 fprintf (outfile, " (%p)", (void *) AT_ref (a));
8673 else
8674 fprintf (outfile, "die -> <null>");
8675 break;
8676 case dw_val_class_vms_delta:
8677 fprintf (outfile, "delta: @slotcount(%s-%s)",
8678 AT_vms_delta2 (a), AT_vms_delta1 (a));
8679 break;
8680 case dw_val_class_lbl_id:
8681 case dw_val_class_lineptr:
8682 case dw_val_class_macptr:
8683 fprintf (outfile, "label: %s", AT_lbl (a));
8684 break;
8685 case dw_val_class_str:
8686 if (AT_string (a) != NULL)
8687 fprintf (outfile, "\"%s\"", AT_string (a));
8688 else
8689 fprintf (outfile, "<null>");
8690 break;
8691 case dw_val_class_file:
8692 fprintf (outfile, "\"%s\" (%d)", AT_file (a)->filename,
8693 AT_file (a)->emitted_number);
8694 break;
8695 case dw_val_class_data8:
8697 int i;
8699 for (i = 0; i < 8; i++)
8700 fprintf (outfile, "%02x", a->dw_attr_val.v.val_data8[i]);
8701 break;
8703 default:
8704 break;
8707 fprintf (outfile, "\n");
8710 if (die->die_child != NULL)
8712 print_indent += 4;
8713 FOR_EACH_CHILD (die, c, print_die (c, outfile));
8714 print_indent -= 4;
8716 if (print_indent == 0)
8717 fprintf (outfile, "\n");
8720 /* Print the information collected for a given DIE. */
8722 DEBUG_FUNCTION void
8723 debug_dwarf_die (dw_die_ref die)
8725 print_die (die, stderr);
8728 /* Print all DWARF information collected for the compilation unit.
8729 This routine is a debugging aid only. */
8731 DEBUG_FUNCTION void
8732 debug_dwarf (void)
8734 print_indent = 0;
8735 print_die (comp_unit_die (), stderr);
8738 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
8739 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
8740 DIE that marks the start of the DIEs for this include file. */
8742 static dw_die_ref
8743 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
8745 const char *filename = get_AT_string (bincl_die, DW_AT_name);
8746 dw_die_ref new_unit = gen_compile_unit_die (filename);
8748 new_unit->die_sib = old_unit;
8749 return new_unit;
8752 /* Close an include-file CU and reopen the enclosing one. */
8754 static dw_die_ref
8755 pop_compile_unit (dw_die_ref old_unit)
8757 dw_die_ref new_unit = old_unit->die_sib;
8759 old_unit->die_sib = NULL;
8760 return new_unit;
8763 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8764 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
8766 /* Calculate the checksum of a location expression. */
8768 static inline void
8769 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8771 int tem;
8773 tem = (loc->dtprel << 8) | ((unsigned int) loc->dw_loc_opc);
8774 CHECKSUM (tem);
8775 CHECKSUM (loc->dw_loc_oprnd1);
8776 CHECKSUM (loc->dw_loc_oprnd2);
8779 /* Calculate the checksum of an attribute. */
8781 static void
8782 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
8784 dw_loc_descr_ref loc;
8785 rtx r;
8787 CHECKSUM (at->dw_attr);
8789 /* We don't care that this was compiled with a different compiler
8790 snapshot; if the output is the same, that's what matters. */
8791 if (at->dw_attr == DW_AT_producer)
8792 return;
8794 switch (AT_class (at))
8796 case dw_val_class_const:
8797 CHECKSUM (at->dw_attr_val.v.val_int);
8798 break;
8799 case dw_val_class_unsigned_const:
8800 CHECKSUM (at->dw_attr_val.v.val_unsigned);
8801 break;
8802 case dw_val_class_const_double:
8803 CHECKSUM (at->dw_attr_val.v.val_double);
8804 break;
8805 case dw_val_class_vec:
8806 CHECKSUM (at->dw_attr_val.v.val_vec);
8807 break;
8808 case dw_val_class_flag:
8809 CHECKSUM (at->dw_attr_val.v.val_flag);
8810 break;
8811 case dw_val_class_str:
8812 CHECKSUM_STRING (AT_string (at));
8813 break;
8815 case dw_val_class_addr:
8816 r = AT_addr (at);
8817 gcc_assert (GET_CODE (r) == SYMBOL_REF);
8818 CHECKSUM_STRING (XSTR (r, 0));
8819 break;
8821 case dw_val_class_offset:
8822 CHECKSUM (at->dw_attr_val.v.val_offset);
8823 break;
8825 case dw_val_class_loc:
8826 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
8827 loc_checksum (loc, ctx);
8828 break;
8830 case dw_val_class_die_ref:
8831 die_checksum (AT_ref (at), ctx, mark);
8832 break;
8834 case dw_val_class_fde_ref:
8835 case dw_val_class_vms_delta:
8836 case dw_val_class_lbl_id:
8837 case dw_val_class_lineptr:
8838 case dw_val_class_macptr:
8839 break;
8841 case dw_val_class_file:
8842 CHECKSUM_STRING (AT_file (at)->filename);
8843 break;
8845 case dw_val_class_data8:
8846 CHECKSUM (at->dw_attr_val.v.val_data8);
8847 break;
8849 default:
8850 break;
8854 /* Calculate the checksum of a DIE. */
8856 static void
8857 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
8859 dw_die_ref c;
8860 dw_attr_ref a;
8861 unsigned ix;
8863 /* To avoid infinite recursion. */
8864 if (die->die_mark)
8866 CHECKSUM (die->die_mark);
8867 return;
8869 die->die_mark = ++(*mark);
8871 CHECKSUM (die->die_tag);
8873 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
8874 attr_checksum (a, ctx, mark);
8876 FOR_EACH_CHILD (die, c, die_checksum (c, ctx, mark));
8879 #undef CHECKSUM
8880 #undef CHECKSUM_STRING
8882 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
8883 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
8884 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
8885 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
8886 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
8887 #define CHECKSUM_ATTR(FOO) \
8888 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
8890 /* Calculate the checksum of a number in signed LEB128 format. */
8892 static void
8893 checksum_sleb128 (HOST_WIDE_INT value, struct md5_ctx *ctx)
8895 unsigned char byte;
8896 bool more;
8898 while (1)
8900 byte = (value & 0x7f);
8901 value >>= 7;
8902 more = !((value == 0 && (byte & 0x40) == 0)
8903 || (value == -1 && (byte & 0x40) != 0));
8904 if (more)
8905 byte |= 0x80;
8906 CHECKSUM (byte);
8907 if (!more)
8908 break;
8912 /* Calculate the checksum of a number in unsigned LEB128 format. */
8914 static void
8915 checksum_uleb128 (unsigned HOST_WIDE_INT value, struct md5_ctx *ctx)
8917 while (1)
8919 unsigned char byte = (value & 0x7f);
8920 value >>= 7;
8921 if (value != 0)
8922 /* More bytes to follow. */
8923 byte |= 0x80;
8924 CHECKSUM (byte);
8925 if (value == 0)
8926 break;
8930 /* Checksum the context of the DIE. This adds the names of any
8931 surrounding namespaces or structures to the checksum. */
8933 static void
8934 checksum_die_context (dw_die_ref die, struct md5_ctx *ctx)
8936 const char *name;
8937 dw_die_ref spec;
8938 int tag = die->die_tag;
8940 if (tag != DW_TAG_namespace
8941 && tag != DW_TAG_structure_type
8942 && tag != DW_TAG_class_type)
8943 return;
8945 name = get_AT_string (die, DW_AT_name);
8947 spec = get_AT_ref (die, DW_AT_specification);
8948 if (spec != NULL)
8949 die = spec;
8951 if (die->die_parent != NULL)
8952 checksum_die_context (die->die_parent, ctx);
8954 CHECKSUM_ULEB128 ('C');
8955 CHECKSUM_ULEB128 (tag);
8956 if (name != NULL)
8957 CHECKSUM_STRING (name);
8960 /* Calculate the checksum of a location expression. */
8962 static inline void
8963 loc_checksum_ordered (dw_loc_descr_ref loc, struct md5_ctx *ctx)
8965 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
8966 were emitted as a DW_FORM_sdata instead of a location expression. */
8967 if (loc->dw_loc_opc == DW_OP_plus_uconst && loc->dw_loc_next == NULL)
8969 CHECKSUM_ULEB128 (DW_FORM_sdata);
8970 CHECKSUM_SLEB128 ((HOST_WIDE_INT) loc->dw_loc_oprnd1.v.val_unsigned);
8971 return;
8974 /* Otherwise, just checksum the raw location expression. */
8975 while (loc != NULL)
8977 CHECKSUM_ULEB128 (loc->dw_loc_opc);
8978 CHECKSUM (loc->dw_loc_oprnd1);
8979 CHECKSUM (loc->dw_loc_oprnd2);
8980 loc = loc->dw_loc_next;
8984 /* Calculate the checksum of an attribute. */
8986 static void
8987 attr_checksum_ordered (enum dwarf_tag tag, dw_attr_ref at,
8988 struct md5_ctx *ctx, int *mark)
8990 dw_loc_descr_ref loc;
8991 rtx r;
8993 if (AT_class (at) == dw_val_class_die_ref)
8995 dw_die_ref target_die = AT_ref (at);
8997 /* For pointer and reference types, we checksum only the (qualified)
8998 name of the target type (if there is a name). For friend entries,
8999 we checksum only the (qualified) name of the target type or function.
9000 This allows the checksum to remain the same whether the target type
9001 is complete or not. */
9002 if ((at->dw_attr == DW_AT_type
9003 && (tag == DW_TAG_pointer_type
9004 || tag == DW_TAG_reference_type
9005 || tag == DW_TAG_rvalue_reference_type
9006 || tag == DW_TAG_ptr_to_member_type))
9007 || (at->dw_attr == DW_AT_friend
9008 && tag == DW_TAG_friend))
9010 dw_attr_ref name_attr = get_AT (target_die, DW_AT_name);
9012 if (name_attr != NULL)
9014 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9016 if (decl == NULL)
9017 decl = target_die;
9018 CHECKSUM_ULEB128 ('N');
9019 CHECKSUM_ULEB128 (at->dw_attr);
9020 if (decl->die_parent != NULL)
9021 checksum_die_context (decl->die_parent, ctx);
9022 CHECKSUM_ULEB128 ('E');
9023 CHECKSUM_STRING (AT_string (name_attr));
9024 return;
9028 /* For all other references to another DIE, we check to see if the
9029 target DIE has already been visited. If it has, we emit a
9030 backward reference; if not, we descend recursively. */
9031 if (target_die->die_mark > 0)
9033 CHECKSUM_ULEB128 ('R');
9034 CHECKSUM_ULEB128 (at->dw_attr);
9035 CHECKSUM_ULEB128 (target_die->die_mark);
9037 else
9039 dw_die_ref decl = get_AT_ref (target_die, DW_AT_specification);
9041 if (decl == NULL)
9042 decl = target_die;
9043 target_die->die_mark = ++(*mark);
9044 CHECKSUM_ULEB128 ('T');
9045 CHECKSUM_ULEB128 (at->dw_attr);
9046 if (decl->die_parent != NULL)
9047 checksum_die_context (decl->die_parent, ctx);
9048 die_checksum_ordered (target_die, ctx, mark);
9050 return;
9053 CHECKSUM_ULEB128 ('A');
9054 CHECKSUM_ULEB128 (at->dw_attr);
9056 switch (AT_class (at))
9058 case dw_val_class_const:
9059 CHECKSUM_ULEB128 (DW_FORM_sdata);
9060 CHECKSUM_SLEB128 (at->dw_attr_val.v.val_int);
9061 break;
9063 case dw_val_class_unsigned_const:
9064 CHECKSUM_ULEB128 (DW_FORM_sdata);
9065 CHECKSUM_SLEB128 ((int) at->dw_attr_val.v.val_unsigned);
9066 break;
9068 case dw_val_class_const_double:
9069 CHECKSUM_ULEB128 (DW_FORM_block);
9070 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_double));
9071 CHECKSUM (at->dw_attr_val.v.val_double);
9072 break;
9074 case dw_val_class_vec:
9075 CHECKSUM_ULEB128 (DW_FORM_block);
9076 CHECKSUM_ULEB128 (sizeof (at->dw_attr_val.v.val_vec));
9077 CHECKSUM (at->dw_attr_val.v.val_vec);
9078 break;
9080 case dw_val_class_flag:
9081 CHECKSUM_ULEB128 (DW_FORM_flag);
9082 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_flag ? 1 : 0);
9083 break;
9085 case dw_val_class_str:
9086 CHECKSUM_ULEB128 (DW_FORM_string);
9087 CHECKSUM_STRING (AT_string (at));
9088 break;
9090 case dw_val_class_addr:
9091 r = AT_addr (at);
9092 gcc_assert (GET_CODE (r) == SYMBOL_REF);
9093 CHECKSUM_ULEB128 (DW_FORM_string);
9094 CHECKSUM_STRING (XSTR (r, 0));
9095 break;
9097 case dw_val_class_offset:
9098 CHECKSUM_ULEB128 (DW_FORM_sdata);
9099 CHECKSUM_ULEB128 (at->dw_attr_val.v.val_offset);
9100 break;
9102 case dw_val_class_loc:
9103 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
9104 loc_checksum_ordered (loc, ctx);
9105 break;
9107 case dw_val_class_fde_ref:
9108 case dw_val_class_lbl_id:
9109 case dw_val_class_lineptr:
9110 case dw_val_class_macptr:
9111 break;
9113 case dw_val_class_file:
9114 CHECKSUM_ULEB128 (DW_FORM_string);
9115 CHECKSUM_STRING (AT_file (at)->filename);
9116 break;
9118 case dw_val_class_data8:
9119 CHECKSUM (at->dw_attr_val.v.val_data8);
9120 break;
9122 default:
9123 break;
9127 struct checksum_attributes
9129 dw_attr_ref at_name;
9130 dw_attr_ref at_type;
9131 dw_attr_ref at_friend;
9132 dw_attr_ref at_accessibility;
9133 dw_attr_ref at_address_class;
9134 dw_attr_ref at_allocated;
9135 dw_attr_ref at_artificial;
9136 dw_attr_ref at_associated;
9137 dw_attr_ref at_binary_scale;
9138 dw_attr_ref at_bit_offset;
9139 dw_attr_ref at_bit_size;
9140 dw_attr_ref at_bit_stride;
9141 dw_attr_ref at_byte_size;
9142 dw_attr_ref at_byte_stride;
9143 dw_attr_ref at_const_value;
9144 dw_attr_ref at_containing_type;
9145 dw_attr_ref at_count;
9146 dw_attr_ref at_data_location;
9147 dw_attr_ref at_data_member_location;
9148 dw_attr_ref at_decimal_scale;
9149 dw_attr_ref at_decimal_sign;
9150 dw_attr_ref at_default_value;
9151 dw_attr_ref at_digit_count;
9152 dw_attr_ref at_discr;
9153 dw_attr_ref at_discr_list;
9154 dw_attr_ref at_discr_value;
9155 dw_attr_ref at_encoding;
9156 dw_attr_ref at_endianity;
9157 dw_attr_ref at_explicit;
9158 dw_attr_ref at_is_optional;
9159 dw_attr_ref at_location;
9160 dw_attr_ref at_lower_bound;
9161 dw_attr_ref at_mutable;
9162 dw_attr_ref at_ordering;
9163 dw_attr_ref at_picture_string;
9164 dw_attr_ref at_prototyped;
9165 dw_attr_ref at_small;
9166 dw_attr_ref at_segment;
9167 dw_attr_ref at_string_length;
9168 dw_attr_ref at_threads_scaled;
9169 dw_attr_ref at_upper_bound;
9170 dw_attr_ref at_use_location;
9171 dw_attr_ref at_use_UTF8;
9172 dw_attr_ref at_variable_parameter;
9173 dw_attr_ref at_virtuality;
9174 dw_attr_ref at_visibility;
9175 dw_attr_ref at_vtable_elem_location;
9178 /* Collect the attributes that we will want to use for the checksum. */
9180 static void
9181 collect_checksum_attributes (struct checksum_attributes *attrs, dw_die_ref die)
9183 dw_attr_ref a;
9184 unsigned ix;
9186 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9188 switch (a->dw_attr)
9190 case DW_AT_name:
9191 attrs->at_name = a;
9192 break;
9193 case DW_AT_type:
9194 attrs->at_type = a;
9195 break;
9196 case DW_AT_friend:
9197 attrs->at_friend = a;
9198 break;
9199 case DW_AT_accessibility:
9200 attrs->at_accessibility = a;
9201 break;
9202 case DW_AT_address_class:
9203 attrs->at_address_class = a;
9204 break;
9205 case DW_AT_allocated:
9206 attrs->at_allocated = a;
9207 break;
9208 case DW_AT_artificial:
9209 attrs->at_artificial = a;
9210 break;
9211 case DW_AT_associated:
9212 attrs->at_associated = a;
9213 break;
9214 case DW_AT_binary_scale:
9215 attrs->at_binary_scale = a;
9216 break;
9217 case DW_AT_bit_offset:
9218 attrs->at_bit_offset = a;
9219 break;
9220 case DW_AT_bit_size:
9221 attrs->at_bit_size = a;
9222 break;
9223 case DW_AT_bit_stride:
9224 attrs->at_bit_stride = a;
9225 break;
9226 case DW_AT_byte_size:
9227 attrs->at_byte_size = a;
9228 break;
9229 case DW_AT_byte_stride:
9230 attrs->at_byte_stride = a;
9231 break;
9232 case DW_AT_const_value:
9233 attrs->at_const_value = a;
9234 break;
9235 case DW_AT_containing_type:
9236 attrs->at_containing_type = a;
9237 break;
9238 case DW_AT_count:
9239 attrs->at_count = a;
9240 break;
9241 case DW_AT_data_location:
9242 attrs->at_data_location = a;
9243 break;
9244 case DW_AT_data_member_location:
9245 attrs->at_data_member_location = a;
9246 break;
9247 case DW_AT_decimal_scale:
9248 attrs->at_decimal_scale = a;
9249 break;
9250 case DW_AT_decimal_sign:
9251 attrs->at_decimal_sign = a;
9252 break;
9253 case DW_AT_default_value:
9254 attrs->at_default_value = a;
9255 break;
9256 case DW_AT_digit_count:
9257 attrs->at_digit_count = a;
9258 break;
9259 case DW_AT_discr:
9260 attrs->at_discr = a;
9261 break;
9262 case DW_AT_discr_list:
9263 attrs->at_discr_list = a;
9264 break;
9265 case DW_AT_discr_value:
9266 attrs->at_discr_value = a;
9267 break;
9268 case DW_AT_encoding:
9269 attrs->at_encoding = a;
9270 break;
9271 case DW_AT_endianity:
9272 attrs->at_endianity = a;
9273 break;
9274 case DW_AT_explicit:
9275 attrs->at_explicit = a;
9276 break;
9277 case DW_AT_is_optional:
9278 attrs->at_is_optional = a;
9279 break;
9280 case DW_AT_location:
9281 attrs->at_location = a;
9282 break;
9283 case DW_AT_lower_bound:
9284 attrs->at_lower_bound = a;
9285 break;
9286 case DW_AT_mutable:
9287 attrs->at_mutable = a;
9288 break;
9289 case DW_AT_ordering:
9290 attrs->at_ordering = a;
9291 break;
9292 case DW_AT_picture_string:
9293 attrs->at_picture_string = a;
9294 break;
9295 case DW_AT_prototyped:
9296 attrs->at_prototyped = a;
9297 break;
9298 case DW_AT_small:
9299 attrs->at_small = a;
9300 break;
9301 case DW_AT_segment:
9302 attrs->at_segment = a;
9303 break;
9304 case DW_AT_string_length:
9305 attrs->at_string_length = a;
9306 break;
9307 case DW_AT_threads_scaled:
9308 attrs->at_threads_scaled = a;
9309 break;
9310 case DW_AT_upper_bound:
9311 attrs->at_upper_bound = a;
9312 break;
9313 case DW_AT_use_location:
9314 attrs->at_use_location = a;
9315 break;
9316 case DW_AT_use_UTF8:
9317 attrs->at_use_UTF8 = a;
9318 break;
9319 case DW_AT_variable_parameter:
9320 attrs->at_variable_parameter = a;
9321 break;
9322 case DW_AT_virtuality:
9323 attrs->at_virtuality = a;
9324 break;
9325 case DW_AT_visibility:
9326 attrs->at_visibility = a;
9327 break;
9328 case DW_AT_vtable_elem_location:
9329 attrs->at_vtable_elem_location = a;
9330 break;
9331 default:
9332 break;
9337 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
9339 static void
9340 die_checksum_ordered (dw_die_ref die, struct md5_ctx *ctx, int *mark)
9342 dw_die_ref c;
9343 dw_die_ref decl;
9344 struct checksum_attributes attrs;
9346 CHECKSUM_ULEB128 ('D');
9347 CHECKSUM_ULEB128 (die->die_tag);
9349 memset (&attrs, 0, sizeof (attrs));
9351 decl = get_AT_ref (die, DW_AT_specification);
9352 if (decl != NULL)
9353 collect_checksum_attributes (&attrs, decl);
9354 collect_checksum_attributes (&attrs, die);
9356 CHECKSUM_ATTR (attrs.at_name);
9357 CHECKSUM_ATTR (attrs.at_accessibility);
9358 CHECKSUM_ATTR (attrs.at_address_class);
9359 CHECKSUM_ATTR (attrs.at_allocated);
9360 CHECKSUM_ATTR (attrs.at_artificial);
9361 CHECKSUM_ATTR (attrs.at_associated);
9362 CHECKSUM_ATTR (attrs.at_binary_scale);
9363 CHECKSUM_ATTR (attrs.at_bit_offset);
9364 CHECKSUM_ATTR (attrs.at_bit_size);
9365 CHECKSUM_ATTR (attrs.at_bit_stride);
9366 CHECKSUM_ATTR (attrs.at_byte_size);
9367 CHECKSUM_ATTR (attrs.at_byte_stride);
9368 CHECKSUM_ATTR (attrs.at_const_value);
9369 CHECKSUM_ATTR (attrs.at_containing_type);
9370 CHECKSUM_ATTR (attrs.at_count);
9371 CHECKSUM_ATTR (attrs.at_data_location);
9372 CHECKSUM_ATTR (attrs.at_data_member_location);
9373 CHECKSUM_ATTR (attrs.at_decimal_scale);
9374 CHECKSUM_ATTR (attrs.at_decimal_sign);
9375 CHECKSUM_ATTR (attrs.at_default_value);
9376 CHECKSUM_ATTR (attrs.at_digit_count);
9377 CHECKSUM_ATTR (attrs.at_discr);
9378 CHECKSUM_ATTR (attrs.at_discr_list);
9379 CHECKSUM_ATTR (attrs.at_discr_value);
9380 CHECKSUM_ATTR (attrs.at_encoding);
9381 CHECKSUM_ATTR (attrs.at_endianity);
9382 CHECKSUM_ATTR (attrs.at_explicit);
9383 CHECKSUM_ATTR (attrs.at_is_optional);
9384 CHECKSUM_ATTR (attrs.at_location);
9385 CHECKSUM_ATTR (attrs.at_lower_bound);
9386 CHECKSUM_ATTR (attrs.at_mutable);
9387 CHECKSUM_ATTR (attrs.at_ordering);
9388 CHECKSUM_ATTR (attrs.at_picture_string);
9389 CHECKSUM_ATTR (attrs.at_prototyped);
9390 CHECKSUM_ATTR (attrs.at_small);
9391 CHECKSUM_ATTR (attrs.at_segment);
9392 CHECKSUM_ATTR (attrs.at_string_length);
9393 CHECKSUM_ATTR (attrs.at_threads_scaled);
9394 CHECKSUM_ATTR (attrs.at_upper_bound);
9395 CHECKSUM_ATTR (attrs.at_use_location);
9396 CHECKSUM_ATTR (attrs.at_use_UTF8);
9397 CHECKSUM_ATTR (attrs.at_variable_parameter);
9398 CHECKSUM_ATTR (attrs.at_virtuality);
9399 CHECKSUM_ATTR (attrs.at_visibility);
9400 CHECKSUM_ATTR (attrs.at_vtable_elem_location);
9401 CHECKSUM_ATTR (attrs.at_type);
9402 CHECKSUM_ATTR (attrs.at_friend);
9404 /* Checksum the child DIEs, except for nested types and member functions. */
9405 c = die->die_child;
9406 if (c) do {
9407 dw_attr_ref name_attr;
9409 c = c->die_sib;
9410 name_attr = get_AT (c, DW_AT_name);
9411 if ((is_type_die (c) || c->die_tag == DW_TAG_subprogram)
9412 && name_attr != NULL)
9414 CHECKSUM_ULEB128 ('S');
9415 CHECKSUM_ULEB128 (c->die_tag);
9416 CHECKSUM_STRING (AT_string (name_attr));
9418 else
9420 /* Mark this DIE so it gets processed when unmarking. */
9421 if (c->die_mark == 0)
9422 c->die_mark = -1;
9423 die_checksum_ordered (c, ctx, mark);
9425 } while (c != die->die_child);
9427 CHECKSUM_ULEB128 (0);
9430 #undef CHECKSUM
9431 #undef CHECKSUM_STRING
9432 #undef CHECKSUM_ATTR
9433 #undef CHECKSUM_LEB128
9434 #undef CHECKSUM_ULEB128
9436 /* Generate the type signature for DIE. This is computed by generating an
9437 MD5 checksum over the DIE's tag, its relevant attributes, and its
9438 children. Attributes that are references to other DIEs are processed
9439 by recursion, using the MARK field to prevent infinite recursion.
9440 If the DIE is nested inside a namespace or another type, we also
9441 need to include that context in the signature. The lower 64 bits
9442 of the resulting MD5 checksum comprise the signature. */
9444 static void
9445 generate_type_signature (dw_die_ref die, comdat_type_node *type_node)
9447 int mark;
9448 const char *name;
9449 unsigned char checksum[16];
9450 struct md5_ctx ctx;
9451 dw_die_ref decl;
9453 name = get_AT_string (die, DW_AT_name);
9454 decl = get_AT_ref (die, DW_AT_specification);
9456 /* First, compute a signature for just the type name (and its surrounding
9457 context, if any. This is stored in the type unit DIE for link-time
9458 ODR (one-definition rule) checking. */
9460 if (is_cxx() && name != NULL)
9462 md5_init_ctx (&ctx);
9464 /* Checksum the names of surrounding namespaces and structures. */
9465 if (decl != NULL && decl->die_parent != NULL)
9466 checksum_die_context (decl->die_parent, &ctx);
9468 md5_process_bytes (&die->die_tag, sizeof (die->die_tag), &ctx);
9469 md5_process_bytes (name, strlen (name) + 1, &ctx);
9470 md5_finish_ctx (&ctx, checksum);
9472 add_AT_data8 (type_node->root_die, DW_AT_GNU_odr_signature, &checksum[8]);
9475 /* Next, compute the complete type signature. */
9477 md5_init_ctx (&ctx);
9478 mark = 1;
9479 die->die_mark = mark;
9481 /* Checksum the names of surrounding namespaces and structures. */
9482 if (decl != NULL && decl->die_parent != NULL)
9483 checksum_die_context (decl->die_parent, &ctx);
9485 /* Checksum the DIE and its children. */
9486 die_checksum_ordered (die, &ctx, &mark);
9487 unmark_all_dies (die);
9488 md5_finish_ctx (&ctx, checksum);
9490 /* Store the signature in the type node and link the type DIE and the
9491 type node together. */
9492 memcpy (type_node->signature, &checksum[16 - DWARF_TYPE_SIGNATURE_SIZE],
9493 DWARF_TYPE_SIGNATURE_SIZE);
9494 die->die_id.die_type_node = type_node;
9495 type_node->type_die = die;
9497 /* If the DIE is a specification, link its declaration to the type node
9498 as well. */
9499 if (decl != NULL)
9500 decl->die_id.die_type_node = type_node;
9503 /* Do the location expressions look same? */
9504 static inline int
9505 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
9507 return loc1->dw_loc_opc == loc2->dw_loc_opc
9508 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
9509 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
9512 /* Do the values look the same? */
9513 static int
9514 same_dw_val_p (const dw_val_node *v1, const dw_val_node *v2, int *mark)
9516 dw_loc_descr_ref loc1, loc2;
9517 rtx r1, r2;
9519 if (v1->val_class != v2->val_class)
9520 return 0;
9522 switch (v1->val_class)
9524 case dw_val_class_const:
9525 return v1->v.val_int == v2->v.val_int;
9526 case dw_val_class_unsigned_const:
9527 return v1->v.val_unsigned == v2->v.val_unsigned;
9528 case dw_val_class_const_double:
9529 return v1->v.val_double.high == v2->v.val_double.high
9530 && v1->v.val_double.low == v2->v.val_double.low;
9531 case dw_val_class_vec:
9532 if (v1->v.val_vec.length != v2->v.val_vec.length
9533 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
9534 return 0;
9535 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
9536 v1->v.val_vec.length * v1->v.val_vec.elt_size))
9537 return 0;
9538 return 1;
9539 case dw_val_class_flag:
9540 return v1->v.val_flag == v2->v.val_flag;
9541 case dw_val_class_str:
9542 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
9544 case dw_val_class_addr:
9545 r1 = v1->v.val_addr;
9546 r2 = v2->v.val_addr;
9547 if (GET_CODE (r1) != GET_CODE (r2))
9548 return 0;
9549 return !rtx_equal_p (r1, r2);
9551 case dw_val_class_offset:
9552 return v1->v.val_offset == v2->v.val_offset;
9554 case dw_val_class_loc:
9555 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
9556 loc1 && loc2;
9557 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
9558 if (!same_loc_p (loc1, loc2, mark))
9559 return 0;
9560 return !loc1 && !loc2;
9562 case dw_val_class_die_ref:
9563 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
9565 case dw_val_class_fde_ref:
9566 case dw_val_class_vms_delta:
9567 case dw_val_class_lbl_id:
9568 case dw_val_class_lineptr:
9569 case dw_val_class_macptr:
9570 return 1;
9572 case dw_val_class_file:
9573 return v1->v.val_file == v2->v.val_file;
9575 case dw_val_class_data8:
9576 return !memcmp (v1->v.val_data8, v2->v.val_data8, 8);
9578 default:
9579 return 1;
9583 /* Do the attributes look the same? */
9585 static int
9586 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
9588 if (at1->dw_attr != at2->dw_attr)
9589 return 0;
9591 /* We don't care that this was compiled with a different compiler
9592 snapshot; if the output is the same, that's what matters. */
9593 if (at1->dw_attr == DW_AT_producer)
9594 return 1;
9596 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
9599 /* Do the dies look the same? */
9601 static int
9602 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
9604 dw_die_ref c1, c2;
9605 dw_attr_ref a1;
9606 unsigned ix;
9608 /* To avoid infinite recursion. */
9609 if (die1->die_mark)
9610 return die1->die_mark == die2->die_mark;
9611 die1->die_mark = die2->die_mark = ++(*mark);
9613 if (die1->die_tag != die2->die_tag)
9614 return 0;
9616 if (VEC_length (dw_attr_node, die1->die_attr)
9617 != VEC_length (dw_attr_node, die2->die_attr))
9618 return 0;
9620 FOR_EACH_VEC_ELT (dw_attr_node, die1->die_attr, ix, a1)
9621 if (!same_attr_p (a1, VEC_index (dw_attr_node, die2->die_attr, ix), mark))
9622 return 0;
9624 c1 = die1->die_child;
9625 c2 = die2->die_child;
9626 if (! c1)
9628 if (c2)
9629 return 0;
9631 else
9632 for (;;)
9634 if (!same_die_p (c1, c2, mark))
9635 return 0;
9636 c1 = c1->die_sib;
9637 c2 = c2->die_sib;
9638 if (c1 == die1->die_child)
9640 if (c2 == die2->die_child)
9641 break;
9642 else
9643 return 0;
9647 return 1;
9650 /* Do the dies look the same? Wrapper around same_die_p. */
9652 static int
9653 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
9655 int mark = 0;
9656 int ret = same_die_p (die1, die2, &mark);
9658 unmark_all_dies (die1);
9659 unmark_all_dies (die2);
9661 return ret;
9664 /* The prefix to attach to symbols on DIEs in the current comdat debug
9665 info section. */
9666 static char *comdat_symbol_id;
9668 /* The index of the current symbol within the current comdat CU. */
9669 static unsigned int comdat_symbol_number;
9671 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
9672 children, and set comdat_symbol_id accordingly. */
9674 static void
9675 compute_section_prefix (dw_die_ref unit_die)
9677 const char *die_name = get_AT_string (unit_die, DW_AT_name);
9678 const char *base = die_name ? lbasename (die_name) : "anonymous";
9679 char *name = XALLOCAVEC (char, strlen (base) + 64);
9680 char *p;
9681 int i, mark;
9682 unsigned char checksum[16];
9683 struct md5_ctx ctx;
9685 /* Compute the checksum of the DIE, then append part of it as hex digits to
9686 the name filename of the unit. */
9688 md5_init_ctx (&ctx);
9689 mark = 0;
9690 die_checksum (unit_die, &ctx, &mark);
9691 unmark_all_dies (unit_die);
9692 md5_finish_ctx (&ctx, checksum);
9694 sprintf (name, "%s.", base);
9695 clean_symbol_name (name);
9697 p = name + strlen (name);
9698 for (i = 0; i < 4; i++)
9700 sprintf (p, "%.2x", checksum[i]);
9701 p += 2;
9704 comdat_symbol_id = unit_die->die_id.die_symbol = xstrdup (name);
9705 comdat_symbol_number = 0;
9708 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
9710 static int
9711 is_type_die (dw_die_ref die)
9713 switch (die->die_tag)
9715 case DW_TAG_array_type:
9716 case DW_TAG_class_type:
9717 case DW_TAG_interface_type:
9718 case DW_TAG_enumeration_type:
9719 case DW_TAG_pointer_type:
9720 case DW_TAG_reference_type:
9721 case DW_TAG_rvalue_reference_type:
9722 case DW_TAG_string_type:
9723 case DW_TAG_structure_type:
9724 case DW_TAG_subroutine_type:
9725 case DW_TAG_union_type:
9726 case DW_TAG_ptr_to_member_type:
9727 case DW_TAG_set_type:
9728 case DW_TAG_subrange_type:
9729 case DW_TAG_base_type:
9730 case DW_TAG_const_type:
9731 case DW_TAG_file_type:
9732 case DW_TAG_packed_type:
9733 case DW_TAG_volatile_type:
9734 case DW_TAG_typedef:
9735 return 1;
9736 default:
9737 return 0;
9741 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
9742 Basically, we want to choose the bits that are likely to be shared between
9743 compilations (types) and leave out the bits that are specific to individual
9744 compilations (functions). */
9746 static int
9747 is_comdat_die (dw_die_ref c)
9749 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
9750 we do for stabs. The advantage is a greater likelihood of sharing between
9751 objects that don't include headers in the same order (and therefore would
9752 put the base types in a different comdat). jason 8/28/00 */
9754 if (c->die_tag == DW_TAG_base_type)
9755 return 0;
9757 if (c->die_tag == DW_TAG_pointer_type
9758 || c->die_tag == DW_TAG_reference_type
9759 || c->die_tag == DW_TAG_rvalue_reference_type
9760 || c->die_tag == DW_TAG_const_type
9761 || c->die_tag == DW_TAG_volatile_type)
9763 dw_die_ref t = get_AT_ref (c, DW_AT_type);
9765 return t ? is_comdat_die (t) : 0;
9768 return is_type_die (c);
9771 /* Returns 1 iff C is the sort of DIE that might be referred to from another
9772 compilation unit. */
9774 static int
9775 is_symbol_die (dw_die_ref c)
9777 return (is_type_die (c)
9778 || is_declaration_die (c)
9779 || c->die_tag == DW_TAG_namespace
9780 || c->die_tag == DW_TAG_module);
9783 /* Returns true iff C is a compile-unit DIE. */
9785 static inline bool
9786 is_cu_die (dw_die_ref c)
9788 return c && c->die_tag == DW_TAG_compile_unit;
9791 static char *
9792 gen_internal_sym (const char *prefix)
9794 char buf[256];
9796 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
9797 return xstrdup (buf);
9800 /* Assign symbols to all worthy DIEs under DIE. */
9802 static void
9803 assign_symbol_names (dw_die_ref die)
9805 dw_die_ref c;
9807 if (is_symbol_die (die))
9809 if (comdat_symbol_id)
9811 char *p = XALLOCAVEC (char, strlen (comdat_symbol_id) + 64);
9813 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
9814 comdat_symbol_id, comdat_symbol_number++);
9815 die->die_id.die_symbol = xstrdup (p);
9817 else
9818 die->die_id.die_symbol = gen_internal_sym ("LDIE");
9821 FOR_EACH_CHILD (die, c, assign_symbol_names (c));
9824 struct cu_hash_table_entry
9826 dw_die_ref cu;
9827 unsigned min_comdat_num, max_comdat_num;
9828 struct cu_hash_table_entry *next;
9831 /* Routines to manipulate hash table of CUs. */
9832 static hashval_t
9833 htab_cu_hash (const void *of)
9835 const struct cu_hash_table_entry *const entry =
9836 (const struct cu_hash_table_entry *) of;
9838 return htab_hash_string (entry->cu->die_id.die_symbol);
9841 static int
9842 htab_cu_eq (const void *of1, const void *of2)
9844 const struct cu_hash_table_entry *const entry1 =
9845 (const struct cu_hash_table_entry *) of1;
9846 const struct die_struct *const entry2 = (const struct die_struct *) of2;
9848 return !strcmp (entry1->cu->die_id.die_symbol, entry2->die_id.die_symbol);
9851 static void
9852 htab_cu_del (void *what)
9854 struct cu_hash_table_entry *next,
9855 *entry = (struct cu_hash_table_entry *) what;
9857 while (entry)
9859 next = entry->next;
9860 free (entry);
9861 entry = next;
9865 /* Check whether we have already seen this CU and set up SYM_NUM
9866 accordingly. */
9867 static int
9868 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
9870 struct cu_hash_table_entry dummy;
9871 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
9873 dummy.max_comdat_num = 0;
9875 slot = (struct cu_hash_table_entry **)
9876 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9877 INSERT);
9878 entry = *slot;
9880 for (; entry; last = entry, entry = entry->next)
9882 if (same_die_p_wrap (cu, entry->cu))
9883 break;
9886 if (entry)
9888 *sym_num = entry->min_comdat_num;
9889 return 1;
9892 entry = XCNEW (struct cu_hash_table_entry);
9893 entry->cu = cu;
9894 entry->min_comdat_num = *sym_num = last->max_comdat_num;
9895 entry->next = *slot;
9896 *slot = entry;
9898 return 0;
9901 /* Record SYM_NUM to record of CU in HTABLE. */
9902 static void
9903 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
9905 struct cu_hash_table_entry **slot, *entry;
9907 slot = (struct cu_hash_table_entry **)
9908 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_id.die_symbol),
9909 NO_INSERT);
9910 entry = *slot;
9912 entry->max_comdat_num = sym_num;
9915 /* Traverse the DIE (which is always comp_unit_die), and set up
9916 additional compilation units for each of the include files we see
9917 bracketed by BINCL/EINCL. */
9919 static void
9920 break_out_includes (dw_die_ref die)
9922 dw_die_ref c;
9923 dw_die_ref unit = NULL;
9924 limbo_die_node *node, **pnode;
9925 htab_t cu_hash_table;
9927 c = die->die_child;
9928 if (c) do {
9929 dw_die_ref prev = c;
9930 c = c->die_sib;
9931 while (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
9932 || (unit && is_comdat_die (c)))
9934 dw_die_ref next = c->die_sib;
9936 /* This DIE is for a secondary CU; remove it from the main one. */
9937 remove_child_with_prev (c, prev);
9939 if (c->die_tag == DW_TAG_GNU_BINCL)
9940 unit = push_new_compile_unit (unit, c);
9941 else if (c->die_tag == DW_TAG_GNU_EINCL)
9942 unit = pop_compile_unit (unit);
9943 else
9944 add_child_die (unit, c);
9945 c = next;
9946 if (c == die->die_child)
9947 break;
9949 } while (c != die->die_child);
9951 #if 0
9952 /* We can only use this in debugging, since the frontend doesn't check
9953 to make sure that we leave every include file we enter. */
9954 gcc_assert (!unit);
9955 #endif
9957 assign_symbol_names (die);
9958 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
9959 for (node = limbo_die_list, pnode = &limbo_die_list;
9960 node;
9961 node = node->next)
9963 int is_dupl;
9965 compute_section_prefix (node->die);
9966 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
9967 &comdat_symbol_number);
9968 assign_symbol_names (node->die);
9969 if (is_dupl)
9970 *pnode = node->next;
9971 else
9973 pnode = &node->next;
9974 record_comdat_symbol_number (node->die, cu_hash_table,
9975 comdat_symbol_number);
9978 htab_delete (cu_hash_table);
9981 /* Return non-zero if this DIE is a declaration. */
9983 static int
9984 is_declaration_die (dw_die_ref die)
9986 dw_attr_ref a;
9987 unsigned ix;
9989 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
9990 if (a->dw_attr == DW_AT_declaration)
9991 return 1;
9993 return 0;
9996 /* Return non-zero if this DIE is nested inside a subprogram. */
9998 static int
9999 is_nested_in_subprogram (dw_die_ref die)
10001 dw_die_ref decl = get_AT_ref (die, DW_AT_specification);
10003 if (decl == NULL)
10004 decl = die;
10005 return local_scope_p (decl);
10008 /* Return non-zero if this is a type DIE that should be moved to a
10009 COMDAT .debug_types section. */
10011 static int
10012 should_move_die_to_comdat (dw_die_ref die)
10014 switch (die->die_tag)
10016 case DW_TAG_class_type:
10017 case DW_TAG_structure_type:
10018 case DW_TAG_enumeration_type:
10019 case DW_TAG_union_type:
10020 /* Don't move declarations, inlined instances, or types nested in a
10021 subprogram. */
10022 if (is_declaration_die (die)
10023 || get_AT (die, DW_AT_abstract_origin)
10024 || is_nested_in_subprogram (die))
10025 return 0;
10026 return 1;
10027 case DW_TAG_array_type:
10028 case DW_TAG_interface_type:
10029 case DW_TAG_pointer_type:
10030 case DW_TAG_reference_type:
10031 case DW_TAG_rvalue_reference_type:
10032 case DW_TAG_string_type:
10033 case DW_TAG_subroutine_type:
10034 case DW_TAG_ptr_to_member_type:
10035 case DW_TAG_set_type:
10036 case DW_TAG_subrange_type:
10037 case DW_TAG_base_type:
10038 case DW_TAG_const_type:
10039 case DW_TAG_file_type:
10040 case DW_TAG_packed_type:
10041 case DW_TAG_volatile_type:
10042 case DW_TAG_typedef:
10043 default:
10044 return 0;
10048 /* Make a clone of DIE. */
10050 static dw_die_ref
10051 clone_die (dw_die_ref die)
10053 dw_die_ref clone;
10054 dw_attr_ref a;
10055 unsigned ix;
10057 clone = ggc_alloc_cleared_die_node ();
10058 clone->die_tag = die->die_tag;
10060 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10061 add_dwarf_attr (clone, a);
10063 return clone;
10066 /* Make a clone of the tree rooted at DIE. */
10068 static dw_die_ref
10069 clone_tree (dw_die_ref die)
10071 dw_die_ref c;
10072 dw_die_ref clone = clone_die (die);
10074 FOR_EACH_CHILD (die, c, add_child_die (clone, clone_tree(c)));
10076 return clone;
10079 /* Make a clone of DIE as a declaration. */
10081 static dw_die_ref
10082 clone_as_declaration (dw_die_ref die)
10084 dw_die_ref clone;
10085 dw_die_ref decl;
10086 dw_attr_ref a;
10087 unsigned ix;
10089 /* If the DIE is already a declaration, just clone it. */
10090 if (is_declaration_die (die))
10091 return clone_die (die);
10093 /* If the DIE is a specification, just clone its declaration DIE. */
10094 decl = get_AT_ref (die, DW_AT_specification);
10095 if (decl != NULL)
10096 return clone_die (decl);
10098 clone = ggc_alloc_cleared_die_node ();
10099 clone->die_tag = die->die_tag;
10101 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10103 /* We don't want to copy over all attributes.
10104 For example we don't want DW_AT_byte_size because otherwise we will no
10105 longer have a declaration and GDB will treat it as a definition. */
10107 switch (a->dw_attr)
10109 case DW_AT_artificial:
10110 case DW_AT_containing_type:
10111 case DW_AT_external:
10112 case DW_AT_name:
10113 case DW_AT_type:
10114 case DW_AT_virtuality:
10115 case DW_AT_linkage_name:
10116 case DW_AT_MIPS_linkage_name:
10117 add_dwarf_attr (clone, a);
10118 break;
10119 case DW_AT_byte_size:
10120 default:
10121 break;
10125 if (die->die_id.die_type_node)
10126 add_AT_die_ref (clone, DW_AT_signature, die);
10128 add_AT_flag (clone, DW_AT_declaration, 1);
10129 return clone;
10132 /* Copy the declaration context to the new compile unit DIE. This includes
10133 any surrounding namespace or type declarations. If the DIE has an
10134 AT_specification attribute, it also includes attributes and children
10135 attached to the specification. */
10137 static void
10138 copy_declaration_context (dw_die_ref unit, dw_die_ref die)
10140 dw_die_ref decl;
10141 dw_die_ref new_decl;
10143 decl = get_AT_ref (die, DW_AT_specification);
10144 if (decl == NULL)
10145 decl = die;
10146 else
10148 unsigned ix;
10149 dw_die_ref c;
10150 dw_attr_ref a;
10152 /* Copy the type node pointer from the new DIE to the original
10153 declaration DIE so we can forward references later. */
10154 decl->die_id.die_type_node = die->die_id.die_type_node;
10156 remove_AT (die, DW_AT_specification);
10158 FOR_EACH_VEC_ELT (dw_attr_node, decl->die_attr, ix, a)
10160 if (a->dw_attr != DW_AT_name
10161 && a->dw_attr != DW_AT_declaration
10162 && a->dw_attr != DW_AT_external)
10163 add_dwarf_attr (die, a);
10166 FOR_EACH_CHILD (decl, c, add_child_die (die, clone_tree(c)));
10169 if (decl->die_parent != NULL
10170 && decl->die_parent->die_tag != DW_TAG_compile_unit
10171 && decl->die_parent->die_tag != DW_TAG_type_unit)
10173 new_decl = copy_ancestor_tree (unit, decl, NULL);
10174 if (new_decl != NULL)
10176 remove_AT (new_decl, DW_AT_signature);
10177 add_AT_specification (die, new_decl);
10182 /* Generate the skeleton ancestor tree for the given NODE, then clone
10183 the DIE and add the clone into the tree. */
10185 static void
10186 generate_skeleton_ancestor_tree (skeleton_chain_node *node)
10188 if (node->new_die != NULL)
10189 return;
10191 node->new_die = clone_as_declaration (node->old_die);
10193 if (node->parent != NULL)
10195 generate_skeleton_ancestor_tree (node->parent);
10196 add_child_die (node->parent->new_die, node->new_die);
10200 /* Generate a skeleton tree of DIEs containing any declarations that are
10201 found in the original tree. We traverse the tree looking for declaration
10202 DIEs, and construct the skeleton from the bottom up whenever we find one. */
10204 static void
10205 generate_skeleton_bottom_up (skeleton_chain_node *parent)
10207 skeleton_chain_node node;
10208 dw_die_ref c;
10209 dw_die_ref first;
10210 dw_die_ref prev = NULL;
10211 dw_die_ref next = NULL;
10213 node.parent = parent;
10215 first = c = parent->old_die->die_child;
10216 if (c)
10217 next = c->die_sib;
10218 if (c) do {
10219 if (prev == NULL || prev->die_sib == c)
10220 prev = c;
10221 c = next;
10222 next = (c == first ? NULL : c->die_sib);
10223 node.old_die = c;
10224 node.new_die = NULL;
10225 if (is_declaration_die (c))
10227 /* Clone the existing DIE, move the original to the skeleton
10228 tree (which is in the main CU), and put the clone, with
10229 all the original's children, where the original came from. */
10230 dw_die_ref clone = clone_die (c);
10231 move_all_children (c, clone);
10233 replace_child (c, clone, prev);
10234 generate_skeleton_ancestor_tree (parent);
10235 add_child_die (parent->new_die, c);
10236 node.new_die = c;
10237 c = clone;
10239 generate_skeleton_bottom_up (&node);
10240 } while (next != NULL);
10243 /* Wrapper function for generate_skeleton_bottom_up. */
10245 static dw_die_ref
10246 generate_skeleton (dw_die_ref die)
10248 skeleton_chain_node node;
10250 node.old_die = die;
10251 node.new_die = NULL;
10252 node.parent = NULL;
10254 /* If this type definition is nested inside another type,
10255 always leave at least a declaration in its place. */
10256 if (die->die_parent != NULL && is_type_die (die->die_parent))
10257 node.new_die = clone_as_declaration (die);
10259 generate_skeleton_bottom_up (&node);
10260 return node.new_die;
10263 /* Remove the DIE from its parent, possibly replacing it with a cloned
10264 declaration. The original DIE will be moved to a new compile unit
10265 so that existing references to it follow it to the new location. If
10266 any of the original DIE's descendants is a declaration, we need to
10267 replace the original DIE with a skeleton tree and move the
10268 declarations back into the skeleton tree. */
10270 static dw_die_ref
10271 remove_child_or_replace_with_skeleton (dw_die_ref child, dw_die_ref prev)
10273 dw_die_ref skeleton;
10275 skeleton = generate_skeleton (child);
10276 if (skeleton == NULL)
10277 remove_child_with_prev (child, prev);
10278 else
10280 skeleton->die_id.die_type_node = child->die_id.die_type_node;
10281 replace_child (child, skeleton, prev);
10284 return skeleton;
10287 /* Traverse the DIE and set up additional .debug_types sections for each
10288 type worthy of being placed in a COMDAT section. */
10290 static void
10291 break_out_comdat_types (dw_die_ref die)
10293 dw_die_ref c;
10294 dw_die_ref first;
10295 dw_die_ref prev = NULL;
10296 dw_die_ref next = NULL;
10297 dw_die_ref unit = NULL;
10299 first = c = die->die_child;
10300 if (c)
10301 next = c->die_sib;
10302 if (c) do {
10303 if (prev == NULL || prev->die_sib == c)
10304 prev = c;
10305 c = next;
10306 next = (c == first ? NULL : c->die_sib);
10307 if (should_move_die_to_comdat (c))
10309 dw_die_ref replacement;
10310 comdat_type_node_ref type_node;
10312 /* Create a new type unit DIE as the root for the new tree, and
10313 add it to the list of comdat types. */
10314 unit = new_die (DW_TAG_type_unit, NULL, NULL);
10315 add_AT_unsigned (unit, DW_AT_language,
10316 get_AT_unsigned (comp_unit_die (), DW_AT_language));
10317 type_node = ggc_alloc_cleared_comdat_type_node ();
10318 type_node->root_die = unit;
10319 type_node->next = comdat_type_list;
10320 comdat_type_list = type_node;
10322 /* Generate the type signature. */
10323 generate_type_signature (c, type_node);
10325 /* Copy the declaration context, attributes, and children of the
10326 declaration into the new compile unit DIE. */
10327 copy_declaration_context (unit, c);
10329 /* Remove this DIE from the main CU. */
10330 replacement = remove_child_or_replace_with_skeleton (c, prev);
10332 /* Break out nested types into their own type units. */
10333 break_out_comdat_types (c);
10335 /* Add the DIE to the new compunit. */
10336 add_child_die (unit, c);
10338 if (replacement != NULL)
10339 c = replacement;
10341 else if (c->die_tag == DW_TAG_namespace
10342 || c->die_tag == DW_TAG_class_type
10343 || c->die_tag == DW_TAG_structure_type
10344 || c->die_tag == DW_TAG_union_type)
10346 /* Look for nested types that can be broken out. */
10347 break_out_comdat_types (c);
10349 } while (next != NULL);
10352 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
10354 struct decl_table_entry
10356 dw_die_ref orig;
10357 dw_die_ref copy;
10360 /* Routines to manipulate hash table of copied declarations. */
10362 static hashval_t
10363 htab_decl_hash (const void *of)
10365 const struct decl_table_entry *const entry =
10366 (const struct decl_table_entry *) of;
10368 return htab_hash_pointer (entry->orig);
10371 static int
10372 htab_decl_eq (const void *of1, const void *of2)
10374 const struct decl_table_entry *const entry1 =
10375 (const struct decl_table_entry *) of1;
10376 const struct die_struct *const entry2 = (const struct die_struct *) of2;
10378 return entry1->orig == entry2;
10381 static void
10382 htab_decl_del (void *what)
10384 struct decl_table_entry *entry = (struct decl_table_entry *) what;
10386 free (entry);
10389 /* Copy DIE and its ancestors, up to, but not including, the compile unit
10390 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
10391 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
10392 to check if the ancestor has already been copied into UNIT. */
10394 static dw_die_ref
10395 copy_ancestor_tree (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10397 dw_die_ref parent = die->die_parent;
10398 dw_die_ref new_parent = unit;
10399 dw_die_ref copy;
10400 void **slot = NULL;
10401 struct decl_table_entry *entry = NULL;
10403 if (decl_table)
10405 /* Check if the entry has already been copied to UNIT. */
10406 slot = htab_find_slot_with_hash (decl_table, die,
10407 htab_hash_pointer (die), INSERT);
10408 if (*slot != HTAB_EMPTY_ENTRY)
10410 entry = (struct decl_table_entry *) *slot;
10411 return entry->copy;
10414 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
10415 entry = XCNEW (struct decl_table_entry);
10416 entry->orig = die;
10417 entry->copy = NULL;
10418 *slot = entry;
10421 if (parent != NULL)
10423 dw_die_ref spec = get_AT_ref (parent, DW_AT_specification);
10424 if (spec != NULL)
10425 parent = spec;
10426 if (parent->die_tag != DW_TAG_compile_unit
10427 && parent->die_tag != DW_TAG_type_unit)
10428 new_parent = copy_ancestor_tree (unit, parent, decl_table);
10431 copy = clone_as_declaration (die);
10432 add_child_die (new_parent, copy);
10434 if (decl_table != NULL)
10436 /* Record the pointer to the copy. */
10437 entry->copy = copy;
10440 return copy;
10443 /* Walk the DIE and its children, looking for references to incomplete
10444 or trivial types that are unmarked (i.e., that are not in the current
10445 type_unit). */
10447 static void
10448 copy_decls_walk (dw_die_ref unit, dw_die_ref die, htab_t decl_table)
10450 dw_die_ref c;
10451 dw_attr_ref a;
10452 unsigned ix;
10454 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10456 if (AT_class (a) == dw_val_class_die_ref)
10458 dw_die_ref targ = AT_ref (a);
10459 comdat_type_node_ref type_node = targ->die_id.die_type_node;
10460 void **slot;
10461 struct decl_table_entry *entry;
10463 if (targ->die_mark != 0 || type_node != NULL)
10464 continue;
10466 slot = htab_find_slot_with_hash (decl_table, targ,
10467 htab_hash_pointer (targ), INSERT);
10469 if (*slot != HTAB_EMPTY_ENTRY)
10471 /* TARG has already been copied, so we just need to
10472 modify the reference to point to the copy. */
10473 entry = (struct decl_table_entry *) *slot;
10474 a->dw_attr_val.v.val_die_ref.die = entry->copy;
10476 else
10478 dw_die_ref parent = unit;
10479 dw_die_ref copy = clone_tree (targ);
10481 /* Make sure the cloned tree is marked as part of the
10482 type unit. */
10483 mark_dies (copy);
10485 /* Record in DECL_TABLE that TARG has been copied.
10486 Need to do this now, before the recursive call,
10487 because DECL_TABLE may be expanded and SLOT
10488 would no longer be a valid pointer. */
10489 entry = XCNEW (struct decl_table_entry);
10490 entry->orig = targ;
10491 entry->copy = copy;
10492 *slot = entry;
10494 /* If TARG has surrounding context, copy its ancestor tree
10495 into the new type unit. */
10496 if (targ->die_parent != NULL
10497 && targ->die_parent->die_tag != DW_TAG_compile_unit
10498 && targ->die_parent->die_tag != DW_TAG_type_unit)
10499 parent = copy_ancestor_tree (unit, targ->die_parent,
10500 decl_table);
10502 add_child_die (parent, copy);
10503 a->dw_attr_val.v.val_die_ref.die = copy;
10505 /* Make sure the newly-copied DIE is walked. If it was
10506 installed in a previously-added context, it won't
10507 get visited otherwise. */
10508 if (parent != unit)
10510 /* Find the highest point of the newly-added tree,
10511 mark each node along the way, and walk from there. */
10512 parent->die_mark = 1;
10513 while (parent->die_parent
10514 && parent->die_parent->die_mark == 0)
10516 parent = parent->die_parent;
10517 parent->die_mark = 1;
10519 copy_decls_walk (unit, parent, decl_table);
10525 FOR_EACH_CHILD (die, c, copy_decls_walk (unit, c, decl_table));
10528 /* Copy declarations for "unworthy" types into the new comdat section.
10529 Incomplete types, modified types, and certain other types aren't broken
10530 out into comdat sections of their own, so they don't have a signature,
10531 and we need to copy the declaration into the same section so that we
10532 don't have an external reference. */
10534 static void
10535 copy_decls_for_unworthy_types (dw_die_ref unit)
10537 htab_t decl_table;
10539 mark_dies (unit);
10540 decl_table = htab_create (10, htab_decl_hash, htab_decl_eq, htab_decl_del);
10541 copy_decls_walk (unit, unit, decl_table);
10542 htab_delete (decl_table);
10543 unmark_dies (unit);
10546 /* Traverse the DIE and add a sibling attribute if it may have the
10547 effect of speeding up access to siblings. To save some space,
10548 avoid generating sibling attributes for DIE's without children. */
10550 static void
10551 add_sibling_attributes (dw_die_ref die)
10553 dw_die_ref c;
10555 if (! die->die_child)
10556 return;
10558 if (die->die_parent && die != die->die_parent->die_child)
10559 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
10561 FOR_EACH_CHILD (die, c, add_sibling_attributes (c));
10564 /* Output all location lists for the DIE and its children. */
10566 static void
10567 output_location_lists (dw_die_ref die)
10569 dw_die_ref c;
10570 dw_attr_ref a;
10571 unsigned ix;
10573 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10574 if (AT_class (a) == dw_val_class_loc_list)
10575 output_loc_list (AT_loc_list (a));
10577 FOR_EACH_CHILD (die, c, output_location_lists (c));
10580 /* The format of each DIE (and its attribute value pairs) is encoded in an
10581 abbreviation table. This routine builds the abbreviation table and assigns
10582 a unique abbreviation id for each abbreviation entry. The children of each
10583 die are visited recursively. */
10585 static void
10586 build_abbrev_table (dw_die_ref die)
10588 unsigned long abbrev_id;
10589 unsigned int n_alloc;
10590 dw_die_ref c;
10591 dw_attr_ref a;
10592 unsigned ix;
10594 /* Scan the DIE references, and mark as external any that refer to
10595 DIEs from other CUs (i.e. those which are not marked). */
10596 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10597 if (AT_class (a) == dw_val_class_die_ref
10598 && AT_ref (a)->die_mark == 0)
10600 gcc_assert (use_debug_types || AT_ref (a)->die_id.die_symbol);
10601 set_AT_ref_external (a, 1);
10604 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
10606 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
10607 dw_attr_ref die_a, abbrev_a;
10608 unsigned ix;
10609 bool ok = true;
10611 if (abbrev->die_tag != die->die_tag)
10612 continue;
10613 if ((abbrev->die_child != NULL) != (die->die_child != NULL))
10614 continue;
10616 if (VEC_length (dw_attr_node, abbrev->die_attr)
10617 != VEC_length (dw_attr_node, die->die_attr))
10618 continue;
10620 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, die_a)
10622 abbrev_a = VEC_index (dw_attr_node, abbrev->die_attr, ix);
10623 if ((abbrev_a->dw_attr != die_a->dw_attr)
10624 || (value_format (abbrev_a) != value_format (die_a)))
10626 ok = false;
10627 break;
10630 if (ok)
10631 break;
10634 if (abbrev_id >= abbrev_die_table_in_use)
10636 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
10638 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
10639 abbrev_die_table = GGC_RESIZEVEC (dw_die_ref, abbrev_die_table,
10640 n_alloc);
10642 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
10643 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
10644 abbrev_die_table_allocated = n_alloc;
10647 ++abbrev_die_table_in_use;
10648 abbrev_die_table[abbrev_id] = die;
10651 die->die_abbrev = abbrev_id;
10652 FOR_EACH_CHILD (die, c, build_abbrev_table (c));
10655 /* Return the power-of-two number of bytes necessary to represent VALUE. */
10657 static int
10658 constant_size (unsigned HOST_WIDE_INT value)
10660 int log;
10662 if (value == 0)
10663 log = 0;
10664 else
10665 log = floor_log2 (value);
10667 log = log / 8;
10668 log = 1 << (floor_log2 (log) + 1);
10670 return log;
10673 /* Return the size of a DIE as it is represented in the
10674 .debug_info section. */
10676 static unsigned long
10677 size_of_die (dw_die_ref die)
10679 unsigned long size = 0;
10680 dw_attr_ref a;
10681 unsigned ix;
10683 size += size_of_uleb128 (die->die_abbrev);
10684 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10686 switch (AT_class (a))
10688 case dw_val_class_addr:
10689 size += DWARF2_ADDR_SIZE;
10690 break;
10691 case dw_val_class_offset:
10692 size += DWARF_OFFSET_SIZE;
10693 break;
10694 case dw_val_class_loc:
10696 unsigned long lsize = size_of_locs (AT_loc (a));
10698 /* Block length. */
10699 if (dwarf_version >= 4)
10700 size += size_of_uleb128 (lsize);
10701 else
10702 size += constant_size (lsize);
10703 size += lsize;
10705 break;
10706 case dw_val_class_loc_list:
10707 size += DWARF_OFFSET_SIZE;
10708 break;
10709 case dw_val_class_range_list:
10710 size += DWARF_OFFSET_SIZE;
10711 break;
10712 case dw_val_class_const:
10713 size += size_of_sleb128 (AT_int (a));
10714 break;
10715 case dw_val_class_unsigned_const:
10716 size += constant_size (AT_unsigned (a));
10717 break;
10718 case dw_val_class_const_double:
10719 size += 2 * HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
10720 if (HOST_BITS_PER_WIDE_INT >= 64)
10721 size++; /* block */
10722 break;
10723 case dw_val_class_vec:
10724 size += constant_size (a->dw_attr_val.v.val_vec.length
10725 * a->dw_attr_val.v.val_vec.elt_size)
10726 + a->dw_attr_val.v.val_vec.length
10727 * a->dw_attr_val.v.val_vec.elt_size; /* block */
10728 break;
10729 case dw_val_class_flag:
10730 if (dwarf_version >= 4)
10731 /* Currently all add_AT_flag calls pass in 1 as last argument,
10732 so DW_FORM_flag_present can be used. If that ever changes,
10733 we'll need to use DW_FORM_flag and have some optimization
10734 in build_abbrev_table that will change those to
10735 DW_FORM_flag_present if it is set to 1 in all DIEs using
10736 the same abbrev entry. */
10737 gcc_assert (a->dw_attr_val.v.val_flag == 1);
10738 else
10739 size += 1;
10740 break;
10741 case dw_val_class_die_ref:
10742 if (AT_ref_external (a))
10744 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
10745 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
10746 is sized by target address length, whereas in DWARF3
10747 it's always sized as an offset. */
10748 if (use_debug_types)
10749 size += DWARF_TYPE_SIGNATURE_SIZE;
10750 else if (dwarf_version == 2)
10751 size += DWARF2_ADDR_SIZE;
10752 else
10753 size += DWARF_OFFSET_SIZE;
10755 else
10756 size += DWARF_OFFSET_SIZE;
10757 break;
10758 case dw_val_class_fde_ref:
10759 size += DWARF_OFFSET_SIZE;
10760 break;
10761 case dw_val_class_lbl_id:
10762 size += DWARF2_ADDR_SIZE;
10763 break;
10764 case dw_val_class_lineptr:
10765 case dw_val_class_macptr:
10766 size += DWARF_OFFSET_SIZE;
10767 break;
10768 case dw_val_class_str:
10769 if (AT_string_form (a) == DW_FORM_strp)
10770 size += DWARF_OFFSET_SIZE;
10771 else
10772 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
10773 break;
10774 case dw_val_class_file:
10775 size += constant_size (maybe_emit_file (a->dw_attr_val.v.val_file));
10776 break;
10777 case dw_val_class_data8:
10778 size += 8;
10779 break;
10780 case dw_val_class_vms_delta:
10781 size += DWARF_OFFSET_SIZE;
10782 break;
10783 default:
10784 gcc_unreachable ();
10788 return size;
10791 /* Size the debugging information associated with a given DIE. Visits the
10792 DIE's children recursively. Updates the global variable next_die_offset, on
10793 each time through. Uses the current value of next_die_offset to update the
10794 die_offset field in each DIE. */
10796 static void
10797 calc_die_sizes (dw_die_ref die)
10799 dw_die_ref c;
10801 die->die_offset = next_die_offset;
10802 next_die_offset += size_of_die (die);
10804 FOR_EACH_CHILD (die, c, calc_die_sizes (c));
10806 if (die->die_child != NULL)
10807 /* Count the null byte used to terminate sibling lists. */
10808 next_die_offset += 1;
10811 /* Set the marks for a die and its children. We do this so
10812 that we know whether or not a reference needs to use FORM_ref_addr; only
10813 DIEs in the same CU will be marked. We used to clear out the offset
10814 and use that as the flag, but ran into ordering problems. */
10816 static void
10817 mark_dies (dw_die_ref die)
10819 dw_die_ref c;
10821 gcc_assert (!die->die_mark);
10823 die->die_mark = 1;
10824 FOR_EACH_CHILD (die, c, mark_dies (c));
10827 /* Clear the marks for a die and its children. */
10829 static void
10830 unmark_dies (dw_die_ref die)
10832 dw_die_ref c;
10834 if (! use_debug_types)
10835 gcc_assert (die->die_mark);
10837 die->die_mark = 0;
10838 FOR_EACH_CHILD (die, c, unmark_dies (c));
10841 /* Clear the marks for a die, its children and referred dies. */
10843 static void
10844 unmark_all_dies (dw_die_ref die)
10846 dw_die_ref c;
10847 dw_attr_ref a;
10848 unsigned ix;
10850 if (!die->die_mark)
10851 return;
10852 die->die_mark = 0;
10854 FOR_EACH_CHILD (die, c, unmark_all_dies (c));
10856 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
10857 if (AT_class (a) == dw_val_class_die_ref)
10858 unmark_all_dies (AT_ref (a));
10861 /* Return the size of the .debug_pubnames or .debug_pubtypes table
10862 generated for the compilation unit. */
10864 static unsigned long
10865 size_of_pubnames (VEC (pubname_entry, gc) * names)
10867 unsigned long size;
10868 unsigned i;
10869 pubname_ref p;
10871 size = DWARF_PUBNAMES_HEADER_SIZE;
10872 FOR_EACH_VEC_ELT (pubname_entry, names, i, p)
10873 if (names != pubtype_table
10874 || p->die->die_offset != 0
10875 || !flag_eliminate_unused_debug_types)
10876 size += strlen (p->name) + DWARF_OFFSET_SIZE + 1;
10878 size += DWARF_OFFSET_SIZE;
10879 return size;
10882 /* Return the size of the information in the .debug_aranges section. */
10884 static unsigned long
10885 size_of_aranges (void)
10887 unsigned long size;
10889 size = DWARF_ARANGES_HEADER_SIZE;
10891 /* Count the address/length pair for this compilation unit. */
10892 if (text_section_used)
10893 size += 2 * DWARF2_ADDR_SIZE;
10894 if (cold_text_section_used)
10895 size += 2 * DWARF2_ADDR_SIZE;
10896 if (have_multiple_function_sections)
10898 unsigned fde_idx = 0;
10900 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
10902 dw_fde_ref fde = &fde_table[fde_idx];
10904 if (!fde->in_std_section)
10905 size += 2 * DWARF2_ADDR_SIZE;
10906 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
10907 size += 2 * DWARF2_ADDR_SIZE;
10911 /* Count the two zero words used to terminated the address range table. */
10912 size += 2 * DWARF2_ADDR_SIZE;
10913 return size;
10916 /* Select the encoding of an attribute value. */
10918 static enum dwarf_form
10919 value_format (dw_attr_ref a)
10921 switch (a->dw_attr_val.val_class)
10923 case dw_val_class_addr:
10924 /* Only very few attributes allow DW_FORM_addr. */
10925 switch (a->dw_attr)
10927 case DW_AT_low_pc:
10928 case DW_AT_high_pc:
10929 case DW_AT_entry_pc:
10930 case DW_AT_trampoline:
10931 return DW_FORM_addr;
10932 default:
10933 break;
10935 switch (DWARF2_ADDR_SIZE)
10937 case 1:
10938 return DW_FORM_data1;
10939 case 2:
10940 return DW_FORM_data2;
10941 case 4:
10942 return DW_FORM_data4;
10943 case 8:
10944 return DW_FORM_data8;
10945 default:
10946 gcc_unreachable ();
10948 case dw_val_class_range_list:
10949 case dw_val_class_loc_list:
10950 if (dwarf_version >= 4)
10951 return DW_FORM_sec_offset;
10952 /* FALLTHRU */
10953 case dw_val_class_vms_delta:
10954 case dw_val_class_offset:
10955 switch (DWARF_OFFSET_SIZE)
10957 case 4:
10958 return DW_FORM_data4;
10959 case 8:
10960 return DW_FORM_data8;
10961 default:
10962 gcc_unreachable ();
10964 case dw_val_class_loc:
10965 if (dwarf_version >= 4)
10966 return DW_FORM_exprloc;
10967 switch (constant_size (size_of_locs (AT_loc (a))))
10969 case 1:
10970 return DW_FORM_block1;
10971 case 2:
10972 return DW_FORM_block2;
10973 default:
10974 gcc_unreachable ();
10976 case dw_val_class_const:
10977 return DW_FORM_sdata;
10978 case dw_val_class_unsigned_const:
10979 switch (constant_size (AT_unsigned (a)))
10981 case 1:
10982 return DW_FORM_data1;
10983 case 2:
10984 return DW_FORM_data2;
10985 case 4:
10986 return DW_FORM_data4;
10987 case 8:
10988 return DW_FORM_data8;
10989 default:
10990 gcc_unreachable ();
10992 case dw_val_class_const_double:
10993 switch (HOST_BITS_PER_WIDE_INT)
10995 case 8:
10996 return DW_FORM_data2;
10997 case 16:
10998 return DW_FORM_data4;
10999 case 32:
11000 return DW_FORM_data8;
11001 case 64:
11002 default:
11003 return DW_FORM_block1;
11005 case dw_val_class_vec:
11006 switch (constant_size (a->dw_attr_val.v.val_vec.length
11007 * a->dw_attr_val.v.val_vec.elt_size))
11009 case 1:
11010 return DW_FORM_block1;
11011 case 2:
11012 return DW_FORM_block2;
11013 case 4:
11014 return DW_FORM_block4;
11015 default:
11016 gcc_unreachable ();
11018 case dw_val_class_flag:
11019 if (dwarf_version >= 4)
11021 /* Currently all add_AT_flag calls pass in 1 as last argument,
11022 so DW_FORM_flag_present can be used. If that ever changes,
11023 we'll need to use DW_FORM_flag and have some optimization
11024 in build_abbrev_table that will change those to
11025 DW_FORM_flag_present if it is set to 1 in all DIEs using
11026 the same abbrev entry. */
11027 gcc_assert (a->dw_attr_val.v.val_flag == 1);
11028 return DW_FORM_flag_present;
11030 return DW_FORM_flag;
11031 case dw_val_class_die_ref:
11032 if (AT_ref_external (a))
11033 return use_debug_types ? DW_FORM_ref_sig8 : DW_FORM_ref_addr;
11034 else
11035 return DW_FORM_ref;
11036 case dw_val_class_fde_ref:
11037 return DW_FORM_data;
11038 case dw_val_class_lbl_id:
11039 return DW_FORM_addr;
11040 case dw_val_class_lineptr:
11041 case dw_val_class_macptr:
11042 return dwarf_version >= 4 ? DW_FORM_sec_offset : DW_FORM_data;
11043 case dw_val_class_str:
11044 return AT_string_form (a);
11045 case dw_val_class_file:
11046 switch (constant_size (maybe_emit_file (a->dw_attr_val.v.val_file)))
11048 case 1:
11049 return DW_FORM_data1;
11050 case 2:
11051 return DW_FORM_data2;
11052 case 4:
11053 return DW_FORM_data4;
11054 default:
11055 gcc_unreachable ();
11058 case dw_val_class_data8:
11059 return DW_FORM_data8;
11061 default:
11062 gcc_unreachable ();
11066 /* Output the encoding of an attribute value. */
11068 static void
11069 output_value_format (dw_attr_ref a)
11071 enum dwarf_form form = value_format (a);
11073 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
11076 /* Output the .debug_abbrev section which defines the DIE abbreviation
11077 table. */
11079 static void
11080 output_abbrev_section (void)
11082 unsigned long abbrev_id;
11084 if (abbrev_die_table_in_use == 1)
11085 return;
11087 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
11089 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
11090 unsigned ix;
11091 dw_attr_ref a_attr;
11093 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
11094 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
11095 dwarf_tag_name (abbrev->die_tag));
11097 if (abbrev->die_child != NULL)
11098 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
11099 else
11100 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
11102 for (ix = 0; VEC_iterate (dw_attr_node, abbrev->die_attr, ix, a_attr);
11103 ix++)
11105 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
11106 dwarf_attr_name (a_attr->dw_attr));
11107 output_value_format (a_attr);
11110 dw2_asm_output_data (1, 0, NULL);
11111 dw2_asm_output_data (1, 0, NULL);
11114 /* Terminate the table. */
11115 dw2_asm_output_data (1, 0, NULL);
11118 /* Output a symbol we can use to refer to this DIE from another CU. */
11120 static inline void
11121 output_die_symbol (dw_die_ref die)
11123 char *sym = die->die_id.die_symbol;
11125 if (sym == 0)
11126 return;
11128 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
11129 /* We make these global, not weak; if the target doesn't support
11130 .linkonce, it doesn't support combining the sections, so debugging
11131 will break. */
11132 targetm.asm_out.globalize_label (asm_out_file, sym);
11134 ASM_OUTPUT_LABEL (asm_out_file, sym);
11137 /* Return a new location list, given the begin and end range, and the
11138 expression. */
11140 static inline dw_loc_list_ref
11141 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
11142 const char *section)
11144 dw_loc_list_ref retlist = ggc_alloc_cleared_dw_loc_list_node ();
11146 retlist->begin = begin;
11147 retlist->end = end;
11148 retlist->expr = expr;
11149 retlist->section = section;
11151 return retlist;
11154 /* Generate a new internal symbol for this location list node, if it
11155 hasn't got one yet. */
11157 static inline void
11158 gen_llsym (dw_loc_list_ref list)
11160 gcc_assert (!list->ll_symbol);
11161 list->ll_symbol = gen_internal_sym ("LLST");
11164 /* Output the location list given to us. */
11166 static void
11167 output_loc_list (dw_loc_list_ref list_head)
11169 dw_loc_list_ref curr = list_head;
11171 if (list_head->emitted)
11172 return;
11173 list_head->emitted = true;
11175 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
11177 /* Walk the location list, and output each range + expression. */
11178 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
11180 unsigned long size;
11181 /* Don't output an entry that starts and ends at the same address. */
11182 if (strcmp (curr->begin, curr->end) == 0)
11183 continue;
11184 if (!have_multiple_function_sections)
11186 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
11187 "Location list begin address (%s)",
11188 list_head->ll_symbol);
11189 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
11190 "Location list end address (%s)",
11191 list_head->ll_symbol);
11193 else
11195 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
11196 "Location list begin address (%s)",
11197 list_head->ll_symbol);
11198 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
11199 "Location list end address (%s)",
11200 list_head->ll_symbol);
11202 size = size_of_locs (curr->expr);
11204 /* Output the block length for this list of location operations. */
11205 gcc_assert (size <= 0xffff);
11206 dw2_asm_output_data (2, size, "%s", "Location expression size");
11208 output_loc_sequence (curr->expr, -1);
11211 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11212 "Location list terminator begin (%s)",
11213 list_head->ll_symbol);
11214 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
11215 "Location list terminator end (%s)",
11216 list_head->ll_symbol);
11219 /* Output a type signature. */
11221 static inline void
11222 output_signature (const char *sig, const char *name)
11224 int i;
11226 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11227 dw2_asm_output_data (1, sig[i], i == 0 ? "%s" : NULL, name);
11230 /* Output the DIE and its attributes. Called recursively to generate
11231 the definitions of each child DIE. */
11233 static void
11234 output_die (dw_die_ref die)
11236 dw_attr_ref a;
11237 dw_die_ref c;
11238 unsigned long size;
11239 unsigned ix;
11241 /* If someone in another CU might refer to us, set up a symbol for
11242 them to point to. */
11243 if (! use_debug_types && die->die_id.die_symbol)
11244 output_die_symbol (die);
11246 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (%#lx) %s)",
11247 (unsigned long)die->die_offset,
11248 dwarf_tag_name (die->die_tag));
11250 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
11252 const char *name = dwarf_attr_name (a->dw_attr);
11254 switch (AT_class (a))
11256 case dw_val_class_addr:
11257 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
11258 break;
11260 case dw_val_class_offset:
11261 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
11262 "%s", name);
11263 break;
11265 case dw_val_class_range_list:
11267 char *p = strchr (ranges_section_label, '\0');
11269 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
11270 a->dw_attr_val.v.val_offset);
11271 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
11272 debug_ranges_section, "%s", name);
11273 *p = '\0';
11275 break;
11277 case dw_val_class_loc:
11278 size = size_of_locs (AT_loc (a));
11280 /* Output the block length for this list of location operations. */
11281 if (dwarf_version >= 4)
11282 dw2_asm_output_data_uleb128 (size, "%s", name);
11283 else
11284 dw2_asm_output_data (constant_size (size), size, "%s", name);
11286 output_loc_sequence (AT_loc (a), -1);
11287 break;
11289 case dw_val_class_const:
11290 /* ??? It would be slightly more efficient to use a scheme like is
11291 used for unsigned constants below, but gdb 4.x does not sign
11292 extend. Gdb 5.x does sign extend. */
11293 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
11294 break;
11296 case dw_val_class_unsigned_const:
11297 dw2_asm_output_data (constant_size (AT_unsigned (a)),
11298 AT_unsigned (a), "%s", name);
11299 break;
11301 case dw_val_class_const_double:
11303 unsigned HOST_WIDE_INT first, second;
11305 if (HOST_BITS_PER_WIDE_INT >= 64)
11306 dw2_asm_output_data (1,
11307 2 * HOST_BITS_PER_WIDE_INT
11308 / HOST_BITS_PER_CHAR,
11309 NULL);
11311 if (WORDS_BIG_ENDIAN)
11313 first = a->dw_attr_val.v.val_double.high;
11314 second = a->dw_attr_val.v.val_double.low;
11316 else
11318 first = a->dw_attr_val.v.val_double.low;
11319 second = a->dw_attr_val.v.val_double.high;
11322 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11323 first, name);
11324 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR,
11325 second, NULL);
11327 break;
11329 case dw_val_class_vec:
11331 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
11332 unsigned int len = a->dw_attr_val.v.val_vec.length;
11333 unsigned int i;
11334 unsigned char *p;
11336 dw2_asm_output_data (constant_size (len * elt_size),
11337 len * elt_size, "%s", name);
11338 if (elt_size > sizeof (HOST_WIDE_INT))
11340 elt_size /= 2;
11341 len *= 2;
11343 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
11344 i < len;
11345 i++, p += elt_size)
11346 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
11347 "fp or vector constant word %u", i);
11348 break;
11351 case dw_val_class_flag:
11352 if (dwarf_version >= 4)
11354 /* Currently all add_AT_flag calls pass in 1 as last argument,
11355 so DW_FORM_flag_present can be used. If that ever changes,
11356 we'll need to use DW_FORM_flag and have some optimization
11357 in build_abbrev_table that will change those to
11358 DW_FORM_flag_present if it is set to 1 in all DIEs using
11359 the same abbrev entry. */
11360 gcc_assert (AT_flag (a) == 1);
11361 if (flag_debug_asm)
11362 fprintf (asm_out_file, "\t\t\t%s %s\n",
11363 ASM_COMMENT_START, name);
11364 break;
11366 dw2_asm_output_data (1, AT_flag (a), "%s", name);
11367 break;
11369 case dw_val_class_loc_list:
11371 char *sym = AT_loc_list (a)->ll_symbol;
11373 gcc_assert (sym);
11374 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, debug_loc_section,
11375 "%s", name);
11377 break;
11379 case dw_val_class_die_ref:
11380 if (AT_ref_external (a))
11382 if (use_debug_types)
11384 comdat_type_node_ref type_node =
11385 AT_ref (a)->die_id.die_type_node;
11387 gcc_assert (type_node);
11388 output_signature (type_node->signature, name);
11390 else
11392 char *sym = AT_ref (a)->die_id.die_symbol;
11393 int size;
11395 gcc_assert (sym);
11396 /* In DWARF2, DW_FORM_ref_addr is sized by target address
11397 length, whereas in DWARF3 it's always sized as an
11398 offset. */
11399 if (dwarf_version == 2)
11400 size = DWARF2_ADDR_SIZE;
11401 else
11402 size = DWARF_OFFSET_SIZE;
11403 dw2_asm_output_offset (size, sym, debug_info_section, "%s",
11404 name);
11407 else
11409 gcc_assert (AT_ref (a)->die_offset);
11410 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
11411 "%s", name);
11413 break;
11415 case dw_val_class_fde_ref:
11417 char l1[20];
11419 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
11420 a->dw_attr_val.v.val_fde_index * 2);
11421 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, debug_frame_section,
11422 "%s", name);
11424 break;
11426 case dw_val_class_vms_delta:
11427 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE,
11428 AT_vms_delta2 (a), AT_vms_delta1 (a),
11429 "%s", name);
11430 break;
11432 case dw_val_class_lbl_id:
11433 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
11434 break;
11436 case dw_val_class_lineptr:
11437 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11438 debug_line_section, "%s", name);
11439 break;
11441 case dw_val_class_macptr:
11442 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a),
11443 debug_macinfo_section, "%s", name);
11444 break;
11446 case dw_val_class_str:
11447 if (AT_string_form (a) == DW_FORM_strp)
11448 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
11449 a->dw_attr_val.v.val_str->label,
11450 debug_str_section,
11451 "%s: \"%s\"", name, AT_string (a));
11452 else
11453 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
11454 break;
11456 case dw_val_class_file:
11458 int f = maybe_emit_file (a->dw_attr_val.v.val_file);
11460 dw2_asm_output_data (constant_size (f), f, "%s (%s)", name,
11461 a->dw_attr_val.v.val_file->filename);
11462 break;
11465 case dw_val_class_data8:
11467 int i;
11469 for (i = 0; i < 8; i++)
11470 dw2_asm_output_data (1, a->dw_attr_val.v.val_data8[i],
11471 i == 0 ? "%s" : NULL, name);
11472 break;
11475 default:
11476 gcc_unreachable ();
11480 FOR_EACH_CHILD (die, c, output_die (c));
11482 /* Add null byte to terminate sibling list. */
11483 if (die->die_child != NULL)
11484 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
11485 (unsigned long) die->die_offset);
11488 /* Output the compilation unit that appears at the beginning of the
11489 .debug_info section, and precedes the DIE descriptions. */
11491 static void
11492 output_compilation_unit_header (void)
11494 int ver = dwarf_version;
11496 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11497 dw2_asm_output_data (4, 0xffffffff,
11498 "Initial length escape value indicating 64-bit DWARF extension");
11499 dw2_asm_output_data (DWARF_OFFSET_SIZE,
11500 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
11501 "Length of Compilation Unit Info");
11502 dw2_asm_output_data (2, ver, "DWARF version number");
11503 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
11504 debug_abbrev_section,
11505 "Offset Into Abbrev. Section");
11506 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
11509 /* Output the compilation unit DIE and its children. */
11511 static void
11512 output_comp_unit (dw_die_ref die, int output_if_empty)
11514 const char *secname;
11515 char *oldsym, *tmp;
11517 /* Unless we are outputting main CU, we may throw away empty ones. */
11518 if (!output_if_empty && die->die_child == NULL)
11519 return;
11521 /* Even if there are no children of this DIE, we must output the information
11522 about the compilation unit. Otherwise, on an empty translation unit, we
11523 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
11524 will then complain when examining the file. First mark all the DIEs in
11525 this CU so we know which get local refs. */
11526 mark_dies (die);
11528 build_abbrev_table (die);
11530 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11531 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
11532 calc_die_sizes (die);
11534 oldsym = die->die_id.die_symbol;
11535 if (oldsym)
11537 tmp = XALLOCAVEC (char, strlen (oldsym) + 24);
11539 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
11540 secname = tmp;
11541 die->die_id.die_symbol = NULL;
11542 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11544 else
11546 switch_to_section (debug_info_section);
11547 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11548 info_section_emitted = true;
11551 /* Output debugging information. */
11552 output_compilation_unit_header ();
11553 output_die (die);
11555 /* Leave the marks on the main CU, so we can check them in
11556 output_pubnames. */
11557 if (oldsym)
11559 unmark_dies (die);
11560 die->die_id.die_symbol = oldsym;
11564 /* Output a comdat type unit DIE and its children. */
11566 static void
11567 output_comdat_type_unit (comdat_type_node *node)
11569 const char *secname;
11570 char *tmp;
11571 int i;
11572 #if defined (OBJECT_FORMAT_ELF)
11573 tree comdat_key;
11574 #endif
11576 /* First mark all the DIEs in this CU so we know which get local refs. */
11577 mark_dies (node->root_die);
11579 build_abbrev_table (node->root_die);
11581 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
11582 next_die_offset = DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE;
11583 calc_die_sizes (node->root_die);
11585 #if defined (OBJECT_FORMAT_ELF)
11586 secname = ".debug_types";
11587 tmp = XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11588 sprintf (tmp, "wt.");
11589 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11590 sprintf (tmp + 3 + i * 2, "%02x", node->signature[i] & 0xff);
11591 comdat_key = get_identifier (tmp);
11592 targetm.asm_out.named_section (secname,
11593 SECTION_DEBUG | SECTION_LINKONCE,
11594 comdat_key);
11595 #else
11596 tmp = XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE * 2);
11597 sprintf (tmp, ".gnu.linkonce.wt.");
11598 for (i = 0; i < DWARF_TYPE_SIGNATURE_SIZE; i++)
11599 sprintf (tmp + 17 + i * 2, "%02x", node->signature[i] & 0xff);
11600 secname = tmp;
11601 switch_to_section (get_section (secname, SECTION_DEBUG, NULL));
11602 #endif
11604 /* Output debugging information. */
11605 output_compilation_unit_header ();
11606 output_signature (node->signature, "Type Signature");
11607 dw2_asm_output_data (DWARF_OFFSET_SIZE, node->type_die->die_offset,
11608 "Offset to Type DIE");
11609 output_die (node->root_die);
11611 unmark_dies (node->root_die);
11614 /* Return the DWARF2/3 pubname associated with a decl. */
11616 static const char *
11617 dwarf2_name (tree decl, int scope)
11619 if (DECL_NAMELESS (decl))
11620 return NULL;
11621 return lang_hooks.dwarf_name (decl, scope ? 1 : 0);
11624 /* Add a new entry to .debug_pubnames if appropriate. */
11626 static void
11627 add_pubname_string (const char *str, dw_die_ref die)
11629 if (targetm.want_debug_pub_sections)
11631 pubname_entry e;
11633 e.die = die;
11634 e.name = xstrdup (str);
11635 VEC_safe_push (pubname_entry, gc, pubname_table, &e);
11639 static void
11640 add_pubname (tree decl, dw_die_ref die)
11642 if (targetm.want_debug_pub_sections && TREE_PUBLIC (decl))
11644 const char *name = dwarf2_name (decl, 1);
11645 if (name)
11646 add_pubname_string (name, die);
11650 /* Add a new entry to .debug_pubtypes if appropriate. */
11652 static void
11653 add_pubtype (tree decl, dw_die_ref die)
11655 pubname_entry e;
11657 if (!targetm.want_debug_pub_sections)
11658 return;
11660 e.name = NULL;
11661 if ((TREE_PUBLIC (decl)
11662 || is_cu_die (die->die_parent))
11663 && (die->die_tag == DW_TAG_typedef || COMPLETE_TYPE_P (decl)))
11665 e.die = die;
11666 if (TYPE_P (decl))
11668 if (TYPE_NAME (decl))
11670 if (TREE_CODE (TYPE_NAME (decl)) == IDENTIFIER_NODE)
11671 e.name = IDENTIFIER_POINTER (TYPE_NAME (decl));
11672 else if (TREE_CODE (TYPE_NAME (decl)) == TYPE_DECL
11673 && DECL_NAME (TYPE_NAME (decl)))
11674 e.name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (decl)));
11675 else
11676 e.name = xstrdup ((const char *) get_AT_string (die, DW_AT_name));
11679 else
11681 e.name = dwarf2_name (decl, 1);
11682 if (e.name)
11683 e.name = xstrdup (e.name);
11686 /* If we don't have a name for the type, there's no point in adding
11687 it to the table. */
11688 if (e.name && e.name[0] != '\0')
11689 VEC_safe_push (pubname_entry, gc, pubtype_table, &e);
11693 /* Output the public names table used to speed up access to externally
11694 visible names; or the public types table used to find type definitions. */
11696 static void
11697 output_pubnames (VEC (pubname_entry, gc) * names)
11699 unsigned i;
11700 unsigned long pubnames_length = size_of_pubnames (names);
11701 pubname_ref pub;
11703 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11704 dw2_asm_output_data (4, 0xffffffff,
11705 "Initial length escape value indicating 64-bit DWARF extension");
11706 if (names == pubname_table)
11707 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11708 "Length of Public Names Info");
11709 else
11710 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
11711 "Length of Public Type Names Info");
11712 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
11713 dw2_asm_output_data (2, 2, "DWARF Version");
11714 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11715 debug_info_section,
11716 "Offset of Compilation Unit Info");
11717 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
11718 "Compilation Unit Length");
11720 FOR_EACH_VEC_ELT (pubname_entry, names, i, pub)
11722 /* We shouldn't see pubnames for DIEs outside of the main CU. */
11723 if (names == pubname_table)
11724 gcc_assert (pub->die->die_mark);
11726 if (names != pubtype_table
11727 || pub->die->die_offset != 0
11728 || !flag_eliminate_unused_debug_types)
11730 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
11731 "DIE offset");
11733 dw2_asm_output_nstring (pub->name, -1, "external name");
11737 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
11740 /* Output the information that goes into the .debug_aranges table.
11741 Namely, define the beginning and ending address range of the
11742 text section generated for this compilation unit. */
11744 static void
11745 output_aranges (unsigned long aranges_length)
11747 unsigned i;
11749 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
11750 dw2_asm_output_data (4, 0xffffffff,
11751 "Initial length escape value indicating 64-bit DWARF extension");
11752 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
11753 "Length of Address Ranges Info");
11754 /* Version number for aranges is still 2, even in DWARF3. */
11755 dw2_asm_output_data (2, 2, "DWARF Version");
11756 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
11757 debug_info_section,
11758 "Offset of Compilation Unit Info");
11759 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
11760 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
11762 /* We need to align to twice the pointer size here. */
11763 if (DWARF_ARANGES_PAD_SIZE)
11765 /* Pad using a 2 byte words so that padding is correct for any
11766 pointer size. */
11767 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
11768 2 * DWARF2_ADDR_SIZE);
11769 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
11770 dw2_asm_output_data (2, 0, NULL);
11773 /* It is necessary not to output these entries if the sections were
11774 not used; if the sections were not used, the length will be 0 and
11775 the address may end up as 0 if the section is discarded by ld
11776 --gc-sections, leaving an invalid (0, 0) entry that can be
11777 confused with the terminator. */
11778 if (text_section_used)
11780 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
11781 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
11782 text_section_label, "Length");
11784 if (cold_text_section_used)
11786 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
11787 "Address");
11788 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
11789 cold_text_section_label, "Length");
11792 if (have_multiple_function_sections)
11794 unsigned fde_idx = 0;
11796 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
11798 dw_fde_ref fde = &fde_table[fde_idx];
11800 if (!fde->in_std_section)
11802 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
11803 "Address");
11804 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_end,
11805 fde->dw_fde_begin, "Length");
11807 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
11809 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_second_begin,
11810 "Address");
11811 dw2_asm_output_delta (DWARF2_ADDR_SIZE, fde->dw_fde_second_end,
11812 fde->dw_fde_second_begin, "Length");
11817 /* Output the terminator words. */
11818 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11819 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11822 /* Add a new entry to .debug_ranges. Return the offset at which it
11823 was placed. */
11825 static unsigned int
11826 add_ranges_num (int num)
11828 unsigned int in_use = ranges_table_in_use;
11830 if (in_use == ranges_table_allocated)
11832 ranges_table_allocated += RANGES_TABLE_INCREMENT;
11833 ranges_table = GGC_RESIZEVEC (struct dw_ranges_struct, ranges_table,
11834 ranges_table_allocated);
11835 memset (ranges_table + ranges_table_in_use, 0,
11836 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
11839 ranges_table[in_use].num = num;
11840 ranges_table_in_use = in_use + 1;
11842 return in_use * 2 * DWARF2_ADDR_SIZE;
11845 /* Add a new entry to .debug_ranges corresponding to a block, or a
11846 range terminator if BLOCK is NULL. */
11848 static unsigned int
11849 add_ranges (const_tree block)
11851 return add_ranges_num (block ? BLOCK_NUMBER (block) : 0);
11854 /* Add a new entry to .debug_ranges corresponding to a pair of
11855 labels. */
11857 static void
11858 add_ranges_by_labels (dw_die_ref die, const char *begin, const char *end,
11859 bool *added)
11861 unsigned int in_use = ranges_by_label_in_use;
11862 unsigned int offset;
11864 if (in_use == ranges_by_label_allocated)
11866 ranges_by_label_allocated += RANGES_TABLE_INCREMENT;
11867 ranges_by_label = GGC_RESIZEVEC (struct dw_ranges_by_label_struct,
11868 ranges_by_label,
11869 ranges_by_label_allocated);
11870 memset (ranges_by_label + ranges_by_label_in_use, 0,
11871 RANGES_TABLE_INCREMENT
11872 * sizeof (struct dw_ranges_by_label_struct));
11875 ranges_by_label[in_use].begin = begin;
11876 ranges_by_label[in_use].end = end;
11877 ranges_by_label_in_use = in_use + 1;
11879 offset = add_ranges_num (-(int)in_use - 1);
11880 if (!*added)
11882 add_AT_range_list (die, DW_AT_ranges, offset);
11883 *added = true;
11887 static void
11888 output_ranges (void)
11890 unsigned i;
11891 static const char *const start_fmt = "Offset %#x";
11892 const char *fmt = start_fmt;
11894 for (i = 0; i < ranges_table_in_use; i++)
11896 int block_num = ranges_table[i].num;
11898 if (block_num > 0)
11900 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
11901 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
11903 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
11904 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
11906 /* If all code is in the text section, then the compilation
11907 unit base address defaults to DW_AT_low_pc, which is the
11908 base of the text section. */
11909 if (!have_multiple_function_sections)
11911 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
11912 text_section_label,
11913 fmt, i * 2 * DWARF2_ADDR_SIZE);
11914 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
11915 text_section_label, NULL);
11918 /* Otherwise, the compilation unit base address is zero,
11919 which allows us to use absolute addresses, and not worry
11920 about whether the target supports cross-section
11921 arithmetic. */
11922 else
11924 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
11925 fmt, i * 2 * DWARF2_ADDR_SIZE);
11926 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
11929 fmt = NULL;
11932 /* Negative block_num stands for an index into ranges_by_label. */
11933 else if (block_num < 0)
11935 int lab_idx = - block_num - 1;
11937 if (!have_multiple_function_sections)
11939 gcc_unreachable ();
11940 #if 0
11941 /* If we ever use add_ranges_by_labels () for a single
11942 function section, all we have to do is to take out
11943 the #if 0 above. */
11944 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11945 ranges_by_label[lab_idx].begin,
11946 text_section_label,
11947 fmt, i * 2 * DWARF2_ADDR_SIZE);
11948 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
11949 ranges_by_label[lab_idx].end,
11950 text_section_label, NULL);
11951 #endif
11953 else
11955 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11956 ranges_by_label[lab_idx].begin,
11957 fmt, i * 2 * DWARF2_ADDR_SIZE);
11958 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
11959 ranges_by_label[lab_idx].end,
11960 NULL);
11963 else
11965 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11966 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
11967 fmt = start_fmt;
11972 /* Data structure containing information about input files. */
11973 struct file_info
11975 const char *path; /* Complete file name. */
11976 const char *fname; /* File name part. */
11977 int length; /* Length of entire string. */
11978 struct dwarf_file_data * file_idx; /* Index in input file table. */
11979 int dir_idx; /* Index in directory table. */
11982 /* Data structure containing information about directories with source
11983 files. */
11984 struct dir_info
11986 const char *path; /* Path including directory name. */
11987 int length; /* Path length. */
11988 int prefix; /* Index of directory entry which is a prefix. */
11989 int count; /* Number of files in this directory. */
11990 int dir_idx; /* Index of directory used as base. */
11993 /* Callback function for file_info comparison. We sort by looking at
11994 the directories in the path. */
11996 static int
11997 file_info_cmp (const void *p1, const void *p2)
11999 const struct file_info *const s1 = (const struct file_info *) p1;
12000 const struct file_info *const s2 = (const struct file_info *) p2;
12001 const unsigned char *cp1;
12002 const unsigned char *cp2;
12004 /* Take care of file names without directories. We need to make sure that
12005 we return consistent values to qsort since some will get confused if
12006 we return the same value when identical operands are passed in opposite
12007 orders. So if neither has a directory, return 0 and otherwise return
12008 1 or -1 depending on which one has the directory. */
12009 if ((s1->path == s1->fname || s2->path == s2->fname))
12010 return (s2->path == s2->fname) - (s1->path == s1->fname);
12012 cp1 = (const unsigned char *) s1->path;
12013 cp2 = (const unsigned char *) s2->path;
12015 while (1)
12017 ++cp1;
12018 ++cp2;
12019 /* Reached the end of the first path? If so, handle like above. */
12020 if ((cp1 == (const unsigned char *) s1->fname)
12021 || (cp2 == (const unsigned char *) s2->fname))
12022 return ((cp2 == (const unsigned char *) s2->fname)
12023 - (cp1 == (const unsigned char *) s1->fname));
12025 /* Character of current path component the same? */
12026 else if (*cp1 != *cp2)
12027 return *cp1 - *cp2;
12031 struct file_name_acquire_data
12033 struct file_info *files;
12034 int used_files;
12035 int max_files;
12038 /* Traversal function for the hash table. */
12040 static int
12041 file_name_acquire (void ** slot, void *data)
12043 struct file_name_acquire_data *fnad = (struct file_name_acquire_data *) data;
12044 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
12045 struct file_info *fi;
12046 const char *f;
12048 gcc_assert (fnad->max_files >= d->emitted_number);
12050 if (! d->emitted_number)
12051 return 1;
12053 gcc_assert (fnad->max_files != fnad->used_files);
12055 fi = fnad->files + fnad->used_files++;
12057 /* Skip all leading "./". */
12058 f = d->filename;
12059 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
12060 f += 2;
12062 /* Create a new array entry. */
12063 fi->path = f;
12064 fi->length = strlen (f);
12065 fi->file_idx = d;
12067 /* Search for the file name part. */
12068 f = strrchr (f, DIR_SEPARATOR);
12069 #if defined (DIR_SEPARATOR_2)
12071 char *g = strrchr (fi->path, DIR_SEPARATOR_2);
12073 if (g != NULL)
12075 if (f == NULL || f < g)
12076 f = g;
12079 #endif
12081 fi->fname = f == NULL ? fi->path : f + 1;
12082 return 1;
12085 /* Output the directory table and the file name table. We try to minimize
12086 the total amount of memory needed. A heuristic is used to avoid large
12087 slowdowns with many input files. */
12089 static void
12090 output_file_names (void)
12092 struct file_name_acquire_data fnad;
12093 int numfiles;
12094 struct file_info *files;
12095 struct dir_info *dirs;
12096 int *saved;
12097 int *savehere;
12098 int *backmap;
12099 int ndirs;
12100 int idx_offset;
12101 int i;
12103 if (!last_emitted_file)
12105 dw2_asm_output_data (1, 0, "End directory table");
12106 dw2_asm_output_data (1, 0, "End file name table");
12107 return;
12110 numfiles = last_emitted_file->emitted_number;
12112 /* Allocate the various arrays we need. */
12113 files = XALLOCAVEC (struct file_info, numfiles);
12114 dirs = XALLOCAVEC (struct dir_info, numfiles);
12116 fnad.files = files;
12117 fnad.used_files = 0;
12118 fnad.max_files = numfiles;
12119 htab_traverse (file_table, file_name_acquire, &fnad);
12120 gcc_assert (fnad.used_files == fnad.max_files);
12122 qsort (files, numfiles, sizeof (files[0]), file_info_cmp);
12124 /* Find all the different directories used. */
12125 dirs[0].path = files[0].path;
12126 dirs[0].length = files[0].fname - files[0].path;
12127 dirs[0].prefix = -1;
12128 dirs[0].count = 1;
12129 dirs[0].dir_idx = 0;
12130 files[0].dir_idx = 0;
12131 ndirs = 1;
12133 for (i = 1; i < numfiles; i++)
12134 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
12135 && memcmp (dirs[ndirs - 1].path, files[i].path,
12136 dirs[ndirs - 1].length) == 0)
12138 /* Same directory as last entry. */
12139 files[i].dir_idx = ndirs - 1;
12140 ++dirs[ndirs - 1].count;
12142 else
12144 int j;
12146 /* This is a new directory. */
12147 dirs[ndirs].path = files[i].path;
12148 dirs[ndirs].length = files[i].fname - files[i].path;
12149 dirs[ndirs].count = 1;
12150 dirs[ndirs].dir_idx = ndirs;
12151 files[i].dir_idx = ndirs;
12153 /* Search for a prefix. */
12154 dirs[ndirs].prefix = -1;
12155 for (j = 0; j < ndirs; j++)
12156 if (dirs[j].length < dirs[ndirs].length
12157 && dirs[j].length > 1
12158 && (dirs[ndirs].prefix == -1
12159 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
12160 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
12161 dirs[ndirs].prefix = j;
12163 ++ndirs;
12166 /* Now to the actual work. We have to find a subset of the directories which
12167 allow expressing the file name using references to the directory table
12168 with the least amount of characters. We do not do an exhaustive search
12169 where we would have to check out every combination of every single
12170 possible prefix. Instead we use a heuristic which provides nearly optimal
12171 results in most cases and never is much off. */
12172 saved = XALLOCAVEC (int, ndirs);
12173 savehere = XALLOCAVEC (int, ndirs);
12175 memset (saved, '\0', ndirs * sizeof (saved[0]));
12176 for (i = 0; i < ndirs; i++)
12178 int j;
12179 int total;
12181 /* We can always save some space for the current directory. But this
12182 does not mean it will be enough to justify adding the directory. */
12183 savehere[i] = dirs[i].length;
12184 total = (savehere[i] - saved[i]) * dirs[i].count;
12186 for (j = i + 1; j < ndirs; j++)
12188 savehere[j] = 0;
12189 if (saved[j] < dirs[i].length)
12191 /* Determine whether the dirs[i] path is a prefix of the
12192 dirs[j] path. */
12193 int k;
12195 k = dirs[j].prefix;
12196 while (k != -1 && k != (int) i)
12197 k = dirs[k].prefix;
12199 if (k == (int) i)
12201 /* Yes it is. We can possibly save some memory by
12202 writing the filenames in dirs[j] relative to
12203 dirs[i]. */
12204 savehere[j] = dirs[i].length;
12205 total += (savehere[j] - saved[j]) * dirs[j].count;
12210 /* Check whether we can save enough to justify adding the dirs[i]
12211 directory. */
12212 if (total > dirs[i].length + 1)
12214 /* It's worthwhile adding. */
12215 for (j = i; j < ndirs; j++)
12216 if (savehere[j] > 0)
12218 /* Remember how much we saved for this directory so far. */
12219 saved[j] = savehere[j];
12221 /* Remember the prefix directory. */
12222 dirs[j].dir_idx = i;
12227 /* Emit the directory name table. */
12228 idx_offset = dirs[0].length > 0 ? 1 : 0;
12229 for (i = 1 - idx_offset; i < ndirs; i++)
12230 dw2_asm_output_nstring (dirs[i].path,
12231 dirs[i].length
12232 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR,
12233 "Directory Entry: %#x", i + idx_offset);
12235 dw2_asm_output_data (1, 0, "End directory table");
12237 /* We have to emit them in the order of emitted_number since that's
12238 used in the debug info generation. To do this efficiently we
12239 generate a back-mapping of the indices first. */
12240 backmap = XALLOCAVEC (int, numfiles);
12241 for (i = 0; i < numfiles; i++)
12242 backmap[files[i].file_idx->emitted_number - 1] = i;
12244 /* Now write all the file names. */
12245 for (i = 0; i < numfiles; i++)
12247 int file_idx = backmap[i];
12248 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
12250 #ifdef VMS_DEBUGGING_INFO
12251 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
12253 /* Setting these fields can lead to debugger miscomparisons,
12254 but VMS Debug requires them to be set correctly. */
12256 int ver;
12257 long long cdt;
12258 long siz;
12259 int maxfilelen = strlen (files[file_idx].path)
12260 + dirs[dir_idx].length
12261 + MAX_VMS_VERSION_LEN + 1;
12262 char *filebuf = XALLOCAVEC (char, maxfilelen);
12264 vms_file_stats_name (files[file_idx].path, 0, 0, 0, &ver);
12265 snprintf (filebuf, maxfilelen, "%s;%d",
12266 files[file_idx].path + dirs[dir_idx].length, ver);
12268 dw2_asm_output_nstring
12269 (filebuf, -1, "File Entry: %#x", (unsigned) i + 1);
12271 /* Include directory index. */
12272 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12274 /* Modification time. */
12275 dw2_asm_output_data_uleb128
12276 ((vms_file_stats_name (files[file_idx].path, &cdt, 0, 0, 0) == 0)
12277 ? cdt : 0,
12278 NULL);
12280 /* File length in bytes. */
12281 dw2_asm_output_data_uleb128
12282 ((vms_file_stats_name (files[file_idx].path, 0, &siz, 0, 0) == 0)
12283 ? siz : 0,
12284 NULL);
12285 #else
12286 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
12287 "File Entry: %#x", (unsigned) i + 1);
12289 /* Include directory index. */
12290 dw2_asm_output_data_uleb128 (dir_idx + idx_offset, NULL);
12292 /* Modification time. */
12293 dw2_asm_output_data_uleb128 (0, NULL);
12295 /* File length in bytes. */
12296 dw2_asm_output_data_uleb128 (0, NULL);
12297 #endif /* VMS_DEBUGGING_INFO */
12300 dw2_asm_output_data (1, 0, "End file name table");
12304 /* Output one line number table into the .debug_line section. */
12306 static void
12307 output_one_line_info_table (dw_line_info_table *table)
12309 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
12310 unsigned int current_line = 1;
12311 bool current_is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
12312 dw_line_info_entry *ent;
12313 size_t i;
12315 FOR_EACH_VEC_ELT (dw_line_info_entry, table->entries, i, ent)
12317 switch (ent->opcode)
12319 case LI_set_address:
12320 /* ??? Unfortunately, we have little choice here currently, and
12321 must always use the most general form. GCC does not know the
12322 address delta itself, so we can't use DW_LNS_advance_pc. Many
12323 ports do have length attributes which will give an upper bound
12324 on the address range. We could perhaps use length attributes
12325 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
12326 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, ent->val);
12328 /* This can handle any delta. This takes
12329 4+DWARF2_ADDR_SIZE bytes. */
12330 dw2_asm_output_data (1, 0, "set address %s", line_label);
12331 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12332 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12333 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
12334 break;
12336 case LI_set_line:
12337 if (ent->val == current_line)
12339 /* We still need to start a new row, so output a copy insn. */
12340 dw2_asm_output_data (1, DW_LNS_copy,
12341 "copy line %u", current_line);
12343 else
12345 int line_offset = ent->val - current_line;
12346 int line_delta = line_offset - DWARF_LINE_BASE;
12348 current_line = ent->val;
12349 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
12351 /* This can handle deltas from -10 to 234, using the current
12352 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
12353 This takes 1 byte. */
12354 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
12355 "line %u", current_line);
12357 else
12359 /* This can handle any delta. This takes at least 4 bytes,
12360 depending on the value being encoded. */
12361 dw2_asm_output_data (1, DW_LNS_advance_line,
12362 "advance to line %u", current_line);
12363 dw2_asm_output_data_sleb128 (line_offset, NULL);
12364 dw2_asm_output_data (1, DW_LNS_copy, NULL);
12367 break;
12369 case LI_set_file:
12370 dw2_asm_output_data (1, DW_LNS_set_file, "set file %u", ent->val);
12371 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12372 break;
12374 case LI_set_column:
12375 dw2_asm_output_data (1, DW_LNS_set_column, "column %u", ent->val);
12376 dw2_asm_output_data_uleb128 (ent->val, "%u", ent->val);
12377 break;
12379 case LI_negate_stmt:
12380 current_is_stmt = !current_is_stmt;
12381 dw2_asm_output_data (1, DW_LNS_negate_stmt,
12382 "is_stmt %d", current_is_stmt);
12383 break;
12385 case LI_set_prologue_end:
12386 dw2_asm_output_data (1, DW_LNS_set_prologue_end,
12387 "set prologue end");
12388 break;
12390 case LI_set_epilogue_begin:
12391 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin,
12392 "set epilogue begin");
12393 break;
12395 case LI_set_discriminator:
12396 dw2_asm_output_data (1, 0, "discriminator %u", ent->val);
12397 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent->val), NULL);
12398 dw2_asm_output_data (1, DW_LNE_set_discriminator, NULL);
12399 dw2_asm_output_data_uleb128 (ent->val, NULL);
12400 break;
12404 /* Emit debug info for the address of the end of the table. */
12405 dw2_asm_output_data (1, 0, "set address %s", table->end_label);
12406 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
12407 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
12408 dw2_asm_output_addr (DWARF2_ADDR_SIZE, table->end_label, NULL);
12410 dw2_asm_output_data (1, 0, "end sequence");
12411 dw2_asm_output_data_uleb128 (1, NULL);
12412 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
12415 /* Output the source line number correspondence information. This
12416 information goes into the .debug_line section. */
12418 static void
12419 output_line_info (void)
12421 char l1[20], l2[20], p1[20], p2[20];
12422 int ver = dwarf_version;
12423 int opc;
12425 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
12426 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
12427 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
12428 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
12430 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
12431 dw2_asm_output_data (4, 0xffffffff,
12432 "Initial length escape value indicating 64-bit DWARF extension");
12433 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
12434 "Length of Source Line Info");
12435 ASM_OUTPUT_LABEL (asm_out_file, l1);
12437 dw2_asm_output_data (2, ver, "DWARF Version");
12438 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
12439 ASM_OUTPUT_LABEL (asm_out_file, p1);
12441 /* Define the architecture-dependent minimum instruction length (in bytes).
12442 In this implementation of DWARF, this field is used for information
12443 purposes only. Since GCC generates assembly language, we have no
12444 a priori knowledge of how many instruction bytes are generated for each
12445 source line, and therefore can use only the DW_LNE_set_address and
12446 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
12447 this as '1', which is "correct enough" for all architectures,
12448 and don't let the target override. */
12449 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
12451 if (ver >= 4)
12452 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN,
12453 "Maximum Operations Per Instruction");
12454 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
12455 "Default is_stmt_start flag");
12456 dw2_asm_output_data (1, DWARF_LINE_BASE,
12457 "Line Base Value (Special Opcodes)");
12458 dw2_asm_output_data (1, DWARF_LINE_RANGE,
12459 "Line Range Value (Special Opcodes)");
12460 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
12461 "Special Opcode Base");
12463 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
12465 int n_op_args;
12466 switch (opc)
12468 case DW_LNS_advance_pc:
12469 case DW_LNS_advance_line:
12470 case DW_LNS_set_file:
12471 case DW_LNS_set_column:
12472 case DW_LNS_fixed_advance_pc:
12473 case DW_LNS_set_isa:
12474 n_op_args = 1;
12475 break;
12476 default:
12477 n_op_args = 0;
12478 break;
12481 dw2_asm_output_data (1, n_op_args, "opcode: %#x has %d args",
12482 opc, n_op_args);
12485 /* Write out the information about the files we use. */
12486 output_file_names ();
12487 ASM_OUTPUT_LABEL (asm_out_file, p2);
12489 if (text_section_line_info && text_section_line_info->in_use)
12490 output_one_line_info_table (text_section_line_info);
12491 if (cold_text_section_line_info && cold_text_section_line_info->in_use)
12492 output_one_line_info_table (cold_text_section_line_info);
12494 if (separate_line_info)
12496 dw_line_info_table *table;
12497 size_t i;
12499 FOR_EACH_VEC_ELT (dw_line_info_table_p, separate_line_info, i, table)
12500 if (table->in_use)
12501 output_one_line_info_table (table);
12504 /* Output the marker for the end of the line number info. */
12505 ASM_OUTPUT_LABEL (asm_out_file, l2);
12508 /* Given a pointer to a tree node for some base type, return a pointer to
12509 a DIE that describes the given type.
12511 This routine must only be called for GCC type nodes that correspond to
12512 Dwarf base (fundamental) types. */
12514 static dw_die_ref
12515 base_type_die (tree type)
12517 dw_die_ref base_type_result;
12518 enum dwarf_type encoding;
12520 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
12521 return 0;
12523 /* If this is a subtype that should not be emitted as a subrange type,
12524 use the base type. See subrange_type_for_debug_p. */
12525 if (TREE_CODE (type) == INTEGER_TYPE && TREE_TYPE (type) != NULL_TREE)
12526 type = TREE_TYPE (type);
12528 switch (TREE_CODE (type))
12530 case INTEGER_TYPE:
12531 if ((dwarf_version >= 4 || !dwarf_strict)
12532 && TYPE_NAME (type)
12533 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12534 && DECL_IS_BUILTIN (TYPE_NAME (type))
12535 && DECL_NAME (TYPE_NAME (type)))
12537 const char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
12538 if (strcmp (name, "char16_t") == 0
12539 || strcmp (name, "char32_t") == 0)
12541 encoding = DW_ATE_UTF;
12542 break;
12545 if (TYPE_STRING_FLAG (type))
12547 if (TYPE_UNSIGNED (type))
12548 encoding = DW_ATE_unsigned_char;
12549 else
12550 encoding = DW_ATE_signed_char;
12552 else if (TYPE_UNSIGNED (type))
12553 encoding = DW_ATE_unsigned;
12554 else
12555 encoding = DW_ATE_signed;
12556 break;
12558 case REAL_TYPE:
12559 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)))
12561 if (dwarf_version >= 3 || !dwarf_strict)
12562 encoding = DW_ATE_decimal_float;
12563 else
12564 encoding = DW_ATE_lo_user;
12566 else
12567 encoding = DW_ATE_float;
12568 break;
12570 case FIXED_POINT_TYPE:
12571 if (!(dwarf_version >= 3 || !dwarf_strict))
12572 encoding = DW_ATE_lo_user;
12573 else if (TYPE_UNSIGNED (type))
12574 encoding = DW_ATE_unsigned_fixed;
12575 else
12576 encoding = DW_ATE_signed_fixed;
12577 break;
12579 /* Dwarf2 doesn't know anything about complex ints, so use
12580 a user defined type for it. */
12581 case COMPLEX_TYPE:
12582 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
12583 encoding = DW_ATE_complex_float;
12584 else
12585 encoding = DW_ATE_lo_user;
12586 break;
12588 case BOOLEAN_TYPE:
12589 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
12590 encoding = DW_ATE_boolean;
12591 break;
12593 default:
12594 /* No other TREE_CODEs are Dwarf fundamental types. */
12595 gcc_unreachable ();
12598 base_type_result = new_die (DW_TAG_base_type, comp_unit_die (), type);
12600 add_AT_unsigned (base_type_result, DW_AT_byte_size,
12601 int_size_in_bytes (type));
12602 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
12604 return base_type_result;
12607 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
12608 given input type is a Dwarf "fundamental" type. Otherwise return null. */
12610 static inline int
12611 is_base_type (tree type)
12613 switch (TREE_CODE (type))
12615 case ERROR_MARK:
12616 case VOID_TYPE:
12617 case INTEGER_TYPE:
12618 case REAL_TYPE:
12619 case FIXED_POINT_TYPE:
12620 case COMPLEX_TYPE:
12621 case BOOLEAN_TYPE:
12622 return 1;
12624 case ARRAY_TYPE:
12625 case RECORD_TYPE:
12626 case UNION_TYPE:
12627 case QUAL_UNION_TYPE:
12628 case ENUMERAL_TYPE:
12629 case FUNCTION_TYPE:
12630 case METHOD_TYPE:
12631 case POINTER_TYPE:
12632 case REFERENCE_TYPE:
12633 case NULLPTR_TYPE:
12634 case OFFSET_TYPE:
12635 case LANG_TYPE:
12636 case VECTOR_TYPE:
12637 return 0;
12639 default:
12640 gcc_unreachable ();
12643 return 0;
12646 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
12647 node, return the size in bits for the type if it is a constant, or else
12648 return the alignment for the type if the type's size is not constant, or
12649 else return BITS_PER_WORD if the type actually turns out to be an
12650 ERROR_MARK node. */
12652 static inline unsigned HOST_WIDE_INT
12653 simple_type_size_in_bits (const_tree type)
12655 if (TREE_CODE (type) == ERROR_MARK)
12656 return BITS_PER_WORD;
12657 else if (TYPE_SIZE (type) == NULL_TREE)
12658 return 0;
12659 else if (host_integerp (TYPE_SIZE (type), 1))
12660 return tree_low_cst (TYPE_SIZE (type), 1);
12661 else
12662 return TYPE_ALIGN (type);
12665 /* Similarly, but return a double_int instead of UHWI. */
12667 static inline double_int
12668 double_int_type_size_in_bits (const_tree type)
12670 if (TREE_CODE (type) == ERROR_MARK)
12671 return uhwi_to_double_int (BITS_PER_WORD);
12672 else if (TYPE_SIZE (type) == NULL_TREE)
12673 return double_int_zero;
12674 else if (TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
12675 return tree_to_double_int (TYPE_SIZE (type));
12676 else
12677 return uhwi_to_double_int (TYPE_ALIGN (type));
12680 /* Given a pointer to a tree node for a subrange type, return a pointer
12681 to a DIE that describes the given type. */
12683 static dw_die_ref
12684 subrange_type_die (tree type, tree low, tree high, dw_die_ref context_die)
12686 dw_die_ref subrange_die;
12687 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
12689 if (context_die == NULL)
12690 context_die = comp_unit_die ();
12692 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
12694 if (int_size_in_bytes (TREE_TYPE (type)) != size_in_bytes)
12696 /* The size of the subrange type and its base type do not match,
12697 so we need to generate a size attribute for the subrange type. */
12698 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
12701 if (low)
12702 add_bound_info (subrange_die, DW_AT_lower_bound, low);
12703 if (high)
12704 add_bound_info (subrange_die, DW_AT_upper_bound, high);
12706 return subrange_die;
12709 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
12710 entry that chains various modifiers in front of the given type. */
12712 static dw_die_ref
12713 modified_type_die (tree type, int is_const_type, int is_volatile_type,
12714 dw_die_ref context_die)
12716 enum tree_code code = TREE_CODE (type);
12717 dw_die_ref mod_type_die;
12718 dw_die_ref sub_die = NULL;
12719 tree item_type = NULL;
12720 tree qualified_type;
12721 tree name, low, high;
12723 if (code == ERROR_MARK)
12724 return NULL;
12726 /* See if we already have the appropriately qualified variant of
12727 this type. */
12728 qualified_type
12729 = get_qualified_type (type,
12730 ((is_const_type ? TYPE_QUAL_CONST : 0)
12731 | (is_volatile_type ? TYPE_QUAL_VOLATILE : 0)));
12733 if (qualified_type == sizetype
12734 && TYPE_NAME (qualified_type)
12735 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL)
12737 tree t = TREE_TYPE (TYPE_NAME (qualified_type));
12739 gcc_checking_assert (TREE_CODE (t) == INTEGER_TYPE
12740 && TYPE_PRECISION (t)
12741 == TYPE_PRECISION (qualified_type)
12742 && TYPE_UNSIGNED (t)
12743 == TYPE_UNSIGNED (qualified_type));
12744 qualified_type = t;
12747 /* If we do, then we can just use its DIE, if it exists. */
12748 if (qualified_type)
12750 mod_type_die = lookup_type_die (qualified_type);
12751 if (mod_type_die)
12752 return mod_type_die;
12755 name = qualified_type ? TYPE_NAME (qualified_type) : NULL;
12757 /* Handle C typedef types. */
12758 if (name && TREE_CODE (name) == TYPE_DECL && DECL_ORIGINAL_TYPE (name)
12759 && !DECL_ARTIFICIAL (name))
12761 tree dtype = TREE_TYPE (name);
12763 if (qualified_type == dtype)
12765 /* For a named type, use the typedef. */
12766 gen_type_die (qualified_type, context_die);
12767 return lookup_type_die (qualified_type);
12769 else if (is_const_type < TYPE_READONLY (dtype)
12770 || is_volatile_type < TYPE_VOLATILE (dtype)
12771 || (is_const_type <= TYPE_READONLY (dtype)
12772 && is_volatile_type <= TYPE_VOLATILE (dtype)
12773 && DECL_ORIGINAL_TYPE (name) != type))
12774 /* cv-unqualified version of named type. Just use the unnamed
12775 type to which it refers. */
12776 return modified_type_die (DECL_ORIGINAL_TYPE (name),
12777 is_const_type, is_volatile_type,
12778 context_die);
12779 /* Else cv-qualified version of named type; fall through. */
12782 if (is_const_type
12783 /* If both is_const_type and is_volatile_type, prefer the path
12784 which leads to a qualified type. */
12785 && (!is_volatile_type
12786 || get_qualified_type (type, TYPE_QUAL_CONST) == NULL_TREE
12787 || get_qualified_type (type, TYPE_QUAL_VOLATILE) != NULL_TREE))
12789 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die (), type);
12790 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
12792 else if (is_volatile_type)
12794 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die (), type);
12795 sub_die = modified_type_die (type, is_const_type, 0, context_die);
12797 else if (code == POINTER_TYPE)
12799 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die (), type);
12800 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12801 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12802 item_type = TREE_TYPE (type);
12803 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12804 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12805 TYPE_ADDR_SPACE (item_type));
12807 else if (code == REFERENCE_TYPE)
12809 if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
12810 mod_type_die = new_die (DW_TAG_rvalue_reference_type, comp_unit_die (),
12811 type);
12812 else
12813 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die (), type);
12814 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
12815 simple_type_size_in_bits (type) / BITS_PER_UNIT);
12816 item_type = TREE_TYPE (type);
12817 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type)))
12818 add_AT_unsigned (mod_type_die, DW_AT_address_class,
12819 TYPE_ADDR_SPACE (item_type));
12821 else if (code == INTEGER_TYPE
12822 && TREE_TYPE (type) != NULL_TREE
12823 && subrange_type_for_debug_p (type, &low, &high))
12825 mod_type_die = subrange_type_die (type, low, high, context_die);
12826 item_type = TREE_TYPE (type);
12828 else if (is_base_type (type))
12829 mod_type_die = base_type_die (type);
12830 else
12832 gen_type_die (type, context_die);
12834 /* We have to get the type_main_variant here (and pass that to the
12835 `lookup_type_die' routine) because the ..._TYPE node we have
12836 might simply be a *copy* of some original type node (where the
12837 copy was created to help us keep track of typedef names) and
12838 that copy might have a different TYPE_UID from the original
12839 ..._TYPE node. */
12840 if (TREE_CODE (type) != VECTOR_TYPE)
12841 return lookup_type_die (type_main_variant (type));
12842 else
12843 /* Vectors have the debugging information in the type,
12844 not the main variant. */
12845 return lookup_type_die (type);
12848 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
12849 don't output a DW_TAG_typedef, since there isn't one in the
12850 user's program; just attach a DW_AT_name to the type.
12851 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
12852 if the base type already has the same name. */
12853 if (name
12854 && ((TREE_CODE (name) != TYPE_DECL
12855 && (qualified_type == TYPE_MAIN_VARIANT (type)
12856 || (!is_const_type && !is_volatile_type)))
12857 || (TREE_CODE (name) == TYPE_DECL
12858 && TREE_TYPE (name) == qualified_type
12859 && DECL_NAME (name))))
12861 if (TREE_CODE (name) == TYPE_DECL)
12862 /* Could just call add_name_and_src_coords_attributes here,
12863 but since this is a builtin type it doesn't have any
12864 useful source coordinates anyway. */
12865 name = DECL_NAME (name);
12866 add_name_attribute (mod_type_die, IDENTIFIER_POINTER (name));
12867 add_gnat_descriptive_type_attribute (mod_type_die, type, context_die);
12869 /* This probably indicates a bug. */
12870 else if (mod_type_die && mod_type_die->die_tag == DW_TAG_base_type)
12871 add_name_attribute (mod_type_die, "__unknown__");
12873 if (qualified_type)
12874 equate_type_number_to_die (qualified_type, mod_type_die);
12876 if (item_type)
12877 /* We must do this after the equate_type_number_to_die call, in case
12878 this is a recursive type. This ensures that the modified_type_die
12879 recursion will terminate even if the type is recursive. Recursive
12880 types are possible in Ada. */
12881 sub_die = modified_type_die (item_type,
12882 TYPE_READONLY (item_type),
12883 TYPE_VOLATILE (item_type),
12884 context_die);
12886 if (sub_die != NULL)
12887 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
12889 return mod_type_die;
12892 /* Generate DIEs for the generic parameters of T.
12893 T must be either a generic type or a generic function.
12894 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
12896 static void
12897 gen_generic_params_dies (tree t)
12899 tree parms, args;
12900 int parms_num, i;
12901 dw_die_ref die = NULL;
12903 if (!t || (TYPE_P (t) && !COMPLETE_TYPE_P (t)))
12904 return;
12906 if (TYPE_P (t))
12907 die = lookup_type_die (t);
12908 else if (DECL_P (t))
12909 die = lookup_decl_die (t);
12911 gcc_assert (die);
12913 parms = lang_hooks.get_innermost_generic_parms (t);
12914 if (!parms)
12915 /* T has no generic parameter. It means T is neither a generic type
12916 or function. End of story. */
12917 return;
12919 parms_num = TREE_VEC_LENGTH (parms);
12920 args = lang_hooks.get_innermost_generic_args (t);
12921 for (i = 0; i < parms_num; i++)
12923 tree parm, arg, arg_pack_elems;
12925 parm = TREE_VEC_ELT (parms, i);
12926 arg = TREE_VEC_ELT (args, i);
12927 arg_pack_elems = lang_hooks.types.get_argument_pack_elems (arg);
12928 gcc_assert (parm && TREE_VALUE (parm) && arg);
12930 if (parm && TREE_VALUE (parm) && arg)
12932 /* If PARM represents a template parameter pack,
12933 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
12934 by DW_TAG_template_*_parameter DIEs for the argument
12935 pack elements of ARG. Note that ARG would then be
12936 an argument pack. */
12937 if (arg_pack_elems)
12938 template_parameter_pack_die (TREE_VALUE (parm),
12939 arg_pack_elems,
12940 die);
12941 else
12942 generic_parameter_die (TREE_VALUE (parm), arg,
12943 true /* Emit DW_AT_name */, die);
12948 /* Create and return a DIE for PARM which should be
12949 the representation of a generic type parameter.
12950 For instance, in the C++ front end, PARM would be a template parameter.
12951 ARG is the argument to PARM.
12952 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
12953 name of the PARM.
12954 PARENT_DIE is the parent DIE which the new created DIE should be added to,
12955 as a child node. */
12957 static dw_die_ref
12958 generic_parameter_die (tree parm, tree arg,
12959 bool emit_name_p,
12960 dw_die_ref parent_die)
12962 dw_die_ref tmpl_die = NULL;
12963 const char *name = NULL;
12965 if (!parm || !DECL_NAME (parm) || !arg)
12966 return NULL;
12968 /* We support non-type generic parameters and arguments,
12969 type generic parameters and arguments, as well as
12970 generic generic parameters (a.k.a. template template parameters in C++)
12971 and arguments. */
12972 if (TREE_CODE (parm) == PARM_DECL)
12973 /* PARM is a nontype generic parameter */
12974 tmpl_die = new_die (DW_TAG_template_value_param, parent_die, parm);
12975 else if (TREE_CODE (parm) == TYPE_DECL)
12976 /* PARM is a type generic parameter. */
12977 tmpl_die = new_die (DW_TAG_template_type_param, parent_die, parm);
12978 else if (lang_hooks.decls.generic_generic_parameter_decl_p (parm))
12979 /* PARM is a generic generic parameter.
12980 Its DIE is a GNU extension. It shall have a
12981 DW_AT_name attribute to represent the name of the template template
12982 parameter, and a DW_AT_GNU_template_name attribute to represent the
12983 name of the template template argument. */
12984 tmpl_die = new_die (DW_TAG_GNU_template_template_param,
12985 parent_die, parm);
12986 else
12987 gcc_unreachable ();
12989 if (tmpl_die)
12991 tree tmpl_type;
12993 /* If PARM is a generic parameter pack, it means we are
12994 emitting debug info for a template argument pack element.
12995 In other terms, ARG is a template argument pack element.
12996 In that case, we don't emit any DW_AT_name attribute for
12997 the die. */
12998 if (emit_name_p)
13000 name = IDENTIFIER_POINTER (DECL_NAME (parm));
13001 gcc_assert (name);
13002 add_AT_string (tmpl_die, DW_AT_name, name);
13005 if (!lang_hooks.decls.generic_generic_parameter_decl_p (parm))
13007 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
13008 TMPL_DIE should have a child DW_AT_type attribute that is set
13009 to the type of the argument to PARM, which is ARG.
13010 If PARM is a type generic parameter, TMPL_DIE should have a
13011 child DW_AT_type that is set to ARG. */
13012 tmpl_type = TYPE_P (arg) ? arg : TREE_TYPE (arg);
13013 add_type_attribute (tmpl_die, tmpl_type, 0,
13014 TREE_THIS_VOLATILE (tmpl_type),
13015 parent_die);
13017 else
13019 /* So TMPL_DIE is a DIE representing a
13020 a generic generic template parameter, a.k.a template template
13021 parameter in C++ and arg is a template. */
13023 /* The DW_AT_GNU_template_name attribute of the DIE must be set
13024 to the name of the argument. */
13025 name = dwarf2_name (TYPE_P (arg) ? TYPE_NAME (arg) : arg, 1);
13026 if (name)
13027 add_AT_string (tmpl_die, DW_AT_GNU_template_name, name);
13030 if (TREE_CODE (parm) == PARM_DECL)
13031 /* So PARM is a non-type generic parameter.
13032 DWARF3 5.6.8 says we must set a DW_AT_const_value child
13033 attribute of TMPL_DIE which value represents the value
13034 of ARG.
13035 We must be careful here:
13036 The value of ARG might reference some function decls.
13037 We might currently be emitting debug info for a generic
13038 type and types are emitted before function decls, we don't
13039 know if the function decls referenced by ARG will actually be
13040 emitted after cgraph computations.
13041 So must defer the generation of the DW_AT_const_value to
13042 after cgraph is ready. */
13043 append_entry_to_tmpl_value_parm_die_table (tmpl_die, arg);
13046 return tmpl_die;
13049 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
13050 PARM_PACK must be a template parameter pack. The returned DIE
13051 will be child DIE of PARENT_DIE. */
13053 static dw_die_ref
13054 template_parameter_pack_die (tree parm_pack,
13055 tree parm_pack_args,
13056 dw_die_ref parent_die)
13058 dw_die_ref die;
13059 int j;
13061 gcc_assert (parent_die && parm_pack);
13063 die = new_die (DW_TAG_GNU_template_parameter_pack, parent_die, parm_pack);
13064 add_name_and_src_coords_attributes (die, parm_pack);
13065 for (j = 0; j < TREE_VEC_LENGTH (parm_pack_args); j++)
13066 generic_parameter_die (parm_pack,
13067 TREE_VEC_ELT (parm_pack_args, j),
13068 false /* Don't emit DW_AT_name */,
13069 die);
13070 return die;
13073 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
13074 an enumerated type. */
13076 static inline int
13077 type_is_enum (const_tree type)
13079 return TREE_CODE (type) == ENUMERAL_TYPE;
13082 /* Return the DBX register number described by a given RTL node. */
13084 static unsigned int
13085 dbx_reg_number (const_rtx rtl)
13087 unsigned regno = REGNO (rtl);
13089 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
13091 #ifdef LEAF_REG_REMAP
13092 if (current_function_uses_only_leaf_regs)
13094 int leaf_reg = LEAF_REG_REMAP (regno);
13095 if (leaf_reg != -1)
13096 regno = (unsigned) leaf_reg;
13098 #endif
13100 return DBX_REGISTER_NUMBER (regno);
13103 /* Optionally add a DW_OP_piece term to a location description expression.
13104 DW_OP_piece is only added if the location description expression already
13105 doesn't end with DW_OP_piece. */
13107 static void
13108 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
13110 dw_loc_descr_ref loc;
13112 if (*list_head != NULL)
13114 /* Find the end of the chain. */
13115 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
13118 if (loc->dw_loc_opc != DW_OP_piece)
13119 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
13123 /* Return a location descriptor that designates a machine register or
13124 zero if there is none. */
13126 static dw_loc_descr_ref
13127 reg_loc_descriptor (rtx rtl, enum var_init_status initialized)
13129 rtx regs;
13131 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
13132 return 0;
13134 /* We only use "frame base" when we're sure we're talking about the
13135 post-prologue local stack frame. We do this by *not* running
13136 register elimination until this point, and recognizing the special
13137 argument pointer and soft frame pointer rtx's.
13138 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
13139 if ((rtl == arg_pointer_rtx || rtl == frame_pointer_rtx)
13140 && eliminate_regs (rtl, VOIDmode, NULL_RTX) != rtl)
13142 dw_loc_descr_ref result = NULL;
13144 if (dwarf_version >= 4 || !dwarf_strict)
13146 result = mem_loc_descriptor (rtl, VOIDmode, initialized);
13147 if (result)
13148 add_loc_descr (&result,
13149 new_loc_descr (DW_OP_stack_value, 0, 0));
13151 return result;
13154 regs = targetm.dwarf_register_span (rtl);
13156 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1 || regs)
13157 return multiple_reg_loc_descriptor (rtl, regs, initialized);
13158 else
13159 return one_reg_loc_descriptor (dbx_reg_number (rtl), initialized);
13162 /* Return a location descriptor that designates a machine register for
13163 a given hard register number. */
13165 static dw_loc_descr_ref
13166 one_reg_loc_descriptor (unsigned int regno, enum var_init_status initialized)
13168 dw_loc_descr_ref reg_loc_descr;
13170 if (regno <= 31)
13171 reg_loc_descr
13172 = new_loc_descr ((enum dwarf_location_atom) (DW_OP_reg0 + regno), 0, 0);
13173 else
13174 reg_loc_descr = new_loc_descr (DW_OP_regx, regno, 0);
13176 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13177 add_loc_descr (&reg_loc_descr, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13179 return reg_loc_descr;
13182 /* Given an RTL of a register, return a location descriptor that
13183 designates a value that spans more than one register. */
13185 static dw_loc_descr_ref
13186 multiple_reg_loc_descriptor (rtx rtl, rtx regs,
13187 enum var_init_status initialized)
13189 int nregs, size, i;
13190 unsigned reg;
13191 dw_loc_descr_ref loc_result = NULL;
13193 reg = REGNO (rtl);
13194 #ifdef LEAF_REG_REMAP
13195 if (current_function_uses_only_leaf_regs)
13197 int leaf_reg = LEAF_REG_REMAP (reg);
13198 if (leaf_reg != -1)
13199 reg = (unsigned) leaf_reg;
13201 #endif
13202 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg) == dbx_reg_number (rtl));
13203 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
13205 /* Simple, contiguous registers. */
13206 if (regs == NULL_RTX)
13208 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
13210 loc_result = NULL;
13211 while (nregs--)
13213 dw_loc_descr_ref t;
13215 t = one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg),
13216 VAR_INIT_STATUS_INITIALIZED);
13217 add_loc_descr (&loc_result, t);
13218 add_loc_descr_op_piece (&loc_result, size);
13219 ++reg;
13221 return loc_result;
13224 /* Now onto stupid register sets in non contiguous locations. */
13226 gcc_assert (GET_CODE (regs) == PARALLEL);
13228 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13229 loc_result = NULL;
13231 for (i = 0; i < XVECLEN (regs, 0); ++i)
13233 dw_loc_descr_ref t;
13235 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)),
13236 VAR_INIT_STATUS_INITIALIZED);
13237 add_loc_descr (&loc_result, t);
13238 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
13239 add_loc_descr_op_piece (&loc_result, size);
13242 if (loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
13243 add_loc_descr (&loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13244 return loc_result;
13247 /* Return a location descriptor that designates a constant. */
13249 static dw_loc_descr_ref
13250 int_loc_descriptor (HOST_WIDE_INT i)
13252 enum dwarf_location_atom op;
13254 /* Pick the smallest representation of a constant, rather than just
13255 defaulting to the LEB encoding. */
13256 if (i >= 0)
13258 if (i <= 31)
13259 op = (enum dwarf_location_atom) (DW_OP_lit0 + i);
13260 else if (i <= 0xff)
13261 op = DW_OP_const1u;
13262 else if (i <= 0xffff)
13263 op = DW_OP_const2u;
13264 else if (HOST_BITS_PER_WIDE_INT == 32
13265 || i <= 0xffffffff)
13266 op = DW_OP_const4u;
13267 else
13268 op = DW_OP_constu;
13270 else
13272 if (i >= -0x80)
13273 op = DW_OP_const1s;
13274 else if (i >= -0x8000)
13275 op = DW_OP_const2s;
13276 else if (HOST_BITS_PER_WIDE_INT == 32
13277 || i >= -0x80000000)
13278 op = DW_OP_const4s;
13279 else
13280 op = DW_OP_consts;
13283 return new_loc_descr (op, i, 0);
13286 /* Return loc description representing "address" of integer value.
13287 This can appear only as toplevel expression. */
13289 static dw_loc_descr_ref
13290 address_of_int_loc_descriptor (int size, HOST_WIDE_INT i)
13292 int litsize;
13293 dw_loc_descr_ref loc_result = NULL;
13295 if (!(dwarf_version >= 4 || !dwarf_strict))
13296 return NULL;
13298 if (i >= 0)
13300 if (i <= 31)
13301 litsize = 1;
13302 else if (i <= 0xff)
13303 litsize = 2;
13304 else if (i <= 0xffff)
13305 litsize = 3;
13306 else if (HOST_BITS_PER_WIDE_INT == 32
13307 || i <= 0xffffffff)
13308 litsize = 5;
13309 else
13310 litsize = 1 + size_of_uleb128 ((unsigned HOST_WIDE_INT) i);
13312 else
13314 if (i >= -0x80)
13315 litsize = 2;
13316 else if (i >= -0x8000)
13317 litsize = 3;
13318 else if (HOST_BITS_PER_WIDE_INT == 32
13319 || i >= -0x80000000)
13320 litsize = 5;
13321 else
13322 litsize = 1 + size_of_sleb128 (i);
13324 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
13325 is more compact. For DW_OP_stack_value we need:
13326 litsize + 1 (DW_OP_stack_value)
13327 and for DW_OP_implicit_value:
13328 1 (DW_OP_implicit_value) + 1 (length) + size. */
13329 if ((int) DWARF2_ADDR_SIZE >= size && litsize + 1 <= 1 + 1 + size)
13331 loc_result = int_loc_descriptor (i);
13332 add_loc_descr (&loc_result,
13333 new_loc_descr (DW_OP_stack_value, 0, 0));
13334 return loc_result;
13337 loc_result = new_loc_descr (DW_OP_implicit_value,
13338 size, 0);
13339 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const;
13340 loc_result->dw_loc_oprnd2.v.val_int = i;
13341 return loc_result;
13344 /* Return a location descriptor that designates a base+offset location. */
13346 static dw_loc_descr_ref
13347 based_loc_descr (rtx reg, HOST_WIDE_INT offset,
13348 enum var_init_status initialized)
13350 unsigned int regno;
13351 dw_loc_descr_ref result;
13352 dw_fde_ref fde = current_fde ();
13354 /* We only use "frame base" when we're sure we're talking about the
13355 post-prologue local stack frame. We do this by *not* running
13356 register elimination until this point, and recognizing the special
13357 argument pointer and soft frame pointer rtx's. */
13358 if (reg == arg_pointer_rtx || reg == frame_pointer_rtx)
13360 rtx elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
13362 if (elim != reg)
13364 if (GET_CODE (elim) == PLUS)
13366 offset += INTVAL (XEXP (elim, 1));
13367 elim = XEXP (elim, 0);
13369 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
13370 && (elim == hard_frame_pointer_rtx
13371 || elim == stack_pointer_rtx))
13372 || elim == (frame_pointer_needed
13373 ? hard_frame_pointer_rtx
13374 : stack_pointer_rtx));
13376 /* If drap register is used to align stack, use frame
13377 pointer + offset to access stack variables. If stack
13378 is aligned without drap, use stack pointer + offset to
13379 access stack variables. */
13380 if (crtl->stack_realign_tried
13381 && reg == frame_pointer_rtx)
13383 int base_reg
13384 = DWARF_FRAME_REGNUM ((fde && fde->drap_reg != INVALID_REGNUM)
13385 ? HARD_FRAME_POINTER_REGNUM
13386 : STACK_POINTER_REGNUM);
13387 return new_reg_loc_descr (base_reg, offset);
13390 offset += frame_pointer_fb_offset;
13391 return new_loc_descr (DW_OP_fbreg, offset, 0);
13394 else if (!optimize
13395 && fde
13396 && (fde->drap_reg == REGNO (reg)
13397 || fde->vdrap_reg == REGNO (reg)))
13399 /* Use cfa+offset to represent the location of arguments passed
13400 on the stack when drap is used to align stack.
13401 Only do this when not optimizing, for optimized code var-tracking
13402 is supposed to track where the arguments live and the register
13403 used as vdrap or drap in some spot might be used for something
13404 else in other part of the routine. */
13405 return new_loc_descr (DW_OP_fbreg, offset, 0);
13408 regno = dbx_reg_number (reg);
13409 if (regno <= 31)
13410 result = new_loc_descr ((enum dwarf_location_atom) (DW_OP_breg0 + regno),
13411 offset, 0);
13412 else
13413 result = new_loc_descr (DW_OP_bregx, regno, offset);
13415 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
13416 add_loc_descr (&result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
13418 return result;
13421 /* Return true if this RTL expression describes a base+offset calculation. */
13423 static inline int
13424 is_based_loc (const_rtx rtl)
13426 return (GET_CODE (rtl) == PLUS
13427 && ((REG_P (XEXP (rtl, 0))
13428 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
13429 && CONST_INT_P (XEXP (rtl, 1)))));
13432 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
13433 failed. */
13435 static dw_loc_descr_ref
13436 tls_mem_loc_descriptor (rtx mem)
13438 tree base;
13439 dw_loc_descr_ref loc_result;
13441 if (MEM_EXPR (mem) == NULL_TREE || MEM_OFFSET (mem) == NULL_RTX)
13442 return NULL;
13444 base = get_base_address (MEM_EXPR (mem));
13445 if (base == NULL
13446 || TREE_CODE (base) != VAR_DECL
13447 || !DECL_THREAD_LOCAL_P (base))
13448 return NULL;
13450 loc_result = loc_descriptor_from_tree (MEM_EXPR (mem), 1);
13451 if (loc_result == NULL)
13452 return NULL;
13454 if (INTVAL (MEM_OFFSET (mem)))
13455 loc_descr_plus_const (&loc_result, INTVAL (MEM_OFFSET (mem)));
13457 return loc_result;
13460 /* Output debug info about reason why we failed to expand expression as dwarf
13461 expression. */
13463 static void
13464 expansion_failed (tree expr, rtx rtl, char const *reason)
13466 if (dump_file && (dump_flags & TDF_DETAILS))
13468 fprintf (dump_file, "Failed to expand as dwarf: ");
13469 if (expr)
13470 print_generic_expr (dump_file, expr, dump_flags);
13471 if (rtl)
13473 fprintf (dump_file, "\n");
13474 print_rtl (dump_file, rtl);
13476 fprintf (dump_file, "\nReason: %s\n", reason);
13480 /* Helper function for const_ok_for_output, called either directly
13481 or via for_each_rtx. */
13483 static int
13484 const_ok_for_output_1 (rtx *rtlp, void *data ATTRIBUTE_UNUSED)
13486 rtx rtl = *rtlp;
13488 if (GET_CODE (rtl) == UNSPEC)
13490 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
13491 we can't express it in the debug info. */
13492 #ifdef ENABLE_CHECKING
13493 /* Don't complain about TLS UNSPECs, those are just too hard to
13494 delegitimize. */
13495 if (XVECLEN (rtl, 0) != 1
13496 || GET_CODE (XVECEXP (rtl, 0, 0)) != SYMBOL_REF
13497 || SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0)) == NULL
13498 || TREE_CODE (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))) != VAR_DECL
13499 || !DECL_THREAD_LOCAL_P (SYMBOL_REF_DECL (XVECEXP (rtl, 0, 0))))
13500 inform (current_function_decl
13501 ? DECL_SOURCE_LOCATION (current_function_decl)
13502 : UNKNOWN_LOCATION,
13503 #if NUM_UNSPEC_VALUES > 0
13504 "non-delegitimized UNSPEC %s (%d) found in variable location",
13505 ((XINT (rtl, 1) >= 0 && XINT (rtl, 1) < NUM_UNSPEC_VALUES)
13506 ? unspec_strings[XINT (rtl, 1)] : "unknown"),
13507 XINT (rtl, 1));
13508 #else
13509 "non-delegitimized UNSPEC %d found in variable location",
13510 XINT (rtl, 1));
13511 #endif
13512 #endif
13513 expansion_failed (NULL_TREE, rtl,
13514 "UNSPEC hasn't been delegitimized.\n");
13515 return 1;
13518 if (GET_CODE (rtl) != SYMBOL_REF)
13519 return 0;
13521 if (CONSTANT_POOL_ADDRESS_P (rtl))
13523 bool marked;
13524 get_pool_constant_mark (rtl, &marked);
13525 /* If all references to this pool constant were optimized away,
13526 it was not output and thus we can't represent it. */
13527 if (!marked)
13529 expansion_failed (NULL_TREE, rtl,
13530 "Constant was removed from constant pool.\n");
13531 return 1;
13535 if (SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13536 return 1;
13538 /* Avoid references to external symbols in debug info, on several targets
13539 the linker might even refuse to link when linking a shared library,
13540 and in many other cases the relocations for .debug_info/.debug_loc are
13541 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
13542 to be defined within the same shared library or executable are fine. */
13543 if (SYMBOL_REF_EXTERNAL_P (rtl))
13545 tree decl = SYMBOL_REF_DECL (rtl);
13547 if (decl == NULL || !targetm.binds_local_p (decl))
13549 expansion_failed (NULL_TREE, rtl,
13550 "Symbol not defined in current TU.\n");
13551 return 1;
13555 return 0;
13558 /* Return true if constant RTL can be emitted in DW_OP_addr or
13559 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
13560 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
13562 static bool
13563 const_ok_for_output (rtx rtl)
13565 if (GET_CODE (rtl) == SYMBOL_REF)
13566 return const_ok_for_output_1 (&rtl, NULL) == 0;
13568 if (GET_CODE (rtl) == CONST)
13569 return for_each_rtx (&XEXP (rtl, 0), const_ok_for_output_1, NULL) == 0;
13571 return true;
13574 /* The following routine converts the RTL for a variable or parameter
13575 (resident in memory) into an equivalent Dwarf representation of a
13576 mechanism for getting the address of that same variable onto the top of a
13577 hypothetical "address evaluation" stack.
13579 When creating memory location descriptors, we are effectively transforming
13580 the RTL for a memory-resident object into its Dwarf postfix expression
13581 equivalent. This routine recursively descends an RTL tree, turning
13582 it into Dwarf postfix code as it goes.
13584 MODE is the mode of the memory reference, needed to handle some
13585 autoincrement addressing modes.
13587 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the
13588 location list for RTL.
13590 Return 0 if we can't represent the location. */
13592 static dw_loc_descr_ref
13593 mem_loc_descriptor (rtx rtl, enum machine_mode mode,
13594 enum var_init_status initialized)
13596 dw_loc_descr_ref mem_loc_result = NULL;
13597 enum dwarf_location_atom op;
13598 dw_loc_descr_ref op0, op1;
13600 /* Note that for a dynamically sized array, the location we will generate a
13601 description of here will be the lowest numbered location which is
13602 actually within the array. That's *not* necessarily the same as the
13603 zeroth element of the array. */
13605 rtl = targetm.delegitimize_address (rtl);
13607 switch (GET_CODE (rtl))
13609 case POST_INC:
13610 case POST_DEC:
13611 case POST_MODIFY:
13612 return mem_loc_descriptor (XEXP (rtl, 0), mode, initialized);
13614 case SUBREG:
13615 /* The case of a subreg may arise when we have a local (register)
13616 variable or a formal (register) parameter which doesn't quite fill
13617 up an entire register. For now, just assume that it is
13618 legitimate to make the Dwarf info refer to the whole register which
13619 contains the given subreg. */
13620 if (!subreg_lowpart_p (rtl))
13621 break;
13622 rtl = SUBREG_REG (rtl);
13623 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13624 break;
13625 if (GET_MODE_CLASS (GET_MODE (rtl)) != MODE_INT)
13626 break;
13627 mem_loc_result = mem_loc_descriptor (rtl, mode, initialized);
13628 break;
13630 case REG:
13631 /* Whenever a register number forms a part of the description of the
13632 method for calculating the (dynamic) address of a memory resident
13633 object, DWARF rules require the register number be referred to as
13634 a "base register". This distinction is not based in any way upon
13635 what category of register the hardware believes the given register
13636 belongs to. This is strictly DWARF terminology we're dealing with
13637 here. Note that in cases where the location of a memory-resident
13638 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13639 OP_CONST (0)) the actual DWARF location descriptor that we generate
13640 may just be OP_BASEREG (basereg). This may look deceptively like
13641 the object in question was allocated to a register (rather than in
13642 memory) so DWARF consumers need to be aware of the subtle
13643 distinction between OP_REG and OP_BASEREG. */
13644 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
13645 mem_loc_result = based_loc_descr (rtl, 0, VAR_INIT_STATUS_INITIALIZED);
13646 else if (stack_realign_drap
13647 && crtl->drap_reg
13648 && crtl->args.internal_arg_pointer == rtl
13649 && REGNO (crtl->drap_reg) < FIRST_PSEUDO_REGISTER)
13651 /* If RTL is internal_arg_pointer, which has been optimized
13652 out, use DRAP instead. */
13653 mem_loc_result = based_loc_descr (crtl->drap_reg, 0,
13654 VAR_INIT_STATUS_INITIALIZED);
13656 break;
13658 case SIGN_EXTEND:
13659 case ZERO_EXTEND:
13660 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13661 VAR_INIT_STATUS_INITIALIZED);
13662 if (op0 == 0)
13663 break;
13664 else
13666 int shift = DWARF2_ADDR_SIZE
13667 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
13668 shift *= BITS_PER_UNIT;
13669 if (GET_CODE (rtl) == SIGN_EXTEND)
13670 op = DW_OP_shra;
13671 else
13672 op = DW_OP_shr;
13673 mem_loc_result = op0;
13674 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13675 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
13676 add_loc_descr (&mem_loc_result, int_loc_descriptor (shift));
13677 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13679 break;
13681 case MEM:
13682 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
13683 VAR_INIT_STATUS_INITIALIZED);
13684 if (mem_loc_result == NULL)
13685 mem_loc_result = tls_mem_loc_descriptor (rtl);
13686 if (mem_loc_result != 0)
13688 if (GET_MODE_SIZE (GET_MODE (rtl)) > DWARF2_ADDR_SIZE)
13690 expansion_failed (NULL_TREE, rtl, "DWARF address size mismatch");
13691 return 0;
13693 else if (GET_MODE_SIZE (GET_MODE (rtl)) == DWARF2_ADDR_SIZE)
13694 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
13695 else
13696 add_loc_descr (&mem_loc_result,
13697 new_loc_descr (DW_OP_deref_size,
13698 GET_MODE_SIZE (GET_MODE (rtl)), 0));
13700 else
13702 rtx new_rtl = avoid_constant_pool_reference (rtl);
13703 if (new_rtl != rtl)
13704 return mem_loc_descriptor (new_rtl, mode, initialized);
13706 break;
13708 case LO_SUM:
13709 return mem_loc_descriptor (XEXP (rtl, 1), mode, initialized);
13711 case LABEL_REF:
13712 /* Some ports can transform a symbol ref into a label ref, because
13713 the symbol ref is too far away and has to be dumped into a constant
13714 pool. */
13715 case CONST:
13716 case SYMBOL_REF:
13717 if (GET_CODE (rtl) == SYMBOL_REF
13718 && SYMBOL_REF_TLS_MODEL (rtl) != TLS_MODEL_NONE)
13720 dw_loc_descr_ref temp;
13722 /* If this is not defined, we have no way to emit the data. */
13723 if (!targetm.have_tls || !targetm.asm_out.output_dwarf_dtprel)
13724 break;
13726 /* We used to emit DW_OP_addr here, but that's wrong, since
13727 DW_OP_addr should be relocated by the debug info consumer,
13728 while DW_OP_GNU_push_tls_address operand should not. */
13729 temp = new_loc_descr (DWARF2_ADDR_SIZE == 4
13730 ? DW_OP_const4u : DW_OP_const8u, 0, 0);
13731 temp->dw_loc_oprnd1.val_class = dw_val_class_addr;
13732 temp->dw_loc_oprnd1.v.val_addr = rtl;
13733 temp->dtprel = true;
13735 mem_loc_result = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
13736 add_loc_descr (&mem_loc_result, temp);
13738 break;
13741 if (!const_ok_for_output (rtl))
13742 break;
13744 symref:
13745 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
13746 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
13747 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
13748 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
13749 break;
13751 case CONCAT:
13752 case CONCATN:
13753 case VAR_LOCATION:
13754 case DEBUG_IMPLICIT_PTR:
13755 expansion_failed (NULL_TREE, rtl,
13756 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13757 return 0;
13759 case ENTRY_VALUE:
13760 if (dwarf_strict)
13761 return NULL;
13762 mem_loc_result = new_loc_descr (DW_OP_GNU_entry_value, 0, 0);
13763 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_loc;
13764 if (REG_P (ENTRY_VALUE_EXP (rtl)))
13765 mem_loc_result->dw_loc_oprnd1.v.val_loc
13766 = one_reg_loc_descriptor (dbx_reg_number (ENTRY_VALUE_EXP (rtl)),
13767 VAR_INIT_STATUS_INITIALIZED);
13768 else if (MEM_P (ENTRY_VALUE_EXP (rtl)) && REG_P (XEXP (ENTRY_VALUE_EXP (rtl), 0)))
13770 dw_loc_descr_ref ref
13771 = mem_loc_descriptor (ENTRY_VALUE_EXP (rtl), GET_MODE (rtl),
13772 VAR_INIT_STATUS_INITIALIZED);
13773 if (ref == NULL || ref->dw_loc_opc == DW_OP_fbreg)
13774 return NULL;
13775 mem_loc_result->dw_loc_oprnd1.v.val_loc = ref;
13777 else
13778 gcc_unreachable ();
13779 return mem_loc_result;
13781 case PRE_MODIFY:
13782 /* Extract the PLUS expression nested inside and fall into
13783 PLUS code below. */
13784 rtl = XEXP (rtl, 1);
13785 goto plus;
13787 case PRE_INC:
13788 case PRE_DEC:
13789 /* Turn these into a PLUS expression and fall into the PLUS code
13790 below. */
13791 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
13792 GEN_INT (GET_CODE (rtl) == PRE_INC
13793 ? GET_MODE_UNIT_SIZE (mode)
13794 : -GET_MODE_UNIT_SIZE (mode)));
13796 /* ... fall through ... */
13798 case PLUS:
13799 plus:
13800 if (is_based_loc (rtl))
13801 mem_loc_result = based_loc_descr (XEXP (rtl, 0),
13802 INTVAL (XEXP (rtl, 1)),
13803 VAR_INIT_STATUS_INITIALIZED);
13804 else
13806 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
13807 VAR_INIT_STATUS_INITIALIZED);
13808 if (mem_loc_result == 0)
13809 break;
13811 if (CONST_INT_P (XEXP (rtl, 1)))
13812 loc_descr_plus_const (&mem_loc_result, INTVAL (XEXP (rtl, 1)));
13813 else
13815 dw_loc_descr_ref mem_loc_result2
13816 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13817 VAR_INIT_STATUS_INITIALIZED);
13818 if (mem_loc_result2 == 0)
13819 break;
13820 add_loc_descr (&mem_loc_result, mem_loc_result2);
13821 add_loc_descr (&mem_loc_result,
13822 new_loc_descr (DW_OP_plus, 0, 0));
13825 break;
13827 /* If a pseudo-reg is optimized away, it is possible for it to
13828 be replaced with a MEM containing a multiply or shift. */
13829 case MINUS:
13830 op = DW_OP_minus;
13831 goto do_binop;
13833 case MULT:
13834 op = DW_OP_mul;
13835 goto do_binop;
13837 case DIV:
13838 op = DW_OP_div;
13839 goto do_binop;
13841 case UMOD:
13842 op = DW_OP_mod;
13843 goto do_binop;
13845 case ASHIFT:
13846 op = DW_OP_shl;
13847 goto do_binop;
13849 case ASHIFTRT:
13850 op = DW_OP_shra;
13851 goto do_binop;
13853 case LSHIFTRT:
13854 op = DW_OP_shr;
13855 goto do_binop;
13857 case AND:
13858 op = DW_OP_and;
13859 goto do_binop;
13861 case IOR:
13862 op = DW_OP_or;
13863 goto do_binop;
13865 case XOR:
13866 op = DW_OP_xor;
13867 goto do_binop;
13869 do_binop:
13870 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13871 VAR_INIT_STATUS_INITIALIZED);
13872 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13873 VAR_INIT_STATUS_INITIALIZED);
13875 if (op0 == 0 || op1 == 0)
13876 break;
13878 mem_loc_result = op0;
13879 add_loc_descr (&mem_loc_result, op1);
13880 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13881 break;
13883 case MOD:
13884 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13885 VAR_INIT_STATUS_INITIALIZED);
13886 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13887 VAR_INIT_STATUS_INITIALIZED);
13889 if (op0 == 0 || op1 == 0)
13890 break;
13892 mem_loc_result = op0;
13893 add_loc_descr (&mem_loc_result, op1);
13894 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13895 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_over, 0, 0));
13896 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_div, 0, 0));
13897 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
13898 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_minus, 0, 0));
13899 break;
13901 case NOT:
13902 op = DW_OP_not;
13903 goto do_unop;
13905 case ABS:
13906 op = DW_OP_abs;
13907 goto do_unop;
13909 case NEG:
13910 op = DW_OP_neg;
13911 goto do_unop;
13913 do_unop:
13914 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13915 VAR_INIT_STATUS_INITIALIZED);
13917 if (op0 == 0)
13918 break;
13920 mem_loc_result = op0;
13921 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
13922 break;
13924 case CONST_INT:
13925 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
13926 break;
13928 case EQ:
13929 op = DW_OP_eq;
13930 goto do_scompare;
13932 case GE:
13933 op = DW_OP_ge;
13934 goto do_scompare;
13936 case GT:
13937 op = DW_OP_gt;
13938 goto do_scompare;
13940 case LE:
13941 op = DW_OP_le;
13942 goto do_scompare;
13944 case LT:
13945 op = DW_OP_lt;
13946 goto do_scompare;
13948 case NE:
13949 op = DW_OP_ne;
13950 goto do_scompare;
13952 do_scompare:
13953 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
13954 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
13955 break;
13956 else
13958 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
13960 if (op_mode == VOIDmode)
13961 op_mode = GET_MODE (XEXP (rtl, 1));
13962 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
13963 break;
13965 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
13966 VAR_INIT_STATUS_INITIALIZED);
13967 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
13968 VAR_INIT_STATUS_INITIALIZED);
13970 if (op0 == 0 || op1 == 0)
13971 break;
13973 if (op_mode != VOIDmode
13974 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
13976 int shift = DWARF2_ADDR_SIZE - GET_MODE_SIZE (op_mode);
13977 shift *= BITS_PER_UNIT;
13978 /* For eq/ne, if the operands are known to be zero-extended,
13979 there is no need to do the fancy shifting up. */
13980 if (op == DW_OP_eq || op == DW_OP_ne)
13982 dw_loc_descr_ref last0, last1;
13983 for (last0 = op0;
13984 last0->dw_loc_next != NULL;
13985 last0 = last0->dw_loc_next)
13987 for (last1 = op1;
13988 last1->dw_loc_next != NULL;
13989 last1 = last1->dw_loc_next)
13991 /* deref_size zero extends, and for constants we can check
13992 whether they are zero extended or not. */
13993 if (((last0->dw_loc_opc == DW_OP_deref_size
13994 && last0->dw_loc_oprnd1.v.val_int
13995 <= GET_MODE_SIZE (op_mode))
13996 || (CONST_INT_P (XEXP (rtl, 0))
13997 && (unsigned HOST_WIDE_INT) INTVAL (XEXP (rtl, 0))
13998 == (INTVAL (XEXP (rtl, 0))
13999 & GET_MODE_MASK (op_mode))))
14000 && ((last1->dw_loc_opc == DW_OP_deref_size
14001 && last1->dw_loc_oprnd1.v.val_int
14002 <= GET_MODE_SIZE (op_mode))
14003 || (CONST_INT_P (XEXP (rtl, 1))
14004 && (unsigned HOST_WIDE_INT)
14005 INTVAL (XEXP (rtl, 1))
14006 == (INTVAL (XEXP (rtl, 1))
14007 & GET_MODE_MASK (op_mode)))))
14008 goto do_compare;
14010 add_loc_descr (&op0, int_loc_descriptor (shift));
14011 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14012 if (CONST_INT_P (XEXP (rtl, 1)))
14013 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) << shift);
14014 else
14016 add_loc_descr (&op1, int_loc_descriptor (shift));
14017 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14022 do_compare:
14023 mem_loc_result = op0;
14024 add_loc_descr (&mem_loc_result, op1);
14025 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14026 if (STORE_FLAG_VALUE != 1)
14028 add_loc_descr (&mem_loc_result,
14029 int_loc_descriptor (STORE_FLAG_VALUE));
14030 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
14032 break;
14034 case GEU:
14035 op = DW_OP_ge;
14036 goto do_ucompare;
14038 case GTU:
14039 op = DW_OP_gt;
14040 goto do_ucompare;
14042 case LEU:
14043 op = DW_OP_le;
14044 goto do_ucompare;
14046 case LTU:
14047 op = DW_OP_lt;
14048 goto do_ucompare;
14050 do_ucompare:
14051 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14052 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 1))) > DWARF2_ADDR_SIZE)
14053 break;
14054 else
14056 enum machine_mode op_mode = GET_MODE (XEXP (rtl, 0));
14058 if (op_mode == VOIDmode)
14059 op_mode = GET_MODE (XEXP (rtl, 1));
14060 if (op_mode != VOIDmode && GET_MODE_CLASS (op_mode) != MODE_INT)
14061 break;
14063 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14064 VAR_INIT_STATUS_INITIALIZED);
14065 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14066 VAR_INIT_STATUS_INITIALIZED);
14068 if (op0 == 0 || op1 == 0)
14069 break;
14071 if (op_mode != VOIDmode
14072 && GET_MODE_SIZE (op_mode) < DWARF2_ADDR_SIZE)
14074 HOST_WIDE_INT mask = GET_MODE_MASK (op_mode);
14075 dw_loc_descr_ref last0, last1;
14076 for (last0 = op0;
14077 last0->dw_loc_next != NULL;
14078 last0 = last0->dw_loc_next)
14080 for (last1 = op1;
14081 last1->dw_loc_next != NULL;
14082 last1 = last1->dw_loc_next)
14084 if (CONST_INT_P (XEXP (rtl, 0)))
14085 op0 = int_loc_descriptor (INTVAL (XEXP (rtl, 0)) & mask);
14086 /* deref_size zero extends, so no need to mask it again. */
14087 else if (last0->dw_loc_opc != DW_OP_deref_size
14088 || last0->dw_loc_oprnd1.v.val_int
14089 > GET_MODE_SIZE (op_mode))
14091 add_loc_descr (&op0, int_loc_descriptor (mask));
14092 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14094 if (CONST_INT_P (XEXP (rtl, 1)))
14095 op1 = int_loc_descriptor (INTVAL (XEXP (rtl, 1)) & mask);
14096 /* deref_size zero extends, so no need to mask it again. */
14097 else if (last1->dw_loc_opc != DW_OP_deref_size
14098 || last1->dw_loc_oprnd1.v.val_int
14099 > GET_MODE_SIZE (op_mode))
14101 add_loc_descr (&op1, int_loc_descriptor (mask));
14102 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14105 else
14107 HOST_WIDE_INT bias = 1;
14108 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14109 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14110 if (CONST_INT_P (XEXP (rtl, 1)))
14111 op1 = int_loc_descriptor ((unsigned HOST_WIDE_INT) bias
14112 + INTVAL (XEXP (rtl, 1)));
14113 else
14114 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst,
14115 bias, 0));
14118 goto do_compare;
14120 case SMIN:
14121 case SMAX:
14122 case UMIN:
14123 case UMAX:
14124 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl, 0))) != MODE_INT
14125 || GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) > DWARF2_ADDR_SIZE
14126 || GET_MODE (XEXP (rtl, 0)) != GET_MODE (XEXP (rtl, 1)))
14127 break;
14129 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14130 VAR_INIT_STATUS_INITIALIZED);
14131 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14132 VAR_INIT_STATUS_INITIALIZED);
14134 if (op0 == 0 || op1 == 0)
14135 break;
14137 add_loc_descr (&op0, new_loc_descr (DW_OP_dup, 0, 0));
14138 add_loc_descr (&op1, new_loc_descr (DW_OP_swap, 0, 0));
14139 add_loc_descr (&op1, new_loc_descr (DW_OP_over, 0, 0));
14140 if (GET_CODE (rtl) == UMIN || GET_CODE (rtl) == UMAX)
14142 if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14144 HOST_WIDE_INT mask = GET_MODE_MASK (GET_MODE (XEXP (rtl, 0)));
14145 add_loc_descr (&op0, int_loc_descriptor (mask));
14146 add_loc_descr (&op0, new_loc_descr (DW_OP_and, 0, 0));
14147 add_loc_descr (&op1, int_loc_descriptor (mask));
14148 add_loc_descr (&op1, new_loc_descr (DW_OP_and, 0, 0));
14150 else
14152 HOST_WIDE_INT bias = 1;
14153 bias <<= (DWARF2_ADDR_SIZE * BITS_PER_UNIT - 1);
14154 add_loc_descr (&op0, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14155 add_loc_descr (&op1, new_loc_descr (DW_OP_plus_uconst, bias, 0));
14158 else if (GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) < DWARF2_ADDR_SIZE)
14160 int shift = DWARF2_ADDR_SIZE
14161 - GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0)));
14162 shift *= BITS_PER_UNIT;
14163 add_loc_descr (&op0, int_loc_descriptor (shift));
14164 add_loc_descr (&op0, new_loc_descr (DW_OP_shl, 0, 0));
14165 add_loc_descr (&op1, int_loc_descriptor (shift));
14166 add_loc_descr (&op1, new_loc_descr (DW_OP_shl, 0, 0));
14169 if (GET_CODE (rtl) == SMIN || GET_CODE (rtl) == UMIN)
14170 op = DW_OP_lt;
14171 else
14172 op = DW_OP_gt;
14173 mem_loc_result = op0;
14174 add_loc_descr (&mem_loc_result, op1);
14175 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14177 dw_loc_descr_ref bra_node, drop_node;
14179 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14180 add_loc_descr (&mem_loc_result, bra_node);
14181 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14182 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14183 add_loc_descr (&mem_loc_result, drop_node);
14184 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14185 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14187 break;
14189 case ZERO_EXTRACT:
14190 case SIGN_EXTRACT:
14191 if (CONST_INT_P (XEXP (rtl, 1))
14192 && CONST_INT_P (XEXP (rtl, 2))
14193 && ((unsigned) INTVAL (XEXP (rtl, 1))
14194 + (unsigned) INTVAL (XEXP (rtl, 2))
14195 <= GET_MODE_BITSIZE (GET_MODE (rtl)))
14196 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14197 && GET_MODE_SIZE (GET_MODE (XEXP (rtl, 0))) <= DWARF2_ADDR_SIZE)
14199 int shift, size;
14200 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14201 VAR_INIT_STATUS_INITIALIZED);
14202 if (op0 == 0)
14203 break;
14204 if (GET_CODE (rtl) == SIGN_EXTRACT)
14205 op = DW_OP_shra;
14206 else
14207 op = DW_OP_shr;
14208 mem_loc_result = op0;
14209 size = INTVAL (XEXP (rtl, 1));
14210 shift = INTVAL (XEXP (rtl, 2));
14211 if (BITS_BIG_ENDIAN)
14212 shift = GET_MODE_BITSIZE (GET_MODE (XEXP (rtl, 0)))
14213 - shift - size;
14214 if (shift + size != (int) DWARF2_ADDR_SIZE)
14216 add_loc_descr (&mem_loc_result,
14217 int_loc_descriptor (DWARF2_ADDR_SIZE
14218 - shift - size));
14219 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_shl, 0, 0));
14221 if (size != (int) DWARF2_ADDR_SIZE)
14223 add_loc_descr (&mem_loc_result,
14224 int_loc_descriptor (DWARF2_ADDR_SIZE - size));
14225 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
14228 break;
14230 case IF_THEN_ELSE:
14232 dw_loc_descr_ref op2, bra_node, drop_node;
14233 op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
14234 VAR_INIT_STATUS_INITIALIZED);
14235 op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
14236 VAR_INIT_STATUS_INITIALIZED);
14237 op2 = mem_loc_descriptor (XEXP (rtl, 2), mode,
14238 VAR_INIT_STATUS_INITIALIZED);
14239 if (op0 == NULL || op1 == NULL || op2 == NULL)
14240 break;
14242 mem_loc_result = op1;
14243 add_loc_descr (&mem_loc_result, op2);
14244 add_loc_descr (&mem_loc_result, op0);
14245 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
14246 add_loc_descr (&mem_loc_result, bra_node);
14247 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_swap, 0, 0));
14248 drop_node = new_loc_descr (DW_OP_drop, 0, 0);
14249 add_loc_descr (&mem_loc_result, drop_node);
14250 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
14251 bra_node->dw_loc_oprnd1.v.val_loc = drop_node;
14253 break;
14255 case COMPARE:
14256 case ROTATE:
14257 case ROTATERT:
14258 case TRUNCATE:
14259 /* In theory, we could implement the above. */
14260 /* DWARF cannot represent the unsigned compare operations
14261 natively. */
14262 case SS_MULT:
14263 case US_MULT:
14264 case SS_DIV:
14265 case US_DIV:
14266 case SS_PLUS:
14267 case US_PLUS:
14268 case SS_MINUS:
14269 case US_MINUS:
14270 case SS_NEG:
14271 case US_NEG:
14272 case SS_ABS:
14273 case SS_ASHIFT:
14274 case US_ASHIFT:
14275 case SS_TRUNCATE:
14276 case US_TRUNCATE:
14277 case UDIV:
14278 case UNORDERED:
14279 case ORDERED:
14280 case UNEQ:
14281 case UNGE:
14282 case UNGT:
14283 case UNLE:
14284 case UNLT:
14285 case LTGT:
14286 case FLOAT_EXTEND:
14287 case FLOAT_TRUNCATE:
14288 case FLOAT:
14289 case UNSIGNED_FLOAT:
14290 case FIX:
14291 case UNSIGNED_FIX:
14292 case FRACT_CONVERT:
14293 case UNSIGNED_FRACT_CONVERT:
14294 case SAT_FRACT:
14295 case UNSIGNED_SAT_FRACT:
14296 case SQRT:
14297 case BSWAP:
14298 case FFS:
14299 case CLZ:
14300 case CTZ:
14301 case POPCOUNT:
14302 case PARITY:
14303 case ASM_OPERANDS:
14304 case VEC_MERGE:
14305 case VEC_SELECT:
14306 case VEC_CONCAT:
14307 case VEC_DUPLICATE:
14308 case UNSPEC:
14309 case HIGH:
14310 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14311 can't express it in the debug info. This can happen e.g. with some
14312 TLS UNSPECs. */
14313 break;
14315 case CONST_STRING:
14316 resolve_one_addr (&rtl, NULL);
14317 goto symref;
14319 default:
14320 #ifdef ENABLE_CHECKING
14321 print_rtl (stderr, rtl);
14322 gcc_unreachable ();
14323 #else
14324 break;
14325 #endif
14328 if (mem_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14329 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14331 return mem_loc_result;
14334 /* Return a descriptor that describes the concatenation of two locations.
14335 This is typically a complex variable. */
14337 static dw_loc_descr_ref
14338 concat_loc_descriptor (rtx x0, rtx x1, enum var_init_status initialized)
14340 dw_loc_descr_ref cc_loc_result = NULL;
14341 dw_loc_descr_ref x0_ref
14342 = loc_descriptor (x0, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14343 dw_loc_descr_ref x1_ref
14344 = loc_descriptor (x1, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14346 if (x0_ref == 0 || x1_ref == 0)
14347 return 0;
14349 cc_loc_result = x0_ref;
14350 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
14352 add_loc_descr (&cc_loc_result, x1_ref);
14353 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
14355 if (initialized == VAR_INIT_STATUS_UNINITIALIZED)
14356 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14358 return cc_loc_result;
14361 /* Return a descriptor that describes the concatenation of N
14362 locations. */
14364 static dw_loc_descr_ref
14365 concatn_loc_descriptor (rtx concatn, enum var_init_status initialized)
14367 unsigned int i;
14368 dw_loc_descr_ref cc_loc_result = NULL;
14369 unsigned int n = XVECLEN (concatn, 0);
14371 for (i = 0; i < n; ++i)
14373 dw_loc_descr_ref ref;
14374 rtx x = XVECEXP (concatn, 0, i);
14376 ref = loc_descriptor (x, VOIDmode, VAR_INIT_STATUS_INITIALIZED);
14377 if (ref == NULL)
14378 return NULL;
14380 add_loc_descr (&cc_loc_result, ref);
14381 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x)));
14384 if (cc_loc_result && initialized == VAR_INIT_STATUS_UNINITIALIZED)
14385 add_loc_descr (&cc_loc_result, new_loc_descr (DW_OP_GNU_uninit, 0, 0));
14387 return cc_loc_result;
14390 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14391 for DEBUG_IMPLICIT_PTR RTL. */
14393 static dw_loc_descr_ref
14394 implicit_ptr_descriptor (rtx rtl, HOST_WIDE_INT offset)
14396 dw_loc_descr_ref ret;
14397 dw_die_ref ref;
14399 if (dwarf_strict)
14400 return NULL;
14401 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == VAR_DECL
14402 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == PARM_DECL
14403 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl)) == RESULT_DECL);
14404 ref = lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl));
14405 ret = new_loc_descr (DW_OP_GNU_implicit_pointer, 0, offset);
14406 ret->dw_loc_oprnd2.val_class = dw_val_class_const;
14407 if (ref)
14409 ret->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
14410 ret->dw_loc_oprnd1.v.val_die_ref.die = ref;
14411 ret->dw_loc_oprnd1.v.val_die_ref.external = 0;
14413 else
14415 ret->dw_loc_oprnd1.val_class = dw_val_class_decl_ref;
14416 ret->dw_loc_oprnd1.v.val_decl_ref = DEBUG_IMPLICIT_PTR_DECL (rtl);
14418 return ret;
14421 /* Output a proper Dwarf location descriptor for a variable or parameter
14422 which is either allocated in a register or in a memory location. For a
14423 register, we just generate an OP_REG and the register number. For a
14424 memory location we provide a Dwarf postfix expression describing how to
14425 generate the (dynamic) address of the object onto the address stack.
14427 MODE is mode of the decl if this loc_descriptor is going to be used in
14428 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14429 allowed, VOIDmode otherwise.
14431 If we don't know how to describe it, return 0. */
14433 static dw_loc_descr_ref
14434 loc_descriptor (rtx rtl, enum machine_mode mode,
14435 enum var_init_status initialized)
14437 dw_loc_descr_ref loc_result = NULL;
14439 switch (GET_CODE (rtl))
14441 case SUBREG:
14442 /* The case of a subreg may arise when we have a local (register)
14443 variable or a formal (register) parameter which doesn't quite fill
14444 up an entire register. For now, just assume that it is
14445 legitimate to make the Dwarf info refer to the whole register which
14446 contains the given subreg. */
14447 loc_result = loc_descriptor (SUBREG_REG (rtl), mode, initialized);
14448 break;
14450 case REG:
14451 loc_result = reg_loc_descriptor (rtl, initialized);
14452 break;
14454 case MEM:
14455 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
14456 initialized);
14457 if (loc_result == NULL)
14458 loc_result = tls_mem_loc_descriptor (rtl);
14459 if (loc_result == NULL)
14461 rtx new_rtl = avoid_constant_pool_reference (rtl);
14462 if (new_rtl != rtl)
14463 loc_result = loc_descriptor (new_rtl, mode, initialized);
14465 break;
14467 case CONCAT:
14468 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
14469 initialized);
14470 break;
14472 case CONCATN:
14473 loc_result = concatn_loc_descriptor (rtl, initialized);
14474 break;
14476 case VAR_LOCATION:
14477 /* Single part. */
14478 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl)) != PARALLEL)
14480 rtx loc = PAT_VAR_LOCATION_LOC (rtl);
14481 if (GET_CODE (loc) == EXPR_LIST)
14482 loc = XEXP (loc, 0);
14483 loc_result = loc_descriptor (loc, mode, initialized);
14484 break;
14487 rtl = XEXP (rtl, 1);
14488 /* FALLTHRU */
14490 case PARALLEL:
14492 rtvec par_elems = XVEC (rtl, 0);
14493 int num_elem = GET_NUM_ELEM (par_elems);
14494 enum machine_mode mode;
14495 int i;
14497 /* Create the first one, so we have something to add to. */
14498 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
14499 VOIDmode, initialized);
14500 if (loc_result == NULL)
14501 return NULL;
14502 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
14503 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14504 for (i = 1; i < num_elem; i++)
14506 dw_loc_descr_ref temp;
14508 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
14509 VOIDmode, initialized);
14510 if (temp == NULL)
14511 return NULL;
14512 add_loc_descr (&loc_result, temp);
14513 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
14514 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
14517 break;
14519 case CONST_INT:
14520 if (mode != VOIDmode && mode != BLKmode)
14521 loc_result = address_of_int_loc_descriptor (GET_MODE_SIZE (mode),
14522 INTVAL (rtl));
14523 break;
14525 case CONST_DOUBLE:
14526 if (mode == VOIDmode)
14527 mode = GET_MODE (rtl);
14529 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14531 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14533 /* Note that a CONST_DOUBLE rtx could represent either an integer
14534 or a floating-point constant. A CONST_DOUBLE is used whenever
14535 the constant requires more than one word in order to be
14536 adequately represented. We output CONST_DOUBLEs as blocks. */
14537 loc_result = new_loc_descr (DW_OP_implicit_value,
14538 GET_MODE_SIZE (mode), 0);
14539 if (SCALAR_FLOAT_MODE_P (mode))
14541 unsigned int length = GET_MODE_SIZE (mode);
14542 unsigned char *array
14543 = (unsigned char*) ggc_alloc_atomic (length);
14545 insert_float (rtl, array);
14546 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14547 loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
14548 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
14549 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14551 else
14553 loc_result->dw_loc_oprnd2.val_class = dw_val_class_const_double;
14554 loc_result->dw_loc_oprnd2.v.val_double
14555 = rtx_to_double_int (rtl);
14558 break;
14560 case CONST_VECTOR:
14561 if (mode == VOIDmode)
14562 mode = GET_MODE (rtl);
14564 if (mode != VOIDmode && (dwarf_version >= 4 || !dwarf_strict))
14566 unsigned int elt_size = GET_MODE_UNIT_SIZE (GET_MODE (rtl));
14567 unsigned int length = CONST_VECTOR_NUNITS (rtl);
14568 unsigned char *array = (unsigned char *)
14569 ggc_alloc_atomic (length * elt_size);
14570 unsigned int i;
14571 unsigned char *p;
14573 gcc_assert (mode == GET_MODE (rtl) || VOIDmode == GET_MODE (rtl));
14574 switch (GET_MODE_CLASS (mode))
14576 case MODE_VECTOR_INT:
14577 for (i = 0, p = array; i < length; i++, p += elt_size)
14579 rtx elt = CONST_VECTOR_ELT (rtl, i);
14580 double_int val = rtx_to_double_int (elt);
14582 if (elt_size <= sizeof (HOST_WIDE_INT))
14583 insert_int (double_int_to_shwi (val), elt_size, p);
14584 else
14586 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
14587 insert_double (val, p);
14590 break;
14592 case MODE_VECTOR_FLOAT:
14593 for (i = 0, p = array; i < length; i++, p += elt_size)
14595 rtx elt = CONST_VECTOR_ELT (rtl, i);
14596 insert_float (elt, p);
14598 break;
14600 default:
14601 gcc_unreachable ();
14604 loc_result = new_loc_descr (DW_OP_implicit_value,
14605 length * elt_size, 0);
14606 loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
14607 loc_result->dw_loc_oprnd2.v.val_vec.length = length;
14608 loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
14609 loc_result->dw_loc_oprnd2.v.val_vec.array = array;
14611 break;
14613 case CONST:
14614 if (mode == VOIDmode
14615 || GET_CODE (XEXP (rtl, 0)) == CONST_INT
14616 || GET_CODE (XEXP (rtl, 0)) == CONST_DOUBLE
14617 || GET_CODE (XEXP (rtl, 0)) == CONST_VECTOR)
14619 loc_result = loc_descriptor (XEXP (rtl, 0), mode, initialized);
14620 break;
14622 /* FALLTHROUGH */
14623 case SYMBOL_REF:
14624 if (!const_ok_for_output (rtl))
14625 break;
14626 case LABEL_REF:
14627 if (mode != VOIDmode && GET_MODE_SIZE (mode) == DWARF2_ADDR_SIZE
14628 && (dwarf_version >= 4 || !dwarf_strict))
14630 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
14631 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
14632 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
14633 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
14634 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
14636 break;
14638 case DEBUG_IMPLICIT_PTR:
14639 loc_result = implicit_ptr_descriptor (rtl, 0);
14640 break;
14642 case PLUS:
14643 if (GET_CODE (XEXP (rtl, 0)) == DEBUG_IMPLICIT_PTR
14644 && CONST_INT_P (XEXP (rtl, 1)))
14646 loc_result
14647 = implicit_ptr_descriptor (XEXP (rtl, 0), INTVAL (XEXP (rtl, 1)));
14648 break;
14650 /* FALLTHRU */
14651 default:
14652 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE (rtl) == mode
14653 && GET_MODE_SIZE (GET_MODE (rtl)) <= DWARF2_ADDR_SIZE
14654 && (dwarf_version >= 4 || !dwarf_strict))
14656 /* Value expression. */
14657 loc_result = mem_loc_descriptor (rtl, VOIDmode, initialized);
14658 if (loc_result)
14659 add_loc_descr (&loc_result,
14660 new_loc_descr (DW_OP_stack_value, 0, 0));
14662 break;
14665 return loc_result;
14668 /* We need to figure out what section we should use as the base for the
14669 address ranges where a given location is valid.
14670 1. If this particular DECL has a section associated with it, use that.
14671 2. If this function has a section associated with it, use that.
14672 3. Otherwise, use the text section.
14673 XXX: If you split a variable across multiple sections, we won't notice. */
14675 static const char *
14676 secname_for_decl (const_tree decl)
14678 const char *secname;
14680 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
14682 tree sectree = DECL_SECTION_NAME (decl);
14683 secname = TREE_STRING_POINTER (sectree);
14685 else if (current_function_decl && DECL_SECTION_NAME (current_function_decl))
14687 tree sectree = DECL_SECTION_NAME (current_function_decl);
14688 secname = TREE_STRING_POINTER (sectree);
14690 else if (cfun && in_cold_section_p)
14691 secname = crtl->subsections.cold_section_label;
14692 else
14693 secname = text_section_label;
14695 return secname;
14698 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14700 static bool
14701 decl_by_reference_p (tree decl)
14703 return ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL
14704 || TREE_CODE (decl) == VAR_DECL)
14705 && DECL_BY_REFERENCE (decl));
14708 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14709 for VARLOC. */
14711 static dw_loc_descr_ref
14712 dw_loc_list_1 (tree loc, rtx varloc, int want_address,
14713 enum var_init_status initialized)
14715 int have_address = 0;
14716 dw_loc_descr_ref descr;
14717 enum machine_mode mode;
14719 if (want_address != 2)
14721 gcc_assert (GET_CODE (varloc) == VAR_LOCATION);
14722 /* Single part. */
14723 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14725 varloc = PAT_VAR_LOCATION_LOC (varloc);
14726 if (GET_CODE (varloc) == EXPR_LIST)
14727 varloc = XEXP (varloc, 0);
14728 mode = GET_MODE (varloc);
14729 if (MEM_P (varloc))
14731 rtx addr = XEXP (varloc, 0);
14732 descr = mem_loc_descriptor (addr, mode, initialized);
14733 if (descr)
14734 have_address = 1;
14735 else
14737 rtx x = avoid_constant_pool_reference (varloc);
14738 if (x != varloc)
14739 descr = mem_loc_descriptor (x, mode, initialized);
14742 else
14743 descr = mem_loc_descriptor (varloc, mode, initialized);
14745 else
14746 return 0;
14748 else
14750 if (GET_CODE (varloc) == VAR_LOCATION)
14751 mode = DECL_MODE (PAT_VAR_LOCATION_DECL (varloc));
14752 else
14753 mode = DECL_MODE (loc);
14754 descr = loc_descriptor (varloc, mode, initialized);
14755 have_address = 1;
14758 if (!descr)
14759 return 0;
14761 if (want_address == 2 && !have_address
14762 && (dwarf_version >= 4 || !dwarf_strict))
14764 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
14766 expansion_failed (loc, NULL_RTX,
14767 "DWARF address size mismatch");
14768 return 0;
14770 add_loc_descr (&descr, new_loc_descr (DW_OP_stack_value, 0, 0));
14771 have_address = 1;
14773 /* Show if we can't fill the request for an address. */
14774 if (want_address && !have_address)
14776 expansion_failed (loc, NULL_RTX,
14777 "Want address and only have value");
14778 return 0;
14781 /* If we've got an address and don't want one, dereference. */
14782 if (!want_address && have_address)
14784 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
14785 enum dwarf_location_atom op;
14787 if (size > DWARF2_ADDR_SIZE || size == -1)
14789 expansion_failed (loc, NULL_RTX,
14790 "DWARF address size mismatch");
14791 return 0;
14793 else if (size == DWARF2_ADDR_SIZE)
14794 op = DW_OP_deref;
14795 else
14796 op = DW_OP_deref_size;
14798 add_loc_descr (&descr, new_loc_descr (op, size, 0));
14801 return descr;
14804 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14805 if it is not possible. */
14807 static dw_loc_descr_ref
14808 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize, HOST_WIDE_INT offset)
14810 if ((bitsize % BITS_PER_UNIT) == 0 && offset == 0)
14811 return new_loc_descr (DW_OP_piece, bitsize / BITS_PER_UNIT, 0);
14812 else if (dwarf_version >= 3 || !dwarf_strict)
14813 return new_loc_descr (DW_OP_bit_piece, bitsize, offset);
14814 else
14815 return NULL;
14818 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14819 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14821 static dw_loc_descr_ref
14822 dw_sra_loc_expr (tree decl, rtx loc)
14824 rtx p;
14825 unsigned int padsize = 0;
14826 dw_loc_descr_ref descr, *descr_tail;
14827 unsigned HOST_WIDE_INT decl_size;
14828 rtx varloc;
14829 enum var_init_status initialized;
14831 if (DECL_SIZE (decl) == NULL
14832 || !host_integerp (DECL_SIZE (decl), 1))
14833 return NULL;
14835 decl_size = tree_low_cst (DECL_SIZE (decl), 1);
14836 descr = NULL;
14837 descr_tail = &descr;
14839 for (p = loc; p; p = XEXP (p, 1))
14841 unsigned int bitsize = decl_piece_bitsize (p);
14842 rtx loc_note = *decl_piece_varloc_ptr (p);
14843 dw_loc_descr_ref cur_descr;
14844 dw_loc_descr_ref *tail, last = NULL;
14845 unsigned int opsize = 0;
14847 if (loc_note == NULL_RTX
14848 || NOTE_VAR_LOCATION_LOC (loc_note) == NULL_RTX)
14850 padsize += bitsize;
14851 continue;
14853 initialized = NOTE_VAR_LOCATION_STATUS (loc_note);
14854 varloc = NOTE_VAR_LOCATION (loc_note);
14855 cur_descr = dw_loc_list_1 (decl, varloc, 2, initialized);
14856 if (cur_descr == NULL)
14858 padsize += bitsize;
14859 continue;
14862 /* Check that cur_descr either doesn't use
14863 DW_OP_*piece operations, or their sum is equal
14864 to bitsize. Otherwise we can't embed it. */
14865 for (tail = &cur_descr; *tail != NULL;
14866 tail = &(*tail)->dw_loc_next)
14867 if ((*tail)->dw_loc_opc == DW_OP_piece)
14869 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned
14870 * BITS_PER_UNIT;
14871 last = *tail;
14873 else if ((*tail)->dw_loc_opc == DW_OP_bit_piece)
14875 opsize += (*tail)->dw_loc_oprnd1.v.val_unsigned;
14876 last = *tail;
14879 if (last != NULL && opsize != bitsize)
14881 padsize += bitsize;
14882 continue;
14885 /* If there is a hole, add DW_OP_*piece after empty DWARF
14886 expression, which means that those bits are optimized out. */
14887 if (padsize)
14889 if (padsize > decl_size)
14890 return NULL;
14891 decl_size -= padsize;
14892 *descr_tail = new_loc_descr_op_bit_piece (padsize, 0);
14893 if (*descr_tail == NULL)
14894 return NULL;
14895 descr_tail = &(*descr_tail)->dw_loc_next;
14896 padsize = 0;
14898 *descr_tail = cur_descr;
14899 descr_tail = tail;
14900 if (bitsize > decl_size)
14901 return NULL;
14902 decl_size -= bitsize;
14903 if (last == NULL)
14905 HOST_WIDE_INT offset = 0;
14906 if (GET_CODE (varloc) == VAR_LOCATION
14907 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc)) != PARALLEL)
14909 varloc = PAT_VAR_LOCATION_LOC (varloc);
14910 if (GET_CODE (varloc) == EXPR_LIST)
14911 varloc = XEXP (varloc, 0);
14915 if (GET_CODE (varloc) == CONST
14916 || GET_CODE (varloc) == SIGN_EXTEND
14917 || GET_CODE (varloc) == ZERO_EXTEND)
14918 varloc = XEXP (varloc, 0);
14919 else if (GET_CODE (varloc) == SUBREG)
14920 varloc = SUBREG_REG (varloc);
14921 else
14922 break;
14924 while (1);
14925 /* DW_OP_bit_size offset should be zero for register
14926 or implicit location descriptions and empty location
14927 descriptions, but for memory addresses needs big endian
14928 adjustment. */
14929 if (MEM_P (varloc))
14931 unsigned HOST_WIDE_INT memsize
14932 = INTVAL (MEM_SIZE (varloc)) * BITS_PER_UNIT;
14933 if (memsize != bitsize)
14935 if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN
14936 && (memsize > BITS_PER_WORD || bitsize > BITS_PER_WORD))
14937 return NULL;
14938 if (memsize < bitsize)
14939 return NULL;
14940 if (BITS_BIG_ENDIAN)
14941 offset = memsize - bitsize;
14945 *descr_tail = new_loc_descr_op_bit_piece (bitsize, offset);
14946 if (*descr_tail == NULL)
14947 return NULL;
14948 descr_tail = &(*descr_tail)->dw_loc_next;
14952 /* If there were any non-empty expressions, add padding till the end of
14953 the decl. */
14954 if (descr != NULL && decl_size != 0)
14956 *descr_tail = new_loc_descr_op_bit_piece (decl_size, 0);
14957 if (*descr_tail == NULL)
14958 return NULL;
14960 return descr;
14963 /* Return the dwarf representation of the location list LOC_LIST of
14964 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14965 function. */
14967 static dw_loc_list_ref
14968 dw_loc_list (var_loc_list *loc_list, tree decl, int want_address)
14970 const char *endname, *secname;
14971 rtx varloc;
14972 enum var_init_status initialized;
14973 struct var_loc_node *node;
14974 dw_loc_descr_ref descr;
14975 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
14976 dw_loc_list_ref list = NULL;
14977 dw_loc_list_ref *listp = &list;
14979 /* Now that we know what section we are using for a base,
14980 actually construct the list of locations.
14981 The first location information is what is passed to the
14982 function that creates the location list, and the remaining
14983 locations just get added on to that list.
14984 Note that we only know the start address for a location
14985 (IE location changes), so to build the range, we use
14986 the range [current location start, next location start].
14987 This means we have to special case the last node, and generate
14988 a range of [last location start, end of function label]. */
14990 secname = secname_for_decl (decl);
14992 for (node = loc_list->first; node; node = node->next)
14993 if (GET_CODE (node->loc) == EXPR_LIST
14994 || NOTE_VAR_LOCATION_LOC (node->loc) != NULL_RTX)
14996 if (GET_CODE (node->loc) == EXPR_LIST)
14998 /* This requires DW_OP_{,bit_}piece, which is not usable
14999 inside DWARF expressions. */
15000 if (want_address != 2)
15001 continue;
15002 descr = dw_sra_loc_expr (decl, node->loc);
15003 if (descr == NULL)
15004 continue;
15006 else
15008 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15009 varloc = NOTE_VAR_LOCATION (node->loc);
15010 descr = dw_loc_list_1 (decl, varloc, want_address, initialized);
15012 if (descr)
15014 bool range_across_switch = false;
15015 /* If section switch happens in between node->label
15016 and node->next->label (or end of function) and
15017 we can't emit it as a single entry list,
15018 emit two ranges, first one ending at the end
15019 of first partition and second one starting at the
15020 beginning of second partition. */
15021 if (node == loc_list->last_before_switch
15022 && (node != loc_list->first || loc_list->first->next)
15023 && current_function_decl)
15025 endname = current_fde ()->dw_fde_end;
15026 range_across_switch = true;
15028 /* The variable has a location between NODE->LABEL and
15029 NODE->NEXT->LABEL. */
15030 else if (node->next)
15031 endname = node->next->label;
15032 /* If the variable has a location at the last label
15033 it keeps its location until the end of function. */
15034 else if (!current_function_decl)
15035 endname = text_end_label;
15036 else
15038 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
15039 current_function_funcdef_no);
15040 endname = ggc_strdup (label_id);
15043 *listp = new_loc_list (descr, node->label, endname, secname);
15044 listp = &(*listp)->dw_loc_next;
15046 if (range_across_switch)
15048 if (GET_CODE (node->loc) == EXPR_LIST)
15049 descr = dw_sra_loc_expr (decl, node->loc);
15050 else
15052 initialized = NOTE_VAR_LOCATION_STATUS (node->loc);
15053 varloc = NOTE_VAR_LOCATION (node->loc);
15054 descr = dw_loc_list_1 (decl, varloc, want_address,
15055 initialized);
15057 gcc_assert (descr);
15058 /* The variable has a location between NODE->LABEL and
15059 NODE->NEXT->LABEL. */
15060 if (node->next)
15061 endname = node->next->label;
15062 else
15063 endname = current_fde ()->dw_fde_second_end;
15064 *listp = new_loc_list (descr,
15065 current_fde ()->dw_fde_second_begin,
15066 endname, secname);
15067 listp = &(*listp)->dw_loc_next;
15072 /* Try to avoid the overhead of a location list emitting a location
15073 expression instead, but only if we didn't have more than one
15074 location entry in the first place. If some entries were not
15075 representable, we don't want to pretend a single entry that was
15076 applies to the entire scope in which the variable is
15077 available. */
15078 if (list && loc_list->first->next)
15079 gen_llsym (list);
15081 return list;
15084 /* Return if the loc_list has only single element and thus can be represented
15085 as location description. */
15087 static bool
15088 single_element_loc_list_p (dw_loc_list_ref list)
15090 gcc_assert (!list->dw_loc_next || list->ll_symbol);
15091 return !list->ll_symbol;
15094 /* To each location in list LIST add loc descr REF. */
15096 static void
15097 add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref)
15099 dw_loc_descr_ref copy;
15100 add_loc_descr (&list->expr, ref);
15101 list = list->dw_loc_next;
15102 while (list)
15104 copy = ggc_alloc_dw_loc_descr_node ();
15105 memcpy (copy, ref, sizeof (dw_loc_descr_node));
15106 add_loc_descr (&list->expr, copy);
15107 while (copy->dw_loc_next)
15109 dw_loc_descr_ref new_copy = ggc_alloc_dw_loc_descr_node ();
15110 memcpy (new_copy, copy->dw_loc_next, sizeof (dw_loc_descr_node));
15111 copy->dw_loc_next = new_copy;
15112 copy = new_copy;
15114 list = list->dw_loc_next;
15118 /* Given two lists RET and LIST
15119 produce location list that is result of adding expression in LIST
15120 to expression in RET on each possition in program.
15121 Might be destructive on both RET and LIST.
15123 TODO: We handle only simple cases of RET or LIST having at most one
15124 element. General case would inolve sorting the lists in program order
15125 and merging them that will need some additional work.
15126 Adding that will improve quality of debug info especially for SRA-ed
15127 structures. */
15129 static void
15130 add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list)
15132 if (!list)
15133 return;
15134 if (!*ret)
15136 *ret = list;
15137 return;
15139 if (!list->dw_loc_next)
15141 add_loc_descr_to_each (*ret, list->expr);
15142 return;
15144 if (!(*ret)->dw_loc_next)
15146 add_loc_descr_to_each (list, (*ret)->expr);
15147 *ret = list;
15148 return;
15150 expansion_failed (NULL_TREE, NULL_RTX,
15151 "Don't know how to merge two non-trivial"
15152 " location lists.\n");
15153 *ret = NULL;
15154 return;
15157 /* LOC is constant expression. Try a luck, look it up in constant
15158 pool and return its loc_descr of its address. */
15160 static dw_loc_descr_ref
15161 cst_pool_loc_descr (tree loc)
15163 /* Get an RTL for this, if something has been emitted. */
15164 rtx rtl = lookup_constant_def (loc);
15165 enum machine_mode mode;
15167 if (!rtl || !MEM_P (rtl))
15169 gcc_assert (!rtl);
15170 return 0;
15172 gcc_assert (GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF);
15174 /* TODO: We might get more coverage if we was actually delaying expansion
15175 of all expressions till end of compilation when constant pools are fully
15176 populated. */
15177 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl, 0))))
15179 expansion_failed (loc, NULL_RTX,
15180 "CST value in contant pool but not marked.");
15181 return 0;
15183 mode = GET_MODE (rtl);
15184 rtl = XEXP (rtl, 0);
15185 return mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15188 /* Return dw_loc_list representing address of addr_expr LOC
15189 by looking for innder INDIRECT_REF expression and turing it
15190 into simple arithmetics. */
15192 static dw_loc_list_ref
15193 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc, bool toplev)
15195 tree obj, offset;
15196 HOST_WIDE_INT bitsize, bitpos, bytepos;
15197 enum machine_mode mode;
15198 int volatilep;
15199 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15200 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15202 obj = get_inner_reference (TREE_OPERAND (loc, 0),
15203 &bitsize, &bitpos, &offset, &mode,
15204 &unsignedp, &volatilep, false);
15205 STRIP_NOPS (obj);
15206 if (bitpos % BITS_PER_UNIT)
15208 expansion_failed (loc, NULL_RTX, "bitfield access");
15209 return 0;
15211 if (!INDIRECT_REF_P (obj))
15213 expansion_failed (obj,
15214 NULL_RTX, "no indirect ref in inner refrence");
15215 return 0;
15217 if (!offset && !bitpos)
15218 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), toplev ? 2 : 1);
15219 else if (toplev
15220 && int_size_in_bytes (TREE_TYPE (loc)) <= DWARF2_ADDR_SIZE
15221 && (dwarf_version >= 4 || !dwarf_strict))
15223 list_ret = loc_list_from_tree (TREE_OPERAND (obj, 0), 0);
15224 if (!list_ret)
15225 return 0;
15226 if (offset)
15228 /* Variable offset. */
15229 list_ret1 = loc_list_from_tree (offset, 0);
15230 if (list_ret1 == 0)
15231 return 0;
15232 add_loc_list (&list_ret, list_ret1);
15233 if (!list_ret)
15234 return 0;
15235 add_loc_descr_to_each (list_ret,
15236 new_loc_descr (DW_OP_plus, 0, 0));
15238 bytepos = bitpos / BITS_PER_UNIT;
15239 if (bytepos > 0)
15240 add_loc_descr_to_each (list_ret,
15241 new_loc_descr (DW_OP_plus_uconst,
15242 bytepos, 0));
15243 else if (bytepos < 0)
15244 loc_list_plus_const (list_ret, bytepos);
15245 add_loc_descr_to_each (list_ret,
15246 new_loc_descr (DW_OP_stack_value, 0, 0));
15248 return list_ret;
15252 /* Generate Dwarf location list representing LOC.
15253 If WANT_ADDRESS is false, expression computing LOC will be computed
15254 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15255 if WANT_ADDRESS is 2, expression computing address useable in location
15256 will be returned (i.e. DW_OP_reg can be used
15257 to refer to register values). */
15259 static dw_loc_list_ref
15260 loc_list_from_tree (tree loc, int want_address)
15262 dw_loc_descr_ref ret = NULL, ret1 = NULL;
15263 dw_loc_list_ref list_ret = NULL, list_ret1 = NULL;
15264 int have_address = 0;
15265 enum dwarf_location_atom op;
15267 /* ??? Most of the time we do not take proper care for sign/zero
15268 extending the values properly. Hopefully this won't be a real
15269 problem... */
15271 switch (TREE_CODE (loc))
15273 case ERROR_MARK:
15274 expansion_failed (loc, NULL_RTX, "ERROR_MARK");
15275 return 0;
15277 case PLACEHOLDER_EXPR:
15278 /* This case involves extracting fields from an object to determine the
15279 position of other fields. We don't try to encode this here. The
15280 only user of this is Ada, which encodes the needed information using
15281 the names of types. */
15282 expansion_failed (loc, NULL_RTX, "PLACEHOLDER_EXPR");
15283 return 0;
15285 case CALL_EXPR:
15286 expansion_failed (loc, NULL_RTX, "CALL_EXPR");
15287 /* There are no opcodes for these operations. */
15288 return 0;
15290 case PREINCREMENT_EXPR:
15291 case PREDECREMENT_EXPR:
15292 case POSTINCREMENT_EXPR:
15293 case POSTDECREMENT_EXPR:
15294 expansion_failed (loc, NULL_RTX, "PRE/POST INDCREMENT/DECREMENT");
15295 /* There are no opcodes for these operations. */
15296 return 0;
15298 case ADDR_EXPR:
15299 /* If we already want an address, see if there is INDIRECT_REF inside
15300 e.g. for &this->field. */
15301 if (want_address)
15303 list_ret = loc_list_for_address_of_addr_expr_of_indirect_ref
15304 (loc, want_address == 2);
15305 if (list_ret)
15306 have_address = 1;
15307 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc, 0))
15308 && (ret = cst_pool_loc_descr (loc)))
15309 have_address = 1;
15311 /* Otherwise, process the argument and look for the address. */
15312 if (!list_ret && !ret)
15313 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 1);
15314 else
15316 if (want_address)
15317 expansion_failed (loc, NULL_RTX, "need address of ADDR_EXPR");
15318 return NULL;
15320 break;
15322 case VAR_DECL:
15323 if (DECL_THREAD_LOCAL_P (loc))
15325 rtx rtl;
15326 enum dwarf_location_atom first_op;
15327 enum dwarf_location_atom second_op;
15328 bool dtprel = false;
15330 if (targetm.have_tls)
15332 /* If this is not defined, we have no way to emit the
15333 data. */
15334 if (!targetm.asm_out.output_dwarf_dtprel)
15335 return 0;
15337 /* The way DW_OP_GNU_push_tls_address is specified, we
15338 can only look up addresses of objects in the current
15339 module. We used DW_OP_addr as first op, but that's
15340 wrong, because DW_OP_addr is relocated by the debug
15341 info consumer, while DW_OP_GNU_push_tls_address
15342 operand shouldn't be. */
15343 if (DECL_EXTERNAL (loc) && !targetm.binds_local_p (loc))
15344 return 0;
15345 first_op = DWARF2_ADDR_SIZE == 4 ? DW_OP_const4u : DW_OP_const8u;
15346 dtprel = true;
15347 second_op = DW_OP_GNU_push_tls_address;
15349 else
15351 if (!targetm.emutls.debug_form_tls_address
15352 || !(dwarf_version >= 3 || !dwarf_strict))
15353 return 0;
15354 /* We stuffed the control variable into the DECL_VALUE_EXPR
15355 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15356 no longer appear in gimple code. We used the control
15357 variable in specific so that we could pick it up here. */
15358 loc = DECL_VALUE_EXPR (loc);
15359 first_op = DW_OP_addr;
15360 second_op = DW_OP_form_tls_address;
15363 rtl = rtl_for_decl_location (loc);
15364 if (rtl == NULL_RTX)
15365 return 0;
15367 if (!MEM_P (rtl))
15368 return 0;
15369 rtl = XEXP (rtl, 0);
15370 if (! CONSTANT_P (rtl))
15371 return 0;
15373 ret = new_loc_descr (first_op, 0, 0);
15374 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15375 ret->dw_loc_oprnd1.v.val_addr = rtl;
15376 ret->dtprel = dtprel;
15378 ret1 = new_loc_descr (second_op, 0, 0);
15379 add_loc_descr (&ret, ret1);
15381 have_address = 1;
15382 break;
15384 /* FALLTHRU */
15386 case PARM_DECL:
15387 case RESULT_DECL:
15388 if (DECL_HAS_VALUE_EXPR_P (loc))
15389 return loc_list_from_tree (DECL_VALUE_EXPR (loc),
15390 want_address);
15391 /* FALLTHRU */
15393 case FUNCTION_DECL:
15395 rtx rtl;
15396 var_loc_list *loc_list = lookup_decl_loc (loc);
15398 if (loc_list && loc_list->first)
15400 list_ret = dw_loc_list (loc_list, loc, want_address);
15401 have_address = want_address != 0;
15402 break;
15404 rtl = rtl_for_decl_location (loc);
15405 if (rtl == NULL_RTX)
15407 expansion_failed (loc, NULL_RTX, "DECL has no RTL");
15408 return 0;
15410 else if (CONST_INT_P (rtl))
15412 HOST_WIDE_INT val = INTVAL (rtl);
15413 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15414 val &= GET_MODE_MASK (DECL_MODE (loc));
15415 ret = int_loc_descriptor (val);
15417 else if (GET_CODE (rtl) == CONST_STRING)
15419 expansion_failed (loc, NULL_RTX, "CONST_STRING");
15420 return 0;
15422 else if (CONSTANT_P (rtl) && const_ok_for_output (rtl))
15424 ret = new_loc_descr (DW_OP_addr, 0, 0);
15425 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
15426 ret->dw_loc_oprnd1.v.val_addr = rtl;
15428 else
15430 enum machine_mode mode;
15432 /* Certain constructs can only be represented at top-level. */
15433 if (want_address == 2)
15435 ret = loc_descriptor (rtl, VOIDmode,
15436 VAR_INIT_STATUS_INITIALIZED);
15437 have_address = 1;
15439 else
15441 mode = GET_MODE (rtl);
15442 if (MEM_P (rtl))
15444 rtl = XEXP (rtl, 0);
15445 have_address = 1;
15447 ret = mem_loc_descriptor (rtl, mode, VAR_INIT_STATUS_INITIALIZED);
15449 if (!ret)
15450 expansion_failed (loc, rtl,
15451 "failed to produce loc descriptor for rtl");
15454 break;
15456 case MEM_REF:
15457 /* ??? FIXME. */
15458 if (!integer_zerop (TREE_OPERAND (loc, 1)))
15459 return 0;
15460 /* Fallthru. */
15461 case INDIRECT_REF:
15462 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15463 have_address = 1;
15464 break;
15466 case COMPOUND_EXPR:
15467 return loc_list_from_tree (TREE_OPERAND (loc, 1), want_address);
15469 CASE_CONVERT:
15470 case VIEW_CONVERT_EXPR:
15471 case SAVE_EXPR:
15472 case MODIFY_EXPR:
15473 return loc_list_from_tree (TREE_OPERAND (loc, 0), want_address);
15475 case COMPONENT_REF:
15476 case BIT_FIELD_REF:
15477 case ARRAY_REF:
15478 case ARRAY_RANGE_REF:
15479 case REALPART_EXPR:
15480 case IMAGPART_EXPR:
15482 tree obj, offset;
15483 HOST_WIDE_INT bitsize, bitpos, bytepos;
15484 enum machine_mode mode;
15485 int volatilep;
15486 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
15488 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
15489 &unsignedp, &volatilep, false);
15491 gcc_assert (obj != loc);
15493 list_ret = loc_list_from_tree (obj,
15494 want_address == 2
15495 && !bitpos && !offset ? 2 : 1);
15496 /* TODO: We can extract value of the small expression via shifting even
15497 for nonzero bitpos. */
15498 if (list_ret == 0)
15499 return 0;
15500 if (bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
15502 expansion_failed (loc, NULL_RTX,
15503 "bitfield access");
15504 return 0;
15507 if (offset != NULL_TREE)
15509 /* Variable offset. */
15510 list_ret1 = loc_list_from_tree (offset, 0);
15511 if (list_ret1 == 0)
15512 return 0;
15513 add_loc_list (&list_ret, list_ret1);
15514 if (!list_ret)
15515 return 0;
15516 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus, 0, 0));
15519 bytepos = bitpos / BITS_PER_UNIT;
15520 if (bytepos > 0)
15521 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
15522 else if (bytepos < 0)
15523 loc_list_plus_const (list_ret, bytepos);
15525 have_address = 1;
15526 break;
15529 case INTEGER_CST:
15530 if ((want_address || !host_integerp (loc, 0))
15531 && (ret = cst_pool_loc_descr (loc)))
15532 have_address = 1;
15533 else if (want_address == 2
15534 && host_integerp (loc, 0)
15535 && (ret = address_of_int_loc_descriptor
15536 (int_size_in_bytes (TREE_TYPE (loc)),
15537 tree_low_cst (loc, 0))))
15538 have_address = 1;
15539 else if (host_integerp (loc, 0))
15540 ret = int_loc_descriptor (tree_low_cst (loc, 0));
15541 else
15543 expansion_failed (loc, NULL_RTX,
15544 "Integer operand is not host integer");
15545 return 0;
15547 break;
15549 case CONSTRUCTOR:
15550 case REAL_CST:
15551 case STRING_CST:
15552 case COMPLEX_CST:
15553 if ((ret = cst_pool_loc_descr (loc)))
15554 have_address = 1;
15555 else
15556 /* We can construct small constants here using int_loc_descriptor. */
15557 expansion_failed (loc, NULL_RTX,
15558 "constructor or constant not in constant pool");
15559 break;
15561 case TRUTH_AND_EXPR:
15562 case TRUTH_ANDIF_EXPR:
15563 case BIT_AND_EXPR:
15564 op = DW_OP_and;
15565 goto do_binop;
15567 case TRUTH_XOR_EXPR:
15568 case BIT_XOR_EXPR:
15569 op = DW_OP_xor;
15570 goto do_binop;
15572 case TRUTH_OR_EXPR:
15573 case TRUTH_ORIF_EXPR:
15574 case BIT_IOR_EXPR:
15575 op = DW_OP_or;
15576 goto do_binop;
15578 case FLOOR_DIV_EXPR:
15579 case CEIL_DIV_EXPR:
15580 case ROUND_DIV_EXPR:
15581 case TRUNC_DIV_EXPR:
15582 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15583 return 0;
15584 op = DW_OP_div;
15585 goto do_binop;
15587 case MINUS_EXPR:
15588 op = DW_OP_minus;
15589 goto do_binop;
15591 case FLOOR_MOD_EXPR:
15592 case CEIL_MOD_EXPR:
15593 case ROUND_MOD_EXPR:
15594 case TRUNC_MOD_EXPR:
15595 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
15597 op = DW_OP_mod;
15598 goto do_binop;
15600 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15601 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15602 if (list_ret == 0 || list_ret1 == 0)
15603 return 0;
15605 add_loc_list (&list_ret, list_ret1);
15606 if (list_ret == 0)
15607 return 0;
15608 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15609 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_over, 0, 0));
15610 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_div, 0, 0));
15611 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_mul, 0, 0));
15612 add_loc_descr_to_each (list_ret, new_loc_descr (DW_OP_minus, 0, 0));
15613 break;
15615 case MULT_EXPR:
15616 op = DW_OP_mul;
15617 goto do_binop;
15619 case LSHIFT_EXPR:
15620 op = DW_OP_shl;
15621 goto do_binop;
15623 case RSHIFT_EXPR:
15624 op = (TYPE_UNSIGNED (TREE_TYPE (loc)) ? DW_OP_shr : DW_OP_shra);
15625 goto do_binop;
15627 case POINTER_PLUS_EXPR:
15628 case PLUS_EXPR:
15629 if (host_integerp (TREE_OPERAND (loc, 1), 0))
15631 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15632 if (list_ret == 0)
15633 return 0;
15635 loc_list_plus_const (list_ret, tree_low_cst (TREE_OPERAND (loc, 1), 0));
15636 break;
15639 op = DW_OP_plus;
15640 goto do_binop;
15642 case LE_EXPR:
15643 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15644 return 0;
15646 op = DW_OP_le;
15647 goto do_binop;
15649 case GE_EXPR:
15650 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15651 return 0;
15653 op = DW_OP_ge;
15654 goto do_binop;
15656 case LT_EXPR:
15657 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15658 return 0;
15660 op = DW_OP_lt;
15661 goto do_binop;
15663 case GT_EXPR:
15664 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
15665 return 0;
15667 op = DW_OP_gt;
15668 goto do_binop;
15670 case EQ_EXPR:
15671 op = DW_OP_eq;
15672 goto do_binop;
15674 case NE_EXPR:
15675 op = DW_OP_ne;
15676 goto do_binop;
15678 do_binop:
15679 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15680 list_ret1 = loc_list_from_tree (TREE_OPERAND (loc, 1), 0);
15681 if (list_ret == 0 || list_ret1 == 0)
15682 return 0;
15684 add_loc_list (&list_ret, list_ret1);
15685 if (list_ret == 0)
15686 return 0;
15687 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15688 break;
15690 case TRUTH_NOT_EXPR:
15691 case BIT_NOT_EXPR:
15692 op = DW_OP_not;
15693 goto do_unop;
15695 case ABS_EXPR:
15696 op = DW_OP_abs;
15697 goto do_unop;
15699 case NEGATE_EXPR:
15700 op = DW_OP_neg;
15701 goto do_unop;
15703 do_unop:
15704 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15705 if (list_ret == 0)
15706 return 0;
15708 add_loc_descr_to_each (list_ret, new_loc_descr (op, 0, 0));
15709 break;
15711 case MIN_EXPR:
15712 case MAX_EXPR:
15714 const enum tree_code code =
15715 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
15717 loc = build3 (COND_EXPR, TREE_TYPE (loc),
15718 build2 (code, integer_type_node,
15719 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
15720 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
15723 /* ... fall through ... */
15725 case COND_EXPR:
15727 dw_loc_descr_ref lhs
15728 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
15729 dw_loc_list_ref rhs
15730 = loc_list_from_tree (TREE_OPERAND (loc, 2), 0);
15731 dw_loc_descr_ref bra_node, jump_node, tmp;
15733 list_ret = loc_list_from_tree (TREE_OPERAND (loc, 0), 0);
15734 if (list_ret == 0 || lhs == 0 || rhs == 0)
15735 return 0;
15737 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
15738 add_loc_descr_to_each (list_ret, bra_node);
15740 add_loc_list (&list_ret, rhs);
15741 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
15742 add_loc_descr_to_each (list_ret, jump_node);
15744 add_loc_descr_to_each (list_ret, lhs);
15745 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15746 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
15748 /* ??? Need a node to point the skip at. Use a nop. */
15749 tmp = new_loc_descr (DW_OP_nop, 0, 0);
15750 add_loc_descr_to_each (list_ret, tmp);
15751 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
15752 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
15754 break;
15756 case FIX_TRUNC_EXPR:
15757 return 0;
15759 default:
15760 /* Leave front-end specific codes as simply unknown. This comes
15761 up, for instance, with the C STMT_EXPR. */
15762 if ((unsigned int) TREE_CODE (loc)
15763 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
15765 expansion_failed (loc, NULL_RTX,
15766 "language specific tree node");
15767 return 0;
15770 #ifdef ENABLE_CHECKING
15771 /* Otherwise this is a generic code; we should just lists all of
15772 these explicitly. We forgot one. */
15773 gcc_unreachable ();
15774 #else
15775 /* In a release build, we want to degrade gracefully: better to
15776 generate incomplete debugging information than to crash. */
15777 return NULL;
15778 #endif
15781 if (!ret && !list_ret)
15782 return 0;
15784 if (want_address == 2 && !have_address
15785 && (dwarf_version >= 4 || !dwarf_strict))
15787 if (int_size_in_bytes (TREE_TYPE (loc)) > DWARF2_ADDR_SIZE)
15789 expansion_failed (loc, NULL_RTX,
15790 "DWARF address size mismatch");
15791 return 0;
15793 if (ret)
15794 add_loc_descr (&ret, new_loc_descr (DW_OP_stack_value, 0, 0));
15795 else
15796 add_loc_descr_to_each (list_ret,
15797 new_loc_descr (DW_OP_stack_value, 0, 0));
15798 have_address = 1;
15800 /* Show if we can't fill the request for an address. */
15801 if (want_address && !have_address)
15803 expansion_failed (loc, NULL_RTX,
15804 "Want address and only have value");
15805 return 0;
15808 gcc_assert (!ret || !list_ret);
15810 /* If we've got an address and don't want one, dereference. */
15811 if (!want_address && have_address)
15813 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
15815 if (size > DWARF2_ADDR_SIZE || size == -1)
15817 expansion_failed (loc, NULL_RTX,
15818 "DWARF address size mismatch");
15819 return 0;
15821 else if (size == DWARF2_ADDR_SIZE)
15822 op = DW_OP_deref;
15823 else
15824 op = DW_OP_deref_size;
15826 if (ret)
15827 add_loc_descr (&ret, new_loc_descr (op, size, 0));
15828 else
15829 add_loc_descr_to_each (list_ret, new_loc_descr (op, size, 0));
15831 if (ret)
15832 list_ret = new_loc_list (ret, NULL, NULL, NULL);
15834 return list_ret;
15837 /* Same as above but return only single location expression. */
15838 static dw_loc_descr_ref
15839 loc_descriptor_from_tree (tree loc, int want_address)
15841 dw_loc_list_ref ret = loc_list_from_tree (loc, want_address);
15842 if (!ret)
15843 return NULL;
15844 if (ret->dw_loc_next)
15846 expansion_failed (loc, NULL_RTX,
15847 "Location list where only loc descriptor needed");
15848 return NULL;
15850 return ret->expr;
15853 /* Given a value, round it up to the lowest multiple of `boundary'
15854 which is not less than the value itself. */
15856 static inline HOST_WIDE_INT
15857 ceiling (HOST_WIDE_INT value, unsigned int boundary)
15859 return (((value + boundary - 1) / boundary) * boundary);
15862 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15863 pointer to the declared type for the relevant field variable, or return
15864 `integer_type_node' if the given node turns out to be an
15865 ERROR_MARK node. */
15867 static inline tree
15868 field_type (const_tree decl)
15870 tree type;
15872 if (TREE_CODE (decl) == ERROR_MARK)
15873 return integer_type_node;
15875 type = DECL_BIT_FIELD_TYPE (decl);
15876 if (type == NULL_TREE)
15877 type = TREE_TYPE (decl);
15879 return type;
15882 /* Given a pointer to a tree node, return the alignment in bits for
15883 it, or else return BITS_PER_WORD if the node actually turns out to
15884 be an ERROR_MARK node. */
15886 static inline unsigned
15887 simple_type_align_in_bits (const_tree type)
15889 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
15892 static inline unsigned
15893 simple_decl_align_in_bits (const_tree decl)
15895 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
15898 /* Return the result of rounding T up to ALIGN. */
15900 static inline double_int
15901 round_up_to_align (double_int t, unsigned int align)
15903 double_int alignd = uhwi_to_double_int (align);
15904 t = double_int_add (t, alignd);
15905 t = double_int_add (t, double_int_minus_one);
15906 t = double_int_div (t, alignd, true, TRUNC_DIV_EXPR);
15907 t = double_int_mul (t, alignd);
15908 return t;
15911 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15912 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15913 or return 0 if we are unable to determine what that offset is, either
15914 because the argument turns out to be a pointer to an ERROR_MARK node, or
15915 because the offset is actually variable. (We can't handle the latter case
15916 just yet). */
15918 static HOST_WIDE_INT
15919 field_byte_offset (const_tree decl)
15921 double_int object_offset_in_bits;
15922 double_int object_offset_in_bytes;
15923 double_int bitpos_int;
15925 if (TREE_CODE (decl) == ERROR_MARK)
15926 return 0;
15928 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
15930 /* We cannot yet cope with fields whose positions are variable, so
15931 for now, when we see such things, we simply return 0. Someday, we may
15932 be able to handle such cases, but it will be damn difficult. */
15933 if (TREE_CODE (bit_position (decl)) != INTEGER_CST)
15934 return 0;
15936 bitpos_int = tree_to_double_int (bit_position (decl));
15938 #ifdef PCC_BITFIELD_TYPE_MATTERS
15939 if (PCC_BITFIELD_TYPE_MATTERS)
15941 tree type;
15942 tree field_size_tree;
15943 double_int deepest_bitpos;
15944 double_int field_size_in_bits;
15945 unsigned int type_align_in_bits;
15946 unsigned int decl_align_in_bits;
15947 double_int type_size_in_bits;
15949 type = field_type (decl);
15950 type_size_in_bits = double_int_type_size_in_bits (type);
15951 type_align_in_bits = simple_type_align_in_bits (type);
15953 field_size_tree = DECL_SIZE (decl);
15955 /* The size could be unspecified if there was an error, or for
15956 a flexible array member. */
15957 if (!field_size_tree)
15958 field_size_tree = bitsize_zero_node;
15960 /* If the size of the field is not constant, use the type size. */
15961 if (TREE_CODE (field_size_tree) == INTEGER_CST)
15962 field_size_in_bits = tree_to_double_int (field_size_tree);
15963 else
15964 field_size_in_bits = type_size_in_bits;
15966 decl_align_in_bits = simple_decl_align_in_bits (decl);
15968 /* The GCC front-end doesn't make any attempt to keep track of the
15969 starting bit offset (relative to the start of the containing
15970 structure type) of the hypothetical "containing object" for a
15971 bit-field. Thus, when computing the byte offset value for the
15972 start of the "containing object" of a bit-field, we must deduce
15973 this information on our own. This can be rather tricky to do in
15974 some cases. For example, handling the following structure type
15975 definition when compiling for an i386/i486 target (which only
15976 aligns long long's to 32-bit boundaries) can be very tricky:
15978 struct S { int field1; long long field2:31; };
15980 Fortunately, there is a simple rule-of-thumb which can be used
15981 in such cases. When compiling for an i386/i486, GCC will
15982 allocate 8 bytes for the structure shown above. It decides to
15983 do this based upon one simple rule for bit-field allocation.
15984 GCC allocates each "containing object" for each bit-field at
15985 the first (i.e. lowest addressed) legitimate alignment boundary
15986 (based upon the required minimum alignment for the declared
15987 type of the field) which it can possibly use, subject to the
15988 condition that there is still enough available space remaining
15989 in the containing object (when allocated at the selected point)
15990 to fully accommodate all of the bits of the bit-field itself.
15992 This simple rule makes it obvious why GCC allocates 8 bytes for
15993 each object of the structure type shown above. When looking
15994 for a place to allocate the "containing object" for `field2',
15995 the compiler simply tries to allocate a 64-bit "containing
15996 object" at each successive 32-bit boundary (starting at zero)
15997 until it finds a place to allocate that 64- bit field such that
15998 at least 31 contiguous (and previously unallocated) bits remain
15999 within that selected 64 bit field. (As it turns out, for the
16000 example above, the compiler finds it is OK to allocate the
16001 "containing object" 64-bit field at bit-offset zero within the
16002 structure type.)
16004 Here we attempt to work backwards from the limited set of facts
16005 we're given, and we try to deduce from those facts, where GCC
16006 must have believed that the containing object started (within
16007 the structure type). The value we deduce is then used (by the
16008 callers of this routine) to generate DW_AT_location and
16009 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16010 the case of DW_AT_location, regular fields as well). */
16012 /* Figure out the bit-distance from the start of the structure to
16013 the "deepest" bit of the bit-field. */
16014 deepest_bitpos = double_int_add (bitpos_int, field_size_in_bits);
16016 /* This is the tricky part. Use some fancy footwork to deduce
16017 where the lowest addressed bit of the containing object must
16018 be. */
16019 object_offset_in_bits
16020 = double_int_sub (deepest_bitpos, type_size_in_bits);
16022 /* Round up to type_align by default. This works best for
16023 bitfields. */
16024 object_offset_in_bits
16025 = round_up_to_align (object_offset_in_bits, type_align_in_bits);
16027 if (double_int_ucmp (object_offset_in_bits, bitpos_int) > 0)
16029 object_offset_in_bits
16030 = double_int_sub (deepest_bitpos, type_size_in_bits);
16032 /* Round up to decl_align instead. */
16033 object_offset_in_bits
16034 = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
16037 else
16038 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16039 object_offset_in_bits = bitpos_int;
16041 object_offset_in_bytes
16042 = double_int_div (object_offset_in_bits,
16043 uhwi_to_double_int (BITS_PER_UNIT), true,
16044 TRUNC_DIV_EXPR);
16045 return double_int_to_shwi (object_offset_in_bytes);
16048 /* The following routines define various Dwarf attributes and any data
16049 associated with them. */
16051 /* Add a location description attribute value to a DIE.
16053 This emits location attributes suitable for whole variables and
16054 whole parameters. Note that the location attributes for struct fields are
16055 generated by the routine `data_member_location_attribute' below. */
16057 static inline void
16058 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
16059 dw_loc_list_ref descr)
16061 if (descr == 0)
16062 return;
16063 if (single_element_loc_list_p (descr))
16064 add_AT_loc (die, attr_kind, descr->expr);
16065 else
16066 add_AT_loc_list (die, attr_kind, descr);
16069 /* Add DW_AT_accessibility attribute to DIE if needed. */
16071 static void
16072 add_accessibility_attribute (dw_die_ref die, tree decl)
16074 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16075 children, otherwise the default is DW_ACCESS_public. In DWARF2
16076 the default has always been DW_ACCESS_public. */
16077 if (TREE_PROTECTED (decl))
16078 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
16079 else if (TREE_PRIVATE (decl))
16081 if (dwarf_version == 2
16082 || die->die_parent == NULL
16083 || die->die_parent->die_tag != DW_TAG_class_type)
16084 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
16086 else if (dwarf_version > 2
16087 && die->die_parent
16088 && die->die_parent->die_tag == DW_TAG_class_type)
16089 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
16092 /* Attach the specialized form of location attribute used for data members of
16093 struct and union types. In the special case of a FIELD_DECL node which
16094 represents a bit-field, the "offset" part of this special location
16095 descriptor must indicate the distance in bytes from the lowest-addressed
16096 byte of the containing struct or union type to the lowest-addressed byte of
16097 the "containing object" for the bit-field. (See the `field_byte_offset'
16098 function above).
16100 For any given bit-field, the "containing object" is a hypothetical object
16101 (of some integral or enum type) within which the given bit-field lives. The
16102 type of this hypothetical "containing object" is always the same as the
16103 declared type of the individual bit-field itself (for GCC anyway... the
16104 DWARF spec doesn't actually mandate this). Note that it is the size (in
16105 bytes) of the hypothetical "containing object" which will be given in the
16106 DW_AT_byte_size attribute for this bit-field. (See the
16107 `byte_size_attribute' function below.) It is also used when calculating the
16108 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16109 function below.) */
16111 static void
16112 add_data_member_location_attribute (dw_die_ref die, tree decl)
16114 HOST_WIDE_INT offset;
16115 dw_loc_descr_ref loc_descr = 0;
16117 if (TREE_CODE (decl) == TREE_BINFO)
16119 /* We're working on the TAG_inheritance for a base class. */
16120 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
16122 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16123 aren't at a fixed offset from all (sub)objects of the same
16124 type. We need to extract the appropriate offset from our
16125 vtable. The following dwarf expression means
16127 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16129 This is specific to the V3 ABI, of course. */
16131 dw_loc_descr_ref tmp;
16133 /* Make a copy of the object address. */
16134 tmp = new_loc_descr (DW_OP_dup, 0, 0);
16135 add_loc_descr (&loc_descr, tmp);
16137 /* Extract the vtable address. */
16138 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16139 add_loc_descr (&loc_descr, tmp);
16141 /* Calculate the address of the offset. */
16142 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
16143 gcc_assert (offset < 0);
16145 tmp = int_loc_descriptor (-offset);
16146 add_loc_descr (&loc_descr, tmp);
16147 tmp = new_loc_descr (DW_OP_minus, 0, 0);
16148 add_loc_descr (&loc_descr, tmp);
16150 /* Extract the offset. */
16151 tmp = new_loc_descr (DW_OP_deref, 0, 0);
16152 add_loc_descr (&loc_descr, tmp);
16154 /* Add it to the object address. */
16155 tmp = new_loc_descr (DW_OP_plus, 0, 0);
16156 add_loc_descr (&loc_descr, tmp);
16158 else
16159 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
16161 else
16162 offset = field_byte_offset (decl);
16164 if (! loc_descr)
16166 if (dwarf_version > 2)
16168 /* Don't need to output a location expression, just the constant. */
16169 if (offset < 0)
16170 add_AT_int (die, DW_AT_data_member_location, offset);
16171 else
16172 add_AT_unsigned (die, DW_AT_data_member_location, offset);
16173 return;
16175 else
16177 enum dwarf_location_atom op;
16179 /* The DWARF2 standard says that we should assume that the structure
16180 address is already on the stack, so we can specify a structure
16181 field address by using DW_OP_plus_uconst. */
16183 #ifdef MIPS_DEBUGGING_INFO
16184 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
16185 operator correctly. It works only if we leave the offset on the
16186 stack. */
16187 op = DW_OP_constu;
16188 #else
16189 op = DW_OP_plus_uconst;
16190 #endif
16192 loc_descr = new_loc_descr (op, offset, 0);
16196 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
16199 /* Writes integer values to dw_vec_const array. */
16201 static void
16202 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
16204 while (size != 0)
16206 *dest++ = val & 0xff;
16207 val >>= 8;
16208 --size;
16212 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16214 static HOST_WIDE_INT
16215 extract_int (const unsigned char *src, unsigned int size)
16217 HOST_WIDE_INT val = 0;
16219 src += size;
16220 while (size != 0)
16222 val <<= 8;
16223 val |= *--src & 0xff;
16224 --size;
16226 return val;
16229 /* Writes double_int values to dw_vec_const array. */
16231 static void
16232 insert_double (double_int val, unsigned char *dest)
16234 unsigned char *p0 = dest;
16235 unsigned char *p1 = dest + sizeof (HOST_WIDE_INT);
16237 if (WORDS_BIG_ENDIAN)
16239 p0 = p1;
16240 p1 = dest;
16243 insert_int ((HOST_WIDE_INT) val.low, sizeof (HOST_WIDE_INT), p0);
16244 insert_int ((HOST_WIDE_INT) val.high, sizeof (HOST_WIDE_INT), p1);
16247 /* Writes floating point values to dw_vec_const array. */
16249 static void
16250 insert_float (const_rtx rtl, unsigned char *array)
16252 REAL_VALUE_TYPE rv;
16253 long val[4];
16254 int i;
16256 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
16257 real_to_target (val, &rv, GET_MODE (rtl));
16259 /* real_to_target puts 32-bit pieces in each long. Pack them. */
16260 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
16262 insert_int (val[i], 4, array);
16263 array += 4;
16267 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
16268 does not have a "location" either in memory or in a register. These
16269 things can arise in GNU C when a constant is passed as an actual parameter
16270 to an inlined function. They can also arise in C++ where declared
16271 constants do not necessarily get memory "homes". */
16273 static bool
16274 add_const_value_attribute (dw_die_ref die, rtx rtl)
16276 switch (GET_CODE (rtl))
16278 case CONST_INT:
16280 HOST_WIDE_INT val = INTVAL (rtl);
16282 if (val < 0)
16283 add_AT_int (die, DW_AT_const_value, val);
16284 else
16285 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
16287 return true;
16289 case CONST_DOUBLE:
16290 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
16291 floating-point constant. A CONST_DOUBLE is used whenever the
16292 constant requires more than one word in order to be adequately
16293 represented. */
16295 enum machine_mode mode = GET_MODE (rtl);
16297 if (SCALAR_FLOAT_MODE_P (mode))
16299 unsigned int length = GET_MODE_SIZE (mode);
16300 unsigned char *array = (unsigned char *) ggc_alloc_atomic (length);
16302 insert_float (rtl, array);
16303 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
16305 else
16306 add_AT_double (die, DW_AT_const_value,
16307 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
16309 return true;
16311 case CONST_VECTOR:
16313 enum machine_mode mode = GET_MODE (rtl);
16314 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
16315 unsigned int length = CONST_VECTOR_NUNITS (rtl);
16316 unsigned char *array = (unsigned char *) ggc_alloc_atomic
16317 (length * elt_size);
16318 unsigned int i;
16319 unsigned char *p;
16321 switch (GET_MODE_CLASS (mode))
16323 case MODE_VECTOR_INT:
16324 for (i = 0, p = array; i < length; i++, p += elt_size)
16326 rtx elt = CONST_VECTOR_ELT (rtl, i);
16327 double_int val = rtx_to_double_int (elt);
16329 if (elt_size <= sizeof (HOST_WIDE_INT))
16330 insert_int (double_int_to_shwi (val), elt_size, p);
16331 else
16333 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
16334 insert_double (val, p);
16337 break;
16339 case MODE_VECTOR_FLOAT:
16340 for (i = 0, p = array; i < length; i++, p += elt_size)
16342 rtx elt = CONST_VECTOR_ELT (rtl, i);
16343 insert_float (elt, p);
16345 break;
16347 default:
16348 gcc_unreachable ();
16351 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
16353 return true;
16355 case CONST_STRING:
16356 if (dwarf_version >= 4 || !dwarf_strict)
16358 dw_loc_descr_ref loc_result;
16359 resolve_one_addr (&rtl, NULL);
16360 rtl_addr:
16361 loc_result = new_loc_descr (DW_OP_addr, 0, 0);
16362 loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
16363 loc_result->dw_loc_oprnd1.v.val_addr = rtl;
16364 add_loc_descr (&loc_result, new_loc_descr (DW_OP_stack_value, 0, 0));
16365 add_AT_loc (die, DW_AT_location, loc_result);
16366 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
16367 return true;
16369 return false;
16371 case CONST:
16372 if (CONSTANT_P (XEXP (rtl, 0)))
16373 return add_const_value_attribute (die, XEXP (rtl, 0));
16374 /* FALLTHROUGH */
16375 case SYMBOL_REF:
16376 if (!const_ok_for_output (rtl))
16377 return false;
16378 case LABEL_REF:
16379 if (dwarf_version >= 4 || !dwarf_strict)
16380 goto rtl_addr;
16381 return false;
16383 case PLUS:
16384 /* In cases where an inlined instance of an inline function is passed
16385 the address of an `auto' variable (which is local to the caller) we
16386 can get a situation where the DECL_RTL of the artificial local
16387 variable (for the inlining) which acts as a stand-in for the
16388 corresponding formal parameter (of the inline function) will look
16389 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
16390 exactly a compile-time constant expression, but it isn't the address
16391 of the (artificial) local variable either. Rather, it represents the
16392 *value* which the artificial local variable always has during its
16393 lifetime. We currently have no way to represent such quasi-constant
16394 values in Dwarf, so for now we just punt and generate nothing. */
16395 return false;
16397 case HIGH:
16398 case CONST_FIXED:
16399 return false;
16401 case MEM:
16402 if (GET_CODE (XEXP (rtl, 0)) == CONST_STRING
16403 && MEM_READONLY_P (rtl)
16404 && GET_MODE (rtl) == BLKmode)
16406 add_AT_string (die, DW_AT_const_value, XSTR (XEXP (rtl, 0), 0));
16407 return true;
16409 return false;
16411 default:
16412 /* No other kinds of rtx should be possible here. */
16413 gcc_unreachable ();
16415 return false;
16418 /* Determine whether the evaluation of EXPR references any variables
16419 or functions which aren't otherwise used (and therefore may not be
16420 output). */
16421 static tree
16422 reference_to_unused (tree * tp, int * walk_subtrees,
16423 void * data ATTRIBUTE_UNUSED)
16425 if (! EXPR_P (*tp) && ! CONSTANT_CLASS_P (*tp))
16426 *walk_subtrees = 0;
16428 if (DECL_P (*tp) && ! TREE_PUBLIC (*tp) && ! TREE_USED (*tp)
16429 && ! TREE_ASM_WRITTEN (*tp))
16430 return *tp;
16431 /* ??? The C++ FE emits debug information for using decls, so
16432 putting gcc_unreachable here falls over. See PR31899. For now
16433 be conservative. */
16434 else if (!cgraph_global_info_ready
16435 && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL))
16436 return *tp;
16437 else if (TREE_CODE (*tp) == VAR_DECL)
16439 struct varpool_node *node = varpool_get_node (*tp);
16440 if (!node || !node->needed)
16441 return *tp;
16443 else if (TREE_CODE (*tp) == FUNCTION_DECL
16444 && (!DECL_EXTERNAL (*tp) || DECL_DECLARED_INLINE_P (*tp)))
16446 /* The call graph machinery must have finished analyzing,
16447 optimizing and gimplifying the CU by now.
16448 So if *TP has no call graph node associated
16449 to it, it means *TP will not be emitted. */
16450 if (!cgraph_get_node (*tp))
16451 return *tp;
16453 else if (TREE_CODE (*tp) == STRING_CST && !TREE_ASM_WRITTEN (*tp))
16454 return *tp;
16456 return NULL_TREE;
16459 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
16460 for use in a later add_const_value_attribute call. */
16462 static rtx
16463 rtl_for_decl_init (tree init, tree type)
16465 rtx rtl = NULL_RTX;
16467 STRIP_NOPS (init);
16469 /* If a variable is initialized with a string constant without embedded
16470 zeros, build CONST_STRING. */
16471 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
16473 tree enttype = TREE_TYPE (type);
16474 tree domain = TYPE_DOMAIN (type);
16475 enum machine_mode mode = TYPE_MODE (enttype);
16477 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
16478 && domain
16479 && integer_zerop (TYPE_MIN_VALUE (domain))
16480 && compare_tree_int (TYPE_MAX_VALUE (domain),
16481 TREE_STRING_LENGTH (init) - 1) == 0
16482 && ((size_t) TREE_STRING_LENGTH (init)
16483 == strlen (TREE_STRING_POINTER (init)) + 1))
16485 rtl = gen_rtx_CONST_STRING (VOIDmode,
16486 ggc_strdup (TREE_STRING_POINTER (init)));
16487 rtl = gen_rtx_MEM (BLKmode, rtl);
16488 MEM_READONLY_P (rtl) = 1;
16491 /* Other aggregates, and complex values, could be represented using
16492 CONCAT: FIXME! */
16493 else if (AGGREGATE_TYPE_P (type)
16494 || (TREE_CODE (init) == VIEW_CONVERT_EXPR
16495 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init, 0))))
16496 || TREE_CODE (type) == COMPLEX_TYPE)
16498 /* Vectors only work if their mode is supported by the target.
16499 FIXME: generic vectors ought to work too. */
16500 else if (TREE_CODE (type) == VECTOR_TYPE
16501 && !VECTOR_MODE_P (TYPE_MODE (type)))
16503 /* If the initializer is something that we know will expand into an
16504 immediate RTL constant, expand it now. We must be careful not to
16505 reference variables which won't be output. */
16506 else if (initializer_constant_valid_p (init, type)
16507 && ! walk_tree (&init, reference_to_unused, NULL, NULL))
16509 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
16510 possible. */
16511 if (TREE_CODE (type) == VECTOR_TYPE)
16512 switch (TREE_CODE (init))
16514 case VECTOR_CST:
16515 break;
16516 case CONSTRUCTOR:
16517 if (TREE_CONSTANT (init))
16519 VEC(constructor_elt,gc) *elts = CONSTRUCTOR_ELTS (init);
16520 bool constant_p = true;
16521 tree value;
16522 unsigned HOST_WIDE_INT ix;
16524 /* Even when ctor is constant, it might contain non-*_CST
16525 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
16526 belong into VECTOR_CST nodes. */
16527 FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
16528 if (!CONSTANT_CLASS_P (value))
16530 constant_p = false;
16531 break;
16534 if (constant_p)
16536 init = build_vector_from_ctor (type, elts);
16537 break;
16540 /* FALLTHRU */
16542 default:
16543 return NULL;
16546 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
16548 /* If expand_expr returns a MEM, it wasn't immediate. */
16549 gcc_assert (!rtl || !MEM_P (rtl));
16552 return rtl;
16555 /* Generate RTL for the variable DECL to represent its location. */
16557 static rtx
16558 rtl_for_decl_location (tree decl)
16560 rtx rtl;
16562 /* Here we have to decide where we are going to say the parameter "lives"
16563 (as far as the debugger is concerned). We only have a couple of
16564 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
16566 DECL_RTL normally indicates where the parameter lives during most of the
16567 activation of the function. If optimization is enabled however, this
16568 could be either NULL or else a pseudo-reg. Both of those cases indicate
16569 that the parameter doesn't really live anywhere (as far as the code
16570 generation parts of GCC are concerned) during most of the function's
16571 activation. That will happen (for example) if the parameter is never
16572 referenced within the function.
16574 We could just generate a location descriptor here for all non-NULL
16575 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
16576 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
16577 where DECL_RTL is NULL or is a pseudo-reg.
16579 Note however that we can only get away with using DECL_INCOMING_RTL as
16580 a backup substitute for DECL_RTL in certain limited cases. In cases
16581 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
16582 we can be sure that the parameter was passed using the same type as it is
16583 declared to have within the function, and that its DECL_INCOMING_RTL
16584 points us to a place where a value of that type is passed.
16586 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
16587 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
16588 because in these cases DECL_INCOMING_RTL points us to a value of some
16589 type which is *different* from the type of the parameter itself. Thus,
16590 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
16591 such cases, the debugger would end up (for example) trying to fetch a
16592 `float' from a place which actually contains the first part of a
16593 `double'. That would lead to really incorrect and confusing
16594 output at debug-time.
16596 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
16597 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
16598 are a couple of exceptions however. On little-endian machines we can
16599 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
16600 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
16601 an integral type that is smaller than TREE_TYPE (decl). These cases arise
16602 when (on a little-endian machine) a non-prototyped function has a
16603 parameter declared to be of type `short' or `char'. In such cases,
16604 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
16605 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
16606 passed `int' value. If the debugger then uses that address to fetch
16607 a `short' or a `char' (on a little-endian machine) the result will be
16608 the correct data, so we allow for such exceptional cases below.
16610 Note that our goal here is to describe the place where the given formal
16611 parameter lives during most of the function's activation (i.e. between the
16612 end of the prologue and the start of the epilogue). We'll do that as best
16613 as we can. Note however that if the given formal parameter is modified
16614 sometime during the execution of the function, then a stack backtrace (at
16615 debug-time) will show the function as having been called with the *new*
16616 value rather than the value which was originally passed in. This happens
16617 rarely enough that it is not a major problem, but it *is* a problem, and
16618 I'd like to fix it.
16620 A future version of dwarf2out.c may generate two additional attributes for
16621 any given DW_TAG_formal_parameter DIE which will describe the "passed
16622 type" and the "passed location" for the given formal parameter in addition
16623 to the attributes we now generate to indicate the "declared type" and the
16624 "active location" for each parameter. This additional set of attributes
16625 could be used by debuggers for stack backtraces. Separately, note that
16626 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
16627 This happens (for example) for inlined-instances of inline function formal
16628 parameters which are never referenced. This really shouldn't be
16629 happening. All PARM_DECL nodes should get valid non-NULL
16630 DECL_INCOMING_RTL values. FIXME. */
16632 /* Use DECL_RTL as the "location" unless we find something better. */
16633 rtl = DECL_RTL_IF_SET (decl);
16635 /* When generating abstract instances, ignore everything except
16636 constants, symbols living in memory, and symbols living in
16637 fixed registers. */
16638 if (! reload_completed)
16640 if (rtl
16641 && (CONSTANT_P (rtl)
16642 || (MEM_P (rtl)
16643 && CONSTANT_P (XEXP (rtl, 0)))
16644 || (REG_P (rtl)
16645 && TREE_CODE (decl) == VAR_DECL
16646 && TREE_STATIC (decl))))
16648 rtl = targetm.delegitimize_address (rtl);
16649 return rtl;
16651 rtl = NULL_RTX;
16653 else if (TREE_CODE (decl) == PARM_DECL)
16655 if (rtl == NULL_RTX
16656 || is_pseudo_reg (rtl)
16657 || (MEM_P (rtl)
16658 && is_pseudo_reg (XEXP (rtl, 0))
16659 && DECL_INCOMING_RTL (decl)
16660 && MEM_P (DECL_INCOMING_RTL (decl))
16661 && GET_MODE (rtl) == GET_MODE (DECL_INCOMING_RTL (decl))))
16663 tree declared_type = TREE_TYPE (decl);
16664 tree passed_type = DECL_ARG_TYPE (decl);
16665 enum machine_mode dmode = TYPE_MODE (declared_type);
16666 enum machine_mode pmode = TYPE_MODE (passed_type);
16668 /* This decl represents a formal parameter which was optimized out.
16669 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
16670 all cases where (rtl == NULL_RTX) just below. */
16671 if (dmode == pmode)
16672 rtl = DECL_INCOMING_RTL (decl);
16673 else if ((rtl == NULL_RTX || is_pseudo_reg (rtl))
16674 && SCALAR_INT_MODE_P (dmode)
16675 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
16676 && DECL_INCOMING_RTL (decl))
16678 rtx inc = DECL_INCOMING_RTL (decl);
16679 if (REG_P (inc))
16680 rtl = inc;
16681 else if (MEM_P (inc))
16683 if (BYTES_BIG_ENDIAN)
16684 rtl = adjust_address_nv (inc, dmode,
16685 GET_MODE_SIZE (pmode)
16686 - GET_MODE_SIZE (dmode));
16687 else
16688 rtl = inc;
16693 /* If the parm was passed in registers, but lives on the stack, then
16694 make a big endian correction if the mode of the type of the
16695 parameter is not the same as the mode of the rtl. */
16696 /* ??? This is the same series of checks that are made in dbxout.c before
16697 we reach the big endian correction code there. It isn't clear if all
16698 of these checks are necessary here, but keeping them all is the safe
16699 thing to do. */
16700 else if (MEM_P (rtl)
16701 && XEXP (rtl, 0) != const0_rtx
16702 && ! CONSTANT_P (XEXP (rtl, 0))
16703 /* Not passed in memory. */
16704 && !MEM_P (DECL_INCOMING_RTL (decl))
16705 /* Not passed by invisible reference. */
16706 && (!REG_P (XEXP (rtl, 0))
16707 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
16708 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
16709 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
16710 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
16711 #endif
16713 /* Big endian correction check. */
16714 && BYTES_BIG_ENDIAN
16715 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
16716 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
16717 < UNITS_PER_WORD))
16719 int offset = (UNITS_PER_WORD
16720 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
16722 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16723 plus_constant (XEXP (rtl, 0), offset));
16726 else if (TREE_CODE (decl) == VAR_DECL
16727 && rtl
16728 && MEM_P (rtl)
16729 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
16730 && BYTES_BIG_ENDIAN)
16732 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
16733 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
16735 /* If a variable is declared "register" yet is smaller than
16736 a register, then if we store the variable to memory, it
16737 looks like we're storing a register-sized value, when in
16738 fact we are not. We need to adjust the offset of the
16739 storage location to reflect the actual value's bytes,
16740 else gdb will not be able to display it. */
16741 if (rsize > dsize)
16742 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
16743 plus_constant (XEXP (rtl, 0), rsize-dsize));
16746 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16747 and will have been substituted directly into all expressions that use it.
16748 C does not have such a concept, but C++ and other languages do. */
16749 if (!rtl && TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
16750 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
16752 if (rtl)
16753 rtl = targetm.delegitimize_address (rtl);
16755 /* If we don't look past the constant pool, we risk emitting a
16756 reference to a constant pool entry that isn't referenced from
16757 code, and thus is not emitted. */
16758 if (rtl)
16759 rtl = avoid_constant_pool_reference (rtl);
16761 /* Try harder to get a rtl. If this symbol ends up not being emitted
16762 in the current CU, resolve_addr will remove the expression referencing
16763 it. */
16764 if (rtl == NULL_RTX
16765 && TREE_CODE (decl) == VAR_DECL
16766 && !DECL_EXTERNAL (decl)
16767 && TREE_STATIC (decl)
16768 && DECL_NAME (decl)
16769 && !DECL_HARD_REGISTER (decl)
16770 && DECL_MODE (decl) != VOIDmode)
16772 rtl = make_decl_rtl_for_debug (decl);
16773 if (!MEM_P (rtl)
16774 || GET_CODE (XEXP (rtl, 0)) != SYMBOL_REF
16775 || SYMBOL_REF_DECL (XEXP (rtl, 0)) != decl)
16776 rtl = NULL_RTX;
16779 return rtl;
16782 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16783 returned. If so, the decl for the COMMON block is returned, and the
16784 value is the offset into the common block for the symbol. */
16786 static tree
16787 fortran_common (tree decl, HOST_WIDE_INT *value)
16789 tree val_expr, cvar;
16790 enum machine_mode mode;
16791 HOST_WIDE_INT bitsize, bitpos;
16792 tree offset;
16793 int volatilep = 0, unsignedp = 0;
16795 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16796 it does not have a value (the offset into the common area), or if it
16797 is thread local (as opposed to global) then it isn't common, and shouldn't
16798 be handled as such. */
16799 if (TREE_CODE (decl) != VAR_DECL
16800 || !TREE_STATIC (decl)
16801 || !DECL_HAS_VALUE_EXPR_P (decl)
16802 || !is_fortran ())
16803 return NULL_TREE;
16805 val_expr = DECL_VALUE_EXPR (decl);
16806 if (TREE_CODE (val_expr) != COMPONENT_REF)
16807 return NULL_TREE;
16809 cvar = get_inner_reference (val_expr, &bitsize, &bitpos, &offset,
16810 &mode, &unsignedp, &volatilep, true);
16812 if (cvar == NULL_TREE
16813 || TREE_CODE (cvar) != VAR_DECL
16814 || DECL_ARTIFICIAL (cvar)
16815 || !TREE_PUBLIC (cvar))
16816 return NULL_TREE;
16818 *value = 0;
16819 if (offset != NULL)
16821 if (!host_integerp (offset, 0))
16822 return NULL_TREE;
16823 *value = tree_low_cst (offset, 0);
16825 if (bitpos != 0)
16826 *value += bitpos / BITS_PER_UNIT;
16828 return cvar;
16831 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16832 data attribute for a variable or a parameter. We generate the
16833 DW_AT_const_value attribute only in those cases where the given variable
16834 or parameter does not have a true "location" either in memory or in a
16835 register. This can happen (for example) when a constant is passed as an
16836 actual argument in a call to an inline function. (It's possible that
16837 these things can crop up in other ways also.) Note that one type of
16838 constant value which can be passed into an inlined function is a constant
16839 pointer. This can happen for example if an actual argument in an inlined
16840 function call evaluates to a compile-time constant address.
16842 CACHE_P is true if it is worth caching the location list for DECL,
16843 so that future calls can reuse it rather than regenerate it from scratch.
16844 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16845 since we will need to refer to them each time the function is inlined. */
16847 static bool
16848 add_location_or_const_value_attribute (dw_die_ref die, tree decl, bool cache_p,
16849 enum dwarf_attribute attr)
16851 rtx rtl;
16852 dw_loc_list_ref list;
16853 var_loc_list *loc_list;
16854 cached_dw_loc_list *cache;
16855 void **slot;
16857 if (TREE_CODE (decl) == ERROR_MARK)
16858 return false;
16860 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
16861 || TREE_CODE (decl) == RESULT_DECL);
16863 /* Try to get some constant RTL for this decl, and use that as the value of
16864 the location. */
16866 rtl = rtl_for_decl_location (decl);
16867 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16868 && add_const_value_attribute (die, rtl))
16869 return true;
16871 /* See if we have single element location list that is equivalent to
16872 a constant value. That way we are better to use add_const_value_attribute
16873 rather than expanding constant value equivalent. */
16874 loc_list = lookup_decl_loc (decl);
16875 if (loc_list
16876 && loc_list->first
16877 && loc_list->first->next == NULL
16878 && NOTE_P (loc_list->first->loc)
16879 && NOTE_VAR_LOCATION (loc_list->first->loc)
16880 && NOTE_VAR_LOCATION_LOC (loc_list->first->loc))
16882 struct var_loc_node *node;
16884 node = loc_list->first;
16885 rtl = NOTE_VAR_LOCATION_LOC (node->loc);
16886 if (GET_CODE (rtl) == EXPR_LIST)
16887 rtl = XEXP (rtl, 0);
16888 if ((CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING)
16889 && add_const_value_attribute (die, rtl))
16890 return true;
16892 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16893 list several times. See if we've already cached the contents. */
16894 list = NULL;
16895 if (loc_list == NULL || cached_dw_loc_list_table == NULL)
16896 cache_p = false;
16897 if (cache_p)
16899 cache = (cached_dw_loc_list *)
16900 htab_find_with_hash (cached_dw_loc_list_table, decl, DECL_UID (decl));
16901 if (cache)
16902 list = cache->loc_list;
16904 if (list == NULL)
16906 list = loc_list_from_tree (decl, decl_by_reference_p (decl) ? 0 : 2);
16907 /* It is usually worth caching this result if the decl is from
16908 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16909 if (cache_p && list && list->dw_loc_next)
16911 slot = htab_find_slot_with_hash (cached_dw_loc_list_table, decl,
16912 DECL_UID (decl), INSERT);
16913 cache = ggc_alloc_cleared_cached_dw_loc_list ();
16914 cache->decl_id = DECL_UID (decl);
16915 cache->loc_list = list;
16916 *slot = cache;
16919 if (list)
16921 add_AT_location_description (die, attr, list);
16922 return true;
16924 /* None of that worked, so it must not really have a location;
16925 try adding a constant value attribute from the DECL_INITIAL. */
16926 return tree_add_const_value_attribute_for_decl (die, decl);
16929 /* Add VARIABLE and DIE into deferred locations list. */
16931 static void
16932 defer_location (tree variable, dw_die_ref die)
16934 deferred_locations entry;
16935 entry.variable = variable;
16936 entry.die = die;
16937 VEC_safe_push (deferred_locations, gc, deferred_locations_list, &entry);
16940 /* Helper function for tree_add_const_value_attribute. Natively encode
16941 initializer INIT into an array. Return true if successful. */
16943 static bool
16944 native_encode_initializer (tree init, unsigned char *array, int size)
16946 tree type;
16948 if (init == NULL_TREE)
16949 return false;
16951 STRIP_NOPS (init);
16952 switch (TREE_CODE (init))
16954 case STRING_CST:
16955 type = TREE_TYPE (init);
16956 if (TREE_CODE (type) == ARRAY_TYPE)
16958 tree enttype = TREE_TYPE (type);
16959 enum machine_mode mode = TYPE_MODE (enttype);
16961 if (GET_MODE_CLASS (mode) != MODE_INT || GET_MODE_SIZE (mode) != 1)
16962 return false;
16963 if (int_size_in_bytes (type) != size)
16964 return false;
16965 if (size > TREE_STRING_LENGTH (init))
16967 memcpy (array, TREE_STRING_POINTER (init),
16968 TREE_STRING_LENGTH (init));
16969 memset (array + TREE_STRING_LENGTH (init),
16970 '\0', size - TREE_STRING_LENGTH (init));
16972 else
16973 memcpy (array, TREE_STRING_POINTER (init), size);
16974 return true;
16976 return false;
16977 case CONSTRUCTOR:
16978 type = TREE_TYPE (init);
16979 if (int_size_in_bytes (type) != size)
16980 return false;
16981 if (TREE_CODE (type) == ARRAY_TYPE)
16983 HOST_WIDE_INT min_index;
16984 unsigned HOST_WIDE_INT cnt;
16985 int curpos = 0, fieldsize;
16986 constructor_elt *ce;
16988 if (TYPE_DOMAIN (type) == NULL_TREE
16989 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0))
16990 return false;
16992 fieldsize = int_size_in_bytes (TREE_TYPE (type));
16993 if (fieldsize <= 0)
16994 return false;
16996 min_index = tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0);
16997 memset (array, '\0', size);
16998 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17000 tree val = ce->value;
17001 tree index = ce->index;
17002 int pos = curpos;
17003 if (index && TREE_CODE (index) == RANGE_EXPR)
17004 pos = (tree_low_cst (TREE_OPERAND (index, 0), 0) - min_index)
17005 * fieldsize;
17006 else if (index)
17007 pos = (tree_low_cst (index, 0) - min_index) * fieldsize;
17009 if (val)
17011 STRIP_NOPS (val);
17012 if (!native_encode_initializer (val, array + pos, fieldsize))
17013 return false;
17015 curpos = pos + fieldsize;
17016 if (index && TREE_CODE (index) == RANGE_EXPR)
17018 int count = tree_low_cst (TREE_OPERAND (index, 1), 0)
17019 - tree_low_cst (TREE_OPERAND (index, 0), 0);
17020 while (count > 0)
17022 if (val)
17023 memcpy (array + curpos, array + pos, fieldsize);
17024 curpos += fieldsize;
17027 gcc_assert (curpos <= size);
17029 return true;
17031 else if (TREE_CODE (type) == RECORD_TYPE
17032 || TREE_CODE (type) == UNION_TYPE)
17034 tree field = NULL_TREE;
17035 unsigned HOST_WIDE_INT cnt;
17036 constructor_elt *ce;
17038 if (int_size_in_bytes (type) != size)
17039 return false;
17041 if (TREE_CODE (type) == RECORD_TYPE)
17042 field = TYPE_FIELDS (type);
17044 FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (init), cnt, ce)
17046 tree val = ce->value;
17047 int pos, fieldsize;
17049 if (ce->index != 0)
17050 field = ce->index;
17052 if (val)
17053 STRIP_NOPS (val);
17055 if (field == NULL_TREE || DECL_BIT_FIELD (field))
17056 return false;
17058 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
17059 && TYPE_DOMAIN (TREE_TYPE (field))
17060 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
17061 return false;
17062 else if (DECL_SIZE_UNIT (field) == NULL_TREE
17063 || !host_integerp (DECL_SIZE_UNIT (field), 0))
17064 return false;
17065 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 0);
17066 pos = int_byte_position (field);
17067 gcc_assert (pos + fieldsize <= size);
17068 if (val
17069 && !native_encode_initializer (val, array + pos, fieldsize))
17070 return false;
17072 return true;
17074 return false;
17075 case VIEW_CONVERT_EXPR:
17076 case NON_LVALUE_EXPR:
17077 return native_encode_initializer (TREE_OPERAND (init, 0), array, size);
17078 default:
17079 return native_encode_expr (init, array, size) == size;
17083 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17084 attribute is the const value T. */
17086 static bool
17087 tree_add_const_value_attribute (dw_die_ref die, tree t)
17089 tree init;
17090 tree type = TREE_TYPE (t);
17091 rtx rtl;
17093 if (!t || !TREE_TYPE (t) || TREE_TYPE (t) == error_mark_node)
17094 return false;
17096 init = t;
17097 gcc_assert (!DECL_P (init));
17099 rtl = rtl_for_decl_init (init, type);
17100 if (rtl)
17101 return add_const_value_attribute (die, rtl);
17102 /* If the host and target are sane, try harder. */
17103 else if (CHAR_BIT == 8 && BITS_PER_UNIT == 8
17104 && initializer_constant_valid_p (init, type))
17106 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (init));
17107 if (size > 0 && (int) size == size)
17109 unsigned char *array = (unsigned char *)
17110 ggc_alloc_cleared_atomic (size);
17112 if (native_encode_initializer (init, array, size))
17114 add_AT_vec (die, DW_AT_const_value, size, 1, array);
17115 return true;
17119 return false;
17122 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17123 attribute is the const value of T, where T is an integral constant
17124 variable with static storage duration
17125 (so it can't be a PARM_DECL or a RESULT_DECL). */
17127 static bool
17128 tree_add_const_value_attribute_for_decl (dw_die_ref var_die, tree decl)
17131 if (!decl
17132 || (TREE_CODE (decl) != VAR_DECL
17133 && TREE_CODE (decl) != CONST_DECL))
17134 return false;
17136 if (TREE_READONLY (decl)
17137 && ! TREE_THIS_VOLATILE (decl)
17138 && DECL_INITIAL (decl))
17139 /* OK */;
17140 else
17141 return false;
17143 /* Don't add DW_AT_const_value if abstract origin already has one. */
17144 if (get_AT (var_die, DW_AT_const_value))
17145 return false;
17147 return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
17150 /* Convert the CFI instructions for the current function into a
17151 location list. This is used for DW_AT_frame_base when we targeting
17152 a dwarf2 consumer that does not support the dwarf3
17153 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17154 expressions. */
17156 static dw_loc_list_ref
17157 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset)
17159 dw_fde_ref fde;
17160 dw_loc_list_ref list, *list_tail;
17161 dw_cfi_ref cfi;
17162 dw_cfa_location last_cfa, next_cfa;
17163 const char *start_label, *last_label, *section;
17164 dw_cfa_location remember;
17166 fde = current_fde ();
17167 gcc_assert (fde != NULL);
17169 section = secname_for_decl (current_function_decl);
17170 list_tail = &list;
17171 list = NULL;
17173 memset (&next_cfa, 0, sizeof (next_cfa));
17174 next_cfa.reg = INVALID_REGNUM;
17175 remember = next_cfa;
17177 start_label = fde->dw_fde_begin;
17179 /* ??? Bald assumption that the CIE opcode list does not contain
17180 advance opcodes. */
17181 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
17182 lookup_cfa_1 (cfi, &next_cfa, &remember);
17184 last_cfa = next_cfa;
17185 last_label = start_label;
17187 if (fde->dw_fde_second_begin && fde->dw_fde_switch_cfi == NULL)
17189 /* If the first partition contained no CFI adjustments, the
17190 CIE opcodes apply to the whole first partition. */
17191 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17192 fde->dw_fde_begin, fde->dw_fde_end, section);
17193 list_tail =&(*list_tail)->dw_loc_next;
17194 start_label = last_label = fde->dw_fde_second_begin;
17197 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
17199 switch (cfi->dw_cfi_opc)
17201 case DW_CFA_set_loc:
17202 case DW_CFA_advance_loc1:
17203 case DW_CFA_advance_loc2:
17204 case DW_CFA_advance_loc4:
17205 if (!cfa_equal_p (&last_cfa, &next_cfa))
17207 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17208 start_label, last_label, section);
17210 list_tail = &(*list_tail)->dw_loc_next;
17211 last_cfa = next_cfa;
17212 start_label = last_label;
17214 last_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
17215 break;
17217 case DW_CFA_advance_loc:
17218 /* The encoding is complex enough that we should never emit this. */
17219 gcc_unreachable ();
17221 default:
17222 lookup_cfa_1 (cfi, &next_cfa, &remember);
17223 break;
17225 if (cfi == fde->dw_fde_switch_cfi)
17227 if (!cfa_equal_p (&last_cfa, &next_cfa))
17229 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17230 start_label, last_label, section);
17232 list_tail = &(*list_tail)->dw_loc_next;
17233 last_cfa = next_cfa;
17234 start_label = last_label;
17236 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17237 start_label, fde->dw_fde_end, section);
17238 list_tail = &(*list_tail)->dw_loc_next;
17239 start_label = last_label = fde->dw_fde_second_begin;
17243 if (!cfa_equal_p (&last_cfa, &next_cfa))
17245 *list_tail = new_loc_list (build_cfa_loc (&last_cfa, offset),
17246 start_label, last_label, section);
17247 list_tail = &(*list_tail)->dw_loc_next;
17248 start_label = last_label;
17251 *list_tail = new_loc_list (build_cfa_loc (&next_cfa, offset),
17252 start_label,
17253 fde->dw_fde_second_begin
17254 ? fde->dw_fde_second_end : fde->dw_fde_end,
17255 section);
17257 if (list && list->dw_loc_next)
17258 gen_llsym (list);
17260 return list;
17263 /* Compute a displacement from the "steady-state frame pointer" to the
17264 frame base (often the same as the CFA), and store it in
17265 frame_pointer_fb_offset. OFFSET is added to the displacement
17266 before the latter is negated. */
17268 static void
17269 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset)
17271 rtx reg, elim;
17273 #ifdef FRAME_POINTER_CFA_OFFSET
17274 reg = frame_pointer_rtx;
17275 offset += FRAME_POINTER_CFA_OFFSET (current_function_decl);
17276 #else
17277 reg = arg_pointer_rtx;
17278 offset += ARG_POINTER_CFA_OFFSET (current_function_decl);
17279 #endif
17281 elim = eliminate_regs (reg, VOIDmode, NULL_RTX);
17282 if (GET_CODE (elim) == PLUS)
17284 offset += INTVAL (XEXP (elim, 1));
17285 elim = XEXP (elim, 0);
17288 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
17289 && (elim == hard_frame_pointer_rtx
17290 || elim == stack_pointer_rtx))
17291 || elim == (frame_pointer_needed
17292 ? hard_frame_pointer_rtx
17293 : stack_pointer_rtx));
17295 frame_pointer_fb_offset = -offset;
17298 /* Generate a DW_AT_name attribute given some string value to be included as
17299 the value of the attribute. */
17301 static void
17302 add_name_attribute (dw_die_ref die, const char *name_string)
17304 if (name_string != NULL && *name_string != 0)
17306 if (demangle_name_func)
17307 name_string = (*demangle_name_func) (name_string);
17309 add_AT_string (die, DW_AT_name, name_string);
17313 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
17314 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
17315 of TYPE accordingly.
17317 ??? This is a temporary measure until after we're able to generate
17318 regular DWARF for the complex Ada type system. */
17320 static void
17321 add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
17322 dw_die_ref context_die)
17324 tree dtype;
17325 dw_die_ref dtype_die;
17327 if (!lang_hooks.types.descriptive_type)
17328 return;
17330 dtype = lang_hooks.types.descriptive_type (type);
17331 if (!dtype)
17332 return;
17334 dtype_die = lookup_type_die (dtype);
17335 if (!dtype_die)
17337 gen_type_die (dtype, context_die);
17338 dtype_die = lookup_type_die (dtype);
17339 gcc_assert (dtype_die);
17342 add_AT_die_ref (die, DW_AT_GNAT_descriptive_type, dtype_die);
17345 /* Generate a DW_AT_comp_dir attribute for DIE. */
17347 static void
17348 add_comp_dir_attribute (dw_die_ref die)
17350 const char *wd = get_src_pwd ();
17351 char *wd1;
17353 if (wd == NULL)
17354 return;
17356 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
17358 int wdlen;
17360 wdlen = strlen (wd);
17361 wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
17362 strcpy (wd1, wd);
17363 wd1 [wdlen] = DIR_SEPARATOR;
17364 wd1 [wdlen + 1] = 0;
17365 wd = wd1;
17368 add_AT_string (die, DW_AT_comp_dir, remap_debug_filename (wd));
17371 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
17372 default. */
17374 static int
17375 lower_bound_default (void)
17377 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language))
17379 case DW_LANG_C:
17380 case DW_LANG_C89:
17381 case DW_LANG_C99:
17382 case DW_LANG_C_plus_plus:
17383 case DW_LANG_ObjC:
17384 case DW_LANG_ObjC_plus_plus:
17385 case DW_LANG_Java:
17386 return 0;
17387 case DW_LANG_Fortran77:
17388 case DW_LANG_Fortran90:
17389 case DW_LANG_Fortran95:
17390 return 1;
17391 case DW_LANG_UPC:
17392 case DW_LANG_D:
17393 case DW_LANG_Python:
17394 return dwarf_version >= 4 ? 0 : -1;
17395 case DW_LANG_Ada95:
17396 case DW_LANG_Ada83:
17397 case DW_LANG_Cobol74:
17398 case DW_LANG_Cobol85:
17399 case DW_LANG_Pascal83:
17400 case DW_LANG_Modula2:
17401 case DW_LANG_PLI:
17402 return dwarf_version >= 4 ? 1 : -1;
17403 default:
17404 return -1;
17408 /* Given a tree node describing an array bound (either lower or upper) output
17409 a representation for that bound. */
17411 static void
17412 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
17414 switch (TREE_CODE (bound))
17416 case ERROR_MARK:
17417 return;
17419 /* All fixed-bounds are represented by INTEGER_CST nodes. */
17420 case INTEGER_CST:
17422 unsigned int prec = simple_type_size_in_bits (TREE_TYPE (bound));
17423 int dflt;
17425 /* Use the default if possible. */
17426 if (bound_attr == DW_AT_lower_bound
17427 && host_integerp (bound, 0)
17428 && (dflt = lower_bound_default ()) != -1
17429 && tree_low_cst (bound, 0) == dflt)
17432 /* Otherwise represent the bound as an unsigned value with the
17433 precision of its type. The precision and signedness of the
17434 type will be necessary to re-interpret it unambiguously. */
17435 else if (prec < HOST_BITS_PER_WIDE_INT)
17437 unsigned HOST_WIDE_INT mask
17438 = ((unsigned HOST_WIDE_INT) 1 << prec) - 1;
17439 add_AT_unsigned (subrange_die, bound_attr,
17440 TREE_INT_CST_LOW (bound) & mask);
17442 else if (prec == HOST_BITS_PER_WIDE_INT
17443 || TREE_INT_CST_HIGH (bound) == 0)
17444 add_AT_unsigned (subrange_die, bound_attr,
17445 TREE_INT_CST_LOW (bound));
17446 else
17447 add_AT_double (subrange_die, bound_attr, TREE_INT_CST_HIGH (bound),
17448 TREE_INT_CST_LOW (bound));
17450 break;
17452 CASE_CONVERT:
17453 case VIEW_CONVERT_EXPR:
17454 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
17455 break;
17457 case SAVE_EXPR:
17458 break;
17460 case VAR_DECL:
17461 case PARM_DECL:
17462 case RESULT_DECL:
17464 dw_die_ref decl_die = lookup_decl_die (bound);
17466 /* ??? Can this happen, or should the variable have been bound
17467 first? Probably it can, since I imagine that we try to create
17468 the types of parameters in the order in which they exist in
17469 the list, and won't have created a forward reference to a
17470 later parameter. */
17471 if (decl_die != NULL)
17473 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17474 break;
17477 /* FALLTHRU */
17479 default:
17481 /* Otherwise try to create a stack operation procedure to
17482 evaluate the value of the array bound. */
17484 dw_die_ref ctx, decl_die;
17485 dw_loc_list_ref list;
17487 list = loc_list_from_tree (bound, 2);
17488 if (list == NULL || single_element_loc_list_p (list))
17490 /* If DW_AT_*bound is not a reference nor constant, it is
17491 a DWARF expression rather than location description.
17492 For that loc_list_from_tree (bound, 0) is needed.
17493 If that fails to give a single element list,
17494 fall back to outputting this as a reference anyway. */
17495 dw_loc_list_ref list2 = loc_list_from_tree (bound, 0);
17496 if (list2 && single_element_loc_list_p (list2))
17498 add_AT_loc (subrange_die, bound_attr, list2->expr);
17499 break;
17502 if (list == NULL)
17503 break;
17505 if (current_function_decl == 0)
17506 ctx = comp_unit_die ();
17507 else
17508 ctx = lookup_decl_die (current_function_decl);
17510 decl_die = new_die (DW_TAG_variable, ctx, bound);
17511 add_AT_flag (decl_die, DW_AT_artificial, 1);
17512 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
17513 add_AT_location_description (decl_die, DW_AT_location, list);
17514 add_AT_die_ref (subrange_die, bound_attr, decl_die);
17515 break;
17520 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
17521 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
17522 Note that the block of subscript information for an array type also
17523 includes information about the element type of the given array type. */
17525 static void
17526 add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p)
17528 unsigned dimension_number;
17529 tree lower, upper;
17530 dw_die_ref subrange_die;
17532 for (dimension_number = 0;
17533 TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p);
17534 type = TREE_TYPE (type), dimension_number++)
17536 tree domain = TYPE_DOMAIN (type);
17538 if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
17539 break;
17541 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
17542 and (in GNU C only) variable bounds. Handle all three forms
17543 here. */
17544 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
17545 if (domain)
17547 /* We have an array type with specified bounds. */
17548 lower = TYPE_MIN_VALUE (domain);
17549 upper = TYPE_MAX_VALUE (domain);
17551 /* Define the index type. */
17552 if (TREE_TYPE (domain))
17554 /* ??? This is probably an Ada unnamed subrange type. Ignore the
17555 TREE_TYPE field. We can't emit debug info for this
17556 because it is an unnamed integral type. */
17557 if (TREE_CODE (domain) == INTEGER_TYPE
17558 && TYPE_NAME (domain) == NULL_TREE
17559 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
17560 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
17562 else
17563 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
17564 type_die);
17567 /* ??? If upper is NULL, the array has unspecified length,
17568 but it does have a lower bound. This happens with Fortran
17569 dimension arr(N:*)
17570 Since the debugger is definitely going to need to know N
17571 to produce useful results, go ahead and output the lower
17572 bound solo, and hope the debugger can cope. */
17574 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
17575 if (upper)
17576 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
17579 /* Otherwise we have an array type with an unspecified length. The
17580 DWARF-2 spec does not say how to handle this; let's just leave out the
17581 bounds. */
17585 static void
17586 add_byte_size_attribute (dw_die_ref die, tree tree_node)
17588 unsigned size;
17590 switch (TREE_CODE (tree_node))
17592 case ERROR_MARK:
17593 size = 0;
17594 break;
17595 case ENUMERAL_TYPE:
17596 case RECORD_TYPE:
17597 case UNION_TYPE:
17598 case QUAL_UNION_TYPE:
17599 size = int_size_in_bytes (tree_node);
17600 break;
17601 case FIELD_DECL:
17602 /* For a data member of a struct or union, the DW_AT_byte_size is
17603 generally given as the number of bytes normally allocated for an
17604 object of the *declared* type of the member itself. This is true
17605 even for bit-fields. */
17606 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
17607 break;
17608 default:
17609 gcc_unreachable ();
17612 /* Note that `size' might be -1 when we get to this point. If it is, that
17613 indicates that the byte size of the entity in question is variable. We
17614 have no good way of expressing this fact in Dwarf at the present time,
17615 so just let the -1 pass on through. */
17616 add_AT_unsigned (die, DW_AT_byte_size, size);
17619 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17620 which specifies the distance in bits from the highest order bit of the
17621 "containing object" for the bit-field to the highest order bit of the
17622 bit-field itself.
17624 For any given bit-field, the "containing object" is a hypothetical object
17625 (of some integral or enum type) within which the given bit-field lives. The
17626 type of this hypothetical "containing object" is always the same as the
17627 declared type of the individual bit-field itself. The determination of the
17628 exact location of the "containing object" for a bit-field is rather
17629 complicated. It's handled by the `field_byte_offset' function (above).
17631 Note that it is the size (in bytes) of the hypothetical "containing object"
17632 which will be given in the DW_AT_byte_size attribute for this bit-field.
17633 (See `byte_size_attribute' above). */
17635 static inline void
17636 add_bit_offset_attribute (dw_die_ref die, tree decl)
17638 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
17639 tree type = DECL_BIT_FIELD_TYPE (decl);
17640 HOST_WIDE_INT bitpos_int;
17641 HOST_WIDE_INT highest_order_object_bit_offset;
17642 HOST_WIDE_INT highest_order_field_bit_offset;
17643 HOST_WIDE_INT bit_offset;
17645 /* Must be a field and a bit field. */
17646 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
17648 /* We can't yet handle bit-fields whose offsets are variable, so if we
17649 encounter such things, just return without generating any attribute
17650 whatsoever. Likewise for variable or too large size. */
17651 if (! host_integerp (bit_position (decl), 0)
17652 || ! host_integerp (DECL_SIZE (decl), 1))
17653 return;
17655 bitpos_int = int_bit_position (decl);
17657 /* Note that the bit offset is always the distance (in bits) from the
17658 highest-order bit of the "containing object" to the highest-order bit of
17659 the bit-field itself. Since the "high-order end" of any object or field
17660 is different on big-endian and little-endian machines, the computation
17661 below must take account of these differences. */
17662 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
17663 highest_order_field_bit_offset = bitpos_int;
17665 if (! BYTES_BIG_ENDIAN)
17667 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
17668 highest_order_object_bit_offset += simple_type_size_in_bits (type);
17671 bit_offset
17672 = (! BYTES_BIG_ENDIAN
17673 ? highest_order_object_bit_offset - highest_order_field_bit_offset
17674 : highest_order_field_bit_offset - highest_order_object_bit_offset);
17676 if (bit_offset < 0)
17677 add_AT_int (die, DW_AT_bit_offset, bit_offset);
17678 else
17679 add_AT_unsigned (die, DW_AT_bit_offset, (unsigned HOST_WIDE_INT) bit_offset);
17682 /* For a FIELD_DECL node which represents a bit field, output an attribute
17683 which specifies the length in bits of the given field. */
17685 static inline void
17686 add_bit_size_attribute (dw_die_ref die, tree decl)
17688 /* Must be a field and a bit field. */
17689 gcc_assert (TREE_CODE (decl) == FIELD_DECL
17690 && DECL_BIT_FIELD_TYPE (decl));
17692 if (host_integerp (DECL_SIZE (decl), 1))
17693 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
17696 /* If the compiled language is ANSI C, then add a 'prototyped'
17697 attribute, if arg types are given for the parameters of a function. */
17699 static inline void
17700 add_prototyped_attribute (dw_die_ref die, tree func_type)
17702 if (get_AT_unsigned (comp_unit_die (), DW_AT_language) == DW_LANG_C89
17703 && prototype_p (func_type))
17704 add_AT_flag (die, DW_AT_prototyped, 1);
17707 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17708 by looking in either the type declaration or object declaration
17709 equate table. */
17711 static inline dw_die_ref
17712 add_abstract_origin_attribute (dw_die_ref die, tree origin)
17714 dw_die_ref origin_die = NULL;
17716 if (TREE_CODE (origin) != FUNCTION_DECL)
17718 /* We may have gotten separated from the block for the inlined
17719 function, if we're in an exception handler or some such; make
17720 sure that the abstract function has been written out.
17722 Doing this for nested functions is wrong, however; functions are
17723 distinct units, and our context might not even be inline. */
17724 tree fn = origin;
17726 if (TYPE_P (fn))
17727 fn = TYPE_STUB_DECL (fn);
17729 fn = decl_function_context (fn);
17730 if (fn)
17731 dwarf2out_abstract_function (fn);
17734 if (DECL_P (origin))
17735 origin_die = lookup_decl_die (origin);
17736 else if (TYPE_P (origin))
17737 origin_die = lookup_type_die (origin);
17739 /* XXX: Functions that are never lowered don't always have correct block
17740 trees (in the case of java, they simply have no block tree, in some other
17741 languages). For these functions, there is nothing we can really do to
17742 output correct debug info for inlined functions in all cases. Rather
17743 than die, we'll just produce deficient debug info now, in that we will
17744 have variables without a proper abstract origin. In the future, when all
17745 functions are lowered, we should re-add a gcc_assert (origin_die)
17746 here. */
17748 if (origin_die)
17749 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
17750 return origin_die;
17753 /* We do not currently support the pure_virtual attribute. */
17755 static inline void
17756 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
17758 if (DECL_VINDEX (func_decl))
17760 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
17762 if (host_integerp (DECL_VINDEX (func_decl), 0))
17763 add_AT_loc (die, DW_AT_vtable_elem_location,
17764 new_loc_descr (DW_OP_constu,
17765 tree_low_cst (DECL_VINDEX (func_decl), 0),
17766 0));
17768 /* GNU extension: Record what type this method came from originally. */
17769 if (debug_info_level > DINFO_LEVEL_TERSE
17770 && DECL_CONTEXT (func_decl))
17771 add_AT_die_ref (die, DW_AT_containing_type,
17772 lookup_type_die (DECL_CONTEXT (func_decl)));
17776 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17777 given decl. This used to be a vendor extension until after DWARF 4
17778 standardized it. */
17780 static void
17781 add_linkage_attr (dw_die_ref die, tree decl)
17783 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
17785 /* Mimic what assemble_name_raw does with a leading '*'. */
17786 if (name[0] == '*')
17787 name = &name[1];
17789 if (dwarf_version >= 4)
17790 add_AT_string (die, DW_AT_linkage_name, name);
17791 else
17792 add_AT_string (die, DW_AT_MIPS_linkage_name, name);
17795 /* Add source coordinate attributes for the given decl. */
17797 static void
17798 add_src_coords_attributes (dw_die_ref die, tree decl)
17800 expanded_location s;
17802 if (DECL_SOURCE_LOCATION (decl) == UNKNOWN_LOCATION)
17803 return;
17804 s = expand_location (DECL_SOURCE_LOCATION (decl));
17805 add_AT_file (die, DW_AT_decl_file, lookup_filename (s.file));
17806 add_AT_unsigned (die, DW_AT_decl_line, s.line);
17809 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17811 static void
17812 add_linkage_name (dw_die_ref die, tree decl)
17814 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
17815 && TREE_PUBLIC (decl)
17816 && !DECL_ABSTRACT (decl)
17817 && !(TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
17818 && die->die_tag != DW_TAG_member)
17820 /* Defer until we have an assembler name set. */
17821 if (!DECL_ASSEMBLER_NAME_SET_P (decl))
17823 limbo_die_node *asm_name;
17825 asm_name = ggc_alloc_cleared_limbo_die_node ();
17826 asm_name->die = die;
17827 asm_name->created_for = decl;
17828 asm_name->next = deferred_asm_name;
17829 deferred_asm_name = asm_name;
17831 else if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
17832 add_linkage_attr (die, decl);
17836 /* Add a DW_AT_name attribute and source coordinate attribute for the
17837 given decl, but only if it actually has a name. */
17839 static void
17840 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
17842 tree decl_name;
17844 decl_name = DECL_NAME (decl);
17845 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
17847 const char *name = dwarf2_name (decl, 0);
17848 if (name)
17849 add_name_attribute (die, name);
17850 if (! DECL_ARTIFICIAL (decl))
17851 add_src_coords_attributes (die, decl);
17853 add_linkage_name (die, decl);
17856 #ifdef VMS_DEBUGGING_INFO
17857 /* Get the function's name, as described by its RTL. This may be different
17858 from the DECL_NAME name used in the source file. */
17859 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
17861 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
17862 XEXP (DECL_RTL (decl), 0));
17863 VEC_safe_push (rtx, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
17865 #endif /* VMS_DEBUGGING_INFO */
17868 #ifdef VMS_DEBUGGING_INFO
17869 /* Output the debug main pointer die for VMS */
17871 void
17872 dwarf2out_vms_debug_main_pointer (void)
17874 char label[MAX_ARTIFICIAL_LABEL_BYTES];
17875 dw_die_ref die;
17877 /* Allocate the VMS debug main subprogram die. */
17878 die = ggc_alloc_cleared_die_node ();
17879 die->die_tag = DW_TAG_subprogram;
17880 add_name_attribute (die, VMS_DEBUG_MAIN_POINTER);
17881 ASM_GENERATE_INTERNAL_LABEL (label, PROLOGUE_END_LABEL,
17882 current_function_funcdef_no);
17883 add_AT_lbl_id (die, DW_AT_entry_pc, label);
17885 /* Make it the first child of comp_unit_die (). */
17886 die->die_parent = comp_unit_die ();
17887 if (comp_unit_die ()->die_child)
17889 die->die_sib = comp_unit_die ()->die_child->die_sib;
17890 comp_unit_die ()->die_child->die_sib = die;
17892 else
17894 die->die_sib = die;
17895 comp_unit_die ()->die_child = die;
17898 #endif /* VMS_DEBUGGING_INFO */
17900 /* Push a new declaration scope. */
17902 static void
17903 push_decl_scope (tree scope)
17905 VEC_safe_push (tree, gc, decl_scope_table, scope);
17908 /* Pop a declaration scope. */
17910 static inline void
17911 pop_decl_scope (void)
17913 VEC_pop (tree, decl_scope_table);
17916 /* Return the DIE for the scope that immediately contains this type.
17917 Non-named types get global scope. Named types nested in other
17918 types get their containing scope if it's open, or global scope
17919 otherwise. All other types (i.e. function-local named types) get
17920 the current active scope. */
17922 static dw_die_ref
17923 scope_die_for (tree t, dw_die_ref context_die)
17925 dw_die_ref scope_die = NULL;
17926 tree containing_scope;
17927 int i;
17929 /* Non-types always go in the current scope. */
17930 gcc_assert (TYPE_P (t));
17932 containing_scope = TYPE_CONTEXT (t);
17934 /* Use the containing namespace if it was passed in (for a declaration). */
17935 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
17937 if (context_die == lookup_decl_die (containing_scope))
17938 /* OK */;
17939 else
17940 containing_scope = NULL_TREE;
17943 /* Ignore function type "scopes" from the C frontend. They mean that
17944 a tagged type is local to a parmlist of a function declarator, but
17945 that isn't useful to DWARF. */
17946 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
17947 containing_scope = NULL_TREE;
17949 if (SCOPE_FILE_SCOPE_P (containing_scope))
17950 scope_die = comp_unit_die ();
17951 else if (TYPE_P (containing_scope))
17953 /* For types, we can just look up the appropriate DIE. But
17954 first we check to see if we're in the middle of emitting it
17955 so we know where the new DIE should go. */
17956 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
17957 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
17958 break;
17960 if (i < 0)
17962 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
17963 || TREE_ASM_WRITTEN (containing_scope));
17964 /*We are not in the middle of emitting the type
17965 CONTAINING_SCOPE. Let's see if it's emitted already. */
17966 scope_die = lookup_type_die (containing_scope);
17968 /* If none of the current dies are suitable, we get file scope. */
17969 if (scope_die == NULL)
17970 scope_die = comp_unit_die ();
17972 else
17973 scope_die = lookup_type_die_strip_naming_typedef (containing_scope);
17975 else
17976 scope_die = context_die;
17978 return scope_die;
17981 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17983 static inline int
17984 local_scope_p (dw_die_ref context_die)
17986 for (; context_die; context_die = context_die->die_parent)
17987 if (context_die->die_tag == DW_TAG_inlined_subroutine
17988 || context_die->die_tag == DW_TAG_subprogram)
17989 return 1;
17991 return 0;
17994 /* Returns nonzero if CONTEXT_DIE is a class. */
17996 static inline int
17997 class_scope_p (dw_die_ref context_die)
17999 return (context_die
18000 && (context_die->die_tag == DW_TAG_structure_type
18001 || context_die->die_tag == DW_TAG_class_type
18002 || context_die->die_tag == DW_TAG_interface_type
18003 || context_die->die_tag == DW_TAG_union_type));
18006 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18007 whether or not to treat a DIE in this context as a declaration. */
18009 static inline int
18010 class_or_namespace_scope_p (dw_die_ref context_die)
18012 return (class_scope_p (context_die)
18013 || (context_die && context_die->die_tag == DW_TAG_namespace));
18016 /* Many forms of DIEs require a "type description" attribute. This
18017 routine locates the proper "type descriptor" die for the type given
18018 by 'type', and adds a DW_AT_type attribute below the given die. */
18020 static void
18021 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
18022 int decl_volatile, dw_die_ref context_die)
18024 enum tree_code code = TREE_CODE (type);
18025 dw_die_ref type_die = NULL;
18027 /* ??? If this type is an unnamed subrange type of an integral, floating-point
18028 or fixed-point type, use the inner type. This is because we have no
18029 support for unnamed types in base_type_die. This can happen if this is
18030 an Ada subrange type. Correct solution is emit a subrange type die. */
18031 if ((code == INTEGER_TYPE || code == REAL_TYPE || code == FIXED_POINT_TYPE)
18032 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
18033 type = TREE_TYPE (type), code = TREE_CODE (type);
18035 if (code == ERROR_MARK
18036 /* Handle a special case. For functions whose return type is void, we
18037 generate *no* type attribute. (Note that no object may have type
18038 `void', so this only applies to function return types). */
18039 || code == VOID_TYPE)
18040 return;
18042 type_die = modified_type_die (type,
18043 decl_const || TYPE_READONLY (type),
18044 decl_volatile || TYPE_VOLATILE (type),
18045 context_die);
18047 if (type_die != NULL)
18048 add_AT_die_ref (object_die, DW_AT_type, type_die);
18051 /* Given an object die, add the calling convention attribute for the
18052 function call type. */
18053 static void
18054 add_calling_convention_attribute (dw_die_ref subr_die, tree decl)
18056 enum dwarf_calling_convention value = DW_CC_normal;
18058 value = ((enum dwarf_calling_convention)
18059 targetm.dwarf_calling_convention (TREE_TYPE (decl)));
18061 if (is_fortran ()
18062 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), "MAIN__"))
18064 /* DWARF 2 doesn't provide a way to identify a program's source-level
18065 entry point. DW_AT_calling_convention attributes are only meant
18066 to describe functions' calling conventions. However, lacking a
18067 better way to signal the Fortran main program, we used this for
18068 a long time, following existing custom. Now, DWARF 4 has
18069 DW_AT_main_subprogram, which we add below, but some tools still
18070 rely on the old way, which we thus keep. */
18071 value = DW_CC_program;
18073 if (dwarf_version >= 4 || !dwarf_strict)
18074 add_AT_flag (subr_die, DW_AT_main_subprogram, 1);
18077 /* Only add the attribute if the backend requests it, and
18078 is not DW_CC_normal. */
18079 if (value && (value != DW_CC_normal))
18080 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
18083 /* Given a tree pointer to a struct, class, union, or enum type node, return
18084 a pointer to the (string) tag name for the given type, or zero if the type
18085 was declared without a tag. */
18087 static const char *
18088 type_tag (const_tree type)
18090 const char *name = 0;
18092 if (TYPE_NAME (type) != 0)
18094 tree t = 0;
18096 /* Find the IDENTIFIER_NODE for the type name. */
18097 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
18098 && !TYPE_NAMELESS (type))
18099 t = TYPE_NAME (type);
18101 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
18102 a TYPE_DECL node, regardless of whether or not a `typedef' was
18103 involved. */
18104 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
18105 && ! DECL_IGNORED_P (TYPE_NAME (type)))
18107 /* We want to be extra verbose. Don't call dwarf_name if
18108 DECL_NAME isn't set. The default hook for decl_printable_name
18109 doesn't like that, and in this context it's correct to return
18110 0, instead of "<anonymous>" or the like. */
18111 if (DECL_NAME (TYPE_NAME (type))
18112 && !DECL_NAMELESS (TYPE_NAME (type)))
18113 name = lang_hooks.dwarf_name (TYPE_NAME (type), 2);
18116 /* Now get the name as a string, or invent one. */
18117 if (!name && t != 0)
18118 name = IDENTIFIER_POINTER (t);
18121 return (name == 0 || *name == '\0') ? 0 : name;
18124 /* Return the type associated with a data member, make a special check
18125 for bit field types. */
18127 static inline tree
18128 member_declared_type (const_tree member)
18130 return (DECL_BIT_FIELD_TYPE (member)
18131 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
18134 /* Get the decl's label, as described by its RTL. This may be different
18135 from the DECL_NAME name used in the source file. */
18137 #if 0
18138 static const char *
18139 decl_start_label (tree decl)
18141 rtx x;
18142 const char *fnname;
18144 x = DECL_RTL (decl);
18145 gcc_assert (MEM_P (x));
18147 x = XEXP (x, 0);
18148 gcc_assert (GET_CODE (x) == SYMBOL_REF);
18150 fnname = XSTR (x, 0);
18151 return fnname;
18153 #endif
18155 /* These routines generate the internal representation of the DIE's for
18156 the compilation unit. Debugging information is collected by walking
18157 the declaration trees passed in from dwarf2out_decl(). */
18159 static void
18160 gen_array_type_die (tree type, dw_die_ref context_die)
18162 dw_die_ref scope_die = scope_die_for (type, context_die);
18163 dw_die_ref array_die;
18165 /* GNU compilers represent multidimensional array types as sequences of one
18166 dimensional array types whose element types are themselves array types.
18167 We sometimes squish that down to a single array_type DIE with multiple
18168 subscripts in the Dwarf debugging info. The draft Dwarf specification
18169 say that we are allowed to do this kind of compression in C, because
18170 there is no difference between an array of arrays and a multidimensional
18171 array. We don't do this for Ada to remain as close as possible to the
18172 actual representation, which is especially important against the language
18173 flexibilty wrt arrays of variable size. */
18175 bool collapse_nested_arrays = !is_ada ();
18176 tree element_type;
18178 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
18179 DW_TAG_string_type doesn't have DW_AT_type attribute). */
18180 if (TYPE_STRING_FLAG (type)
18181 && TREE_CODE (type) == ARRAY_TYPE
18182 && is_fortran ()
18183 && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))
18185 HOST_WIDE_INT size;
18187 array_die = new_die (DW_TAG_string_type, scope_die, type);
18188 add_name_attribute (array_die, type_tag (type));
18189 equate_type_number_to_die (type, array_die);
18190 size = int_size_in_bytes (type);
18191 if (size >= 0)
18192 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18193 else if (TYPE_DOMAIN (type) != NULL_TREE
18194 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
18195 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
18197 tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
18198 dw_loc_list_ref loc = loc_list_from_tree (szdecl, 2);
18200 size = int_size_in_bytes (TREE_TYPE (szdecl));
18201 if (loc && size > 0)
18203 add_AT_location_description (array_die, DW_AT_string_length, loc);
18204 if (size != DWARF2_ADDR_SIZE)
18205 add_AT_unsigned (array_die, DW_AT_byte_size, size);
18208 return;
18211 /* ??? The SGI dwarf reader fails for array of array of enum types
18212 (e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
18213 array type comes before the outer array type. We thus call gen_type_die
18214 before we new_die and must prevent nested array types collapsing for this
18215 target. */
18217 #ifdef MIPS_DEBUGGING_INFO
18218 gen_type_die (TREE_TYPE (type), context_die);
18219 collapse_nested_arrays = false;
18220 #endif
18222 array_die = new_die (DW_TAG_array_type, scope_die, type);
18223 add_name_attribute (array_die, type_tag (type));
18224 add_gnat_descriptive_type_attribute (array_die, type, context_die);
18225 equate_type_number_to_die (type, array_die);
18227 if (TREE_CODE (type) == VECTOR_TYPE)
18228 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
18230 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18231 if (is_fortran ()
18232 && TREE_CODE (type) == ARRAY_TYPE
18233 && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
18234 && !TYPE_STRING_FLAG (TREE_TYPE (type)))
18235 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18237 #if 0
18238 /* We default the array ordering. SDB will probably do
18239 the right things even if DW_AT_ordering is not present. It's not even
18240 an issue until we start to get into multidimensional arrays anyway. If
18241 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
18242 then we'll have to put the DW_AT_ordering attribute back in. (But if
18243 and when we find out that we need to put these in, we will only do so
18244 for multidimensional arrays. */
18245 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
18246 #endif
18248 #ifdef MIPS_DEBUGGING_INFO
18249 /* The SGI compilers handle arrays of unknown bound by setting
18250 AT_declaration and not emitting any subrange DIEs. */
18251 if (TREE_CODE (type) == ARRAY_TYPE
18252 && ! TYPE_DOMAIN (type))
18253 add_AT_flag (array_die, DW_AT_declaration, 1);
18254 else
18255 #endif
18256 if (TREE_CODE (type) == VECTOR_TYPE)
18258 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
18259 dw_die_ref subrange_die = new_die (DW_TAG_subrange_type, array_die, NULL);
18260 add_bound_info (subrange_die, DW_AT_lower_bound, size_zero_node);
18261 add_bound_info (subrange_die, DW_AT_upper_bound,
18262 size_int (TYPE_VECTOR_SUBPARTS (type) - 1));
18264 else
18265 add_subscript_info (array_die, type, collapse_nested_arrays);
18267 /* Add representation of the type of the elements of this array type and
18268 emit the corresponding DIE if we haven't done it already. */
18269 element_type = TREE_TYPE (type);
18270 if (collapse_nested_arrays)
18271 while (TREE_CODE (element_type) == ARRAY_TYPE)
18273 if (TYPE_STRING_FLAG (element_type) && is_fortran ())
18274 break;
18275 element_type = TREE_TYPE (element_type);
18278 #ifndef MIPS_DEBUGGING_INFO
18279 gen_type_die (element_type, context_die);
18280 #endif
18282 add_type_attribute (array_die, element_type, 0, 0, context_die);
18284 if (get_AT (array_die, DW_AT_name))
18285 add_pubtype (type, array_die);
18288 static dw_loc_descr_ref
18289 descr_info_loc (tree val, tree base_decl)
18291 HOST_WIDE_INT size;
18292 dw_loc_descr_ref loc, loc2;
18293 enum dwarf_location_atom op;
18295 if (val == base_decl)
18296 return new_loc_descr (DW_OP_push_object_address, 0, 0);
18298 switch (TREE_CODE (val))
18300 CASE_CONVERT:
18301 return descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18302 case VAR_DECL:
18303 return loc_descriptor_from_tree (val, 0);
18304 case INTEGER_CST:
18305 if (host_integerp (val, 0))
18306 return int_loc_descriptor (tree_low_cst (val, 0));
18307 break;
18308 case INDIRECT_REF:
18309 size = int_size_in_bytes (TREE_TYPE (val));
18310 if (size < 0)
18311 break;
18312 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18313 if (!loc)
18314 break;
18315 if (size == DWARF2_ADDR_SIZE)
18316 add_loc_descr (&loc, new_loc_descr (DW_OP_deref, 0, 0));
18317 else
18318 add_loc_descr (&loc, new_loc_descr (DW_OP_deref_size, size, 0));
18319 return loc;
18320 case POINTER_PLUS_EXPR:
18321 case PLUS_EXPR:
18322 if (host_integerp (TREE_OPERAND (val, 1), 1)
18323 && (unsigned HOST_WIDE_INT) tree_low_cst (TREE_OPERAND (val, 1), 1)
18324 < 16384)
18326 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18327 if (!loc)
18328 break;
18329 loc_descr_plus_const (&loc, tree_low_cst (TREE_OPERAND (val, 1), 0));
18331 else
18333 op = DW_OP_plus;
18334 do_binop:
18335 loc = descr_info_loc (TREE_OPERAND (val, 0), base_decl);
18336 if (!loc)
18337 break;
18338 loc2 = descr_info_loc (TREE_OPERAND (val, 1), base_decl);
18339 if (!loc2)
18340 break;
18341 add_loc_descr (&loc, loc2);
18342 add_loc_descr (&loc2, new_loc_descr (op, 0, 0));
18344 return loc;
18345 case MINUS_EXPR:
18346 op = DW_OP_minus;
18347 goto do_binop;
18348 case MULT_EXPR:
18349 op = DW_OP_mul;
18350 goto do_binop;
18351 case EQ_EXPR:
18352 op = DW_OP_eq;
18353 goto do_binop;
18354 case NE_EXPR:
18355 op = DW_OP_ne;
18356 goto do_binop;
18357 default:
18358 break;
18360 return NULL;
18363 static void
18364 add_descr_info_field (dw_die_ref die, enum dwarf_attribute attr,
18365 tree val, tree base_decl)
18367 dw_loc_descr_ref loc;
18369 if (host_integerp (val, 0))
18371 add_AT_unsigned (die, attr, tree_low_cst (val, 0));
18372 return;
18375 loc = descr_info_loc (val, base_decl);
18376 if (!loc)
18377 return;
18379 add_AT_loc (die, attr, loc);
18382 /* This routine generates DIE for array with hidden descriptor, details
18383 are filled into *info by a langhook. */
18385 static void
18386 gen_descr_array_type_die (tree type, struct array_descr_info *info,
18387 dw_die_ref context_die)
18389 dw_die_ref scope_die = scope_die_for (type, context_die);
18390 dw_die_ref array_die;
18391 int dim;
18393 array_die = new_die (DW_TAG_array_type, scope_die, type);
18394 add_name_attribute (array_die, type_tag (type));
18395 equate_type_number_to_die (type, array_die);
18397 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
18398 if (is_fortran ()
18399 && info->ndimensions >= 2)
18400 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);
18402 if (info->data_location)
18403 add_descr_info_field (array_die, DW_AT_data_location, info->data_location,
18404 info->base_decl);
18405 if (info->associated)
18406 add_descr_info_field (array_die, DW_AT_associated, info->associated,
18407 info->base_decl);
18408 if (info->allocated)
18409 add_descr_info_field (array_die, DW_AT_allocated, info->allocated,
18410 info->base_decl);
18412 for (dim = 0; dim < info->ndimensions; dim++)
18414 dw_die_ref subrange_die
18415 = new_die (DW_TAG_subrange_type, array_die, NULL);
18417 if (info->dimen[dim].lower_bound)
18419 /* If it is the default value, omit it. */
18420 int dflt;
18422 if (host_integerp (info->dimen[dim].lower_bound, 0)
18423 && (dflt = lower_bound_default ()) != -1
18424 && tree_low_cst (info->dimen[dim].lower_bound, 0) == dflt)
18426 else
18427 add_descr_info_field (subrange_die, DW_AT_lower_bound,
18428 info->dimen[dim].lower_bound,
18429 info->base_decl);
18431 if (info->dimen[dim].upper_bound)
18432 add_descr_info_field (subrange_die, DW_AT_upper_bound,
18433 info->dimen[dim].upper_bound,
18434 info->base_decl);
18435 if (info->dimen[dim].stride)
18436 add_descr_info_field (subrange_die, DW_AT_byte_stride,
18437 info->dimen[dim].stride,
18438 info->base_decl);
18441 gen_type_die (info->element_type, context_die);
18442 add_type_attribute (array_die, info->element_type, 0, 0, context_die);
18444 if (get_AT (array_die, DW_AT_name))
18445 add_pubtype (type, array_die);
18448 #if 0
18449 static void
18450 gen_entry_point_die (tree decl, dw_die_ref context_die)
18452 tree origin = decl_ultimate_origin (decl);
18453 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
18455 if (origin != NULL)
18456 add_abstract_origin_attribute (decl_die, origin);
18457 else
18459 add_name_and_src_coords_attributes (decl_die, decl);
18460 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
18461 0, 0, context_die);
18464 if (DECL_ABSTRACT (decl))
18465 equate_decl_number_to_die (decl, decl_die);
18466 else
18467 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
18469 #endif
18471 /* Walk through the list of incomplete types again, trying once more to
18472 emit full debugging info for them. */
18474 static void
18475 retry_incomplete_types (void)
18477 int i;
18479 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
18480 if (should_emit_struct_debug (VEC_index (tree, incomplete_types, i),
18481 DINFO_USAGE_DIR_USE))
18482 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die ());
18485 /* Determine what tag to use for a record type. */
18487 static enum dwarf_tag
18488 record_type_tag (tree type)
18490 if (! lang_hooks.types.classify_record)
18491 return DW_TAG_structure_type;
18493 switch (lang_hooks.types.classify_record (type))
18495 case RECORD_IS_STRUCT:
18496 return DW_TAG_structure_type;
18498 case RECORD_IS_CLASS:
18499 return DW_TAG_class_type;
18501 case RECORD_IS_INTERFACE:
18502 if (dwarf_version >= 3 || !dwarf_strict)
18503 return DW_TAG_interface_type;
18504 return DW_TAG_structure_type;
18506 default:
18507 gcc_unreachable ();
18511 /* Generate a DIE to represent an enumeration type. Note that these DIEs
18512 include all of the information about the enumeration values also. Each
18513 enumerated type name/value is listed as a child of the enumerated type
18514 DIE. */
18516 static dw_die_ref
18517 gen_enumeration_type_die (tree type, dw_die_ref context_die)
18519 dw_die_ref type_die = lookup_type_die (type);
18521 if (type_die == NULL)
18523 type_die = new_die (DW_TAG_enumeration_type,
18524 scope_die_for (type, context_die), type);
18525 equate_type_number_to_die (type, type_die);
18526 add_name_attribute (type_die, type_tag (type));
18527 add_gnat_descriptive_type_attribute (type_die, type, context_die);
18528 if (dwarf_version >= 4 || !dwarf_strict)
18530 if (ENUM_IS_SCOPED (type))
18531 add_AT_flag (type_die, DW_AT_enum_class, 1);
18532 if (ENUM_IS_OPAQUE (type))
18533 add_AT_flag (type_die, DW_AT_declaration, 1);
18536 else if (! TYPE_SIZE (type))
18537 return type_die;
18538 else
18539 remove_AT (type_die, DW_AT_declaration);
18541 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
18542 given enum type is incomplete, do not generate the DW_AT_byte_size
18543 attribute or the DW_AT_element_list attribute. */
18544 if (TYPE_SIZE (type))
18546 tree link;
18548 TREE_ASM_WRITTEN (type) = 1;
18549 add_byte_size_attribute (type_die, type);
18550 if (TYPE_STUB_DECL (type) != NULL_TREE)
18552 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
18553 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
18556 /* If the first reference to this type was as the return type of an
18557 inline function, then it may not have a parent. Fix this now. */
18558 if (type_die->die_parent == NULL)
18559 add_child_die (scope_die_for (type, context_die), type_die);
18561 for (link = TYPE_VALUES (type);
18562 link != NULL; link = TREE_CHAIN (link))
18564 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
18565 tree value = TREE_VALUE (link);
18567 add_name_attribute (enum_die,
18568 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
18570 if (TREE_CODE (value) == CONST_DECL)
18571 value = DECL_INITIAL (value);
18573 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
18574 /* DWARF2 does not provide a way of indicating whether or
18575 not enumeration constants are signed or unsigned. GDB
18576 always assumes the values are signed, so we output all
18577 values as if they were signed. That means that
18578 enumeration constants with very large unsigned values
18579 will appear to have negative values in the debugger. */
18580 add_AT_int (enum_die, DW_AT_const_value,
18581 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
18584 else
18585 add_AT_flag (type_die, DW_AT_declaration, 1);
18587 if (get_AT (type_die, DW_AT_name))
18588 add_pubtype (type, type_die);
18590 return type_die;
18593 /* Generate a DIE to represent either a real live formal parameter decl or to
18594 represent just the type of some formal parameter position in some function
18595 type.
18597 Note that this routine is a bit unusual because its argument may be a
18598 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
18599 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
18600 node. If it's the former then this function is being called to output a
18601 DIE to represent a formal parameter object (or some inlining thereof). If
18602 it's the latter, then this function is only being called to output a
18603 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
18604 argument type of some subprogram type.
18605 If EMIT_NAME_P is true, name and source coordinate attributes
18606 are emitted. */
18608 static dw_die_ref
18609 gen_formal_parameter_die (tree node, tree origin, bool emit_name_p,
18610 dw_die_ref context_die)
18612 tree node_or_origin = node ? node : origin;
18613 tree ultimate_origin;
18614 dw_die_ref parm_die
18615 = new_die (DW_TAG_formal_parameter, context_die, node);
18617 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin)))
18619 case tcc_declaration:
18620 ultimate_origin = decl_ultimate_origin (node_or_origin);
18621 if (node || ultimate_origin)
18622 origin = ultimate_origin;
18623 if (origin != NULL)
18624 add_abstract_origin_attribute (parm_die, origin);
18625 else if (emit_name_p)
18626 add_name_and_src_coords_attributes (parm_die, node);
18627 if (origin == NULL
18628 || (! DECL_ABSTRACT (node_or_origin)
18629 && variably_modified_type_p (TREE_TYPE (node_or_origin),
18630 decl_function_context
18631 (node_or_origin))))
18633 tree type = TREE_TYPE (node_or_origin);
18634 if (decl_by_reference_p (node_or_origin))
18635 add_type_attribute (parm_die, TREE_TYPE (type), 0, 0,
18636 context_die);
18637 else
18638 add_type_attribute (parm_die, type,
18639 TREE_READONLY (node_or_origin),
18640 TREE_THIS_VOLATILE (node_or_origin),
18641 context_die);
18643 if (origin == NULL && DECL_ARTIFICIAL (node))
18644 add_AT_flag (parm_die, DW_AT_artificial, 1);
18646 if (node && node != origin)
18647 equate_decl_number_to_die (node, parm_die);
18648 if (! DECL_ABSTRACT (node_or_origin))
18649 add_location_or_const_value_attribute (parm_die, node_or_origin,
18650 node == NULL, DW_AT_location);
18652 break;
18654 case tcc_type:
18655 /* We were called with some kind of a ..._TYPE node. */
18656 add_type_attribute (parm_die, node_or_origin, 0, 0, context_die);
18657 break;
18659 default:
18660 gcc_unreachable ();
18663 return parm_die;
18666 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18667 children DW_TAG_formal_parameter DIEs representing the arguments of the
18668 parameter pack.
18670 PARM_PACK must be a function parameter pack.
18671 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18672 must point to the subsequent arguments of the function PACK_ARG belongs to.
18673 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18674 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18675 following the last one for which a DIE was generated. */
18677 static dw_die_ref
18678 gen_formal_parameter_pack_die (tree parm_pack,
18679 tree pack_arg,
18680 dw_die_ref subr_die,
18681 tree *next_arg)
18683 tree arg;
18684 dw_die_ref parm_pack_die;
18686 gcc_assert (parm_pack
18687 && lang_hooks.function_parameter_pack_p (parm_pack)
18688 && subr_die);
18690 parm_pack_die = new_die (DW_TAG_GNU_formal_parameter_pack, subr_die, parm_pack);
18691 add_src_coords_attributes (parm_pack_die, parm_pack);
18693 for (arg = pack_arg; arg; arg = DECL_CHAIN (arg))
18695 if (! lang_hooks.decls.function_parm_expanded_from_pack_p (arg,
18696 parm_pack))
18697 break;
18698 gen_formal_parameter_die (arg, NULL,
18699 false /* Don't emit name attribute. */,
18700 parm_pack_die);
18702 if (next_arg)
18703 *next_arg = arg;
18704 return parm_pack_die;
18707 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18708 at the end of an (ANSI prototyped) formal parameters list. */
18710 static void
18711 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
18713 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
18716 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18717 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18718 parameters as specified in some function type specification (except for
18719 those which appear as part of a function *definition*). */
18721 static void
18722 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
18724 tree link;
18725 tree formal_type = NULL;
18726 tree first_parm_type;
18727 tree arg;
18729 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
18731 arg = DECL_ARGUMENTS (function_or_method_type);
18732 function_or_method_type = TREE_TYPE (function_or_method_type);
18734 else
18735 arg = NULL_TREE;
18737 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
18739 /* Make our first pass over the list of formal parameter types and output a
18740 DW_TAG_formal_parameter DIE for each one. */
18741 for (link = first_parm_type; link; )
18743 dw_die_ref parm_die;
18745 formal_type = TREE_VALUE (link);
18746 if (formal_type == void_type_node)
18747 break;
18749 /* Output a (nameless) DIE to represent the formal parameter itself. */
18750 parm_die = gen_formal_parameter_die (formal_type, NULL,
18751 true /* Emit name attribute. */,
18752 context_die);
18753 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
18754 && link == first_parm_type)
18756 add_AT_flag (parm_die, DW_AT_artificial, 1);
18757 if (dwarf_version >= 3 || !dwarf_strict)
18758 add_AT_die_ref (context_die, DW_AT_object_pointer, parm_die);
18760 else if (arg && DECL_ARTIFICIAL (arg))
18761 add_AT_flag (parm_die, DW_AT_artificial, 1);
18763 link = TREE_CHAIN (link);
18764 if (arg)
18765 arg = DECL_CHAIN (arg);
18768 /* If this function type has an ellipsis, add a
18769 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18770 if (formal_type != void_type_node)
18771 gen_unspecified_parameters_die (function_or_method_type, context_die);
18773 /* Make our second (and final) pass over the list of formal parameter types
18774 and output DIEs to represent those types (as necessary). */
18775 for (link = TYPE_ARG_TYPES (function_or_method_type);
18776 link && TREE_VALUE (link);
18777 link = TREE_CHAIN (link))
18778 gen_type_die (TREE_VALUE (link), context_die);
18781 /* We want to generate the DIE for TYPE so that we can generate the
18782 die for MEMBER, which has been defined; we will need to refer back
18783 to the member declaration nested within TYPE. If we're trying to
18784 generate minimal debug info for TYPE, processing TYPE won't do the
18785 trick; we need to attach the member declaration by hand. */
18787 static void
18788 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
18790 gen_type_die (type, context_die);
18792 /* If we're trying to avoid duplicate debug info, we may not have
18793 emitted the member decl for this function. Emit it now. */
18794 if (TYPE_STUB_DECL (type)
18795 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
18796 && ! lookup_decl_die (member))
18798 dw_die_ref type_die;
18799 gcc_assert (!decl_ultimate_origin (member));
18801 push_decl_scope (type);
18802 type_die = lookup_type_die_strip_naming_typedef (type);
18803 if (TREE_CODE (member) == FUNCTION_DECL)
18804 gen_subprogram_die (member, type_die);
18805 else if (TREE_CODE (member) == FIELD_DECL)
18807 /* Ignore the nameless fields that are used to skip bits but handle
18808 C++ anonymous unions and structs. */
18809 if (DECL_NAME (member) != NULL_TREE
18810 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
18811 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
18813 gen_type_die (member_declared_type (member), type_die);
18814 gen_field_die (member, type_die);
18817 else
18818 gen_variable_die (member, NULL_TREE, type_die);
18820 pop_decl_scope ();
18824 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18825 may later generate inlined and/or out-of-line instances of. */
18827 static void
18828 dwarf2out_abstract_function (tree decl)
18830 dw_die_ref old_die;
18831 tree save_fn;
18832 tree context;
18833 int was_abstract;
18834 htab_t old_decl_loc_table;
18835 htab_t old_cached_dw_loc_list_table;
18836 int old_call_site_count, old_tail_call_site_count;
18837 struct call_arg_loc_node *old_call_arg_locations;
18839 /* Make sure we have the actual abstract inline, not a clone. */
18840 decl = DECL_ORIGIN (decl);
18842 old_die = lookup_decl_die (decl);
18843 if (old_die && get_AT (old_die, DW_AT_inline))
18844 /* We've already generated the abstract instance. */
18845 return;
18847 /* We can be called while recursively when seeing block defining inlined subroutine
18848 DIE. Be sure to not clobber the outer location table nor use it or we would
18849 get locations in abstract instantces. */
18850 old_decl_loc_table = decl_loc_table;
18851 decl_loc_table = NULL;
18852 old_cached_dw_loc_list_table = cached_dw_loc_list_table;
18853 cached_dw_loc_list_table = NULL;
18854 old_call_arg_locations = call_arg_locations;
18855 call_arg_locations = NULL;
18856 old_call_site_count = call_site_count;
18857 call_site_count = -1;
18858 old_tail_call_site_count = tail_call_site_count;
18859 tail_call_site_count = -1;
18861 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18862 we don't get confused by DECL_ABSTRACT. */
18863 if (debug_info_level > DINFO_LEVEL_TERSE)
18865 context = decl_class_context (decl);
18866 if (context)
18867 gen_type_die_for_member
18868 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die ());
18871 /* Pretend we've just finished compiling this function. */
18872 save_fn = current_function_decl;
18873 current_function_decl = decl;
18874 push_cfun (DECL_STRUCT_FUNCTION (decl));
18876 was_abstract = DECL_ABSTRACT (decl);
18877 set_decl_abstract_flags (decl, 1);
18878 dwarf2out_decl (decl);
18879 if (! was_abstract)
18880 set_decl_abstract_flags (decl, 0);
18882 current_function_decl = save_fn;
18883 decl_loc_table = old_decl_loc_table;
18884 cached_dw_loc_list_table = old_cached_dw_loc_list_table;
18885 call_arg_locations = old_call_arg_locations;
18886 call_site_count = old_call_site_count;
18887 tail_call_site_count = old_tail_call_site_count;
18888 pop_cfun ();
18891 /* Helper function of premark_used_types() which gets called through
18892 htab_traverse.
18894 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18895 marked as unused by prune_unused_types. */
18897 static int
18898 premark_used_types_helper (void **slot, void *data ATTRIBUTE_UNUSED)
18900 tree type;
18901 dw_die_ref die;
18903 type = (tree) *slot;
18904 die = lookup_type_die (type);
18905 if (die != NULL)
18906 die->die_perennial_p = 1;
18907 return 1;
18910 /* Helper function of premark_types_used_by_global_vars which gets called
18911 through htab_traverse.
18913 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18914 marked as unused by prune_unused_types. The DIE of the type is marked
18915 only if the global variable using the type will actually be emitted. */
18917 static int
18918 premark_types_used_by_global_vars_helper (void **slot,
18919 void *data ATTRIBUTE_UNUSED)
18921 struct types_used_by_vars_entry *entry;
18922 dw_die_ref die;
18924 entry = (struct types_used_by_vars_entry *) *slot;
18925 gcc_assert (entry->type != NULL
18926 && entry->var_decl != NULL);
18927 die = lookup_type_die (entry->type);
18928 if (die)
18930 /* Ask cgraph if the global variable really is to be emitted.
18931 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18932 struct varpool_node *node = varpool_get_node (entry->var_decl);
18933 if (node && node->needed)
18935 die->die_perennial_p = 1;
18936 /* Keep the parent DIEs as well. */
18937 while ((die = die->die_parent) && die->die_perennial_p == 0)
18938 die->die_perennial_p = 1;
18941 return 1;
18944 /* Mark all members of used_types_hash as perennial. */
18946 static void
18947 premark_used_types (void)
18949 if (cfun && cfun->used_types_hash)
18950 htab_traverse (cfun->used_types_hash, premark_used_types_helper, NULL);
18953 /* Mark all members of types_used_by_vars_entry as perennial. */
18955 static void
18956 premark_types_used_by_global_vars (void)
18958 if (types_used_by_vars_hash)
18959 htab_traverse (types_used_by_vars_hash,
18960 premark_types_used_by_global_vars_helper, NULL);
18963 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18964 for CA_LOC call arg loc node. */
18966 static dw_die_ref
18967 gen_call_site_die (tree decl, dw_die_ref subr_die,
18968 struct call_arg_loc_node *ca_loc)
18970 dw_die_ref stmt_die = NULL, die;
18971 tree block = ca_loc->block;
18973 while (block
18974 && block != DECL_INITIAL (decl)
18975 && TREE_CODE (block) == BLOCK)
18977 if (VEC_length (dw_die_ref, block_map) > BLOCK_NUMBER (block))
18978 stmt_die = VEC_index (dw_die_ref, block_map, BLOCK_NUMBER (block));
18979 if (stmt_die)
18980 break;
18981 block = BLOCK_SUPERCONTEXT (block);
18983 if (stmt_die == NULL)
18984 stmt_die = subr_die;
18985 die = new_die (DW_TAG_GNU_call_site, stmt_die, NULL_TREE);
18986 add_AT_lbl_id (die, DW_AT_low_pc, ca_loc->label);
18987 if (ca_loc->tail_call_p)
18988 add_AT_flag (die, DW_AT_GNU_tail_call, 1);
18989 if (ca_loc->symbol_ref)
18991 dw_die_ref tdie = lookup_decl_die (SYMBOL_REF_DECL (ca_loc->symbol_ref));
18992 if (tdie)
18993 add_AT_die_ref (die, DW_AT_abstract_origin, tdie);
18994 else
18995 add_AT_addr (die, DW_AT_abstract_origin, ca_loc->symbol_ref);
18997 return die;
19000 /* Generate a DIE to represent a declared function (either file-scope or
19001 block-local). */
19003 static void
19004 gen_subprogram_die (tree decl, dw_die_ref context_die)
19006 tree origin = decl_ultimate_origin (decl);
19007 dw_die_ref subr_die;
19008 tree outer_scope;
19009 dw_die_ref old_die = lookup_decl_die (decl);
19010 int declaration = (current_function_decl != decl
19011 || class_or_namespace_scope_p (context_die));
19013 premark_used_types ();
19015 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
19016 started to generate the abstract instance of an inline, decided to output
19017 its containing class, and proceeded to emit the declaration of the inline
19018 from the member list for the class. If so, DECLARATION takes priority;
19019 we'll get back to the abstract instance when done with the class. */
19021 /* The class-scope declaration DIE must be the primary DIE. */
19022 if (origin && declaration && class_or_namespace_scope_p (context_die))
19024 origin = NULL;
19025 gcc_assert (!old_die);
19028 /* Now that the C++ front end lazily declares artificial member fns, we
19029 might need to retrofit the declaration into its class. */
19030 if (!declaration && !origin && !old_die
19031 && DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl))
19032 && !class_or_namespace_scope_p (context_die)
19033 && debug_info_level > DINFO_LEVEL_TERSE)
19034 old_die = force_decl_die (decl);
19036 if (origin != NULL)
19038 gcc_assert (!declaration || local_scope_p (context_die));
19040 /* Fixup die_parent for the abstract instance of a nested
19041 inline function. */
19042 if (old_die && old_die->die_parent == NULL)
19043 add_child_die (context_die, old_die);
19045 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19046 add_abstract_origin_attribute (subr_die, origin);
19048 else if (old_die)
19050 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19051 struct dwarf_file_data * file_index = lookup_filename (s.file);
19053 if (!get_AT_flag (old_die, DW_AT_declaration)
19054 /* We can have a normal definition following an inline one in the
19055 case of redefinition of GNU C extern inlines.
19056 It seems reasonable to use AT_specification in this case. */
19057 && !get_AT (old_die, DW_AT_inline))
19059 /* Detect and ignore this case, where we are trying to output
19060 something we have already output. */
19061 return;
19064 /* If the definition comes from the same place as the declaration,
19065 maybe use the old DIE. We always want the DIE for this function
19066 that has the *_pc attributes to be under comp_unit_die so the
19067 debugger can find it. We also need to do this for abstract
19068 instances of inlines, since the spec requires the out-of-line copy
19069 to have the same parent. For local class methods, this doesn't
19070 apply; we just use the old DIE. */
19071 if ((is_cu_die (old_die->die_parent) || context_die == NULL)
19072 && (DECL_ARTIFICIAL (decl)
19073 || (get_AT_file (old_die, DW_AT_decl_file) == file_index
19074 && (get_AT_unsigned (old_die, DW_AT_decl_line)
19075 == (unsigned) s.line))))
19077 subr_die = old_die;
19079 /* Clear out the declaration attribute and the formal parameters.
19080 Do not remove all children, because it is possible that this
19081 declaration die was forced using force_decl_die(). In such
19082 cases die that forced declaration die (e.g. TAG_imported_module)
19083 is one of the children that we do not want to remove. */
19084 remove_AT (subr_die, DW_AT_declaration);
19085 remove_AT (subr_die, DW_AT_object_pointer);
19086 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
19088 else
19090 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19091 add_AT_specification (subr_die, old_die);
19092 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19093 add_AT_file (subr_die, DW_AT_decl_file, file_index);
19094 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19095 add_AT_unsigned (subr_die, DW_AT_decl_line, s.line);
19098 else
19100 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
19102 if (TREE_PUBLIC (decl))
19103 add_AT_flag (subr_die, DW_AT_external, 1);
19105 add_name_and_src_coords_attributes (subr_die, decl);
19106 if (debug_info_level > DINFO_LEVEL_TERSE)
19108 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
19109 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
19110 0, 0, context_die);
19113 add_pure_or_virtual_attribute (subr_die, decl);
19114 if (DECL_ARTIFICIAL (decl))
19115 add_AT_flag (subr_die, DW_AT_artificial, 1);
19117 add_accessibility_attribute (subr_die, decl);
19120 if (declaration)
19122 if (!old_die || !get_AT (old_die, DW_AT_inline))
19124 add_AT_flag (subr_die, DW_AT_declaration, 1);
19126 /* If this is an explicit function declaration then generate
19127 a DW_AT_explicit attribute. */
19128 if (lang_hooks.decls.function_decl_explicit_p (decl)
19129 && (dwarf_version >= 3 || !dwarf_strict))
19130 add_AT_flag (subr_die, DW_AT_explicit, 1);
19132 /* The first time we see a member function, it is in the context of
19133 the class to which it belongs. We make sure of this by emitting
19134 the class first. The next time is the definition, which is
19135 handled above. The two may come from the same source text.
19137 Note that force_decl_die() forces function declaration die. It is
19138 later reused to represent definition. */
19139 equate_decl_number_to_die (decl, subr_die);
19142 else if (DECL_ABSTRACT (decl))
19144 if (DECL_DECLARED_INLINE_P (decl))
19146 if (cgraph_function_possibly_inlined_p (decl))
19147 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
19148 else
19149 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
19151 else
19153 if (cgraph_function_possibly_inlined_p (decl))
19154 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
19155 else
19156 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
19159 if (DECL_DECLARED_INLINE_P (decl)
19160 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl)))
19161 add_AT_flag (subr_die, DW_AT_artificial, 1);
19163 equate_decl_number_to_die (decl, subr_die);
19165 else if (!DECL_EXTERNAL (decl))
19167 HOST_WIDE_INT cfa_fb_offset;
19169 if (!old_die || !get_AT (old_die, DW_AT_inline))
19170 equate_decl_number_to_die (decl, subr_die);
19172 if (!flag_reorder_blocks_and_partition)
19174 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19175 if (fde->dw_fde_begin)
19177 /* We have already generated the labels. */
19178 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19179 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19181 else
19183 /* Create start/end labels and add the range. */
19184 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
19185 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
19186 current_function_funcdef_no);
19187 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
19188 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
19189 current_function_funcdef_no);
19190 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
19193 #if VMS_DEBUGGING_INFO
19194 /* HP OpenVMS Industry Standard 64: DWARF Extensions
19195 Section 2.3 Prologue and Epilogue Attributes:
19196 When a breakpoint is set on entry to a function, it is generally
19197 desirable for execution to be suspended, not on the very first
19198 instruction of the function, but rather at a point after the
19199 function's frame has been set up, after any language defined local
19200 declaration processing has been completed, and before execution of
19201 the first statement of the function begins. Debuggers generally
19202 cannot properly determine where this point is. Similarly for a
19203 breakpoint set on exit from a function. The prologue and epilogue
19204 attributes allow a compiler to communicate the location(s) to use. */
19207 if (fde->dw_fde_vms_end_prologue)
19208 add_AT_vms_delta (subr_die, DW_AT_HP_prologue,
19209 fde->dw_fde_begin, fde->dw_fde_vms_end_prologue);
19211 if (fde->dw_fde_vms_begin_epilogue)
19212 add_AT_vms_delta (subr_die, DW_AT_HP_epilogue,
19213 fde->dw_fde_begin, fde->dw_fde_vms_begin_epilogue);
19215 #endif
19217 add_pubname (decl, subr_die);
19219 else
19220 { /* Generate pubnames entries for the split function code
19221 ranges. */
19222 dw_fde_ref fde = &fde_table[current_funcdef_fde];
19224 if (fde->dw_fde_second_begin)
19226 if (dwarf_version >= 3 || !dwarf_strict)
19228 /* We should use ranges for non-contiguous code section
19229 addresses. Use the actual code range for the initial
19230 section, since the HOT/COLD labels might precede an
19231 alignment offset. */
19232 bool range_list_added = false;
19233 add_ranges_by_labels (subr_die, fde->dw_fde_begin,
19234 fde->dw_fde_end, &range_list_added);
19235 add_ranges_by_labels (subr_die, fde->dw_fde_second_begin,
19236 fde->dw_fde_second_end,
19237 &range_list_added);
19238 add_pubname (decl, subr_die);
19239 if (range_list_added)
19240 add_ranges (NULL);
19242 else
19244 /* There is no real support in DW2 for this .. so we make
19245 a work-around. First, emit the pub name for the segment
19246 containing the function label. Then make and emit a
19247 simplified subprogram DIE for the second segment with the
19248 name pre-fixed by __hot/cold_sect_of_. We use the same
19249 linkage name for the second die so that gdb will find both
19250 sections when given "b foo". */
19251 const char *name = NULL;
19252 tree decl_name = DECL_NAME (decl);
19253 dw_die_ref seg_die;
19255 /* Do the 'primary' section. */
19256 add_AT_lbl_id (subr_die, DW_AT_low_pc,
19257 fde->dw_fde_begin);
19258 add_AT_lbl_id (subr_die, DW_AT_high_pc,
19259 fde->dw_fde_end);
19260 /* Add it. */
19261 add_pubname (decl, subr_die);
19263 /* Build a minimal DIE for the secondary section. */
19264 seg_die = new_die (DW_TAG_subprogram,
19265 subr_die->die_parent, decl);
19267 if (TREE_PUBLIC (decl))
19268 add_AT_flag (seg_die, DW_AT_external, 1);
19270 if (decl_name != NULL
19271 && IDENTIFIER_POINTER (decl_name) != NULL)
19273 name = dwarf2_name (decl, 1);
19274 if (! DECL_ARTIFICIAL (decl))
19275 add_src_coords_attributes (seg_die, decl);
19277 add_linkage_name (seg_die, decl);
19279 gcc_assert (name != NULL);
19280 add_pure_or_virtual_attribute (seg_die, decl);
19281 if (DECL_ARTIFICIAL (decl))
19282 add_AT_flag (seg_die, DW_AT_artificial, 1);
19284 name = concat ("__second_sect_of_", name, NULL);
19285 add_AT_lbl_id (seg_die, DW_AT_low_pc,
19286 fde->dw_fde_second_begin);
19287 add_AT_lbl_id (seg_die, DW_AT_high_pc,
19288 fde->dw_fde_second_end);
19289 add_name_attribute (seg_die, name);
19290 add_pubname_string (name, seg_die);
19293 else
19295 add_AT_lbl_id (subr_die, DW_AT_low_pc, fde->dw_fde_begin);
19296 add_AT_lbl_id (subr_die, DW_AT_high_pc, fde->dw_fde_end);
19297 add_pubname (decl, subr_die);
19301 #ifdef MIPS_DEBUGGING_INFO
19302 /* Add a reference to the FDE for this routine. */
19303 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
19304 #endif
19306 cfa_fb_offset = CFA_FRAME_BASE_OFFSET (decl);
19308 /* We define the "frame base" as the function's CFA. This is more
19309 convenient for several reasons: (1) It's stable across the prologue
19310 and epilogue, which makes it better than just a frame pointer,
19311 (2) With dwarf3, there exists a one-byte encoding that allows us
19312 to reference the .debug_frame data by proxy, but failing that,
19313 (3) We can at least reuse the code inspection and interpretation
19314 code that determines the CFA position at various points in the
19315 function. */
19316 if (dwarf_version >= 3)
19318 dw_loc_descr_ref op = new_loc_descr (DW_OP_call_frame_cfa, 0, 0);
19319 add_AT_loc (subr_die, DW_AT_frame_base, op);
19321 else
19323 dw_loc_list_ref list = convert_cfa_to_fb_loc_list (cfa_fb_offset);
19324 if (list->dw_loc_next)
19325 add_AT_loc_list (subr_die, DW_AT_frame_base, list);
19326 else
19327 add_AT_loc (subr_die, DW_AT_frame_base, list->expr);
19330 /* Compute a displacement from the "steady-state frame pointer" to
19331 the CFA. The former is what all stack slots and argument slots
19332 will reference in the rtl; the later is what we've told the
19333 debugger about. We'll need to adjust all frame_base references
19334 by this displacement. */
19335 compute_frame_pointer_to_fb_displacement (cfa_fb_offset);
19337 if (cfun->static_chain_decl)
19338 add_AT_location_description (subr_die, DW_AT_static_link,
19339 loc_list_from_tree (cfun->static_chain_decl, 2));
19342 /* Generate child dies for template paramaters. */
19343 if (debug_info_level > DINFO_LEVEL_TERSE)
19344 gen_generic_params_dies (decl);
19346 /* Now output descriptions of the arguments for this function. This gets
19347 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19348 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19349 `...' at the end of the formal parameter list. In order to find out if
19350 there was a trailing ellipsis or not, we must instead look at the type
19351 associated with the FUNCTION_DECL. This will be a node of type
19352 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19353 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19354 an ellipsis at the end. */
19356 /* In the case where we are describing a mere function declaration, all we
19357 need to do here (and all we *can* do here) is to describe the *types* of
19358 its formal parameters. */
19359 if (debug_info_level <= DINFO_LEVEL_TERSE)
19361 else if (declaration)
19362 gen_formal_types_die (decl, subr_die);
19363 else
19365 /* Generate DIEs to represent all known formal parameters. */
19366 tree parm = DECL_ARGUMENTS (decl);
19367 tree generic_decl = lang_hooks.decls.get_generic_function_decl (decl);
19368 tree generic_decl_parm = generic_decl
19369 ? DECL_ARGUMENTS (generic_decl)
19370 : NULL;
19372 /* Now we want to walk the list of parameters of the function and
19373 emit their relevant DIEs.
19375 We consider the case of DECL being an instance of a generic function
19376 as well as it being a normal function.
19378 If DECL is an instance of a generic function we walk the
19379 parameters of the generic function declaration _and_ the parameters of
19380 DECL itself. This is useful because we want to emit specific DIEs for
19381 function parameter packs and those are declared as part of the
19382 generic function declaration. In that particular case,
19383 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19384 That DIE has children DIEs representing the set of arguments
19385 of the pack. Note that the set of pack arguments can be empty.
19386 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19387 children DIE.
19389 Otherwise, we just consider the parameters of DECL. */
19390 while (generic_decl_parm || parm)
19392 if (generic_decl_parm
19393 && lang_hooks.function_parameter_pack_p (generic_decl_parm))
19394 gen_formal_parameter_pack_die (generic_decl_parm,
19395 parm, subr_die,
19396 &parm);
19397 else if (parm)
19399 dw_die_ref parm_die = gen_decl_die (parm, NULL, subr_die);
19401 if (parm == DECL_ARGUMENTS (decl)
19402 && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
19403 && parm_die
19404 && (dwarf_version >= 3 || !dwarf_strict))
19405 add_AT_die_ref (subr_die, DW_AT_object_pointer, parm_die);
19407 parm = DECL_CHAIN (parm);
19410 if (generic_decl_parm)
19411 generic_decl_parm = DECL_CHAIN (generic_decl_parm);
19414 /* Decide whether we need an unspecified_parameters DIE at the end.
19415 There are 2 more cases to do this for: 1) the ansi ... declaration -
19416 this is detectable when the end of the arg list is not a
19417 void_type_node 2) an unprototyped function declaration (not a
19418 definition). This just means that we have no info about the
19419 parameters at all. */
19420 if (prototype_p (TREE_TYPE (decl)))
19422 /* This is the prototyped case, check for.... */
19423 if (stdarg_p (TREE_TYPE (decl)))
19424 gen_unspecified_parameters_die (decl, subr_die);
19426 else if (DECL_INITIAL (decl) == NULL_TREE)
19427 gen_unspecified_parameters_die (decl, subr_die);
19430 /* Output Dwarf info for all of the stuff within the body of the function
19431 (if it has one - it may be just a declaration). */
19432 outer_scope = DECL_INITIAL (decl);
19434 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19435 a function. This BLOCK actually represents the outermost binding contour
19436 for the function, i.e. the contour in which the function's formal
19437 parameters and labels get declared. Curiously, it appears that the front
19438 end doesn't actually put the PARM_DECL nodes for the current function onto
19439 the BLOCK_VARS list for this outer scope, but are strung off of the
19440 DECL_ARGUMENTS list for the function instead.
19442 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19443 the LABEL_DECL nodes for the function however, and we output DWARF info
19444 for those in decls_for_scope. Just within the `outer_scope' there will be
19445 a BLOCK node representing the function's outermost pair of curly braces,
19446 and any blocks used for the base and member initializers of a C++
19447 constructor function. */
19448 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
19450 int call_site_note_count = 0;
19451 int tail_call_site_note_count = 0;
19453 /* Emit a DW_TAG_variable DIE for a named return value. */
19454 if (DECL_NAME (DECL_RESULT (decl)))
19455 gen_decl_die (DECL_RESULT (decl), NULL, subr_die);
19457 current_function_has_inlines = 0;
19458 decls_for_scope (outer_scope, subr_die, 0);
19460 if (call_arg_locations && !dwarf_strict)
19462 struct call_arg_loc_node *ca_loc;
19463 for (ca_loc = call_arg_locations; ca_loc; ca_loc = ca_loc->next)
19465 dw_die_ref die = NULL;
19466 rtx tloc = NULL_RTX, tlocc = NULL_RTX;
19467 rtx arg, next_arg;
19469 for (arg = NOTE_VAR_LOCATION (ca_loc->call_arg_loc_note);
19470 arg; arg = next_arg)
19472 dw_loc_descr_ref reg, val;
19473 enum machine_mode mode = GET_MODE (XEXP (XEXP (arg, 0), 1));
19474 dw_die_ref cdie;
19476 next_arg = XEXP (arg, 1);
19477 if (REG_P (XEXP (XEXP (arg, 0), 0))
19478 && next_arg
19479 && MEM_P (XEXP (XEXP (next_arg, 0), 0))
19480 && REG_P (XEXP (XEXP (XEXP (next_arg, 0), 0), 0))
19481 && REGNO (XEXP (XEXP (arg, 0), 0))
19482 == REGNO (XEXP (XEXP (XEXP (next_arg, 0), 0), 0)))
19483 next_arg = XEXP (next_arg, 1);
19484 if (mode == VOIDmode)
19486 mode = GET_MODE (XEXP (XEXP (arg, 0), 0));
19487 if (mode == VOIDmode)
19488 mode = GET_MODE (XEXP (arg, 0));
19490 if (GET_MODE_CLASS (mode) != MODE_INT
19491 || GET_MODE_SIZE (mode) > DWARF2_ADDR_SIZE)
19492 continue;
19493 if (XEXP (XEXP (arg, 0), 0) == pc_rtx)
19495 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19496 tloc = XEXP (XEXP (arg, 0), 1);
19497 continue;
19499 else if (GET_CODE (XEXP (XEXP (arg, 0), 0)) == CLOBBER
19500 && XEXP (XEXP (XEXP (arg, 0), 0), 0) == pc_rtx)
19502 gcc_assert (ca_loc->symbol_ref == NULL_RTX);
19503 tlocc = XEXP (XEXP (arg, 0), 1);
19504 continue;
19506 if (REG_P (XEXP (XEXP (arg, 0), 0)))
19507 reg = reg_loc_descriptor (XEXP (XEXP (arg, 0), 0),
19508 VAR_INIT_STATUS_INITIALIZED);
19509 else if (MEM_P (XEXP (XEXP (arg, 0), 0)))
19510 reg = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 0),
19511 0), 0), mode,
19512 VAR_INIT_STATUS_INITIALIZED);
19513 else
19514 continue;
19515 if (reg == NULL)
19516 continue;
19517 val = mem_loc_descriptor (XEXP (XEXP (arg, 0), 1), VOIDmode,
19518 VAR_INIT_STATUS_INITIALIZED);
19519 if (val == NULL)
19520 continue;
19521 if (die == NULL)
19522 die = gen_call_site_die (decl, subr_die, ca_loc);
19523 cdie = new_die (DW_TAG_GNU_call_site_parameter, die,
19524 NULL_TREE);
19525 add_AT_loc (cdie, DW_AT_location, reg);
19526 add_AT_loc (cdie, DW_AT_GNU_call_site_value, val);
19527 if (next_arg != XEXP (arg, 1))
19529 val = mem_loc_descriptor (XEXP (XEXP (XEXP (arg, 1),
19530 0), 1), VOIDmode,
19531 VAR_INIT_STATUS_INITIALIZED);
19532 if (val != NULL)
19533 add_AT_loc (cdie, DW_AT_GNU_call_site_data_value, val);
19536 if (die == NULL
19537 && (ca_loc->symbol_ref || tloc))
19538 die = gen_call_site_die (decl, subr_die, ca_loc);
19539 if (die != NULL && (tloc != NULL_RTX || tlocc != NULL_RTX))
19541 dw_loc_descr_ref tval = NULL;
19543 if (tloc != NULL_RTX)
19544 tval = mem_loc_descriptor (tloc, VOIDmode,
19545 VAR_INIT_STATUS_INITIALIZED);
19546 if (tval)
19547 add_AT_loc (die, DW_AT_GNU_call_site_target, tval);
19548 else if (tlocc != NULL_RTX)
19550 tval = mem_loc_descriptor (tlocc, VOIDmode,
19551 VAR_INIT_STATUS_INITIALIZED);
19552 if (tval)
19553 add_AT_loc (die, DW_AT_GNU_call_site_target_clobbered,
19554 tval);
19557 if (die != NULL)
19559 call_site_note_count++;
19560 if (ca_loc->tail_call_p)
19561 tail_call_site_note_count++;
19565 call_arg_locations = NULL;
19566 call_arg_loc_last = NULL;
19567 if (tail_call_site_count >= 0
19568 && tail_call_site_count == tail_call_site_note_count
19569 && !dwarf_strict)
19571 if (call_site_count >= 0
19572 && call_site_count == call_site_note_count)
19573 add_AT_flag (subr_die, DW_AT_GNU_all_call_sites, 1);
19574 else
19575 add_AT_flag (subr_die, DW_AT_GNU_all_tail_call_sites, 1);
19577 call_site_count = -1;
19578 tail_call_site_count = -1;
19580 /* Add the calling convention attribute if requested. */
19581 add_calling_convention_attribute (subr_die, decl);
19585 /* Returns a hash value for X (which really is a die_struct). */
19587 static hashval_t
19588 common_block_die_table_hash (const void *x)
19590 const_dw_die_ref d = (const_dw_die_ref) x;
19591 return (hashval_t) d->decl_id ^ htab_hash_pointer (d->die_parent);
19594 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19595 as decl_id and die_parent of die_struct Y. */
19597 static int
19598 common_block_die_table_eq (const void *x, const void *y)
19600 const_dw_die_ref d = (const_dw_die_ref) x;
19601 const_dw_die_ref e = (const_dw_die_ref) y;
19602 return d->decl_id == e->decl_id && d->die_parent == e->die_parent;
19605 /* Generate a DIE to represent a declared data object.
19606 Either DECL or ORIGIN must be non-null. */
19608 static void
19609 gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
19611 HOST_WIDE_INT off;
19612 tree com_decl;
19613 tree decl_or_origin = decl ? decl : origin;
19614 tree ultimate_origin;
19615 dw_die_ref var_die;
19616 dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
19617 dw_die_ref origin_die;
19618 bool declaration = (DECL_EXTERNAL (decl_or_origin)
19619 || class_or_namespace_scope_p (context_die));
19620 bool specialization_p = false;
19622 ultimate_origin = decl_ultimate_origin (decl_or_origin);
19623 if (decl || ultimate_origin)
19624 origin = ultimate_origin;
19625 com_decl = fortran_common (decl_or_origin, &off);
19627 /* Symbol in common gets emitted as a child of the common block, in the form
19628 of a data member. */
19629 if (com_decl)
19631 dw_die_ref com_die;
19632 dw_loc_list_ref loc;
19633 die_node com_die_arg;
19635 var_die = lookup_decl_die (decl_or_origin);
19636 if (var_die)
19638 if (get_AT (var_die, DW_AT_location) == NULL)
19640 loc = loc_list_from_tree (com_decl, off ? 1 : 2);
19641 if (loc)
19643 if (off)
19645 /* Optimize the common case. */
19646 if (single_element_loc_list_p (loc)
19647 && loc->expr->dw_loc_opc == DW_OP_addr
19648 && loc->expr->dw_loc_next == NULL
19649 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr)
19650 == SYMBOL_REF)
19651 loc->expr->dw_loc_oprnd1.v.val_addr
19652 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19653 else
19654 loc_list_plus_const (loc, off);
19656 add_AT_location_description (var_die, DW_AT_location, loc);
19657 remove_AT (var_die, DW_AT_declaration);
19660 return;
19663 if (common_block_die_table == NULL)
19664 common_block_die_table
19665 = htab_create_ggc (10, common_block_die_table_hash,
19666 common_block_die_table_eq, NULL);
19668 com_die_arg.decl_id = DECL_UID (com_decl);
19669 com_die_arg.die_parent = context_die;
19670 com_die = (dw_die_ref) htab_find (common_block_die_table, &com_die_arg);
19671 loc = loc_list_from_tree (com_decl, 2);
19672 if (com_die == NULL)
19674 const char *cnam
19675 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl));
19676 void **slot;
19678 com_die = new_die (DW_TAG_common_block, context_die, decl);
19679 add_name_and_src_coords_attributes (com_die, com_decl);
19680 if (loc)
19682 add_AT_location_description (com_die, DW_AT_location, loc);
19683 /* Avoid sharing the same loc descriptor between
19684 DW_TAG_common_block and DW_TAG_variable. */
19685 loc = loc_list_from_tree (com_decl, 2);
19687 else if (DECL_EXTERNAL (decl))
19688 add_AT_flag (com_die, DW_AT_declaration, 1);
19689 add_pubname_string (cnam, com_die); /* ??? needed? */
19690 com_die->decl_id = DECL_UID (com_decl);
19691 slot = htab_find_slot (common_block_die_table, com_die, INSERT);
19692 *slot = (void *) com_die;
19694 else if (get_AT (com_die, DW_AT_location) == NULL && loc)
19696 add_AT_location_description (com_die, DW_AT_location, loc);
19697 loc = loc_list_from_tree (com_decl, 2);
19698 remove_AT (com_die, DW_AT_declaration);
19700 var_die = new_die (DW_TAG_variable, com_die, decl);
19701 add_name_and_src_coords_attributes (var_die, decl);
19702 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
19703 TREE_THIS_VOLATILE (decl), context_die);
19704 add_AT_flag (var_die, DW_AT_external, 1);
19705 if (loc)
19707 if (off)
19709 /* Optimize the common case. */
19710 if (single_element_loc_list_p (loc)
19711 && loc->expr->dw_loc_opc == DW_OP_addr
19712 && loc->expr->dw_loc_next == NULL
19713 && GET_CODE (loc->expr->dw_loc_oprnd1.v.val_addr) == SYMBOL_REF)
19714 loc->expr->dw_loc_oprnd1.v.val_addr
19715 = plus_constant (loc->expr->dw_loc_oprnd1.v.val_addr, off);
19716 else
19717 loc_list_plus_const (loc, off);
19719 add_AT_location_description (var_die, DW_AT_location, loc);
19721 else if (DECL_EXTERNAL (decl))
19722 add_AT_flag (var_die, DW_AT_declaration, 1);
19723 equate_decl_number_to_die (decl, var_die);
19724 return;
19727 /* If the compiler emitted a definition for the DECL declaration
19728 and if we already emitted a DIE for it, don't emit a second
19729 DIE for it again. Allow re-declarations of DECLs that are
19730 inside functions, though. */
19731 if (old_die && declaration && !local_scope_p (context_die))
19732 return;
19734 /* For static data members, the declaration in the class is supposed
19735 to have DW_TAG_member tag; the specification should still be
19736 DW_TAG_variable referencing the DW_TAG_member DIE. */
19737 if (declaration && class_scope_p (context_die))
19738 var_die = new_die (DW_TAG_member, context_die, decl);
19739 else
19740 var_die = new_die (DW_TAG_variable, context_die, decl);
19742 origin_die = NULL;
19743 if (origin != NULL)
19744 origin_die = add_abstract_origin_attribute (var_die, origin);
19746 /* Loop unrolling can create multiple blocks that refer to the same
19747 static variable, so we must test for the DW_AT_declaration flag.
19749 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19750 copy decls and set the DECL_ABSTRACT flag on them instead of
19751 sharing them.
19753 ??? Duplicated blocks have been rewritten to use .debug_ranges.
19755 ??? The declare_in_namespace support causes us to get two DIEs for one
19756 variable, both of which are declarations. We want to avoid considering
19757 one to be a specification, so we must test that this DIE is not a
19758 declaration. */
19759 else if (old_die && TREE_STATIC (decl) && ! declaration
19760 && get_AT_flag (old_die, DW_AT_declaration) == 1)
19762 /* This is a definition of a C++ class level static. */
19763 add_AT_specification (var_die, old_die);
19764 specialization_p = true;
19765 if (DECL_NAME (decl))
19767 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
19768 struct dwarf_file_data * file_index = lookup_filename (s.file);
19770 if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
19771 add_AT_file (var_die, DW_AT_decl_file, file_index);
19773 if (get_AT_unsigned (old_die, DW_AT_decl_line) != (unsigned) s.line)
19774 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
19776 if (old_die->die_tag == DW_TAG_member)
19777 add_linkage_name (var_die, decl);
19780 else
19781 add_name_and_src_coords_attributes (var_die, decl);
19783 if ((origin == NULL && !specialization_p)
19784 || (origin != NULL
19785 && !DECL_ABSTRACT (decl_or_origin)
19786 && variably_modified_type_p (TREE_TYPE (decl_or_origin),
19787 decl_function_context
19788 (decl_or_origin))))
19790 tree type = TREE_TYPE (decl_or_origin);
19792 if (decl_by_reference_p (decl_or_origin))
19793 add_type_attribute (var_die, TREE_TYPE (type), 0, 0, context_die);
19794 else
19795 add_type_attribute (var_die, type, TREE_READONLY (decl_or_origin),
19796 TREE_THIS_VOLATILE (decl_or_origin), context_die);
19799 if (origin == NULL && !specialization_p)
19801 if (TREE_PUBLIC (decl))
19802 add_AT_flag (var_die, DW_AT_external, 1);
19804 if (DECL_ARTIFICIAL (decl))
19805 add_AT_flag (var_die, DW_AT_artificial, 1);
19807 add_accessibility_attribute (var_die, decl);
19810 if (declaration)
19811 add_AT_flag (var_die, DW_AT_declaration, 1);
19813 if (decl && (DECL_ABSTRACT (decl) || declaration || old_die == NULL))
19814 equate_decl_number_to_die (decl, var_die);
19816 if (! declaration
19817 && (! DECL_ABSTRACT (decl_or_origin)
19818 /* Local static vars are shared between all clones/inlines,
19819 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19820 already set. */
19821 || (TREE_CODE (decl_or_origin) == VAR_DECL
19822 && TREE_STATIC (decl_or_origin)
19823 && DECL_RTL_SET_P (decl_or_origin)))
19824 /* When abstract origin already has DW_AT_location attribute, no need
19825 to add it again. */
19826 && (origin_die == NULL || get_AT (origin_die, DW_AT_location) == NULL))
19828 if (TREE_CODE (decl_or_origin) == VAR_DECL && TREE_STATIC (decl_or_origin)
19829 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin)))
19830 defer_location (decl_or_origin, var_die);
19831 else
19832 add_location_or_const_value_attribute (var_die, decl_or_origin,
19833 decl == NULL, DW_AT_location);
19834 add_pubname (decl_or_origin, var_die);
19836 else
19837 tree_add_const_value_attribute_for_decl (var_die, decl_or_origin);
19840 /* Generate a DIE to represent a named constant. */
19842 static void
19843 gen_const_die (tree decl, dw_die_ref context_die)
19845 dw_die_ref const_die;
19846 tree type = TREE_TYPE (decl);
19848 const_die = new_die (DW_TAG_constant, context_die, decl);
19849 add_name_and_src_coords_attributes (const_die, decl);
19850 add_type_attribute (const_die, type, 1, 0, context_die);
19851 if (TREE_PUBLIC (decl))
19852 add_AT_flag (const_die, DW_AT_external, 1);
19853 if (DECL_ARTIFICIAL (decl))
19854 add_AT_flag (const_die, DW_AT_artificial, 1);
19855 tree_add_const_value_attribute_for_decl (const_die, decl);
19858 /* Generate a DIE to represent a label identifier. */
19860 static void
19861 gen_label_die (tree decl, dw_die_ref context_die)
19863 tree origin = decl_ultimate_origin (decl);
19864 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
19865 rtx insn;
19866 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19868 if (origin != NULL)
19869 add_abstract_origin_attribute (lbl_die, origin);
19870 else
19871 add_name_and_src_coords_attributes (lbl_die, decl);
19873 if (DECL_ABSTRACT (decl))
19874 equate_decl_number_to_die (decl, lbl_die);
19875 else
19877 insn = DECL_RTL_IF_SET (decl);
19879 /* Deleted labels are programmer specified labels which have been
19880 eliminated because of various optimizations. We still emit them
19881 here so that it is possible to put breakpoints on them. */
19882 if (insn
19883 && (LABEL_P (insn)
19884 || ((NOTE_P (insn)
19885 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))))
19887 /* When optimization is enabled (via -O) some parts of the compiler
19888 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19889 represent source-level labels which were explicitly declared by
19890 the user. This really shouldn't be happening though, so catch
19891 it if it ever does happen. */
19892 gcc_assert (!INSN_DELETED_P (insn));
19894 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
19895 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
19900 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19901 attributes to the DIE for a block STMT, to describe where the inlined
19902 function was called from. This is similar to add_src_coords_attributes. */
19904 static inline void
19905 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
19907 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
19909 if (dwarf_version >= 3 || !dwarf_strict)
19911 add_AT_file (die, DW_AT_call_file, lookup_filename (s.file));
19912 add_AT_unsigned (die, DW_AT_call_line, s.line);
19917 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19918 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19920 static inline void
19921 add_high_low_attributes (tree stmt, dw_die_ref die)
19923 char label[MAX_ARTIFICIAL_LABEL_BYTES];
19925 if (BLOCK_FRAGMENT_CHAIN (stmt)
19926 && (dwarf_version >= 3 || !dwarf_strict))
19928 tree chain;
19930 if (inlined_function_outer_scope_p (stmt))
19932 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19933 BLOCK_NUMBER (stmt));
19934 add_AT_lbl_id (die, DW_AT_entry_pc, label);
19937 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
19939 chain = BLOCK_FRAGMENT_CHAIN (stmt);
19942 add_ranges (chain);
19943 chain = BLOCK_FRAGMENT_CHAIN (chain);
19945 while (chain);
19946 add_ranges (NULL);
19948 else
19950 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
19951 BLOCK_NUMBER (stmt));
19952 add_AT_lbl_id (die, DW_AT_low_pc, label);
19953 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
19954 BLOCK_NUMBER (stmt));
19955 add_AT_lbl_id (die, DW_AT_high_pc, label);
19959 /* Generate a DIE for a lexical block. */
19961 static void
19962 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
19964 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
19966 if (call_arg_locations)
19968 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
19969 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
19970 BLOCK_NUMBER (stmt) + 1);
19971 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), stmt_die);
19974 if (! BLOCK_ABSTRACT (stmt) && TREE_ASM_WRITTEN (stmt))
19975 add_high_low_attributes (stmt, stmt_die);
19977 decls_for_scope (stmt, stmt_die, depth);
19980 /* Generate a DIE for an inlined subprogram. */
19982 static void
19983 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
19985 tree decl;
19987 /* The instance of function that is effectively being inlined shall not
19988 be abstract. */
19989 gcc_assert (! BLOCK_ABSTRACT (stmt));
19991 decl = block_ultimate_origin (stmt);
19993 /* Emit info for the abstract instance first, if we haven't yet. We
19994 must emit this even if the block is abstract, otherwise when we
19995 emit the block below (or elsewhere), we may end up trying to emit
19996 a die whose origin die hasn't been emitted, and crashing. */
19997 dwarf2out_abstract_function (decl);
19999 if (! BLOCK_ABSTRACT (stmt))
20001 dw_die_ref subr_die
20002 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
20004 if (call_arg_locations)
20006 if (VEC_length (dw_die_ref, block_map) <= BLOCK_NUMBER (stmt))
20007 VEC_safe_grow_cleared (dw_die_ref, heap, block_map,
20008 BLOCK_NUMBER (stmt) + 1);
20009 VEC_replace (dw_die_ref, block_map, BLOCK_NUMBER (stmt), subr_die);
20011 add_abstract_origin_attribute (subr_die, decl);
20012 if (TREE_ASM_WRITTEN (stmt))
20013 add_high_low_attributes (stmt, subr_die);
20014 add_call_src_coords_attributes (stmt, subr_die);
20016 decls_for_scope (stmt, subr_die, depth);
20017 current_function_has_inlines = 1;
20021 /* Generate a DIE for a field in a record, or structure. */
20023 static void
20024 gen_field_die (tree decl, dw_die_ref context_die)
20026 dw_die_ref decl_die;
20028 if (TREE_TYPE (decl) == error_mark_node)
20029 return;
20031 decl_die = new_die (DW_TAG_member, context_die, decl);
20032 add_name_and_src_coords_attributes (decl_die, decl);
20033 add_type_attribute (decl_die, member_declared_type (decl),
20034 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
20035 context_die);
20037 if (DECL_BIT_FIELD_TYPE (decl))
20039 add_byte_size_attribute (decl_die, decl);
20040 add_bit_size_attribute (decl_die, decl);
20041 add_bit_offset_attribute (decl_die, decl);
20044 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
20045 add_data_member_location_attribute (decl_die, decl);
20047 if (DECL_ARTIFICIAL (decl))
20048 add_AT_flag (decl_die, DW_AT_artificial, 1);
20050 add_accessibility_attribute (decl_die, decl);
20052 /* Equate decl number to die, so that we can look up this decl later on. */
20053 equate_decl_number_to_die (decl, decl_die);
20056 #if 0
20057 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20058 Use modified_type_die instead.
20059 We keep this code here just in case these types of DIEs may be needed to
20060 represent certain things in other languages (e.g. Pascal) someday. */
20062 static void
20063 gen_pointer_type_die (tree type, dw_die_ref context_die)
20065 dw_die_ref ptr_die
20066 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
20068 equate_type_number_to_die (type, ptr_die);
20069 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20070 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20073 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
20074 Use modified_type_die instead.
20075 We keep this code here just in case these types of DIEs may be needed to
20076 represent certain things in other languages (e.g. Pascal) someday. */
20078 static void
20079 gen_reference_type_die (tree type, dw_die_ref context_die)
20081 dw_die_ref ref_die, scope_die = scope_die_for (type, context_die);
20083 if (TYPE_REF_IS_RVALUE (type) && use_debug_types)
20084 ref_die = new_die (DW_TAG_rvalue_reference_type, scope_die, type);
20085 else
20086 ref_die = new_die (DW_TAG_reference_type, scope_die, type);
20088 equate_type_number_to_die (type, ref_die);
20089 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
20090 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
20092 #endif
20094 /* Generate a DIE for a pointer to a member type. */
20096 static void
20097 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
20099 dw_die_ref ptr_die
20100 = new_die (DW_TAG_ptr_to_member_type,
20101 scope_die_for (type, context_die), type);
20103 equate_type_number_to_die (type, ptr_die);
20104 add_AT_die_ref (ptr_die, DW_AT_containing_type,
20105 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
20106 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
20109 /* Generate the DIE for the compilation unit. */
20111 static dw_die_ref
20112 gen_compile_unit_die (const char *filename)
20114 dw_die_ref die;
20115 char producer[250];
20116 const char *language_string = lang_hooks.name;
20117 int language;
20119 die = new_die (DW_TAG_compile_unit, NULL, NULL);
20121 if (filename)
20123 add_name_attribute (die, filename);
20124 /* Don't add cwd for <built-in>. */
20125 if (!IS_ABSOLUTE_PATH (filename) && filename[0] != '<')
20126 add_comp_dir_attribute (die);
20129 sprintf (producer, "%s %s", language_string, version_string);
20131 #ifdef MIPS_DEBUGGING_INFO
20132 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
20133 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
20134 not appear in the producer string, the debugger reaches the conclusion
20135 that the object file is stripped and has no debugging information.
20136 To get the MIPS/SGI debugger to believe that there is debugging
20137 information in the object file, we add a -g to the producer string. */
20138 if (debug_info_level > DINFO_LEVEL_TERSE)
20139 strcat (producer, " -g");
20140 #endif
20142 add_AT_string (die, DW_AT_producer, producer);
20144 /* If our producer is LTO try to figure out a common language to use
20145 from the global list of translation units. */
20146 if (strcmp (language_string, "GNU GIMPLE") == 0)
20148 unsigned i;
20149 tree t;
20150 const char *common_lang = NULL;
20152 FOR_EACH_VEC_ELT (tree, all_translation_units, i, t)
20154 if (!TRANSLATION_UNIT_LANGUAGE (t))
20155 continue;
20156 if (!common_lang)
20157 common_lang = TRANSLATION_UNIT_LANGUAGE (t);
20158 else if (strcmp (common_lang, TRANSLATION_UNIT_LANGUAGE (t)) == 0)
20160 else if (strncmp (common_lang, "GNU C", 5) == 0
20161 && strncmp (TRANSLATION_UNIT_LANGUAGE (t), "GNU C", 5) == 0)
20162 /* Mixing C and C++ is ok, use C++ in that case. */
20163 common_lang = "GNU C++";
20164 else
20166 /* Fall back to C. */
20167 common_lang = NULL;
20168 break;
20172 if (common_lang)
20173 language_string = common_lang;
20176 language = DW_LANG_C89;
20177 if (strcmp (language_string, "GNU C++") == 0)
20178 language = DW_LANG_C_plus_plus;
20179 else if (strcmp (language_string, "GNU F77") == 0)
20180 language = DW_LANG_Fortran77;
20181 else if (strcmp (language_string, "GNU Pascal") == 0)
20182 language = DW_LANG_Pascal83;
20183 else if (dwarf_version >= 3 || !dwarf_strict)
20185 if (strcmp (language_string, "GNU Ada") == 0)
20186 language = DW_LANG_Ada95;
20187 else if (strcmp (language_string, "GNU Fortran") == 0)
20188 language = DW_LANG_Fortran95;
20189 else if (strcmp (language_string, "GNU Java") == 0)
20190 language = DW_LANG_Java;
20191 else if (strcmp (language_string, "GNU Objective-C") == 0)
20192 language = DW_LANG_ObjC;
20193 else if (strcmp (language_string, "GNU Objective-C++") == 0)
20194 language = DW_LANG_ObjC_plus_plus;
20197 add_AT_unsigned (die, DW_AT_language, language);
20199 switch (language)
20201 case DW_LANG_Fortran77:
20202 case DW_LANG_Fortran90:
20203 case DW_LANG_Fortran95:
20204 /* Fortran has case insensitive identifiers and the front-end
20205 lowercases everything. */
20206 add_AT_unsigned (die, DW_AT_identifier_case, DW_ID_down_case);
20207 break;
20208 default:
20209 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20210 break;
20212 return die;
20215 /* Generate the DIE for a base class. */
20217 static void
20218 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
20220 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
20222 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
20223 add_data_member_location_attribute (die, binfo);
20225 if (BINFO_VIRTUAL_P (binfo))
20226 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
20228 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20229 children, otherwise the default is DW_ACCESS_public. In DWARF2
20230 the default has always been DW_ACCESS_private. */
20231 if (access == access_public_node)
20233 if (dwarf_version == 2
20234 || context_die->die_tag == DW_TAG_class_type)
20235 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
20237 else if (access == access_protected_node)
20238 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
20239 else if (dwarf_version > 2
20240 && context_die->die_tag != DW_TAG_class_type)
20241 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_private);
20244 /* Generate a DIE for a class member. */
20246 static void
20247 gen_member_die (tree type, dw_die_ref context_die)
20249 tree member;
20250 tree binfo = TYPE_BINFO (type);
20251 dw_die_ref child;
20253 /* If this is not an incomplete type, output descriptions of each of its
20254 members. Note that as we output the DIEs necessary to represent the
20255 members of this record or union type, we will also be trying to output
20256 DIEs to represent the *types* of those members. However the `type'
20257 function (above) will specifically avoid generating type DIEs for member
20258 types *within* the list of member DIEs for this (containing) type except
20259 for those types (of members) which are explicitly marked as also being
20260 members of this (containing) type themselves. The g++ front- end can
20261 force any given type to be treated as a member of some other (containing)
20262 type by setting the TYPE_CONTEXT of the given (member) type to point to
20263 the TREE node representing the appropriate (containing) type. */
20265 /* First output info about the base classes. */
20266 if (binfo)
20268 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
20269 int i;
20270 tree base;
20272 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
20273 gen_inheritance_die (base,
20274 (accesses ? VEC_index (tree, accesses, i)
20275 : access_public_node), context_die);
20278 /* Now output info about the data members and type members. */
20279 for (member = TYPE_FIELDS (type); member; member = DECL_CHAIN (member))
20281 /* If we thought we were generating minimal debug info for TYPE
20282 and then changed our minds, some of the member declarations
20283 may have already been defined. Don't define them again, but
20284 do put them in the right order. */
20286 child = lookup_decl_die (member);
20287 if (child)
20288 splice_child_die (context_die, child);
20289 else
20290 gen_decl_die (member, NULL, context_die);
20293 /* Now output info about the function members (if any). */
20294 for (member = TYPE_METHODS (type); member; member = DECL_CHAIN (member))
20296 /* Don't include clones in the member list. */
20297 if (DECL_ABSTRACT_ORIGIN (member))
20298 continue;
20300 child = lookup_decl_die (member);
20301 if (child)
20302 splice_child_die (context_die, child);
20303 else
20304 gen_decl_die (member, NULL, context_die);
20308 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20309 is set, we pretend that the type was never defined, so we only get the
20310 member DIEs needed by later specification DIEs. */
20312 static void
20313 gen_struct_or_union_type_die (tree type, dw_die_ref context_die,
20314 enum debug_info_usage usage)
20316 dw_die_ref type_die = lookup_type_die (type);
20317 dw_die_ref scope_die = 0;
20318 int nested = 0;
20319 int complete = (TYPE_SIZE (type)
20320 && (! TYPE_STUB_DECL (type)
20321 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
20322 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
20323 complete = complete && should_emit_struct_debug (type, usage);
20325 if (type_die && ! complete)
20326 return;
20328 if (TYPE_CONTEXT (type) != NULL_TREE
20329 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20330 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
20331 nested = 1;
20333 scope_die = scope_die_for (type, context_die);
20335 if (! type_die || (nested && is_cu_die (scope_die)))
20336 /* First occurrence of type or toplevel definition of nested class. */
20338 dw_die_ref old_die = type_die;
20340 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
20341 ? record_type_tag (type) : DW_TAG_union_type,
20342 scope_die, type);
20343 equate_type_number_to_die (type, type_die);
20344 if (old_die)
20345 add_AT_specification (type_die, old_die);
20346 else
20348 add_name_attribute (type_die, type_tag (type));
20349 add_gnat_descriptive_type_attribute (type_die, type, context_die);
20352 else
20353 remove_AT (type_die, DW_AT_declaration);
20355 /* Generate child dies for template paramaters. */
20356 if (debug_info_level > DINFO_LEVEL_TERSE
20357 && COMPLETE_TYPE_P (type))
20358 schedule_generic_params_dies_gen (type);
20360 /* If this type has been completed, then give it a byte_size attribute and
20361 then give a list of members. */
20362 if (complete && !ns_decl)
20364 /* Prevent infinite recursion in cases where the type of some member of
20365 this type is expressed in terms of this type itself. */
20366 TREE_ASM_WRITTEN (type) = 1;
20367 add_byte_size_attribute (type_die, type);
20368 if (TYPE_STUB_DECL (type) != NULL_TREE)
20370 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
20371 add_accessibility_attribute (type_die, TYPE_STUB_DECL (type));
20374 /* If the first reference to this type was as the return type of an
20375 inline function, then it may not have a parent. Fix this now. */
20376 if (type_die->die_parent == NULL)
20377 add_child_die (scope_die, type_die);
20379 push_decl_scope (type);
20380 gen_member_die (type, type_die);
20381 pop_decl_scope ();
20383 /* GNU extension: Record what type our vtable lives in. */
20384 if (TYPE_VFIELD (type))
20386 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
20388 gen_type_die (vtype, context_die);
20389 add_AT_die_ref (type_die, DW_AT_containing_type,
20390 lookup_type_die (vtype));
20393 else
20395 add_AT_flag (type_die, DW_AT_declaration, 1);
20397 /* We don't need to do this for function-local types. */
20398 if (TYPE_STUB_DECL (type)
20399 && ! decl_function_context (TYPE_STUB_DECL (type)))
20400 VEC_safe_push (tree, gc, incomplete_types, type);
20403 if (get_AT (type_die, DW_AT_name))
20404 add_pubtype (type, type_die);
20407 /* Generate a DIE for a subroutine _type_. */
20409 static void
20410 gen_subroutine_type_die (tree type, dw_die_ref context_die)
20412 tree return_type = TREE_TYPE (type);
20413 dw_die_ref subr_die
20414 = new_die (DW_TAG_subroutine_type,
20415 scope_die_for (type, context_die), type);
20417 equate_type_number_to_die (type, subr_die);
20418 add_prototyped_attribute (subr_die, type);
20419 add_type_attribute (subr_die, return_type, 0, 0, context_die);
20420 gen_formal_types_die (type, subr_die);
20422 if (get_AT (subr_die, DW_AT_name))
20423 add_pubtype (type, subr_die);
20426 /* Generate a DIE for a type definition. */
20428 static void
20429 gen_typedef_die (tree decl, dw_die_ref context_die)
20431 dw_die_ref type_die;
20432 tree origin;
20434 if (TREE_ASM_WRITTEN (decl))
20435 return;
20437 TREE_ASM_WRITTEN (decl) = 1;
20438 type_die = new_die (DW_TAG_typedef, context_die, decl);
20439 origin = decl_ultimate_origin (decl);
20440 if (origin != NULL)
20441 add_abstract_origin_attribute (type_die, origin);
20442 else
20444 tree type;
20446 add_name_and_src_coords_attributes (type_die, decl);
20447 if (DECL_ORIGINAL_TYPE (decl))
20449 type = DECL_ORIGINAL_TYPE (decl);
20451 gcc_assert (type != TREE_TYPE (decl));
20452 equate_type_number_to_die (TREE_TYPE (decl), type_die);
20454 else
20456 type = TREE_TYPE (decl);
20458 if (is_naming_typedef_decl (TYPE_NAME (type)))
20460 /* Here, we are in the case of decl being a typedef naming
20461 an anonymous type, e.g:
20462 typedef struct {...} foo;
20463 In that case TREE_TYPE (decl) is not a typedef variant
20464 type and TYPE_NAME of the anonymous type is set to the
20465 TYPE_DECL of the typedef. This construct is emitted by
20466 the C++ FE.
20468 TYPE is the anonymous struct named by the typedef
20469 DECL. As we need the DW_AT_type attribute of the
20470 DW_TAG_typedef to point to the DIE of TYPE, let's
20471 generate that DIE right away. add_type_attribute
20472 called below will then pick (via lookup_type_die) that
20473 anonymous struct DIE. */
20474 if (!TREE_ASM_WRITTEN (type))
20475 gen_tagged_type_die (type, context_die, DINFO_USAGE_DIR_USE);
20477 /* This is a GNU Extension. We are adding a
20478 DW_AT_linkage_name attribute to the DIE of the
20479 anonymous struct TYPE. The value of that attribute
20480 is the name of the typedef decl naming the anonymous
20481 struct. This greatly eases the work of consumers of
20482 this debug info. */
20483 add_linkage_attr (lookup_type_die (type), decl);
20487 add_type_attribute (type_die, type, TREE_READONLY (decl),
20488 TREE_THIS_VOLATILE (decl), context_die);
20490 if (is_naming_typedef_decl (decl))
20491 /* We want that all subsequent calls to lookup_type_die with
20492 TYPE in argument yield the DW_TAG_typedef we have just
20493 created. */
20494 equate_type_number_to_die (type, type_die);
20496 add_accessibility_attribute (type_die, decl);
20499 if (DECL_ABSTRACT (decl))
20500 equate_decl_number_to_die (decl, type_die);
20502 if (get_AT (type_die, DW_AT_name))
20503 add_pubtype (decl, type_die);
20506 /* Generate a DIE for a struct, class, enum or union type. */
20508 static void
20509 gen_tagged_type_die (tree type,
20510 dw_die_ref context_die,
20511 enum debug_info_usage usage)
20513 int need_pop;
20515 if (type == NULL_TREE
20516 || !is_tagged_type (type))
20517 return;
20519 /* If this is a nested type whose containing class hasn't been written
20520 out yet, writing it out will cover this one, too. This does not apply
20521 to instantiations of member class templates; they need to be added to
20522 the containing class as they are generated. FIXME: This hurts the
20523 idea of combining type decls from multiple TUs, since we can't predict
20524 what set of template instantiations we'll get. */
20525 if (TYPE_CONTEXT (type)
20526 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
20527 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
20529 gen_type_die_with_usage (TYPE_CONTEXT (type), context_die, usage);
20531 if (TREE_ASM_WRITTEN (type))
20532 return;
20534 /* If that failed, attach ourselves to the stub. */
20535 push_decl_scope (TYPE_CONTEXT (type));
20536 context_die = lookup_type_die (TYPE_CONTEXT (type));
20537 need_pop = 1;
20539 else if (TYPE_CONTEXT (type) != NULL_TREE
20540 && (TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL))
20542 /* If this type is local to a function that hasn't been written
20543 out yet, use a NULL context for now; it will be fixed up in
20544 decls_for_scope. */
20545 context_die = lookup_decl_die (TYPE_CONTEXT (type));
20546 /* A declaration DIE doesn't count; nested types need to go in the
20547 specification. */
20548 if (context_die && is_declaration_die (context_die))
20549 context_die = NULL;
20550 need_pop = 0;
20552 else
20554 context_die = declare_in_namespace (type, context_die);
20555 need_pop = 0;
20558 if (TREE_CODE (type) == ENUMERAL_TYPE)
20560 /* This might have been written out by the call to
20561 declare_in_namespace. */
20562 if (!TREE_ASM_WRITTEN (type))
20563 gen_enumeration_type_die (type, context_die);
20565 else
20566 gen_struct_or_union_type_die (type, context_die, usage);
20568 if (need_pop)
20569 pop_decl_scope ();
20571 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20572 it up if it is ever completed. gen_*_type_die will set it for us
20573 when appropriate. */
20576 /* Generate a type description DIE. */
20578 static void
20579 gen_type_die_with_usage (tree type, dw_die_ref context_die,
20580 enum debug_info_usage usage)
20582 struct array_descr_info info;
20584 if (type == NULL_TREE || type == error_mark_node)
20585 return;
20587 if (TYPE_NAME (type) != NULL_TREE
20588 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
20589 && is_redundant_typedef (TYPE_NAME (type))
20590 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
20591 /* The DECL of this type is a typedef we don't want to emit debug
20592 info for but we want debug info for its underlying typedef.
20593 This can happen for e.g, the injected-class-name of a C++
20594 type. */
20595 type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
20597 /* If TYPE is a typedef type variant, let's generate debug info
20598 for the parent typedef which TYPE is a type of. */
20599 if (typedef_variant_p (type))
20601 if (TREE_ASM_WRITTEN (type))
20602 return;
20604 /* Prevent broken recursion; we can't hand off to the same type. */
20605 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
20607 /* Use the DIE of the containing namespace as the parent DIE of
20608 the type description DIE we want to generate. */
20609 if (DECL_CONTEXT (TYPE_NAME (type))
20610 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20611 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20613 TREE_ASM_WRITTEN (type) = 1;
20615 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20616 return;
20619 /* If type is an anonymous tagged type named by a typedef, let's
20620 generate debug info for the typedef. */
20621 if (is_naming_typedef_decl (TYPE_NAME (type)))
20623 /* Use the DIE of the containing namespace as the parent DIE of
20624 the type description DIE we want to generate. */
20625 if (DECL_CONTEXT (TYPE_NAME (type))
20626 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type))) == NAMESPACE_DECL)
20627 context_die = get_context_die (DECL_CONTEXT (TYPE_NAME (type)));
20629 gen_decl_die (TYPE_NAME (type), NULL, context_die);
20630 return;
20633 /* If this is an array type with hidden descriptor, handle it first. */
20634 if (!TREE_ASM_WRITTEN (type)
20635 && lang_hooks.types.get_array_descr_info
20636 && lang_hooks.types.get_array_descr_info (type, &info)
20637 && (dwarf_version >= 3 || !dwarf_strict))
20639 gen_descr_array_type_die (type, &info, context_die);
20640 TREE_ASM_WRITTEN (type) = 1;
20641 return;
20644 /* We are going to output a DIE to represent the unqualified version
20645 of this type (i.e. without any const or volatile qualifiers) so
20646 get the main variant (i.e. the unqualified version) of this type
20647 now. (Vectors are special because the debugging info is in the
20648 cloned type itself). */
20649 if (TREE_CODE (type) != VECTOR_TYPE)
20650 type = type_main_variant (type);
20652 if (TREE_ASM_WRITTEN (type))
20653 return;
20655 switch (TREE_CODE (type))
20657 case ERROR_MARK:
20658 break;
20660 case POINTER_TYPE:
20661 case REFERENCE_TYPE:
20662 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20663 ensures that the gen_type_die recursion will terminate even if the
20664 type is recursive. Recursive types are possible in Ada. */
20665 /* ??? We could perhaps do this for all types before the switch
20666 statement. */
20667 TREE_ASM_WRITTEN (type) = 1;
20669 /* For these types, all that is required is that we output a DIE (or a
20670 set of DIEs) to represent the "basis" type. */
20671 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20672 DINFO_USAGE_IND_USE);
20673 break;
20675 case OFFSET_TYPE:
20676 /* This code is used for C++ pointer-to-data-member types.
20677 Output a description of the relevant class type. */
20678 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type), context_die,
20679 DINFO_USAGE_IND_USE);
20681 /* Output a description of the type of the object pointed to. */
20682 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20683 DINFO_USAGE_IND_USE);
20685 /* Now output a DIE to represent this pointer-to-data-member type
20686 itself. */
20687 gen_ptr_to_mbr_type_die (type, context_die);
20688 break;
20690 case FUNCTION_TYPE:
20691 /* Force out return type (in case it wasn't forced out already). */
20692 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20693 DINFO_USAGE_DIR_USE);
20694 gen_subroutine_type_die (type, context_die);
20695 break;
20697 case METHOD_TYPE:
20698 /* Force out return type (in case it wasn't forced out already). */
20699 gen_type_die_with_usage (TREE_TYPE (type), context_die,
20700 DINFO_USAGE_DIR_USE);
20701 gen_subroutine_type_die (type, context_die);
20702 break;
20704 case ARRAY_TYPE:
20705 gen_array_type_die (type, context_die);
20706 break;
20708 case VECTOR_TYPE:
20709 gen_array_type_die (type, context_die);
20710 break;
20712 case ENUMERAL_TYPE:
20713 case RECORD_TYPE:
20714 case UNION_TYPE:
20715 case QUAL_UNION_TYPE:
20716 gen_tagged_type_die (type, context_die, usage);
20717 return;
20719 case VOID_TYPE:
20720 case INTEGER_TYPE:
20721 case REAL_TYPE:
20722 case FIXED_POINT_TYPE:
20723 case COMPLEX_TYPE:
20724 case BOOLEAN_TYPE:
20725 /* No DIEs needed for fundamental types. */
20726 break;
20728 case NULLPTR_TYPE:
20729 case LANG_TYPE:
20730 /* Just use DW_TAG_unspecified_type. */
20732 dw_die_ref type_die = lookup_type_die (type);
20733 if (type_die == NULL)
20735 tree name = TYPE_NAME (type);
20736 if (TREE_CODE (name) == TYPE_DECL)
20737 name = DECL_NAME (name);
20738 type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type);
20739 add_name_attribute (type_die, IDENTIFIER_POINTER (name));
20740 equate_type_number_to_die (type, type_die);
20743 break;
20745 default:
20746 gcc_unreachable ();
20749 TREE_ASM_WRITTEN (type) = 1;
20752 static void
20753 gen_type_die (tree type, dw_die_ref context_die)
20755 gen_type_die_with_usage (type, context_die, DINFO_USAGE_DIR_USE);
20758 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20759 things which are local to the given block. */
20761 static void
20762 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
20764 int must_output_die = 0;
20765 bool inlined_func;
20767 /* Ignore blocks that are NULL. */
20768 if (stmt == NULL_TREE)
20769 return;
20771 inlined_func = inlined_function_outer_scope_p (stmt);
20773 /* If the block is one fragment of a non-contiguous block, do not
20774 process the variables, since they will have been done by the
20775 origin block. Do process subblocks. */
20776 if (BLOCK_FRAGMENT_ORIGIN (stmt))
20778 tree sub;
20780 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
20781 gen_block_die (sub, context_die, depth + 1);
20783 return;
20786 /* Determine if we need to output any Dwarf DIEs at all to represent this
20787 block. */
20788 if (inlined_func)
20789 /* The outer scopes for inlinings *must* always be represented. We
20790 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20791 must_output_die = 1;
20792 else
20794 /* Determine if this block directly contains any "significant"
20795 local declarations which we will need to output DIEs for. */
20796 if (debug_info_level > DINFO_LEVEL_TERSE)
20797 /* We are not in terse mode so *any* local declaration counts
20798 as being a "significant" one. */
20799 must_output_die = ((BLOCK_VARS (stmt) != NULL
20800 || BLOCK_NUM_NONLOCALIZED_VARS (stmt))
20801 && (TREE_USED (stmt)
20802 || TREE_ASM_WRITTEN (stmt)
20803 || BLOCK_ABSTRACT (stmt)));
20804 else if ((TREE_USED (stmt)
20805 || TREE_ASM_WRITTEN (stmt)
20806 || BLOCK_ABSTRACT (stmt))
20807 && !dwarf2out_ignore_block (stmt))
20808 must_output_die = 1;
20811 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20812 DIE for any block which contains no significant local declarations at
20813 all. Rather, in such cases we just call `decls_for_scope' so that any
20814 needed Dwarf info for any sub-blocks will get properly generated. Note
20815 that in terse mode, our definition of what constitutes a "significant"
20816 local declaration gets restricted to include only inlined function
20817 instances and local (nested) function definitions. */
20818 if (must_output_die)
20820 if (inlined_func)
20822 /* If STMT block is abstract, that means we have been called
20823 indirectly from dwarf2out_abstract_function.
20824 That function rightfully marks the descendent blocks (of
20825 the abstract function it is dealing with) as being abstract,
20826 precisely to prevent us from emitting any
20827 DW_TAG_inlined_subroutine DIE as a descendent
20828 of an abstract function instance. So in that case, we should
20829 not call gen_inlined_subroutine_die.
20831 Later though, when cgraph asks dwarf2out to emit info
20832 for the concrete instance of the function decl into which
20833 the concrete instance of STMT got inlined, the later will lead
20834 to the generation of a DW_TAG_inlined_subroutine DIE. */
20835 if (! BLOCK_ABSTRACT (stmt))
20836 gen_inlined_subroutine_die (stmt, context_die, depth);
20838 else
20839 gen_lexical_block_die (stmt, context_die, depth);
20841 else
20842 decls_for_scope (stmt, context_die, depth);
20845 /* Process variable DECL (or variable with origin ORIGIN) within
20846 block STMT and add it to CONTEXT_DIE. */
20847 static void
20848 process_scope_var (tree stmt, tree decl, tree origin, dw_die_ref context_die)
20850 dw_die_ref die;
20851 tree decl_or_origin = decl ? decl : origin;
20853 if (TREE_CODE (decl_or_origin) == FUNCTION_DECL)
20854 die = lookup_decl_die (decl_or_origin);
20855 else if (TREE_CODE (decl_or_origin) == TYPE_DECL
20856 && TYPE_DECL_IS_STUB (decl_or_origin))
20857 die = lookup_type_die (TREE_TYPE (decl_or_origin));
20858 else
20859 die = NULL;
20861 if (die != NULL && die->die_parent == NULL)
20862 add_child_die (context_die, die);
20863 else if (TREE_CODE (decl_or_origin) == IMPORTED_DECL)
20864 dwarf2out_imported_module_or_decl_1 (decl_or_origin, DECL_NAME (decl_or_origin),
20865 stmt, context_die);
20866 else
20867 gen_decl_die (decl, origin, context_die);
20870 /* Generate all of the decls declared within a given scope and (recursively)
20871 all of its sub-blocks. */
20873 static void
20874 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
20876 tree decl;
20877 unsigned int i;
20878 tree subblocks;
20880 /* Ignore NULL blocks. */
20881 if (stmt == NULL_TREE)
20882 return;
20884 /* Output the DIEs to represent all of the data objects and typedefs
20885 declared directly within this block but not within any nested
20886 sub-blocks. Also, nested function and tag DIEs have been
20887 generated with a parent of NULL; fix that up now. */
20888 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = DECL_CHAIN (decl))
20889 process_scope_var (stmt, decl, NULL_TREE, context_die);
20890 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (stmt); i++)
20891 process_scope_var (stmt, NULL, BLOCK_NONLOCALIZED_VAR (stmt, i),
20892 context_die);
20894 /* If we're at -g1, we're not interested in subblocks. */
20895 if (debug_info_level <= DINFO_LEVEL_TERSE)
20896 return;
20898 /* Output the DIEs to represent all sub-blocks (and the items declared
20899 therein) of this block. */
20900 for (subblocks = BLOCK_SUBBLOCKS (stmt);
20901 subblocks != NULL;
20902 subblocks = BLOCK_CHAIN (subblocks))
20903 gen_block_die (subblocks, context_die, depth + 1);
20906 /* Is this a typedef we can avoid emitting? */
20908 static inline int
20909 is_redundant_typedef (const_tree decl)
20911 if (TYPE_DECL_IS_STUB (decl))
20912 return 1;
20914 if (DECL_ARTIFICIAL (decl)
20915 && DECL_CONTEXT (decl)
20916 && is_tagged_type (DECL_CONTEXT (decl))
20917 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
20918 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
20919 /* Also ignore the artificial member typedef for the class name. */
20920 return 1;
20922 return 0;
20925 /* Return TRUE if TYPE is a typedef that names a type for linkage
20926 purposes. This kind of typedefs is produced by the C++ FE for
20927 constructs like:
20929 typedef struct {...} foo;
20931 In that case, there is no typedef variant type produced for foo.
20932 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20933 struct type. */
20935 static bool
20936 is_naming_typedef_decl (const_tree decl)
20938 if (decl == NULL_TREE
20939 || TREE_CODE (decl) != TYPE_DECL
20940 || !is_tagged_type (TREE_TYPE (decl))
20941 || DECL_IS_BUILTIN (decl)
20942 || is_redundant_typedef (decl)
20943 /* It looks like Ada produces TYPE_DECLs that are very similar
20944 to C++ naming typedefs but that have different
20945 semantics. Let's be specific to c++ for now. */
20946 || !is_cxx ())
20947 return FALSE;
20949 return (DECL_ORIGINAL_TYPE (decl) == NULL_TREE
20950 && TYPE_NAME (TREE_TYPE (decl)) == decl
20951 && (TYPE_STUB_DECL (TREE_TYPE (decl))
20952 != TYPE_NAME (TREE_TYPE (decl))));
20955 /* Returns the DIE for a context. */
20957 static inline dw_die_ref
20958 get_context_die (tree context)
20960 if (context)
20962 /* Find die that represents this context. */
20963 if (TYPE_P (context))
20965 context = TYPE_MAIN_VARIANT (context);
20966 return strip_naming_typedef (context, force_type_die (context));
20968 else
20969 return force_decl_die (context);
20971 return comp_unit_die ();
20974 /* Returns the DIE for decl. A DIE will always be returned. */
20976 static dw_die_ref
20977 force_decl_die (tree decl)
20979 dw_die_ref decl_die;
20980 unsigned saved_external_flag;
20981 tree save_fn = NULL_TREE;
20982 decl_die = lookup_decl_die (decl);
20983 if (!decl_die)
20985 dw_die_ref context_die = get_context_die (DECL_CONTEXT (decl));
20987 decl_die = lookup_decl_die (decl);
20988 if (decl_die)
20989 return decl_die;
20991 switch (TREE_CODE (decl))
20993 case FUNCTION_DECL:
20994 /* Clear current_function_decl, so that gen_subprogram_die thinks
20995 that this is a declaration. At this point, we just want to force
20996 declaration die. */
20997 save_fn = current_function_decl;
20998 current_function_decl = NULL_TREE;
20999 gen_subprogram_die (decl, context_die);
21000 current_function_decl = save_fn;
21001 break;
21003 case VAR_DECL:
21004 /* Set external flag to force declaration die. Restore it after
21005 gen_decl_die() call. */
21006 saved_external_flag = DECL_EXTERNAL (decl);
21007 DECL_EXTERNAL (decl) = 1;
21008 gen_decl_die (decl, NULL, context_die);
21009 DECL_EXTERNAL (decl) = saved_external_flag;
21010 break;
21012 case NAMESPACE_DECL:
21013 if (dwarf_version >= 3 || !dwarf_strict)
21014 dwarf2out_decl (decl);
21015 else
21016 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21017 decl_die = comp_unit_die ();
21018 break;
21020 case TRANSLATION_UNIT_DECL:
21021 decl_die = comp_unit_die ();
21022 break;
21024 default:
21025 gcc_unreachable ();
21028 /* We should be able to find the DIE now. */
21029 if (!decl_die)
21030 decl_die = lookup_decl_die (decl);
21031 gcc_assert (decl_die);
21034 return decl_die;
21037 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21038 always returned. */
21040 static dw_die_ref
21041 force_type_die (tree type)
21043 dw_die_ref type_die;
21045 type_die = lookup_type_die (type);
21046 if (!type_die)
21048 dw_die_ref context_die = get_context_die (TYPE_CONTEXT (type));
21050 type_die = modified_type_die (type, TYPE_READONLY (type),
21051 TYPE_VOLATILE (type), context_die);
21052 gcc_assert (type_die);
21054 return type_die;
21057 /* Force out any required namespaces to be able to output DECL,
21058 and return the new context_die for it, if it's changed. */
21060 static dw_die_ref
21061 setup_namespace_context (tree thing, dw_die_ref context_die)
21063 tree context = (DECL_P (thing)
21064 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
21065 if (context && TREE_CODE (context) == NAMESPACE_DECL)
21066 /* Force out the namespace. */
21067 context_die = force_decl_die (context);
21069 return context_die;
21072 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21073 type) within its namespace, if appropriate.
21075 For compatibility with older debuggers, namespace DIEs only contain
21076 declarations; all definitions are emitted at CU scope. */
21078 static dw_die_ref
21079 declare_in_namespace (tree thing, dw_die_ref context_die)
21081 dw_die_ref ns_context;
21083 if (debug_info_level <= DINFO_LEVEL_TERSE)
21084 return context_die;
21086 /* If this decl is from an inlined function, then don't try to emit it in its
21087 namespace, as we will get confused. It would have already been emitted
21088 when the abstract instance of the inline function was emitted anyways. */
21089 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
21090 return context_die;
21092 ns_context = setup_namespace_context (thing, context_die);
21094 if (ns_context != context_die)
21096 if (is_fortran ())
21097 return ns_context;
21098 if (DECL_P (thing))
21099 gen_decl_die (thing, NULL, ns_context);
21100 else
21101 gen_type_die (thing, ns_context);
21103 return context_die;
21106 /* Generate a DIE for a namespace or namespace alias. */
21108 static void
21109 gen_namespace_die (tree decl, dw_die_ref context_die)
21111 dw_die_ref namespace_die;
21113 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21114 they are an alias of. */
21115 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
21117 /* Output a real namespace or module. */
21118 context_die = setup_namespace_context (decl, comp_unit_die ());
21119 namespace_die = new_die (is_fortran ()
21120 ? DW_TAG_module : DW_TAG_namespace,
21121 context_die, decl);
21122 /* For Fortran modules defined in different CU don't add src coords. */
21123 if (namespace_die->die_tag == DW_TAG_module && DECL_EXTERNAL (decl))
21125 const char *name = dwarf2_name (decl, 0);
21126 if (name)
21127 add_name_attribute (namespace_die, name);
21129 else
21130 add_name_and_src_coords_attributes (namespace_die, decl);
21131 if (DECL_EXTERNAL (decl))
21132 add_AT_flag (namespace_die, DW_AT_declaration, 1);
21133 equate_decl_number_to_die (decl, namespace_die);
21135 else
21137 /* Output a namespace alias. */
21139 /* Force out the namespace we are an alias of, if necessary. */
21140 dw_die_ref origin_die
21141 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
21143 if (DECL_FILE_SCOPE_P (decl)
21144 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)
21145 context_die = setup_namespace_context (decl, comp_unit_die ());
21146 /* Now create the namespace alias DIE. */
21147 namespace_die = new_die (DW_TAG_imported_declaration, context_die, decl);
21148 add_name_and_src_coords_attributes (namespace_die, decl);
21149 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
21150 equate_decl_number_to_die (decl, namespace_die);
21154 /* Generate Dwarf debug information for a decl described by DECL.
21155 The return value is currently only meaningful for PARM_DECLs,
21156 for all other decls it returns NULL. */
21158 static dw_die_ref
21159 gen_decl_die (tree decl, tree origin, dw_die_ref context_die)
21161 tree decl_or_origin = decl ? decl : origin;
21162 tree class_origin = NULL, ultimate_origin;
21164 if (DECL_P (decl_or_origin) && DECL_IGNORED_P (decl_or_origin))
21165 return NULL;
21167 switch (TREE_CODE (decl_or_origin))
21169 case ERROR_MARK:
21170 break;
21172 case CONST_DECL:
21173 if (!is_fortran () && !is_ada ())
21175 /* The individual enumerators of an enum type get output when we output
21176 the Dwarf representation of the relevant enum type itself. */
21177 break;
21180 /* Emit its type. */
21181 gen_type_die (TREE_TYPE (decl), context_die);
21183 /* And its containing namespace. */
21184 context_die = declare_in_namespace (decl, context_die);
21186 gen_const_die (decl, context_die);
21187 break;
21189 case FUNCTION_DECL:
21190 /* Don't output any DIEs to represent mere function declarations,
21191 unless they are class members or explicit block externs. */
21192 if (DECL_INITIAL (decl_or_origin) == NULL_TREE
21193 && DECL_FILE_SCOPE_P (decl_or_origin)
21194 && (current_function_decl == NULL_TREE
21195 || DECL_ARTIFICIAL (decl_or_origin)))
21196 break;
21198 #if 0
21199 /* FIXME */
21200 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21201 on local redeclarations of global functions. That seems broken. */
21202 if (current_function_decl != decl)
21203 /* This is only a declaration. */;
21204 #endif
21206 /* If we're emitting a clone, emit info for the abstract instance. */
21207 if (origin || DECL_ORIGIN (decl) != decl)
21208 dwarf2out_abstract_function (origin
21209 ? DECL_ORIGIN (origin)
21210 : DECL_ABSTRACT_ORIGIN (decl));
21212 /* If we're emitting an out-of-line copy of an inline function,
21213 emit info for the abstract instance and set up to refer to it. */
21214 else if (cgraph_function_possibly_inlined_p (decl)
21215 && ! DECL_ABSTRACT (decl)
21216 && ! class_or_namespace_scope_p (context_die)
21217 /* dwarf2out_abstract_function won't emit a die if this is just
21218 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21219 that case, because that works only if we have a die. */
21220 && DECL_INITIAL (decl) != NULL_TREE)
21222 dwarf2out_abstract_function (decl);
21223 set_decl_origin_self (decl);
21226 /* Otherwise we're emitting the primary DIE for this decl. */
21227 else if (debug_info_level > DINFO_LEVEL_TERSE)
21229 /* Before we describe the FUNCTION_DECL itself, make sure that we
21230 have its containing type. */
21231 if (!origin)
21232 origin = decl_class_context (decl);
21233 if (origin != NULL_TREE)
21234 gen_type_die (origin, context_die);
21236 /* And its return type. */
21237 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
21239 /* And its virtual context. */
21240 if (DECL_VINDEX (decl) != NULL_TREE)
21241 gen_type_die (DECL_CONTEXT (decl), context_die);
21243 /* Make sure we have a member DIE for decl. */
21244 if (origin != NULL_TREE)
21245 gen_type_die_for_member (origin, decl, context_die);
21247 /* And its containing namespace. */
21248 context_die = declare_in_namespace (decl, context_die);
21251 /* Now output a DIE to represent the function itself. */
21252 if (decl)
21253 gen_subprogram_die (decl, context_die);
21254 break;
21256 case TYPE_DECL:
21257 /* If we are in terse mode, don't generate any DIEs to represent any
21258 actual typedefs. */
21259 if (debug_info_level <= DINFO_LEVEL_TERSE)
21260 break;
21262 /* In the special case of a TYPE_DECL node representing the declaration
21263 of some type tag, if the given TYPE_DECL is marked as having been
21264 instantiated from some other (original) TYPE_DECL node (e.g. one which
21265 was generated within the original definition of an inline function) we
21266 used to generate a special (abbreviated) DW_TAG_structure_type,
21267 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21268 should be actually referencing those DIEs, as variable DIEs with that
21269 type would be emitted already in the abstract origin, so it was always
21270 removed during unused type prunning. Don't add anything in this
21271 case. */
21272 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
21273 break;
21275 if (is_redundant_typedef (decl))
21276 gen_type_die (TREE_TYPE (decl), context_die);
21277 else
21278 /* Output a DIE to represent the typedef itself. */
21279 gen_typedef_die (decl, context_die);
21280 break;
21282 case LABEL_DECL:
21283 if (debug_info_level >= DINFO_LEVEL_NORMAL)
21284 gen_label_die (decl, context_die);
21285 break;
21287 case VAR_DECL:
21288 case RESULT_DECL:
21289 /* If we are in terse mode, don't generate any DIEs to represent any
21290 variable declarations or definitions. */
21291 if (debug_info_level <= DINFO_LEVEL_TERSE)
21292 break;
21294 /* Output any DIEs that are needed to specify the type of this data
21295 object. */
21296 if (decl_by_reference_p (decl_or_origin))
21297 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21298 else
21299 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21301 /* And its containing type. */
21302 class_origin = decl_class_context (decl_or_origin);
21303 if (class_origin != NULL_TREE)
21304 gen_type_die_for_member (class_origin, decl_or_origin, context_die);
21306 /* And its containing namespace. */
21307 context_die = declare_in_namespace (decl_or_origin, context_die);
21309 /* Now output the DIE to represent the data object itself. This gets
21310 complicated because of the possibility that the VAR_DECL really
21311 represents an inlined instance of a formal parameter for an inline
21312 function. */
21313 ultimate_origin = decl_ultimate_origin (decl_or_origin);
21314 if (ultimate_origin != NULL_TREE
21315 && TREE_CODE (ultimate_origin) == PARM_DECL)
21316 gen_formal_parameter_die (decl, origin,
21317 true /* Emit name attribute. */,
21318 context_die);
21319 else
21320 gen_variable_die (decl, origin, context_die);
21321 break;
21323 case FIELD_DECL:
21324 /* Ignore the nameless fields that are used to skip bits but handle C++
21325 anonymous unions and structs. */
21326 if (DECL_NAME (decl) != NULL_TREE
21327 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
21328 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
21330 gen_type_die (member_declared_type (decl), context_die);
21331 gen_field_die (decl, context_die);
21333 break;
21335 case PARM_DECL:
21336 if (DECL_BY_REFERENCE (decl_or_origin))
21337 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin)), context_die);
21338 else
21339 gen_type_die (TREE_TYPE (decl_or_origin), context_die);
21340 return gen_formal_parameter_die (decl, origin,
21341 true /* Emit name attribute. */,
21342 context_die);
21344 case NAMESPACE_DECL:
21345 case IMPORTED_DECL:
21346 if (dwarf_version >= 3 || !dwarf_strict)
21347 gen_namespace_die (decl, context_die);
21348 break;
21350 default:
21351 /* Probably some frontend-internal decl. Assume we don't care. */
21352 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
21353 break;
21356 return NULL;
21359 /* Output debug information for global decl DECL. Called from toplev.c after
21360 compilation proper has finished. */
21362 static void
21363 dwarf2out_global_decl (tree decl)
21365 /* Output DWARF2 information for file-scope tentative data object
21366 declarations, file-scope (extern) function declarations (which
21367 had no corresponding body) and file-scope tagged type declarations
21368 and definitions which have not yet been forced out. */
21369 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
21370 dwarf2out_decl (decl);
21373 /* Output debug information for type decl DECL. Called from toplev.c
21374 and from language front ends (to record built-in types). */
21375 static void
21376 dwarf2out_type_decl (tree decl, int local)
21378 if (!local)
21379 dwarf2out_decl (decl);
21382 /* Output debug information for imported module or decl DECL.
21383 NAME is non-NULL name in the lexical block if the decl has been renamed.
21384 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21385 that DECL belongs to.
21386 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21387 static void
21388 dwarf2out_imported_module_or_decl_1 (tree decl,
21389 tree name,
21390 tree lexical_block,
21391 dw_die_ref lexical_block_die)
21393 expanded_location xloc;
21394 dw_die_ref imported_die = NULL;
21395 dw_die_ref at_import_die;
21397 if (TREE_CODE (decl) == IMPORTED_DECL)
21399 xloc = expand_location (DECL_SOURCE_LOCATION (decl));
21400 decl = IMPORTED_DECL_ASSOCIATED_DECL (decl);
21401 gcc_assert (decl);
21403 else
21404 xloc = expand_location (input_location);
21406 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
21408 at_import_die = force_type_die (TREE_TYPE (decl));
21409 /* For namespace N { typedef void T; } using N::T; base_type_die
21410 returns NULL, but DW_TAG_imported_declaration requires
21411 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21412 if (!at_import_die)
21414 gcc_assert (TREE_CODE (decl) == TYPE_DECL);
21415 gen_typedef_die (decl, get_context_die (DECL_CONTEXT (decl)));
21416 at_import_die = lookup_type_die (TREE_TYPE (decl));
21417 gcc_assert (at_import_die);
21420 else
21422 at_import_die = lookup_decl_die (decl);
21423 if (!at_import_die)
21425 /* If we're trying to avoid duplicate debug info, we may not have
21426 emitted the member decl for this field. Emit it now. */
21427 if (TREE_CODE (decl) == FIELD_DECL)
21429 tree type = DECL_CONTEXT (decl);
21431 if (TYPE_CONTEXT (type)
21432 && TYPE_P (TYPE_CONTEXT (type))
21433 && !should_emit_struct_debug (TYPE_CONTEXT (type),
21434 DINFO_USAGE_DIR_USE))
21435 return;
21436 gen_type_die_for_member (type, decl,
21437 get_context_die (TYPE_CONTEXT (type)));
21439 at_import_die = force_decl_die (decl);
21443 if (TREE_CODE (decl) == NAMESPACE_DECL)
21445 if (dwarf_version >= 3 || !dwarf_strict)
21446 imported_die = new_die (DW_TAG_imported_module,
21447 lexical_block_die,
21448 lexical_block);
21449 else
21450 return;
21452 else
21453 imported_die = new_die (DW_TAG_imported_declaration,
21454 lexical_block_die,
21455 lexical_block);
21457 add_AT_file (imported_die, DW_AT_decl_file, lookup_filename (xloc.file));
21458 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
21459 if (name)
21460 add_AT_string (imported_die, DW_AT_name,
21461 IDENTIFIER_POINTER (name));
21462 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
21465 /* Output debug information for imported module or decl DECL.
21466 NAME is non-NULL name in context if the decl has been renamed.
21467 CHILD is true if decl is one of the renamed decls as part of
21468 importing whole module. */
21470 static void
21471 dwarf2out_imported_module_or_decl (tree decl, tree name, tree context,
21472 bool child)
21474 /* dw_die_ref at_import_die; */
21475 dw_die_ref scope_die;
21477 if (debug_info_level <= DINFO_LEVEL_TERSE)
21478 return;
21480 gcc_assert (decl);
21482 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21483 We need decl DIE for reference and scope die. First, get DIE for the decl
21484 itself. */
21486 /* Get the scope die for decl context. Use comp_unit_die for global module
21487 or decl. If die is not found for non globals, force new die. */
21488 if (context
21489 && TYPE_P (context)
21490 && !should_emit_struct_debug (context, DINFO_USAGE_DIR_USE))
21491 return;
21493 if (!(dwarf_version >= 3 || !dwarf_strict))
21494 return;
21496 scope_die = get_context_die (context);
21498 if (child)
21500 gcc_assert (scope_die->die_child);
21501 gcc_assert (scope_die->die_child->die_tag == DW_TAG_imported_module);
21502 gcc_assert (TREE_CODE (decl) != NAMESPACE_DECL);
21503 scope_die = scope_die->die_child;
21506 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21507 dwarf2out_imported_module_or_decl_1 (decl, name, context, scope_die);
21511 /* Write the debugging output for DECL. */
21513 void
21514 dwarf2out_decl (tree decl)
21516 dw_die_ref context_die = comp_unit_die ();
21518 switch (TREE_CODE (decl))
21520 case ERROR_MARK:
21521 return;
21523 case FUNCTION_DECL:
21524 /* What we would really like to do here is to filter out all mere
21525 file-scope declarations of file-scope functions which are never
21526 referenced later within this translation unit (and keep all of ones
21527 that *are* referenced later on) but we aren't clairvoyant, so we have
21528 no idea which functions will be referenced in the future (i.e. later
21529 on within the current translation unit). So here we just ignore all
21530 file-scope function declarations which are not also definitions. If
21531 and when the debugger needs to know something about these functions,
21532 it will have to hunt around and find the DWARF information associated
21533 with the definition of the function.
21535 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21536 nodes represent definitions and which ones represent mere
21537 declarations. We have to check DECL_INITIAL instead. That's because
21538 the C front-end supports some weird semantics for "extern inline"
21539 function definitions. These can get inlined within the current
21540 translation unit (and thus, we need to generate Dwarf info for their
21541 abstract instances so that the Dwarf info for the concrete inlined
21542 instances can have something to refer to) but the compiler never
21543 generates any out-of-lines instances of such things (despite the fact
21544 that they *are* definitions).
21546 The important point is that the C front-end marks these "extern
21547 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21548 them anyway. Note that the C++ front-end also plays some similar games
21549 for inline function definitions appearing within include files which
21550 also contain `#pragma interface' pragmas. */
21551 if (DECL_INITIAL (decl) == NULL_TREE)
21552 return;
21554 /* If we're a nested function, initially use a parent of NULL; if we're
21555 a plain function, this will be fixed up in decls_for_scope. If
21556 we're a method, it will be ignored, since we already have a DIE. */
21557 if (decl_function_context (decl)
21558 /* But if we're in terse mode, we don't care about scope. */
21559 && debug_info_level > DINFO_LEVEL_TERSE)
21560 context_die = NULL;
21561 break;
21563 case VAR_DECL:
21564 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
21565 declaration and if the declaration was never even referenced from
21566 within this entire compilation unit. We suppress these DIEs in
21567 order to save space in the .debug section (by eliminating entries
21568 which are probably useless). Note that we must not suppress
21569 block-local extern declarations (whether used or not) because that
21570 would screw-up the debugger's name lookup mechanism and cause it to
21571 miss things which really ought to be in scope at a given point. */
21572 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
21573 return;
21575 /* For local statics lookup proper context die. */
21576 if (TREE_STATIC (decl) && decl_function_context (decl))
21577 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21579 /* If we are in terse mode, don't generate any DIEs to represent any
21580 variable declarations or definitions. */
21581 if (debug_info_level <= DINFO_LEVEL_TERSE)
21582 return;
21583 break;
21585 case CONST_DECL:
21586 if (debug_info_level <= DINFO_LEVEL_TERSE)
21587 return;
21588 if (!is_fortran () && !is_ada ())
21589 return;
21590 if (TREE_STATIC (decl) && decl_function_context (decl))
21591 context_die = lookup_decl_die (DECL_CONTEXT (decl));
21592 break;
21594 case NAMESPACE_DECL:
21595 case IMPORTED_DECL:
21596 if (debug_info_level <= DINFO_LEVEL_TERSE)
21597 return;
21598 if (lookup_decl_die (decl) != NULL)
21599 return;
21600 break;
21602 case TYPE_DECL:
21603 /* Don't emit stubs for types unless they are needed by other DIEs. */
21604 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
21605 return;
21607 /* Don't bother trying to generate any DIEs to represent any of the
21608 normal built-in types for the language we are compiling. */
21609 if (DECL_IS_BUILTIN (decl))
21610 return;
21612 /* If we are in terse mode, don't generate any DIEs for types. */
21613 if (debug_info_level <= DINFO_LEVEL_TERSE)
21614 return;
21616 /* If we're a function-scope tag, initially use a parent of NULL;
21617 this will be fixed up in decls_for_scope. */
21618 if (decl_function_context (decl))
21619 context_die = NULL;
21621 break;
21623 default:
21624 return;
21627 gen_decl_die (decl, NULL, context_die);
21630 /* Write the debugging output for DECL. */
21632 static void
21633 dwarf2out_function_decl (tree decl)
21635 dwarf2out_decl (decl);
21636 call_arg_locations = NULL;
21637 call_arg_loc_last = NULL;
21638 call_site_count = -1;
21639 tail_call_site_count = -1;
21640 VEC_free (dw_die_ref, heap, block_map);
21641 htab_empty (decl_loc_table);
21642 htab_empty (cached_dw_loc_list_table);
21645 /* Output a marker (i.e. a label) for the beginning of the generated code for
21646 a lexical block. */
21648 static void
21649 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
21650 unsigned int blocknum)
21652 switch_to_section (current_function_section ());
21653 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
21656 /* Output a marker (i.e. a label) for the end of the generated code for a
21657 lexical block. */
21659 static void
21660 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
21662 switch_to_section (current_function_section ());
21663 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
21666 /* Returns nonzero if it is appropriate not to emit any debugging
21667 information for BLOCK, because it doesn't contain any instructions.
21669 Don't allow this for blocks with nested functions or local classes
21670 as we would end up with orphans, and in the presence of scheduling
21671 we may end up calling them anyway. */
21673 static bool
21674 dwarf2out_ignore_block (const_tree block)
21676 tree decl;
21677 unsigned int i;
21679 for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl))
21680 if (TREE_CODE (decl) == FUNCTION_DECL
21681 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21682 return 0;
21683 for (i = 0; i < BLOCK_NUM_NONLOCALIZED_VARS (block); i++)
21685 decl = BLOCK_NONLOCALIZED_VAR (block, i);
21686 if (TREE_CODE (decl) == FUNCTION_DECL
21687 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
21688 return 0;
21691 return 1;
21694 /* Hash table routines for file_hash. */
21696 static int
21697 file_table_eq (const void *p1_p, const void *p2_p)
21699 const struct dwarf_file_data *const p1 =
21700 (const struct dwarf_file_data *) p1_p;
21701 const char *const p2 = (const char *) p2_p;
21702 return filename_cmp (p1->filename, p2) == 0;
21705 static hashval_t
21706 file_table_hash (const void *p_p)
21708 const struct dwarf_file_data *const p = (const struct dwarf_file_data *) p_p;
21709 return htab_hash_string (p->filename);
21712 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21713 dwarf2out.c) and return its "index". The index of each (known) filename is
21714 just a unique number which is associated with only that one filename. We
21715 need such numbers for the sake of generating labels (in the .debug_sfnames
21716 section) and references to those files numbers (in the .debug_srcinfo
21717 and.debug_macinfo sections). If the filename given as an argument is not
21718 found in our current list, add it to the list and assign it the next
21719 available unique index number. In order to speed up searches, we remember
21720 the index of the filename was looked up last. This handles the majority of
21721 all searches. */
21723 static struct dwarf_file_data *
21724 lookup_filename (const char *file_name)
21726 void ** slot;
21727 struct dwarf_file_data * created;
21729 /* Check to see if the file name that was searched on the previous
21730 call matches this file name. If so, return the index. */
21731 if (file_table_last_lookup
21732 && (file_name == file_table_last_lookup->filename
21733 || filename_cmp (file_table_last_lookup->filename, file_name) == 0))
21734 return file_table_last_lookup;
21736 /* Didn't match the previous lookup, search the table. */
21737 slot = htab_find_slot_with_hash (file_table, file_name,
21738 htab_hash_string (file_name), INSERT);
21739 if (*slot)
21740 return (struct dwarf_file_data *) *slot;
21742 created = ggc_alloc_dwarf_file_data ();
21743 created->filename = file_name;
21744 created->emitted_number = 0;
21745 *slot = created;
21746 return created;
21749 /* If the assembler will construct the file table, then translate the compiler
21750 internal file table number into the assembler file table number, and emit
21751 a .file directive if we haven't already emitted one yet. The file table
21752 numbers are different because we prune debug info for unused variables and
21753 types, which may include filenames. */
21755 static int
21756 maybe_emit_file (struct dwarf_file_data * fd)
21758 if (! fd->emitted_number)
21760 if (last_emitted_file)
21761 fd->emitted_number = last_emitted_file->emitted_number + 1;
21762 else
21763 fd->emitted_number = 1;
21764 last_emitted_file = fd;
21766 if (DWARF2_ASM_LINE_DEBUG_INFO)
21768 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
21769 output_quoted_string (asm_out_file,
21770 remap_debug_filename (fd->filename));
21771 fputc ('\n', asm_out_file);
21775 return fd->emitted_number;
21778 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21779 That generation should happen after function debug info has been
21780 generated. The value of the attribute is the constant value of ARG. */
21782 static void
21783 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die, tree arg)
21785 die_arg_entry entry;
21787 if (!die || !arg)
21788 return;
21790 if (!tmpl_value_parm_die_table)
21791 tmpl_value_parm_die_table
21792 = VEC_alloc (die_arg_entry, gc, 32);
21794 entry.die = die;
21795 entry.arg = arg;
21796 VEC_safe_push (die_arg_entry, gc,
21797 tmpl_value_parm_die_table,
21798 &entry);
21801 /* Return TRUE if T is an instance of generic type, FALSE
21802 otherwise. */
21804 static bool
21805 generic_type_p (tree t)
21807 if (t == NULL_TREE || !TYPE_P (t))
21808 return false;
21809 return lang_hooks.get_innermost_generic_parms (t) != NULL_TREE;
21812 /* Schedule the generation of the generic parameter dies for the
21813 instance of generic type T. The proper generation itself is later
21814 done by gen_scheduled_generic_parms_dies. */
21816 static void
21817 schedule_generic_params_dies_gen (tree t)
21819 if (!generic_type_p (t))
21820 return;
21822 if (generic_type_instances == NULL)
21823 generic_type_instances = VEC_alloc (tree, gc, 256);
21825 VEC_safe_push (tree, gc, generic_type_instances, t);
21828 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21829 by append_entry_to_tmpl_value_parm_die_table. This function must
21830 be called after function DIEs have been generated. */
21832 static void
21833 gen_remaining_tmpl_value_param_die_attribute (void)
21835 if (tmpl_value_parm_die_table)
21837 unsigned i;
21838 die_arg_entry *e;
21840 FOR_EACH_VEC_ELT (die_arg_entry, tmpl_value_parm_die_table, i, e)
21841 tree_add_const_value_attribute (e->die, e->arg);
21845 /* Generate generic parameters DIEs for instances of generic types
21846 that have been previously scheduled by
21847 schedule_generic_params_dies_gen. This function must be called
21848 after all the types of the CU have been laid out. */
21850 static void
21851 gen_scheduled_generic_parms_dies (void)
21853 unsigned i;
21854 tree t;
21856 if (generic_type_instances == NULL)
21857 return;
21859 FOR_EACH_VEC_ELT (tree, generic_type_instances, i, t)
21860 gen_generic_params_dies (t);
21864 /* Replace DW_AT_name for the decl with name. */
21866 static void
21867 dwarf2out_set_name (tree decl, tree name)
21869 dw_die_ref die;
21870 dw_attr_ref attr;
21871 const char *dname;
21873 die = TYPE_SYMTAB_DIE (decl);
21874 if (!die)
21875 return;
21877 dname = dwarf2_name (name, 0);
21878 if (!dname)
21879 return;
21881 attr = get_AT (die, DW_AT_name);
21882 if (attr)
21884 struct indirect_string_node *node;
21886 node = find_AT_string (dname);
21887 /* replace the string. */
21888 attr->dw_attr_val.v.val_str = node;
21891 else
21892 add_name_attribute (die, dname);
21895 /* Called by the final INSN scan whenever we see a var location. We
21896 use it to drop labels in the right places, and throw the location in
21897 our lookup table. */
21899 static void
21900 dwarf2out_var_location (rtx loc_note)
21902 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES + 2];
21903 struct var_loc_node *newloc;
21904 rtx next_real;
21905 static const char *last_label;
21906 static const char *last_postcall_label;
21907 static bool last_in_cold_section_p;
21908 tree decl;
21909 bool var_loc_p;
21911 if (!NOTE_P (loc_note))
21913 if (CALL_P (loc_note))
21915 call_site_count++;
21916 if (SIBLING_CALL_P (loc_note))
21917 tail_call_site_count++;
21919 return;
21922 var_loc_p = NOTE_KIND (loc_note) == NOTE_INSN_VAR_LOCATION;
21923 if (var_loc_p && !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
21924 return;
21926 next_real = next_real_insn (loc_note);
21928 /* If there are no instructions which would be affected by this note,
21929 don't do anything. */
21930 if (var_loc_p
21931 && next_real == NULL_RTX
21932 && !NOTE_DURING_CALL_P (loc_note))
21933 return;
21935 if (next_real == NULL_RTX)
21936 next_real = get_last_insn ();
21938 /* If there were any real insns between note we processed last time
21939 and this note (or if it is the first note), clear
21940 last_{,postcall_}label so that they are not reused this time. */
21941 if (last_var_location_insn == NULL_RTX
21942 || last_var_location_insn != next_real
21943 || last_in_cold_section_p != in_cold_section_p)
21945 last_label = NULL;
21946 last_postcall_label = NULL;
21949 if (var_loc_p)
21951 decl = NOTE_VAR_LOCATION_DECL (loc_note);
21952 newloc = add_var_loc_to_decl (decl, loc_note,
21953 NOTE_DURING_CALL_P (loc_note)
21954 ? last_postcall_label : last_label);
21955 if (newloc == NULL)
21956 return;
21958 else
21960 decl = NULL_TREE;
21961 newloc = NULL;
21964 /* If there were no real insns between note we processed last time
21965 and this note, use the label we emitted last time. Otherwise
21966 create a new label and emit it. */
21967 if (last_label == NULL)
21969 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
21970 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
21971 loclabel_num++;
21972 last_label = ggc_strdup (loclabel);
21975 if (!var_loc_p)
21977 struct call_arg_loc_node *ca_loc
21978 = ggc_alloc_cleared_call_arg_loc_node ();
21979 rtx prev = prev_real_insn (loc_note), x;
21980 ca_loc->call_arg_loc_note = loc_note;
21981 ca_loc->next = NULL;
21982 ca_loc->label = last_label;
21983 gcc_assert (prev
21984 && (CALL_P (prev)
21985 || (NONJUMP_INSN_P (prev)
21986 && GET_CODE (PATTERN (prev)) == SEQUENCE
21987 && CALL_P (XVECEXP (PATTERN (prev), 0, 0)))));
21988 if (!CALL_P (prev))
21989 prev = XVECEXP (PATTERN (prev), 0, 0);
21990 ca_loc->tail_call_p = SIBLING_CALL_P (prev);
21991 x = PATTERN (prev);
21992 if (GET_CODE (x) == PARALLEL)
21993 x = XVECEXP (x, 0, 0);
21994 if (GET_CODE (x) == SET)
21995 x = SET_SRC (x);
21996 if (GET_CODE (x) == CALL && MEM_P (XEXP (x, 0)))
21998 x = XEXP (XEXP (x, 0), 0);
21999 if (GET_CODE (x) == SYMBOL_REF
22000 && SYMBOL_REF_DECL (x)
22001 && TREE_CODE (SYMBOL_REF_DECL (x)) == FUNCTION_DECL)
22002 ca_loc->symbol_ref = x;
22004 ca_loc->block = insn_scope (prev);
22005 if (call_arg_locations)
22006 call_arg_loc_last->next = ca_loc;
22007 else
22008 call_arg_locations = ca_loc;
22009 call_arg_loc_last = ca_loc;
22011 else if (!NOTE_DURING_CALL_P (loc_note))
22012 newloc->label = last_label;
22013 else
22015 if (!last_postcall_label)
22017 sprintf (loclabel, "%s-1", last_label);
22018 last_postcall_label = ggc_strdup (loclabel);
22020 newloc->label = last_postcall_label;
22023 last_var_location_insn = next_real;
22024 last_in_cold_section_p = in_cold_section_p;
22027 /* Note in one location list that text section has changed. */
22029 static int
22030 var_location_switch_text_section_1 (void **slot, void *data ATTRIBUTE_UNUSED)
22032 var_loc_list *list = (var_loc_list *) *slot;
22033 if (list->first)
22034 list->last_before_switch
22035 = list->last->next ? list->last->next : list->last;
22036 return 1;
22039 /* Note in all location lists that text section has changed. */
22041 static void
22042 var_location_switch_text_section (void)
22044 if (decl_loc_table == NULL)
22045 return;
22047 htab_traverse (decl_loc_table, var_location_switch_text_section_1, NULL);
22050 /* Create a new line number table. */
22052 static dw_line_info_table *
22053 new_line_info_table (void)
22055 dw_line_info_table *table;
22057 table = ggc_alloc_cleared_dw_line_info_table_struct ();
22058 table->file_num = 1;
22059 table->line_num = 1;
22060 table->is_stmt = DWARF_LINE_DEFAULT_IS_STMT_START;
22062 return table;
22065 /* Lookup the "current" table into which we emit line info, so
22066 that we don't have to do it for every source line. */
22068 static void
22069 set_cur_line_info_table (section *sec)
22071 dw_line_info_table *table;
22073 if (sec == text_section)
22075 table = text_section_line_info;
22076 if (!table)
22078 text_section_line_info = table = new_line_info_table ();
22079 table->end_label = text_end_label;
22082 else if (sec == cold_text_section)
22084 table = cold_text_section_line_info;
22085 if (!table)
22087 cold_text_section_line_info = table = new_line_info_table ();
22088 table->end_label = cold_end_label;
22091 else
22093 const char *end_label;
22095 if (flag_reorder_blocks_and_partition)
22097 if (in_cold_section_p)
22098 end_label = crtl->subsections.cold_section_end_label;
22099 else
22100 end_label = crtl->subsections.hot_section_end_label;
22102 else
22104 char label[MAX_ARTIFICIAL_LABEL_BYTES];
22105 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
22106 current_function_funcdef_no);
22107 end_label = ggc_strdup (label);
22110 table = new_line_info_table ();
22111 table->end_label = end_label;
22113 VEC_safe_push (dw_line_info_table_p, gc, separate_line_info, table);
22116 cur_line_info_table = table;
22120 /* We need to reset the locations at the beginning of each
22121 function. We can't do this in the end_function hook, because the
22122 declarations that use the locations won't have been output when
22123 that hook is called. Also compute have_multiple_function_sections here. */
22125 static void
22126 dwarf2out_begin_function (tree fun)
22128 section *sec = function_section (fun);
22130 if (sec != text_section)
22131 have_multiple_function_sections = true;
22133 if (flag_reorder_blocks_and_partition && !cold_text_section)
22135 gcc_assert (current_function_decl == fun);
22136 cold_text_section = unlikely_text_section ();
22137 switch_to_section (cold_text_section);
22138 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
22139 switch_to_section (sec);
22142 dwarf2out_note_section_used ();
22143 call_site_count = 0;
22144 tail_call_site_count = 0;
22146 set_cur_line_info_table (sec);
22149 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22151 static void
22152 push_dw_line_info_entry (dw_line_info_table *table,
22153 enum dw_line_info_opcode opcode, unsigned int val)
22155 dw_line_info_entry e;
22156 e.opcode = opcode;
22157 e.val = val;
22158 VEC_safe_push (dw_line_info_entry, gc, table->entries, &e);
22161 /* Output a label to mark the beginning of a source code line entry
22162 and record information relating to this source line, in
22163 'line_info_table' for later output of the .debug_line section. */
22164 /* ??? The discriminator parameter ought to be unsigned. */
22166 static void
22167 dwarf2out_source_line (unsigned int line, const char *filename,
22168 int discriminator, bool is_stmt)
22170 unsigned int file_num;
22171 dw_line_info_table *table;
22173 if (debug_info_level < DINFO_LEVEL_NORMAL || line == 0)
22174 return;
22176 /* The discriminator column was added in dwarf4. Simplify the below
22177 by simply removing it if we're not supposed to output it. */
22178 if (dwarf_version < 4 && dwarf_strict)
22179 discriminator = 0;
22181 table = cur_line_info_table;
22182 file_num = maybe_emit_file (lookup_filename (filename));
22184 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22185 the debugger has used the second (possibly duplicate) line number
22186 at the beginning of the function to mark the end of the prologue.
22187 We could eliminate any other duplicates within the function. For
22188 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22189 that second line number entry. */
22190 /* Recall that this end-of-prologue indication is *not* the same thing
22191 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22192 to which the hook corresponds, follows the last insn that was
22193 emitted by gen_prologue. What we need is to preceed the first insn
22194 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22195 insn that corresponds to something the user wrote. These may be
22196 very different locations once scheduling is enabled. */
22198 if (0 && file_num == table->file_num
22199 && line == table->line_num
22200 && discriminator == table->discrim_num
22201 && is_stmt == table->is_stmt)
22202 return;
22204 switch_to_section (current_function_section ());
22206 /* If requested, emit something human-readable. */
22207 if (flag_debug_asm)
22208 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, filename, line);
22210 if (DWARF2_ASM_LINE_DEBUG_INFO)
22212 /* Emit the .loc directive understood by GNU as. */
22213 fprintf (asm_out_file, "\t.loc %d %d 0", file_num, line);
22214 if (is_stmt != table->is_stmt)
22215 fprintf (asm_out_file, " is_stmt %d", is_stmt ? 1 : 0);
22216 if (SUPPORTS_DISCRIMINATOR && discriminator != 0)
22217 fprintf (asm_out_file, " discriminator %d", discriminator);
22218 fputc ('\n', asm_out_file);
22220 else
22222 unsigned int label_num = ++line_info_label_num;
22224 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL, label_num);
22226 push_dw_line_info_entry (table, LI_set_address, label_num);
22227 if (file_num != table->file_num)
22228 push_dw_line_info_entry (table, LI_set_file, file_num);
22229 if (discriminator != table->discrim_num)
22230 push_dw_line_info_entry (table, LI_set_discriminator, discriminator);
22231 if (is_stmt != table->is_stmt)
22232 push_dw_line_info_entry (table, LI_negate_stmt, 0);
22233 push_dw_line_info_entry (table, LI_set_line, line);
22236 table->file_num = file_num;
22237 table->line_num = line;
22238 table->discrim_num = discriminator;
22239 table->is_stmt = is_stmt;
22240 table->in_use = true;
22243 /* Record the beginning of a new source file. */
22245 static void
22246 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
22248 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22250 /* Record the beginning of the file for break_out_includes. */
22251 dw_die_ref bincl_die;
22253 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die (), NULL);
22254 add_AT_string (bincl_die, DW_AT_name, remap_debug_filename (filename));
22257 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22259 macinfo_entry e;
22260 e.code = DW_MACINFO_start_file;
22261 e.lineno = lineno;
22262 e.info = xstrdup (filename);
22263 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22267 /* Record the end of a source file. */
22269 static void
22270 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
22272 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
22273 /* Record the end of the file for break_out_includes. */
22274 new_die (DW_TAG_GNU_EINCL, comp_unit_die (), NULL);
22276 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22278 macinfo_entry e;
22279 e.code = DW_MACINFO_end_file;
22280 e.lineno = lineno;
22281 e.info = NULL;
22282 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22286 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22287 the tail part of the directive line, i.e. the part which is past the
22288 initial whitespace, #, whitespace, directive-name, whitespace part. */
22290 static void
22291 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
22292 const char *buffer ATTRIBUTE_UNUSED)
22294 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22296 macinfo_entry e;
22297 e.code = DW_MACINFO_define;
22298 e.lineno = lineno;
22299 e.info = xstrdup (buffer);;
22300 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22304 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22305 the tail part of the directive line, i.e. the part which is past the
22306 initial whitespace, #, whitespace, directive-name, whitespace part. */
22308 static void
22309 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
22310 const char *buffer ATTRIBUTE_UNUSED)
22312 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22314 macinfo_entry e;
22315 e.code = DW_MACINFO_undef;
22316 e.lineno = lineno;
22317 e.info = xstrdup (buffer);;
22318 VEC_safe_push (macinfo_entry, gc, macinfo_table, &e);
22322 static void
22323 output_macinfo (void)
22325 unsigned i;
22326 unsigned long length = VEC_length (macinfo_entry, macinfo_table);
22327 macinfo_entry *ref;
22329 if (! length)
22330 return;
22332 for (i = 0; VEC_iterate (macinfo_entry, macinfo_table, i, ref); i++)
22334 switch (ref->code)
22336 case DW_MACINFO_start_file:
22338 int file_num = maybe_emit_file (lookup_filename (ref->info));
22339 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
22340 dw2_asm_output_data_uleb128
22341 (ref->lineno, "Included from line number %lu",
22342 (unsigned long)ref->lineno);
22343 dw2_asm_output_data_uleb128 (file_num, "file %s", ref->info);
22345 break;
22346 case DW_MACINFO_end_file:
22347 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
22348 break;
22349 case DW_MACINFO_define:
22350 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
22351 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22352 (unsigned long)ref->lineno);
22353 dw2_asm_output_nstring (ref->info, -1, "The macro");
22354 break;
22355 case DW_MACINFO_undef:
22356 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
22357 dw2_asm_output_data_uleb128 (ref->lineno, "At line number %lu",
22358 (unsigned long)ref->lineno);
22359 dw2_asm_output_nstring (ref->info, -1, "The macro");
22360 break;
22361 default:
22362 fprintf (asm_out_file, "%s unrecognized macinfo code %lu\n",
22363 ASM_COMMENT_START, (unsigned long)ref->code);
22364 break;
22369 /* Set up for Dwarf output at the start of compilation. */
22371 static void
22372 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
22374 /* Allocate the file_table. */
22375 file_table = htab_create_ggc (50, file_table_hash,
22376 file_table_eq, NULL);
22378 /* Allocate the decl_die_table. */
22379 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
22380 decl_die_table_eq, NULL);
22382 /* Allocate the decl_loc_table. */
22383 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
22384 decl_loc_table_eq, NULL);
22386 /* Allocate the cached_dw_loc_list_table. */
22387 cached_dw_loc_list_table
22388 = htab_create_ggc (10, cached_dw_loc_list_table_hash,
22389 cached_dw_loc_list_table_eq, NULL);
22391 /* Allocate the initial hunk of the decl_scope_table. */
22392 decl_scope_table = VEC_alloc (tree, gc, 256);
22394 /* Allocate the initial hunk of the abbrev_die_table. */
22395 abbrev_die_table = ggc_alloc_cleared_vec_dw_die_ref
22396 (ABBREV_DIE_TABLE_INCREMENT);
22397 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
22398 /* Zero-th entry is allocated, but unused. */
22399 abbrev_die_table_in_use = 1;
22401 /* Allocate the pubtypes and pubnames vectors. */
22402 pubname_table = VEC_alloc (pubname_entry, gc, 32);
22403 pubtype_table = VEC_alloc (pubname_entry, gc, 32);
22405 incomplete_types = VEC_alloc (tree, gc, 64);
22407 used_rtx_array = VEC_alloc (rtx, gc, 32);
22409 debug_info_section = get_section (DEBUG_INFO_SECTION,
22410 SECTION_DEBUG, NULL);
22411 debug_abbrev_section = get_section (DEBUG_ABBREV_SECTION,
22412 SECTION_DEBUG, NULL);
22413 debug_aranges_section = get_section (DEBUG_ARANGES_SECTION,
22414 SECTION_DEBUG, NULL);
22415 debug_macinfo_section = get_section (DEBUG_MACINFO_SECTION,
22416 SECTION_DEBUG, NULL);
22417 debug_line_section = get_section (DEBUG_LINE_SECTION,
22418 SECTION_DEBUG, NULL);
22419 debug_loc_section = get_section (DEBUG_LOC_SECTION,
22420 SECTION_DEBUG, NULL);
22421 debug_pubnames_section = get_section (DEBUG_PUBNAMES_SECTION,
22422 SECTION_DEBUG, NULL);
22423 debug_pubtypes_section = get_section (DEBUG_PUBTYPES_SECTION,
22424 SECTION_DEBUG, NULL);
22425 debug_str_section = get_section (DEBUG_STR_SECTION,
22426 DEBUG_STR_SECTION_FLAGS, NULL);
22427 debug_ranges_section = get_section (DEBUG_RANGES_SECTION,
22428 SECTION_DEBUG, NULL);
22429 debug_frame_section = get_section (DEBUG_FRAME_SECTION,
22430 SECTION_DEBUG, NULL);
22432 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
22433 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
22434 DEBUG_ABBREV_SECTION_LABEL, 0);
22435 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
22436 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
22437 COLD_TEXT_SECTION_LABEL, 0);
22438 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
22440 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
22441 DEBUG_INFO_SECTION_LABEL, 0);
22442 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
22443 DEBUG_LINE_SECTION_LABEL, 0);
22444 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
22445 DEBUG_RANGES_SECTION_LABEL, 0);
22446 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
22447 DEBUG_MACINFO_SECTION_LABEL, 0);
22449 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
22450 macinfo_table = VEC_alloc (macinfo_entry, gc, 64);
22452 switch_to_section (text_section);
22453 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
22456 /* Called before cgraph_optimize starts outputtting functions, variables
22457 and toplevel asms into assembly. */
22459 static void
22460 dwarf2out_assembly_start (void)
22462 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22463 && dwarf2out_do_cfi_asm ()
22464 && (!(flag_unwind_tables || flag_exceptions)
22465 || targetm.except_unwind_info (&global_options) != UI_DWARF2))
22466 fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n");
22469 /* A helper function for dwarf2out_finish called through
22470 htab_traverse. Emit one queued .debug_str string. */
22472 static int
22473 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22475 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22477 if (node->label && node->refcount)
22479 switch_to_section (debug_str_section);
22480 ASM_OUTPUT_LABEL (asm_out_file, node->label);
22481 assemble_string (node->str, strlen (node->str) + 1);
22484 return 1;
22487 #if ENABLE_ASSERT_CHECKING
22488 /* Verify that all marks are clear. */
22490 static void
22491 verify_marks_clear (dw_die_ref die)
22493 dw_die_ref c;
22495 gcc_assert (! die->die_mark);
22496 FOR_EACH_CHILD (die, c, verify_marks_clear (c));
22498 #endif /* ENABLE_ASSERT_CHECKING */
22500 /* Clear the marks for a die and its children.
22501 Be cool if the mark isn't set. */
22503 static void
22504 prune_unmark_dies (dw_die_ref die)
22506 dw_die_ref c;
22508 if (die->die_mark)
22509 die->die_mark = 0;
22510 FOR_EACH_CHILD (die, c, prune_unmark_dies (c));
22513 /* Given DIE that we're marking as used, find any other dies
22514 it references as attributes and mark them as used. */
22516 static void
22517 prune_unused_types_walk_attribs (dw_die_ref die)
22519 dw_attr_ref a;
22520 unsigned ix;
22522 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22524 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
22526 /* A reference to another DIE.
22527 Make sure that it will get emitted.
22528 If it was broken out into a comdat group, don't follow it. */
22529 if (! use_debug_types
22530 || a->dw_attr == DW_AT_specification
22531 || a->dw_attr_val.v.val_die_ref.die->die_id.die_type_node == NULL)
22532 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
22534 /* Set the string's refcount to 0 so that prune_unused_types_mark
22535 accounts properly for it. */
22536 if (AT_class (a) == dw_val_class_str)
22537 a->dw_attr_val.v.val_str->refcount = 0;
22541 /* Mark the generic parameters and arguments children DIEs of DIE. */
22543 static void
22544 prune_unused_types_mark_generic_parms_dies (dw_die_ref die)
22546 dw_die_ref c;
22548 if (die == NULL || die->die_child == NULL)
22549 return;
22550 c = die->die_child;
22553 switch (c->die_tag)
22555 case DW_TAG_template_type_param:
22556 case DW_TAG_template_value_param:
22557 case DW_TAG_GNU_template_template_param:
22558 case DW_TAG_GNU_template_parameter_pack:
22559 prune_unused_types_mark (c, 1);
22560 break;
22561 default:
22562 break;
22564 c = c->die_sib;
22565 } while (c && c != die->die_child);
22568 /* Mark DIE as being used. If DOKIDS is true, then walk down
22569 to DIE's children. */
22571 static void
22572 prune_unused_types_mark (dw_die_ref die, int dokids)
22574 dw_die_ref c;
22576 if (die->die_mark == 0)
22578 /* We haven't done this node yet. Mark it as used. */
22579 die->die_mark = 1;
22580 /* If this is the DIE of a generic type instantiation,
22581 mark the children DIEs that describe its generic parms and
22582 args. */
22583 prune_unused_types_mark_generic_parms_dies (die);
22585 /* We also have to mark its parents as used.
22586 (But we don't want to mark our parents' kids due to this.) */
22587 if (die->die_parent)
22588 prune_unused_types_mark (die->die_parent, 0);
22590 /* Mark any referenced nodes. */
22591 prune_unused_types_walk_attribs (die);
22593 /* If this node is a specification,
22594 also mark the definition, if it exists. */
22595 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
22596 prune_unused_types_mark (die->die_definition, 1);
22599 if (dokids && die->die_mark != 2)
22601 /* We need to walk the children, but haven't done so yet.
22602 Remember that we've walked the kids. */
22603 die->die_mark = 2;
22605 /* If this is an array type, we need to make sure our
22606 kids get marked, even if they're types. If we're
22607 breaking out types into comdat sections, do this
22608 for all type definitions. */
22609 if (die->die_tag == DW_TAG_array_type
22610 || (use_debug_types
22611 && is_type_die (die) && ! is_declaration_die (die)))
22612 FOR_EACH_CHILD (die, c, prune_unused_types_mark (c, 1));
22613 else
22614 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22618 /* For local classes, look if any static member functions were emitted
22619 and if so, mark them. */
22621 static void
22622 prune_unused_types_walk_local_classes (dw_die_ref die)
22624 dw_die_ref c;
22626 if (die->die_mark == 2)
22627 return;
22629 switch (die->die_tag)
22631 case DW_TAG_structure_type:
22632 case DW_TAG_union_type:
22633 case DW_TAG_class_type:
22634 break;
22636 case DW_TAG_subprogram:
22637 if (!get_AT_flag (die, DW_AT_declaration)
22638 || die->die_definition != NULL)
22639 prune_unused_types_mark (die, 1);
22640 return;
22642 default:
22643 return;
22646 /* Mark children. */
22647 FOR_EACH_CHILD (die, c, prune_unused_types_walk_local_classes (c));
22650 /* Walk the tree DIE and mark types that we actually use. */
22652 static void
22653 prune_unused_types_walk (dw_die_ref die)
22655 dw_die_ref c;
22657 /* Don't do anything if this node is already marked and
22658 children have been marked as well. */
22659 if (die->die_mark == 2)
22660 return;
22662 switch (die->die_tag)
22664 case DW_TAG_structure_type:
22665 case DW_TAG_union_type:
22666 case DW_TAG_class_type:
22667 if (die->die_perennial_p)
22668 break;
22670 for (c = die->die_parent; c; c = c->die_parent)
22671 if (c->die_tag == DW_TAG_subprogram)
22672 break;
22674 /* Finding used static member functions inside of classes
22675 is needed just for local classes, because for other classes
22676 static member function DIEs with DW_AT_specification
22677 are emitted outside of the DW_TAG_*_type. If we ever change
22678 it, we'd need to call this even for non-local classes. */
22679 if (c)
22680 prune_unused_types_walk_local_classes (die);
22682 /* It's a type node --- don't mark it. */
22683 return;
22685 case DW_TAG_const_type:
22686 case DW_TAG_packed_type:
22687 case DW_TAG_pointer_type:
22688 case DW_TAG_reference_type:
22689 case DW_TAG_rvalue_reference_type:
22690 case DW_TAG_volatile_type:
22691 case DW_TAG_typedef:
22692 case DW_TAG_array_type:
22693 case DW_TAG_interface_type:
22694 case DW_TAG_friend:
22695 case DW_TAG_variant_part:
22696 case DW_TAG_enumeration_type:
22697 case DW_TAG_subroutine_type:
22698 case DW_TAG_string_type:
22699 case DW_TAG_set_type:
22700 case DW_TAG_subrange_type:
22701 case DW_TAG_ptr_to_member_type:
22702 case DW_TAG_file_type:
22703 if (die->die_perennial_p)
22704 break;
22706 /* It's a type node --- don't mark it. */
22707 return;
22709 default:
22710 /* Mark everything else. */
22711 break;
22714 if (die->die_mark == 0)
22716 die->die_mark = 1;
22718 /* Now, mark any dies referenced from here. */
22719 prune_unused_types_walk_attribs (die);
22722 die->die_mark = 2;
22724 /* Mark children. */
22725 FOR_EACH_CHILD (die, c, prune_unused_types_walk (c));
22728 /* Increment the string counts on strings referred to from DIE's
22729 attributes. */
22731 static void
22732 prune_unused_types_update_strings (dw_die_ref die)
22734 dw_attr_ref a;
22735 unsigned ix;
22737 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
22738 if (AT_class (a) == dw_val_class_str)
22740 struct indirect_string_node *s = a->dw_attr_val.v.val_str;
22741 s->refcount++;
22742 /* Avoid unnecessarily putting strings that are used less than
22743 twice in the hash table. */
22744 if (s->refcount
22745 == ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) ? 1 : 2))
22747 void ** slot;
22748 slot = htab_find_slot_with_hash (debug_str_hash, s->str,
22749 htab_hash_string (s->str),
22750 INSERT);
22751 gcc_assert (*slot == NULL);
22752 *slot = s;
22757 /* Remove from the tree DIE any dies that aren't marked. */
22759 static void
22760 prune_unused_types_prune (dw_die_ref die)
22762 dw_die_ref c;
22764 gcc_assert (die->die_mark);
22765 prune_unused_types_update_strings (die);
22767 if (! die->die_child)
22768 return;
22770 c = die->die_child;
22771 do {
22772 dw_die_ref prev = c;
22773 for (c = c->die_sib; ! c->die_mark; c = c->die_sib)
22774 if (c == die->die_child)
22776 /* No marked children between 'prev' and the end of the list. */
22777 if (prev == c)
22778 /* No marked children at all. */
22779 die->die_child = NULL;
22780 else
22782 prev->die_sib = c->die_sib;
22783 die->die_child = prev;
22785 return;
22788 if (c != prev->die_sib)
22789 prev->die_sib = c;
22790 prune_unused_types_prune (c);
22791 } while (c != die->die_child);
22794 /* A helper function for dwarf2out_finish called through
22795 htab_traverse. Clear .debug_str strings that we haven't already
22796 decided to emit. */
22798 static int
22799 prune_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
22801 struct indirect_string_node *node = (struct indirect_string_node *) *h;
22803 if (!node->label || !node->refcount)
22804 htab_clear_slot (debug_str_hash, h);
22806 return 1;
22809 /* Remove dies representing declarations that we never use. */
22811 static void
22812 prune_unused_types (void)
22814 unsigned int i;
22815 limbo_die_node *node;
22816 comdat_type_node *ctnode;
22817 pubname_ref pub;
22819 #if ENABLE_ASSERT_CHECKING
22820 /* All the marks should already be clear. */
22821 verify_marks_clear (comp_unit_die ());
22822 for (node = limbo_die_list; node; node = node->next)
22823 verify_marks_clear (node->die);
22824 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22825 verify_marks_clear (ctnode->root_die);
22826 #endif /* ENABLE_ASSERT_CHECKING */
22828 /* Mark types that are used in global variables. */
22829 premark_types_used_by_global_vars ();
22831 /* Set the mark on nodes that are actually used. */
22832 prune_unused_types_walk (comp_unit_die ());
22833 for (node = limbo_die_list; node; node = node->next)
22834 prune_unused_types_walk (node->die);
22835 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22837 prune_unused_types_walk (ctnode->root_die);
22838 prune_unused_types_mark (ctnode->type_die, 1);
22841 /* Also set the mark on nodes referenced from the
22842 pubname_table. */
22843 FOR_EACH_VEC_ELT (pubname_entry, pubname_table, i, pub)
22844 prune_unused_types_mark (pub->die, 1);
22846 /* Get rid of nodes that aren't marked; and update the string counts. */
22847 if (debug_str_hash && debug_str_hash_forced)
22848 htab_traverse (debug_str_hash, prune_indirect_string, NULL);
22849 else if (debug_str_hash)
22850 htab_empty (debug_str_hash);
22851 prune_unused_types_prune (comp_unit_die ());
22852 for (node = limbo_die_list; node; node = node->next)
22853 prune_unused_types_prune (node->die);
22854 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22855 prune_unused_types_prune (ctnode->root_die);
22857 /* Leave the marks clear. */
22858 prune_unmark_dies (comp_unit_die ());
22859 for (node = limbo_die_list; node; node = node->next)
22860 prune_unmark_dies (node->die);
22861 for (ctnode = comdat_type_list; ctnode; ctnode = ctnode->next)
22862 prune_unmark_dies (ctnode->root_die);
22865 /* Set the parameter to true if there are any relative pathnames in
22866 the file table. */
22867 static int
22868 file_table_relative_p (void ** slot, void *param)
22870 bool *p = (bool *) param;
22871 struct dwarf_file_data *d = (struct dwarf_file_data *) *slot;
22872 if (!IS_ABSOLUTE_PATH (d->filename))
22874 *p = true;
22875 return 0;
22877 return 1;
22880 /* Routines to manipulate hash table of comdat type units. */
22882 static hashval_t
22883 htab_ct_hash (const void *of)
22885 hashval_t h;
22886 const comdat_type_node *const type_node = (const comdat_type_node *) of;
22888 memcpy (&h, type_node->signature, sizeof (h));
22889 return h;
22892 static int
22893 htab_ct_eq (const void *of1, const void *of2)
22895 const comdat_type_node *const type_node_1 = (const comdat_type_node *) of1;
22896 const comdat_type_node *const type_node_2 = (const comdat_type_node *) of2;
22898 return (! memcmp (type_node_1->signature, type_node_2->signature,
22899 DWARF_TYPE_SIGNATURE_SIZE));
22902 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22903 to the location it would have been added, should we know its
22904 DECL_ASSEMBLER_NAME when we added other attributes. This will
22905 probably improve compactness of debug info, removing equivalent
22906 abbrevs, and hide any differences caused by deferring the
22907 computation of the assembler name, triggered by e.g. PCH. */
22909 static inline void
22910 move_linkage_attr (dw_die_ref die)
22912 unsigned ix = VEC_length (dw_attr_node, die->die_attr);
22913 dw_attr_node linkage = *VEC_index (dw_attr_node, die->die_attr, ix - 1);
22915 gcc_assert (linkage.dw_attr == DW_AT_linkage_name
22916 || linkage.dw_attr == DW_AT_MIPS_linkage_name);
22918 while (--ix > 0)
22920 dw_attr_node *prev = VEC_index (dw_attr_node, die->die_attr, ix - 1);
22922 if (prev->dw_attr == DW_AT_decl_line || prev->dw_attr == DW_AT_name)
22923 break;
22926 if (ix != VEC_length (dw_attr_node, die->die_attr) - 1)
22928 VEC_pop (dw_attr_node, die->die_attr);
22929 VEC_quick_insert (dw_attr_node, die->die_attr, ix, &linkage);
22933 /* Helper function for resolve_addr, attempt to resolve
22934 one CONST_STRING, return non-zero if not successful. Similarly verify that
22935 SYMBOL_REFs refer to variables emitted in the current CU. */
22937 static int
22938 resolve_one_addr (rtx *addr, void *data ATTRIBUTE_UNUSED)
22940 rtx rtl = *addr;
22942 if (GET_CODE (rtl) == CONST_STRING)
22944 size_t len = strlen (XSTR (rtl, 0)) + 1;
22945 tree t = build_string (len, XSTR (rtl, 0));
22946 tree tlen = build_int_cst (NULL_TREE, len - 1);
22947 TREE_TYPE (t)
22948 = build_array_type (char_type_node, build_index_type (tlen));
22949 rtl = lookup_constant_def (t);
22950 if (!rtl || !MEM_P (rtl))
22951 return 1;
22952 rtl = XEXP (rtl, 0);
22953 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
22954 *addr = rtl;
22955 return 0;
22958 if (GET_CODE (rtl) == SYMBOL_REF
22959 && SYMBOL_REF_DECL (rtl))
22961 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl))
22963 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl))))
22964 return 1;
22966 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl)))
22967 return 1;
22970 if (GET_CODE (rtl) == CONST
22971 && for_each_rtx (&XEXP (rtl, 0), resolve_one_addr, NULL))
22972 return 1;
22974 return 0;
22977 /* Helper function for resolve_addr, handle one location
22978 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22979 the location list couldn't be resolved. */
22981 static bool
22982 resolve_addr_in_expr (dw_loc_descr_ref loc)
22984 for (; loc; loc = loc->dw_loc_next)
22985 if (((loc->dw_loc_opc == DW_OP_addr || loc->dtprel)
22986 && resolve_one_addr (&loc->dw_loc_oprnd1.v.val_addr, NULL))
22987 || (loc->dw_loc_opc == DW_OP_implicit_value
22988 && loc->dw_loc_oprnd2.val_class == dw_val_class_addr
22989 && resolve_one_addr (&loc->dw_loc_oprnd2.v.val_addr, NULL)))
22990 return false;
22991 else if (loc->dw_loc_opc == DW_OP_GNU_implicit_pointer
22992 && loc->dw_loc_oprnd1.val_class == dw_val_class_decl_ref)
22994 dw_die_ref ref
22995 = lookup_decl_die (loc->dw_loc_oprnd1.v.val_decl_ref);
22996 if (ref == NULL)
22997 return false;
22998 loc->dw_loc_oprnd1.val_class = dw_val_class_die_ref;
22999 loc->dw_loc_oprnd1.v.val_die_ref.die = ref;
23000 loc->dw_loc_oprnd1.v.val_die_ref.external = 0;
23002 return true;
23005 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23006 an address in .rodata section if the string literal is emitted there,
23007 or remove the containing location list or replace DW_AT_const_value
23008 with DW_AT_location and empty location expression, if it isn't found
23009 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23010 to something that has been emitted in the current CU. */
23012 static void
23013 resolve_addr (dw_die_ref die)
23015 dw_die_ref c;
23016 dw_attr_ref a;
23017 dw_loc_list_ref *curr, *start, loc;
23018 unsigned ix;
23020 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23021 switch (AT_class (a))
23023 case dw_val_class_loc_list:
23024 start = curr = AT_loc_list_ptr (a);
23025 loc = *curr;
23026 gcc_assert (loc);
23027 /* The same list can be referenced more than once. See if we have
23028 already recorded the result from a previous pass. */
23029 if (loc->replaced)
23030 *curr = loc->dw_loc_next;
23031 else if (!loc->resolved_addr)
23033 /* As things stand, we do not expect or allow one die to
23034 reference a suffix of another die's location list chain.
23035 References must be identical or completely separate.
23036 There is therefore no need to cache the result of this
23037 pass on any list other than the first; doing so
23038 would lead to unnecessary writes. */
23039 while (*curr)
23041 gcc_assert (!(*curr)->replaced && !(*curr)->resolved_addr);
23042 if (!resolve_addr_in_expr ((*curr)->expr))
23044 dw_loc_list_ref next = (*curr)->dw_loc_next;
23045 if (next && (*curr)->ll_symbol)
23047 gcc_assert (!next->ll_symbol);
23048 next->ll_symbol = (*curr)->ll_symbol;
23050 *curr = next;
23052 else
23053 curr = &(*curr)->dw_loc_next;
23055 if (loc == *start)
23056 loc->resolved_addr = 1;
23057 else
23059 loc->replaced = 1;
23060 loc->dw_loc_next = *start;
23063 if (!*start)
23065 remove_AT (die, a->dw_attr);
23066 ix--;
23068 break;
23069 case dw_val_class_loc:
23070 if (!resolve_addr_in_expr (AT_loc (a)))
23072 remove_AT (die, a->dw_attr);
23073 ix--;
23075 break;
23076 case dw_val_class_addr:
23077 if (a->dw_attr == DW_AT_const_value
23078 && resolve_one_addr (&a->dw_attr_val.v.val_addr, NULL))
23080 remove_AT (die, a->dw_attr);
23081 ix--;
23083 if (die->die_tag == DW_TAG_GNU_call_site
23084 && a->dw_attr == DW_AT_abstract_origin)
23086 tree tdecl = SYMBOL_REF_DECL (a->dw_attr_val.v.val_addr);
23087 dw_die_ref tdie = lookup_decl_die (tdecl);
23088 if (tdie == NULL
23089 && DECL_EXTERNAL (tdecl)
23090 && DECL_ABSTRACT_ORIGIN (tdecl) == NULL_TREE)
23092 force_decl_die (tdecl);
23093 tdie = lookup_decl_die (tdecl);
23095 if (tdie)
23097 a->dw_attr_val.val_class = dw_val_class_die_ref;
23098 a->dw_attr_val.v.val_die_ref.die = tdie;
23099 a->dw_attr_val.v.val_die_ref.external = 0;
23101 else
23103 remove_AT (die, a->dw_attr);
23104 ix--;
23107 break;
23108 default:
23109 break;
23112 FOR_EACH_CHILD (die, c, resolve_addr (c));
23115 /* Helper routines for optimize_location_lists.
23116 This pass tries to share identical local lists in .debug_loc
23117 section. */
23119 /* Iteratively hash operands of LOC opcode. */
23121 static inline hashval_t
23122 hash_loc_operands (dw_loc_descr_ref loc, hashval_t hash)
23124 dw_val_ref val1 = &loc->dw_loc_oprnd1;
23125 dw_val_ref val2 = &loc->dw_loc_oprnd2;
23127 switch (loc->dw_loc_opc)
23129 case DW_OP_const4u:
23130 case DW_OP_const8u:
23131 if (loc->dtprel)
23132 goto hash_addr;
23133 /* FALLTHRU */
23134 case DW_OP_const1u:
23135 case DW_OP_const1s:
23136 case DW_OP_const2u:
23137 case DW_OP_const2s:
23138 case DW_OP_const4s:
23139 case DW_OP_const8s:
23140 case DW_OP_constu:
23141 case DW_OP_consts:
23142 case DW_OP_pick:
23143 case DW_OP_plus_uconst:
23144 case DW_OP_breg0:
23145 case DW_OP_breg1:
23146 case DW_OP_breg2:
23147 case DW_OP_breg3:
23148 case DW_OP_breg4:
23149 case DW_OP_breg5:
23150 case DW_OP_breg6:
23151 case DW_OP_breg7:
23152 case DW_OP_breg8:
23153 case DW_OP_breg9:
23154 case DW_OP_breg10:
23155 case DW_OP_breg11:
23156 case DW_OP_breg12:
23157 case DW_OP_breg13:
23158 case DW_OP_breg14:
23159 case DW_OP_breg15:
23160 case DW_OP_breg16:
23161 case DW_OP_breg17:
23162 case DW_OP_breg18:
23163 case DW_OP_breg19:
23164 case DW_OP_breg20:
23165 case DW_OP_breg21:
23166 case DW_OP_breg22:
23167 case DW_OP_breg23:
23168 case DW_OP_breg24:
23169 case DW_OP_breg25:
23170 case DW_OP_breg26:
23171 case DW_OP_breg27:
23172 case DW_OP_breg28:
23173 case DW_OP_breg29:
23174 case DW_OP_breg30:
23175 case DW_OP_breg31:
23176 case DW_OP_regx:
23177 case DW_OP_fbreg:
23178 case DW_OP_piece:
23179 case DW_OP_deref_size:
23180 case DW_OP_xderef_size:
23181 hash = iterative_hash_object (val1->v.val_int, hash);
23182 break;
23183 case DW_OP_skip:
23184 case DW_OP_bra:
23186 int offset;
23188 gcc_assert (val1->val_class == dw_val_class_loc);
23189 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
23190 hash = iterative_hash_object (offset, hash);
23192 break;
23193 case DW_OP_implicit_value:
23194 hash = iterative_hash_object (val1->v.val_unsigned, hash);
23195 switch (val2->val_class)
23197 case dw_val_class_const:
23198 hash = iterative_hash_object (val2->v.val_int, hash);
23199 break;
23200 case dw_val_class_vec:
23202 unsigned int elt_size = val2->v.val_vec.elt_size;
23203 unsigned int len = val2->v.val_vec.length;
23205 hash = iterative_hash_object (elt_size, hash);
23206 hash = iterative_hash_object (len, hash);
23207 hash = iterative_hash (val2->v.val_vec.array,
23208 len * elt_size, hash);
23210 break;
23211 case dw_val_class_const_double:
23212 hash = iterative_hash_object (val2->v.val_double.low, hash);
23213 hash = iterative_hash_object (val2->v.val_double.high, hash);
23214 break;
23215 case dw_val_class_addr:
23216 hash = iterative_hash_rtx (val2->v.val_addr, hash);
23217 break;
23218 default:
23219 gcc_unreachable ();
23221 break;
23222 case DW_OP_bregx:
23223 case DW_OP_bit_piece:
23224 hash = iterative_hash_object (val1->v.val_int, hash);
23225 hash = iterative_hash_object (val2->v.val_int, hash);
23226 break;
23227 case DW_OP_addr:
23228 hash_addr:
23229 if (loc->dtprel)
23231 unsigned char dtprel = 0xd1;
23232 hash = iterative_hash_object (dtprel, hash);
23234 hash = iterative_hash_rtx (val1->v.val_addr, hash);
23235 break;
23236 case DW_OP_GNU_implicit_pointer:
23237 hash = iterative_hash_object (val2->v.val_int, hash);
23238 break;
23239 case DW_OP_GNU_entry_value:
23240 hash = hash_loc_operands (val1->v.val_loc, hash);
23241 break;
23243 default:
23244 /* Other codes have no operands. */
23245 break;
23247 return hash;
23250 /* Iteratively hash the whole DWARF location expression LOC. */
23252 static inline hashval_t
23253 hash_locs (dw_loc_descr_ref loc, hashval_t hash)
23255 dw_loc_descr_ref l;
23256 bool sizes_computed = false;
23257 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23258 size_of_locs (loc);
23260 for (l = loc; l != NULL; l = l->dw_loc_next)
23262 enum dwarf_location_atom opc = l->dw_loc_opc;
23263 hash = iterative_hash_object (opc, hash);
23264 if ((opc == DW_OP_skip || opc == DW_OP_bra) && !sizes_computed)
23266 size_of_locs (loc);
23267 sizes_computed = true;
23269 hash = hash_loc_operands (l, hash);
23271 return hash;
23274 /* Compute hash of the whole location list LIST_HEAD. */
23276 static inline void
23277 hash_loc_list (dw_loc_list_ref list_head)
23279 dw_loc_list_ref curr = list_head;
23280 hashval_t hash = 0;
23282 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
23284 hash = iterative_hash (curr->begin, strlen (curr->begin) + 1, hash);
23285 hash = iterative_hash (curr->end, strlen (curr->end) + 1, hash);
23286 if (curr->section)
23287 hash = iterative_hash (curr->section, strlen (curr->section) + 1,
23288 hash);
23289 hash = hash_locs (curr->expr, hash);
23291 list_head->hash = hash;
23294 /* Return true if X and Y opcodes have the same operands. */
23296 static inline bool
23297 compare_loc_operands (dw_loc_descr_ref x, dw_loc_descr_ref y)
23299 dw_val_ref valx1 = &x->dw_loc_oprnd1;
23300 dw_val_ref valx2 = &x->dw_loc_oprnd2;
23301 dw_val_ref valy1 = &y->dw_loc_oprnd1;
23302 dw_val_ref valy2 = &y->dw_loc_oprnd2;
23304 switch (x->dw_loc_opc)
23306 case DW_OP_const4u:
23307 case DW_OP_const8u:
23308 if (x->dtprel)
23309 goto hash_addr;
23310 /* FALLTHRU */
23311 case DW_OP_const1u:
23312 case DW_OP_const1s:
23313 case DW_OP_const2u:
23314 case DW_OP_const2s:
23315 case DW_OP_const4s:
23316 case DW_OP_const8s:
23317 case DW_OP_constu:
23318 case DW_OP_consts:
23319 case DW_OP_pick:
23320 case DW_OP_plus_uconst:
23321 case DW_OP_breg0:
23322 case DW_OP_breg1:
23323 case DW_OP_breg2:
23324 case DW_OP_breg3:
23325 case DW_OP_breg4:
23326 case DW_OP_breg5:
23327 case DW_OP_breg6:
23328 case DW_OP_breg7:
23329 case DW_OP_breg8:
23330 case DW_OP_breg9:
23331 case DW_OP_breg10:
23332 case DW_OP_breg11:
23333 case DW_OP_breg12:
23334 case DW_OP_breg13:
23335 case DW_OP_breg14:
23336 case DW_OP_breg15:
23337 case DW_OP_breg16:
23338 case DW_OP_breg17:
23339 case DW_OP_breg18:
23340 case DW_OP_breg19:
23341 case DW_OP_breg20:
23342 case DW_OP_breg21:
23343 case DW_OP_breg22:
23344 case DW_OP_breg23:
23345 case DW_OP_breg24:
23346 case DW_OP_breg25:
23347 case DW_OP_breg26:
23348 case DW_OP_breg27:
23349 case DW_OP_breg28:
23350 case DW_OP_breg29:
23351 case DW_OP_breg30:
23352 case DW_OP_breg31:
23353 case DW_OP_regx:
23354 case DW_OP_fbreg:
23355 case DW_OP_piece:
23356 case DW_OP_deref_size:
23357 case DW_OP_xderef_size:
23358 return valx1->v.val_int == valy1->v.val_int;
23359 case DW_OP_skip:
23360 case DW_OP_bra:
23361 gcc_assert (valx1->val_class == dw_val_class_loc
23362 && valy1->val_class == dw_val_class_loc
23363 && x->dw_loc_addr == y->dw_loc_addr);
23364 return valx1->v.val_loc->dw_loc_addr == valy1->v.val_loc->dw_loc_addr;
23365 case DW_OP_implicit_value:
23366 if (valx1->v.val_unsigned != valy1->v.val_unsigned
23367 || valx2->val_class != valy2->val_class)
23368 return false;
23369 switch (valx2->val_class)
23371 case dw_val_class_const:
23372 return valx2->v.val_int == valy2->v.val_int;
23373 case dw_val_class_vec:
23374 return valx2->v.val_vec.elt_size == valy2->v.val_vec.elt_size
23375 && valx2->v.val_vec.length == valy2->v.val_vec.length
23376 && memcmp (valx2->v.val_vec.array, valy2->v.val_vec.array,
23377 valx2->v.val_vec.elt_size
23378 * valx2->v.val_vec.length) == 0;
23379 case dw_val_class_const_double:
23380 return valx2->v.val_double.low == valy2->v.val_double.low
23381 && valx2->v.val_double.high == valy2->v.val_double.high;
23382 case dw_val_class_addr:
23383 return rtx_equal_p (valx2->v.val_addr, valy2->v.val_addr);
23384 default:
23385 gcc_unreachable ();
23387 case DW_OP_bregx:
23388 case DW_OP_bit_piece:
23389 return valx1->v.val_int == valy1->v.val_int
23390 && valx2->v.val_int == valy2->v.val_int;
23391 case DW_OP_addr:
23392 hash_addr:
23393 return rtx_equal_p (valx1->v.val_addr, valy1->v.val_addr);
23394 case DW_OP_GNU_implicit_pointer:
23395 return valx1->val_class == dw_val_class_die_ref
23396 && valx1->val_class == valy1->val_class
23397 && valx1->v.val_die_ref.die == valy1->v.val_die_ref.die
23398 && valx2->v.val_int == valy2->v.val_int;
23399 case DW_OP_GNU_entry_value:
23400 return compare_loc_operands (valx1->v.val_loc, valy1->v.val_loc);
23401 default:
23402 /* Other codes have no operands. */
23403 return true;
23407 /* Return true if DWARF location expressions X and Y are the same. */
23409 static inline bool
23410 compare_locs (dw_loc_descr_ref x, dw_loc_descr_ref y)
23412 for (; x != NULL && y != NULL; x = x->dw_loc_next, y = y->dw_loc_next)
23413 if (x->dw_loc_opc != y->dw_loc_opc
23414 || x->dtprel != y->dtprel
23415 || !compare_loc_operands (x, y))
23416 break;
23417 return x == NULL && y == NULL;
23420 /* Return precomputed hash of location list X. */
23422 static hashval_t
23423 loc_list_hash (const void *x)
23425 return ((const struct dw_loc_list_struct *) x)->hash;
23428 /* Return 1 if location lists X and Y are the same. */
23430 static int
23431 loc_list_eq (const void *x, const void *y)
23433 const struct dw_loc_list_struct *a = (const struct dw_loc_list_struct *) x;
23434 const struct dw_loc_list_struct *b = (const struct dw_loc_list_struct *) y;
23435 if (a == b)
23436 return 1;
23437 if (a->hash != b->hash)
23438 return 0;
23439 for (; a != NULL && b != NULL; a = a->dw_loc_next, b = b->dw_loc_next)
23440 if (strcmp (a->begin, b->begin) != 0
23441 || strcmp (a->end, b->end) != 0
23442 || (a->section == NULL) != (b->section == NULL)
23443 || (a->section && strcmp (a->section, b->section) != 0)
23444 || !compare_locs (a->expr, b->expr))
23445 break;
23446 return a == NULL && b == NULL;
23449 /* Recursively optimize location lists referenced from DIE
23450 children and share them whenever possible. */
23452 static void
23453 optimize_location_lists_1 (dw_die_ref die, htab_t htab)
23455 dw_die_ref c;
23456 dw_attr_ref a;
23457 unsigned ix;
23458 void **slot;
23460 FOR_EACH_VEC_ELT (dw_attr_node, die->die_attr, ix, a)
23461 if (AT_class (a) == dw_val_class_loc_list)
23463 dw_loc_list_ref list = AT_loc_list (a);
23464 /* TODO: perform some optimizations here, before hashing
23465 it and storing into the hash table. */
23466 hash_loc_list (list);
23467 slot = htab_find_slot_with_hash (htab, list, list->hash,
23468 INSERT);
23469 if (*slot == NULL)
23470 *slot = (void *) list;
23471 else
23472 a->dw_attr_val.v.val_loc_list = (dw_loc_list_ref) *slot;
23475 FOR_EACH_CHILD (die, c, optimize_location_lists_1 (c, htab));
23478 /* Optimize location lists referenced from DIE
23479 children and share them whenever possible. */
23481 static void
23482 optimize_location_lists (dw_die_ref die)
23484 htab_t htab = htab_create (500, loc_list_hash, loc_list_eq, NULL);
23485 optimize_location_lists_1 (die, htab);
23486 htab_delete (htab);
23489 /* Output stuff that dwarf requires at the end of every file,
23490 and generate the DWARF-2 debugging info. */
23492 static void
23493 dwarf2out_finish (const char *filename)
23495 limbo_die_node *node, *next_node;
23496 comdat_type_node *ctnode;
23497 htab_t comdat_type_table;
23498 unsigned int i;
23500 gen_scheduled_generic_parms_dies ();
23501 gen_remaining_tmpl_value_param_die_attribute ();
23503 /* Add the name for the main input file now. We delayed this from
23504 dwarf2out_init to avoid complications with PCH. */
23505 add_name_attribute (comp_unit_die (), remap_debug_filename (filename));
23506 if (!IS_ABSOLUTE_PATH (filename))
23507 add_comp_dir_attribute (comp_unit_die ());
23508 else if (get_AT (comp_unit_die (), DW_AT_comp_dir) == NULL)
23510 bool p = false;
23511 htab_traverse (file_table, file_table_relative_p, &p);
23512 if (p)
23513 add_comp_dir_attribute (comp_unit_die ());
23516 for (i = 0; i < VEC_length (deferred_locations, deferred_locations_list); i++)
23518 add_location_or_const_value_attribute (
23519 VEC_index (deferred_locations, deferred_locations_list, i)->die,
23520 VEC_index (deferred_locations, deferred_locations_list, i)->variable,
23521 false,
23522 DW_AT_location);
23525 /* Traverse the limbo die list, and add parent/child links. The only
23526 dies without parents that should be here are concrete instances of
23527 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23528 For concrete instances, we can get the parent die from the abstract
23529 instance. */
23530 for (node = limbo_die_list; node; node = next_node)
23532 dw_die_ref die = node->die;
23533 next_node = node->next;
23535 if (die->die_parent == NULL)
23537 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
23539 if (origin)
23540 add_child_die (origin->die_parent, die);
23541 else if (is_cu_die (die))
23543 else if (seen_error ())
23544 /* It's OK to be confused by errors in the input. */
23545 add_child_die (comp_unit_die (), die);
23546 else
23548 /* In certain situations, the lexical block containing a
23549 nested function can be optimized away, which results
23550 in the nested function die being orphaned. Likewise
23551 with the return type of that nested function. Force
23552 this to be a child of the containing function.
23554 It may happen that even the containing function got fully
23555 inlined and optimized out. In that case we are lost and
23556 assign the empty child. This should not be big issue as
23557 the function is likely unreachable too. */
23558 tree context = NULL_TREE;
23560 gcc_assert (node->created_for);
23562 if (DECL_P (node->created_for))
23563 context = DECL_CONTEXT (node->created_for);
23564 else if (TYPE_P (node->created_for))
23565 context = TYPE_CONTEXT (node->created_for);
23567 gcc_assert (context
23568 && (TREE_CODE (context) == FUNCTION_DECL
23569 || TREE_CODE (context) == NAMESPACE_DECL));
23571 origin = lookup_decl_die (context);
23572 if (origin)
23573 add_child_die (origin, die);
23574 else
23575 add_child_die (comp_unit_die (), die);
23580 limbo_die_list = NULL;
23582 resolve_addr (comp_unit_die ());
23584 for (node = deferred_asm_name; node; node = node->next)
23586 tree decl = node->created_for;
23587 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
23589 add_linkage_attr (node->die, decl);
23590 move_linkage_attr (node->die);
23594 deferred_asm_name = NULL;
23596 /* Walk through the list of incomplete types again, trying once more to
23597 emit full debugging info for them. */
23598 retry_incomplete_types ();
23600 if (flag_eliminate_unused_debug_types)
23601 prune_unused_types ();
23603 /* Generate separate CUs for each of the include files we've seen.
23604 They will go into limbo_die_list. */
23605 if (flag_eliminate_dwarf2_dups && ! use_debug_types)
23606 break_out_includes (comp_unit_die ());
23608 /* Generate separate COMDAT sections for type DIEs. */
23609 if (use_debug_types)
23611 break_out_comdat_types (comp_unit_die ());
23613 /* Each new type_unit DIE was added to the limbo die list when created.
23614 Since these have all been added to comdat_type_list, clear the
23615 limbo die list. */
23616 limbo_die_list = NULL;
23618 /* For each new comdat type unit, copy declarations for incomplete
23619 types to make the new unit self-contained (i.e., no direct
23620 references to the main compile unit). */
23621 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23622 copy_decls_for_unworthy_types (ctnode->root_die);
23623 copy_decls_for_unworthy_types (comp_unit_die ());
23625 /* In the process of copying declarations from one unit to another,
23626 we may have left some declarations behind that are no longer
23627 referenced. Prune them. */
23628 prune_unused_types ();
23631 /* Traverse the DIE's and add add sibling attributes to those DIE's
23632 that have children. */
23633 add_sibling_attributes (comp_unit_die ());
23634 for (node = limbo_die_list; node; node = node->next)
23635 add_sibling_attributes (node->die);
23636 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23637 add_sibling_attributes (ctnode->root_die);
23639 /* Output a terminator label for the .text section. */
23640 switch_to_section (text_section);
23641 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
23642 if (cold_text_section)
23644 switch_to_section (cold_text_section);
23645 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
23648 /* We can only use the low/high_pc attributes if all of the code was
23649 in .text. */
23650 if (!have_multiple_function_sections
23651 || (dwarf_version < 3 && dwarf_strict))
23653 /* Don't add if the CU has no associated code. */
23654 if (text_section_used)
23656 add_AT_lbl_id (comp_unit_die (), DW_AT_low_pc, text_section_label);
23657 add_AT_lbl_id (comp_unit_die (), DW_AT_high_pc, text_end_label);
23660 else
23662 unsigned fde_idx = 0;
23663 bool range_list_added = false;
23665 if (text_section_used)
23666 add_ranges_by_labels (comp_unit_die (), text_section_label,
23667 text_end_label, &range_list_added);
23668 if (cold_text_section_used)
23669 add_ranges_by_labels (comp_unit_die (), cold_text_section_label,
23670 cold_end_label, &range_list_added);
23672 for (fde_idx = 0; fde_idx < fde_table_in_use; fde_idx++)
23674 dw_fde_ref fde = &fde_table[fde_idx];
23676 if (!fde->in_std_section)
23677 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_begin,
23678 fde->dw_fde_end, &range_list_added);
23679 if (fde->dw_fde_second_begin && !fde->second_in_std_section)
23680 add_ranges_by_labels (comp_unit_die (), fde->dw_fde_second_begin,
23681 fde->dw_fde_second_end, &range_list_added);
23684 if (range_list_added)
23686 /* We need to give .debug_loc and .debug_ranges an appropriate
23687 "base address". Use zero so that these addresses become
23688 absolute. Historically, we've emitted the unexpected
23689 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23690 Emit both to give time for other tools to adapt. */
23691 add_AT_addr (comp_unit_die (), DW_AT_low_pc, const0_rtx);
23692 if (! dwarf_strict && dwarf_version < 4)
23693 add_AT_addr (comp_unit_die (), DW_AT_entry_pc, const0_rtx);
23695 add_ranges (NULL);
23699 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23700 add_AT_lineptr (comp_unit_die (), DW_AT_stmt_list,
23701 debug_line_section_label);
23703 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23704 add_AT_macptr (comp_unit_die (), DW_AT_macro_info, macinfo_section_label);
23706 if (have_location_lists)
23707 optimize_location_lists (comp_unit_die ());
23709 /* Output all of the compilation units. We put the main one last so that
23710 the offsets are available to output_pubnames. */
23711 for (node = limbo_die_list; node; node = node->next)
23712 output_comp_unit (node->die, 0);
23714 comdat_type_table = htab_create (100, htab_ct_hash, htab_ct_eq, NULL);
23715 for (ctnode = comdat_type_list; ctnode != NULL; ctnode = ctnode->next)
23717 void **slot = htab_find_slot (comdat_type_table, ctnode, INSERT);
23719 /* Don't output duplicate types. */
23720 if (*slot != HTAB_EMPTY_ENTRY)
23721 continue;
23723 /* Add a pointer to the line table for the main compilation unit
23724 so that the debugger can make sense of DW_AT_decl_file
23725 attributes. */
23726 if (debug_info_level >= DINFO_LEVEL_NORMAL)
23727 add_AT_lineptr (ctnode->root_die, DW_AT_stmt_list,
23728 debug_line_section_label);
23730 output_comdat_type_unit (ctnode);
23731 *slot = ctnode;
23733 htab_delete (comdat_type_table);
23735 /* Output the main compilation unit if non-empty or if .debug_macinfo
23736 will be emitted. */
23737 output_comp_unit (comp_unit_die (), debug_info_level >= DINFO_LEVEL_VERBOSE);
23739 /* Output the abbreviation table. */
23740 switch_to_section (debug_abbrev_section);
23741 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
23742 output_abbrev_section ();
23744 /* Output location list section if necessary. */
23745 if (have_location_lists)
23747 /* Output the location lists info. */
23748 switch_to_section (debug_loc_section);
23749 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
23750 DEBUG_LOC_SECTION_LABEL, 0);
23751 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
23752 output_location_lists (comp_unit_die ());
23755 /* Output public names table if necessary. */
23756 if (!VEC_empty (pubname_entry, pubname_table))
23758 gcc_assert (info_section_emitted);
23759 switch_to_section (debug_pubnames_section);
23760 output_pubnames (pubname_table);
23763 /* Output public types table if necessary. */
23764 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23765 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23766 simply won't look for the section. */
23767 if (!VEC_empty (pubname_entry, pubtype_table))
23769 bool empty = false;
23771 if (flag_eliminate_unused_debug_types)
23773 /* The pubtypes table might be emptied by pruning unused items. */
23774 unsigned i;
23775 pubname_ref p;
23776 empty = true;
23777 FOR_EACH_VEC_ELT (pubname_entry, pubtype_table, i, p)
23778 if (p->die->die_offset != 0)
23780 empty = false;
23781 break;
23784 if (!empty)
23786 gcc_assert (info_section_emitted);
23787 switch_to_section (debug_pubtypes_section);
23788 output_pubnames (pubtype_table);
23792 /* Output the address range information. We only put functions in the
23793 arange table, so don't write it out if we don't have any. */
23794 if (info_section_emitted)
23796 unsigned long aranges_length = size_of_aranges ();
23798 /* Empty .debug_aranges would contain just header and
23799 terminating 0,0. */
23800 if (aranges_length
23801 != (unsigned long) (DWARF_ARANGES_HEADER_SIZE
23802 + 2 * DWARF2_ADDR_SIZE))
23804 switch_to_section (debug_aranges_section);
23805 output_aranges (aranges_length);
23809 /* Output ranges section if necessary. */
23810 if (ranges_table_in_use)
23812 switch_to_section (debug_ranges_section);
23813 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
23814 output_ranges ();
23817 /* Output the source line correspondence table. We must do this
23818 even if there is no line information. Otherwise, on an empty
23819 translation unit, we will generate a present, but empty,
23820 .debug_info section. IRIX 6.5 `nm' will then complain when
23821 examining the file. This is done late so that any filenames
23822 used by the debug_info section are marked as 'used'. */
23823 switch_to_section (debug_line_section);
23824 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
23825 if (! DWARF2_ASM_LINE_DEBUG_INFO)
23826 output_line_info ();
23828 /* Have to end the macro section. */
23829 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
23831 switch_to_section (debug_macinfo_section);
23832 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
23833 if (!VEC_empty (macinfo_entry, macinfo_table))
23834 output_macinfo ();
23835 dw2_asm_output_data (1, 0, "End compilation unit");
23838 /* If we emitted any DW_FORM_strp form attribute, output the string
23839 table too. */
23840 if (debug_str_hash)
23841 htab_traverse (debug_str_hash, output_indirect_string, NULL);
23844 #include "gt-dwarf2out.h"