* sh.c (sh_gimplify_va_arg_expr): Don't substitute a RECORD_TYPE
[official-gcc.git] / gcc / dwarf2out.c
blob2dc03f4d0e6c5e92b5135d6d24dd0024d02bb9a8
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 Free Software Foundation, Inc.
4 Contributed by Gary Funck (gary@intrepid.com).
5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
6 Extensively modified by Jason Merrill (jason@cygnus.com).
8 This file is part of GCC.
10 GCC is free software; you can redistribute it and/or modify it under
11 the terms of the GNU General Public License as published by the Free
12 Software Foundation; either version 2, or (at your option) any later
13 version.
15 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 for more details.
20 You should have received a copy of the GNU General Public License
21 along with GCC; see the file COPYING. If not, write to the Free
22 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
23 02110-1301, USA. */
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 #include "config.h"
38 #include "system.h"
39 #include "coretypes.h"
40 #include "tm.h"
41 #include "tree.h"
42 #include "version.h"
43 #include "flags.h"
44 #include "real.h"
45 #include "rtl.h"
46 #include "hard-reg-set.h"
47 #include "regs.h"
48 #include "insn-config.h"
49 #include "reload.h"
50 #include "function.h"
51 #include "output.h"
52 #include "expr.h"
53 #include "libfuncs.h"
54 #include "except.h"
55 #include "dwarf2.h"
56 #include "dwarf2out.h"
57 #include "dwarf2asm.h"
58 #include "toplev.h"
59 #include "varray.h"
60 #include "ggc.h"
61 #include "md5.h"
62 #include "tm_p.h"
63 #include "diagnostic.h"
64 #include "debug.h"
65 #include "target.h"
66 #include "langhooks.h"
67 #include "hashtab.h"
68 #include "cgraph.h"
69 #include "input.h"
71 #ifdef DWARF2_DEBUGGING_INFO
72 static void dwarf2out_source_line (unsigned int, const char *);
73 #endif
75 /* DWARF2 Abbreviation Glossary:
76 CFA = Canonical Frame Address
77 a fixed address on the stack which identifies a call frame.
78 We define it to be the value of SP just before the call insn.
79 The CFA register and offset, which may change during the course
80 of the function, are used to calculate its value at runtime.
81 CFI = Call Frame Instruction
82 an instruction for the DWARF2 abstract machine
83 CIE = Common Information Entry
84 information describing information common to one or more FDEs
85 DIE = Debugging Information Entry
86 FDE = Frame Description Entry
87 information describing the stack call frame, in particular,
88 how to restore registers
90 DW_CFA_... = DWARF2 CFA call frame instruction
91 DW_TAG_... = DWARF2 DIE tag */
93 /* Decide whether we want to emit frame unwind information for the current
94 translation unit. */
96 int
97 dwarf2out_do_frame (void)
99 return (write_symbols == DWARF2_DEBUG
100 || write_symbols == VMS_AND_DWARF2_DEBUG
101 #ifdef DWARF2_FRAME_INFO
102 || DWARF2_FRAME_INFO
103 #endif
104 #ifdef DWARF2_UNWIND_INFO
105 || flag_unwind_tables
106 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
107 #endif
111 /* The size of the target's pointer type. */
112 #ifndef PTR_SIZE
113 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
114 #endif
116 /* Various versions of targetm.eh_frame_section. Note these must appear
117 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro guards. */
119 /* Version of targetm.eh_frame_section for systems with named sections. */
120 void
121 named_section_eh_frame_section (void)
123 #ifdef EH_FRAME_SECTION_NAME
124 int flags;
126 if (EH_TABLES_CAN_BE_READ_ONLY)
128 int fde_encoding;
129 int per_encoding;
130 int lsda_encoding;
132 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
133 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
134 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
135 flags = (! flag_pic
136 || ((fde_encoding & 0x70) != DW_EH_PE_absptr
137 && (fde_encoding & 0x70) != DW_EH_PE_aligned
138 && (per_encoding & 0x70) != DW_EH_PE_absptr
139 && (per_encoding & 0x70) != DW_EH_PE_aligned
140 && (lsda_encoding & 0x70) != DW_EH_PE_absptr
141 && (lsda_encoding & 0x70) != DW_EH_PE_aligned))
142 ? 0 : SECTION_WRITE;
144 else
145 flags = SECTION_WRITE;
146 named_section_flags (EH_FRAME_SECTION_NAME, flags);
147 #endif
150 /* Version of targetm.eh_frame_section for systems using collect2. */
151 void
152 collect2_eh_frame_section (void)
154 tree label = get_file_function_name ('F');
156 data_section ();
157 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
158 targetm.asm_out.globalize_label (asm_out_file, IDENTIFIER_POINTER (label));
159 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
162 /* Default version of targetm.eh_frame_section. */
163 void
164 default_eh_frame_section (void)
166 #ifdef EH_FRAME_SECTION_NAME
167 named_section_eh_frame_section ();
168 #else
169 collect2_eh_frame_section ();
170 #endif
173 DEF_VEC_P(rtx);
174 DEF_VEC_ALLOC_P(rtx,gc);
176 /* Array of RTXes referenced by the debugging information, which therefore
177 must be kept around forever. */
178 static GTY(()) VEC(rtx,gc) *used_rtx_array;
180 /* A pointer to the base of a list of incomplete types which might be
181 completed at some later time. incomplete_types_list needs to be a
182 VEC(tree,gc) because we want to tell the garbage collector about
183 it. */
184 static GTY(()) VEC(tree,gc) *incomplete_types;
186 /* A pointer to the base of a table of references to declaration
187 scopes. This table is a display which tracks the nesting
188 of declaration scopes at the current scope and containing
189 scopes. This table is used to find the proper place to
190 define type declaration DIE's. */
191 static GTY(()) VEC(tree,gc) *decl_scope_table;
193 /* How to start an assembler comment. */
194 #ifndef ASM_COMMENT_START
195 #define ASM_COMMENT_START ";#"
196 #endif
198 typedef struct dw_cfi_struct *dw_cfi_ref;
199 typedef struct dw_fde_struct *dw_fde_ref;
200 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
202 /* Call frames are described using a sequence of Call Frame
203 Information instructions. The register number, offset
204 and address fields are provided as possible operands;
205 their use is selected by the opcode field. */
207 enum dw_cfi_oprnd_type {
208 dw_cfi_oprnd_unused,
209 dw_cfi_oprnd_reg_num,
210 dw_cfi_oprnd_offset,
211 dw_cfi_oprnd_addr,
212 dw_cfi_oprnd_loc
215 typedef union dw_cfi_oprnd_struct GTY(())
217 unsigned long GTY ((tag ("dw_cfi_oprnd_reg_num"))) dw_cfi_reg_num;
218 HOST_WIDE_INT GTY ((tag ("dw_cfi_oprnd_offset"))) dw_cfi_offset;
219 const char * GTY ((tag ("dw_cfi_oprnd_addr"))) dw_cfi_addr;
220 struct dw_loc_descr_struct * GTY ((tag ("dw_cfi_oprnd_loc"))) dw_cfi_loc;
222 dw_cfi_oprnd;
224 typedef struct dw_cfi_struct GTY(())
226 dw_cfi_ref dw_cfi_next;
227 enum dwarf_call_frame_info dw_cfi_opc;
228 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd1_desc (%1.dw_cfi_opc)")))
229 dw_cfi_oprnd1;
230 dw_cfi_oprnd GTY ((desc ("dw_cfi_oprnd2_desc (%1.dw_cfi_opc)")))
231 dw_cfi_oprnd2;
233 dw_cfi_node;
235 /* This is how we define the location of the CFA. We use to handle it
236 as REG + OFFSET all the time, but now it can be more complex.
237 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
238 Instead of passing around REG and OFFSET, we pass a copy
239 of this structure. */
240 typedef struct cfa_loc GTY(())
242 unsigned long reg;
243 HOST_WIDE_INT offset;
244 HOST_WIDE_INT base_offset;
245 int indirect; /* 1 if CFA is accessed via a dereference. */
246 } dw_cfa_location;
248 /* All call frame descriptions (FDE's) in the GCC generated DWARF
249 refer to a single Common Information Entry (CIE), defined at
250 the beginning of the .debug_frame section. This use of a single
251 CIE obviates the need to keep track of multiple CIE's
252 in the DWARF generation routines below. */
254 typedef struct dw_fde_struct GTY(())
256 tree decl;
257 const char *dw_fde_begin;
258 const char *dw_fde_current_label;
259 const char *dw_fde_end;
260 const char *dw_fde_hot_section_label;
261 const char *dw_fde_hot_section_end_label;
262 const char *dw_fde_unlikely_section_label;
263 const char *dw_fde_unlikely_section_end_label;
264 bool dw_fde_switched_sections;
265 dw_cfi_ref dw_fde_cfi;
266 unsigned funcdef_number;
267 unsigned all_throwers_are_sibcalls : 1;
268 unsigned nothrow : 1;
269 unsigned uses_eh_lsda : 1;
271 dw_fde_node;
273 /* Maximum size (in bytes) of an artificially generated label. */
274 #define MAX_ARTIFICIAL_LABEL_BYTES 30
276 /* The size of addresses as they appear in the Dwarf 2 data.
277 Some architectures use word addresses to refer to code locations,
278 but Dwarf 2 info always uses byte addresses. On such machines,
279 Dwarf 2 addresses need to be larger than the architecture's
280 pointers. */
281 #ifndef DWARF2_ADDR_SIZE
282 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
283 #endif
285 /* The size in bytes of a DWARF field indicating an offset or length
286 relative to a debug info section, specified to be 4 bytes in the
287 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
288 as PTR_SIZE. */
290 #ifndef DWARF_OFFSET_SIZE
291 #define DWARF_OFFSET_SIZE 4
292 #endif
294 /* According to the (draft) DWARF 3 specification, the initial length
295 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
296 bytes are 0xffffffff, followed by the length stored in the next 8
297 bytes.
299 However, the SGI/MIPS ABI uses an initial length which is equal to
300 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
302 #ifndef DWARF_INITIAL_LENGTH_SIZE
303 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
304 #endif
306 #define DWARF_VERSION 2
308 /* Round SIZE up to the nearest BOUNDARY. */
309 #define DWARF_ROUND(SIZE,BOUNDARY) \
310 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
312 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
313 #ifndef DWARF_CIE_DATA_ALIGNMENT
314 #ifdef STACK_GROWS_DOWNWARD
315 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
316 #else
317 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
318 #endif
319 #endif
321 /* A pointer to the base of a table that contains frame description
322 information for each routine. */
323 static GTY((length ("fde_table_allocated"))) dw_fde_ref fde_table;
325 /* Number of elements currently allocated for fde_table. */
326 static GTY(()) unsigned fde_table_allocated;
328 /* Number of elements in fde_table currently in use. */
329 static GTY(()) unsigned fde_table_in_use;
331 /* Size (in elements) of increments by which we may expand the
332 fde_table. */
333 #define FDE_TABLE_INCREMENT 256
335 /* A list of call frame insns for the CIE. */
336 static GTY(()) dw_cfi_ref cie_cfi_head;
338 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
339 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
340 attribute that accelerates the lookup of the FDE associated
341 with the subprogram. This variable holds the table index of the FDE
342 associated with the current function (body) definition. */
343 static unsigned current_funcdef_fde;
344 #endif
346 struct indirect_string_node GTY(())
348 const char *str;
349 unsigned int refcount;
350 unsigned int form;
351 char *label;
354 static GTY ((param_is (struct indirect_string_node))) htab_t debug_str_hash;
356 static GTY(()) int dw2_string_counter;
357 static GTY(()) unsigned long dwarf2out_cfi_label_num;
359 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
361 /* Forward declarations for functions defined in this file. */
363 static char *stripattributes (const char *);
364 static const char *dwarf_cfi_name (unsigned);
365 static dw_cfi_ref new_cfi (void);
366 static void add_cfi (dw_cfi_ref *, dw_cfi_ref);
367 static void add_fde_cfi (const char *, dw_cfi_ref);
368 static void lookup_cfa_1 (dw_cfi_ref, dw_cfa_location *);
369 static void lookup_cfa (dw_cfa_location *);
370 static void reg_save (const char *, unsigned, unsigned, HOST_WIDE_INT);
371 static void initial_return_save (rtx);
372 static HOST_WIDE_INT stack_adjust_offset (rtx);
373 static void output_cfi (dw_cfi_ref, dw_fde_ref, int);
374 static void output_call_frame_info (int);
375 static void dwarf2out_stack_adjust (rtx, bool);
376 static void flush_queued_reg_saves (void);
377 static bool clobbers_queued_reg_save (rtx);
378 static void dwarf2out_frame_debug_expr (rtx, const char *);
380 /* Support for complex CFA locations. */
381 static void output_cfa_loc (dw_cfi_ref);
382 static void get_cfa_from_loc_descr (dw_cfa_location *,
383 struct dw_loc_descr_struct *);
384 static struct dw_loc_descr_struct *build_cfa_loc
385 (dw_cfa_location *);
386 static void def_cfa_1 (const char *, dw_cfa_location *);
388 /* How to start an assembler comment. */
389 #ifndef ASM_COMMENT_START
390 #define ASM_COMMENT_START ";#"
391 #endif
393 /* Data and reference forms for relocatable data. */
394 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
395 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
397 #ifndef DEBUG_FRAME_SECTION
398 #define DEBUG_FRAME_SECTION ".debug_frame"
399 #endif
401 #ifndef FUNC_BEGIN_LABEL
402 #define FUNC_BEGIN_LABEL "LFB"
403 #endif
405 #ifndef FUNC_END_LABEL
406 #define FUNC_END_LABEL "LFE"
407 #endif
409 #ifndef FRAME_BEGIN_LABEL
410 #define FRAME_BEGIN_LABEL "Lframe"
411 #endif
412 #define CIE_AFTER_SIZE_LABEL "LSCIE"
413 #define CIE_END_LABEL "LECIE"
414 #define FDE_LABEL "LSFDE"
415 #define FDE_AFTER_SIZE_LABEL "LASFDE"
416 #define FDE_END_LABEL "LEFDE"
417 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
418 #define LINE_NUMBER_END_LABEL "LELT"
419 #define LN_PROLOG_AS_LABEL "LASLTP"
420 #define LN_PROLOG_END_LABEL "LELTP"
421 #define DIE_LABEL_PREFIX "DW"
423 /* The DWARF 2 CFA column which tracks the return address. Normally this
424 is the column for PC, or the first column after all of the hard
425 registers. */
426 #ifndef DWARF_FRAME_RETURN_COLUMN
427 #ifdef PC_REGNUM
428 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
429 #else
430 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
431 #endif
432 #endif
434 /* The mapping from gcc register number to DWARF 2 CFA column number. By
435 default, we just provide columns for all registers. */
436 #ifndef DWARF_FRAME_REGNUM
437 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
438 #endif
440 /* The offset from the incoming value of %sp to the top of the stack frame
441 for the current function. */
442 #ifndef INCOMING_FRAME_SP_OFFSET
443 #define INCOMING_FRAME_SP_OFFSET 0
444 #endif
446 /* Hook used by __throw. */
449 expand_builtin_dwarf_sp_column (void)
451 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
454 /* Return a pointer to a copy of the section string name S with all
455 attributes stripped off, and an asterisk prepended (for assemble_name). */
457 static inline char *
458 stripattributes (const char *s)
460 char *stripped = xmalloc (strlen (s) + 2);
461 char *p = stripped;
463 *p++ = '*';
465 while (*s && *s != ',')
466 *p++ = *s++;
468 *p = '\0';
469 return stripped;
472 /* Generate code to initialize the register size table. */
474 void
475 expand_builtin_init_dwarf_reg_sizes (tree address)
477 int i;
478 enum machine_mode mode = TYPE_MODE (char_type_node);
479 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
480 rtx mem = gen_rtx_MEM (BLKmode, addr);
481 bool wrote_return_column = false;
483 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
484 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
486 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
487 enum machine_mode save_mode = reg_raw_mode[i];
488 HOST_WIDE_INT size;
490 if (HARD_REGNO_CALL_PART_CLOBBERED (i, save_mode))
491 save_mode = choose_hard_reg_mode (i, 1, true);
492 if (DWARF_FRAME_REGNUM (i) == DWARF_FRAME_RETURN_COLUMN)
494 if (save_mode == VOIDmode)
495 continue;
496 wrote_return_column = true;
498 size = GET_MODE_SIZE (save_mode);
499 if (offset < 0)
500 continue;
502 emit_move_insn (adjust_address (mem, mode, offset),
503 gen_int_mode (size, mode));
506 #ifdef DWARF_ALT_FRAME_RETURN_COLUMN
507 gcc_assert (wrote_return_column);
508 i = DWARF_ALT_FRAME_RETURN_COLUMN;
509 wrote_return_column = false;
510 #else
511 i = DWARF_FRAME_RETURN_COLUMN;
512 #endif
514 if (! wrote_return_column)
516 enum machine_mode save_mode = Pmode;
517 HOST_WIDE_INT offset = i * GET_MODE_SIZE (mode);
518 HOST_WIDE_INT size = GET_MODE_SIZE (save_mode);
519 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
523 /* Convert a DWARF call frame info. operation to its string name */
525 static const char *
526 dwarf_cfi_name (unsigned int cfi_opc)
528 switch (cfi_opc)
530 case DW_CFA_advance_loc:
531 return "DW_CFA_advance_loc";
532 case DW_CFA_offset:
533 return "DW_CFA_offset";
534 case DW_CFA_restore:
535 return "DW_CFA_restore";
536 case DW_CFA_nop:
537 return "DW_CFA_nop";
538 case DW_CFA_set_loc:
539 return "DW_CFA_set_loc";
540 case DW_CFA_advance_loc1:
541 return "DW_CFA_advance_loc1";
542 case DW_CFA_advance_loc2:
543 return "DW_CFA_advance_loc2";
544 case DW_CFA_advance_loc4:
545 return "DW_CFA_advance_loc4";
546 case DW_CFA_offset_extended:
547 return "DW_CFA_offset_extended";
548 case DW_CFA_restore_extended:
549 return "DW_CFA_restore_extended";
550 case DW_CFA_undefined:
551 return "DW_CFA_undefined";
552 case DW_CFA_same_value:
553 return "DW_CFA_same_value";
554 case DW_CFA_register:
555 return "DW_CFA_register";
556 case DW_CFA_remember_state:
557 return "DW_CFA_remember_state";
558 case DW_CFA_restore_state:
559 return "DW_CFA_restore_state";
560 case DW_CFA_def_cfa:
561 return "DW_CFA_def_cfa";
562 case DW_CFA_def_cfa_register:
563 return "DW_CFA_def_cfa_register";
564 case DW_CFA_def_cfa_offset:
565 return "DW_CFA_def_cfa_offset";
567 /* DWARF 3 */
568 case DW_CFA_def_cfa_expression:
569 return "DW_CFA_def_cfa_expression";
570 case DW_CFA_expression:
571 return "DW_CFA_expression";
572 case DW_CFA_offset_extended_sf:
573 return "DW_CFA_offset_extended_sf";
574 case DW_CFA_def_cfa_sf:
575 return "DW_CFA_def_cfa_sf";
576 case DW_CFA_def_cfa_offset_sf:
577 return "DW_CFA_def_cfa_offset_sf";
579 /* SGI/MIPS specific */
580 case DW_CFA_MIPS_advance_loc8:
581 return "DW_CFA_MIPS_advance_loc8";
583 /* GNU extensions */
584 case DW_CFA_GNU_window_save:
585 return "DW_CFA_GNU_window_save";
586 case DW_CFA_GNU_args_size:
587 return "DW_CFA_GNU_args_size";
588 case DW_CFA_GNU_negative_offset_extended:
589 return "DW_CFA_GNU_negative_offset_extended";
591 default:
592 return "DW_CFA_<unknown>";
596 /* Return a pointer to a newly allocated Call Frame Instruction. */
598 static inline dw_cfi_ref
599 new_cfi (void)
601 dw_cfi_ref cfi = ggc_alloc (sizeof (dw_cfi_node));
603 cfi->dw_cfi_next = NULL;
604 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
605 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
607 return cfi;
610 /* Add a Call Frame Instruction to list of instructions. */
612 static inline void
613 add_cfi (dw_cfi_ref *list_head, dw_cfi_ref cfi)
615 dw_cfi_ref *p;
617 /* Find the end of the chain. */
618 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
621 *p = cfi;
624 /* Generate a new label for the CFI info to refer to. */
626 char *
627 dwarf2out_cfi_label (void)
629 static char label[20];
631 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", dwarf2out_cfi_label_num++);
632 ASM_OUTPUT_LABEL (asm_out_file, label);
633 return label;
636 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
637 or to the CIE if LABEL is NULL. */
639 static void
640 add_fde_cfi (const char *label, dw_cfi_ref cfi)
642 if (label)
644 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
646 if (*label == 0)
647 label = dwarf2out_cfi_label ();
649 if (fde->dw_fde_current_label == NULL
650 || strcmp (label, fde->dw_fde_current_label) != 0)
652 dw_cfi_ref xcfi;
654 fde->dw_fde_current_label = label = xstrdup (label);
656 /* Set the location counter to the new label. */
657 xcfi = new_cfi ();
658 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
659 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
660 add_cfi (&fde->dw_fde_cfi, xcfi);
663 add_cfi (&fde->dw_fde_cfi, cfi);
666 else
667 add_cfi (&cie_cfi_head, cfi);
670 /* Subroutine of lookup_cfa. */
672 static inline void
673 lookup_cfa_1 (dw_cfi_ref cfi, dw_cfa_location *loc)
675 switch (cfi->dw_cfi_opc)
677 case DW_CFA_def_cfa_offset:
678 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
679 break;
680 case DW_CFA_def_cfa_register:
681 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
682 break;
683 case DW_CFA_def_cfa:
684 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
685 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
686 break;
687 case DW_CFA_def_cfa_expression:
688 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
689 break;
690 default:
691 break;
695 /* Find the previous value for the CFA. */
697 static void
698 lookup_cfa (dw_cfa_location *loc)
700 dw_cfi_ref cfi;
702 loc->reg = (unsigned long) -1;
703 loc->offset = 0;
704 loc->indirect = 0;
705 loc->base_offset = 0;
707 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
708 lookup_cfa_1 (cfi, loc);
710 if (fde_table_in_use)
712 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
713 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
714 lookup_cfa_1 (cfi, loc);
718 /* The current rule for calculating the DWARF2 canonical frame address. */
719 static dw_cfa_location cfa;
721 /* The register used for saving registers to the stack, and its offset
722 from the CFA. */
723 static dw_cfa_location cfa_store;
725 /* The running total of the size of arguments pushed onto the stack. */
726 static HOST_WIDE_INT args_size;
728 /* The last args_size we actually output. */
729 static HOST_WIDE_INT old_args_size;
731 /* Entry point to update the canonical frame address (CFA).
732 LABEL is passed to add_fde_cfi. The value of CFA is now to be
733 calculated from REG+OFFSET. */
735 void
736 dwarf2out_def_cfa (const char *label, unsigned int reg, HOST_WIDE_INT offset)
738 dw_cfa_location loc;
739 loc.indirect = 0;
740 loc.base_offset = 0;
741 loc.reg = reg;
742 loc.offset = offset;
743 def_cfa_1 (label, &loc);
746 /* This routine does the actual work. The CFA is now calculated from
747 the dw_cfa_location structure. */
749 static void
750 def_cfa_1 (const char *label, dw_cfa_location *loc_p)
752 dw_cfi_ref cfi;
753 dw_cfa_location old_cfa, loc;
755 cfa = *loc_p;
756 loc = *loc_p;
758 if (cfa_store.reg == loc.reg && loc.indirect == 0)
759 cfa_store.offset = loc.offset;
761 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
762 lookup_cfa (&old_cfa);
764 /* If nothing changed, no need to issue any call frame instructions. */
765 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
766 && loc.indirect == old_cfa.indirect
767 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
768 return;
770 cfi = new_cfi ();
772 if (loc.reg == old_cfa.reg && !loc.indirect)
774 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
775 indicating the CFA register did not change but the offset
776 did. */
777 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
778 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
781 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
782 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
783 && !loc.indirect)
785 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
786 indicating the CFA register has changed to <register> but the
787 offset has not changed. */
788 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
789 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
791 #endif
793 else if (loc.indirect == 0)
795 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
796 indicating the CFA register has changed to <register> with
797 the specified offset. */
798 cfi->dw_cfi_opc = DW_CFA_def_cfa;
799 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
800 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
802 else
804 /* Construct a DW_CFA_def_cfa_expression instruction to
805 calculate the CFA using a full location expression since no
806 register-offset pair is available. */
807 struct dw_loc_descr_struct *loc_list;
809 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
810 loc_list = build_cfa_loc (&loc);
811 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
814 add_fde_cfi (label, cfi);
817 /* Add the CFI for saving a register. REG is the CFA column number.
818 LABEL is passed to add_fde_cfi.
819 If SREG is -1, the register is saved at OFFSET from the CFA;
820 otherwise it is saved in SREG. */
822 static void
823 reg_save (const char *label, unsigned int reg, unsigned int sreg, HOST_WIDE_INT offset)
825 dw_cfi_ref cfi = new_cfi ();
827 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
829 if (sreg == INVALID_REGNUM)
831 if (reg & ~0x3f)
832 /* The register number won't fit in 6 bits, so we have to use
833 the long form. */
834 cfi->dw_cfi_opc = DW_CFA_offset_extended;
835 else
836 cfi->dw_cfi_opc = DW_CFA_offset;
838 #ifdef ENABLE_CHECKING
840 /* If we get an offset that is not a multiple of
841 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
842 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
843 description. */
844 HOST_WIDE_INT check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
846 gcc_assert (check_offset * DWARF_CIE_DATA_ALIGNMENT == offset);
848 #endif
849 offset /= DWARF_CIE_DATA_ALIGNMENT;
850 if (offset < 0)
851 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
853 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
855 else if (sreg == reg)
856 cfi->dw_cfi_opc = DW_CFA_same_value;
857 else
859 cfi->dw_cfi_opc = DW_CFA_register;
860 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
863 add_fde_cfi (label, cfi);
866 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
867 This CFI tells the unwinder that it needs to restore the window registers
868 from the previous frame's window save area.
870 ??? Perhaps we should note in the CIE where windows are saved (instead of
871 assuming 0(cfa)) and what registers are in the window. */
873 void
874 dwarf2out_window_save (const char *label)
876 dw_cfi_ref cfi = new_cfi ();
878 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
879 add_fde_cfi (label, cfi);
882 /* Add a CFI to update the running total of the size of arguments
883 pushed onto the stack. */
885 void
886 dwarf2out_args_size (const char *label, HOST_WIDE_INT size)
888 dw_cfi_ref cfi;
890 if (size == old_args_size)
891 return;
893 old_args_size = size;
895 cfi = new_cfi ();
896 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
897 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
898 add_fde_cfi (label, cfi);
901 /* Entry point for saving a register to the stack. REG is the GCC register
902 number. LABEL and OFFSET are passed to reg_save. */
904 void
905 dwarf2out_reg_save (const char *label, unsigned int reg, HOST_WIDE_INT offset)
907 reg_save (label, DWARF_FRAME_REGNUM (reg), INVALID_REGNUM, offset);
910 /* Entry point for saving the return address in the stack.
911 LABEL and OFFSET are passed to reg_save. */
913 void
914 dwarf2out_return_save (const char *label, HOST_WIDE_INT offset)
916 reg_save (label, DWARF_FRAME_RETURN_COLUMN, INVALID_REGNUM, offset);
919 /* Entry point for saving the return address in a register.
920 LABEL and SREG are passed to reg_save. */
922 void
923 dwarf2out_return_reg (const char *label, unsigned int sreg)
925 reg_save (label, DWARF_FRAME_RETURN_COLUMN, DWARF_FRAME_REGNUM (sreg), 0);
928 /* Record the initial position of the return address. RTL is
929 INCOMING_RETURN_ADDR_RTX. */
931 static void
932 initial_return_save (rtx rtl)
934 unsigned int reg = INVALID_REGNUM;
935 HOST_WIDE_INT offset = 0;
937 switch (GET_CODE (rtl))
939 case REG:
940 /* RA is in a register. */
941 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
942 break;
944 case MEM:
945 /* RA is on the stack. */
946 rtl = XEXP (rtl, 0);
947 switch (GET_CODE (rtl))
949 case REG:
950 gcc_assert (REGNO (rtl) == STACK_POINTER_REGNUM);
951 offset = 0;
952 break;
954 case PLUS:
955 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
956 offset = INTVAL (XEXP (rtl, 1));
957 break;
959 case MINUS:
960 gcc_assert (REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM);
961 offset = -INTVAL (XEXP (rtl, 1));
962 break;
964 default:
965 gcc_unreachable ();
968 break;
970 case PLUS:
971 /* The return address is at some offset from any value we can
972 actually load. For instance, on the SPARC it is in %i7+8. Just
973 ignore the offset for now; it doesn't matter for unwinding frames. */
974 gcc_assert (GET_CODE (XEXP (rtl, 1)) == CONST_INT);
975 initial_return_save (XEXP (rtl, 0));
976 return;
978 default:
979 gcc_unreachable ();
982 if (reg != DWARF_FRAME_RETURN_COLUMN)
983 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
986 /* Given a SET, calculate the amount of stack adjustment it
987 contains. */
989 static HOST_WIDE_INT
990 stack_adjust_offset (rtx pattern)
992 rtx src = SET_SRC (pattern);
993 rtx dest = SET_DEST (pattern);
994 HOST_WIDE_INT offset = 0;
995 enum rtx_code code;
997 if (dest == stack_pointer_rtx)
999 /* (set (reg sp) (plus (reg sp) (const_int))) */
1000 code = GET_CODE (src);
1001 if (! (code == PLUS || code == MINUS)
1002 || XEXP (src, 0) != stack_pointer_rtx
1003 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1004 return 0;
1006 offset = INTVAL (XEXP (src, 1));
1007 if (code == PLUS)
1008 offset = -offset;
1010 else if (MEM_P (dest))
1012 /* (set (mem (pre_dec (reg sp))) (foo)) */
1013 src = XEXP (dest, 0);
1014 code = GET_CODE (src);
1016 switch (code)
1018 case PRE_MODIFY:
1019 case POST_MODIFY:
1020 if (XEXP (src, 0) == stack_pointer_rtx)
1022 rtx val = XEXP (XEXP (src, 1), 1);
1023 /* We handle only adjustments by constant amount. */
1024 gcc_assert (GET_CODE (XEXP (src, 1)) == PLUS
1025 && GET_CODE (val) == CONST_INT);
1026 offset = -INTVAL (val);
1027 break;
1029 return 0;
1031 case PRE_DEC:
1032 case POST_DEC:
1033 if (XEXP (src, 0) == stack_pointer_rtx)
1035 offset = GET_MODE_SIZE (GET_MODE (dest));
1036 break;
1038 return 0;
1040 case PRE_INC:
1041 case POST_INC:
1042 if (XEXP (src, 0) == stack_pointer_rtx)
1044 offset = -GET_MODE_SIZE (GET_MODE (dest));
1045 break;
1047 return 0;
1049 default:
1050 return 0;
1053 else
1054 return 0;
1056 return offset;
1059 /* Check INSN to see if it looks like a push or a stack adjustment, and
1060 make a note of it if it does. EH uses this information to find out how
1061 much extra space it needs to pop off the stack. */
1063 static void
1064 dwarf2out_stack_adjust (rtx insn, bool after_p)
1066 HOST_WIDE_INT offset;
1067 const char *label;
1068 int i;
1070 /* Don't handle epilogues at all. Certainly it would be wrong to do so
1071 with this function. Proper support would require all frame-related
1072 insns to be marked, and to be able to handle saving state around
1073 epilogues textually in the middle of the function. */
1074 if (prologue_epilogue_contains (insn) || sibcall_epilogue_contains (insn))
1075 return;
1077 /* If only calls can throw, and we have a frame pointer,
1078 save up adjustments until we see the CALL_INSN. */
1079 if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1081 if (CALL_P (insn) && !after_p)
1083 /* Extract the size of the args from the CALL rtx itself. */
1084 insn = PATTERN (insn);
1085 if (GET_CODE (insn) == PARALLEL)
1086 insn = XVECEXP (insn, 0, 0);
1087 if (GET_CODE (insn) == SET)
1088 insn = SET_SRC (insn);
1089 gcc_assert (GET_CODE (insn) == CALL);
1090 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1092 return;
1095 if (CALL_P (insn) && !after_p)
1097 if (!flag_asynchronous_unwind_tables)
1098 dwarf2out_args_size ("", args_size);
1099 return;
1101 else if (BARRIER_P (insn))
1103 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1104 the compiler will have already emitted a stack adjustment, but
1105 doesn't bother for calls to noreturn functions. */
1106 #ifdef STACK_GROWS_DOWNWARD
1107 offset = -args_size;
1108 #else
1109 offset = args_size;
1110 #endif
1112 else if (GET_CODE (PATTERN (insn)) == SET)
1113 offset = stack_adjust_offset (PATTERN (insn));
1114 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1115 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1117 /* There may be stack adjustments inside compound insns. Search
1118 for them. */
1119 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1120 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1121 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1123 else
1124 return;
1126 if (offset == 0)
1127 return;
1129 if (cfa.reg == STACK_POINTER_REGNUM)
1130 cfa.offset += offset;
1132 #ifndef STACK_GROWS_DOWNWARD
1133 offset = -offset;
1134 #endif
1136 args_size += offset;
1137 if (args_size < 0)
1138 args_size = 0;
1140 label = dwarf2out_cfi_label ();
1141 def_cfa_1 (label, &cfa);
1142 if (flag_asynchronous_unwind_tables)
1143 dwarf2out_args_size (label, args_size);
1146 #endif
1148 /* We delay emitting a register save until either (a) we reach the end
1149 of the prologue or (b) the register is clobbered. This clusters
1150 register saves so that there are fewer pc advances. */
1152 struct queued_reg_save GTY(())
1154 struct queued_reg_save *next;
1155 rtx reg;
1156 HOST_WIDE_INT cfa_offset;
1157 rtx saved_reg;
1160 static GTY(()) struct queued_reg_save *queued_reg_saves;
1162 /* The caller's ORIG_REG is saved in SAVED_IN_REG. */
1163 struct reg_saved_in_data GTY(()) {
1164 rtx orig_reg;
1165 rtx saved_in_reg;
1168 /* A list of registers saved in other registers.
1169 The list intentionally has a small maximum capacity of 4; if your
1170 port needs more than that, you might consider implementing a
1171 more efficient data structure. */
1172 static GTY(()) struct reg_saved_in_data regs_saved_in_regs[4];
1173 static GTY(()) size_t num_regs_saved_in_regs;
1175 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1176 static const char *last_reg_save_label;
1178 /* Add an entry to QUEUED_REG_SAVES saying that REG is now saved at
1179 SREG, or if SREG is NULL then it is saved at OFFSET to the CFA. */
1181 static void
1182 queue_reg_save (const char *label, rtx reg, rtx sreg, HOST_WIDE_INT offset)
1184 struct queued_reg_save *q;
1186 /* Duplicates waste space, but it's also necessary to remove them
1187 for correctness, since the queue gets output in reverse
1188 order. */
1189 for (q = queued_reg_saves; q != NULL; q = q->next)
1190 if (REGNO (q->reg) == REGNO (reg))
1191 break;
1193 if (q == NULL)
1195 q = ggc_alloc (sizeof (*q));
1196 q->next = queued_reg_saves;
1197 queued_reg_saves = q;
1200 q->reg = reg;
1201 q->cfa_offset = offset;
1202 q->saved_reg = sreg;
1204 last_reg_save_label = label;
1207 /* Output all the entries in QUEUED_REG_SAVES. */
1209 static void
1210 flush_queued_reg_saves (void)
1212 struct queued_reg_save *q;
1214 for (q = queued_reg_saves; q; q = q->next)
1216 size_t i;
1217 unsigned int reg, sreg;
1219 for (i = 0; i < num_regs_saved_in_regs; i++)
1220 if (REGNO (regs_saved_in_regs[i].orig_reg) == REGNO (q->reg))
1221 break;
1222 if (q->saved_reg && i == num_regs_saved_in_regs)
1224 gcc_assert (i != ARRAY_SIZE (regs_saved_in_regs));
1225 num_regs_saved_in_regs++;
1227 if (i != num_regs_saved_in_regs)
1229 regs_saved_in_regs[i].orig_reg = q->reg;
1230 regs_saved_in_regs[i].saved_in_reg = q->saved_reg;
1233 reg = DWARF_FRAME_REGNUM (REGNO (q->reg));
1234 if (q->saved_reg)
1235 sreg = DWARF_FRAME_REGNUM (REGNO (q->saved_reg));
1236 else
1237 sreg = INVALID_REGNUM;
1238 reg_save (last_reg_save_label, reg, sreg, q->cfa_offset);
1241 queued_reg_saves = NULL;
1242 last_reg_save_label = NULL;
1245 /* Does INSN clobber any register which QUEUED_REG_SAVES lists a saved
1246 location for? Or, does it clobber a register which we've previously
1247 said that some other register is saved in, and for which we now
1248 have a new location for? */
1250 static bool
1251 clobbers_queued_reg_save (rtx insn)
1253 struct queued_reg_save *q;
1255 for (q = queued_reg_saves; q; q = q->next)
1257 size_t i;
1258 if (modified_in_p (q->reg, insn))
1259 return true;
1260 for (i = 0; i < num_regs_saved_in_regs; i++)
1261 if (REGNO (q->reg) == REGNO (regs_saved_in_regs[i].orig_reg)
1262 && modified_in_p (regs_saved_in_regs[i].saved_in_reg, insn))
1263 return true;
1266 return false;
1269 /* What register, if any, is currently saved in REG? */
1271 static rtx
1272 reg_saved_in (rtx reg)
1274 unsigned int regn = REGNO (reg);
1275 size_t i;
1276 struct queued_reg_save *q;
1278 for (q = queued_reg_saves; q; q = q->next)
1279 if (q->saved_reg && regn == REGNO (q->saved_reg))
1280 return q->reg;
1282 for (i = 0; i < num_regs_saved_in_regs; i++)
1283 if (regs_saved_in_regs[i].saved_in_reg
1284 && regn == REGNO (regs_saved_in_regs[i].saved_in_reg))
1285 return regs_saved_in_regs[i].orig_reg;
1287 return NULL_RTX;
1291 /* A temporary register holding an integral value used in adjusting SP
1292 or setting up the store_reg. The "offset" field holds the integer
1293 value, not an offset. */
1294 static dw_cfa_location cfa_temp;
1296 /* Record call frame debugging information for an expression EXPR,
1297 which either sets SP or FP (adjusting how we calculate the frame
1298 address) or saves a register to the stack or another register.
1299 LABEL indicates the address of EXPR.
1301 This function encodes a state machine mapping rtxes to actions on
1302 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1303 users need not read the source code.
1305 The High-Level Picture
1307 Changes in the register we use to calculate the CFA: Currently we
1308 assume that if you copy the CFA register into another register, we
1309 should take the other one as the new CFA register; this seems to
1310 work pretty well. If it's wrong for some target, it's simple
1311 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1313 Changes in the register we use for saving registers to the stack:
1314 This is usually SP, but not always. Again, we deduce that if you
1315 copy SP into another register (and SP is not the CFA register),
1316 then the new register is the one we will be using for register
1317 saves. This also seems to work.
1319 Register saves: There's not much guesswork about this one; if
1320 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1321 register save, and the register used to calculate the destination
1322 had better be the one we think we're using for this purpose.
1323 It's also assumed that a copy from a call-saved register to another
1324 register is saving that register if RTX_FRAME_RELATED_P is set on
1325 that instruction. If the copy is from a call-saved register to
1326 the *same* register, that means that the register is now the same
1327 value as in the caller.
1329 Except: If the register being saved is the CFA register, and the
1330 offset is nonzero, we are saving the CFA, so we assume we have to
1331 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1332 the intent is to save the value of SP from the previous frame.
1334 In addition, if a register has previously been saved to a different
1335 register,
1337 Invariants / Summaries of Rules
1339 cfa current rule for calculating the CFA. It usually
1340 consists of a register and an offset.
1341 cfa_store register used by prologue code to save things to the stack
1342 cfa_store.offset is the offset from the value of
1343 cfa_store.reg to the actual CFA
1344 cfa_temp register holding an integral value. cfa_temp.offset
1345 stores the value, which will be used to adjust the
1346 stack pointer. cfa_temp is also used like cfa_store,
1347 to track stores to the stack via fp or a temp reg.
1349 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1350 with cfa.reg as the first operand changes the cfa.reg and its
1351 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1352 cfa_temp.offset.
1354 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1355 expression yielding a constant. This sets cfa_temp.reg
1356 and cfa_temp.offset.
1358 Rule 5: Create a new register cfa_store used to save items to the
1359 stack.
1361 Rules 10-14: Save a register to the stack. Define offset as the
1362 difference of the original location and cfa_store's
1363 location (or cfa_temp's location if cfa_temp is used).
1365 The Rules
1367 "{a,b}" indicates a choice of a xor b.
1368 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1370 Rule 1:
1371 (set <reg1> <reg2>:cfa.reg)
1372 effects: cfa.reg = <reg1>
1373 cfa.offset unchanged
1374 cfa_temp.reg = <reg1>
1375 cfa_temp.offset = cfa.offset
1377 Rule 2:
1378 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1379 {<const_int>,<reg>:cfa_temp.reg}))
1380 effects: cfa.reg = sp if fp used
1381 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1382 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1383 if cfa_store.reg==sp
1385 Rule 3:
1386 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1387 effects: cfa.reg = fp
1388 cfa_offset += +/- <const_int>
1390 Rule 4:
1391 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1392 constraints: <reg1> != fp
1393 <reg1> != sp
1394 effects: cfa.reg = <reg1>
1395 cfa_temp.reg = <reg1>
1396 cfa_temp.offset = cfa.offset
1398 Rule 5:
1399 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1400 constraints: <reg1> != fp
1401 <reg1> != sp
1402 effects: cfa_store.reg = <reg1>
1403 cfa_store.offset = cfa.offset - cfa_temp.offset
1405 Rule 6:
1406 (set <reg> <const_int>)
1407 effects: cfa_temp.reg = <reg>
1408 cfa_temp.offset = <const_int>
1410 Rule 7:
1411 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1412 effects: cfa_temp.reg = <reg1>
1413 cfa_temp.offset |= <const_int>
1415 Rule 8:
1416 (set <reg> (high <exp>))
1417 effects: none
1419 Rule 9:
1420 (set <reg> (lo_sum <exp> <const_int>))
1421 effects: cfa_temp.reg = <reg>
1422 cfa_temp.offset = <const_int>
1424 Rule 10:
1425 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1426 effects: cfa_store.offset -= <const_int>
1427 cfa.offset = cfa_store.offset if cfa.reg == sp
1428 cfa.reg = sp
1429 cfa.base_offset = -cfa_store.offset
1431 Rule 11:
1432 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1433 effects: cfa_store.offset += -/+ mode_size(mem)
1434 cfa.offset = cfa_store.offset if cfa.reg == sp
1435 cfa.reg = sp
1436 cfa.base_offset = -cfa_store.offset
1438 Rule 12:
1439 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1441 <reg2>)
1442 effects: cfa.reg = <reg1>
1443 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1445 Rule 13:
1446 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1447 effects: cfa.reg = <reg1>
1448 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1450 Rule 14:
1451 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1452 effects: cfa.reg = <reg1>
1453 cfa.base_offset = -cfa_temp.offset
1454 cfa_temp.offset -= mode_size(mem)
1456   Rule 15:
1457   (set <reg> {unspec, unspec_volatile})
1458   effects: target-dependent */
1460 static void
1461 dwarf2out_frame_debug_expr (rtx expr, const char *label)
1463 rtx src, dest;
1464 HOST_WIDE_INT offset;
1466 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1467 the PARALLEL independently. The first element is always processed if
1468 it is a SET. This is for backward compatibility. Other elements
1469 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1470 flag is set in them. */
1471 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1473 int par_index;
1474 int limit = XVECLEN (expr, 0);
1476 for (par_index = 0; par_index < limit; par_index++)
1477 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1478 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1479 || par_index == 0))
1480 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1482 return;
1485 gcc_assert (GET_CODE (expr) == SET);
1487 src = SET_SRC (expr);
1488 dest = SET_DEST (expr);
1490 if (REG_P (src))
1492 rtx rsi = reg_saved_in (src);
1493 if (rsi)
1494 src = rsi;
1497 switch (GET_CODE (dest))
1499 case REG:
1500 switch (GET_CODE (src))
1502 /* Setting FP from SP. */
1503 case REG:
1504 if (cfa.reg == (unsigned) REGNO (src))
1506 /* Rule 1 */
1507 /* Update the CFA rule wrt SP or FP. Make sure src is
1508 relative to the current CFA register.
1510 We used to require that dest be either SP or FP, but the
1511 ARM copies SP to a temporary register, and from there to
1512 FP. So we just rely on the backends to only set
1513 RTX_FRAME_RELATED_P on appropriate insns. */
1514 cfa.reg = REGNO (dest);
1515 cfa_temp.reg = cfa.reg;
1516 cfa_temp.offset = cfa.offset;
1518 else
1520 /* Saving a register in a register. */
1521 gcc_assert (call_used_regs [REGNO (dest)]
1522 && (!fixed_regs [REGNO (dest)]
1523 /* For the SPARC and its register window. */
1524 || DWARF_FRAME_REGNUM (REGNO (src))
1525 == DWARF_FRAME_RETURN_COLUMN));
1526 queue_reg_save (label, src, dest, 0);
1528 break;
1530 case PLUS:
1531 case MINUS:
1532 case LO_SUM:
1533 if (dest == stack_pointer_rtx)
1535 /* Rule 2 */
1536 /* Adjusting SP. */
1537 switch (GET_CODE (XEXP (src, 1)))
1539 case CONST_INT:
1540 offset = INTVAL (XEXP (src, 1));
1541 break;
1542 case REG:
1543 gcc_assert ((unsigned) REGNO (XEXP (src, 1))
1544 == cfa_temp.reg);
1545 offset = cfa_temp.offset;
1546 break;
1547 default:
1548 gcc_unreachable ();
1551 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1553 /* Restoring SP from FP in the epilogue. */
1554 gcc_assert (cfa.reg == (unsigned) HARD_FRAME_POINTER_REGNUM);
1555 cfa.reg = STACK_POINTER_REGNUM;
1557 else if (GET_CODE (src) == LO_SUM)
1558 /* Assume we've set the source reg of the LO_SUM from sp. */
1560 else
1561 gcc_assert (XEXP (src, 0) == stack_pointer_rtx);
1563 if (GET_CODE (src) != MINUS)
1564 offset = -offset;
1565 if (cfa.reg == STACK_POINTER_REGNUM)
1566 cfa.offset += offset;
1567 if (cfa_store.reg == STACK_POINTER_REGNUM)
1568 cfa_store.offset += offset;
1570 else if (dest == hard_frame_pointer_rtx)
1572 /* Rule 3 */
1573 /* Either setting the FP from an offset of the SP,
1574 or adjusting the FP */
1575 gcc_assert (frame_pointer_needed);
1577 gcc_assert (REG_P (XEXP (src, 0))
1578 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1579 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1580 offset = INTVAL (XEXP (src, 1));
1581 if (GET_CODE (src) != MINUS)
1582 offset = -offset;
1583 cfa.offset += offset;
1584 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1586 else
1588 gcc_assert (GET_CODE (src) != MINUS);
1590 /* Rule 4 */
1591 if (REG_P (XEXP (src, 0))
1592 && REGNO (XEXP (src, 0)) == cfa.reg
1593 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1595 /* Setting a temporary CFA register that will be copied
1596 into the FP later on. */
1597 offset = - INTVAL (XEXP (src, 1));
1598 cfa.offset += offset;
1599 cfa.reg = REGNO (dest);
1600 /* Or used to save regs to the stack. */
1601 cfa_temp.reg = cfa.reg;
1602 cfa_temp.offset = cfa.offset;
1605 /* Rule 5 */
1606 else if (REG_P (XEXP (src, 0))
1607 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1608 && XEXP (src, 1) == stack_pointer_rtx)
1610 /* Setting a scratch register that we will use instead
1611 of SP for saving registers to the stack. */
1612 gcc_assert (cfa.reg == STACK_POINTER_REGNUM);
1613 cfa_store.reg = REGNO (dest);
1614 cfa_store.offset = cfa.offset - cfa_temp.offset;
1617 /* Rule 9 */
1618 else if (GET_CODE (src) == LO_SUM
1619 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1621 cfa_temp.reg = REGNO (dest);
1622 cfa_temp.offset = INTVAL (XEXP (src, 1));
1624 else
1625 gcc_unreachable ();
1627 break;
1629 /* Rule 6 */
1630 case CONST_INT:
1631 cfa_temp.reg = REGNO (dest);
1632 cfa_temp.offset = INTVAL (src);
1633 break;
1635 /* Rule 7 */
1636 case IOR:
1637 gcc_assert (REG_P (XEXP (src, 0))
1638 && (unsigned) REGNO (XEXP (src, 0)) == cfa_temp.reg
1639 && GET_CODE (XEXP (src, 1)) == CONST_INT);
1641 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1642 cfa_temp.reg = REGNO (dest);
1643 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1644 break;
1646 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1647 which will fill in all of the bits. */
1648 /* Rule 8 */
1649 case HIGH:
1650 break;
1652 /* Rule 15 */
1653 case UNSPEC:
1654 case UNSPEC_VOLATILE:
1655 gcc_assert (targetm.dwarf_handle_frame_unspec);
1656 targetm.dwarf_handle_frame_unspec (label, expr, XINT (src, 1));
1657 break;
1659 default:
1660 gcc_unreachable ();
1663 def_cfa_1 (label, &cfa);
1664 break;
1666 case MEM:
1667 gcc_assert (REG_P (src));
1669 /* Saving a register to the stack. Make sure dest is relative to the
1670 CFA register. */
1671 switch (GET_CODE (XEXP (dest, 0)))
1673 /* Rule 10 */
1674 /* With a push. */
1675 case PRE_MODIFY:
1676 /* We can't handle variable size modifications. */
1677 gcc_assert (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1))
1678 == CONST_INT);
1679 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1681 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1682 && cfa_store.reg == STACK_POINTER_REGNUM);
1684 cfa_store.offset += offset;
1685 if (cfa.reg == STACK_POINTER_REGNUM)
1686 cfa.offset = cfa_store.offset;
1688 offset = -cfa_store.offset;
1689 break;
1691 /* Rule 11 */
1692 case PRE_INC:
1693 case PRE_DEC:
1694 offset = GET_MODE_SIZE (GET_MODE (dest));
1695 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1696 offset = -offset;
1698 gcc_assert (REGNO (XEXP (XEXP (dest, 0), 0)) == STACK_POINTER_REGNUM
1699 && cfa_store.reg == STACK_POINTER_REGNUM);
1701 cfa_store.offset += offset;
1702 if (cfa.reg == STACK_POINTER_REGNUM)
1703 cfa.offset = cfa_store.offset;
1705 offset = -cfa_store.offset;
1706 break;
1708 /* Rule 12 */
1709 /* With an offset. */
1710 case PLUS:
1711 case MINUS:
1712 case LO_SUM:
1714 int regno;
1716 gcc_assert (GET_CODE (XEXP (XEXP (dest, 0), 1)) == CONST_INT);
1717 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1718 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1719 offset = -offset;
1721 regno = REGNO (XEXP (XEXP (dest, 0), 0));
1723 if (cfa_store.reg == (unsigned) regno)
1724 offset -= cfa_store.offset;
1725 else
1727 gcc_assert (cfa_temp.reg == (unsigned) regno);
1728 offset -= cfa_temp.offset;
1731 break;
1733 /* Rule 13 */
1734 /* Without an offset. */
1735 case REG:
1737 int regno = REGNO (XEXP (dest, 0));
1739 if (cfa_store.reg == (unsigned) regno)
1740 offset = -cfa_store.offset;
1741 else
1743 gcc_assert (cfa_temp.reg == (unsigned) regno);
1744 offset = -cfa_temp.offset;
1747 break;
1749 /* Rule 14 */
1750 case POST_INC:
1751 gcc_assert (cfa_temp.reg
1752 == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)));
1753 offset = -cfa_temp.offset;
1754 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1755 break;
1757 default:
1758 gcc_unreachable ();
1761 if (REGNO (src) != STACK_POINTER_REGNUM
1762 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1763 && (unsigned) REGNO (src) == cfa.reg)
1765 /* We're storing the current CFA reg into the stack. */
1767 if (cfa.offset == 0)
1769 /* If the source register is exactly the CFA, assume
1770 we're saving SP like any other register; this happens
1771 on the ARM. */
1772 def_cfa_1 (label, &cfa);
1773 queue_reg_save (label, stack_pointer_rtx, NULL_RTX, offset);
1774 break;
1776 else
1778 /* Otherwise, we'll need to look in the stack to
1779 calculate the CFA. */
1780 rtx x = XEXP (dest, 0);
1782 if (!REG_P (x))
1783 x = XEXP (x, 0);
1784 gcc_assert (REG_P (x));
1786 cfa.reg = REGNO (x);
1787 cfa.base_offset = offset;
1788 cfa.indirect = 1;
1789 def_cfa_1 (label, &cfa);
1790 break;
1794 def_cfa_1 (label, &cfa);
1795 queue_reg_save (label, src, NULL_RTX, offset);
1796 break;
1798 default:
1799 gcc_unreachable ();
1803 /* Record call frame debugging information for INSN, which either
1804 sets SP or FP (adjusting how we calculate the frame address) or saves a
1805 register to the stack. If INSN is NULL_RTX, initialize our state.
1807 If AFTER_P is false, we're being called before the insn is emitted,
1808 otherwise after. Call instructions get invoked twice. */
1810 void
1811 dwarf2out_frame_debug (rtx insn, bool after_p)
1813 const char *label;
1814 rtx src;
1816 if (insn == NULL_RTX)
1818 size_t i;
1820 /* Flush any queued register saves. */
1821 flush_queued_reg_saves ();
1823 /* Set up state for generating call frame debug info. */
1824 lookup_cfa (&cfa);
1825 gcc_assert (cfa.reg
1826 == (unsigned long)DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM));
1828 cfa.reg = STACK_POINTER_REGNUM;
1829 cfa_store = cfa;
1830 cfa_temp.reg = -1;
1831 cfa_temp.offset = 0;
1833 for (i = 0; i < num_regs_saved_in_regs; i++)
1835 regs_saved_in_regs[i].orig_reg = NULL_RTX;
1836 regs_saved_in_regs[i].saved_in_reg = NULL_RTX;
1838 num_regs_saved_in_regs = 0;
1839 return;
1842 if (!NONJUMP_INSN_P (insn) || clobbers_queued_reg_save (insn))
1843 flush_queued_reg_saves ();
1845 if (! RTX_FRAME_RELATED_P (insn))
1847 if (!ACCUMULATE_OUTGOING_ARGS)
1848 dwarf2out_stack_adjust (insn, after_p);
1849 return;
1852 label = dwarf2out_cfi_label ();
1853 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1854 if (src)
1855 insn = XEXP (src, 0);
1856 else
1857 insn = PATTERN (insn);
1859 dwarf2out_frame_debug_expr (insn, label);
1862 #endif
1864 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
1865 static enum dw_cfi_oprnd_type dw_cfi_oprnd1_desc
1866 (enum dwarf_call_frame_info cfi);
1868 static enum dw_cfi_oprnd_type
1869 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi)
1871 switch (cfi)
1873 case DW_CFA_nop:
1874 case DW_CFA_GNU_window_save:
1875 return dw_cfi_oprnd_unused;
1877 case DW_CFA_set_loc:
1878 case DW_CFA_advance_loc1:
1879 case DW_CFA_advance_loc2:
1880 case DW_CFA_advance_loc4:
1881 case DW_CFA_MIPS_advance_loc8:
1882 return dw_cfi_oprnd_addr;
1884 case DW_CFA_offset:
1885 case DW_CFA_offset_extended:
1886 case DW_CFA_def_cfa:
1887 case DW_CFA_offset_extended_sf:
1888 case DW_CFA_def_cfa_sf:
1889 case DW_CFA_restore_extended:
1890 case DW_CFA_undefined:
1891 case DW_CFA_same_value:
1892 case DW_CFA_def_cfa_register:
1893 case DW_CFA_register:
1894 return dw_cfi_oprnd_reg_num;
1896 case DW_CFA_def_cfa_offset:
1897 case DW_CFA_GNU_args_size:
1898 case DW_CFA_def_cfa_offset_sf:
1899 return dw_cfi_oprnd_offset;
1901 case DW_CFA_def_cfa_expression:
1902 case DW_CFA_expression:
1903 return dw_cfi_oprnd_loc;
1905 default:
1906 gcc_unreachable ();
1910 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
1911 static enum dw_cfi_oprnd_type dw_cfi_oprnd2_desc
1912 (enum dwarf_call_frame_info cfi);
1914 static enum dw_cfi_oprnd_type
1915 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi)
1917 switch (cfi)
1919 case DW_CFA_def_cfa:
1920 case DW_CFA_def_cfa_sf:
1921 case DW_CFA_offset:
1922 case DW_CFA_offset_extended_sf:
1923 case DW_CFA_offset_extended:
1924 return dw_cfi_oprnd_offset;
1926 case DW_CFA_register:
1927 return dw_cfi_oprnd_reg_num;
1929 default:
1930 return dw_cfi_oprnd_unused;
1934 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
1936 /* Map register numbers held in the call frame info that gcc has
1937 collected using DWARF_FRAME_REGNUM to those that should be output in
1938 .debug_frame and .eh_frame. */
1939 #ifndef DWARF2_FRAME_REG_OUT
1940 #define DWARF2_FRAME_REG_OUT(REGNO, FOR_EH) (REGNO)
1941 #endif
1943 /* Output a Call Frame Information opcode and its operand(s). */
1945 static void
1946 output_cfi (dw_cfi_ref cfi, dw_fde_ref fde, int for_eh)
1948 unsigned long r;
1949 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1950 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1951 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1952 "DW_CFA_advance_loc " HOST_WIDE_INT_PRINT_HEX,
1953 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1954 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1956 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1957 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1958 "DW_CFA_offset, column 0x%lx", r);
1959 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1961 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1963 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
1964 dw2_asm_output_data (1, (cfi->dw_cfi_opc | (r & 0x3f)),
1965 "DW_CFA_restore, column 0x%lx", r);
1967 else
1969 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1970 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1972 switch (cfi->dw_cfi_opc)
1974 case DW_CFA_set_loc:
1975 if (for_eh)
1976 dw2_asm_output_encoded_addr_rtx (
1977 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1978 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1979 NULL);
1980 else
1981 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1982 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1983 break;
1985 case DW_CFA_advance_loc1:
1986 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1987 fde->dw_fde_current_label, NULL);
1988 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1989 break;
1991 case DW_CFA_advance_loc2:
1992 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1993 fde->dw_fde_current_label, NULL);
1994 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1995 break;
1997 case DW_CFA_advance_loc4:
1998 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1999 fde->dw_fde_current_label, NULL);
2000 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2001 break;
2003 case DW_CFA_MIPS_advance_loc8:
2004 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
2005 fde->dw_fde_current_label, NULL);
2006 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
2007 break;
2009 case DW_CFA_offset_extended:
2010 case DW_CFA_def_cfa:
2011 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2012 dw2_asm_output_data_uleb128 (r, NULL);
2013 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2014 break;
2016 case DW_CFA_offset_extended_sf:
2017 case DW_CFA_def_cfa_sf:
2018 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2019 dw2_asm_output_data_uleb128 (r, NULL);
2020 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
2021 break;
2023 case DW_CFA_restore_extended:
2024 case DW_CFA_undefined:
2025 case DW_CFA_same_value:
2026 case DW_CFA_def_cfa_register:
2027 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2028 dw2_asm_output_data_uleb128 (r, NULL);
2029 break;
2031 case DW_CFA_register:
2032 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, for_eh);
2033 dw2_asm_output_data_uleb128 (r, NULL);
2034 r = DWARF2_FRAME_REG_OUT (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, for_eh);
2035 dw2_asm_output_data_uleb128 (r, NULL);
2036 break;
2038 case DW_CFA_def_cfa_offset:
2039 case DW_CFA_GNU_args_size:
2040 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2041 break;
2043 case DW_CFA_def_cfa_offset_sf:
2044 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
2045 break;
2047 case DW_CFA_GNU_window_save:
2048 break;
2050 case DW_CFA_def_cfa_expression:
2051 case DW_CFA_expression:
2052 output_cfa_loc (cfi);
2053 break;
2055 case DW_CFA_GNU_negative_offset_extended:
2056 /* Obsoleted by DW_CFA_offset_extended_sf. */
2057 gcc_unreachable ();
2059 default:
2060 break;
2065 /* Output the call frame information used to record information
2066 that relates to calculating the frame pointer, and records the
2067 location of saved registers. */
2069 static void
2070 output_call_frame_info (int for_eh)
2072 unsigned int i;
2073 dw_fde_ref fde;
2074 dw_cfi_ref cfi;
2075 char l1[20], l2[20], section_start_label[20];
2076 bool any_lsda_needed = false;
2077 char augmentation[6];
2078 int augmentation_size;
2079 int fde_encoding = DW_EH_PE_absptr;
2080 int per_encoding = DW_EH_PE_absptr;
2081 int lsda_encoding = DW_EH_PE_absptr;
2082 int return_reg;
2084 /* Don't emit a CIE if there won't be any FDEs. */
2085 if (fde_table_in_use == 0)
2086 return;
2088 /* If we make FDEs linkonce, we may have to emit an empty label for
2089 an FDE that wouldn't otherwise be emitted. We want to avoid
2090 having an FDE kept around when the function it refers to is
2091 discarded. Example where this matters: a primary function
2092 template in C++ requires EH information, but an explicit
2093 specialization doesn't. */
2094 if (TARGET_USES_WEAK_UNWIND_INFO
2095 && ! flag_asynchronous_unwind_tables
2096 && for_eh)
2097 for (i = 0; i < fde_table_in_use; i++)
2098 if ((fde_table[i].nothrow || fde_table[i].all_throwers_are_sibcalls)
2099 && !fde_table[i].uses_eh_lsda
2100 && ! DECL_WEAK (fde_table[i].decl))
2101 targetm.asm_out.unwind_label (asm_out_file, fde_table[i].decl,
2102 for_eh, /* empty */ 1);
2104 /* If we don't have any functions we'll want to unwind out of, don't
2105 emit any EH unwind information. Note that if exceptions aren't
2106 enabled, we won't have collected nothrow information, and if we
2107 asked for asynchronous tables, we always want this info. */
2108 if (for_eh)
2110 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables;
2112 for (i = 0; i < fde_table_in_use; i++)
2113 if (fde_table[i].uses_eh_lsda)
2114 any_eh_needed = any_lsda_needed = true;
2115 else if (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2116 any_eh_needed = true;
2117 else if (! fde_table[i].nothrow
2118 && ! fde_table[i].all_throwers_are_sibcalls)
2119 any_eh_needed = true;
2121 if (! any_eh_needed)
2122 return;
2125 /* We're going to be generating comments, so turn on app. */
2126 if (flag_debug_asm)
2127 app_enable ();
2129 if (for_eh)
2130 targetm.asm_out.eh_frame_section ();
2131 else
2132 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
2134 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
2135 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
2137 /* Output the CIE. */
2138 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
2139 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
2140 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2141 "Length of Common Information Entry");
2142 ASM_OUTPUT_LABEL (asm_out_file, l1);
2144 /* Now that the CIE pointer is PC-relative for EH,
2145 use 0 to identify the CIE. */
2146 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
2147 (for_eh ? 0 : DW_CIE_ID),
2148 "CIE Identifier Tag");
2150 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
2152 augmentation[0] = 0;
2153 augmentation_size = 0;
2154 if (for_eh)
2156 char *p;
2158 /* Augmentation:
2159 z Indicates that a uleb128 is present to size the
2160 augmentation section.
2161 L Indicates the encoding (and thus presence) of
2162 an LSDA pointer in the FDE augmentation.
2163 R Indicates a non-default pointer encoding for
2164 FDE code pointers.
2165 P Indicates the presence of an encoding + language
2166 personality routine in the CIE augmentation. */
2168 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
2169 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
2170 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
2172 p = augmentation + 1;
2173 if (eh_personality_libfunc)
2175 *p++ = 'P';
2176 augmentation_size += 1 + size_of_encoded_value (per_encoding);
2178 if (any_lsda_needed)
2180 *p++ = 'L';
2181 augmentation_size += 1;
2183 if (fde_encoding != DW_EH_PE_absptr)
2185 *p++ = 'R';
2186 augmentation_size += 1;
2188 if (p > augmentation + 1)
2190 augmentation[0] = 'z';
2191 *p = '\0';
2194 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
2195 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
2197 int offset = ( 4 /* Length */
2198 + 4 /* CIE Id */
2199 + 1 /* CIE version */
2200 + strlen (augmentation) + 1 /* Augmentation */
2201 + size_of_uleb128 (1) /* Code alignment */
2202 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
2203 + 1 /* RA column */
2204 + 1 /* Augmentation size */
2205 + 1 /* Personality encoding */ );
2206 int pad = -offset & (PTR_SIZE - 1);
2208 augmentation_size += pad;
2210 /* Augmentations should be small, so there's scarce need to
2211 iterate for a solution. Die if we exceed one uleb128 byte. */
2212 gcc_assert (size_of_uleb128 (augmentation_size) == 1);
2216 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
2217 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
2218 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
2219 "CIE Data Alignment Factor");
2221 return_reg = DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN, for_eh);
2222 if (DW_CIE_VERSION == 1)
2223 dw2_asm_output_data (1, return_reg, "CIE RA Column");
2224 else
2225 dw2_asm_output_data_uleb128 (return_reg, "CIE RA Column");
2227 if (augmentation[0])
2229 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
2230 if (eh_personality_libfunc)
2232 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
2233 eh_data_format_name (per_encoding));
2234 dw2_asm_output_encoded_addr_rtx (per_encoding,
2235 eh_personality_libfunc, NULL);
2238 if (any_lsda_needed)
2239 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
2240 eh_data_format_name (lsda_encoding));
2242 if (fde_encoding != DW_EH_PE_absptr)
2243 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
2244 eh_data_format_name (fde_encoding));
2247 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
2248 output_cfi (cfi, NULL, for_eh);
2250 /* Pad the CIE out to an address sized boundary. */
2251 ASM_OUTPUT_ALIGN (asm_out_file,
2252 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
2253 ASM_OUTPUT_LABEL (asm_out_file, l2);
2255 /* Loop through all of the FDE's. */
2256 for (i = 0; i < fde_table_in_use; i++)
2258 fde = &fde_table[i];
2260 /* Don't emit EH unwind info for leaf functions that don't need it. */
2261 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions
2262 && (fde->nothrow || fde->all_throwers_are_sibcalls)
2263 && ! (TARGET_USES_WEAK_UNWIND_INFO && DECL_WEAK (fde_table[i].decl))
2264 && !fde->uses_eh_lsda)
2265 continue;
2267 targetm.asm_out.unwind_label (asm_out_file, fde->decl, for_eh, /* empty */ 0);
2268 targetm.asm_out.internal_label (asm_out_file, FDE_LABEL, for_eh + i * 2);
2269 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
2270 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
2271 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
2272 "FDE Length");
2273 ASM_OUTPUT_LABEL (asm_out_file, l1);
2275 if (for_eh)
2276 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
2277 else
2278 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
2279 "FDE CIE offset");
2281 if (for_eh)
2283 rtx sym_ref = gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin);
2284 SYMBOL_REF_FLAGS (sym_ref) |= SYMBOL_FLAG_LOCAL;
2285 dw2_asm_output_encoded_addr_rtx (fde_encoding,
2286 sym_ref,
2287 "FDE initial location");
2288 if (fde->dw_fde_switched_sections)
2290 rtx sym_ref2 = gen_rtx_SYMBOL_REF (Pmode,
2291 fde->dw_fde_unlikely_section_label);
2292 rtx sym_ref3= gen_rtx_SYMBOL_REF (Pmode,
2293 fde->dw_fde_hot_section_label);
2294 SYMBOL_REF_FLAGS (sym_ref2) |= SYMBOL_FLAG_LOCAL;
2295 SYMBOL_REF_FLAGS (sym_ref3) |= SYMBOL_FLAG_LOCAL;
2296 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref3,
2297 "FDE initial location");
2298 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2299 fde->dw_fde_hot_section_end_label,
2300 fde->dw_fde_hot_section_label,
2301 "FDE address range");
2302 dw2_asm_output_encoded_addr_rtx (fde_encoding, sym_ref2,
2303 "FDE initial location");
2304 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2305 fde->dw_fde_unlikely_section_end_label,
2306 fde->dw_fde_unlikely_section_label,
2307 "FDE address range");
2309 else
2310 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
2311 fde->dw_fde_end, fde->dw_fde_begin,
2312 "FDE address range");
2314 else
2316 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
2317 "FDE initial location");
2318 if (fde->dw_fde_switched_sections)
2320 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2321 fde->dw_fde_hot_section_label,
2322 "FDE initial location");
2323 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2324 fde->dw_fde_hot_section_end_label,
2325 fde->dw_fde_hot_section_label,
2326 "FDE address range");
2327 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
2328 fde->dw_fde_unlikely_section_label,
2329 "FDE initial location");
2330 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2331 fde->dw_fde_unlikely_section_end_label,
2332 fde->dw_fde_unlikely_section_label,
2333 "FDE address range");
2335 else
2336 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
2337 fde->dw_fde_end, fde->dw_fde_begin,
2338 "FDE address range");
2341 if (augmentation[0])
2343 if (any_lsda_needed)
2345 int size = size_of_encoded_value (lsda_encoding);
2347 if (lsda_encoding == DW_EH_PE_aligned)
2349 int offset = ( 4 /* Length */
2350 + 4 /* CIE offset */
2351 + 2 * size_of_encoded_value (fde_encoding)
2352 + 1 /* Augmentation size */ );
2353 int pad = -offset & (PTR_SIZE - 1);
2355 size += pad;
2356 gcc_assert (size_of_uleb128 (size) == 1);
2359 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2361 if (fde->uses_eh_lsda)
2363 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2364 fde->funcdef_number);
2365 dw2_asm_output_encoded_addr_rtx (
2366 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2367 "Language Specific Data Area");
2369 else
2371 if (lsda_encoding == DW_EH_PE_aligned)
2372 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2373 dw2_asm_output_data
2374 (size_of_encoded_value (lsda_encoding), 0,
2375 "Language Specific Data Area (none)");
2378 else
2379 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2382 /* Loop through the Call Frame Instructions associated with
2383 this FDE. */
2384 fde->dw_fde_current_label = fde->dw_fde_begin;
2385 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2386 output_cfi (cfi, fde, for_eh);
2388 /* Pad the FDE out to an address sized boundary. */
2389 ASM_OUTPUT_ALIGN (asm_out_file,
2390 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2391 ASM_OUTPUT_LABEL (asm_out_file, l2);
2394 if (for_eh && targetm.terminate_dw2_eh_frame_info)
2395 dw2_asm_output_data (4, 0, "End of Table");
2396 #ifdef MIPS_DEBUGGING_INFO
2397 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2398 get a value of 0. Putting .align 0 after the label fixes it. */
2399 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2400 #endif
2402 /* Turn off app to make assembly quicker. */
2403 if (flag_debug_asm)
2404 app_disable ();
2407 /* Output a marker (i.e. a label) for the beginning of a function, before
2408 the prologue. */
2410 void
2411 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED,
2412 const char *file ATTRIBUTE_UNUSED)
2414 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2415 char * dup_label;
2416 dw_fde_ref fde;
2418 current_function_func_begin_label = NULL;
2420 #ifdef TARGET_UNWIND_INFO
2421 /* ??? current_function_func_begin_label is also used by except.c
2422 for call-site information. We must emit this label if it might
2423 be used. */
2424 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2425 && ! dwarf2out_do_frame ())
2426 return;
2427 #else
2428 if (! dwarf2out_do_frame ())
2429 return;
2430 #endif
2432 function_section (current_function_decl);
2433 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2434 current_function_funcdef_no);
2435 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2436 current_function_funcdef_no);
2437 dup_label = xstrdup (label);
2438 current_function_func_begin_label = dup_label;
2440 #ifdef TARGET_UNWIND_INFO
2441 /* We can elide the fde allocation if we're not emitting debug info. */
2442 if (! dwarf2out_do_frame ())
2443 return;
2444 #endif
2446 /* Expand the fde table if necessary. */
2447 if (fde_table_in_use == fde_table_allocated)
2449 fde_table_allocated += FDE_TABLE_INCREMENT;
2450 fde_table = ggc_realloc (fde_table,
2451 fde_table_allocated * sizeof (dw_fde_node));
2452 memset (fde_table + fde_table_in_use, 0,
2453 FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2456 /* Record the FDE associated with this function. */
2457 current_funcdef_fde = fde_table_in_use;
2459 /* Add the new FDE at the end of the fde_table. */
2460 fde = &fde_table[fde_table_in_use++];
2461 fde->decl = current_function_decl;
2462 fde->dw_fde_begin = dup_label;
2463 fde->dw_fde_current_label = NULL;
2464 fde->dw_fde_hot_section_label = NULL;
2465 fde->dw_fde_hot_section_end_label = NULL;
2466 fde->dw_fde_unlikely_section_label = NULL;
2467 fde->dw_fde_unlikely_section_end_label = NULL;
2468 fde->dw_fde_switched_sections = false;
2469 fde->dw_fde_end = NULL;
2470 fde->dw_fde_cfi = NULL;
2471 fde->funcdef_number = current_function_funcdef_no;
2472 fde->nothrow = TREE_NOTHROW (current_function_decl);
2473 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2474 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls;
2476 args_size = old_args_size = 0;
2478 /* We only want to output line number information for the genuine dwarf2
2479 prologue case, not the eh frame case. */
2480 #ifdef DWARF2_DEBUGGING_INFO
2481 if (file)
2482 dwarf2out_source_line (line, file);
2483 #endif
2486 /* Output a marker (i.e. a label) for the absolute end of the generated code
2487 for a function definition. This gets called *after* the epilogue code has
2488 been generated. */
2490 void
2491 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
2492 const char *file ATTRIBUTE_UNUSED)
2494 dw_fde_ref fde;
2495 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2497 /* Output a label to mark the endpoint of the code generated for this
2498 function. */
2499 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL,
2500 current_function_funcdef_no);
2501 ASM_OUTPUT_LABEL (asm_out_file, label);
2502 fde = &fde_table[fde_table_in_use - 1];
2503 fde->dw_fde_end = xstrdup (label);
2506 void
2507 dwarf2out_frame_init (void)
2509 /* Allocate the initial hunk of the fde_table. */
2510 fde_table = ggc_alloc_cleared (FDE_TABLE_INCREMENT * sizeof (dw_fde_node));
2511 fde_table_allocated = FDE_TABLE_INCREMENT;
2512 fde_table_in_use = 0;
2514 /* Generate the CFA instructions common to all FDE's. Do it now for the
2515 sake of lookup_cfa. */
2517 #ifdef DWARF2_UNWIND_INFO
2518 /* On entry, the Canonical Frame Address is at SP. */
2519 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2520 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2521 #endif
2524 void
2525 dwarf2out_frame_finish (void)
2527 /* Output call frame information. */
2528 if (write_symbols == DWARF2_DEBUG
2529 || write_symbols == VMS_AND_DWARF2_DEBUG
2530 #ifdef DWARF2_FRAME_INFO
2531 || DWARF2_FRAME_INFO
2532 #endif
2534 output_call_frame_info (0);
2536 #ifndef TARGET_UNWIND_INFO
2537 /* Output another copy for the unwinder. */
2538 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2539 output_call_frame_info (1);
2540 #endif
2542 #endif
2544 /* And now, the subset of the debugging information support code necessary
2545 for emitting location expressions. */
2547 /* We need some way to distinguish DW_OP_addr with a direct symbol
2548 relocation from DW_OP_addr with a dtp-relative symbol relocation. */
2549 #define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr)
2552 typedef struct dw_val_struct *dw_val_ref;
2553 typedef struct die_struct *dw_die_ref;
2554 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2555 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2557 /* Each DIE may have a series of attribute/value pairs. Values
2558 can take on several forms. The forms that are used in this
2559 implementation are listed below. */
2561 enum dw_val_class
2563 dw_val_class_addr,
2564 dw_val_class_offset,
2565 dw_val_class_loc,
2566 dw_val_class_loc_list,
2567 dw_val_class_range_list,
2568 dw_val_class_const,
2569 dw_val_class_unsigned_const,
2570 dw_val_class_long_long,
2571 dw_val_class_vec,
2572 dw_val_class_flag,
2573 dw_val_class_die_ref,
2574 dw_val_class_fde_ref,
2575 dw_val_class_lbl_id,
2576 dw_val_class_lbl_offset,
2577 dw_val_class_str
2580 /* Describe a double word constant value. */
2581 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2583 typedef struct dw_long_long_struct GTY(())
2585 unsigned long hi;
2586 unsigned long low;
2588 dw_long_long_const;
2590 /* Describe a floating point constant value, or a vector constant value. */
2592 typedef struct dw_vec_struct GTY(())
2594 unsigned char * GTY((length ("%h.length"))) array;
2595 unsigned length;
2596 unsigned elt_size;
2598 dw_vec_const;
2600 /* The dw_val_node describes an attribute's value, as it is
2601 represented internally. */
2603 typedef struct dw_val_struct GTY(())
2605 enum dw_val_class val_class;
2606 union dw_val_struct_union
2608 rtx GTY ((tag ("dw_val_class_addr"))) val_addr;
2609 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_offset"))) val_offset;
2610 dw_loc_list_ref GTY ((tag ("dw_val_class_loc_list"))) val_loc_list;
2611 dw_loc_descr_ref GTY ((tag ("dw_val_class_loc"))) val_loc;
2612 HOST_WIDE_INT GTY ((default)) val_int;
2613 unsigned HOST_WIDE_INT GTY ((tag ("dw_val_class_unsigned_const"))) val_unsigned;
2614 dw_long_long_const GTY ((tag ("dw_val_class_long_long"))) val_long_long;
2615 dw_vec_const GTY ((tag ("dw_val_class_vec"))) val_vec;
2616 struct dw_val_die_union
2618 dw_die_ref die;
2619 int external;
2620 } GTY ((tag ("dw_val_class_die_ref"))) val_die_ref;
2621 unsigned GTY ((tag ("dw_val_class_fde_ref"))) val_fde_index;
2622 struct indirect_string_node * GTY ((tag ("dw_val_class_str"))) val_str;
2623 char * GTY ((tag ("dw_val_class_lbl_id"))) val_lbl_id;
2624 unsigned char GTY ((tag ("dw_val_class_flag"))) val_flag;
2626 GTY ((desc ("%1.val_class"))) v;
2628 dw_val_node;
2630 /* Locations in memory are described using a sequence of stack machine
2631 operations. */
2633 typedef struct dw_loc_descr_struct GTY(())
2635 dw_loc_descr_ref dw_loc_next;
2636 enum dwarf_location_atom dw_loc_opc;
2637 dw_val_node dw_loc_oprnd1;
2638 dw_val_node dw_loc_oprnd2;
2639 int dw_loc_addr;
2641 dw_loc_descr_node;
2643 /* Location lists are ranges + location descriptions for that range,
2644 so you can track variables that are in different places over
2645 their entire life. */
2646 typedef struct dw_loc_list_struct GTY(())
2648 dw_loc_list_ref dw_loc_next;
2649 const char *begin; /* Label for begin address of range */
2650 const char *end; /* Label for end address of range */
2651 char *ll_symbol; /* Label for beginning of location list.
2652 Only on head of list */
2653 const char *section; /* Section this loclist is relative to */
2654 dw_loc_descr_ref expr;
2655 } dw_loc_list_node;
2657 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
2659 static const char *dwarf_stack_op_name (unsigned);
2660 static dw_loc_descr_ref new_loc_descr (enum dwarf_location_atom,
2661 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
2662 static void add_loc_descr (dw_loc_descr_ref *, dw_loc_descr_ref);
2663 static unsigned long size_of_loc_descr (dw_loc_descr_ref);
2664 static unsigned long size_of_locs (dw_loc_descr_ref);
2665 static void output_loc_operands (dw_loc_descr_ref);
2666 static void output_loc_sequence (dw_loc_descr_ref);
2668 /* Convert a DWARF stack opcode into its string name. */
2670 static const char *
2671 dwarf_stack_op_name (unsigned int op)
2673 switch (op)
2675 case DW_OP_addr:
2676 case INTERNAL_DW_OP_tls_addr:
2677 return "DW_OP_addr";
2678 case DW_OP_deref:
2679 return "DW_OP_deref";
2680 case DW_OP_const1u:
2681 return "DW_OP_const1u";
2682 case DW_OP_const1s:
2683 return "DW_OP_const1s";
2684 case DW_OP_const2u:
2685 return "DW_OP_const2u";
2686 case DW_OP_const2s:
2687 return "DW_OP_const2s";
2688 case DW_OP_const4u:
2689 return "DW_OP_const4u";
2690 case DW_OP_const4s:
2691 return "DW_OP_const4s";
2692 case DW_OP_const8u:
2693 return "DW_OP_const8u";
2694 case DW_OP_const8s:
2695 return "DW_OP_const8s";
2696 case DW_OP_constu:
2697 return "DW_OP_constu";
2698 case DW_OP_consts:
2699 return "DW_OP_consts";
2700 case DW_OP_dup:
2701 return "DW_OP_dup";
2702 case DW_OP_drop:
2703 return "DW_OP_drop";
2704 case DW_OP_over:
2705 return "DW_OP_over";
2706 case DW_OP_pick:
2707 return "DW_OP_pick";
2708 case DW_OP_swap:
2709 return "DW_OP_swap";
2710 case DW_OP_rot:
2711 return "DW_OP_rot";
2712 case DW_OP_xderef:
2713 return "DW_OP_xderef";
2714 case DW_OP_abs:
2715 return "DW_OP_abs";
2716 case DW_OP_and:
2717 return "DW_OP_and";
2718 case DW_OP_div:
2719 return "DW_OP_div";
2720 case DW_OP_minus:
2721 return "DW_OP_minus";
2722 case DW_OP_mod:
2723 return "DW_OP_mod";
2724 case DW_OP_mul:
2725 return "DW_OP_mul";
2726 case DW_OP_neg:
2727 return "DW_OP_neg";
2728 case DW_OP_not:
2729 return "DW_OP_not";
2730 case DW_OP_or:
2731 return "DW_OP_or";
2732 case DW_OP_plus:
2733 return "DW_OP_plus";
2734 case DW_OP_plus_uconst:
2735 return "DW_OP_plus_uconst";
2736 case DW_OP_shl:
2737 return "DW_OP_shl";
2738 case DW_OP_shr:
2739 return "DW_OP_shr";
2740 case DW_OP_shra:
2741 return "DW_OP_shra";
2742 case DW_OP_xor:
2743 return "DW_OP_xor";
2744 case DW_OP_bra:
2745 return "DW_OP_bra";
2746 case DW_OP_eq:
2747 return "DW_OP_eq";
2748 case DW_OP_ge:
2749 return "DW_OP_ge";
2750 case DW_OP_gt:
2751 return "DW_OP_gt";
2752 case DW_OP_le:
2753 return "DW_OP_le";
2754 case DW_OP_lt:
2755 return "DW_OP_lt";
2756 case DW_OP_ne:
2757 return "DW_OP_ne";
2758 case DW_OP_skip:
2759 return "DW_OP_skip";
2760 case DW_OP_lit0:
2761 return "DW_OP_lit0";
2762 case DW_OP_lit1:
2763 return "DW_OP_lit1";
2764 case DW_OP_lit2:
2765 return "DW_OP_lit2";
2766 case DW_OP_lit3:
2767 return "DW_OP_lit3";
2768 case DW_OP_lit4:
2769 return "DW_OP_lit4";
2770 case DW_OP_lit5:
2771 return "DW_OP_lit5";
2772 case DW_OP_lit6:
2773 return "DW_OP_lit6";
2774 case DW_OP_lit7:
2775 return "DW_OP_lit7";
2776 case DW_OP_lit8:
2777 return "DW_OP_lit8";
2778 case DW_OP_lit9:
2779 return "DW_OP_lit9";
2780 case DW_OP_lit10:
2781 return "DW_OP_lit10";
2782 case DW_OP_lit11:
2783 return "DW_OP_lit11";
2784 case DW_OP_lit12:
2785 return "DW_OP_lit12";
2786 case DW_OP_lit13:
2787 return "DW_OP_lit13";
2788 case DW_OP_lit14:
2789 return "DW_OP_lit14";
2790 case DW_OP_lit15:
2791 return "DW_OP_lit15";
2792 case DW_OP_lit16:
2793 return "DW_OP_lit16";
2794 case DW_OP_lit17:
2795 return "DW_OP_lit17";
2796 case DW_OP_lit18:
2797 return "DW_OP_lit18";
2798 case DW_OP_lit19:
2799 return "DW_OP_lit19";
2800 case DW_OP_lit20:
2801 return "DW_OP_lit20";
2802 case DW_OP_lit21:
2803 return "DW_OP_lit21";
2804 case DW_OP_lit22:
2805 return "DW_OP_lit22";
2806 case DW_OP_lit23:
2807 return "DW_OP_lit23";
2808 case DW_OP_lit24:
2809 return "DW_OP_lit24";
2810 case DW_OP_lit25:
2811 return "DW_OP_lit25";
2812 case DW_OP_lit26:
2813 return "DW_OP_lit26";
2814 case DW_OP_lit27:
2815 return "DW_OP_lit27";
2816 case DW_OP_lit28:
2817 return "DW_OP_lit28";
2818 case DW_OP_lit29:
2819 return "DW_OP_lit29";
2820 case DW_OP_lit30:
2821 return "DW_OP_lit30";
2822 case DW_OP_lit31:
2823 return "DW_OP_lit31";
2824 case DW_OP_reg0:
2825 return "DW_OP_reg0";
2826 case DW_OP_reg1:
2827 return "DW_OP_reg1";
2828 case DW_OP_reg2:
2829 return "DW_OP_reg2";
2830 case DW_OP_reg3:
2831 return "DW_OP_reg3";
2832 case DW_OP_reg4:
2833 return "DW_OP_reg4";
2834 case DW_OP_reg5:
2835 return "DW_OP_reg5";
2836 case DW_OP_reg6:
2837 return "DW_OP_reg6";
2838 case DW_OP_reg7:
2839 return "DW_OP_reg7";
2840 case DW_OP_reg8:
2841 return "DW_OP_reg8";
2842 case DW_OP_reg9:
2843 return "DW_OP_reg9";
2844 case DW_OP_reg10:
2845 return "DW_OP_reg10";
2846 case DW_OP_reg11:
2847 return "DW_OP_reg11";
2848 case DW_OP_reg12:
2849 return "DW_OP_reg12";
2850 case DW_OP_reg13:
2851 return "DW_OP_reg13";
2852 case DW_OP_reg14:
2853 return "DW_OP_reg14";
2854 case DW_OP_reg15:
2855 return "DW_OP_reg15";
2856 case DW_OP_reg16:
2857 return "DW_OP_reg16";
2858 case DW_OP_reg17:
2859 return "DW_OP_reg17";
2860 case DW_OP_reg18:
2861 return "DW_OP_reg18";
2862 case DW_OP_reg19:
2863 return "DW_OP_reg19";
2864 case DW_OP_reg20:
2865 return "DW_OP_reg20";
2866 case DW_OP_reg21:
2867 return "DW_OP_reg21";
2868 case DW_OP_reg22:
2869 return "DW_OP_reg22";
2870 case DW_OP_reg23:
2871 return "DW_OP_reg23";
2872 case DW_OP_reg24:
2873 return "DW_OP_reg24";
2874 case DW_OP_reg25:
2875 return "DW_OP_reg25";
2876 case DW_OP_reg26:
2877 return "DW_OP_reg26";
2878 case DW_OP_reg27:
2879 return "DW_OP_reg27";
2880 case DW_OP_reg28:
2881 return "DW_OP_reg28";
2882 case DW_OP_reg29:
2883 return "DW_OP_reg29";
2884 case DW_OP_reg30:
2885 return "DW_OP_reg30";
2886 case DW_OP_reg31:
2887 return "DW_OP_reg31";
2888 case DW_OP_breg0:
2889 return "DW_OP_breg0";
2890 case DW_OP_breg1:
2891 return "DW_OP_breg1";
2892 case DW_OP_breg2:
2893 return "DW_OP_breg2";
2894 case DW_OP_breg3:
2895 return "DW_OP_breg3";
2896 case DW_OP_breg4:
2897 return "DW_OP_breg4";
2898 case DW_OP_breg5:
2899 return "DW_OP_breg5";
2900 case DW_OP_breg6:
2901 return "DW_OP_breg6";
2902 case DW_OP_breg7:
2903 return "DW_OP_breg7";
2904 case DW_OP_breg8:
2905 return "DW_OP_breg8";
2906 case DW_OP_breg9:
2907 return "DW_OP_breg9";
2908 case DW_OP_breg10:
2909 return "DW_OP_breg10";
2910 case DW_OP_breg11:
2911 return "DW_OP_breg11";
2912 case DW_OP_breg12:
2913 return "DW_OP_breg12";
2914 case DW_OP_breg13:
2915 return "DW_OP_breg13";
2916 case DW_OP_breg14:
2917 return "DW_OP_breg14";
2918 case DW_OP_breg15:
2919 return "DW_OP_breg15";
2920 case DW_OP_breg16:
2921 return "DW_OP_breg16";
2922 case DW_OP_breg17:
2923 return "DW_OP_breg17";
2924 case DW_OP_breg18:
2925 return "DW_OP_breg18";
2926 case DW_OP_breg19:
2927 return "DW_OP_breg19";
2928 case DW_OP_breg20:
2929 return "DW_OP_breg20";
2930 case DW_OP_breg21:
2931 return "DW_OP_breg21";
2932 case DW_OP_breg22:
2933 return "DW_OP_breg22";
2934 case DW_OP_breg23:
2935 return "DW_OP_breg23";
2936 case DW_OP_breg24:
2937 return "DW_OP_breg24";
2938 case DW_OP_breg25:
2939 return "DW_OP_breg25";
2940 case DW_OP_breg26:
2941 return "DW_OP_breg26";
2942 case DW_OP_breg27:
2943 return "DW_OP_breg27";
2944 case DW_OP_breg28:
2945 return "DW_OP_breg28";
2946 case DW_OP_breg29:
2947 return "DW_OP_breg29";
2948 case DW_OP_breg30:
2949 return "DW_OP_breg30";
2950 case DW_OP_breg31:
2951 return "DW_OP_breg31";
2952 case DW_OP_regx:
2953 return "DW_OP_regx";
2954 case DW_OP_fbreg:
2955 return "DW_OP_fbreg";
2956 case DW_OP_bregx:
2957 return "DW_OP_bregx";
2958 case DW_OP_piece:
2959 return "DW_OP_piece";
2960 case DW_OP_deref_size:
2961 return "DW_OP_deref_size";
2962 case DW_OP_xderef_size:
2963 return "DW_OP_xderef_size";
2964 case DW_OP_nop:
2965 return "DW_OP_nop";
2966 case DW_OP_push_object_address:
2967 return "DW_OP_push_object_address";
2968 case DW_OP_call2:
2969 return "DW_OP_call2";
2970 case DW_OP_call4:
2971 return "DW_OP_call4";
2972 case DW_OP_call_ref:
2973 return "DW_OP_call_ref";
2974 case DW_OP_GNU_push_tls_address:
2975 return "DW_OP_GNU_push_tls_address";
2976 default:
2977 return "OP_<unknown>";
2981 /* Return a pointer to a newly allocated location description. Location
2982 descriptions are simple expression terms that can be strung
2983 together to form more complicated location (address) descriptions. */
2985 static inline dw_loc_descr_ref
2986 new_loc_descr (enum dwarf_location_atom op, unsigned HOST_WIDE_INT oprnd1,
2987 unsigned HOST_WIDE_INT oprnd2)
2989 dw_loc_descr_ref descr = ggc_alloc_cleared (sizeof (dw_loc_descr_node));
2991 descr->dw_loc_opc = op;
2992 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2993 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2994 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2995 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2997 return descr;
3000 /* Add a location description term to a location description expression. */
3002 static inline void
3003 add_loc_descr (dw_loc_descr_ref *list_head, dw_loc_descr_ref descr)
3005 dw_loc_descr_ref *d;
3007 /* Find the end of the chain. */
3008 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
3011 *d = descr;
3014 /* Return the size of a location descriptor. */
3016 static unsigned long
3017 size_of_loc_descr (dw_loc_descr_ref loc)
3019 unsigned long size = 1;
3021 switch (loc->dw_loc_opc)
3023 case DW_OP_addr:
3024 case INTERNAL_DW_OP_tls_addr:
3025 size += DWARF2_ADDR_SIZE;
3026 break;
3027 case DW_OP_const1u:
3028 case DW_OP_const1s:
3029 size += 1;
3030 break;
3031 case DW_OP_const2u:
3032 case DW_OP_const2s:
3033 size += 2;
3034 break;
3035 case DW_OP_const4u:
3036 case DW_OP_const4s:
3037 size += 4;
3038 break;
3039 case DW_OP_const8u:
3040 case DW_OP_const8s:
3041 size += 8;
3042 break;
3043 case DW_OP_constu:
3044 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3045 break;
3046 case DW_OP_consts:
3047 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3048 break;
3049 case DW_OP_pick:
3050 size += 1;
3051 break;
3052 case DW_OP_plus_uconst:
3053 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3054 break;
3055 case DW_OP_skip:
3056 case DW_OP_bra:
3057 size += 2;
3058 break;
3059 case DW_OP_breg0:
3060 case DW_OP_breg1:
3061 case DW_OP_breg2:
3062 case DW_OP_breg3:
3063 case DW_OP_breg4:
3064 case DW_OP_breg5:
3065 case DW_OP_breg6:
3066 case DW_OP_breg7:
3067 case DW_OP_breg8:
3068 case DW_OP_breg9:
3069 case DW_OP_breg10:
3070 case DW_OP_breg11:
3071 case DW_OP_breg12:
3072 case DW_OP_breg13:
3073 case DW_OP_breg14:
3074 case DW_OP_breg15:
3075 case DW_OP_breg16:
3076 case DW_OP_breg17:
3077 case DW_OP_breg18:
3078 case DW_OP_breg19:
3079 case DW_OP_breg20:
3080 case DW_OP_breg21:
3081 case DW_OP_breg22:
3082 case DW_OP_breg23:
3083 case DW_OP_breg24:
3084 case DW_OP_breg25:
3085 case DW_OP_breg26:
3086 case DW_OP_breg27:
3087 case DW_OP_breg28:
3088 case DW_OP_breg29:
3089 case DW_OP_breg30:
3090 case DW_OP_breg31:
3091 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3092 break;
3093 case DW_OP_regx:
3094 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3095 break;
3096 case DW_OP_fbreg:
3097 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
3098 break;
3099 case DW_OP_bregx:
3100 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3101 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
3102 break;
3103 case DW_OP_piece:
3104 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
3105 break;
3106 case DW_OP_deref_size:
3107 case DW_OP_xderef_size:
3108 size += 1;
3109 break;
3110 case DW_OP_call2:
3111 size += 2;
3112 break;
3113 case DW_OP_call4:
3114 size += 4;
3115 break;
3116 case DW_OP_call_ref:
3117 size += DWARF2_ADDR_SIZE;
3118 break;
3119 default:
3120 break;
3123 return size;
3126 /* Return the size of a series of location descriptors. */
3128 static unsigned long
3129 size_of_locs (dw_loc_descr_ref loc)
3131 unsigned long size;
3133 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
3135 loc->dw_loc_addr = size;
3136 size += size_of_loc_descr (loc);
3139 return size;
3142 /* Output location description stack opcode's operands (if any). */
3144 static void
3145 output_loc_operands (dw_loc_descr_ref loc)
3147 dw_val_ref val1 = &loc->dw_loc_oprnd1;
3148 dw_val_ref val2 = &loc->dw_loc_oprnd2;
3150 switch (loc->dw_loc_opc)
3152 #ifdef DWARF2_DEBUGGING_INFO
3153 case DW_OP_addr:
3154 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
3155 break;
3156 case DW_OP_const2u:
3157 case DW_OP_const2s:
3158 dw2_asm_output_data (2, val1->v.val_int, NULL);
3159 break;
3160 case DW_OP_const4u:
3161 case DW_OP_const4s:
3162 dw2_asm_output_data (4, val1->v.val_int, NULL);
3163 break;
3164 case DW_OP_const8u:
3165 case DW_OP_const8s:
3166 gcc_assert (HOST_BITS_PER_LONG >= 64);
3167 dw2_asm_output_data (8, val1->v.val_int, NULL);
3168 break;
3169 case DW_OP_skip:
3170 case DW_OP_bra:
3172 int offset;
3174 gcc_assert (val1->val_class == dw_val_class_loc);
3175 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
3177 dw2_asm_output_data (2, offset, NULL);
3179 break;
3180 #else
3181 case DW_OP_addr:
3182 case DW_OP_const2u:
3183 case DW_OP_const2s:
3184 case DW_OP_const4u:
3185 case DW_OP_const4s:
3186 case DW_OP_const8u:
3187 case DW_OP_const8s:
3188 case DW_OP_skip:
3189 case DW_OP_bra:
3190 /* We currently don't make any attempt to make sure these are
3191 aligned properly like we do for the main unwind info, so
3192 don't support emitting things larger than a byte if we're
3193 only doing unwinding. */
3194 gcc_unreachable ();
3195 #endif
3196 case DW_OP_const1u:
3197 case DW_OP_const1s:
3198 dw2_asm_output_data (1, val1->v.val_int, NULL);
3199 break;
3200 case DW_OP_constu:
3201 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3202 break;
3203 case DW_OP_consts:
3204 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3205 break;
3206 case DW_OP_pick:
3207 dw2_asm_output_data (1, val1->v.val_int, NULL);
3208 break;
3209 case DW_OP_plus_uconst:
3210 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3211 break;
3212 case DW_OP_breg0:
3213 case DW_OP_breg1:
3214 case DW_OP_breg2:
3215 case DW_OP_breg3:
3216 case DW_OP_breg4:
3217 case DW_OP_breg5:
3218 case DW_OP_breg6:
3219 case DW_OP_breg7:
3220 case DW_OP_breg8:
3221 case DW_OP_breg9:
3222 case DW_OP_breg10:
3223 case DW_OP_breg11:
3224 case DW_OP_breg12:
3225 case DW_OP_breg13:
3226 case DW_OP_breg14:
3227 case DW_OP_breg15:
3228 case DW_OP_breg16:
3229 case DW_OP_breg17:
3230 case DW_OP_breg18:
3231 case DW_OP_breg19:
3232 case DW_OP_breg20:
3233 case DW_OP_breg21:
3234 case DW_OP_breg22:
3235 case DW_OP_breg23:
3236 case DW_OP_breg24:
3237 case DW_OP_breg25:
3238 case DW_OP_breg26:
3239 case DW_OP_breg27:
3240 case DW_OP_breg28:
3241 case DW_OP_breg29:
3242 case DW_OP_breg30:
3243 case DW_OP_breg31:
3244 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3245 break;
3246 case DW_OP_regx:
3247 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3248 break;
3249 case DW_OP_fbreg:
3250 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
3251 break;
3252 case DW_OP_bregx:
3253 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3254 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
3255 break;
3256 case DW_OP_piece:
3257 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
3258 break;
3259 case DW_OP_deref_size:
3260 case DW_OP_xderef_size:
3261 dw2_asm_output_data (1, val1->v.val_int, NULL);
3262 break;
3264 case INTERNAL_DW_OP_tls_addr:
3265 if (targetm.asm_out.output_dwarf_dtprel)
3267 targetm.asm_out.output_dwarf_dtprel (asm_out_file,
3268 DWARF2_ADDR_SIZE,
3269 val1->v.val_addr);
3270 fputc ('\n', asm_out_file);
3272 else
3273 gcc_unreachable ();
3274 break;
3276 default:
3277 /* Other codes have no operands. */
3278 break;
3282 /* Output a sequence of location operations. */
3284 static void
3285 output_loc_sequence (dw_loc_descr_ref loc)
3287 for (; loc != NULL; loc = loc->dw_loc_next)
3289 /* Output the opcode. */
3290 dw2_asm_output_data (1, loc->dw_loc_opc,
3291 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
3293 /* Output the operand(s) (if any). */
3294 output_loc_operands (loc);
3298 /* This routine will generate the correct assembly data for a location
3299 description based on a cfi entry with a complex address. */
3301 static void
3302 output_cfa_loc (dw_cfi_ref cfi)
3304 dw_loc_descr_ref loc;
3305 unsigned long size;
3307 /* Output the size of the block. */
3308 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
3309 size = size_of_locs (loc);
3310 dw2_asm_output_data_uleb128 (size, NULL);
3312 /* Now output the operations themselves. */
3313 output_loc_sequence (loc);
3316 /* This function builds a dwarf location descriptor sequence from
3317 a dw_cfa_location. */
3319 static struct dw_loc_descr_struct *
3320 build_cfa_loc (dw_cfa_location *cfa)
3322 struct dw_loc_descr_struct *head, *tmp;
3324 gcc_assert (cfa->indirect);
3326 if (cfa->base_offset)
3328 if (cfa->reg <= 31)
3329 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
3330 else
3331 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
3333 else if (cfa->reg <= 31)
3334 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
3335 else
3336 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
3338 head->dw_loc_oprnd1.val_class = dw_val_class_const;
3339 tmp = new_loc_descr (DW_OP_deref, 0, 0);
3340 add_loc_descr (&head, tmp);
3341 if (cfa->offset != 0)
3343 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
3344 add_loc_descr (&head, tmp);
3347 return head;
3350 /* This function fills in aa dw_cfa_location structure from a dwarf location
3351 descriptor sequence. */
3353 static void
3354 get_cfa_from_loc_descr (dw_cfa_location *cfa, struct dw_loc_descr_struct *loc)
3356 struct dw_loc_descr_struct *ptr;
3357 cfa->offset = 0;
3358 cfa->base_offset = 0;
3359 cfa->indirect = 0;
3360 cfa->reg = -1;
3362 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
3364 enum dwarf_location_atom op = ptr->dw_loc_opc;
3366 switch (op)
3368 case DW_OP_reg0:
3369 case DW_OP_reg1:
3370 case DW_OP_reg2:
3371 case DW_OP_reg3:
3372 case DW_OP_reg4:
3373 case DW_OP_reg5:
3374 case DW_OP_reg6:
3375 case DW_OP_reg7:
3376 case DW_OP_reg8:
3377 case DW_OP_reg9:
3378 case DW_OP_reg10:
3379 case DW_OP_reg11:
3380 case DW_OP_reg12:
3381 case DW_OP_reg13:
3382 case DW_OP_reg14:
3383 case DW_OP_reg15:
3384 case DW_OP_reg16:
3385 case DW_OP_reg17:
3386 case DW_OP_reg18:
3387 case DW_OP_reg19:
3388 case DW_OP_reg20:
3389 case DW_OP_reg21:
3390 case DW_OP_reg22:
3391 case DW_OP_reg23:
3392 case DW_OP_reg24:
3393 case DW_OP_reg25:
3394 case DW_OP_reg26:
3395 case DW_OP_reg27:
3396 case DW_OP_reg28:
3397 case DW_OP_reg29:
3398 case DW_OP_reg30:
3399 case DW_OP_reg31:
3400 cfa->reg = op - DW_OP_reg0;
3401 break;
3402 case DW_OP_regx:
3403 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3404 break;
3405 case DW_OP_breg0:
3406 case DW_OP_breg1:
3407 case DW_OP_breg2:
3408 case DW_OP_breg3:
3409 case DW_OP_breg4:
3410 case DW_OP_breg5:
3411 case DW_OP_breg6:
3412 case DW_OP_breg7:
3413 case DW_OP_breg8:
3414 case DW_OP_breg9:
3415 case DW_OP_breg10:
3416 case DW_OP_breg11:
3417 case DW_OP_breg12:
3418 case DW_OP_breg13:
3419 case DW_OP_breg14:
3420 case DW_OP_breg15:
3421 case DW_OP_breg16:
3422 case DW_OP_breg17:
3423 case DW_OP_breg18:
3424 case DW_OP_breg19:
3425 case DW_OP_breg20:
3426 case DW_OP_breg21:
3427 case DW_OP_breg22:
3428 case DW_OP_breg23:
3429 case DW_OP_breg24:
3430 case DW_OP_breg25:
3431 case DW_OP_breg26:
3432 case DW_OP_breg27:
3433 case DW_OP_breg28:
3434 case DW_OP_breg29:
3435 case DW_OP_breg30:
3436 case DW_OP_breg31:
3437 cfa->reg = op - DW_OP_breg0;
3438 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3439 break;
3440 case DW_OP_bregx:
3441 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3442 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3443 break;
3444 case DW_OP_deref:
3445 cfa->indirect = 1;
3446 break;
3447 case DW_OP_plus_uconst:
3448 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3449 break;
3450 default:
3451 internal_error ("DW_LOC_OP %s not implemented",
3452 dwarf_stack_op_name (ptr->dw_loc_opc));
3456 #endif /* .debug_frame support */
3458 /* And now, the support for symbolic debugging information. */
3459 #ifdef DWARF2_DEBUGGING_INFO
3461 /* .debug_str support. */
3462 static int output_indirect_string (void **, void *);
3464 static void dwarf2out_init (const char *);
3465 static void dwarf2out_finish (const char *);
3466 static void dwarf2out_define (unsigned int, const char *);
3467 static void dwarf2out_undef (unsigned int, const char *);
3468 static void dwarf2out_start_source_file (unsigned, const char *);
3469 static void dwarf2out_end_source_file (unsigned);
3470 static void dwarf2out_begin_block (unsigned, unsigned);
3471 static void dwarf2out_end_block (unsigned, unsigned);
3472 static bool dwarf2out_ignore_block (tree);
3473 static void dwarf2out_global_decl (tree);
3474 static void dwarf2out_type_decl (tree, int);
3475 static void dwarf2out_imported_module_or_decl (tree, tree);
3476 static void dwarf2out_abstract_function (tree);
3477 static void dwarf2out_var_location (rtx);
3478 static void dwarf2out_begin_function (tree);
3479 static void dwarf2out_switch_text_section (void);
3481 /* The debug hooks structure. */
3483 const struct gcc_debug_hooks dwarf2_debug_hooks =
3485 dwarf2out_init,
3486 dwarf2out_finish,
3487 dwarf2out_define,
3488 dwarf2out_undef,
3489 dwarf2out_start_source_file,
3490 dwarf2out_end_source_file,
3491 dwarf2out_begin_block,
3492 dwarf2out_end_block,
3493 dwarf2out_ignore_block,
3494 dwarf2out_source_line,
3495 dwarf2out_begin_prologue,
3496 debug_nothing_int_charstar, /* end_prologue */
3497 dwarf2out_end_epilogue,
3498 dwarf2out_begin_function,
3499 debug_nothing_int, /* end_function */
3500 dwarf2out_decl, /* function_decl */
3501 dwarf2out_global_decl,
3502 dwarf2out_type_decl, /* type_decl */
3503 dwarf2out_imported_module_or_decl,
3504 debug_nothing_tree, /* deferred_inline_function */
3505 /* The DWARF 2 backend tries to reduce debugging bloat by not
3506 emitting the abstract description of inline functions until
3507 something tries to reference them. */
3508 dwarf2out_abstract_function, /* outlining_inline_function */
3509 debug_nothing_rtx, /* label */
3510 debug_nothing_int, /* handle_pch */
3511 dwarf2out_var_location,
3512 dwarf2out_switch_text_section,
3513 1 /* start_end_main_source_file */
3515 #endif
3517 /* NOTE: In the comments in this file, many references are made to
3518 "Debugging Information Entries". This term is abbreviated as `DIE'
3519 throughout the remainder of this file. */
3521 /* An internal representation of the DWARF output is built, and then
3522 walked to generate the DWARF debugging info. The walk of the internal
3523 representation is done after the entire program has been compiled.
3524 The types below are used to describe the internal representation. */
3526 /* Various DIE's use offsets relative to the beginning of the
3527 .debug_info section to refer to each other. */
3529 typedef long int dw_offset;
3531 /* Define typedefs here to avoid circular dependencies. */
3533 typedef struct dw_attr_struct *dw_attr_ref;
3534 typedef struct dw_line_info_struct *dw_line_info_ref;
3535 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3536 typedef struct pubname_struct *pubname_ref;
3537 typedef struct dw_ranges_struct *dw_ranges_ref;
3539 /* Each entry in the line_info_table maintains the file and
3540 line number associated with the label generated for that
3541 entry. The label gives the PC value associated with
3542 the line number entry. */
3544 typedef struct dw_line_info_struct GTY(())
3546 unsigned long dw_file_num;
3547 unsigned long dw_line_num;
3549 dw_line_info_entry;
3551 /* Line information for functions in separate sections; each one gets its
3552 own sequence. */
3553 typedef struct dw_separate_line_info_struct GTY(())
3555 unsigned long dw_file_num;
3556 unsigned long dw_line_num;
3557 unsigned long function;
3559 dw_separate_line_info_entry;
3561 /* Each DIE attribute has a field specifying the attribute kind,
3562 a link to the next attribute in the chain, and an attribute value.
3563 Attributes are typically linked below the DIE they modify. */
3565 typedef struct dw_attr_struct GTY(())
3567 enum dwarf_attribute dw_attr;
3568 dw_attr_ref dw_attr_next;
3569 dw_val_node dw_attr_val;
3571 dw_attr_node;
3573 /* The Debugging Information Entry (DIE) structure */
3575 typedef struct die_struct GTY(())
3577 enum dwarf_tag die_tag;
3578 char *die_symbol;
3579 dw_attr_ref die_attr;
3580 dw_die_ref die_parent;
3581 dw_die_ref die_child;
3582 dw_die_ref die_sib;
3583 dw_die_ref die_definition; /* ref from a specification to its definition */
3584 dw_offset die_offset;
3585 unsigned long die_abbrev;
3586 int die_mark;
3587 unsigned int decl_id;
3589 die_node;
3591 /* The pubname structure */
3593 typedef struct pubname_struct GTY(())
3595 dw_die_ref die;
3596 char *name;
3598 pubname_entry;
3600 struct dw_ranges_struct GTY(())
3602 int block_num;
3605 /* The limbo die list structure. */
3606 typedef struct limbo_die_struct GTY(())
3608 dw_die_ref die;
3609 tree created_for;
3610 struct limbo_die_struct *next;
3612 limbo_die_node;
3614 /* How to start an assembler comment. */
3615 #ifndef ASM_COMMENT_START
3616 #define ASM_COMMENT_START ";#"
3617 #endif
3619 /* Define a macro which returns nonzero for a TYPE_DECL which was
3620 implicitly generated for a tagged type.
3622 Note that unlike the gcc front end (which generates a NULL named
3623 TYPE_DECL node for each complete tagged type, each array type, and
3624 each function type node created) the g++ front end generates a
3625 _named_ TYPE_DECL node for each tagged type node created.
3626 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3627 generate a DW_TAG_typedef DIE for them. */
3629 #define TYPE_DECL_IS_STUB(decl) \
3630 (DECL_NAME (decl) == NULL_TREE \
3631 || (DECL_ARTIFICIAL (decl) \
3632 && is_tagged_type (TREE_TYPE (decl)) \
3633 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3634 /* This is necessary for stub decls that \
3635 appear in nested inline functions. */ \
3636 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3637 && (decl_ultimate_origin (decl) \
3638 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3640 /* Information concerning the compilation unit's programming
3641 language, and compiler version. */
3643 /* Fixed size portion of the DWARF compilation unit header. */
3644 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
3645 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
3647 /* Fixed size portion of public names info. */
3648 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3650 /* Fixed size portion of the address range info. */
3651 #define DWARF_ARANGES_HEADER_SIZE \
3652 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3653 DWARF2_ADDR_SIZE * 2) \
3654 - DWARF_INITIAL_LENGTH_SIZE)
3656 /* Size of padding portion in the address range info. It must be
3657 aligned to twice the pointer size. */
3658 #define DWARF_ARANGES_PAD_SIZE \
3659 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
3660 DWARF2_ADDR_SIZE * 2) \
3661 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
3663 /* Use assembler line directives if available. */
3664 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3665 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3666 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3667 #else
3668 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3669 #endif
3670 #endif
3672 /* Minimum line offset in a special line info. opcode.
3673 This value was chosen to give a reasonable range of values. */
3674 #define DWARF_LINE_BASE -10
3676 /* First special line opcode - leave room for the standard opcodes. */
3677 #define DWARF_LINE_OPCODE_BASE 10
3679 /* Range of line offsets in a special line info. opcode. */
3680 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3682 /* Flag that indicates the initial value of the is_stmt_start flag.
3683 In the present implementation, we do not mark any lines as
3684 the beginning of a source statement, because that information
3685 is not made available by the GCC front-end. */
3686 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3688 #ifdef DWARF2_DEBUGGING_INFO
3689 /* This location is used by calc_die_sizes() to keep track
3690 the offset of each DIE within the .debug_info section. */
3691 static unsigned long next_die_offset;
3692 #endif
3694 /* Record the root of the DIE's built for the current compilation unit. */
3695 static GTY(()) dw_die_ref comp_unit_die;
3697 /* A list of DIEs with a NULL parent waiting to be relocated. */
3698 static GTY(()) limbo_die_node *limbo_die_list;
3700 /* Filenames referenced by this compilation unit. */
3701 static GTY(()) varray_type file_table;
3702 static GTY(()) varray_type file_table_emitted;
3703 static GTY(()) size_t file_table_last_lookup_index;
3705 /* A hash table of references to DIE's that describe declarations.
3706 The key is a DECL_UID() which is a unique number identifying each decl. */
3707 static GTY ((param_is (struct die_struct))) htab_t decl_die_table;
3709 /* Node of the variable location list. */
3710 struct var_loc_node GTY ((chain_next ("%h.next")))
3712 rtx GTY (()) var_loc_note;
3713 const char * GTY (()) label;
3714 const char * GTY (()) section_label;
3715 struct var_loc_node * GTY (()) next;
3718 /* Variable location list. */
3719 struct var_loc_list_def GTY (())
3721 struct var_loc_node * GTY (()) first;
3723 /* Do not mark the last element of the chained list because
3724 it is marked through the chain. */
3725 struct var_loc_node * GTY ((skip ("%h"))) last;
3727 /* DECL_UID of the variable decl. */
3728 unsigned int decl_id;
3730 typedef struct var_loc_list_def var_loc_list;
3733 /* Table of decl location linked lists. */
3734 static GTY ((param_is (var_loc_list))) htab_t decl_loc_table;
3736 /* A pointer to the base of a list of references to DIE's that
3737 are uniquely identified by their tag, presence/absence of
3738 children DIE's, and list of attribute/value pairs. */
3739 static GTY((length ("abbrev_die_table_allocated")))
3740 dw_die_ref *abbrev_die_table;
3742 /* Number of elements currently allocated for abbrev_die_table. */
3743 static GTY(()) unsigned abbrev_die_table_allocated;
3745 /* Number of elements in type_die_table currently in use. */
3746 static GTY(()) unsigned abbrev_die_table_in_use;
3748 /* Size (in elements) of increments by which we may expand the
3749 abbrev_die_table. */
3750 #define ABBREV_DIE_TABLE_INCREMENT 256
3752 /* A pointer to the base of a table that contains line information
3753 for each source code line in .text in the compilation unit. */
3754 static GTY((length ("line_info_table_allocated")))
3755 dw_line_info_ref line_info_table;
3757 /* Number of elements currently allocated for line_info_table. */
3758 static GTY(()) unsigned line_info_table_allocated;
3760 /* Number of elements in line_info_table currently in use. */
3761 static GTY(()) unsigned line_info_table_in_use;
3763 /* A pointer to the base of a table that contains line information
3764 for each source code line outside of .text in the compilation unit. */
3765 static GTY ((length ("separate_line_info_table_allocated")))
3766 dw_separate_line_info_ref separate_line_info_table;
3768 /* Number of elements currently allocated for separate_line_info_table. */
3769 static GTY(()) unsigned separate_line_info_table_allocated;
3771 /* Number of elements in separate_line_info_table currently in use. */
3772 static GTY(()) unsigned separate_line_info_table_in_use;
3774 /* Size (in elements) of increments by which we may expand the
3775 line_info_table. */
3776 #define LINE_INFO_TABLE_INCREMENT 1024
3778 /* A pointer to the base of a table that contains a list of publicly
3779 accessible names. */
3780 static GTY ((length ("pubname_table_allocated"))) pubname_ref pubname_table;
3782 /* Number of elements currently allocated for pubname_table. */
3783 static GTY(()) unsigned pubname_table_allocated;
3785 /* Number of elements in pubname_table currently in use. */
3786 static GTY(()) unsigned pubname_table_in_use;
3788 /* Size (in elements) of increments by which we may expand the
3789 pubname_table. */
3790 #define PUBNAME_TABLE_INCREMENT 64
3792 /* Array of dies for which we should generate .debug_arange info. */
3793 static GTY((length ("arange_table_allocated"))) dw_die_ref *arange_table;
3795 /* Number of elements currently allocated for arange_table. */
3796 static GTY(()) unsigned arange_table_allocated;
3798 /* Number of elements in arange_table currently in use. */
3799 static GTY(()) unsigned arange_table_in_use;
3801 /* Size (in elements) of increments by which we may expand the
3802 arange_table. */
3803 #define ARANGE_TABLE_INCREMENT 64
3805 /* Array of dies for which we should generate .debug_ranges info. */
3806 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table;
3808 /* Number of elements currently allocated for ranges_table. */
3809 static GTY(()) unsigned ranges_table_allocated;
3811 /* Number of elements in ranges_table currently in use. */
3812 static GTY(()) unsigned ranges_table_in_use;
3814 /* Size (in elements) of increments by which we may expand the
3815 ranges_table. */
3816 #define RANGES_TABLE_INCREMENT 64
3818 /* Whether we have location lists that need outputting */
3819 static GTY(()) unsigned have_location_lists;
3821 /* Unique label counter. */
3822 static GTY(()) unsigned int loclabel_num;
3824 #ifdef DWARF2_DEBUGGING_INFO
3825 /* Record whether the function being analyzed contains inlined functions. */
3826 static int current_function_has_inlines;
3827 #endif
3828 #if 0 && defined (MIPS_DEBUGGING_INFO)
3829 static int comp_unit_has_inlines;
3830 #endif
3832 /* Number of file tables emitted in maybe_emit_file(). */
3833 static GTY(()) int emitcount = 0;
3835 /* Number of internal labels generated by gen_internal_sym(). */
3836 static GTY(()) int label_num;
3838 #ifdef DWARF2_DEBUGGING_INFO
3840 /* Forward declarations for functions defined in this file. */
3842 static int is_pseudo_reg (rtx);
3843 static tree type_main_variant (tree);
3844 static int is_tagged_type (tree);
3845 static const char *dwarf_tag_name (unsigned);
3846 static const char *dwarf_attr_name (unsigned);
3847 static const char *dwarf_form_name (unsigned);
3848 static tree decl_ultimate_origin (tree);
3849 static tree block_ultimate_origin (tree);
3850 static tree decl_class_context (tree);
3851 static void add_dwarf_attr (dw_die_ref, dw_attr_ref);
3852 static inline enum dw_val_class AT_class (dw_attr_ref);
3853 static void add_AT_flag (dw_die_ref, enum dwarf_attribute, unsigned);
3854 static inline unsigned AT_flag (dw_attr_ref);
3855 static void add_AT_int (dw_die_ref, enum dwarf_attribute, HOST_WIDE_INT);
3856 static inline HOST_WIDE_INT AT_int (dw_attr_ref);
3857 static void add_AT_unsigned (dw_die_ref, enum dwarf_attribute, unsigned HOST_WIDE_INT);
3858 static inline unsigned HOST_WIDE_INT AT_unsigned (dw_attr_ref);
3859 static void add_AT_long_long (dw_die_ref, enum dwarf_attribute, unsigned long,
3860 unsigned long);
3861 static inline void add_AT_vec (dw_die_ref, enum dwarf_attribute, unsigned int,
3862 unsigned int, unsigned char *);
3863 static hashval_t debug_str_do_hash (const void *);
3864 static int debug_str_eq (const void *, const void *);
3865 static void add_AT_string (dw_die_ref, enum dwarf_attribute, const char *);
3866 static inline const char *AT_string (dw_attr_ref);
3867 static int AT_string_form (dw_attr_ref);
3868 static void add_AT_die_ref (dw_die_ref, enum dwarf_attribute, dw_die_ref);
3869 static void add_AT_specification (dw_die_ref, dw_die_ref);
3870 static inline dw_die_ref AT_ref (dw_attr_ref);
3871 static inline int AT_ref_external (dw_attr_ref);
3872 static inline void set_AT_ref_external (dw_attr_ref, int);
3873 static void add_AT_fde_ref (dw_die_ref, enum dwarf_attribute, unsigned);
3874 static void add_AT_loc (dw_die_ref, enum dwarf_attribute, dw_loc_descr_ref);
3875 static inline dw_loc_descr_ref AT_loc (dw_attr_ref);
3876 static void add_AT_loc_list (dw_die_ref, enum dwarf_attribute,
3877 dw_loc_list_ref);
3878 static inline dw_loc_list_ref AT_loc_list (dw_attr_ref);
3879 static void add_AT_addr (dw_die_ref, enum dwarf_attribute, rtx);
3880 static inline rtx AT_addr (dw_attr_ref);
3881 static void add_AT_lbl_id (dw_die_ref, enum dwarf_attribute, const char *);
3882 static void add_AT_lbl_offset (dw_die_ref, enum dwarf_attribute, const char *);
3883 static void add_AT_offset (dw_die_ref, enum dwarf_attribute,
3884 unsigned HOST_WIDE_INT);
3885 static void add_AT_range_list (dw_die_ref, enum dwarf_attribute,
3886 unsigned long);
3887 static inline const char *AT_lbl (dw_attr_ref);
3888 static dw_attr_ref get_AT (dw_die_ref, enum dwarf_attribute);
3889 static const char *get_AT_low_pc (dw_die_ref);
3890 static const char *get_AT_hi_pc (dw_die_ref);
3891 static const char *get_AT_string (dw_die_ref, enum dwarf_attribute);
3892 static int get_AT_flag (dw_die_ref, enum dwarf_attribute);
3893 static unsigned get_AT_unsigned (dw_die_ref, enum dwarf_attribute);
3894 static inline dw_die_ref get_AT_ref (dw_die_ref, enum dwarf_attribute);
3895 static bool is_c_family (void);
3896 static bool is_cxx (void);
3897 static bool is_java (void);
3898 static bool is_fortran (void);
3899 static bool is_ada (void);
3900 static void remove_AT (dw_die_ref, enum dwarf_attribute);
3901 static void remove_child_TAG (dw_die_ref, enum dwarf_tag);
3902 static inline void free_die (dw_die_ref);
3903 static void remove_children (dw_die_ref);
3904 static void add_child_die (dw_die_ref, dw_die_ref);
3905 static dw_die_ref new_die (enum dwarf_tag, dw_die_ref, tree);
3906 static dw_die_ref lookup_type_die (tree);
3907 static void equate_type_number_to_die (tree, dw_die_ref);
3908 static hashval_t decl_die_table_hash (const void *);
3909 static int decl_die_table_eq (const void *, const void *);
3910 static dw_die_ref lookup_decl_die (tree);
3911 static hashval_t decl_loc_table_hash (const void *);
3912 static int decl_loc_table_eq (const void *, const void *);
3913 static var_loc_list *lookup_decl_loc (tree);
3914 static void equate_decl_number_to_die (tree, dw_die_ref);
3915 static void add_var_loc_to_decl (tree, struct var_loc_node *);
3916 static void print_spaces (FILE *);
3917 static void print_die (dw_die_ref, FILE *);
3918 static void print_dwarf_line_table (FILE *);
3919 static void reverse_die_lists (dw_die_ref);
3920 static void reverse_all_dies (dw_die_ref);
3921 static dw_die_ref push_new_compile_unit (dw_die_ref, dw_die_ref);
3922 static dw_die_ref pop_compile_unit (dw_die_ref);
3923 static void loc_checksum (dw_loc_descr_ref, struct md5_ctx *);
3924 static void attr_checksum (dw_attr_ref, struct md5_ctx *, int *);
3925 static void die_checksum (dw_die_ref, struct md5_ctx *, int *);
3926 static int same_loc_p (dw_loc_descr_ref, dw_loc_descr_ref, int *);
3927 static int same_dw_val_p (dw_val_node *, dw_val_node *, int *);
3928 static int same_attr_p (dw_attr_ref, dw_attr_ref, int *);
3929 static int same_die_p (dw_die_ref, dw_die_ref, int *);
3930 static int same_die_p_wrap (dw_die_ref, dw_die_ref);
3931 static void compute_section_prefix (dw_die_ref);
3932 static int is_type_die (dw_die_ref);
3933 static int is_comdat_die (dw_die_ref);
3934 static int is_symbol_die (dw_die_ref);
3935 static void assign_symbol_names (dw_die_ref);
3936 static void break_out_includes (dw_die_ref);
3937 static hashval_t htab_cu_hash (const void *);
3938 static int htab_cu_eq (const void *, const void *);
3939 static void htab_cu_del (void *);
3940 static int check_duplicate_cu (dw_die_ref, htab_t, unsigned *);
3941 static void record_comdat_symbol_number (dw_die_ref, htab_t, unsigned);
3942 static void add_sibling_attributes (dw_die_ref);
3943 static void build_abbrev_table (dw_die_ref);
3944 static void output_location_lists (dw_die_ref);
3945 static int constant_size (long unsigned);
3946 static unsigned long size_of_die (dw_die_ref);
3947 static void calc_die_sizes (dw_die_ref);
3948 static void mark_dies (dw_die_ref);
3949 static void unmark_dies (dw_die_ref);
3950 static void unmark_all_dies (dw_die_ref);
3951 static unsigned long size_of_pubnames (void);
3952 static unsigned long size_of_aranges (void);
3953 static enum dwarf_form value_format (dw_attr_ref);
3954 static void output_value_format (dw_attr_ref);
3955 static void output_abbrev_section (void);
3956 static void output_die_symbol (dw_die_ref);
3957 static void output_die (dw_die_ref);
3958 static void output_compilation_unit_header (void);
3959 static void output_comp_unit (dw_die_ref, int);
3960 static const char *dwarf2_name (tree, int);
3961 static void add_pubname (tree, dw_die_ref);
3962 static void output_pubnames (void);
3963 static void add_arange (tree, dw_die_ref);
3964 static void output_aranges (void);
3965 static unsigned int add_ranges (tree);
3966 static void output_ranges (void);
3967 static void output_line_info (void);
3968 static void output_file_names (void);
3969 static dw_die_ref base_type_die (tree);
3970 static tree root_type (tree);
3971 static int is_base_type (tree);
3972 static bool is_subrange_type (tree);
3973 static dw_die_ref subrange_type_die (tree, dw_die_ref);
3974 static dw_die_ref modified_type_die (tree, int, int, dw_die_ref);
3975 static int type_is_enum (tree);
3976 static unsigned int dbx_reg_number (rtx);
3977 static void add_loc_descr_op_piece (dw_loc_descr_ref *, int);
3978 static dw_loc_descr_ref reg_loc_descriptor (rtx);
3979 static dw_loc_descr_ref one_reg_loc_descriptor (unsigned int);
3980 static dw_loc_descr_ref multiple_reg_loc_descriptor (rtx, rtx);
3981 static dw_loc_descr_ref int_loc_descriptor (HOST_WIDE_INT);
3982 static dw_loc_descr_ref based_loc_descr (unsigned, HOST_WIDE_INT, bool);
3983 static int is_based_loc (rtx);
3984 static dw_loc_descr_ref mem_loc_descriptor (rtx, enum machine_mode mode, bool);
3985 static dw_loc_descr_ref concat_loc_descriptor (rtx, rtx, bool);
3986 static dw_loc_descr_ref loc_descriptor (rtx, bool);
3987 static dw_loc_descr_ref loc_descriptor_from_tree_1 (tree, int);
3988 static dw_loc_descr_ref loc_descriptor_from_tree (tree);
3989 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
3990 static tree field_type (tree);
3991 static unsigned int simple_type_align_in_bits (tree);
3992 static unsigned int simple_decl_align_in_bits (tree);
3993 static unsigned HOST_WIDE_INT simple_type_size_in_bits (tree);
3994 static HOST_WIDE_INT field_byte_offset (tree);
3995 static void add_AT_location_description (dw_die_ref, enum dwarf_attribute,
3996 dw_loc_descr_ref);
3997 static void add_data_member_location_attribute (dw_die_ref, tree);
3998 static void add_const_value_attribute (dw_die_ref, rtx);
3999 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
4000 static HOST_WIDE_INT extract_int (const unsigned char *, unsigned);
4001 static void insert_float (rtx, unsigned char *);
4002 static rtx rtl_for_decl_location (tree);
4003 static void add_location_or_const_value_attribute (dw_die_ref, tree,
4004 enum dwarf_attribute);
4005 static void tree_add_const_value_attribute (dw_die_ref, tree);
4006 static void add_name_attribute (dw_die_ref, const char *);
4007 static void add_comp_dir_attribute (dw_die_ref);
4008 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree);
4009 static void add_subscript_info (dw_die_ref, tree);
4010 static void add_byte_size_attribute (dw_die_ref, tree);
4011 static void add_bit_offset_attribute (dw_die_ref, tree);
4012 static void add_bit_size_attribute (dw_die_ref, tree);
4013 static void add_prototyped_attribute (dw_die_ref, tree);
4014 static void add_abstract_origin_attribute (dw_die_ref, tree);
4015 static void add_pure_or_virtual_attribute (dw_die_ref, tree);
4016 static void add_src_coords_attributes (dw_die_ref, tree);
4017 static void add_name_and_src_coords_attributes (dw_die_ref, tree);
4018 static void push_decl_scope (tree);
4019 static void pop_decl_scope (void);
4020 static dw_die_ref scope_die_for (tree, dw_die_ref);
4021 static inline int local_scope_p (dw_die_ref);
4022 static inline int class_or_namespace_scope_p (dw_die_ref);
4023 static void add_type_attribute (dw_die_ref, tree, int, int, dw_die_ref);
4024 static void add_calling_convention_attribute (dw_die_ref, tree);
4025 static const char *type_tag (tree);
4026 static tree member_declared_type (tree);
4027 #if 0
4028 static const char *decl_start_label (tree);
4029 #endif
4030 static void gen_array_type_die (tree, dw_die_ref);
4031 #if 0
4032 static void gen_entry_point_die (tree, dw_die_ref);
4033 #endif
4034 static void gen_inlined_enumeration_type_die (tree, dw_die_ref);
4035 static void gen_inlined_structure_type_die (tree, dw_die_ref);
4036 static void gen_inlined_union_type_die (tree, dw_die_ref);
4037 static dw_die_ref gen_enumeration_type_die (tree, dw_die_ref);
4038 static dw_die_ref gen_formal_parameter_die (tree, dw_die_ref);
4039 static void gen_unspecified_parameters_die (tree, dw_die_ref);
4040 static void gen_formal_types_die (tree, dw_die_ref);
4041 static void gen_subprogram_die (tree, dw_die_ref);
4042 static void gen_variable_die (tree, dw_die_ref);
4043 static void gen_label_die (tree, dw_die_ref);
4044 static void gen_lexical_block_die (tree, dw_die_ref, int);
4045 static void gen_inlined_subroutine_die (tree, dw_die_ref, int);
4046 static void gen_field_die (tree, dw_die_ref);
4047 static void gen_ptr_to_mbr_type_die (tree, dw_die_ref);
4048 static dw_die_ref gen_compile_unit_die (const char *);
4049 static void gen_string_type_die (tree, dw_die_ref);
4050 static void gen_inheritance_die (tree, tree, dw_die_ref);
4051 static void gen_member_die (tree, dw_die_ref);
4052 static void gen_struct_or_union_type_die (tree, dw_die_ref);
4053 static void gen_subroutine_type_die (tree, dw_die_ref);
4054 static void gen_typedef_die (tree, dw_die_ref);
4055 static void gen_type_die (tree, dw_die_ref);
4056 static void gen_tagged_type_instantiation_die (tree, dw_die_ref);
4057 static void gen_block_die (tree, dw_die_ref, int);
4058 static void decls_for_scope (tree, dw_die_ref, int);
4059 static int is_redundant_typedef (tree);
4060 static void gen_namespace_die (tree);
4061 static void gen_decl_die (tree, dw_die_ref);
4062 static dw_die_ref force_decl_die (tree);
4063 static dw_die_ref force_type_die (tree);
4064 static dw_die_ref setup_namespace_context (tree, dw_die_ref);
4065 static void declare_in_namespace (tree, dw_die_ref);
4066 static unsigned lookup_filename (const char *);
4067 static void init_file_table (void);
4068 static void retry_incomplete_types (void);
4069 static void gen_type_die_for_member (tree, tree, dw_die_ref);
4070 static void splice_child_die (dw_die_ref, dw_die_ref);
4071 static int file_info_cmp (const void *, const void *);
4072 static dw_loc_list_ref new_loc_list (dw_loc_descr_ref, const char *,
4073 const char *, const char *, unsigned);
4074 static void add_loc_descr_to_loc_list (dw_loc_list_ref *, dw_loc_descr_ref,
4075 const char *, const char *,
4076 const char *);
4077 static void output_loc_list (dw_loc_list_ref);
4078 static char *gen_internal_sym (const char *);
4080 static void prune_unmark_dies (dw_die_ref);
4081 static void prune_unused_types_mark (dw_die_ref, int);
4082 static void prune_unused_types_walk (dw_die_ref);
4083 static void prune_unused_types_walk_attribs (dw_die_ref);
4084 static void prune_unused_types_prune (dw_die_ref);
4085 static void prune_unused_types (void);
4086 static int maybe_emit_file (int);
4088 /* Section names used to hold DWARF debugging information. */
4089 #ifndef DEBUG_INFO_SECTION
4090 #define DEBUG_INFO_SECTION ".debug_info"
4091 #endif
4092 #ifndef DEBUG_ABBREV_SECTION
4093 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
4094 #endif
4095 #ifndef DEBUG_ARANGES_SECTION
4096 #define DEBUG_ARANGES_SECTION ".debug_aranges"
4097 #endif
4098 #ifndef DEBUG_MACINFO_SECTION
4099 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
4100 #endif
4101 #ifndef DEBUG_LINE_SECTION
4102 #define DEBUG_LINE_SECTION ".debug_line"
4103 #endif
4104 #ifndef DEBUG_LOC_SECTION
4105 #define DEBUG_LOC_SECTION ".debug_loc"
4106 #endif
4107 #ifndef DEBUG_PUBNAMES_SECTION
4108 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
4109 #endif
4110 #ifndef DEBUG_STR_SECTION
4111 #define DEBUG_STR_SECTION ".debug_str"
4112 #endif
4113 #ifndef DEBUG_RANGES_SECTION
4114 #define DEBUG_RANGES_SECTION ".debug_ranges"
4115 #endif
4117 /* Standard ELF section names for compiled code and data. */
4118 #ifndef TEXT_SECTION_NAME
4119 #define TEXT_SECTION_NAME ".text"
4120 #endif
4122 /* Section flags for .debug_str section. */
4123 #define DEBUG_STR_SECTION_FLAGS \
4124 (HAVE_GAS_SHF_MERGE && flag_merge_constants \
4125 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
4126 : SECTION_DEBUG)
4128 /* Labels we insert at beginning sections we can reference instead of
4129 the section names themselves. */
4131 #ifndef TEXT_SECTION_LABEL
4132 #define TEXT_SECTION_LABEL "Ltext"
4133 #endif
4134 #ifndef COLD_TEXT_SECTION_LABEL
4135 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
4136 #endif
4137 #ifndef DEBUG_LINE_SECTION_LABEL
4138 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
4139 #endif
4140 #ifndef DEBUG_INFO_SECTION_LABEL
4141 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
4142 #endif
4143 #ifndef DEBUG_ABBREV_SECTION_LABEL
4144 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
4145 #endif
4146 #ifndef DEBUG_LOC_SECTION_LABEL
4147 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
4148 #endif
4149 #ifndef DEBUG_RANGES_SECTION_LABEL
4150 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
4151 #endif
4152 #ifndef DEBUG_MACINFO_SECTION_LABEL
4153 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
4154 #endif
4156 /* Definitions of defaults for formats and names of various special
4157 (artificial) labels which may be generated within this file (when the -g
4158 options is used and DWARF2_DEBUGGING_INFO is in effect.
4159 If necessary, these may be overridden from within the tm.h file, but
4160 typically, overriding these defaults is unnecessary. */
4162 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4163 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4164 static char cold_text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4165 static char cold_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
4166 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4167 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4168 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4169 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4170 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
4171 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
4173 #ifndef TEXT_END_LABEL
4174 #define TEXT_END_LABEL "Letext"
4175 #endif
4176 #ifndef COLD_END_LABEL
4177 #define COLD_END_LABEL "Letext_cold"
4178 #endif
4179 #ifndef BLOCK_BEGIN_LABEL
4180 #define BLOCK_BEGIN_LABEL "LBB"
4181 #endif
4182 #ifndef BLOCK_END_LABEL
4183 #define BLOCK_END_LABEL "LBE"
4184 #endif
4185 #ifndef LINE_CODE_LABEL
4186 #define LINE_CODE_LABEL "LM"
4187 #endif
4188 #ifndef SEPARATE_LINE_CODE_LABEL
4189 #define SEPARATE_LINE_CODE_LABEL "LSM"
4190 #endif
4192 /* We allow a language front-end to designate a function that is to be
4193 called to "demangle" any name before it is put into a DIE. */
4195 static const char *(*demangle_name_func) (const char *);
4197 void
4198 dwarf2out_set_demangle_name_func (const char *(*func) (const char *))
4200 demangle_name_func = func;
4203 /* Test if rtl node points to a pseudo register. */
4205 static inline int
4206 is_pseudo_reg (rtx rtl)
4208 return ((REG_P (rtl) && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
4209 || (GET_CODE (rtl) == SUBREG
4210 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
4213 /* Return a reference to a type, with its const and volatile qualifiers
4214 removed. */
4216 static inline tree
4217 type_main_variant (tree type)
4219 type = TYPE_MAIN_VARIANT (type);
4221 /* ??? There really should be only one main variant among any group of
4222 variants of a given type (and all of the MAIN_VARIANT values for all
4223 members of the group should point to that one type) but sometimes the C
4224 front-end messes this up for array types, so we work around that bug
4225 here. */
4226 if (TREE_CODE (type) == ARRAY_TYPE)
4227 while (type != TYPE_MAIN_VARIANT (type))
4228 type = TYPE_MAIN_VARIANT (type);
4230 return type;
4233 /* Return nonzero if the given type node represents a tagged type. */
4235 static inline int
4236 is_tagged_type (tree type)
4238 enum tree_code code = TREE_CODE (type);
4240 return (code == RECORD_TYPE || code == UNION_TYPE
4241 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
4244 /* Convert a DIE tag into its string name. */
4246 static const char *
4247 dwarf_tag_name (unsigned int tag)
4249 switch (tag)
4251 case DW_TAG_padding:
4252 return "DW_TAG_padding";
4253 case DW_TAG_array_type:
4254 return "DW_TAG_array_type";
4255 case DW_TAG_class_type:
4256 return "DW_TAG_class_type";
4257 case DW_TAG_entry_point:
4258 return "DW_TAG_entry_point";
4259 case DW_TAG_enumeration_type:
4260 return "DW_TAG_enumeration_type";
4261 case DW_TAG_formal_parameter:
4262 return "DW_TAG_formal_parameter";
4263 case DW_TAG_imported_declaration:
4264 return "DW_TAG_imported_declaration";
4265 case DW_TAG_label:
4266 return "DW_TAG_label";
4267 case DW_TAG_lexical_block:
4268 return "DW_TAG_lexical_block";
4269 case DW_TAG_member:
4270 return "DW_TAG_member";
4271 case DW_TAG_pointer_type:
4272 return "DW_TAG_pointer_type";
4273 case DW_TAG_reference_type:
4274 return "DW_TAG_reference_type";
4275 case DW_TAG_compile_unit:
4276 return "DW_TAG_compile_unit";
4277 case DW_TAG_string_type:
4278 return "DW_TAG_string_type";
4279 case DW_TAG_structure_type:
4280 return "DW_TAG_structure_type";
4281 case DW_TAG_subroutine_type:
4282 return "DW_TAG_subroutine_type";
4283 case DW_TAG_typedef:
4284 return "DW_TAG_typedef";
4285 case DW_TAG_union_type:
4286 return "DW_TAG_union_type";
4287 case DW_TAG_unspecified_parameters:
4288 return "DW_TAG_unspecified_parameters";
4289 case DW_TAG_variant:
4290 return "DW_TAG_variant";
4291 case DW_TAG_common_block:
4292 return "DW_TAG_common_block";
4293 case DW_TAG_common_inclusion:
4294 return "DW_TAG_common_inclusion";
4295 case DW_TAG_inheritance:
4296 return "DW_TAG_inheritance";
4297 case DW_TAG_inlined_subroutine:
4298 return "DW_TAG_inlined_subroutine";
4299 case DW_TAG_module:
4300 return "DW_TAG_module";
4301 case DW_TAG_ptr_to_member_type:
4302 return "DW_TAG_ptr_to_member_type";
4303 case DW_TAG_set_type:
4304 return "DW_TAG_set_type";
4305 case DW_TAG_subrange_type:
4306 return "DW_TAG_subrange_type";
4307 case DW_TAG_with_stmt:
4308 return "DW_TAG_with_stmt";
4309 case DW_TAG_access_declaration:
4310 return "DW_TAG_access_declaration";
4311 case DW_TAG_base_type:
4312 return "DW_TAG_base_type";
4313 case DW_TAG_catch_block:
4314 return "DW_TAG_catch_block";
4315 case DW_TAG_const_type:
4316 return "DW_TAG_const_type";
4317 case DW_TAG_constant:
4318 return "DW_TAG_constant";
4319 case DW_TAG_enumerator:
4320 return "DW_TAG_enumerator";
4321 case DW_TAG_file_type:
4322 return "DW_TAG_file_type";
4323 case DW_TAG_friend:
4324 return "DW_TAG_friend";
4325 case DW_TAG_namelist:
4326 return "DW_TAG_namelist";
4327 case DW_TAG_namelist_item:
4328 return "DW_TAG_namelist_item";
4329 case DW_TAG_namespace:
4330 return "DW_TAG_namespace";
4331 case DW_TAG_packed_type:
4332 return "DW_TAG_packed_type";
4333 case DW_TAG_subprogram:
4334 return "DW_TAG_subprogram";
4335 case DW_TAG_template_type_param:
4336 return "DW_TAG_template_type_param";
4337 case DW_TAG_template_value_param:
4338 return "DW_TAG_template_value_param";
4339 case DW_TAG_thrown_type:
4340 return "DW_TAG_thrown_type";
4341 case DW_TAG_try_block:
4342 return "DW_TAG_try_block";
4343 case DW_TAG_variant_part:
4344 return "DW_TAG_variant_part";
4345 case DW_TAG_variable:
4346 return "DW_TAG_variable";
4347 case DW_TAG_volatile_type:
4348 return "DW_TAG_volatile_type";
4349 case DW_TAG_imported_module:
4350 return "DW_TAG_imported_module";
4351 case DW_TAG_MIPS_loop:
4352 return "DW_TAG_MIPS_loop";
4353 case DW_TAG_format_label:
4354 return "DW_TAG_format_label";
4355 case DW_TAG_function_template:
4356 return "DW_TAG_function_template";
4357 case DW_TAG_class_template:
4358 return "DW_TAG_class_template";
4359 case DW_TAG_GNU_BINCL:
4360 return "DW_TAG_GNU_BINCL";
4361 case DW_TAG_GNU_EINCL:
4362 return "DW_TAG_GNU_EINCL";
4363 default:
4364 return "DW_TAG_<unknown>";
4368 /* Convert a DWARF attribute code into its string name. */
4370 static const char *
4371 dwarf_attr_name (unsigned int attr)
4373 switch (attr)
4375 case DW_AT_sibling:
4376 return "DW_AT_sibling";
4377 case DW_AT_location:
4378 return "DW_AT_location";
4379 case DW_AT_name:
4380 return "DW_AT_name";
4381 case DW_AT_ordering:
4382 return "DW_AT_ordering";
4383 case DW_AT_subscr_data:
4384 return "DW_AT_subscr_data";
4385 case DW_AT_byte_size:
4386 return "DW_AT_byte_size";
4387 case DW_AT_bit_offset:
4388 return "DW_AT_bit_offset";
4389 case DW_AT_bit_size:
4390 return "DW_AT_bit_size";
4391 case DW_AT_element_list:
4392 return "DW_AT_element_list";
4393 case DW_AT_stmt_list:
4394 return "DW_AT_stmt_list";
4395 case DW_AT_low_pc:
4396 return "DW_AT_low_pc";
4397 case DW_AT_high_pc:
4398 return "DW_AT_high_pc";
4399 case DW_AT_language:
4400 return "DW_AT_language";
4401 case DW_AT_member:
4402 return "DW_AT_member";
4403 case DW_AT_discr:
4404 return "DW_AT_discr";
4405 case DW_AT_discr_value:
4406 return "DW_AT_discr_value";
4407 case DW_AT_visibility:
4408 return "DW_AT_visibility";
4409 case DW_AT_import:
4410 return "DW_AT_import";
4411 case DW_AT_string_length:
4412 return "DW_AT_string_length";
4413 case DW_AT_common_reference:
4414 return "DW_AT_common_reference";
4415 case DW_AT_comp_dir:
4416 return "DW_AT_comp_dir";
4417 case DW_AT_const_value:
4418 return "DW_AT_const_value";
4419 case DW_AT_containing_type:
4420 return "DW_AT_containing_type";
4421 case DW_AT_default_value:
4422 return "DW_AT_default_value";
4423 case DW_AT_inline:
4424 return "DW_AT_inline";
4425 case DW_AT_is_optional:
4426 return "DW_AT_is_optional";
4427 case DW_AT_lower_bound:
4428 return "DW_AT_lower_bound";
4429 case DW_AT_producer:
4430 return "DW_AT_producer";
4431 case DW_AT_prototyped:
4432 return "DW_AT_prototyped";
4433 case DW_AT_return_addr:
4434 return "DW_AT_return_addr";
4435 case DW_AT_start_scope:
4436 return "DW_AT_start_scope";
4437 case DW_AT_stride_size:
4438 return "DW_AT_stride_size";
4439 case DW_AT_upper_bound:
4440 return "DW_AT_upper_bound";
4441 case DW_AT_abstract_origin:
4442 return "DW_AT_abstract_origin";
4443 case DW_AT_accessibility:
4444 return "DW_AT_accessibility";
4445 case DW_AT_address_class:
4446 return "DW_AT_address_class";
4447 case DW_AT_artificial:
4448 return "DW_AT_artificial";
4449 case DW_AT_base_types:
4450 return "DW_AT_base_types";
4451 case DW_AT_calling_convention:
4452 return "DW_AT_calling_convention";
4453 case DW_AT_count:
4454 return "DW_AT_count";
4455 case DW_AT_data_member_location:
4456 return "DW_AT_data_member_location";
4457 case DW_AT_decl_column:
4458 return "DW_AT_decl_column";
4459 case DW_AT_decl_file:
4460 return "DW_AT_decl_file";
4461 case DW_AT_decl_line:
4462 return "DW_AT_decl_line";
4463 case DW_AT_declaration:
4464 return "DW_AT_declaration";
4465 case DW_AT_discr_list:
4466 return "DW_AT_discr_list";
4467 case DW_AT_encoding:
4468 return "DW_AT_encoding";
4469 case DW_AT_external:
4470 return "DW_AT_external";
4471 case DW_AT_frame_base:
4472 return "DW_AT_frame_base";
4473 case DW_AT_friend:
4474 return "DW_AT_friend";
4475 case DW_AT_identifier_case:
4476 return "DW_AT_identifier_case";
4477 case DW_AT_macro_info:
4478 return "DW_AT_macro_info";
4479 case DW_AT_namelist_items:
4480 return "DW_AT_namelist_items";
4481 case DW_AT_priority:
4482 return "DW_AT_priority";
4483 case DW_AT_segment:
4484 return "DW_AT_segment";
4485 case DW_AT_specification:
4486 return "DW_AT_specification";
4487 case DW_AT_static_link:
4488 return "DW_AT_static_link";
4489 case DW_AT_type:
4490 return "DW_AT_type";
4491 case DW_AT_use_location:
4492 return "DW_AT_use_location";
4493 case DW_AT_variable_parameter:
4494 return "DW_AT_variable_parameter";
4495 case DW_AT_virtuality:
4496 return "DW_AT_virtuality";
4497 case DW_AT_vtable_elem_location:
4498 return "DW_AT_vtable_elem_location";
4500 case DW_AT_allocated:
4501 return "DW_AT_allocated";
4502 case DW_AT_associated:
4503 return "DW_AT_associated";
4504 case DW_AT_data_location:
4505 return "DW_AT_data_location";
4506 case DW_AT_stride:
4507 return "DW_AT_stride";
4508 case DW_AT_entry_pc:
4509 return "DW_AT_entry_pc";
4510 case DW_AT_use_UTF8:
4511 return "DW_AT_use_UTF8";
4512 case DW_AT_extension:
4513 return "DW_AT_extension";
4514 case DW_AT_ranges:
4515 return "DW_AT_ranges";
4516 case DW_AT_trampoline:
4517 return "DW_AT_trampoline";
4518 case DW_AT_call_column:
4519 return "DW_AT_call_column";
4520 case DW_AT_call_file:
4521 return "DW_AT_call_file";
4522 case DW_AT_call_line:
4523 return "DW_AT_call_line";
4525 case DW_AT_MIPS_fde:
4526 return "DW_AT_MIPS_fde";
4527 case DW_AT_MIPS_loop_begin:
4528 return "DW_AT_MIPS_loop_begin";
4529 case DW_AT_MIPS_tail_loop_begin:
4530 return "DW_AT_MIPS_tail_loop_begin";
4531 case DW_AT_MIPS_epilog_begin:
4532 return "DW_AT_MIPS_epilog_begin";
4533 case DW_AT_MIPS_loop_unroll_factor:
4534 return "DW_AT_MIPS_loop_unroll_factor";
4535 case DW_AT_MIPS_software_pipeline_depth:
4536 return "DW_AT_MIPS_software_pipeline_depth";
4537 case DW_AT_MIPS_linkage_name:
4538 return "DW_AT_MIPS_linkage_name";
4539 case DW_AT_MIPS_stride:
4540 return "DW_AT_MIPS_stride";
4541 case DW_AT_MIPS_abstract_name:
4542 return "DW_AT_MIPS_abstract_name";
4543 case DW_AT_MIPS_clone_origin:
4544 return "DW_AT_MIPS_clone_origin";
4545 case DW_AT_MIPS_has_inlines:
4546 return "DW_AT_MIPS_has_inlines";
4548 case DW_AT_sf_names:
4549 return "DW_AT_sf_names";
4550 case DW_AT_src_info:
4551 return "DW_AT_src_info";
4552 case DW_AT_mac_info:
4553 return "DW_AT_mac_info";
4554 case DW_AT_src_coords:
4555 return "DW_AT_src_coords";
4556 case DW_AT_body_begin:
4557 return "DW_AT_body_begin";
4558 case DW_AT_body_end:
4559 return "DW_AT_body_end";
4560 case DW_AT_GNU_vector:
4561 return "DW_AT_GNU_vector";
4563 case DW_AT_VMS_rtnbeg_pd_address:
4564 return "DW_AT_VMS_rtnbeg_pd_address";
4566 default:
4567 return "DW_AT_<unknown>";
4571 /* Convert a DWARF value form code into its string name. */
4573 static const char *
4574 dwarf_form_name (unsigned int form)
4576 switch (form)
4578 case DW_FORM_addr:
4579 return "DW_FORM_addr";
4580 case DW_FORM_block2:
4581 return "DW_FORM_block2";
4582 case DW_FORM_block4:
4583 return "DW_FORM_block4";
4584 case DW_FORM_data2:
4585 return "DW_FORM_data2";
4586 case DW_FORM_data4:
4587 return "DW_FORM_data4";
4588 case DW_FORM_data8:
4589 return "DW_FORM_data8";
4590 case DW_FORM_string:
4591 return "DW_FORM_string";
4592 case DW_FORM_block:
4593 return "DW_FORM_block";
4594 case DW_FORM_block1:
4595 return "DW_FORM_block1";
4596 case DW_FORM_data1:
4597 return "DW_FORM_data1";
4598 case DW_FORM_flag:
4599 return "DW_FORM_flag";
4600 case DW_FORM_sdata:
4601 return "DW_FORM_sdata";
4602 case DW_FORM_strp:
4603 return "DW_FORM_strp";
4604 case DW_FORM_udata:
4605 return "DW_FORM_udata";
4606 case DW_FORM_ref_addr:
4607 return "DW_FORM_ref_addr";
4608 case DW_FORM_ref1:
4609 return "DW_FORM_ref1";
4610 case DW_FORM_ref2:
4611 return "DW_FORM_ref2";
4612 case DW_FORM_ref4:
4613 return "DW_FORM_ref4";
4614 case DW_FORM_ref8:
4615 return "DW_FORM_ref8";
4616 case DW_FORM_ref_udata:
4617 return "DW_FORM_ref_udata";
4618 case DW_FORM_indirect:
4619 return "DW_FORM_indirect";
4620 default:
4621 return "DW_FORM_<unknown>";
4625 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4626 instance of an inlined instance of a decl which is local to an inline
4627 function, so we have to trace all of the way back through the origin chain
4628 to find out what sort of node actually served as the original seed for the
4629 given block. */
4631 static tree
4632 decl_ultimate_origin (tree decl)
4634 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl), TS_DECL_COMMON))
4635 return NULL_TREE;
4637 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4638 nodes in the function to point to themselves; ignore that if
4639 we're trying to output the abstract instance of this function. */
4640 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4641 return NULL_TREE;
4643 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4644 most distant ancestor, this should never happen. */
4645 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl)));
4647 return DECL_ABSTRACT_ORIGIN (decl);
4650 /* Determine the "ultimate origin" of a block. The block may be an inlined
4651 instance of an inlined instance of a block which is local to an inline
4652 function, so we have to trace all of the way back through the origin chain
4653 to find out what sort of node actually served as the original seed for the
4654 given block. */
4656 static tree
4657 block_ultimate_origin (tree block)
4659 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4661 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4662 nodes in the function to point to themselves; ignore that if
4663 we're trying to output the abstract instance of this function. */
4664 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4665 return NULL_TREE;
4667 if (immediate_origin == NULL_TREE)
4668 return NULL_TREE;
4669 else
4671 tree ret_val;
4672 tree lookahead = immediate_origin;
4676 ret_val = lookahead;
4677 lookahead = (TREE_CODE (ret_val) == BLOCK
4678 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4680 while (lookahead != NULL && lookahead != ret_val);
4682 /* The block's abstract origin chain may not be the *ultimate* origin of
4683 the block. It could lead to a DECL that has an abstract origin set.
4684 If so, we want that DECL's abstract origin (which is what DECL_ORIGIN
4685 will give us if it has one). Note that DECL's abstract origins are
4686 supposed to be the most distant ancestor (or so decl_ultimate_origin
4687 claims), so we don't need to loop following the DECL origins. */
4688 if (DECL_P (ret_val))
4689 return DECL_ORIGIN (ret_val);
4691 return ret_val;
4695 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4696 of a virtual function may refer to a base class, so we check the 'this'
4697 parameter. */
4699 static tree
4700 decl_class_context (tree decl)
4702 tree context = NULL_TREE;
4704 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4705 context = DECL_CONTEXT (decl);
4706 else
4707 context = TYPE_MAIN_VARIANT
4708 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4710 if (context && !TYPE_P (context))
4711 context = NULL_TREE;
4713 return context;
4716 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4717 addition order, and correct that in reverse_all_dies. */
4719 static inline void
4720 add_dwarf_attr (dw_die_ref die, dw_attr_ref attr)
4722 if (die != NULL && attr != NULL)
4724 attr->dw_attr_next = die->die_attr;
4725 die->die_attr = attr;
4729 static inline enum dw_val_class
4730 AT_class (dw_attr_ref a)
4732 return a->dw_attr_val.val_class;
4735 /* Add a flag value attribute to a DIE. */
4737 static inline void
4738 add_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int flag)
4740 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4742 attr->dw_attr_next = NULL;
4743 attr->dw_attr = attr_kind;
4744 attr->dw_attr_val.val_class = dw_val_class_flag;
4745 attr->dw_attr_val.v.val_flag = flag;
4746 add_dwarf_attr (die, attr);
4749 static inline unsigned
4750 AT_flag (dw_attr_ref a)
4752 gcc_assert (a && AT_class (a) == dw_val_class_flag);
4753 return a->dw_attr_val.v.val_flag;
4756 /* Add a signed integer attribute value to a DIE. */
4758 static inline void
4759 add_AT_int (dw_die_ref die, enum dwarf_attribute attr_kind, HOST_WIDE_INT int_val)
4761 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4763 attr->dw_attr_next = NULL;
4764 attr->dw_attr = attr_kind;
4765 attr->dw_attr_val.val_class = dw_val_class_const;
4766 attr->dw_attr_val.v.val_int = int_val;
4767 add_dwarf_attr (die, attr);
4770 static inline HOST_WIDE_INT
4771 AT_int (dw_attr_ref a)
4773 gcc_assert (a && AT_class (a) == dw_val_class_const);
4774 return a->dw_attr_val.v.val_int;
4777 /* Add an unsigned integer attribute value to a DIE. */
4779 static inline void
4780 add_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind,
4781 unsigned HOST_WIDE_INT unsigned_val)
4783 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4785 attr->dw_attr_next = NULL;
4786 attr->dw_attr = attr_kind;
4787 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4788 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4789 add_dwarf_attr (die, attr);
4792 static inline unsigned HOST_WIDE_INT
4793 AT_unsigned (dw_attr_ref a)
4795 gcc_assert (a && AT_class (a) == dw_val_class_unsigned_const);
4796 return a->dw_attr_val.v.val_unsigned;
4799 /* Add an unsigned double integer attribute value to a DIE. */
4801 static inline void
4802 add_AT_long_long (dw_die_ref die, enum dwarf_attribute attr_kind,
4803 long unsigned int val_hi, long unsigned int val_low)
4805 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4807 attr->dw_attr_next = NULL;
4808 attr->dw_attr = attr_kind;
4809 attr->dw_attr_val.val_class = dw_val_class_long_long;
4810 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4811 attr->dw_attr_val.v.val_long_long.low = val_low;
4812 add_dwarf_attr (die, attr);
4815 /* Add a floating point attribute value to a DIE and return it. */
4817 static inline void
4818 add_AT_vec (dw_die_ref die, enum dwarf_attribute attr_kind,
4819 unsigned int length, unsigned int elt_size, unsigned char *array)
4821 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4823 attr->dw_attr_next = NULL;
4824 attr->dw_attr = attr_kind;
4825 attr->dw_attr_val.val_class = dw_val_class_vec;
4826 attr->dw_attr_val.v.val_vec.length = length;
4827 attr->dw_attr_val.v.val_vec.elt_size = elt_size;
4828 attr->dw_attr_val.v.val_vec.array = array;
4829 add_dwarf_attr (die, attr);
4832 /* Hash and equality functions for debug_str_hash. */
4834 static hashval_t
4835 debug_str_do_hash (const void *x)
4837 return htab_hash_string (((const struct indirect_string_node *)x)->str);
4840 static int
4841 debug_str_eq (const void *x1, const void *x2)
4843 return strcmp ((((const struct indirect_string_node *)x1)->str),
4844 (const char *)x2) == 0;
4847 /* Add a string attribute value to a DIE. */
4849 static inline void
4850 add_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind, const char *str)
4852 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4853 struct indirect_string_node *node;
4854 void **slot;
4856 if (! debug_str_hash)
4857 debug_str_hash = htab_create_ggc (10, debug_str_do_hash,
4858 debug_str_eq, NULL);
4860 slot = htab_find_slot_with_hash (debug_str_hash, str,
4861 htab_hash_string (str), INSERT);
4862 if (*slot == NULL)
4863 *slot = ggc_alloc_cleared (sizeof (struct indirect_string_node));
4864 node = (struct indirect_string_node *) *slot;
4865 node->str = ggc_strdup (str);
4866 node->refcount++;
4868 attr->dw_attr_next = NULL;
4869 attr->dw_attr = attr_kind;
4870 attr->dw_attr_val.val_class = dw_val_class_str;
4871 attr->dw_attr_val.v.val_str = node;
4872 add_dwarf_attr (die, attr);
4875 static inline const char *
4876 AT_string (dw_attr_ref a)
4878 gcc_assert (a && AT_class (a) == dw_val_class_str);
4879 return a->dw_attr_val.v.val_str->str;
4882 /* Find out whether a string should be output inline in DIE
4883 or out-of-line in .debug_str section. */
4885 static int
4886 AT_string_form (dw_attr_ref a)
4888 struct indirect_string_node *node;
4889 unsigned int len;
4890 char label[32];
4892 gcc_assert (a && AT_class (a) == dw_val_class_str);
4894 node = a->dw_attr_val.v.val_str;
4895 if (node->form)
4896 return node->form;
4898 len = strlen (node->str) + 1;
4900 /* If the string is shorter or equal to the size of the reference, it is
4901 always better to put it inline. */
4902 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4903 return node->form = DW_FORM_string;
4905 /* If we cannot expect the linker to merge strings in .debug_str
4906 section, only put it into .debug_str if it is worth even in this
4907 single module. */
4908 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4909 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4910 return node->form = DW_FORM_string;
4912 ASM_GENERATE_INTERNAL_LABEL (label, "LASF", dw2_string_counter);
4913 ++dw2_string_counter;
4914 node->label = xstrdup (label);
4916 return node->form = DW_FORM_strp;
4919 /* Add a DIE reference attribute value to a DIE. */
4921 static inline void
4922 add_AT_die_ref (dw_die_ref die, enum dwarf_attribute attr_kind, dw_die_ref targ_die)
4924 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4926 attr->dw_attr_next = NULL;
4927 attr->dw_attr = attr_kind;
4928 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4929 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4930 attr->dw_attr_val.v.val_die_ref.external = 0;
4931 add_dwarf_attr (die, attr);
4934 /* Add an AT_specification attribute to a DIE, and also make the back
4935 pointer from the specification to the definition. */
4937 static inline void
4938 add_AT_specification (dw_die_ref die, dw_die_ref targ_die)
4940 add_AT_die_ref (die, DW_AT_specification, targ_die);
4941 gcc_assert (!targ_die->die_definition);
4942 targ_die->die_definition = die;
4945 static inline dw_die_ref
4946 AT_ref (dw_attr_ref a)
4948 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4949 return a->dw_attr_val.v.val_die_ref.die;
4952 static inline int
4953 AT_ref_external (dw_attr_ref a)
4955 if (a && AT_class (a) == dw_val_class_die_ref)
4956 return a->dw_attr_val.v.val_die_ref.external;
4958 return 0;
4961 static inline void
4962 set_AT_ref_external (dw_attr_ref a, int i)
4964 gcc_assert (a && AT_class (a) == dw_val_class_die_ref);
4965 a->dw_attr_val.v.val_die_ref.external = i;
4968 /* Add an FDE reference attribute value to a DIE. */
4970 static inline void
4971 add_AT_fde_ref (dw_die_ref die, enum dwarf_attribute attr_kind, unsigned int targ_fde)
4973 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4975 attr->dw_attr_next = NULL;
4976 attr->dw_attr = attr_kind;
4977 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4978 attr->dw_attr_val.v.val_fde_index = targ_fde;
4979 add_dwarf_attr (die, attr);
4982 /* Add a location description attribute value to a DIE. */
4984 static inline void
4985 add_AT_loc (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_descr_ref loc)
4987 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
4989 attr->dw_attr_next = NULL;
4990 attr->dw_attr = attr_kind;
4991 attr->dw_attr_val.val_class = dw_val_class_loc;
4992 attr->dw_attr_val.v.val_loc = loc;
4993 add_dwarf_attr (die, attr);
4996 static inline dw_loc_descr_ref
4997 AT_loc (dw_attr_ref a)
4999 gcc_assert (a && AT_class (a) == dw_val_class_loc);
5000 return a->dw_attr_val.v.val_loc;
5003 static inline void
5004 add_AT_loc_list (dw_die_ref die, enum dwarf_attribute attr_kind, dw_loc_list_ref loc_list)
5006 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5008 attr->dw_attr_next = NULL;
5009 attr->dw_attr = attr_kind;
5010 attr->dw_attr_val.val_class = dw_val_class_loc_list;
5011 attr->dw_attr_val.v.val_loc_list = loc_list;
5012 add_dwarf_attr (die, attr);
5013 have_location_lists = 1;
5016 static inline dw_loc_list_ref
5017 AT_loc_list (dw_attr_ref a)
5019 gcc_assert (a && AT_class (a) == dw_val_class_loc_list);
5020 return a->dw_attr_val.v.val_loc_list;
5023 /* Add an address constant attribute value to a DIE. */
5025 static inline void
5026 add_AT_addr (dw_die_ref die, enum dwarf_attribute attr_kind, rtx addr)
5028 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5030 attr->dw_attr_next = NULL;
5031 attr->dw_attr = attr_kind;
5032 attr->dw_attr_val.val_class = dw_val_class_addr;
5033 attr->dw_attr_val.v.val_addr = addr;
5034 add_dwarf_attr (die, attr);
5037 static inline rtx
5038 AT_addr (dw_attr_ref a)
5040 gcc_assert (a && AT_class (a) == dw_val_class_addr);
5041 return a->dw_attr_val.v.val_addr;
5044 /* Add a label identifier attribute value to a DIE. */
5046 static inline void
5047 add_AT_lbl_id (dw_die_ref die, enum dwarf_attribute attr_kind, const char *lbl_id)
5049 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5051 attr->dw_attr_next = NULL;
5052 attr->dw_attr = attr_kind;
5053 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
5054 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
5055 add_dwarf_attr (die, attr);
5058 /* Add a section offset attribute value to a DIE. */
5060 static inline void
5061 add_AT_lbl_offset (dw_die_ref die, enum dwarf_attribute attr_kind, const char *label)
5063 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5065 attr->dw_attr_next = NULL;
5066 attr->dw_attr = attr_kind;
5067 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
5068 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
5069 add_dwarf_attr (die, attr);
5072 /* Add an offset attribute value to a DIE. */
5074 static inline void
5075 add_AT_offset (dw_die_ref die, enum dwarf_attribute attr_kind,
5076 unsigned HOST_WIDE_INT offset)
5078 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5080 attr->dw_attr_next = NULL;
5081 attr->dw_attr = attr_kind;
5082 attr->dw_attr_val.val_class = dw_val_class_offset;
5083 attr->dw_attr_val.v.val_offset = offset;
5084 add_dwarf_attr (die, attr);
5087 /* Add an range_list attribute value to a DIE. */
5089 static void
5090 add_AT_range_list (dw_die_ref die, enum dwarf_attribute attr_kind,
5091 long unsigned int offset)
5093 dw_attr_ref attr = ggc_alloc (sizeof (dw_attr_node));
5095 attr->dw_attr_next = NULL;
5096 attr->dw_attr = attr_kind;
5097 attr->dw_attr_val.val_class = dw_val_class_range_list;
5098 attr->dw_attr_val.v.val_offset = offset;
5099 add_dwarf_attr (die, attr);
5102 static inline const char *
5103 AT_lbl (dw_attr_ref a)
5105 gcc_assert (a && (AT_class (a) == dw_val_class_lbl_id
5106 || AT_class (a) == dw_val_class_lbl_offset));
5107 return a->dw_attr_val.v.val_lbl_id;
5110 /* Get the attribute of type attr_kind. */
5112 static dw_attr_ref
5113 get_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5115 dw_attr_ref a;
5116 dw_die_ref spec = NULL;
5118 if (die != NULL)
5120 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5121 if (a->dw_attr == attr_kind)
5122 return a;
5123 else if (a->dw_attr == DW_AT_specification
5124 || a->dw_attr == DW_AT_abstract_origin)
5125 spec = AT_ref (a);
5127 if (spec)
5128 return get_AT (spec, attr_kind);
5131 return NULL;
5134 /* Return the "low pc" attribute value, typically associated with a subprogram
5135 DIE. Return null if the "low pc" attribute is either not present, or if it
5136 cannot be represented as an assembler label identifier. */
5138 static inline const char *
5139 get_AT_low_pc (dw_die_ref die)
5141 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
5143 return a ? AT_lbl (a) : NULL;
5146 /* Return the "high pc" attribute value, typically associated with a subprogram
5147 DIE. Return null if the "high pc" attribute is either not present, or if it
5148 cannot be represented as an assembler label identifier. */
5150 static inline const char *
5151 get_AT_hi_pc (dw_die_ref die)
5153 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
5155 return a ? AT_lbl (a) : NULL;
5158 /* Return the value of the string attribute designated by ATTR_KIND, or
5159 NULL if it is not present. */
5161 static inline const char *
5162 get_AT_string (dw_die_ref die, enum dwarf_attribute attr_kind)
5164 dw_attr_ref a = get_AT (die, attr_kind);
5166 return a ? AT_string (a) : NULL;
5169 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
5170 if it is not present. */
5172 static inline int
5173 get_AT_flag (dw_die_ref die, enum dwarf_attribute attr_kind)
5175 dw_attr_ref a = get_AT (die, attr_kind);
5177 return a ? AT_flag (a) : 0;
5180 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
5181 if it is not present. */
5183 static inline unsigned
5184 get_AT_unsigned (dw_die_ref die, enum dwarf_attribute attr_kind)
5186 dw_attr_ref a = get_AT (die, attr_kind);
5188 return a ? AT_unsigned (a) : 0;
5191 static inline dw_die_ref
5192 get_AT_ref (dw_die_ref die, enum dwarf_attribute attr_kind)
5194 dw_attr_ref a = get_AT (die, attr_kind);
5196 return a ? AT_ref (a) : NULL;
5199 /* Return TRUE if the language is C or C++. */
5201 static inline bool
5202 is_c_family (void)
5204 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5206 return (lang == DW_LANG_C || lang == DW_LANG_C89
5207 || lang == DW_LANG_C_plus_plus);
5210 /* Return TRUE if the language is C++. */
5212 static inline bool
5213 is_cxx (void)
5215 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
5216 == DW_LANG_C_plus_plus);
5219 /* Return TRUE if the language is Fortran. */
5221 static inline bool
5222 is_fortran (void)
5224 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5226 return (lang == DW_LANG_Fortran77
5227 || lang == DW_LANG_Fortran90
5228 || lang == DW_LANG_Fortran95);
5231 /* Return TRUE if the language is Java. */
5233 static inline bool
5234 is_java (void)
5236 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5238 return lang == DW_LANG_Java;
5241 /* Return TRUE if the language is Ada. */
5243 static inline bool
5244 is_ada (void)
5246 unsigned int lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
5248 return lang == DW_LANG_Ada95 || lang == DW_LANG_Ada83;
5251 /* Free up the memory used by A. */
5253 static inline void free_AT (dw_attr_ref);
5254 static inline void
5255 free_AT (dw_attr_ref a)
5257 if (AT_class (a) == dw_val_class_str)
5258 if (a->dw_attr_val.v.val_str->refcount)
5259 a->dw_attr_val.v.val_str->refcount--;
5262 /* Remove the specified attribute if present. */
5264 static void
5265 remove_AT (dw_die_ref die, enum dwarf_attribute attr_kind)
5267 dw_attr_ref *p;
5268 dw_attr_ref removed = NULL;
5270 if (die != NULL)
5272 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
5273 if ((*p)->dw_attr == attr_kind)
5275 removed = *p;
5276 *p = (*p)->dw_attr_next;
5277 break;
5280 if (removed != 0)
5281 free_AT (removed);
5285 /* Remove child die whose die_tag is specified tag. */
5287 static void
5288 remove_child_TAG (dw_die_ref die, enum dwarf_tag tag)
5290 dw_die_ref current, prev, next;
5291 current = die->die_child;
5292 prev = NULL;
5293 while (current != NULL)
5295 if (current->die_tag == tag)
5297 next = current->die_sib;
5298 if (prev == NULL)
5299 die->die_child = next;
5300 else
5301 prev->die_sib = next;
5302 free_die (current);
5303 current = next;
5305 else
5307 prev = current;
5308 current = current->die_sib;
5313 /* Free up the memory used by DIE. */
5315 static inline void
5316 free_die (dw_die_ref die)
5318 remove_children (die);
5321 /* Discard the children of this DIE. */
5323 static void
5324 remove_children (dw_die_ref die)
5326 dw_die_ref child_die = die->die_child;
5328 die->die_child = NULL;
5330 while (child_die != NULL)
5332 dw_die_ref tmp_die = child_die;
5333 dw_attr_ref a;
5335 child_die = child_die->die_sib;
5337 for (a = tmp_die->die_attr; a != NULL;)
5339 dw_attr_ref tmp_a = a;
5341 a = a->dw_attr_next;
5342 free_AT (tmp_a);
5345 free_die (tmp_die);
5349 /* Add a child DIE below its parent. We build the lists up in reverse
5350 addition order, and correct that in reverse_all_dies. */
5352 static inline void
5353 add_child_die (dw_die_ref die, dw_die_ref child_die)
5355 if (die != NULL && child_die != NULL)
5357 gcc_assert (die != child_die);
5359 child_die->die_parent = die;
5360 child_die->die_sib = die->die_child;
5361 die->die_child = child_die;
5365 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5366 is the specification, to the front of PARENT's list of children. */
5368 static void
5369 splice_child_die (dw_die_ref parent, dw_die_ref child)
5371 dw_die_ref *p;
5373 /* We want the declaration DIE from inside the class, not the
5374 specification DIE at toplevel. */
5375 if (child->die_parent != parent)
5377 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5379 if (tmp)
5380 child = tmp;
5383 gcc_assert (child->die_parent == parent
5384 || (child->die_parent
5385 == get_AT_ref (parent, DW_AT_specification)));
5387 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5388 if (*p == child)
5390 *p = child->die_sib;
5391 break;
5394 child->die_parent = parent;
5395 child->die_sib = parent->die_child;
5396 parent->die_child = child;
5399 /* Return a pointer to a newly created DIE node. */
5401 static inline dw_die_ref
5402 new_die (enum dwarf_tag tag_value, dw_die_ref parent_die, tree t)
5404 dw_die_ref die = ggc_alloc_cleared (sizeof (die_node));
5406 die->die_tag = tag_value;
5408 if (parent_die != NULL)
5409 add_child_die (parent_die, die);
5410 else
5412 limbo_die_node *limbo_node;
5414 limbo_node = ggc_alloc_cleared (sizeof (limbo_die_node));
5415 limbo_node->die = die;
5416 limbo_node->created_for = t;
5417 limbo_node->next = limbo_die_list;
5418 limbo_die_list = limbo_node;
5421 return die;
5424 /* Return the DIE associated with the given type specifier. */
5426 static inline dw_die_ref
5427 lookup_type_die (tree type)
5429 return TYPE_SYMTAB_DIE (type);
5432 /* Equate a DIE to a given type specifier. */
5434 static inline void
5435 equate_type_number_to_die (tree type, dw_die_ref type_die)
5437 TYPE_SYMTAB_DIE (type) = type_die;
5440 /* Returns a hash value for X (which really is a die_struct). */
5442 static hashval_t
5443 decl_die_table_hash (const void *x)
5445 return (hashval_t) ((const dw_die_ref) x)->decl_id;
5448 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5450 static int
5451 decl_die_table_eq (const void *x, const void *y)
5453 return (((const dw_die_ref) x)->decl_id == DECL_UID ((const tree) y));
5456 /* Return the DIE associated with a given declaration. */
5458 static inline dw_die_ref
5459 lookup_decl_die (tree decl)
5461 return htab_find_with_hash (decl_die_table, decl, DECL_UID (decl));
5464 /* Returns a hash value for X (which really is a var_loc_list). */
5466 static hashval_t
5467 decl_loc_table_hash (const void *x)
5469 return (hashval_t) ((const var_loc_list *) x)->decl_id;
5472 /* Return nonzero if decl_id of var_loc_list X is the same as
5473 UID of decl *Y. */
5475 static int
5476 decl_loc_table_eq (const void *x, const void *y)
5478 return (((const var_loc_list *) x)->decl_id == DECL_UID ((const tree) y));
5481 /* Return the var_loc list associated with a given declaration. */
5483 static inline var_loc_list *
5484 lookup_decl_loc (tree decl)
5486 return htab_find_with_hash (decl_loc_table, decl, DECL_UID (decl));
5489 /* Equate a DIE to a particular declaration. */
5491 static void
5492 equate_decl_number_to_die (tree decl, dw_die_ref decl_die)
5494 unsigned int decl_id = DECL_UID (decl);
5495 void **slot;
5497 slot = htab_find_slot_with_hash (decl_die_table, decl, decl_id, INSERT);
5498 *slot = decl_die;
5499 decl_die->decl_id = decl_id;
5502 /* Add a variable location node to the linked list for DECL. */
5504 static void
5505 add_var_loc_to_decl (tree decl, struct var_loc_node *loc)
5507 unsigned int decl_id = DECL_UID (decl);
5508 var_loc_list *temp;
5509 void **slot;
5511 slot = htab_find_slot_with_hash (decl_loc_table, decl, decl_id, INSERT);
5512 if (*slot == NULL)
5514 temp = ggc_alloc_cleared (sizeof (var_loc_list));
5515 temp->decl_id = decl_id;
5516 *slot = temp;
5518 else
5519 temp = *slot;
5521 if (temp->last)
5523 /* If the current location is the same as the end of the list,
5524 we have nothing to do. */
5525 if (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp->last->var_loc_note),
5526 NOTE_VAR_LOCATION_LOC (loc->var_loc_note)))
5528 /* Add LOC to the end of list and update LAST. */
5529 temp->last->next = loc;
5530 temp->last = loc;
5533 /* Do not add empty location to the beginning of the list. */
5534 else if (NOTE_VAR_LOCATION_LOC (loc->var_loc_note) != NULL_RTX)
5536 temp->first = loc;
5537 temp->last = loc;
5541 /* Keep track of the number of spaces used to indent the
5542 output of the debugging routines that print the structure of
5543 the DIE internal representation. */
5544 static int print_indent;
5546 /* Indent the line the number of spaces given by print_indent. */
5548 static inline void
5549 print_spaces (FILE *outfile)
5551 fprintf (outfile, "%*s", print_indent, "");
5554 /* Print the information associated with a given DIE, and its children.
5555 This routine is a debugging aid only. */
5557 static void
5558 print_die (dw_die_ref die, FILE *outfile)
5560 dw_attr_ref a;
5561 dw_die_ref c;
5563 print_spaces (outfile);
5564 fprintf (outfile, "DIE %4lu: %s\n",
5565 die->die_offset, dwarf_tag_name (die->die_tag));
5566 print_spaces (outfile);
5567 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5568 fprintf (outfile, " offset: %lu\n", die->die_offset);
5570 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5572 print_spaces (outfile);
5573 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5575 switch (AT_class (a))
5577 case dw_val_class_addr:
5578 fprintf (outfile, "address");
5579 break;
5580 case dw_val_class_offset:
5581 fprintf (outfile, "offset");
5582 break;
5583 case dw_val_class_loc:
5584 fprintf (outfile, "location descriptor");
5585 break;
5586 case dw_val_class_loc_list:
5587 fprintf (outfile, "location list -> label:%s",
5588 AT_loc_list (a)->ll_symbol);
5589 break;
5590 case dw_val_class_range_list:
5591 fprintf (outfile, "range list");
5592 break;
5593 case dw_val_class_const:
5594 fprintf (outfile, HOST_WIDE_INT_PRINT_DEC, AT_int (a));
5595 break;
5596 case dw_val_class_unsigned_const:
5597 fprintf (outfile, HOST_WIDE_INT_PRINT_UNSIGNED, AT_unsigned (a));
5598 break;
5599 case dw_val_class_long_long:
5600 fprintf (outfile, "constant (%lu,%lu)",
5601 a->dw_attr_val.v.val_long_long.hi,
5602 a->dw_attr_val.v.val_long_long.low);
5603 break;
5604 case dw_val_class_vec:
5605 fprintf (outfile, "floating-point or vector constant");
5606 break;
5607 case dw_val_class_flag:
5608 fprintf (outfile, "%u", AT_flag (a));
5609 break;
5610 case dw_val_class_die_ref:
5611 if (AT_ref (a) != NULL)
5613 if (AT_ref (a)->die_symbol)
5614 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5615 else
5616 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5618 else
5619 fprintf (outfile, "die -> <null>");
5620 break;
5621 case dw_val_class_lbl_id:
5622 case dw_val_class_lbl_offset:
5623 fprintf (outfile, "label: %s", AT_lbl (a));
5624 break;
5625 case dw_val_class_str:
5626 if (AT_string (a) != NULL)
5627 fprintf (outfile, "\"%s\"", AT_string (a));
5628 else
5629 fprintf (outfile, "<null>");
5630 break;
5631 default:
5632 break;
5635 fprintf (outfile, "\n");
5638 if (die->die_child != NULL)
5640 print_indent += 4;
5641 for (c = die->die_child; c != NULL; c = c->die_sib)
5642 print_die (c, outfile);
5644 print_indent -= 4;
5646 if (print_indent == 0)
5647 fprintf (outfile, "\n");
5650 /* Print the contents of the source code line number correspondence table.
5651 This routine is a debugging aid only. */
5653 static void
5654 print_dwarf_line_table (FILE *outfile)
5656 unsigned i;
5657 dw_line_info_ref line_info;
5659 fprintf (outfile, "\n\nDWARF source line information\n");
5660 for (i = 1; i < line_info_table_in_use; i++)
5662 line_info = &line_info_table[i];
5663 fprintf (outfile, "%5d: ", i);
5664 fprintf (outfile, "%-20s",
5665 VARRAY_CHAR_PTR (file_table, line_info->dw_file_num));
5666 fprintf (outfile, "%6ld", line_info->dw_line_num);
5667 fprintf (outfile, "\n");
5670 fprintf (outfile, "\n\n");
5673 /* Print the information collected for a given DIE. */
5675 void
5676 debug_dwarf_die (dw_die_ref die)
5678 print_die (die, stderr);
5681 /* Print all DWARF information collected for the compilation unit.
5682 This routine is a debugging aid only. */
5684 void
5685 debug_dwarf (void)
5687 print_indent = 0;
5688 print_die (comp_unit_die, stderr);
5689 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5690 print_dwarf_line_table (stderr);
5693 /* We build up the lists of children and attributes by pushing new ones
5694 onto the beginning of the list. Reverse the lists for DIE so that
5695 they are in order of addition. */
5697 static void
5698 reverse_die_lists (dw_die_ref die)
5700 dw_die_ref c, cp, cn;
5701 dw_attr_ref a, ap, an;
5703 for (a = die->die_attr, ap = 0; a; a = an)
5705 an = a->dw_attr_next;
5706 a->dw_attr_next = ap;
5707 ap = a;
5710 die->die_attr = ap;
5712 for (c = die->die_child, cp = 0; c; c = cn)
5714 cn = c->die_sib;
5715 c->die_sib = cp;
5716 cp = c;
5719 die->die_child = cp;
5722 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5723 reverse all dies in add_sibling_attributes, which runs through all the dies,
5724 it would reverse all the dies. Now, however, since we don't call
5725 reverse_die_lists in add_sibling_attributes, we need a routine to
5726 recursively reverse all the dies. This is that routine. */
5728 static void
5729 reverse_all_dies (dw_die_ref die)
5731 dw_die_ref c;
5733 reverse_die_lists (die);
5735 for (c = die->die_child; c; c = c->die_sib)
5736 reverse_all_dies (c);
5739 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5740 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5741 DIE that marks the start of the DIEs for this include file. */
5743 static dw_die_ref
5744 push_new_compile_unit (dw_die_ref old_unit, dw_die_ref bincl_die)
5746 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5747 dw_die_ref new_unit = gen_compile_unit_die (filename);
5749 new_unit->die_sib = old_unit;
5750 return new_unit;
5753 /* Close an include-file CU and reopen the enclosing one. */
5755 static dw_die_ref
5756 pop_compile_unit (dw_die_ref old_unit)
5758 dw_die_ref new_unit = old_unit->die_sib;
5760 old_unit->die_sib = NULL;
5761 return new_unit;
5764 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5765 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5767 /* Calculate the checksum of a location expression. */
5769 static inline void
5770 loc_checksum (dw_loc_descr_ref loc, struct md5_ctx *ctx)
5772 CHECKSUM (loc->dw_loc_opc);
5773 CHECKSUM (loc->dw_loc_oprnd1);
5774 CHECKSUM (loc->dw_loc_oprnd2);
5777 /* Calculate the checksum of an attribute. */
5779 static void
5780 attr_checksum (dw_attr_ref at, struct md5_ctx *ctx, int *mark)
5782 dw_loc_descr_ref loc;
5783 rtx r;
5785 CHECKSUM (at->dw_attr);
5787 /* We don't care about differences in file numbering. */
5788 if (at->dw_attr == DW_AT_decl_file
5789 /* Or that this was compiled with a different compiler snapshot; if
5790 the output is the same, that's what matters. */
5791 || at->dw_attr == DW_AT_producer)
5792 return;
5794 switch (AT_class (at))
5796 case dw_val_class_const:
5797 CHECKSUM (at->dw_attr_val.v.val_int);
5798 break;
5799 case dw_val_class_unsigned_const:
5800 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5801 break;
5802 case dw_val_class_long_long:
5803 CHECKSUM (at->dw_attr_val.v.val_long_long);
5804 break;
5805 case dw_val_class_vec:
5806 CHECKSUM (at->dw_attr_val.v.val_vec);
5807 break;
5808 case dw_val_class_flag:
5809 CHECKSUM (at->dw_attr_val.v.val_flag);
5810 break;
5811 case dw_val_class_str:
5812 CHECKSUM_STRING (AT_string (at));
5813 break;
5815 case dw_val_class_addr:
5816 r = AT_addr (at);
5817 gcc_assert (GET_CODE (r) == SYMBOL_REF);
5818 CHECKSUM_STRING (XSTR (r, 0));
5819 break;
5821 case dw_val_class_offset:
5822 CHECKSUM (at->dw_attr_val.v.val_offset);
5823 break;
5825 case dw_val_class_loc:
5826 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5827 loc_checksum (loc, ctx);
5828 break;
5830 case dw_val_class_die_ref:
5831 die_checksum (AT_ref (at), ctx, mark);
5832 break;
5834 case dw_val_class_fde_ref:
5835 case dw_val_class_lbl_id:
5836 case dw_val_class_lbl_offset:
5837 break;
5839 default:
5840 break;
5844 /* Calculate the checksum of a DIE. */
5846 static void
5847 die_checksum (dw_die_ref die, struct md5_ctx *ctx, int *mark)
5849 dw_die_ref c;
5850 dw_attr_ref a;
5852 /* To avoid infinite recursion. */
5853 if (die->die_mark)
5855 CHECKSUM (die->die_mark);
5856 return;
5858 die->die_mark = ++(*mark);
5860 CHECKSUM (die->die_tag);
5862 for (a = die->die_attr; a; a = a->dw_attr_next)
5863 attr_checksum (a, ctx, mark);
5865 for (c = die->die_child; c; c = c->die_sib)
5866 die_checksum (c, ctx, mark);
5869 #undef CHECKSUM
5870 #undef CHECKSUM_STRING
5872 /* Do the location expressions look same? */
5873 static inline int
5874 same_loc_p (dw_loc_descr_ref loc1, dw_loc_descr_ref loc2, int *mark)
5876 return loc1->dw_loc_opc == loc2->dw_loc_opc
5877 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark)
5878 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark);
5881 /* Do the values look the same? */
5882 static int
5883 same_dw_val_p (dw_val_node *v1, dw_val_node *v2, int *mark)
5885 dw_loc_descr_ref loc1, loc2;
5886 rtx r1, r2;
5888 if (v1->val_class != v2->val_class)
5889 return 0;
5891 switch (v1->val_class)
5893 case dw_val_class_const:
5894 return v1->v.val_int == v2->v.val_int;
5895 case dw_val_class_unsigned_const:
5896 return v1->v.val_unsigned == v2->v.val_unsigned;
5897 case dw_val_class_long_long:
5898 return v1->v.val_long_long.hi == v2->v.val_long_long.hi
5899 && v1->v.val_long_long.low == v2->v.val_long_long.low;
5900 case dw_val_class_vec:
5901 if (v1->v.val_vec.length != v2->v.val_vec.length
5902 || v1->v.val_vec.elt_size != v2->v.val_vec.elt_size)
5903 return 0;
5904 if (memcmp (v1->v.val_vec.array, v2->v.val_vec.array,
5905 v1->v.val_vec.length * v1->v.val_vec.elt_size))
5906 return 0;
5907 return 1;
5908 case dw_val_class_flag:
5909 return v1->v.val_flag == v2->v.val_flag;
5910 case dw_val_class_str:
5911 return !strcmp(v1->v.val_str->str, v2->v.val_str->str);
5913 case dw_val_class_addr:
5914 r1 = v1->v.val_addr;
5915 r2 = v2->v.val_addr;
5916 if (GET_CODE (r1) != GET_CODE (r2))
5917 return 0;
5918 gcc_assert (GET_CODE (r1) == SYMBOL_REF);
5919 return !strcmp (XSTR (r1, 0), XSTR (r2, 0));
5921 case dw_val_class_offset:
5922 return v1->v.val_offset == v2->v.val_offset;
5924 case dw_val_class_loc:
5925 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc;
5926 loc1 && loc2;
5927 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next)
5928 if (!same_loc_p (loc1, loc2, mark))
5929 return 0;
5930 return !loc1 && !loc2;
5932 case dw_val_class_die_ref:
5933 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark);
5935 case dw_val_class_fde_ref:
5936 case dw_val_class_lbl_id:
5937 case dw_val_class_lbl_offset:
5938 return 1;
5940 default:
5941 return 1;
5945 /* Do the attributes look the same? */
5947 static int
5948 same_attr_p (dw_attr_ref at1, dw_attr_ref at2, int *mark)
5950 if (at1->dw_attr != at2->dw_attr)
5951 return 0;
5953 /* We don't care about differences in file numbering. */
5954 if (at1->dw_attr == DW_AT_decl_file
5955 /* Or that this was compiled with a different compiler snapshot; if
5956 the output is the same, that's what matters. */
5957 || at1->dw_attr == DW_AT_producer)
5958 return 1;
5960 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark);
5963 /* Do the dies look the same? */
5965 static int
5966 same_die_p (dw_die_ref die1, dw_die_ref die2, int *mark)
5968 dw_die_ref c1, c2;
5969 dw_attr_ref a1, a2;
5971 /* To avoid infinite recursion. */
5972 if (die1->die_mark)
5973 return die1->die_mark == die2->die_mark;
5974 die1->die_mark = die2->die_mark = ++(*mark);
5976 if (die1->die_tag != die2->die_tag)
5977 return 0;
5979 for (a1 = die1->die_attr, a2 = die2->die_attr;
5980 a1 && a2;
5981 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next)
5982 if (!same_attr_p (a1, a2, mark))
5983 return 0;
5984 if (a1 || a2)
5985 return 0;
5987 for (c1 = die1->die_child, c2 = die2->die_child;
5988 c1 && c2;
5989 c1 = c1->die_sib, c2 = c2->die_sib)
5990 if (!same_die_p (c1, c2, mark))
5991 return 0;
5992 if (c1 || c2)
5993 return 0;
5995 return 1;
5998 /* Do the dies look the same? Wrapper around same_die_p. */
6000 static int
6001 same_die_p_wrap (dw_die_ref die1, dw_die_ref die2)
6003 int mark = 0;
6004 int ret = same_die_p (die1, die2, &mark);
6006 unmark_all_dies (die1);
6007 unmark_all_dies (die2);
6009 return ret;
6012 /* The prefix to attach to symbols on DIEs in the current comdat debug
6013 info section. */
6014 static char *comdat_symbol_id;
6016 /* The index of the current symbol within the current comdat CU. */
6017 static unsigned int comdat_symbol_number;
6019 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6020 children, and set comdat_symbol_id accordingly. */
6022 static void
6023 compute_section_prefix (dw_die_ref unit_die)
6025 const char *die_name = get_AT_string (unit_die, DW_AT_name);
6026 const char *base = die_name ? lbasename (die_name) : "anonymous";
6027 char *name = alloca (strlen (base) + 64);
6028 char *p;
6029 int i, mark;
6030 unsigned char checksum[16];
6031 struct md5_ctx ctx;
6033 /* Compute the checksum of the DIE, then append part of it as hex digits to
6034 the name filename of the unit. */
6036 md5_init_ctx (&ctx);
6037 mark = 0;
6038 die_checksum (unit_die, &ctx, &mark);
6039 unmark_all_dies (unit_die);
6040 md5_finish_ctx (&ctx, checksum);
6042 sprintf (name, "%s.", base);
6043 clean_symbol_name (name);
6045 p = name + strlen (name);
6046 for (i = 0; i < 4; i++)
6048 sprintf (p, "%.2x", checksum[i]);
6049 p += 2;
6052 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
6053 comdat_symbol_number = 0;
6056 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6058 static int
6059 is_type_die (dw_die_ref die)
6061 switch (die->die_tag)
6063 case DW_TAG_array_type:
6064 case DW_TAG_class_type:
6065 case DW_TAG_enumeration_type:
6066 case DW_TAG_pointer_type:
6067 case DW_TAG_reference_type:
6068 case DW_TAG_string_type:
6069 case DW_TAG_structure_type:
6070 case DW_TAG_subroutine_type:
6071 case DW_TAG_union_type:
6072 case DW_TAG_ptr_to_member_type:
6073 case DW_TAG_set_type:
6074 case DW_TAG_subrange_type:
6075 case DW_TAG_base_type:
6076 case DW_TAG_const_type:
6077 case DW_TAG_file_type:
6078 case DW_TAG_packed_type:
6079 case DW_TAG_volatile_type:
6080 case DW_TAG_typedef:
6081 return 1;
6082 default:
6083 return 0;
6087 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6088 Basically, we want to choose the bits that are likely to be shared between
6089 compilations (types) and leave out the bits that are specific to individual
6090 compilations (functions). */
6092 static int
6093 is_comdat_die (dw_die_ref c)
6095 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6096 we do for stabs. The advantage is a greater likelihood of sharing between
6097 objects that don't include headers in the same order (and therefore would
6098 put the base types in a different comdat). jason 8/28/00 */
6100 if (c->die_tag == DW_TAG_base_type)
6101 return 0;
6103 if (c->die_tag == DW_TAG_pointer_type
6104 || c->die_tag == DW_TAG_reference_type
6105 || c->die_tag == DW_TAG_const_type
6106 || c->die_tag == DW_TAG_volatile_type)
6108 dw_die_ref t = get_AT_ref (c, DW_AT_type);
6110 return t ? is_comdat_die (t) : 0;
6113 return is_type_die (c);
6116 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6117 compilation unit. */
6119 static int
6120 is_symbol_die (dw_die_ref c)
6122 return (is_type_die (c)
6123 || (get_AT (c, DW_AT_declaration)
6124 && !get_AT (c, DW_AT_specification)));
6127 static char *
6128 gen_internal_sym (const char *prefix)
6130 char buf[256];
6132 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
6133 return xstrdup (buf);
6136 /* Assign symbols to all worthy DIEs under DIE. */
6138 static void
6139 assign_symbol_names (dw_die_ref die)
6141 dw_die_ref c;
6143 if (is_symbol_die (die))
6145 if (comdat_symbol_id)
6147 char *p = alloca (strlen (comdat_symbol_id) + 64);
6149 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
6150 comdat_symbol_id, comdat_symbol_number++);
6151 die->die_symbol = xstrdup (p);
6153 else
6154 die->die_symbol = gen_internal_sym ("LDIE");
6157 for (c = die->die_child; c != NULL; c = c->die_sib)
6158 assign_symbol_names (c);
6161 struct cu_hash_table_entry
6163 dw_die_ref cu;
6164 unsigned min_comdat_num, max_comdat_num;
6165 struct cu_hash_table_entry *next;
6168 /* Routines to manipulate hash table of CUs. */
6169 static hashval_t
6170 htab_cu_hash (const void *of)
6172 const struct cu_hash_table_entry *entry = of;
6174 return htab_hash_string (entry->cu->die_symbol);
6177 static int
6178 htab_cu_eq (const void *of1, const void *of2)
6180 const struct cu_hash_table_entry *entry1 = of1;
6181 const struct die_struct *entry2 = of2;
6183 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol);
6186 static void
6187 htab_cu_del (void *what)
6189 struct cu_hash_table_entry *next, *entry = what;
6191 while (entry)
6193 next = entry->next;
6194 free (entry);
6195 entry = next;
6199 /* Check whether we have already seen this CU and set up SYM_NUM
6200 accordingly. */
6201 static int
6202 check_duplicate_cu (dw_die_ref cu, htab_t htable, unsigned int *sym_num)
6204 struct cu_hash_table_entry dummy;
6205 struct cu_hash_table_entry **slot, *entry, *last = &dummy;
6207 dummy.max_comdat_num = 0;
6209 slot = (struct cu_hash_table_entry **)
6210 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6211 INSERT);
6212 entry = *slot;
6214 for (; entry; last = entry, entry = entry->next)
6216 if (same_die_p_wrap (cu, entry->cu))
6217 break;
6220 if (entry)
6222 *sym_num = entry->min_comdat_num;
6223 return 1;
6226 entry = xcalloc (1, sizeof (struct cu_hash_table_entry));
6227 entry->cu = cu;
6228 entry->min_comdat_num = *sym_num = last->max_comdat_num;
6229 entry->next = *slot;
6230 *slot = entry;
6232 return 0;
6235 /* Record SYM_NUM to record of CU in HTABLE. */
6236 static void
6237 record_comdat_symbol_number (dw_die_ref cu, htab_t htable, unsigned int sym_num)
6239 struct cu_hash_table_entry **slot, *entry;
6241 slot = (struct cu_hash_table_entry **)
6242 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol),
6243 NO_INSERT);
6244 entry = *slot;
6246 entry->max_comdat_num = sym_num;
6249 /* Traverse the DIE (which is always comp_unit_die), and set up
6250 additional compilation units for each of the include files we see
6251 bracketed by BINCL/EINCL. */
6253 static void
6254 break_out_includes (dw_die_ref die)
6256 dw_die_ref *ptr;
6257 dw_die_ref unit = NULL;
6258 limbo_die_node *node, **pnode;
6259 htab_t cu_hash_table;
6261 for (ptr = &(die->die_child); *ptr;)
6263 dw_die_ref c = *ptr;
6265 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
6266 || (unit && is_comdat_die (c)))
6268 /* This DIE is for a secondary CU; remove it from the main one. */
6269 *ptr = c->die_sib;
6271 if (c->die_tag == DW_TAG_GNU_BINCL)
6273 unit = push_new_compile_unit (unit, c);
6274 free_die (c);
6276 else if (c->die_tag == DW_TAG_GNU_EINCL)
6278 unit = pop_compile_unit (unit);
6279 free_die (c);
6281 else
6282 add_child_die (unit, c);
6284 else
6286 /* Leave this DIE in the main CU. */
6287 ptr = &(c->die_sib);
6288 continue;
6292 #if 0
6293 /* We can only use this in debugging, since the frontend doesn't check
6294 to make sure that we leave every include file we enter. */
6295 gcc_assert (!unit);
6296 #endif
6298 assign_symbol_names (die);
6299 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del);
6300 for (node = limbo_die_list, pnode = &limbo_die_list;
6301 node;
6302 node = node->next)
6304 int is_dupl;
6306 compute_section_prefix (node->die);
6307 is_dupl = check_duplicate_cu (node->die, cu_hash_table,
6308 &comdat_symbol_number);
6309 assign_symbol_names (node->die);
6310 if (is_dupl)
6311 *pnode = node->next;
6312 else
6314 pnode = &node->next;
6315 record_comdat_symbol_number (node->die, cu_hash_table,
6316 comdat_symbol_number);
6319 htab_delete (cu_hash_table);
6322 /* Traverse the DIE and add a sibling attribute if it may have the
6323 effect of speeding up access to siblings. To save some space,
6324 avoid generating sibling attributes for DIE's without children. */
6326 static void
6327 add_sibling_attributes (dw_die_ref die)
6329 dw_die_ref c;
6331 if (die->die_tag != DW_TAG_compile_unit
6332 && die->die_sib && die->die_child != NULL)
6333 /* Add the sibling link to the front of the attribute list. */
6334 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
6336 for (c = die->die_child; c != NULL; c = c->die_sib)
6337 add_sibling_attributes (c);
6340 /* Output all location lists for the DIE and its children. */
6342 static void
6343 output_location_lists (dw_die_ref die)
6345 dw_die_ref c;
6346 dw_attr_ref d_attr;
6348 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6349 if (AT_class (d_attr) == dw_val_class_loc_list)
6350 output_loc_list (AT_loc_list (d_attr));
6352 for (c = die->die_child; c != NULL; c = c->die_sib)
6353 output_location_lists (c);
6357 /* The format of each DIE (and its attribute value pairs) is encoded in an
6358 abbreviation table. This routine builds the abbreviation table and assigns
6359 a unique abbreviation id for each abbreviation entry. The children of each
6360 die are visited recursively. */
6362 static void
6363 build_abbrev_table (dw_die_ref die)
6365 unsigned long abbrev_id;
6366 unsigned int n_alloc;
6367 dw_die_ref c;
6368 dw_attr_ref d_attr, a_attr;
6370 /* Scan the DIE references, and mark as external any that refer to
6371 DIEs from other CUs (i.e. those which are not marked). */
6372 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
6373 if (AT_class (d_attr) == dw_val_class_die_ref
6374 && AT_ref (d_attr)->die_mark == 0)
6376 gcc_assert (AT_ref (d_attr)->die_symbol);
6378 set_AT_ref_external (d_attr, 1);
6381 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6383 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6385 if (abbrev->die_tag == die->die_tag)
6387 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
6389 a_attr = abbrev->die_attr;
6390 d_attr = die->die_attr;
6392 while (a_attr != NULL && d_attr != NULL)
6394 if ((a_attr->dw_attr != d_attr->dw_attr)
6395 || (value_format (a_attr) != value_format (d_attr)))
6396 break;
6398 a_attr = a_attr->dw_attr_next;
6399 d_attr = d_attr->dw_attr_next;
6402 if (a_attr == NULL && d_attr == NULL)
6403 break;
6408 if (abbrev_id >= abbrev_die_table_in_use)
6410 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
6412 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
6413 abbrev_die_table = ggc_realloc (abbrev_die_table,
6414 sizeof (dw_die_ref) * n_alloc);
6416 memset (&abbrev_die_table[abbrev_die_table_allocated], 0,
6417 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
6418 abbrev_die_table_allocated = n_alloc;
6421 ++abbrev_die_table_in_use;
6422 abbrev_die_table[abbrev_id] = die;
6425 die->die_abbrev = abbrev_id;
6426 for (c = die->die_child; c != NULL; c = c->die_sib)
6427 build_abbrev_table (c);
6430 /* Return the power-of-two number of bytes necessary to represent VALUE. */
6432 static int
6433 constant_size (long unsigned int value)
6435 int log;
6437 if (value == 0)
6438 log = 0;
6439 else
6440 log = floor_log2 (value);
6442 log = log / 8;
6443 log = 1 << (floor_log2 (log) + 1);
6445 return log;
6448 /* Return the size of a DIE as it is represented in the
6449 .debug_info section. */
6451 static unsigned long
6452 size_of_die (dw_die_ref die)
6454 unsigned long size = 0;
6455 dw_attr_ref a;
6457 size += size_of_uleb128 (die->die_abbrev);
6458 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6460 switch (AT_class (a))
6462 case dw_val_class_addr:
6463 size += DWARF2_ADDR_SIZE;
6464 break;
6465 case dw_val_class_offset:
6466 size += DWARF_OFFSET_SIZE;
6467 break;
6468 case dw_val_class_loc:
6470 unsigned long lsize = size_of_locs (AT_loc (a));
6472 /* Block length. */
6473 size += constant_size (lsize);
6474 size += lsize;
6476 break;
6477 case dw_val_class_loc_list:
6478 size += DWARF_OFFSET_SIZE;
6479 break;
6480 case dw_val_class_range_list:
6481 size += DWARF_OFFSET_SIZE;
6482 break;
6483 case dw_val_class_const:
6484 size += size_of_sleb128 (AT_int (a));
6485 break;
6486 case dw_val_class_unsigned_const:
6487 size += constant_size (AT_unsigned (a));
6488 break;
6489 case dw_val_class_long_long:
6490 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
6491 break;
6492 case dw_val_class_vec:
6493 size += 1 + (a->dw_attr_val.v.val_vec.length
6494 * a->dw_attr_val.v.val_vec.elt_size); /* block */
6495 break;
6496 case dw_val_class_flag:
6497 size += 1;
6498 break;
6499 case dw_val_class_die_ref:
6500 if (AT_ref_external (a))
6501 size += DWARF2_ADDR_SIZE;
6502 else
6503 size += DWARF_OFFSET_SIZE;
6504 break;
6505 case dw_val_class_fde_ref:
6506 size += DWARF_OFFSET_SIZE;
6507 break;
6508 case dw_val_class_lbl_id:
6509 size += DWARF2_ADDR_SIZE;
6510 break;
6511 case dw_val_class_lbl_offset:
6512 size += DWARF_OFFSET_SIZE;
6513 break;
6514 case dw_val_class_str:
6515 if (AT_string_form (a) == DW_FORM_strp)
6516 size += DWARF_OFFSET_SIZE;
6517 else
6518 size += strlen (a->dw_attr_val.v.val_str->str) + 1;
6519 break;
6520 default:
6521 gcc_unreachable ();
6525 return size;
6528 /* Size the debugging information associated with a given DIE. Visits the
6529 DIE's children recursively. Updates the global variable next_die_offset, on
6530 each time through. Uses the current value of next_die_offset to update the
6531 die_offset field in each DIE. */
6533 static void
6534 calc_die_sizes (dw_die_ref die)
6536 dw_die_ref c;
6538 die->die_offset = next_die_offset;
6539 next_die_offset += size_of_die (die);
6541 for (c = die->die_child; c != NULL; c = c->die_sib)
6542 calc_die_sizes (c);
6544 if (die->die_child != NULL)
6545 /* Count the null byte used to terminate sibling lists. */
6546 next_die_offset += 1;
6549 /* Set the marks for a die and its children. We do this so
6550 that we know whether or not a reference needs to use FORM_ref_addr; only
6551 DIEs in the same CU will be marked. We used to clear out the offset
6552 and use that as the flag, but ran into ordering problems. */
6554 static void
6555 mark_dies (dw_die_ref die)
6557 dw_die_ref c;
6559 gcc_assert (!die->die_mark);
6561 die->die_mark = 1;
6562 for (c = die->die_child; c; c = c->die_sib)
6563 mark_dies (c);
6566 /* Clear the marks for a die and its children. */
6568 static void
6569 unmark_dies (dw_die_ref die)
6571 dw_die_ref c;
6573 gcc_assert (die->die_mark);
6575 die->die_mark = 0;
6576 for (c = die->die_child; c; c = c->die_sib)
6577 unmark_dies (c);
6580 /* Clear the marks for a die, its children and referred dies. */
6582 static void
6583 unmark_all_dies (dw_die_ref die)
6585 dw_die_ref c;
6586 dw_attr_ref a;
6588 if (!die->die_mark)
6589 return;
6590 die->die_mark = 0;
6592 for (c = die->die_child; c; c = c->die_sib)
6593 unmark_all_dies (c);
6595 for (a = die->die_attr; a; a = a->dw_attr_next)
6596 if (AT_class (a) == dw_val_class_die_ref)
6597 unmark_all_dies (AT_ref (a));
6600 /* Return the size of the .debug_pubnames table generated for the
6601 compilation unit. */
6603 static unsigned long
6604 size_of_pubnames (void)
6606 unsigned long size;
6607 unsigned i;
6609 size = DWARF_PUBNAMES_HEADER_SIZE;
6610 for (i = 0; i < pubname_table_in_use; i++)
6612 pubname_ref p = &pubname_table[i];
6613 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
6616 size += DWARF_OFFSET_SIZE;
6617 return size;
6620 /* Return the size of the information in the .debug_aranges section. */
6622 static unsigned long
6623 size_of_aranges (void)
6625 unsigned long size;
6627 size = DWARF_ARANGES_HEADER_SIZE;
6629 /* Count the address/length pair for this compilation unit. */
6630 size += 2 * DWARF2_ADDR_SIZE;
6631 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6633 /* Count the two zero words used to terminated the address range table. */
6634 size += 2 * DWARF2_ADDR_SIZE;
6635 return size;
6638 /* Select the encoding of an attribute value. */
6640 static enum dwarf_form
6641 value_format (dw_attr_ref a)
6643 switch (a->dw_attr_val.val_class)
6645 case dw_val_class_addr:
6646 return DW_FORM_addr;
6647 case dw_val_class_range_list:
6648 case dw_val_class_offset:
6649 switch (DWARF_OFFSET_SIZE)
6651 case 4:
6652 return DW_FORM_data4;
6653 case 8:
6654 return DW_FORM_data8;
6655 default:
6656 gcc_unreachable ();
6658 case dw_val_class_loc_list:
6659 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6660 .debug_loc section */
6661 return DW_FORM_data4;
6662 case dw_val_class_loc:
6663 switch (constant_size (size_of_locs (AT_loc (a))))
6665 case 1:
6666 return DW_FORM_block1;
6667 case 2:
6668 return DW_FORM_block2;
6669 default:
6670 gcc_unreachable ();
6672 case dw_val_class_const:
6673 return DW_FORM_sdata;
6674 case dw_val_class_unsigned_const:
6675 switch (constant_size (AT_unsigned (a)))
6677 case 1:
6678 return DW_FORM_data1;
6679 case 2:
6680 return DW_FORM_data2;
6681 case 4:
6682 return DW_FORM_data4;
6683 case 8:
6684 return DW_FORM_data8;
6685 default:
6686 gcc_unreachable ();
6688 case dw_val_class_long_long:
6689 return DW_FORM_block1;
6690 case dw_val_class_vec:
6691 return DW_FORM_block1;
6692 case dw_val_class_flag:
6693 return DW_FORM_flag;
6694 case dw_val_class_die_ref:
6695 if (AT_ref_external (a))
6696 return DW_FORM_ref_addr;
6697 else
6698 return DW_FORM_ref;
6699 case dw_val_class_fde_ref:
6700 return DW_FORM_data;
6701 case dw_val_class_lbl_id:
6702 return DW_FORM_addr;
6703 case dw_val_class_lbl_offset:
6704 return DW_FORM_data;
6705 case dw_val_class_str:
6706 return AT_string_form (a);
6708 default:
6709 gcc_unreachable ();
6713 /* Output the encoding of an attribute value. */
6715 static void
6716 output_value_format (dw_attr_ref a)
6718 enum dwarf_form form = value_format (a);
6720 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6723 /* Output the .debug_abbrev section which defines the DIE abbreviation
6724 table. */
6726 static void
6727 output_abbrev_section (void)
6729 unsigned long abbrev_id;
6731 dw_attr_ref a_attr;
6733 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6735 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6737 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6738 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6739 dwarf_tag_name (abbrev->die_tag));
6741 if (abbrev->die_child != NULL)
6742 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6743 else
6744 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6746 for (a_attr = abbrev->die_attr; a_attr != NULL;
6747 a_attr = a_attr->dw_attr_next)
6749 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6750 dwarf_attr_name (a_attr->dw_attr));
6751 output_value_format (a_attr);
6754 dw2_asm_output_data (1, 0, NULL);
6755 dw2_asm_output_data (1, 0, NULL);
6758 /* Terminate the table. */
6759 dw2_asm_output_data (1, 0, NULL);
6762 /* Output a symbol we can use to refer to this DIE from another CU. */
6764 static inline void
6765 output_die_symbol (dw_die_ref die)
6767 char *sym = die->die_symbol;
6769 if (sym == 0)
6770 return;
6772 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6773 /* We make these global, not weak; if the target doesn't support
6774 .linkonce, it doesn't support combining the sections, so debugging
6775 will break. */
6776 targetm.asm_out.globalize_label (asm_out_file, sym);
6778 ASM_OUTPUT_LABEL (asm_out_file, sym);
6781 /* Return a new location list, given the begin and end range, and the
6782 expression. gensym tells us whether to generate a new internal symbol for
6783 this location list node, which is done for the head of the list only. */
6785 static inline dw_loc_list_ref
6786 new_loc_list (dw_loc_descr_ref expr, const char *begin, const char *end,
6787 const char *section, unsigned int gensym)
6789 dw_loc_list_ref retlist = ggc_alloc_cleared (sizeof (dw_loc_list_node));
6791 retlist->begin = begin;
6792 retlist->end = end;
6793 retlist->expr = expr;
6794 retlist->section = section;
6795 if (gensym)
6796 retlist->ll_symbol = gen_internal_sym ("LLST");
6798 return retlist;
6801 /* Add a location description expression to a location list. */
6803 static inline void
6804 add_loc_descr_to_loc_list (dw_loc_list_ref *list_head, dw_loc_descr_ref descr,
6805 const char *begin, const char *end,
6806 const char *section)
6808 dw_loc_list_ref *d;
6810 /* Find the end of the chain. */
6811 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6814 /* Add a new location list node to the list. */
6815 *d = new_loc_list (descr, begin, end, section, 0);
6818 static void
6819 dwarf2out_switch_text_section (void)
6821 dw_fde_ref fde;
6823 gcc_assert (cfun);
6825 fde = &fde_table[fde_table_in_use - 1];
6826 fde->dw_fde_switched_sections = true;
6827 fde->dw_fde_hot_section_label = cfun->hot_section_label;
6828 fde->dw_fde_hot_section_end_label = cfun->hot_section_end_label;
6829 fde->dw_fde_unlikely_section_label = cfun->cold_section_label;
6830 fde->dw_fde_unlikely_section_end_label = cfun->cold_section_end_label;
6831 separate_line_info_table_in_use++;
6834 /* Output the location list given to us. */
6836 static void
6837 output_loc_list (dw_loc_list_ref list_head)
6839 dw_loc_list_ref curr = list_head;
6841 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6843 /* Walk the location list, and output each range + expression. */
6844 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next)
6846 unsigned long size;
6847 if (separate_line_info_table_in_use == 0)
6849 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6850 "Location list begin address (%s)",
6851 list_head->ll_symbol);
6852 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6853 "Location list end address (%s)",
6854 list_head->ll_symbol);
6856 else
6858 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->begin,
6859 "Location list begin address (%s)",
6860 list_head->ll_symbol);
6861 dw2_asm_output_addr (DWARF2_ADDR_SIZE, curr->end,
6862 "Location list end address (%s)",
6863 list_head->ll_symbol);
6865 size = size_of_locs (curr->expr);
6867 /* Output the block length for this list of location operations. */
6868 gcc_assert (size <= 0xffff);
6869 dw2_asm_output_data (2, size, "%s", "Location expression size");
6871 output_loc_sequence (curr->expr);
6874 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6875 "Location list terminator begin (%s)",
6876 list_head->ll_symbol);
6877 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0,
6878 "Location list terminator end (%s)",
6879 list_head->ll_symbol);
6882 /* Output the DIE and its attributes. Called recursively to generate
6883 the definitions of each child DIE. */
6885 static void
6886 output_die (dw_die_ref die)
6888 dw_attr_ref a;
6889 dw_die_ref c;
6890 unsigned long size;
6892 /* If someone in another CU might refer to us, set up a symbol for
6893 them to point to. */
6894 if (die->die_symbol)
6895 output_die_symbol (die);
6897 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6898 die->die_offset, dwarf_tag_name (die->die_tag));
6900 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6902 const char *name = dwarf_attr_name (a->dw_attr);
6904 switch (AT_class (a))
6906 case dw_val_class_addr:
6907 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6908 break;
6910 case dw_val_class_offset:
6911 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6912 "%s", name);
6913 break;
6915 case dw_val_class_range_list:
6917 char *p = strchr (ranges_section_label, '\0');
6919 sprintf (p, "+" HOST_WIDE_INT_PRINT_HEX,
6920 a->dw_attr_val.v.val_offset);
6921 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6922 "%s", name);
6923 *p = '\0';
6925 break;
6927 case dw_val_class_loc:
6928 size = size_of_locs (AT_loc (a));
6930 /* Output the block length for this list of location operations. */
6931 dw2_asm_output_data (constant_size (size), size, "%s", name);
6933 output_loc_sequence (AT_loc (a));
6934 break;
6936 case dw_val_class_const:
6937 /* ??? It would be slightly more efficient to use a scheme like is
6938 used for unsigned constants below, but gdb 4.x does not sign
6939 extend. Gdb 5.x does sign extend. */
6940 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6941 break;
6943 case dw_val_class_unsigned_const:
6944 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6945 AT_unsigned (a), "%s", name);
6946 break;
6948 case dw_val_class_long_long:
6950 unsigned HOST_WIDE_INT first, second;
6952 dw2_asm_output_data (1,
6953 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6954 "%s", name);
6956 if (WORDS_BIG_ENDIAN)
6958 first = a->dw_attr_val.v.val_long_long.hi;
6959 second = a->dw_attr_val.v.val_long_long.low;
6961 else
6963 first = a->dw_attr_val.v.val_long_long.low;
6964 second = a->dw_attr_val.v.val_long_long.hi;
6967 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6968 first, "long long constant");
6969 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6970 second, NULL);
6972 break;
6974 case dw_val_class_vec:
6976 unsigned int elt_size = a->dw_attr_val.v.val_vec.elt_size;
6977 unsigned int len = a->dw_attr_val.v.val_vec.length;
6978 unsigned int i;
6979 unsigned char *p;
6981 dw2_asm_output_data (1, len * elt_size, "%s", name);
6982 if (elt_size > sizeof (HOST_WIDE_INT))
6984 elt_size /= 2;
6985 len *= 2;
6987 for (i = 0, p = a->dw_attr_val.v.val_vec.array;
6988 i < len;
6989 i++, p += elt_size)
6990 dw2_asm_output_data (elt_size, extract_int (p, elt_size),
6991 "fp or vector constant word %u", i);
6992 break;
6995 case dw_val_class_flag:
6996 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6997 break;
6999 case dw_val_class_loc_list:
7001 char *sym = AT_loc_list (a)->ll_symbol;
7003 gcc_assert (sym);
7004 dw2_asm_output_offset (DWARF_OFFSET_SIZE, sym, "%s", name);
7006 break;
7008 case dw_val_class_die_ref:
7009 if (AT_ref_external (a))
7011 char *sym = AT_ref (a)->die_symbol;
7013 gcc_assert (sym);
7014 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
7016 else
7018 gcc_assert (AT_ref (a)->die_offset);
7019 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
7020 "%s", name);
7022 break;
7024 case dw_val_class_fde_ref:
7026 char l1[20];
7028 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
7029 a->dw_attr_val.v.val_fde_index * 2);
7030 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
7032 break;
7034 case dw_val_class_lbl_id:
7035 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
7036 break;
7038 case dw_val_class_lbl_offset:
7039 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
7040 break;
7042 case dw_val_class_str:
7043 if (AT_string_form (a) == DW_FORM_strp)
7044 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
7045 a->dw_attr_val.v.val_str->label,
7046 "%s: \"%s\"", name, AT_string (a));
7047 else
7048 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
7049 break;
7051 default:
7052 gcc_unreachable ();
7056 for (c = die->die_child; c != NULL; c = c->die_sib)
7057 output_die (c);
7059 /* Add null byte to terminate sibling list. */
7060 if (die->die_child != NULL)
7061 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
7062 die->die_offset);
7065 /* Output the compilation unit that appears at the beginning of the
7066 .debug_info section, and precedes the DIE descriptions. */
7068 static void
7069 output_compilation_unit_header (void)
7071 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7072 dw2_asm_output_data (4, 0xffffffff,
7073 "Initial length escape value indicating 64-bit DWARF extension");
7074 dw2_asm_output_data (DWARF_OFFSET_SIZE,
7075 next_die_offset - DWARF_INITIAL_LENGTH_SIZE,
7076 "Length of Compilation Unit Info");
7077 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
7078 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
7079 "Offset Into Abbrev. Section");
7080 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
7083 /* Output the compilation unit DIE and its children. */
7085 static void
7086 output_comp_unit (dw_die_ref die, int output_if_empty)
7088 const char *secname;
7089 char *oldsym, *tmp;
7091 /* Unless we are outputting main CU, we may throw away empty ones. */
7092 if (!output_if_empty && die->die_child == NULL)
7093 return;
7095 /* Even if there are no children of this DIE, we must output the information
7096 about the compilation unit. Otherwise, on an empty translation unit, we
7097 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
7098 will then complain when examining the file. First mark all the DIEs in
7099 this CU so we know which get local refs. */
7100 mark_dies (die);
7102 build_abbrev_table (die);
7104 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
7105 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
7106 calc_die_sizes (die);
7108 oldsym = die->die_symbol;
7109 if (oldsym)
7111 tmp = alloca (strlen (oldsym) + 24);
7113 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym);
7114 secname = tmp;
7115 die->die_symbol = NULL;
7117 else
7118 secname = (const char *) DEBUG_INFO_SECTION;
7120 /* Output debugging information. */
7121 named_section_flags (secname, SECTION_DEBUG);
7122 output_compilation_unit_header ();
7123 output_die (die);
7125 /* Leave the marks on the main CU, so we can check them in
7126 output_pubnames. */
7127 if (oldsym)
7129 unmark_dies (die);
7130 die->die_symbol = oldsym;
7134 /* The DWARF2 pubname for a nested thingy looks like "A::f". The
7135 output of lang_hooks.decl_printable_name for C++ looks like
7136 "A::f(int)". Let's drop the argument list, and maybe the scope. */
7138 static const char *
7139 dwarf2_name (tree decl, int scope)
7141 return lang_hooks.decl_printable_name (decl, scope ? 1 : 0);
7144 /* Add a new entry to .debug_pubnames if appropriate. */
7146 static void
7147 add_pubname (tree decl, dw_die_ref die)
7149 pubname_ref p;
7151 if (! TREE_PUBLIC (decl))
7152 return;
7154 if (pubname_table_in_use == pubname_table_allocated)
7156 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
7157 pubname_table
7158 = ggc_realloc (pubname_table,
7159 (pubname_table_allocated * sizeof (pubname_entry)));
7160 memset (pubname_table + pubname_table_in_use, 0,
7161 PUBNAME_TABLE_INCREMENT * sizeof (pubname_entry));
7164 p = &pubname_table[pubname_table_in_use++];
7165 p->die = die;
7166 p->name = xstrdup (dwarf2_name (decl, 1));
7169 /* Output the public names table used to speed up access to externally
7170 visible names. For now, only generate entries for externally
7171 visible procedures. */
7173 static void
7174 output_pubnames (void)
7176 unsigned i;
7177 unsigned long pubnames_length = size_of_pubnames ();
7179 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7180 dw2_asm_output_data (4, 0xffffffff,
7181 "Initial length escape value indicating 64-bit DWARF extension");
7182 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
7183 "Length of Public Names Info");
7184 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7185 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7186 "Offset of Compilation Unit Info");
7187 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
7188 "Compilation Unit Length");
7190 for (i = 0; i < pubname_table_in_use; i++)
7192 pubname_ref pub = &pubname_table[i];
7194 /* We shouldn't see pubnames for DIEs outside of the main CU. */
7195 gcc_assert (pub->die->die_mark);
7197 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
7198 "DIE offset");
7200 dw2_asm_output_nstring (pub->name, -1, "external name");
7203 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
7206 /* Add a new entry to .debug_aranges if appropriate. */
7208 static void
7209 add_arange (tree decl, dw_die_ref die)
7211 if (! DECL_SECTION_NAME (decl))
7212 return;
7214 if (arange_table_in_use == arange_table_allocated)
7216 arange_table_allocated += ARANGE_TABLE_INCREMENT;
7217 arange_table = ggc_realloc (arange_table,
7218 (arange_table_allocated
7219 * sizeof (dw_die_ref)));
7220 memset (arange_table + arange_table_in_use, 0,
7221 ARANGE_TABLE_INCREMENT * sizeof (dw_die_ref));
7224 arange_table[arange_table_in_use++] = die;
7227 /* Output the information that goes into the .debug_aranges table.
7228 Namely, define the beginning and ending address range of the
7229 text section generated for this compilation unit. */
7231 static void
7232 output_aranges (void)
7234 unsigned i;
7235 unsigned long aranges_length = size_of_aranges ();
7237 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7238 dw2_asm_output_data (4, 0xffffffff,
7239 "Initial length escape value indicating 64-bit DWARF extension");
7240 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
7241 "Length of Address Ranges Info");
7242 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7243 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
7244 "Offset of Compilation Unit Info");
7245 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
7246 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
7248 /* We need to align to twice the pointer size here. */
7249 if (DWARF_ARANGES_PAD_SIZE)
7251 /* Pad using a 2 byte words so that padding is correct for any
7252 pointer size. */
7253 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
7254 2 * DWARF2_ADDR_SIZE);
7255 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
7256 dw2_asm_output_data (2, 0, NULL);
7259 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
7260 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
7261 text_section_label, "Length");
7262 if (flag_reorder_blocks_and_partition)
7264 dw2_asm_output_addr (DWARF2_ADDR_SIZE, cold_text_section_label,
7265 "Address");
7266 dw2_asm_output_delta (DWARF2_ADDR_SIZE, cold_end_label,
7267 cold_text_section_label, "Length");
7270 for (i = 0; i < arange_table_in_use; i++)
7272 dw_die_ref die = arange_table[i];
7274 /* We shouldn't see aranges for DIEs outside of the main CU. */
7275 gcc_assert (die->die_mark);
7277 if (die->die_tag == DW_TAG_subprogram)
7279 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
7280 "Address");
7281 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
7282 get_AT_low_pc (die), "Length");
7284 else
7286 /* A static variable; extract the symbol from DW_AT_location.
7287 Note that this code isn't currently hit, as we only emit
7288 aranges for functions (jason 9/23/99). */
7289 dw_attr_ref a = get_AT (die, DW_AT_location);
7290 dw_loc_descr_ref loc;
7292 gcc_assert (a && AT_class (a) == dw_val_class_loc);
7294 loc = AT_loc (a);
7295 gcc_assert (loc->dw_loc_opc == DW_OP_addr);
7297 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
7298 loc->dw_loc_oprnd1.v.val_addr, "Address");
7299 dw2_asm_output_data (DWARF2_ADDR_SIZE,
7300 get_AT_unsigned (die, DW_AT_byte_size),
7301 "Length");
7305 /* Output the terminator words. */
7306 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7307 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7310 /* Add a new entry to .debug_ranges. Return the offset at which it
7311 was placed. */
7313 static unsigned int
7314 add_ranges (tree block)
7316 unsigned int in_use = ranges_table_in_use;
7318 if (in_use == ranges_table_allocated)
7320 ranges_table_allocated += RANGES_TABLE_INCREMENT;
7321 ranges_table
7322 = ggc_realloc (ranges_table, (ranges_table_allocated
7323 * sizeof (struct dw_ranges_struct)));
7324 memset (ranges_table + ranges_table_in_use, 0,
7325 RANGES_TABLE_INCREMENT * sizeof (struct dw_ranges_struct));
7328 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
7329 ranges_table_in_use = in_use + 1;
7331 return in_use * 2 * DWARF2_ADDR_SIZE;
7334 static void
7335 output_ranges (void)
7337 unsigned i;
7338 static const char *const start_fmt = "Offset 0x%x";
7339 const char *fmt = start_fmt;
7341 for (i = 0; i < ranges_table_in_use; i++)
7343 int block_num = ranges_table[i].block_num;
7345 if (block_num)
7347 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
7348 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
7350 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
7351 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
7353 /* If all code is in the text section, then the compilation
7354 unit base address defaults to DW_AT_low_pc, which is the
7355 base of the text section. */
7356 if (separate_line_info_table_in_use == 0)
7358 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
7359 text_section_label,
7360 fmt, i * 2 * DWARF2_ADDR_SIZE);
7361 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
7362 text_section_label, NULL);
7365 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
7366 compilation unit base address to zero, which allows us to
7367 use absolute addresses, and not worry about whether the
7368 target supports cross-section arithmetic. */
7369 else
7371 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
7372 fmt, i * 2 * DWARF2_ADDR_SIZE);
7373 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
7376 fmt = NULL;
7378 else
7380 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7381 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
7382 fmt = start_fmt;
7387 /* Data structure containing information about input files. */
7388 struct file_info
7390 char *path; /* Complete file name. */
7391 char *fname; /* File name part. */
7392 int length; /* Length of entire string. */
7393 int file_idx; /* Index in input file table. */
7394 int dir_idx; /* Index in directory table. */
7397 /* Data structure containing information about directories with source
7398 files. */
7399 struct dir_info
7401 char *path; /* Path including directory name. */
7402 int length; /* Path length. */
7403 int prefix; /* Index of directory entry which is a prefix. */
7404 int count; /* Number of files in this directory. */
7405 int dir_idx; /* Index of directory used as base. */
7406 int used; /* Used in the end? */
7409 /* Callback function for file_info comparison. We sort by looking at
7410 the directories in the path. */
7412 static int
7413 file_info_cmp (const void *p1, const void *p2)
7415 const struct file_info *s1 = p1;
7416 const struct file_info *s2 = p2;
7417 unsigned char *cp1;
7418 unsigned char *cp2;
7420 /* Take care of file names without directories. We need to make sure that
7421 we return consistent values to qsort since some will get confused if
7422 we return the same value when identical operands are passed in opposite
7423 orders. So if neither has a directory, return 0 and otherwise return
7424 1 or -1 depending on which one has the directory. */
7425 if ((s1->path == s1->fname || s2->path == s2->fname))
7426 return (s2->path == s2->fname) - (s1->path == s1->fname);
7428 cp1 = (unsigned char *) s1->path;
7429 cp2 = (unsigned char *) s2->path;
7431 while (1)
7433 ++cp1;
7434 ++cp2;
7435 /* Reached the end of the first path? If so, handle like above. */
7436 if ((cp1 == (unsigned char *) s1->fname)
7437 || (cp2 == (unsigned char *) s2->fname))
7438 return ((cp2 == (unsigned char *) s2->fname)
7439 - (cp1 == (unsigned char *) s1->fname));
7441 /* Character of current path component the same? */
7442 else if (*cp1 != *cp2)
7443 return *cp1 - *cp2;
7447 /* Output the directory table and the file name table. We try to minimize
7448 the total amount of memory needed. A heuristic is used to avoid large
7449 slowdowns with many input files. */
7451 static void
7452 output_file_names (void)
7454 struct file_info *files;
7455 struct dir_info *dirs;
7456 int *saved;
7457 int *savehere;
7458 int *backmap;
7459 size_t ndirs;
7460 int idx_offset;
7461 size_t i;
7462 int idx;
7464 /* Handle the case where file_table is empty. */
7465 if (VARRAY_ACTIVE_SIZE (file_table) <= 1)
7467 dw2_asm_output_data (1, 0, "End directory table");
7468 dw2_asm_output_data (1, 0, "End file name table");
7469 return;
7472 /* Allocate the various arrays we need. */
7473 files = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct file_info));
7474 dirs = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (struct dir_info));
7476 /* Sort the file names. */
7477 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7479 char *f;
7481 /* Skip all leading "./". */
7482 f = VARRAY_CHAR_PTR (file_table, i);
7483 while (f[0] == '.' && f[1] == '/')
7484 f += 2;
7486 /* Create a new array entry. */
7487 files[i].path = f;
7488 files[i].length = strlen (f);
7489 files[i].file_idx = i;
7491 /* Search for the file name part. */
7492 f = strrchr (f, '/');
7493 files[i].fname = f == NULL ? files[i].path : f + 1;
7496 qsort (files + 1, VARRAY_ACTIVE_SIZE (file_table) - 1,
7497 sizeof (files[0]), file_info_cmp);
7499 /* Find all the different directories used. */
7500 dirs[0].path = files[1].path;
7501 dirs[0].length = files[1].fname - files[1].path;
7502 dirs[0].prefix = -1;
7503 dirs[0].count = 1;
7504 dirs[0].dir_idx = 0;
7505 dirs[0].used = 0;
7506 files[1].dir_idx = 0;
7507 ndirs = 1;
7509 for (i = 2; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7510 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
7511 && memcmp (dirs[ndirs - 1].path, files[i].path,
7512 dirs[ndirs - 1].length) == 0)
7514 /* Same directory as last entry. */
7515 files[i].dir_idx = ndirs - 1;
7516 ++dirs[ndirs - 1].count;
7518 else
7520 size_t j;
7522 /* This is a new directory. */
7523 dirs[ndirs].path = files[i].path;
7524 dirs[ndirs].length = files[i].fname - files[i].path;
7525 dirs[ndirs].count = 1;
7526 dirs[ndirs].dir_idx = ndirs;
7527 dirs[ndirs].used = 0;
7528 files[i].dir_idx = ndirs;
7530 /* Search for a prefix. */
7531 dirs[ndirs].prefix = -1;
7532 for (j = 0; j < ndirs; j++)
7533 if (dirs[j].length < dirs[ndirs].length
7534 && dirs[j].length > 1
7535 && (dirs[ndirs].prefix == -1
7536 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
7537 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
7538 dirs[ndirs].prefix = j;
7540 ++ndirs;
7543 /* Now to the actual work. We have to find a subset of the directories which
7544 allow expressing the file name using references to the directory table
7545 with the least amount of characters. We do not do an exhaustive search
7546 where we would have to check out every combination of every single
7547 possible prefix. Instead we use a heuristic which provides nearly optimal
7548 results in most cases and never is much off. */
7549 saved = alloca (ndirs * sizeof (int));
7550 savehere = alloca (ndirs * sizeof (int));
7552 memset (saved, '\0', ndirs * sizeof (saved[0]));
7553 for (i = 0; i < ndirs; i++)
7555 size_t j;
7556 int total;
7558 /* We can always save some space for the current directory. But this
7559 does not mean it will be enough to justify adding the directory. */
7560 savehere[i] = dirs[i].length;
7561 total = (savehere[i] - saved[i]) * dirs[i].count;
7563 for (j = i + 1; j < ndirs; j++)
7565 savehere[j] = 0;
7566 if (saved[j] < dirs[i].length)
7568 /* Determine whether the dirs[i] path is a prefix of the
7569 dirs[j] path. */
7570 int k;
7572 k = dirs[j].prefix;
7573 while (k != -1 && k != (int) i)
7574 k = dirs[k].prefix;
7576 if (k == (int) i)
7578 /* Yes it is. We can possibly safe some memory but
7579 writing the filenames in dirs[j] relative to
7580 dirs[i]. */
7581 savehere[j] = dirs[i].length;
7582 total += (savehere[j] - saved[j]) * dirs[j].count;
7587 /* Check whether we can safe enough to justify adding the dirs[i]
7588 directory. */
7589 if (total > dirs[i].length + 1)
7591 /* It's worthwhile adding. */
7592 for (j = i; j < ndirs; j++)
7593 if (savehere[j] > 0)
7595 /* Remember how much we saved for this directory so far. */
7596 saved[j] = savehere[j];
7598 /* Remember the prefix directory. */
7599 dirs[j].dir_idx = i;
7604 /* We have to emit them in the order they appear in the file_table array
7605 since the index is used in the debug info generation. To do this
7606 efficiently we generate a back-mapping of the indices first. */
7607 backmap = alloca (VARRAY_ACTIVE_SIZE (file_table) * sizeof (int));
7608 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7610 backmap[files[i].file_idx] = i;
7612 /* Mark this directory as used. */
7613 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
7616 /* That was it. We are ready to emit the information. First emit the
7617 directory name table. We have to make sure the first actually emitted
7618 directory name has index one; zero is reserved for the current working
7619 directory. Make sure we do not confuse these indices with the one for the
7620 constructed table (even though most of the time they are identical). */
7621 idx = 1;
7622 idx_offset = dirs[0].length > 0 ? 1 : 0;
7623 for (i = 1 - idx_offset; i < ndirs; i++)
7624 if (dirs[i].used != 0)
7626 dirs[i].used = idx++;
7627 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
7628 "Directory Entry: 0x%x", dirs[i].used);
7631 dw2_asm_output_data (1, 0, "End directory table");
7633 /* Correct the index for the current working directory entry if it
7634 exists. */
7635 if (idx_offset == 0)
7636 dirs[0].used = 0;
7638 /* Now write all the file names. */
7639 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
7641 int file_idx = backmap[i];
7642 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
7644 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
7645 "File Entry: 0x%lx", (unsigned long) i);
7647 /* Include directory index. */
7648 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
7650 /* Modification time. */
7651 dw2_asm_output_data_uleb128 (0, NULL);
7653 /* File length in bytes. */
7654 dw2_asm_output_data_uleb128 (0, NULL);
7657 dw2_asm_output_data (1, 0, "End file name table");
7661 /* Output the source line number correspondence information. This
7662 information goes into the .debug_line section. */
7664 static void
7665 output_line_info (void)
7667 char l1[20], l2[20], p1[20], p2[20];
7668 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7669 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7670 unsigned opc;
7671 unsigned n_op_args;
7672 unsigned long lt_index;
7673 unsigned long current_line;
7674 long line_offset;
7675 long line_delta;
7676 unsigned long current_file;
7677 unsigned long function;
7679 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7680 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7681 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7682 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7684 if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4)
7685 dw2_asm_output_data (4, 0xffffffff,
7686 "Initial length escape value indicating 64-bit DWARF extension");
7687 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7688 "Length of Source Line Info");
7689 ASM_OUTPUT_LABEL (asm_out_file, l1);
7691 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7692 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7693 ASM_OUTPUT_LABEL (asm_out_file, p1);
7695 /* Define the architecture-dependent minimum instruction length (in
7696 bytes). In this implementation of DWARF, this field is used for
7697 information purposes only. Since GCC generates assembly language,
7698 we have no a priori knowledge of how many instruction bytes are
7699 generated for each source line, and therefore can use only the
7700 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7701 commands. Accordingly, we fix this as `1', which is "correct
7702 enough" for all architectures, and don't let the target override. */
7703 dw2_asm_output_data (1, 1,
7704 "Minimum Instruction Length");
7706 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7707 "Default is_stmt_start flag");
7708 dw2_asm_output_data (1, DWARF_LINE_BASE,
7709 "Line Base Value (Special Opcodes)");
7710 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7711 "Line Range Value (Special Opcodes)");
7712 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7713 "Special Opcode Base");
7715 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7717 switch (opc)
7719 case DW_LNS_advance_pc:
7720 case DW_LNS_advance_line:
7721 case DW_LNS_set_file:
7722 case DW_LNS_set_column:
7723 case DW_LNS_fixed_advance_pc:
7724 n_op_args = 1;
7725 break;
7726 default:
7727 n_op_args = 0;
7728 break;
7731 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7732 opc, n_op_args);
7735 /* Write out the information about the files we use. */
7736 output_file_names ();
7737 ASM_OUTPUT_LABEL (asm_out_file, p2);
7739 /* We used to set the address register to the first location in the text
7740 section here, but that didn't accomplish anything since we already
7741 have a line note for the opening brace of the first function. */
7743 /* Generate the line number to PC correspondence table, encoded as
7744 a series of state machine operations. */
7745 current_file = 1;
7746 current_line = 1;
7748 if (cfun
7749 && (last_text_section == in_unlikely_executed_text
7750 || (last_text_section == in_named
7751 && last_text_section_name == cfun->unlikely_text_section_name)))
7752 strcpy (prev_line_label, cfun->cold_section_label);
7753 else
7754 strcpy (prev_line_label, text_section_label);
7755 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7757 dw_line_info_ref line_info = &line_info_table[lt_index];
7759 #if 0
7760 /* Disable this optimization for now; GDB wants to see two line notes
7761 at the beginning of a function so it can find the end of the
7762 prologue. */
7764 /* Don't emit anything for redundant notes. Just updating the
7765 address doesn't accomplish anything, because we already assume
7766 that anything after the last address is this line. */
7767 if (line_info->dw_line_num == current_line
7768 && line_info->dw_file_num == current_file)
7769 continue;
7770 #endif
7772 /* Emit debug info for the address of the current line.
7774 Unfortunately, we have little choice here currently, and must always
7775 use the most general form. GCC does not know the address delta
7776 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7777 attributes which will give an upper bound on the address range. We
7778 could perhaps use length attributes to determine when it is safe to
7779 use DW_LNS_fixed_advance_pc. */
7781 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7782 if (0)
7784 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7785 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7786 "DW_LNS_fixed_advance_pc");
7787 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7789 else
7791 /* This can handle any delta. This takes
7792 4+DWARF2_ADDR_SIZE bytes. */
7793 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7794 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7795 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7796 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7799 strcpy (prev_line_label, line_label);
7801 /* Emit debug info for the source file of the current line, if
7802 different from the previous line. */
7803 if (line_info->dw_file_num != current_file)
7805 current_file = line_info->dw_file_num;
7806 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7807 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7808 VARRAY_CHAR_PTR (file_table,
7809 current_file));
7812 /* Emit debug info for the current line number, choosing the encoding
7813 that uses the least amount of space. */
7814 if (line_info->dw_line_num != current_line)
7816 line_offset = line_info->dw_line_num - current_line;
7817 line_delta = line_offset - DWARF_LINE_BASE;
7818 current_line = line_info->dw_line_num;
7819 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7820 /* This can handle deltas from -10 to 234, using the current
7821 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7822 takes 1 byte. */
7823 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7824 "line %lu", current_line);
7825 else
7827 /* This can handle any delta. This takes at least 4 bytes,
7828 depending on the value being encoded. */
7829 dw2_asm_output_data (1, DW_LNS_advance_line,
7830 "advance to line %lu", current_line);
7831 dw2_asm_output_data_sleb128 (line_offset, NULL);
7832 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7835 else
7836 /* We still need to start a new row, so output a copy insn. */
7837 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7840 /* Emit debug info for the address of the end of the function. */
7841 if (0)
7843 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7844 "DW_LNS_fixed_advance_pc");
7845 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7847 else
7849 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7850 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7851 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7852 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7855 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7856 dw2_asm_output_data_uleb128 (1, NULL);
7857 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7859 function = 0;
7860 current_file = 1;
7861 current_line = 1;
7862 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7864 dw_separate_line_info_ref line_info
7865 = &separate_line_info_table[lt_index];
7867 #if 0
7868 /* Don't emit anything for redundant notes. */
7869 if (line_info->dw_line_num == current_line
7870 && line_info->dw_file_num == current_file
7871 && line_info->function == function)
7872 goto cont;
7873 #endif
7875 /* Emit debug info for the address of the current line. If this is
7876 a new function, or the first line of a function, then we need
7877 to handle it differently. */
7878 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7879 lt_index);
7880 if (function != line_info->function)
7882 function = line_info->function;
7884 /* Set the address register to the first line in the function. */
7885 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7886 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7887 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7888 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7890 else
7892 /* ??? See the DW_LNS_advance_pc comment above. */
7893 if (0)
7895 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7896 "DW_LNS_fixed_advance_pc");
7897 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7899 else
7901 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7902 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7903 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7904 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7908 strcpy (prev_line_label, line_label);
7910 /* Emit debug info for the source file of the current line, if
7911 different from the previous line. */
7912 if (line_info->dw_file_num != current_file)
7914 current_file = line_info->dw_file_num;
7915 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7916 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7917 VARRAY_CHAR_PTR (file_table,
7918 current_file));
7921 /* Emit debug info for the current line number, choosing the encoding
7922 that uses the least amount of space. */
7923 if (line_info->dw_line_num != current_line)
7925 line_offset = line_info->dw_line_num - current_line;
7926 line_delta = line_offset - DWARF_LINE_BASE;
7927 current_line = line_info->dw_line_num;
7928 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7929 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7930 "line %lu", current_line);
7931 else
7933 dw2_asm_output_data (1, DW_LNS_advance_line,
7934 "advance to line %lu", current_line);
7935 dw2_asm_output_data_sleb128 (line_offset, NULL);
7936 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7939 else
7940 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7942 #if 0
7943 cont:
7944 #endif
7946 lt_index++;
7948 /* If we're done with a function, end its sequence. */
7949 if (lt_index == separate_line_info_table_in_use
7950 || separate_line_info_table[lt_index].function != function)
7952 current_file = 1;
7953 current_line = 1;
7955 /* Emit debug info for the address of the end of the function. */
7956 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7957 if (0)
7959 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7960 "DW_LNS_fixed_advance_pc");
7961 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7963 else
7965 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7966 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7967 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7968 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7971 /* Output the marker for the end of this sequence. */
7972 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7973 dw2_asm_output_data_uleb128 (1, NULL);
7974 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7978 /* Output the marker for the end of the line number info. */
7979 ASM_OUTPUT_LABEL (asm_out_file, l2);
7982 /* Given a pointer to a tree node for some base type, return a pointer to
7983 a DIE that describes the given type.
7985 This routine must only be called for GCC type nodes that correspond to
7986 Dwarf base (fundamental) types. */
7988 static dw_die_ref
7989 base_type_die (tree type)
7991 dw_die_ref base_type_result;
7992 const char *type_name;
7993 enum dwarf_type encoding;
7994 tree name = TYPE_NAME (type);
7996 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7997 return 0;
7999 if (name)
8001 if (TREE_CODE (name) == TYPE_DECL)
8002 name = DECL_NAME (name);
8004 type_name = IDENTIFIER_POINTER (name);
8006 else
8007 type_name = "__unknown__";
8009 switch (TREE_CODE (type))
8011 case INTEGER_TYPE:
8012 /* Carefully distinguish the C character types, without messing
8013 up if the language is not C. Note that we check only for the names
8014 that contain spaces; other names might occur by coincidence in other
8015 languages. */
8016 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
8017 && (type == char_type_node
8018 || ! strcmp (type_name, "signed char")
8019 || ! strcmp (type_name, "unsigned char"))))
8021 if (TYPE_UNSIGNED (type))
8022 encoding = DW_ATE_unsigned;
8023 else
8024 encoding = DW_ATE_signed;
8025 break;
8027 /* else fall through. */
8029 case CHAR_TYPE:
8030 /* GNU Pascal/Ada CHAR type. Not used in C. */
8031 if (TYPE_UNSIGNED (type))
8032 encoding = DW_ATE_unsigned_char;
8033 else
8034 encoding = DW_ATE_signed_char;
8035 break;
8037 case REAL_TYPE:
8038 encoding = DW_ATE_float;
8039 break;
8041 /* Dwarf2 doesn't know anything about complex ints, so use
8042 a user defined type for it. */
8043 case COMPLEX_TYPE:
8044 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
8045 encoding = DW_ATE_complex_float;
8046 else
8047 encoding = DW_ATE_lo_user;
8048 break;
8050 case BOOLEAN_TYPE:
8051 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
8052 encoding = DW_ATE_boolean;
8053 break;
8055 default:
8056 /* No other TREE_CODEs are Dwarf fundamental types. */
8057 gcc_unreachable ();
8060 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
8061 if (demangle_name_func)
8062 type_name = (*demangle_name_func) (type_name);
8064 add_AT_string (base_type_result, DW_AT_name, type_name);
8065 add_AT_unsigned (base_type_result, DW_AT_byte_size,
8066 int_size_in_bytes (type));
8067 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
8069 return base_type_result;
8072 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
8073 the Dwarf "root" type for the given input type. The Dwarf "root" type of
8074 a given type is generally the same as the given type, except that if the
8075 given type is a pointer or reference type, then the root type of the given
8076 type is the root type of the "basis" type for the pointer or reference
8077 type. (This definition of the "root" type is recursive.) Also, the root
8078 type of a `const' qualified type or a `volatile' qualified type is the
8079 root type of the given type without the qualifiers. */
8081 static tree
8082 root_type (tree type)
8084 if (TREE_CODE (type) == ERROR_MARK)
8085 return error_mark_node;
8087 switch (TREE_CODE (type))
8089 case ERROR_MARK:
8090 return error_mark_node;
8092 case POINTER_TYPE:
8093 case REFERENCE_TYPE:
8094 return type_main_variant (root_type (TREE_TYPE (type)));
8096 default:
8097 return type_main_variant (type);
8101 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
8102 given input type is a Dwarf "fundamental" type. Otherwise return null. */
8104 static inline int
8105 is_base_type (tree type)
8107 switch (TREE_CODE (type))
8109 case ERROR_MARK:
8110 case VOID_TYPE:
8111 case INTEGER_TYPE:
8112 case REAL_TYPE:
8113 case COMPLEX_TYPE:
8114 case BOOLEAN_TYPE:
8115 case CHAR_TYPE:
8116 return 1;
8118 case ARRAY_TYPE:
8119 case RECORD_TYPE:
8120 case UNION_TYPE:
8121 case QUAL_UNION_TYPE:
8122 case ENUMERAL_TYPE:
8123 case FUNCTION_TYPE:
8124 case METHOD_TYPE:
8125 case POINTER_TYPE:
8126 case REFERENCE_TYPE:
8127 case OFFSET_TYPE:
8128 case LANG_TYPE:
8129 case VECTOR_TYPE:
8130 return 0;
8132 default:
8133 gcc_unreachable ();
8136 return 0;
8139 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8140 node, return the size in bits for the type if it is a constant, or else
8141 return the alignment for the type if the type's size is not constant, or
8142 else return BITS_PER_WORD if the type actually turns out to be an
8143 ERROR_MARK node. */
8145 static inline unsigned HOST_WIDE_INT
8146 simple_type_size_in_bits (tree type)
8148 if (TREE_CODE (type) == ERROR_MARK)
8149 return BITS_PER_WORD;
8150 else if (TYPE_SIZE (type) == NULL_TREE)
8151 return 0;
8152 else if (host_integerp (TYPE_SIZE (type), 1))
8153 return tree_low_cst (TYPE_SIZE (type), 1);
8154 else
8155 return TYPE_ALIGN (type);
8158 /* Return true if the debug information for the given type should be
8159 emitted as a subrange type. */
8161 static inline bool
8162 is_subrange_type (tree type)
8164 tree subtype = TREE_TYPE (type);
8166 /* Subrange types are identified by the fact that they are integer
8167 types, and that they have a subtype which is either an integer type
8168 or an enumeral type. */
8170 if (TREE_CODE (type) != INTEGER_TYPE
8171 || subtype == NULL_TREE)
8172 return false;
8174 if (TREE_CODE (subtype) != INTEGER_TYPE
8175 && TREE_CODE (subtype) != ENUMERAL_TYPE)
8176 return false;
8178 if (TREE_CODE (type) == TREE_CODE (subtype)
8179 && int_size_in_bytes (type) == int_size_in_bytes (subtype)
8180 && TYPE_MIN_VALUE (type) != NULL
8181 && TYPE_MIN_VALUE (subtype) != NULL
8182 && tree_int_cst_equal (TYPE_MIN_VALUE (type), TYPE_MIN_VALUE (subtype))
8183 && TYPE_MAX_VALUE (type) != NULL
8184 && TYPE_MAX_VALUE (subtype) != NULL
8185 && tree_int_cst_equal (TYPE_MAX_VALUE (type), TYPE_MAX_VALUE (subtype)))
8187 /* The type and its subtype have the same representation. If in
8188 addition the two types also have the same name, then the given
8189 type is not a subrange type, but rather a plain base type. */
8190 /* FIXME: brobecker/2004-03-22:
8191 Sizetype INTEGER_CSTs nodes are canonicalized. It should
8192 therefore be sufficient to check the TYPE_SIZE node pointers
8193 rather than checking the actual size. Unfortunately, we have
8194 found some cases, such as in the Ada "integer" type, where
8195 this is not the case. Until this problem is solved, we need to
8196 keep checking the actual size. */
8197 tree type_name = TYPE_NAME (type);
8198 tree subtype_name = TYPE_NAME (subtype);
8200 if (type_name != NULL && TREE_CODE (type_name) == TYPE_DECL)
8201 type_name = DECL_NAME (type_name);
8203 if (subtype_name != NULL && TREE_CODE (subtype_name) == TYPE_DECL)
8204 subtype_name = DECL_NAME (subtype_name);
8206 if (type_name == subtype_name)
8207 return false;
8210 return true;
8213 /* Given a pointer to a tree node for a subrange type, return a pointer
8214 to a DIE that describes the given type. */
8216 static dw_die_ref
8217 subrange_type_die (tree type, dw_die_ref context_die)
8219 dw_die_ref subtype_die;
8220 dw_die_ref subrange_die;
8221 tree name = TYPE_NAME (type);
8222 const HOST_WIDE_INT size_in_bytes = int_size_in_bytes (type);
8223 tree subtype = TREE_TYPE (type);
8225 if (context_die == NULL)
8226 context_die = comp_unit_die;
8228 if (TREE_CODE (subtype) == ENUMERAL_TYPE)
8229 subtype_die = gen_enumeration_type_die (subtype, context_die);
8230 else
8231 subtype_die = base_type_die (subtype);
8233 subrange_die = new_die (DW_TAG_subrange_type, context_die, type);
8235 if (name != NULL)
8237 if (TREE_CODE (name) == TYPE_DECL)
8238 name = DECL_NAME (name);
8239 add_name_attribute (subrange_die, IDENTIFIER_POINTER (name));
8242 if (int_size_in_bytes (subtype) != size_in_bytes)
8244 /* The size of the subrange type and its base type do not match,
8245 so we need to generate a size attribute for the subrange type. */
8246 add_AT_unsigned (subrange_die, DW_AT_byte_size, size_in_bytes);
8249 if (TYPE_MIN_VALUE (type) != NULL)
8250 add_bound_info (subrange_die, DW_AT_lower_bound,
8251 TYPE_MIN_VALUE (type));
8252 if (TYPE_MAX_VALUE (type) != NULL)
8253 add_bound_info (subrange_die, DW_AT_upper_bound,
8254 TYPE_MAX_VALUE (type));
8255 add_AT_die_ref (subrange_die, DW_AT_type, subtype_die);
8257 return subrange_die;
8260 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
8261 entry that chains various modifiers in front of the given type. */
8263 static dw_die_ref
8264 modified_type_die (tree type, int is_const_type, int is_volatile_type,
8265 dw_die_ref context_die)
8267 enum tree_code code = TREE_CODE (type);
8268 dw_die_ref mod_type_die = NULL;
8269 dw_die_ref sub_die = NULL;
8270 tree item_type = NULL;
8272 if (code != ERROR_MARK)
8274 tree qualified_type;
8276 /* See if we already have the appropriately qualified variant of
8277 this type. */
8278 qualified_type
8279 = get_qualified_type (type,
8280 ((is_const_type ? TYPE_QUAL_CONST : 0)
8281 | (is_volatile_type
8282 ? TYPE_QUAL_VOLATILE : 0)));
8284 /* If we do, then we can just use its DIE, if it exists. */
8285 if (qualified_type)
8287 mod_type_die = lookup_type_die (qualified_type);
8288 if (mod_type_die)
8289 return mod_type_die;
8292 /* Handle C typedef types. */
8293 if (qualified_type && TYPE_NAME (qualified_type)
8294 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
8295 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
8297 tree type_name = TYPE_NAME (qualified_type);
8298 tree dtype = TREE_TYPE (type_name);
8300 if (qualified_type == dtype)
8302 /* For a named type, use the typedef. */
8303 gen_type_die (qualified_type, context_die);
8304 mod_type_die = lookup_type_die (qualified_type);
8306 else if (is_const_type < TYPE_READONLY (dtype)
8307 || is_volatile_type < TYPE_VOLATILE (dtype))
8308 /* cv-unqualified version of named type. Just use the unnamed
8309 type to which it refers. */
8310 mod_type_die
8311 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
8312 is_const_type, is_volatile_type,
8313 context_die);
8315 /* Else cv-qualified version of named type; fall through. */
8318 if (mod_type_die)
8319 /* OK. */
8321 else if (is_const_type)
8323 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
8324 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
8326 else if (is_volatile_type)
8328 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
8329 sub_die = modified_type_die (type, 0, 0, context_die);
8331 else if (code == POINTER_TYPE)
8333 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
8334 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8335 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8336 #if 0
8337 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8338 #endif
8339 item_type = TREE_TYPE (type);
8341 else if (code == REFERENCE_TYPE)
8343 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
8344 add_AT_unsigned (mod_type_die, DW_AT_byte_size,
8345 simple_type_size_in_bits (type) / BITS_PER_UNIT);
8346 #if 0
8347 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
8348 #endif
8349 item_type = TREE_TYPE (type);
8351 else if (is_subrange_type (type))
8352 mod_type_die = subrange_type_die (type, context_die);
8353 else if (is_base_type (type))
8354 mod_type_die = base_type_die (type);
8355 else
8357 gen_type_die (type, context_die);
8359 /* We have to get the type_main_variant here (and pass that to the
8360 `lookup_type_die' routine) because the ..._TYPE node we have
8361 might simply be a *copy* of some original type node (where the
8362 copy was created to help us keep track of typedef names) and
8363 that copy might have a different TYPE_UID from the original
8364 ..._TYPE node. */
8365 if (TREE_CODE (type) != VECTOR_TYPE)
8366 mod_type_die = lookup_type_die (type_main_variant (type));
8367 else
8368 /* Vectors have the debugging information in the type,
8369 not the main variant. */
8370 mod_type_die = lookup_type_die (type);
8371 gcc_assert (mod_type_die);
8374 /* We want to equate the qualified type to the die below. */
8375 type = qualified_type;
8378 if (type)
8379 equate_type_number_to_die (type, mod_type_die);
8380 if (item_type)
8381 /* We must do this after the equate_type_number_to_die call, in case
8382 this is a recursive type. This ensures that the modified_type_die
8383 recursion will terminate even if the type is recursive. Recursive
8384 types are possible in Ada. */
8385 sub_die = modified_type_die (item_type,
8386 TYPE_READONLY (item_type),
8387 TYPE_VOLATILE (item_type),
8388 context_die);
8390 if (sub_die != NULL)
8391 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
8393 return mod_type_die;
8396 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
8397 an enumerated type. */
8399 static inline int
8400 type_is_enum (tree type)
8402 return TREE_CODE (type) == ENUMERAL_TYPE;
8405 /* Return the DBX register number described by a given RTL node. */
8407 static unsigned int
8408 dbx_reg_number (rtx rtl)
8410 unsigned regno = REGNO (rtl);
8412 gcc_assert (regno < FIRST_PSEUDO_REGISTER);
8414 return DBX_REGISTER_NUMBER (regno);
8417 /* Optionally add a DW_OP_piece term to a location description expression.
8418 DW_OP_piece is only added if the location description expression already
8419 doesn't end with DW_OP_piece. */
8421 static void
8422 add_loc_descr_op_piece (dw_loc_descr_ref *list_head, int size)
8424 dw_loc_descr_ref loc;
8426 if (*list_head != NULL)
8428 /* Find the end of the chain. */
8429 for (loc = *list_head; loc->dw_loc_next != NULL; loc = loc->dw_loc_next)
8432 if (loc->dw_loc_opc != DW_OP_piece)
8433 loc->dw_loc_next = new_loc_descr (DW_OP_piece, size, 0);
8437 /* Return a location descriptor that designates a machine register or
8438 zero if there is none. */
8440 static dw_loc_descr_ref
8441 reg_loc_descriptor (rtx rtl)
8443 unsigned reg;
8444 rtx regs;
8446 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
8447 return 0;
8449 reg = dbx_reg_number (rtl);
8450 regs = targetm.dwarf_register_span (rtl);
8452 if (hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)] > 1
8453 || regs)
8454 return multiple_reg_loc_descriptor (rtl, regs);
8455 else
8456 return one_reg_loc_descriptor (reg);
8459 /* Return a location descriptor that designates a machine register for
8460 a given hard register number. */
8462 static dw_loc_descr_ref
8463 one_reg_loc_descriptor (unsigned int regno)
8465 if (regno <= 31)
8466 return new_loc_descr (DW_OP_reg0 + regno, 0, 0);
8467 else
8468 return new_loc_descr (DW_OP_regx, regno, 0);
8471 /* Given an RTL of a register, return a location descriptor that
8472 designates a value that spans more than one register. */
8474 static dw_loc_descr_ref
8475 multiple_reg_loc_descriptor (rtx rtl, rtx regs)
8477 int nregs, size, i;
8478 unsigned reg;
8479 dw_loc_descr_ref loc_result = NULL;
8481 reg = dbx_reg_number (rtl);
8482 nregs = hard_regno_nregs[REGNO (rtl)][GET_MODE (rtl)];
8484 /* Simple, contiguous registers. */
8485 if (regs == NULL_RTX)
8487 size = GET_MODE_SIZE (GET_MODE (rtl)) / nregs;
8489 loc_result = NULL;
8490 while (nregs--)
8492 dw_loc_descr_ref t;
8494 t = one_reg_loc_descriptor (reg);
8495 add_loc_descr (&loc_result, t);
8496 add_loc_descr_op_piece (&loc_result, size);
8497 ++reg;
8499 return loc_result;
8502 /* Now onto stupid register sets in non contiguous locations. */
8504 gcc_assert (GET_CODE (regs) == PARALLEL);
8506 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8507 loc_result = NULL;
8509 for (i = 0; i < XVECLEN (regs, 0); ++i)
8511 dw_loc_descr_ref t;
8513 t = one_reg_loc_descriptor (REGNO (XVECEXP (regs, 0, i)));
8514 add_loc_descr (&loc_result, t);
8515 size = GET_MODE_SIZE (GET_MODE (XVECEXP (regs, 0, 0)));
8516 add_loc_descr_op_piece (&loc_result, size);
8518 return loc_result;
8521 /* Return a location descriptor that designates a constant. */
8523 static dw_loc_descr_ref
8524 int_loc_descriptor (HOST_WIDE_INT i)
8526 enum dwarf_location_atom op;
8528 /* Pick the smallest representation of a constant, rather than just
8529 defaulting to the LEB encoding. */
8530 if (i >= 0)
8532 if (i <= 31)
8533 op = DW_OP_lit0 + i;
8534 else if (i <= 0xff)
8535 op = DW_OP_const1u;
8536 else if (i <= 0xffff)
8537 op = DW_OP_const2u;
8538 else if (HOST_BITS_PER_WIDE_INT == 32
8539 || i <= 0xffffffff)
8540 op = DW_OP_const4u;
8541 else
8542 op = DW_OP_constu;
8544 else
8546 if (i >= -0x80)
8547 op = DW_OP_const1s;
8548 else if (i >= -0x8000)
8549 op = DW_OP_const2s;
8550 else if (HOST_BITS_PER_WIDE_INT == 32
8551 || i >= -0x80000000)
8552 op = DW_OP_const4s;
8553 else
8554 op = DW_OP_consts;
8557 return new_loc_descr (op, i, 0);
8560 /* Return a location descriptor that designates a base+offset location. */
8562 static dw_loc_descr_ref
8563 based_loc_descr (unsigned int reg, HOST_WIDE_INT offset, bool can_use_fbreg)
8565 dw_loc_descr_ref loc_result;
8566 /* For the "frame base", we use the frame pointer or stack pointer
8567 registers, since the RTL for local variables is relative to one of
8568 them. */
8569 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
8570 ? HARD_FRAME_POINTER_REGNUM
8571 : STACK_POINTER_REGNUM);
8573 if (reg == fp_reg && can_use_fbreg)
8574 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
8575 else if (reg <= 31)
8576 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
8577 else
8578 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
8580 return loc_result;
8583 /* Return true if this RTL expression describes a base+offset calculation. */
8585 static inline int
8586 is_based_loc (rtx rtl)
8588 return (GET_CODE (rtl) == PLUS
8589 && ((REG_P (XEXP (rtl, 0))
8590 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
8591 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
8594 /* The following routine converts the RTL for a variable or parameter
8595 (resident in memory) into an equivalent Dwarf representation of a
8596 mechanism for getting the address of that same variable onto the top of a
8597 hypothetical "address evaluation" stack.
8599 When creating memory location descriptors, we are effectively transforming
8600 the RTL for a memory-resident object into its Dwarf postfix expression
8601 equivalent. This routine recursively descends an RTL tree, turning
8602 it into Dwarf postfix code as it goes.
8604 MODE is the mode of the memory reference, needed to handle some
8605 autoincrement addressing modes.
8607 CAN_USE_FBREG is a flag whether we can use DW_AT_frame_base in the location
8608 list for RTL. We can't use it when we are emitting location list for
8609 virtual variable frame_base_decl (i.e. a location list for DW_AT_frame_base)
8610 which describes how frame base changes when !frame_pointer_needed.
8612 Return 0 if we can't represent the location. */
8614 static dw_loc_descr_ref
8615 mem_loc_descriptor (rtx rtl, enum machine_mode mode, bool can_use_fbreg)
8617 dw_loc_descr_ref mem_loc_result = NULL;
8618 enum dwarf_location_atom op;
8620 /* Note that for a dynamically sized array, the location we will generate a
8621 description of here will be the lowest numbered location which is
8622 actually within the array. That's *not* necessarily the same as the
8623 zeroth element of the array. */
8625 rtl = targetm.delegitimize_address (rtl);
8627 switch (GET_CODE (rtl))
8629 case POST_INC:
8630 case POST_DEC:
8631 case POST_MODIFY:
8632 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
8633 just fall into the SUBREG code. */
8635 /* ... fall through ... */
8637 case SUBREG:
8638 /* The case of a subreg may arise when we have a local (register)
8639 variable or a formal (register) parameter which doesn't quite fill
8640 up an entire register. For now, just assume that it is
8641 legitimate to make the Dwarf info refer to the whole register which
8642 contains the given subreg. */
8643 rtl = XEXP (rtl, 0);
8645 /* ... fall through ... */
8647 case REG:
8648 /* Whenever a register number forms a part of the description of the
8649 method for calculating the (dynamic) address of a memory resident
8650 object, DWARF rules require the register number be referred to as
8651 a "base register". This distinction is not based in any way upon
8652 what category of register the hardware believes the given register
8653 belongs to. This is strictly DWARF terminology we're dealing with
8654 here. Note that in cases where the location of a memory-resident
8655 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
8656 OP_CONST (0)) the actual DWARF location descriptor that we generate
8657 may just be OP_BASEREG (basereg). This may look deceptively like
8658 the object in question was allocated to a register (rather than in
8659 memory) so DWARF consumers need to be aware of the subtle
8660 distinction between OP_REG and OP_BASEREG. */
8661 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
8662 mem_loc_result = based_loc_descr (dbx_reg_number (rtl), 0,
8663 can_use_fbreg);
8664 break;
8666 case MEM:
8667 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
8668 can_use_fbreg);
8669 if (mem_loc_result != 0)
8670 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
8671 break;
8673 case LO_SUM:
8674 rtl = XEXP (rtl, 1);
8676 /* ... fall through ... */
8678 case LABEL_REF:
8679 /* Some ports can transform a symbol ref into a label ref, because
8680 the symbol ref is too far away and has to be dumped into a constant
8681 pool. */
8682 case CONST:
8683 case SYMBOL_REF:
8684 /* Alternatively, the symbol in the constant pool might be referenced
8685 by a different symbol. */
8686 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
8688 bool marked;
8689 rtx tmp = get_pool_constant_mark (rtl, &marked);
8691 if (GET_CODE (tmp) == SYMBOL_REF)
8693 rtl = tmp;
8694 if (CONSTANT_POOL_ADDRESS_P (tmp))
8695 get_pool_constant_mark (tmp, &marked);
8696 else
8697 marked = true;
8700 /* If all references to this pool constant were optimized away,
8701 it was not output and thus we can't represent it.
8702 FIXME: might try to use DW_OP_const_value here, though
8703 DW_OP_piece complicates it. */
8704 if (!marked)
8705 return 0;
8708 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
8709 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
8710 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
8711 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
8712 break;
8714 case PRE_MODIFY:
8715 /* Extract the PLUS expression nested inside and fall into
8716 PLUS code below. */
8717 rtl = XEXP (rtl, 1);
8718 goto plus;
8720 case PRE_INC:
8721 case PRE_DEC:
8722 /* Turn these into a PLUS expression and fall into the PLUS code
8723 below. */
8724 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
8725 GEN_INT (GET_CODE (rtl) == PRE_INC
8726 ? GET_MODE_UNIT_SIZE (mode)
8727 : -GET_MODE_UNIT_SIZE (mode)));
8729 /* ... fall through ... */
8731 case PLUS:
8732 plus:
8733 if (is_based_loc (rtl))
8734 mem_loc_result = based_loc_descr (dbx_reg_number (XEXP (rtl, 0)),
8735 INTVAL (XEXP (rtl, 1)),
8736 can_use_fbreg);
8737 else
8739 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode,
8740 can_use_fbreg);
8741 if (mem_loc_result == 0)
8742 break;
8744 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
8745 && INTVAL (XEXP (rtl, 1)) >= 0)
8746 add_loc_descr (&mem_loc_result,
8747 new_loc_descr (DW_OP_plus_uconst,
8748 INTVAL (XEXP (rtl, 1)), 0));
8749 else
8751 add_loc_descr (&mem_loc_result,
8752 mem_loc_descriptor (XEXP (rtl, 1), mode,
8753 can_use_fbreg));
8754 add_loc_descr (&mem_loc_result,
8755 new_loc_descr (DW_OP_plus, 0, 0));
8758 break;
8760 /* If a pseudo-reg is optimized away, it is possible for it to
8761 be replaced with a MEM containing a multiply or shift. */
8762 case MULT:
8763 op = DW_OP_mul;
8764 goto do_binop;
8766 case ASHIFT:
8767 op = DW_OP_shl;
8768 goto do_binop;
8770 case ASHIFTRT:
8771 op = DW_OP_shra;
8772 goto do_binop;
8774 case LSHIFTRT:
8775 op = DW_OP_shr;
8776 goto do_binop;
8778 do_binop:
8780 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode,
8781 can_use_fbreg);
8782 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode,
8783 can_use_fbreg);
8785 if (op0 == 0 || op1 == 0)
8786 break;
8788 mem_loc_result = op0;
8789 add_loc_descr (&mem_loc_result, op1);
8790 add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0));
8791 break;
8794 case CONST_INT:
8795 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
8796 break;
8798 default:
8799 gcc_unreachable ();
8802 return mem_loc_result;
8805 /* Return a descriptor that describes the concatenation of two locations.
8806 This is typically a complex variable. */
8808 static dw_loc_descr_ref
8809 concat_loc_descriptor (rtx x0, rtx x1, bool can_use_fbreg)
8811 dw_loc_descr_ref cc_loc_result = NULL;
8812 dw_loc_descr_ref x0_ref = loc_descriptor (x0, can_use_fbreg);
8813 dw_loc_descr_ref x1_ref = loc_descriptor (x1, can_use_fbreg);
8815 if (x0_ref == 0 || x1_ref == 0)
8816 return 0;
8818 cc_loc_result = x0_ref;
8819 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x0)));
8821 add_loc_descr (&cc_loc_result, x1_ref);
8822 add_loc_descr_op_piece (&cc_loc_result, GET_MODE_SIZE (GET_MODE (x1)));
8824 return cc_loc_result;
8827 /* Return true if DECL's containing function has a frame base attribute.
8828 Return false otherwise. */
8830 static bool
8831 containing_function_has_frame_base (tree decl)
8833 tree declcontext = decl_function_context (decl);
8834 dw_die_ref context;
8835 dw_attr_ref attr;
8837 if (!declcontext)
8838 return false;
8840 context = lookup_decl_die (declcontext);
8841 if (!context)
8842 return false;
8844 for (attr = context->die_attr; attr; attr = attr->dw_attr_next)
8845 if (attr->dw_attr == DW_AT_frame_base)
8846 return true;
8847 return false;
8850 /* Output a proper Dwarf location descriptor for a variable or parameter
8851 which is either allocated in a register or in a memory location. For a
8852 register, we just generate an OP_REG and the register number. For a
8853 memory location we provide a Dwarf postfix expression describing how to
8854 generate the (dynamic) address of the object onto the address stack.
8856 If we don't know how to describe it, return 0. */
8858 static dw_loc_descr_ref
8859 loc_descriptor (rtx rtl, bool can_use_fbreg)
8861 dw_loc_descr_ref loc_result = NULL;
8863 switch (GET_CODE (rtl))
8865 case SUBREG:
8866 /* The case of a subreg may arise when we have a local (register)
8867 variable or a formal (register) parameter which doesn't quite fill
8868 up an entire register. For now, just assume that it is
8869 legitimate to make the Dwarf info refer to the whole register which
8870 contains the given subreg. */
8871 rtl = SUBREG_REG (rtl);
8873 /* ... fall through ... */
8875 case REG:
8876 loc_result = reg_loc_descriptor (rtl);
8877 break;
8879 case MEM:
8880 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl),
8881 can_use_fbreg);
8882 break;
8884 case CONCAT:
8885 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1),
8886 can_use_fbreg);
8887 break;
8889 case VAR_LOCATION:
8890 /* Single part. */
8891 if (GET_CODE (XEXP (rtl, 1)) != PARALLEL)
8893 loc_result = loc_descriptor (XEXP (XEXP (rtl, 1), 0), can_use_fbreg);
8894 break;
8897 rtl = XEXP (rtl, 1);
8898 /* FALLTHRU */
8900 case PARALLEL:
8902 rtvec par_elems = XVEC (rtl, 0);
8903 int num_elem = GET_NUM_ELEM (par_elems);
8904 enum machine_mode mode;
8905 int i;
8907 /* Create the first one, so we have something to add to. */
8908 loc_result = loc_descriptor (XEXP (RTVEC_ELT (par_elems, 0), 0),
8909 can_use_fbreg);
8910 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, 0), 0));
8911 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
8912 for (i = 1; i < num_elem; i++)
8914 dw_loc_descr_ref temp;
8916 temp = loc_descriptor (XEXP (RTVEC_ELT (par_elems, i), 0),
8917 can_use_fbreg);
8918 add_loc_descr (&loc_result, temp);
8919 mode = GET_MODE (XEXP (RTVEC_ELT (par_elems, i), 0));
8920 add_loc_descr_op_piece (&loc_result, GET_MODE_SIZE (mode));
8923 break;
8925 default:
8926 gcc_unreachable ();
8929 return loc_result;
8932 /* Similar, but generate the descriptor from trees instead of rtl. This comes
8933 up particularly with variable length arrays. WANT_ADDRESS is 2 if this is
8934 a top-level invocation of loc_descriptor_from_tree; is 1 if this is not a
8935 top-level invocation, and we require the address of LOC; is 0 if we require
8936 the value of LOC. */
8938 static dw_loc_descr_ref
8939 loc_descriptor_from_tree_1 (tree loc, int want_address)
8941 dw_loc_descr_ref ret, ret1;
8942 int have_address = 0;
8943 int unsignedp = TYPE_UNSIGNED (TREE_TYPE (loc));
8944 enum dwarf_location_atom op;
8946 /* ??? Most of the time we do not take proper care for sign/zero
8947 extending the values properly. Hopefully this won't be a real
8948 problem... */
8950 switch (TREE_CODE (loc))
8952 case ERROR_MARK:
8953 return 0;
8955 case PLACEHOLDER_EXPR:
8956 /* This case involves extracting fields from an object to determine the
8957 position of other fields. We don't try to encode this here. The
8958 only user of this is Ada, which encodes the needed information using
8959 the names of types. */
8960 return 0;
8962 case CALL_EXPR:
8963 return 0;
8965 case PREINCREMENT_EXPR:
8966 case PREDECREMENT_EXPR:
8967 case POSTINCREMENT_EXPR:
8968 case POSTDECREMENT_EXPR:
8969 /* There are no opcodes for these operations. */
8970 return 0;
8972 case ADDR_EXPR:
8973 /* If we already want an address, there's nothing we can do. */
8974 if (want_address)
8975 return 0;
8977 /* Otherwise, process the argument and look for the address. */
8978 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 1);
8980 case VAR_DECL:
8981 if (DECL_THREAD_LOCAL_P (loc))
8983 rtx rtl;
8985 /* If this is not defined, we have no way to emit the data. */
8986 if (!targetm.asm_out.output_dwarf_dtprel)
8987 return 0;
8989 /* The way DW_OP_GNU_push_tls_address is specified, we can only
8990 look up addresses of objects in the current module. */
8991 if (DECL_EXTERNAL (loc))
8992 return 0;
8994 rtl = rtl_for_decl_location (loc);
8995 if (rtl == NULL_RTX)
8996 return 0;
8998 if (!MEM_P (rtl))
8999 return 0;
9000 rtl = XEXP (rtl, 0);
9001 if (! CONSTANT_P (rtl))
9002 return 0;
9004 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0);
9005 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9006 ret->dw_loc_oprnd1.v.val_addr = rtl;
9008 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0);
9009 add_loc_descr (&ret, ret1);
9011 have_address = 1;
9012 break;
9014 /* FALLTHRU */
9016 case PARM_DECL:
9017 if (DECL_HAS_VALUE_EXPR_P (loc))
9018 return loc_descriptor_from_tree_1 (DECL_VALUE_EXPR (loc),
9019 want_address);
9020 /* FALLTHRU */
9022 case RESULT_DECL:
9024 rtx rtl = rtl_for_decl_location (loc);
9026 if (rtl == NULL_RTX)
9027 return 0;
9028 else if (GET_CODE (rtl) == CONST_INT)
9030 HOST_WIDE_INT val = INTVAL (rtl);
9031 if (TYPE_UNSIGNED (TREE_TYPE (loc)))
9032 val &= GET_MODE_MASK (DECL_MODE (loc));
9033 ret = int_loc_descriptor (val);
9035 else if (GET_CODE (rtl) == CONST_STRING)
9036 return 0;
9037 else if (CONSTANT_P (rtl))
9039 ret = new_loc_descr (DW_OP_addr, 0, 0);
9040 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
9041 ret->dw_loc_oprnd1.v.val_addr = rtl;
9043 else
9045 enum machine_mode mode;
9046 bool can_use_fb = containing_function_has_frame_base (loc);
9048 /* Certain constructs can only be represented at top-level. */
9049 if (want_address == 2)
9050 return loc_descriptor (rtl, can_use_fb);
9052 mode = GET_MODE (rtl);
9053 if (MEM_P (rtl))
9055 rtl = XEXP (rtl, 0);
9056 have_address = 1;
9058 ret = mem_loc_descriptor (rtl, mode, can_use_fb);
9061 break;
9063 case INDIRECT_REF:
9064 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9065 have_address = 1;
9066 break;
9068 case COMPOUND_EXPR:
9069 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), want_address);
9071 case NOP_EXPR:
9072 case CONVERT_EXPR:
9073 case NON_LVALUE_EXPR:
9074 case VIEW_CONVERT_EXPR:
9075 case SAVE_EXPR:
9076 case MODIFY_EXPR:
9077 return loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), want_address);
9079 case COMPONENT_REF:
9080 case BIT_FIELD_REF:
9081 case ARRAY_REF:
9082 case ARRAY_RANGE_REF:
9084 tree obj, offset;
9085 HOST_WIDE_INT bitsize, bitpos, bytepos;
9086 enum machine_mode mode;
9087 int volatilep;
9089 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
9090 &unsignedp, &volatilep, false);
9092 if (obj == loc)
9093 return 0;
9095 ret = loc_descriptor_from_tree_1 (obj, 1);
9096 if (ret == 0
9097 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
9098 return 0;
9100 if (offset != NULL_TREE)
9102 /* Variable offset. */
9103 add_loc_descr (&ret, loc_descriptor_from_tree_1 (offset, 0));
9104 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9107 bytepos = bitpos / BITS_PER_UNIT;
9108 if (bytepos > 0)
9109 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
9110 else if (bytepos < 0)
9112 add_loc_descr (&ret, int_loc_descriptor (bytepos));
9113 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
9116 have_address = 1;
9117 break;
9120 case INTEGER_CST:
9121 if (host_integerp (loc, 0))
9122 ret = int_loc_descriptor (tree_low_cst (loc, 0));
9123 else
9124 return 0;
9125 break;
9127 case CONSTRUCTOR:
9129 /* Get an RTL for this, if something has been emitted. */
9130 rtx rtl = lookup_constant_def (loc);
9131 enum machine_mode mode;
9132 bool can_use_fb;
9134 if (!rtl || !MEM_P (rtl))
9135 return 0;
9136 can_use_fb = containing_function_has_frame_base (loc);
9137 mode = GET_MODE (rtl);
9138 rtl = XEXP (rtl, 0);
9139 ret = mem_loc_descriptor (rtl, mode, can_use_fb);
9140 have_address = 1;
9141 break;
9144 case TRUTH_AND_EXPR:
9145 case TRUTH_ANDIF_EXPR:
9146 case BIT_AND_EXPR:
9147 op = DW_OP_and;
9148 goto do_binop;
9150 case TRUTH_XOR_EXPR:
9151 case BIT_XOR_EXPR:
9152 op = DW_OP_xor;
9153 goto do_binop;
9155 case TRUTH_OR_EXPR:
9156 case TRUTH_ORIF_EXPR:
9157 case BIT_IOR_EXPR:
9158 op = DW_OP_or;
9159 goto do_binop;
9161 case FLOOR_DIV_EXPR:
9162 case CEIL_DIV_EXPR:
9163 case ROUND_DIV_EXPR:
9164 case TRUNC_DIV_EXPR:
9165 op = DW_OP_div;
9166 goto do_binop;
9168 case MINUS_EXPR:
9169 op = DW_OP_minus;
9170 goto do_binop;
9172 case FLOOR_MOD_EXPR:
9173 case CEIL_MOD_EXPR:
9174 case ROUND_MOD_EXPR:
9175 case TRUNC_MOD_EXPR:
9176 op = DW_OP_mod;
9177 goto do_binop;
9179 case MULT_EXPR:
9180 op = DW_OP_mul;
9181 goto do_binop;
9183 case LSHIFT_EXPR:
9184 op = DW_OP_shl;
9185 goto do_binop;
9187 case RSHIFT_EXPR:
9188 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
9189 goto do_binop;
9191 case PLUS_EXPR:
9192 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
9193 && host_integerp (TREE_OPERAND (loc, 1), 0))
9195 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9196 if (ret == 0)
9197 return 0;
9199 add_loc_descr (&ret,
9200 new_loc_descr (DW_OP_plus_uconst,
9201 tree_low_cst (TREE_OPERAND (loc, 1),
9203 0));
9204 break;
9207 op = DW_OP_plus;
9208 goto do_binop;
9210 case LE_EXPR:
9211 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9212 return 0;
9214 op = DW_OP_le;
9215 goto do_binop;
9217 case GE_EXPR:
9218 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9219 return 0;
9221 op = DW_OP_ge;
9222 goto do_binop;
9224 case LT_EXPR:
9225 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9226 return 0;
9228 op = DW_OP_lt;
9229 goto do_binop;
9231 case GT_EXPR:
9232 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
9233 return 0;
9235 op = DW_OP_gt;
9236 goto do_binop;
9238 case EQ_EXPR:
9239 op = DW_OP_eq;
9240 goto do_binop;
9242 case NE_EXPR:
9243 op = DW_OP_ne;
9244 goto do_binop;
9246 do_binop:
9247 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9248 ret1 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9249 if (ret == 0 || ret1 == 0)
9250 return 0;
9252 add_loc_descr (&ret, ret1);
9253 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9254 break;
9256 case TRUTH_NOT_EXPR:
9257 case BIT_NOT_EXPR:
9258 op = DW_OP_not;
9259 goto do_unop;
9261 case ABS_EXPR:
9262 op = DW_OP_abs;
9263 goto do_unop;
9265 case NEGATE_EXPR:
9266 op = DW_OP_neg;
9267 goto do_unop;
9269 do_unop:
9270 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9271 if (ret == 0)
9272 return 0;
9274 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
9275 break;
9277 case MIN_EXPR:
9278 case MAX_EXPR:
9280 const enum tree_code code =
9281 TREE_CODE (loc) == MIN_EXPR ? GT_EXPR : LT_EXPR;
9283 loc = build3 (COND_EXPR, TREE_TYPE (loc),
9284 build2 (code, integer_type_node,
9285 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
9286 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
9289 /* ... fall through ... */
9291 case COND_EXPR:
9293 dw_loc_descr_ref lhs
9294 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 1), 0);
9295 dw_loc_descr_ref rhs
9296 = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 2), 0);
9297 dw_loc_descr_ref bra_node, jump_node, tmp;
9299 ret = loc_descriptor_from_tree_1 (TREE_OPERAND (loc, 0), 0);
9300 if (ret == 0 || lhs == 0 || rhs == 0)
9301 return 0;
9303 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
9304 add_loc_descr (&ret, bra_node);
9306 add_loc_descr (&ret, rhs);
9307 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
9308 add_loc_descr (&ret, jump_node);
9310 add_loc_descr (&ret, lhs);
9311 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9312 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
9314 /* ??? Need a node to point the skip at. Use a nop. */
9315 tmp = new_loc_descr (DW_OP_nop, 0, 0);
9316 add_loc_descr (&ret, tmp);
9317 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
9318 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
9320 break;
9322 case FIX_TRUNC_EXPR:
9323 case FIX_CEIL_EXPR:
9324 case FIX_FLOOR_EXPR:
9325 case FIX_ROUND_EXPR:
9326 return 0;
9328 default:
9329 /* Leave front-end specific codes as simply unknown. This comes
9330 up, for instance, with the C STMT_EXPR. */
9331 if ((unsigned int) TREE_CODE (loc)
9332 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
9333 return 0;
9335 #ifdef ENABLE_CHECKING
9336 /* Otherwise this is a generic code; we should just lists all of
9337 these explicitly. We forgot one. */
9338 gcc_unreachable ();
9339 #else
9340 /* In a release build, we want to degrade gracefully: better to
9341 generate incomplete debugging information than to crash. */
9342 return NULL;
9343 #endif
9346 /* Show if we can't fill the request for an address. */
9347 if (want_address && !have_address)
9348 return 0;
9350 /* If we've got an address and don't want one, dereference. */
9351 if (!want_address && have_address)
9353 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
9355 if (size > DWARF2_ADDR_SIZE || size == -1)
9356 return 0;
9357 else if (size == DWARF2_ADDR_SIZE)
9358 op = DW_OP_deref;
9359 else
9360 op = DW_OP_deref_size;
9362 add_loc_descr (&ret, new_loc_descr (op, size, 0));
9365 return ret;
9368 static inline dw_loc_descr_ref
9369 loc_descriptor_from_tree (tree loc)
9371 return loc_descriptor_from_tree_1 (loc, 2);
9374 /* Given a value, round it up to the lowest multiple of `boundary'
9375 which is not less than the value itself. */
9377 static inline HOST_WIDE_INT
9378 ceiling (HOST_WIDE_INT value, unsigned int boundary)
9380 return (((value + boundary - 1) / boundary) * boundary);
9383 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
9384 pointer to the declared type for the relevant field variable, or return
9385 `integer_type_node' if the given node turns out to be an
9386 ERROR_MARK node. */
9388 static inline tree
9389 field_type (tree decl)
9391 tree type;
9393 if (TREE_CODE (decl) == ERROR_MARK)
9394 return integer_type_node;
9396 type = DECL_BIT_FIELD_TYPE (decl);
9397 if (type == NULL_TREE)
9398 type = TREE_TYPE (decl);
9400 return type;
9403 /* Given a pointer to a tree node, return the alignment in bits for
9404 it, or else return BITS_PER_WORD if the node actually turns out to
9405 be an ERROR_MARK node. */
9407 static inline unsigned
9408 simple_type_align_in_bits (tree type)
9410 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
9413 static inline unsigned
9414 simple_decl_align_in_bits (tree decl)
9416 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
9419 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
9420 lowest addressed byte of the "containing object" for the given FIELD_DECL,
9421 or return 0 if we are unable to determine what that offset is, either
9422 because the argument turns out to be a pointer to an ERROR_MARK node, or
9423 because the offset is actually variable. (We can't handle the latter case
9424 just yet). */
9426 static HOST_WIDE_INT
9427 field_byte_offset (tree decl)
9429 unsigned int type_align_in_bits;
9430 unsigned int decl_align_in_bits;
9431 unsigned HOST_WIDE_INT type_size_in_bits;
9432 HOST_WIDE_INT object_offset_in_bits;
9433 tree type;
9434 tree field_size_tree;
9435 HOST_WIDE_INT bitpos_int;
9436 HOST_WIDE_INT deepest_bitpos;
9437 unsigned HOST_WIDE_INT field_size_in_bits;
9439 if (TREE_CODE (decl) == ERROR_MARK)
9440 return 0;
9442 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
9444 type = field_type (decl);
9445 field_size_tree = DECL_SIZE (decl);
9447 /* The size could be unspecified if there was an error, or for
9448 a flexible array member. */
9449 if (! field_size_tree)
9450 field_size_tree = bitsize_zero_node;
9452 /* We cannot yet cope with fields whose positions are variable, so
9453 for now, when we see such things, we simply return 0. Someday, we may
9454 be able to handle such cases, but it will be damn difficult. */
9455 if (! host_integerp (bit_position (decl), 0))
9456 return 0;
9458 bitpos_int = int_bit_position (decl);
9460 /* If we don't know the size of the field, pretend it's a full word. */
9461 if (host_integerp (field_size_tree, 1))
9462 field_size_in_bits = tree_low_cst (field_size_tree, 1);
9463 else
9464 field_size_in_bits = BITS_PER_WORD;
9466 type_size_in_bits = simple_type_size_in_bits (type);
9467 type_align_in_bits = simple_type_align_in_bits (type);
9468 decl_align_in_bits = simple_decl_align_in_bits (decl);
9470 /* The GCC front-end doesn't make any attempt to keep track of the starting
9471 bit offset (relative to the start of the containing structure type) of the
9472 hypothetical "containing object" for a bit-field. Thus, when computing
9473 the byte offset value for the start of the "containing object" of a
9474 bit-field, we must deduce this information on our own. This can be rather
9475 tricky to do in some cases. For example, handling the following structure
9476 type definition when compiling for an i386/i486 target (which only aligns
9477 long long's to 32-bit boundaries) can be very tricky:
9479 struct S { int field1; long long field2:31; };
9481 Fortunately, there is a simple rule-of-thumb which can be used in such
9482 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
9483 structure shown above. It decides to do this based upon one simple rule
9484 for bit-field allocation. GCC allocates each "containing object" for each
9485 bit-field at the first (i.e. lowest addressed) legitimate alignment
9486 boundary (based upon the required minimum alignment for the declared type
9487 of the field) which it can possibly use, subject to the condition that
9488 there is still enough available space remaining in the containing object
9489 (when allocated at the selected point) to fully accommodate all of the
9490 bits of the bit-field itself.
9492 This simple rule makes it obvious why GCC allocates 8 bytes for each
9493 object of the structure type shown above. When looking for a place to
9494 allocate the "containing object" for `field2', the compiler simply tries
9495 to allocate a 64-bit "containing object" at each successive 32-bit
9496 boundary (starting at zero) until it finds a place to allocate that 64-
9497 bit field such that at least 31 contiguous (and previously unallocated)
9498 bits remain within that selected 64 bit field. (As it turns out, for the
9499 example above, the compiler finds it is OK to allocate the "containing
9500 object" 64-bit field at bit-offset zero within the structure type.)
9502 Here we attempt to work backwards from the limited set of facts we're
9503 given, and we try to deduce from those facts, where GCC must have believed
9504 that the containing object started (within the structure type). The value
9505 we deduce is then used (by the callers of this routine) to generate
9506 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
9507 and, in the case of DW_AT_location, regular fields as well). */
9509 /* Figure out the bit-distance from the start of the structure to the
9510 "deepest" bit of the bit-field. */
9511 deepest_bitpos = bitpos_int + field_size_in_bits;
9513 /* This is the tricky part. Use some fancy footwork to deduce where the
9514 lowest addressed bit of the containing object must be. */
9515 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9517 /* Round up to type_align by default. This works best for bitfields. */
9518 object_offset_in_bits += type_align_in_bits - 1;
9519 object_offset_in_bits /= type_align_in_bits;
9520 object_offset_in_bits *= type_align_in_bits;
9522 if (object_offset_in_bits > bitpos_int)
9524 /* Sigh, the decl must be packed. */
9525 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
9527 /* Round up to decl_align instead. */
9528 object_offset_in_bits += decl_align_in_bits - 1;
9529 object_offset_in_bits /= decl_align_in_bits;
9530 object_offset_in_bits *= decl_align_in_bits;
9533 return object_offset_in_bits / BITS_PER_UNIT;
9536 /* The following routines define various Dwarf attributes and any data
9537 associated with them. */
9539 /* Add a location description attribute value to a DIE.
9541 This emits location attributes suitable for whole variables and
9542 whole parameters. Note that the location attributes for struct fields are
9543 generated by the routine `data_member_location_attribute' below. */
9545 static inline void
9546 add_AT_location_description (dw_die_ref die, enum dwarf_attribute attr_kind,
9547 dw_loc_descr_ref descr)
9549 if (descr != 0)
9550 add_AT_loc (die, attr_kind, descr);
9553 /* Attach the specialized form of location attribute used for data members of
9554 struct and union types. In the special case of a FIELD_DECL node which
9555 represents a bit-field, the "offset" part of this special location
9556 descriptor must indicate the distance in bytes from the lowest-addressed
9557 byte of the containing struct or union type to the lowest-addressed byte of
9558 the "containing object" for the bit-field. (See the `field_byte_offset'
9559 function above).
9561 For any given bit-field, the "containing object" is a hypothetical object
9562 (of some integral or enum type) within which the given bit-field lives. The
9563 type of this hypothetical "containing object" is always the same as the
9564 declared type of the individual bit-field itself (for GCC anyway... the
9565 DWARF spec doesn't actually mandate this). Note that it is the size (in
9566 bytes) of the hypothetical "containing object" which will be given in the
9567 DW_AT_byte_size attribute for this bit-field. (See the
9568 `byte_size_attribute' function below.) It is also used when calculating the
9569 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
9570 function below.) */
9572 static void
9573 add_data_member_location_attribute (dw_die_ref die, tree decl)
9575 HOST_WIDE_INT offset;
9576 dw_loc_descr_ref loc_descr = 0;
9578 if (TREE_CODE (decl) == TREE_BINFO)
9580 /* We're working on the TAG_inheritance for a base class. */
9581 if (BINFO_VIRTUAL_P (decl) && is_cxx ())
9583 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
9584 aren't at a fixed offset from all (sub)objects of the same
9585 type. We need to extract the appropriate offset from our
9586 vtable. The following dwarf expression means
9588 BaseAddr = ObAddr + *((*ObAddr) - Offset)
9590 This is specific to the V3 ABI, of course. */
9592 dw_loc_descr_ref tmp;
9594 /* Make a copy of the object address. */
9595 tmp = new_loc_descr (DW_OP_dup, 0, 0);
9596 add_loc_descr (&loc_descr, tmp);
9598 /* Extract the vtable address. */
9599 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9600 add_loc_descr (&loc_descr, tmp);
9602 /* Calculate the address of the offset. */
9603 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
9604 gcc_assert (offset < 0);
9606 tmp = int_loc_descriptor (-offset);
9607 add_loc_descr (&loc_descr, tmp);
9608 tmp = new_loc_descr (DW_OP_minus, 0, 0);
9609 add_loc_descr (&loc_descr, tmp);
9611 /* Extract the offset. */
9612 tmp = new_loc_descr (DW_OP_deref, 0, 0);
9613 add_loc_descr (&loc_descr, tmp);
9615 /* Add it to the object address. */
9616 tmp = new_loc_descr (DW_OP_plus, 0, 0);
9617 add_loc_descr (&loc_descr, tmp);
9619 else
9620 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
9622 else
9623 offset = field_byte_offset (decl);
9625 if (! loc_descr)
9627 enum dwarf_location_atom op;
9629 /* The DWARF2 standard says that we should assume that the structure
9630 address is already on the stack, so we can specify a structure field
9631 address by using DW_OP_plus_uconst. */
9633 #ifdef MIPS_DEBUGGING_INFO
9634 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
9635 operator correctly. It works only if we leave the offset on the
9636 stack. */
9637 op = DW_OP_constu;
9638 #else
9639 op = DW_OP_plus_uconst;
9640 #endif
9642 loc_descr = new_loc_descr (op, offset, 0);
9645 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
9648 /* Writes integer values to dw_vec_const array. */
9650 static void
9651 insert_int (HOST_WIDE_INT val, unsigned int size, unsigned char *dest)
9653 while (size != 0)
9655 *dest++ = val & 0xff;
9656 val >>= 8;
9657 --size;
9661 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
9663 static HOST_WIDE_INT
9664 extract_int (const unsigned char *src, unsigned int size)
9666 HOST_WIDE_INT val = 0;
9668 src += size;
9669 while (size != 0)
9671 val <<= 8;
9672 val |= *--src & 0xff;
9673 --size;
9675 return val;
9678 /* Writes floating point values to dw_vec_const array. */
9680 static void
9681 insert_float (rtx rtl, unsigned char *array)
9683 REAL_VALUE_TYPE rv;
9684 long val[4];
9685 int i;
9687 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
9688 real_to_target (val, &rv, GET_MODE (rtl));
9690 /* real_to_target puts 32-bit pieces in each long. Pack them. */
9691 for (i = 0; i < GET_MODE_SIZE (GET_MODE (rtl)) / 4; i++)
9693 insert_int (val[i], 4, array);
9694 array += 4;
9698 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
9699 does not have a "location" either in memory or in a register. These
9700 things can arise in GNU C when a constant is passed as an actual parameter
9701 to an inlined function. They can also arise in C++ where declared
9702 constants do not necessarily get memory "homes". */
9704 static void
9705 add_const_value_attribute (dw_die_ref die, rtx rtl)
9707 switch (GET_CODE (rtl))
9709 case CONST_INT:
9711 HOST_WIDE_INT val = INTVAL (rtl);
9713 if (val < 0)
9714 add_AT_int (die, DW_AT_const_value, val);
9715 else
9716 add_AT_unsigned (die, DW_AT_const_value, (unsigned HOST_WIDE_INT) val);
9718 break;
9720 case CONST_DOUBLE:
9721 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
9722 floating-point constant. A CONST_DOUBLE is used whenever the
9723 constant requires more than one word in order to be adequately
9724 represented. We output CONST_DOUBLEs as blocks. */
9726 enum machine_mode mode = GET_MODE (rtl);
9728 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
9730 unsigned int length = GET_MODE_SIZE (mode);
9731 unsigned char *array = ggc_alloc (length);
9733 insert_float (rtl, array);
9734 add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
9736 else
9738 /* ??? We really should be using HOST_WIDE_INT throughout. */
9739 gcc_assert (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT);
9741 add_AT_long_long (die, DW_AT_const_value,
9742 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
9745 break;
9747 case CONST_VECTOR:
9749 enum machine_mode mode = GET_MODE (rtl);
9750 unsigned int elt_size = GET_MODE_UNIT_SIZE (mode);
9751 unsigned int length = CONST_VECTOR_NUNITS (rtl);
9752 unsigned char *array = ggc_alloc (length * elt_size);
9753 unsigned int i;
9754 unsigned char *p;
9756 switch (GET_MODE_CLASS (mode))
9758 case MODE_VECTOR_INT:
9759 for (i = 0, p = array; i < length; i++, p += elt_size)
9761 rtx elt = CONST_VECTOR_ELT (rtl, i);
9762 HOST_WIDE_INT lo, hi;
9764 switch (GET_CODE (elt))
9766 case CONST_INT:
9767 lo = INTVAL (elt);
9768 hi = -(lo < 0);
9769 break;
9771 case CONST_DOUBLE:
9772 lo = CONST_DOUBLE_LOW (elt);
9773 hi = CONST_DOUBLE_HIGH (elt);
9774 break;
9776 default:
9777 gcc_unreachable ();
9780 if (elt_size <= sizeof (HOST_WIDE_INT))
9781 insert_int (lo, elt_size, p);
9782 else
9784 unsigned char *p0 = p;
9785 unsigned char *p1 = p + sizeof (HOST_WIDE_INT);
9787 gcc_assert (elt_size == 2 * sizeof (HOST_WIDE_INT));
9788 if (WORDS_BIG_ENDIAN)
9790 p0 = p1;
9791 p1 = p;
9793 insert_int (lo, sizeof (HOST_WIDE_INT), p0);
9794 insert_int (hi, sizeof (HOST_WIDE_INT), p1);
9797 break;
9799 case MODE_VECTOR_FLOAT:
9800 for (i = 0, p = array; i < length; i++, p += elt_size)
9802 rtx elt = CONST_VECTOR_ELT (rtl, i);
9803 insert_float (elt, p);
9805 break;
9807 default:
9808 gcc_unreachable ();
9811 add_AT_vec (die, DW_AT_const_value, length, elt_size, array);
9813 break;
9815 case CONST_STRING:
9816 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
9817 break;
9819 case SYMBOL_REF:
9820 case LABEL_REF:
9821 case CONST:
9822 add_AT_addr (die, DW_AT_const_value, rtl);
9823 VEC_safe_push (rtx, gc, used_rtx_array, rtl);
9824 break;
9826 case PLUS:
9827 /* In cases where an inlined instance of an inline function is passed
9828 the address of an `auto' variable (which is local to the caller) we
9829 can get a situation where the DECL_RTL of the artificial local
9830 variable (for the inlining) which acts as a stand-in for the
9831 corresponding formal parameter (of the inline function) will look
9832 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
9833 exactly a compile-time constant expression, but it isn't the address
9834 of the (artificial) local variable either. Rather, it represents the
9835 *value* which the artificial local variable always has during its
9836 lifetime. We currently have no way to represent such quasi-constant
9837 values in Dwarf, so for now we just punt and generate nothing. */
9838 break;
9840 default:
9841 /* No other kinds of rtx should be possible here. */
9842 gcc_unreachable ();
9847 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
9848 for use in a later add_const_value_attribute call. */
9850 static rtx
9851 rtl_for_decl_init (tree init, tree type)
9853 rtx rtl = NULL_RTX;
9855 /* If a variable is initialized with a string constant without embedded
9856 zeros, build CONST_STRING. */
9857 if (TREE_CODE (init) == STRING_CST && TREE_CODE (type) == ARRAY_TYPE)
9859 tree enttype = TREE_TYPE (type);
9860 tree domain = TYPE_DOMAIN (type);
9861 enum machine_mode mode = TYPE_MODE (enttype);
9863 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
9864 && domain
9865 && integer_zerop (TYPE_MIN_VALUE (domain))
9866 && compare_tree_int (TYPE_MAX_VALUE (domain),
9867 TREE_STRING_LENGTH (init) - 1) == 0
9868 && ((size_t) TREE_STRING_LENGTH (init)
9869 == strlen (TREE_STRING_POINTER (init)) + 1))
9870 rtl = gen_rtx_CONST_STRING (VOIDmode,
9871 ggc_strdup (TREE_STRING_POINTER (init)));
9873 /* If the initializer is something that we know will expand into an
9874 immediate RTL constant, expand it now. Expanding anything else
9875 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
9876 /* Aggregate, vector, and complex types may contain constructors that may
9877 result in code being generated when expand_expr is called, so we can't
9878 handle them here. Integer and float are useful and safe types to handle
9879 here. */
9880 else if ((INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type))
9881 && initializer_constant_valid_p (init, type) == null_pointer_node)
9883 rtl = expand_expr (init, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
9885 /* If expand_expr returns a MEM, it wasn't immediate. */
9886 gcc_assert (!rtl || !MEM_P (rtl));
9889 return rtl;
9892 /* Generate RTL for the variable DECL to represent its location. */
9894 static rtx
9895 rtl_for_decl_location (tree decl)
9897 rtx rtl;
9899 /* Here we have to decide where we are going to say the parameter "lives"
9900 (as far as the debugger is concerned). We only have a couple of
9901 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
9903 DECL_RTL normally indicates where the parameter lives during most of the
9904 activation of the function. If optimization is enabled however, this
9905 could be either NULL or else a pseudo-reg. Both of those cases indicate
9906 that the parameter doesn't really live anywhere (as far as the code
9907 generation parts of GCC are concerned) during most of the function's
9908 activation. That will happen (for example) if the parameter is never
9909 referenced within the function.
9911 We could just generate a location descriptor here for all non-NULL
9912 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
9913 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
9914 where DECL_RTL is NULL or is a pseudo-reg.
9916 Note however that we can only get away with using DECL_INCOMING_RTL as
9917 a backup substitute for DECL_RTL in certain limited cases. In cases
9918 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
9919 we can be sure that the parameter was passed using the same type as it is
9920 declared to have within the function, and that its DECL_INCOMING_RTL
9921 points us to a place where a value of that type is passed.
9923 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
9924 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
9925 because in these cases DECL_INCOMING_RTL points us to a value of some
9926 type which is *different* from the type of the parameter itself. Thus,
9927 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
9928 such cases, the debugger would end up (for example) trying to fetch a
9929 `float' from a place which actually contains the first part of a
9930 `double'. That would lead to really incorrect and confusing
9931 output at debug-time.
9933 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
9934 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
9935 are a couple of exceptions however. On little-endian machines we can
9936 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
9937 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
9938 an integral type that is smaller than TREE_TYPE (decl). These cases arise
9939 when (on a little-endian machine) a non-prototyped function has a
9940 parameter declared to be of type `short' or `char'. In such cases,
9941 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
9942 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
9943 passed `int' value. If the debugger then uses that address to fetch
9944 a `short' or a `char' (on a little-endian machine) the result will be
9945 the correct data, so we allow for such exceptional cases below.
9947 Note that our goal here is to describe the place where the given formal
9948 parameter lives during most of the function's activation (i.e. between the
9949 end of the prologue and the start of the epilogue). We'll do that as best
9950 as we can. Note however that if the given formal parameter is modified
9951 sometime during the execution of the function, then a stack backtrace (at
9952 debug-time) will show the function as having been called with the *new*
9953 value rather than the value which was originally passed in. This happens
9954 rarely enough that it is not a major problem, but it *is* a problem, and
9955 I'd like to fix it.
9957 A future version of dwarf2out.c may generate two additional attributes for
9958 any given DW_TAG_formal_parameter DIE which will describe the "passed
9959 type" and the "passed location" for the given formal parameter in addition
9960 to the attributes we now generate to indicate the "declared type" and the
9961 "active location" for each parameter. This additional set of attributes
9962 could be used by debuggers for stack backtraces. Separately, note that
9963 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
9964 This happens (for example) for inlined-instances of inline function formal
9965 parameters which are never referenced. This really shouldn't be
9966 happening. All PARM_DECL nodes should get valid non-NULL
9967 DECL_INCOMING_RTL values. FIXME. */
9969 /* Use DECL_RTL as the "location" unless we find something better. */
9970 rtl = DECL_RTL_IF_SET (decl);
9972 /* When generating abstract instances, ignore everything except
9973 constants, symbols living in memory, and symbols living in
9974 fixed registers. */
9975 if (! reload_completed)
9977 if (rtl
9978 && (CONSTANT_P (rtl)
9979 || (MEM_P (rtl)
9980 && CONSTANT_P (XEXP (rtl, 0)))
9981 || (REG_P (rtl)
9982 && TREE_CODE (decl) == VAR_DECL
9983 && TREE_STATIC (decl))))
9985 rtl = targetm.delegitimize_address (rtl);
9986 return rtl;
9988 rtl = NULL_RTX;
9990 else if (TREE_CODE (decl) == PARM_DECL)
9992 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
9994 tree declared_type = TREE_TYPE (decl);
9995 tree passed_type = DECL_ARG_TYPE (decl);
9996 enum machine_mode dmode = TYPE_MODE (declared_type);
9997 enum machine_mode pmode = TYPE_MODE (passed_type);
9999 /* This decl represents a formal parameter which was optimized out.
10000 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
10001 all cases where (rtl == NULL_RTX) just below. */
10002 if (dmode == pmode)
10003 rtl = DECL_INCOMING_RTL (decl);
10004 else if (SCALAR_INT_MODE_P (dmode)
10005 && GET_MODE_SIZE (dmode) <= GET_MODE_SIZE (pmode)
10006 && DECL_INCOMING_RTL (decl))
10008 rtx inc = DECL_INCOMING_RTL (decl);
10009 if (REG_P (inc))
10010 rtl = inc;
10011 else if (MEM_P (inc))
10013 if (BYTES_BIG_ENDIAN)
10014 rtl = adjust_address_nv (inc, dmode,
10015 GET_MODE_SIZE (pmode)
10016 - GET_MODE_SIZE (dmode));
10017 else
10018 rtl = inc;
10023 /* If the parm was passed in registers, but lives on the stack, then
10024 make a big endian correction if the mode of the type of the
10025 parameter is not the same as the mode of the rtl. */
10026 /* ??? This is the same series of checks that are made in dbxout.c before
10027 we reach the big endian correction code there. It isn't clear if all
10028 of these checks are necessary here, but keeping them all is the safe
10029 thing to do. */
10030 else if (MEM_P (rtl)
10031 && XEXP (rtl, 0) != const0_rtx
10032 && ! CONSTANT_P (XEXP (rtl, 0))
10033 /* Not passed in memory. */
10034 && !MEM_P (DECL_INCOMING_RTL (decl))
10035 /* Not passed by invisible reference. */
10036 && (!REG_P (XEXP (rtl, 0))
10037 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
10038 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
10039 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
10040 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
10041 #endif
10043 /* Big endian correction check. */
10044 && BYTES_BIG_ENDIAN
10045 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
10046 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
10047 < UNITS_PER_WORD))
10049 int offset = (UNITS_PER_WORD
10050 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
10052 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10053 plus_constant (XEXP (rtl, 0), offset));
10056 else if (TREE_CODE (decl) == VAR_DECL
10057 && rtl
10058 && MEM_P (rtl)
10059 && GET_MODE (rtl) != TYPE_MODE (TREE_TYPE (decl))
10060 && BYTES_BIG_ENDIAN)
10062 int rsize = GET_MODE_SIZE (GET_MODE (rtl));
10063 int dsize = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)));
10065 /* If a variable is declared "register" yet is smaller than
10066 a register, then if we store the variable to memory, it
10067 looks like we're storing a register-sized value, when in
10068 fact we are not. We need to adjust the offset of the
10069 storage location to reflect the actual value's bytes,
10070 else gdb will not be able to display it. */
10071 if (rsize > dsize)
10072 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
10073 plus_constant (XEXP (rtl, 0), rsize-dsize));
10076 if (rtl != NULL_RTX)
10078 rtl = eliminate_regs (rtl, 0, NULL_RTX);
10079 #ifdef LEAF_REG_REMAP
10080 if (current_function_uses_only_leaf_regs)
10081 leaf_renumber_regs_insn (rtl);
10082 #endif
10085 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
10086 and will have been substituted directly into all expressions that use it.
10087 C does not have such a concept, but C++ and other languages do. */
10088 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
10089 rtl = rtl_for_decl_init (DECL_INITIAL (decl), TREE_TYPE (decl));
10091 if (rtl)
10092 rtl = targetm.delegitimize_address (rtl);
10094 /* If we don't look past the constant pool, we risk emitting a
10095 reference to a constant pool entry that isn't referenced from
10096 code, and thus is not emitted. */
10097 if (rtl)
10098 rtl = avoid_constant_pool_reference (rtl);
10100 return rtl;
10103 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
10104 data attribute for a variable or a parameter. We generate the
10105 DW_AT_const_value attribute only in those cases where the given variable
10106 or parameter does not have a true "location" either in memory or in a
10107 register. This can happen (for example) when a constant is passed as an
10108 actual argument in a call to an inline function. (It's possible that
10109 these things can crop up in other ways also.) Note that one type of
10110 constant value which can be passed into an inlined function is a constant
10111 pointer. This can happen for example if an actual argument in an inlined
10112 function call evaluates to a compile-time constant address. */
10114 static void
10115 add_location_or_const_value_attribute (dw_die_ref die, tree decl,
10116 enum dwarf_attribute attr)
10118 rtx rtl;
10119 dw_loc_descr_ref descr;
10120 var_loc_list *loc_list;
10121 bool can_use_fb;
10122 struct var_loc_node *node;
10123 if (TREE_CODE (decl) == ERROR_MARK)
10124 return;
10126 gcc_assert (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL
10127 || TREE_CODE (decl) == RESULT_DECL);
10129 can_use_fb = containing_function_has_frame_base (decl);
10131 /* See if we possibly have multiple locations for this variable. */
10132 loc_list = lookup_decl_loc (decl);
10134 /* If it truly has multiple locations, the first and last node will
10135 differ. */
10136 if (loc_list && loc_list->first != loc_list->last)
10138 const char *secname;
10139 const char *endname;
10140 dw_loc_list_ref list;
10141 rtx varloc;
10143 /* We need to figure out what section we should use as the base
10144 for the address ranges where a given location is valid.
10145 1. If this particular DECL has a section associated with it,
10146 use that.
10147 2. If this function has a section associated with it, use
10148 that.
10149 3. Otherwise, use the text section.
10150 XXX: If you split a variable across multiple sections, this
10151 won't notice. */
10153 if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_SECTION_NAME (decl))
10155 tree sectree = DECL_SECTION_NAME (decl);
10156 secname = TREE_STRING_POINTER (sectree);
10158 else if (current_function_decl
10159 && DECL_SECTION_NAME (current_function_decl))
10161 tree sectree = DECL_SECTION_NAME (current_function_decl);
10162 secname = TREE_STRING_POINTER (sectree);
10164 else if (cfun
10165 && (last_text_section == in_unlikely_executed_text
10166 || (last_text_section == in_named
10167 && last_text_section_name ==
10168 cfun->unlikely_text_section_name)))
10169 secname = cfun->cold_section_label;
10170 else
10171 secname = text_section_label;
10173 /* Now that we know what section we are using for a base,
10174 actually construct the list of locations.
10175 The first location information is what is passed to the
10176 function that creates the location list, and the remaining
10177 locations just get added on to that list.
10178 Note that we only know the start address for a location
10179 (IE location changes), so to build the range, we use
10180 the range [current location start, next location start].
10181 This means we have to special case the last node, and generate
10182 a range of [last location start, end of function label]. */
10184 node = loc_list->first;
10185 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10186 list = new_loc_list (loc_descriptor (varloc, can_use_fb),
10187 node->label, node->next->label, secname, 1);
10188 node = node->next;
10190 for (; node->next; node = node->next)
10191 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10193 /* The variable has a location between NODE->LABEL and
10194 NODE->NEXT->LABEL. */
10195 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10196 add_loc_descr_to_loc_list (&list,
10197 loc_descriptor (varloc,
10198 can_use_fb),
10199 node->label, node->next->label, secname);
10202 /* If the variable has a location at the last label
10203 it keeps its location until the end of function. */
10204 if (NOTE_VAR_LOCATION_LOC (node->var_loc_note) != NULL_RTX)
10206 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10208 varloc = NOTE_VAR_LOCATION (node->var_loc_note);
10209 if (!current_function_decl)
10210 endname = text_end_label;
10211 else
10213 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10214 current_function_funcdef_no);
10215 endname = ggc_strdup (label_id);
10217 add_loc_descr_to_loc_list (&list,
10218 loc_descriptor (varloc,
10219 can_use_fb),
10220 node->label, endname, secname);
10223 /* Finally, add the location list to the DIE, and we are done. */
10224 add_AT_loc_list (die, attr, list);
10225 return;
10228 /* Try to get some constant RTL for this decl, and use that as the value of
10229 the location. */
10231 rtl = rtl_for_decl_location (decl);
10232 if (rtl && (CONSTANT_P (rtl) || GET_CODE (rtl) == CONST_STRING))
10234 add_const_value_attribute (die, rtl);
10235 return;
10238 /* If we have tried to generate the location otherwise, and it
10239 didn't work out (we wouldn't be here if we did), and we have a one entry
10240 location list, try generating a location from that. */
10241 if (loc_list && loc_list->first)
10243 node = loc_list->first;
10244 descr = loc_descriptor (NOTE_VAR_LOCATION (node->var_loc_note),
10245 can_use_fb);
10246 if (descr)
10248 add_AT_location_description (die, attr, descr);
10249 return;
10253 /* We couldn't get any rtl, so try directly generating the location
10254 description from the tree. */
10255 descr = loc_descriptor_from_tree (decl);
10256 if (descr)
10258 add_AT_location_description (die, attr, descr);
10259 return;
10263 /* If we don't have a copy of this variable in memory for some reason (such
10264 as a C++ member constant that doesn't have an out-of-line definition),
10265 we should tell the debugger about the constant value. */
10267 static void
10268 tree_add_const_value_attribute (dw_die_ref var_die, tree decl)
10270 tree init = DECL_INITIAL (decl);
10271 tree type = TREE_TYPE (decl);
10272 rtx rtl;
10274 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init)
10275 /* OK */;
10276 else
10277 return;
10279 rtl = rtl_for_decl_init (init, type);
10280 if (rtl)
10281 add_const_value_attribute (var_die, rtl);
10284 /* Generate a DW_AT_name attribute given some string value to be included as
10285 the value of the attribute. */
10287 static void
10288 add_name_attribute (dw_die_ref die, const char *name_string)
10290 if (name_string != NULL && *name_string != 0)
10292 if (demangle_name_func)
10293 name_string = (*demangle_name_func) (name_string);
10295 add_AT_string (die, DW_AT_name, name_string);
10299 /* Generate a DW_AT_comp_dir attribute for DIE. */
10301 static void
10302 add_comp_dir_attribute (dw_die_ref die)
10304 const char *wd = get_src_pwd ();
10305 if (wd != NULL)
10306 add_AT_string (die, DW_AT_comp_dir, wd);
10309 /* Given a tree node describing an array bound (either lower or upper) output
10310 a representation for that bound. */
10312 static void
10313 add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, tree bound)
10315 switch (TREE_CODE (bound))
10317 case ERROR_MARK:
10318 return;
10320 /* All fixed-bounds are represented by INTEGER_CST nodes. */
10321 case INTEGER_CST:
10322 if (! host_integerp (bound, 0)
10323 || (bound_attr == DW_AT_lower_bound
10324 && (((is_c_family () || is_java ()) && integer_zerop (bound))
10325 || (is_fortran () && integer_onep (bound)))))
10326 /* Use the default. */
10328 else
10329 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
10330 break;
10332 case CONVERT_EXPR:
10333 case NOP_EXPR:
10334 case NON_LVALUE_EXPR:
10335 case VIEW_CONVERT_EXPR:
10336 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
10337 break;
10339 case SAVE_EXPR:
10340 break;
10342 case VAR_DECL:
10343 case PARM_DECL:
10344 case RESULT_DECL:
10346 dw_die_ref decl_die = lookup_decl_die (bound);
10348 /* ??? Can this happen, or should the variable have been bound
10349 first? Probably it can, since I imagine that we try to create
10350 the types of parameters in the order in which they exist in
10351 the list, and won't have created a forward reference to a
10352 later parameter. */
10353 if (decl_die != NULL)
10354 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10355 break;
10358 default:
10360 /* Otherwise try to create a stack operation procedure to
10361 evaluate the value of the array bound. */
10363 dw_die_ref ctx, decl_die;
10364 dw_loc_descr_ref loc;
10366 loc = loc_descriptor_from_tree (bound);
10367 if (loc == NULL)
10368 break;
10370 if (current_function_decl == 0)
10371 ctx = comp_unit_die;
10372 else
10373 ctx = lookup_decl_die (current_function_decl);
10375 decl_die = new_die (DW_TAG_variable, ctx, bound);
10376 add_AT_flag (decl_die, DW_AT_artificial, 1);
10377 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
10378 add_AT_loc (decl_die, DW_AT_location, loc);
10380 add_AT_die_ref (subrange_die, bound_attr, decl_die);
10381 break;
10386 /* Note that the block of subscript information for an array type also
10387 includes information about the element type of type given array type. */
10389 static void
10390 add_subscript_info (dw_die_ref type_die, tree type)
10392 #ifndef MIPS_DEBUGGING_INFO
10393 unsigned dimension_number;
10394 #endif
10395 tree lower, upper;
10396 dw_die_ref subrange_die;
10398 /* The GNU compilers represent multidimensional array types as sequences of
10399 one dimensional array types whose element types are themselves array
10400 types. Here we squish that down, so that each multidimensional array
10401 type gets only one array_type DIE in the Dwarf debugging info. The draft
10402 Dwarf specification say that we are allowed to do this kind of
10403 compression in C (because there is no difference between an array or
10404 arrays and a multidimensional array in C) but for other source languages
10405 (e.g. Ada) we probably shouldn't do this. */
10407 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10408 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10409 We work around this by disabling this feature. See also
10410 gen_array_type_die. */
10411 #ifndef MIPS_DEBUGGING_INFO
10412 for (dimension_number = 0;
10413 TREE_CODE (type) == ARRAY_TYPE;
10414 type = TREE_TYPE (type), dimension_number++)
10415 #endif
10417 tree domain = TYPE_DOMAIN (type);
10419 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
10420 and (in GNU C only) variable bounds. Handle all three forms
10421 here. */
10422 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
10423 if (domain)
10425 /* We have an array type with specified bounds. */
10426 lower = TYPE_MIN_VALUE (domain);
10427 upper = TYPE_MAX_VALUE (domain);
10429 /* Define the index type. */
10430 if (TREE_TYPE (domain))
10432 /* ??? This is probably an Ada unnamed subrange type. Ignore the
10433 TREE_TYPE field. We can't emit debug info for this
10434 because it is an unnamed integral type. */
10435 if (TREE_CODE (domain) == INTEGER_TYPE
10436 && TYPE_NAME (domain) == NULL_TREE
10437 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
10438 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
10440 else
10441 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
10442 type_die);
10445 /* ??? If upper is NULL, the array has unspecified length,
10446 but it does have a lower bound. This happens with Fortran
10447 dimension arr(N:*)
10448 Since the debugger is definitely going to need to know N
10449 to produce useful results, go ahead and output the lower
10450 bound solo, and hope the debugger can cope. */
10452 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
10453 if (upper)
10454 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
10457 /* Otherwise we have an array type with an unspecified length. The
10458 DWARF-2 spec does not say how to handle this; let's just leave out the
10459 bounds. */
10463 static void
10464 add_byte_size_attribute (dw_die_ref die, tree tree_node)
10466 unsigned size;
10468 switch (TREE_CODE (tree_node))
10470 case ERROR_MARK:
10471 size = 0;
10472 break;
10473 case ENUMERAL_TYPE:
10474 case RECORD_TYPE:
10475 case UNION_TYPE:
10476 case QUAL_UNION_TYPE:
10477 size = int_size_in_bytes (tree_node);
10478 break;
10479 case FIELD_DECL:
10480 /* For a data member of a struct or union, the DW_AT_byte_size is
10481 generally given as the number of bytes normally allocated for an
10482 object of the *declared* type of the member itself. This is true
10483 even for bit-fields. */
10484 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
10485 break;
10486 default:
10487 gcc_unreachable ();
10490 /* Note that `size' might be -1 when we get to this point. If it is, that
10491 indicates that the byte size of the entity in question is variable. We
10492 have no good way of expressing this fact in Dwarf at the present time,
10493 so just let the -1 pass on through. */
10494 add_AT_unsigned (die, DW_AT_byte_size, size);
10497 /* For a FIELD_DECL node which represents a bit-field, output an attribute
10498 which specifies the distance in bits from the highest order bit of the
10499 "containing object" for the bit-field to the highest order bit of the
10500 bit-field itself.
10502 For any given bit-field, the "containing object" is a hypothetical object
10503 (of some integral or enum type) within which the given bit-field lives. The
10504 type of this hypothetical "containing object" is always the same as the
10505 declared type of the individual bit-field itself. The determination of the
10506 exact location of the "containing object" for a bit-field is rather
10507 complicated. It's handled by the `field_byte_offset' function (above).
10509 Note that it is the size (in bytes) of the hypothetical "containing object"
10510 which will be given in the DW_AT_byte_size attribute for this bit-field.
10511 (See `byte_size_attribute' above). */
10513 static inline void
10514 add_bit_offset_attribute (dw_die_ref die, tree decl)
10516 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
10517 tree type = DECL_BIT_FIELD_TYPE (decl);
10518 HOST_WIDE_INT bitpos_int;
10519 HOST_WIDE_INT highest_order_object_bit_offset;
10520 HOST_WIDE_INT highest_order_field_bit_offset;
10521 HOST_WIDE_INT unsigned bit_offset;
10523 /* Must be a field and a bit field. */
10524 gcc_assert (type && TREE_CODE (decl) == FIELD_DECL);
10526 /* We can't yet handle bit-fields whose offsets are variable, so if we
10527 encounter such things, just return without generating any attribute
10528 whatsoever. Likewise for variable or too large size. */
10529 if (! host_integerp (bit_position (decl), 0)
10530 || ! host_integerp (DECL_SIZE (decl), 1))
10531 return;
10533 bitpos_int = int_bit_position (decl);
10535 /* Note that the bit offset is always the distance (in bits) from the
10536 highest-order bit of the "containing object" to the highest-order bit of
10537 the bit-field itself. Since the "high-order end" of any object or field
10538 is different on big-endian and little-endian machines, the computation
10539 below must take account of these differences. */
10540 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
10541 highest_order_field_bit_offset = bitpos_int;
10543 if (! BYTES_BIG_ENDIAN)
10545 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
10546 highest_order_object_bit_offset += simple_type_size_in_bits (type);
10549 bit_offset
10550 = (! BYTES_BIG_ENDIAN
10551 ? highest_order_object_bit_offset - highest_order_field_bit_offset
10552 : highest_order_field_bit_offset - highest_order_object_bit_offset);
10554 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
10557 /* For a FIELD_DECL node which represents a bit field, output an attribute
10558 which specifies the length in bits of the given field. */
10560 static inline void
10561 add_bit_size_attribute (dw_die_ref die, tree decl)
10563 /* Must be a field and a bit field. */
10564 gcc_assert (TREE_CODE (decl) == FIELD_DECL
10565 && DECL_BIT_FIELD_TYPE (decl));
10567 if (host_integerp (DECL_SIZE (decl), 1))
10568 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
10571 /* If the compiled language is ANSI C, then add a 'prototyped'
10572 attribute, if arg types are given for the parameters of a function. */
10574 static inline void
10575 add_prototyped_attribute (dw_die_ref die, tree func_type)
10577 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
10578 && TYPE_ARG_TYPES (func_type) != NULL)
10579 add_AT_flag (die, DW_AT_prototyped, 1);
10582 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
10583 by looking in either the type declaration or object declaration
10584 equate table. */
10586 static inline void
10587 add_abstract_origin_attribute (dw_die_ref die, tree origin)
10589 dw_die_ref origin_die = NULL;
10591 if (TREE_CODE (origin) != FUNCTION_DECL)
10593 /* We may have gotten separated from the block for the inlined
10594 function, if we're in an exception handler or some such; make
10595 sure that the abstract function has been written out.
10597 Doing this for nested functions is wrong, however; functions are
10598 distinct units, and our context might not even be inline. */
10599 tree fn = origin;
10601 if (TYPE_P (fn))
10602 fn = TYPE_STUB_DECL (fn);
10604 fn = decl_function_context (fn);
10605 if (fn)
10606 dwarf2out_abstract_function (fn);
10609 if (DECL_P (origin))
10610 origin_die = lookup_decl_die (origin);
10611 else if (TYPE_P (origin))
10612 origin_die = lookup_type_die (origin);
10614 /* XXX: Functions that are never lowered don't always have correct block
10615 trees (in the case of java, they simply have no block tree, in some other
10616 languages). For these functions, there is nothing we can really do to
10617 output correct debug info for inlined functions in all cases. Rather
10618 than die, we'll just produce deficient debug info now, in that we will
10619 have variables without a proper abstract origin. In the future, when all
10620 functions are lowered, we should re-add a gcc_assert (origin_die)
10621 here. */
10623 if (origin_die)
10624 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
10627 /* We do not currently support the pure_virtual attribute. */
10629 static inline void
10630 add_pure_or_virtual_attribute (dw_die_ref die, tree func_decl)
10632 if (DECL_VINDEX (func_decl))
10634 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10636 if (host_integerp (DECL_VINDEX (func_decl), 0))
10637 add_AT_loc (die, DW_AT_vtable_elem_location,
10638 new_loc_descr (DW_OP_constu,
10639 tree_low_cst (DECL_VINDEX (func_decl), 0),
10640 0));
10642 /* GNU extension: Record what type this method came from originally. */
10643 if (debug_info_level > DINFO_LEVEL_TERSE)
10644 add_AT_die_ref (die, DW_AT_containing_type,
10645 lookup_type_die (DECL_CONTEXT (func_decl)));
10649 /* Add source coordinate attributes for the given decl. */
10651 static void
10652 add_src_coords_attributes (dw_die_ref die, tree decl)
10654 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
10655 unsigned file_index = lookup_filename (s.file);
10657 add_AT_unsigned (die, DW_AT_decl_file, file_index);
10658 add_AT_unsigned (die, DW_AT_decl_line, s.line);
10661 /* Add a DW_AT_name attribute and source coordinate attribute for the
10662 given decl, but only if it actually has a name. */
10664 static void
10665 add_name_and_src_coords_attributes (dw_die_ref die, tree decl)
10667 tree decl_name;
10669 decl_name = DECL_NAME (decl);
10670 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
10672 add_name_attribute (die, dwarf2_name (decl, 0));
10673 if (! DECL_ARTIFICIAL (decl))
10674 add_src_coords_attributes (die, decl);
10676 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
10677 && TREE_PUBLIC (decl)
10678 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
10679 && !DECL_ABSTRACT (decl))
10680 add_AT_string (die, DW_AT_MIPS_linkage_name,
10681 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
10684 #ifdef VMS_DEBUGGING_INFO
10685 /* Get the function's name, as described by its RTL. This may be different
10686 from the DECL_NAME name used in the source file. */
10687 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
10689 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
10690 XEXP (DECL_RTL (decl), 0));
10691 VEC_safe_push (tree, gc, used_rtx_array, XEXP (DECL_RTL (decl), 0));
10693 #endif
10696 /* Push a new declaration scope. */
10698 static void
10699 push_decl_scope (tree scope)
10701 VEC_safe_push (tree, gc, decl_scope_table, scope);
10704 /* Pop a declaration scope. */
10706 static inline void
10707 pop_decl_scope (void)
10709 VEC_pop (tree, decl_scope_table);
10712 /* Return the DIE for the scope that immediately contains this type.
10713 Non-named types get global scope. Named types nested in other
10714 types get their containing scope if it's open, or global scope
10715 otherwise. All other types (i.e. function-local named types) get
10716 the current active scope. */
10718 static dw_die_ref
10719 scope_die_for (tree t, dw_die_ref context_die)
10721 dw_die_ref scope_die = NULL;
10722 tree containing_scope;
10723 int i;
10725 /* Non-types always go in the current scope. */
10726 gcc_assert (TYPE_P (t));
10728 containing_scope = TYPE_CONTEXT (t);
10730 /* Use the containing namespace if it was passed in (for a declaration). */
10731 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
10733 if (context_die == lookup_decl_die (containing_scope))
10734 /* OK */;
10735 else
10736 containing_scope = NULL_TREE;
10739 /* Ignore function type "scopes" from the C frontend. They mean that
10740 a tagged type is local to a parmlist of a function declarator, but
10741 that isn't useful to DWARF. */
10742 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
10743 containing_scope = NULL_TREE;
10745 if (containing_scope == NULL_TREE)
10746 scope_die = comp_unit_die;
10747 else if (TYPE_P (containing_scope))
10749 /* For types, we can just look up the appropriate DIE. But
10750 first we check to see if we're in the middle of emitting it
10751 so we know where the new DIE should go. */
10752 for (i = VEC_length (tree, decl_scope_table) - 1; i >= 0; --i)
10753 if (VEC_index (tree, decl_scope_table, i) == containing_scope)
10754 break;
10756 if (i < 0)
10758 gcc_assert (debug_info_level <= DINFO_LEVEL_TERSE
10759 || TREE_ASM_WRITTEN (containing_scope));
10761 /* If none of the current dies are suitable, we get file scope. */
10762 scope_die = comp_unit_die;
10764 else
10765 scope_die = lookup_type_die (containing_scope);
10767 else
10768 scope_die = context_die;
10770 return scope_die;
10773 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
10775 static inline int
10776 local_scope_p (dw_die_ref context_die)
10778 for (; context_die; context_die = context_die->die_parent)
10779 if (context_die->die_tag == DW_TAG_inlined_subroutine
10780 || context_die->die_tag == DW_TAG_subprogram)
10781 return 1;
10783 return 0;
10786 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
10787 whether or not to treat a DIE in this context as a declaration. */
10789 static inline int
10790 class_or_namespace_scope_p (dw_die_ref context_die)
10792 return (context_die
10793 && (context_die->die_tag == DW_TAG_structure_type
10794 || context_die->die_tag == DW_TAG_union_type
10795 || context_die->die_tag == DW_TAG_namespace));
10798 /* Many forms of DIEs require a "type description" attribute. This
10799 routine locates the proper "type descriptor" die for the type given
10800 by 'type', and adds a DW_AT_type attribute below the given die. */
10802 static void
10803 add_type_attribute (dw_die_ref object_die, tree type, int decl_const,
10804 int decl_volatile, dw_die_ref context_die)
10806 enum tree_code code = TREE_CODE (type);
10807 dw_die_ref type_die = NULL;
10809 /* ??? If this type is an unnamed subrange type of an integral or
10810 floating-point type, use the inner type. This is because we have no
10811 support for unnamed types in base_type_die. This can happen if this is
10812 an Ada subrange type. Correct solution is emit a subrange type die. */
10813 if ((code == INTEGER_TYPE || code == REAL_TYPE)
10814 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
10815 type = TREE_TYPE (type), code = TREE_CODE (type);
10817 if (code == ERROR_MARK
10818 /* Handle a special case. For functions whose return type is void, we
10819 generate *no* type attribute. (Note that no object may have type
10820 `void', so this only applies to function return types). */
10821 || code == VOID_TYPE)
10822 return;
10824 type_die = modified_type_die (type,
10825 decl_const || TYPE_READONLY (type),
10826 decl_volatile || TYPE_VOLATILE (type),
10827 context_die);
10829 if (type_die != NULL)
10830 add_AT_die_ref (object_die, DW_AT_type, type_die);
10833 /* Given an object die, add the calling convention attribute for the
10834 function call type. */
10835 static void
10836 add_calling_convention_attribute (dw_die_ref subr_die, tree type)
10838 enum dwarf_calling_convention value = DW_CC_normal;
10840 value = targetm.dwarf_calling_convention (type);
10842 /* Only add the attribute if the backend requests it, and
10843 is not DW_CC_normal. */
10844 if (value && (value != DW_CC_normal))
10845 add_AT_unsigned (subr_die, DW_AT_calling_convention, value);
10848 /* Given a tree pointer to a struct, class, union, or enum type node, return
10849 a pointer to the (string) tag name for the given type, or zero if the type
10850 was declared without a tag. */
10852 static const char *
10853 type_tag (tree type)
10855 const char *name = 0;
10857 if (TYPE_NAME (type) != 0)
10859 tree t = 0;
10861 /* Find the IDENTIFIER_NODE for the type name. */
10862 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
10863 t = TYPE_NAME (type);
10865 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
10866 a TYPE_DECL node, regardless of whether or not a `typedef' was
10867 involved. */
10868 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10869 && ! DECL_IGNORED_P (TYPE_NAME (type)))
10870 t = DECL_NAME (TYPE_NAME (type));
10872 /* Now get the name as a string, or invent one. */
10873 if (t != 0)
10874 name = IDENTIFIER_POINTER (t);
10877 return (name == 0 || *name == '\0') ? 0 : name;
10880 /* Return the type associated with a data member, make a special check
10881 for bit field types. */
10883 static inline tree
10884 member_declared_type (tree member)
10886 return (DECL_BIT_FIELD_TYPE (member)
10887 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
10890 /* Get the decl's label, as described by its RTL. This may be different
10891 from the DECL_NAME name used in the source file. */
10893 #if 0
10894 static const char *
10895 decl_start_label (tree decl)
10897 rtx x;
10898 const char *fnname;
10900 x = DECL_RTL (decl);
10901 gcc_assert (MEM_P (x));
10903 x = XEXP (x, 0);
10904 gcc_assert (GET_CODE (x) == SYMBOL_REF);
10906 fnname = XSTR (x, 0);
10907 return fnname;
10909 #endif
10911 /* These routines generate the internal representation of the DIE's for
10912 the compilation unit. Debugging information is collected by walking
10913 the declaration trees passed in from dwarf2out_decl(). */
10915 static void
10916 gen_array_type_die (tree type, dw_die_ref context_die)
10918 dw_die_ref scope_die = scope_die_for (type, context_die);
10919 dw_die_ref array_die;
10920 tree element_type;
10922 /* ??? The SGI dwarf reader fails for array of array of enum types unless
10923 the inner array type comes before the outer array type. Thus we must
10924 call gen_type_die before we call new_die. See below also. */
10925 #ifdef MIPS_DEBUGGING_INFO
10926 gen_type_die (TREE_TYPE (type), context_die);
10927 #endif
10929 array_die = new_die (DW_TAG_array_type, scope_die, type);
10930 add_name_attribute (array_die, type_tag (type));
10931 equate_type_number_to_die (type, array_die);
10933 if (TREE_CODE (type) == VECTOR_TYPE)
10935 /* The frontend feeds us a representation for the vector as a struct
10936 containing an array. Pull out the array type. */
10937 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
10938 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
10941 #if 0
10942 /* We default the array ordering. SDB will probably do
10943 the right things even if DW_AT_ordering is not present. It's not even
10944 an issue until we start to get into multidimensional arrays anyway. If
10945 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
10946 then we'll have to put the DW_AT_ordering attribute back in. (But if
10947 and when we find out that we need to put these in, we will only do so
10948 for multidimensional arrays. */
10949 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
10950 #endif
10952 #ifdef MIPS_DEBUGGING_INFO
10953 /* The SGI compilers handle arrays of unknown bound by setting
10954 AT_declaration and not emitting any subrange DIEs. */
10955 if (! TYPE_DOMAIN (type))
10956 add_AT_flag (array_die, DW_AT_declaration, 1);
10957 else
10958 #endif
10959 add_subscript_info (array_die, type);
10961 /* Add representation of the type of the elements of this array type. */
10962 element_type = TREE_TYPE (type);
10964 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
10965 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
10966 We work around this by disabling this feature. See also
10967 add_subscript_info. */
10968 #ifndef MIPS_DEBUGGING_INFO
10969 while (TREE_CODE (element_type) == ARRAY_TYPE)
10970 element_type = TREE_TYPE (element_type);
10972 gen_type_die (element_type, context_die);
10973 #endif
10975 add_type_attribute (array_die, element_type, 0, 0, context_die);
10978 #if 0
10979 static void
10980 gen_entry_point_die (tree decl, dw_die_ref context_die)
10982 tree origin = decl_ultimate_origin (decl);
10983 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
10985 if (origin != NULL)
10986 add_abstract_origin_attribute (decl_die, origin);
10987 else
10989 add_name_and_src_coords_attributes (decl_die, decl);
10990 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
10991 0, 0, context_die);
10994 if (DECL_ABSTRACT (decl))
10995 equate_decl_number_to_die (decl, decl_die);
10996 else
10997 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
10999 #endif
11001 /* Walk through the list of incomplete types again, trying once more to
11002 emit full debugging info for them. */
11004 static void
11005 retry_incomplete_types (void)
11007 int i;
11009 for (i = VEC_length (tree, incomplete_types) - 1; i >= 0; i--)
11010 gen_type_die (VEC_index (tree, incomplete_types, i), comp_unit_die);
11013 /* Generate a DIE to represent an inlined instance of an enumeration type. */
11015 static void
11016 gen_inlined_enumeration_type_die (tree type, dw_die_ref context_die)
11018 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
11020 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11021 be incomplete and such types are not marked. */
11022 add_abstract_origin_attribute (type_die, type);
11025 /* Generate a DIE to represent an inlined instance of a structure type. */
11027 static void
11028 gen_inlined_structure_type_die (tree type, dw_die_ref context_die)
11030 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
11032 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11033 be incomplete and such types are not marked. */
11034 add_abstract_origin_attribute (type_die, type);
11037 /* Generate a DIE to represent an inlined instance of a union type. */
11039 static void
11040 gen_inlined_union_type_die (tree type, dw_die_ref context_die)
11042 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
11044 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
11045 be incomplete and such types are not marked. */
11046 add_abstract_origin_attribute (type_die, type);
11049 /* Generate a DIE to represent an enumeration type. Note that these DIEs
11050 include all of the information about the enumeration values also. Each
11051 enumerated type name/value is listed as a child of the enumerated type
11052 DIE. */
11054 static dw_die_ref
11055 gen_enumeration_type_die (tree type, dw_die_ref context_die)
11057 dw_die_ref type_die = lookup_type_die (type);
11059 if (type_die == NULL)
11061 type_die = new_die (DW_TAG_enumeration_type,
11062 scope_die_for (type, context_die), type);
11063 equate_type_number_to_die (type, type_die);
11064 add_name_attribute (type_die, type_tag (type));
11066 else if (! TYPE_SIZE (type))
11067 return type_die;
11068 else
11069 remove_AT (type_die, DW_AT_declaration);
11071 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
11072 given enum type is incomplete, do not generate the DW_AT_byte_size
11073 attribute or the DW_AT_element_list attribute. */
11074 if (TYPE_SIZE (type))
11076 tree link;
11078 TREE_ASM_WRITTEN (type) = 1;
11079 add_byte_size_attribute (type_die, type);
11080 if (TYPE_STUB_DECL (type) != NULL_TREE)
11081 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
11083 /* If the first reference to this type was as the return type of an
11084 inline function, then it may not have a parent. Fix this now. */
11085 if (type_die->die_parent == NULL)
11086 add_child_die (scope_die_for (type, context_die), type_die);
11088 for (link = TYPE_VALUES (type);
11089 link != NULL; link = TREE_CHAIN (link))
11091 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
11092 tree value = TREE_VALUE (link);
11094 add_name_attribute (enum_die,
11095 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
11097 if (host_integerp (value, TYPE_UNSIGNED (TREE_TYPE (value))))
11098 /* DWARF2 does not provide a way of indicating whether or
11099 not enumeration constants are signed or unsigned. GDB
11100 always assumes the values are signed, so we output all
11101 values as if they were signed. That means that
11102 enumeration constants with very large unsigned values
11103 will appear to have negative values in the debugger. */
11104 add_AT_int (enum_die, DW_AT_const_value,
11105 tree_low_cst (value, tree_int_cst_sgn (value) > 0));
11108 else
11109 add_AT_flag (type_die, DW_AT_declaration, 1);
11111 return type_die;
11114 /* Generate a DIE to represent either a real live formal parameter decl or to
11115 represent just the type of some formal parameter position in some function
11116 type.
11118 Note that this routine is a bit unusual because its argument may be a
11119 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
11120 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
11121 node. If it's the former then this function is being called to output a
11122 DIE to represent a formal parameter object (or some inlining thereof). If
11123 it's the latter, then this function is only being called to output a
11124 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
11125 argument type of some subprogram type. */
11127 static dw_die_ref
11128 gen_formal_parameter_die (tree node, dw_die_ref context_die)
11130 dw_die_ref parm_die
11131 = new_die (DW_TAG_formal_parameter, context_die, node);
11132 tree origin;
11134 switch (TREE_CODE_CLASS (TREE_CODE (node)))
11136 case tcc_declaration:
11137 origin = decl_ultimate_origin (node);
11138 if (origin != NULL)
11139 add_abstract_origin_attribute (parm_die, origin);
11140 else
11142 add_name_and_src_coords_attributes (parm_die, node);
11143 add_type_attribute (parm_die, TREE_TYPE (node),
11144 TREE_READONLY (node),
11145 TREE_THIS_VOLATILE (node),
11146 context_die);
11147 if (DECL_ARTIFICIAL (node))
11148 add_AT_flag (parm_die, DW_AT_artificial, 1);
11151 equate_decl_number_to_die (node, parm_die);
11152 if (! DECL_ABSTRACT (node))
11153 add_location_or_const_value_attribute (parm_die, node, DW_AT_location);
11155 break;
11157 case tcc_type:
11158 /* We were called with some kind of a ..._TYPE node. */
11159 add_type_attribute (parm_die, node, 0, 0, context_die);
11160 break;
11162 default:
11163 gcc_unreachable ();
11166 return parm_die;
11169 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
11170 at the end of an (ANSI prototyped) formal parameters list. */
11172 static void
11173 gen_unspecified_parameters_die (tree decl_or_type, dw_die_ref context_die)
11175 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
11178 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
11179 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
11180 parameters as specified in some function type specification (except for
11181 those which appear as part of a function *definition*). */
11183 static void
11184 gen_formal_types_die (tree function_or_method_type, dw_die_ref context_die)
11186 tree link;
11187 tree formal_type = NULL;
11188 tree first_parm_type;
11189 tree arg;
11191 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
11193 arg = DECL_ARGUMENTS (function_or_method_type);
11194 function_or_method_type = TREE_TYPE (function_or_method_type);
11196 else
11197 arg = NULL_TREE;
11199 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
11201 /* Make our first pass over the list of formal parameter types and output a
11202 DW_TAG_formal_parameter DIE for each one. */
11203 for (link = first_parm_type; link; )
11205 dw_die_ref parm_die;
11207 formal_type = TREE_VALUE (link);
11208 if (formal_type == void_type_node)
11209 break;
11211 /* Output a (nameless) DIE to represent the formal parameter itself. */
11212 parm_die = gen_formal_parameter_die (formal_type, context_die);
11213 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
11214 && link == first_parm_type)
11215 || (arg && DECL_ARTIFICIAL (arg)))
11216 add_AT_flag (parm_die, DW_AT_artificial, 1);
11218 link = TREE_CHAIN (link);
11219 if (arg)
11220 arg = TREE_CHAIN (arg);
11223 /* If this function type has an ellipsis, add a
11224 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
11225 if (formal_type != void_type_node)
11226 gen_unspecified_parameters_die (function_or_method_type, context_die);
11228 /* Make our second (and final) pass over the list of formal parameter types
11229 and output DIEs to represent those types (as necessary). */
11230 for (link = TYPE_ARG_TYPES (function_or_method_type);
11231 link && TREE_VALUE (link);
11232 link = TREE_CHAIN (link))
11233 gen_type_die (TREE_VALUE (link), context_die);
11236 /* We want to generate the DIE for TYPE so that we can generate the
11237 die for MEMBER, which has been defined; we will need to refer back
11238 to the member declaration nested within TYPE. If we're trying to
11239 generate minimal debug info for TYPE, processing TYPE won't do the
11240 trick; we need to attach the member declaration by hand. */
11242 static void
11243 gen_type_die_for_member (tree type, tree member, dw_die_ref context_die)
11245 gen_type_die (type, context_die);
11247 /* If we're trying to avoid duplicate debug info, we may not have
11248 emitted the member decl for this function. Emit it now. */
11249 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
11250 && ! lookup_decl_die (member))
11252 dw_die_ref type_die;
11253 gcc_assert (!decl_ultimate_origin (member));
11255 push_decl_scope (type);
11256 type_die = lookup_type_die (type);
11257 if (TREE_CODE (member) == FUNCTION_DECL)
11258 gen_subprogram_die (member, type_die);
11259 else if (TREE_CODE (member) == FIELD_DECL)
11261 /* Ignore the nameless fields that are used to skip bits but handle
11262 C++ anonymous unions and structs. */
11263 if (DECL_NAME (member) != NULL_TREE
11264 || TREE_CODE (TREE_TYPE (member)) == UNION_TYPE
11265 || TREE_CODE (TREE_TYPE (member)) == RECORD_TYPE)
11267 gen_type_die (member_declared_type (member), type_die);
11268 gen_field_die (member, type_die);
11271 else
11272 gen_variable_die (member, type_die);
11274 pop_decl_scope ();
11278 /* Generate the DWARF2 info for the "abstract" instance of a function which we
11279 may later generate inlined and/or out-of-line instances of. */
11281 static void
11282 dwarf2out_abstract_function (tree decl)
11284 dw_die_ref old_die;
11285 tree save_fn;
11286 tree context;
11287 int was_abstract = DECL_ABSTRACT (decl);
11289 /* Make sure we have the actual abstract inline, not a clone. */
11290 decl = DECL_ORIGIN (decl);
11292 old_die = lookup_decl_die (decl);
11293 if (old_die && get_AT (old_die, DW_AT_inline))
11294 /* We've already generated the abstract instance. */
11295 return;
11297 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
11298 we don't get confused by DECL_ABSTRACT. */
11299 if (debug_info_level > DINFO_LEVEL_TERSE)
11301 context = decl_class_context (decl);
11302 if (context)
11303 gen_type_die_for_member
11304 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
11307 /* Pretend we've just finished compiling this function. */
11308 save_fn = current_function_decl;
11309 current_function_decl = decl;
11311 set_decl_abstract_flags (decl, 1);
11312 dwarf2out_decl (decl);
11313 if (! was_abstract)
11314 set_decl_abstract_flags (decl, 0);
11316 current_function_decl = save_fn;
11319 /* Generate a DIE to represent a declared function (either file-scope or
11320 block-local). */
11322 static void
11323 gen_subprogram_die (tree decl, dw_die_ref context_die)
11325 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
11326 tree origin = decl_ultimate_origin (decl);
11327 dw_die_ref subr_die;
11328 rtx fp_reg;
11329 tree fn_arg_types;
11330 tree outer_scope;
11331 dw_die_ref old_die = lookup_decl_die (decl);
11332 int declaration = (current_function_decl != decl
11333 || class_or_namespace_scope_p (context_die));
11335 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
11336 started to generate the abstract instance of an inline, decided to output
11337 its containing class, and proceeded to emit the declaration of the inline
11338 from the member list for the class. If so, DECLARATION takes priority;
11339 we'll get back to the abstract instance when done with the class. */
11341 /* The class-scope declaration DIE must be the primary DIE. */
11342 if (origin && declaration && class_or_namespace_scope_p (context_die))
11344 origin = NULL;
11345 gcc_assert (!old_die);
11348 if (origin != NULL)
11350 gcc_assert (!declaration || local_scope_p (context_die));
11352 /* Fixup die_parent for the abstract instance of a nested
11353 inline function. */
11354 if (old_die && old_die->die_parent == NULL)
11355 add_child_die (context_die, old_die);
11357 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11358 add_abstract_origin_attribute (subr_die, origin);
11360 else if (old_die)
11362 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11363 unsigned file_index = lookup_filename (s.file);
11365 if (!get_AT_flag (old_die, DW_AT_declaration)
11366 /* We can have a normal definition following an inline one in the
11367 case of redefinition of GNU C extern inlines.
11368 It seems reasonable to use AT_specification in this case. */
11369 && !get_AT (old_die, DW_AT_inline))
11371 /* Detect and ignore this case, where we are trying to output
11372 something we have already output. */
11373 return;
11376 /* If the definition comes from the same place as the declaration,
11377 maybe use the old DIE. We always want the DIE for this function
11378 that has the *_pc attributes to be under comp_unit_die so the
11379 debugger can find it. We also need to do this for abstract
11380 instances of inlines, since the spec requires the out-of-line copy
11381 to have the same parent. For local class methods, this doesn't
11382 apply; we just use the old DIE. */
11383 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
11384 && (DECL_ARTIFICIAL (decl)
11385 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
11386 && (get_AT_unsigned (old_die, DW_AT_decl_line)
11387 == (unsigned) s.line))))
11389 subr_die = old_die;
11391 /* Clear out the declaration attribute and the formal parameters.
11392 Do not remove all children, because it is possible that this
11393 declaration die was forced using force_decl_die(). In such
11394 cases die that forced declaration die (e.g. TAG_imported_module)
11395 is one of the children that we do not want to remove. */
11396 remove_AT (subr_die, DW_AT_declaration);
11397 remove_child_TAG (subr_die, DW_TAG_formal_parameter);
11399 else
11401 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11402 add_AT_specification (subr_die, old_die);
11403 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11404 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
11405 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11406 != (unsigned) s.line)
11407 add_AT_unsigned
11408 (subr_die, DW_AT_decl_line, s.line);
11411 else
11413 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
11415 if (TREE_PUBLIC (decl))
11416 add_AT_flag (subr_die, DW_AT_external, 1);
11418 add_name_and_src_coords_attributes (subr_die, decl);
11419 if (debug_info_level > DINFO_LEVEL_TERSE)
11421 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
11422 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
11423 0, 0, context_die);
11426 add_pure_or_virtual_attribute (subr_die, decl);
11427 if (DECL_ARTIFICIAL (decl))
11428 add_AT_flag (subr_die, DW_AT_artificial, 1);
11430 if (TREE_PROTECTED (decl))
11431 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
11432 else if (TREE_PRIVATE (decl))
11433 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
11436 if (declaration)
11438 if (!old_die || !get_AT (old_die, DW_AT_inline))
11440 add_AT_flag (subr_die, DW_AT_declaration, 1);
11442 /* The first time we see a member function, it is in the context of
11443 the class to which it belongs. We make sure of this by emitting
11444 the class first. The next time is the definition, which is
11445 handled above. The two may come from the same source text.
11447 Note that force_decl_die() forces function declaration die. It is
11448 later reused to represent definition. */
11449 equate_decl_number_to_die (decl, subr_die);
11452 else if (DECL_ABSTRACT (decl))
11454 if (DECL_DECLARED_INLINE_P (decl))
11456 if (cgraph_function_possibly_inlined_p (decl))
11457 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
11458 else
11459 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
11461 else
11463 if (cgraph_function_possibly_inlined_p (decl))
11464 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
11465 else
11466 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_not_inlined);
11469 equate_decl_number_to_die (decl, subr_die);
11471 else if (!DECL_EXTERNAL (decl))
11473 if (!old_die || !get_AT (old_die, DW_AT_inline))
11474 equate_decl_number_to_die (decl, subr_die);
11476 if (!flag_reorder_blocks_and_partition)
11478 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
11479 current_function_funcdef_no);
11480 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
11481 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
11482 current_function_funcdef_no);
11483 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
11485 add_pubname (decl, subr_die);
11486 add_arange (decl, subr_die);
11488 else
11489 { /* Do nothing for now; maybe need to duplicate die, one for
11490 hot section and ond for cold section, then use the hot/cold
11491 section begin/end labels to generate the aranges... */
11493 add_AT_lbl_id (subr_die, DW_AT_low_pc, hot_section_label);
11494 add_AT_lbl_id (subr_die, DW_AT_high_pc, hot_section_end_label);
11495 add_AT_lbl_id (subr_die, DW_AT_lo_user, unlikely_section_label);
11496 add_AT_lbl_id (subr_die, DW_AT_hi_user, cold_section_end_label);
11498 add_pubname (decl, subr_die);
11499 add_arange (decl, subr_die);
11500 add_arange (decl, subr_die);
11504 #ifdef MIPS_DEBUGGING_INFO
11505 /* Add a reference to the FDE for this routine. */
11506 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
11507 #endif
11509 /* Define the "frame base" location for this routine. We use the
11510 frame pointer or stack pointer registers, since the RTL for local
11511 variables is relative to one of them. */
11512 if (frame_base_decl && lookup_decl_loc (frame_base_decl) != NULL)
11514 add_location_or_const_value_attribute (subr_die, frame_base_decl,
11515 DW_AT_frame_base);
11517 else
11519 fp_reg
11520 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
11521 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
11524 if (cfun->static_chain_decl)
11525 add_AT_location_description (subr_die, DW_AT_static_link,
11526 loc_descriptor_from_tree (cfun->static_chain_decl));
11529 /* Now output descriptions of the arguments for this function. This gets
11530 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
11531 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
11532 `...' at the end of the formal parameter list. In order to find out if
11533 there was a trailing ellipsis or not, we must instead look at the type
11534 associated with the FUNCTION_DECL. This will be a node of type
11535 FUNCTION_TYPE. If the chain of type nodes hanging off of this
11536 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
11537 an ellipsis at the end. */
11539 /* In the case where we are describing a mere function declaration, all we
11540 need to do here (and all we *can* do here) is to describe the *types* of
11541 its formal parameters. */
11542 if (debug_info_level <= DINFO_LEVEL_TERSE)
11544 else if (declaration)
11545 gen_formal_types_die (decl, subr_die);
11546 else
11548 /* Generate DIEs to represent all known formal parameters. */
11549 tree arg_decls = DECL_ARGUMENTS (decl);
11550 tree parm;
11552 /* When generating DIEs, generate the unspecified_parameters DIE
11553 instead if we come across the arg "__builtin_va_alist" */
11554 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
11555 if (TREE_CODE (parm) == PARM_DECL)
11557 if (DECL_NAME (parm)
11558 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
11559 "__builtin_va_alist"))
11560 gen_unspecified_parameters_die (parm, subr_die);
11561 else
11562 gen_decl_die (parm, subr_die);
11565 /* Decide whether we need an unspecified_parameters DIE at the end.
11566 There are 2 more cases to do this for: 1) the ansi ... declaration -
11567 this is detectable when the end of the arg list is not a
11568 void_type_node 2) an unprototyped function declaration (not a
11569 definition). This just means that we have no info about the
11570 parameters at all. */
11571 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
11572 if (fn_arg_types != NULL)
11574 /* This is the prototyped case, check for.... */
11575 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
11576 gen_unspecified_parameters_die (decl, subr_die);
11578 else if (DECL_INITIAL (decl) == NULL_TREE)
11579 gen_unspecified_parameters_die (decl, subr_die);
11582 /* Output Dwarf info for all of the stuff within the body of the function
11583 (if it has one - it may be just a declaration). */
11584 outer_scope = DECL_INITIAL (decl);
11586 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
11587 a function. This BLOCK actually represents the outermost binding contour
11588 for the function, i.e. the contour in which the function's formal
11589 parameters and labels get declared. Curiously, it appears that the front
11590 end doesn't actually put the PARM_DECL nodes for the current function onto
11591 the BLOCK_VARS list for this outer scope, but are strung off of the
11592 DECL_ARGUMENTS list for the function instead.
11594 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
11595 the LABEL_DECL nodes for the function however, and we output DWARF info
11596 for those in decls_for_scope. Just within the `outer_scope' there will be
11597 a BLOCK node representing the function's outermost pair of curly braces,
11598 and any blocks used for the base and member initializers of a C++
11599 constructor function. */
11600 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
11602 /* Emit a DW_TAG_variable DIE for a named return value. */
11603 if (DECL_NAME (DECL_RESULT (decl)))
11604 gen_decl_die (DECL_RESULT (decl), subr_die);
11606 current_function_has_inlines = 0;
11607 decls_for_scope (outer_scope, subr_die, 0);
11609 #if 0 && defined (MIPS_DEBUGGING_INFO)
11610 if (current_function_has_inlines)
11612 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
11613 if (! comp_unit_has_inlines)
11615 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
11616 comp_unit_has_inlines = 1;
11619 #endif
11621 /* Add the calling convention attribute if requested. */
11622 add_calling_convention_attribute (subr_die, TREE_TYPE (decl));
11626 /* Generate a DIE to represent a declared data object. */
11628 static void
11629 gen_variable_die (tree decl, dw_die_ref context_die)
11631 tree origin = decl_ultimate_origin (decl);
11632 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
11634 dw_die_ref old_die = lookup_decl_die (decl);
11635 int declaration = (DECL_EXTERNAL (decl)
11636 /* If DECL is COMDAT and has not actually been
11637 emitted, we cannot take its address; there
11638 might end up being no definition anywhere in
11639 the program. For example, consider the C++
11640 test case:
11642 template <class T>
11643 struct S { static const int i = 7; };
11645 template <class T>
11646 const int S<T>::i;
11648 int f() { return S<int>::i; }
11650 Here, S<int>::i is not DECL_EXTERNAL, but no
11651 definition is required, so the compiler will
11652 not emit a definition. */
11653 || (TREE_CODE (decl) == VAR_DECL
11654 && DECL_COMDAT (decl) && !TREE_ASM_WRITTEN (decl))
11655 || class_or_namespace_scope_p (context_die));
11657 if (origin != NULL)
11658 add_abstract_origin_attribute (var_die, origin);
11660 /* Loop unrolling can create multiple blocks that refer to the same
11661 static variable, so we must test for the DW_AT_declaration flag.
11663 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
11664 copy decls and set the DECL_ABSTRACT flag on them instead of
11665 sharing them.
11667 ??? Duplicated blocks have been rewritten to use .debug_ranges.
11669 ??? The declare_in_namespace support causes us to get two DIEs for one
11670 variable, both of which are declarations. We want to avoid considering
11671 one to be a specification, so we must test that this DIE is not a
11672 declaration. */
11673 else if (old_die && TREE_STATIC (decl) && ! declaration
11674 && get_AT_flag (old_die, DW_AT_declaration) == 1)
11676 /* This is a definition of a C++ class level static. */
11677 add_AT_specification (var_die, old_die);
11678 if (DECL_NAME (decl))
11680 expanded_location s = expand_location (DECL_SOURCE_LOCATION (decl));
11681 unsigned file_index = lookup_filename (s.file);
11683 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
11684 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
11686 if (get_AT_unsigned (old_die, DW_AT_decl_line)
11687 != (unsigned) s.line)
11689 add_AT_unsigned (var_die, DW_AT_decl_line, s.line);
11692 else
11694 add_name_and_src_coords_attributes (var_die, decl);
11695 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
11696 TREE_THIS_VOLATILE (decl), context_die);
11698 if (TREE_PUBLIC (decl))
11699 add_AT_flag (var_die, DW_AT_external, 1);
11701 if (DECL_ARTIFICIAL (decl))
11702 add_AT_flag (var_die, DW_AT_artificial, 1);
11704 if (TREE_PROTECTED (decl))
11705 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
11706 else if (TREE_PRIVATE (decl))
11707 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
11710 if (declaration)
11711 add_AT_flag (var_die, DW_AT_declaration, 1);
11713 if (DECL_ABSTRACT (decl) || declaration)
11714 equate_decl_number_to_die (decl, var_die);
11716 if (! declaration && ! DECL_ABSTRACT (decl))
11718 add_location_or_const_value_attribute (var_die, decl, DW_AT_location);
11719 add_pubname (decl, var_die);
11721 else
11722 tree_add_const_value_attribute (var_die, decl);
11725 /* Generate a DIE to represent a label identifier. */
11727 static void
11728 gen_label_die (tree decl, dw_die_ref context_die)
11730 tree origin = decl_ultimate_origin (decl);
11731 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
11732 rtx insn;
11733 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11735 if (origin != NULL)
11736 add_abstract_origin_attribute (lbl_die, origin);
11737 else
11738 add_name_and_src_coords_attributes (lbl_die, decl);
11740 if (DECL_ABSTRACT (decl))
11741 equate_decl_number_to_die (decl, lbl_die);
11742 else
11744 insn = DECL_RTL_IF_SET (decl);
11746 /* Deleted labels are programmer specified labels which have been
11747 eliminated because of various optimizations. We still emit them
11748 here so that it is possible to put breakpoints on them. */
11749 if (insn
11750 && (LABEL_P (insn)
11751 || ((NOTE_P (insn)
11752 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))))
11754 /* When optimization is enabled (via -O) some parts of the compiler
11755 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
11756 represent source-level labels which were explicitly declared by
11757 the user. This really shouldn't be happening though, so catch
11758 it if it ever does happen. */
11759 gcc_assert (!INSN_DELETED_P (insn));
11761 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
11762 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
11767 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
11768 attributes to the DIE for a block STMT, to describe where the inlined
11769 function was called from. This is similar to add_src_coords_attributes. */
11771 static inline void
11772 add_call_src_coords_attributes (tree stmt, dw_die_ref die)
11774 expanded_location s = expand_location (BLOCK_SOURCE_LOCATION (stmt));
11775 unsigned file_index = lookup_filename (s.file);
11777 add_AT_unsigned (die, DW_AT_call_file, file_index);
11778 add_AT_unsigned (die, DW_AT_call_line, s.line);
11781 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
11782 Add low_pc and high_pc attributes to the DIE for a block STMT. */
11784 static inline void
11785 add_high_low_attributes (tree stmt, dw_die_ref die)
11787 char label[MAX_ARTIFICIAL_LABEL_BYTES];
11789 if (BLOCK_FRAGMENT_CHAIN (stmt))
11791 tree chain;
11793 add_AT_range_list (die, DW_AT_ranges, add_ranges (stmt));
11795 chain = BLOCK_FRAGMENT_CHAIN (stmt);
11798 add_ranges (chain);
11799 chain = BLOCK_FRAGMENT_CHAIN (chain);
11801 while (chain);
11802 add_ranges (NULL);
11804 else
11806 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
11807 BLOCK_NUMBER (stmt));
11808 add_AT_lbl_id (die, DW_AT_low_pc, label);
11809 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
11810 BLOCK_NUMBER (stmt));
11811 add_AT_lbl_id (die, DW_AT_high_pc, label);
11815 /* Generate a DIE for a lexical block. */
11817 static void
11818 gen_lexical_block_die (tree stmt, dw_die_ref context_die, int depth)
11820 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
11822 if (! BLOCK_ABSTRACT (stmt))
11823 add_high_low_attributes (stmt, stmt_die);
11825 decls_for_scope (stmt, stmt_die, depth);
11828 /* Generate a DIE for an inlined subprogram. */
11830 static void
11831 gen_inlined_subroutine_die (tree stmt, dw_die_ref context_die, int depth)
11833 tree decl = block_ultimate_origin (stmt);
11835 /* Emit info for the abstract instance first, if we haven't yet. We
11836 must emit this even if the block is abstract, otherwise when we
11837 emit the block below (or elsewhere), we may end up trying to emit
11838 a die whose origin die hasn't been emitted, and crashing. */
11839 dwarf2out_abstract_function (decl);
11841 if (! BLOCK_ABSTRACT (stmt))
11843 dw_die_ref subr_die
11844 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
11846 add_abstract_origin_attribute (subr_die, decl);
11847 add_high_low_attributes (stmt, subr_die);
11848 add_call_src_coords_attributes (stmt, subr_die);
11850 decls_for_scope (stmt, subr_die, depth);
11851 current_function_has_inlines = 1;
11853 else
11854 /* We may get here if we're the outer block of function A that was
11855 inlined into function B that was inlined into function C. When
11856 generating debugging info for C, dwarf2out_abstract_function(B)
11857 would mark all inlined blocks as abstract, including this one.
11858 So, we wouldn't (and shouldn't) expect labels to be generated
11859 for this one. Instead, just emit debugging info for
11860 declarations within the block. This is particularly important
11861 in the case of initializers of arguments passed from B to us:
11862 if they're statement expressions containing declarations, we
11863 wouldn't generate dies for their abstract variables, and then,
11864 when generating dies for the real variables, we'd die (pun
11865 intended :-) */
11866 gen_lexical_block_die (stmt, context_die, depth);
11869 /* Generate a DIE for a field in a record, or structure. */
11871 static void
11872 gen_field_die (tree decl, dw_die_ref context_die)
11874 dw_die_ref decl_die;
11876 if (TREE_TYPE (decl) == error_mark_node)
11877 return;
11879 decl_die = new_die (DW_TAG_member, context_die, decl);
11880 add_name_and_src_coords_attributes (decl_die, decl);
11881 add_type_attribute (decl_die, member_declared_type (decl),
11882 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
11883 context_die);
11885 if (DECL_BIT_FIELD_TYPE (decl))
11887 add_byte_size_attribute (decl_die, decl);
11888 add_bit_size_attribute (decl_die, decl);
11889 add_bit_offset_attribute (decl_die, decl);
11892 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
11893 add_data_member_location_attribute (decl_die, decl);
11895 if (DECL_ARTIFICIAL (decl))
11896 add_AT_flag (decl_die, DW_AT_artificial, 1);
11898 if (TREE_PROTECTED (decl))
11899 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
11900 else if (TREE_PRIVATE (decl))
11901 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
11903 /* Equate decl number to die, so that we can look up this decl later on. */
11904 equate_decl_number_to_die (decl, decl_die);
11907 #if 0
11908 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11909 Use modified_type_die instead.
11910 We keep this code here just in case these types of DIEs may be needed to
11911 represent certain things in other languages (e.g. Pascal) someday. */
11913 static void
11914 gen_pointer_type_die (tree type, dw_die_ref context_die)
11916 dw_die_ref ptr_die
11917 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
11919 equate_type_number_to_die (type, ptr_die);
11920 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11921 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11924 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
11925 Use modified_type_die instead.
11926 We keep this code here just in case these types of DIEs may be needed to
11927 represent certain things in other languages (e.g. Pascal) someday. */
11929 static void
11930 gen_reference_type_die (tree type, dw_die_ref context_die)
11932 dw_die_ref ref_die
11933 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
11935 equate_type_number_to_die (type, ref_die);
11936 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
11937 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
11939 #endif
11941 /* Generate a DIE for a pointer to a member type. */
11943 static void
11944 gen_ptr_to_mbr_type_die (tree type, dw_die_ref context_die)
11946 dw_die_ref ptr_die
11947 = new_die (DW_TAG_ptr_to_member_type,
11948 scope_die_for (type, context_die), type);
11950 equate_type_number_to_die (type, ptr_die);
11951 add_AT_die_ref (ptr_die, DW_AT_containing_type,
11952 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
11953 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
11956 /* Generate the DIE for the compilation unit. */
11958 static dw_die_ref
11959 gen_compile_unit_die (const char *filename)
11961 dw_die_ref die;
11962 char producer[250];
11963 const char *language_string = lang_hooks.name;
11964 int language;
11966 die = new_die (DW_TAG_compile_unit, NULL, NULL);
11968 if (filename)
11970 add_name_attribute (die, filename);
11971 /* Don't add cwd for <built-in>. */
11972 if (filename[0] != DIR_SEPARATOR && filename[0] != '<')
11973 add_comp_dir_attribute (die);
11976 sprintf (producer, "%s %s", language_string, version_string);
11978 #ifdef MIPS_DEBUGGING_INFO
11979 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
11980 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
11981 not appear in the producer string, the debugger reaches the conclusion
11982 that the object file is stripped and has no debugging information.
11983 To get the MIPS/SGI debugger to believe that there is debugging
11984 information in the object file, we add a -g to the producer string. */
11985 if (debug_info_level > DINFO_LEVEL_TERSE)
11986 strcat (producer, " -g");
11987 #endif
11989 add_AT_string (die, DW_AT_producer, producer);
11991 if (strcmp (language_string, "GNU C++") == 0)
11992 language = DW_LANG_C_plus_plus;
11993 else if (strcmp (language_string, "GNU Ada") == 0)
11994 language = DW_LANG_Ada95;
11995 else if (strcmp (language_string, "GNU F77") == 0)
11996 language = DW_LANG_Fortran77;
11997 else if (strcmp (language_string, "GNU F95") == 0)
11998 language = DW_LANG_Fortran95;
11999 else if (strcmp (language_string, "GNU Pascal") == 0)
12000 language = DW_LANG_Pascal83;
12001 else if (strcmp (language_string, "GNU Java") == 0)
12002 language = DW_LANG_Java;
12003 else
12004 language = DW_LANG_C89;
12006 add_AT_unsigned (die, DW_AT_language, language);
12007 return die;
12010 /* Generate a DIE for a string type. */
12012 static void
12013 gen_string_type_die (tree type, dw_die_ref context_die)
12015 dw_die_ref type_die
12016 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
12018 equate_type_number_to_die (type, type_die);
12020 /* ??? Fudge the string length attribute for now.
12021 TODO: add string length info. */
12022 #if 0
12023 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
12024 bound_representation (upper_bound, 0, 'u');
12025 #endif
12028 /* Generate the DIE for a base class. */
12030 static void
12031 gen_inheritance_die (tree binfo, tree access, dw_die_ref context_die)
12033 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
12035 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
12036 add_data_member_location_attribute (die, binfo);
12038 if (BINFO_VIRTUAL_P (binfo))
12039 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
12041 if (access == access_public_node)
12042 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
12043 else if (access == access_protected_node)
12044 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
12047 /* Generate a DIE for a class member. */
12049 static void
12050 gen_member_die (tree type, dw_die_ref context_die)
12052 tree member;
12053 tree binfo = TYPE_BINFO (type);
12054 dw_die_ref child;
12056 /* If this is not an incomplete type, output descriptions of each of its
12057 members. Note that as we output the DIEs necessary to represent the
12058 members of this record or union type, we will also be trying to output
12059 DIEs to represent the *types* of those members. However the `type'
12060 function (above) will specifically avoid generating type DIEs for member
12061 types *within* the list of member DIEs for this (containing) type except
12062 for those types (of members) which are explicitly marked as also being
12063 members of this (containing) type themselves. The g++ front- end can
12064 force any given type to be treated as a member of some other (containing)
12065 type by setting the TYPE_CONTEXT of the given (member) type to point to
12066 the TREE node representing the appropriate (containing) type. */
12068 /* First output info about the base classes. */
12069 if (binfo)
12071 VEC(tree,gc) *accesses = BINFO_BASE_ACCESSES (binfo);
12072 int i;
12073 tree base;
12075 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base); i++)
12076 gen_inheritance_die (base,
12077 (accesses ? VEC_index (tree, accesses, i)
12078 : access_public_node), context_die);
12081 /* Now output info about the data members and type members. */
12082 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
12084 /* If we thought we were generating minimal debug info for TYPE
12085 and then changed our minds, some of the member declarations
12086 may have already been defined. Don't define them again, but
12087 do put them in the right order. */
12089 child = lookup_decl_die (member);
12090 if (child)
12091 splice_child_die (context_die, child);
12092 else
12093 gen_decl_die (member, context_die);
12096 /* Now output info about the function members (if any). */
12097 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
12099 /* Don't include clones in the member list. */
12100 if (DECL_ABSTRACT_ORIGIN (member))
12101 continue;
12103 child = lookup_decl_die (member);
12104 if (child)
12105 splice_child_die (context_die, child);
12106 else
12107 gen_decl_die (member, context_die);
12111 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
12112 is set, we pretend that the type was never defined, so we only get the
12113 member DIEs needed by later specification DIEs. */
12115 static void
12116 gen_struct_or_union_type_die (tree type, dw_die_ref context_die)
12118 dw_die_ref type_die = lookup_type_die (type);
12119 dw_die_ref scope_die = 0;
12120 int nested = 0;
12121 int complete = (TYPE_SIZE (type)
12122 && (! TYPE_STUB_DECL (type)
12123 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
12124 int ns_decl = (context_die && context_die->die_tag == DW_TAG_namespace);
12126 if (type_die && ! complete)
12127 return;
12129 if (TYPE_CONTEXT (type) != NULL_TREE
12130 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12131 || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL))
12132 nested = 1;
12134 scope_die = scope_die_for (type, context_die);
12136 if (! type_die || (nested && scope_die == comp_unit_die))
12137 /* First occurrence of type or toplevel definition of nested class. */
12139 dw_die_ref old_die = type_die;
12141 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
12142 ? DW_TAG_structure_type : DW_TAG_union_type,
12143 scope_die, type);
12144 equate_type_number_to_die (type, type_die);
12145 if (old_die)
12146 add_AT_specification (type_die, old_die);
12147 else
12148 add_name_attribute (type_die, type_tag (type));
12150 else
12151 remove_AT (type_die, DW_AT_declaration);
12153 /* If this type has been completed, then give it a byte_size attribute and
12154 then give a list of members. */
12155 if (complete && !ns_decl)
12157 /* Prevent infinite recursion in cases where the type of some member of
12158 this type is expressed in terms of this type itself. */
12159 TREE_ASM_WRITTEN (type) = 1;
12160 add_byte_size_attribute (type_die, type);
12161 if (TYPE_STUB_DECL (type) != NULL_TREE)
12162 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
12164 /* If the first reference to this type was as the return type of an
12165 inline function, then it may not have a parent. Fix this now. */
12166 if (type_die->die_parent == NULL)
12167 add_child_die (scope_die, type_die);
12169 push_decl_scope (type);
12170 gen_member_die (type, type_die);
12171 pop_decl_scope ();
12173 /* GNU extension: Record what type our vtable lives in. */
12174 if (TYPE_VFIELD (type))
12176 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
12178 gen_type_die (vtype, context_die);
12179 add_AT_die_ref (type_die, DW_AT_containing_type,
12180 lookup_type_die (vtype));
12183 else
12185 add_AT_flag (type_die, DW_AT_declaration, 1);
12187 /* We don't need to do this for function-local types. */
12188 if (TYPE_STUB_DECL (type)
12189 && ! decl_function_context (TYPE_STUB_DECL (type)))
12190 VEC_safe_push (tree, gc, incomplete_types, type);
12194 /* Generate a DIE for a subroutine _type_. */
12196 static void
12197 gen_subroutine_type_die (tree type, dw_die_ref context_die)
12199 tree return_type = TREE_TYPE (type);
12200 dw_die_ref subr_die
12201 = new_die (DW_TAG_subroutine_type,
12202 scope_die_for (type, context_die), type);
12204 equate_type_number_to_die (type, subr_die);
12205 add_prototyped_attribute (subr_die, type);
12206 add_type_attribute (subr_die, return_type, 0, 0, context_die);
12207 gen_formal_types_die (type, subr_die);
12210 /* Generate a DIE for a type definition. */
12212 static void
12213 gen_typedef_die (tree decl, dw_die_ref context_die)
12215 dw_die_ref type_die;
12216 tree origin;
12218 if (TREE_ASM_WRITTEN (decl))
12219 return;
12221 TREE_ASM_WRITTEN (decl) = 1;
12222 type_die = new_die (DW_TAG_typedef, context_die, decl);
12223 origin = decl_ultimate_origin (decl);
12224 if (origin != NULL)
12225 add_abstract_origin_attribute (type_die, origin);
12226 else
12228 tree type;
12230 add_name_and_src_coords_attributes (type_die, decl);
12231 if (DECL_ORIGINAL_TYPE (decl))
12233 type = DECL_ORIGINAL_TYPE (decl);
12235 gcc_assert (type != TREE_TYPE (decl));
12236 equate_type_number_to_die (TREE_TYPE (decl), type_die);
12238 else
12239 type = TREE_TYPE (decl);
12241 add_type_attribute (type_die, type, TREE_READONLY (decl),
12242 TREE_THIS_VOLATILE (decl), context_die);
12245 if (DECL_ABSTRACT (decl))
12246 equate_decl_number_to_die (decl, type_die);
12249 /* Generate a type description DIE. */
12251 static void
12252 gen_type_die (tree type, dw_die_ref context_die)
12254 int need_pop;
12256 if (type == NULL_TREE || type == error_mark_node)
12257 return;
12259 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
12260 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
12262 if (TREE_ASM_WRITTEN (type))
12263 return;
12265 /* Prevent broken recursion; we can't hand off to the same type. */
12266 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) != type);
12268 TREE_ASM_WRITTEN (type) = 1;
12269 gen_decl_die (TYPE_NAME (type), context_die);
12270 return;
12273 /* We are going to output a DIE to represent the unqualified version
12274 of this type (i.e. without any const or volatile qualifiers) so
12275 get the main variant (i.e. the unqualified version) of this type
12276 now. (Vectors are special because the debugging info is in the
12277 cloned type itself). */
12278 if (TREE_CODE (type) != VECTOR_TYPE)
12279 type = type_main_variant (type);
12281 if (TREE_ASM_WRITTEN (type))
12282 return;
12284 switch (TREE_CODE (type))
12286 case ERROR_MARK:
12287 break;
12289 case POINTER_TYPE:
12290 case REFERENCE_TYPE:
12291 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
12292 ensures that the gen_type_die recursion will terminate even if the
12293 type is recursive. Recursive types are possible in Ada. */
12294 /* ??? We could perhaps do this for all types before the switch
12295 statement. */
12296 TREE_ASM_WRITTEN (type) = 1;
12298 /* For these types, all that is required is that we output a DIE (or a
12299 set of DIEs) to represent the "basis" type. */
12300 gen_type_die (TREE_TYPE (type), context_die);
12301 break;
12303 case OFFSET_TYPE:
12304 /* This code is used for C++ pointer-to-data-member types.
12305 Output a description of the relevant class type. */
12306 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
12308 /* Output a description of the type of the object pointed to. */
12309 gen_type_die (TREE_TYPE (type), context_die);
12311 /* Now output a DIE to represent this pointer-to-data-member type
12312 itself. */
12313 gen_ptr_to_mbr_type_die (type, context_die);
12314 break;
12316 case FUNCTION_TYPE:
12317 /* Force out return type (in case it wasn't forced out already). */
12318 gen_type_die (TREE_TYPE (type), context_die);
12319 gen_subroutine_type_die (type, context_die);
12320 break;
12322 case METHOD_TYPE:
12323 /* Force out return type (in case it wasn't forced out already). */
12324 gen_type_die (TREE_TYPE (type), context_die);
12325 gen_subroutine_type_die (type, context_die);
12326 break;
12328 case ARRAY_TYPE:
12329 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
12331 gen_type_die (TREE_TYPE (type), context_die);
12332 gen_string_type_die (type, context_die);
12334 else
12335 gen_array_type_die (type, context_die);
12336 break;
12338 case VECTOR_TYPE:
12339 gen_array_type_die (type, context_die);
12340 break;
12342 case ENUMERAL_TYPE:
12343 case RECORD_TYPE:
12344 case UNION_TYPE:
12345 case QUAL_UNION_TYPE:
12346 /* If this is a nested type whose containing class hasn't been written
12347 out yet, writing it out will cover this one, too. This does not apply
12348 to instantiations of member class templates; they need to be added to
12349 the containing class as they are generated. FIXME: This hurts the
12350 idea of combining type decls from multiple TUs, since we can't predict
12351 what set of template instantiations we'll get. */
12352 if (TYPE_CONTEXT (type)
12353 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
12354 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
12356 gen_type_die (TYPE_CONTEXT (type), context_die);
12358 if (TREE_ASM_WRITTEN (type))
12359 return;
12361 /* If that failed, attach ourselves to the stub. */
12362 push_decl_scope (TYPE_CONTEXT (type));
12363 context_die = lookup_type_die (TYPE_CONTEXT (type));
12364 need_pop = 1;
12366 else
12368 declare_in_namespace (type, context_die);
12369 need_pop = 0;
12372 if (TREE_CODE (type) == ENUMERAL_TYPE)
12373 gen_enumeration_type_die (type, context_die);
12374 else
12375 gen_struct_or_union_type_die (type, context_die);
12377 if (need_pop)
12378 pop_decl_scope ();
12380 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
12381 it up if it is ever completed. gen_*_type_die will set it for us
12382 when appropriate. */
12383 return;
12385 case VOID_TYPE:
12386 case INTEGER_TYPE:
12387 case REAL_TYPE:
12388 case COMPLEX_TYPE:
12389 case BOOLEAN_TYPE:
12390 case CHAR_TYPE:
12391 /* No DIEs needed for fundamental types. */
12392 break;
12394 case LANG_TYPE:
12395 /* No Dwarf representation currently defined. */
12396 break;
12398 default:
12399 gcc_unreachable ();
12402 TREE_ASM_WRITTEN (type) = 1;
12405 /* Generate a DIE for a tagged type instantiation. */
12407 static void
12408 gen_tagged_type_instantiation_die (tree type, dw_die_ref context_die)
12410 if (type == NULL_TREE || type == error_mark_node)
12411 return;
12413 /* We are going to output a DIE to represent the unqualified version of
12414 this type (i.e. without any const or volatile qualifiers) so make sure
12415 that we have the main variant (i.e. the unqualified version) of this
12416 type now. */
12417 gcc_assert (type == type_main_variant (type));
12419 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
12420 an instance of an unresolved type. */
12422 switch (TREE_CODE (type))
12424 case ERROR_MARK:
12425 break;
12427 case ENUMERAL_TYPE:
12428 gen_inlined_enumeration_type_die (type, context_die);
12429 break;
12431 case RECORD_TYPE:
12432 gen_inlined_structure_type_die (type, context_die);
12433 break;
12435 case UNION_TYPE:
12436 case QUAL_UNION_TYPE:
12437 gen_inlined_union_type_die (type, context_die);
12438 break;
12440 default:
12441 gcc_unreachable ();
12445 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
12446 things which are local to the given block. */
12448 static void
12449 gen_block_die (tree stmt, dw_die_ref context_die, int depth)
12451 int must_output_die = 0;
12452 tree origin;
12453 tree decl;
12454 enum tree_code origin_code;
12456 /* Ignore blocks that are NULL. */
12457 if (stmt == NULL_TREE)
12458 return;
12460 /* If the block is one fragment of a non-contiguous block, do not
12461 process the variables, since they will have been done by the
12462 origin block. Do process subblocks. */
12463 if (BLOCK_FRAGMENT_ORIGIN (stmt))
12465 tree sub;
12467 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
12468 gen_block_die (sub, context_die, depth + 1);
12470 return;
12473 /* Determine the "ultimate origin" of this block. This block may be an
12474 inlined instance of an inlined instance of inline function, so we have
12475 to trace all of the way back through the origin chain to find out what
12476 sort of node actually served as the original seed for the creation of
12477 the current block. */
12478 origin = block_ultimate_origin (stmt);
12479 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
12481 /* Determine if we need to output any Dwarf DIEs at all to represent this
12482 block. */
12483 if (origin_code == FUNCTION_DECL)
12484 /* The outer scopes for inlinings *must* always be represented. We
12485 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
12486 must_output_die = 1;
12487 else
12489 /* In the case where the current block represents an inlining of the
12490 "body block" of an inline function, we must *NOT* output any DIE for
12491 this block because we have already output a DIE to represent the whole
12492 inlined function scope and the "body block" of any function doesn't
12493 really represent a different scope according to ANSI C rules. So we
12494 check here to make sure that this block does not represent a "body
12495 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
12496 if (! is_body_block (origin ? origin : stmt))
12498 /* Determine if this block directly contains any "significant"
12499 local declarations which we will need to output DIEs for. */
12500 if (debug_info_level > DINFO_LEVEL_TERSE)
12501 /* We are not in terse mode so *any* local declaration counts
12502 as being a "significant" one. */
12503 must_output_die = (BLOCK_VARS (stmt) != NULL
12504 && (TREE_USED (stmt)
12505 || TREE_ASM_WRITTEN (stmt)
12506 || BLOCK_ABSTRACT (stmt)));
12507 else
12508 /* We are in terse mode, so only local (nested) function
12509 definitions count as "significant" local declarations. */
12510 for (decl = BLOCK_VARS (stmt);
12511 decl != NULL; decl = TREE_CHAIN (decl))
12512 if (TREE_CODE (decl) == FUNCTION_DECL
12513 && DECL_INITIAL (decl))
12515 must_output_die = 1;
12516 break;
12521 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
12522 DIE for any block which contains no significant local declarations at
12523 all. Rather, in such cases we just call `decls_for_scope' so that any
12524 needed Dwarf info for any sub-blocks will get properly generated. Note
12525 that in terse mode, our definition of what constitutes a "significant"
12526 local declaration gets restricted to include only inlined function
12527 instances and local (nested) function definitions. */
12528 if (must_output_die)
12530 if (origin_code == FUNCTION_DECL)
12531 gen_inlined_subroutine_die (stmt, context_die, depth);
12532 else
12533 gen_lexical_block_die (stmt, context_die, depth);
12535 else
12536 decls_for_scope (stmt, context_die, depth);
12539 /* Generate all of the decls declared within a given scope and (recursively)
12540 all of its sub-blocks. */
12542 static void
12543 decls_for_scope (tree stmt, dw_die_ref context_die, int depth)
12545 tree decl;
12546 tree subblocks;
12548 /* Ignore NULL blocks. */
12549 if (stmt == NULL_TREE)
12550 return;
12552 if (TREE_USED (stmt))
12554 /* Output the DIEs to represent all of the data objects and typedefs
12555 declared directly within this block but not within any nested
12556 sub-blocks. Also, nested function and tag DIEs have been
12557 generated with a parent of NULL; fix that up now. */
12558 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
12560 dw_die_ref die;
12562 if (TREE_CODE (decl) == FUNCTION_DECL)
12563 die = lookup_decl_die (decl);
12564 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
12565 die = lookup_type_die (TREE_TYPE (decl));
12566 else
12567 die = NULL;
12569 if (die != NULL && die->die_parent == NULL)
12570 add_child_die (context_die, die);
12571 /* Do not produce debug information for static variables since
12572 these might be optimized out. We are called for these later
12573 in cgraph_varpool_analyze_pending_decls. */
12574 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
12576 else
12577 gen_decl_die (decl, context_die);
12581 /* If we're at -g1, we're not interested in subblocks. */
12582 if (debug_info_level <= DINFO_LEVEL_TERSE)
12583 return;
12585 /* Output the DIEs to represent all sub-blocks (and the items declared
12586 therein) of this block. */
12587 for (subblocks = BLOCK_SUBBLOCKS (stmt);
12588 subblocks != NULL;
12589 subblocks = BLOCK_CHAIN (subblocks))
12590 gen_block_die (subblocks, context_die, depth + 1);
12593 /* Is this a typedef we can avoid emitting? */
12595 static inline int
12596 is_redundant_typedef (tree decl)
12598 if (TYPE_DECL_IS_STUB (decl))
12599 return 1;
12601 if (DECL_ARTIFICIAL (decl)
12602 && DECL_CONTEXT (decl)
12603 && is_tagged_type (DECL_CONTEXT (decl))
12604 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
12605 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
12606 /* Also ignore the artificial member typedef for the class name. */
12607 return 1;
12609 return 0;
12612 /* Returns the DIE for decl. A DIE will always be returned. */
12614 static dw_die_ref
12615 force_decl_die (tree decl)
12617 dw_die_ref decl_die;
12618 unsigned saved_external_flag;
12619 tree save_fn = NULL_TREE;
12620 decl_die = lookup_decl_die (decl);
12621 if (!decl_die)
12623 dw_die_ref context_die;
12624 tree decl_context = DECL_CONTEXT (decl);
12625 if (decl_context)
12627 /* Find die that represents this context. */
12628 if (TYPE_P (decl_context))
12629 context_die = force_type_die (decl_context);
12630 else
12631 context_die = force_decl_die (decl_context);
12633 else
12634 context_die = comp_unit_die;
12636 switch (TREE_CODE (decl))
12638 case FUNCTION_DECL:
12639 /* Clear current_function_decl, so that gen_subprogram_die thinks
12640 that this is a declaration. At this point, we just want to force
12641 declaration die. */
12642 save_fn = current_function_decl;
12643 current_function_decl = NULL_TREE;
12644 gen_subprogram_die (decl, context_die);
12645 current_function_decl = save_fn;
12646 break;
12648 case VAR_DECL:
12649 /* Set external flag to force declaration die. Restore it after
12650 gen_decl_die() call. */
12651 saved_external_flag = DECL_EXTERNAL (decl);
12652 DECL_EXTERNAL (decl) = 1;
12653 gen_decl_die (decl, context_die);
12654 DECL_EXTERNAL (decl) = saved_external_flag;
12655 break;
12657 case NAMESPACE_DECL:
12658 dwarf2out_decl (decl);
12659 break;
12661 default:
12662 gcc_unreachable ();
12665 /* We should be able to find the DIE now. */
12666 if (!decl_die)
12667 decl_die = lookup_decl_die (decl);
12668 gcc_assert (decl_die);
12671 return decl_die;
12674 /* Returns the DIE for TYPE. A DIE is always returned. */
12676 static dw_die_ref
12677 force_type_die (tree type)
12679 dw_die_ref type_die;
12681 type_die = lookup_type_die (type);
12682 if (!type_die)
12684 dw_die_ref context_die;
12685 if (TYPE_CONTEXT (type))
12686 if (TYPE_P (TYPE_CONTEXT (type)))
12687 context_die = force_type_die (TYPE_CONTEXT (type));
12688 else
12689 context_die = force_decl_die (TYPE_CONTEXT (type));
12690 else
12691 context_die = comp_unit_die;
12693 gen_type_die (type, context_die);
12694 type_die = lookup_type_die (type);
12695 gcc_assert (type_die);
12697 return type_die;
12700 /* Force out any required namespaces to be able to output DECL,
12701 and return the new context_die for it, if it's changed. */
12703 static dw_die_ref
12704 setup_namespace_context (tree thing, dw_die_ref context_die)
12706 tree context = (DECL_P (thing)
12707 ? DECL_CONTEXT (thing) : TYPE_CONTEXT (thing));
12708 if (context && TREE_CODE (context) == NAMESPACE_DECL)
12709 /* Force out the namespace. */
12710 context_die = force_decl_die (context);
12712 return context_die;
12715 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
12716 type) within its namespace, if appropriate.
12718 For compatibility with older debuggers, namespace DIEs only contain
12719 declarations; all definitions are emitted at CU scope. */
12721 static void
12722 declare_in_namespace (tree thing, dw_die_ref context_die)
12724 dw_die_ref ns_context;
12726 if (debug_info_level <= DINFO_LEVEL_TERSE)
12727 return;
12729 /* If this decl is from an inlined function, then don't try to emit it in its
12730 namespace, as we will get confused. It would have already been emitted
12731 when the abstract instance of the inline function was emitted anyways. */
12732 if (DECL_P (thing) && DECL_ABSTRACT_ORIGIN (thing))
12733 return;
12735 ns_context = setup_namespace_context (thing, context_die);
12737 if (ns_context != context_die)
12739 if (DECL_P (thing))
12740 gen_decl_die (thing, ns_context);
12741 else
12742 gen_type_die (thing, ns_context);
12746 /* Generate a DIE for a namespace or namespace alias. */
12748 static void
12749 gen_namespace_die (tree decl)
12751 dw_die_ref context_die = setup_namespace_context (decl, comp_unit_die);
12753 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
12754 they are an alias of. */
12755 if (DECL_ABSTRACT_ORIGIN (decl) == NULL)
12757 /* Output a real namespace. */
12758 dw_die_ref namespace_die
12759 = new_die (DW_TAG_namespace, context_die, decl);
12760 add_name_and_src_coords_attributes (namespace_die, decl);
12761 equate_decl_number_to_die (decl, namespace_die);
12763 else
12765 /* Output a namespace alias. */
12767 /* Force out the namespace we are an alias of, if necessary. */
12768 dw_die_ref origin_die
12769 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl));
12771 /* Now create the namespace alias DIE. */
12772 dw_die_ref namespace_die
12773 = new_die (DW_TAG_imported_declaration, context_die, decl);
12774 add_name_and_src_coords_attributes (namespace_die, decl);
12775 add_AT_die_ref (namespace_die, DW_AT_import, origin_die);
12776 equate_decl_number_to_die (decl, namespace_die);
12780 /* Generate Dwarf debug information for a decl described by DECL. */
12782 static void
12783 gen_decl_die (tree decl, dw_die_ref context_die)
12785 tree origin;
12787 if (DECL_P (decl) && DECL_IGNORED_P (decl))
12788 return;
12790 switch (TREE_CODE (decl))
12792 case ERROR_MARK:
12793 break;
12795 case CONST_DECL:
12796 /* The individual enumerators of an enum type get output when we output
12797 the Dwarf representation of the relevant enum type itself. */
12798 break;
12800 case FUNCTION_DECL:
12801 /* Don't output any DIEs to represent mere function declarations,
12802 unless they are class members or explicit block externs. */
12803 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
12804 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
12805 break;
12807 #if 0
12808 /* FIXME */
12809 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
12810 on local redeclarations of global functions. That seems broken. */
12811 if (current_function_decl != decl)
12812 /* This is only a declaration. */;
12813 #endif
12815 /* If we're emitting a clone, emit info for the abstract instance. */
12816 if (DECL_ORIGIN (decl) != decl)
12817 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
12819 /* If we're emitting an out-of-line copy of an inline function,
12820 emit info for the abstract instance and set up to refer to it. */
12821 else if (cgraph_function_possibly_inlined_p (decl)
12822 && ! DECL_ABSTRACT (decl)
12823 && ! class_or_namespace_scope_p (context_die)
12824 /* dwarf2out_abstract_function won't emit a die if this is just
12825 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
12826 that case, because that works only if we have a die. */
12827 && DECL_INITIAL (decl) != NULL_TREE)
12829 dwarf2out_abstract_function (decl);
12830 set_decl_origin_self (decl);
12833 /* Otherwise we're emitting the primary DIE for this decl. */
12834 else if (debug_info_level > DINFO_LEVEL_TERSE)
12836 /* Before we describe the FUNCTION_DECL itself, make sure that we
12837 have described its return type. */
12838 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
12840 /* And its virtual context. */
12841 if (DECL_VINDEX (decl) != NULL_TREE)
12842 gen_type_die (DECL_CONTEXT (decl), context_die);
12844 /* And its containing type. */
12845 origin = decl_class_context (decl);
12846 if (origin != NULL_TREE)
12847 gen_type_die_for_member (origin, decl, context_die);
12849 /* And its containing namespace. */
12850 declare_in_namespace (decl, context_die);
12853 /* Now output a DIE to represent the function itself. */
12854 gen_subprogram_die (decl, context_die);
12855 break;
12857 case TYPE_DECL:
12858 /* If we are in terse mode, don't generate any DIEs to represent any
12859 actual typedefs. */
12860 if (debug_info_level <= DINFO_LEVEL_TERSE)
12861 break;
12863 /* In the special case of a TYPE_DECL node representing the declaration
12864 of some type tag, if the given TYPE_DECL is marked as having been
12865 instantiated from some other (original) TYPE_DECL node (e.g. one which
12866 was generated within the original definition of an inline function) we
12867 have to generate a special (abbreviated) DW_TAG_structure_type,
12868 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
12869 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
12871 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
12872 break;
12875 if (is_redundant_typedef (decl))
12876 gen_type_die (TREE_TYPE (decl), context_die);
12877 else
12878 /* Output a DIE to represent the typedef itself. */
12879 gen_typedef_die (decl, context_die);
12880 break;
12882 case LABEL_DECL:
12883 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12884 gen_label_die (decl, context_die);
12885 break;
12887 case VAR_DECL:
12888 case RESULT_DECL:
12889 /* If we are in terse mode, don't generate any DIEs to represent any
12890 variable declarations or definitions. */
12891 if (debug_info_level <= DINFO_LEVEL_TERSE)
12892 break;
12894 /* Output any DIEs that are needed to specify the type of this data
12895 object. */
12896 gen_type_die (TREE_TYPE (decl), context_die);
12898 /* And its containing type. */
12899 origin = decl_class_context (decl);
12900 if (origin != NULL_TREE)
12901 gen_type_die_for_member (origin, decl, context_die);
12903 /* And its containing namespace. */
12904 declare_in_namespace (decl, context_die);
12906 /* Now output the DIE to represent the data object itself. This gets
12907 complicated because of the possibility that the VAR_DECL really
12908 represents an inlined instance of a formal parameter for an inline
12909 function. */
12910 origin = decl_ultimate_origin (decl);
12911 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
12912 gen_formal_parameter_die (decl, context_die);
12913 else
12914 gen_variable_die (decl, context_die);
12915 break;
12917 case FIELD_DECL:
12918 /* Ignore the nameless fields that are used to skip bits but handle C++
12919 anonymous unions and structs. */
12920 if (DECL_NAME (decl) != NULL_TREE
12921 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
12922 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
12924 gen_type_die (member_declared_type (decl), context_die);
12925 gen_field_die (decl, context_die);
12927 break;
12929 case PARM_DECL:
12930 gen_type_die (TREE_TYPE (decl), context_die);
12931 gen_formal_parameter_die (decl, context_die);
12932 break;
12934 case NAMESPACE_DECL:
12935 gen_namespace_die (decl);
12936 break;
12938 default:
12939 /* Probably some frontend-internal decl. Assume we don't care. */
12940 gcc_assert ((int)TREE_CODE (decl) > NUM_TREE_CODES);
12941 break;
12945 /* Add Ada "use" clause information for SGI Workshop debugger. */
12947 void
12948 dwarf2out_add_library_unit_info (const char *filename, const char *context_list)
12950 unsigned int file_index;
12952 if (filename != NULL)
12954 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
12955 tree context_list_decl
12956 = build_decl (LABEL_DECL, get_identifier (context_list),
12957 void_type_node);
12959 TREE_PUBLIC (context_list_decl) = TRUE;
12960 add_name_attribute (unit_die, context_list);
12961 file_index = lookup_filename (filename);
12962 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
12963 add_pubname (context_list_decl, unit_die);
12967 /* Output debug information for global decl DECL. Called from toplev.c after
12968 compilation proper has finished. */
12970 static void
12971 dwarf2out_global_decl (tree decl)
12973 /* Output DWARF2 information for file-scope tentative data object
12974 declarations, file-scope (extern) function declarations (which had no
12975 corresponding body) and file-scope tagged type declarations and
12976 definitions which have not yet been forced out. */
12977 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
12978 dwarf2out_decl (decl);
12981 /* Output debug information for type decl DECL. Called from toplev.c
12982 and from language front ends (to record built-in types). */
12983 static void
12984 dwarf2out_type_decl (tree decl, int local)
12986 if (!local)
12987 dwarf2out_decl (decl);
12990 /* Output debug information for imported module or decl. */
12992 static void
12993 dwarf2out_imported_module_or_decl (tree decl, tree context)
12995 dw_die_ref imported_die, at_import_die;
12996 dw_die_ref scope_die;
12997 unsigned file_index;
12998 expanded_location xloc;
13000 if (debug_info_level <= DINFO_LEVEL_TERSE)
13001 return;
13003 gcc_assert (decl);
13005 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
13006 We need decl DIE for reference and scope die. First, get DIE for the decl
13007 itself. */
13009 /* Get the scope die for decl context. Use comp_unit_die for global module
13010 or decl. If die is not found for non globals, force new die. */
13011 if (!context)
13012 scope_die = comp_unit_die;
13013 else if (TYPE_P (context))
13014 scope_die = force_type_die (context);
13015 else
13016 scope_die = force_decl_die (context);
13018 /* For TYPE_DECL or CONST_DECL, lookup TREE_TYPE. */
13019 if (TREE_CODE (decl) == TYPE_DECL || TREE_CODE (decl) == CONST_DECL)
13020 at_import_die = force_type_die (TREE_TYPE (decl));
13021 else
13023 at_import_die = lookup_decl_die (decl);
13024 if (!at_import_die)
13026 /* If we're trying to avoid duplicate debug info, we may not have
13027 emitted the member decl for this field. Emit it now. */
13028 if (TREE_CODE (decl) == FIELD_DECL)
13030 tree type = DECL_CONTEXT (decl);
13031 dw_die_ref type_context_die;
13033 if (TYPE_CONTEXT (type))
13034 if (TYPE_P (TYPE_CONTEXT (type)))
13035 type_context_die = force_type_die (TYPE_CONTEXT (type));
13036 else
13037 type_context_die = force_decl_die (TYPE_CONTEXT (type));
13038 else
13039 type_context_die = comp_unit_die;
13040 gen_type_die_for_member (type, decl, type_context_die);
13042 at_import_die = force_decl_die (decl);
13046 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
13047 if (TREE_CODE (decl) == NAMESPACE_DECL)
13048 imported_die = new_die (DW_TAG_imported_module, scope_die, context);
13049 else
13050 imported_die = new_die (DW_TAG_imported_declaration, scope_die, context);
13052 xloc = expand_location (input_location);
13053 file_index = lookup_filename (xloc.file);
13054 add_AT_unsigned (imported_die, DW_AT_decl_file, file_index);
13055 add_AT_unsigned (imported_die, DW_AT_decl_line, xloc.line);
13056 add_AT_die_ref (imported_die, DW_AT_import, at_import_die);
13059 /* Write the debugging output for DECL. */
13061 void
13062 dwarf2out_decl (tree decl)
13064 dw_die_ref context_die = comp_unit_die;
13066 switch (TREE_CODE (decl))
13068 case ERROR_MARK:
13069 return;
13071 case FUNCTION_DECL:
13072 /* What we would really like to do here is to filter out all mere
13073 file-scope declarations of file-scope functions which are never
13074 referenced later within this translation unit (and keep all of ones
13075 that *are* referenced later on) but we aren't clairvoyant, so we have
13076 no idea which functions will be referenced in the future (i.e. later
13077 on within the current translation unit). So here we just ignore all
13078 file-scope function declarations which are not also definitions. If
13079 and when the debugger needs to know something about these functions,
13080 it will have to hunt around and find the DWARF information associated
13081 with the definition of the function.
13083 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
13084 nodes represent definitions and which ones represent mere
13085 declarations. We have to check DECL_INITIAL instead. That's because
13086 the C front-end supports some weird semantics for "extern inline"
13087 function definitions. These can get inlined within the current
13088 translation unit (and thus, we need to generate Dwarf info for their
13089 abstract instances so that the Dwarf info for the concrete inlined
13090 instances can have something to refer to) but the compiler never
13091 generates any out-of-lines instances of such things (despite the fact
13092 that they *are* definitions).
13094 The important point is that the C front-end marks these "extern
13095 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
13096 them anyway. Note that the C++ front-end also plays some similar games
13097 for inline function definitions appearing within include files which
13098 also contain `#pragma interface' pragmas. */
13099 if (DECL_INITIAL (decl) == NULL_TREE)
13100 return;
13102 /* If we're a nested function, initially use a parent of NULL; if we're
13103 a plain function, this will be fixed up in decls_for_scope. If
13104 we're a method, it will be ignored, since we already have a DIE. */
13105 if (decl_function_context (decl)
13106 /* But if we're in terse mode, we don't care about scope. */
13107 && debug_info_level > DINFO_LEVEL_TERSE)
13108 context_die = NULL;
13109 break;
13111 case VAR_DECL:
13112 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
13113 declaration and if the declaration was never even referenced from
13114 within this entire compilation unit. We suppress these DIEs in
13115 order to save space in the .debug section (by eliminating entries
13116 which are probably useless). Note that we must not suppress
13117 block-local extern declarations (whether used or not) because that
13118 would screw-up the debugger's name lookup mechanism and cause it to
13119 miss things which really ought to be in scope at a given point. */
13120 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
13121 return;
13123 /* For local statics lookup proper context die. */
13124 if (TREE_STATIC (decl) && decl_function_context (decl))
13125 context_die = lookup_decl_die (DECL_CONTEXT (decl));
13127 /* If we are in terse mode, don't generate any DIEs to represent any
13128 variable declarations or definitions. */
13129 if (debug_info_level <= DINFO_LEVEL_TERSE)
13130 return;
13131 break;
13133 case NAMESPACE_DECL:
13134 if (debug_info_level <= DINFO_LEVEL_TERSE)
13135 return;
13136 if (lookup_decl_die (decl) != NULL)
13137 return;
13138 break;
13140 case TYPE_DECL:
13141 /* Don't emit stubs for types unless they are needed by other DIEs. */
13142 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
13143 return;
13145 /* Don't bother trying to generate any DIEs to represent any of the
13146 normal built-in types for the language we are compiling. */
13147 if (DECL_IS_BUILTIN (decl))
13149 /* OK, we need to generate one for `bool' so GDB knows what type
13150 comparisons have. */
13151 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
13152 == DW_LANG_C_plus_plus)
13153 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
13154 && ! DECL_IGNORED_P (decl))
13155 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
13157 return;
13160 /* If we are in terse mode, don't generate any DIEs for types. */
13161 if (debug_info_level <= DINFO_LEVEL_TERSE)
13162 return;
13164 /* If we're a function-scope tag, initially use a parent of NULL;
13165 this will be fixed up in decls_for_scope. */
13166 if (decl_function_context (decl))
13167 context_die = NULL;
13169 break;
13171 default:
13172 return;
13175 gen_decl_die (decl, context_die);
13178 /* Output a marker (i.e. a label) for the beginning of the generated code for
13179 a lexical block. */
13181 static void
13182 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED,
13183 unsigned int blocknum)
13185 current_function_section (current_function_decl);
13186 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
13189 /* Output a marker (i.e. a label) for the end of the generated code for a
13190 lexical block. */
13192 static void
13193 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum)
13195 current_function_section (current_function_decl);
13196 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
13199 /* Returns nonzero if it is appropriate not to emit any debugging
13200 information for BLOCK, because it doesn't contain any instructions.
13202 Don't allow this for blocks with nested functions or local classes
13203 as we would end up with orphans, and in the presence of scheduling
13204 we may end up calling them anyway. */
13206 static bool
13207 dwarf2out_ignore_block (tree block)
13209 tree decl;
13211 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
13212 if (TREE_CODE (decl) == FUNCTION_DECL
13213 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
13214 return 0;
13216 return 1;
13219 /* Lookup FILE_NAME (in the list of filenames that we know about here in
13220 dwarf2out.c) and return its "index". The index of each (known) filename is
13221 just a unique number which is associated with only that one filename. We
13222 need such numbers for the sake of generating labels (in the .debug_sfnames
13223 section) and references to those files numbers (in the .debug_srcinfo
13224 and.debug_macinfo sections). If the filename given as an argument is not
13225 found in our current list, add it to the list and assign it the next
13226 available unique index number. In order to speed up searches, we remember
13227 the index of the filename was looked up last. This handles the majority of
13228 all searches. */
13230 static unsigned
13231 lookup_filename (const char *file_name)
13233 size_t i, n;
13234 char *save_file_name;
13236 /* Check to see if the file name that was searched on the previous
13237 call matches this file name. If so, return the index. */
13238 if (file_table_last_lookup_index != 0)
13240 const char *last
13241 = VARRAY_CHAR_PTR (file_table, file_table_last_lookup_index);
13242 if (strcmp (file_name, last) == 0)
13243 return file_table_last_lookup_index;
13246 /* Didn't match the previous lookup, search the table. */
13247 n = VARRAY_ACTIVE_SIZE (file_table);
13248 for (i = 1; i < n; i++)
13249 if (strcmp (file_name, VARRAY_CHAR_PTR (file_table, i)) == 0)
13251 file_table_last_lookup_index = i;
13252 return i;
13255 /* Add the new entry to the end of the filename table. */
13256 file_table_last_lookup_index = n;
13257 save_file_name = (char *) ggc_strdup (file_name);
13258 VARRAY_PUSH_CHAR_PTR (file_table, save_file_name);
13259 VARRAY_PUSH_UINT (file_table_emitted, 0);
13261 /* If the assembler is emitting the file table, and we aren't eliminating
13262 unused debug types, then we must emit .file here. If we are eliminating
13263 unused debug types, then this will be done by the maybe_emit_file call in
13264 prune_unused_types_walk_attribs. */
13266 if (DWARF2_ASM_LINE_DEBUG_INFO && ! flag_eliminate_unused_debug_types)
13267 maybe_emit_file (i);
13269 return i;
13272 /* If the assembler will construct the file table, then translate the compiler
13273 internal file table number into the assembler file table number, and emit
13274 a .file directive if we haven't already emitted one yet. The file table
13275 numbers are different because we prune debug info for unused variables and
13276 types, which may include filenames. */
13278 static int
13279 maybe_emit_file (int fileno)
13281 if (DWARF2_ASM_LINE_DEBUG_INFO && fileno > 0)
13283 if (!VARRAY_UINT (file_table_emitted, fileno))
13285 VARRAY_UINT (file_table_emitted, fileno) = ++emitcount;
13286 fprintf (asm_out_file, "\t.file %u ",
13287 VARRAY_UINT (file_table_emitted, fileno));
13288 output_quoted_string (asm_out_file,
13289 VARRAY_CHAR_PTR (file_table, fileno));
13290 fputc ('\n', asm_out_file);
13292 return VARRAY_UINT (file_table_emitted, fileno);
13294 else
13295 return fileno;
13298 /* Initialize the compiler internal file table. */
13300 static void
13301 init_file_table (void)
13303 /* Allocate the initial hunk of the file_table. */
13304 VARRAY_CHAR_PTR_INIT (file_table, 64, "file_table");
13305 VARRAY_UINT_INIT (file_table_emitted, 64, "file_table_emitted");
13307 /* Skip the first entry - file numbers begin at 1. */
13308 VARRAY_PUSH_CHAR_PTR (file_table, NULL);
13309 VARRAY_PUSH_UINT (file_table_emitted, 0);
13310 file_table_last_lookup_index = 0;
13313 /* Called by the final INSN scan whenever we see a var location. We
13314 use it to drop labels in the right places, and throw the location in
13315 our lookup table. */
13317 static void
13318 dwarf2out_var_location (rtx loc_note)
13320 char loclabel[MAX_ARTIFICIAL_LABEL_BYTES];
13321 struct var_loc_node *newloc;
13322 rtx prev_insn;
13323 static rtx last_insn;
13324 static const char *last_label;
13325 tree decl;
13327 if (!DECL_P (NOTE_VAR_LOCATION_DECL (loc_note)))
13328 return;
13329 prev_insn = PREV_INSN (loc_note);
13331 newloc = ggc_alloc_cleared (sizeof (struct var_loc_node));
13332 /* If the insn we processed last time is the previous insn
13333 and it is also a var location note, use the label we emitted
13334 last time. */
13335 if (last_insn != NULL_RTX
13336 && last_insn == prev_insn
13337 && NOTE_P (prev_insn)
13338 && NOTE_LINE_NUMBER (prev_insn) == NOTE_INSN_VAR_LOCATION)
13340 newloc->label = last_label;
13342 else
13344 ASM_GENERATE_INTERNAL_LABEL (loclabel, "LVL", loclabel_num);
13345 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LVL", loclabel_num);
13346 loclabel_num++;
13347 newloc->label = ggc_strdup (loclabel);
13349 newloc->var_loc_note = loc_note;
13350 newloc->next = NULL;
13352 if (cfun
13353 && (last_text_section == in_unlikely_executed_text
13354 || (last_text_section == in_named
13355 && last_text_section_name == cfun->unlikely_text_section_name)))
13356 newloc->section_label = cfun->cold_section_label;
13357 else
13358 newloc->section_label = text_section_label;
13360 last_insn = loc_note;
13361 last_label = newloc->label;
13362 decl = NOTE_VAR_LOCATION_DECL (loc_note);
13363 if (DECL_DEBUG_EXPR_IS_FROM (decl) && DECL_DEBUG_EXPR (decl)
13364 && DECL_P (DECL_DEBUG_EXPR (decl)))
13365 decl = DECL_DEBUG_EXPR (decl);
13366 add_var_loc_to_decl (decl, newloc);
13369 /* We need to reset the locations at the beginning of each
13370 function. We can't do this in the end_function hook, because the
13371 declarations that use the locations won't have been outputted when
13372 that hook is called. */
13374 static void
13375 dwarf2out_begin_function (tree unused ATTRIBUTE_UNUSED)
13377 htab_empty (decl_loc_table);
13380 /* Output a label to mark the beginning of a source code line entry
13381 and record information relating to this source line, in
13382 'line_info_table' for later output of the .debug_line section. */
13384 static void
13385 dwarf2out_source_line (unsigned int line, const char *filename)
13387 if (debug_info_level >= DINFO_LEVEL_NORMAL
13388 && line != 0)
13390 current_function_section (current_function_decl);
13392 /* If requested, emit something human-readable. */
13393 if (flag_debug_asm)
13394 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
13395 filename, line);
13397 if (DWARF2_ASM_LINE_DEBUG_INFO)
13399 unsigned file_num = lookup_filename (filename);
13401 file_num = maybe_emit_file (file_num);
13403 /* Emit the .loc directive understood by GNU as. */
13404 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
13406 /* Indicate that line number info exists. */
13407 line_info_table_in_use++;
13409 /* Indicate that multiple line number tables exist. */
13410 if (DECL_SECTION_NAME (current_function_decl))
13411 separate_line_info_table_in_use++;
13413 else if (DECL_SECTION_NAME (current_function_decl))
13415 dw_separate_line_info_ref line_info;
13416 targetm.asm_out.internal_label (asm_out_file, SEPARATE_LINE_CODE_LABEL,
13417 separate_line_info_table_in_use);
13419 /* Expand the line info table if necessary. */
13420 if (separate_line_info_table_in_use
13421 == separate_line_info_table_allocated)
13423 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13424 separate_line_info_table
13425 = ggc_realloc (separate_line_info_table,
13426 separate_line_info_table_allocated
13427 * sizeof (dw_separate_line_info_entry));
13428 memset (separate_line_info_table
13429 + separate_line_info_table_in_use,
13431 (LINE_INFO_TABLE_INCREMENT
13432 * sizeof (dw_separate_line_info_entry)));
13435 /* Add the new entry at the end of the line_info_table. */
13436 line_info
13437 = &separate_line_info_table[separate_line_info_table_in_use++];
13438 line_info->dw_file_num = lookup_filename (filename);
13439 line_info->dw_line_num = line;
13440 line_info->function = current_function_funcdef_no;
13442 else
13444 dw_line_info_ref line_info;
13446 targetm.asm_out.internal_label (asm_out_file, LINE_CODE_LABEL,
13447 line_info_table_in_use);
13449 /* Expand the line info table if necessary. */
13450 if (line_info_table_in_use == line_info_table_allocated)
13452 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
13453 line_info_table
13454 = ggc_realloc (line_info_table,
13455 (line_info_table_allocated
13456 * sizeof (dw_line_info_entry)));
13457 memset (line_info_table + line_info_table_in_use, 0,
13458 LINE_INFO_TABLE_INCREMENT * sizeof (dw_line_info_entry));
13461 /* Add the new entry at the end of the line_info_table. */
13462 line_info = &line_info_table[line_info_table_in_use++];
13463 line_info->dw_file_num = lookup_filename (filename);
13464 line_info->dw_line_num = line;
13469 /* Record the beginning of a new source file. */
13471 static void
13472 dwarf2out_start_source_file (unsigned int lineno, const char *filename)
13474 if (flag_eliminate_dwarf2_dups)
13476 /* Record the beginning of the file for break_out_includes. */
13477 dw_die_ref bincl_die;
13479 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
13480 add_AT_string (bincl_die, DW_AT_name, filename);
13483 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13485 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13486 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
13487 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
13488 lineno);
13489 maybe_emit_file (lookup_filename (filename));
13490 dw2_asm_output_data_uleb128 (lookup_filename (filename),
13491 "Filename we just started");
13495 /* Record the end of a source file. */
13497 static void
13498 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED)
13500 if (flag_eliminate_dwarf2_dups)
13501 /* Record the end of the file for break_out_includes. */
13502 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
13504 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13506 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13507 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
13511 /* Called from debug_define in toplev.c. The `buffer' parameter contains
13512 the tail part of the directive line, i.e. the part which is past the
13513 initial whitespace, #, whitespace, directive-name, whitespace part. */
13515 static void
13516 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED,
13517 const char *buffer ATTRIBUTE_UNUSED)
13519 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13521 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13522 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
13523 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13524 dw2_asm_output_nstring (buffer, -1, "The macro");
13528 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
13529 the tail part of the directive line, i.e. the part which is past the
13530 initial whitespace, #, whitespace, directive-name, whitespace part. */
13532 static void
13533 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED,
13534 const char *buffer ATTRIBUTE_UNUSED)
13536 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13538 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13539 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
13540 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
13541 dw2_asm_output_nstring (buffer, -1, "The macro");
13545 /* Set up for Dwarf output at the start of compilation. */
13547 static void
13548 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED)
13550 init_file_table ();
13552 /* Allocate the decl_die_table. */
13553 decl_die_table = htab_create_ggc (10, decl_die_table_hash,
13554 decl_die_table_eq, NULL);
13556 /* Allocate the decl_loc_table. */
13557 decl_loc_table = htab_create_ggc (10, decl_loc_table_hash,
13558 decl_loc_table_eq, NULL);
13560 /* Allocate the initial hunk of the decl_scope_table. */
13561 decl_scope_table = VEC_alloc (tree, gc, 256);
13563 /* Allocate the initial hunk of the abbrev_die_table. */
13564 abbrev_die_table = ggc_alloc_cleared (ABBREV_DIE_TABLE_INCREMENT
13565 * sizeof (dw_die_ref));
13566 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
13567 /* Zero-th entry is allocated, but unused. */
13568 abbrev_die_table_in_use = 1;
13570 /* Allocate the initial hunk of the line_info_table. */
13571 line_info_table = ggc_alloc_cleared (LINE_INFO_TABLE_INCREMENT
13572 * sizeof (dw_line_info_entry));
13573 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
13575 /* Zero-th entry is allocated, but unused. */
13576 line_info_table_in_use = 1;
13578 /* Generate the initial DIE for the .debug section. Note that the (string)
13579 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
13580 will (typically) be a relative pathname and that this pathname should be
13581 taken as being relative to the directory from which the compiler was
13582 invoked when the given (base) source file was compiled. We will fill
13583 in this value in dwarf2out_finish. */
13584 comp_unit_die = gen_compile_unit_die (NULL);
13586 incomplete_types = VEC_alloc (tree, gc, 64);
13588 used_rtx_array = VEC_alloc (rtx, gc, 32);
13590 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
13591 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
13592 DEBUG_ABBREV_SECTION_LABEL, 0);
13593 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
13594 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label,
13595 COLD_TEXT_SECTION_LABEL, 0);
13596 ASM_GENERATE_INTERNAL_LABEL (cold_end_label, COLD_END_LABEL, 0);
13598 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
13599 DEBUG_INFO_SECTION_LABEL, 0);
13600 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
13601 DEBUG_LINE_SECTION_LABEL, 0);
13602 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
13603 DEBUG_RANGES_SECTION_LABEL, 0);
13604 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
13605 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
13606 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
13607 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
13608 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13609 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
13611 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
13613 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
13614 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
13615 DEBUG_MACINFO_SECTION_LABEL, 0);
13616 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
13619 text_section ();
13620 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
13621 if (flag_reorder_blocks_and_partition)
13623 unlikely_text_section ();
13624 ASM_OUTPUT_LABEL (asm_out_file, cold_text_section_label);
13628 /* A helper function for dwarf2out_finish called through
13629 ht_forall. Emit one queued .debug_str string. */
13631 static int
13632 output_indirect_string (void **h, void *v ATTRIBUTE_UNUSED)
13634 struct indirect_string_node *node = (struct indirect_string_node *) *h;
13636 if (node->form == DW_FORM_strp)
13638 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
13639 ASM_OUTPUT_LABEL (asm_out_file, node->label);
13640 assemble_string (node->str, strlen (node->str) + 1);
13643 return 1;
13648 /* Clear the marks for a die and its children.
13649 Be cool if the mark isn't set. */
13651 static void
13652 prune_unmark_dies (dw_die_ref die)
13654 dw_die_ref c;
13655 die->die_mark = 0;
13656 for (c = die->die_child; c; c = c->die_sib)
13657 prune_unmark_dies (c);
13661 /* Given DIE that we're marking as used, find any other dies
13662 it references as attributes and mark them as used. */
13664 static void
13665 prune_unused_types_walk_attribs (dw_die_ref die)
13667 dw_attr_ref a;
13669 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
13671 if (a->dw_attr_val.val_class == dw_val_class_die_ref)
13673 /* A reference to another DIE.
13674 Make sure that it will get emitted. */
13675 prune_unused_types_mark (a->dw_attr_val.v.val_die_ref.die, 1);
13677 else if (a->dw_attr == DW_AT_decl_file || a->dw_attr == DW_AT_call_file)
13679 /* A reference to a file. Make sure the file name is emitted. */
13680 a->dw_attr_val.v.val_unsigned =
13681 maybe_emit_file (a->dw_attr_val.v.val_unsigned);
13687 /* Mark DIE as being used. If DOKIDS is true, then walk down
13688 to DIE's children. */
13690 static void
13691 prune_unused_types_mark (dw_die_ref die, int dokids)
13693 dw_die_ref c;
13695 if (die->die_mark == 0)
13697 /* We haven't done this node yet. Mark it as used. */
13698 die->die_mark = 1;
13700 /* We also have to mark its parents as used.
13701 (But we don't want to mark our parents' kids due to this.) */
13702 if (die->die_parent)
13703 prune_unused_types_mark (die->die_parent, 0);
13705 /* Mark any referenced nodes. */
13706 prune_unused_types_walk_attribs (die);
13708 /* If this node is a specification,
13709 also mark the definition, if it exists. */
13710 if (get_AT_flag (die, DW_AT_declaration) && die->die_definition)
13711 prune_unused_types_mark (die->die_definition, 1);
13714 if (dokids && die->die_mark != 2)
13716 /* We need to walk the children, but haven't done so yet.
13717 Remember that we've walked the kids. */
13718 die->die_mark = 2;
13720 /* Walk them. */
13721 for (c = die->die_child; c; c = c->die_sib)
13723 /* If this is an array type, we need to make sure our
13724 kids get marked, even if they're types. */
13725 if (die->die_tag == DW_TAG_array_type)
13726 prune_unused_types_mark (c, 1);
13727 else
13728 prune_unused_types_walk (c);
13734 /* Walk the tree DIE and mark types that we actually use. */
13736 static void
13737 prune_unused_types_walk (dw_die_ref die)
13739 dw_die_ref c;
13741 /* Don't do anything if this node is already marked. */
13742 if (die->die_mark)
13743 return;
13745 switch (die->die_tag) {
13746 case DW_TAG_const_type:
13747 case DW_TAG_packed_type:
13748 case DW_TAG_pointer_type:
13749 case DW_TAG_reference_type:
13750 case DW_TAG_volatile_type:
13751 case DW_TAG_typedef:
13752 case DW_TAG_array_type:
13753 case DW_TAG_structure_type:
13754 case DW_TAG_union_type:
13755 case DW_TAG_class_type:
13756 case DW_TAG_friend:
13757 case DW_TAG_variant_part:
13758 case DW_TAG_enumeration_type:
13759 case DW_TAG_subroutine_type:
13760 case DW_TAG_string_type:
13761 case DW_TAG_set_type:
13762 case DW_TAG_subrange_type:
13763 case DW_TAG_ptr_to_member_type:
13764 case DW_TAG_file_type:
13765 /* It's a type node --- don't mark it. */
13766 return;
13768 default:
13769 /* Mark everything else. */
13770 break;
13773 die->die_mark = 1;
13775 /* Now, mark any dies referenced from here. */
13776 prune_unused_types_walk_attribs (die);
13778 /* Mark children. */
13779 for (c = die->die_child; c; c = c->die_sib)
13780 prune_unused_types_walk (c);
13784 /* Remove from the tree DIE any dies that aren't marked. */
13786 static void
13787 prune_unused_types_prune (dw_die_ref die)
13789 dw_die_ref c, p, n;
13791 gcc_assert (die->die_mark);
13793 p = NULL;
13794 for (c = die->die_child; c; c = n)
13796 n = c->die_sib;
13797 if (c->die_mark)
13799 prune_unused_types_prune (c);
13800 p = c;
13802 else
13804 if (p)
13805 p->die_sib = n;
13806 else
13807 die->die_child = n;
13808 free_die (c);
13814 /* Remove dies representing declarations that we never use. */
13816 static void
13817 prune_unused_types (void)
13819 unsigned int i;
13820 limbo_die_node *node;
13822 /* Clear all the marks. */
13823 prune_unmark_dies (comp_unit_die);
13824 for (node = limbo_die_list; node; node = node->next)
13825 prune_unmark_dies (node->die);
13827 /* Set the mark on nodes that are actually used. */
13828 prune_unused_types_walk (comp_unit_die);
13829 for (node = limbo_die_list; node; node = node->next)
13830 prune_unused_types_walk (node->die);
13832 /* Also set the mark on nodes referenced from the
13833 pubname_table or arange_table. */
13834 for (i = 0; i < pubname_table_in_use; i++)
13835 prune_unused_types_mark (pubname_table[i].die, 1);
13836 for (i = 0; i < arange_table_in_use; i++)
13837 prune_unused_types_mark (arange_table[i], 1);
13839 /* Get rid of nodes that aren't marked. */
13840 prune_unused_types_prune (comp_unit_die);
13841 for (node = limbo_die_list; node; node = node->next)
13842 prune_unused_types_prune (node->die);
13844 /* Leave the marks clear. */
13845 prune_unmark_dies (comp_unit_die);
13846 for (node = limbo_die_list; node; node = node->next)
13847 prune_unmark_dies (node->die);
13850 /* Output stuff that dwarf requires at the end of every file,
13851 and generate the DWARF-2 debugging info. */
13853 static void
13854 dwarf2out_finish (const char *filename)
13856 limbo_die_node *node, *next_node;
13857 dw_die_ref die = 0;
13859 /* Add the name for the main input file now. We delayed this from
13860 dwarf2out_init to avoid complications with PCH. */
13861 add_name_attribute (comp_unit_die, filename);
13862 if (filename[0] != DIR_SEPARATOR)
13863 add_comp_dir_attribute (comp_unit_die);
13864 else if (get_AT (comp_unit_die, DW_AT_comp_dir) == NULL)
13866 size_t i;
13867 for (i = 1; i < VARRAY_ACTIVE_SIZE (file_table); i++)
13868 if (VARRAY_CHAR_PTR (file_table, i)[0] != DIR_SEPARATOR
13869 /* Don't add cwd for <built-in>. */
13870 && VARRAY_CHAR_PTR (file_table, i)[0] != '<')
13872 add_comp_dir_attribute (comp_unit_die);
13873 break;
13877 /* Traverse the limbo die list, and add parent/child links. The only
13878 dies without parents that should be here are concrete instances of
13879 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
13880 For concrete instances, we can get the parent die from the abstract
13881 instance. */
13882 for (node = limbo_die_list; node; node = next_node)
13884 next_node = node->next;
13885 die = node->die;
13887 if (die->die_parent == NULL)
13889 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
13891 if (origin)
13892 add_child_die (origin->die_parent, die);
13893 else if (die == comp_unit_die)
13895 else if (errorcount > 0 || sorrycount > 0)
13896 /* It's OK to be confused by errors in the input. */
13897 add_child_die (comp_unit_die, die);
13898 else
13900 /* In certain situations, the lexical block containing a
13901 nested function can be optimized away, which results
13902 in the nested function die being orphaned. Likewise
13903 with the return type of that nested function. Force
13904 this to be a child of the containing function.
13906 It may happen that even the containing function got fully
13907 inlined and optimized out. In that case we are lost and
13908 assign the empty child. This should not be big issue as
13909 the function is likely unreachable too. */
13910 tree context = NULL_TREE;
13912 gcc_assert (node->created_for);
13914 if (DECL_P (node->created_for))
13915 context = DECL_CONTEXT (node->created_for);
13916 else if (TYPE_P (node->created_for))
13917 context = TYPE_CONTEXT (node->created_for);
13919 gcc_assert (context && TREE_CODE (context) == FUNCTION_DECL);
13921 origin = lookup_decl_die (context);
13922 if (origin)
13923 add_child_die (origin, die);
13924 else
13925 add_child_die (comp_unit_die, die);
13930 limbo_die_list = NULL;
13932 /* Walk through the list of incomplete types again, trying once more to
13933 emit full debugging info for them. */
13934 retry_incomplete_types ();
13936 /* We need to reverse all the dies before break_out_includes, or
13937 we'll see the end of an include file before the beginning. */
13938 reverse_all_dies (comp_unit_die);
13940 if (flag_eliminate_unused_debug_types)
13941 prune_unused_types ();
13943 /* Generate separate CUs for each of the include files we've seen.
13944 They will go into limbo_die_list. */
13945 if (flag_eliminate_dwarf2_dups)
13946 break_out_includes (comp_unit_die);
13948 /* Traverse the DIE's and add add sibling attributes to those DIE's
13949 that have children. */
13950 add_sibling_attributes (comp_unit_die);
13951 for (node = limbo_die_list; node; node = node->next)
13952 add_sibling_attributes (node->die);
13954 /* Output a terminator label for the .text section. */
13955 text_section ();
13956 targetm.asm_out.internal_label (asm_out_file, TEXT_END_LABEL, 0);
13957 if (flag_reorder_blocks_and_partition)
13959 unlikely_text_section ();
13960 targetm.asm_out.internal_label (asm_out_file, COLD_END_LABEL, 0);
13963 /* Output the source line correspondence table. We must do this
13964 even if there is no line information. Otherwise, on an empty
13965 translation unit, we will generate a present, but empty,
13966 .debug_info section. IRIX 6.5 `nm' will then complain when
13967 examining the file. */
13968 if (! DWARF2_ASM_LINE_DEBUG_INFO)
13970 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
13971 output_line_info ();
13974 /* Output location list section if necessary. */
13975 if (have_location_lists)
13977 /* Output the location lists info. */
13978 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
13979 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
13980 DEBUG_LOC_SECTION_LABEL, 0);
13981 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
13982 output_location_lists (die);
13983 have_location_lists = 0;
13986 /* We can only use the low/high_pc attributes if all of the code was
13987 in .text. */
13988 if (separate_line_info_table_in_use == 0)
13990 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
13991 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
13994 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
13995 "base address". Use zero so that these addresses become absolute. */
13996 else if (have_location_lists || ranges_table_in_use)
13997 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
13999 if (debug_info_level >= DINFO_LEVEL_NORMAL)
14000 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
14001 debug_line_section_label);
14003 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14004 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
14006 /* Output all of the compilation units. We put the main one last so that
14007 the offsets are available to output_pubnames. */
14008 for (node = limbo_die_list; node; node = node->next)
14009 output_comp_unit (node->die, 0);
14011 output_comp_unit (comp_unit_die, 0);
14013 /* Output the abbreviation table. */
14014 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
14015 output_abbrev_section ();
14017 /* Output public names table if necessary. */
14018 if (pubname_table_in_use)
14020 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
14021 output_pubnames ();
14024 /* Output the address range information. We only put functions in the arange
14025 table, so don't write it out if we don't have any. */
14026 if (fde_table_in_use)
14028 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
14029 output_aranges ();
14032 /* Output ranges section if necessary. */
14033 if (ranges_table_in_use)
14035 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
14036 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
14037 output_ranges ();
14040 /* Have to end the macro section. */
14041 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
14043 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
14044 dw2_asm_output_data (1, 0, "End compilation unit");
14047 /* If we emitted any DW_FORM_strp form attribute, output the string
14048 table too. */
14049 if (debug_str_hash)
14050 htab_traverse (debug_str_hash, output_indirect_string, NULL);
14052 #else
14054 /* This should never be used, but its address is needed for comparisons. */
14055 const struct gcc_debug_hooks dwarf2_debug_hooks;
14057 #endif /* DWARF2_DEBUGGING_INFO */
14059 #include "gt-dwarf2out.h"