Daily bump.
[official-gcc.git] / gcc / dwarf2out.c
blobc691dd0875ae712e08c5fe44bc63712377f3c94d
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 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, 59 Temple Place - Suite 330, Boston, MA
23 02111-1307, 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 "tree.h"
40 #include "flags.h"
41 #include "rtl.h"
42 #include "hard-reg-set.h"
43 #include "regs.h"
44 #include "insn-config.h"
45 #include "reload.h"
46 #include "function.h"
47 #include "output.h"
48 #include "expr.h"
49 #include "libfuncs.h"
50 #include "except.h"
51 #include "dwarf2.h"
52 #include "dwarf2out.h"
53 #include "dwarf2asm.h"
54 #include "toplev.h"
55 #include "varray.h"
56 #include "ggc.h"
57 #include "md5.h"
58 #include "tm_p.h"
59 #include "diagnostic.h"
60 #include "debug.h"
61 #include "target.h"
62 #include "langhooks.h"
63 #include "hashtable.h"
65 #ifdef DWARF2_DEBUGGING_INFO
66 static void dwarf2out_source_line PARAMS ((unsigned int, const char *));
67 #endif
69 /* DWARF2 Abbreviation Glossary:
70 CFA = Canonical Frame Address
71 a fixed address on the stack which identifies a call frame.
72 We define it to be the value of SP just before the call insn.
73 The CFA register and offset, which may change during the course
74 of the function, are used to calculate its value at runtime.
75 CFI = Call Frame Instruction
76 an instruction for the DWARF2 abstract machine
77 CIE = Common Information Entry
78 information describing information common to one or more FDEs
79 DIE = Debugging Information Entry
80 FDE = Frame Description Entry
81 information describing the stack call frame, in particular,
82 how to restore registers
84 DW_CFA_... = DWARF2 CFA call frame instruction
85 DW_TAG_... = DWARF2 DIE tag */
87 /* Decide whether we want to emit frame unwind information for the current
88 translation unit. */
90 int
91 dwarf2out_do_frame ()
93 return (write_symbols == DWARF2_DEBUG
94 || write_symbols == VMS_AND_DWARF2_DEBUG
95 #ifdef DWARF2_FRAME_INFO
96 || DWARF2_FRAME_INFO
97 #endif
98 #ifdef DWARF2_UNWIND_INFO
99 || flag_unwind_tables
100 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
101 #endif
105 /* The number of the current function definition for which debugging
106 information is being generated. These numbers range from 1 up to the
107 maximum number of function definitions contained within the current
108 compilation unit. These numbers are used to create unique label id's
109 unique to each function definition. */
110 unsigned current_funcdef_number = 0;
112 /* The size of the target's pointer type. */
113 #ifndef PTR_SIZE
114 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
115 #endif
117 /* Default version of targetm.eh_frame_section. Note this must appear
118 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro
119 guards. */
121 void
122 default_eh_frame_section ()
124 #ifdef EH_FRAME_SECTION_NAME
125 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE);
126 #else
127 tree label = get_file_function_name ('F');
129 data_section ();
130 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
131 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
132 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
133 #endif
136 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
138 /* How to start an assembler comment. */
139 #ifndef ASM_COMMENT_START
140 #define ASM_COMMENT_START ";#"
141 #endif
143 typedef struct dw_cfi_struct *dw_cfi_ref;
144 typedef struct dw_fde_struct *dw_fde_ref;
145 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
147 /* Call frames are described using a sequence of Call Frame
148 Information instructions. The register number, offset
149 and address fields are provided as possible operands;
150 their use is selected by the opcode field. */
152 typedef union dw_cfi_oprnd_struct
154 unsigned long dw_cfi_reg_num;
155 long int dw_cfi_offset;
156 const char *dw_cfi_addr;
157 struct dw_loc_descr_struct *dw_cfi_loc;
159 dw_cfi_oprnd;
161 typedef struct dw_cfi_struct
163 dw_cfi_ref dw_cfi_next;
164 enum dwarf_call_frame_info dw_cfi_opc;
165 dw_cfi_oprnd dw_cfi_oprnd1;
166 dw_cfi_oprnd dw_cfi_oprnd2;
168 dw_cfi_node;
170 /* This is how we define the location of the CFA. We use to handle it
171 as REG + OFFSET all the time, but now it can be more complex.
172 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
173 Instead of passing around REG and OFFSET, we pass a copy
174 of this structure. */
175 typedef struct cfa_loc
177 unsigned long reg;
178 long offset;
179 long base_offset;
180 int indirect; /* 1 if CFA is accessed via a dereference. */
181 } dw_cfa_location;
183 /* All call frame descriptions (FDE's) in the GCC generated DWARF
184 refer to a single Common Information Entry (CIE), defined at
185 the beginning of the .debug_frame section. This use of a single
186 CIE obviates the need to keep track of multiple CIE's
187 in the DWARF generation routines below. */
189 typedef struct dw_fde_struct
191 const char *dw_fde_begin;
192 const char *dw_fde_current_label;
193 const char *dw_fde_end;
194 dw_cfi_ref dw_fde_cfi;
195 unsigned funcdef_number;
196 unsigned nothrow : 1;
197 unsigned uses_eh_lsda : 1;
199 dw_fde_node;
201 /* Maximum size (in bytes) of an artificially generated label. */
202 #define MAX_ARTIFICIAL_LABEL_BYTES 30
204 /* The size of addresses as they appear in the Dwarf 2 data.
205 Some architectures use word addresses to refer to code locations,
206 but Dwarf 2 info always uses byte addresses. On such machines,
207 Dwarf 2 addresses need to be larger than the architecture's
208 pointers. */
209 #ifndef DWARF2_ADDR_SIZE
210 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
211 #endif
213 /* The size in bytes of a DWARF field indicating an offset or length
214 relative to a debug info section, specified to be 4 bytes in the
215 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
216 as PTR_SIZE. */
218 #ifndef DWARF_OFFSET_SIZE
219 #define DWARF_OFFSET_SIZE 4
220 #endif
222 #define DWARF_VERSION 2
224 /* Round SIZE up to the nearest BOUNDARY. */
225 #define DWARF_ROUND(SIZE,BOUNDARY) \
226 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
228 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
229 #ifndef DWARF_CIE_DATA_ALIGNMENT
230 #ifdef STACK_GROWS_DOWNWARD
231 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
232 #else
233 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
234 #endif
235 #endif
237 /* A pointer to the base of a table that contains frame description
238 information for each routine. */
239 static dw_fde_ref fde_table;
241 /* Number of elements currently allocated for fde_table. */
242 static unsigned fde_table_allocated;
244 /* Number of elements in fde_table currently in use. */
245 static unsigned fde_table_in_use;
247 /* Size (in elements) of increments by which we may expand the
248 fde_table. */
249 #define FDE_TABLE_INCREMENT 256
251 /* A list of call frame insns for the CIE. */
252 static dw_cfi_ref cie_cfi_head;
254 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
255 attribute that accelerates the lookup of the FDE associated
256 with the subprogram. This variable holds the table index of the FDE
257 associated with the current function (body) definition. */
258 static unsigned current_funcdef_fde;
260 struct ht *debug_str_hash;
262 struct indirect_string_node
264 struct ht_identifier id;
265 unsigned int refcount;
266 unsigned int form;
267 char *label;
270 /* Forward declarations for functions defined in this file. */
272 static char *stripattributes PARAMS ((const char *));
273 static const char *dwarf_cfi_name PARAMS ((unsigned));
274 static dw_cfi_ref new_cfi PARAMS ((void));
275 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
276 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
277 static void lookup_cfa_1 PARAMS ((dw_cfi_ref,
278 dw_cfa_location *));
279 static void lookup_cfa PARAMS ((dw_cfa_location *));
280 static void reg_save PARAMS ((const char *, unsigned,
281 unsigned, long));
282 static void initial_return_save PARAMS ((rtx));
283 static long stack_adjust_offset PARAMS ((rtx));
284 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
285 static void output_call_frame_info PARAMS ((int));
286 static void dwarf2out_stack_adjust PARAMS ((rtx));
287 static void queue_reg_save PARAMS ((const char *, rtx, long));
288 static void flush_queued_reg_saves PARAMS ((void));
289 static bool clobbers_queued_reg_save PARAMS ((rtx));
290 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
292 /* Support for complex CFA locations. */
293 static void output_cfa_loc PARAMS ((dw_cfi_ref));
294 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
295 struct dw_loc_descr_struct *));
296 static struct dw_loc_descr_struct *build_cfa_loc
297 PARAMS ((dw_cfa_location *));
298 static void def_cfa_1 PARAMS ((const char *,
299 dw_cfa_location *));
301 /* How to start an assembler comment. */
302 #ifndef ASM_COMMENT_START
303 #define ASM_COMMENT_START ";#"
304 #endif
306 /* Data and reference forms for relocatable data. */
307 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
308 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
310 /* Pseudo-op for defining a new section. */
311 #ifndef SECTION_ASM_OP
312 #define SECTION_ASM_OP "\t.section\t"
313 #endif
315 #ifndef DEBUG_FRAME_SECTION
316 #define DEBUG_FRAME_SECTION ".debug_frame"
317 #endif
319 #ifndef FUNC_BEGIN_LABEL
320 #define FUNC_BEGIN_LABEL "LFB"
321 #endif
323 #ifndef FUNC_END_LABEL
324 #define FUNC_END_LABEL "LFE"
325 #endif
327 #define FRAME_BEGIN_LABEL "Lframe"
328 #define CIE_AFTER_SIZE_LABEL "LSCIE"
329 #define CIE_END_LABEL "LECIE"
330 #define CIE_LENGTH_LABEL "LLCIE"
331 #define FDE_LABEL "LSFDE"
332 #define FDE_AFTER_SIZE_LABEL "LASFDE"
333 #define FDE_END_LABEL "LEFDE"
334 #define FDE_LENGTH_LABEL "LLFDE"
335 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
336 #define LINE_NUMBER_END_LABEL "LELT"
337 #define LN_PROLOG_AS_LABEL "LASLTP"
338 #define LN_PROLOG_END_LABEL "LELTP"
339 #define DIE_LABEL_PREFIX "DW"
341 /* Definitions of defaults for various types of primitive assembly language
342 output operations. These may be overridden from within the tm.h file,
343 but typically, that is unnecessary. */
345 #ifdef SET_ASM_OP
346 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
347 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
348 do { \
349 fprintf (FILE, "%s", SET_ASM_OP); \
350 assemble_name (FILE, SY); \
351 fputc (',', FILE); \
352 assemble_name (FILE, HI); \
353 fputc ('-', FILE); \
354 assemble_name (FILE, LO); \
355 } while (0)
356 #endif
357 #endif
359 /* The DWARF 2 CFA column which tracks the return address. Normally this
360 is the column for PC, or the first column after all of the hard
361 registers. */
362 #ifndef DWARF_FRAME_RETURN_COLUMN
363 #ifdef PC_REGNUM
364 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
365 #else
366 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
367 #endif
368 #endif
370 /* The mapping from gcc register number to DWARF 2 CFA column number. By
371 default, we just provide columns for all registers. */
372 #ifndef DWARF_FRAME_REGNUM
373 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
374 #endif
376 /* The offset from the incoming value of %sp to the top of the stack frame
377 for the current function. */
378 #ifndef INCOMING_FRAME_SP_OFFSET
379 #define INCOMING_FRAME_SP_OFFSET 0
380 #endif
382 /* Hook used by __throw. */
385 expand_builtin_dwarf_fp_regnum ()
387 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
390 /* Return a pointer to a copy of the section string name S with all
391 attributes stripped off, and an asterisk prepended (for assemble_name). */
393 static inline char *
394 stripattributes (s)
395 const char *s;
397 char *stripped = xmalloc (strlen (s) + 2);
398 char *p = stripped;
400 *p++ = '*';
402 while (*s && *s != ',')
403 *p++ = *s++;
405 *p = '\0';
406 return stripped;
409 /* Generate code to initialize the register size table. */
411 void
412 expand_builtin_init_dwarf_reg_sizes (address)
413 tree address;
415 int i;
416 enum machine_mode mode = TYPE_MODE (char_type_node);
417 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
418 rtx mem = gen_rtx_MEM (BLKmode, addr);
420 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
421 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS)
423 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
424 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]);
426 if (offset < 0)
427 continue;
429 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
433 /* Convert a DWARF call frame info. operation to its string name */
435 static const char *
436 dwarf_cfi_name (cfi_opc)
437 unsigned cfi_opc;
439 switch (cfi_opc)
441 case DW_CFA_advance_loc:
442 return "DW_CFA_advance_loc";
443 case DW_CFA_offset:
444 return "DW_CFA_offset";
445 case DW_CFA_restore:
446 return "DW_CFA_restore";
447 case DW_CFA_nop:
448 return "DW_CFA_nop";
449 case DW_CFA_set_loc:
450 return "DW_CFA_set_loc";
451 case DW_CFA_advance_loc1:
452 return "DW_CFA_advance_loc1";
453 case DW_CFA_advance_loc2:
454 return "DW_CFA_advance_loc2";
455 case DW_CFA_advance_loc4:
456 return "DW_CFA_advance_loc4";
457 case DW_CFA_offset_extended:
458 return "DW_CFA_offset_extended";
459 case DW_CFA_restore_extended:
460 return "DW_CFA_restore_extended";
461 case DW_CFA_undefined:
462 return "DW_CFA_undefined";
463 case DW_CFA_same_value:
464 return "DW_CFA_same_value";
465 case DW_CFA_register:
466 return "DW_CFA_register";
467 case DW_CFA_remember_state:
468 return "DW_CFA_remember_state";
469 case DW_CFA_restore_state:
470 return "DW_CFA_restore_state";
471 case DW_CFA_def_cfa:
472 return "DW_CFA_def_cfa";
473 case DW_CFA_def_cfa_register:
474 return "DW_CFA_def_cfa_register";
475 case DW_CFA_def_cfa_offset:
476 return "DW_CFA_def_cfa_offset";
478 /* DWARF 3 */
479 case DW_CFA_def_cfa_expression:
480 return "DW_CFA_def_cfa_expression";
481 case DW_CFA_expression:
482 return "DW_CFA_expression";
483 case DW_CFA_offset_extended_sf:
484 return "DW_CFA_offset_extended_sf";
485 case DW_CFA_def_cfa_sf:
486 return "DW_CFA_def_cfa_sf";
487 case DW_CFA_def_cfa_offset_sf:
488 return "DW_CFA_def_cfa_offset_sf";
490 /* SGI/MIPS specific */
491 case DW_CFA_MIPS_advance_loc8:
492 return "DW_CFA_MIPS_advance_loc8";
494 /* GNU extensions */
495 case DW_CFA_GNU_window_save:
496 return "DW_CFA_GNU_window_save";
497 case DW_CFA_GNU_args_size:
498 return "DW_CFA_GNU_args_size";
499 case DW_CFA_GNU_negative_offset_extended:
500 return "DW_CFA_GNU_negative_offset_extended";
502 default:
503 return "DW_CFA_<unknown>";
507 /* Return a pointer to a newly allocated Call Frame Instruction. */
509 static inline dw_cfi_ref
510 new_cfi ()
512 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
514 cfi->dw_cfi_next = NULL;
515 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
516 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
518 return cfi;
521 /* Add a Call Frame Instruction to list of instructions. */
523 static inline void
524 add_cfi (list_head, cfi)
525 dw_cfi_ref *list_head;
526 dw_cfi_ref cfi;
528 dw_cfi_ref *p;
530 /* Find the end of the chain. */
531 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
534 *p = cfi;
537 /* Generate a new label for the CFI info to refer to. */
539 char *
540 dwarf2out_cfi_label ()
542 static char label[20];
543 static unsigned long label_num = 0;
545 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
546 ASM_OUTPUT_LABEL (asm_out_file, label);
547 return label;
550 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
551 or to the CIE if LABEL is NULL. */
553 static void
554 add_fde_cfi (label, cfi)
555 const char *label;
556 dw_cfi_ref cfi;
558 if (label)
560 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
562 if (*label == 0)
563 label = dwarf2out_cfi_label ();
565 if (fde->dw_fde_current_label == NULL
566 || strcmp (label, fde->dw_fde_current_label) != 0)
568 dw_cfi_ref xcfi;
570 fde->dw_fde_current_label = label = xstrdup (label);
572 /* Set the location counter to the new label. */
573 xcfi = new_cfi ();
574 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
575 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
576 add_cfi (&fde->dw_fde_cfi, xcfi);
579 add_cfi (&fde->dw_fde_cfi, cfi);
582 else
583 add_cfi (&cie_cfi_head, cfi);
586 /* Subroutine of lookup_cfa. */
588 static inline void
589 lookup_cfa_1 (cfi, loc)
590 dw_cfi_ref cfi;
591 dw_cfa_location *loc;
593 switch (cfi->dw_cfi_opc)
595 case DW_CFA_def_cfa_offset:
596 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
597 break;
598 case DW_CFA_def_cfa_register:
599 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
600 break;
601 case DW_CFA_def_cfa:
602 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
603 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
604 break;
605 case DW_CFA_def_cfa_expression:
606 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
607 break;
608 default:
609 break;
613 /* Find the previous value for the CFA. */
615 static void
616 lookup_cfa (loc)
617 dw_cfa_location *loc;
619 dw_cfi_ref cfi;
621 loc->reg = (unsigned long) -1;
622 loc->offset = 0;
623 loc->indirect = 0;
624 loc->base_offset = 0;
626 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
627 lookup_cfa_1 (cfi, loc);
629 if (fde_table_in_use)
631 dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
632 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
633 lookup_cfa_1 (cfi, loc);
637 /* The current rule for calculating the DWARF2 canonical frame address. */
638 static dw_cfa_location cfa;
640 /* The register used for saving registers to the stack, and its offset
641 from the CFA. */
642 static dw_cfa_location cfa_store;
644 /* The running total of the size of arguments pushed onto the stack. */
645 static long args_size;
647 /* The last args_size we actually output. */
648 static long old_args_size;
650 /* Entry point to update the canonical frame address (CFA).
651 LABEL is passed to add_fde_cfi. The value of CFA is now to be
652 calculated from REG+OFFSET. */
654 void
655 dwarf2out_def_cfa (label, reg, offset)
656 const char *label;
657 unsigned reg;
658 long offset;
660 dw_cfa_location loc;
661 loc.indirect = 0;
662 loc.base_offset = 0;
663 loc.reg = reg;
664 loc.offset = offset;
665 def_cfa_1 (label, &loc);
668 /* This routine does the actual work. The CFA is now calculated from
669 the dw_cfa_location structure. */
671 static void
672 def_cfa_1 (label, loc_p)
673 const char *label;
674 dw_cfa_location *loc_p;
676 dw_cfi_ref cfi;
677 dw_cfa_location old_cfa, loc;
679 cfa = *loc_p;
680 loc = *loc_p;
682 if (cfa_store.reg == loc.reg && loc.indirect == 0)
683 cfa_store.offset = loc.offset;
685 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
686 lookup_cfa (&old_cfa);
688 /* If nothing changed, no need to issue any call frame instructions. */
689 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset
690 && loc.indirect == old_cfa.indirect
691 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset))
692 return;
694 cfi = new_cfi ();
696 if (loc.reg == old_cfa.reg && !loc.indirect)
698 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
699 indicating the CFA register did not change but the offset
700 did. */
701 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
702 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
705 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
706 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
707 && !loc.indirect)
709 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
710 indicating the CFA register has changed to <register> but the
711 offset has not changed. */
712 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
713 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
715 #endif
717 else if (loc.indirect == 0)
719 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
720 indicating the CFA register has changed to <register> with
721 the specified offset. */
722 cfi->dw_cfi_opc = DW_CFA_def_cfa;
723 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
724 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
726 else
728 /* Construct a DW_CFA_def_cfa_expression instruction to
729 calculate the CFA using a full location expression since no
730 register-offset pair is available. */
731 struct dw_loc_descr_struct *loc_list;
733 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
734 loc_list = build_cfa_loc (&loc);
735 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
738 add_fde_cfi (label, cfi);
741 /* Add the CFI for saving a register. REG is the CFA column number.
742 LABEL is passed to add_fde_cfi.
743 If SREG is -1, the register is saved at OFFSET from the CFA;
744 otherwise it is saved in SREG. */
746 static void
747 reg_save (label, reg, sreg, offset)
748 const char *label;
749 unsigned reg;
750 unsigned sreg;
751 long offset;
753 dw_cfi_ref cfi = new_cfi ();
755 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
757 /* The following comparison is correct. -1 is used to indicate that
758 the value isn't a register number. */
759 if (sreg == (unsigned int) -1)
761 if (reg & ~0x3f)
762 /* The register number won't fit in 6 bits, so we have to use
763 the long form. */
764 cfi->dw_cfi_opc = DW_CFA_offset_extended;
765 else
766 cfi->dw_cfi_opc = DW_CFA_offset;
768 #ifdef ENABLE_CHECKING
770 /* If we get an offset that is not a multiple of
771 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
772 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
773 description. */
774 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
776 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
777 abort ();
779 #endif
780 offset /= DWARF_CIE_DATA_ALIGNMENT;
781 if (offset < 0)
782 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf;
784 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
786 else if (sreg == reg)
787 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
788 return;
789 else
791 cfi->dw_cfi_opc = DW_CFA_register;
792 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
795 add_fde_cfi (label, cfi);
798 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
799 This CFI tells the unwinder that it needs to restore the window registers
800 from the previous frame's window save area.
802 ??? Perhaps we should note in the CIE where windows are saved (instead of
803 assuming 0(cfa)) and what registers are in the window. */
805 void
806 dwarf2out_window_save (label)
807 const char *label;
809 dw_cfi_ref cfi = new_cfi ();
811 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
812 add_fde_cfi (label, cfi);
815 /* Add a CFI to update the running total of the size of arguments
816 pushed onto the stack. */
818 void
819 dwarf2out_args_size (label, size)
820 const char *label;
821 long size;
823 dw_cfi_ref cfi;
825 if (size == old_args_size)
826 return;
828 old_args_size = size;
830 cfi = new_cfi ();
831 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
832 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
833 add_fde_cfi (label, cfi);
836 /* Entry point for saving a register to the stack. REG is the GCC register
837 number. LABEL and OFFSET are passed to reg_save. */
839 void
840 dwarf2out_reg_save (label, reg, offset)
841 const char *label;
842 unsigned reg;
843 long offset;
845 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
848 /* Entry point for saving the return address in the stack.
849 LABEL and OFFSET are passed to reg_save. */
851 void
852 dwarf2out_return_save (label, offset)
853 const char *label;
854 long offset;
856 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
859 /* Entry point for saving the return address in a register.
860 LABEL and SREG are passed to reg_save. */
862 void
863 dwarf2out_return_reg (label, sreg)
864 const char *label;
865 unsigned sreg;
867 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
870 /* Record the initial position of the return address. RTL is
871 INCOMING_RETURN_ADDR_RTX. */
873 static void
874 initial_return_save (rtl)
875 rtx rtl;
877 unsigned int reg = (unsigned int) -1;
878 HOST_WIDE_INT offset = 0;
880 switch (GET_CODE (rtl))
882 case REG:
883 /* RA is in a register. */
884 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
885 break;
887 case MEM:
888 /* RA is on the stack. */
889 rtl = XEXP (rtl, 0);
890 switch (GET_CODE (rtl))
892 case REG:
893 if (REGNO (rtl) != STACK_POINTER_REGNUM)
894 abort ();
895 offset = 0;
896 break;
898 case PLUS:
899 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
900 abort ();
901 offset = INTVAL (XEXP (rtl, 1));
902 break;
904 case MINUS:
905 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
906 abort ();
907 offset = -INTVAL (XEXP (rtl, 1));
908 break;
910 default:
911 abort ();
914 break;
916 case PLUS:
917 /* The return address is at some offset from any value we can
918 actually load. For instance, on the SPARC it is in %i7+8. Just
919 ignore the offset for now; it doesn't matter for unwinding frames. */
920 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
921 abort ();
922 initial_return_save (XEXP (rtl, 0));
923 return;
925 default:
926 abort ();
929 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
932 /* Given a SET, calculate the amount of stack adjustment it
933 contains. */
935 static long
936 stack_adjust_offset (pattern)
937 rtx pattern;
939 rtx src = SET_SRC (pattern);
940 rtx dest = SET_DEST (pattern);
941 HOST_WIDE_INT offset = 0;
942 enum rtx_code code;
944 if (dest == stack_pointer_rtx)
946 /* (set (reg sp) (plus (reg sp) (const_int))) */
947 code = GET_CODE (src);
948 if (! (code == PLUS || code == MINUS)
949 || XEXP (src, 0) != stack_pointer_rtx
950 || GET_CODE (XEXP (src, 1)) != CONST_INT)
951 return 0;
953 offset = INTVAL (XEXP (src, 1));
955 else if (GET_CODE (dest) == MEM)
957 /* (set (mem (pre_dec (reg sp))) (foo)) */
958 src = XEXP (dest, 0);
959 code = GET_CODE (src);
961 if ((code != PRE_DEC && code != PRE_INC && code != PRE_MODIFY)
962 || XEXP (src, 0) != stack_pointer_rtx)
963 return 0;
965 if (code == PRE_MODIFY)
967 rtx val = XEXP (XEXP (src, 1), 1);
969 /* We handle only adjustments by constant amount. */
970 if (GET_CODE (XEXP (src, 1)) != PLUS ||
971 GET_CODE (val) != CONST_INT)
972 abort ();
974 offset = -INTVAL (val);
976 else
977 offset = GET_MODE_SIZE (GET_MODE (dest));
979 else
980 return 0;
982 if (code == PLUS || code == PRE_INC)
983 offset = -offset;
985 return offset;
988 /* Check INSN to see if it looks like a push or a stack adjustment, and
989 make a note of it if it does. EH uses this information to find out how
990 much extra space it needs to pop off the stack. */
992 static void
993 dwarf2out_stack_adjust (insn)
994 rtx insn;
996 HOST_WIDE_INT offset;
997 const char *label;
998 int i;
1000 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN)
1002 /* Extract the size of the args from the CALL rtx itself. */
1003 insn = PATTERN (insn);
1004 if (GET_CODE (insn) == PARALLEL)
1005 insn = XVECEXP (insn, 0, 0);
1006 if (GET_CODE (insn) == SET)
1007 insn = SET_SRC (insn);
1008 if (GET_CODE (insn) != CALL)
1009 abort ();
1011 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1012 return;
1015 /* If only calls can throw, and we have a frame pointer,
1016 save up adjustments until we see the CALL_INSN. */
1017 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM)
1018 return;
1020 if (GET_CODE (insn) == BARRIER)
1022 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1023 the compiler will have already emitted a stack adjustment, but
1024 doesn't bother for calls to noreturn functions. */
1025 #ifdef STACK_GROWS_DOWNWARD
1026 offset = -args_size;
1027 #else
1028 offset = args_size;
1029 #endif
1031 else if (GET_CODE (PATTERN (insn)) == SET)
1032 offset = stack_adjust_offset (PATTERN (insn));
1033 else if (GET_CODE (PATTERN (insn)) == PARALLEL
1034 || GET_CODE (PATTERN (insn)) == SEQUENCE)
1036 /* There may be stack adjustments inside compound insns. Search
1037 for them. */
1038 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1039 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET)
1040 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i));
1042 else
1043 return;
1045 if (offset == 0)
1046 return;
1048 if (cfa.reg == STACK_POINTER_REGNUM)
1049 cfa.offset += offset;
1051 #ifndef STACK_GROWS_DOWNWARD
1052 offset = -offset;
1053 #endif
1055 args_size += offset;
1056 if (args_size < 0)
1057 args_size = 0;
1059 label = dwarf2out_cfi_label ();
1060 def_cfa_1 (label, &cfa);
1061 dwarf2out_args_size (label, args_size);
1064 /* We delay emitting a register save until either (a) we reach the end
1065 of the prologue or (b) the register is clobbered. This clusters
1066 register saves so that there are fewer pc advances. */
1068 struct queued_reg_save
1070 struct queued_reg_save *next;
1071 rtx reg;
1072 long cfa_offset;
1075 static struct queued_reg_save *queued_reg_saves;
1076 static const char *last_reg_save_label;
1078 static void
1079 queue_reg_save (label, reg, offset)
1080 const char *label;
1081 rtx reg;
1082 long offset;
1084 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1086 q->next = queued_reg_saves;
1087 q->reg = reg;
1088 q->cfa_offset = offset;
1089 queued_reg_saves = q;
1091 last_reg_save_label = label;
1094 static void
1095 flush_queued_reg_saves ()
1097 struct queued_reg_save *q, *next;
1099 for (q = queued_reg_saves; q ; q = next)
1101 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1102 next = q->next;
1103 free (q);
1106 queued_reg_saves = NULL;
1107 last_reg_save_label = NULL;
1110 static bool
1111 clobbers_queued_reg_save (insn)
1112 rtx insn;
1114 struct queued_reg_save *q;
1116 for (q = queued_reg_saves; q ; q = q->next)
1117 if (modified_in_p (q->reg, insn))
1118 return true;
1120 return false;
1124 /* A temporary register holding an integral value used in adjusting SP
1125 or setting up the store_reg. The "offset" field holds the integer
1126 value, not an offset. */
1127 static dw_cfa_location cfa_temp;
1129 /* Record call frame debugging information for an expression EXPR,
1130 which either sets SP or FP (adjusting how we calculate the frame
1131 address) or saves a register to the stack. LABEL indicates the
1132 address of EXPR.
1134 This function encodes a state machine mapping rtxes to actions on
1135 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1136 users need not read the source code.
1138 The High-Level Picture
1140 Changes in the register we use to calculate the CFA: Currently we
1141 assume that if you copy the CFA register into another register, we
1142 should take the other one as the new CFA register; this seems to
1143 work pretty well. If it's wrong for some target, it's simple
1144 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1146 Changes in the register we use for saving registers to the stack:
1147 This is usually SP, but not always. Again, we deduce that if you
1148 copy SP into another register (and SP is not the CFA register),
1149 then the new register is the one we will be using for register
1150 saves. This also seems to work.
1152 Register saves: There's not much guesswork about this one; if
1153 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1154 register save, and the register used to calculate the destination
1155 had better be the one we think we're using for this purpose.
1157 Except: If the register being saved is the CFA register, and the
1158 offset is non-zero, we are saving the CFA, so we assume we have to
1159 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1160 the intent is to save the value of SP from the previous frame.
1162 Invariants / Summaries of Rules
1164 cfa current rule for calculating the CFA. It usually
1165 consists of a register and an offset.
1166 cfa_store register used by prologue code to save things to the stack
1167 cfa_store.offset is the offset from the value of
1168 cfa_store.reg to the actual CFA
1169 cfa_temp register holding an integral value. cfa_temp.offset
1170 stores the value, which will be used to adjust the
1171 stack pointer. cfa_temp is also used like cfa_store,
1172 to track stores to the stack via fp or a temp reg.
1174 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1175 with cfa.reg as the first operand changes the cfa.reg and its
1176 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1177 cfa_temp.offset.
1179 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1180 expression yielding a constant. This sets cfa_temp.reg
1181 and cfa_temp.offset.
1183 Rule 5: Create a new register cfa_store used to save items to the
1184 stack.
1186 Rules 10-14: Save a register to the stack. Define offset as the
1187 difference of the original location and cfa_store's
1188 location (or cfa_temp's location if cfa_temp is used).
1190 The Rules
1192 "{a,b}" indicates a choice of a xor b.
1193 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1195 Rule 1:
1196 (set <reg1> <reg2>:cfa.reg)
1197 effects: cfa.reg = <reg1>
1198 cfa.offset unchanged
1199 cfa_temp.reg = <reg1>
1200 cfa_temp.offset = cfa.offset
1202 Rule 2:
1203 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg
1204 {<const_int>,<reg>:cfa_temp.reg}))
1205 effects: cfa.reg = sp if fp used
1206 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1207 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1208 if cfa_store.reg==sp
1210 Rule 3:
1211 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1212 effects: cfa.reg = fp
1213 cfa_offset += +/- <const_int>
1215 Rule 4:
1216 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1217 constraints: <reg1> != fp
1218 <reg1> != sp
1219 effects: cfa.reg = <reg1>
1220 cfa_temp.reg = <reg1>
1221 cfa_temp.offset = cfa.offset
1223 Rule 5:
1224 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1225 constraints: <reg1> != fp
1226 <reg1> != sp
1227 effects: cfa_store.reg = <reg1>
1228 cfa_store.offset = cfa.offset - cfa_temp.offset
1230 Rule 6:
1231 (set <reg> <const_int>)
1232 effects: cfa_temp.reg = <reg>
1233 cfa_temp.offset = <const_int>
1235 Rule 7:
1236 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1237 effects: cfa_temp.reg = <reg1>
1238 cfa_temp.offset |= <const_int>
1240 Rule 8:
1241 (set <reg> (high <exp>))
1242 effects: none
1244 Rule 9:
1245 (set <reg> (lo_sum <exp> <const_int>))
1246 effects: cfa_temp.reg = <reg>
1247 cfa_temp.offset = <const_int>
1249 Rule 10:
1250 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1251 effects: cfa_store.offset -= <const_int>
1252 cfa.offset = cfa_store.offset if cfa.reg == sp
1253 cfa.reg = sp
1254 cfa.base_offset = -cfa_store.offset
1256 Rule 11:
1257 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1258 effects: cfa_store.offset += -/+ mode_size(mem)
1259 cfa.offset = cfa_store.offset if cfa.reg == sp
1260 cfa.reg = sp
1261 cfa.base_offset = -cfa_store.offset
1263 Rule 12:
1264 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>))
1266 <reg2>)
1267 effects: cfa.reg = <reg1>
1268 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1270 Rule 13:
1271 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1272 effects: cfa.reg = <reg1>
1273 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1275 Rule 14:
1276 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1277 effects: cfa.reg = <reg1>
1278 cfa.base_offset = -cfa_temp.offset
1279 cfa_temp.offset -= mode_size(mem) */
1281 static void
1282 dwarf2out_frame_debug_expr (expr, label)
1283 rtx expr;
1284 const char *label;
1286 rtx src, dest;
1287 HOST_WIDE_INT offset;
1289 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1290 the PARALLEL independently. The first element is always processed if
1291 it is a SET. This is for backward compatibility. Other elements
1292 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1293 flag is set in them. */
1294 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE)
1296 int par_index;
1297 int limit = XVECLEN (expr, 0);
1299 for (par_index = 0; par_index < limit; par_index++)
1300 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET
1301 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index))
1302 || par_index == 0))
1303 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label);
1305 return;
1308 if (GET_CODE (expr) != SET)
1309 abort ();
1311 src = SET_SRC (expr);
1312 dest = SET_DEST (expr);
1314 switch (GET_CODE (dest))
1316 case REG:
1317 /* Rule 1 */
1318 /* Update the CFA rule wrt SP or FP. Make sure src is
1319 relative to the current CFA register. */
1320 switch (GET_CODE (src))
1322 /* Setting FP from SP. */
1323 case REG:
1324 if (cfa.reg == (unsigned) REGNO (src))
1325 /* OK. */
1327 else
1328 abort ();
1330 /* We used to require that dest be either SP or FP, but the
1331 ARM copies SP to a temporary register, and from there to
1332 FP. So we just rely on the backends to only set
1333 RTX_FRAME_RELATED_P on appropriate insns. */
1334 cfa.reg = REGNO (dest);
1335 cfa_temp.reg = cfa.reg;
1336 cfa_temp.offset = cfa.offset;
1337 break;
1339 case PLUS:
1340 case MINUS:
1341 case LO_SUM:
1342 if (dest == stack_pointer_rtx)
1344 /* Rule 2 */
1345 /* Adjusting SP. */
1346 switch (GET_CODE (XEXP (src, 1)))
1348 case CONST_INT:
1349 offset = INTVAL (XEXP (src, 1));
1350 break;
1351 case REG:
1352 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1353 abort ();
1354 offset = cfa_temp.offset;
1355 break;
1356 default:
1357 abort ();
1360 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1362 /* Restoring SP from FP in the epilogue. */
1363 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1364 abort ();
1365 cfa.reg = STACK_POINTER_REGNUM;
1367 else if (GET_CODE (src) == LO_SUM)
1368 /* Assume we've set the source reg of the LO_SUM from sp. */
1370 else if (XEXP (src, 0) != stack_pointer_rtx)
1371 abort ();
1373 if (GET_CODE (src) != MINUS)
1374 offset = -offset;
1375 if (cfa.reg == STACK_POINTER_REGNUM)
1376 cfa.offset += offset;
1377 if (cfa_store.reg == STACK_POINTER_REGNUM)
1378 cfa_store.offset += offset;
1380 else if (dest == hard_frame_pointer_rtx)
1382 /* Rule 3 */
1383 /* Either setting the FP from an offset of the SP,
1384 or adjusting the FP */
1385 if (! frame_pointer_needed)
1386 abort ();
1388 if (GET_CODE (XEXP (src, 0)) == REG
1389 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1390 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1392 offset = INTVAL (XEXP (src, 1));
1393 if (GET_CODE (src) != MINUS)
1394 offset = -offset;
1395 cfa.offset += offset;
1396 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1398 else
1399 abort ();
1401 else
1403 if (GET_CODE (src) == MINUS)
1404 abort ();
1406 /* Rule 4 */
1407 if (GET_CODE (XEXP (src, 0)) == REG
1408 && REGNO (XEXP (src, 0)) == cfa.reg
1409 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1411 /* Setting a temporary CFA register that will be copied
1412 into the FP later on. */
1413 offset = - INTVAL (XEXP (src, 1));
1414 cfa.offset += offset;
1415 cfa.reg = REGNO (dest);
1416 /* Or used to save regs to the stack. */
1417 cfa_temp.reg = cfa.reg;
1418 cfa_temp.offset = cfa.offset;
1421 /* Rule 5 */
1422 else if (GET_CODE (XEXP (src, 0)) == REG
1423 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1424 && XEXP (src, 1) == stack_pointer_rtx)
1426 /* Setting a scratch register that we will use instead
1427 of SP for saving registers to the stack. */
1428 if (cfa.reg != STACK_POINTER_REGNUM)
1429 abort ();
1430 cfa_store.reg = REGNO (dest);
1431 cfa_store.offset = cfa.offset - cfa_temp.offset;
1434 /* Rule 9 */
1435 else if (GET_CODE (src) == LO_SUM
1436 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1438 cfa_temp.reg = REGNO (dest);
1439 cfa_temp.offset = INTVAL (XEXP (src, 1));
1441 else
1442 abort ();
1444 break;
1446 /* Rule 6 */
1447 case CONST_INT:
1448 cfa_temp.reg = REGNO (dest);
1449 cfa_temp.offset = INTVAL (src);
1450 break;
1452 /* Rule 7 */
1453 case IOR:
1454 if (GET_CODE (XEXP (src, 0)) != REG
1455 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1456 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1457 abort ();
1459 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1460 cfa_temp.reg = REGNO (dest);
1461 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1462 break;
1464 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1465 which will fill in all of the bits. */
1466 /* Rule 8 */
1467 case HIGH:
1468 break;
1470 default:
1471 abort ();
1474 def_cfa_1 (label, &cfa);
1475 break;
1477 case MEM:
1478 if (GET_CODE (src) != REG)
1479 abort ();
1481 /* Saving a register to the stack. Make sure dest is relative to the
1482 CFA register. */
1483 switch (GET_CODE (XEXP (dest, 0)))
1485 /* Rule 10 */
1486 /* With a push. */
1487 case PRE_MODIFY:
1488 /* We can't handle variable size modifications. */
1489 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1490 abort ();
1491 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1493 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1494 || cfa_store.reg != STACK_POINTER_REGNUM)
1495 abort ();
1497 cfa_store.offset += offset;
1498 if (cfa.reg == STACK_POINTER_REGNUM)
1499 cfa.offset = cfa_store.offset;
1501 offset = -cfa_store.offset;
1502 break;
1504 /* Rule 11 */
1505 case PRE_INC:
1506 case PRE_DEC:
1507 offset = GET_MODE_SIZE (GET_MODE (dest));
1508 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1509 offset = -offset;
1511 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1512 || cfa_store.reg != STACK_POINTER_REGNUM)
1513 abort ();
1515 cfa_store.offset += offset;
1516 if (cfa.reg == STACK_POINTER_REGNUM)
1517 cfa.offset = cfa_store.offset;
1519 offset = -cfa_store.offset;
1520 break;
1522 /* Rule 12 */
1523 /* With an offset. */
1524 case PLUS:
1525 case MINUS:
1526 case LO_SUM:
1527 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1528 abort ();
1529 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1530 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1531 offset = -offset;
1533 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1534 offset -= cfa_store.offset;
1535 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1536 offset -= cfa_temp.offset;
1537 else
1538 abort ();
1539 break;
1541 /* Rule 13 */
1542 /* Without an offset. */
1543 case REG:
1544 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1545 offset = -cfa_store.offset;
1546 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1547 offset = -cfa_temp.offset;
1548 else
1549 abort ();
1550 break;
1552 /* Rule 14 */
1553 case POST_INC:
1554 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1555 abort ();
1556 offset = -cfa_temp.offset;
1557 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1558 break;
1560 default:
1561 abort ();
1564 if (REGNO (src) != STACK_POINTER_REGNUM
1565 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1566 && (unsigned) REGNO (src) == cfa.reg)
1568 /* We're storing the current CFA reg into the stack. */
1570 if (cfa.offset == 0)
1572 /* If the source register is exactly the CFA, assume
1573 we're saving SP like any other register; this happens
1574 on the ARM. */
1575 def_cfa_1 (label, &cfa);
1576 queue_reg_save (label, stack_pointer_rtx, offset);
1577 break;
1579 else
1581 /* Otherwise, we'll need to look in the stack to
1582 calculate the CFA. */
1583 rtx x = XEXP (dest, 0);
1585 if (GET_CODE (x) != REG)
1586 x = XEXP (x, 0);
1587 if (GET_CODE (x) != REG)
1588 abort ();
1590 cfa.reg = REGNO (x);
1591 cfa.base_offset = offset;
1592 cfa.indirect = 1;
1593 def_cfa_1 (label, &cfa);
1594 break;
1598 def_cfa_1 (label, &cfa);
1599 queue_reg_save (label, src, offset);
1600 break;
1602 default:
1603 abort ();
1607 /* Record call frame debugging information for INSN, which either
1608 sets SP or FP (adjusting how we calculate the frame address) or saves a
1609 register to the stack. If INSN is NULL_RTX, initialize our state. */
1611 void
1612 dwarf2out_frame_debug (insn)
1613 rtx insn;
1615 const char *label;
1616 rtx src;
1618 if (insn == NULL_RTX)
1620 /* Flush any queued register saves. */
1621 flush_queued_reg_saves ();
1623 /* Set up state for generating call frame debug info. */
1624 lookup_cfa (&cfa);
1625 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1626 abort ();
1628 cfa.reg = STACK_POINTER_REGNUM;
1629 cfa_store = cfa;
1630 cfa_temp.reg = -1;
1631 cfa_temp.offset = 0;
1632 return;
1635 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1636 flush_queued_reg_saves ();
1638 if (! RTX_FRAME_RELATED_P (insn))
1640 if (!ACCUMULATE_OUTGOING_ARGS)
1641 dwarf2out_stack_adjust (insn);
1643 return;
1646 label = dwarf2out_cfi_label ();
1647 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1648 if (src)
1649 insn = XEXP (src, 0);
1650 else
1651 insn = PATTERN (insn);
1653 dwarf2out_frame_debug_expr (insn, label);
1656 /* Output a Call Frame Information opcode and its operand(s). */
1658 static void
1659 output_cfi (cfi, fde, for_eh)
1660 dw_cfi_ref cfi;
1661 dw_fde_ref fde;
1662 int for_eh;
1664 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1665 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1666 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1667 "DW_CFA_advance_loc 0x%lx",
1668 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1669 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1671 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1672 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1673 "DW_CFA_offset, column 0x%lx",
1674 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1675 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1677 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1678 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1679 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1680 "DW_CFA_restore, column 0x%lx",
1681 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1682 else
1684 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1685 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1687 switch (cfi->dw_cfi_opc)
1689 case DW_CFA_set_loc:
1690 if (for_eh)
1691 dw2_asm_output_encoded_addr_rtx (
1692 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1693 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1694 NULL);
1695 else
1696 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1697 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1698 break;
1700 case DW_CFA_advance_loc1:
1701 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1702 fde->dw_fde_current_label, NULL);
1703 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1704 break;
1706 case DW_CFA_advance_loc2:
1707 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1708 fde->dw_fde_current_label, NULL);
1709 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1710 break;
1712 case DW_CFA_advance_loc4:
1713 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1714 fde->dw_fde_current_label, NULL);
1715 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1716 break;
1718 case DW_CFA_MIPS_advance_loc8:
1719 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1720 fde->dw_fde_current_label, NULL);
1721 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1722 break;
1724 case DW_CFA_offset_extended:
1725 case DW_CFA_def_cfa:
1726 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1727 NULL);
1728 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1729 break;
1731 case DW_CFA_offset_extended_sf:
1732 case DW_CFA_def_cfa_sf:
1733 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1734 NULL);
1735 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1736 break;
1738 case DW_CFA_restore_extended:
1739 case DW_CFA_undefined:
1740 case DW_CFA_same_value:
1741 case DW_CFA_def_cfa_register:
1742 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1743 NULL);
1744 break;
1746 case DW_CFA_register:
1747 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num,
1748 NULL);
1749 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num,
1750 NULL);
1751 break;
1753 case DW_CFA_def_cfa_offset:
1754 case DW_CFA_GNU_args_size:
1755 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1756 break;
1758 case DW_CFA_def_cfa_offset_sf:
1759 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1760 break;
1762 case DW_CFA_GNU_window_save:
1763 break;
1765 case DW_CFA_def_cfa_expression:
1766 case DW_CFA_expression:
1767 output_cfa_loc (cfi);
1768 break;
1770 case DW_CFA_GNU_negative_offset_extended:
1771 /* Obsoleted by DW_CFA_offset_extended_sf. */
1772 abort ();
1774 default:
1775 break;
1780 /* Output the call frame information used to used to record information
1781 that relates to calculating the frame pointer, and records the
1782 location of saved registers. */
1784 static void
1785 output_call_frame_info (for_eh)
1786 int for_eh;
1788 unsigned int i;
1789 dw_fde_ref fde;
1790 dw_cfi_ref cfi;
1791 char l1[20], l2[20], section_start_label[20];
1792 int any_lsda_needed = 0;
1793 char augmentation[6];
1794 int augmentation_size;
1795 int fde_encoding = DW_EH_PE_absptr;
1796 int per_encoding = DW_EH_PE_absptr;
1797 int lsda_encoding = DW_EH_PE_absptr;
1799 /* If we don't have any functions we'll want to unwind out of, don't emit any
1800 EH unwind information. */
1801 if (for_eh)
1803 int any_eh_needed = flag_asynchronous_unwind_tables;
1805 for (i = 0; i < fde_table_in_use; i++)
1806 if (fde_table[i].uses_eh_lsda)
1807 any_eh_needed = any_lsda_needed = 1;
1808 else if (! fde_table[i].nothrow)
1809 any_eh_needed = 1;
1811 if (! any_eh_needed)
1812 return;
1815 /* We're going to be generating comments, so turn on app. */
1816 if (flag_debug_asm)
1817 app_enable ();
1819 if (for_eh)
1820 (*targetm.asm_out.eh_frame_section) ();
1821 else
1822 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG);
1824 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh);
1825 ASM_OUTPUT_LABEL (asm_out_file, section_start_label);
1827 /* Output the CIE. */
1828 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1829 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1830 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1831 "Length of Common Information Entry");
1832 ASM_OUTPUT_LABEL (asm_out_file, l1);
1834 /* Now that the CIE pointer is PC-relative for EH,
1835 use 0 to identify the CIE. */
1836 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1837 (for_eh ? 0 : DW_CIE_ID),
1838 "CIE Identifier Tag");
1840 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1842 augmentation[0] = 0;
1843 augmentation_size = 0;
1844 if (for_eh)
1846 char *p;
1848 /* Augmentation:
1849 z Indicates that a uleb128 is present to size the
1850 augmentation section.
1851 L Indicates the encoding (and thus presence) of
1852 an LSDA pointer in the FDE augmentation.
1853 R Indicates a non-default pointer encoding for
1854 FDE code pointers.
1855 P Indicates the presence of an encoding + language
1856 personality routine in the CIE augmentation. */
1858 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1859 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1860 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1862 p = augmentation + 1;
1863 if (eh_personality_libfunc)
1865 *p++ = 'P';
1866 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1868 if (any_lsda_needed)
1870 *p++ = 'L';
1871 augmentation_size += 1;
1873 if (fde_encoding != DW_EH_PE_absptr)
1875 *p++ = 'R';
1876 augmentation_size += 1;
1878 if (p > augmentation + 1)
1880 augmentation[0] = 'z';
1881 *p = '\0';
1884 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1885 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1887 int offset = ( 4 /* Length */
1888 + 4 /* CIE Id */
1889 + 1 /* CIE version */
1890 + strlen (augmentation) + 1 /* Augmentation */
1891 + size_of_uleb128 (1) /* Code alignment */
1892 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1893 + 1 /* RA column */
1894 + 1 /* Augmentation size */
1895 + 1 /* Personality encoding */ );
1896 int pad = -offset & (PTR_SIZE - 1);
1898 augmentation_size += pad;
1900 /* Augmentations should be small, so there's scarce need to
1901 iterate for a solution. Die if we exceed one uleb128 byte. */
1902 if (size_of_uleb128 (augmentation_size) != 1)
1903 abort ();
1907 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1908 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1909 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1910 "CIE Data Alignment Factor");
1911 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1913 if (augmentation[0])
1915 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1916 if (eh_personality_libfunc)
1918 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1919 eh_data_format_name (per_encoding));
1920 dw2_asm_output_encoded_addr_rtx (per_encoding,
1921 eh_personality_libfunc, NULL);
1924 if (any_lsda_needed)
1925 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1926 eh_data_format_name (lsda_encoding));
1928 if (fde_encoding != DW_EH_PE_absptr)
1929 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1930 eh_data_format_name (fde_encoding));
1933 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1934 output_cfi (cfi, NULL, for_eh);
1936 /* Pad the CIE out to an address sized boundary. */
1937 ASM_OUTPUT_ALIGN (asm_out_file,
1938 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1939 ASM_OUTPUT_LABEL (asm_out_file, l2);
1941 /* Loop through all of the FDE's. */
1942 for (i = 0; i < fde_table_in_use; i++)
1944 fde = &fde_table[i];
1946 /* Don't emit EH unwind info for leaf functions that don't need it. */
1947 if (!flag_asynchronous_unwind_tables && for_eh && fde->nothrow
1948 && ! fde->uses_eh_lsda)
1949 continue;
1951 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1952 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1953 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1954 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1955 "FDE Length");
1956 ASM_OUTPUT_LABEL (asm_out_file, l1);
1958 if (for_eh)
1959 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset");
1960 else
1961 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label,
1962 "FDE CIE offset");
1964 if (for_eh)
1966 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1967 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1968 "FDE initial location");
1969 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1970 fde->dw_fde_end, fde->dw_fde_begin,
1971 "FDE address range");
1973 else
1975 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1976 "FDE initial location");
1977 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1978 fde->dw_fde_end, fde->dw_fde_begin,
1979 "FDE address range");
1982 if (augmentation[0])
1984 if (any_lsda_needed)
1986 int size = size_of_encoded_value (lsda_encoding);
1988 if (lsda_encoding == DW_EH_PE_aligned)
1990 int offset = ( 4 /* Length */
1991 + 4 /* CIE offset */
1992 + 2 * size_of_encoded_value (fde_encoding)
1993 + 1 /* Augmentation size */ );
1994 int pad = -offset & (PTR_SIZE - 1);
1996 size += pad;
1997 if (size_of_uleb128 (size) != 1)
1998 abort ();
2001 dw2_asm_output_data_uleb128 (size, "Augmentation size");
2003 if (fde->uses_eh_lsda)
2005 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
2006 fde->funcdef_number);
2007 dw2_asm_output_encoded_addr_rtx (
2008 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
2009 "Language Specific Data Area");
2011 else
2013 if (lsda_encoding == DW_EH_PE_aligned)
2014 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
2015 dw2_asm_output_data
2016 (size_of_encoded_value (lsda_encoding), 0,
2017 "Language Specific Data Area (none)");
2020 else
2021 dw2_asm_output_data_uleb128 (0, "Augmentation size");
2024 /* Loop through the Call Frame Instructions associated with
2025 this FDE. */
2026 fde->dw_fde_current_label = fde->dw_fde_begin;
2027 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
2028 output_cfi (cfi, fde, for_eh);
2030 /* Pad the FDE out to an address sized boundary. */
2031 ASM_OUTPUT_ALIGN (asm_out_file,
2032 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
2033 ASM_OUTPUT_LABEL (asm_out_file, l2);
2036 #ifndef EH_FRAME_SECTION_NAME
2037 if (for_eh)
2038 dw2_asm_output_data (4, 0, "End of Table");
2039 #endif
2040 #ifdef MIPS_DEBUGGING_INFO
2041 /* Work around Irix 6 assembler bug whereby labels at the end of a section
2042 get a value of 0. Putting .align 0 after the label fixes it. */
2043 ASM_OUTPUT_ALIGN (asm_out_file, 0);
2044 #endif
2046 /* Turn off app to make assembly quicker. */
2047 if (flag_debug_asm)
2048 app_disable ();
2051 /* Output a marker (i.e. a label) for the beginning of a function, before
2052 the prologue. */
2054 void
2055 dwarf2out_begin_prologue (line, file)
2056 unsigned int line ATTRIBUTE_UNUSED;
2057 const char *file ATTRIBUTE_UNUSED;
2059 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2060 dw_fde_ref fde;
2062 current_function_func_begin_label = 0;
2064 #ifdef IA64_UNWIND_INFO
2065 /* ??? current_function_func_begin_label is also used by except.c
2066 for call-site information. We must emit this label if it might
2067 be used. */
2068 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2069 && ! dwarf2out_do_frame ())
2070 return;
2071 #else
2072 if (! dwarf2out_do_frame ())
2073 return;
2074 #endif
2076 current_funcdef_number++;
2077 function_section (current_function_decl);
2078 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2079 current_funcdef_number);
2080 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2081 current_funcdef_number);
2082 current_function_func_begin_label = get_identifier (label);
2084 #ifdef IA64_UNWIND_INFO
2085 /* We can elide the fde allocation if we're not emitting debug info. */
2086 if (! dwarf2out_do_frame ())
2087 return;
2088 #endif
2090 /* Expand the fde table if necessary. */
2091 if (fde_table_in_use == fde_table_allocated)
2093 fde_table_allocated += FDE_TABLE_INCREMENT;
2094 fde_table
2095 = (dw_fde_ref) xrealloc (fde_table,
2096 fde_table_allocated * sizeof (dw_fde_node));
2099 /* Record the FDE associated with this function. */
2100 current_funcdef_fde = fde_table_in_use;
2102 /* Add the new FDE at the end of the fde_table. */
2103 fde = &fde_table[fde_table_in_use++];
2104 fde->dw_fde_begin = xstrdup (label);
2105 fde->dw_fde_current_label = NULL;
2106 fde->dw_fde_end = NULL;
2107 fde->dw_fde_cfi = NULL;
2108 fde->funcdef_number = current_funcdef_number;
2109 fde->nothrow = current_function_nothrow;
2110 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2112 args_size = old_args_size = 0;
2114 /* We only want to output line number information for the genuine dwarf2
2115 prologue case, not the eh frame case. */
2116 #ifdef DWARF2_DEBUGGING_INFO
2117 if (file)
2118 dwarf2out_source_line (line, file);
2119 #endif
2122 /* Output a marker (i.e. a label) for the absolute end of the generated code
2123 for a function definition. This gets called *after* the epilogue code has
2124 been generated. */
2126 void
2127 dwarf2out_end_epilogue ()
2129 dw_fde_ref fde;
2130 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2132 /* Output a label to mark the endpoint of the code generated for this
2133 function. */
2134 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2135 ASM_OUTPUT_LABEL (asm_out_file, label);
2136 fde = &fde_table[fde_table_in_use - 1];
2137 fde->dw_fde_end = xstrdup (label);
2140 void
2141 dwarf2out_frame_init ()
2143 /* Allocate the initial hunk of the fde_table. */
2144 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2145 fde_table_allocated = FDE_TABLE_INCREMENT;
2146 fde_table_in_use = 0;
2148 /* Generate the CFA instructions common to all FDE's. Do it now for the
2149 sake of lookup_cfa. */
2151 #ifdef DWARF2_UNWIND_INFO
2152 /* On entry, the Canonical Frame Address is at SP. */
2153 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2154 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2155 #endif
2158 void
2159 dwarf2out_frame_finish ()
2161 /* Output call frame information. */
2162 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
2163 output_call_frame_info (0);
2165 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions))
2166 output_call_frame_info (1);
2169 /* And now, the subset of the debugging information support code necessary
2170 for emitting location expressions. */
2172 typedef struct dw_val_struct *dw_val_ref;
2173 typedef struct die_struct *dw_die_ref;
2174 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2175 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2177 /* Each DIE may have a series of attribute/value pairs. Values
2178 can take on several forms. The forms that are used in this
2179 implementation are listed below. */
2181 typedef enum
2183 dw_val_class_addr,
2184 dw_val_class_offset,
2185 dw_val_class_loc,
2186 dw_val_class_loc_list,
2187 dw_val_class_range_list,
2188 dw_val_class_const,
2189 dw_val_class_unsigned_const,
2190 dw_val_class_long_long,
2191 dw_val_class_float,
2192 dw_val_class_flag,
2193 dw_val_class_die_ref,
2194 dw_val_class_fde_ref,
2195 dw_val_class_lbl_id,
2196 dw_val_class_lbl_offset,
2197 dw_val_class_str
2199 dw_val_class;
2201 /* Describe a double word constant value. */
2202 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2204 typedef struct dw_long_long_struct
2206 unsigned long hi;
2207 unsigned long low;
2209 dw_long_long_const;
2211 /* Describe a floating point constant value. */
2213 typedef struct dw_fp_struct
2215 long *array;
2216 unsigned length;
2218 dw_float_const;
2220 /* The dw_val_node describes an attribute's value, as it is
2221 represented internally. */
2223 typedef struct dw_val_struct
2225 dw_val_class val_class;
2226 union
2228 rtx val_addr;
2229 long unsigned val_offset;
2230 dw_loc_list_ref val_loc_list;
2231 dw_loc_descr_ref val_loc;
2232 long int val_int;
2233 long unsigned val_unsigned;
2234 dw_long_long_const val_long_long;
2235 dw_float_const val_float;
2236 struct
2238 dw_die_ref die;
2239 int external;
2240 } val_die_ref;
2241 unsigned val_fde_index;
2242 struct indirect_string_node *val_str;
2243 char *val_lbl_id;
2244 unsigned char val_flag;
2248 dw_val_node;
2250 /* Locations in memory are described using a sequence of stack machine
2251 operations. */
2253 typedef struct dw_loc_descr_struct
2255 dw_loc_descr_ref dw_loc_next;
2256 enum dwarf_location_atom dw_loc_opc;
2257 dw_val_node dw_loc_oprnd1;
2258 dw_val_node dw_loc_oprnd2;
2259 int dw_loc_addr;
2261 dw_loc_descr_node;
2263 /* Location lists are ranges + location descriptions for that range,
2264 so you can track variables that are in different places over
2265 their entire life. */
2266 typedef struct dw_loc_list_struct
2268 dw_loc_list_ref dw_loc_next;
2269 const char *begin; /* Label for begin address of range */
2270 const char *end; /* Label for end address of range */
2271 char *ll_symbol; /* Label for beginning of location list.
2272 Only on head of list */
2273 const char *section; /* Section this loclist is relative to */
2274 dw_loc_descr_ref expr;
2275 } dw_loc_list_node;
2277 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2278 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2279 unsigned long,
2280 unsigned long));
2281 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2282 dw_loc_descr_ref));
2283 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2284 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2285 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2286 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2288 /* Convert a DWARF stack opcode into its string name. */
2290 static const char *
2291 dwarf_stack_op_name (op)
2292 unsigned op;
2294 switch (op)
2296 case DW_OP_addr:
2297 return "DW_OP_addr";
2298 case DW_OP_deref:
2299 return "DW_OP_deref";
2300 case DW_OP_const1u:
2301 return "DW_OP_const1u";
2302 case DW_OP_const1s:
2303 return "DW_OP_const1s";
2304 case DW_OP_const2u:
2305 return "DW_OP_const2u";
2306 case DW_OP_const2s:
2307 return "DW_OP_const2s";
2308 case DW_OP_const4u:
2309 return "DW_OP_const4u";
2310 case DW_OP_const4s:
2311 return "DW_OP_const4s";
2312 case DW_OP_const8u:
2313 return "DW_OP_const8u";
2314 case DW_OP_const8s:
2315 return "DW_OP_const8s";
2316 case DW_OP_constu:
2317 return "DW_OP_constu";
2318 case DW_OP_consts:
2319 return "DW_OP_consts";
2320 case DW_OP_dup:
2321 return "DW_OP_dup";
2322 case DW_OP_drop:
2323 return "DW_OP_drop";
2324 case DW_OP_over:
2325 return "DW_OP_over";
2326 case DW_OP_pick:
2327 return "DW_OP_pick";
2328 case DW_OP_swap:
2329 return "DW_OP_swap";
2330 case DW_OP_rot:
2331 return "DW_OP_rot";
2332 case DW_OP_xderef:
2333 return "DW_OP_xderef";
2334 case DW_OP_abs:
2335 return "DW_OP_abs";
2336 case DW_OP_and:
2337 return "DW_OP_and";
2338 case DW_OP_div:
2339 return "DW_OP_div";
2340 case DW_OP_minus:
2341 return "DW_OP_minus";
2342 case DW_OP_mod:
2343 return "DW_OP_mod";
2344 case DW_OP_mul:
2345 return "DW_OP_mul";
2346 case DW_OP_neg:
2347 return "DW_OP_neg";
2348 case DW_OP_not:
2349 return "DW_OP_not";
2350 case DW_OP_or:
2351 return "DW_OP_or";
2352 case DW_OP_plus:
2353 return "DW_OP_plus";
2354 case DW_OP_plus_uconst:
2355 return "DW_OP_plus_uconst";
2356 case DW_OP_shl:
2357 return "DW_OP_shl";
2358 case DW_OP_shr:
2359 return "DW_OP_shr";
2360 case DW_OP_shra:
2361 return "DW_OP_shra";
2362 case DW_OP_xor:
2363 return "DW_OP_xor";
2364 case DW_OP_bra:
2365 return "DW_OP_bra";
2366 case DW_OP_eq:
2367 return "DW_OP_eq";
2368 case DW_OP_ge:
2369 return "DW_OP_ge";
2370 case DW_OP_gt:
2371 return "DW_OP_gt";
2372 case DW_OP_le:
2373 return "DW_OP_le";
2374 case DW_OP_lt:
2375 return "DW_OP_lt";
2376 case DW_OP_ne:
2377 return "DW_OP_ne";
2378 case DW_OP_skip:
2379 return "DW_OP_skip";
2380 case DW_OP_lit0:
2381 return "DW_OP_lit0";
2382 case DW_OP_lit1:
2383 return "DW_OP_lit1";
2384 case DW_OP_lit2:
2385 return "DW_OP_lit2";
2386 case DW_OP_lit3:
2387 return "DW_OP_lit3";
2388 case DW_OP_lit4:
2389 return "DW_OP_lit4";
2390 case DW_OP_lit5:
2391 return "DW_OP_lit5";
2392 case DW_OP_lit6:
2393 return "DW_OP_lit6";
2394 case DW_OP_lit7:
2395 return "DW_OP_lit7";
2396 case DW_OP_lit8:
2397 return "DW_OP_lit8";
2398 case DW_OP_lit9:
2399 return "DW_OP_lit9";
2400 case DW_OP_lit10:
2401 return "DW_OP_lit10";
2402 case DW_OP_lit11:
2403 return "DW_OP_lit11";
2404 case DW_OP_lit12:
2405 return "DW_OP_lit12";
2406 case DW_OP_lit13:
2407 return "DW_OP_lit13";
2408 case DW_OP_lit14:
2409 return "DW_OP_lit14";
2410 case DW_OP_lit15:
2411 return "DW_OP_lit15";
2412 case DW_OP_lit16:
2413 return "DW_OP_lit16";
2414 case DW_OP_lit17:
2415 return "DW_OP_lit17";
2416 case DW_OP_lit18:
2417 return "DW_OP_lit18";
2418 case DW_OP_lit19:
2419 return "DW_OP_lit19";
2420 case DW_OP_lit20:
2421 return "DW_OP_lit20";
2422 case DW_OP_lit21:
2423 return "DW_OP_lit21";
2424 case DW_OP_lit22:
2425 return "DW_OP_lit22";
2426 case DW_OP_lit23:
2427 return "DW_OP_lit23";
2428 case DW_OP_lit24:
2429 return "DW_OP_lit24";
2430 case DW_OP_lit25:
2431 return "DW_OP_lit25";
2432 case DW_OP_lit26:
2433 return "DW_OP_lit26";
2434 case DW_OP_lit27:
2435 return "DW_OP_lit27";
2436 case DW_OP_lit28:
2437 return "DW_OP_lit28";
2438 case DW_OP_lit29:
2439 return "DW_OP_lit29";
2440 case DW_OP_lit30:
2441 return "DW_OP_lit30";
2442 case DW_OP_lit31:
2443 return "DW_OP_lit31";
2444 case DW_OP_reg0:
2445 return "DW_OP_reg0";
2446 case DW_OP_reg1:
2447 return "DW_OP_reg1";
2448 case DW_OP_reg2:
2449 return "DW_OP_reg2";
2450 case DW_OP_reg3:
2451 return "DW_OP_reg3";
2452 case DW_OP_reg4:
2453 return "DW_OP_reg4";
2454 case DW_OP_reg5:
2455 return "DW_OP_reg5";
2456 case DW_OP_reg6:
2457 return "DW_OP_reg6";
2458 case DW_OP_reg7:
2459 return "DW_OP_reg7";
2460 case DW_OP_reg8:
2461 return "DW_OP_reg8";
2462 case DW_OP_reg9:
2463 return "DW_OP_reg9";
2464 case DW_OP_reg10:
2465 return "DW_OP_reg10";
2466 case DW_OP_reg11:
2467 return "DW_OP_reg11";
2468 case DW_OP_reg12:
2469 return "DW_OP_reg12";
2470 case DW_OP_reg13:
2471 return "DW_OP_reg13";
2472 case DW_OP_reg14:
2473 return "DW_OP_reg14";
2474 case DW_OP_reg15:
2475 return "DW_OP_reg15";
2476 case DW_OP_reg16:
2477 return "DW_OP_reg16";
2478 case DW_OP_reg17:
2479 return "DW_OP_reg17";
2480 case DW_OP_reg18:
2481 return "DW_OP_reg18";
2482 case DW_OP_reg19:
2483 return "DW_OP_reg19";
2484 case DW_OP_reg20:
2485 return "DW_OP_reg20";
2486 case DW_OP_reg21:
2487 return "DW_OP_reg21";
2488 case DW_OP_reg22:
2489 return "DW_OP_reg22";
2490 case DW_OP_reg23:
2491 return "DW_OP_reg23";
2492 case DW_OP_reg24:
2493 return "DW_OP_reg24";
2494 case DW_OP_reg25:
2495 return "DW_OP_reg25";
2496 case DW_OP_reg26:
2497 return "DW_OP_reg26";
2498 case DW_OP_reg27:
2499 return "DW_OP_reg27";
2500 case DW_OP_reg28:
2501 return "DW_OP_reg28";
2502 case DW_OP_reg29:
2503 return "DW_OP_reg29";
2504 case DW_OP_reg30:
2505 return "DW_OP_reg30";
2506 case DW_OP_reg31:
2507 return "DW_OP_reg31";
2508 case DW_OP_breg0:
2509 return "DW_OP_breg0";
2510 case DW_OP_breg1:
2511 return "DW_OP_breg1";
2512 case DW_OP_breg2:
2513 return "DW_OP_breg2";
2514 case DW_OP_breg3:
2515 return "DW_OP_breg3";
2516 case DW_OP_breg4:
2517 return "DW_OP_breg4";
2518 case DW_OP_breg5:
2519 return "DW_OP_breg5";
2520 case DW_OP_breg6:
2521 return "DW_OP_breg6";
2522 case DW_OP_breg7:
2523 return "DW_OP_breg7";
2524 case DW_OP_breg8:
2525 return "DW_OP_breg8";
2526 case DW_OP_breg9:
2527 return "DW_OP_breg9";
2528 case DW_OP_breg10:
2529 return "DW_OP_breg10";
2530 case DW_OP_breg11:
2531 return "DW_OP_breg11";
2532 case DW_OP_breg12:
2533 return "DW_OP_breg12";
2534 case DW_OP_breg13:
2535 return "DW_OP_breg13";
2536 case DW_OP_breg14:
2537 return "DW_OP_breg14";
2538 case DW_OP_breg15:
2539 return "DW_OP_breg15";
2540 case DW_OP_breg16:
2541 return "DW_OP_breg16";
2542 case DW_OP_breg17:
2543 return "DW_OP_breg17";
2544 case DW_OP_breg18:
2545 return "DW_OP_breg18";
2546 case DW_OP_breg19:
2547 return "DW_OP_breg19";
2548 case DW_OP_breg20:
2549 return "DW_OP_breg20";
2550 case DW_OP_breg21:
2551 return "DW_OP_breg21";
2552 case DW_OP_breg22:
2553 return "DW_OP_breg22";
2554 case DW_OP_breg23:
2555 return "DW_OP_breg23";
2556 case DW_OP_breg24:
2557 return "DW_OP_breg24";
2558 case DW_OP_breg25:
2559 return "DW_OP_breg25";
2560 case DW_OP_breg26:
2561 return "DW_OP_breg26";
2562 case DW_OP_breg27:
2563 return "DW_OP_breg27";
2564 case DW_OP_breg28:
2565 return "DW_OP_breg28";
2566 case DW_OP_breg29:
2567 return "DW_OP_breg29";
2568 case DW_OP_breg30:
2569 return "DW_OP_breg30";
2570 case DW_OP_breg31:
2571 return "DW_OP_breg31";
2572 case DW_OP_regx:
2573 return "DW_OP_regx";
2574 case DW_OP_fbreg:
2575 return "DW_OP_fbreg";
2576 case DW_OP_bregx:
2577 return "DW_OP_bregx";
2578 case DW_OP_piece:
2579 return "DW_OP_piece";
2580 case DW_OP_deref_size:
2581 return "DW_OP_deref_size";
2582 case DW_OP_xderef_size:
2583 return "DW_OP_xderef_size";
2584 case DW_OP_nop:
2585 return "DW_OP_nop";
2586 default:
2587 return "OP_<unknown>";
2591 /* Return a pointer to a newly allocated location description. Location
2592 descriptions are simple expression terms that can be strung
2593 together to form more complicated location (address) descriptions. */
2595 static inline dw_loc_descr_ref
2596 new_loc_descr (op, oprnd1, oprnd2)
2597 enum dwarf_location_atom op;
2598 unsigned long oprnd1;
2599 unsigned long oprnd2;
2601 /* Use xcalloc here so we clear out all of the long_long constant in
2602 the union. */
2603 dw_loc_descr_ref descr
2604 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2606 descr->dw_loc_opc = op;
2607 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2608 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2609 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2610 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2612 return descr;
2616 /* Add a location description term to a location description expression. */
2618 static inline void
2619 add_loc_descr (list_head, descr)
2620 dw_loc_descr_ref *list_head;
2621 dw_loc_descr_ref descr;
2623 dw_loc_descr_ref *d;
2625 /* Find the end of the chain. */
2626 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2629 *d = descr;
2632 /* Return the size of a location descriptor. */
2634 static unsigned long
2635 size_of_loc_descr (loc)
2636 dw_loc_descr_ref loc;
2638 unsigned long size = 1;
2640 switch (loc->dw_loc_opc)
2642 case DW_OP_addr:
2643 size += DWARF2_ADDR_SIZE;
2644 break;
2645 case DW_OP_const1u:
2646 case DW_OP_const1s:
2647 size += 1;
2648 break;
2649 case DW_OP_const2u:
2650 case DW_OP_const2s:
2651 size += 2;
2652 break;
2653 case DW_OP_const4u:
2654 case DW_OP_const4s:
2655 size += 4;
2656 break;
2657 case DW_OP_const8u:
2658 case DW_OP_const8s:
2659 size += 8;
2660 break;
2661 case DW_OP_constu:
2662 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2663 break;
2664 case DW_OP_consts:
2665 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2666 break;
2667 case DW_OP_pick:
2668 size += 1;
2669 break;
2670 case DW_OP_plus_uconst:
2671 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2672 break;
2673 case DW_OP_skip:
2674 case DW_OP_bra:
2675 size += 2;
2676 break;
2677 case DW_OP_breg0:
2678 case DW_OP_breg1:
2679 case DW_OP_breg2:
2680 case DW_OP_breg3:
2681 case DW_OP_breg4:
2682 case DW_OP_breg5:
2683 case DW_OP_breg6:
2684 case DW_OP_breg7:
2685 case DW_OP_breg8:
2686 case DW_OP_breg9:
2687 case DW_OP_breg10:
2688 case DW_OP_breg11:
2689 case DW_OP_breg12:
2690 case DW_OP_breg13:
2691 case DW_OP_breg14:
2692 case DW_OP_breg15:
2693 case DW_OP_breg16:
2694 case DW_OP_breg17:
2695 case DW_OP_breg18:
2696 case DW_OP_breg19:
2697 case DW_OP_breg20:
2698 case DW_OP_breg21:
2699 case DW_OP_breg22:
2700 case DW_OP_breg23:
2701 case DW_OP_breg24:
2702 case DW_OP_breg25:
2703 case DW_OP_breg26:
2704 case DW_OP_breg27:
2705 case DW_OP_breg28:
2706 case DW_OP_breg29:
2707 case DW_OP_breg30:
2708 case DW_OP_breg31:
2709 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2710 break;
2711 case DW_OP_regx:
2712 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2713 break;
2714 case DW_OP_fbreg:
2715 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2716 break;
2717 case DW_OP_bregx:
2718 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2719 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2720 break;
2721 case DW_OP_piece:
2722 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2723 break;
2724 case DW_OP_deref_size:
2725 case DW_OP_xderef_size:
2726 size += 1;
2727 break;
2728 default:
2729 break;
2732 return size;
2735 /* Return the size of a series of location descriptors. */
2737 static unsigned long
2738 size_of_locs (loc)
2739 dw_loc_descr_ref loc;
2741 unsigned long size;
2743 for (size = 0; loc != NULL; loc = loc->dw_loc_next)
2745 loc->dw_loc_addr = size;
2746 size += size_of_loc_descr (loc);
2749 return size;
2752 /* Output location description stack opcode's operands (if any). */
2754 static void
2755 output_loc_operands (loc)
2756 dw_loc_descr_ref loc;
2758 dw_val_ref val1 = &loc->dw_loc_oprnd1;
2759 dw_val_ref val2 = &loc->dw_loc_oprnd2;
2761 switch (loc->dw_loc_opc)
2763 #ifdef DWARF2_DEBUGGING_INFO
2764 case DW_OP_addr:
2765 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2766 break;
2767 case DW_OP_const2u:
2768 case DW_OP_const2s:
2769 dw2_asm_output_data (2, val1->v.val_int, NULL);
2770 break;
2771 case DW_OP_const4u:
2772 case DW_OP_const4s:
2773 dw2_asm_output_data (4, val1->v.val_int, NULL);
2774 break;
2775 case DW_OP_const8u:
2776 case DW_OP_const8s:
2777 if (HOST_BITS_PER_LONG < 64)
2778 abort ();
2779 dw2_asm_output_data (8, val1->v.val_int, NULL);
2780 break;
2781 case DW_OP_skip:
2782 case DW_OP_bra:
2784 int offset;
2786 if (val1->val_class == dw_val_class_loc)
2787 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2788 else
2789 abort ();
2791 dw2_asm_output_data (2, offset, NULL);
2793 break;
2794 #else
2795 case DW_OP_addr:
2796 case DW_OP_const2u:
2797 case DW_OP_const2s:
2798 case DW_OP_const4u:
2799 case DW_OP_const4s:
2800 case DW_OP_const8u:
2801 case DW_OP_const8s:
2802 case DW_OP_skip:
2803 case DW_OP_bra:
2804 /* We currently don't make any attempt to make sure these are
2805 aligned properly like we do for the main unwind info, so
2806 don't support emitting things larger than a byte if we're
2807 only doing unwinding. */
2808 abort ();
2809 #endif
2810 case DW_OP_const1u:
2811 case DW_OP_const1s:
2812 dw2_asm_output_data (1, val1->v.val_int, NULL);
2813 break;
2814 case DW_OP_constu:
2815 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2816 break;
2817 case DW_OP_consts:
2818 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2819 break;
2820 case DW_OP_pick:
2821 dw2_asm_output_data (1, val1->v.val_int, NULL);
2822 break;
2823 case DW_OP_plus_uconst:
2824 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2825 break;
2826 case DW_OP_breg0:
2827 case DW_OP_breg1:
2828 case DW_OP_breg2:
2829 case DW_OP_breg3:
2830 case DW_OP_breg4:
2831 case DW_OP_breg5:
2832 case DW_OP_breg6:
2833 case DW_OP_breg7:
2834 case DW_OP_breg8:
2835 case DW_OP_breg9:
2836 case DW_OP_breg10:
2837 case DW_OP_breg11:
2838 case DW_OP_breg12:
2839 case DW_OP_breg13:
2840 case DW_OP_breg14:
2841 case DW_OP_breg15:
2842 case DW_OP_breg16:
2843 case DW_OP_breg17:
2844 case DW_OP_breg18:
2845 case DW_OP_breg19:
2846 case DW_OP_breg20:
2847 case DW_OP_breg21:
2848 case DW_OP_breg22:
2849 case DW_OP_breg23:
2850 case DW_OP_breg24:
2851 case DW_OP_breg25:
2852 case DW_OP_breg26:
2853 case DW_OP_breg27:
2854 case DW_OP_breg28:
2855 case DW_OP_breg29:
2856 case DW_OP_breg30:
2857 case DW_OP_breg31:
2858 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2859 break;
2860 case DW_OP_regx:
2861 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2862 break;
2863 case DW_OP_fbreg:
2864 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2865 break;
2866 case DW_OP_bregx:
2867 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2868 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2869 break;
2870 case DW_OP_piece:
2871 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2872 break;
2873 case DW_OP_deref_size:
2874 case DW_OP_xderef_size:
2875 dw2_asm_output_data (1, val1->v.val_int, NULL);
2876 break;
2877 default:
2878 /* Other codes have no operands. */
2879 break;
2883 /* Output a sequence of location operations. */
2885 static void
2886 output_loc_sequence (loc)
2887 dw_loc_descr_ref loc;
2889 for (; loc != NULL; loc = loc->dw_loc_next)
2891 /* Output the opcode. */
2892 dw2_asm_output_data (1, loc->dw_loc_opc,
2893 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2895 /* Output the operand(s) (if any). */
2896 output_loc_operands (loc);
2900 /* This routine will generate the correct assembly data for a location
2901 description based on a cfi entry with a complex address. */
2903 static void
2904 output_cfa_loc (cfi)
2905 dw_cfi_ref cfi;
2907 dw_loc_descr_ref loc;
2908 unsigned long size;
2910 /* Output the size of the block. */
2911 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2912 size = size_of_locs (loc);
2913 dw2_asm_output_data_uleb128 (size, NULL);
2915 /* Now output the operations themselves. */
2916 output_loc_sequence (loc);
2919 /* This function builds a dwarf location descriptor sequence from
2920 a dw_cfa_location. */
2922 static struct dw_loc_descr_struct *
2923 build_cfa_loc (cfa)
2924 dw_cfa_location *cfa;
2926 struct dw_loc_descr_struct *head, *tmp;
2928 if (cfa->indirect == 0)
2929 abort ();
2931 if (cfa->base_offset)
2933 if (cfa->reg <= 31)
2934 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2935 else
2936 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2938 else if (cfa->reg <= 31)
2939 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2940 else
2941 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2943 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2944 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2945 add_loc_descr (&head, tmp);
2946 if (cfa->offset != 0)
2948 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2949 add_loc_descr (&head, tmp);
2952 return head;
2955 /* This function fills in aa dw_cfa_location structure from a dwarf location
2956 descriptor sequence. */
2958 static void
2959 get_cfa_from_loc_descr (cfa, loc)
2960 dw_cfa_location *cfa;
2961 struct dw_loc_descr_struct *loc;
2963 struct dw_loc_descr_struct *ptr;
2964 cfa->offset = 0;
2965 cfa->base_offset = 0;
2966 cfa->indirect = 0;
2967 cfa->reg = -1;
2969 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2971 enum dwarf_location_atom op = ptr->dw_loc_opc;
2973 switch (op)
2975 case DW_OP_reg0:
2976 case DW_OP_reg1:
2977 case DW_OP_reg2:
2978 case DW_OP_reg3:
2979 case DW_OP_reg4:
2980 case DW_OP_reg5:
2981 case DW_OP_reg6:
2982 case DW_OP_reg7:
2983 case DW_OP_reg8:
2984 case DW_OP_reg9:
2985 case DW_OP_reg10:
2986 case DW_OP_reg11:
2987 case DW_OP_reg12:
2988 case DW_OP_reg13:
2989 case DW_OP_reg14:
2990 case DW_OP_reg15:
2991 case DW_OP_reg16:
2992 case DW_OP_reg17:
2993 case DW_OP_reg18:
2994 case DW_OP_reg19:
2995 case DW_OP_reg20:
2996 case DW_OP_reg21:
2997 case DW_OP_reg22:
2998 case DW_OP_reg23:
2999 case DW_OP_reg24:
3000 case DW_OP_reg25:
3001 case DW_OP_reg26:
3002 case DW_OP_reg27:
3003 case DW_OP_reg28:
3004 case DW_OP_reg29:
3005 case DW_OP_reg30:
3006 case DW_OP_reg31:
3007 cfa->reg = op - DW_OP_reg0;
3008 break;
3009 case DW_OP_regx:
3010 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3011 break;
3012 case DW_OP_breg0:
3013 case DW_OP_breg1:
3014 case DW_OP_breg2:
3015 case DW_OP_breg3:
3016 case DW_OP_breg4:
3017 case DW_OP_breg5:
3018 case DW_OP_breg6:
3019 case DW_OP_breg7:
3020 case DW_OP_breg8:
3021 case DW_OP_breg9:
3022 case DW_OP_breg10:
3023 case DW_OP_breg11:
3024 case DW_OP_breg12:
3025 case DW_OP_breg13:
3026 case DW_OP_breg14:
3027 case DW_OP_breg15:
3028 case DW_OP_breg16:
3029 case DW_OP_breg17:
3030 case DW_OP_breg18:
3031 case DW_OP_breg19:
3032 case DW_OP_breg20:
3033 case DW_OP_breg21:
3034 case DW_OP_breg22:
3035 case DW_OP_breg23:
3036 case DW_OP_breg24:
3037 case DW_OP_breg25:
3038 case DW_OP_breg26:
3039 case DW_OP_breg27:
3040 case DW_OP_breg28:
3041 case DW_OP_breg29:
3042 case DW_OP_breg30:
3043 case DW_OP_breg31:
3044 cfa->reg = op - DW_OP_breg0;
3045 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
3046 break;
3047 case DW_OP_bregx:
3048 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
3049 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
3050 break;
3051 case DW_OP_deref:
3052 cfa->indirect = 1;
3053 break;
3054 case DW_OP_plus_uconst:
3055 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
3056 break;
3057 default:
3058 internal_error ("DW_LOC_OP %s not implemented\n",
3059 dwarf_stack_op_name (ptr->dw_loc_opc));
3063 #endif /* .debug_frame support */
3065 /* And now, the support for symbolic debugging information. */
3066 #ifdef DWARF2_DEBUGGING_INFO
3068 /* .debug_str support. */
3069 static hashnode indirect_string_alloc PARAMS ((hash_table *));
3070 static int output_indirect_string PARAMS ((struct cpp_reader *,
3071 hashnode, const PTR));
3074 static void dwarf2out_init PARAMS ((const char *));
3075 static void dwarf2out_finish PARAMS ((const char *));
3076 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3077 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3078 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3079 static void dwarf2out_end_source_file PARAMS ((unsigned));
3080 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3081 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3082 static bool dwarf2out_ignore_block PARAMS ((tree));
3083 static void dwarf2out_global_decl PARAMS ((tree));
3084 static void dwarf2out_abstract_function PARAMS ((tree));
3086 /* The debug hooks structure. */
3088 struct gcc_debug_hooks dwarf2_debug_hooks =
3090 dwarf2out_init,
3091 dwarf2out_finish,
3092 dwarf2out_define,
3093 dwarf2out_undef,
3094 dwarf2out_start_source_file,
3095 dwarf2out_end_source_file,
3096 dwarf2out_begin_block,
3097 dwarf2out_end_block,
3098 dwarf2out_ignore_block,
3099 dwarf2out_source_line,
3100 dwarf2out_begin_prologue,
3101 debug_nothing_int, /* end_prologue */
3102 dwarf2out_end_epilogue,
3103 debug_nothing_tree, /* begin_function */
3104 debug_nothing_int, /* end_function */
3105 dwarf2out_decl, /* function_decl */
3106 dwarf2out_global_decl,
3107 debug_nothing_tree, /* deferred_inline_function */
3108 /* The DWARF 2 backend tries to reduce debugging bloat by not
3109 emitting the abstract description of inline functions until
3110 something tries to reference them. */
3111 dwarf2out_abstract_function, /* outlining_inline_function */
3112 debug_nothing_rtx /* label */
3115 /* NOTE: In the comments in this file, many references are made to
3116 "Debugging Information Entries". This term is abbreviated as `DIE'
3117 throughout the remainder of this file. */
3119 /* An internal representation of the DWARF output is built, and then
3120 walked to generate the DWARF debugging info. The walk of the internal
3121 representation is done after the entire program has been compiled.
3122 The types below are used to describe the internal representation. */
3124 /* Various DIE's use offsets relative to the beginning of the
3125 .debug_info section to refer to each other. */
3127 typedef long int dw_offset;
3129 /* Define typedefs here to avoid circular dependencies. */
3131 typedef struct dw_attr_struct *dw_attr_ref;
3132 typedef struct dw_line_info_struct *dw_line_info_ref;
3133 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3134 typedef struct pubname_struct *pubname_ref;
3135 typedef struct dw_ranges_struct *dw_ranges_ref;
3137 /* Each entry in the line_info_table maintains the file and
3138 line number associated with the label generated for that
3139 entry. The label gives the PC value associated with
3140 the line number entry. */
3142 typedef struct dw_line_info_struct
3144 unsigned long dw_file_num;
3145 unsigned long dw_line_num;
3147 dw_line_info_entry;
3149 /* Line information for functions in separate sections; each one gets its
3150 own sequence. */
3151 typedef struct dw_separate_line_info_struct
3153 unsigned long dw_file_num;
3154 unsigned long dw_line_num;
3155 unsigned long function;
3157 dw_separate_line_info_entry;
3159 /* Each DIE attribute has a field specifying the attribute kind,
3160 a link to the next attribute in the chain, and an attribute value.
3161 Attributes are typically linked below the DIE they modify. */
3163 typedef struct dw_attr_struct
3165 enum dwarf_attribute dw_attr;
3166 dw_attr_ref dw_attr_next;
3167 dw_val_node dw_attr_val;
3169 dw_attr_node;
3171 /* The Debugging Information Entry (DIE) structure */
3173 typedef struct die_struct
3175 enum dwarf_tag die_tag;
3176 char *die_symbol;
3177 dw_attr_ref die_attr;
3178 dw_die_ref die_parent;
3179 dw_die_ref die_child;
3180 dw_die_ref die_sib;
3181 dw_offset die_offset;
3182 unsigned long die_abbrev;
3183 int die_mark;
3185 die_node;
3187 /* The pubname structure */
3189 typedef struct pubname_struct
3191 dw_die_ref die;
3192 char *name;
3194 pubname_entry;
3196 struct dw_ranges_struct
3198 int block_num;
3201 /* The limbo die list structure. */
3202 typedef struct limbo_die_struct
3204 dw_die_ref die;
3205 tree created_for;
3206 struct limbo_die_struct *next;
3208 limbo_die_node;
3210 /* How to start an assembler comment. */
3211 #ifndef ASM_COMMENT_START
3212 #define ASM_COMMENT_START ";#"
3213 #endif
3215 /* Define a macro which returns non-zero for a TYPE_DECL which was
3216 implicitly generated for a tagged type.
3218 Note that unlike the gcc front end (which generates a NULL named
3219 TYPE_DECL node for each complete tagged type, each array type, and
3220 each function type node created) the g++ front end generates a
3221 _named_ TYPE_DECL node for each tagged type node created.
3222 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3223 generate a DW_TAG_typedef DIE for them. */
3225 #define TYPE_DECL_IS_STUB(decl) \
3226 (DECL_NAME (decl) == NULL_TREE \
3227 || (DECL_ARTIFICIAL (decl) \
3228 && is_tagged_type (TREE_TYPE (decl)) \
3229 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3230 /* This is necessary for stub decls that \
3231 appear in nested inline functions. */ \
3232 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3233 && (decl_ultimate_origin (decl) \
3234 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3236 /* Information concerning the compilation unit's programming
3237 language, and compiler version. */
3239 extern int flag_traditional;
3241 /* Fixed size portion of the DWARF compilation unit header. */
3242 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3244 /* Fixed size portion of debugging line information prolog. */
3245 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3247 /* Fixed size portion of public names info. */
3248 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3250 /* Fixed size portion of the address range info. */
3251 #define DWARF_ARANGES_HEADER_SIZE \
3252 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3253 - DWARF_OFFSET_SIZE)
3255 /* Size of padding portion in the address range info. It must be
3256 aligned to twice the pointer size. */
3257 #define DWARF_ARANGES_PAD_SIZE \
3258 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3259 - (2 * DWARF_OFFSET_SIZE + 4))
3261 /* Use assembler line directives if available. */
3262 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3263 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3264 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3265 #else
3266 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3267 #endif
3268 #endif
3270 /* Minimum line offset in a special line info. opcode.
3271 This value was chosen to give a reasonable range of values. */
3272 #define DWARF_LINE_BASE -10
3274 /* First special line opcode - leave room for the standard opcodes. */
3275 #define DWARF_LINE_OPCODE_BASE 10
3277 /* Range of line offsets in a special line info. opcode. */
3278 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3280 /* Flag that indicates the initial value of the is_stmt_start flag.
3281 In the present implementation, we do not mark any lines as
3282 the beginning of a source statement, because that information
3283 is not made available by the GCC front-end. */
3284 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3286 /* This location is used by calc_die_sizes() to keep track
3287 the offset of each DIE within the .debug_info section. */
3288 static unsigned long next_die_offset;
3290 /* Record the root of the DIE's built for the current compilation unit. */
3291 static dw_die_ref comp_unit_die;
3293 /* A list of DIEs with a NULL parent waiting to be relocated. */
3294 static limbo_die_node *limbo_die_list = 0;
3296 /* Structure used by lookup_filename to manage sets of filenames. */
3297 struct file_table
3299 char **table;
3300 unsigned allocated;
3301 unsigned in_use;
3302 unsigned last_lookup_index;
3305 /* Size (in elements) of increments by which we may expand the filename
3306 table. */
3307 #define FILE_TABLE_INCREMENT 64
3309 /* Filenames referenced by this compilation unit. */
3310 static struct file_table file_table;
3312 /* Local pointer to the name of the main input file. Initialized in
3313 dwarf2out_init. */
3314 static const char *primary_filename;
3316 /* A pointer to the base of a table of references to DIE's that describe
3317 declarations. The table is indexed by DECL_UID() which is a unique
3318 number identifying each decl. */
3319 static dw_die_ref *decl_die_table;
3321 /* Number of elements currently allocated for the decl_die_table. */
3322 static unsigned decl_die_table_allocated;
3324 /* Number of elements in decl_die_table currently in use. */
3325 static unsigned decl_die_table_in_use;
3327 /* Size (in elements) of increments by which we may expand the
3328 decl_die_table. */
3329 #define DECL_DIE_TABLE_INCREMENT 256
3331 /* A pointer to the base of a table of references to declaration
3332 scopes. This table is a display which tracks the nesting
3333 of declaration scopes at the current scope and containing
3334 scopes. This table is used to find the proper place to
3335 define type declaration DIE's. */
3336 varray_type decl_scope_table;
3338 /* A pointer to the base of a list of references to DIE's that
3339 are uniquely identified by their tag, presence/absence of
3340 children DIE's, and list of attribute/value pairs. */
3341 static dw_die_ref *abbrev_die_table;
3343 /* Number of elements currently allocated for abbrev_die_table. */
3344 static unsigned abbrev_die_table_allocated;
3346 /* Number of elements in type_die_table currently in use. */
3347 static unsigned abbrev_die_table_in_use;
3349 /* Size (in elements) of increments by which we may expand the
3350 abbrev_die_table. */
3351 #define ABBREV_DIE_TABLE_INCREMENT 256
3353 /* A pointer to the base of a table that contains line information
3354 for each source code line in .text in the compilation unit. */
3355 static dw_line_info_ref line_info_table;
3357 /* Number of elements currently allocated for line_info_table. */
3358 static unsigned line_info_table_allocated;
3360 /* Number of elements in separate_line_info_table currently in use. */
3361 static unsigned separate_line_info_table_in_use;
3363 /* A pointer to the base of a table that contains line information
3364 for each source code line outside of .text in the compilation unit. */
3365 static dw_separate_line_info_ref separate_line_info_table;
3367 /* Number of elements currently allocated for separate_line_info_table. */
3368 static unsigned separate_line_info_table_allocated;
3370 /* Number of elements in line_info_table currently in use. */
3371 static unsigned line_info_table_in_use;
3373 /* Size (in elements) of increments by which we may expand the
3374 line_info_table. */
3375 #define LINE_INFO_TABLE_INCREMENT 1024
3377 /* A pointer to the base of a table that contains a list of publicly
3378 accessible names. */
3379 static pubname_ref pubname_table;
3381 /* Number of elements currently allocated for pubname_table. */
3382 static unsigned pubname_table_allocated;
3384 /* Number of elements in pubname_table currently in use. */
3385 static unsigned pubname_table_in_use;
3387 /* Size (in elements) of increments by which we may expand the
3388 pubname_table. */
3389 #define PUBNAME_TABLE_INCREMENT 64
3391 /* Array of dies for which we should generate .debug_arange info. */
3392 static dw_die_ref *arange_table;
3394 /* Number of elements currently allocated for arange_table. */
3395 static unsigned arange_table_allocated;
3397 /* Number of elements in arange_table currently in use. */
3398 static unsigned arange_table_in_use;
3400 /* Size (in elements) of increments by which we may expand the
3401 arange_table. */
3402 #define ARANGE_TABLE_INCREMENT 64
3404 /* Array of dies for which we should generate .debug_ranges info. */
3405 static dw_ranges_ref ranges_table;
3407 /* Number of elements currently allocated for ranges_table. */
3408 static unsigned ranges_table_allocated;
3410 /* Number of elements in ranges_table currently in use. */
3411 static unsigned ranges_table_in_use;
3413 /* Size (in elements) of increments by which we may expand the
3414 ranges_table. */
3415 #define RANGES_TABLE_INCREMENT 64
3417 /* Whether we have location lists that need outputting */
3418 static unsigned have_location_lists;
3420 /* A pointer to the base of a list of incomplete types which might be
3421 completed at some later time. incomplete_types_list needs to be a VARRAY
3422 because we want to tell the garbage collector about it. */
3423 varray_type incomplete_types;
3425 /* Record whether the function being analyzed contains inlined functions. */
3426 static int current_function_has_inlines;
3427 #if 0 && defined (MIPS_DEBUGGING_INFO)
3428 static int comp_unit_has_inlines;
3429 #endif
3431 /* Array of RTXes referenced by the debugging information, which therefore
3432 must be kept around forever. This is a GC root. */
3433 static varray_type used_rtx_varray;
3435 /* Forward declarations for functions defined in this file. */
3437 static int is_pseudo_reg PARAMS ((rtx));
3438 static tree type_main_variant PARAMS ((tree));
3439 static int is_tagged_type PARAMS ((tree));
3440 static const char *dwarf_tag_name PARAMS ((unsigned));
3441 static const char *dwarf_attr_name PARAMS ((unsigned));
3442 static const char *dwarf_form_name PARAMS ((unsigned));
3443 #if 0
3444 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3445 #endif
3446 static tree decl_ultimate_origin PARAMS ((tree));
3447 static tree block_ultimate_origin PARAMS ((tree));
3448 static tree decl_class_context PARAMS ((tree));
3449 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3450 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
3451 static void add_AT_flag PARAMS ((dw_die_ref,
3452 enum dwarf_attribute,
3453 unsigned));
3454 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
3455 static void add_AT_int PARAMS ((dw_die_ref,
3456 enum dwarf_attribute, long));
3457 static inline long int AT_int PARAMS ((dw_attr_ref));
3458 static void add_AT_unsigned PARAMS ((dw_die_ref,
3459 enum dwarf_attribute,
3460 unsigned long));
3461 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
3462 static void add_AT_long_long PARAMS ((dw_die_ref,
3463 enum dwarf_attribute,
3464 unsigned long,
3465 unsigned long));
3466 static void add_AT_float PARAMS ((dw_die_ref,
3467 enum dwarf_attribute,
3468 unsigned, long *));
3469 static void add_AT_string PARAMS ((dw_die_ref,
3470 enum dwarf_attribute,
3471 const char *));
3472 static inline const char *AT_string PARAMS ((dw_attr_ref));
3473 static int AT_string_form PARAMS ((dw_attr_ref));
3474 static void add_AT_die_ref PARAMS ((dw_die_ref,
3475 enum dwarf_attribute,
3476 dw_die_ref));
3477 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
3478 static inline int AT_ref_external PARAMS ((dw_attr_ref));
3479 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
3480 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3481 enum dwarf_attribute,
3482 unsigned));
3483 static void add_AT_loc PARAMS ((dw_die_ref,
3484 enum dwarf_attribute,
3485 dw_loc_descr_ref));
3486 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
3487 static void add_AT_loc_list PARAMS ((dw_die_ref,
3488 enum dwarf_attribute,
3489 dw_loc_list_ref));
3490 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
3491 static void add_AT_addr PARAMS ((dw_die_ref,
3492 enum dwarf_attribute,
3493 rtx));
3494 static inline rtx AT_addr PARAMS ((dw_attr_ref));
3495 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3496 enum dwarf_attribute,
3497 const char *));
3498 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3499 enum dwarf_attribute,
3500 const char *));
3501 static void add_AT_offset PARAMS ((dw_die_ref,
3502 enum dwarf_attribute,
3503 unsigned long));
3504 static void add_AT_range_list PARAMS ((dw_die_ref,
3505 enum dwarf_attribute,
3506 unsigned long));
3507 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
3508 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3509 enum dwarf_attribute));
3510 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3511 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3512 static const char *get_AT_string PARAMS ((dw_die_ref,
3513 enum dwarf_attribute));
3514 static int get_AT_flag PARAMS ((dw_die_ref,
3515 enum dwarf_attribute));
3516 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3517 enum dwarf_attribute));
3518 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3519 enum dwarf_attribute));
3520 static int is_c_family PARAMS ((void));
3521 static int is_cxx PARAMS ((void));
3522 static int is_java PARAMS ((void));
3523 static int is_fortran PARAMS ((void));
3524 static void remove_AT PARAMS ((dw_die_ref,
3525 enum dwarf_attribute));
3526 static inline void free_die PARAMS ((dw_die_ref));
3527 static void remove_children PARAMS ((dw_die_ref));
3528 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3529 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref,
3530 tree));
3531 static dw_die_ref lookup_type_die PARAMS ((tree));
3532 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3533 static dw_die_ref lookup_decl_die PARAMS ((tree));
3534 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3535 static void print_spaces PARAMS ((FILE *));
3536 static void print_die PARAMS ((dw_die_ref, FILE *));
3537 static void print_dwarf_line_table PARAMS ((FILE *));
3538 static void reverse_die_lists PARAMS ((dw_die_ref));
3539 static void reverse_all_dies PARAMS ((dw_die_ref));
3540 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3541 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3542 static void loc_checksum PARAMS ((dw_loc_descr_ref,
3543 struct md5_ctx *));
3544 static void attr_checksum PARAMS ((dw_attr_ref,
3545 struct md5_ctx *));
3546 static void die_checksum PARAMS ((dw_die_ref,
3547 struct md5_ctx *));
3548 static void compute_section_prefix PARAMS ((dw_die_ref));
3549 static int is_type_die PARAMS ((dw_die_ref));
3550 static int is_comdat_die PARAMS ((dw_die_ref));
3551 static int is_symbol_die PARAMS ((dw_die_ref));
3552 static void assign_symbol_names PARAMS ((dw_die_ref));
3553 static void break_out_includes PARAMS ((dw_die_ref));
3554 static void add_sibling_attributes PARAMS ((dw_die_ref));
3555 static void build_abbrev_table PARAMS ((dw_die_ref));
3556 static void output_location_lists PARAMS ((dw_die_ref));
3557 static int constant_size PARAMS ((long unsigned));
3558 static unsigned long size_of_die PARAMS ((dw_die_ref));
3559 static void calc_die_sizes PARAMS ((dw_die_ref));
3560 static void mark_dies PARAMS ((dw_die_ref));
3561 static void unmark_dies PARAMS ((dw_die_ref));
3562 static unsigned long size_of_pubnames PARAMS ((void));
3563 static unsigned long size_of_aranges PARAMS ((void));
3564 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3565 static void output_value_format PARAMS ((dw_attr_ref));
3566 static void output_abbrev_section PARAMS ((void));
3567 static void output_die_symbol PARAMS ((dw_die_ref));
3568 static void output_die PARAMS ((dw_die_ref));
3569 static void output_compilation_unit_header PARAMS ((void));
3570 static void output_comp_unit PARAMS ((dw_die_ref));
3571 static const char *dwarf2_name PARAMS ((tree, int));
3572 static void add_pubname PARAMS ((tree, dw_die_ref));
3573 static void output_pubnames PARAMS ((void));
3574 static void add_arange PARAMS ((tree, dw_die_ref));
3575 static void output_aranges PARAMS ((void));
3576 static unsigned int add_ranges PARAMS ((tree));
3577 static void output_ranges PARAMS ((void));
3578 static void output_line_info PARAMS ((void));
3579 static void output_file_names PARAMS ((void));
3580 static dw_die_ref base_type_die PARAMS ((tree));
3581 static tree root_type PARAMS ((tree));
3582 static int is_base_type PARAMS ((tree));
3583 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3584 static int type_is_enum PARAMS ((tree));
3585 static unsigned int reg_number PARAMS ((rtx));
3586 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3587 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3588 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3589 static int is_based_loc PARAMS ((rtx));
3590 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3591 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3592 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3593 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3594 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3595 static tree field_type PARAMS ((tree));
3596 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3597 static unsigned int simple_field_decl_align_in_bits PARAMS ((tree));
3598 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3599 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3600 static void add_AT_location_description PARAMS ((dw_die_ref,
3601 enum dwarf_attribute, rtx));
3602 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3603 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3604 static rtx rtl_for_decl_location PARAMS ((tree));
3605 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3606 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3607 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3608 static void add_bound_info PARAMS ((dw_die_ref,
3609 enum dwarf_attribute, tree));
3610 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3611 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3612 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3613 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3614 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3615 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3616 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3617 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3618 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3619 static void push_decl_scope PARAMS ((tree));
3620 static void pop_decl_scope PARAMS ((void));
3621 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3622 static inline int local_scope_p PARAMS ((dw_die_ref));
3623 static inline int class_scope_p PARAMS ((dw_die_ref));
3624 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3625 dw_die_ref));
3626 static const char *type_tag PARAMS ((tree));
3627 static tree member_declared_type PARAMS ((tree));
3628 #if 0
3629 static const char *decl_start_label PARAMS ((tree));
3630 #endif
3631 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3632 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3633 #if 0
3634 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3635 #endif
3636 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3637 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3638 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3639 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3640 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3641 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3642 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3643 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3644 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3645 static void gen_label_die PARAMS ((tree, dw_die_ref));
3646 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3647 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3648 static void gen_field_die PARAMS ((tree, dw_die_ref));
3649 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3650 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3651 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3652 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3653 static void gen_member_die PARAMS ((tree, dw_die_ref));
3654 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3655 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3656 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3657 static void gen_type_die PARAMS ((tree, dw_die_ref));
3658 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3659 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3660 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3661 static int is_redundant_typedef PARAMS ((tree));
3662 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3663 static unsigned lookup_filename PARAMS ((const char *));
3664 static void init_file_table PARAMS ((void));
3665 static void retry_incomplete_types PARAMS ((void));
3666 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3667 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3668 static int file_info_cmp PARAMS ((const void *, const void *));
3669 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3670 const char *, const char *,
3671 const char *, unsigned));
3672 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3673 dw_loc_descr_ref,
3674 const char *, const char *, const char *));
3675 static void output_loc_list PARAMS ((dw_loc_list_ref));
3676 static char *gen_internal_sym PARAMS ((const char *));
3677 static void mark_limbo_die_list PARAMS ((void *));
3679 /* Section names used to hold DWARF debugging information. */
3680 #ifndef DEBUG_INFO_SECTION
3681 #define DEBUG_INFO_SECTION ".debug_info"
3682 #endif
3683 #ifndef DEBUG_ABBREV_SECTION
3684 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3685 #endif
3686 #ifndef DEBUG_ARANGES_SECTION
3687 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3688 #endif
3689 #ifndef DEBUG_MACINFO_SECTION
3690 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3691 #endif
3692 #ifndef DEBUG_LINE_SECTION
3693 #define DEBUG_LINE_SECTION ".debug_line"
3694 #endif
3695 #ifndef DEBUG_LOC_SECTION
3696 #define DEBUG_LOC_SECTION ".debug_loc"
3697 #endif
3698 #ifndef DEBUG_PUBNAMES_SECTION
3699 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3700 #endif
3701 #ifndef DEBUG_STR_SECTION
3702 #define DEBUG_STR_SECTION ".debug_str"
3703 #endif
3704 #ifndef DEBUG_RANGES_SECTION
3705 #define DEBUG_RANGES_SECTION ".debug_ranges"
3706 #endif
3708 /* Standard ELF section names for compiled code and data. */
3709 #ifndef TEXT_SECTION_NAME
3710 #define TEXT_SECTION_NAME ".text"
3711 #endif
3713 /* Section flags for .debug_str section. */
3714 #ifdef HAVE_GAS_SHF_MERGE
3715 #define DEBUG_STR_SECTION_FLAGS \
3716 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1)
3717 #else
3718 #define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG
3719 #endif
3721 /* Labels we insert at beginning sections we can reference instead of
3722 the section names themselves. */
3724 #ifndef TEXT_SECTION_LABEL
3725 #define TEXT_SECTION_LABEL "Ltext"
3726 #endif
3727 #ifndef DEBUG_LINE_SECTION_LABEL
3728 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3729 #endif
3730 #ifndef DEBUG_INFO_SECTION_LABEL
3731 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3732 #endif
3733 #ifndef DEBUG_ABBREV_SECTION_LABEL
3734 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3735 #endif
3736 #ifndef DEBUG_LOC_SECTION_LABEL
3737 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3738 #endif
3739 #ifndef DEBUG_RANGES_SECTION_LABEL
3740 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3741 #endif
3742 #ifndef DEBUG_MACINFO_SECTION_LABEL
3743 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3744 #endif
3746 /* Definitions of defaults for formats and names of various special
3747 (artificial) labels which may be generated within this file (when the -g
3748 options is used and DWARF_DEBUGGING_INFO is in effect.
3749 If necessary, these may be overridden from within the tm.h file, but
3750 typically, overriding these defaults is unnecessary. */
3752 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3753 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3754 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3755 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3756 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3757 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3758 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3759 static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES];
3761 #ifndef TEXT_END_LABEL
3762 #define TEXT_END_LABEL "Letext"
3763 #endif
3764 #ifndef DATA_END_LABEL
3765 #define DATA_END_LABEL "Ledata"
3766 #endif
3767 #ifndef BSS_END_LABEL
3768 #define BSS_END_LABEL "Lebss"
3769 #endif
3770 #ifndef BLOCK_BEGIN_LABEL
3771 #define BLOCK_BEGIN_LABEL "LBB"
3772 #endif
3773 #ifndef BLOCK_END_LABEL
3774 #define BLOCK_END_LABEL "LBE"
3775 #endif
3776 #ifndef BODY_BEGIN_LABEL
3777 #define BODY_BEGIN_LABEL "Lbb"
3778 #endif
3779 #ifndef BODY_END_LABEL
3780 #define BODY_END_LABEL "Lbe"
3781 #endif
3782 #ifndef LINE_CODE_LABEL
3783 #define LINE_CODE_LABEL "LM"
3784 #endif
3785 #ifndef SEPARATE_LINE_CODE_LABEL
3786 #define SEPARATE_LINE_CODE_LABEL "LSM"
3787 #endif
3789 /* We allow a language front-end to designate a function that is to be
3790 called to "demangle" any name before it it put into a DIE. */
3792 static const char *(*demangle_name_func) PARAMS ((const char *));
3794 void
3795 dwarf2out_set_demangle_name_func (func)
3796 const char *(*func) PARAMS ((const char *));
3798 demangle_name_func = func;
3801 /* Test if rtl node points to a pseudo register. */
3803 static inline int
3804 is_pseudo_reg (rtl)
3805 rtx rtl;
3807 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3808 || (GET_CODE (rtl) == SUBREG
3809 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3812 /* Return a reference to a type, with its const and volatile qualifiers
3813 removed. */
3815 static inline tree
3816 type_main_variant (type)
3817 tree type;
3819 type = TYPE_MAIN_VARIANT (type);
3821 /* ??? There really should be only one main variant among any group of
3822 variants of a given type (and all of the MAIN_VARIANT values for all
3823 members of the group should point to that one type) but sometimes the C
3824 front-end messes this up for array types, so we work around that bug
3825 here. */
3826 if (TREE_CODE (type) == ARRAY_TYPE)
3827 while (type != TYPE_MAIN_VARIANT (type))
3828 type = TYPE_MAIN_VARIANT (type);
3830 return type;
3833 /* Return non-zero if the given type node represents a tagged type. */
3835 static inline int
3836 is_tagged_type (type)
3837 tree type;
3839 enum tree_code code = TREE_CODE (type);
3841 return (code == RECORD_TYPE || code == UNION_TYPE
3842 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3845 /* Convert a DIE tag into its string name. */
3847 static const char *
3848 dwarf_tag_name (tag)
3849 unsigned tag;
3851 switch (tag)
3853 case DW_TAG_padding:
3854 return "DW_TAG_padding";
3855 case DW_TAG_array_type:
3856 return "DW_TAG_array_type";
3857 case DW_TAG_class_type:
3858 return "DW_TAG_class_type";
3859 case DW_TAG_entry_point:
3860 return "DW_TAG_entry_point";
3861 case DW_TAG_enumeration_type:
3862 return "DW_TAG_enumeration_type";
3863 case DW_TAG_formal_parameter:
3864 return "DW_TAG_formal_parameter";
3865 case DW_TAG_imported_declaration:
3866 return "DW_TAG_imported_declaration";
3867 case DW_TAG_label:
3868 return "DW_TAG_label";
3869 case DW_TAG_lexical_block:
3870 return "DW_TAG_lexical_block";
3871 case DW_TAG_member:
3872 return "DW_TAG_member";
3873 case DW_TAG_pointer_type:
3874 return "DW_TAG_pointer_type";
3875 case DW_TAG_reference_type:
3876 return "DW_TAG_reference_type";
3877 case DW_TAG_compile_unit:
3878 return "DW_TAG_compile_unit";
3879 case DW_TAG_string_type:
3880 return "DW_TAG_string_type";
3881 case DW_TAG_structure_type:
3882 return "DW_TAG_structure_type";
3883 case DW_TAG_subroutine_type:
3884 return "DW_TAG_subroutine_type";
3885 case DW_TAG_typedef:
3886 return "DW_TAG_typedef";
3887 case DW_TAG_union_type:
3888 return "DW_TAG_union_type";
3889 case DW_TAG_unspecified_parameters:
3890 return "DW_TAG_unspecified_parameters";
3891 case DW_TAG_variant:
3892 return "DW_TAG_variant";
3893 case DW_TAG_common_block:
3894 return "DW_TAG_common_block";
3895 case DW_TAG_common_inclusion:
3896 return "DW_TAG_common_inclusion";
3897 case DW_TAG_inheritance:
3898 return "DW_TAG_inheritance";
3899 case DW_TAG_inlined_subroutine:
3900 return "DW_TAG_inlined_subroutine";
3901 case DW_TAG_module:
3902 return "DW_TAG_module";
3903 case DW_TAG_ptr_to_member_type:
3904 return "DW_TAG_ptr_to_member_type";
3905 case DW_TAG_set_type:
3906 return "DW_TAG_set_type";
3907 case DW_TAG_subrange_type:
3908 return "DW_TAG_subrange_type";
3909 case DW_TAG_with_stmt:
3910 return "DW_TAG_with_stmt";
3911 case DW_TAG_access_declaration:
3912 return "DW_TAG_access_declaration";
3913 case DW_TAG_base_type:
3914 return "DW_TAG_base_type";
3915 case DW_TAG_catch_block:
3916 return "DW_TAG_catch_block";
3917 case DW_TAG_const_type:
3918 return "DW_TAG_const_type";
3919 case DW_TAG_constant:
3920 return "DW_TAG_constant";
3921 case DW_TAG_enumerator:
3922 return "DW_TAG_enumerator";
3923 case DW_TAG_file_type:
3924 return "DW_TAG_file_type";
3925 case DW_TAG_friend:
3926 return "DW_TAG_friend";
3927 case DW_TAG_namelist:
3928 return "DW_TAG_namelist";
3929 case DW_TAG_namelist_item:
3930 return "DW_TAG_namelist_item";
3931 case DW_TAG_packed_type:
3932 return "DW_TAG_packed_type";
3933 case DW_TAG_subprogram:
3934 return "DW_TAG_subprogram";
3935 case DW_TAG_template_type_param:
3936 return "DW_TAG_template_type_param";
3937 case DW_TAG_template_value_param:
3938 return "DW_TAG_template_value_param";
3939 case DW_TAG_thrown_type:
3940 return "DW_TAG_thrown_type";
3941 case DW_TAG_try_block:
3942 return "DW_TAG_try_block";
3943 case DW_TAG_variant_part:
3944 return "DW_TAG_variant_part";
3945 case DW_TAG_variable:
3946 return "DW_TAG_variable";
3947 case DW_TAG_volatile_type:
3948 return "DW_TAG_volatile_type";
3949 case DW_TAG_MIPS_loop:
3950 return "DW_TAG_MIPS_loop";
3951 case DW_TAG_format_label:
3952 return "DW_TAG_format_label";
3953 case DW_TAG_function_template:
3954 return "DW_TAG_function_template";
3955 case DW_TAG_class_template:
3956 return "DW_TAG_class_template";
3957 case DW_TAG_GNU_BINCL:
3958 return "DW_TAG_GNU_BINCL";
3959 case DW_TAG_GNU_EINCL:
3960 return "DW_TAG_GNU_EINCL";
3961 default:
3962 return "DW_TAG_<unknown>";
3966 /* Convert a DWARF attribute code into its string name. */
3968 static const char *
3969 dwarf_attr_name (attr)
3970 unsigned attr;
3972 switch (attr)
3974 case DW_AT_sibling:
3975 return "DW_AT_sibling";
3976 case DW_AT_location:
3977 return "DW_AT_location";
3978 case DW_AT_name:
3979 return "DW_AT_name";
3980 case DW_AT_ordering:
3981 return "DW_AT_ordering";
3982 case DW_AT_subscr_data:
3983 return "DW_AT_subscr_data";
3984 case DW_AT_byte_size:
3985 return "DW_AT_byte_size";
3986 case DW_AT_bit_offset:
3987 return "DW_AT_bit_offset";
3988 case DW_AT_bit_size:
3989 return "DW_AT_bit_size";
3990 case DW_AT_element_list:
3991 return "DW_AT_element_list";
3992 case DW_AT_stmt_list:
3993 return "DW_AT_stmt_list";
3994 case DW_AT_low_pc:
3995 return "DW_AT_low_pc";
3996 case DW_AT_high_pc:
3997 return "DW_AT_high_pc";
3998 case DW_AT_language:
3999 return "DW_AT_language";
4000 case DW_AT_member:
4001 return "DW_AT_member";
4002 case DW_AT_discr:
4003 return "DW_AT_discr";
4004 case DW_AT_discr_value:
4005 return "DW_AT_discr_value";
4006 case DW_AT_visibility:
4007 return "DW_AT_visibility";
4008 case DW_AT_import:
4009 return "DW_AT_import";
4010 case DW_AT_string_length:
4011 return "DW_AT_string_length";
4012 case DW_AT_common_reference:
4013 return "DW_AT_common_reference";
4014 case DW_AT_comp_dir:
4015 return "DW_AT_comp_dir";
4016 case DW_AT_const_value:
4017 return "DW_AT_const_value";
4018 case DW_AT_containing_type:
4019 return "DW_AT_containing_type";
4020 case DW_AT_default_value:
4021 return "DW_AT_default_value";
4022 case DW_AT_inline:
4023 return "DW_AT_inline";
4024 case DW_AT_is_optional:
4025 return "DW_AT_is_optional";
4026 case DW_AT_lower_bound:
4027 return "DW_AT_lower_bound";
4028 case DW_AT_producer:
4029 return "DW_AT_producer";
4030 case DW_AT_prototyped:
4031 return "DW_AT_prototyped";
4032 case DW_AT_return_addr:
4033 return "DW_AT_return_addr";
4034 case DW_AT_start_scope:
4035 return "DW_AT_start_scope";
4036 case DW_AT_stride_size:
4037 return "DW_AT_stride_size";
4038 case DW_AT_upper_bound:
4039 return "DW_AT_upper_bound";
4040 case DW_AT_abstract_origin:
4041 return "DW_AT_abstract_origin";
4042 case DW_AT_accessibility:
4043 return "DW_AT_accessibility";
4044 case DW_AT_address_class:
4045 return "DW_AT_address_class";
4046 case DW_AT_artificial:
4047 return "DW_AT_artificial";
4048 case DW_AT_base_types:
4049 return "DW_AT_base_types";
4050 case DW_AT_calling_convention:
4051 return "DW_AT_calling_convention";
4052 case DW_AT_count:
4053 return "DW_AT_count";
4054 case DW_AT_data_member_location:
4055 return "DW_AT_data_member_location";
4056 case DW_AT_decl_column:
4057 return "DW_AT_decl_column";
4058 case DW_AT_decl_file:
4059 return "DW_AT_decl_file";
4060 case DW_AT_decl_line:
4061 return "DW_AT_decl_line";
4062 case DW_AT_declaration:
4063 return "DW_AT_declaration";
4064 case DW_AT_discr_list:
4065 return "DW_AT_discr_list";
4066 case DW_AT_encoding:
4067 return "DW_AT_encoding";
4068 case DW_AT_external:
4069 return "DW_AT_external";
4070 case DW_AT_frame_base:
4071 return "DW_AT_frame_base";
4072 case DW_AT_friend:
4073 return "DW_AT_friend";
4074 case DW_AT_identifier_case:
4075 return "DW_AT_identifier_case";
4076 case DW_AT_macro_info:
4077 return "DW_AT_macro_info";
4078 case DW_AT_namelist_items:
4079 return "DW_AT_namelist_items";
4080 case DW_AT_priority:
4081 return "DW_AT_priority";
4082 case DW_AT_segment:
4083 return "DW_AT_segment";
4084 case DW_AT_specification:
4085 return "DW_AT_specification";
4086 case DW_AT_static_link:
4087 return "DW_AT_static_link";
4088 case DW_AT_type:
4089 return "DW_AT_type";
4090 case DW_AT_use_location:
4091 return "DW_AT_use_location";
4092 case DW_AT_variable_parameter:
4093 return "DW_AT_variable_parameter";
4094 case DW_AT_virtuality:
4095 return "DW_AT_virtuality";
4096 case DW_AT_vtable_elem_location:
4097 return "DW_AT_vtable_elem_location";
4099 case DW_AT_allocated:
4100 return "DW_AT_allocated";
4101 case DW_AT_associated:
4102 return "DW_AT_associated";
4103 case DW_AT_data_location:
4104 return "DW_AT_data_location";
4105 case DW_AT_stride:
4106 return "DW_AT_stride";
4107 case DW_AT_entry_pc:
4108 return "DW_AT_entry_pc";
4109 case DW_AT_use_UTF8:
4110 return "DW_AT_use_UTF8";
4111 case DW_AT_extension:
4112 return "DW_AT_extension";
4113 case DW_AT_ranges:
4114 return "DW_AT_ranges";
4115 case DW_AT_trampoline:
4116 return "DW_AT_trampoline";
4117 case DW_AT_call_column:
4118 return "DW_AT_call_column";
4119 case DW_AT_call_file:
4120 return "DW_AT_call_file";
4121 case DW_AT_call_line:
4122 return "DW_AT_call_line";
4124 case DW_AT_MIPS_fde:
4125 return "DW_AT_MIPS_fde";
4126 case DW_AT_MIPS_loop_begin:
4127 return "DW_AT_MIPS_loop_begin";
4128 case DW_AT_MIPS_tail_loop_begin:
4129 return "DW_AT_MIPS_tail_loop_begin";
4130 case DW_AT_MIPS_epilog_begin:
4131 return "DW_AT_MIPS_epilog_begin";
4132 case DW_AT_MIPS_loop_unroll_factor:
4133 return "DW_AT_MIPS_loop_unroll_factor";
4134 case DW_AT_MIPS_software_pipeline_depth:
4135 return "DW_AT_MIPS_software_pipeline_depth";
4136 case DW_AT_MIPS_linkage_name:
4137 return "DW_AT_MIPS_linkage_name";
4138 case DW_AT_MIPS_stride:
4139 return "DW_AT_MIPS_stride";
4140 case DW_AT_MIPS_abstract_name:
4141 return "DW_AT_MIPS_abstract_name";
4142 case DW_AT_MIPS_clone_origin:
4143 return "DW_AT_MIPS_clone_origin";
4144 case DW_AT_MIPS_has_inlines:
4145 return "DW_AT_MIPS_has_inlines";
4147 case DW_AT_sf_names:
4148 return "DW_AT_sf_names";
4149 case DW_AT_src_info:
4150 return "DW_AT_src_info";
4151 case DW_AT_mac_info:
4152 return "DW_AT_mac_info";
4153 case DW_AT_src_coords:
4154 return "DW_AT_src_coords";
4155 case DW_AT_body_begin:
4156 return "DW_AT_body_begin";
4157 case DW_AT_body_end:
4158 return "DW_AT_body_end";
4159 case DW_AT_GNU_vector:
4160 return "DW_AT_GNU_vector";
4162 case DW_AT_VMS_rtnbeg_pd_address:
4163 return "DW_AT_VMS_rtnbeg_pd_address";
4165 default:
4166 return "DW_AT_<unknown>";
4170 /* Convert a DWARF value form code into its string name. */
4172 static const char *
4173 dwarf_form_name (form)
4174 unsigned form;
4176 switch (form)
4178 case DW_FORM_addr:
4179 return "DW_FORM_addr";
4180 case DW_FORM_block2:
4181 return "DW_FORM_block2";
4182 case DW_FORM_block4:
4183 return "DW_FORM_block4";
4184 case DW_FORM_data2:
4185 return "DW_FORM_data2";
4186 case DW_FORM_data4:
4187 return "DW_FORM_data4";
4188 case DW_FORM_data8:
4189 return "DW_FORM_data8";
4190 case DW_FORM_string:
4191 return "DW_FORM_string";
4192 case DW_FORM_block:
4193 return "DW_FORM_block";
4194 case DW_FORM_block1:
4195 return "DW_FORM_block1";
4196 case DW_FORM_data1:
4197 return "DW_FORM_data1";
4198 case DW_FORM_flag:
4199 return "DW_FORM_flag";
4200 case DW_FORM_sdata:
4201 return "DW_FORM_sdata";
4202 case DW_FORM_strp:
4203 return "DW_FORM_strp";
4204 case DW_FORM_udata:
4205 return "DW_FORM_udata";
4206 case DW_FORM_ref_addr:
4207 return "DW_FORM_ref_addr";
4208 case DW_FORM_ref1:
4209 return "DW_FORM_ref1";
4210 case DW_FORM_ref2:
4211 return "DW_FORM_ref2";
4212 case DW_FORM_ref4:
4213 return "DW_FORM_ref4";
4214 case DW_FORM_ref8:
4215 return "DW_FORM_ref8";
4216 case DW_FORM_ref_udata:
4217 return "DW_FORM_ref_udata";
4218 case DW_FORM_indirect:
4219 return "DW_FORM_indirect";
4220 default:
4221 return "DW_FORM_<unknown>";
4225 /* Convert a DWARF type code into its string name. */
4227 #if 0
4228 static const char *
4229 dwarf_type_encoding_name (enc)
4230 unsigned enc;
4232 switch (enc)
4234 case DW_ATE_address:
4235 return "DW_ATE_address";
4236 case DW_ATE_boolean:
4237 return "DW_ATE_boolean";
4238 case DW_ATE_complex_float:
4239 return "DW_ATE_complex_float";
4240 case DW_ATE_float:
4241 return "DW_ATE_float";
4242 case DW_ATE_signed:
4243 return "DW_ATE_signed";
4244 case DW_ATE_signed_char:
4245 return "DW_ATE_signed_char";
4246 case DW_ATE_unsigned:
4247 return "DW_ATE_unsigned";
4248 case DW_ATE_unsigned_char:
4249 return "DW_ATE_unsigned_char";
4250 default:
4251 return "DW_ATE_<unknown>";
4254 #endif
4256 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4257 instance of an inlined instance of a decl which is local to an inline
4258 function, so we have to trace all of the way back through the origin chain
4259 to find out what sort of node actually served as the original seed for the
4260 given block. */
4262 static tree
4263 decl_ultimate_origin (decl)
4264 tree decl;
4266 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4267 nodes in the function to point to themselves; ignore that if
4268 we're trying to output the abstract instance of this function. */
4269 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4270 return NULL_TREE;
4272 #ifdef ENABLE_CHECKING
4273 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4274 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4275 most distant ancestor, this should never happen. */
4276 abort ();
4277 #endif
4279 return DECL_ABSTRACT_ORIGIN (decl);
4282 /* Determine the "ultimate origin" of a block. The block may be an inlined
4283 instance of an inlined instance of a block which is local to an inline
4284 function, so we have to trace all of the way back through the origin chain
4285 to find out what sort of node actually served as the original seed for the
4286 given block. */
4288 static tree
4289 block_ultimate_origin (block)
4290 tree block;
4292 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4294 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4295 nodes in the function to point to themselves; ignore that if
4296 we're trying to output the abstract instance of this function. */
4297 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4298 return NULL_TREE;
4300 if (immediate_origin == NULL_TREE)
4301 return NULL_TREE;
4302 else
4304 tree ret_val;
4305 tree lookahead = immediate_origin;
4309 ret_val = lookahead;
4310 lookahead = (TREE_CODE (ret_val) == BLOCK
4311 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL);
4313 while (lookahead != NULL && lookahead != ret_val);
4315 return ret_val;
4319 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4320 of a virtual function may refer to a base class, so we check the 'this'
4321 parameter. */
4323 static tree
4324 decl_class_context (decl)
4325 tree decl;
4327 tree context = NULL_TREE;
4329 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4330 context = DECL_CONTEXT (decl);
4331 else
4332 context = TYPE_MAIN_VARIANT
4333 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4335 if (context && !TYPE_P (context))
4336 context = NULL_TREE;
4338 return context;
4341 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4342 addition order, and correct that in reverse_all_dies. */
4344 static inline void
4345 add_dwarf_attr (die, attr)
4346 dw_die_ref die;
4347 dw_attr_ref attr;
4349 if (die != NULL && attr != NULL)
4351 attr->dw_attr_next = die->die_attr;
4352 die->die_attr = attr;
4356 static inline dw_val_class
4357 AT_class (a)
4358 dw_attr_ref a;
4360 return a->dw_attr_val.val_class;
4363 /* Add a flag value attribute to a DIE. */
4365 static inline void
4366 add_AT_flag (die, attr_kind, flag)
4367 dw_die_ref die;
4368 enum dwarf_attribute attr_kind;
4369 unsigned flag;
4371 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4373 attr->dw_attr_next = NULL;
4374 attr->dw_attr = attr_kind;
4375 attr->dw_attr_val.val_class = dw_val_class_flag;
4376 attr->dw_attr_val.v.val_flag = flag;
4377 add_dwarf_attr (die, attr);
4380 static inline unsigned
4381 AT_flag (a)
4382 dw_attr_ref a;
4384 if (a && AT_class (a) == dw_val_class_flag)
4385 return a->dw_attr_val.v.val_flag;
4387 abort ();
4390 /* Add a signed integer attribute value to a DIE. */
4392 static inline void
4393 add_AT_int (die, attr_kind, int_val)
4394 dw_die_ref die;
4395 enum dwarf_attribute attr_kind;
4396 long int int_val;
4398 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4400 attr->dw_attr_next = NULL;
4401 attr->dw_attr = attr_kind;
4402 attr->dw_attr_val.val_class = dw_val_class_const;
4403 attr->dw_attr_val.v.val_int = int_val;
4404 add_dwarf_attr (die, attr);
4407 static inline long int
4408 AT_int (a)
4409 dw_attr_ref a;
4411 if (a && AT_class (a) == dw_val_class_const)
4412 return a->dw_attr_val.v.val_int;
4414 abort ();
4417 /* Add an unsigned integer attribute value to a DIE. */
4419 static inline void
4420 add_AT_unsigned (die, attr_kind, unsigned_val)
4421 dw_die_ref die;
4422 enum dwarf_attribute attr_kind;
4423 unsigned long unsigned_val;
4425 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4427 attr->dw_attr_next = NULL;
4428 attr->dw_attr = attr_kind;
4429 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4430 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4431 add_dwarf_attr (die, attr);
4434 static inline unsigned long
4435 AT_unsigned (a)
4436 dw_attr_ref a;
4438 if (a && AT_class (a) == dw_val_class_unsigned_const)
4439 return a->dw_attr_val.v.val_unsigned;
4441 abort ();
4444 /* Add an unsigned double integer attribute value to a DIE. */
4446 static inline void
4447 add_AT_long_long (die, attr_kind, val_hi, val_low)
4448 dw_die_ref die;
4449 enum dwarf_attribute attr_kind;
4450 unsigned long val_hi;
4451 unsigned long val_low;
4453 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4455 attr->dw_attr_next = NULL;
4456 attr->dw_attr = attr_kind;
4457 attr->dw_attr_val.val_class = dw_val_class_long_long;
4458 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4459 attr->dw_attr_val.v.val_long_long.low = val_low;
4460 add_dwarf_attr (die, attr);
4463 /* Add a floating point attribute value to a DIE and return it. */
4465 static inline void
4466 add_AT_float (die, attr_kind, length, array)
4467 dw_die_ref die;
4468 enum dwarf_attribute attr_kind;
4469 unsigned length;
4470 long *array;
4472 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4474 attr->dw_attr_next = NULL;
4475 attr->dw_attr = attr_kind;
4476 attr->dw_attr_val.val_class = dw_val_class_float;
4477 attr->dw_attr_val.v.val_float.length = length;
4478 attr->dw_attr_val.v.val_float.array = array;
4479 add_dwarf_attr (die, attr);
4482 /* Add a string attribute value to a DIE. */
4484 static inline void
4485 add_AT_string (die, attr_kind, str)
4486 dw_die_ref die;
4487 enum dwarf_attribute attr_kind;
4488 const char *str;
4490 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4491 struct indirect_string_node *node;
4493 if (! debug_str_hash)
4495 debug_str_hash = ht_create (10);
4496 debug_str_hash->alloc_node = indirect_string_alloc;
4499 node = (struct indirect_string_node *)
4500 ht_lookup (debug_str_hash, (const unsigned char *) str,
4501 strlen (str), HT_ALLOC);
4502 node->refcount++;
4504 attr->dw_attr_next = NULL;
4505 attr->dw_attr = attr_kind;
4506 attr->dw_attr_val.val_class = dw_val_class_str;
4507 attr->dw_attr_val.v.val_str = node;
4508 add_dwarf_attr (die, attr);
4511 static inline const char *
4512 AT_string (a)
4513 dw_attr_ref a;
4515 if (a && AT_class (a) == dw_val_class_str)
4516 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id);
4518 abort ();
4521 /* Find out whether a string should be output inline in DIE
4522 or out-of-line in .debug_str section. */
4524 static int
4525 AT_string_form (a)
4526 dw_attr_ref a;
4528 if (a && AT_class (a) == dw_val_class_str)
4530 struct indirect_string_node *node;
4531 unsigned int len;
4532 extern int const_labelno;
4533 char label[32];
4535 node = a->dw_attr_val.v.val_str;
4536 if (node->form)
4537 return node->form;
4539 len = HT_LEN (&node->id) + 1;
4541 /* If the string is shorter or equal to the size of the reference, it is
4542 always better to put it inline. */
4543 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0)
4544 return node->form = DW_FORM_string;
4546 /* If we cannot expect the linker to merge strings in .debug_str
4547 section, only put it into .debug_str if it is worth even in this
4548 single module. */
4549 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0
4550 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len)
4551 return node->form = DW_FORM_string;
4553 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4554 ++const_labelno;
4555 node->label = xstrdup (label);
4557 return node->form = DW_FORM_strp;
4560 abort ();
4563 /* Add a DIE reference attribute value to a DIE. */
4565 static inline void
4566 add_AT_die_ref (die, attr_kind, targ_die)
4567 dw_die_ref die;
4568 enum dwarf_attribute attr_kind;
4569 dw_die_ref targ_die;
4571 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4573 attr->dw_attr_next = NULL;
4574 attr->dw_attr = attr_kind;
4575 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4576 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4577 attr->dw_attr_val.v.val_die_ref.external = 0;
4578 add_dwarf_attr (die, attr);
4581 static inline dw_die_ref
4582 AT_ref (a)
4583 dw_attr_ref a;
4585 if (a && AT_class (a) == dw_val_class_die_ref)
4586 return a->dw_attr_val.v.val_die_ref.die;
4588 abort ();
4591 static inline int
4592 AT_ref_external (a)
4593 dw_attr_ref a;
4595 if (a && AT_class (a) == dw_val_class_die_ref)
4596 return a->dw_attr_val.v.val_die_ref.external;
4598 return 0;
4601 static inline void
4602 set_AT_ref_external (a, i)
4603 dw_attr_ref a;
4604 int i;
4606 if (a && AT_class (a) == dw_val_class_die_ref)
4607 a->dw_attr_val.v.val_die_ref.external = i;
4608 else
4609 abort ();
4612 /* Add an FDE reference attribute value to a DIE. */
4614 static inline void
4615 add_AT_fde_ref (die, attr_kind, targ_fde)
4616 dw_die_ref die;
4617 enum dwarf_attribute attr_kind;
4618 unsigned targ_fde;
4620 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4622 attr->dw_attr_next = NULL;
4623 attr->dw_attr = attr_kind;
4624 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4625 attr->dw_attr_val.v.val_fde_index = targ_fde;
4626 add_dwarf_attr (die, attr);
4629 /* Add a location description attribute value to a DIE. */
4631 static inline void
4632 add_AT_loc (die, attr_kind, loc)
4633 dw_die_ref die;
4634 enum dwarf_attribute attr_kind;
4635 dw_loc_descr_ref loc;
4637 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4639 attr->dw_attr_next = NULL;
4640 attr->dw_attr = attr_kind;
4641 attr->dw_attr_val.val_class = dw_val_class_loc;
4642 attr->dw_attr_val.v.val_loc = loc;
4643 add_dwarf_attr (die, attr);
4646 static inline dw_loc_descr_ref
4647 AT_loc (a)
4648 dw_attr_ref a;
4650 if (a && AT_class (a) == dw_val_class_loc)
4651 return a->dw_attr_val.v.val_loc;
4653 abort ();
4656 static inline void
4657 add_AT_loc_list (die, attr_kind, loc_list)
4658 dw_die_ref die;
4659 enum dwarf_attribute attr_kind;
4660 dw_loc_list_ref loc_list;
4662 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4664 attr->dw_attr_next = NULL;
4665 attr->dw_attr = attr_kind;
4666 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4667 attr->dw_attr_val.v.val_loc_list = loc_list;
4668 add_dwarf_attr (die, attr);
4669 have_location_lists = 1;
4672 static inline dw_loc_list_ref
4673 AT_loc_list (a)
4674 dw_attr_ref a;
4676 if (a && AT_class (a) == dw_val_class_loc_list)
4677 return a->dw_attr_val.v.val_loc_list;
4679 abort ();
4682 /* Add an address constant attribute value to a DIE. */
4684 static inline void
4685 add_AT_addr (die, attr_kind, addr)
4686 dw_die_ref die;
4687 enum dwarf_attribute attr_kind;
4688 rtx addr;
4690 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4692 attr->dw_attr_next = NULL;
4693 attr->dw_attr = attr_kind;
4694 attr->dw_attr_val.val_class = dw_val_class_addr;
4695 attr->dw_attr_val.v.val_addr = addr;
4696 add_dwarf_attr (die, attr);
4699 static inline rtx
4700 AT_addr (a)
4701 dw_attr_ref a;
4703 if (a && AT_class (a) == dw_val_class_addr)
4704 return a->dw_attr_val.v.val_addr;
4706 abort ();
4709 /* Add a label identifier attribute value to a DIE. */
4711 static inline void
4712 add_AT_lbl_id (die, attr_kind, lbl_id)
4713 dw_die_ref die;
4714 enum dwarf_attribute attr_kind;
4715 const char *lbl_id;
4717 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4719 attr->dw_attr_next = NULL;
4720 attr->dw_attr = attr_kind;
4721 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4722 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4723 add_dwarf_attr (die, attr);
4726 /* Add a section offset attribute value to a DIE. */
4728 static inline void
4729 add_AT_lbl_offset (die, attr_kind, label)
4730 dw_die_ref die;
4731 enum dwarf_attribute attr_kind;
4732 const char *label;
4734 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4736 attr->dw_attr_next = NULL;
4737 attr->dw_attr = attr_kind;
4738 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4739 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4740 add_dwarf_attr (die, attr);
4743 /* Add an offset attribute value to a DIE. */
4745 static inline void
4746 add_AT_offset (die, attr_kind, offset)
4747 dw_die_ref die;
4748 enum dwarf_attribute attr_kind;
4749 unsigned long offset;
4751 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4753 attr->dw_attr_next = NULL;
4754 attr->dw_attr = attr_kind;
4755 attr->dw_attr_val.val_class = dw_val_class_offset;
4756 attr->dw_attr_val.v.val_offset = offset;
4757 add_dwarf_attr (die, attr);
4760 /* Add an range_list attribute value to a DIE. */
4762 static void
4763 add_AT_range_list (die, attr_kind, offset)
4764 dw_die_ref die;
4765 enum dwarf_attribute attr_kind;
4766 unsigned long offset;
4768 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4770 attr->dw_attr_next = NULL;
4771 attr->dw_attr = attr_kind;
4772 attr->dw_attr_val.val_class = dw_val_class_range_list;
4773 attr->dw_attr_val.v.val_offset = offset;
4774 add_dwarf_attr (die, attr);
4777 static inline const char *
4778 AT_lbl (a)
4779 dw_attr_ref a;
4781 if (a && (AT_class (a) == dw_val_class_lbl_id
4782 || AT_class (a) == dw_val_class_lbl_offset))
4783 return a->dw_attr_val.v.val_lbl_id;
4785 abort ();
4788 /* Get the attribute of type attr_kind. */
4790 static inline dw_attr_ref
4791 get_AT (die, attr_kind)
4792 dw_die_ref die;
4793 enum dwarf_attribute attr_kind;
4795 dw_attr_ref a;
4796 dw_die_ref spec = NULL;
4798 if (die != NULL)
4800 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4801 if (a->dw_attr == attr_kind)
4802 return a;
4803 else if (a->dw_attr == DW_AT_specification
4804 || a->dw_attr == DW_AT_abstract_origin)
4805 spec = AT_ref (a);
4807 if (spec)
4808 return get_AT (spec, attr_kind);
4811 return NULL;
4814 /* Return the "low pc" attribute value, typically associated with a subprogram
4815 DIE. Return null if the "low pc" attribute is either not present, or if it
4816 cannot be represented as an assembler label identifier. */
4818 static inline const char *
4819 get_AT_low_pc (die)
4820 dw_die_ref die;
4822 dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4824 return a ? AT_lbl (a) : NULL;
4827 /* Return the "high pc" attribute value, typically associated with a subprogram
4828 DIE. Return null if the "high pc" attribute is either not present, or if it
4829 cannot be represented as an assembler label identifier. */
4831 static inline const char *
4832 get_AT_hi_pc (die)
4833 dw_die_ref die;
4835 dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4837 return a ? AT_lbl (a) : NULL;
4840 /* Return the value of the string attribute designated by ATTR_KIND, or
4841 NULL if it is not present. */
4843 static inline const char *
4844 get_AT_string (die, attr_kind)
4845 dw_die_ref die;
4846 enum dwarf_attribute attr_kind;
4848 dw_attr_ref a = get_AT (die, attr_kind);
4850 return a ? AT_string (a) : NULL;
4853 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4854 if it is not present. */
4856 static inline int
4857 get_AT_flag (die, attr_kind)
4858 dw_die_ref die;
4859 enum dwarf_attribute attr_kind;
4861 dw_attr_ref a = get_AT (die, attr_kind);
4863 return a ? AT_flag (a) : 0;
4866 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4867 if it is not present. */
4869 static inline unsigned
4870 get_AT_unsigned (die, attr_kind)
4871 dw_die_ref die;
4872 enum dwarf_attribute attr_kind;
4874 dw_attr_ref a = get_AT (die, attr_kind);
4876 return a ? AT_unsigned (a) : 0;
4879 static inline dw_die_ref
4880 get_AT_ref (die, attr_kind)
4881 dw_die_ref die;
4882 enum dwarf_attribute attr_kind;
4884 dw_attr_ref a = get_AT (die, attr_kind);
4886 return a ? AT_ref (a) : NULL;
4889 static inline int
4890 is_c_family ()
4892 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4894 return (lang == DW_LANG_C || lang == DW_LANG_C89
4895 || lang == DW_LANG_C_plus_plus);
4898 static inline int
4899 is_cxx ()
4901 return (get_AT_unsigned (comp_unit_die, DW_AT_language)
4902 == DW_LANG_C_plus_plus);
4905 static inline int
4906 is_fortran ()
4908 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4910 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4913 static inline int
4914 is_java ()
4916 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4918 return (lang == DW_LANG_Java);
4921 /* Free up the memory used by A. */
4923 static inline void free_AT PARAMS ((dw_attr_ref));
4924 static inline void
4925 free_AT (a)
4926 dw_attr_ref a;
4928 switch (AT_class (a))
4930 case dw_val_class_str:
4931 if (a->dw_attr_val.v.val_str->refcount)
4932 a->dw_attr_val.v.val_str->refcount--;
4933 break;
4935 case dw_val_class_lbl_id:
4936 case dw_val_class_lbl_offset:
4937 free (a->dw_attr_val.v.val_lbl_id);
4938 break;
4940 case dw_val_class_float:
4941 free (a->dw_attr_val.v.val_float.array);
4942 break;
4944 default:
4945 break;
4948 free (a);
4951 /* Remove the specified attribute if present. */
4953 static void
4954 remove_AT (die, attr_kind)
4955 dw_die_ref die;
4956 enum dwarf_attribute attr_kind;
4958 dw_attr_ref *p;
4959 dw_attr_ref removed = NULL;
4961 if (die != NULL)
4963 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4964 if ((*p)->dw_attr == attr_kind)
4966 removed = *p;
4967 *p = (*p)->dw_attr_next;
4968 break;
4971 if (removed != 0)
4972 free_AT (removed);
4976 /* Free up the memory used by DIE. */
4978 static inline void
4979 free_die (die)
4980 dw_die_ref die;
4982 remove_children (die);
4983 free (die);
4986 /* Discard the children of this DIE. */
4988 static void
4989 remove_children (die)
4990 dw_die_ref die;
4992 dw_die_ref child_die = die->die_child;
4994 die->die_child = NULL;
4996 while (child_die != NULL)
4998 dw_die_ref tmp_die = child_die;
4999 dw_attr_ref a;
5001 child_die = child_die->die_sib;
5003 for (a = tmp_die->die_attr; a != NULL;)
5005 dw_attr_ref tmp_a = a;
5007 a = a->dw_attr_next;
5008 free_AT (tmp_a);
5011 free_die (tmp_die);
5015 /* Add a child DIE below its parent. We build the lists up in reverse
5016 addition order, and correct that in reverse_all_dies. */
5018 static inline void
5019 add_child_die (die, child_die)
5020 dw_die_ref die;
5021 dw_die_ref child_die;
5023 if (die != NULL && child_die != NULL)
5025 if (die == child_die)
5026 abort ();
5028 child_die->die_parent = die;
5029 child_die->die_sib = die->die_child;
5030 die->die_child = child_die;
5034 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5035 is the specification, to the front of PARENT's list of children. */
5037 static void
5038 splice_child_die (parent, child)
5039 dw_die_ref parent, child;
5041 dw_die_ref *p;
5043 /* We want the declaration DIE from inside the class, not the
5044 specification DIE at toplevel. */
5045 if (child->die_parent != parent)
5047 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
5049 if (tmp)
5050 child = tmp;
5053 if (child->die_parent != parent
5054 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
5055 abort ();
5057 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
5058 if (*p == child)
5060 *p = child->die_sib;
5061 break;
5064 child->die_sib = parent->die_child;
5065 parent->die_child = child;
5068 /* Return a pointer to a newly created DIE node. */
5070 static inline dw_die_ref
5071 new_die (tag_value, parent_die, t)
5072 enum dwarf_tag tag_value;
5073 dw_die_ref parent_die;
5074 tree t;
5076 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
5078 die->die_tag = tag_value;
5080 if (parent_die != NULL)
5081 add_child_die (parent_die, die);
5082 else
5084 limbo_die_node *limbo_node;
5086 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
5087 limbo_node->die = die;
5088 limbo_node->created_for = t;
5089 limbo_node->next = limbo_die_list;
5090 limbo_die_list = limbo_node;
5093 return die;
5096 /* Return the DIE associated with the given type specifier. */
5098 static inline dw_die_ref
5099 lookup_type_die (type)
5100 tree type;
5102 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
5105 /* Equate a DIE to a given type specifier. */
5107 static inline void
5108 equate_type_number_to_die (type, type_die)
5109 tree type;
5110 dw_die_ref type_die;
5112 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
5115 /* Return the DIE associated with a given declaration. */
5117 static inline dw_die_ref
5118 lookup_decl_die (decl)
5119 tree decl;
5121 unsigned decl_id = DECL_UID (decl);
5123 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL);
5126 /* Equate a DIE to a particular declaration. */
5128 static void
5129 equate_decl_number_to_die (decl, decl_die)
5130 tree decl;
5131 dw_die_ref decl_die;
5133 unsigned int decl_id = DECL_UID (decl);
5134 unsigned int num_allocated;
5136 if (decl_id >= decl_die_table_allocated)
5138 num_allocated
5139 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
5140 / DECL_DIE_TABLE_INCREMENT)
5141 * DECL_DIE_TABLE_INCREMENT;
5143 decl_die_table
5144 = (dw_die_ref *) xrealloc (decl_die_table,
5145 sizeof (dw_die_ref) * num_allocated);
5147 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
5148 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
5149 decl_die_table_allocated = num_allocated;
5152 if (decl_id >= decl_die_table_in_use)
5153 decl_die_table_in_use = (decl_id + 1);
5155 decl_die_table[decl_id] = decl_die;
5158 /* Keep track of the number of spaces used to indent the
5159 output of the debugging routines that print the structure of
5160 the DIE internal representation. */
5161 static int print_indent;
5163 /* Indent the line the number of spaces given by print_indent. */
5165 static inline void
5166 print_spaces (outfile)
5167 FILE *outfile;
5169 fprintf (outfile, "%*s", print_indent, "");
5172 /* Print the information associated with a given DIE, and its children.
5173 This routine is a debugging aid only. */
5175 static void
5176 print_die (die, outfile)
5177 dw_die_ref die;
5178 FILE *outfile;
5180 dw_attr_ref a;
5181 dw_die_ref c;
5183 print_spaces (outfile);
5184 fprintf (outfile, "DIE %4lu: %s\n",
5185 die->die_offset, dwarf_tag_name (die->die_tag));
5186 print_spaces (outfile);
5187 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
5188 fprintf (outfile, " offset: %lu\n", die->die_offset);
5190 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5192 print_spaces (outfile);
5193 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
5195 switch (AT_class (a))
5197 case dw_val_class_addr:
5198 fprintf (outfile, "address");
5199 break;
5200 case dw_val_class_offset:
5201 fprintf (outfile, "offset");
5202 break;
5203 case dw_val_class_loc:
5204 fprintf (outfile, "location descriptor");
5205 break;
5206 case dw_val_class_loc_list:
5207 fprintf (outfile, "location list -> label:%s",
5208 AT_loc_list (a)->ll_symbol);
5209 break;
5210 case dw_val_class_range_list:
5211 fprintf (outfile, "range list");
5212 break;
5213 case dw_val_class_const:
5214 fprintf (outfile, "%ld", AT_int (a));
5215 break;
5216 case dw_val_class_unsigned_const:
5217 fprintf (outfile, "%lu", AT_unsigned (a));
5218 break;
5219 case dw_val_class_long_long:
5220 fprintf (outfile, "constant (%lu,%lu)",
5221 a->dw_attr_val.v.val_long_long.hi,
5222 a->dw_attr_val.v.val_long_long.low);
5223 break;
5224 case dw_val_class_float:
5225 fprintf (outfile, "floating-point constant");
5226 break;
5227 case dw_val_class_flag:
5228 fprintf (outfile, "%u", AT_flag (a));
5229 break;
5230 case dw_val_class_die_ref:
5231 if (AT_ref (a) != NULL)
5233 if (AT_ref (a)->die_symbol)
5234 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5235 else
5236 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5238 else
5239 fprintf (outfile, "die -> <null>");
5240 break;
5241 case dw_val_class_lbl_id:
5242 case dw_val_class_lbl_offset:
5243 fprintf (outfile, "label: %s", AT_lbl (a));
5244 break;
5245 case dw_val_class_str:
5246 if (AT_string (a) != NULL)
5247 fprintf (outfile, "\"%s\"", AT_string (a));
5248 else
5249 fprintf (outfile, "<null>");
5250 break;
5251 default:
5252 break;
5255 fprintf (outfile, "\n");
5258 if (die->die_child != NULL)
5260 print_indent += 4;
5261 for (c = die->die_child; c != NULL; c = c->die_sib)
5262 print_die (c, outfile);
5264 print_indent -= 4;
5266 if (print_indent == 0)
5267 fprintf (outfile, "\n");
5270 /* Print the contents of the source code line number correspondence table.
5271 This routine is a debugging aid only. */
5273 static void
5274 print_dwarf_line_table (outfile)
5275 FILE *outfile;
5277 unsigned i;
5278 dw_line_info_ref line_info;
5280 fprintf (outfile, "\n\nDWARF source line information\n");
5281 for (i = 1; i < line_info_table_in_use; i++)
5283 line_info = &line_info_table[i];
5284 fprintf (outfile, "%5d: ", i);
5285 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5286 fprintf (outfile, "%6ld", line_info->dw_line_num);
5287 fprintf (outfile, "\n");
5290 fprintf (outfile, "\n\n");
5293 /* Print the information collected for a given DIE. */
5295 void
5296 debug_dwarf_die (die)
5297 dw_die_ref die;
5299 print_die (die, stderr);
5302 /* Print all DWARF information collected for the compilation unit.
5303 This routine is a debugging aid only. */
5305 void
5306 debug_dwarf ()
5308 print_indent = 0;
5309 print_die (comp_unit_die, stderr);
5310 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5311 print_dwarf_line_table (stderr);
5314 /* We build up the lists of children and attributes by pushing new ones
5315 onto the beginning of the list. Reverse the lists for DIE so that
5316 they are in order of addition. */
5318 static void
5319 reverse_die_lists (die)
5320 dw_die_ref die;
5322 dw_die_ref c, cp, cn;
5323 dw_attr_ref a, ap, an;
5325 for (a = die->die_attr, ap = 0; a; a = an)
5327 an = a->dw_attr_next;
5328 a->dw_attr_next = ap;
5329 ap = a;
5332 die->die_attr = ap;
5334 for (c = die->die_child, cp = 0; c; c = cn)
5336 cn = c->die_sib;
5337 c->die_sib = cp;
5338 cp = c;
5341 die->die_child = cp;
5344 /* reverse_die_lists only reverses the single die you pass it. Since we used to
5345 reverse all dies in add_sibling_attributes, which runs through all the dies,
5346 it would reverse all the dies. Now, however, since we don't call
5347 reverse_die_lists in add_sibling_attributes, we need a routine to
5348 recursively reverse all the dies. This is that routine. */
5350 static void
5351 reverse_all_dies (die)
5352 dw_die_ref die;
5354 dw_die_ref c;
5356 reverse_die_lists (die);
5358 for (c = die->die_child; c; c = c->die_sib)
5359 reverse_all_dies (c);
5362 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5363 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5364 DIE that marks the start of the DIEs for this include file. */
5366 static dw_die_ref
5367 push_new_compile_unit (old_unit, bincl_die)
5368 dw_die_ref old_unit, bincl_die;
5370 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5371 dw_die_ref new_unit = gen_compile_unit_die (filename);
5373 new_unit->die_sib = old_unit;
5374 return new_unit;
5377 /* Close an include-file CU and reopen the enclosing one. */
5379 static dw_die_ref
5380 pop_compile_unit (old_unit)
5381 dw_die_ref old_unit;
5383 dw_die_ref new_unit = old_unit->die_sib;
5385 old_unit->die_sib = NULL;
5386 return new_unit;
5389 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5390 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5392 /* Calculate the checksum of a location expression. */
5394 static inline void
5395 loc_checksum (loc, ctx)
5396 dw_loc_descr_ref loc;
5397 struct md5_ctx *ctx;
5399 CHECKSUM (loc->dw_loc_opc);
5400 CHECKSUM (loc->dw_loc_oprnd1);
5401 CHECKSUM (loc->dw_loc_oprnd2);
5404 /* Calculate the checksum of an attribute. */
5406 static void
5407 attr_checksum (at, ctx)
5408 dw_attr_ref at;
5409 struct md5_ctx *ctx;
5411 dw_loc_descr_ref loc;
5412 rtx r;
5414 CHECKSUM (at->dw_attr);
5416 /* We don't care about differences in file numbering. */
5417 if (at->dw_attr == DW_AT_decl_file
5418 /* Or that this was compiled with a different compiler snapshot; if
5419 the output is the same, that's what matters. */
5420 || at->dw_attr == DW_AT_producer)
5421 return;
5423 switch (AT_class (at))
5425 case dw_val_class_const:
5426 CHECKSUM (at->dw_attr_val.v.val_int);
5427 break;
5428 case dw_val_class_unsigned_const:
5429 CHECKSUM (at->dw_attr_val.v.val_unsigned);
5430 break;
5431 case dw_val_class_long_long:
5432 CHECKSUM (at->dw_attr_val.v.val_long_long);
5433 break;
5434 case dw_val_class_float:
5435 CHECKSUM (at->dw_attr_val.v.val_float);
5436 break;
5437 case dw_val_class_flag:
5438 CHECKSUM (at->dw_attr_val.v.val_flag);
5439 break;
5440 case dw_val_class_str:
5441 CHECKSUM_STRING (AT_string (at));
5442 break;
5444 case dw_val_class_addr:
5445 r = AT_addr (at);
5446 switch (GET_CODE (r))
5448 case SYMBOL_REF:
5449 CHECKSUM_STRING (XSTR (r, 0));
5450 break;
5452 default:
5453 abort ();
5455 break;
5457 case dw_val_class_offset:
5458 CHECKSUM (at->dw_attr_val.v.val_offset);
5459 break;
5461 case dw_val_class_loc:
5462 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5463 loc_checksum (loc, ctx);
5464 break;
5466 case dw_val_class_die_ref:
5467 if (AT_ref (at)->die_offset)
5468 CHECKSUM (AT_ref (at)->die_offset);
5469 /* FIXME else use target die name or something. */
5471 case dw_val_class_fde_ref:
5472 case dw_val_class_lbl_id:
5473 case dw_val_class_lbl_offset:
5474 break;
5476 default:
5477 break;
5481 /* Calculate the checksum of a DIE. */
5483 static void
5484 die_checksum (die, ctx)
5485 dw_die_ref die;
5486 struct md5_ctx *ctx;
5488 dw_die_ref c;
5489 dw_attr_ref a;
5491 CHECKSUM (die->die_tag);
5493 for (a = die->die_attr; a; a = a->dw_attr_next)
5494 attr_checksum (a, ctx);
5496 for (c = die->die_child; c; c = c->die_sib)
5497 die_checksum (c, ctx);
5500 #undef CHECKSUM
5501 #undef CHECKSUM_STRING
5503 /* The prefix to attach to symbols on DIEs in the current comdat debug
5504 info section. */
5505 static char *comdat_symbol_id;
5507 /* The index of the current symbol within the current comdat CU. */
5508 static unsigned int comdat_symbol_number;
5510 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5511 children, and set comdat_symbol_id accordingly. */
5513 static void
5514 compute_section_prefix (unit_die)
5515 dw_die_ref unit_die;
5517 const char *base = lbasename (get_AT_string (unit_die, DW_AT_name));
5518 char *name = (char *) alloca (strlen (base) + 64);
5519 char *p;
5520 int i;
5521 unsigned char checksum[16];
5522 struct md5_ctx ctx;
5524 /* Compute the checksum of the DIE, then append part of it as hex digits to
5525 the name filename of the unit. */
5527 md5_init_ctx (&ctx);
5528 die_checksum (unit_die, &ctx);
5529 md5_finish_ctx (&ctx, checksum);
5531 sprintf (name, "%s.", base);
5532 clean_symbol_name (name);
5534 p = name + strlen (name);
5535 for (i = 0; i < 4; i++)
5537 sprintf (p, "%.2x", checksum[i]);
5538 p += 2;
5541 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5542 comdat_symbol_number = 0;
5545 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
5547 static int
5548 is_type_die (die)
5549 dw_die_ref die;
5551 switch (die->die_tag)
5553 case DW_TAG_array_type:
5554 case DW_TAG_class_type:
5555 case DW_TAG_enumeration_type:
5556 case DW_TAG_pointer_type:
5557 case DW_TAG_reference_type:
5558 case DW_TAG_string_type:
5559 case DW_TAG_structure_type:
5560 case DW_TAG_subroutine_type:
5561 case DW_TAG_union_type:
5562 case DW_TAG_ptr_to_member_type:
5563 case DW_TAG_set_type:
5564 case DW_TAG_subrange_type:
5565 case DW_TAG_base_type:
5566 case DW_TAG_const_type:
5567 case DW_TAG_file_type:
5568 case DW_TAG_packed_type:
5569 case DW_TAG_volatile_type:
5570 return 1;
5571 default:
5572 return 0;
5576 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5577 Basically, we want to choose the bits that are likely to be shared between
5578 compilations (types) and leave out the bits that are specific to individual
5579 compilations (functions). */
5581 static int
5582 is_comdat_die (c)
5583 dw_die_ref c;
5585 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
5586 we do for stabs. The advantage is a greater likelihood of sharing between
5587 objects that don't include headers in the same order (and therefore would
5588 put the base types in a different comdat). jason 8/28/00 */
5590 if (c->die_tag == DW_TAG_base_type)
5591 return 0;
5593 if (c->die_tag == DW_TAG_pointer_type
5594 || c->die_tag == DW_TAG_reference_type
5595 || c->die_tag == DW_TAG_const_type
5596 || c->die_tag == DW_TAG_volatile_type)
5598 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5600 return t ? is_comdat_die (t) : 0;
5603 return is_type_die (c);
5606 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5607 compilation unit. */
5609 static int
5610 is_symbol_die (c)
5611 dw_die_ref c;
5613 return (is_type_die (c)
5614 || (get_AT (c, DW_AT_declaration)
5615 && !get_AT (c, DW_AT_specification)));
5618 static char *
5619 gen_internal_sym (prefix)
5620 const char *prefix;
5622 char buf[256];
5623 static int label_num;
5625 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5626 return xstrdup (buf);
5629 /* Assign symbols to all worthy DIEs under DIE. */
5631 static void
5632 assign_symbol_names (die)
5633 dw_die_ref die;
5635 dw_die_ref c;
5637 if (is_symbol_die (die))
5639 if (comdat_symbol_id)
5641 char *p = alloca (strlen (comdat_symbol_id) + 64);
5643 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5644 comdat_symbol_id, comdat_symbol_number++);
5645 die->die_symbol = xstrdup (p);
5647 else
5648 die->die_symbol = gen_internal_sym ("LDIE");
5651 for (c = die->die_child; c != NULL; c = c->die_sib)
5652 assign_symbol_names (c);
5655 /* Traverse the DIE (which is always comp_unit_die), and set up
5656 additional compilation units for each of the include files we see
5657 bracketed by BINCL/EINCL. */
5659 static void
5660 break_out_includes (die)
5661 dw_die_ref die;
5663 dw_die_ref *ptr;
5664 dw_die_ref unit = NULL;
5665 limbo_die_node *node;
5667 for (ptr = &(die->die_child); *ptr; )
5669 dw_die_ref c = *ptr;
5671 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL
5672 || (unit && is_comdat_die (c)))
5674 /* This DIE is for a secondary CU; remove it from the main one. */
5675 *ptr = c->die_sib;
5677 if (c->die_tag == DW_TAG_GNU_BINCL)
5679 unit = push_new_compile_unit (unit, c);
5680 free_die (c);
5682 else if (c->die_tag == DW_TAG_GNU_EINCL)
5684 unit = pop_compile_unit (unit);
5685 free_die (c);
5687 else
5688 add_child_die (unit, c);
5690 else
5692 /* Leave this DIE in the main CU. */
5693 ptr = &(c->die_sib);
5694 continue;
5698 #if 0
5699 /* We can only use this in debugging, since the frontend doesn't check
5700 to make sure that we leave every include file we enter. */
5701 if (unit != NULL)
5702 abort ();
5703 #endif
5705 assign_symbol_names (die);
5706 for (node = limbo_die_list; node; node = node->next)
5708 compute_section_prefix (node->die);
5709 assign_symbol_names (node->die);
5713 /* Traverse the DIE and add a sibling attribute if it may have the
5714 effect of speeding up access to siblings. To save some space,
5715 avoid generating sibling attributes for DIE's without children. */
5717 static void
5718 add_sibling_attributes (die)
5719 dw_die_ref die;
5721 dw_die_ref c;
5723 if (die->die_tag != DW_TAG_compile_unit
5724 && die->die_sib && die->die_child != NULL)
5725 /* Add the sibling link to the front of the attribute list. */
5726 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5728 for (c = die->die_child; c != NULL; c = c->die_sib)
5729 add_sibling_attributes (c);
5732 /* Output all location lists for the DIE and its children. */
5734 static void
5735 output_location_lists (die)
5736 dw_die_ref die;
5738 dw_die_ref c;
5739 dw_attr_ref d_attr;
5741 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5742 if (AT_class (d_attr) == dw_val_class_loc_list)
5743 output_loc_list (AT_loc_list (d_attr));
5745 for (c = die->die_child; c != NULL; c = c->die_sib)
5746 output_location_lists (c);
5749 /* The format of each DIE (and its attribute value pairs) is encoded in an
5750 abbreviation table. This routine builds the abbreviation table and assigns
5751 a unique abbreviation id for each abbreviation entry. The children of each
5752 die are visited recursively. */
5754 static void
5755 build_abbrev_table (die)
5756 dw_die_ref die;
5758 unsigned long abbrev_id;
5759 unsigned int n_alloc;
5760 dw_die_ref c;
5761 dw_attr_ref d_attr, a_attr;
5763 /* Scan the DIE references, and mark as external any that refer to
5764 DIEs from other CUs (i.e. those which are not marked). */
5765 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5766 if (AT_class (d_attr) == dw_val_class_die_ref
5767 && AT_ref (d_attr)->die_mark == 0)
5769 if (AT_ref (d_attr)->die_symbol == 0)
5770 abort ();
5772 set_AT_ref_external (d_attr, 1);
5775 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5777 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5779 if (abbrev->die_tag == die->die_tag)
5781 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5783 a_attr = abbrev->die_attr;
5784 d_attr = die->die_attr;
5786 while (a_attr != NULL && d_attr != NULL)
5788 if ((a_attr->dw_attr != d_attr->dw_attr)
5789 || (value_format (a_attr) != value_format (d_attr)))
5790 break;
5792 a_attr = a_attr->dw_attr_next;
5793 d_attr = d_attr->dw_attr_next;
5796 if (a_attr == NULL && d_attr == NULL)
5797 break;
5802 if (abbrev_id >= abbrev_die_table_in_use)
5804 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5806 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5807 abbrev_die_table
5808 = (dw_die_ref *) xrealloc (abbrev_die_table,
5809 sizeof (dw_die_ref) * n_alloc);
5811 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5812 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5813 abbrev_die_table_allocated = n_alloc;
5816 ++abbrev_die_table_in_use;
5817 abbrev_die_table[abbrev_id] = die;
5820 die->die_abbrev = abbrev_id;
5821 for (c = die->die_child; c != NULL; c = c->die_sib)
5822 build_abbrev_table (c);
5825 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5827 static int
5828 constant_size (value)
5829 long unsigned value;
5831 int log;
5833 if (value == 0)
5834 log = 0;
5835 else
5836 log = floor_log2 (value);
5838 log = log / 8;
5839 log = 1 << (floor_log2 (log) + 1);
5841 return log;
5844 /* Return the size of a DIE as it is represented in the
5845 .debug_info section. */
5847 static unsigned long
5848 size_of_die (die)
5849 dw_die_ref die;
5851 unsigned long size = 0;
5852 dw_attr_ref a;
5854 size += size_of_uleb128 (die->die_abbrev);
5855 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5857 switch (AT_class (a))
5859 case dw_val_class_addr:
5860 size += DWARF2_ADDR_SIZE;
5861 break;
5862 case dw_val_class_offset:
5863 size += DWARF_OFFSET_SIZE;
5864 break;
5865 case dw_val_class_loc:
5867 unsigned long lsize = size_of_locs (AT_loc (a));
5869 /* Block length. */
5870 size += constant_size (lsize);
5871 size += lsize;
5873 break;
5874 case dw_val_class_loc_list:
5875 size += DWARF_OFFSET_SIZE;
5876 break;
5877 case dw_val_class_range_list:
5878 size += DWARF_OFFSET_SIZE;
5879 break;
5880 case dw_val_class_const:
5881 size += size_of_sleb128 (AT_int (a));
5882 break;
5883 case dw_val_class_unsigned_const:
5884 size += constant_size (AT_unsigned (a));
5885 break;
5886 case dw_val_class_long_long:
5887 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5888 break;
5889 case dw_val_class_float:
5890 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5891 break;
5892 case dw_val_class_flag:
5893 size += 1;
5894 break;
5895 case dw_val_class_die_ref:
5896 size += DWARF_OFFSET_SIZE;
5897 break;
5898 case dw_val_class_fde_ref:
5899 size += DWARF_OFFSET_SIZE;
5900 break;
5901 case dw_val_class_lbl_id:
5902 size += DWARF2_ADDR_SIZE;
5903 break;
5904 case dw_val_class_lbl_offset:
5905 size += DWARF_OFFSET_SIZE;
5906 break;
5907 case dw_val_class_str:
5908 if (AT_string_form (a) == DW_FORM_strp)
5909 size += DWARF_OFFSET_SIZE;
5910 else
5911 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1;
5912 break;
5913 default:
5914 abort ();
5918 return size;
5921 /* Size the debugging information associated with a given DIE. Visits the
5922 DIE's children recursively. Updates the global variable next_die_offset, on
5923 each time through. Uses the current value of next_die_offset to update the
5924 die_offset field in each DIE. */
5926 static void
5927 calc_die_sizes (die)
5928 dw_die_ref die;
5930 dw_die_ref c;
5932 die->die_offset = next_die_offset;
5933 next_die_offset += size_of_die (die);
5935 for (c = die->die_child; c != NULL; c = c->die_sib)
5936 calc_die_sizes (c);
5938 if (die->die_child != NULL)
5939 /* Count the null byte used to terminate sibling lists. */
5940 next_die_offset += 1;
5943 /* Set the marks for a die and its children. We do this so
5944 that we know whether or not a reference needs to use FORM_ref_addr; only
5945 DIEs in the same CU will be marked. We used to clear out the offset
5946 and use that as the flag, but ran into ordering problems. */
5948 static void
5949 mark_dies (die)
5950 dw_die_ref die;
5952 dw_die_ref c;
5954 die->die_mark = 1;
5955 for (c = die->die_child; c; c = c->die_sib)
5956 mark_dies (c);
5959 /* Clear the marks for a die and its children. */
5961 static void
5962 unmark_dies (die)
5963 dw_die_ref die;
5965 dw_die_ref c;
5967 die->die_mark = 0;
5968 for (c = die->die_child; c; c = c->die_sib)
5969 unmark_dies (c);
5972 /* Return the size of the .debug_pubnames table generated for the
5973 compilation unit. */
5975 static unsigned long
5976 size_of_pubnames ()
5978 unsigned long size;
5979 unsigned i;
5981 size = DWARF_PUBNAMES_HEADER_SIZE;
5982 for (i = 0; i < pubname_table_in_use; i++)
5984 pubname_ref p = &pubname_table[i];
5985 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1;
5988 size += DWARF_OFFSET_SIZE;
5989 return size;
5992 /* Return the size of the information in the .debug_aranges section. */
5994 static unsigned long
5995 size_of_aranges ()
5997 unsigned long size;
5999 size = DWARF_ARANGES_HEADER_SIZE;
6001 /* Count the address/length pair for this compilation unit. */
6002 size += 2 * DWARF2_ADDR_SIZE;
6003 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
6005 /* Count the two zero words used to terminated the address range table. */
6006 size += 2 * DWARF2_ADDR_SIZE;
6007 return size;
6010 /* Select the encoding of an attribute value. */
6012 static enum dwarf_form
6013 value_format (a)
6014 dw_attr_ref a;
6016 switch (a->dw_attr_val.val_class)
6018 case dw_val_class_addr:
6019 return DW_FORM_addr;
6020 case dw_val_class_range_list:
6021 case dw_val_class_offset:
6022 if (DWARF_OFFSET_SIZE == 4)
6023 return DW_FORM_data4;
6024 if (DWARF_OFFSET_SIZE == 8)
6025 return DW_FORM_data8;
6026 abort ();
6027 case dw_val_class_loc_list:
6028 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
6029 .debug_loc section */
6030 return DW_FORM_data4;
6031 case dw_val_class_loc:
6032 switch (constant_size (size_of_locs (AT_loc (a))))
6034 case 1:
6035 return DW_FORM_block1;
6036 case 2:
6037 return DW_FORM_block2;
6038 default:
6039 abort ();
6041 case dw_val_class_const:
6042 return DW_FORM_sdata;
6043 case dw_val_class_unsigned_const:
6044 switch (constant_size (AT_unsigned (a)))
6046 case 1:
6047 return DW_FORM_data1;
6048 case 2:
6049 return DW_FORM_data2;
6050 case 4:
6051 return DW_FORM_data4;
6052 case 8:
6053 return DW_FORM_data8;
6054 default:
6055 abort ();
6057 case dw_val_class_long_long:
6058 return DW_FORM_block1;
6059 case dw_val_class_float:
6060 return DW_FORM_block1;
6061 case dw_val_class_flag:
6062 return DW_FORM_flag;
6063 case dw_val_class_die_ref:
6064 if (AT_ref_external (a))
6065 return DW_FORM_ref_addr;
6066 else
6067 return DW_FORM_ref;
6068 case dw_val_class_fde_ref:
6069 return DW_FORM_data;
6070 case dw_val_class_lbl_id:
6071 return DW_FORM_addr;
6072 case dw_val_class_lbl_offset:
6073 return DW_FORM_data;
6074 case dw_val_class_str:
6075 return AT_string_form (a);
6077 default:
6078 abort ();
6082 /* Output the encoding of an attribute value. */
6084 static void
6085 output_value_format (a)
6086 dw_attr_ref a;
6088 enum dwarf_form form = value_format (a);
6090 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
6093 /* Output the .debug_abbrev section which defines the DIE abbreviation
6094 table. */
6096 static void
6097 output_abbrev_section ()
6099 unsigned long abbrev_id;
6101 dw_attr_ref a_attr;
6103 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
6105 dw_die_ref abbrev = abbrev_die_table[abbrev_id];
6107 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
6108 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
6109 dwarf_tag_name (abbrev->die_tag));
6111 if (abbrev->die_child != NULL)
6112 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
6113 else
6114 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
6116 for (a_attr = abbrev->die_attr; a_attr != NULL;
6117 a_attr = a_attr->dw_attr_next)
6119 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
6120 dwarf_attr_name (a_attr->dw_attr));
6121 output_value_format (a_attr);
6124 dw2_asm_output_data (1, 0, NULL);
6125 dw2_asm_output_data (1, 0, NULL);
6128 /* Terminate the table. */
6129 dw2_asm_output_data (1, 0, NULL);
6132 /* Output a symbol we can use to refer to this DIE from another CU. */
6134 static inline void
6135 output_die_symbol (die)
6136 dw_die_ref die;
6138 char *sym = die->die_symbol;
6140 if (sym == 0)
6141 return;
6143 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
6144 /* We make these global, not weak; if the target doesn't support
6145 .linkonce, it doesn't support combining the sections, so debugging
6146 will break. */
6147 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
6149 ASM_OUTPUT_LABEL (asm_out_file, sym);
6152 /* Return a new location list, given the begin and end range, and the
6153 expression. gensym tells us whether to generate a new internal symbol for
6154 this location list node, which is done for the head of the list only. */
6156 static inline dw_loc_list_ref
6157 new_loc_list (expr, begin, end, section, gensym)
6158 dw_loc_descr_ref expr;
6159 const char *begin;
6160 const char *end;
6161 const char *section;
6162 unsigned gensym;
6164 dw_loc_list_ref retlist
6165 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
6167 retlist->begin = begin;
6168 retlist->end = end;
6169 retlist->expr = expr;
6170 retlist->section = section;
6171 if (gensym)
6172 retlist->ll_symbol = gen_internal_sym ("LLST");
6174 return retlist;
6177 /* Add a location description expression to a location list */
6179 static inline void
6180 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
6181 dw_loc_list_ref *list_head;
6182 dw_loc_descr_ref descr;
6183 const char *begin;
6184 const char *end;
6185 const char *section;
6187 dw_loc_list_ref *d;
6189 /* Find the end of the chain. */
6190 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
6193 /* Add a new location list node to the list */
6194 *d = new_loc_list (descr, begin, end, section, 0);
6197 /* Output the location list given to us */
6199 static void
6200 output_loc_list (list_head)
6201 dw_loc_list_ref list_head;
6203 dw_loc_list_ref curr = list_head;
6205 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
6207 /* ??? This shouldn't be needed now that we've forced the
6208 compilation unit base address to zero when there is code
6209 in more than one section. */
6210 if (strcmp (curr->section, ".text") == 0)
6212 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
6213 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0,
6214 "Location list base address specifier fake entry");
6215 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
6216 "Location list base address specifier base");
6219 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
6221 unsigned long size;
6223 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
6224 "Location list begin address (%s)",
6225 list_head->ll_symbol);
6226 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
6227 "Location list end address (%s)",
6228 list_head->ll_symbol);
6229 size = size_of_locs (curr->expr);
6231 /* Output the block length for this list of location operations. */
6232 if (size > 0xffff)
6233 abort ();
6234 dw2_asm_output_data (2, size, "%s", "Location expression size");
6236 output_loc_sequence (curr->expr);
6239 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6240 "Location list terminator begin (%s)",
6241 list_head->ll_symbol);
6242 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6243 "Location list terminator end (%s)",
6244 list_head->ll_symbol);
6247 /* Output the DIE and its attributes. Called recursively to generate
6248 the definitions of each child DIE. */
6250 static void
6251 output_die (die)
6252 dw_die_ref die;
6254 dw_attr_ref a;
6255 dw_die_ref c;
6256 unsigned long size;
6258 /* If someone in another CU might refer to us, set up a symbol for
6259 them to point to. */
6260 if (die->die_symbol)
6261 output_die_symbol (die);
6263 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6264 die->die_offset, dwarf_tag_name (die->die_tag));
6266 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6268 const char *name = dwarf_attr_name (a->dw_attr);
6270 switch (AT_class (a))
6272 case dw_val_class_addr:
6273 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6274 break;
6276 case dw_val_class_offset:
6277 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset,
6278 "%s", name);
6279 break;
6281 case dw_val_class_range_list:
6283 char *p = strchr (ranges_section_label, '\0');
6285 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset);
6286 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label,
6287 "%s", name);
6288 *p = '\0';
6290 break;
6292 case dw_val_class_loc:
6293 size = size_of_locs (AT_loc (a));
6295 /* Output the block length for this list of location operations. */
6296 dw2_asm_output_data (constant_size (size), size, "%s", name);
6298 output_loc_sequence (AT_loc (a));
6299 break;
6301 case dw_val_class_const:
6302 /* ??? It would be slightly more efficient to use a scheme like is
6303 used for unsigned constants below, but gdb 4.x does not sign
6304 extend. Gdb 5.x does sign extend. */
6305 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6306 break;
6308 case dw_val_class_unsigned_const:
6309 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6310 AT_unsigned (a), "%s", name);
6311 break;
6313 case dw_val_class_long_long:
6315 unsigned HOST_WIDE_INT first, second;
6317 dw2_asm_output_data (1,
6318 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6319 "%s", name);
6321 if (WORDS_BIG_ENDIAN)
6323 first = a->dw_attr_val.v.val_long_long.hi;
6324 second = a->dw_attr_val.v.val_long_long.low;
6326 else
6328 first = a->dw_attr_val.v.val_long_long.low;
6329 second = a->dw_attr_val.v.val_long_long.hi;
6332 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6333 first, "long long constant");
6334 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR,
6335 second, NULL);
6337 break;
6339 case dw_val_class_float:
6341 unsigned int i;
6343 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6344 "%s", name);
6346 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++)
6347 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6348 "fp constant word %u", i);
6349 break;
6352 case dw_val_class_flag:
6353 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6354 break;
6356 case dw_val_class_loc_list:
6358 char *sym = AT_loc_list (a)->ll_symbol;
6360 if (sym == 0)
6361 abort ();
6362 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym,
6363 loc_section_label, "%s", name);
6365 break;
6367 case dw_val_class_die_ref:
6368 if (AT_ref_external (a))
6370 char *sym = AT_ref (a)->die_symbol;
6372 if (sym == 0)
6373 abort ();
6374 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6376 else if (AT_ref (a)->die_offset == 0)
6377 abort ();
6378 else
6379 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6380 "%s", name);
6381 break;
6383 case dw_val_class_fde_ref:
6385 char l1[20];
6387 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6388 a->dw_attr_val.v.val_fde_index * 2);
6389 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6391 break;
6393 case dw_val_class_lbl_id:
6394 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6395 break;
6397 case dw_val_class_lbl_offset:
6398 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6399 break;
6401 case dw_val_class_str:
6402 if (AT_string_form (a) == DW_FORM_strp)
6403 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
6404 a->dw_attr_val.v.val_str->label,
6405 "%s: \"%s\"", name, AT_string (a));
6406 else
6407 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6408 break;
6410 default:
6411 abort ();
6415 for (c = die->die_child; c != NULL; c = c->die_sib)
6416 output_die (c);
6418 /* Add null byte to terminate sibling list. */
6419 if (die->die_child != NULL)
6420 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6421 die->die_offset);
6424 /* Output the compilation unit that appears at the beginning of the
6425 .debug_info section, and precedes the DIE descriptions. */
6427 static void
6428 output_compilation_unit_header ()
6430 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6431 "Length of Compilation Unit Info");
6432 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6433 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6434 "Offset Into Abbrev. Section");
6435 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6438 /* Output the compilation unit DIE and its children. */
6440 static void
6441 output_comp_unit (die)
6442 dw_die_ref die;
6444 const char *secname;
6446 /* Even if there are no children of this DIE, we must output the information
6447 about the compilation unit. Otherwise, on an empty translation unit, we
6448 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
6449 will then complain when examining the file. First mark all the DIEs in
6450 this CU so we know which get local refs. */
6451 mark_dies (die);
6453 build_abbrev_table (die);
6455 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6456 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6457 calc_die_sizes (die);
6459 if (die->die_symbol)
6461 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6463 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6464 secname = tmp;
6465 die->die_symbol = NULL;
6467 else
6468 secname = (const char *) DEBUG_INFO_SECTION;
6470 /* Output debugging information. */
6471 named_section_flags (secname, SECTION_DEBUG);
6472 output_compilation_unit_header ();
6473 output_die (die);
6475 /* Leave the marks on the main CU, so we can check them in
6476 output_pubnames. */
6477 if (die->die_symbol)
6478 unmark_dies (die);
6481 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6482 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6483 argument list, and maybe the scope. */
6485 static const char *
6486 dwarf2_name (decl, scope)
6487 tree decl;
6488 int scope;
6490 return (*decl_printable_name) (decl, scope ? 1 : 0);
6493 /* Add a new entry to .debug_pubnames if appropriate. */
6495 static void
6496 add_pubname (decl, die)
6497 tree decl;
6498 dw_die_ref die;
6500 pubname_ref p;
6502 if (! TREE_PUBLIC (decl))
6503 return;
6505 if (pubname_table_in_use == pubname_table_allocated)
6507 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6508 pubname_table
6509 = (pubname_ref) xrealloc (pubname_table,
6510 (pubname_table_allocated
6511 * sizeof (pubname_entry)));
6514 p = &pubname_table[pubname_table_in_use++];
6515 p->die = die;
6516 p->name = xstrdup (dwarf2_name (decl, 1));
6519 /* Output the public names table used to speed up access to externally
6520 visible names. For now, only generate entries for externally
6521 visible procedures. */
6523 static void
6524 output_pubnames ()
6526 unsigned i;
6527 unsigned long pubnames_length = size_of_pubnames ();
6529 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6530 "Length of Public Names Info");
6531 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6532 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6533 "Offset of Compilation Unit Info");
6534 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6535 "Compilation Unit Length");
6537 for (i = 0; i < pubname_table_in_use; i++)
6539 pubname_ref pub = &pubname_table[i];
6541 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6542 if (pub->die->die_mark == 0)
6543 abort ();
6545 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6546 "DIE offset");
6548 dw2_asm_output_nstring (pub->name, -1, "external name");
6551 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6554 /* Add a new entry to .debug_aranges if appropriate. */
6556 static void
6557 add_arange (decl, die)
6558 tree decl;
6559 dw_die_ref die;
6561 if (! DECL_SECTION_NAME (decl))
6562 return;
6564 if (arange_table_in_use == arange_table_allocated)
6566 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6567 arange_table = (dw_die_ref *)
6568 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref));
6571 arange_table[arange_table_in_use++] = die;
6574 /* Output the information that goes into the .debug_aranges table.
6575 Namely, define the beginning and ending address range of the
6576 text section generated for this compilation unit. */
6578 static void
6579 output_aranges ()
6581 unsigned i;
6582 unsigned long aranges_length = size_of_aranges ();
6584 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6585 "Length of Address Ranges Info");
6586 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6587 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6588 "Offset of Compilation Unit Info");
6589 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6590 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6592 /* We need to align to twice the pointer size here. */
6593 if (DWARF_ARANGES_PAD_SIZE)
6595 /* Pad using a 2 byte words so that padding is correct for any
6596 pointer size. */
6597 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6598 2 * DWARF2_ADDR_SIZE);
6599 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6600 dw2_asm_output_data (2, 0, NULL);
6603 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6604 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6605 text_section_label, "Length");
6607 for (i = 0; i < arange_table_in_use; i++)
6609 dw_die_ref die = arange_table[i];
6611 /* We shouldn't see aranges for DIEs outside of the main CU. */
6612 if (die->die_mark == 0)
6613 abort ();
6615 if (die->die_tag == DW_TAG_subprogram)
6617 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6618 "Address");
6619 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6620 get_AT_low_pc (die), "Length");
6622 else
6624 /* A static variable; extract the symbol from DW_AT_location.
6625 Note that this code isn't currently hit, as we only emit
6626 aranges for functions (jason 9/23/99). */
6627 dw_attr_ref a = get_AT (die, DW_AT_location);
6628 dw_loc_descr_ref loc;
6630 if (! a || AT_class (a) != dw_val_class_loc)
6631 abort ();
6633 loc = AT_loc (a);
6634 if (loc->dw_loc_opc != DW_OP_addr)
6635 abort ();
6637 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6638 loc->dw_loc_oprnd1.v.val_addr, "Address");
6639 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6640 get_AT_unsigned (die, DW_AT_byte_size),
6641 "Length");
6645 /* Output the terminator words. */
6646 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6647 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6650 /* Add a new entry to .debug_ranges. Return the offset at which it
6651 was placed. */
6653 static unsigned int
6654 add_ranges (block)
6655 tree block;
6657 unsigned int in_use = ranges_table_in_use;
6659 if (in_use == ranges_table_allocated)
6661 ranges_table_allocated += RANGES_TABLE_INCREMENT;
6662 ranges_table = (dw_ranges_ref)
6663 xrealloc (ranges_table, (ranges_table_allocated
6664 * sizeof (struct dw_ranges_struct)));
6667 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0);
6668 ranges_table_in_use = in_use + 1;
6670 return in_use * 2 * DWARF2_ADDR_SIZE;
6673 static void
6674 output_ranges ()
6676 unsigned i;
6677 static const char *const start_fmt = "Offset 0x%x";
6678 const char *fmt = start_fmt;
6680 for (i = 0; i < ranges_table_in_use; i++)
6682 int block_num = ranges_table[i].block_num;
6684 if (block_num)
6686 char blabel[MAX_ARTIFICIAL_LABEL_BYTES];
6687 char elabel[MAX_ARTIFICIAL_LABEL_BYTES];
6689 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num);
6690 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num);
6692 /* If all code is in the text section, then the compilation
6693 unit base address defaults to DW_AT_low_pc, which is the
6694 base of the text section. */
6695 if (separate_line_info_table_in_use == 0)
6697 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel,
6698 text_section_label,
6699 fmt, i * 2 * DWARF2_ADDR_SIZE);
6700 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel,
6701 text_section_label, NULL);
6704 /* Otherwise, we add a DW_AT_entry_pc attribute to force the
6705 compilation unit base address to zero, which allows us to
6706 use absolute addresses, and not worry about whether the
6707 target supports cross-section arithmetic. */
6708 else
6710 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel,
6711 fmt, i * 2 * DWARF2_ADDR_SIZE);
6712 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL);
6715 fmt = NULL;
6717 else
6719 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6720 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6721 fmt = start_fmt;
6726 /* Data structure containing information about input files. */
6727 struct file_info
6729 char *path; /* Complete file name. */
6730 char *fname; /* File name part. */
6731 int length; /* Length of entire string. */
6732 int file_idx; /* Index in input file table. */
6733 int dir_idx; /* Index in directory table. */
6736 /* Data structure containing information about directories with source
6737 files. */
6738 struct dir_info
6740 char *path; /* Path including directory name. */
6741 int length; /* Path length. */
6742 int prefix; /* Index of directory entry which is a prefix. */
6743 int count; /* Number of files in this directory. */
6744 int dir_idx; /* Index of directory used as base. */
6745 int used; /* Used in the end? */
6748 /* Callback function for file_info comparison. We sort by looking at
6749 the directories in the path. */
6751 static int
6752 file_info_cmp (p1, p2)
6753 const void *p1;
6754 const void *p2;
6756 const struct file_info *s1 = p1;
6757 const struct file_info *s2 = p2;
6758 unsigned char *cp1;
6759 unsigned char *cp2;
6761 /* Take care of file names without directories. We need to make sure that
6762 we return consistent values to qsort since some will get confused if
6763 we return the same value when identical operands are passed in opposite
6764 orders. So if neither has a directory, return 0 and otherwise return
6765 1 or -1 depending on which one has the directory. */
6766 if ((s1->path == s1->fname || s2->path == s2->fname))
6767 return (s2->path == s2->fname) - (s1->path == s1->fname);
6769 cp1 = (unsigned char *) s1->path;
6770 cp2 = (unsigned char *) s2->path;
6772 while (1)
6774 ++cp1;
6775 ++cp2;
6776 /* Reached the end of the first path? If so, handle like above. */
6777 if ((cp1 == (unsigned char *) s1->fname)
6778 || (cp2 == (unsigned char *) s2->fname))
6779 return ((cp2 == (unsigned char *) s2->fname)
6780 - (cp1 == (unsigned char *) s1->fname));
6782 /* Character of current path component the same? */
6783 else if (*cp1 != *cp2)
6784 return *cp1 - *cp2;
6788 /* Output the directory table and the file name table. We try to minimize
6789 the total amount of memory needed. A heuristic is used to avoid large
6790 slowdowns with many input files. */
6792 static void
6793 output_file_names ()
6795 struct file_info *files;
6796 struct dir_info *dirs;
6797 int *saved;
6798 int *savehere;
6799 int *backmap;
6800 int ndirs;
6801 int idx_offset;
6802 int i;
6803 int idx;
6805 /* Allocate the various arrays we need. */
6806 files = (struct file_info *) alloca (file_table.in_use
6807 * sizeof (struct file_info));
6808 dirs = (struct dir_info *) alloca (file_table.in_use
6809 * sizeof (struct dir_info));
6811 /* Sort the file names. */
6812 for (i = 1; i < (int) file_table.in_use; i++)
6814 char *f;
6816 /* Skip all leading "./". */
6817 f = file_table.table[i];
6818 while (f[0] == '.' && f[1] == '/')
6819 f += 2;
6821 /* Create a new array entry. */
6822 files[i].path = f;
6823 files[i].length = strlen (f);
6824 files[i].file_idx = i;
6826 /* Search for the file name part. */
6827 f = strrchr (f, '/');
6828 files[i].fname = f == NULL ? files[i].path : f + 1;
6831 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6833 /* Find all the different directories used. */
6834 dirs[0].path = files[1].path;
6835 dirs[0].length = files[1].fname - files[1].path;
6836 dirs[0].prefix = -1;
6837 dirs[0].count = 1;
6838 dirs[0].dir_idx = 0;
6839 dirs[0].used = 0;
6840 files[1].dir_idx = 0;
6841 ndirs = 1;
6843 for (i = 2; i < (int) file_table.in_use; i++)
6844 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6845 && memcmp (dirs[ndirs - 1].path, files[i].path,
6846 dirs[ndirs - 1].length) == 0)
6848 /* Same directory as last entry. */
6849 files[i].dir_idx = ndirs - 1;
6850 ++dirs[ndirs - 1].count;
6852 else
6854 int j;
6856 /* This is a new directory. */
6857 dirs[ndirs].path = files[i].path;
6858 dirs[ndirs].length = files[i].fname - files[i].path;
6859 dirs[ndirs].count = 1;
6860 dirs[ndirs].dir_idx = ndirs;
6861 dirs[ndirs].used = 0;
6862 files[i].dir_idx = ndirs;
6864 /* Search for a prefix. */
6865 dirs[ndirs].prefix = -1;
6866 for (j = 0; j < ndirs; j++)
6867 if (dirs[j].length < dirs[ndirs].length
6868 && dirs[j].length > 1
6869 && (dirs[ndirs].prefix == -1
6870 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6871 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6872 dirs[ndirs].prefix = j;
6874 ++ndirs;
6877 /* Now to the actual work. We have to find a subset of the directories which
6878 allow expressing the file name using references to the directory table
6879 with the least amount of characters. We do not do an exhaustive search
6880 where we would have to check out every combination of every single
6881 possible prefix. Instead we use a heuristic which provides nearly optimal
6882 results in most cases and never is much off. */
6883 saved = (int *) alloca (ndirs * sizeof (int));
6884 savehere = (int *) alloca (ndirs * sizeof (int));
6886 memset (saved, '\0', ndirs * sizeof (saved[0]));
6887 for (i = 0; i < ndirs; i++)
6889 int j;
6890 int total;
6892 /* We can always save some space for the current directory. But this
6893 does not mean it will be enough to justify adding the directory. */
6894 savehere[i] = dirs[i].length;
6895 total = (savehere[i] - saved[i]) * dirs[i].count;
6897 for (j = i + 1; j < ndirs; j++)
6899 savehere[j] = 0;
6900 if (saved[j] < dirs[i].length)
6902 /* Determine whether the dirs[i] path is a prefix of the
6903 dirs[j] path. */
6904 int k;
6906 k = dirs[j].prefix;
6907 while (k != -1 && k != i)
6908 k = dirs[k].prefix;
6910 if (k == i)
6912 /* Yes it is. We can possibly safe some memory but
6913 writing the filenames in dirs[j] relative to
6914 dirs[i]. */
6915 savehere[j] = dirs[i].length;
6916 total += (savehere[j] - saved[j]) * dirs[j].count;
6921 /* Check whether we can safe enough to justify adding the dirs[i]
6922 directory. */
6923 if (total > dirs[i].length + 1)
6925 /* It's worthwhile adding. */
6926 for (j = i; j < ndirs; j++)
6927 if (savehere[j] > 0)
6929 /* Remember how much we saved for this directory so far. */
6930 saved[j] = savehere[j];
6932 /* Remember the prefix directory. */
6933 dirs[j].dir_idx = i;
6938 /* We have to emit them in the order they appear in the file_table array
6939 since the index is used in the debug info generation. To do this
6940 efficiently we generate a back-mapping of the indices first. */
6941 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6942 for (i = 1; i < (int) file_table.in_use; i++)
6944 backmap[files[i].file_idx] = i;
6946 /* Mark this directory as used. */
6947 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6950 /* That was it. We are ready to emit the information. First emit the
6951 directory name table. We have to make sure the first actually emitted
6952 directory name has index one; zero is reserved for the current working
6953 directory. Make sure we do not confuse these indices with the one for the
6954 constructed table (even though most of the time they are identical). */
6955 idx = 1;
6956 idx_offset = dirs[0].length > 0 ? 1 : 0;
6957 for (i = 1 - idx_offset; i < ndirs; i++)
6958 if (dirs[i].used != 0)
6960 dirs[i].used = idx++;
6961 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6962 "Directory Entry: 0x%x", dirs[i].used);
6965 dw2_asm_output_data (1, 0, "End directory table");
6967 /* Correct the index for the current working directory entry if it
6968 exists. */
6969 if (idx_offset == 0)
6970 dirs[0].used = 0;
6972 /* Now write all the file names. */
6973 for (i = 1; i < (int) file_table.in_use; i++)
6975 int file_idx = backmap[i];
6976 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6978 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6979 "File Entry: 0x%x", i);
6981 /* Include directory index. */
6982 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6984 /* Modification time. */
6985 dw2_asm_output_data_uleb128 (0, NULL);
6987 /* File length in bytes. */
6988 dw2_asm_output_data_uleb128 (0, NULL);
6991 dw2_asm_output_data (1, 0, "End file name table");
6995 /* Output the source line number correspondence information. This
6996 information goes into the .debug_line section. */
6998 static void
6999 output_line_info ()
7001 char l1[20], l2[20], p1[20], p2[20];
7002 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7003 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
7004 unsigned opc;
7005 unsigned n_op_args;
7006 unsigned long lt_index;
7007 unsigned long current_line;
7008 long line_offset;
7009 long line_delta;
7010 unsigned long current_file;
7011 unsigned long function;
7013 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
7014 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
7015 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
7016 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
7018 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
7019 "Length of Source Line Info");
7020 ASM_OUTPUT_LABEL (asm_out_file, l1);
7022 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
7023 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
7024 ASM_OUTPUT_LABEL (asm_out_file, p1);
7026 /* Define the architecture-dependent minimum instruction length (in
7027 bytes). In this implementation of DWARF, this field is used for
7028 information purposes only. Since GCC generates assembly language,
7029 we have no a priori knowledge of how many instruction bytes are
7030 generated for each source line, and therefore can use only the
7031 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information
7032 commands. Accordingly, we fix this as `1', which is "correct
7033 enough" for all architectures, and don't let the target override. */
7034 dw2_asm_output_data (1, 1,
7035 "Minimum Instruction Length");
7037 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
7038 "Default is_stmt_start flag");
7039 dw2_asm_output_data (1, DWARF_LINE_BASE,
7040 "Line Base Value (Special Opcodes)");
7041 dw2_asm_output_data (1, DWARF_LINE_RANGE,
7042 "Line Range Value (Special Opcodes)");
7043 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
7044 "Special Opcode Base");
7046 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++)
7048 switch (opc)
7050 case DW_LNS_advance_pc:
7051 case DW_LNS_advance_line:
7052 case DW_LNS_set_file:
7053 case DW_LNS_set_column:
7054 case DW_LNS_fixed_advance_pc:
7055 n_op_args = 1;
7056 break;
7057 default:
7058 n_op_args = 0;
7059 break;
7062 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
7063 opc, n_op_args);
7066 /* Write out the information about the files we use. */
7067 output_file_names ();
7068 ASM_OUTPUT_LABEL (asm_out_file, p2);
7070 /* We used to set the address register to the first location in the text
7071 section here, but that didn't accomplish anything since we already
7072 have a line note for the opening brace of the first function. */
7074 /* Generate the line number to PC correspondence table, encoded as
7075 a series of state machine operations. */
7076 current_file = 1;
7077 current_line = 1;
7078 strcpy (prev_line_label, text_section_label);
7079 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
7081 dw_line_info_ref line_info = &line_info_table[lt_index];
7083 #if 0
7084 /* Disable this optimization for now; GDB wants to see two line notes
7085 at the beginning of a function so it can find the end of the
7086 prologue. */
7088 /* Don't emit anything for redundant notes. Just updating the
7089 address doesn't accomplish anything, because we already assume
7090 that anything after the last address is this line. */
7091 if (line_info->dw_line_num == current_line
7092 && line_info->dw_file_num == current_file)
7093 continue;
7094 #endif
7096 /* Emit debug info for the address of the current line.
7098 Unfortunately, we have little choice here currently, and must always
7099 use the most general form. GCC does not know the address delta
7100 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
7101 attributes which will give an upper bound on the address range. We
7102 could perhaps use length attributes to determine when it is safe to
7103 use DW_LNS_fixed_advance_pc. */
7105 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
7106 if (0)
7108 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
7109 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7110 "DW_LNS_fixed_advance_pc");
7111 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7113 else
7115 /* This can handle any delta. This takes
7116 4+DWARF2_ADDR_SIZE bytes. */
7117 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7118 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7119 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7120 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7123 strcpy (prev_line_label, line_label);
7125 /* Emit debug info for the source file of the current line, if
7126 different from the previous line. */
7127 if (line_info->dw_file_num != current_file)
7129 current_file = line_info->dw_file_num;
7130 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7131 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7132 file_table.table[current_file]);
7135 /* Emit debug info for the current line number, choosing the encoding
7136 that uses the least amount of space. */
7137 if (line_info->dw_line_num != current_line)
7139 line_offset = line_info->dw_line_num - current_line;
7140 line_delta = line_offset - DWARF_LINE_BASE;
7141 current_line = line_info->dw_line_num;
7142 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7143 /* This can handle deltas from -10 to 234, using the current
7144 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
7145 takes 1 byte. */
7146 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7147 "line %lu", current_line);
7148 else
7150 /* This can handle any delta. This takes at least 4 bytes,
7151 depending on the value being encoded. */
7152 dw2_asm_output_data (1, DW_LNS_advance_line,
7153 "advance to line %lu", current_line);
7154 dw2_asm_output_data_sleb128 (line_offset, NULL);
7155 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7158 else
7159 /* We still need to start a new row, so output a copy insn. */
7160 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7163 /* Emit debug info for the address of the end of the function. */
7164 if (0)
7166 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7167 "DW_LNS_fixed_advance_pc");
7168 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
7170 else
7172 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7173 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7174 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7175 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
7178 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7179 dw2_asm_output_data_uleb128 (1, NULL);
7180 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7182 function = 0;
7183 current_file = 1;
7184 current_line = 1;
7185 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
7187 dw_separate_line_info_ref line_info
7188 = &separate_line_info_table[lt_index];
7190 #if 0
7191 /* Don't emit anything for redundant notes. */
7192 if (line_info->dw_line_num == current_line
7193 && line_info->dw_file_num == current_file
7194 && line_info->function == function)
7195 goto cont;
7196 #endif
7198 /* Emit debug info for the address of the current line. If this is
7199 a new function, or the first line of a function, then we need
7200 to handle it differently. */
7201 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
7202 lt_index);
7203 if (function != line_info->function)
7205 function = line_info->function;
7207 /* Set the address register to the first line in the function */
7208 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7209 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7210 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7211 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7213 else
7215 /* ??? See the DW_LNS_advance_pc comment above. */
7216 if (0)
7218 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7219 "DW_LNS_fixed_advance_pc");
7220 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7222 else
7224 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7225 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7226 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7227 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7231 strcpy (prev_line_label, line_label);
7233 /* Emit debug info for the source file of the current line, if
7234 different from the previous line. */
7235 if (line_info->dw_file_num != current_file)
7237 current_file = line_info->dw_file_num;
7238 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
7239 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
7240 file_table.table[current_file]);
7243 /* Emit debug info for the current line number, choosing the encoding
7244 that uses the least amount of space. */
7245 if (line_info->dw_line_num != current_line)
7247 line_offset = line_info->dw_line_num - current_line;
7248 line_delta = line_offset - DWARF_LINE_BASE;
7249 current_line = line_info->dw_line_num;
7250 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
7251 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
7252 "line %lu", current_line);
7253 else
7255 dw2_asm_output_data (1, DW_LNS_advance_line,
7256 "advance to line %lu", current_line);
7257 dw2_asm_output_data_sleb128 (line_offset, NULL);
7258 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7261 else
7262 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
7264 #if 0
7265 cont:
7266 #endif
7268 lt_index++;
7270 /* If we're done with a function, end its sequence. */
7271 if (lt_index == separate_line_info_table_in_use
7272 || separate_line_info_table[lt_index].function != function)
7274 current_file = 1;
7275 current_line = 1;
7277 /* Emit debug info for the address of the end of the function. */
7278 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
7279 if (0)
7281 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
7282 "DW_LNS_fixed_advance_pc");
7283 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
7285 else
7287 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
7288 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
7289 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
7290 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
7293 /* Output the marker for the end of this sequence. */
7294 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
7295 dw2_asm_output_data_uleb128 (1, NULL);
7296 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
7300 /* Output the marker for the end of the line number info. */
7301 ASM_OUTPUT_LABEL (asm_out_file, l2);
7304 /* Given a pointer to a tree node for some base type, return a pointer to
7305 a DIE that describes the given type.
7307 This routine must only be called for GCC type nodes that correspond to
7308 Dwarf base (fundamental) types. */
7310 static dw_die_ref
7311 base_type_die (type)
7312 tree type;
7314 dw_die_ref base_type_result;
7315 const char *type_name;
7316 enum dwarf_type encoding;
7317 tree name = TYPE_NAME (type);
7319 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE)
7320 return 0;
7322 if (name)
7324 if (TREE_CODE (name) == TYPE_DECL)
7325 name = DECL_NAME (name);
7327 type_name = IDENTIFIER_POINTER (name);
7329 else
7330 type_name = "__unknown__";
7332 switch (TREE_CODE (type))
7334 case INTEGER_TYPE:
7335 /* Carefully distinguish the C character types, without messing
7336 up if the language is not C. Note that we check only for the names
7337 that contain spaces; other names might occur by coincidence in other
7338 languages. */
7339 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7340 && (type == char_type_node
7341 || ! strcmp (type_name, "signed char")
7342 || ! strcmp (type_name, "unsigned char"))))
7344 if (TREE_UNSIGNED (type))
7345 encoding = DW_ATE_unsigned;
7346 else
7347 encoding = DW_ATE_signed;
7348 break;
7350 /* else fall through. */
7352 case CHAR_TYPE:
7353 /* GNU Pascal/Ada CHAR type. Not used in C. */
7354 if (TREE_UNSIGNED (type))
7355 encoding = DW_ATE_unsigned_char;
7356 else
7357 encoding = DW_ATE_signed_char;
7358 break;
7360 case REAL_TYPE:
7361 encoding = DW_ATE_float;
7362 break;
7364 /* Dwarf2 doesn't know anything about complex ints, so use
7365 a user defined type for it. */
7366 case COMPLEX_TYPE:
7367 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7368 encoding = DW_ATE_complex_float;
7369 else
7370 encoding = DW_ATE_lo_user;
7371 break;
7373 case BOOLEAN_TYPE:
7374 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7375 encoding = DW_ATE_boolean;
7376 break;
7378 default:
7379 /* No other TREE_CODEs are Dwarf fundamental types. */
7380 abort ();
7383 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type);
7384 if (demangle_name_func)
7385 type_name = (*demangle_name_func) (type_name);
7387 add_AT_string (base_type_result, DW_AT_name, type_name);
7388 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7389 int_size_in_bytes (type));
7390 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7392 return base_type_result;
7395 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7396 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7397 a given type is generally the same as the given type, except that if the
7398 given type is a pointer or reference type, then the root type of the given
7399 type is the root type of the "basis" type for the pointer or reference
7400 type. (This definition of the "root" type is recursive.) Also, the root
7401 type of a `const' qualified type or a `volatile' qualified type is the
7402 root type of the given type without the qualifiers. */
7404 static tree
7405 root_type (type)
7406 tree type;
7408 if (TREE_CODE (type) == ERROR_MARK)
7409 return error_mark_node;
7411 switch (TREE_CODE (type))
7413 case ERROR_MARK:
7414 return error_mark_node;
7416 case POINTER_TYPE:
7417 case REFERENCE_TYPE:
7418 return type_main_variant (root_type (TREE_TYPE (type)));
7420 default:
7421 return type_main_variant (type);
7425 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7426 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7428 static inline int
7429 is_base_type (type)
7430 tree type;
7432 switch (TREE_CODE (type))
7434 case ERROR_MARK:
7435 case VOID_TYPE:
7436 case INTEGER_TYPE:
7437 case REAL_TYPE:
7438 case COMPLEX_TYPE:
7439 case BOOLEAN_TYPE:
7440 case CHAR_TYPE:
7441 return 1;
7443 case SET_TYPE:
7444 case ARRAY_TYPE:
7445 case RECORD_TYPE:
7446 case UNION_TYPE:
7447 case QUAL_UNION_TYPE:
7448 case ENUMERAL_TYPE:
7449 case FUNCTION_TYPE:
7450 case METHOD_TYPE:
7451 case POINTER_TYPE:
7452 case REFERENCE_TYPE:
7453 case FILE_TYPE:
7454 case OFFSET_TYPE:
7455 case LANG_TYPE:
7456 case VECTOR_TYPE:
7457 return 0;
7459 default:
7460 abort ();
7463 return 0;
7466 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7467 entry that chains various modifiers in front of the given type. */
7469 static dw_die_ref
7470 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7471 tree type;
7472 int is_const_type;
7473 int is_volatile_type;
7474 dw_die_ref context_die;
7476 enum tree_code code = TREE_CODE (type);
7477 dw_die_ref mod_type_die = NULL;
7478 dw_die_ref sub_die = NULL;
7479 tree item_type = NULL;
7481 if (code != ERROR_MARK)
7483 tree qualified_type;
7485 /* See if we already have the appropriately qualified variant of
7486 this type. */
7487 qualified_type
7488 = get_qualified_type (type,
7489 ((is_const_type ? TYPE_QUAL_CONST : 0)
7490 | (is_volatile_type
7491 ? TYPE_QUAL_VOLATILE : 0)));
7493 /* If we do, then we can just use its DIE, if it exists. */
7494 if (qualified_type)
7496 mod_type_die = lookup_type_die (qualified_type);
7497 if (mod_type_die)
7498 return mod_type_die;
7501 /* Handle C typedef types. */
7502 if (qualified_type && TYPE_NAME (qualified_type)
7503 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7504 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7506 tree type_name = TYPE_NAME (qualified_type);
7507 tree dtype = TREE_TYPE (type_name);
7509 if (qualified_type == dtype)
7511 /* For a named type, use the typedef. */
7512 gen_type_die (qualified_type, context_die);
7513 mod_type_die = lookup_type_die (qualified_type);
7515 else if (is_const_type < TYPE_READONLY (dtype)
7516 || is_volatile_type < TYPE_VOLATILE (dtype))
7517 /* cv-unqualified version of named type. Just use the unnamed
7518 type to which it refers. */
7519 mod_type_die
7520 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7521 is_const_type, is_volatile_type,
7522 context_die);
7524 /* Else cv-qualified version of named type; fall through. */
7527 if (mod_type_die)
7528 /* OK. */
7530 else if (is_const_type)
7532 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type);
7533 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7535 else if (is_volatile_type)
7537 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type);
7538 sub_die = modified_type_die (type, 0, 0, context_die);
7540 else if (code == POINTER_TYPE)
7542 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type);
7543 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7544 #if 0
7545 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7546 #endif
7547 item_type = TREE_TYPE (type);
7549 else if (code == REFERENCE_TYPE)
7551 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type);
7552 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7553 #if 0
7554 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7555 #endif
7556 item_type = TREE_TYPE (type);
7558 else if (is_base_type (type))
7559 mod_type_die = base_type_die (type);
7560 else
7562 gen_type_die (type, context_die);
7564 /* We have to get the type_main_variant here (and pass that to the
7565 `lookup_type_die' routine) because the ..._TYPE node we have
7566 might simply be a *copy* of some original type node (where the
7567 copy was created to help us keep track of typedef names) and
7568 that copy might have a different TYPE_UID from the original
7569 ..._TYPE node. */
7570 mod_type_die = lookup_type_die (type_main_variant (type));
7571 if (mod_type_die == NULL)
7572 abort ();
7575 /* We want to equate the qualified type to the die below. */
7576 type = qualified_type;
7579 if (type)
7580 equate_type_number_to_die (type, mod_type_die);
7581 if (item_type)
7582 /* We must do this after the equate_type_number_to_die call, in case
7583 this is a recursive type. This ensures that the modified_type_die
7584 recursion will terminate even if the type is recursive. Recursive
7585 types are possible in Ada. */
7586 sub_die = modified_type_die (item_type,
7587 TYPE_READONLY (item_type),
7588 TYPE_VOLATILE (item_type),
7589 context_die);
7591 if (sub_die != NULL)
7592 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7594 return mod_type_die;
7597 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7598 an enumerated type. */
7600 static inline int
7601 type_is_enum (type)
7602 tree type;
7604 return TREE_CODE (type) == ENUMERAL_TYPE;
7607 /* Return the register number described by a given RTL node. */
7609 static unsigned int
7610 reg_number (rtl)
7611 rtx rtl;
7613 unsigned regno = REGNO (rtl);
7615 if (regno >= FIRST_PSEUDO_REGISTER)
7616 abort ();
7618 return DBX_REGISTER_NUMBER (regno);
7621 /* Return a location descriptor that designates a machine register or
7622 zero if there is no such. */
7624 static dw_loc_descr_ref
7625 reg_loc_descriptor (rtl)
7626 rtx rtl;
7628 dw_loc_descr_ref loc_result = NULL;
7629 unsigned reg;
7631 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
7632 return 0;
7634 reg = reg_number (rtl);
7635 if (reg <= 31)
7636 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7637 else
7638 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7640 return loc_result;
7643 /* Return a location descriptor that designates a constant. */
7645 static dw_loc_descr_ref
7646 int_loc_descriptor (i)
7647 HOST_WIDE_INT i;
7649 enum dwarf_location_atom op;
7651 /* Pick the smallest representation of a constant, rather than just
7652 defaulting to the LEB encoding. */
7653 if (i >= 0)
7655 if (i <= 31)
7656 op = DW_OP_lit0 + i;
7657 else if (i <= 0xff)
7658 op = DW_OP_const1u;
7659 else if (i <= 0xffff)
7660 op = DW_OP_const2u;
7661 else if (HOST_BITS_PER_WIDE_INT == 32
7662 || i <= 0xffffffff)
7663 op = DW_OP_const4u;
7664 else
7665 op = DW_OP_constu;
7667 else
7669 if (i >= -0x80)
7670 op = DW_OP_const1s;
7671 else if (i >= -0x8000)
7672 op = DW_OP_const2s;
7673 else if (HOST_BITS_PER_WIDE_INT == 32
7674 || i >= -0x80000000)
7675 op = DW_OP_const4s;
7676 else
7677 op = DW_OP_consts;
7680 return new_loc_descr (op, i, 0);
7683 /* Return a location descriptor that designates a base+offset location. */
7685 static dw_loc_descr_ref
7686 based_loc_descr (reg, offset)
7687 unsigned reg;
7688 long int offset;
7690 dw_loc_descr_ref loc_result;
7691 /* For the "frame base", we use the frame pointer or stack pointer
7692 registers, since the RTL for local variables is relative to one of
7693 them. */
7694 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7695 ? HARD_FRAME_POINTER_REGNUM
7696 : STACK_POINTER_REGNUM);
7698 if (reg == fp_reg)
7699 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7700 else if (reg <= 31)
7701 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7702 else
7703 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7705 return loc_result;
7708 /* Return true if this RTL expression describes a base+offset calculation. */
7710 static inline int
7711 is_based_loc (rtl)
7712 rtx rtl;
7714 return (GET_CODE (rtl) == PLUS
7715 && ((GET_CODE (XEXP (rtl, 0)) == REG
7716 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER
7717 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7720 /* The following routine converts the RTL for a variable or parameter
7721 (resident in memory) into an equivalent Dwarf representation of a
7722 mechanism for getting the address of that same variable onto the top of a
7723 hypothetical "address evaluation" stack.
7725 When creating memory location descriptors, we are effectively transforming
7726 the RTL for a memory-resident object into its Dwarf postfix expression
7727 equivalent. This routine recursively descends an RTL tree, turning
7728 it into Dwarf postfix code as it goes.
7730 MODE is the mode of the memory reference, needed to handle some
7731 autoincrement addressing modes.
7733 Return 0 if we can't represent the location. */
7735 static dw_loc_descr_ref
7736 mem_loc_descriptor (rtl, mode)
7737 rtx rtl;
7738 enum machine_mode mode;
7740 dw_loc_descr_ref mem_loc_result = NULL;
7742 /* Note that for a dynamically sized array, the location we will generate a
7743 description of here will be the lowest numbered location which is
7744 actually within the array. That's *not* necessarily the same as the
7745 zeroth element of the array. */
7747 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7748 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7749 #endif
7751 switch (GET_CODE (rtl))
7753 case POST_INC:
7754 case POST_DEC:
7755 case POST_MODIFY:
7756 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7757 just fall into the SUBREG code. */
7759 /* ... fall through ... */
7761 case SUBREG:
7762 /* The case of a subreg may arise when we have a local (register)
7763 variable or a formal (register) parameter which doesn't quite fill
7764 up an entire register. For now, just assume that it is
7765 legitimate to make the Dwarf info refer to the whole register which
7766 contains the given subreg. */
7767 rtl = SUBREG_REG (rtl);
7769 /* ... fall through ... */
7771 case REG:
7772 /* Whenever a register number forms a part of the description of the
7773 method for calculating the (dynamic) address of a memory resident
7774 object, DWARF rules require the register number be referred to as
7775 a "base register". This distinction is not based in any way upon
7776 what category of register the hardware believes the given register
7777 belongs to. This is strictly DWARF terminology we're dealing with
7778 here. Note that in cases where the location of a memory-resident
7779 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7780 OP_CONST (0)) the actual DWARF location descriptor that we generate
7781 may just be OP_BASEREG (basereg). This may look deceptively like
7782 the object in question was allocated to a register (rather than in
7783 memory) so DWARF consumers need to be aware of the subtle
7784 distinction between OP_REG and OP_BASEREG. */
7785 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
7786 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7787 break;
7789 case MEM:
7790 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7791 if (mem_loc_result != 0)
7792 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7793 break;
7795 case LABEL_REF:
7796 /* Some ports can transform a symbol ref into a label ref, because
7797 the symbol ref is too far away and has to be dumped into a constant
7798 pool. */
7799 case CONST:
7800 case SYMBOL_REF:
7801 /* Alternatively, the symbol in the constant pool might be referenced
7802 by a different symbol. */
7803 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl))
7805 bool marked;
7806 rtx tmp = get_pool_constant_mark (rtl, &marked);
7808 if (GET_CODE (tmp) == SYMBOL_REF)
7810 rtl = tmp;
7811 if (CONSTANT_POOL_ADDRESS_P (tmp))
7812 get_pool_constant_mark (tmp, &marked);
7813 else
7814 marked = true;
7817 /* If all references to this pool constant were optimized away,
7818 it was not output and thus we can't represent it.
7819 FIXME: might try to use DW_OP_const_value here, though
7820 DW_OP_piece complicates it. */
7821 if (!marked)
7822 return 0;
7825 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7826 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7827 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl;
7828 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
7829 break;
7831 case PRE_MODIFY:
7832 /* Extract the PLUS expression nested inside and fall into
7833 PLUS code below. */
7834 rtl = XEXP (rtl, 1);
7835 goto plus;
7837 case PRE_INC:
7838 case PRE_DEC:
7839 /* Turn these into a PLUS expression and fall into the PLUS code
7840 below. */
7841 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7842 GEN_INT (GET_CODE (rtl) == PRE_INC
7843 ? GET_MODE_UNIT_SIZE (mode)
7844 : -GET_MODE_UNIT_SIZE (mode)));
7846 /* ... fall through ... */
7848 case PLUS:
7849 plus:
7850 if (is_based_loc (rtl))
7851 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7852 INTVAL (XEXP (rtl, 1)));
7853 else
7855 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7856 if (mem_loc_result == 0)
7857 break;
7859 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7860 && INTVAL (XEXP (rtl, 1)) >= 0)
7861 add_loc_descr (&mem_loc_result,
7862 new_loc_descr (DW_OP_plus_uconst,
7863 INTVAL (XEXP (rtl, 1)), 0));
7864 else
7866 add_loc_descr (&mem_loc_result,
7867 mem_loc_descriptor (XEXP (rtl, 1), mode));
7868 add_loc_descr (&mem_loc_result,
7869 new_loc_descr (DW_OP_plus, 0, 0));
7872 break;
7874 case MULT:
7876 /* If a pseudo-reg is optimized away, it is possible for it to
7877 be replaced with a MEM containing a multiply. */
7878 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode);
7879 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode);
7881 if (op0 == 0 || op1 == 0)
7882 break;
7884 mem_loc_result = op0;
7885 add_loc_descr (&mem_loc_result, op1);
7886 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7887 break;
7890 case CONST_INT:
7891 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7892 break;
7894 case ADDRESSOF:
7895 /* If this is a MEM, return its address. Otherwise, we can't
7896 represent this. */
7897 if (GET_CODE (XEXP (rtl, 0)) == MEM)
7898 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode);
7899 else
7900 return 0;
7902 default:
7903 abort ();
7906 return mem_loc_result;
7909 /* Return a descriptor that describes the concatenation of two locations.
7910 This is typically a complex variable. */
7912 static dw_loc_descr_ref
7913 concat_loc_descriptor (x0, x1)
7914 rtx x0, x1;
7916 dw_loc_descr_ref cc_loc_result = NULL;
7917 dw_loc_descr_ref x0_ref = loc_descriptor (x0);
7918 dw_loc_descr_ref x1_ref = loc_descriptor (x1);
7920 if (x0_ref == 0 || x1_ref == 0)
7921 return 0;
7923 cc_loc_result = x0_ref;
7924 add_loc_descr (&cc_loc_result,
7925 new_loc_descr (DW_OP_piece,
7926 GET_MODE_SIZE (GET_MODE (x0)), 0));
7928 add_loc_descr (&cc_loc_result, x1_ref);
7929 add_loc_descr (&cc_loc_result,
7930 new_loc_descr (DW_OP_piece,
7931 GET_MODE_SIZE (GET_MODE (x1)), 0));
7933 return cc_loc_result;
7936 /* Output a proper Dwarf location descriptor for a variable or parameter
7937 which is either allocated in a register or in a memory location. For a
7938 register, we just generate an OP_REG and the register number. For a
7939 memory location we provide a Dwarf postfix expression describing how to
7940 generate the (dynamic) address of the object onto the address stack.
7942 If we don't know how to describe it, return 0. */
7944 static dw_loc_descr_ref
7945 loc_descriptor (rtl)
7946 rtx rtl;
7948 dw_loc_descr_ref loc_result = NULL;
7950 switch (GET_CODE (rtl))
7952 case SUBREG:
7953 /* The case of a subreg may arise when we have a local (register)
7954 variable or a formal (register) parameter which doesn't quite fill
7955 up an entire register. For now, just assume that it is
7956 legitimate to make the Dwarf info refer to the whole register which
7957 contains the given subreg. */
7958 rtl = SUBREG_REG (rtl);
7960 /* ... fall through ... */
7962 case REG:
7963 loc_result = reg_loc_descriptor (rtl);
7964 break;
7966 case MEM:
7967 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7968 break;
7970 case CONCAT:
7971 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7972 break;
7974 default:
7975 abort ();
7978 return loc_result;
7981 /* Similar, but generate the descriptor from trees instead of rtl. This comes
7982 up particularly with variable length arrays. If ADDRESSP is nonzero, we are
7983 looking for an address. Otherwise, we return a value. If we can't make a
7984 descriptor, return 0. */
7986 static dw_loc_descr_ref
7987 loc_descriptor_from_tree (loc, addressp)
7988 tree loc;
7989 int addressp;
7991 dw_loc_descr_ref ret, ret1;
7992 int indirect_p = 0;
7993 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7994 enum dwarf_location_atom op;
7996 /* ??? Most of the time we do not take proper care for sign/zero
7997 extending the values properly. Hopefully this won't be a real
7998 problem... */
8000 switch (TREE_CODE (loc))
8002 case ERROR_MARK:
8003 return 0;
8005 case WITH_RECORD_EXPR:
8006 case PLACEHOLDER_EXPR:
8007 /* This case involves extracting fields from an object to determine the
8008 position of other fields. We don't try to encode this here. The
8009 only user of this is Ada, which encodes the needed information using
8010 the names of types. */
8011 return 0;
8013 case CALL_EXPR:
8014 return 0;
8016 case ADDR_EXPR:
8017 /* We can support this only if we can look through conversions and
8018 find an INDIRECT_EXPR. */
8019 for (loc = TREE_OPERAND (loc, 0);
8020 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR
8021 || TREE_CODE (loc) == NON_LVALUE_EXPR
8022 || TREE_CODE (loc) == VIEW_CONVERT_EXPR
8023 || TREE_CODE (loc) == SAVE_EXPR;
8024 loc = TREE_OPERAND (loc, 0))
8027 return (TREE_CODE (loc) == INDIRECT_REF
8028 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp)
8029 : 0);
8031 case VAR_DECL:
8032 case PARM_DECL:
8034 rtx rtl = rtl_for_decl_location (loc);
8036 if (rtl == NULL_RTX)
8037 return 0;
8038 else if (CONSTANT_P (rtl))
8040 ret = new_loc_descr (DW_OP_addr, 0, 0);
8041 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
8042 ret->dw_loc_oprnd1.v.val_addr = rtl;
8043 indirect_p = 1;
8045 else
8047 enum machine_mode mode = GET_MODE (rtl);
8049 if (GET_CODE (rtl) == MEM)
8051 indirect_p = 1;
8052 rtl = XEXP (rtl, 0);
8055 ret = mem_loc_descriptor (rtl, mode);
8058 break;
8060 case INDIRECT_REF:
8061 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8062 indirect_p = 1;
8063 break;
8065 case COMPOUND_EXPR:
8066 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp);
8068 case NOP_EXPR:
8069 case CONVERT_EXPR:
8070 case NON_LVALUE_EXPR:
8071 case VIEW_CONVERT_EXPR:
8072 case SAVE_EXPR:
8073 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
8075 case COMPONENT_REF:
8076 case BIT_FIELD_REF:
8077 case ARRAY_REF:
8078 case ARRAY_RANGE_REF:
8080 tree obj, offset;
8081 HOST_WIDE_INT bitsize, bitpos, bytepos;
8082 enum machine_mode mode;
8083 int volatilep;
8085 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
8086 &unsignedp, &volatilep);
8088 if (obj == loc)
8089 return 0;
8091 ret = loc_descriptor_from_tree (obj, 1);
8092 if (ret == 0
8093 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0)
8094 return 0;
8096 if (offset != NULL_TREE)
8098 /* Variable offset. */
8099 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
8100 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8103 if (!addressp)
8104 indirect_p = 1;
8106 bytepos = bitpos / BITS_PER_UNIT;
8107 if (bytepos > 0)
8108 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
8109 else if (bytepos < 0)
8111 add_loc_descr (&ret, int_loc_descriptor (bytepos));
8112 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
8114 break;
8117 case INTEGER_CST:
8118 if (host_integerp (loc, 0))
8119 ret = int_loc_descriptor (tree_low_cst (loc, 0));
8120 else
8121 return 0;
8122 break;
8124 case TRUTH_AND_EXPR:
8125 case TRUTH_ANDIF_EXPR:
8126 case BIT_AND_EXPR:
8127 op = DW_OP_and;
8128 goto do_binop;
8130 case TRUTH_XOR_EXPR:
8131 case BIT_XOR_EXPR:
8132 op = DW_OP_xor;
8133 goto do_binop;
8135 case TRUTH_OR_EXPR:
8136 case TRUTH_ORIF_EXPR:
8137 case BIT_IOR_EXPR:
8138 op = DW_OP_or;
8139 goto do_binop;
8141 case TRUNC_DIV_EXPR:
8142 op = DW_OP_div;
8143 goto do_binop;
8145 case MINUS_EXPR:
8146 op = DW_OP_minus;
8147 goto do_binop;
8149 case TRUNC_MOD_EXPR:
8150 op = DW_OP_mod;
8151 goto do_binop;
8153 case MULT_EXPR:
8154 op = DW_OP_mul;
8155 goto do_binop;
8157 case LSHIFT_EXPR:
8158 op = DW_OP_shl;
8159 goto do_binop;
8161 case RSHIFT_EXPR:
8162 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
8163 goto do_binop;
8165 case PLUS_EXPR:
8166 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
8167 && host_integerp (TREE_OPERAND (loc, 1), 0))
8169 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8170 if (ret == 0)
8171 return 0;
8173 add_loc_descr (&ret,
8174 new_loc_descr (DW_OP_plus_uconst,
8175 tree_low_cst (TREE_OPERAND (loc, 1),
8177 0));
8178 break;
8181 op = DW_OP_plus;
8182 goto do_binop;
8184 case LE_EXPR:
8185 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8186 return 0;
8188 op = DW_OP_le;
8189 goto do_binop;
8191 case GE_EXPR:
8192 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8193 return 0;
8195 op = DW_OP_ge;
8196 goto do_binop;
8198 case LT_EXPR:
8199 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8200 return 0;
8202 op = DW_OP_lt;
8203 goto do_binop;
8205 case GT_EXPR:
8206 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
8207 return 0;
8209 op = DW_OP_gt;
8210 goto do_binop;
8212 case EQ_EXPR:
8213 op = DW_OP_eq;
8214 goto do_binop;
8216 case NE_EXPR:
8217 op = DW_OP_ne;
8218 goto do_binop;
8220 do_binop:
8221 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8222 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8223 if (ret == 0 || ret1 == 0)
8224 return 0;
8226 add_loc_descr (&ret, ret1);
8227 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8228 break;
8230 case TRUTH_NOT_EXPR:
8231 case BIT_NOT_EXPR:
8232 op = DW_OP_not;
8233 goto do_unop;
8235 case ABS_EXPR:
8236 op = DW_OP_abs;
8237 goto do_unop;
8239 case NEGATE_EXPR:
8240 op = DW_OP_neg;
8241 goto do_unop;
8243 do_unop:
8244 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8245 if (ret == 0)
8246 return 0;
8248 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
8249 break;
8251 case MAX_EXPR:
8252 loc = build (COND_EXPR, TREE_TYPE (loc),
8253 build (LT_EXPR, integer_type_node,
8254 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
8255 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
8257 /* ... fall through ... */
8259 case COND_EXPR:
8261 dw_loc_descr_ref lhs
8262 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
8263 dw_loc_descr_ref rhs
8264 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
8265 dw_loc_descr_ref bra_node, jump_node, tmp;
8267 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
8268 if (ret == 0 || lhs == 0 || rhs == 0)
8269 return 0;
8271 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
8272 add_loc_descr (&ret, bra_node);
8274 add_loc_descr (&ret, rhs);
8275 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
8276 add_loc_descr (&ret, jump_node);
8278 add_loc_descr (&ret, lhs);
8279 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8280 bra_node->dw_loc_oprnd1.v.val_loc = lhs;
8282 /* ??? Need a node to point the skip at. Use a nop. */
8283 tmp = new_loc_descr (DW_OP_nop, 0, 0);
8284 add_loc_descr (&ret, tmp);
8285 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
8286 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
8288 break;
8290 default:
8291 abort ();
8294 /* Show if we can't fill the request for an address. */
8295 if (addressp && indirect_p == 0)
8296 return 0;
8298 /* If we've got an address and don't want one, dereference. */
8299 if (!addressp && indirect_p > 0)
8301 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc));
8303 if (size > DWARF2_ADDR_SIZE || size == -1)
8304 return 0;
8305 else if (size == DWARF2_ADDR_SIZE)
8306 op = DW_OP_deref;
8307 else
8308 op = DW_OP_deref_size;
8310 add_loc_descr (&ret, new_loc_descr (op, size, 0));
8313 return ret;
8316 /* Given a value, round it up to the lowest multiple of `boundary'
8317 which is not less than the value itself. */
8319 static inline HOST_WIDE_INT
8320 ceiling (value, boundary)
8321 HOST_WIDE_INT value;
8322 unsigned int boundary;
8324 return (((value + boundary - 1) / boundary) * boundary);
8327 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
8328 pointer to the declared type for the relevant field variable, or return
8329 `integer_type_node' if the given node turns out to be an
8330 ERROR_MARK node. */
8332 static inline tree
8333 field_type (decl)
8334 tree decl;
8336 tree type;
8338 if (TREE_CODE (decl) == ERROR_MARK)
8339 return integer_type_node;
8341 type = DECL_BIT_FIELD_TYPE (decl);
8342 if (type == NULL_TREE)
8343 type = TREE_TYPE (decl);
8345 return type;
8348 /* Given a pointer to a tree node, return the alignment in bits for
8349 it, or else return BITS_PER_WORD if the node actually turns out to
8350 be an ERROR_MARK node. */
8352 static inline unsigned
8353 simple_type_align_in_bits (type)
8354 tree type;
8356 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
8359 static inline unsigned
8360 simple_field_decl_align_in_bits (field)
8361 tree field;
8363 unsigned align;
8365 if (TREE_CODE (field) == ERROR_MARK)
8366 return BITS_PER_WORD;
8368 align = DECL_ALIGN (field);
8370 #ifdef BIGGEST_FIELD_ALIGNMENT
8371 /* Some targets (i.e. i386) limit union field alignment
8372 to a lower boundary than alignment of variables unless
8373 it was overridden by attribute aligned. */
8374 if (! DECL_USER_ALIGN (field))
8375 align = MIN (align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
8376 #endif
8378 #ifdef ADJUST_FIELD_ALIGN
8379 align = ADJUST_FIELD_ALIGN (field, align);
8380 #endif
8381 return align;
8384 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
8385 node, return the size in bits for the type if it is a constant, or else
8386 return the alignment for the type if the type's size is not constant, or
8387 else return BITS_PER_WORD if the type actually turns out to be an
8388 ERROR_MARK node. */
8390 static inline unsigned HOST_WIDE_INT
8391 simple_type_size_in_bits (type)
8392 tree type;
8395 if (TREE_CODE (type) == ERROR_MARK)
8396 return BITS_PER_WORD;
8397 else if (TYPE_SIZE (type) == NULL_TREE)
8398 return 0;
8399 else if (host_integerp (TYPE_SIZE (type), 1))
8400 return tree_low_cst (TYPE_SIZE (type), 1);
8401 else
8402 return TYPE_ALIGN (type);
8405 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
8406 lowest addressed byte of the "containing object" for the given FIELD_DECL,
8407 or return 0 if we are unable to determine what that offset is, either
8408 because the argument turns out to be a pointer to an ERROR_MARK node, or
8409 because the offset is actually variable. (We can't handle the latter case
8410 just yet). */
8412 static HOST_WIDE_INT
8413 field_byte_offset (decl)
8414 tree decl;
8416 unsigned int type_align_in_bits;
8417 unsigned int decl_align_in_bits;
8418 unsigned HOST_WIDE_INT type_size_in_bits;
8419 HOST_WIDE_INT object_offset_in_bits;
8420 tree type;
8421 tree field_size_tree;
8422 HOST_WIDE_INT bitpos_int;
8423 HOST_WIDE_INT deepest_bitpos;
8424 unsigned HOST_WIDE_INT field_size_in_bits;
8426 if (TREE_CODE (decl) == ERROR_MARK)
8427 return 0;
8428 else if (TREE_CODE (decl) != FIELD_DECL)
8429 abort ();
8431 type = field_type (decl);
8432 field_size_tree = DECL_SIZE (decl);
8434 /* The size could be unspecified if there was an error, or for
8435 a flexible array member. */
8436 if (! field_size_tree)
8437 field_size_tree = bitsize_zero_node;
8439 /* We cannot yet cope with fields whose positions are variable, so
8440 for now, when we see such things, we simply return 0. Someday, we may
8441 be able to handle such cases, but it will be damn difficult. */
8442 if (! host_integerp (bit_position (decl), 0))
8443 return 0;
8445 bitpos_int = int_bit_position (decl);
8447 /* If we don't know the size of the field, pretend it's a full word. */
8448 if (host_integerp (field_size_tree, 1))
8449 field_size_in_bits = tree_low_cst (field_size_tree, 1);
8450 else
8451 field_size_in_bits = BITS_PER_WORD;
8453 type_size_in_bits = simple_type_size_in_bits (type);
8454 type_align_in_bits = simple_type_align_in_bits (type);
8455 decl_align_in_bits = simple_field_decl_align_in_bits (decl);
8457 /* The GCC front-end doesn't make any attempt to keep track of the starting
8458 bit offset (relative to the start of the containing structure type) of the
8459 hypothetical "containing object" for a bit-field. Thus, when computing
8460 the byte offset value for the start of the "containing object" of a
8461 bit-field, we must deduce this information on our own. This can be rather
8462 tricky to do in some cases. For example, handling the following structure
8463 type definition when compiling for an i386/i486 target (which only aligns
8464 long long's to 32-bit boundaries) can be very tricky:
8466 struct S { int field1; long long field2:31; };
8468 Fortunately, there is a simple rule-of-thumb which can be used in such
8469 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the
8470 structure shown above. It decides to do this based upon one simple rule
8471 for bit-field allocation. GCC allocates each "containing object" for each
8472 bit-field at the first (i.e. lowest addressed) legitimate alignment
8473 boundary (based upon the required minimum alignment for the declared type
8474 of the field) which it can possibly use, subject to the condition that
8475 there is still enough available space remaining in the containing object
8476 (when allocated at the selected point) to fully accommodate all of the
8477 bits of the bit-field itself.
8479 This simple rule makes it obvious why GCC allocates 8 bytes for each
8480 object of the structure type shown above. When looking for a place to
8481 allocate the "containing object" for `field2', the compiler simply tries
8482 to allocate a 64-bit "containing object" at each successive 32-bit
8483 boundary (starting at zero) until it finds a place to allocate that 64-
8484 bit field such that at least 31 contiguous (and previously unallocated)
8485 bits remain within that selected 64 bit field. (As it turns out, for the
8486 example above, the compiler finds it is OK to allocate the "containing
8487 object" 64-bit field at bit-offset zero within the structure type.)
8489 Here we attempt to work backwards from the limited set of facts we're
8490 given, and we try to deduce from those facts, where GCC must have believed
8491 that the containing object started (within the structure type). The value
8492 we deduce is then used (by the callers of this routine) to generate
8493 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields
8494 and, in the case of DW_AT_location, regular fields as well). */
8496 /* Figure out the bit-distance from the start of the structure to the
8497 "deepest" bit of the bit-field. */
8498 deepest_bitpos = bitpos_int + field_size_in_bits;
8500 /* This is the tricky part. Use some fancy footwork to deduce where the
8501 lowest addressed bit of the containing object must be. */
8502 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8504 /* Round up to type_align by default. This works best for bitfields. */
8505 object_offset_in_bits += type_align_in_bits - 1;
8506 object_offset_in_bits /= type_align_in_bits;
8507 object_offset_in_bits *= type_align_in_bits;
8509 if (object_offset_in_bits > bitpos_int)
8511 /* Sigh, the decl must be packed. */
8512 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8514 /* Round up to decl_align instead. */
8515 object_offset_in_bits += decl_align_in_bits - 1;
8516 object_offset_in_bits /= decl_align_in_bits;
8517 object_offset_in_bits *= decl_align_in_bits;
8520 return object_offset_in_bits / BITS_PER_UNIT;
8523 /* The following routines define various Dwarf attributes and any data
8524 associated with them. */
8526 /* Add a location description attribute value to a DIE.
8528 This emits location attributes suitable for whole variables and
8529 whole parameters. Note that the location attributes for struct fields are
8530 generated by the routine `data_member_location_attribute' below. */
8532 static void
8533 add_AT_location_description (die, attr_kind, rtl)
8534 dw_die_ref die;
8535 enum dwarf_attribute attr_kind;
8536 rtx rtl;
8538 dw_loc_descr_ref descr = loc_descriptor (rtl);
8540 if (descr != 0)
8541 add_AT_loc (die, attr_kind, descr);
8544 /* Attach the specialized form of location attribute used for data members of
8545 struct and union types. In the special case of a FIELD_DECL node which
8546 represents a bit-field, the "offset" part of this special location
8547 descriptor must indicate the distance in bytes from the lowest-addressed
8548 byte of the containing struct or union type to the lowest-addressed byte of
8549 the "containing object" for the bit-field. (See the `field_byte_offset'
8550 function above).
8552 For any given bit-field, the "containing object" is a hypothetical object
8553 (of some integral or enum type) within which the given bit-field lives. The
8554 type of this hypothetical "containing object" is always the same as the
8555 declared type of the individual bit-field itself (for GCC anyway... the
8556 DWARF spec doesn't actually mandate this). Note that it is the size (in
8557 bytes) of the hypothetical "containing object" which will be given in the
8558 DW_AT_byte_size attribute for this bit-field. (See the
8559 `byte_size_attribute' function below.) It is also used when calculating the
8560 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
8561 function below.) */
8563 static void
8564 add_data_member_location_attribute (die, decl)
8565 dw_die_ref die;
8566 tree decl;
8568 long offset;
8569 dw_loc_descr_ref loc_descr = 0;
8571 if (TREE_CODE (decl) == TREE_VEC)
8573 /* We're working on the TAG_inheritance for a base class. */
8574 if (TREE_VIA_VIRTUAL (decl) && is_cxx ())
8576 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
8577 aren't at a fixed offset from all (sub)objects of the same
8578 type. We need to extract the appropriate offset from our
8579 vtable. The following dwarf expression means
8581 BaseAddr = ObAddr + *((*ObAddr) - Offset)
8583 This is specific to the V3 ABI, of course. */
8585 dw_loc_descr_ref tmp;
8587 /* Make a copy of the object address. */
8588 tmp = new_loc_descr (DW_OP_dup, 0, 0);
8589 add_loc_descr (&loc_descr, tmp);
8591 /* Extract the vtable address. */
8592 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8593 add_loc_descr (&loc_descr, tmp);
8595 /* Calculate the address of the offset. */
8596 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0);
8597 if (offset >= 0)
8598 abort ();
8600 tmp = int_loc_descriptor (-offset);
8601 add_loc_descr (&loc_descr, tmp);
8602 tmp = new_loc_descr (DW_OP_minus, 0, 0);
8603 add_loc_descr (&loc_descr, tmp);
8605 /* Extract the offset. */
8606 tmp = new_loc_descr (DW_OP_deref, 0, 0);
8607 add_loc_descr (&loc_descr, tmp);
8609 /* Add it to the object address. */
8610 tmp = new_loc_descr (DW_OP_plus, 0, 0);
8611 add_loc_descr (&loc_descr, tmp);
8613 else
8614 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8616 else
8617 offset = field_byte_offset (decl);
8619 if (! loc_descr)
8621 enum dwarf_location_atom op;
8623 /* The DWARF2 standard says that we should assume that the structure
8624 address is already on the stack, so we can specify a structure field
8625 address by using DW_OP_plus_uconst. */
8627 #ifdef MIPS_DEBUGGING_INFO
8628 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst
8629 operator correctly. It works only if we leave the offset on the
8630 stack. */
8631 op = DW_OP_constu;
8632 #else
8633 op = DW_OP_plus_uconst;
8634 #endif
8636 loc_descr = new_loc_descr (op, offset, 0);
8639 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8642 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8643 does not have a "location" either in memory or in a register. These
8644 things can arise in GNU C when a constant is passed as an actual parameter
8645 to an inlined function. They can also arise in C++ where declared
8646 constants do not necessarily get memory "homes". */
8648 static void
8649 add_const_value_attribute (die, rtl)
8650 dw_die_ref die;
8651 rtx rtl;
8653 switch (GET_CODE (rtl))
8655 case CONST_INT:
8656 /* Note that a CONST_INT rtx could represent either an integer
8657 or a floating-point constant. A CONST_INT is used whenever
8658 the constant will fit into a single word. In all such
8659 cases, the original mode of the constant value is wiped
8660 out, and the CONST_INT rtx is assigned VOIDmode. */
8662 HOST_WIDE_INT val = INTVAL (rtl);
8664 /* ??? We really should be using HOST_WIDE_INT throughout. */
8665 if (val < 0 && (long) val == val)
8666 add_AT_int (die, DW_AT_const_value, (long) val);
8667 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val)
8668 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val);
8669 else
8671 #if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT
8672 add_AT_long_long (die, DW_AT_const_value,
8673 val >> HOST_BITS_PER_LONG, val);
8674 #else
8675 abort ();
8676 #endif
8679 break;
8681 case CONST_DOUBLE:
8682 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8683 floating-point constant. A CONST_DOUBLE is used whenever the
8684 constant requires more than one word in order to be adequately
8685 represented. We output CONST_DOUBLEs as blocks. */
8687 enum machine_mode mode = GET_MODE (rtl);
8689 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8691 unsigned length = GET_MODE_SIZE (mode) / 4;
8692 long *array = (long *) xmalloc (sizeof (long) * length);
8693 REAL_VALUE_TYPE rv;
8695 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8696 switch (mode)
8698 case SFmode:
8699 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8700 break;
8702 case DFmode:
8703 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8704 break;
8706 case XFmode:
8707 case TFmode:
8708 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8709 break;
8711 default:
8712 abort ();
8715 add_AT_float (die, DW_AT_const_value, length, array);
8717 else
8719 /* ??? We really should be using HOST_WIDE_INT throughout. */
8720 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8721 abort ();
8723 add_AT_long_long (die, DW_AT_const_value,
8724 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8727 break;
8729 case CONST_STRING:
8730 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8731 break;
8733 case SYMBOL_REF:
8734 case LABEL_REF:
8735 case CONST:
8736 add_AT_addr (die, DW_AT_const_value, rtl);
8737 VARRAY_PUSH_RTX (used_rtx_varray, rtl);
8738 break;
8740 case PLUS:
8741 /* In cases where an inlined instance of an inline function is passed
8742 the address of an `auto' variable (which is local to the caller) we
8743 can get a situation where the DECL_RTL of the artificial local
8744 variable (for the inlining) which acts as a stand-in for the
8745 corresponding formal parameter (of the inline function) will look
8746 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8747 exactly a compile-time constant expression, but it isn't the address
8748 of the (artificial) local variable either. Rather, it represents the
8749 *value* which the artificial local variable always has during its
8750 lifetime. We currently have no way to represent such quasi-constant
8751 values in Dwarf, so for now we just punt and generate nothing. */
8752 break;
8754 default:
8755 /* No other kinds of rtx should be possible here. */
8756 abort ();
8761 static rtx
8762 rtl_for_decl_location (decl)
8763 tree decl;
8765 rtx rtl;
8767 /* Here we have to decide where we are going to say the parameter "lives"
8768 (as far as the debugger is concerned). We only have a couple of
8769 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8771 DECL_RTL normally indicates where the parameter lives during most of the
8772 activation of the function. If optimization is enabled however, this
8773 could be either NULL or else a pseudo-reg. Both of those cases indicate
8774 that the parameter doesn't really live anywhere (as far as the code
8775 generation parts of GCC are concerned) during most of the function's
8776 activation. That will happen (for example) if the parameter is never
8777 referenced within the function.
8779 We could just generate a location descriptor here for all non-NULL
8780 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8781 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8782 where DECL_RTL is NULL or is a pseudo-reg.
8784 Note however that we can only get away with using DECL_INCOMING_RTL as
8785 a backup substitute for DECL_RTL in certain limited cases. In cases
8786 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8787 we can be sure that the parameter was passed using the same type as it is
8788 declared to have within the function, and that its DECL_INCOMING_RTL
8789 points us to a place where a value of that type is passed.
8791 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8792 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8793 because in these cases DECL_INCOMING_RTL points us to a value of some
8794 type which is *different* from the type of the parameter itself. Thus,
8795 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8796 such cases, the debugger would end up (for example) trying to fetch a
8797 `float' from a place which actually contains the first part of a
8798 `double'. That would lead to really incorrect and confusing
8799 output at debug-time.
8801 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8802 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8803 are a couple of exceptions however. On little-endian machines we can
8804 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8805 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8806 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8807 when (on a little-endian machine) a non-prototyped function has a
8808 parameter declared to be of type `short' or `char'. In such cases,
8809 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8810 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8811 passed `int' value. If the debugger then uses that address to fetch
8812 a `short' or a `char' (on a little-endian machine) the result will be
8813 the correct data, so we allow for such exceptional cases below.
8815 Note that our goal here is to describe the place where the given formal
8816 parameter lives during most of the function's activation (i.e. between the
8817 end of the prologue and the start of the epilogue). We'll do that as best
8818 as we can. Note however that if the given formal parameter is modified
8819 sometime during the execution of the function, then a stack backtrace (at
8820 debug-time) will show the function as having been called with the *new*
8821 value rather than the value which was originally passed in. This happens
8822 rarely enough that it is not a major problem, but it *is* a problem, and
8823 I'd like to fix it.
8825 A future version of dwarf2out.c may generate two additional attributes for
8826 any given DW_TAG_formal_parameter DIE which will describe the "passed
8827 type" and the "passed location" for the given formal parameter in addition
8828 to the attributes we now generate to indicate the "declared type" and the
8829 "active location" for each parameter. This additional set of attributes
8830 could be used by debuggers for stack backtraces. Separately, note that
8831 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
8832 This happens (for example) for inlined-instances of inline function formal
8833 parameters which are never referenced. This really shouldn't be
8834 happening. All PARM_DECL nodes should get valid non-NULL
8835 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these
8836 values for inlined instances of inline function parameters, so when we see
8837 such cases, we are just out-of-luck for the time being (until integrate.c
8838 gets fixed). */
8840 /* Use DECL_RTL as the "location" unless we find something better. */
8841 rtl = DECL_RTL_IF_SET (decl);
8843 /* When generating abstract instances, ignore everything except
8844 constants and symbols living in memory. */
8845 if (! reload_completed)
8847 if (rtl
8848 && (CONSTANT_P (rtl)
8849 || (GET_CODE (rtl) == MEM
8850 && CONSTANT_P (XEXP (rtl, 0)))))
8852 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8853 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8854 #endif
8855 return rtl;
8857 rtl = NULL_RTX;
8859 else if (TREE_CODE (decl) == PARM_DECL)
8861 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8863 tree declared_type = type_main_variant (TREE_TYPE (decl));
8864 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8866 /* This decl represents a formal parameter which was optimized out.
8867 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8868 all cases where (rtl == NULL_RTX) just below. */
8869 if (declared_type == passed_type)
8870 rtl = DECL_INCOMING_RTL (decl);
8871 else if (! BYTES_BIG_ENDIAN
8872 && TREE_CODE (declared_type) == INTEGER_TYPE
8873 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8874 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8875 rtl = DECL_INCOMING_RTL (decl);
8878 /* If the parm was passed in registers, but lives on the stack, then
8879 make a big endian correction if the mode of the type of the
8880 parameter is not the same as the mode of the rtl. */
8881 /* ??? This is the same series of checks that are made in dbxout.c before
8882 we reach the big endian correction code there. It isn't clear if all
8883 of these checks are necessary here, but keeping them all is the safe
8884 thing to do. */
8885 else if (GET_CODE (rtl) == MEM
8886 && XEXP (rtl, 0) != const0_rtx
8887 && ! CONSTANT_P (XEXP (rtl, 0))
8888 /* Not passed in memory. */
8889 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8890 /* Not passed by invisible reference. */
8891 && (GET_CODE (XEXP (rtl, 0)) != REG
8892 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8893 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8894 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8895 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8896 #endif
8898 /* Big endian correction check. */
8899 && BYTES_BIG_ENDIAN
8900 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8901 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8902 < UNITS_PER_WORD))
8904 int offset = (UNITS_PER_WORD
8905 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8907 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8908 plus_constant (XEXP (rtl, 0), offset));
8912 if (rtl != NULL_RTX)
8914 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8915 #ifdef LEAF_REG_REMAP
8916 if (current_function_uses_only_leaf_regs)
8917 leaf_renumber_regs_insn (rtl);
8918 #endif
8921 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
8922 and will have been substituted directly into all expressions that use it.
8923 C does not have such a concept, but C++ and other languages do. */
8924 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl))
8926 /* If a variable is initialized with a string constant without embedded
8927 zeros, build CONST_STRING. */
8928 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8929 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
8931 tree arrtype = TREE_TYPE (decl);
8932 tree enttype = TREE_TYPE (arrtype);
8933 tree domain = TYPE_DOMAIN (arrtype);
8934 tree init = DECL_INITIAL (decl);
8935 enum machine_mode mode = TYPE_MODE (enttype);
8937 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1
8938 && domain
8939 && integer_zerop (TYPE_MIN_VALUE (domain))
8940 && compare_tree_int (TYPE_MAX_VALUE (domain),
8941 TREE_STRING_LENGTH (init) - 1) == 0
8942 && ((size_t) TREE_STRING_LENGTH (init)
8943 == strlen (TREE_STRING_POINTER (init)) + 1))
8944 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init));
8946 /* If the initializer is something that we know will expand into an
8947 immediate RTL constant, expand it now. Expanding anything else
8948 tends to produce unresolved symbols; see debug/5770 and c++/6381. */
8949 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST
8950 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST)
8952 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode,
8953 EXPAND_INITIALIZER);
8954 /* If expand_expr returns a MEM, it wasn't immediate. */
8955 if (rtl && GET_CODE (rtl) == MEM)
8956 abort ();
8960 #ifdef ASM_SIMPLIFY_DWARF_ADDR
8961 if (rtl)
8962 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
8963 #endif
8964 return rtl;
8967 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8968 data attribute for a variable or a parameter. We generate the
8969 DW_AT_const_value attribute only in those cases where the given variable
8970 or parameter does not have a true "location" either in memory or in a
8971 register. This can happen (for example) when a constant is passed as an
8972 actual argument in a call to an inline function. (It's possible that
8973 these things can crop up in other ways also.) Note that one type of
8974 constant value which can be passed into an inlined function is a constant
8975 pointer. This can happen for example if an actual argument in an inlined
8976 function call evaluates to a compile-time constant address. */
8978 static void
8979 add_location_or_const_value_attribute (die, decl)
8980 dw_die_ref die;
8981 tree decl;
8983 rtx rtl;
8985 if (TREE_CODE (decl) == ERROR_MARK)
8986 return;
8987 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8988 abort ();
8990 rtl = rtl_for_decl_location (decl);
8991 if (rtl == NULL_RTX)
8992 return;
8994 /* If we don't look past the constant pool, we risk emitting a
8995 reference to a constant pool entry that isn't referenced from
8996 code, and thus is not emitted. */
8997 rtl = avoid_constant_pool_reference (rtl);
8999 switch (GET_CODE (rtl))
9001 case ADDRESSOF:
9002 /* The address of a variable that was optimized away; don't emit
9003 anything. */
9004 break;
9006 case CONST_INT:
9007 case CONST_DOUBLE:
9008 case CONST_STRING:
9009 case SYMBOL_REF:
9010 case LABEL_REF:
9011 case CONST:
9012 case PLUS:
9013 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
9014 add_const_value_attribute (die, rtl);
9015 break;
9017 case MEM:
9018 case REG:
9019 case SUBREG:
9020 case CONCAT:
9021 add_AT_location_description (die, DW_AT_location, rtl);
9022 break;
9024 default:
9025 abort ();
9029 /* If we don't have a copy of this variable in memory for some reason (such
9030 as a C++ member constant that doesn't have an out-of-line definition),
9031 we should tell the debugger about the constant value. */
9033 static void
9034 tree_add_const_value_attribute (var_die, decl)
9035 dw_die_ref var_die;
9036 tree decl;
9038 tree init = DECL_INITIAL (decl);
9039 tree type = TREE_TYPE (decl);
9041 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
9042 && initializer_constant_valid_p (init, type) == null_pointer_node)
9043 /* OK */;
9044 else
9045 return;
9047 switch (TREE_CODE (type))
9049 case INTEGER_TYPE:
9050 if (host_integerp (init, 0))
9051 add_AT_unsigned (var_die, DW_AT_const_value,
9052 tree_low_cst (init, 0));
9053 else
9054 add_AT_long_long (var_die, DW_AT_const_value,
9055 TREE_INT_CST_HIGH (init),
9056 TREE_INT_CST_LOW (init));
9057 break;
9059 default:;
9063 /* Generate an DW_AT_name attribute given some string value to be included as
9064 the value of the attribute. */
9066 static inline void
9067 add_name_attribute (die, name_string)
9068 dw_die_ref die;
9069 const char *name_string;
9071 if (name_string != NULL && *name_string != 0)
9073 if (demangle_name_func)
9074 name_string = (*demangle_name_func) (name_string);
9076 add_AT_string (die, DW_AT_name, name_string);
9080 /* Given a tree node describing an array bound (either lower or upper) output
9081 a representation for that bound. */
9083 static void
9084 add_bound_info (subrange_die, bound_attr, bound)
9085 dw_die_ref subrange_die;
9086 enum dwarf_attribute bound_attr;
9087 tree bound;
9089 switch (TREE_CODE (bound))
9091 case ERROR_MARK:
9092 return;
9094 /* All fixed-bounds are represented by INTEGER_CST nodes. */
9095 case INTEGER_CST:
9096 if (! host_integerp (bound, 0)
9097 || (bound_attr == DW_AT_lower_bound
9098 && (((is_c_family () || is_java ()) && integer_zerop (bound))
9099 || (is_fortran () && integer_onep (bound)))))
9100 /* use the default */
9102 else
9103 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
9104 break;
9106 case CONVERT_EXPR:
9107 case NOP_EXPR:
9108 case NON_LVALUE_EXPR:
9109 case VIEW_CONVERT_EXPR:
9110 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
9111 break;
9113 case SAVE_EXPR:
9114 /* If optimization is turned on, the SAVE_EXPRs that describe how to
9115 access the upper bound values may be bogus. If they refer to a
9116 register, they may only describe how to get at these values at the
9117 points in the generated code right after they have just been
9118 computed. Worse yet, in the typical case, the upper bound values
9119 will not even *be* computed in the optimized code (though the
9120 number of elements will), so these SAVE_EXPRs are entirely
9121 bogus. In order to compensate for this fact, we check here to see
9122 if optimization is enabled, and if so, we don't add an attribute
9123 for the (unknown and unknowable) upper bound. This should not
9124 cause too much trouble for existing (stupid?) debuggers because
9125 they have to deal with empty upper bounds location descriptions
9126 anyway in order to be able to deal with incomplete array types.
9127 Of course an intelligent debugger (GDB?) should be able to
9128 comprehend that a missing upper bound specification in an array
9129 type used for a storage class `auto' local array variable
9130 indicates that the upper bound is both unknown (at compile- time)
9131 and unknowable (at run-time) due to optimization.
9133 We assume that a MEM rtx is safe because gcc wouldn't put the
9134 value there unless it was going to be used repeatedly in the
9135 function, i.e. for cleanups. */
9136 if (SAVE_EXPR_RTL (bound)
9137 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
9139 dw_die_ref ctx = lookup_decl_die (current_function_decl);
9140 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound);
9141 rtx loc = SAVE_EXPR_RTL (bound);
9143 /* If the RTL for the SAVE_EXPR is memory, handle the case where
9144 it references an outer function's frame. */
9145 if (GET_CODE (loc) == MEM)
9147 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
9149 if (XEXP (loc, 0) != new_addr)
9150 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
9153 add_AT_flag (decl_die, DW_AT_artificial, 1);
9154 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9155 add_AT_location_description (decl_die, DW_AT_location, loc);
9156 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9159 /* Else leave out the attribute. */
9160 break;
9162 case VAR_DECL:
9163 case PARM_DECL:
9165 dw_die_ref decl_die = lookup_decl_die (bound);
9167 /* ??? Can this happen, or should the variable have been bound
9168 first? Probably it can, since I imagine that we try to create
9169 the types of parameters in the order in which they exist in
9170 the list, and won't have created a forward reference to a
9171 later parameter. */
9172 if (decl_die != NULL)
9173 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9174 break;
9177 default:
9179 /* Otherwise try to create a stack operation procedure to
9180 evaluate the value of the array bound. */
9182 dw_die_ref ctx, decl_die;
9183 dw_loc_descr_ref loc;
9185 loc = loc_descriptor_from_tree (bound, 0);
9186 if (loc == NULL)
9187 break;
9189 if (current_function_decl == 0)
9190 ctx = comp_unit_die;
9191 else
9192 ctx = lookup_decl_die (current_function_decl);
9194 /* If we weren't able to find a context, it's most likely the case
9195 that we are processing the return type of the function. So
9196 make a SAVE_EXPR to point to it and have the limbo DIE code
9197 find the proper die. The save_expr function doesn't always
9198 make a SAVE_EXPR, so do it ourselves. */
9199 if (ctx == 0)
9200 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound,
9201 current_function_decl, NULL_TREE);
9203 decl_die = new_die (DW_TAG_variable, ctx, bound);
9204 add_AT_flag (decl_die, DW_AT_artificial, 1);
9205 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
9206 add_AT_loc (decl_die, DW_AT_location, loc);
9208 add_AT_die_ref (subrange_die, bound_attr, decl_die);
9209 break;
9214 /* Note that the block of subscript information for an array type also
9215 includes information about the element type of type given array type. */
9217 static void
9218 add_subscript_info (type_die, type)
9219 dw_die_ref type_die;
9220 tree type;
9222 #ifndef MIPS_DEBUGGING_INFO
9223 unsigned dimension_number;
9224 #endif
9225 tree lower, upper;
9226 dw_die_ref subrange_die;
9228 /* The GNU compilers represent multidimensional array types as sequences of
9229 one dimensional array types whose element types are themselves array
9230 types. Here we squish that down, so that each multidimensional array
9231 type gets only one array_type DIE in the Dwarf debugging info. The draft
9232 Dwarf specification say that we are allowed to do this kind of
9233 compression in C (because there is no difference between an array or
9234 arrays and a multidimensional array in C) but for other source languages
9235 (e.g. Ada) we probably shouldn't do this. */
9237 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9238 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9239 We work around this by disabling this feature. See also
9240 gen_array_type_die. */
9241 #ifndef MIPS_DEBUGGING_INFO
9242 for (dimension_number = 0;
9243 TREE_CODE (type) == ARRAY_TYPE;
9244 type = TREE_TYPE (type), dimension_number++)
9245 #endif
9247 tree domain = TYPE_DOMAIN (type);
9249 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
9250 and (in GNU C only) variable bounds. Handle all three forms
9251 here. */
9252 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL);
9253 if (domain)
9255 /* We have an array type with specified bounds. */
9256 lower = TYPE_MIN_VALUE (domain);
9257 upper = TYPE_MAX_VALUE (domain);
9259 /* define the index type. */
9260 if (TREE_TYPE (domain))
9262 /* ??? This is probably an Ada unnamed subrange type. Ignore the
9263 TREE_TYPE field. We can't emit debug info for this
9264 because it is an unnamed integral type. */
9265 if (TREE_CODE (domain) == INTEGER_TYPE
9266 && TYPE_NAME (domain) == NULL_TREE
9267 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
9268 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
9270 else
9271 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
9272 type_die);
9275 /* ??? If upper is NULL, the array has unspecified length,
9276 but it does have a lower bound. This happens with Fortran
9277 dimension arr(N:*)
9278 Since the debugger is definitely going to need to know N
9279 to produce useful results, go ahead and output the lower
9280 bound solo, and hope the debugger can cope. */
9282 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
9283 if (upper)
9284 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
9287 /* Otherwise we have an array type with an unspecified length. The
9288 DWARF-2 spec does not say how to handle this; let's just leave out the
9289 bounds. */
9293 static void
9294 add_byte_size_attribute (die, tree_node)
9295 dw_die_ref die;
9296 tree tree_node;
9298 unsigned size;
9300 switch (TREE_CODE (tree_node))
9302 case ERROR_MARK:
9303 size = 0;
9304 break;
9305 case ENUMERAL_TYPE:
9306 case RECORD_TYPE:
9307 case UNION_TYPE:
9308 case QUAL_UNION_TYPE:
9309 size = int_size_in_bytes (tree_node);
9310 break;
9311 case FIELD_DECL:
9312 /* For a data member of a struct or union, the DW_AT_byte_size is
9313 generally given as the number of bytes normally allocated for an
9314 object of the *declared* type of the member itself. This is true
9315 even for bit-fields. */
9316 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
9317 break;
9318 default:
9319 abort ();
9322 /* Note that `size' might be -1 when we get to this point. If it is, that
9323 indicates that the byte size of the entity in question is variable. We
9324 have no good way of expressing this fact in Dwarf at the present time,
9325 so just let the -1 pass on through. */
9326 add_AT_unsigned (die, DW_AT_byte_size, size);
9329 /* For a FIELD_DECL node which represents a bit-field, output an attribute
9330 which specifies the distance in bits from the highest order bit of the
9331 "containing object" for the bit-field to the highest order bit of the
9332 bit-field itself.
9334 For any given bit-field, the "containing object" is a hypothetical object
9335 (of some integral or enum type) within which the given bit-field lives. The
9336 type of this hypothetical "containing object" is always the same as the
9337 declared type of the individual bit-field itself. The determination of the
9338 exact location of the "containing object" for a bit-field is rather
9339 complicated. It's handled by the `field_byte_offset' function (above).
9341 Note that it is the size (in bytes) of the hypothetical "containing object"
9342 which will be given in the DW_AT_byte_size attribute for this bit-field.
9343 (See `byte_size_attribute' above). */
9345 static inline void
9346 add_bit_offset_attribute (die, decl)
9347 dw_die_ref die;
9348 tree decl;
9350 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
9351 tree type = DECL_BIT_FIELD_TYPE (decl);
9352 HOST_WIDE_INT bitpos_int;
9353 HOST_WIDE_INT highest_order_object_bit_offset;
9354 HOST_WIDE_INT highest_order_field_bit_offset;
9355 HOST_WIDE_INT unsigned bit_offset;
9357 /* Must be a field and a bit field. */
9358 if (!type
9359 || TREE_CODE (decl) != FIELD_DECL)
9360 abort ();
9362 /* We can't yet handle bit-fields whose offsets are variable, so if we
9363 encounter such things, just return without generating any attribute
9364 whatsoever. Likewise for variable or too large size. */
9365 if (! host_integerp (bit_position (decl), 0)
9366 || ! host_integerp (DECL_SIZE (decl), 1))
9367 return;
9369 bitpos_int = int_bit_position (decl);
9371 /* Note that the bit offset is always the distance (in bits) from the
9372 highest-order bit of the "containing object" to the highest-order bit of
9373 the bit-field itself. Since the "high-order end" of any object or field
9374 is different on big-endian and little-endian machines, the computation
9375 below must take account of these differences. */
9376 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
9377 highest_order_field_bit_offset = bitpos_int;
9379 if (! BYTES_BIG_ENDIAN)
9381 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
9382 highest_order_object_bit_offset += simple_type_size_in_bits (type);
9385 bit_offset
9386 = (! BYTES_BIG_ENDIAN
9387 ? highest_order_object_bit_offset - highest_order_field_bit_offset
9388 : highest_order_field_bit_offset - highest_order_object_bit_offset);
9390 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
9393 /* For a FIELD_DECL node which represents a bit field, output an attribute
9394 which specifies the length in bits of the given field. */
9396 static inline void
9397 add_bit_size_attribute (die, decl)
9398 dw_die_ref die;
9399 tree decl;
9401 /* Must be a field and a bit field. */
9402 if (TREE_CODE (decl) != FIELD_DECL
9403 || ! DECL_BIT_FIELD_TYPE (decl))
9404 abort ();
9406 if (host_integerp (DECL_SIZE (decl), 1))
9407 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
9410 /* If the compiled language is ANSI C, then add a 'prototyped'
9411 attribute, if arg types are given for the parameters of a function. */
9413 static inline void
9414 add_prototyped_attribute (die, func_type)
9415 dw_die_ref die;
9416 tree func_type;
9418 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
9419 && TYPE_ARG_TYPES (func_type) != NULL)
9420 add_AT_flag (die, DW_AT_prototyped, 1);
9423 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
9424 by looking in either the type declaration or object declaration
9425 equate table. */
9427 static inline void
9428 add_abstract_origin_attribute (die, origin)
9429 dw_die_ref die;
9430 tree origin;
9432 dw_die_ref origin_die = NULL;
9434 if (TREE_CODE (origin) != FUNCTION_DECL)
9436 /* We may have gotten separated from the block for the inlined
9437 function, if we're in an exception handler or some such; make
9438 sure that the abstract function has been written out.
9440 Doing this for nested functions is wrong, however; functions are
9441 distinct units, and our context might not even be inline. */
9442 tree fn = origin;
9444 if (TYPE_P (fn))
9445 fn = TYPE_STUB_DECL (fn);
9447 fn = decl_function_context (fn);
9448 if (fn)
9449 dwarf2out_abstract_function (fn);
9452 if (DECL_P (origin))
9453 origin_die = lookup_decl_die (origin);
9454 else if (TYPE_P (origin))
9455 origin_die = lookup_type_die (origin);
9457 if (origin_die == NULL)
9458 abort ();
9460 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
9463 /* We do not currently support the pure_virtual attribute. */
9465 static inline void
9466 add_pure_or_virtual_attribute (die, func_decl)
9467 dw_die_ref die;
9468 tree func_decl;
9470 if (DECL_VINDEX (func_decl))
9472 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
9474 if (host_integerp (DECL_VINDEX (func_decl), 0))
9475 add_AT_loc (die, DW_AT_vtable_elem_location,
9476 new_loc_descr (DW_OP_constu,
9477 tree_low_cst (DECL_VINDEX (func_decl), 0),
9478 0));
9480 /* GNU extension: Record what type this method came from originally. */
9481 if (debug_info_level > DINFO_LEVEL_TERSE)
9482 add_AT_die_ref (die, DW_AT_containing_type,
9483 lookup_type_die (DECL_CONTEXT (func_decl)));
9487 /* Add source coordinate attributes for the given decl. */
9489 static void
9490 add_src_coords_attributes (die, decl)
9491 dw_die_ref die;
9492 tree decl;
9494 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9496 add_AT_unsigned (die, DW_AT_decl_file, file_index);
9497 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9500 /* Add an DW_AT_name attribute and source coordinate attribute for the
9501 given decl, but only if it actually has a name. */
9503 static void
9504 add_name_and_src_coords_attributes (die, decl)
9505 dw_die_ref die;
9506 tree decl;
9508 tree decl_name;
9510 decl_name = DECL_NAME (decl);
9511 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
9513 add_name_attribute (die, dwarf2_name (decl, 0));
9514 if (! DECL_ARTIFICIAL (decl))
9515 add_src_coords_attributes (die, decl);
9517 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
9518 && TREE_PUBLIC (decl)
9519 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
9520 && !DECL_ABSTRACT (decl))
9521 add_AT_string (die, DW_AT_MIPS_linkage_name,
9522 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
9525 #ifdef VMS_DEBUGGING_INFO
9526 /* Get the function's name, as described by its RTL. This may be different
9527 from the DECL_NAME name used in the source file. */
9528 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
9530 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address,
9531 XEXP (DECL_RTL (decl), 0));
9532 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0));
9534 #endif
9537 /* Push a new declaration scope. */
9539 static void
9540 push_decl_scope (scope)
9541 tree scope;
9543 VARRAY_PUSH_TREE (decl_scope_table, scope);
9546 /* Pop a declaration scope. */
9548 static inline void
9549 pop_decl_scope ()
9551 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0)
9552 abort ();
9554 VARRAY_POP (decl_scope_table);
9557 /* Return the DIE for the scope that immediately contains this type.
9558 Non-named types get global scope. Named types nested in other
9559 types get their containing scope if it's open, or global scope
9560 otherwise. All other types (i.e. function-local named types) get
9561 the current active scope. */
9563 static dw_die_ref
9564 scope_die_for (t, context_die)
9565 tree t;
9566 dw_die_ref context_die;
9568 dw_die_ref scope_die = NULL;
9569 tree containing_scope;
9570 int i;
9572 /* Non-types always go in the current scope. */
9573 if (! TYPE_P (t))
9574 abort ();
9576 containing_scope = TYPE_CONTEXT (t);
9578 /* Ignore namespaces for the moment. */
9579 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9580 containing_scope = NULL_TREE;
9582 /* Ignore function type "scopes" from the C frontend. They mean that
9583 a tagged type is local to a parmlist of a function declarator, but
9584 that isn't useful to DWARF. */
9585 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9586 containing_scope = NULL_TREE;
9588 if (containing_scope == NULL_TREE)
9589 scope_die = comp_unit_die;
9590 else if (TYPE_P (containing_scope))
9592 /* For types, we can just look up the appropriate DIE. But
9593 first we check to see if we're in the middle of emitting it
9594 so we know where the new DIE should go. */
9595 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i)
9596 if (VARRAY_TREE (decl_scope_table, i) == containing_scope)
9597 break;
9599 if (i < 0)
9601 if (debug_info_level > DINFO_LEVEL_TERSE
9602 && !TREE_ASM_WRITTEN (containing_scope))
9603 abort ();
9605 /* If none of the current dies are suitable, we get file scope. */
9606 scope_die = comp_unit_die;
9608 else
9609 scope_die = lookup_type_die (containing_scope);
9611 else
9612 scope_die = context_die;
9614 return scope_die;
9617 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
9619 static inline int
9620 local_scope_p (context_die)
9621 dw_die_ref context_die;
9623 for (; context_die; context_die = context_die->die_parent)
9624 if (context_die->die_tag == DW_TAG_inlined_subroutine
9625 || context_die->die_tag == DW_TAG_subprogram)
9626 return 1;
9628 return 0;
9631 /* Returns nonzero if CONTEXT_DIE is a class. */
9633 static inline int
9634 class_scope_p (context_die)
9635 dw_die_ref context_die;
9637 return (context_die
9638 && (context_die->die_tag == DW_TAG_structure_type
9639 || context_die->die_tag == DW_TAG_union_type));
9642 /* Many forms of DIEs require a "type description" attribute. This
9643 routine locates the proper "type descriptor" die for the type given
9644 by 'type', and adds an DW_AT_type attribute below the given die. */
9646 static void
9647 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9648 dw_die_ref object_die;
9649 tree type;
9650 int decl_const;
9651 int decl_volatile;
9652 dw_die_ref context_die;
9654 enum tree_code code = TREE_CODE (type);
9655 dw_die_ref type_die = NULL;
9657 /* ??? If this type is an unnamed subrange type of an integral or
9658 floating-point type, use the inner type. This is because we have no
9659 support for unnamed types in base_type_die. This can happen if this is
9660 an Ada subrange type. Correct solution is emit a subrange type die. */
9661 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9662 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9663 type = TREE_TYPE (type), code = TREE_CODE (type);
9665 if (code == ERROR_MARK
9666 /* Handle a special case. For functions whose return type is void, we
9667 generate *no* type attribute. (Note that no object may have type
9668 `void', so this only applies to function return types). */
9669 || code == VOID_TYPE)
9670 return;
9672 type_die = modified_type_die (type,
9673 decl_const || TYPE_READONLY (type),
9674 decl_volatile || TYPE_VOLATILE (type),
9675 context_die);
9677 if (type_die != NULL)
9678 add_AT_die_ref (object_die, DW_AT_type, type_die);
9681 /* Given a tree pointer to a struct, class, union, or enum type node, return
9682 a pointer to the (string) tag name for the given type, or zero if the type
9683 was declared without a tag. */
9685 static const char *
9686 type_tag (type)
9687 tree type;
9689 const char *name = 0;
9691 if (TYPE_NAME (type) != 0)
9693 tree t = 0;
9695 /* Find the IDENTIFIER_NODE for the type name. */
9696 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9697 t = TYPE_NAME (type);
9699 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9700 a TYPE_DECL node, regardless of whether or not a `typedef' was
9701 involved. */
9702 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9703 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9704 t = DECL_NAME (TYPE_NAME (type));
9706 /* Now get the name as a string, or invent one. */
9707 if (t != 0)
9708 name = IDENTIFIER_POINTER (t);
9711 return (name == 0 || *name == '\0') ? 0 : name;
9714 /* Return the type associated with a data member, make a special check
9715 for bit field types. */
9717 static inline tree
9718 member_declared_type (member)
9719 tree member;
9721 return (DECL_BIT_FIELD_TYPE (member)
9722 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member));
9725 /* Get the decl's label, as described by its RTL. This may be different
9726 from the DECL_NAME name used in the source file. */
9728 #if 0
9729 static const char *
9730 decl_start_label (decl)
9731 tree decl;
9733 rtx x;
9734 const char *fnname;
9736 x = DECL_RTL (decl);
9737 if (GET_CODE (x) != MEM)
9738 abort ();
9740 x = XEXP (x, 0);
9741 if (GET_CODE (x) != SYMBOL_REF)
9742 abort ();
9744 fnname = XSTR (x, 0);
9745 return fnname;
9747 #endif
9749 /* These routines generate the internal representation of the DIE's for
9750 the compilation unit. Debugging information is collected by walking
9751 the declaration trees passed in from dwarf2out_decl(). */
9753 static void
9754 gen_array_type_die (type, context_die)
9755 tree type;
9756 dw_die_ref context_die;
9758 dw_die_ref scope_die = scope_die_for (type, context_die);
9759 dw_die_ref array_die;
9760 tree element_type;
9762 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9763 the inner array type comes before the outer array type. Thus we must
9764 call gen_type_die before we call new_die. See below also. */
9765 #ifdef MIPS_DEBUGGING_INFO
9766 gen_type_die (TREE_TYPE (type), context_die);
9767 #endif
9769 array_die = new_die (DW_TAG_array_type, scope_die, type);
9770 add_name_attribute (array_die, type_tag (type));
9771 equate_type_number_to_die (type, array_die);
9773 if (TREE_CODE (type) == VECTOR_TYPE)
9775 /* The frontend feeds us a representation for the vector as a struct
9776 containing an array. Pull out the array type. */
9777 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
9778 add_AT_flag (array_die, DW_AT_GNU_vector, 1);
9781 #if 0
9782 /* We default the array ordering. SDB will probably do
9783 the right things even if DW_AT_ordering is not present. It's not even
9784 an issue until we start to get into multidimensional arrays anyway. If
9785 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9786 then we'll have to put the DW_AT_ordering attribute back in. (But if
9787 and when we find out that we need to put these in, we will only do so
9788 for multidimensional arrays. */
9789 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9790 #endif
9792 #ifdef MIPS_DEBUGGING_INFO
9793 /* The SGI compilers handle arrays of unknown bound by setting
9794 AT_declaration and not emitting any subrange DIEs. */
9795 if (! TYPE_DOMAIN (type))
9796 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9797 else
9798 #endif
9799 add_subscript_info (array_die, type);
9801 /* Add representation of the type of the elements of this array type. */
9802 element_type = TREE_TYPE (type);
9804 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9805 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9806 We work around this by disabling this feature. See also
9807 add_subscript_info. */
9808 #ifndef MIPS_DEBUGGING_INFO
9809 while (TREE_CODE (element_type) == ARRAY_TYPE)
9810 element_type = TREE_TYPE (element_type);
9812 gen_type_die (element_type, context_die);
9813 #endif
9815 add_type_attribute (array_die, element_type, 0, 0, context_die);
9818 static void
9819 gen_set_type_die (type, context_die)
9820 tree type;
9821 dw_die_ref context_die;
9823 dw_die_ref type_die
9824 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type);
9826 equate_type_number_to_die (type, type_die);
9827 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9830 #if 0
9831 static void
9832 gen_entry_point_die (decl, context_die)
9833 tree decl;
9834 dw_die_ref context_die;
9836 tree origin = decl_ultimate_origin (decl);
9837 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl);
9839 if (origin != NULL)
9840 add_abstract_origin_attribute (decl_die, origin);
9841 else
9843 add_name_and_src_coords_attributes (decl_die, decl);
9844 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9845 0, 0, context_die);
9848 if (DECL_ABSTRACT (decl))
9849 equate_decl_number_to_die (decl, decl_die);
9850 else
9851 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9853 #endif
9855 /* Walk through the list of incomplete types again, trying once more to
9856 emit full debugging info for them. */
9858 static void
9859 retry_incomplete_types ()
9861 int i;
9863 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--)
9864 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die);
9867 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9869 static void
9870 gen_inlined_enumeration_type_die (type, context_die)
9871 tree type;
9872 dw_die_ref context_die;
9874 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type);
9876 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9877 be incomplete and such types are not marked. */
9878 add_abstract_origin_attribute (type_die, type);
9881 /* Generate a DIE to represent an inlined instance of a structure type. */
9883 static void
9884 gen_inlined_structure_type_die (type, context_die)
9885 tree type;
9886 dw_die_ref context_die;
9888 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type);
9890 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9891 be incomplete and such types are not marked. */
9892 add_abstract_origin_attribute (type_die, type);
9895 /* Generate a DIE to represent an inlined instance of a union type. */
9897 static void
9898 gen_inlined_union_type_die (type, context_die)
9899 tree type;
9900 dw_die_ref context_die;
9902 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type);
9904 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9905 be incomplete and such types are not marked. */
9906 add_abstract_origin_attribute (type_die, type);
9909 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9910 include all of the information about the enumeration values also. Each
9911 enumerated type name/value is listed as a child of the enumerated type
9912 DIE. */
9914 static void
9915 gen_enumeration_type_die (type, context_die)
9916 tree type;
9917 dw_die_ref context_die;
9919 dw_die_ref type_die = lookup_type_die (type);
9921 if (type_die == NULL)
9923 type_die = new_die (DW_TAG_enumeration_type,
9924 scope_die_for (type, context_die), type);
9925 equate_type_number_to_die (type, type_die);
9926 add_name_attribute (type_die, type_tag (type));
9928 else if (! TYPE_SIZE (type))
9929 return;
9930 else
9931 remove_AT (type_die, DW_AT_declaration);
9933 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9934 given enum type is incomplete, do not generate the DW_AT_byte_size
9935 attribute or the DW_AT_element_list attribute. */
9936 if (TYPE_SIZE (type))
9938 tree link;
9940 TREE_ASM_WRITTEN (type) = 1;
9941 add_byte_size_attribute (type_die, type);
9942 if (TYPE_STUB_DECL (type) != NULL_TREE)
9943 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9945 /* If the first reference to this type was as the return type of an
9946 inline function, then it may not have a parent. Fix this now. */
9947 if (type_die->die_parent == NULL)
9948 add_child_die (scope_die_for (type, context_die), type_die);
9950 for (link = TYPE_FIELDS (type);
9951 link != NULL; link = TREE_CHAIN (link))
9953 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link);
9955 add_name_attribute (enum_die,
9956 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9958 if (host_integerp (TREE_VALUE (link), 0))
9960 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9961 add_AT_int (enum_die, DW_AT_const_value,
9962 tree_low_cst (TREE_VALUE (link), 0));
9963 else
9964 add_AT_unsigned (enum_die, DW_AT_const_value,
9965 tree_low_cst (TREE_VALUE (link), 0));
9969 else
9970 add_AT_flag (type_die, DW_AT_declaration, 1);
9973 /* Generate a DIE to represent either a real live formal parameter decl or to
9974 represent just the type of some formal parameter position in some function
9975 type.
9977 Note that this routine is a bit unusual because its argument may be a
9978 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9979 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9980 node. If it's the former then this function is being called to output a
9981 DIE to represent a formal parameter object (or some inlining thereof). If
9982 it's the latter, then this function is only being called to output a
9983 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9984 argument type of some subprogram type. */
9986 static dw_die_ref
9987 gen_formal_parameter_die (node, context_die)
9988 tree node;
9989 dw_die_ref context_die;
9991 dw_die_ref parm_die
9992 = new_die (DW_TAG_formal_parameter, context_die, node);
9993 tree origin;
9995 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9997 case 'd':
9998 origin = decl_ultimate_origin (node);
9999 if (origin != NULL)
10000 add_abstract_origin_attribute (parm_die, origin);
10001 else
10003 add_name_and_src_coords_attributes (parm_die, node);
10004 add_type_attribute (parm_die, TREE_TYPE (node),
10005 TREE_READONLY (node),
10006 TREE_THIS_VOLATILE (node),
10007 context_die);
10008 if (DECL_ARTIFICIAL (node))
10009 add_AT_flag (parm_die, DW_AT_artificial, 1);
10012 equate_decl_number_to_die (node, parm_die);
10013 if (! DECL_ABSTRACT (node))
10014 add_location_or_const_value_attribute (parm_die, node);
10016 break;
10018 case 't':
10019 /* We were called with some kind of a ..._TYPE node. */
10020 add_type_attribute (parm_die, node, 0, 0, context_die);
10021 break;
10023 default:
10024 abort ();
10027 return parm_die;
10030 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
10031 at the end of an (ANSI prototyped) formal parameters list. */
10033 static void
10034 gen_unspecified_parameters_die (decl_or_type, context_die)
10035 tree decl_or_type;
10036 dw_die_ref context_die;
10038 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type);
10041 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
10042 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
10043 parameters as specified in some function type specification (except for
10044 those which appear as part of a function *definition*). */
10046 static void
10047 gen_formal_types_die (function_or_method_type, context_die)
10048 tree function_or_method_type;
10049 dw_die_ref context_die;
10051 tree link;
10052 tree formal_type = NULL;
10053 tree first_parm_type;
10054 tree arg;
10056 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
10058 arg = DECL_ARGUMENTS (function_or_method_type);
10059 function_or_method_type = TREE_TYPE (function_or_method_type);
10061 else
10062 arg = NULL_TREE;
10064 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
10066 /* Make our first pass over the list of formal parameter types and output a
10067 DW_TAG_formal_parameter DIE for each one. */
10068 for (link = first_parm_type; link; )
10070 dw_die_ref parm_die;
10072 formal_type = TREE_VALUE (link);
10073 if (formal_type == void_type_node)
10074 break;
10076 /* Output a (nameless) DIE to represent the formal parameter itself. */
10077 parm_die = gen_formal_parameter_die (formal_type, context_die);
10078 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
10079 && link == first_parm_type)
10080 || (arg && DECL_ARTIFICIAL (arg)))
10081 add_AT_flag (parm_die, DW_AT_artificial, 1);
10083 link = TREE_CHAIN (link);
10084 if (arg)
10085 arg = TREE_CHAIN (arg);
10088 /* If this function type has an ellipsis, add a
10089 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
10090 if (formal_type != void_type_node)
10091 gen_unspecified_parameters_die (function_or_method_type, context_die);
10093 /* Make our second (and final) pass over the list of formal parameter types
10094 and output DIEs to represent those types (as necessary). */
10095 for (link = TYPE_ARG_TYPES (function_or_method_type);
10096 link && TREE_VALUE (link);
10097 link = TREE_CHAIN (link))
10098 gen_type_die (TREE_VALUE (link), context_die);
10101 /* We want to generate the DIE for TYPE so that we can generate the
10102 die for MEMBER, which has been defined; we will need to refer back
10103 to the member declaration nested within TYPE. If we're trying to
10104 generate minimal debug info for TYPE, processing TYPE won't do the
10105 trick; we need to attach the member declaration by hand. */
10107 static void
10108 gen_type_die_for_member (type, member, context_die)
10109 tree type, member;
10110 dw_die_ref context_die;
10112 gen_type_die (type, context_die);
10114 /* If we're trying to avoid duplicate debug info, we may not have
10115 emitted the member decl for this function. Emit it now. */
10116 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
10117 && ! lookup_decl_die (member))
10119 if (decl_ultimate_origin (member))
10120 abort ();
10122 push_decl_scope (type);
10123 if (TREE_CODE (member) == FUNCTION_DECL)
10124 gen_subprogram_die (member, lookup_type_die (type));
10125 else
10126 gen_variable_die (member, lookup_type_die (type));
10128 pop_decl_scope ();
10132 /* Generate the DWARF2 info for the "abstract" instance of a function which we
10133 may later generate inlined and/or out-of-line instances of. */
10135 static void
10136 dwarf2out_abstract_function (decl)
10137 tree decl;
10139 dw_die_ref old_die;
10140 tree save_fn;
10141 tree context;
10142 int was_abstract = DECL_ABSTRACT (decl);
10144 /* Make sure we have the actual abstract inline, not a clone. */
10145 decl = DECL_ORIGIN (decl);
10147 old_die = lookup_decl_die (decl);
10148 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
10149 /* We've already generated the abstract instance. */
10150 return;
10152 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
10153 we don't get confused by DECL_ABSTRACT. */
10154 if (debug_info_level > DINFO_LEVEL_TERSE)
10156 context = decl_class_context (decl);
10157 if (context)
10158 gen_type_die_for_member
10159 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
10162 /* Pretend we've just finished compiling this function. */
10163 save_fn = current_function_decl;
10164 current_function_decl = decl;
10166 set_decl_abstract_flags (decl, 1);
10167 dwarf2out_decl (decl);
10168 if (! was_abstract)
10169 set_decl_abstract_flags (decl, 0);
10171 current_function_decl = save_fn;
10174 /* Generate a DIE to represent a declared function (either file-scope or
10175 block-local). */
10177 static void
10178 gen_subprogram_die (decl, context_die)
10179 tree decl;
10180 dw_die_ref context_die;
10182 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
10183 tree origin = decl_ultimate_origin (decl);
10184 dw_die_ref subr_die;
10185 rtx fp_reg;
10186 tree fn_arg_types;
10187 tree outer_scope;
10188 dw_die_ref old_die = lookup_decl_die (decl);
10189 int declaration = (current_function_decl != decl
10190 || class_scope_p (context_die));
10192 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
10193 started to generate the abstract instance of an inline, decided to output
10194 its containing class, and proceeded to emit the declaration of the inline
10195 from the member list for the class. If so, DECLARATION takes priority;
10196 we'll get back to the abstract instance when done with the class. */
10198 /* The class-scope declaration DIE must be the primary DIE. */
10199 if (origin && declaration && class_scope_p (context_die))
10201 origin = NULL;
10202 if (old_die)
10203 abort ();
10206 if (origin != NULL)
10208 if (declaration && ! local_scope_p (context_die))
10209 abort ();
10211 /* Fixup die_parent for the abstract instance of a nested
10212 inline function. */
10213 if (old_die && old_die->die_parent == NULL)
10214 add_child_die (context_die, old_die);
10216 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10217 add_abstract_origin_attribute (subr_die, origin);
10219 else if (old_die)
10221 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10223 if (!get_AT_flag (old_die, DW_AT_declaration)
10224 /* We can have a normal definition following an inline one in the
10225 case of redefinition of GNU C extern inlines.
10226 It seems reasonable to use AT_specification in this case. */
10227 && !get_AT_unsigned (old_die, DW_AT_inline))
10229 /* ??? This can happen if there is a bug in the program, for
10230 instance, if it has duplicate function definitions. Ideally,
10231 we should detect this case and ignore it. For now, if we have
10232 already reported an error, any error at all, then assume that
10233 we got here because of an input error, not a dwarf2 bug. */
10234 if (errorcount)
10235 return;
10236 abort ();
10239 /* If the definition comes from the same place as the declaration,
10240 maybe use the old DIE. We always want the DIE for this function
10241 that has the *_pc attributes to be under comp_unit_die so the
10242 debugger can find it. We also need to do this for abstract
10243 instances of inlines, since the spec requires the out-of-line copy
10244 to have the same parent. For local class methods, this doesn't
10245 apply; we just use the old DIE. */
10246 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
10247 && (DECL_ARTIFICIAL (decl)
10248 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
10249 && (get_AT_unsigned (old_die, DW_AT_decl_line)
10250 == (unsigned) DECL_SOURCE_LINE (decl)))))
10252 subr_die = old_die;
10254 /* Clear out the declaration attribute and the parm types. */
10255 remove_AT (subr_die, DW_AT_declaration);
10256 remove_children (subr_die);
10258 else
10260 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10261 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
10262 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10263 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
10264 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10265 != (unsigned) DECL_SOURCE_LINE (decl))
10266 add_AT_unsigned
10267 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
10270 else
10272 subr_die = new_die (DW_TAG_subprogram, context_die, decl);
10274 if (TREE_PUBLIC (decl))
10275 add_AT_flag (subr_die, DW_AT_external, 1);
10277 add_name_and_src_coords_attributes (subr_die, decl);
10278 if (debug_info_level > DINFO_LEVEL_TERSE)
10280 add_prototyped_attribute (subr_die, TREE_TYPE (decl));
10281 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)),
10282 0, 0, context_die);
10285 add_pure_or_virtual_attribute (subr_die, decl);
10286 if (DECL_ARTIFICIAL (decl))
10287 add_AT_flag (subr_die, DW_AT_artificial, 1);
10289 if (TREE_PROTECTED (decl))
10290 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
10291 else if (TREE_PRIVATE (decl))
10292 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
10295 if (declaration)
10297 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10299 add_AT_flag (subr_die, DW_AT_declaration, 1);
10301 /* The first time we see a member function, it is in the context of
10302 the class to which it belongs. We make sure of this by emitting
10303 the class first. The next time is the definition, which is
10304 handled above. The two may come from the same source text. */
10305 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
10306 equate_decl_number_to_die (decl, subr_die);
10309 else if (DECL_ABSTRACT (decl))
10311 if (DECL_INLINE (decl) && !flag_no_inline)
10313 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
10314 inline functions, but not for extern inline functions.
10315 We can't get this completely correct because information
10316 about whether the function was declared inline is not
10317 saved anywhere. */
10318 if (DECL_DEFER_OUTPUT (decl))
10319 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
10320 else
10321 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
10323 else
10324 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
10326 equate_decl_number_to_die (decl, subr_die);
10328 else if (!DECL_EXTERNAL (decl))
10330 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline))
10331 equate_decl_number_to_die (decl, subr_die);
10333 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
10334 current_funcdef_number);
10335 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
10336 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
10337 current_funcdef_number);
10338 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
10340 add_pubname (decl, subr_die);
10341 add_arange (decl, subr_die);
10343 #ifdef MIPS_DEBUGGING_INFO
10344 /* Add a reference to the FDE for this routine. */
10345 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
10346 #endif
10348 /* Define the "frame base" location for this routine. We use the
10349 frame pointer or stack pointer registers, since the RTL for local
10350 variables is relative to one of them. */
10351 fp_reg
10352 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
10353 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
10355 #if 0
10356 /* ??? This fails for nested inline functions, because context_display
10357 is not part of the state saved/restored for inline functions. */
10358 if (current_function_needs_context)
10359 add_AT_location_description (subr_die, DW_AT_static_link,
10360 lookup_static_chain (decl));
10361 #endif
10364 /* Now output descriptions of the arguments for this function. This gets
10365 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
10366 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
10367 `...' at the end of the formal parameter list. In order to find out if
10368 there was a trailing ellipsis or not, we must instead look at the type
10369 associated with the FUNCTION_DECL. This will be a node of type
10370 FUNCTION_TYPE. If the chain of type nodes hanging off of this
10371 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
10372 an ellipsis at the end. */
10374 /* In the case where we are describing a mere function declaration, all we
10375 need to do here (and all we *can* do here) is to describe the *types* of
10376 its formal parameters. */
10377 if (debug_info_level <= DINFO_LEVEL_TERSE)
10379 else if (declaration)
10380 gen_formal_types_die (decl, subr_die);
10381 else
10383 /* Generate DIEs to represent all known formal parameters */
10384 tree arg_decls = DECL_ARGUMENTS (decl);
10385 tree parm;
10387 /* When generating DIEs, generate the unspecified_parameters DIE
10388 instead if we come across the arg "__builtin_va_alist" */
10389 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
10390 if (TREE_CODE (parm) == PARM_DECL)
10392 if (DECL_NAME (parm)
10393 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
10394 "__builtin_va_alist"))
10395 gen_unspecified_parameters_die (parm, subr_die);
10396 else
10397 gen_decl_die (parm, subr_die);
10400 /* Decide whether we need an unspecified_parameters DIE at the end.
10401 There are 2 more cases to do this for: 1) the ansi ... declaration -
10402 this is detectable when the end of the arg list is not a
10403 void_type_node 2) an unprototyped function declaration (not a
10404 definition). This just means that we have no info about the
10405 parameters at all. */
10406 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
10407 if (fn_arg_types != NULL)
10409 /* this is the prototyped case, check for ... */
10410 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
10411 gen_unspecified_parameters_die (decl, subr_die);
10413 else if (DECL_INITIAL (decl) == NULL_TREE)
10414 gen_unspecified_parameters_die (decl, subr_die);
10417 /* Output Dwarf info for all of the stuff within the body of the function
10418 (if it has one - it may be just a declaration). */
10419 outer_scope = DECL_INITIAL (decl);
10421 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
10422 a function. This BLOCK actually represents the outermost binding contour
10423 for the function, i.e. the contour in which the function's formal
10424 parameters and labels get declared. Curiously, it appears that the front
10425 end doesn't actually put the PARM_DECL nodes for the current function onto
10426 the BLOCK_VARS list for this outer scope, but are strung off of the
10427 DECL_ARGUMENTS list for the function instead.
10429 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
10430 the LABEL_DECL nodes for the function however, and we output DWARF info
10431 for those in decls_for_scope. Just within the `outer_scope' there will be
10432 a BLOCK node representing the function's outermost pair of curly braces,
10433 and any blocks used for the base and member initializers of a C++
10434 constructor function. */
10435 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
10437 current_function_has_inlines = 0;
10438 decls_for_scope (outer_scope, subr_die, 0);
10440 #if 0 && defined (MIPS_DEBUGGING_INFO)
10441 if (current_function_has_inlines)
10443 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
10444 if (! comp_unit_has_inlines)
10446 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
10447 comp_unit_has_inlines = 1;
10450 #endif
10454 /* Generate a DIE to represent a declared data object. */
10456 static void
10457 gen_variable_die (decl, context_die)
10458 tree decl;
10459 dw_die_ref context_die;
10461 tree origin = decl_ultimate_origin (decl);
10462 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl);
10464 dw_die_ref old_die = lookup_decl_die (decl);
10465 int declaration = (DECL_EXTERNAL (decl)
10466 || class_scope_p (context_die));
10468 if (origin != NULL)
10469 add_abstract_origin_attribute (var_die, origin);
10471 /* Loop unrolling can create multiple blocks that refer to the same
10472 static variable, so we must test for the DW_AT_declaration flag.
10474 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
10475 copy decls and set the DECL_ABSTRACT flag on them instead of
10476 sharing them.
10478 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
10479 else if (old_die && TREE_STATIC (decl)
10480 && get_AT_flag (old_die, DW_AT_declaration) == 1)
10482 /* This is a definition of a C++ class level static. */
10483 add_AT_die_ref (var_die, DW_AT_specification, old_die);
10484 if (DECL_NAME (decl))
10486 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
10488 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
10489 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
10491 if (get_AT_unsigned (old_die, DW_AT_decl_line)
10492 != (unsigned) DECL_SOURCE_LINE (decl))
10494 add_AT_unsigned (var_die, DW_AT_decl_line,
10495 DECL_SOURCE_LINE (decl));
10498 else
10500 add_name_and_src_coords_attributes (var_die, decl);
10501 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl),
10502 TREE_THIS_VOLATILE (decl), context_die);
10504 if (TREE_PUBLIC (decl))
10505 add_AT_flag (var_die, DW_AT_external, 1);
10507 if (DECL_ARTIFICIAL (decl))
10508 add_AT_flag (var_die, DW_AT_artificial, 1);
10510 if (TREE_PROTECTED (decl))
10511 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
10512 else if (TREE_PRIVATE (decl))
10513 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
10516 if (declaration)
10517 add_AT_flag (var_die, DW_AT_declaration, 1);
10519 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
10520 equate_decl_number_to_die (decl, var_die);
10522 if (! declaration && ! DECL_ABSTRACT (decl))
10524 add_location_or_const_value_attribute (var_die, decl);
10525 add_pubname (decl, var_die);
10527 else
10528 tree_add_const_value_attribute (var_die, decl);
10531 /* Generate a DIE to represent a label identifier. */
10533 static void
10534 gen_label_die (decl, context_die)
10535 tree decl;
10536 dw_die_ref context_die;
10538 tree origin = decl_ultimate_origin (decl);
10539 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl);
10540 rtx insn;
10541 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10543 if (origin != NULL)
10544 add_abstract_origin_attribute (lbl_die, origin);
10545 else
10546 add_name_and_src_coords_attributes (lbl_die, decl);
10548 if (DECL_ABSTRACT (decl))
10549 equate_decl_number_to_die (decl, lbl_die);
10550 else
10552 insn = DECL_RTL (decl);
10554 /* Deleted labels are programmer specified labels which have been
10555 eliminated because of various optimisations. We still emit them
10556 here so that it is possible to put breakpoints on them. */
10557 if (GET_CODE (insn) == CODE_LABEL
10558 || ((GET_CODE (insn) == NOTE
10559 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10561 /* When optimization is enabled (via -O) some parts of the compiler
10562 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10563 represent source-level labels which were explicitly declared by
10564 the user. This really shouldn't be happening though, so catch
10565 it if it ever does happen. */
10566 if (INSN_DELETED_P (insn))
10567 abort ();
10569 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10570 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10575 /* Generate a DIE for a lexical block. */
10577 static void
10578 gen_lexical_block_die (stmt, context_die, depth)
10579 tree stmt;
10580 dw_die_ref context_die;
10581 int depth;
10583 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt);
10584 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10586 if (! BLOCK_ABSTRACT (stmt))
10588 if (BLOCK_FRAGMENT_CHAIN (stmt))
10590 tree chain;
10592 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt));
10594 chain = BLOCK_FRAGMENT_CHAIN (stmt);
10597 add_ranges (chain);
10598 chain = BLOCK_FRAGMENT_CHAIN (chain);
10600 while (chain);
10601 add_ranges (NULL);
10603 else
10605 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10606 BLOCK_NUMBER (stmt));
10607 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10608 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10609 BLOCK_NUMBER (stmt));
10610 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10614 decls_for_scope (stmt, stmt_die, depth);
10617 /* Generate a DIE for an inlined subprogram. */
10619 static void
10620 gen_inlined_subroutine_die (stmt, context_die, depth)
10621 tree stmt;
10622 dw_die_ref context_die;
10623 int depth;
10625 if (! BLOCK_ABSTRACT (stmt))
10627 dw_die_ref subr_die
10628 = new_die (DW_TAG_inlined_subroutine, context_die, stmt);
10629 tree decl = block_ultimate_origin (stmt);
10630 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10632 /* Emit info for the abstract instance first, if we haven't yet. */
10633 dwarf2out_abstract_function (decl);
10635 add_abstract_origin_attribute (subr_die, decl);
10636 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10637 BLOCK_NUMBER (stmt));
10638 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10639 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10640 BLOCK_NUMBER (stmt));
10641 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10642 decls_for_scope (stmt, subr_die, depth);
10643 current_function_has_inlines = 1;
10645 else
10646 /* We may get here if we're the outer block of function A that was
10647 inlined into function B that was inlined into function C. When
10648 generating debugging info for C, dwarf2out_abstract_function(B)
10649 would mark all inlined blocks as abstract, including this one.
10650 So, we wouldn't (and shouldn't) expect labels to be generated
10651 for this one. Instead, just emit debugging info for
10652 declarations within the block. This is particularly important
10653 in the case of initializers of arguments passed from B to us:
10654 if they're statement expressions containing declarations, we
10655 wouldn't generate dies for their abstract variables, and then,
10656 when generating dies for the real variables, we'd die (pun
10657 intended :-) */
10658 gen_lexical_block_die (stmt, context_die, depth);
10661 /* Generate a DIE for a field in a record, or structure. */
10663 static void
10664 gen_field_die (decl, context_die)
10665 tree decl;
10666 dw_die_ref context_die;
10668 dw_die_ref decl_die = new_die (DW_TAG_member, context_die, decl);
10670 add_name_and_src_coords_attributes (decl_die, decl);
10671 add_type_attribute (decl_die, member_declared_type (decl),
10672 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10673 context_die);
10675 if (DECL_BIT_FIELD_TYPE (decl))
10677 add_byte_size_attribute (decl_die, decl);
10678 add_bit_size_attribute (decl_die, decl);
10679 add_bit_offset_attribute (decl_die, decl);
10682 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10683 add_data_member_location_attribute (decl_die, decl);
10685 if (DECL_ARTIFICIAL (decl))
10686 add_AT_flag (decl_die, DW_AT_artificial, 1);
10688 if (TREE_PROTECTED (decl))
10689 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10690 else if (TREE_PRIVATE (decl))
10691 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10694 #if 0
10695 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10696 Use modified_type_die instead.
10697 We keep this code here just in case these types of DIEs may be needed to
10698 represent certain things in other languages (e.g. Pascal) someday. */
10700 static void
10701 gen_pointer_type_die (type, context_die)
10702 tree type;
10703 dw_die_ref context_die;
10705 dw_die_ref ptr_die
10706 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type);
10708 equate_type_number_to_die (type, ptr_die);
10709 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10710 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10713 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10714 Use modified_type_die instead.
10715 We keep this code here just in case these types of DIEs may be needed to
10716 represent certain things in other languages (e.g. Pascal) someday. */
10718 static void
10719 gen_reference_type_die (type, context_die)
10720 tree type;
10721 dw_die_ref context_die;
10723 dw_die_ref ref_die
10724 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type);
10726 equate_type_number_to_die (type, ref_die);
10727 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10728 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10730 #endif
10732 /* Generate a DIE for a pointer to a member type. */
10734 static void
10735 gen_ptr_to_mbr_type_die (type, context_die)
10736 tree type;
10737 dw_die_ref context_die;
10739 dw_die_ref ptr_die
10740 = new_die (DW_TAG_ptr_to_member_type,
10741 scope_die_for (type, context_die), type);
10743 equate_type_number_to_die (type, ptr_die);
10744 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10745 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10746 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10749 /* Generate the DIE for the compilation unit. */
10751 static dw_die_ref
10752 gen_compile_unit_die (filename)
10753 const char *filename;
10755 dw_die_ref die;
10756 char producer[250];
10757 const char *wd = getpwd ();
10758 const char *language_string = lang_hooks.name;
10759 int language;
10761 die = new_die (DW_TAG_compile_unit, NULL, NULL);
10762 add_name_attribute (die, filename);
10764 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10765 add_AT_string (die, DW_AT_comp_dir, wd);
10767 sprintf (producer, "%s %s", language_string, version_string);
10769 #ifdef MIPS_DEBUGGING_INFO
10770 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10771 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10772 not appear in the producer string, the debugger reaches the conclusion
10773 that the object file is stripped and has no debugging information.
10774 To get the MIPS/SGI debugger to believe that there is debugging
10775 information in the object file, we add a -g to the producer string. */
10776 if (debug_info_level > DINFO_LEVEL_TERSE)
10777 strcat (producer, " -g");
10778 #endif
10780 add_AT_string (die, DW_AT_producer, producer);
10782 if (strcmp (language_string, "GNU C++") == 0)
10783 language = DW_LANG_C_plus_plus;
10784 else if (strcmp (language_string, "GNU Ada") == 0)
10785 language = DW_LANG_Ada83;
10786 else if (strcmp (language_string, "GNU F77") == 0)
10787 language = DW_LANG_Fortran77;
10788 else if (strcmp (language_string, "GNU Pascal") == 0)
10789 language = DW_LANG_Pascal83;
10790 else if (strcmp (language_string, "GNU Java") == 0)
10791 language = DW_LANG_Java;
10792 else if (flag_traditional)
10793 language = DW_LANG_C;
10794 else
10795 language = DW_LANG_C89;
10797 add_AT_unsigned (die, DW_AT_language, language);
10798 return die;
10801 /* Generate a DIE for a string type. */
10803 static void
10804 gen_string_type_die (type, context_die)
10805 tree type;
10806 dw_die_ref context_die;
10808 dw_die_ref type_die
10809 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type);
10811 equate_type_number_to_die (type, type_die);
10813 /* ??? Fudge the string length attribute for now.
10814 TODO: add string length info. */
10815 #if 0
10816 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10817 bound_representation (upper_bound, 0, 'u');
10818 #endif
10821 /* Generate the DIE for a base class. */
10823 static void
10824 gen_inheritance_die (binfo, context_die)
10825 tree binfo;
10826 dw_die_ref context_die;
10828 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo);
10830 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10831 add_data_member_location_attribute (die, binfo);
10833 if (TREE_VIA_VIRTUAL (binfo))
10834 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10836 if (TREE_VIA_PUBLIC (binfo))
10837 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10838 else if (TREE_VIA_PROTECTED (binfo))
10839 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10842 /* Generate a DIE for a class member. */
10844 static void
10845 gen_member_die (type, context_die)
10846 tree type;
10847 dw_die_ref context_die;
10849 tree member;
10850 dw_die_ref child;
10852 /* If this is not an incomplete type, output descriptions of each of its
10853 members. Note that as we output the DIEs necessary to represent the
10854 members of this record or union type, we will also be trying to output
10855 DIEs to represent the *types* of those members. However the `type'
10856 function (above) will specifically avoid generating type DIEs for member
10857 types *within* the list of member DIEs for this (containing) type except
10858 for those types (of members) which are explicitly marked as also being
10859 members of this (containing) type themselves. The g++ front- end can
10860 force any given type to be treated as a member of some other (containing)
10861 type by setting the TYPE_CONTEXT of the given (member) type to point to
10862 the TREE node representing the appropriate (containing) type. */
10864 /* First output info about the base classes. */
10865 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10867 tree bases = TYPE_BINFO_BASETYPES (type);
10868 int n_bases = TREE_VEC_LENGTH (bases);
10869 int i;
10871 for (i = 0; i < n_bases; i++)
10872 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10875 /* Now output info about the data members and type members. */
10876 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10878 /* If we thought we were generating minimal debug info for TYPE
10879 and then changed our minds, some of the member declarations
10880 may have already been defined. Don't define them again, but
10881 do put them in the right order. */
10883 child = lookup_decl_die (member);
10884 if (child)
10885 splice_child_die (context_die, child);
10886 else
10887 gen_decl_die (member, context_die);
10890 /* Now output info about the function members (if any). */
10891 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10893 /* Don't include clones in the member list. */
10894 if (DECL_ABSTRACT_ORIGIN (member))
10895 continue;
10897 child = lookup_decl_die (member);
10898 if (child)
10899 splice_child_die (context_die, child);
10900 else
10901 gen_decl_die (member, context_die);
10905 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10906 is set, we pretend that the type was never defined, so we only get the
10907 member DIEs needed by later specification DIEs. */
10909 static void
10910 gen_struct_or_union_type_die (type, context_die)
10911 tree type;
10912 dw_die_ref context_die;
10914 dw_die_ref type_die = lookup_type_die (type);
10915 dw_die_ref scope_die = 0;
10916 int nested = 0;
10917 int complete = (TYPE_SIZE (type)
10918 && (! TYPE_STUB_DECL (type)
10919 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10921 if (type_die && ! complete)
10922 return;
10924 if (TYPE_CONTEXT (type) != NULL_TREE
10925 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10926 nested = 1;
10928 scope_die = scope_die_for (type, context_die);
10930 if (! type_die || (nested && scope_die == comp_unit_die))
10931 /* First occurrence of type or toplevel definition of nested class. */
10933 dw_die_ref old_die = type_die;
10935 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10936 ? DW_TAG_structure_type : DW_TAG_union_type,
10937 scope_die, type);
10938 equate_type_number_to_die (type, type_die);
10939 if (old_die)
10940 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10941 else
10942 add_name_attribute (type_die, type_tag (type));
10944 else
10945 remove_AT (type_die, DW_AT_declaration);
10947 /* If this type has been completed, then give it a byte_size attribute and
10948 then give a list of members. */
10949 if (complete)
10951 /* Prevent infinite recursion in cases where the type of some member of
10952 this type is expressed in terms of this type itself. */
10953 TREE_ASM_WRITTEN (type) = 1;
10954 add_byte_size_attribute (type_die, type);
10955 if (TYPE_STUB_DECL (type) != NULL_TREE)
10956 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10958 /* If the first reference to this type was as the return type of an
10959 inline function, then it may not have a parent. Fix this now. */
10960 if (type_die->die_parent == NULL)
10961 add_child_die (scope_die, type_die);
10963 push_decl_scope (type);
10964 gen_member_die (type, type_die);
10965 pop_decl_scope ();
10967 /* GNU extension: Record what type our vtable lives in. */
10968 if (TYPE_VFIELD (type))
10970 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10972 gen_type_die (vtype, context_die);
10973 add_AT_die_ref (type_die, DW_AT_containing_type,
10974 lookup_type_die (vtype));
10977 else
10979 add_AT_flag (type_die, DW_AT_declaration, 1);
10981 /* We don't need to do this for function-local types. */
10982 if (TYPE_STUB_DECL (type)
10983 && ! decl_function_context (TYPE_STUB_DECL (type)))
10984 VARRAY_PUSH_TREE (incomplete_types, type);
10988 /* Generate a DIE for a subroutine _type_. */
10990 static void
10991 gen_subroutine_type_die (type, context_die)
10992 tree type;
10993 dw_die_ref context_die;
10995 tree return_type = TREE_TYPE (type);
10996 dw_die_ref subr_die
10997 = new_die (DW_TAG_subroutine_type,
10998 scope_die_for (type, context_die), type);
11000 equate_type_number_to_die (type, subr_die);
11001 add_prototyped_attribute (subr_die, type);
11002 add_type_attribute (subr_die, return_type, 0, 0, context_die);
11003 gen_formal_types_die (type, subr_die);
11006 /* Generate a DIE for a type definition */
11008 static void
11009 gen_typedef_die (decl, context_die)
11010 tree decl;
11011 dw_die_ref context_die;
11013 dw_die_ref type_die;
11014 tree origin;
11016 if (TREE_ASM_WRITTEN (decl))
11017 return;
11019 TREE_ASM_WRITTEN (decl) = 1;
11020 type_die = new_die (DW_TAG_typedef, context_die, decl);
11021 origin = decl_ultimate_origin (decl);
11022 if (origin != NULL)
11023 add_abstract_origin_attribute (type_die, origin);
11024 else
11026 tree type;
11028 add_name_and_src_coords_attributes (type_die, decl);
11029 if (DECL_ORIGINAL_TYPE (decl))
11031 type = DECL_ORIGINAL_TYPE (decl);
11033 if (type == TREE_TYPE (decl))
11034 abort ();
11035 else
11036 equate_type_number_to_die (TREE_TYPE (decl), type_die);
11038 else
11039 type = TREE_TYPE (decl);
11041 add_type_attribute (type_die, type, TREE_READONLY (decl),
11042 TREE_THIS_VOLATILE (decl), context_die);
11045 if (DECL_ABSTRACT (decl))
11046 equate_decl_number_to_die (decl, type_die);
11049 /* Generate a type description DIE. */
11051 static void
11052 gen_type_die (type, context_die)
11053 tree type;
11054 dw_die_ref context_die;
11056 int need_pop;
11058 if (type == NULL_TREE || type == error_mark_node)
11059 return;
11061 /* We are going to output a DIE to represent the unqualified version of
11062 this type (i.e. without any const or volatile qualifiers) so get the
11063 main variant (i.e. the unqualified version) of this type now. */
11064 type = type_main_variant (type);
11066 if (TREE_ASM_WRITTEN (type))
11067 return;
11069 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
11070 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
11072 TREE_ASM_WRITTEN (type) = 1;
11073 gen_decl_die (TYPE_NAME (type), context_die);
11074 return;
11077 switch (TREE_CODE (type))
11079 case ERROR_MARK:
11080 break;
11082 case POINTER_TYPE:
11083 case REFERENCE_TYPE:
11084 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
11085 ensures that the gen_type_die recursion will terminate even if the
11086 type is recursive. Recursive types are possible in Ada. */
11087 /* ??? We could perhaps do this for all types before the switch
11088 statement. */
11089 TREE_ASM_WRITTEN (type) = 1;
11091 /* For these types, all that is required is that we output a DIE (or a
11092 set of DIEs) to represent the "basis" type. */
11093 gen_type_die (TREE_TYPE (type), context_die);
11094 break;
11096 case OFFSET_TYPE:
11097 /* This code is used for C++ pointer-to-data-member types.
11098 Output a description of the relevant class type. */
11099 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
11101 /* Output a description of the type of the object pointed to. */
11102 gen_type_die (TREE_TYPE (type), context_die);
11104 /* Now output a DIE to represent this pointer-to-data-member type
11105 itself. */
11106 gen_ptr_to_mbr_type_die (type, context_die);
11107 break;
11109 case SET_TYPE:
11110 gen_type_die (TYPE_DOMAIN (type), context_die);
11111 gen_set_type_die (type, context_die);
11112 break;
11114 case FILE_TYPE:
11115 gen_type_die (TREE_TYPE (type), context_die);
11116 abort (); /* No way to represent these in Dwarf yet! */
11117 break;
11119 case FUNCTION_TYPE:
11120 /* Force out return type (in case it wasn't forced out already). */
11121 gen_type_die (TREE_TYPE (type), context_die);
11122 gen_subroutine_type_die (type, context_die);
11123 break;
11125 case METHOD_TYPE:
11126 /* Force out return type (in case it wasn't forced out already). */
11127 gen_type_die (TREE_TYPE (type), context_die);
11128 gen_subroutine_type_die (type, context_die);
11129 break;
11131 case ARRAY_TYPE:
11132 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
11134 gen_type_die (TREE_TYPE (type), context_die);
11135 gen_string_type_die (type, context_die);
11137 else
11138 gen_array_type_die (type, context_die);
11139 break;
11141 case VECTOR_TYPE:
11142 gen_array_type_die (type, context_die);
11143 break;
11145 case ENUMERAL_TYPE:
11146 case RECORD_TYPE:
11147 case UNION_TYPE:
11148 case QUAL_UNION_TYPE:
11149 /* If this is a nested type whose containing class hasn't been written
11150 out yet, writing it out will cover this one, too. This does not apply
11151 to instantiations of member class templates; they need to be added to
11152 the containing class as they are generated. FIXME: This hurts the
11153 idea of combining type decls from multiple TUs, since we can't predict
11154 what set of template instantiations we'll get. */
11155 if (TYPE_CONTEXT (type)
11156 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
11157 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
11159 gen_type_die (TYPE_CONTEXT (type), context_die);
11161 if (TREE_ASM_WRITTEN (type))
11162 return;
11164 /* If that failed, attach ourselves to the stub. */
11165 push_decl_scope (TYPE_CONTEXT (type));
11166 context_die = lookup_type_die (TYPE_CONTEXT (type));
11167 need_pop = 1;
11169 else
11170 need_pop = 0;
11172 if (TREE_CODE (type) == ENUMERAL_TYPE)
11173 gen_enumeration_type_die (type, context_die);
11174 else
11175 gen_struct_or_union_type_die (type, context_die);
11177 if (need_pop)
11178 pop_decl_scope ();
11180 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
11181 it up if it is ever completed. gen_*_type_die will set it for us
11182 when appropriate. */
11183 return;
11185 case VOID_TYPE:
11186 case INTEGER_TYPE:
11187 case REAL_TYPE:
11188 case COMPLEX_TYPE:
11189 case BOOLEAN_TYPE:
11190 case CHAR_TYPE:
11191 /* No DIEs needed for fundamental types. */
11192 break;
11194 case LANG_TYPE:
11195 /* No Dwarf representation currently defined. */
11196 break;
11198 default:
11199 abort ();
11202 TREE_ASM_WRITTEN (type) = 1;
11205 /* Generate a DIE for a tagged type instantiation. */
11207 static void
11208 gen_tagged_type_instantiation_die (type, context_die)
11209 tree type;
11210 dw_die_ref context_die;
11212 if (type == NULL_TREE || type == error_mark_node)
11213 return;
11215 /* We are going to output a DIE to represent the unqualified version of
11216 this type (i.e. without any const or volatile qualifiers) so make sure
11217 that we have the main variant (i.e. the unqualified version) of this
11218 type now. */
11219 if (type != type_main_variant (type))
11220 abort ();
11222 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
11223 an instance of an unresolved type. */
11225 switch (TREE_CODE (type))
11227 case ERROR_MARK:
11228 break;
11230 case ENUMERAL_TYPE:
11231 gen_inlined_enumeration_type_die (type, context_die);
11232 break;
11234 case RECORD_TYPE:
11235 gen_inlined_structure_type_die (type, context_die);
11236 break;
11238 case UNION_TYPE:
11239 case QUAL_UNION_TYPE:
11240 gen_inlined_union_type_die (type, context_die);
11241 break;
11243 default:
11244 abort ();
11248 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
11249 things which are local to the given block. */
11251 static void
11252 gen_block_die (stmt, context_die, depth)
11253 tree stmt;
11254 dw_die_ref context_die;
11255 int depth;
11257 int must_output_die = 0;
11258 tree origin;
11259 tree decl;
11260 enum tree_code origin_code;
11262 /* Ignore blocks never really used to make RTL. */
11263 if (stmt == NULL_TREE || !TREE_USED (stmt)
11264 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
11265 return;
11267 /* If the block is one fragment of a non-contiguous block, do not
11268 process the variables, since they will have been done by the
11269 origin block. Do process subblocks. */
11270 if (BLOCK_FRAGMENT_ORIGIN (stmt))
11272 tree sub;
11274 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub))
11275 gen_block_die (sub, context_die, depth + 1);
11277 return;
11280 /* Determine the "ultimate origin" of this block. This block may be an
11281 inlined instance of an inlined instance of inline function, so we have
11282 to trace all of the way back through the origin chain to find out what
11283 sort of node actually served as the original seed for the creation of
11284 the current block. */
11285 origin = block_ultimate_origin (stmt);
11286 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
11288 /* Determine if we need to output any Dwarf DIEs at all to represent this
11289 block. */
11290 if (origin_code == FUNCTION_DECL)
11291 /* The outer scopes for inlinings *must* always be represented. We
11292 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
11293 must_output_die = 1;
11294 else
11296 /* In the case where the current block represents an inlining of the
11297 "body block" of an inline function, we must *NOT* output any DIE for
11298 this block because we have already output a DIE to represent the whole
11299 inlined function scope and the "body block" of any function doesn't
11300 really represent a different scope according to ANSI C rules. So we
11301 check here to make sure that this block does not represent a "body
11302 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */
11303 if (! is_body_block (origin ? origin : stmt))
11305 /* Determine if this block directly contains any "significant"
11306 local declarations which we will need to output DIEs for. */
11307 if (debug_info_level > DINFO_LEVEL_TERSE)
11308 /* We are not in terse mode so *any* local declaration counts
11309 as being a "significant" one. */
11310 must_output_die = (BLOCK_VARS (stmt) != NULL);
11311 else
11312 /* We are in terse mode, so only local (nested) function
11313 definitions count as "significant" local declarations. */
11314 for (decl = BLOCK_VARS (stmt);
11315 decl != NULL; decl = TREE_CHAIN (decl))
11316 if (TREE_CODE (decl) == FUNCTION_DECL
11317 && DECL_INITIAL (decl))
11319 must_output_die = 1;
11320 break;
11325 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
11326 DIE for any block which contains no significant local declarations at
11327 all. Rather, in such cases we just call `decls_for_scope' so that any
11328 needed Dwarf info for any sub-blocks will get properly generated. Note
11329 that in terse mode, our definition of what constitutes a "significant"
11330 local declaration gets restricted to include only inlined function
11331 instances and local (nested) function definitions. */
11332 if (must_output_die)
11334 if (origin_code == FUNCTION_DECL)
11335 gen_inlined_subroutine_die (stmt, context_die, depth);
11336 else
11337 gen_lexical_block_die (stmt, context_die, depth);
11339 else
11340 decls_for_scope (stmt, context_die, depth);
11343 /* Generate all of the decls declared within a given scope and (recursively)
11344 all of its sub-blocks. */
11346 static void
11347 decls_for_scope (stmt, context_die, depth)
11348 tree stmt;
11349 dw_die_ref context_die;
11350 int depth;
11352 tree decl;
11353 tree subblocks;
11355 /* Ignore blocks never really used to make RTL. */
11356 if (stmt == NULL_TREE || ! TREE_USED (stmt))
11357 return;
11359 /* Output the DIEs to represent all of the data objects and typedefs
11360 declared directly within this block but not within any nested
11361 sub-blocks. Also, nested function and tag DIEs have been
11362 generated with a parent of NULL; fix that up now. */
11363 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl))
11365 dw_die_ref die;
11367 if (TREE_CODE (decl) == FUNCTION_DECL)
11368 die = lookup_decl_die (decl);
11369 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
11370 die = lookup_type_die (TREE_TYPE (decl));
11371 else
11372 die = NULL;
11374 if (die != NULL && die->die_parent == NULL)
11375 add_child_die (context_die, die);
11376 else
11377 gen_decl_die (decl, context_die);
11380 /* Output the DIEs to represent all sub-blocks (and the items declared
11381 therein) of this block. */
11382 for (subblocks = BLOCK_SUBBLOCKS (stmt);
11383 subblocks != NULL;
11384 subblocks = BLOCK_CHAIN (subblocks))
11385 gen_block_die (subblocks, context_die, depth + 1);
11388 /* Is this a typedef we can avoid emitting? */
11390 static inline int
11391 is_redundant_typedef (decl)
11392 tree decl;
11394 if (TYPE_DECL_IS_STUB (decl))
11395 return 1;
11397 if (DECL_ARTIFICIAL (decl)
11398 && DECL_CONTEXT (decl)
11399 && is_tagged_type (DECL_CONTEXT (decl))
11400 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
11401 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
11402 /* Also ignore the artificial member typedef for the class name. */
11403 return 1;
11405 return 0;
11408 /* Generate Dwarf debug information for a decl described by DECL. */
11410 static void
11411 gen_decl_die (decl, context_die)
11412 tree decl;
11413 dw_die_ref context_die;
11415 tree origin;
11417 if (DECL_P (decl) && DECL_IGNORED_P (decl))
11418 return;
11420 switch (TREE_CODE (decl))
11422 case ERROR_MARK:
11423 break;
11425 case CONST_DECL:
11426 /* The individual enumerators of an enum type get output when we output
11427 the Dwarf representation of the relevant enum type itself. */
11428 break;
11430 case FUNCTION_DECL:
11431 /* Don't output any DIEs to represent mere function declarations,
11432 unless they are class members or explicit block externs. */
11433 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
11434 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
11435 break;
11437 /* If we're emitting a clone, emit info for the abstract instance. */
11438 if (DECL_ORIGIN (decl) != decl)
11439 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
11441 /* If we're emitting an out-of-line copy of an inline function,
11442 emit info for the abstract instance and set up to refer to it. */
11443 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
11444 && ! class_scope_p (context_die)
11445 /* dwarf2out_abstract_function won't emit a die if this is just
11446 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
11447 that case, because that works only if we have a die. */
11448 && DECL_INITIAL (decl) != NULL_TREE)
11450 dwarf2out_abstract_function (decl);
11451 set_decl_origin_self (decl);
11454 /* Otherwise we're emitting the primary DIE for this decl. */
11455 else if (debug_info_level > DINFO_LEVEL_TERSE)
11457 /* Before we describe the FUNCTION_DECL itself, make sure that we
11458 have described its return type. */
11459 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
11461 /* And its virtual context. */
11462 if (DECL_VINDEX (decl) != NULL_TREE)
11463 gen_type_die (DECL_CONTEXT (decl), context_die);
11465 /* And its containing type. */
11466 origin = decl_class_context (decl);
11467 if (origin != NULL_TREE)
11468 gen_type_die_for_member (origin, decl, context_die);
11471 /* Now output a DIE to represent the function itself. */
11472 gen_subprogram_die (decl, context_die);
11473 break;
11475 case TYPE_DECL:
11476 /* If we are in terse mode, don't generate any DIEs to represent any
11477 actual typedefs. */
11478 if (debug_info_level <= DINFO_LEVEL_TERSE)
11479 break;
11481 /* In the special case of a TYPE_DECL node representing the declaration
11482 of some type tag, if the given TYPE_DECL is marked as having been
11483 instantiated from some other (original) TYPE_DECL node (e.g. one which
11484 was generated within the original definition of an inline function) we
11485 have to generate a special (abbreviated) DW_TAG_structure_type,
11486 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */
11487 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
11489 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
11490 break;
11493 if (is_redundant_typedef (decl))
11494 gen_type_die (TREE_TYPE (decl), context_die);
11495 else
11496 /* Output a DIE to represent the typedef itself. */
11497 gen_typedef_die (decl, context_die);
11498 break;
11500 case LABEL_DECL:
11501 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11502 gen_label_die (decl, context_die);
11503 break;
11505 case VAR_DECL:
11506 /* If we are in terse mode, don't generate any DIEs to represent any
11507 variable declarations or definitions. */
11508 if (debug_info_level <= DINFO_LEVEL_TERSE)
11509 break;
11511 /* Output any DIEs that are needed to specify the type of this data
11512 object. */
11513 gen_type_die (TREE_TYPE (decl), context_die);
11515 /* And its containing type. */
11516 origin = decl_class_context (decl);
11517 if (origin != NULL_TREE)
11518 gen_type_die_for_member (origin, decl, context_die);
11520 /* Now output the DIE to represent the data object itself. This gets
11521 complicated because of the possibility that the VAR_DECL really
11522 represents an inlined instance of a formal parameter for an inline
11523 function. */
11524 origin = decl_ultimate_origin (decl);
11525 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
11526 gen_formal_parameter_die (decl, context_die);
11527 else
11528 gen_variable_die (decl, context_die);
11529 break;
11531 case FIELD_DECL:
11532 /* Ignore the nameless fields that are used to skip bits but handle C++
11533 anonymous unions. */
11534 if (DECL_NAME (decl) != NULL_TREE
11535 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
11537 gen_type_die (member_declared_type (decl), context_die);
11538 gen_field_die (decl, context_die);
11540 break;
11542 case PARM_DECL:
11543 gen_type_die (TREE_TYPE (decl), context_die);
11544 gen_formal_parameter_die (decl, context_die);
11545 break;
11547 case NAMESPACE_DECL:
11548 /* Ignore for now. */
11549 break;
11551 default:
11552 abort ();
11556 static void
11557 mark_limbo_die_list (ptr)
11558 void *ptr ATTRIBUTE_UNUSED;
11560 limbo_die_node *node;
11561 for (node = limbo_die_list; node ; node = node->next)
11562 ggc_mark_tree (node->created_for);
11565 /* Add Ada "use" clause information for SGI Workshop debugger. */
11567 void
11568 dwarf2out_add_library_unit_info (filename, context_list)
11569 const char *filename;
11570 const char *context_list;
11572 unsigned int file_index;
11574 if (filename != NULL)
11576 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL);
11577 tree context_list_decl
11578 = build_decl (LABEL_DECL, get_identifier (context_list),
11579 void_type_node);
11581 TREE_PUBLIC (context_list_decl) = TRUE;
11582 add_name_attribute (unit_die, context_list);
11583 file_index = lookup_filename (filename);
11584 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
11585 add_pubname (context_list_decl, unit_die);
11589 /* Output debug information for global decl DECL. Called from toplev.c after
11590 compilation proper has finished. */
11592 static void
11593 dwarf2out_global_decl (decl)
11594 tree decl;
11596 /* Output DWARF2 information for file-scope tentative data object
11597 declarations, file-scope (extern) function declarations (which had no
11598 corresponding body) and file-scope tagged type declarations and
11599 definitions which have not yet been forced out. */
11600 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl))
11601 dwarf2out_decl (decl);
11604 /* Write the debugging output for DECL. */
11606 void
11607 dwarf2out_decl (decl)
11608 tree decl;
11610 dw_die_ref context_die = comp_unit_die;
11612 switch (TREE_CODE (decl))
11614 case ERROR_MARK:
11615 return;
11617 case FUNCTION_DECL:
11618 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11619 builtin function. Explicit programmer-supplied declarations of
11620 these same functions should NOT be ignored however. */
11621 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11622 return;
11624 /* What we would really like to do here is to filter out all mere
11625 file-scope declarations of file-scope functions which are never
11626 referenced later within this translation unit (and keep all of ones
11627 that *are* referenced later on) but we aren't clairvoyant, so we have
11628 no idea which functions will be referenced in the future (i.e. later
11629 on within the current translation unit). So here we just ignore all
11630 file-scope function declarations which are not also definitions. If
11631 and when the debugger needs to know something about these functions,
11632 it will have to hunt around and find the DWARF information associated
11633 with the definition of the function.
11635 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
11636 nodes represent definitions and which ones represent mere
11637 declarations. We have to check DECL_INITIAL instead. That's because
11638 the C front-end supports some weird semantics for "extern inline"
11639 function definitions. These can get inlined within the current
11640 translation unit (an thus, we need to generate Dwarf info for their
11641 abstract instances so that the Dwarf info for the concrete inlined
11642 instances can have something to refer to) but the compiler never
11643 generates any out-of-lines instances of such things (despite the fact
11644 that they *are* definitions).
11646 The important point is that the C front-end marks these "extern
11647 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
11648 them anyway. Note that the C++ front-end also plays some similar games
11649 for inline function definitions appearing within include files which
11650 also contain `#pragma interface' pragmas. */
11651 if (DECL_INITIAL (decl) == NULL_TREE)
11652 return;
11654 /* If we're a nested function, initially use a parent of NULL; if we're
11655 a plain function, this will be fixed up in decls_for_scope. If
11656 we're a method, it will be ignored, since we already have a DIE. */
11657 if (decl_function_context (decl))
11658 context_die = NULL;
11659 break;
11661 case VAR_DECL:
11662 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11663 declaration and if the declaration was never even referenced from
11664 within this entire compilation unit. We suppress these DIEs in
11665 order to save space in the .debug section (by eliminating entries
11666 which are probably useless). Note that we must not suppress
11667 block-local extern declarations (whether used or not) because that
11668 would screw-up the debugger's name lookup mechanism and cause it to
11669 miss things which really ought to be in scope at a given point. */
11670 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11671 return;
11673 /* If we are in terse mode, don't generate any DIEs to represent any
11674 variable declarations or definitions. */
11675 if (debug_info_level <= DINFO_LEVEL_TERSE)
11676 return;
11677 break;
11679 case TYPE_DECL:
11680 /* Don't emit stubs for types unless they are needed by other DIEs. */
11681 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11682 return;
11684 /* Don't bother trying to generate any DIEs to represent any of the
11685 normal built-in types for the language we are compiling. */
11686 if (DECL_SOURCE_LINE (decl) == 0)
11688 /* OK, we need to generate one for `bool' so GDB knows what type
11689 comparisons have. */
11690 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11691 == DW_LANG_C_plus_plus)
11692 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE
11693 && ! DECL_IGNORED_P (decl))
11694 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11696 return;
11699 /* If we are in terse mode, don't generate any DIEs for types. */
11700 if (debug_info_level <= DINFO_LEVEL_TERSE)
11701 return;
11703 /* If we're a function-scope tag, initially use a parent of NULL;
11704 this will be fixed up in decls_for_scope. */
11705 if (decl_function_context (decl))
11706 context_die = NULL;
11708 break;
11710 default:
11711 return;
11714 gen_decl_die (decl, context_die);
11717 /* Output a marker (i.e. a label) for the beginning of the generated code for
11718 a lexical block. */
11720 static void
11721 dwarf2out_begin_block (line, blocknum)
11722 unsigned int line ATTRIBUTE_UNUSED;
11723 unsigned int blocknum;
11725 function_section (current_function_decl);
11726 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11729 /* Output a marker (i.e. a label) for the end of the generated code for a
11730 lexical block. */
11732 static void
11733 dwarf2out_end_block (line, blocknum)
11734 unsigned int line ATTRIBUTE_UNUSED;
11735 unsigned int blocknum;
11737 function_section (current_function_decl);
11738 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11741 /* Returns nonzero if it is appropriate not to emit any debugging
11742 information for BLOCK, because it doesn't contain any instructions.
11744 Don't allow this for blocks with nested functions or local classes
11745 as we would end up with orphans, and in the presence of scheduling
11746 we may end up calling them anyway. */
11748 static bool
11749 dwarf2out_ignore_block (block)
11750 tree block;
11752 tree decl;
11754 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11755 if (TREE_CODE (decl) == FUNCTION_DECL
11756 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11757 return 0;
11759 return 1;
11762 /* Lookup FILE_NAME (in the list of filenames that we know about here in
11763 dwarf2out.c) and return its "index". The index of each (known) filename is
11764 just a unique number which is associated with only that one filename. We
11765 need such numbers for the sake of generating labels (in the .debug_sfnames
11766 section) and references to those files numbers (in the .debug_srcinfo
11767 and.debug_macinfo sections). If the filename given as an argument is not
11768 found in our current list, add it to the list and assign it the next
11769 available unique index number. In order to speed up searches, we remember
11770 the index of the filename was looked up last. This handles the majority of
11771 all searches. */
11773 static unsigned
11774 lookup_filename (file_name)
11775 const char *file_name;
11777 unsigned i;
11779 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11780 if (strcmp (file_name, "<internal>") == 0
11781 || strcmp (file_name, "<built-in>") == 0)
11782 return 0;
11784 /* Check to see if the file name that was searched on the previous
11785 call matches this file name. If so, return the index. */
11786 if (file_table.last_lookup_index != 0)
11787 if (0 == strcmp (file_name,
11788 file_table.table[file_table.last_lookup_index]))
11789 return file_table.last_lookup_index;
11791 /* Didn't match the previous lookup, search the table */
11792 for (i = 1; i < file_table.in_use; i++)
11793 if (strcmp (file_name, file_table.table[i]) == 0)
11795 file_table.last_lookup_index = i;
11796 return i;
11799 /* Prepare to add a new table entry by making sure there is enough space in
11800 the table to do so. If not, expand the current table. */
11801 if (i == file_table.allocated)
11803 file_table.allocated = i + FILE_TABLE_INCREMENT;
11804 file_table.table = (char **)
11805 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11808 /* Add the new entry to the end of the filename table. */
11809 file_table.table[i] = xstrdup (file_name);
11810 file_table.in_use = i + 1;
11811 file_table.last_lookup_index = i;
11813 if (DWARF2_ASM_LINE_DEBUG_INFO)
11814 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11816 return i;
11819 static void
11820 init_file_table ()
11822 /* Allocate the initial hunk of the file_table. */
11823 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11824 file_table.allocated = FILE_TABLE_INCREMENT;
11826 /* Skip the first entry - file numbers begin at 1. */
11827 file_table.in_use = 1;
11828 file_table.last_lookup_index = 0;
11831 /* Output a label to mark the beginning of a source code line entry
11832 and record information relating to this source line, in
11833 'line_info_table' for later output of the .debug_line section. */
11835 static void
11836 dwarf2out_source_line (line, filename)
11837 unsigned int line;
11838 const char *filename;
11840 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11842 function_section (current_function_decl);
11844 /* If requested, emit something human-readable. */
11845 if (flag_debug_asm)
11846 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11847 filename, line);
11849 if (DWARF2_ASM_LINE_DEBUG_INFO)
11851 unsigned file_num = lookup_filename (filename);
11853 /* Emit the .loc directive understood by GNU as. */
11854 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11856 /* Indicate that line number info exists. */
11857 line_info_table_in_use++;
11859 /* Indicate that multiple line number tables exist. */
11860 if (DECL_SECTION_NAME (current_function_decl))
11861 separate_line_info_table_in_use++;
11863 else if (DECL_SECTION_NAME (current_function_decl))
11865 dw_separate_line_info_ref line_info;
11866 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11867 separate_line_info_table_in_use);
11869 /* expand the line info table if necessary */
11870 if (separate_line_info_table_in_use
11871 == separate_line_info_table_allocated)
11873 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11874 separate_line_info_table
11875 = (dw_separate_line_info_ref)
11876 xrealloc (separate_line_info_table,
11877 separate_line_info_table_allocated
11878 * sizeof (dw_separate_line_info_entry));
11881 /* Add the new entry at the end of the line_info_table. */
11882 line_info
11883 = &separate_line_info_table[separate_line_info_table_in_use++];
11884 line_info->dw_file_num = lookup_filename (filename);
11885 line_info->dw_line_num = line;
11886 line_info->function = current_funcdef_number;
11888 else
11890 dw_line_info_ref line_info;
11892 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11893 line_info_table_in_use);
11895 /* Expand the line info table if necessary. */
11896 if (line_info_table_in_use == line_info_table_allocated)
11898 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11899 line_info_table
11900 = (dw_line_info_ref)
11901 xrealloc (line_info_table,
11902 (line_info_table_allocated
11903 * sizeof (dw_line_info_entry)));
11906 /* Add the new entry at the end of the line_info_table. */
11907 line_info = &line_info_table[line_info_table_in_use++];
11908 line_info->dw_file_num = lookup_filename (filename);
11909 line_info->dw_line_num = line;
11914 /* Record the beginning of a new source file. */
11916 static void
11917 dwarf2out_start_source_file (lineno, filename)
11918 unsigned int lineno;
11919 const char *filename;
11921 if (flag_eliminate_dwarf2_dups)
11923 /* Record the beginning of the file for break_out_includes. */
11924 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL);
11925 add_AT_string (bincl_die, DW_AT_name, filename);
11928 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11930 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11931 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11932 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d",
11933 lineno);
11934 dw2_asm_output_data_uleb128 (lookup_filename (filename),
11935 "Filename we just started");
11939 /* Record the end of a source file. */
11941 static void
11942 dwarf2out_end_source_file (lineno)
11943 unsigned int lineno ATTRIBUTE_UNUSED;
11945 if (flag_eliminate_dwarf2_dups)
11946 /* Record the end of the file for break_out_includes. */
11947 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL);
11949 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11951 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11952 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11956 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11957 the tail part of the directive line, i.e. the part which is past the
11958 initial whitespace, #, whitespace, directive-name, whitespace part. */
11960 static void
11961 dwarf2out_define (lineno, buffer)
11962 unsigned lineno ATTRIBUTE_UNUSED;
11963 const char *buffer ATTRIBUTE_UNUSED;
11965 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11967 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11968 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11969 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11970 dw2_asm_output_nstring (buffer, -1, "The macro");
11974 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11975 the tail part of the directive line, i.e. the part which is past the
11976 initial whitespace, #, whitespace, directive-name, whitespace part. */
11978 static void
11979 dwarf2out_undef (lineno, buffer)
11980 unsigned lineno ATTRIBUTE_UNUSED;
11981 const char *buffer ATTRIBUTE_UNUSED;
11983 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11985 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
11986 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11987 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11988 dw2_asm_output_nstring (buffer, -1, "The macro");
11992 /* Set up for Dwarf output at the start of compilation. */
11994 static void
11995 dwarf2out_init (main_input_filename)
11996 const char *main_input_filename;
11998 init_file_table ();
12000 /* Remember the name of the primary input file. */
12001 primary_filename = main_input_filename;
12003 /* Add it to the file table first, under the assumption that we'll
12004 be emitting line number data for it first, which avoids having
12005 to add an initial DW_LNS_set_file. */
12006 lookup_filename (main_input_filename);
12008 /* Allocate the initial hunk of the decl_die_table. */
12009 decl_die_table
12010 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
12011 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
12012 decl_die_table_in_use = 0;
12014 /* Allocate the initial hunk of the decl_scope_table. */
12015 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table");
12016 ggc_add_tree_varray_root (&decl_scope_table, 1);
12018 /* Allocate the initial hunk of the abbrev_die_table. */
12019 abbrev_die_table
12020 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
12021 sizeof (dw_die_ref));
12022 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
12023 /* Zero-th entry is allocated, but unused */
12024 abbrev_die_table_in_use = 1;
12026 /* Allocate the initial hunk of the line_info_table. */
12027 line_info_table
12028 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
12029 sizeof (dw_line_info_entry));
12030 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
12032 /* Zero-th entry is allocated, but unused */
12033 line_info_table_in_use = 1;
12035 /* Generate the initial DIE for the .debug section. Note that the (string)
12036 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
12037 will (typically) be a relative pathname and that this pathname should be
12038 taken as being relative to the directory from which the compiler was
12039 invoked when the given (base) source file was compiled. */
12040 comp_unit_die = gen_compile_unit_die (main_input_filename);
12042 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types");
12043 ggc_add_tree_varray_root (&incomplete_types, 1);
12045 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
12046 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
12048 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list);
12050 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
12051 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
12052 DEBUG_ABBREV_SECTION_LABEL, 0);
12053 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12054 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
12055 else
12056 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME));
12058 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
12059 DEBUG_INFO_SECTION_LABEL, 0);
12060 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
12061 DEBUG_LINE_SECTION_LABEL, 0);
12062 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label,
12063 DEBUG_RANGES_SECTION_LABEL, 0);
12064 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12065 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
12066 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG);
12067 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
12068 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12069 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
12071 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12073 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12074 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
12075 DEBUG_MACINFO_SECTION_LABEL, 0);
12076 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
12079 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
12081 text_section ();
12082 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
12086 /* Allocate a string in .debug_str hash table. */
12088 static hashnode
12089 indirect_string_alloc (tab)
12090 hash_table *tab ATTRIBUTE_UNUSED;
12092 struct indirect_string_node *node;
12094 node = xmalloc (sizeof (struct indirect_string_node));
12095 node->refcount = 0;
12096 node->form = 0;
12097 node->label = NULL;
12099 return (hashnode) node;
12102 /* A helper function for dwarf2out_finish called through
12103 ht_forall. Emit one queued .debug_str string. */
12105 static int
12106 output_indirect_string (pfile, h, v)
12107 struct cpp_reader *pfile ATTRIBUTE_UNUSED;
12108 hashnode h;
12109 const PTR v ATTRIBUTE_UNUSED;
12111 struct indirect_string_node *node = (struct indirect_string_node *) h;
12113 if (node->form == DW_FORM_strp)
12115 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS);
12116 ASM_OUTPUT_LABEL (asm_out_file, node->label);
12117 assemble_string ((const char *) HT_STR (&node->id),
12118 HT_LEN (&node->id) + 1);
12121 return 1;
12124 /* Output stuff that dwarf requires at the end of every file,
12125 and generate the DWARF-2 debugging info. */
12127 static void
12128 dwarf2out_finish (input_filename)
12129 const char *input_filename ATTRIBUTE_UNUSED;
12131 limbo_die_node *node, *next_node;
12132 dw_die_ref die = 0;
12134 /* Traverse the limbo die list, and add parent/child links. The only
12135 dies without parents that should be here are concrete instances of
12136 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
12137 For concrete instances, we can get the parent die from the abstract
12138 instance. */
12139 for (node = limbo_die_list; node; node = next_node)
12141 next_node = node->next;
12142 die = node->die;
12144 if (die->die_parent == NULL)
12146 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
12147 tree context;
12149 if (origin)
12150 add_child_die (origin->die_parent, die);
12151 else if (die == comp_unit_die)
12153 /* If this was an expression for a bound involved in a function
12154 return type, it may be a SAVE_EXPR for which we weren't able
12155 to find a DIE previously. So try now. */
12156 else if (node->created_for
12157 && TREE_CODE (node->created_for) == SAVE_EXPR
12158 && 0 != (origin = (lookup_decl_die
12159 (SAVE_EXPR_CONTEXT
12160 (node->created_for)))))
12161 add_child_die (origin, die);
12162 else if (errorcount > 0 || sorrycount > 0)
12163 /* It's OK to be confused by errors in the input. */
12164 add_child_die (comp_unit_die, die);
12165 else if (node->created_for
12166 && ((DECL_P (node->created_for)
12167 && (context = DECL_CONTEXT (node->created_for)))
12168 || (TYPE_P (node->created_for)
12169 && (context = TYPE_CONTEXT (node->created_for))))
12170 && TREE_CODE (context) == FUNCTION_DECL)
12172 /* In certain situations, the lexical block containing a
12173 nested function can be optimized away, which results
12174 in the nested function die being orphaned. Likewise
12175 with the return type of that nested function. Force
12176 this to be a child of the containing function. */
12177 origin = lookup_decl_die (context);
12178 if (! origin)
12179 abort ();
12180 add_child_die (origin, die);
12182 else
12183 abort ();
12186 free (node);
12189 limbo_die_list = NULL;
12191 /* Walk through the list of incomplete types again, trying once more to
12192 emit full debugging info for them. */
12193 retry_incomplete_types ();
12195 /* We need to reverse all the dies before break_out_includes, or
12196 we'll see the end of an include file before the beginning. */
12197 reverse_all_dies (comp_unit_die);
12199 /* Generate separate CUs for each of the include files we've seen.
12200 They will go into limbo_die_list. */
12201 if (flag_eliminate_dwarf2_dups)
12202 break_out_includes (comp_unit_die);
12204 /* Traverse the DIE's and add add sibling attributes to those DIE's
12205 that have children. */
12206 add_sibling_attributes (comp_unit_die);
12207 for (node = limbo_die_list; node; node = node->next)
12208 add_sibling_attributes (node->die);
12210 /* Output a terminator label for the .text section. */
12211 text_section ();
12212 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
12214 /* Output the source line correspondence table. We must do this
12215 even if there is no line information. Otherwise, on an empty
12216 translation unit, we will generate a present, but empty,
12217 .debug_info section. IRIX 6.5 `nm' will then complain when
12218 examining the file. */
12219 if (! DWARF2_ASM_LINE_DEBUG_INFO)
12221 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG);
12222 output_line_info ();
12225 /* Output location list section if necessary. */
12226 if (have_location_lists)
12228 /* Output the location lists info. */
12229 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG);
12230 ASM_GENERATE_INTERNAL_LABEL (loc_section_label,
12231 DEBUG_LOC_SECTION_LABEL, 0);
12232 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
12233 output_location_lists (die);
12234 have_location_lists = 0;
12237 /* We can only use the low/high_pc attributes if all of the code was
12238 in .text. */
12239 if (separate_line_info_table_in_use == 0)
12241 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
12242 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
12245 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate
12246 "base address". Use zero so that these addresses become absolute. */
12247 else if (have_location_lists || ranges_table_in_use)
12248 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx);
12250 if (debug_info_level >= DINFO_LEVEL_NORMAL)
12251 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
12252 debug_line_section_label);
12254 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12255 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
12257 /* Output all of the compilation units. We put the main one last so that
12258 the offsets are available to output_pubnames. */
12259 for (node = limbo_die_list; node; node = node->next)
12260 output_comp_unit (node->die);
12262 output_comp_unit (comp_unit_die);
12264 /* Output the abbreviation table. */
12265 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG);
12266 output_abbrev_section ();
12268 /* Output public names table if necessary. */
12269 if (pubname_table_in_use)
12271 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG);
12272 output_pubnames ();
12275 /* Output the address range information. We only put functions in the arange
12276 table, so don't write it out if we don't have any. */
12277 if (fde_table_in_use)
12279 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG);
12280 output_aranges ();
12283 /* Output ranges section if necessary. */
12284 if (ranges_table_in_use)
12286 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG);
12287 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label);
12288 output_ranges ();
12291 /* Have to end the primary source file. */
12292 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
12294 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG);
12295 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
12298 /* If we emitted any DW_FORM_strp form attribute, output the string
12299 table too. */
12300 if (debug_str_hash)
12301 ht_forall (debug_str_hash, output_indirect_string, NULL);
12303 #endif /* DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO */