acinclude.m4 (GLIBCPP_ENABLE_CHEADERS): Use glibcpp_srcdir when setting C_INCLUDE_DIR.
[official-gcc.git] / gcc / dwarf2out.c
blob207bda72c09d4c1ce38cfd6bdf37c3e8194bedcf
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001
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 GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* TODO: Implement .debug_str handling, and share entries somehow.
26 Emit .debug_line header even when there are no functions, since
27 the file numbers are used by .debug_info. Alternately, leave
28 out locations for types and decls.
29 Avoid talking about ctors and op= for PODs.
30 Factor out common prologue sequences into multiple CIEs. */
32 /* The first part of this file deals with the DWARF 2 frame unwind
33 information, which is also used by the GCC efficient exception handling
34 mechanism. The second part, controlled only by an #ifdef
35 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
36 information. */
38 #include "config.h"
39 #include "system.h"
40 #include "tree.h"
41 #include "flags.h"
42 #include "rtl.h"
43 #include "hard-reg-set.h"
44 #include "regs.h"
45 #include "insn-config.h"
46 #include "reload.h"
47 #include "function.h"
48 #include "output.h"
49 #include "expr.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"
62 /* DWARF2 Abbreviation Glossary:
63 CFA = Canonical Frame Address
64 a fixed address on the stack which identifies a call frame.
65 We define it to be the value of SP just before the call insn.
66 The CFA register and offset, which may change during the course
67 of the function, are used to calculate its value at runtime.
68 CFI = Call Frame Instruction
69 an instruction for the DWARF2 abstract machine
70 CIE = Common Information Entry
71 information describing information common to one or more FDEs
72 DIE = Debugging Information Entry
73 FDE = Frame Description Entry
74 information describing the stack call frame, in particular,
75 how to restore registers
77 DW_CFA_... = DWARF2 CFA call frame instruction
78 DW_TAG_... = DWARF2 DIE tag */
80 /* Decide whether we want to emit frame unwind information for the current
81 translation unit. */
83 int
84 dwarf2out_do_frame ()
86 return (write_symbols == DWARF2_DEBUG
87 #ifdef DWARF2_FRAME_INFO
88 || DWARF2_FRAME_INFO
89 #endif
90 #ifdef DWARF2_UNWIND_INFO
91 || flag_unwind_tables
92 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS)
93 #endif
97 /* The number of the current function definition for which debugging
98 information is being generated. These numbers range from 1 up to the
99 maximum number of function definitions contained within the current
100 compilation unit. These numbers are used to create unique label id's
101 unique to each function definition. */
102 unsigned current_funcdef_number = 0;
104 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
106 /* How to start an assembler comment. */
107 #ifndef ASM_COMMENT_START
108 #define ASM_COMMENT_START ";#"
109 #endif
111 typedef struct dw_cfi_struct *dw_cfi_ref;
112 typedef struct dw_fde_struct *dw_fde_ref;
113 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
115 /* Call frames are described using a sequence of Call Frame
116 Information instructions. The register number, offset
117 and address fields are provided as possible operands;
118 their use is selected by the opcode field. */
120 typedef union dw_cfi_oprnd_struct
122 unsigned long dw_cfi_reg_num;
123 long int dw_cfi_offset;
124 const char *dw_cfi_addr;
125 struct dw_loc_descr_struct *dw_cfi_loc;
127 dw_cfi_oprnd;
129 typedef struct dw_cfi_struct
131 dw_cfi_ref dw_cfi_next;
132 enum dwarf_call_frame_info dw_cfi_opc;
133 dw_cfi_oprnd dw_cfi_oprnd1;
134 dw_cfi_oprnd dw_cfi_oprnd2;
136 dw_cfi_node;
138 /* This is how we define the location of the CFA. We use to handle it
139 as REG + OFFSET all the time, but now it can be more complex.
140 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET.
141 Instead of passing around REG and OFFSET, we pass a copy
142 of this structure. */
143 typedef struct cfa_loc
145 unsigned long reg;
146 long offset;
147 long base_offset;
148 int indirect; /* 1 if CFA is accessed via a dereference. */
149 } dw_cfa_location;
151 /* All call frame descriptions (FDE's) in the GCC generated DWARF
152 refer to a single Common Information Entry (CIE), defined at
153 the beginning of the .debug_frame section. This used of a single
154 CIE obviates the need to keep track of multiple CIE's
155 in the DWARF generation routines below. */
157 typedef struct dw_fde_struct
159 const char *dw_fde_begin;
160 const char *dw_fde_current_label;
161 const char *dw_fde_end;
162 dw_cfi_ref dw_fde_cfi;
163 unsigned funcdef_number;
164 unsigned nothrow : 1;
165 unsigned uses_eh_lsda : 1;
167 dw_fde_node;
169 /* Maximum size (in bytes) of an artificially generated label. */
170 #define MAX_ARTIFICIAL_LABEL_BYTES 30
172 /* The size of the target's pointer type. */
173 #ifndef PTR_SIZE
174 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
175 #endif
177 /* The size of addresses as they appear in the Dwarf 2 data.
178 Some architectures use word addresses to refer to code locations,
179 but Dwarf 2 info always uses byte addresses. On such machines,
180 Dwarf 2 addresses need to be larger than the architecture's
181 pointers. */
182 #ifndef DWARF2_ADDR_SIZE
183 #define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
184 #endif
186 /* The size in bytes of a DWARF field indicating an offset or length
187 relative to a debug info section, specified to be 4 bytes in the
188 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same
189 as PTR_SIZE. */
191 #ifndef DWARF_OFFSET_SIZE
192 #define DWARF_OFFSET_SIZE 4
193 #endif
195 #define DWARF_VERSION 2
197 /* Round SIZE up to the nearest BOUNDARY. */
198 #define DWARF_ROUND(SIZE,BOUNDARY) \
199 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
201 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
202 #ifndef DWARF_CIE_DATA_ALIGNMENT
203 #ifdef STACK_GROWS_DOWNWARD
204 #define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD))
205 #else
206 #define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD)
207 #endif
208 #endif /* not DWARF_CIE_DATA_ALIGNMENT */
210 /* A pointer to the base of a table that contains frame description
211 information for each routine. */
212 static dw_fde_ref fde_table;
214 /* Number of elements currently allocated for fde_table. */
215 static unsigned fde_table_allocated;
217 /* Number of elements in fde_table currently in use. */
218 static unsigned fde_table_in_use;
220 /* Size (in elements) of increments by which we may expand the
221 fde_table. */
222 #define FDE_TABLE_INCREMENT 256
224 /* A list of call frame insns for the CIE. */
225 static dw_cfi_ref cie_cfi_head;
227 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
228 attribute that accelerates the lookup of the FDE associated
229 with the subprogram. This variable holds the table index of the FDE
230 associated with the current function (body) definition. */
231 static unsigned current_funcdef_fde;
233 /* Forward declarations for functions defined in this file. */
235 static char *stripattributes PARAMS ((const char *));
236 static const char *dwarf_cfi_name PARAMS ((unsigned));
237 static dw_cfi_ref new_cfi PARAMS ((void));
238 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
239 static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref));
240 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, dw_cfa_location *));
241 static void lookup_cfa PARAMS ((dw_cfa_location *));
242 static void reg_save PARAMS ((const char *, unsigned,
243 unsigned, long));
244 static void initial_return_save PARAMS ((rtx));
245 static long stack_adjust_offset PARAMS ((rtx));
246 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int));
247 static void output_call_frame_info PARAMS ((int));
248 static void dwarf2out_stack_adjust PARAMS ((rtx));
249 static void queue_reg_save PARAMS ((const char *, rtx, long));
250 static void flush_queued_reg_saves PARAMS ((void));
251 static bool clobbers_queued_reg_save PARAMS ((rtx));
252 static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *));
254 /* Support for complex CFA locations. */
255 static void output_cfa_loc PARAMS ((dw_cfi_ref));
256 static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *,
257 struct dw_loc_descr_struct *));
258 static struct dw_loc_descr_struct *build_cfa_loc
259 PARAMS ((dw_cfa_location *));
260 static void def_cfa_1 PARAMS ((const char *, dw_cfa_location *));
262 /* How to start an assembler comment. */
263 #ifndef ASM_COMMENT_START
264 #define ASM_COMMENT_START ";#"
265 #endif
267 /* Data and reference forms for relocatable data. */
268 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
269 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
271 /* Pseudo-op for defining a new section. */
272 #ifndef SECTION_ASM_OP
273 #define SECTION_ASM_OP "\t.section\t"
274 #endif
276 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
277 print the SECTION_ASM_OP and the section name. The default here works for
278 almost all svr4 assemblers, except for the sparc, where the section name
279 must be enclosed in double quotes. (See sparcv4.h). */
280 #ifndef SECTION_FORMAT
281 #ifdef PUSHSECTION_FORMAT
282 #define SECTION_FORMAT PUSHSECTION_FORMAT
283 #else
284 #define SECTION_FORMAT "%s%s\n"
285 #endif
286 #endif
288 #ifndef DEBUG_FRAME_SECTION
289 #define DEBUG_FRAME_SECTION ".debug_frame"
290 #endif
292 #ifndef FUNC_BEGIN_LABEL
293 #define FUNC_BEGIN_LABEL "LFB"
294 #endif
295 #ifndef FUNC_END_LABEL
296 #define FUNC_END_LABEL "LFE"
297 #endif
298 #define CIE_AFTER_SIZE_LABEL "LSCIE"
299 #define CIE_END_LABEL "LECIE"
300 #define CIE_LENGTH_LABEL "LLCIE"
301 #define FDE_LABEL "LSFDE"
302 #define FDE_AFTER_SIZE_LABEL "LASFDE"
303 #define FDE_END_LABEL "LEFDE"
304 #define FDE_LENGTH_LABEL "LLFDE"
305 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
306 #define LINE_NUMBER_END_LABEL "LELT"
307 #define LN_PROLOG_AS_LABEL "LASLTP"
308 #define LN_PROLOG_END_LABEL "LELTP"
309 #define DIE_LABEL_PREFIX "DW"
311 /* Definitions of defaults for various types of primitive assembly language
312 output operations. These may be overridden from within the tm.h file,
313 but typically, that is unnecessary. */
315 #ifndef ASM_OUTPUT_SECTION
316 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
317 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
318 #endif
320 #ifdef SET_ASM_OP
321 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
322 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
323 do { \
324 fprintf (FILE, "%s", SET_ASM_OP); \
325 assemble_name (FILE, SY); \
326 fputc (',', FILE); \
327 assemble_name (FILE, HI); \
328 fputc ('-', FILE); \
329 assemble_name (FILE, LO); \
330 } while (0)
331 #endif
332 #endif /* SET_ASM_OP */
334 /* The DWARF 2 CFA column which tracks the return address. Normally this
335 is the column for PC, or the first column after all of the hard
336 registers. */
337 #ifndef DWARF_FRAME_RETURN_COLUMN
338 #ifdef PC_REGNUM
339 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
340 #else
341 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
342 #endif
343 #endif
345 /* The mapping from gcc register number to DWARF 2 CFA column number. By
346 default, we just provide columns for all registers. */
347 #ifndef DWARF_FRAME_REGNUM
348 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
349 #endif
351 /* Hook used by __throw. */
354 expand_builtin_dwarf_fp_regnum ()
356 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
359 /* The offset from the incoming value of %sp to the top of the stack frame
360 for the current function. */
361 #ifndef INCOMING_FRAME_SP_OFFSET
362 #define INCOMING_FRAME_SP_OFFSET 0
363 #endif
365 /* Return a pointer to a copy of the section string name S with all
366 attributes stripped off, and an asterisk prepended (for assemble_name). */
368 static inline char *
369 stripattributes (s)
370 const char *s;
372 char *stripped = xmalloc (strlen (s) + 2);
373 char *p = stripped;
375 *p++ = '*';
377 while (*s && *s != ',')
378 *p++ = *s++;
380 *p = '\0';
381 return stripped;
384 /* Generate code to initialize the register size table. */
386 void
387 expand_builtin_init_dwarf_reg_sizes (address)
388 tree address;
390 int i;
391 enum machine_mode mode = TYPE_MODE (char_type_node);
392 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
393 rtx mem = gen_rtx_MEM (mode, addr);
395 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
397 int offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode);
398 int size = GET_MODE_SIZE (reg_raw_mode[i]);
400 if (offset < 0)
401 continue;
403 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size));
407 /* Convert a DWARF call frame info. operation to its string name */
409 static const char *
410 dwarf_cfi_name (cfi_opc)
411 register unsigned cfi_opc;
413 switch (cfi_opc)
415 case DW_CFA_advance_loc:
416 return "DW_CFA_advance_loc";
417 case DW_CFA_offset:
418 return "DW_CFA_offset";
419 case DW_CFA_restore:
420 return "DW_CFA_restore";
421 case DW_CFA_nop:
422 return "DW_CFA_nop";
423 case DW_CFA_set_loc:
424 return "DW_CFA_set_loc";
425 case DW_CFA_advance_loc1:
426 return "DW_CFA_advance_loc1";
427 case DW_CFA_advance_loc2:
428 return "DW_CFA_advance_loc2";
429 case DW_CFA_advance_loc4:
430 return "DW_CFA_advance_loc4";
431 case DW_CFA_offset_extended:
432 return "DW_CFA_offset_extended";
433 case DW_CFA_restore_extended:
434 return "DW_CFA_restore_extended";
435 case DW_CFA_undefined:
436 return "DW_CFA_undefined";
437 case DW_CFA_same_value:
438 return "DW_CFA_same_value";
439 case DW_CFA_register:
440 return "DW_CFA_register";
441 case DW_CFA_remember_state:
442 return "DW_CFA_remember_state";
443 case DW_CFA_restore_state:
444 return "DW_CFA_restore_state";
445 case DW_CFA_def_cfa:
446 return "DW_CFA_def_cfa";
447 case DW_CFA_def_cfa_register:
448 return "DW_CFA_def_cfa_register";
449 case DW_CFA_def_cfa_offset:
450 return "DW_CFA_def_cfa_offset";
451 case DW_CFA_def_cfa_expression:
452 return "DW_CFA_def_cfa_expression";
454 /* SGI/MIPS specific */
455 case DW_CFA_MIPS_advance_loc8:
456 return "DW_CFA_MIPS_advance_loc8";
458 /* GNU extensions */
459 case DW_CFA_GNU_window_save:
460 return "DW_CFA_GNU_window_save";
461 case DW_CFA_GNU_args_size:
462 return "DW_CFA_GNU_args_size";
463 case DW_CFA_GNU_negative_offset_extended:
464 return "DW_CFA_GNU_negative_offset_extended";
466 default:
467 return "DW_CFA_<unknown>";
471 /* Return a pointer to a newly allocated Call Frame Instruction. */
473 static inline dw_cfi_ref
474 new_cfi ()
476 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
478 cfi->dw_cfi_next = NULL;
479 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
480 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
482 return cfi;
485 /* Add a Call Frame Instruction to list of instructions. */
487 static inline void
488 add_cfi (list_head, cfi)
489 register dw_cfi_ref *list_head;
490 register dw_cfi_ref cfi;
492 register dw_cfi_ref *p;
494 /* Find the end of the chain. */
495 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
498 *p = cfi;
501 /* Generate a new label for the CFI info to refer to. */
503 char *
504 dwarf2out_cfi_label ()
506 static char label[20];
507 static unsigned long label_num = 0;
509 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
510 ASM_OUTPUT_LABEL (asm_out_file, label);
512 return label;
515 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
516 or to the CIE if LABEL is NULL. */
518 static void
519 add_fde_cfi (label, cfi)
520 register const char *label;
521 register dw_cfi_ref cfi;
523 if (label)
525 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
527 if (*label == 0)
528 label = dwarf2out_cfi_label ();
530 if (fde->dw_fde_current_label == NULL
531 || strcmp (label, fde->dw_fde_current_label) != 0)
533 register dw_cfi_ref xcfi;
535 fde->dw_fde_current_label = label = xstrdup (label);
537 /* Set the location counter to the new label. */
538 xcfi = new_cfi ();
539 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
540 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
541 add_cfi (&fde->dw_fde_cfi, xcfi);
544 add_cfi (&fde->dw_fde_cfi, cfi);
547 else
548 add_cfi (&cie_cfi_head, cfi);
551 /* Subroutine of lookup_cfa. */
553 static inline void
554 lookup_cfa_1 (cfi, loc)
555 register dw_cfi_ref cfi;
556 register dw_cfa_location *loc;
558 switch (cfi->dw_cfi_opc)
560 case DW_CFA_def_cfa_offset:
561 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset;
562 break;
563 case DW_CFA_def_cfa_register:
564 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
565 break;
566 case DW_CFA_def_cfa:
567 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
568 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset;
569 break;
570 case DW_CFA_def_cfa_expression:
571 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc);
572 break;
573 default:
574 break;
578 /* Find the previous value for the CFA. */
580 static void
581 lookup_cfa (loc)
582 register dw_cfa_location *loc;
584 register dw_cfi_ref cfi;
586 loc->reg = (unsigned long) -1;
587 loc->offset = 0;
588 loc->indirect = 0;
589 loc->base_offset = 0;
591 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
592 lookup_cfa_1 (cfi, loc);
594 if (fde_table_in_use)
596 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
597 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
598 lookup_cfa_1 (cfi, loc);
602 /* The current rule for calculating the DWARF2 canonical frame address. */
603 static dw_cfa_location cfa;
605 /* The register used for saving registers to the stack, and its offset
606 from the CFA. */
607 static dw_cfa_location cfa_store;
609 /* The running total of the size of arguments pushed onto the stack. */
610 static long args_size;
612 /* The last args_size we actually output. */
613 static long old_args_size;
615 /* Entry point to update the canonical frame address (CFA).
616 LABEL is passed to add_fde_cfi. The value of CFA is now to be
617 calculated from REG+OFFSET. */
619 void
620 dwarf2out_def_cfa (label, reg, offset)
621 register const char *label;
622 unsigned reg;
623 long offset;
625 dw_cfa_location loc;
626 loc.indirect = 0;
627 loc.base_offset = 0;
628 loc.reg = reg;
629 loc.offset = offset;
630 def_cfa_1 (label, &loc);
633 /* This routine does the actual work. The CFA is now calculated from
634 the dw_cfa_location structure. */
635 static void
636 def_cfa_1 (label, loc_p)
637 register const char *label;
638 dw_cfa_location *loc_p;
640 register dw_cfi_ref cfi;
641 dw_cfa_location old_cfa, loc;
643 cfa = *loc_p;
644 loc = *loc_p;
646 if (cfa_store.reg == loc.reg && loc.indirect == 0)
647 cfa_store.offset = loc.offset;
649 loc.reg = DWARF_FRAME_REGNUM (loc.reg);
650 lookup_cfa (&old_cfa);
652 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset &&
653 loc.indirect == old_cfa.indirect)
655 if (loc.indirect == 0
656 || loc.base_offset == old_cfa.base_offset)
657 /* Nothing changed so no need to issue any call frame
658 instructions. */
659 return;
662 cfi = new_cfi ();
664 if (loc.reg == old_cfa.reg && !loc.indirect)
666 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction,
667 indicating the CFA register did not change but the offset
668 did. */
669 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
670 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset;
673 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
674 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1
675 && !loc.indirect)
677 /* Construct a "DW_CFA_def_cfa_register <register>" instruction,
678 indicating the CFA register has changed to <register> but the
679 offset has not changed. */
680 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
681 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
683 #endif
685 else if (loc.indirect == 0)
687 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction,
688 indicating the CFA register has changed to <register> with
689 the specified offset. */
690 cfi->dw_cfi_opc = DW_CFA_def_cfa;
691 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg;
692 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset;
694 else
696 /* Construct a DW_CFA_def_cfa_expression instruction to
697 calculate the CFA using a full location expression since no
698 register-offset pair is available. */
699 struct dw_loc_descr_struct *loc_list;
700 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression;
701 loc_list = build_cfa_loc (&loc);
702 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list;
705 add_fde_cfi (label, cfi);
708 /* Add the CFI for saving a register. REG is the CFA column number.
709 LABEL is passed to add_fde_cfi.
710 If SREG is -1, the register is saved at OFFSET from the CFA;
711 otherwise it is saved in SREG. */
713 static void
714 reg_save (label, reg, sreg, offset)
715 register const char *label;
716 register unsigned reg;
717 register unsigned sreg;
718 register long offset;
720 register dw_cfi_ref cfi = new_cfi ();
722 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
724 /* The following comparison is correct. -1 is used to indicate that
725 the value isn't a register number. */
726 if (sreg == (unsigned int) -1)
728 if (reg & ~0x3f)
729 /* The register number won't fit in 6 bits, so we have to use
730 the long form. */
731 cfi->dw_cfi_opc = DW_CFA_offset_extended;
732 else
733 cfi->dw_cfi_opc = DW_CFA_offset;
735 #ifdef ENABLE_CHECKING
737 /* If we get an offset that is not a multiple of
738 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the
739 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine
740 description. */
741 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT;
743 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset)
744 abort ();
746 #endif
747 offset /= DWARF_CIE_DATA_ALIGNMENT;
748 if (offset < 0)
750 cfi->dw_cfi_opc = DW_CFA_GNU_negative_offset_extended;
751 offset = -offset;
753 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
755 else if (sreg == reg)
756 /* We could emit a DW_CFA_same_value in this case, but don't bother. */
757 return;
758 else
760 cfi->dw_cfi_opc = DW_CFA_register;
761 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
764 add_fde_cfi (label, cfi);
767 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
768 This CFI tells the unwinder that it needs to restore the window registers
769 from the previous frame's window save area.
771 ??? Perhaps we should note in the CIE where windows are saved (instead of
772 assuming 0(cfa)) and what registers are in the window. */
774 void
775 dwarf2out_window_save (label)
776 register const char *label;
778 register dw_cfi_ref cfi = new_cfi ();
779 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
780 add_fde_cfi (label, cfi);
783 /* Add a CFI to update the running total of the size of arguments
784 pushed onto the stack. */
786 void
787 dwarf2out_args_size (label, size)
788 const char *label;
789 long size;
791 register dw_cfi_ref cfi;
793 if (size == old_args_size)
794 return;
795 old_args_size = size;
797 cfi = new_cfi ();
798 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
799 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
800 add_fde_cfi (label, cfi);
803 /* Entry point for saving a register to the stack. REG is the GCC register
804 number. LABEL and OFFSET are passed to reg_save. */
806 void
807 dwarf2out_reg_save (label, reg, offset)
808 register const char *label;
809 register unsigned reg;
810 register long offset;
812 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
815 /* Entry point for saving the return address in the stack.
816 LABEL and OFFSET are passed to reg_save. */
818 void
819 dwarf2out_return_save (label, offset)
820 register const char *label;
821 register long offset;
823 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
826 /* Entry point for saving the return address in a register.
827 LABEL and SREG are passed to reg_save. */
829 void
830 dwarf2out_return_reg (label, sreg)
831 register const char *label;
832 register unsigned sreg;
834 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
837 /* Record the initial position of the return address. RTL is
838 INCOMING_RETURN_ADDR_RTX. */
840 static void
841 initial_return_save (rtl)
842 register rtx rtl;
844 unsigned int reg = (unsigned int) -1;
845 long offset = 0;
847 switch (GET_CODE (rtl))
849 case REG:
850 /* RA is in a register. */
851 reg = DWARF_FRAME_REGNUM (REGNO (rtl));
852 break;
853 case MEM:
854 /* RA is on the stack. */
855 rtl = XEXP (rtl, 0);
856 switch (GET_CODE (rtl))
858 case REG:
859 if (REGNO (rtl) != STACK_POINTER_REGNUM)
860 abort ();
861 offset = 0;
862 break;
863 case PLUS:
864 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
865 abort ();
866 offset = INTVAL (XEXP (rtl, 1));
867 break;
868 case MINUS:
869 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
870 abort ();
871 offset = -INTVAL (XEXP (rtl, 1));
872 break;
873 default:
874 abort ();
876 break;
877 case PLUS:
878 /* The return address is at some offset from any value we can
879 actually load. For instance, on the SPARC it is in %i7+8. Just
880 ignore the offset for now; it doesn't matter for unwinding frames. */
881 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
882 abort ();
883 initial_return_save (XEXP (rtl, 0));
884 return;
885 default:
886 abort ();
889 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset);
892 /* Given a SET, calculate the amount of stack adjustment it
893 contains. */
895 static long
896 stack_adjust_offset (pattern)
897 rtx pattern;
899 rtx src = SET_SRC (pattern);
900 rtx dest = SET_DEST (pattern);
901 long offset = 0;
902 enum rtx_code code;
904 if (dest == stack_pointer_rtx)
906 /* (set (reg sp) (plus (reg sp) (const_int))) */
907 code = GET_CODE (src);
908 if (! (code == PLUS || code == MINUS)
909 || XEXP (src, 0) != stack_pointer_rtx
910 || GET_CODE (XEXP (src, 1)) != CONST_INT)
911 return 0;
913 offset = INTVAL (XEXP (src, 1));
915 else if (GET_CODE (dest) == MEM)
917 /* (set (mem (pre_dec (reg sp))) (foo)) */
918 src = XEXP (dest, 0);
919 code = GET_CODE (src);
921 if (! (code == PRE_DEC || code == PRE_INC
922 || code == PRE_MODIFY)
923 || XEXP (src, 0) != stack_pointer_rtx)
924 return 0;
926 if (code == PRE_MODIFY)
928 rtx val = XEXP (XEXP (src, 1), 1);
929 /* We handle only adjustments by constant amount. */
930 if (GET_CODE (XEXP (src, 1)) != PLUS ||
931 GET_CODE (val) != CONST_INT)
932 abort();
933 offset = -INTVAL (val);
935 else offset = GET_MODE_SIZE (GET_MODE (dest));
937 else
938 return 0;
940 if (code == PLUS || code == PRE_INC)
941 offset = -offset;
943 return offset;
946 /* Check INSN to see if it looks like a push or a stack adjustment, and
947 make a note of it if it does. EH uses this information to find out how
948 much extra space it needs to pop off the stack. */
950 static void
951 dwarf2out_stack_adjust (insn)
952 rtx insn;
954 long offset;
955 const char *label;
957 if (! flag_non_call_exceptions && GET_CODE (insn) == CALL_INSN)
959 /* Extract the size of the args from the CALL rtx itself. */
961 insn = PATTERN (insn);
962 if (GET_CODE (insn) == PARALLEL)
963 insn = XVECEXP (insn, 0, 0);
964 if (GET_CODE (insn) == SET)
965 insn = SET_SRC (insn);
966 if (GET_CODE (insn) != CALL)
967 abort ();
968 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
969 return;
972 /* If only calls can throw, and we have a frame pointer,
973 save up adjustments until we see the CALL_INSN. */
974 else if (! flag_non_call_exceptions
975 && cfa.reg != STACK_POINTER_REGNUM)
976 return;
978 if (GET_CODE (insn) == BARRIER)
980 /* When we see a BARRIER, we know to reset args_size to 0. Usually
981 the compiler will have already emitted a stack adjustment, but
982 doesn't bother for calls to noreturn functions. */
983 #ifdef STACK_GROWS_DOWNWARD
984 offset = -args_size;
985 #else
986 offset = args_size;
987 #endif
989 else if (GET_CODE (PATTERN (insn)) == SET)
991 offset = stack_adjust_offset (PATTERN (insn));
993 else if (GET_CODE (PATTERN (insn)) == PARALLEL
994 || GET_CODE (PATTERN (insn)) == SEQUENCE)
996 /* There may be stack adjustments inside compound insns. Search
997 for them. */
998 int j;
1000 offset = 0;
1001 for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
1003 rtx pattern = XVECEXP (PATTERN (insn), 0, j);
1004 if (GET_CODE (pattern) == SET)
1005 offset += stack_adjust_offset (pattern);
1008 else
1009 return;
1011 if (offset == 0)
1012 return;
1014 if (cfa.reg == STACK_POINTER_REGNUM)
1015 cfa.offset += offset;
1017 #ifndef STACK_GROWS_DOWNWARD
1018 offset = -offset;
1019 #endif
1020 args_size += offset;
1021 if (args_size < 0)
1022 args_size = 0;
1024 label = dwarf2out_cfi_label ();
1025 def_cfa_1 (label, &cfa);
1026 dwarf2out_args_size (label, args_size);
1029 /* We delay emitting a register save until either (a) we reach the end
1030 of the prologue or (b) the register is clobbered. This clusters
1031 register saves so that there are fewer pc advances. */
1033 struct queued_reg_save
1035 struct queued_reg_save *next;
1036 rtx reg;
1037 long cfa_offset;
1040 static struct queued_reg_save *queued_reg_saves;
1041 static const char *last_reg_save_label;
1043 static void
1044 queue_reg_save (label, reg, offset)
1045 const char *label;
1046 rtx reg;
1047 long offset;
1049 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q));
1051 q->next = queued_reg_saves;
1052 q->reg = reg;
1053 q->cfa_offset = offset;
1054 queued_reg_saves = q;
1056 last_reg_save_label = label;
1059 static void
1060 flush_queued_reg_saves ()
1062 struct queued_reg_save *q, *next;
1064 for (q = queued_reg_saves; q ; q = next)
1066 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset);
1067 next = q->next;
1068 free (q);
1071 queued_reg_saves = NULL;
1072 last_reg_save_label = NULL;
1075 static bool
1076 clobbers_queued_reg_save (insn)
1077 rtx insn;
1079 struct queued_reg_save *q;
1081 for (q = queued_reg_saves; q ; q = q->next)
1082 if (modified_in_p (q->reg, insn))
1083 return true;
1085 return false;
1089 /* A temporary register holding an integral value used in adjusting SP
1090 or setting up the store_reg. The "offset" field holds the integer
1091 value, not an offset. */
1092 static dw_cfa_location cfa_temp;
1094 /* Record call frame debugging information for an expression EXPR,
1095 which either sets SP or FP (adjusting how we calculate the frame
1096 address) or saves a register to the stack. LABEL indicates the
1097 address of EXPR.
1099 This function encodes a state machine mapping rtxes to actions on
1100 cfa, cfa_store, and cfa_temp.reg. We describe these rules so
1101 users need not read the source code.
1103 The High-Level Picture
1105 Changes in the register we use to calculate the CFA: Currently we
1106 assume that if you copy the CFA register into another register, we
1107 should take the other one as the new CFA register; this seems to
1108 work pretty well. If it's wrong for some target, it's simple
1109 enough not to set RTX_FRAME_RELATED_P on the insn in question.
1111 Changes in the register we use for saving registers to the stack:
1112 This is usually SP, but not always. Again, we deduce that if you
1113 copy SP into another register (and SP is not the CFA register),
1114 then the new register is the one we will be using for register
1115 saves. This also seems to work.
1117 Register saves: There's not much guesswork about this one; if
1118 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a
1119 register save, and the register used to calculate the destination
1120 had better be the one we think we're using for this purpose.
1122 Except: If the register being saved is the CFA register, and the
1123 offset is non-zero, we are saving the CFA, so we assume we have to
1124 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that
1125 the intent is to save the value of SP from the previous frame.
1127 Invariants / Summaries of Rules
1129 cfa current rule for calculating the CFA. It usually
1130 consists of a register and an offset.
1131 cfa_store register used by prologue code to save things to the stack
1132 cfa_store.offset is the offset from the value of
1133 cfa_store.reg to the actual CFA
1134 cfa_temp register holding an integral value. cfa_temp.offset
1135 stores the value, which will be used to adjust the
1136 stack pointer. cfa_temp is also used like cfa_store,
1137 to track stores to the stack via fp or a temp reg.
1139 Rules 1- 4: Setting a register's value to cfa.reg or an expression
1140 with cfa.reg as the first operand changes the cfa.reg and its
1141 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and
1142 cfa_temp.offset.
1144 Rules 6- 9: Set a non-cfa.reg register value to a constant or an
1145 expression yielding a constant. This sets cfa_temp.reg
1146 and cfa_temp.offset.
1148 Rule 5: Create a new register cfa_store used to save items to the
1149 stack.
1151 Rules 10-14: Save a register to the stack. Define offset as the
1152 difference of the original location and cfa_store's
1153 location (or cfa_temp's location if cfa_temp is used).
1155 The Rules
1157 "{a,b}" indicates a choice of a xor b.
1158 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg.
1160 Rule 1:
1161 (set <reg1> <reg2>:cfa.reg)
1162 effects: cfa.reg = <reg1>
1163 cfa.offset unchanged
1164 cfa_temp.reg = <reg1>
1165 cfa_temp.offset = cfa.offset
1167 Rule 2:
1168 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg {<const_int>,<reg>:cfa_temp.reg}))
1169 effects: cfa.reg = sp if fp used
1170 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp
1171 cfa_store.offset += {+/- <const_int>, cfa_temp.offset}
1172 if cfa_store.reg==sp
1174 Rule 3:
1175 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>))
1176 effects: cfa.reg = fp
1177 cfa_offset += +/- <const_int>
1179 Rule 4:
1180 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>))
1181 constraints: <reg1> != fp
1182 <reg1> != sp
1183 effects: cfa.reg = <reg1>
1184 cfa_temp.reg = <reg1>
1185 cfa_temp.offset = cfa.offset
1187 Rule 5:
1188 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg))
1189 constraints: <reg1> != fp
1190 <reg1> != sp
1191 effects: cfa_store.reg = <reg1>
1192 cfa_store.offset = cfa.offset - cfa_temp.offset
1194 Rule 6:
1195 (set <reg> <const_int>)
1196 effects: cfa_temp.reg = <reg>
1197 cfa_temp.offset = <const_int>
1199 Rule 7:
1200 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>))
1201 effects: cfa_temp.reg = <reg1>
1202 cfa_temp.offset |= <const_int>
1204 Rule 8:
1205 (set <reg> (high <exp>))
1206 effects: none
1208 Rule 9:
1209 (set <reg> (lo_sum <exp> <const_int>))
1210 effects: cfa_temp.reg = <reg>
1211 cfa_temp.offset = <const_int>
1213 Rule 10:
1214 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>)
1215 effects: cfa_store.offset -= <const_int>
1216 cfa.offset = cfa_store.offset if cfa.reg == sp
1217 cfa.reg = sp
1218 cfa.base_offset = -cfa_store.offset
1220 Rule 11:
1221 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>)
1222 effects: cfa_store.offset += -/+ mode_size(mem)
1223 cfa.offset = cfa_store.offset if cfa.reg == sp
1224 cfa.reg = sp
1225 cfa.base_offset = -cfa_store.offset
1227 Rule 12:
1228 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) <reg2>)
1229 effects: cfa.reg = <reg1>
1230 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset
1232 Rule 13:
1233 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>)
1234 effects: cfa.reg = <reg1>
1235 cfa.base_offset = -{cfa_store,cfa_temp}.offset
1237 Rule 14:
1238 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>)
1239 effects: cfa.reg = <reg1>
1240 cfa.base_offset = -cfa_temp.offset
1241 cfa_temp.offset -= mode_size(mem) */
1243 static void
1244 dwarf2out_frame_debug_expr (expr, label)
1245 rtx expr;
1246 const char *label;
1248 rtx src, dest;
1249 long offset;
1251 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1252 the PARALLEL independently. The first element is always processed if
1253 it is a SET. This is for backward compatibility. Other elements
1254 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1255 flag is set in them. */
1257 if (GET_CODE (expr) == PARALLEL
1258 || GET_CODE (expr) == SEQUENCE)
1260 int par_index;
1261 int limit = XVECLEN (expr, 0);
1263 for (par_index = 0; par_index < limit; par_index++)
1265 rtx x = XVECEXP (expr, 0, par_index);
1267 if (GET_CODE (x) == SET &&
1268 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1269 dwarf2out_frame_debug_expr (x, label);
1271 return;
1274 if (GET_CODE (expr) != SET)
1275 abort ();
1277 src = SET_SRC (expr);
1278 dest = SET_DEST (expr);
1280 switch (GET_CODE (dest))
1282 case REG:
1283 /* Rule 1 */
1284 /* Update the CFA rule wrt SP or FP. Make sure src is
1285 relative to the current CFA register. */
1286 switch (GET_CODE (src))
1288 /* Setting FP from SP. */
1289 case REG:
1290 if (cfa.reg == (unsigned) REGNO (src))
1291 /* OK. */
1293 else
1294 abort ();
1296 /* We used to require that dest be either SP or FP, but the
1297 ARM copies SP to a temporary register, and from there to
1298 FP. So we just rely on the backends to only set
1299 RTX_FRAME_RELATED_P on appropriate insns. */
1300 cfa.reg = REGNO (dest);
1301 cfa_temp.reg = cfa.reg;
1302 cfa_temp.offset = cfa.offset;
1303 break;
1305 case PLUS:
1306 case MINUS:
1307 case LO_SUM:
1308 if (dest == stack_pointer_rtx)
1310 /* Rule 2 */
1311 /* Adjusting SP. */
1312 switch (GET_CODE (XEXP (src, 1)))
1314 case CONST_INT:
1315 offset = INTVAL (XEXP (src, 1));
1316 break;
1317 case REG:
1318 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg)
1319 abort ();
1320 offset = cfa_temp.offset;
1321 break;
1322 default:
1323 abort ();
1326 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1328 /* Restoring SP from FP in the epilogue. */
1329 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1330 abort ();
1331 cfa.reg = STACK_POINTER_REGNUM;
1333 else if (GET_CODE (src) == LO_SUM)
1334 /* Assume we've set the source reg of the LO_SUM from sp. */
1336 else if (XEXP (src, 0) != stack_pointer_rtx)
1337 abort ();
1339 if (GET_CODE (src) != MINUS)
1340 offset = -offset;
1341 if (cfa.reg == STACK_POINTER_REGNUM)
1342 cfa.offset += offset;
1343 if (cfa_store.reg == STACK_POINTER_REGNUM)
1344 cfa_store.offset += offset;
1346 else if (dest == hard_frame_pointer_rtx)
1348 /* Rule 3 */
1349 /* Either setting the FP from an offset of the SP,
1350 or adjusting the FP */
1351 if (! frame_pointer_needed)
1352 abort ();
1354 if (GET_CODE (XEXP (src, 0)) == REG
1355 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg
1356 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1358 offset = INTVAL (XEXP (src, 1));
1359 if (GET_CODE (src) != MINUS)
1360 offset = -offset;
1361 cfa.offset += offset;
1362 cfa.reg = HARD_FRAME_POINTER_REGNUM;
1364 else
1365 abort ();
1367 else
1369 if (GET_CODE (src) == MINUS)
1370 abort ();
1372 /* Rule 4 */
1373 if (GET_CODE (XEXP (src, 0)) == REG
1374 && REGNO (XEXP (src, 0)) == cfa.reg
1375 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1377 /* Setting a temporary CFA register that will be copied
1378 into the FP later on. */
1379 offset = - INTVAL (XEXP (src, 1));
1380 cfa.offset += offset;
1381 cfa.reg = REGNO (dest);
1382 /* Or used to save regs to the stack. */
1383 cfa_temp.reg = cfa.reg;
1384 cfa_temp.offset = cfa.offset;
1386 /* Rule 5 */
1387 else if (GET_CODE (XEXP (src, 0)) == REG
1388 && REGNO (XEXP (src, 0)) == cfa_temp.reg
1389 && XEXP (src, 1) == stack_pointer_rtx)
1391 /* Setting a scratch register that we will use instead
1392 of SP for saving registers to the stack. */
1393 if (cfa.reg != STACK_POINTER_REGNUM)
1394 abort ();
1395 cfa_store.reg = REGNO (dest);
1396 cfa_store.offset = cfa.offset - cfa_temp.offset;
1398 /* Rule 9 */
1399 else if (GET_CODE (src) == LO_SUM
1400 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1402 cfa_temp.reg = REGNO (dest);
1403 cfa_temp.offset = INTVAL (XEXP (src, 1));
1405 else
1406 abort ();
1408 break;
1410 /* Rule 6 */
1411 case CONST_INT:
1412 cfa_temp.reg = REGNO (dest);
1413 cfa_temp.offset = INTVAL (src);
1414 break;
1416 /* Rule 7 */
1417 case IOR:
1418 if (GET_CODE (XEXP (src, 0)) != REG
1419 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg
1420 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1421 abort ();
1422 if ((unsigned) REGNO (dest) != cfa_temp.reg)
1423 cfa_temp.reg = REGNO (dest);
1424 cfa_temp.offset |= INTVAL (XEXP (src, 1));
1425 break;
1427 /* Skip over HIGH, assuming it will be followed by a LO_SUM,
1428 which will fill in all of the bits. */
1429 /* Rule 8 */
1430 case HIGH:
1431 break;
1433 default:
1434 abort ();
1436 def_cfa_1 (label, &cfa);
1437 break;
1439 case MEM:
1440 if (GET_CODE (src) != REG)
1441 abort ();
1443 /* Saving a register to the stack. Make sure dest is relative to the
1444 CFA register. */
1445 switch (GET_CODE (XEXP (dest, 0)))
1447 /* Rule 10 */
1448 /* With a push. */
1449 case PRE_MODIFY:
1450 /* We can't handle variable size modifications. */
1451 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT)
1452 abort();
1453 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1));
1455 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1456 || cfa_store.reg != STACK_POINTER_REGNUM)
1457 abort ();
1458 cfa_store.offset += offset;
1459 if (cfa.reg == STACK_POINTER_REGNUM)
1460 cfa.offset = cfa_store.offset;
1462 offset = -cfa_store.offset;
1463 break;
1464 /* Rule 11 */
1465 case PRE_INC:
1466 case PRE_DEC:
1467 offset = GET_MODE_SIZE (GET_MODE (dest));
1468 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1469 offset = -offset;
1471 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1472 || cfa_store.reg != STACK_POINTER_REGNUM)
1473 abort ();
1474 cfa_store.offset += offset;
1475 if (cfa.reg == STACK_POINTER_REGNUM)
1476 cfa.offset = cfa_store.offset;
1478 offset = -cfa_store.offset;
1479 break;
1481 /* Rule 12 */
1482 /* With an offset. */
1483 case PLUS:
1484 case MINUS:
1485 case LO_SUM:
1486 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT)
1487 abort ();
1488 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1489 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1490 offset = -offset;
1492 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1493 offset -= cfa_store.offset;
1494 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1495 offset -= cfa_temp.offset;
1496 else
1497 abort ();
1498 break;
1500 /* Rule 13 */
1501 /* Without an offset. */
1502 case REG:
1503 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0)))
1504 offset = -cfa_store.offset;
1505 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0)))
1506 offset = -cfa_temp.offset;
1507 else
1508 abort ();
1509 break;
1511 /* Rule 14 */
1512 case POST_INC:
1513 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1514 abort ();
1515 offset = -cfa_temp.offset;
1516 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest));
1517 break;
1519 default:
1520 abort ();
1523 if (REGNO (src) != STACK_POINTER_REGNUM
1524 && REGNO (src) != HARD_FRAME_POINTER_REGNUM
1525 && (unsigned) REGNO (src) == cfa.reg)
1527 /* We're storing the current CFA reg into the stack. */
1529 if (cfa.offset == 0)
1531 /* If the source register is exactly the CFA, assume
1532 we're saving SP like any other register; this happens
1533 on the ARM. */
1535 def_cfa_1 (label, &cfa);
1536 queue_reg_save (label, stack_pointer_rtx, offset);
1537 break;
1539 else
1541 /* Otherwise, we'll need to look in the stack to
1542 calculate the CFA. */
1544 rtx x = XEXP (dest, 0);
1545 if (GET_CODE (x) != REG)
1546 x = XEXP (x, 0);
1547 if (GET_CODE (x) != REG)
1548 abort ();
1549 cfa.reg = (unsigned) REGNO (x);
1550 cfa.base_offset = offset;
1551 cfa.indirect = 1;
1552 def_cfa_1 (label, &cfa);
1553 break;
1557 def_cfa_1 (label, &cfa);
1558 queue_reg_save (label, src, offset);
1559 break;
1561 default:
1562 abort ();
1566 /* Record call frame debugging information for INSN, which either
1567 sets SP or FP (adjusting how we calculate the frame address) or saves a
1568 register to the stack. If INSN is NULL_RTX, initialize our state. */
1570 void
1571 dwarf2out_frame_debug (insn)
1572 rtx insn;
1574 const char *label;
1575 rtx src;
1577 if (insn == NULL_RTX)
1579 /* Flush any queued register saves. */
1580 flush_queued_reg_saves ();
1582 /* Set up state for generating call frame debug info. */
1583 lookup_cfa (&cfa);
1584 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1585 abort ();
1586 cfa.reg = STACK_POINTER_REGNUM;
1587 cfa_store = cfa;
1588 cfa_temp.reg = -1;
1589 cfa_temp.offset = 0;
1590 return;
1593 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn))
1594 flush_queued_reg_saves ();
1596 if (! RTX_FRAME_RELATED_P (insn))
1598 if (!ACCUMULATE_OUTGOING_ARGS)
1599 dwarf2out_stack_adjust (insn);
1600 return;
1603 label = dwarf2out_cfi_label ();
1605 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1606 if (src)
1607 insn = XEXP (src, 0);
1608 else
1609 insn = PATTERN (insn);
1611 dwarf2out_frame_debug_expr (insn, label);
1614 /* Output a Call Frame Information opcode and its operand(s). */
1616 static void
1617 output_cfi (cfi, fde, for_eh)
1618 register dw_cfi_ref cfi;
1619 register dw_fde_ref fde;
1620 int for_eh;
1622 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1624 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1625 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)),
1626 "DW_CFA_advance_loc 0x%lx",
1627 cfi->dw_cfi_oprnd1.dw_cfi_offset);
1629 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1631 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1632 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1633 "DW_CFA_offset, column 0x%lx",
1634 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1635 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1637 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1639 dw2_asm_output_data (1, (cfi->dw_cfi_opc
1640 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)),
1641 "DW_CFA_restore, column 0x%lx",
1642 cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1644 else
1646 dw2_asm_output_data (1, cfi->dw_cfi_opc,
1647 "%s", dwarf_cfi_name (cfi->dw_cfi_opc));
1649 switch (cfi->dw_cfi_opc)
1651 case DW_CFA_set_loc:
1652 if (for_eh)
1653 dw2_asm_output_encoded_addr_rtx (
1654 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0),
1655 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr),
1656 NULL);
1657 else
1658 dw2_asm_output_addr (DWARF2_ADDR_SIZE,
1659 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL);
1660 break;
1661 case DW_CFA_advance_loc1:
1662 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1663 fde->dw_fde_current_label, NULL);
1664 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1665 break;
1666 case DW_CFA_advance_loc2:
1667 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1668 fde->dw_fde_current_label, NULL);
1669 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1670 break;
1671 case DW_CFA_advance_loc4:
1672 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1673 fde->dw_fde_current_label, NULL);
1674 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1675 break;
1676 case DW_CFA_MIPS_advance_loc8:
1677 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr,
1678 fde->dw_fde_current_label, NULL);
1679 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1680 break;
1681 case DW_CFA_offset_extended:
1682 case DW_CFA_GNU_negative_offset_extended:
1683 case DW_CFA_def_cfa:
1684 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1685 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL);
1686 break;
1687 case DW_CFA_restore_extended:
1688 case DW_CFA_undefined:
1689 case DW_CFA_same_value:
1690 case DW_CFA_def_cfa_register:
1691 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1692 break;
1693 case DW_CFA_register:
1694 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, NULL);
1695 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, NULL);
1696 break;
1697 case DW_CFA_def_cfa_offset:
1698 case DW_CFA_GNU_args_size:
1699 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL);
1700 break;
1701 case DW_CFA_GNU_window_save:
1702 break;
1703 case DW_CFA_def_cfa_expression:
1704 output_cfa_loc (cfi);
1705 break;
1706 default:
1707 break;
1712 /* Output the call frame information used to used to record information
1713 that relates to calculating the frame pointer, and records the
1714 location of saved registers. */
1716 static void
1717 output_call_frame_info (for_eh)
1718 int for_eh;
1720 register unsigned int i;
1721 register dw_fde_ref fde;
1722 register dw_cfi_ref cfi;
1723 char l1[20], l2[20];
1724 int any_lsda_needed = 0;
1725 char augmentation[6];
1726 int augmentation_size;
1727 int fde_encoding = DW_EH_PE_absptr;
1728 int per_encoding = DW_EH_PE_absptr;
1729 int lsda_encoding = DW_EH_PE_absptr;
1731 /* If we don't have any functions we'll want to unwind out of, don't
1732 emit any EH unwind information. */
1733 if (for_eh)
1735 int any_eh_needed = 0;
1736 for (i = 0; i < fde_table_in_use; ++i)
1737 if (fde_table[i].uses_eh_lsda)
1738 any_eh_needed = any_lsda_needed = 1;
1739 else if (! fde_table[i].nothrow)
1740 any_eh_needed = 1;
1742 if (! any_eh_needed)
1743 return;
1746 /* We're going to be generating comments, so turn on app. */
1747 if (flag_debug_asm)
1748 app_enable ();
1750 if (for_eh)
1752 #ifdef EH_FRAME_SECTION
1753 EH_FRAME_SECTION ();
1754 #else
1755 tree label = get_file_function_name ('F');
1757 force_data_section ();
1758 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1759 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1760 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1761 #endif
1762 assemble_label ("__FRAME_BEGIN__");
1764 else
1765 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_FRAME_SECTION);
1767 /* Output the CIE. */
1768 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1769 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1770 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1771 "Length of Common Information Entry");
1772 ASM_OUTPUT_LABEL (asm_out_file, l1);
1774 /* Now that the CIE pointer is PC-relative for EH,
1775 use 0 to identify the CIE. */
1776 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE),
1777 (for_eh ? 0 : DW_CIE_ID),
1778 "CIE Identifier Tag");
1780 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version");
1782 augmentation[0] = 0;
1783 augmentation_size = 0;
1784 if (for_eh)
1786 char *p;
1788 /* Augmentation:
1789 z Indicates that a uleb128 is present to size the
1790 augmentation section.
1791 L Indicates the encoding (and thus presence) of
1792 an LSDA pointer in the FDE augmentation.
1793 R Indicates a non-default pointer encoding for
1794 FDE code pointers.
1795 P Indicates the presence of an encoding + language
1796 personality routine in the CIE augmentation. */
1798 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
1799 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
1800 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
1802 p = augmentation + 1;
1803 if (eh_personality_libfunc)
1805 *p++ = 'P';
1806 augmentation_size += 1 + size_of_encoded_value (per_encoding);
1808 if (any_lsda_needed)
1810 *p++ = 'L';
1811 augmentation_size += 1;
1813 if (fde_encoding != DW_EH_PE_absptr)
1815 *p++ = 'R';
1816 augmentation_size += 1;
1818 if (p > augmentation + 1)
1820 augmentation[0] = 'z';
1821 *p = '\0';
1824 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
1825 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned)
1827 int offset = ( 4 /* Length */
1828 + 4 /* CIE Id */
1829 + 1 /* CIE version */
1830 + strlen (augmentation) + 1 /* Augmentation */
1831 + size_of_uleb128 (1) /* Code alignment */
1832 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT)
1833 + 1 /* RA column */
1834 + 1 /* Augmentation size */
1835 + 1 /* Personality encoding */ );
1836 int pad = -offset & (PTR_SIZE - 1);
1838 augmentation_size += pad;
1840 /* Augmentations should be small, so there's scarce need to
1841 iterate for a solution. Die if we exceed one uleb128 byte. */
1842 if (size_of_uleb128 (augmentation_size) != 1)
1843 abort ();
1846 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation");
1848 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
1850 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT,
1851 "CIE Data Alignment Factor");
1853 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column");
1855 if (augmentation[0])
1857 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size");
1858 if (eh_personality_libfunc)
1860 dw2_asm_output_data (1, per_encoding, "Personality (%s)",
1861 eh_data_format_name (per_encoding));
1862 dw2_asm_output_encoded_addr_rtx (per_encoding,
1863 eh_personality_libfunc, NULL);
1865 if (any_lsda_needed)
1866 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)",
1867 eh_data_format_name (lsda_encoding));
1868 if (fde_encoding != DW_EH_PE_absptr)
1869 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)",
1870 eh_data_format_name (fde_encoding));
1873 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1874 output_cfi (cfi, NULL, for_eh);
1876 /* Pad the CIE out to an address sized boundary. */
1877 ASM_OUTPUT_ALIGN (asm_out_file,
1878 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE));
1879 ASM_OUTPUT_LABEL (asm_out_file, l2);
1881 /* Loop through all of the FDE's. */
1882 for (i = 0; i < fde_table_in_use; ++i)
1884 fde = &fde_table[i];
1886 /* Don't emit EH unwind info for leaf functions that don't need it. */
1887 if (for_eh && fde->nothrow && ! fde->uses_eh_lsda)
1888 continue;
1890 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2);
1891 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2);
1892 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2);
1893 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1,
1894 "FDE Length");
1895 ASM_OUTPUT_LABEL (asm_out_file, l1);
1897 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1898 emits a target dependent sized offset when for_eh is not true.
1899 This inconsistency may confuse gdb. The only case where we need a
1900 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1901 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1902 though in order to be compatible with the dwarf_fde struct in frame.c.
1903 If the for_eh case is changed, then the struct in frame.c has
1904 to be adjusted appropriately. */
1905 if (for_eh)
1906 dw2_asm_output_delta (4, l1, "__FRAME_BEGIN__", "FDE CIE offset");
1907 else
1908 dw2_asm_output_offset (DWARF_OFFSET_SIZE,
1909 stripattributes (DEBUG_FRAME_SECTION),
1910 "FDE CIE offset");
1912 if (for_eh)
1914 dw2_asm_output_encoded_addr_rtx (fde_encoding,
1915 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin),
1916 "FDE initial location");
1917 dw2_asm_output_delta (size_of_encoded_value (fde_encoding),
1918 fde->dw_fde_end, fde->dw_fde_begin,
1919 "FDE address range");
1921 else
1923 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin,
1924 "FDE initial location");
1925 dw2_asm_output_delta (DWARF2_ADDR_SIZE,
1926 fde->dw_fde_end, fde->dw_fde_begin,
1927 "FDE address range");
1930 if (augmentation[0])
1932 if (any_lsda_needed)
1934 int size = size_of_encoded_value (lsda_encoding);
1936 if (lsda_encoding == DW_EH_PE_aligned)
1938 int offset = ( 4 /* Length */
1939 + 4 /* CIE offset */
1940 + 2 * size_of_encoded_value (fde_encoding)
1941 + 1 /* Augmentation size */ );
1942 int pad = -offset & (PTR_SIZE - 1);
1944 size += pad;
1945 if (size_of_uleb128 (size) != 1)
1946 abort ();
1949 dw2_asm_output_data_uleb128 (size, "Augmentation size");
1951 if (fde->uses_eh_lsda)
1953 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA",
1954 fde->funcdef_number);
1955 dw2_asm_output_encoded_addr_rtx (
1956 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1),
1957 "Language Specific Data Area");
1959 else
1961 if (lsda_encoding == DW_EH_PE_aligned)
1962 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1963 dw2_asm_output_data (size_of_encoded_value (lsda_encoding),
1964 0, "Language Specific Data Area (none)");
1967 else
1968 dw2_asm_output_data_uleb128 (0, "Augmentation size");
1971 /* Loop through the Call Frame Instructions associated with
1972 this FDE. */
1973 fde->dw_fde_current_label = fde->dw_fde_begin;
1974 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1975 output_cfi (cfi, fde, for_eh);
1977 /* Pad the FDE out to an address sized boundary. */
1978 ASM_OUTPUT_ALIGN (asm_out_file,
1979 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)));
1980 ASM_OUTPUT_LABEL (asm_out_file, l2);
1983 #ifndef EH_FRAME_SECTION
1984 if (for_eh)
1985 dw2_asm_output_data (4, 0, "End of Table");
1986 #endif
1987 #ifdef MIPS_DEBUGGING_INFO
1988 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1989 get a value of 0. Putting .align 0 after the label fixes it. */
1990 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1991 #endif
1993 /* Turn off app to make assembly quicker. */
1994 if (flag_debug_asm)
1995 app_disable ();
1998 /* Output a marker (i.e. a label) for the beginning of a function, before
1999 the prologue. */
2001 void
2002 dwarf2out_begin_prologue ()
2004 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2005 register dw_fde_ref fde;
2007 current_function_func_begin_label = 0;
2009 #ifdef IA64_UNWIND_INFO
2010 /* ??? current_function_func_begin_label is also used by except.c
2011 for call-site information. We must emit this label if it might
2012 be used. */
2013 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS)
2014 && ! dwarf2out_do_frame ())
2015 return;
2016 #else
2017 if (! dwarf2out_do_frame ())
2018 return;
2019 #endif
2021 ++current_funcdef_number;
2023 function_section (current_function_decl);
2024 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
2025 current_funcdef_number);
2026 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL,
2027 current_funcdef_number);
2028 current_function_func_begin_label = get_identifier (label);
2030 #ifdef IA64_UNWIND_INFO
2031 /* We can elide the fde allocation if we're not emitting debug info. */
2032 if (! dwarf2out_do_frame ())
2033 return;
2034 #endif
2036 /* Expand the fde table if necessary. */
2037 if (fde_table_in_use == fde_table_allocated)
2039 fde_table_allocated += FDE_TABLE_INCREMENT;
2040 fde_table
2041 = (dw_fde_ref) xrealloc (fde_table,
2042 fde_table_allocated * sizeof (dw_fde_node));
2045 /* Record the FDE associated with this function. */
2046 current_funcdef_fde = fde_table_in_use;
2048 /* Add the new FDE at the end of the fde_table. */
2049 fde = &fde_table[fde_table_in_use++];
2050 fde->dw_fde_begin = xstrdup (label);
2051 fde->dw_fde_current_label = NULL;
2052 fde->dw_fde_end = NULL;
2053 fde->dw_fde_cfi = NULL;
2054 fde->funcdef_number = current_funcdef_number;
2055 fde->nothrow = current_function_nothrow;
2056 fde->uses_eh_lsda = cfun->uses_eh_lsda;
2058 args_size = old_args_size = 0;
2061 /* Output a marker (i.e. a label) for the absolute end of the generated code
2062 for a function definition. This gets called *after* the epilogue code has
2063 been generated. */
2065 void
2066 dwarf2out_end_epilogue ()
2068 dw_fde_ref fde;
2069 char label[MAX_ARTIFICIAL_LABEL_BYTES];
2071 /* Output a label to mark the endpoint of the code generated for this
2072 function. */
2073 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
2074 ASM_OUTPUT_LABEL (asm_out_file, label);
2075 fde = &fde_table[fde_table_in_use - 1];
2076 fde->dw_fde_end = xstrdup (label);
2079 void
2080 dwarf2out_frame_init ()
2082 /* Allocate the initial hunk of the fde_table. */
2083 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
2084 fde_table_allocated = FDE_TABLE_INCREMENT;
2085 fde_table_in_use = 0;
2087 /* Generate the CFA instructions common to all FDE's. Do it now for the
2088 sake of lookup_cfa. */
2090 #ifdef DWARF2_UNWIND_INFO
2091 /* On entry, the Canonical Frame Address is at SP. */
2092 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
2093 initial_return_save (INCOMING_RETURN_ADDR_RTX);
2094 #endif
2097 void
2098 dwarf2out_frame_finish ()
2100 /* Output call frame information. */
2101 #ifdef MIPS_DEBUGGING_INFO
2102 if (write_symbols == DWARF2_DEBUG)
2103 output_call_frame_info (0);
2104 if (flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2105 output_call_frame_info (1);
2106 #else
2107 if (write_symbols == DWARF2_DEBUG
2108 || flag_unwind_tables || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS))
2109 output_call_frame_info (1);
2110 #endif
2113 /* And now, the subset of the debugging information support code necessary
2114 for emitting location expressions. */
2116 typedef struct dw_val_struct *dw_val_ref;
2117 typedef struct die_struct *dw_die_ref;
2118 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
2119 typedef struct dw_loc_list_struct *dw_loc_list_ref;
2121 /* Each DIE may have a series of attribute/value pairs. Values
2122 can take on several forms. The forms that are used in this
2123 implementation are listed below. */
2125 typedef enum
2127 dw_val_class_addr,
2128 dw_val_class_loc,
2129 dw_val_class_loc_list,
2130 dw_val_class_const,
2131 dw_val_class_unsigned_const,
2132 dw_val_class_long_long,
2133 dw_val_class_float,
2134 dw_val_class_flag,
2135 dw_val_class_die_ref,
2136 dw_val_class_fde_ref,
2137 dw_val_class_lbl_id,
2138 dw_val_class_lbl_offset,
2139 dw_val_class_str
2141 dw_val_class;
2143 /* Describe a double word constant value. */
2144 /* ??? Every instance of long_long in the code really means CONST_DOUBLE. */
2146 typedef struct dw_long_long_struct
2148 unsigned long hi;
2149 unsigned long low;
2151 dw_long_long_const;
2153 /* Describe a floating point constant value. */
2155 typedef struct dw_fp_struct
2157 long *array;
2158 unsigned length;
2160 dw_float_const;
2162 /* The dw_val_node describes an attribute's value, as it is
2163 represented internally. */
2165 typedef struct dw_val_struct
2167 dw_val_class val_class;
2168 union
2170 rtx val_addr;
2171 dw_loc_list_ref val_loc_list;
2172 dw_loc_descr_ref val_loc;
2173 long int val_int;
2174 long unsigned val_unsigned;
2175 dw_long_long_const val_long_long;
2176 dw_float_const val_float;
2177 struct {
2178 dw_die_ref die;
2179 int external;
2180 } val_die_ref;
2181 unsigned val_fde_index;
2182 char *val_str;
2183 char *val_lbl_id;
2184 unsigned char val_flag;
2188 dw_val_node;
2190 /* Locations in memory are described using a sequence of stack machine
2191 operations. */
2193 typedef struct dw_loc_descr_struct
2195 dw_loc_descr_ref dw_loc_next;
2196 enum dwarf_location_atom dw_loc_opc;
2197 dw_val_node dw_loc_oprnd1;
2198 dw_val_node dw_loc_oprnd2;
2199 int dw_loc_addr;
2201 dw_loc_descr_node;
2203 /* Location lists are ranges + location descriptions for that range,
2204 so you can track variables that are in different places over
2205 their entire life. */
2206 typedef struct dw_loc_list_struct
2208 dw_loc_list_ref dw_loc_next;
2209 const char *begin; /* Label for begin address of range */
2210 const char *end; /* Label for end address of range */
2211 char *ll_symbol; /* Label for beginning of location list. Only on head of list */
2212 const char *section; /* Section this loclist is relative to */
2213 dw_loc_descr_ref expr;
2214 } dw_loc_list_node;
2216 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2217 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2218 unsigned long,
2219 unsigned long));
2220 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2221 dw_loc_descr_ref));
2222 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2223 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2224 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2225 static void output_loc_sequence PARAMS ((dw_loc_descr_ref));
2227 /* Convert a DWARF stack opcode into its string name. */
2229 static const char *
2230 dwarf_stack_op_name (op)
2231 register unsigned op;
2233 switch (op)
2235 case DW_OP_addr:
2236 return "DW_OP_addr";
2237 case DW_OP_deref:
2238 return "DW_OP_deref";
2239 case DW_OP_const1u:
2240 return "DW_OP_const1u";
2241 case DW_OP_const1s:
2242 return "DW_OP_const1s";
2243 case DW_OP_const2u:
2244 return "DW_OP_const2u";
2245 case DW_OP_const2s:
2246 return "DW_OP_const2s";
2247 case DW_OP_const4u:
2248 return "DW_OP_const4u";
2249 case DW_OP_const4s:
2250 return "DW_OP_const4s";
2251 case DW_OP_const8u:
2252 return "DW_OP_const8u";
2253 case DW_OP_const8s:
2254 return "DW_OP_const8s";
2255 case DW_OP_constu:
2256 return "DW_OP_constu";
2257 case DW_OP_consts:
2258 return "DW_OP_consts";
2259 case DW_OP_dup:
2260 return "DW_OP_dup";
2261 case DW_OP_drop:
2262 return "DW_OP_drop";
2263 case DW_OP_over:
2264 return "DW_OP_over";
2265 case DW_OP_pick:
2266 return "DW_OP_pick";
2267 case DW_OP_swap:
2268 return "DW_OP_swap";
2269 case DW_OP_rot:
2270 return "DW_OP_rot";
2271 case DW_OP_xderef:
2272 return "DW_OP_xderef";
2273 case DW_OP_abs:
2274 return "DW_OP_abs";
2275 case DW_OP_and:
2276 return "DW_OP_and";
2277 case DW_OP_div:
2278 return "DW_OP_div";
2279 case DW_OP_minus:
2280 return "DW_OP_minus";
2281 case DW_OP_mod:
2282 return "DW_OP_mod";
2283 case DW_OP_mul:
2284 return "DW_OP_mul";
2285 case DW_OP_neg:
2286 return "DW_OP_neg";
2287 case DW_OP_not:
2288 return "DW_OP_not";
2289 case DW_OP_or:
2290 return "DW_OP_or";
2291 case DW_OP_plus:
2292 return "DW_OP_plus";
2293 case DW_OP_plus_uconst:
2294 return "DW_OP_plus_uconst";
2295 case DW_OP_shl:
2296 return "DW_OP_shl";
2297 case DW_OP_shr:
2298 return "DW_OP_shr";
2299 case DW_OP_shra:
2300 return "DW_OP_shra";
2301 case DW_OP_xor:
2302 return "DW_OP_xor";
2303 case DW_OP_bra:
2304 return "DW_OP_bra";
2305 case DW_OP_eq:
2306 return "DW_OP_eq";
2307 case DW_OP_ge:
2308 return "DW_OP_ge";
2309 case DW_OP_gt:
2310 return "DW_OP_gt";
2311 case DW_OP_le:
2312 return "DW_OP_le";
2313 case DW_OP_lt:
2314 return "DW_OP_lt";
2315 case DW_OP_ne:
2316 return "DW_OP_ne";
2317 case DW_OP_skip:
2318 return "DW_OP_skip";
2319 case DW_OP_lit0:
2320 return "DW_OP_lit0";
2321 case DW_OP_lit1:
2322 return "DW_OP_lit1";
2323 case DW_OP_lit2:
2324 return "DW_OP_lit2";
2325 case DW_OP_lit3:
2326 return "DW_OP_lit3";
2327 case DW_OP_lit4:
2328 return "DW_OP_lit4";
2329 case DW_OP_lit5:
2330 return "DW_OP_lit5";
2331 case DW_OP_lit6:
2332 return "DW_OP_lit6";
2333 case DW_OP_lit7:
2334 return "DW_OP_lit7";
2335 case DW_OP_lit8:
2336 return "DW_OP_lit8";
2337 case DW_OP_lit9:
2338 return "DW_OP_lit9";
2339 case DW_OP_lit10:
2340 return "DW_OP_lit10";
2341 case DW_OP_lit11:
2342 return "DW_OP_lit11";
2343 case DW_OP_lit12:
2344 return "DW_OP_lit12";
2345 case DW_OP_lit13:
2346 return "DW_OP_lit13";
2347 case DW_OP_lit14:
2348 return "DW_OP_lit14";
2349 case DW_OP_lit15:
2350 return "DW_OP_lit15";
2351 case DW_OP_lit16:
2352 return "DW_OP_lit16";
2353 case DW_OP_lit17:
2354 return "DW_OP_lit17";
2355 case DW_OP_lit18:
2356 return "DW_OP_lit18";
2357 case DW_OP_lit19:
2358 return "DW_OP_lit19";
2359 case DW_OP_lit20:
2360 return "DW_OP_lit20";
2361 case DW_OP_lit21:
2362 return "DW_OP_lit21";
2363 case DW_OP_lit22:
2364 return "DW_OP_lit22";
2365 case DW_OP_lit23:
2366 return "DW_OP_lit23";
2367 case DW_OP_lit24:
2368 return "DW_OP_lit24";
2369 case DW_OP_lit25:
2370 return "DW_OP_lit25";
2371 case DW_OP_lit26:
2372 return "DW_OP_lit26";
2373 case DW_OP_lit27:
2374 return "DW_OP_lit27";
2375 case DW_OP_lit28:
2376 return "DW_OP_lit28";
2377 case DW_OP_lit29:
2378 return "DW_OP_lit29";
2379 case DW_OP_lit30:
2380 return "DW_OP_lit30";
2381 case DW_OP_lit31:
2382 return "DW_OP_lit31";
2383 case DW_OP_reg0:
2384 return "DW_OP_reg0";
2385 case DW_OP_reg1:
2386 return "DW_OP_reg1";
2387 case DW_OP_reg2:
2388 return "DW_OP_reg2";
2389 case DW_OP_reg3:
2390 return "DW_OP_reg3";
2391 case DW_OP_reg4:
2392 return "DW_OP_reg4";
2393 case DW_OP_reg5:
2394 return "DW_OP_reg5";
2395 case DW_OP_reg6:
2396 return "DW_OP_reg6";
2397 case DW_OP_reg7:
2398 return "DW_OP_reg7";
2399 case DW_OP_reg8:
2400 return "DW_OP_reg8";
2401 case DW_OP_reg9:
2402 return "DW_OP_reg9";
2403 case DW_OP_reg10:
2404 return "DW_OP_reg10";
2405 case DW_OP_reg11:
2406 return "DW_OP_reg11";
2407 case DW_OP_reg12:
2408 return "DW_OP_reg12";
2409 case DW_OP_reg13:
2410 return "DW_OP_reg13";
2411 case DW_OP_reg14:
2412 return "DW_OP_reg14";
2413 case DW_OP_reg15:
2414 return "DW_OP_reg15";
2415 case DW_OP_reg16:
2416 return "DW_OP_reg16";
2417 case DW_OP_reg17:
2418 return "DW_OP_reg17";
2419 case DW_OP_reg18:
2420 return "DW_OP_reg18";
2421 case DW_OP_reg19:
2422 return "DW_OP_reg19";
2423 case DW_OP_reg20:
2424 return "DW_OP_reg20";
2425 case DW_OP_reg21:
2426 return "DW_OP_reg21";
2427 case DW_OP_reg22:
2428 return "DW_OP_reg22";
2429 case DW_OP_reg23:
2430 return "DW_OP_reg23";
2431 case DW_OP_reg24:
2432 return "DW_OP_reg24";
2433 case DW_OP_reg25:
2434 return "DW_OP_reg25";
2435 case DW_OP_reg26:
2436 return "DW_OP_reg26";
2437 case DW_OP_reg27:
2438 return "DW_OP_reg27";
2439 case DW_OP_reg28:
2440 return "DW_OP_reg28";
2441 case DW_OP_reg29:
2442 return "DW_OP_reg29";
2443 case DW_OP_reg30:
2444 return "DW_OP_reg30";
2445 case DW_OP_reg31:
2446 return "DW_OP_reg31";
2447 case DW_OP_breg0:
2448 return "DW_OP_breg0";
2449 case DW_OP_breg1:
2450 return "DW_OP_breg1";
2451 case DW_OP_breg2:
2452 return "DW_OP_breg2";
2453 case DW_OP_breg3:
2454 return "DW_OP_breg3";
2455 case DW_OP_breg4:
2456 return "DW_OP_breg4";
2457 case DW_OP_breg5:
2458 return "DW_OP_breg5";
2459 case DW_OP_breg6:
2460 return "DW_OP_breg6";
2461 case DW_OP_breg7:
2462 return "DW_OP_breg7";
2463 case DW_OP_breg8:
2464 return "DW_OP_breg8";
2465 case DW_OP_breg9:
2466 return "DW_OP_breg9";
2467 case DW_OP_breg10:
2468 return "DW_OP_breg10";
2469 case DW_OP_breg11:
2470 return "DW_OP_breg11";
2471 case DW_OP_breg12:
2472 return "DW_OP_breg12";
2473 case DW_OP_breg13:
2474 return "DW_OP_breg13";
2475 case DW_OP_breg14:
2476 return "DW_OP_breg14";
2477 case DW_OP_breg15:
2478 return "DW_OP_breg15";
2479 case DW_OP_breg16:
2480 return "DW_OP_breg16";
2481 case DW_OP_breg17:
2482 return "DW_OP_breg17";
2483 case DW_OP_breg18:
2484 return "DW_OP_breg18";
2485 case DW_OP_breg19:
2486 return "DW_OP_breg19";
2487 case DW_OP_breg20:
2488 return "DW_OP_breg20";
2489 case DW_OP_breg21:
2490 return "DW_OP_breg21";
2491 case DW_OP_breg22:
2492 return "DW_OP_breg22";
2493 case DW_OP_breg23:
2494 return "DW_OP_breg23";
2495 case DW_OP_breg24:
2496 return "DW_OP_breg24";
2497 case DW_OP_breg25:
2498 return "DW_OP_breg25";
2499 case DW_OP_breg26:
2500 return "DW_OP_breg26";
2501 case DW_OP_breg27:
2502 return "DW_OP_breg27";
2503 case DW_OP_breg28:
2504 return "DW_OP_breg28";
2505 case DW_OP_breg29:
2506 return "DW_OP_breg29";
2507 case DW_OP_breg30:
2508 return "DW_OP_breg30";
2509 case DW_OP_breg31:
2510 return "DW_OP_breg31";
2511 case DW_OP_regx:
2512 return "DW_OP_regx";
2513 case DW_OP_fbreg:
2514 return "DW_OP_fbreg";
2515 case DW_OP_bregx:
2516 return "DW_OP_bregx";
2517 case DW_OP_piece:
2518 return "DW_OP_piece";
2519 case DW_OP_deref_size:
2520 return "DW_OP_deref_size";
2521 case DW_OP_xderef_size:
2522 return "DW_OP_xderef_size";
2523 case DW_OP_nop:
2524 return "DW_OP_nop";
2525 default:
2526 return "OP_<unknown>";
2530 /* Return a pointer to a newly allocated location description. Location
2531 descriptions are simple expression terms that can be strung
2532 together to form more complicated location (address) descriptions. */
2534 static inline dw_loc_descr_ref
2535 new_loc_descr (op, oprnd1, oprnd2)
2536 register enum dwarf_location_atom op;
2537 register unsigned long oprnd1;
2538 register unsigned long oprnd2;
2540 /* Use xcalloc here so we clear out all of the long_long constant in
2541 the union. */
2542 register dw_loc_descr_ref descr
2543 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node));
2545 descr->dw_loc_opc = op;
2546 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
2547 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
2548 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
2549 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
2551 return descr;
2555 /* Add a location description term to a location description expression. */
2557 static inline void
2558 add_loc_descr (list_head, descr)
2559 register dw_loc_descr_ref *list_head;
2560 register dw_loc_descr_ref descr;
2562 register dw_loc_descr_ref *d;
2564 /* Find the end of the chain. */
2565 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
2568 *d = descr;
2571 /* Return the size of a location descriptor. */
2573 static unsigned long
2574 size_of_loc_descr (loc)
2575 register dw_loc_descr_ref loc;
2577 register unsigned long size = 1;
2579 switch (loc->dw_loc_opc)
2581 case DW_OP_addr:
2582 size += DWARF2_ADDR_SIZE;
2583 break;
2584 case DW_OP_const1u:
2585 case DW_OP_const1s:
2586 size += 1;
2587 break;
2588 case DW_OP_const2u:
2589 case DW_OP_const2s:
2590 size += 2;
2591 break;
2592 case DW_OP_const4u:
2593 case DW_OP_const4s:
2594 size += 4;
2595 break;
2596 case DW_OP_const8u:
2597 case DW_OP_const8s:
2598 size += 8;
2599 break;
2600 case DW_OP_constu:
2601 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2602 break;
2603 case DW_OP_consts:
2604 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2605 break;
2606 case DW_OP_pick:
2607 size += 1;
2608 break;
2609 case DW_OP_plus_uconst:
2610 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2611 break;
2612 case DW_OP_skip:
2613 case DW_OP_bra:
2614 size += 2;
2615 break;
2616 case DW_OP_breg0:
2617 case DW_OP_breg1:
2618 case DW_OP_breg2:
2619 case DW_OP_breg3:
2620 case DW_OP_breg4:
2621 case DW_OP_breg5:
2622 case DW_OP_breg6:
2623 case DW_OP_breg7:
2624 case DW_OP_breg8:
2625 case DW_OP_breg9:
2626 case DW_OP_breg10:
2627 case DW_OP_breg11:
2628 case DW_OP_breg12:
2629 case DW_OP_breg13:
2630 case DW_OP_breg14:
2631 case DW_OP_breg15:
2632 case DW_OP_breg16:
2633 case DW_OP_breg17:
2634 case DW_OP_breg18:
2635 case DW_OP_breg19:
2636 case DW_OP_breg20:
2637 case DW_OP_breg21:
2638 case DW_OP_breg22:
2639 case DW_OP_breg23:
2640 case DW_OP_breg24:
2641 case DW_OP_breg25:
2642 case DW_OP_breg26:
2643 case DW_OP_breg27:
2644 case DW_OP_breg28:
2645 case DW_OP_breg29:
2646 case DW_OP_breg30:
2647 case DW_OP_breg31:
2648 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2649 break;
2650 case DW_OP_regx:
2651 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2652 break;
2653 case DW_OP_fbreg:
2654 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
2655 break;
2656 case DW_OP_bregx:
2657 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2658 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
2659 break;
2660 case DW_OP_piece:
2661 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
2662 break;
2663 case DW_OP_deref_size:
2664 case DW_OP_xderef_size:
2665 size += 1;
2666 break;
2667 default:
2668 break;
2671 return size;
2674 /* Return the size of a series of location descriptors. */
2676 static unsigned long
2677 size_of_locs (loc)
2678 register dw_loc_descr_ref loc;
2680 register unsigned long size = 0;
2682 for (; loc != NULL; loc = loc->dw_loc_next)
2684 loc->dw_loc_addr = size;
2685 size += size_of_loc_descr (loc);
2688 return size;
2691 /* Output location description stack opcode's operands (if any). */
2693 static void
2694 output_loc_operands (loc)
2695 register dw_loc_descr_ref loc;
2697 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
2698 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
2700 switch (loc->dw_loc_opc)
2702 #ifdef DWARF2_DEBUGGING_INFO
2703 case DW_OP_addr:
2704 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL);
2705 break;
2706 case DW_OP_const2u:
2707 case DW_OP_const2s:
2708 dw2_asm_output_data (2, val1->v.val_int, NULL);
2709 break;
2710 case DW_OP_const4u:
2711 case DW_OP_const4s:
2712 dw2_asm_output_data (4, val1->v.val_int, NULL);
2713 break;
2714 case DW_OP_const8u:
2715 case DW_OP_const8s:
2716 if (HOST_BITS_PER_LONG < 64)
2717 abort ();
2718 dw2_asm_output_data (8, val1->v.val_int, NULL);
2719 break;
2720 case DW_OP_skip:
2721 case DW_OP_bra:
2723 int offset;
2725 if (val1->val_class == dw_val_class_loc)
2726 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3);
2727 else
2728 abort ();
2730 dw2_asm_output_data (2, offset, NULL);
2732 break;
2733 #else
2734 case DW_OP_addr:
2735 case DW_OP_const2u:
2736 case DW_OP_const2s:
2737 case DW_OP_const4u:
2738 case DW_OP_const4s:
2739 case DW_OP_const8u:
2740 case DW_OP_const8s:
2741 case DW_OP_skip:
2742 case DW_OP_bra:
2743 /* We currently don't make any attempt to make sure these are
2744 aligned properly like we do for the main unwind info, so
2745 don't support emitting things larger than a byte if we're
2746 only doing unwinding. */
2747 abort ();
2748 #endif
2749 case DW_OP_const1u:
2750 case DW_OP_const1s:
2751 dw2_asm_output_data (1, val1->v.val_int, NULL);
2752 break;
2753 case DW_OP_constu:
2754 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2755 break;
2756 case DW_OP_consts:
2757 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2758 break;
2759 case DW_OP_pick:
2760 dw2_asm_output_data (1, val1->v.val_int, NULL);
2761 break;
2762 case DW_OP_plus_uconst:
2763 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2764 break;
2765 case DW_OP_breg0:
2766 case DW_OP_breg1:
2767 case DW_OP_breg2:
2768 case DW_OP_breg3:
2769 case DW_OP_breg4:
2770 case DW_OP_breg5:
2771 case DW_OP_breg6:
2772 case DW_OP_breg7:
2773 case DW_OP_breg8:
2774 case DW_OP_breg9:
2775 case DW_OP_breg10:
2776 case DW_OP_breg11:
2777 case DW_OP_breg12:
2778 case DW_OP_breg13:
2779 case DW_OP_breg14:
2780 case DW_OP_breg15:
2781 case DW_OP_breg16:
2782 case DW_OP_breg17:
2783 case DW_OP_breg18:
2784 case DW_OP_breg19:
2785 case DW_OP_breg20:
2786 case DW_OP_breg21:
2787 case DW_OP_breg22:
2788 case DW_OP_breg23:
2789 case DW_OP_breg24:
2790 case DW_OP_breg25:
2791 case DW_OP_breg26:
2792 case DW_OP_breg27:
2793 case DW_OP_breg28:
2794 case DW_OP_breg29:
2795 case DW_OP_breg30:
2796 case DW_OP_breg31:
2797 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2798 break;
2799 case DW_OP_regx:
2800 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2801 break;
2802 case DW_OP_fbreg:
2803 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL);
2804 break;
2805 case DW_OP_bregx:
2806 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2807 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL);
2808 break;
2809 case DW_OP_piece:
2810 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL);
2811 break;
2812 case DW_OP_deref_size:
2813 case DW_OP_xderef_size:
2814 dw2_asm_output_data (1, val1->v.val_int, NULL);
2815 break;
2816 default:
2817 /* Other codes have no operands. */
2818 break;
2822 /* Output a sequence of location operations. */
2824 static void
2825 output_loc_sequence (loc)
2826 dw_loc_descr_ref loc;
2828 for (; loc != NULL; loc = loc->dw_loc_next)
2830 /* Output the opcode. */
2831 dw2_asm_output_data (1, loc->dw_loc_opc,
2832 "%s", dwarf_stack_op_name (loc->dw_loc_opc));
2834 /* Output the operand(s) (if any). */
2835 output_loc_operands (loc);
2839 /* This routine will generate the correct assembly data for a location
2840 description based on a cfi entry with a complex address. */
2842 static void
2843 output_cfa_loc (cfi)
2844 dw_cfi_ref cfi;
2846 dw_loc_descr_ref loc;
2847 unsigned long size;
2849 /* Output the size of the block. */
2850 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc;
2851 size = size_of_locs (loc);
2852 dw2_asm_output_data_uleb128 (size, NULL);
2854 /* Now output the operations themselves. */
2855 output_loc_sequence (loc);
2858 /* This function builds a dwarf location descriptor seqeunce from
2859 a dw_cfa_location. */
2861 static struct dw_loc_descr_struct *
2862 build_cfa_loc (cfa)
2863 dw_cfa_location *cfa;
2865 struct dw_loc_descr_struct *head, *tmp;
2867 if (cfa->indirect == 0)
2868 abort ();
2870 if (cfa->base_offset)
2872 if (cfa->reg <= 31)
2873 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0);
2874 else
2875 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset);
2877 else if (cfa->reg <= 31)
2878 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0);
2879 else
2880 head = new_loc_descr (DW_OP_regx, cfa->reg, 0);
2881 head->dw_loc_oprnd1.val_class = dw_val_class_const;
2882 tmp = new_loc_descr (DW_OP_deref, 0, 0);
2883 add_loc_descr (&head, tmp);
2884 if (cfa->offset != 0)
2886 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0);
2887 add_loc_descr (&head, tmp);
2889 return head;
2892 /* This function fills in aa dw_cfa_location structure from a
2893 dwarf location descriptor sequence. */
2895 static void
2896 get_cfa_from_loc_descr (cfa, loc)
2897 dw_cfa_location *cfa;
2898 struct dw_loc_descr_struct *loc;
2900 struct dw_loc_descr_struct *ptr;
2901 cfa->offset = 0;
2902 cfa->base_offset = 0;
2903 cfa->indirect = 0;
2904 cfa->reg = -1;
2906 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next)
2908 enum dwarf_location_atom op = ptr->dw_loc_opc;
2909 switch (op)
2911 case DW_OP_reg0:
2912 case DW_OP_reg1:
2913 case DW_OP_reg2:
2914 case DW_OP_reg3:
2915 case DW_OP_reg4:
2916 case DW_OP_reg5:
2917 case DW_OP_reg6:
2918 case DW_OP_reg7:
2919 case DW_OP_reg8:
2920 case DW_OP_reg9:
2921 case DW_OP_reg10:
2922 case DW_OP_reg11:
2923 case DW_OP_reg12:
2924 case DW_OP_reg13:
2925 case DW_OP_reg14:
2926 case DW_OP_reg15:
2927 case DW_OP_reg16:
2928 case DW_OP_reg17:
2929 case DW_OP_reg18:
2930 case DW_OP_reg19:
2931 case DW_OP_reg20:
2932 case DW_OP_reg21:
2933 case DW_OP_reg22:
2934 case DW_OP_reg23:
2935 case DW_OP_reg24:
2936 case DW_OP_reg25:
2937 case DW_OP_reg26:
2938 case DW_OP_reg27:
2939 case DW_OP_reg28:
2940 case DW_OP_reg29:
2941 case DW_OP_reg30:
2942 case DW_OP_reg31:
2943 cfa->reg = op - DW_OP_reg0;
2944 break;
2945 case DW_OP_regx:
2946 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2947 break;
2948 case DW_OP_breg0:
2949 case DW_OP_breg1:
2950 case DW_OP_breg2:
2951 case DW_OP_breg3:
2952 case DW_OP_breg4:
2953 case DW_OP_breg5:
2954 case DW_OP_breg6:
2955 case DW_OP_breg7:
2956 case DW_OP_breg8:
2957 case DW_OP_breg9:
2958 case DW_OP_breg10:
2959 case DW_OP_breg11:
2960 case DW_OP_breg12:
2961 case DW_OP_breg13:
2962 case DW_OP_breg14:
2963 case DW_OP_breg15:
2964 case DW_OP_breg16:
2965 case DW_OP_breg17:
2966 case DW_OP_breg18:
2967 case DW_OP_breg19:
2968 case DW_OP_breg20:
2969 case DW_OP_breg21:
2970 case DW_OP_breg22:
2971 case DW_OP_breg23:
2972 case DW_OP_breg24:
2973 case DW_OP_breg25:
2974 case DW_OP_breg26:
2975 case DW_OP_breg27:
2976 case DW_OP_breg28:
2977 case DW_OP_breg29:
2978 case DW_OP_breg30:
2979 case DW_OP_breg31:
2980 cfa->reg = op - DW_OP_breg0;
2981 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int;
2982 break;
2983 case DW_OP_bregx:
2984 cfa->reg = ptr->dw_loc_oprnd1.v.val_int;
2985 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int;
2986 break;
2987 case DW_OP_deref:
2988 cfa->indirect = 1;
2989 break;
2990 case DW_OP_plus_uconst:
2991 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned;
2992 break;
2993 default:
2994 internal_error ("DW_LOC_OP %s not implememnted\n",
2995 dwarf_stack_op_name (ptr->dw_loc_opc));
2999 #endif /* .debug_frame support */
3001 /* And now, the support for symbolic debugging information. */
3002 #ifdef DWARF2_DEBUGGING_INFO
3004 static void dwarf2out_init PARAMS ((const char *));
3005 static void dwarf2out_finish PARAMS ((const char *));
3006 static void dwarf2out_define PARAMS ((unsigned int, const char *));
3007 static void dwarf2out_undef PARAMS ((unsigned int, const char *));
3008 static void dwarf2out_start_source_file PARAMS ((unsigned, const char *));
3009 static void dwarf2out_end_source_file PARAMS ((unsigned));
3010 static void dwarf2out_begin_block PARAMS ((unsigned, unsigned));
3011 static void dwarf2out_end_block PARAMS ((unsigned, unsigned));
3012 static void dwarf2out_source_line PARAMS ((const char *, rtx));
3014 /* The debug hooks structure. */
3016 struct gcc_debug_hooks dwarf2_debug_hooks =
3018 dwarf2out_init,
3019 dwarf2out_finish,
3020 dwarf2out_define,
3021 dwarf2out_undef,
3022 dwarf2out_start_source_file,
3023 dwarf2out_end_source_file,
3024 dwarf2out_begin_block,
3025 dwarf2out_end_block,
3026 dwarf2out_source_line,
3027 dwarf2out_end_epilogue,
3028 debug_nothing_int /* end_function */
3031 /* NOTE: In the comments in this file, many references are made to
3032 "Debugging Information Entries". This term is abbreviated as `DIE'
3033 throughout the remainder of this file. */
3035 /* An internal representation of the DWARF output is built, and then
3036 walked to generate the DWARF debugging info. The walk of the internal
3037 representation is done after the entire program has been compiled.
3038 The types below are used to describe the internal representation. */
3040 /* Various DIE's use offsets relative to the beginning of the
3041 .debug_info section to refer to each other. */
3043 typedef long int dw_offset;
3045 /* Define typedefs here to avoid circular dependencies. */
3047 typedef struct dw_attr_struct *dw_attr_ref;
3048 typedef struct dw_line_info_struct *dw_line_info_ref;
3049 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
3050 typedef struct pubname_struct *pubname_ref;
3051 typedef dw_die_ref *arange_ref;
3053 /* Each entry in the line_info_table maintains the file and
3054 line number associated with the label generated for that
3055 entry. The label gives the PC value associated with
3056 the line number entry. */
3058 typedef struct dw_line_info_struct
3060 unsigned long dw_file_num;
3061 unsigned long dw_line_num;
3063 dw_line_info_entry;
3065 /* Line information for functions in separate sections; each one gets its
3066 own sequence. */
3067 typedef struct dw_separate_line_info_struct
3069 unsigned long dw_file_num;
3070 unsigned long dw_line_num;
3071 unsigned long function;
3073 dw_separate_line_info_entry;
3075 /* Each DIE attribute has a field specifying the attribute kind,
3076 a link to the next attribute in the chain, and an attribute value.
3077 Attributes are typically linked below the DIE they modify. */
3079 typedef struct dw_attr_struct
3081 enum dwarf_attribute dw_attr;
3082 dw_attr_ref dw_attr_next;
3083 dw_val_node dw_attr_val;
3085 dw_attr_node;
3087 /* The Debugging Information Entry (DIE) structure */
3089 typedef struct die_struct
3091 enum dwarf_tag die_tag;
3092 char *die_symbol;
3093 dw_attr_ref die_attr;
3094 dw_die_ref die_parent;
3095 dw_die_ref die_child;
3096 dw_die_ref die_sib;
3097 dw_offset die_offset;
3098 unsigned long die_abbrev;
3099 int die_mark;
3101 die_node;
3103 /* The pubname structure */
3105 typedef struct pubname_struct
3107 dw_die_ref die;
3108 char *name;
3110 pubname_entry;
3112 /* The limbo die list structure. */
3113 typedef struct limbo_die_struct
3115 dw_die_ref die;
3116 struct limbo_die_struct *next;
3118 limbo_die_node;
3120 /* How to start an assembler comment. */
3121 #ifndef ASM_COMMENT_START
3122 #define ASM_COMMENT_START ";#"
3123 #endif
3125 /* Define a macro which returns non-zero for a TYPE_DECL which was
3126 implicitly generated for a tagged type.
3128 Note that unlike the gcc front end (which generates a NULL named
3129 TYPE_DECL node for each complete tagged type, each array type, and
3130 each function type node created) the g++ front end generates a
3131 _named_ TYPE_DECL node for each tagged type node created.
3132 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
3133 generate a DW_TAG_typedef DIE for them. */
3135 #define TYPE_DECL_IS_STUB(decl) \
3136 (DECL_NAME (decl) == NULL_TREE \
3137 || (DECL_ARTIFICIAL (decl) \
3138 && is_tagged_type (TREE_TYPE (decl)) \
3139 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
3140 /* This is necessary for stub decls that \
3141 appear in nested inline functions. */ \
3142 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
3143 && (decl_ultimate_origin (decl) \
3144 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
3146 /* Information concerning the compilation unit's programming
3147 language, and compiler version. */
3149 extern int flag_traditional;
3151 /* Fixed size portion of the DWARF compilation unit header. */
3152 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
3154 /* Fixed size portion of debugging line information prolog. */
3155 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
3157 /* Fixed size portion of public names info. */
3158 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
3160 /* Fixed size portion of the address range info. */
3161 #define DWARF_ARANGES_HEADER_SIZE \
3162 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3163 - DWARF_OFFSET_SIZE)
3165 /* Size of padding portion in the address range info. It must be
3166 aligned to twice the pointer size. */
3167 #define DWARF_ARANGES_PAD_SIZE \
3168 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \
3169 - (2 * DWARF_OFFSET_SIZE + 4))
3171 /* Use assembler line directives if available. */
3172 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
3173 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
3174 #define DWARF2_ASM_LINE_DEBUG_INFO 1
3175 #else
3176 #define DWARF2_ASM_LINE_DEBUG_INFO 0
3177 #endif
3178 #endif
3180 /* Define the architecture-dependent minimum instruction length (in bytes).
3181 In this implementation of DWARF, this field is used for information
3182 purposes only. Since GCC generates assembly language, we have
3183 no a priori knowledge of how many instruction bytes are generated
3184 for each source line, and therefore can use only the DW_LNE_set_address
3185 and DW_LNS_fixed_advance_pc line information commands. */
3187 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
3188 #define DWARF_LINE_MIN_INSTR_LENGTH 4
3189 #endif
3191 /* Minimum line offset in a special line info. opcode.
3192 This value was chosen to give a reasonable range of values. */
3193 #define DWARF_LINE_BASE -10
3195 /* First special line opcde - leave room for the standard opcodes. */
3196 #define DWARF_LINE_OPCODE_BASE 10
3198 /* Range of line offsets in a special line info. opcode. */
3199 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
3201 /* Flag that indicates the initial value of the is_stmt_start flag.
3202 In the present implementation, we do not mark any lines as
3203 the beginning of a source statement, because that information
3204 is not made available by the GCC front-end. */
3205 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
3207 /* This location is used by calc_die_sizes() to keep track
3208 the offset of each DIE within the .debug_info section. */
3209 static unsigned long next_die_offset;
3211 /* Record the root of the DIE's built for the current compilation unit. */
3212 static dw_die_ref comp_unit_die;
3214 /* A list of DIEs with a NULL parent waiting to be relocated. */
3215 static limbo_die_node *limbo_die_list = 0;
3217 /* Structure used by lookup_filename to manage sets of filenames. */
3218 struct file_table
3220 char **table;
3221 unsigned allocated;
3222 unsigned in_use;
3223 unsigned last_lookup_index;
3226 /* Size (in elements) of increments by which we may expand the filename
3227 table. */
3228 #define FILE_TABLE_INCREMENT 64
3230 /* Filenames referenced by this compilation unit. */
3231 static struct file_table file_table;
3233 /* Local pointer to the name of the main input file. Initialized in
3234 dwarf2out_init. */
3235 static const char *primary_filename;
3237 /* A pointer to the base of a table of references to DIE's that describe
3238 declarations. The table is indexed by DECL_UID() which is a unique
3239 number identifying each decl. */
3240 static dw_die_ref *decl_die_table;
3242 /* Number of elements currently allocated for the decl_die_table. */
3243 static unsigned decl_die_table_allocated;
3245 /* Number of elements in decl_die_table currently in use. */
3246 static unsigned decl_die_table_in_use;
3248 /* Size (in elements) of increments by which we may expand the
3249 decl_die_table. */
3250 #define DECL_DIE_TABLE_INCREMENT 256
3252 /* A pointer to the base of a table of references to declaration
3253 scopes. This table is a display which tracks the nesting
3254 of declaration scopes at the current scope and containing
3255 scopes. This table is used to find the proper place to
3256 define type declaration DIE's. */
3257 static tree *decl_scope_table;
3259 /* Number of elements currently allocated for the decl_scope_table. */
3260 static int decl_scope_table_allocated;
3262 /* Current level of nesting of declaration scopes. */
3263 static int decl_scope_depth;
3265 /* Size (in elements) of increments by which we may expand the
3266 decl_scope_table. */
3267 #define DECL_SCOPE_TABLE_INCREMENT 64
3269 /* A pointer to the base of a list of references to DIE's that
3270 are uniquely identified by their tag, presence/absence of
3271 children DIE's, and list of attribute/value pairs. */
3272 static dw_die_ref *abbrev_die_table;
3274 /* Number of elements currently allocated for abbrev_die_table. */
3275 static unsigned abbrev_die_table_allocated;
3277 /* Number of elements in type_die_table currently in use. */
3278 static unsigned abbrev_die_table_in_use;
3280 /* Size (in elements) of increments by which we may expand the
3281 abbrev_die_table. */
3282 #define ABBREV_DIE_TABLE_INCREMENT 256
3284 /* A pointer to the base of a table that contains line information
3285 for each source code line in .text in the compilation unit. */
3286 static dw_line_info_ref line_info_table;
3288 /* Number of elements currently allocated for line_info_table. */
3289 static unsigned line_info_table_allocated;
3291 /* Number of elements in separate_line_info_table currently in use. */
3292 static unsigned separate_line_info_table_in_use;
3294 /* A pointer to the base of a table that contains line information
3295 for each source code line outside of .text in the compilation unit. */
3296 static dw_separate_line_info_ref separate_line_info_table;
3298 /* Number of elements currently allocated for separate_line_info_table. */
3299 static unsigned separate_line_info_table_allocated;
3301 /* Number of elements in line_info_table currently in use. */
3302 static unsigned line_info_table_in_use;
3304 /* Size (in elements) of increments by which we may expand the
3305 line_info_table. */
3306 #define LINE_INFO_TABLE_INCREMENT 1024
3308 /* A pointer to the base of a table that contains a list of publicly
3309 accessible names. */
3310 static pubname_ref pubname_table;
3312 /* Number of elements currently allocated for pubname_table. */
3313 static unsigned pubname_table_allocated;
3315 /* Number of elements in pubname_table currently in use. */
3316 static unsigned pubname_table_in_use;
3318 /* Size (in elements) of increments by which we may expand the
3319 pubname_table. */
3320 #define PUBNAME_TABLE_INCREMENT 64
3322 /* A pointer to the base of a table that contains a list of publicly
3323 accessible names. */
3324 static arange_ref arange_table;
3326 /* Number of elements currently allocated for arange_table. */
3327 static unsigned arange_table_allocated;
3329 /* Number of elements in arange_table currently in use. */
3330 static unsigned arange_table_in_use;
3332 /* Size (in elements) of increments by which we may expand the
3333 arange_table. */
3334 #define ARANGE_TABLE_INCREMENT 64
3336 /* Whether we have location lists that need outputting */
3337 static unsigned have_location_lists;
3339 /* A pointer to the base of a list of incomplete types which might be
3340 completed at some later time. */
3342 static tree *incomplete_types_list;
3344 /* Number of elements currently allocated for the incomplete_types_list. */
3345 static unsigned incomplete_types_allocated;
3347 /* Number of elements of incomplete_types_list currently in use. */
3348 static unsigned incomplete_types;
3350 /* Size (in elements) of increments by which we may expand the incomplete
3351 types list. Actually, a single hunk of space of this size should
3352 be enough for most typical programs. */
3353 #define INCOMPLETE_TYPES_INCREMENT 64
3355 /* Record whether the function being analyzed contains inlined functions. */
3356 static int current_function_has_inlines;
3357 #if 0 && defined (MIPS_DEBUGGING_INFO)
3358 static int comp_unit_has_inlines;
3359 #endif
3361 /* Array of RTXes referenced by the debugging information, which therefore
3362 must be kept around forever. We do this rather than perform GC on
3363 the dwarf info because almost all of the dwarf info lives forever, and
3364 it's easier to support non-GC frontends this way. */
3365 static varray_type used_rtx_varray;
3367 /* Forward declarations for functions defined in this file. */
3369 static int is_pseudo_reg PARAMS ((rtx));
3370 static tree type_main_variant PARAMS ((tree));
3371 static int is_tagged_type PARAMS ((tree));
3372 static const char *dwarf_tag_name PARAMS ((unsigned));
3373 static const char *dwarf_attr_name PARAMS ((unsigned));
3374 static const char *dwarf_form_name PARAMS ((unsigned));
3375 #if 0
3376 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
3377 #endif
3378 static tree decl_ultimate_origin PARAMS ((tree));
3379 static tree block_ultimate_origin PARAMS ((tree));
3380 static tree decl_class_context PARAMS ((tree));
3381 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
3382 static void add_AT_flag PARAMS ((dw_die_ref,
3383 enum dwarf_attribute,
3384 unsigned));
3385 static void add_AT_int PARAMS ((dw_die_ref,
3386 enum dwarf_attribute, long));
3387 static void add_AT_unsigned PARAMS ((dw_die_ref,
3388 enum dwarf_attribute,
3389 unsigned long));
3390 static void add_AT_long_long PARAMS ((dw_die_ref,
3391 enum dwarf_attribute,
3392 unsigned long,
3393 unsigned long));
3394 static void add_AT_float PARAMS ((dw_die_ref,
3395 enum dwarf_attribute,
3396 unsigned, long *));
3397 static void add_AT_string PARAMS ((dw_die_ref,
3398 enum dwarf_attribute,
3399 const char *));
3400 static void add_AT_die_ref PARAMS ((dw_die_ref,
3401 enum dwarf_attribute,
3402 dw_die_ref));
3403 static void add_AT_fde_ref PARAMS ((dw_die_ref,
3404 enum dwarf_attribute,
3405 unsigned));
3406 static void add_AT_loc PARAMS ((dw_die_ref,
3407 enum dwarf_attribute,
3408 dw_loc_descr_ref));
3409 static void add_AT_loc_list PARAMS ((dw_die_ref,
3410 enum dwarf_attribute,
3411 dw_loc_list_ref));
3412 static void add_AT_addr PARAMS ((dw_die_ref,
3413 enum dwarf_attribute,
3414 rtx));
3415 static void add_AT_lbl_id PARAMS ((dw_die_ref,
3416 enum dwarf_attribute,
3417 const char *));
3418 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
3419 enum dwarf_attribute,
3420 const char *));
3421 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
3422 enum dwarf_attribute));
3423 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
3424 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
3425 static const char *get_AT_string PARAMS ((dw_die_ref,
3426 enum dwarf_attribute));
3427 static int get_AT_flag PARAMS ((dw_die_ref,
3428 enum dwarf_attribute));
3429 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
3430 enum dwarf_attribute));
3431 static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref,
3432 enum dwarf_attribute));
3433 static int is_c_family PARAMS ((void));
3434 static int is_java PARAMS ((void));
3435 static int is_fortran PARAMS ((void));
3436 static void remove_AT PARAMS ((dw_die_ref,
3437 enum dwarf_attribute));
3438 static void remove_children PARAMS ((dw_die_ref));
3439 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
3440 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
3441 static dw_die_ref lookup_type_die PARAMS ((tree));
3442 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
3443 static dw_die_ref lookup_decl_die PARAMS ((tree));
3444 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
3445 static void print_spaces PARAMS ((FILE *));
3446 static void print_die PARAMS ((dw_die_ref, FILE *));
3447 static void print_dwarf_line_table PARAMS ((FILE *));
3448 static void reverse_die_lists PARAMS ((dw_die_ref));
3449 static void reverse_all_dies PARAMS ((dw_die_ref));
3450 static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref));
3451 static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref));
3452 static void loc_checksum PARAMS ((dw_loc_descr_ref, struct md5_ctx *));
3453 static void attr_checksum PARAMS ((dw_attr_ref, struct md5_ctx *));
3454 static void die_checksum PARAMS ((dw_die_ref, struct md5_ctx *));
3455 static void compute_section_prefix PARAMS ((dw_die_ref));
3456 static int is_type_die PARAMS ((dw_die_ref));
3457 static int is_comdat_die PARAMS ((dw_die_ref));
3458 static int is_symbol_die PARAMS ((dw_die_ref));
3459 static void assign_symbol_names PARAMS ((dw_die_ref));
3460 static void break_out_includes PARAMS ((dw_die_ref));
3461 static void add_sibling_attributes PARAMS ((dw_die_ref));
3462 static void build_abbrev_table PARAMS ((dw_die_ref));
3463 static void output_location_lists PARAMS ((dw_die_ref));
3464 static unsigned long size_of_string PARAMS ((const char *));
3465 static int constant_size PARAMS ((long unsigned));
3466 static unsigned long size_of_die PARAMS ((dw_die_ref));
3467 static void calc_die_sizes PARAMS ((dw_die_ref));
3468 static void mark_dies PARAMS ((dw_die_ref));
3469 static void unmark_dies PARAMS ((dw_die_ref));
3470 static unsigned long size_of_pubnames PARAMS ((void));
3471 static unsigned long size_of_aranges PARAMS ((void));
3472 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
3473 static void output_value_format PARAMS ((dw_attr_ref));
3474 static void output_abbrev_section PARAMS ((void));
3475 static void output_die_symbol PARAMS ((dw_die_ref));
3476 static void output_die PARAMS ((dw_die_ref));
3477 static void output_compilation_unit_header PARAMS ((void));
3478 static void output_comp_unit PARAMS ((dw_die_ref));
3479 static const char *dwarf2_name PARAMS ((tree, int));
3480 static void add_pubname PARAMS ((tree, dw_die_ref));
3481 static void output_pubnames PARAMS ((void));
3482 static void add_arange PARAMS ((tree, dw_die_ref));
3483 static void output_aranges PARAMS ((void));
3484 static void output_line_info PARAMS ((void));
3485 static void output_file_names PARAMS ((void));
3486 static dw_die_ref base_type_die PARAMS ((tree));
3487 static tree root_type PARAMS ((tree));
3488 static int is_base_type PARAMS ((tree));
3489 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
3490 static int type_is_enum PARAMS ((tree));
3491 static unsigned int reg_number PARAMS ((rtx));
3492 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
3493 static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT));
3494 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
3495 static int is_based_loc PARAMS ((rtx));
3496 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
3497 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
3498 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
3499 static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int));
3500 static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int));
3501 static tree field_type PARAMS ((tree));
3502 static unsigned int simple_type_align_in_bits PARAMS ((tree));
3503 static unsigned int simple_decl_align_in_bits PARAMS ((tree));
3504 static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree));
3505 static HOST_WIDE_INT field_byte_offset PARAMS ((tree));
3506 static void add_AT_location_description PARAMS ((dw_die_ref,
3507 enum dwarf_attribute, rtx));
3508 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
3509 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
3510 static rtx rtl_for_decl_location PARAMS ((tree));
3511 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
3512 static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree));
3513 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
3514 static void add_bound_info PARAMS ((dw_die_ref,
3515 enum dwarf_attribute, tree));
3516 static void add_subscript_info PARAMS ((dw_die_ref, tree));
3517 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
3518 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
3519 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
3520 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
3521 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
3522 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
3523 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
3524 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
3525 static void push_decl_scope PARAMS ((tree));
3526 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
3527 static void pop_decl_scope PARAMS ((void));
3528 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
3529 dw_die_ref));
3530 static const char *type_tag PARAMS ((tree));
3531 static tree member_declared_type PARAMS ((tree));
3532 #if 0
3533 static const char *decl_start_label PARAMS ((tree));
3534 #endif
3535 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
3536 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
3537 #if 0
3538 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
3539 #endif
3540 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
3541 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
3542 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
3543 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
3544 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
3545 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
3546 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
3547 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
3548 static void gen_variable_die PARAMS ((tree, dw_die_ref));
3549 static void gen_label_die PARAMS ((tree, dw_die_ref));
3550 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
3551 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
3552 static void gen_field_die PARAMS ((tree, dw_die_ref));
3553 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
3554 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
3555 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
3556 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
3557 static void gen_member_die PARAMS ((tree, dw_die_ref));
3558 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
3559 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
3560 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
3561 static void gen_type_die PARAMS ((tree, dw_die_ref));
3562 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
3563 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
3564 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
3565 static int is_redundant_typedef PARAMS ((tree));
3566 static void gen_decl_die PARAMS ((tree, dw_die_ref));
3567 static unsigned lookup_filename PARAMS ((const char *));
3568 static void init_file_table PARAMS ((void));
3569 static void add_incomplete_type PARAMS ((tree));
3570 static void retry_incomplete_types PARAMS ((void));
3571 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
3572 static rtx save_rtx PARAMS ((rtx));
3573 static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref));
3574 static int file_info_cmp PARAMS ((const void *, const void *));
3575 static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref,
3576 const char *, const char *,
3577 const char *, unsigned));
3578 static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *,
3579 dw_loc_descr_ref,
3580 const char *, const char *, const char *));
3581 static void output_loc_list PARAMS ((dw_loc_list_ref));
3582 static char *gen_internal_sym PARAMS ((const char *));
3584 /* Section names used to hold DWARF debugging information. */
3585 #ifndef DEBUG_INFO_SECTION
3586 #define DEBUG_INFO_SECTION ".debug_info"
3587 #endif
3588 #ifndef DEBUG_ABBREV_SECTION
3589 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3590 #endif
3591 #ifndef DEBUG_ARANGES_SECTION
3592 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3593 #endif
3594 #ifndef DEBUG_MACINFO_SECTION
3595 #define DEBUG_MACINFO_SECTION ".debug_macinfo"
3596 #endif
3597 #ifndef DEBUG_LINE_SECTION
3598 #define DEBUG_LINE_SECTION ".debug_line"
3599 #endif
3600 #ifndef DEBUG_LOC_SECTION
3601 #define DEBUG_LOC_SECTION ".debug_loc"
3602 #endif
3603 #ifndef DEBUG_PUBNAMES_SECTION
3604 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3605 #endif
3606 #ifndef DEBUG_STR_SECTION
3607 #define DEBUG_STR_SECTION ".debug_str"
3608 #endif
3610 /* Standard ELF section names for compiled code and data. */
3611 #ifndef TEXT_SECTION
3612 #define TEXT_SECTION ".text"
3613 #endif
3614 #ifndef DATA_SECTION
3615 #define DATA_SECTION ".data"
3616 #endif
3617 #ifndef BSS_SECTION
3618 #define BSS_SECTION ".bss"
3619 #endif
3621 /* Labels we insert at beginning sections we can reference instead of
3622 the section names themselves. */
3624 #ifndef TEXT_SECTION_LABEL
3625 #define TEXT_SECTION_LABEL "Ltext"
3626 #endif
3627 #ifndef DEBUG_LINE_SECTION_LABEL
3628 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3629 #endif
3630 #ifndef DEBUG_INFO_SECTION_LABEL
3631 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3632 #endif
3633 #ifndef DEBUG_ABBREV_SECTION_LABEL
3634 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3635 #endif
3636 #ifndef DEBUG_LOC_SECTION_LABEL
3637 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3638 #endif
3639 #ifndef DEBUG_MACINFO_SECTION_LABEL
3640 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3641 #endif
3642 /* Definitions of defaults for formats and names of various special
3643 (artificial) labels which may be generated within this file (when the -g
3644 options is used and DWARF_DEBUGGING_INFO is in effect.
3645 If necessary, these may be overridden from within the tm.h file, but
3646 typically, overriding these defaults is unnecessary. */
3648 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
3649 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3650 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3651 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3652 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3653 static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3654 static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
3655 #ifndef TEXT_END_LABEL
3656 #define TEXT_END_LABEL "Letext"
3657 #endif
3658 #ifndef DATA_END_LABEL
3659 #define DATA_END_LABEL "Ledata"
3660 #endif
3661 #ifndef BSS_END_LABEL
3662 #define BSS_END_LABEL "Lebss"
3663 #endif
3664 #ifndef BLOCK_BEGIN_LABEL
3665 #define BLOCK_BEGIN_LABEL "LBB"
3666 #endif
3667 #ifndef BLOCK_END_LABEL
3668 #define BLOCK_END_LABEL "LBE"
3669 #endif
3670 #ifndef BODY_BEGIN_LABEL
3671 #define BODY_BEGIN_LABEL "Lbb"
3672 #endif
3673 #ifndef BODY_END_LABEL
3674 #define BODY_END_LABEL "Lbe"
3675 #endif
3676 #ifndef LINE_CODE_LABEL
3677 #define LINE_CODE_LABEL "LM"
3678 #endif
3679 #ifndef SEPARATE_LINE_CODE_LABEL
3680 #define SEPARATE_LINE_CODE_LABEL "LSM"
3681 #endif
3683 /* We allow a language front-end to designate a function that is to be
3684 called to "demangle" any name before it it put into a DIE. */
3686 static const char *(*demangle_name_func) PARAMS ((const char *));
3688 void
3689 dwarf2out_set_demangle_name_func (func)
3690 const char *(*func) PARAMS ((const char *));
3692 demangle_name_func = func;
3695 /* Return an rtx like ORIG which lives forever. If we're doing GC,
3696 that means adding it to used_rtx_varray. If not, that means making
3697 a copy on the permanent_obstack. */
3699 static rtx
3700 save_rtx (orig)
3701 register rtx orig;
3703 VARRAY_PUSH_RTX (used_rtx_varray, orig);
3705 return orig;
3708 /* Test if rtl node points to a pseudo register. */
3710 static inline int
3711 is_pseudo_reg (rtl)
3712 register rtx rtl;
3714 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER)
3715 || (GET_CODE (rtl) == SUBREG
3716 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER));
3719 /* Return a reference to a type, with its const and volatile qualifiers
3720 removed. */
3722 static inline tree
3723 type_main_variant (type)
3724 register tree type;
3726 type = TYPE_MAIN_VARIANT (type);
3728 /* There really should be only one main variant among any group of variants
3729 of a given type (and all of the MAIN_VARIANT values for all members of
3730 the group should point to that one type) but sometimes the C front-end
3731 messes this up for array types, so we work around that bug here. */
3733 if (TREE_CODE (type) == ARRAY_TYPE)
3734 while (type != TYPE_MAIN_VARIANT (type))
3735 type = TYPE_MAIN_VARIANT (type);
3737 return type;
3740 /* Return non-zero if the given type node represents a tagged type. */
3742 static inline int
3743 is_tagged_type (type)
3744 register tree type;
3746 register enum tree_code code = TREE_CODE (type);
3748 return (code == RECORD_TYPE || code == UNION_TYPE
3749 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
3752 /* Convert a DIE tag into its string name. */
3754 static const char *
3755 dwarf_tag_name (tag)
3756 register unsigned tag;
3758 switch (tag)
3760 case DW_TAG_padding:
3761 return "DW_TAG_padding";
3762 case DW_TAG_array_type:
3763 return "DW_TAG_array_type";
3764 case DW_TAG_class_type:
3765 return "DW_TAG_class_type";
3766 case DW_TAG_entry_point:
3767 return "DW_TAG_entry_point";
3768 case DW_TAG_enumeration_type:
3769 return "DW_TAG_enumeration_type";
3770 case DW_TAG_formal_parameter:
3771 return "DW_TAG_formal_parameter";
3772 case DW_TAG_imported_declaration:
3773 return "DW_TAG_imported_declaration";
3774 case DW_TAG_label:
3775 return "DW_TAG_label";
3776 case DW_TAG_lexical_block:
3777 return "DW_TAG_lexical_block";
3778 case DW_TAG_member:
3779 return "DW_TAG_member";
3780 case DW_TAG_pointer_type:
3781 return "DW_TAG_pointer_type";
3782 case DW_TAG_reference_type:
3783 return "DW_TAG_reference_type";
3784 case DW_TAG_compile_unit:
3785 return "DW_TAG_compile_unit";
3786 case DW_TAG_string_type:
3787 return "DW_TAG_string_type";
3788 case DW_TAG_structure_type:
3789 return "DW_TAG_structure_type";
3790 case DW_TAG_subroutine_type:
3791 return "DW_TAG_subroutine_type";
3792 case DW_TAG_typedef:
3793 return "DW_TAG_typedef";
3794 case DW_TAG_union_type:
3795 return "DW_TAG_union_type";
3796 case DW_TAG_unspecified_parameters:
3797 return "DW_TAG_unspecified_parameters";
3798 case DW_TAG_variant:
3799 return "DW_TAG_variant";
3800 case DW_TAG_common_block:
3801 return "DW_TAG_common_block";
3802 case DW_TAG_common_inclusion:
3803 return "DW_TAG_common_inclusion";
3804 case DW_TAG_inheritance:
3805 return "DW_TAG_inheritance";
3806 case DW_TAG_inlined_subroutine:
3807 return "DW_TAG_inlined_subroutine";
3808 case DW_TAG_module:
3809 return "DW_TAG_module";
3810 case DW_TAG_ptr_to_member_type:
3811 return "DW_TAG_ptr_to_member_type";
3812 case DW_TAG_set_type:
3813 return "DW_TAG_set_type";
3814 case DW_TAG_subrange_type:
3815 return "DW_TAG_subrange_type";
3816 case DW_TAG_with_stmt:
3817 return "DW_TAG_with_stmt";
3818 case DW_TAG_access_declaration:
3819 return "DW_TAG_access_declaration";
3820 case DW_TAG_base_type:
3821 return "DW_TAG_base_type";
3822 case DW_TAG_catch_block:
3823 return "DW_TAG_catch_block";
3824 case DW_TAG_const_type:
3825 return "DW_TAG_const_type";
3826 case DW_TAG_constant:
3827 return "DW_TAG_constant";
3828 case DW_TAG_enumerator:
3829 return "DW_TAG_enumerator";
3830 case DW_TAG_file_type:
3831 return "DW_TAG_file_type";
3832 case DW_TAG_friend:
3833 return "DW_TAG_friend";
3834 case DW_TAG_namelist:
3835 return "DW_TAG_namelist";
3836 case DW_TAG_namelist_item:
3837 return "DW_TAG_namelist_item";
3838 case DW_TAG_packed_type:
3839 return "DW_TAG_packed_type";
3840 case DW_TAG_subprogram:
3841 return "DW_TAG_subprogram";
3842 case DW_TAG_template_type_param:
3843 return "DW_TAG_template_type_param";
3844 case DW_TAG_template_value_param:
3845 return "DW_TAG_template_value_param";
3846 case DW_TAG_thrown_type:
3847 return "DW_TAG_thrown_type";
3848 case DW_TAG_try_block:
3849 return "DW_TAG_try_block";
3850 case DW_TAG_variant_part:
3851 return "DW_TAG_variant_part";
3852 case DW_TAG_variable:
3853 return "DW_TAG_variable";
3854 case DW_TAG_volatile_type:
3855 return "DW_TAG_volatile_type";
3856 case DW_TAG_MIPS_loop:
3857 return "DW_TAG_MIPS_loop";
3858 case DW_TAG_format_label:
3859 return "DW_TAG_format_label";
3860 case DW_TAG_function_template:
3861 return "DW_TAG_function_template";
3862 case DW_TAG_class_template:
3863 return "DW_TAG_class_template";
3864 case DW_TAG_GNU_BINCL:
3865 return "DW_TAG_GNU_BINCL";
3866 case DW_TAG_GNU_EINCL:
3867 return "DW_TAG_GNU_EINCL";
3868 default:
3869 return "DW_TAG_<unknown>";
3873 /* Convert a DWARF attribute code into its string name. */
3875 static const char *
3876 dwarf_attr_name (attr)
3877 register unsigned attr;
3879 switch (attr)
3881 case DW_AT_sibling:
3882 return "DW_AT_sibling";
3883 case DW_AT_location:
3884 return "DW_AT_location";
3885 case DW_AT_name:
3886 return "DW_AT_name";
3887 case DW_AT_ordering:
3888 return "DW_AT_ordering";
3889 case DW_AT_subscr_data:
3890 return "DW_AT_subscr_data";
3891 case DW_AT_byte_size:
3892 return "DW_AT_byte_size";
3893 case DW_AT_bit_offset:
3894 return "DW_AT_bit_offset";
3895 case DW_AT_bit_size:
3896 return "DW_AT_bit_size";
3897 case DW_AT_element_list:
3898 return "DW_AT_element_list";
3899 case DW_AT_stmt_list:
3900 return "DW_AT_stmt_list";
3901 case DW_AT_low_pc:
3902 return "DW_AT_low_pc";
3903 case DW_AT_high_pc:
3904 return "DW_AT_high_pc";
3905 case DW_AT_language:
3906 return "DW_AT_language";
3907 case DW_AT_member:
3908 return "DW_AT_member";
3909 case DW_AT_discr:
3910 return "DW_AT_discr";
3911 case DW_AT_discr_value:
3912 return "DW_AT_discr_value";
3913 case DW_AT_visibility:
3914 return "DW_AT_visibility";
3915 case DW_AT_import:
3916 return "DW_AT_import";
3917 case DW_AT_string_length:
3918 return "DW_AT_string_length";
3919 case DW_AT_common_reference:
3920 return "DW_AT_common_reference";
3921 case DW_AT_comp_dir:
3922 return "DW_AT_comp_dir";
3923 case DW_AT_const_value:
3924 return "DW_AT_const_value";
3925 case DW_AT_containing_type:
3926 return "DW_AT_containing_type";
3927 case DW_AT_default_value:
3928 return "DW_AT_default_value";
3929 case DW_AT_inline:
3930 return "DW_AT_inline";
3931 case DW_AT_is_optional:
3932 return "DW_AT_is_optional";
3933 case DW_AT_lower_bound:
3934 return "DW_AT_lower_bound";
3935 case DW_AT_producer:
3936 return "DW_AT_producer";
3937 case DW_AT_prototyped:
3938 return "DW_AT_prototyped";
3939 case DW_AT_return_addr:
3940 return "DW_AT_return_addr";
3941 case DW_AT_start_scope:
3942 return "DW_AT_start_scope";
3943 case DW_AT_stride_size:
3944 return "DW_AT_stride_size";
3945 case DW_AT_upper_bound:
3946 return "DW_AT_upper_bound";
3947 case DW_AT_abstract_origin:
3948 return "DW_AT_abstract_origin";
3949 case DW_AT_accessibility:
3950 return "DW_AT_accessibility";
3951 case DW_AT_address_class:
3952 return "DW_AT_address_class";
3953 case DW_AT_artificial:
3954 return "DW_AT_artificial";
3955 case DW_AT_base_types:
3956 return "DW_AT_base_types";
3957 case DW_AT_calling_convention:
3958 return "DW_AT_calling_convention";
3959 case DW_AT_count:
3960 return "DW_AT_count";
3961 case DW_AT_data_member_location:
3962 return "DW_AT_data_member_location";
3963 case DW_AT_decl_column:
3964 return "DW_AT_decl_column";
3965 case DW_AT_decl_file:
3966 return "DW_AT_decl_file";
3967 case DW_AT_decl_line:
3968 return "DW_AT_decl_line";
3969 case DW_AT_declaration:
3970 return "DW_AT_declaration";
3971 case DW_AT_discr_list:
3972 return "DW_AT_discr_list";
3973 case DW_AT_encoding:
3974 return "DW_AT_encoding";
3975 case DW_AT_external:
3976 return "DW_AT_external";
3977 case DW_AT_frame_base:
3978 return "DW_AT_frame_base";
3979 case DW_AT_friend:
3980 return "DW_AT_friend";
3981 case DW_AT_identifier_case:
3982 return "DW_AT_identifier_case";
3983 case DW_AT_macro_info:
3984 return "DW_AT_macro_info";
3985 case DW_AT_namelist_items:
3986 return "DW_AT_namelist_items";
3987 case DW_AT_priority:
3988 return "DW_AT_priority";
3989 case DW_AT_segment:
3990 return "DW_AT_segment";
3991 case DW_AT_specification:
3992 return "DW_AT_specification";
3993 case DW_AT_static_link:
3994 return "DW_AT_static_link";
3995 case DW_AT_type:
3996 return "DW_AT_type";
3997 case DW_AT_use_location:
3998 return "DW_AT_use_location";
3999 case DW_AT_variable_parameter:
4000 return "DW_AT_variable_parameter";
4001 case DW_AT_virtuality:
4002 return "DW_AT_virtuality";
4003 case DW_AT_vtable_elem_location:
4004 return "DW_AT_vtable_elem_location";
4006 case DW_AT_MIPS_fde:
4007 return "DW_AT_MIPS_fde";
4008 case DW_AT_MIPS_loop_begin:
4009 return "DW_AT_MIPS_loop_begin";
4010 case DW_AT_MIPS_tail_loop_begin:
4011 return "DW_AT_MIPS_tail_loop_begin";
4012 case DW_AT_MIPS_epilog_begin:
4013 return "DW_AT_MIPS_epilog_begin";
4014 case DW_AT_MIPS_loop_unroll_factor:
4015 return "DW_AT_MIPS_loop_unroll_factor";
4016 case DW_AT_MIPS_software_pipeline_depth:
4017 return "DW_AT_MIPS_software_pipeline_depth";
4018 case DW_AT_MIPS_linkage_name:
4019 return "DW_AT_MIPS_linkage_name";
4020 case DW_AT_MIPS_stride:
4021 return "DW_AT_MIPS_stride";
4022 case DW_AT_MIPS_abstract_name:
4023 return "DW_AT_MIPS_abstract_name";
4024 case DW_AT_MIPS_clone_origin:
4025 return "DW_AT_MIPS_clone_origin";
4026 case DW_AT_MIPS_has_inlines:
4027 return "DW_AT_MIPS_has_inlines";
4029 case DW_AT_sf_names:
4030 return "DW_AT_sf_names";
4031 case DW_AT_src_info:
4032 return "DW_AT_src_info";
4033 case DW_AT_mac_info:
4034 return "DW_AT_mac_info";
4035 case DW_AT_src_coords:
4036 return "DW_AT_src_coords";
4037 case DW_AT_body_begin:
4038 return "DW_AT_body_begin";
4039 case DW_AT_body_end:
4040 return "DW_AT_body_end";
4041 default:
4042 return "DW_AT_<unknown>";
4046 /* Convert a DWARF value form code into its string name. */
4048 static const char *
4049 dwarf_form_name (form)
4050 register unsigned form;
4052 switch (form)
4054 case DW_FORM_addr:
4055 return "DW_FORM_addr";
4056 case DW_FORM_block2:
4057 return "DW_FORM_block2";
4058 case DW_FORM_block4:
4059 return "DW_FORM_block4";
4060 case DW_FORM_data2:
4061 return "DW_FORM_data2";
4062 case DW_FORM_data4:
4063 return "DW_FORM_data4";
4064 case DW_FORM_data8:
4065 return "DW_FORM_data8";
4066 case DW_FORM_string:
4067 return "DW_FORM_string";
4068 case DW_FORM_block:
4069 return "DW_FORM_block";
4070 case DW_FORM_block1:
4071 return "DW_FORM_block1";
4072 case DW_FORM_data1:
4073 return "DW_FORM_data1";
4074 case DW_FORM_flag:
4075 return "DW_FORM_flag";
4076 case DW_FORM_sdata:
4077 return "DW_FORM_sdata";
4078 case DW_FORM_strp:
4079 return "DW_FORM_strp";
4080 case DW_FORM_udata:
4081 return "DW_FORM_udata";
4082 case DW_FORM_ref_addr:
4083 return "DW_FORM_ref_addr";
4084 case DW_FORM_ref1:
4085 return "DW_FORM_ref1";
4086 case DW_FORM_ref2:
4087 return "DW_FORM_ref2";
4088 case DW_FORM_ref4:
4089 return "DW_FORM_ref4";
4090 case DW_FORM_ref8:
4091 return "DW_FORM_ref8";
4092 case DW_FORM_ref_udata:
4093 return "DW_FORM_ref_udata";
4094 case DW_FORM_indirect:
4095 return "DW_FORM_indirect";
4096 default:
4097 return "DW_FORM_<unknown>";
4101 /* Convert a DWARF type code into its string name. */
4103 #if 0
4104 static const char *
4105 dwarf_type_encoding_name (enc)
4106 register unsigned enc;
4108 switch (enc)
4110 case DW_ATE_address:
4111 return "DW_ATE_address";
4112 case DW_ATE_boolean:
4113 return "DW_ATE_boolean";
4114 case DW_ATE_complex_float:
4115 return "DW_ATE_complex_float";
4116 case DW_ATE_float:
4117 return "DW_ATE_float";
4118 case DW_ATE_signed:
4119 return "DW_ATE_signed";
4120 case DW_ATE_signed_char:
4121 return "DW_ATE_signed_char";
4122 case DW_ATE_unsigned:
4123 return "DW_ATE_unsigned";
4124 case DW_ATE_unsigned_char:
4125 return "DW_ATE_unsigned_char";
4126 default:
4127 return "DW_ATE_<unknown>";
4130 #endif
4132 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
4133 instance of an inlined instance of a decl which is local to an inline
4134 function, so we have to trace all of the way back through the origin chain
4135 to find out what sort of node actually served as the original seed for the
4136 given block. */
4138 static tree
4139 decl_ultimate_origin (decl)
4140 register tree decl;
4142 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
4143 nodes in the function to point to themselves; ignore that if
4144 we're trying to output the abstract instance of this function. */
4145 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
4146 return NULL_TREE;
4148 #ifdef ENABLE_CHECKING
4149 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
4150 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
4151 most distant ancestor, this should never happen. */
4152 abort ();
4153 #endif
4155 return DECL_ABSTRACT_ORIGIN (decl);
4158 /* Determine the "ultimate origin" of a block. The block may be an inlined
4159 instance of an inlined instance of a block which is local to an inline
4160 function, so we have to trace all of the way back through the origin chain
4161 to find out what sort of node actually served as the original seed for the
4162 given block. */
4164 static tree
4165 block_ultimate_origin (block)
4166 register tree block;
4168 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
4170 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
4171 nodes in the function to point to themselves; ignore that if
4172 we're trying to output the abstract instance of this function. */
4173 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
4174 return NULL_TREE;
4176 if (immediate_origin == NULL_TREE)
4177 return NULL_TREE;
4178 else
4180 register tree ret_val;
4181 register tree lookahead = immediate_origin;
4185 ret_val = lookahead;
4186 lookahead = (TREE_CODE (ret_val) == BLOCK)
4187 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
4188 : NULL;
4190 while (lookahead != NULL && lookahead != ret_val);
4192 return ret_val;
4196 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
4197 of a virtual function may refer to a base class, so we check the 'this'
4198 parameter. */
4200 static tree
4201 decl_class_context (decl)
4202 tree decl;
4204 tree context = NULL_TREE;
4206 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
4207 context = DECL_CONTEXT (decl);
4208 else
4209 context = TYPE_MAIN_VARIANT
4210 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
4212 if (context && !TYPE_P (context))
4213 context = NULL_TREE;
4215 return context;
4218 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
4219 addition order, and correct that in reverse_all_dies. */
4221 static inline void
4222 add_dwarf_attr (die, attr)
4223 register dw_die_ref die;
4224 register dw_attr_ref attr;
4226 if (die != NULL && attr != NULL)
4228 attr->dw_attr_next = die->die_attr;
4229 die->die_attr = attr;
4233 static inline dw_val_class AT_class PARAMS ((dw_attr_ref));
4234 static inline dw_val_class
4235 AT_class (a)
4236 dw_attr_ref a;
4238 return a->dw_attr_val.val_class;
4241 /* Add a flag value attribute to a DIE. */
4243 static inline void
4244 add_AT_flag (die, attr_kind, flag)
4245 register dw_die_ref die;
4246 register enum dwarf_attribute attr_kind;
4247 register unsigned flag;
4249 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4251 attr->dw_attr_next = NULL;
4252 attr->dw_attr = attr_kind;
4253 attr->dw_attr_val.val_class = dw_val_class_flag;
4254 attr->dw_attr_val.v.val_flag = flag;
4255 add_dwarf_attr (die, attr);
4258 static inline unsigned AT_flag PARAMS ((dw_attr_ref));
4259 static inline unsigned
4260 AT_flag (a)
4261 register dw_attr_ref a;
4263 if (a && AT_class (a) == dw_val_class_flag)
4264 return a->dw_attr_val.v.val_flag;
4266 abort ();
4269 /* Add a signed integer attribute value to a DIE. */
4271 static inline void
4272 add_AT_int (die, attr_kind, int_val)
4273 register dw_die_ref die;
4274 register enum dwarf_attribute attr_kind;
4275 register long int int_val;
4277 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4279 attr->dw_attr_next = NULL;
4280 attr->dw_attr = attr_kind;
4281 attr->dw_attr_val.val_class = dw_val_class_const;
4282 attr->dw_attr_val.v.val_int = int_val;
4283 add_dwarf_attr (die, attr);
4286 static inline long int AT_int PARAMS ((dw_attr_ref));
4287 static inline long int
4288 AT_int (a)
4289 register dw_attr_ref a;
4291 if (a && AT_class (a) == dw_val_class_const)
4292 return a->dw_attr_val.v.val_int;
4294 abort ();
4297 /* Add an unsigned integer attribute value to a DIE. */
4299 static inline void
4300 add_AT_unsigned (die, attr_kind, unsigned_val)
4301 register dw_die_ref die;
4302 register enum dwarf_attribute attr_kind;
4303 register unsigned long unsigned_val;
4305 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4307 attr->dw_attr_next = NULL;
4308 attr->dw_attr = attr_kind;
4309 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
4310 attr->dw_attr_val.v.val_unsigned = unsigned_val;
4311 add_dwarf_attr (die, attr);
4314 static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref));
4315 static inline unsigned long
4316 AT_unsigned (a)
4317 register dw_attr_ref a;
4319 if (a && AT_class (a) == dw_val_class_unsigned_const)
4320 return a->dw_attr_val.v.val_unsigned;
4322 abort ();
4325 /* Add an unsigned double integer attribute value to a DIE. */
4327 static inline void
4328 add_AT_long_long (die, attr_kind, val_hi, val_low)
4329 register dw_die_ref die;
4330 register enum dwarf_attribute attr_kind;
4331 register unsigned long val_hi;
4332 register unsigned long val_low;
4334 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4336 attr->dw_attr_next = NULL;
4337 attr->dw_attr = attr_kind;
4338 attr->dw_attr_val.val_class = dw_val_class_long_long;
4339 attr->dw_attr_val.v.val_long_long.hi = val_hi;
4340 attr->dw_attr_val.v.val_long_long.low = val_low;
4341 add_dwarf_attr (die, attr);
4344 /* Add a floating point attribute value to a DIE and return it. */
4346 static inline void
4347 add_AT_float (die, attr_kind, length, array)
4348 register dw_die_ref die;
4349 register enum dwarf_attribute attr_kind;
4350 register unsigned length;
4351 register long *array;
4353 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4355 attr->dw_attr_next = NULL;
4356 attr->dw_attr = attr_kind;
4357 attr->dw_attr_val.val_class = dw_val_class_float;
4358 attr->dw_attr_val.v.val_float.length = length;
4359 attr->dw_attr_val.v.val_float.array = array;
4360 add_dwarf_attr (die, attr);
4363 /* Add a string attribute value to a DIE. */
4365 static inline void
4366 add_AT_string (die, attr_kind, str)
4367 register dw_die_ref die;
4368 register enum dwarf_attribute attr_kind;
4369 register const char *str;
4371 register 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_str;
4376 attr->dw_attr_val.v.val_str = xstrdup (str);
4377 add_dwarf_attr (die, attr);
4380 static inline const char *AT_string PARAMS ((dw_attr_ref));
4381 static inline const char *
4382 AT_string (a)
4383 register dw_attr_ref a;
4385 if (a && AT_class (a) == dw_val_class_str)
4386 return a->dw_attr_val.v.val_str;
4388 abort ();
4391 /* Add a DIE reference attribute value to a DIE. */
4393 static inline void
4394 add_AT_die_ref (die, attr_kind, targ_die)
4395 register dw_die_ref die;
4396 register enum dwarf_attribute attr_kind;
4397 register dw_die_ref targ_die;
4399 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4401 attr->dw_attr_next = NULL;
4402 attr->dw_attr = attr_kind;
4403 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4404 attr->dw_attr_val.v.val_die_ref.die = targ_die;
4405 attr->dw_attr_val.v.val_die_ref.external = 0;
4406 add_dwarf_attr (die, attr);
4409 static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref));
4410 static inline dw_die_ref
4411 AT_ref (a)
4412 register dw_attr_ref a;
4414 if (a && AT_class (a) == dw_val_class_die_ref)
4415 return a->dw_attr_val.v.val_die_ref.die;
4417 abort ();
4420 static inline int AT_ref_external PARAMS ((dw_attr_ref));
4421 static inline int
4422 AT_ref_external (a)
4423 register dw_attr_ref a;
4425 if (a && AT_class (a) == dw_val_class_die_ref)
4426 return a->dw_attr_val.v.val_die_ref.external;
4428 return 0;
4431 static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int));
4432 static inline void
4433 set_AT_ref_external (a, i)
4434 register dw_attr_ref a;
4435 int i;
4437 if (a && AT_class (a) == dw_val_class_die_ref)
4438 a->dw_attr_val.v.val_die_ref.external = i;
4439 else
4440 abort ();
4443 /* Add an FDE reference attribute value to a DIE. */
4445 static inline void
4446 add_AT_fde_ref (die, attr_kind, targ_fde)
4447 register dw_die_ref die;
4448 register enum dwarf_attribute attr_kind;
4449 register unsigned targ_fde;
4451 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4453 attr->dw_attr_next = NULL;
4454 attr->dw_attr = attr_kind;
4455 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
4456 attr->dw_attr_val.v.val_fde_index = targ_fde;
4457 add_dwarf_attr (die, attr);
4460 /* Add a location description attribute value to a DIE. */
4462 static inline void
4463 add_AT_loc (die, attr_kind, loc)
4464 register dw_die_ref die;
4465 register enum dwarf_attribute attr_kind;
4466 register dw_loc_descr_ref loc;
4468 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4470 attr->dw_attr_next = NULL;
4471 attr->dw_attr = attr_kind;
4472 attr->dw_attr_val.val_class = dw_val_class_loc;
4473 attr->dw_attr_val.v.val_loc = loc;
4474 add_dwarf_attr (die, attr);
4477 static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref));
4478 static inline dw_loc_descr_ref
4479 AT_loc (a)
4480 register dw_attr_ref a;
4482 if (a && AT_class (a) == dw_val_class_loc)
4483 return a->dw_attr_val.v.val_loc;
4485 abort ();
4488 static inline void
4489 add_AT_loc_list (die, attr_kind, loc_list)
4490 register dw_die_ref die;
4491 register enum dwarf_attribute attr_kind;
4492 register dw_loc_list_ref loc_list;
4494 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4496 attr->dw_attr_next = NULL;
4497 attr->dw_attr = attr_kind;
4498 attr->dw_attr_val.val_class = dw_val_class_loc_list;
4499 attr->dw_attr_val.v.val_loc_list = loc_list;
4500 add_dwarf_attr (die, attr);
4501 have_location_lists = 1;
4504 static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref));
4506 static inline dw_loc_list_ref
4507 AT_loc_list (a)
4508 register dw_attr_ref a;
4510 if (a && AT_class (a) == dw_val_class_loc_list)
4511 return a->dw_attr_val.v.val_loc_list;
4513 abort ();
4516 /* Add an address constant attribute value to a DIE. */
4518 static inline void
4519 add_AT_addr (die, attr_kind, addr)
4520 register dw_die_ref die;
4521 register enum dwarf_attribute attr_kind;
4522 rtx addr;
4524 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4526 attr->dw_attr_next = NULL;
4527 attr->dw_attr = attr_kind;
4528 attr->dw_attr_val.val_class = dw_val_class_addr;
4529 attr->dw_attr_val.v.val_addr = addr;
4530 add_dwarf_attr (die, attr);
4533 static inline rtx AT_addr PARAMS ((dw_attr_ref));
4534 static inline rtx
4535 AT_addr (a)
4536 register dw_attr_ref a;
4538 if (a && AT_class (a) == dw_val_class_addr)
4539 return a->dw_attr_val.v.val_addr;
4541 abort ();
4544 /* Add a label identifier attribute value to a DIE. */
4546 static inline void
4547 add_AT_lbl_id (die, attr_kind, lbl_id)
4548 register dw_die_ref die;
4549 register enum dwarf_attribute attr_kind;
4550 register const char *lbl_id;
4552 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4554 attr->dw_attr_next = NULL;
4555 attr->dw_attr = attr_kind;
4556 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
4557 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
4558 add_dwarf_attr (die, attr);
4561 /* Add a section offset attribute value to a DIE. */
4563 static inline void
4564 add_AT_lbl_offset (die, attr_kind, label)
4565 register dw_die_ref die;
4566 register enum dwarf_attribute attr_kind;
4567 register const char *label;
4569 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4571 attr->dw_attr_next = NULL;
4572 attr->dw_attr = attr_kind;
4573 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
4574 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
4575 add_dwarf_attr (die, attr);
4578 static inline const char *AT_lbl PARAMS ((dw_attr_ref));
4579 static inline const char *
4580 AT_lbl (a)
4581 register dw_attr_ref a;
4583 if (a && (AT_class (a) == dw_val_class_lbl_id
4584 || AT_class (a) == dw_val_class_lbl_offset))
4585 return a->dw_attr_val.v.val_lbl_id;
4587 abort ();
4590 /* Get the attribute of type attr_kind. */
4592 static inline dw_attr_ref
4593 get_AT (die, attr_kind)
4594 register dw_die_ref die;
4595 register enum dwarf_attribute attr_kind;
4597 register dw_attr_ref a;
4598 register dw_die_ref spec = NULL;
4600 if (die != NULL)
4602 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4604 if (a->dw_attr == attr_kind)
4605 return a;
4607 if (a->dw_attr == DW_AT_specification
4608 || a->dw_attr == DW_AT_abstract_origin)
4609 spec = AT_ref (a);
4612 if (spec)
4613 return get_AT (spec, attr_kind);
4616 return NULL;
4619 /* Return the "low pc" attribute value, typically associated with
4620 a subprogram DIE. Return null if the "low pc" attribute is
4621 either not prsent, or if it cannot be represented as an
4622 assembler label identifier. */
4624 static inline const char *
4625 get_AT_low_pc (die)
4626 register dw_die_ref die;
4628 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
4629 return a ? AT_lbl (a) : NULL;
4632 /* Return the "high pc" attribute value, typically associated with
4633 a subprogram DIE. Return null if the "high pc" attribute is
4634 either not prsent, or if it cannot be represented as an
4635 assembler label identifier. */
4637 static inline const char *
4638 get_AT_hi_pc (die)
4639 register dw_die_ref die;
4641 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
4642 return a ? AT_lbl (a) : NULL;
4645 /* Return the value of the string attribute designated by ATTR_KIND, or
4646 NULL if it is not present. */
4648 static inline const char *
4649 get_AT_string (die, attr_kind)
4650 register dw_die_ref die;
4651 register enum dwarf_attribute attr_kind;
4653 register dw_attr_ref a = get_AT (die, attr_kind);
4654 return a ? AT_string (a) : NULL;
4657 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4658 if it is not present. */
4660 static inline int
4661 get_AT_flag (die, attr_kind)
4662 register dw_die_ref die;
4663 register enum dwarf_attribute attr_kind;
4665 register dw_attr_ref a = get_AT (die, attr_kind);
4666 return a ? AT_flag (a) : 0;
4669 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4670 if it is not present. */
4672 static inline unsigned
4673 get_AT_unsigned (die, attr_kind)
4674 register dw_die_ref die;
4675 register enum dwarf_attribute attr_kind;
4677 register dw_attr_ref a = get_AT (die, attr_kind);
4678 return a ? AT_unsigned (a) : 0;
4681 static inline dw_die_ref
4682 get_AT_ref (die, attr_kind)
4683 dw_die_ref die;
4684 register enum dwarf_attribute attr_kind;
4686 register dw_attr_ref a = get_AT (die, attr_kind);
4687 return a ? AT_ref (a) : NULL;
4690 static inline int
4691 is_c_family ()
4693 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4695 return (lang == DW_LANG_C || lang == DW_LANG_C89
4696 || lang == DW_LANG_C_plus_plus);
4699 static inline int
4700 is_fortran ()
4702 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4704 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
4707 static inline int
4708 is_java ()
4710 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
4712 return (lang == DW_LANG_Java);
4715 /* Free up the memory used by A. */
4717 static inline void free_AT PARAMS ((dw_attr_ref));
4718 static inline void
4719 free_AT (a)
4720 dw_attr_ref a;
4722 switch (AT_class (a))
4724 case dw_val_class_str:
4725 case dw_val_class_lbl_id:
4726 case dw_val_class_lbl_offset:
4727 free (a->dw_attr_val.v.val_str);
4728 break;
4730 case dw_val_class_float:
4731 free (a->dw_attr_val.v.val_float.array);
4732 break;
4734 default:
4735 break;
4738 free (a);
4741 /* Remove the specified attribute if present. */
4743 static void
4744 remove_AT (die, attr_kind)
4745 register dw_die_ref die;
4746 register enum dwarf_attribute attr_kind;
4748 register dw_attr_ref *p;
4749 register dw_attr_ref removed = NULL;
4751 if (die != NULL)
4753 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
4754 if ((*p)->dw_attr == attr_kind)
4756 removed = *p;
4757 *p = (*p)->dw_attr_next;
4758 break;
4761 if (removed != 0)
4762 free_AT (removed);
4766 /* Free up the memory used by DIE. */
4768 static inline void free_die PARAMS ((dw_die_ref));
4769 static inline void
4770 free_die (die)
4771 dw_die_ref die;
4773 remove_children (die);
4774 free (die);
4777 /* Discard the children of this DIE. */
4779 static void
4780 remove_children (die)
4781 register dw_die_ref die;
4783 register dw_die_ref child_die = die->die_child;
4785 die->die_child = NULL;
4787 while (child_die != NULL)
4789 register dw_die_ref tmp_die = child_die;
4790 register dw_attr_ref a;
4792 child_die = child_die->die_sib;
4794 for (a = tmp_die->die_attr; a != NULL;)
4796 register dw_attr_ref tmp_a = a;
4798 a = a->dw_attr_next;
4799 free_AT (tmp_a);
4802 free_die (tmp_die);
4806 /* Add a child DIE below its parent. We build the lists up in reverse
4807 addition order, and correct that in reverse_all_dies. */
4809 static inline void
4810 add_child_die (die, child_die)
4811 register dw_die_ref die;
4812 register dw_die_ref child_die;
4814 if (die != NULL && child_die != NULL)
4816 if (die == child_die)
4817 abort ();
4818 child_die->die_parent = die;
4819 child_die->die_sib = die->die_child;
4820 die->die_child = child_die;
4824 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4825 is the specification, to the front of PARENT's list of children. */
4827 static void
4828 splice_child_die (parent, child)
4829 dw_die_ref parent, child;
4831 dw_die_ref *p;
4833 /* We want the declaration DIE from inside the class, not the
4834 specification DIE at toplevel. */
4835 if (child->die_parent != parent)
4837 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4838 if (tmp)
4839 child = tmp;
4842 if (child->die_parent != parent
4843 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4844 abort ();
4846 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib))
4847 if (*p == child)
4849 *p = child->die_sib;
4850 break;
4853 child->die_sib = parent->die_child;
4854 parent->die_child = child;
4857 /* Return a pointer to a newly created DIE node. */
4859 static inline dw_die_ref
4860 new_die (tag_value, parent_die)
4861 register enum dwarf_tag tag_value;
4862 register dw_die_ref parent_die;
4864 register dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node));
4866 die->die_tag = tag_value;
4868 if (parent_die != NULL)
4869 add_child_die (parent_die, die);
4870 else
4872 limbo_die_node *limbo_node;
4874 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4875 limbo_node->die = die;
4876 limbo_node->next = limbo_die_list;
4877 limbo_die_list = limbo_node;
4880 return die;
4883 /* Return the DIE associated with the given type specifier. */
4885 static inline dw_die_ref
4886 lookup_type_die (type)
4887 register tree type;
4889 if (TREE_CODE (type) == VECTOR_TYPE)
4890 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
4891 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4894 /* Equate a DIE to a given type specifier. */
4896 static inline void
4897 equate_type_number_to_die (type, type_die)
4898 register tree type;
4899 register dw_die_ref type_die;
4901 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4904 /* Return the DIE associated with a given declaration. */
4906 static inline dw_die_ref
4907 lookup_decl_die (decl)
4908 register tree decl;
4910 register unsigned decl_id = DECL_UID (decl);
4912 return (decl_id < decl_die_table_in_use
4913 ? decl_die_table[decl_id] : NULL);
4916 /* Equate a DIE to a particular declaration. */
4918 static void
4919 equate_decl_number_to_die (decl, decl_die)
4920 register tree decl;
4921 register dw_die_ref decl_die;
4923 register unsigned decl_id = DECL_UID (decl);
4924 register unsigned num_allocated;
4926 if (decl_id >= decl_die_table_allocated)
4928 num_allocated
4929 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4930 / DECL_DIE_TABLE_INCREMENT)
4931 * DECL_DIE_TABLE_INCREMENT;
4933 decl_die_table
4934 = (dw_die_ref *) xrealloc (decl_die_table,
4935 sizeof (dw_die_ref) * num_allocated);
4937 memset ((char *) &decl_die_table[decl_die_table_allocated], 0,
4938 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4939 decl_die_table_allocated = num_allocated;
4942 if (decl_id >= decl_die_table_in_use)
4943 decl_die_table_in_use = (decl_id + 1);
4945 decl_die_table[decl_id] = decl_die;
4948 /* Keep track of the number of spaces used to indent the
4949 output of the debugging routines that print the structure of
4950 the DIE internal representation. */
4951 static int print_indent;
4953 /* Indent the line the number of spaces given by print_indent. */
4955 static inline void
4956 print_spaces (outfile)
4957 FILE *outfile;
4959 fprintf (outfile, "%*s", print_indent, "");
4962 /* Print the information associated with a given DIE, and its children.
4963 This routine is a debugging aid only. */
4965 static void
4966 print_die (die, outfile)
4967 dw_die_ref die;
4968 FILE *outfile;
4970 register dw_attr_ref a;
4971 register dw_die_ref c;
4973 print_spaces (outfile);
4974 fprintf (outfile, "DIE %4lu: %s\n",
4975 die->die_offset, dwarf_tag_name (die->die_tag));
4976 print_spaces (outfile);
4977 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4978 fprintf (outfile, " offset: %lu\n", die->die_offset);
4980 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4982 print_spaces (outfile);
4983 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4985 switch (AT_class (a))
4987 case dw_val_class_addr:
4988 fprintf (outfile, "address");
4989 break;
4990 case dw_val_class_loc:
4991 fprintf (outfile, "location descriptor");
4992 break;
4993 case dw_val_class_loc_list:
4994 fprintf (outfile, "location list -> label:%s", AT_loc_list (a)->ll_symbol);
4995 break;
4996 case dw_val_class_const:
4997 fprintf (outfile, "%ld", AT_int (a));
4998 break;
4999 case dw_val_class_unsigned_const:
5000 fprintf (outfile, "%lu", AT_unsigned (a));
5001 break;
5002 case dw_val_class_long_long:
5003 fprintf (outfile, "constant (%lu,%lu)",
5004 a->dw_attr_val.v.val_long_long.hi,
5005 a->dw_attr_val.v.val_long_long.low);
5006 break;
5007 case dw_val_class_float:
5008 fprintf (outfile, "floating-point constant");
5009 break;
5010 case dw_val_class_flag:
5011 fprintf (outfile, "%u", AT_flag (a));
5012 break;
5013 case dw_val_class_die_ref:
5014 if (AT_ref (a) != NULL)
5016 if (AT_ref (a)->die_symbol)
5017 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
5018 else
5019 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
5021 else
5022 fprintf (outfile, "die -> <null>");
5023 break;
5024 case dw_val_class_lbl_id:
5025 case dw_val_class_lbl_offset:
5026 fprintf (outfile, "label: %s", AT_lbl (a));
5027 break;
5028 case dw_val_class_str:
5029 if (AT_string (a) != NULL)
5030 fprintf (outfile, "\"%s\"", AT_string (a));
5031 else
5032 fprintf (outfile, "<null>");
5033 break;
5034 default:
5035 break;
5038 fprintf (outfile, "\n");
5041 if (die->die_child != NULL)
5043 print_indent += 4;
5044 for (c = die->die_child; c != NULL; c = c->die_sib)
5045 print_die (c, outfile);
5047 print_indent -= 4;
5049 if (print_indent == 0)
5050 fprintf (outfile, "\n");
5053 /* Print the contents of the source code line number correspondence table.
5054 This routine is a debugging aid only. */
5056 static void
5057 print_dwarf_line_table (outfile)
5058 FILE *outfile;
5060 register unsigned i;
5061 register dw_line_info_ref line_info;
5063 fprintf (outfile, "\n\nDWARF source line information\n");
5064 for (i = 1; i < line_info_table_in_use; ++i)
5066 line_info = &line_info_table[i];
5067 fprintf (outfile, "%5d: ", i);
5068 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]);
5069 fprintf (outfile, "%6ld", line_info->dw_line_num);
5070 fprintf (outfile, "\n");
5073 fprintf (outfile, "\n\n");
5076 /* Print the information collected for a given DIE. */
5078 void
5079 debug_dwarf_die (die)
5080 dw_die_ref die;
5082 print_die (die, stderr);
5085 /* Print all DWARF information collected for the compilation unit.
5086 This routine is a debugging aid only. */
5088 void
5089 debug_dwarf ()
5091 print_indent = 0;
5092 print_die (comp_unit_die, stderr);
5093 if (! DWARF2_ASM_LINE_DEBUG_INFO)
5094 print_dwarf_line_table (stderr);
5097 /* We build up the lists of children and attributes by pushing new ones
5098 onto the beginning of the list. Reverse the lists for DIE so that
5099 they are in order of addition. */
5101 static void
5102 reverse_die_lists (die)
5103 register dw_die_ref die;
5105 register dw_die_ref c, cp, cn;
5106 register dw_attr_ref a, ap, an;
5108 for (a = die->die_attr, ap = 0; a; a = an)
5110 an = a->dw_attr_next;
5111 a->dw_attr_next = ap;
5112 ap = a;
5114 die->die_attr = ap;
5116 for (c = die->die_child, cp = 0; c; c = cn)
5118 cn = c->die_sib;
5119 c->die_sib = cp;
5120 cp = c;
5122 die->die_child = cp;
5125 /* reverse_die_lists only reverses the single die you pass it. Since
5126 we used to reverse all dies in add_sibling_attributes, which runs
5127 through all the dies, it would reverse all the dies. Now, however,
5128 since we don't call reverse_die_lists in add_sibling_attributes, we
5129 need a routine to recursively reverse all the dies. This is that
5130 routine. */
5132 static void
5133 reverse_all_dies (die)
5134 register dw_die_ref die;
5136 register dw_die_ref c;
5138 reverse_die_lists (die);
5140 for (c = die->die_child; c; c = c->die_sib)
5141 reverse_all_dies (c);
5144 /* Start a new compilation unit DIE for an include file. OLD_UNIT is
5145 the CU for the enclosing include file, if any. BINCL_DIE is the
5146 DW_TAG_GNU_BINCL DIE that marks the start of the DIEs for this
5147 include file. */
5149 static dw_die_ref
5150 push_new_compile_unit (old_unit, bincl_die)
5151 dw_die_ref old_unit, bincl_die;
5153 const char *filename = get_AT_string (bincl_die, DW_AT_name);
5154 dw_die_ref new_unit = gen_compile_unit_die (filename);
5155 new_unit->die_sib = old_unit;
5156 return new_unit;
5159 /* Close an include-file CU and reopen the enclosing one. */
5161 static dw_die_ref
5162 pop_compile_unit (old_unit)
5163 dw_die_ref old_unit;
5165 dw_die_ref new_unit = old_unit->die_sib;
5166 old_unit->die_sib = NULL;
5167 return new_unit;
5170 #define PROCESS(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5171 #define PROCESS_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5173 /* Calculate the checksum of a location expression. */
5175 static inline void
5176 loc_checksum (loc, ctx)
5177 dw_loc_descr_ref loc;
5178 struct md5_ctx *ctx;
5180 PROCESS (loc->dw_loc_opc);
5181 PROCESS (loc->dw_loc_oprnd1);
5182 PROCESS (loc->dw_loc_oprnd2);
5185 /* Calculate the checksum of an attribute. */
5187 static void
5188 attr_checksum (at, ctx)
5189 dw_attr_ref at;
5190 struct md5_ctx *ctx;
5192 dw_loc_descr_ref loc;
5193 rtx r;
5195 PROCESS (at->dw_attr);
5197 /* We don't care about differences in file numbering. */
5198 if (at->dw_attr == DW_AT_decl_file
5199 /* Or that this was compiled with a different compiler snapshot; if
5200 the output is the same, that's what matters. */
5201 || at->dw_attr == DW_AT_producer)
5202 return;
5204 switch (AT_class (at))
5206 case dw_val_class_const:
5207 PROCESS (at->dw_attr_val.v.val_int);
5208 break;
5209 case dw_val_class_unsigned_const:
5210 PROCESS (at->dw_attr_val.v.val_unsigned);
5211 break;
5212 case dw_val_class_long_long:
5213 PROCESS (at->dw_attr_val.v.val_long_long);
5214 break;
5215 case dw_val_class_float:
5216 PROCESS (at->dw_attr_val.v.val_float);
5217 break;
5218 case dw_val_class_flag:
5219 PROCESS (at->dw_attr_val.v.val_flag);
5220 break;
5222 case dw_val_class_str:
5223 PROCESS_STRING (AT_string (at));
5224 break;
5225 case dw_val_class_addr:
5226 r = AT_addr (at);
5227 switch (GET_CODE (r))
5229 case SYMBOL_REF:
5230 PROCESS_STRING (XSTR (r, 0));
5231 break;
5233 default:
5234 abort ();
5236 break;
5238 case dw_val_class_loc:
5239 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next)
5240 loc_checksum (loc, ctx);
5241 break;
5243 case dw_val_class_die_ref:
5244 if (AT_ref (at)->die_offset)
5245 PROCESS (AT_ref (at)->die_offset);
5246 /* FIXME else use target die name or something. */
5248 case dw_val_class_fde_ref:
5249 case dw_val_class_lbl_id:
5250 case dw_val_class_lbl_offset:
5252 default:
5253 break;
5257 /* Calculate the checksum of a DIE. */
5259 static void
5260 die_checksum (die, ctx)
5261 dw_die_ref die;
5262 struct md5_ctx *ctx;
5264 dw_die_ref c;
5265 dw_attr_ref a;
5267 PROCESS (die->die_tag);
5269 for (a = die->die_attr; a; a = a->dw_attr_next)
5270 attr_checksum (a, ctx);
5272 for (c = die->die_child; c; c = c->die_sib)
5273 die_checksum (c, ctx);
5276 #undef PROCESS
5277 #undef PROCESS_STRING
5279 /* The prefix to attach to symbols on DIEs in the current comdat debug
5280 info section. */
5281 static char *comdat_symbol_id;
5283 /* The index of the current symbol within the current comdat CU. */
5284 static unsigned int comdat_symbol_number;
5286 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
5287 children, and set comdat_symbol_id accordingly. */
5289 static void
5290 compute_section_prefix (unit_die)
5291 dw_die_ref unit_die;
5293 char *p, *name;
5294 int i;
5295 unsigned char checksum[16];
5296 struct md5_ctx ctx;
5298 md5_init_ctx (&ctx);
5299 die_checksum (unit_die, &ctx);
5300 md5_finish_ctx (&ctx, checksum);
5302 p = lbasename (get_AT_string (unit_die, DW_AT_name));
5303 name = (char *) alloca (strlen (p) + 64);
5304 sprintf (name, "%s.", p);
5306 clean_symbol_name (name);
5308 p = name + strlen (name);
5309 for (i = 0; i < 4; ++i)
5311 sprintf (p, "%.2x", checksum[i]);
5312 p += 2;
5315 comdat_symbol_id = unit_die->die_symbol = xstrdup (name);
5316 comdat_symbol_number = 0;
5319 /* Returns nonzero iff DIE represents a type, in the sense of TYPE_P. */
5321 static int
5322 is_type_die (die)
5323 dw_die_ref die;
5325 switch (die->die_tag)
5327 case DW_TAG_array_type:
5328 case DW_TAG_class_type:
5329 case DW_TAG_enumeration_type:
5330 case DW_TAG_pointer_type:
5331 case DW_TAG_reference_type:
5332 case DW_TAG_string_type:
5333 case DW_TAG_structure_type:
5334 case DW_TAG_subroutine_type:
5335 case DW_TAG_union_type:
5336 case DW_TAG_ptr_to_member_type:
5337 case DW_TAG_set_type:
5338 case DW_TAG_subrange_type:
5339 case DW_TAG_base_type:
5340 case DW_TAG_const_type:
5341 case DW_TAG_file_type:
5342 case DW_TAG_packed_type:
5343 case DW_TAG_volatile_type:
5344 return 1;
5345 default:
5346 return 0;
5350 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
5351 Basically, we want to choose the bits that are likely to be shared between
5352 compilations (types) and leave out the bits that are specific to individual
5353 compilations (functions). */
5355 static int
5356 is_comdat_die (c)
5357 dw_die_ref c;
5359 #if 1
5360 /* I think we want to leave base types and __vtbl_ptr_type in the
5361 main CU, as we do for stabs. The advantage is a greater
5362 likelihood of sharing between objects that don't include headers
5363 in the same order (and therefore would put the base types in a
5364 different comdat). jason 8/28/00 */
5365 if (c->die_tag == DW_TAG_base_type)
5366 return 0;
5368 if (c->die_tag == DW_TAG_pointer_type
5369 || c->die_tag == DW_TAG_reference_type
5370 || c->die_tag == DW_TAG_const_type
5371 || c->die_tag == DW_TAG_volatile_type)
5373 dw_die_ref t = get_AT_ref (c, DW_AT_type);
5374 return t ? is_comdat_die (t) : 0;
5376 #endif
5378 return is_type_die (c);
5381 /* Returns 1 iff C is the sort of DIE that might be referred to from another
5382 compilation unit. */
5384 static int
5385 is_symbol_die (c)
5386 dw_die_ref c;
5388 if (is_type_die (c))
5389 return 1;
5390 if (get_AT (c, DW_AT_declaration)
5391 && ! get_AT (c, DW_AT_specification))
5392 return 1;
5393 return 0;
5396 static char *
5397 gen_internal_sym (prefix)
5398 const char *prefix;
5400 char buf[256];
5401 static int label_num;
5402 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++);
5403 return xstrdup (buf);
5406 /* Assign symbols to all worthy DIEs under DIE. */
5408 static void
5409 assign_symbol_names (die)
5410 register dw_die_ref die;
5412 register dw_die_ref c;
5414 if (is_symbol_die (die))
5416 if (comdat_symbol_id)
5418 char *p = alloca (strlen (comdat_symbol_id) + 64);
5419 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX,
5420 comdat_symbol_id, comdat_symbol_number++);
5421 die->die_symbol = xstrdup (p);
5423 else
5424 die->die_symbol = gen_internal_sym ("LDIE");
5427 for (c = die->die_child; c != NULL; c = c->die_sib)
5428 assign_symbol_names (c);
5431 /* Traverse the DIE (which is always comp_unit_die), and set up
5432 additional compilation units for each of the include files we see
5433 bracketed by BINCL/EINCL. */
5435 static void
5436 break_out_includes (die)
5437 register dw_die_ref die;
5439 dw_die_ref *ptr;
5440 register dw_die_ref unit = NULL;
5441 limbo_die_node *node;
5443 for (ptr = &(die->die_child); *ptr; )
5445 register dw_die_ref c = *ptr;
5447 if (c->die_tag == DW_TAG_GNU_BINCL
5448 || c->die_tag == DW_TAG_GNU_EINCL
5449 || (unit && is_comdat_die (c)))
5451 /* This DIE is for a secondary CU; remove it from the main one. */
5452 *ptr = c->die_sib;
5454 if (c->die_tag == DW_TAG_GNU_BINCL)
5456 unit = push_new_compile_unit (unit, c);
5457 free_die (c);
5459 else if (c->die_tag == DW_TAG_GNU_EINCL)
5461 unit = pop_compile_unit (unit);
5462 free_die (c);
5464 else
5465 add_child_die (unit, c);
5467 else
5469 /* Leave this DIE in the main CU. */
5470 ptr = &(c->die_sib);
5471 continue;
5475 #if 0
5476 /* We can only use this in debugging, since the frontend doesn't check
5477 to make sure that we leave every include file we enter. */
5478 if (unit != NULL)
5479 abort ();
5480 #endif
5482 assign_symbol_names (die);
5483 for (node = limbo_die_list; node; node = node->next)
5485 compute_section_prefix (node->die);
5486 assign_symbol_names (node->die);
5490 /* Traverse the DIE and add a sibling attribute if it may have the
5491 effect of speeding up access to siblings. To save some space,
5492 avoid generating sibling attributes for DIE's without children. */
5494 static void
5495 add_sibling_attributes (die)
5496 register dw_die_ref die;
5498 register dw_die_ref c;
5500 if (die->die_tag != DW_TAG_compile_unit
5501 && die->die_sib && die->die_child != NULL)
5502 /* Add the sibling link to the front of the attribute list. */
5503 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
5505 for (c = die->die_child; c != NULL; c = c->die_sib)
5506 add_sibling_attributes (c);
5509 /* Output all location lists for the DIE and it's children */
5510 static void
5511 output_location_lists (die)
5512 register dw_die_ref die;
5514 dw_die_ref c;
5515 dw_attr_ref d_attr;
5516 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5518 if (AT_class (d_attr) == dw_val_class_loc_list)
5520 output_loc_list (AT_loc_list (d_attr));
5523 for (c = die->die_child; c != NULL; c = c->die_sib)
5524 output_location_lists (c);
5527 /* The format of each DIE (and its attribute value pairs)
5528 is encoded in an abbreviation table. This routine builds the
5529 abbreviation table and assigns a unique abbreviation id for
5530 each abbreviation entry. The children of each die are visited
5531 recursively. */
5533 static void
5534 build_abbrev_table (die)
5535 register dw_die_ref die;
5537 register unsigned long abbrev_id;
5538 register unsigned int n_alloc;
5539 register dw_die_ref c;
5540 register dw_attr_ref d_attr, a_attr;
5542 /* Scan the DIE references, and mark as external any that refer to
5543 DIEs from other CUs (i.e. those which are not marked). */
5544 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next)
5546 if (AT_class (d_attr) == dw_val_class_die_ref
5547 && AT_ref (d_attr)->die_mark == 0)
5549 if (AT_ref (d_attr)->die_symbol == 0)
5550 abort ();
5551 set_AT_ref_external (d_attr, 1);
5555 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5557 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5559 if (abbrev->die_tag == die->die_tag)
5561 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
5563 a_attr = abbrev->die_attr;
5564 d_attr = die->die_attr;
5566 while (a_attr != NULL && d_attr != NULL)
5568 if ((a_attr->dw_attr != d_attr->dw_attr)
5569 || (value_format (a_attr) != value_format (d_attr)))
5570 break;
5572 a_attr = a_attr->dw_attr_next;
5573 d_attr = d_attr->dw_attr_next;
5576 if (a_attr == NULL && d_attr == NULL)
5577 break;
5582 if (abbrev_id >= abbrev_die_table_in_use)
5584 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
5586 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
5587 abbrev_die_table
5588 = (dw_die_ref *) xrealloc (abbrev_die_table,
5589 sizeof (dw_die_ref) * n_alloc);
5591 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0,
5592 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
5593 abbrev_die_table_allocated = n_alloc;
5596 ++abbrev_die_table_in_use;
5597 abbrev_die_table[abbrev_id] = die;
5600 die->die_abbrev = abbrev_id;
5601 for (c = die->die_child; c != NULL; c = c->die_sib)
5602 build_abbrev_table (c);
5605 /* Return the size of a string, including the null byte.
5607 This used to treat backslashes as escapes, and hence they were not included
5608 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
5609 which treats a backslash as a backslash, escaping it if necessary, and hence
5610 we must include them in the count. */
5612 static unsigned long
5613 size_of_string (str)
5614 register const char *str;
5616 return strlen (str) + 1;
5619 /* Return the power-of-two number of bytes necessary to represent VALUE. */
5621 static int
5622 constant_size (value)
5623 long unsigned value;
5625 int log;
5627 if (value == 0)
5628 log = 0;
5629 else
5630 log = floor_log2 (value);
5632 log = log / 8;
5633 log = 1 << (floor_log2 (log) + 1);
5635 return log;
5638 /* Return the size of a DIE, as it is represented in the
5639 .debug_info section. */
5641 static unsigned long
5642 size_of_die (die)
5643 register dw_die_ref die;
5645 register unsigned long size = 0;
5646 register dw_attr_ref a;
5648 size += size_of_uleb128 (die->die_abbrev);
5649 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5651 switch (AT_class (a))
5653 case dw_val_class_addr:
5654 size += DWARF2_ADDR_SIZE;
5655 break;
5656 case dw_val_class_loc:
5658 register unsigned long lsize = size_of_locs (AT_loc (a));
5660 /* Block length. */
5661 size += constant_size (lsize);
5662 size += lsize;
5664 break;
5665 case dw_val_class_loc_list:
5666 size += DWARF_OFFSET_SIZE;
5667 break;
5668 case dw_val_class_const:
5669 size += size_of_sleb128 (AT_int (a));
5670 break;
5671 case dw_val_class_unsigned_const:
5672 size += constant_size (AT_unsigned (a));
5673 break;
5674 case dw_val_class_long_long:
5675 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */
5676 break;
5677 case dw_val_class_float:
5678 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
5679 break;
5680 case dw_val_class_flag:
5681 size += 1;
5682 break;
5683 case dw_val_class_die_ref:
5684 size += DWARF_OFFSET_SIZE;
5685 break;
5686 case dw_val_class_fde_ref:
5687 size += DWARF_OFFSET_SIZE;
5688 break;
5689 case dw_val_class_lbl_id:
5690 size += DWARF2_ADDR_SIZE;
5691 break;
5692 case dw_val_class_lbl_offset:
5693 size += DWARF_OFFSET_SIZE;
5694 break;
5695 case dw_val_class_str:
5696 size += size_of_string (AT_string (a));
5697 break;
5698 default:
5699 abort ();
5703 return size;
5706 /* Size the debugging information associated with a given DIE.
5707 Visits the DIE's children recursively. Updates the global
5708 variable next_die_offset, on each time through. Uses the
5709 current value of next_die_offset to update the die_offset
5710 field in each DIE. */
5712 static void
5713 calc_die_sizes (die)
5714 dw_die_ref die;
5716 register dw_die_ref c;
5717 die->die_offset = next_die_offset;
5718 next_die_offset += size_of_die (die);
5720 for (c = die->die_child; c != NULL; c = c->die_sib)
5721 calc_die_sizes (c);
5723 if (die->die_child != NULL)
5724 /* Count the null byte used to terminate sibling lists. */
5725 next_die_offset += 1;
5728 /* Set the marks for a die and its children. We do this so
5729 that we know whether or not a reference needs to use FORM_ref_addr; only
5730 DIEs in the same CU will be marked. We used to clear out the offset
5731 and use that as the flag, but ran into ordering problems. */
5733 static void
5734 mark_dies (die)
5735 dw_die_ref die;
5737 register dw_die_ref c;
5738 die->die_mark = 1;
5739 for (c = die->die_child; c; c = c->die_sib)
5740 mark_dies (c);
5743 /* Clear the marks for a die and its children. */
5745 static void
5746 unmark_dies (die)
5747 dw_die_ref die;
5749 register dw_die_ref c;
5750 die->die_mark = 0;
5751 for (c = die->die_child; c; c = c->die_sib)
5752 unmark_dies (c);
5755 /* Return the size of the .debug_pubnames table generated for the
5756 compilation unit. */
5758 static unsigned long
5759 size_of_pubnames ()
5761 register unsigned long size;
5762 register unsigned i;
5764 size = DWARF_PUBNAMES_HEADER_SIZE;
5765 for (i = 0; i < pubname_table_in_use; ++i)
5767 register pubname_ref p = &pubname_table[i];
5768 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
5771 size += DWARF_OFFSET_SIZE;
5772 return size;
5775 /* Return the size of the information in the .debug_aranges section. */
5777 static unsigned long
5778 size_of_aranges ()
5780 register unsigned long size;
5782 size = DWARF_ARANGES_HEADER_SIZE;
5784 /* Count the address/length pair for this compilation unit. */
5785 size += 2 * DWARF2_ADDR_SIZE;
5786 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use;
5788 /* Count the two zero words used to terminated the address range table. */
5789 size += 2 * DWARF2_ADDR_SIZE;
5790 return size;
5793 /* Select the encoding of an attribute value. */
5795 static enum dwarf_form
5796 value_format (a)
5797 dw_attr_ref a;
5799 switch (a->dw_attr_val.val_class)
5801 case dw_val_class_addr:
5802 return DW_FORM_addr;
5803 case dw_val_class_loc_list:
5804 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size
5805 .debug_loc section */
5806 return DW_FORM_data4;
5807 case dw_val_class_loc:
5808 switch (constant_size (size_of_locs (AT_loc (a))))
5810 case 1:
5811 return DW_FORM_block1;
5812 case 2:
5813 return DW_FORM_block2;
5814 default:
5815 abort ();
5817 case dw_val_class_const:
5818 return DW_FORM_sdata;
5819 case dw_val_class_unsigned_const:
5820 switch (constant_size (AT_unsigned (a)))
5822 case 1:
5823 return DW_FORM_data1;
5824 case 2:
5825 return DW_FORM_data2;
5826 case 4:
5827 return DW_FORM_data4;
5828 case 8:
5829 return DW_FORM_data8;
5830 default:
5831 abort ();
5833 case dw_val_class_long_long:
5834 return DW_FORM_block1;
5835 case dw_val_class_float:
5836 return DW_FORM_block1;
5837 case dw_val_class_flag:
5838 return DW_FORM_flag;
5839 case dw_val_class_die_ref:
5840 if (AT_ref_external (a))
5841 return DW_FORM_ref_addr;
5842 else
5843 return DW_FORM_ref;
5844 case dw_val_class_fde_ref:
5845 return DW_FORM_data;
5846 case dw_val_class_lbl_id:
5847 return DW_FORM_addr;
5848 case dw_val_class_lbl_offset:
5849 return DW_FORM_data;
5850 case dw_val_class_str:
5851 return DW_FORM_string;
5852 default:
5853 abort ();
5857 /* Output the encoding of an attribute value. */
5859 static void
5860 output_value_format (a)
5861 dw_attr_ref a;
5863 enum dwarf_form form = value_format (a);
5864 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form));
5867 /* Output the .debug_abbrev section which defines the DIE abbreviation
5868 table. */
5870 static void
5871 output_abbrev_section ()
5873 unsigned long abbrev_id;
5875 dw_attr_ref a_attr;
5876 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
5878 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
5880 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)");
5882 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)",
5883 dwarf_tag_name (abbrev->die_tag));
5885 if (abbrev->die_child != NULL)
5886 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes");
5887 else
5888 dw2_asm_output_data (1, DW_children_no, "DW_children_no");
5890 for (a_attr = abbrev->die_attr; a_attr != NULL;
5891 a_attr = a_attr->dw_attr_next)
5893 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)",
5894 dwarf_attr_name (a_attr->dw_attr));
5895 output_value_format (a_attr);
5898 dw2_asm_output_data (1, 0, NULL);
5899 dw2_asm_output_data (1, 0, NULL);
5902 /* Terminate the table. */
5903 dw2_asm_output_data (1, 0, NULL);
5906 /* Output a symbol we can use to refer to this DIE from another CU. */
5908 static inline void
5909 output_die_symbol (die)
5910 register dw_die_ref die;
5912 char *sym = die->die_symbol;
5914 if (sym == 0)
5915 return;
5917 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0)
5918 /* We make these global, not weak; if the target doesn't support
5919 .linkonce, it doesn't support combining the sections, so debugging
5920 will break. */
5921 ASM_GLOBALIZE_LABEL (asm_out_file, sym);
5922 ASM_OUTPUT_LABEL (asm_out_file, sym);
5925 /* Return a new location list, given the begin and end range, and the
5926 expression. gensym tells us whether to generate a new internal
5927 symbol for this location list node, which is done for the head of
5928 the list only. */
5929 static inline dw_loc_list_ref
5930 new_loc_list (expr, begin, end, section, gensym)
5931 register dw_loc_descr_ref expr;
5932 register const char *begin;
5933 register const char *end;
5934 register const char *section;
5935 register unsigned gensym;
5937 register dw_loc_list_ref retlist
5938 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node));
5939 retlist->begin = begin;
5940 retlist->end = end;
5941 retlist->expr = expr;
5942 retlist->section = section;
5943 if (gensym)
5944 retlist->ll_symbol = gen_internal_sym ("LLST");
5945 return retlist;
5948 /* Add a location description expression to a location list */
5949 static inline void
5950 add_loc_descr_to_loc_list (list_head, descr, begin, end, section)
5951 register dw_loc_list_ref *list_head;
5952 register dw_loc_descr_ref descr;
5953 register const char *begin;
5954 register const char *end;
5955 register const char *section;
5957 register dw_loc_list_ref *d;
5959 /* Find the end of the chain. */
5960 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
5962 /* Add a new location list node to the list */
5963 *d = new_loc_list (descr, begin, end, section, 0);
5968 /* Output the location list given to us */
5969 static void
5970 output_loc_list (list_head)
5971 register dw_loc_list_ref list_head;
5973 register dw_loc_list_ref curr=list_head;
5974 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol);
5975 if (strcmp (curr->section, ".text") == 0)
5977 /* dw2_asm_output_data will mask off any extra bits in the ~0. */
5978 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT)0,
5979 "Location list base address specifier fake entry");
5980 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section,
5981 "Location list base address specifier base");
5983 for (curr = list_head; curr != NULL; curr=curr->dw_loc_next)
5985 int size;
5986 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section,
5987 "Location list begin address (%s)",
5988 list_head->ll_symbol);
5989 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section,
5990 "Location list end address (%s)",
5991 list_head->ll_symbol);
5992 size = size_of_locs (curr->expr);
5994 /* Output the block length for this list of location operations. */
5995 dw2_asm_output_data (constant_size (size), size, "%s",
5996 "Location expression size");
5998 output_loc_sequence (curr->expr);
6000 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6001 "Location list terminator begin (%s)",
6002 list_head->ll_symbol);
6003 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0,
6004 "Location list terminator end (%s)",
6005 list_head->ll_symbol);
6007 /* Output the DIE and its attributes. Called recursively to generate
6008 the definitions of each child DIE. */
6010 static void
6011 output_die (die)
6012 register dw_die_ref die;
6014 register dw_attr_ref a;
6015 register dw_die_ref c;
6016 register unsigned long size;
6018 /* If someone in another CU might refer to us, set up a symbol for
6019 them to point to. */
6020 if (die->die_symbol)
6021 output_die_symbol (die);
6023 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
6024 die->die_offset, dwarf_tag_name (die->die_tag));
6026 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
6028 const char *name = dwarf_attr_name (a->dw_attr);
6030 switch (AT_class (a))
6032 case dw_val_class_addr:
6033 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name);
6034 break;
6036 case dw_val_class_loc:
6037 size = size_of_locs (AT_loc (a));
6039 /* Output the block length for this list of location operations. */
6040 dw2_asm_output_data (constant_size (size), size, "%s", name);
6042 output_loc_sequence (AT_loc (a));
6043 break;
6045 case dw_val_class_const:
6046 /* ??? It would be slightly more efficient to use a scheme like is
6047 used for unsigned constants below, but gdb 4.x does not sign
6048 extend. Gdb 5.x does sign extend. */
6049 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name);
6050 break;
6052 case dw_val_class_unsigned_const:
6053 dw2_asm_output_data (constant_size (AT_unsigned (a)),
6054 AT_unsigned (a), "%s", name);
6055 break;
6057 case dw_val_class_long_long:
6059 unsigned HOST_WIDE_INT first, second;
6061 dw2_asm_output_data (1, 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6062 "%s", name);
6064 if (WORDS_BIG_ENDIAN)
6066 first = a->dw_attr_val.v.val_long_long.hi;
6067 second = a->dw_attr_val.v.val_long_long.low;
6069 else
6071 first = a->dw_attr_val.v.val_long_long.low;
6072 second = a->dw_attr_val.v.val_long_long.hi;
6074 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6075 first, "long long constant");
6076 dw2_asm_output_data (HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR,
6077 second, NULL);
6079 break;
6081 case dw_val_class_float:
6083 register unsigned int i;
6085 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4,
6086 "%s", name);
6088 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
6089 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i],
6090 "fp constant word %u", i);
6091 break;
6094 case dw_val_class_flag:
6095 dw2_asm_output_data (1, AT_flag (a), "%s", name);
6096 break;
6097 case dw_val_class_loc_list:
6099 char *sym = AT_loc_list (a)->ll_symbol;
6100 if (sym == 0)
6101 abort();
6102 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, loc_section_label, name);
6104 break;
6105 case dw_val_class_die_ref:
6106 if (AT_ref_external (a))
6108 char *sym = AT_ref (a)->die_symbol;
6109 if (sym == 0)
6110 abort ();
6111 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name);
6113 else if (AT_ref (a)->die_offset == 0)
6114 abort ();
6115 else
6116 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset,
6117 "%s", name);
6118 break;
6120 case dw_val_class_fde_ref:
6122 char l1[20];
6123 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL,
6124 a->dw_attr_val.v.val_fde_index * 2);
6125 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name);
6127 break;
6129 case dw_val_class_lbl_id:
6130 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name);
6131 break;
6133 case dw_val_class_lbl_offset:
6134 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name);
6135 break;
6137 case dw_val_class_str:
6138 dw2_asm_output_nstring (AT_string (a), -1, "%s", name);
6139 break;
6141 default:
6142 abort ();
6146 for (c = die->die_child; c != NULL; c = c->die_sib)
6147 output_die (c);
6149 if (die->die_child != NULL)
6151 /* Add null byte to terminate sibling list. */
6152 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
6153 die->die_offset);
6157 /* Output the compilation unit that appears at the beginning of the
6158 .debug_info section, and precedes the DIE descriptions. */
6160 static void
6161 output_compilation_unit_header ()
6163 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE,
6164 "Length of Compilation Unit Info");
6166 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number");
6168 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label,
6169 "Offset Into Abbrev. Section");
6171 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)");
6174 /* Output the compilation unit DIE and its children. */
6176 static void
6177 output_comp_unit (die)
6178 dw_die_ref die;
6180 const char *secname;
6182 /* Even if there are no children of this DIE, we must output the
6183 information about the compilation unit. Otherwise, on an empty
6184 translation unit, we will generate a present, but empty,
6185 .debug_info section. IRIX 6.5 `nm' will then complain when
6186 examining the file.
6188 Mark all the DIEs in this CU so we know which get local refs. */
6189 mark_dies (die);
6191 build_abbrev_table (die);
6193 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
6194 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
6195 calc_die_sizes (die);
6197 if (die->die_symbol)
6199 char *tmp = (char *) alloca (strlen (die->die_symbol) + 24);
6200 sprintf (tmp, ".gnu.linkonce.wi.%s", die->die_symbol);
6201 secname = tmp;
6202 die->die_symbol = NULL;
6204 else
6205 secname = (const char *) DEBUG_INFO_SECTION;
6207 /* Output debugging information. */
6208 ASM_OUTPUT_SECTION (asm_out_file, secname);
6209 output_compilation_unit_header ();
6210 output_die (die);
6212 /* Leave the marks on the main CU, so we can check them in
6213 output_pubnames. */
6214 if (die->die_symbol)
6215 unmark_dies (die);
6218 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
6219 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
6220 argument list, and maybe the scope. */
6222 static const char *
6223 dwarf2_name (decl, scope)
6224 tree decl;
6225 int scope;
6227 return (*decl_printable_name) (decl, scope ? 1 : 0);
6230 /* Add a new entry to .debug_pubnames if appropriate. */
6232 static void
6233 add_pubname (decl, die)
6234 tree decl;
6235 dw_die_ref die;
6237 pubname_ref p;
6239 if (! TREE_PUBLIC (decl))
6240 return;
6242 if (pubname_table_in_use == pubname_table_allocated)
6244 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
6245 pubname_table = (pubname_ref) xrealloc
6246 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
6249 p = &pubname_table[pubname_table_in_use++];
6250 p->die = die;
6252 p->name = xstrdup (dwarf2_name (decl, 1));
6255 /* Output the public names table used to speed up access to externally
6256 visible names. For now, only generate entries for externally
6257 visible procedures. */
6259 static void
6260 output_pubnames ()
6262 register unsigned i;
6263 register unsigned long pubnames_length = size_of_pubnames ();
6265 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length,
6266 "Length of Public Names Info");
6268 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6270 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6271 "Offset of Compilation Unit Info");
6273 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset,
6274 "Compilation Unit Length");
6276 for (i = 0; i < pubname_table_in_use; ++i)
6278 register pubname_ref pub = &pubname_table[i];
6280 /* We shouldn't see pubnames for DIEs outside of the main CU. */
6281 if (pub->die->die_mark == 0)
6282 abort ();
6284 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset,
6285 "DIE offset");
6287 dw2_asm_output_nstring (pub->name, -1, "external name");
6290 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL);
6293 /* Add a new entry to .debug_aranges if appropriate. */
6295 static void
6296 add_arange (decl, die)
6297 tree decl;
6298 dw_die_ref die;
6300 if (! DECL_SECTION_NAME (decl))
6301 return;
6303 if (arange_table_in_use == arange_table_allocated)
6305 arange_table_allocated += ARANGE_TABLE_INCREMENT;
6306 arange_table
6307 = (arange_ref) xrealloc (arange_table,
6308 arange_table_allocated * sizeof (dw_die_ref));
6311 arange_table[arange_table_in_use++] = die;
6314 /* Output the information that goes into the .debug_aranges table.
6315 Namely, define the beginning and ending address range of the
6316 text section generated for this compilation unit. */
6318 static void
6319 output_aranges ()
6321 register unsigned i;
6322 register unsigned long aranges_length = size_of_aranges ();
6324 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length,
6325 "Length of Address Ranges Info");
6327 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6329 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label,
6330 "Offset of Compilation Unit Info");
6332 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address");
6334 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
6336 /* We need to align to twice the pointer size here. */
6337 if (DWARF_ARANGES_PAD_SIZE)
6339 /* Pad using a 2 byte words so that padding is correct for any
6340 pointer size. */
6341 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
6342 2 * DWARF2_ADDR_SIZE);
6343 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2)
6344 dw2_asm_output_data (2, 0, NULL);
6347 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address");
6348 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label,
6349 text_section_label, "Length");
6351 for (i = 0; i < arange_table_in_use; ++i)
6353 dw_die_ref die = arange_table[i];
6355 /* We shouldn't see aranges for DIEs outside of the main CU. */
6356 if (die->die_mark == 0)
6357 abort ();
6359 if (die->die_tag == DW_TAG_subprogram)
6361 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die),
6362 "Address");
6363 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die),
6364 get_AT_low_pc (die), "Length");
6366 else
6368 /* A static variable; extract the symbol from DW_AT_location.
6369 Note that this code isn't currently hit, as we only emit
6370 aranges for functions (jason 9/23/99). */
6372 dw_attr_ref a = get_AT (die, DW_AT_location);
6373 dw_loc_descr_ref loc;
6374 if (! a || AT_class (a) != dw_val_class_loc)
6375 abort ();
6377 loc = AT_loc (a);
6378 if (loc->dw_loc_opc != DW_OP_addr)
6379 abort ();
6381 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE,
6382 loc->dw_loc_oprnd1.v.val_addr, "Address");
6383 dw2_asm_output_data (DWARF2_ADDR_SIZE,
6384 get_AT_unsigned (die, DW_AT_byte_size),
6385 "Length");
6389 /* Output the terminator words. */
6390 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6391 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL);
6395 /* Data structure containing information about input files. */
6396 struct file_info
6398 char *path; /* Complete file name. */
6399 char *fname; /* File name part. */
6400 int length; /* Length of entire string. */
6401 int file_idx; /* Index in input file table. */
6402 int dir_idx; /* Index in directory table. */
6405 /* Data structure containing information about directories with source
6406 files. */
6407 struct dir_info
6409 char *path; /* Path including directory name. */
6410 int length; /* Path length. */
6411 int prefix; /* Index of directory entry which is a prefix. */
6412 int count; /* Number of files in this directory. */
6413 int dir_idx; /* Index of directory used as base. */
6414 int used; /* Used in the end? */
6417 /* Callback function for file_info comparison. We sort by looking at
6418 the directories in the path. */
6419 static int
6420 file_info_cmp (p1, p2)
6421 const void *p1;
6422 const void *p2;
6424 const struct file_info *s1 = p1;
6425 const struct file_info *s2 = p2;
6426 unsigned char *cp1;
6427 unsigned char *cp2;
6429 /* Take care of file names without directories. */
6430 if (s1->path == s1->fname)
6431 return -1;
6432 else if (s2->path == s2->fname)
6433 return 1;
6435 cp1 = (unsigned char *) s1->path;
6436 cp2 = (unsigned char *) s2->path;
6438 while (1)
6440 ++cp1;
6441 ++cp2;
6442 /* Reached the end of the first path? */
6443 if (cp1 == (unsigned char *) s1->fname)
6444 /* It doesn't really matter in which order files from the
6445 same directory are sorted in. Therefore don't test for
6446 the second path reaching the end. */
6447 return -1;
6448 else if (cp2 == (unsigned char *) s2->fname)
6449 return 1;
6451 /* Character of current path component the same? */
6452 if (*cp1 != *cp2)
6453 return *cp1 - *cp2;
6457 /* Output the directory table and the file name table. We try to minimize
6458 the total amount of memory needed. A heuristic is used to avoid large
6459 slowdowns with many input files. */
6460 static void
6461 output_file_names ()
6463 struct file_info *files;
6464 struct dir_info *dirs;
6465 int *saved;
6466 int *savehere;
6467 int *backmap;
6468 int ndirs;
6469 int idx_offset;
6470 int i;
6471 int idx;
6473 /* Allocate the various arrays we need. */
6474 files = (struct file_info *) alloca (file_table.in_use
6475 * sizeof (struct file_info));
6476 dirs = (struct dir_info *) alloca (file_table.in_use
6477 * sizeof (struct dir_info));
6479 /* Sort the file names. */
6480 for (i = 1; i < (int) file_table.in_use; ++i)
6482 char *f;
6484 /* Skip all leading "./". */
6485 f = file_table.table[i];
6486 while (f[0] == '.' && f[1] == '/')
6487 f += 2;
6489 /* Create a new array entry. */
6490 files[i].path = f;
6491 files[i].length = strlen (f);
6492 files[i].file_idx = i;
6494 /* Search for the file name part. */
6495 f = strrchr (f, '/');
6496 files[i].fname = f == NULL ? files[i].path : f + 1;
6498 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp);
6500 /* Find all the different directories used. */
6501 dirs[0].path = files[1].path;
6502 dirs[0].length = files[1].fname - files[1].path;
6503 dirs[0].prefix = -1;
6504 dirs[0].count = 1;
6505 dirs[0].dir_idx = 0;
6506 dirs[0].used = 0;
6507 files[1].dir_idx = 0;
6508 ndirs = 1;
6510 for (i = 2; i < (int) file_table.in_use; ++i)
6511 if (files[i].fname - files[i].path == dirs[ndirs - 1].length
6512 && memcmp (dirs[ndirs - 1].path, files[i].path,
6513 dirs[ndirs - 1].length) == 0)
6515 /* Same directory as last entry. */
6516 files[i].dir_idx = ndirs - 1;
6517 ++dirs[ndirs - 1].count;
6519 else
6521 int j;
6523 /* This is a new directory. */
6524 dirs[ndirs].path = files[i].path;
6525 dirs[ndirs].length = files[i].fname - files[i].path;
6526 dirs[ndirs].count = 1;
6527 dirs[ndirs].dir_idx = ndirs;
6528 dirs[ndirs].used = 0;
6529 files[i].dir_idx = ndirs;
6531 /* Search for a prefix. */
6532 dirs[ndirs].prefix = -1;
6533 for (j = 0; j < ndirs; ++j)
6534 if (dirs[j].length < dirs[ndirs].length
6535 && dirs[j].length > 1
6536 && (dirs[ndirs].prefix == -1
6537 || dirs[j].length > dirs[dirs[ndirs].prefix].length)
6538 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0)
6539 dirs[ndirs].prefix = j;
6541 ++ndirs;
6544 /* Now to the actual work. We have to find a subset of the
6545 directories which allow expressing the file name using references
6546 to the directory table with the least amount of characters. We
6547 do not do an exhaustive search where we would have to check out
6548 every combination of every single possible prefix. Instead we
6549 use a heuristic which provides nearly optimal results in most
6550 cases and never is much off. */
6551 saved = (int *) alloca (ndirs * sizeof (int));
6552 savehere = (int *) alloca (ndirs * sizeof (int));
6554 memset (saved, '\0', ndirs * sizeof (saved[0]));
6555 for (i = 0; i < ndirs; ++i)
6557 int j;
6558 int total;
6560 /* We can always save some space for the current directory. But
6561 this does not mean it will be enough to justify adding the
6562 directory. */
6563 savehere[i] = dirs[i].length;
6564 total = (savehere[i] - saved[i]) * dirs[i].count;
6566 for (j = i + 1; j < ndirs; ++j)
6568 savehere[j] = 0;
6570 if (saved[j] < dirs[i].length)
6572 /* Determine whether the dirs[i] path is a prefix of the
6573 dirs[j] path. */
6574 int k;
6576 k = dirs[j].prefix;
6577 while (k != -1 && k != i)
6578 k = dirs[k].prefix;
6580 if (k == i)
6582 /* Yes it is. We can possibly safe some memory but
6583 writing the filenames in dirs[j] relative to
6584 dirs[i]. */
6585 savehere[j] = dirs[i].length;
6586 total += (savehere[j] - saved[j]) * dirs[j].count;
6591 /* Check whether we can safe enough to justify adding the dirs[i]
6592 directory. */
6593 if (total > dirs[i].length + 1)
6595 /* It's worthwhile adding. */
6596 for (j = i; j < ndirs; ++j)
6597 if (savehere[j] > 0)
6599 /* Remember how much we saved for this directory so far. */
6600 saved[j] = savehere[j];
6602 /* Remember the prefix directory. */
6603 dirs[j].dir_idx = i;
6608 /* We have to emit them in the order they appear in the file_table
6609 array since the index is used in the debug info generation. To
6610 do this efficiently we generate a back-mapping of the indices
6611 first. */
6612 backmap = (int *) alloca (file_table.in_use * sizeof (int));
6613 for (i = 1; i < (int) file_table.in_use; ++i)
6615 backmap[files[i].file_idx] = i;
6616 /* Mark this directory as used. */
6617 dirs[dirs[files[i].dir_idx].dir_idx].used = 1;
6620 /* That was it. We are ready to emit the information. First the
6621 directory name table. Here we have to make sure that the first
6622 actually emitted directory name has the index one. Zero is
6623 reserved for the current working directory. Make sure we do not
6624 confuse these indices with the one for the constructed table
6625 (even though most of the time they are identical). */
6626 idx = 1;
6627 idx_offset = dirs[0].length > 0 ? 1 : 0;
6628 for (i = 1 - idx_offset; i < ndirs; ++i)
6629 if (dirs[i].used != 0)
6631 dirs[i].used = idx++;
6632 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1,
6633 "Directory Entry: 0x%x", dirs[i].used);
6635 dw2_asm_output_data (1, 0, "End directory table");
6637 /* Correct the index for the current working directory entry if it
6638 exists. */
6639 if (idx_offset == 0)
6640 dirs[0].used = 0;
6642 /* Now write all the file names. */
6643 for (i = 1; i < (int) file_table.in_use; ++i)
6645 int file_idx = backmap[i];
6646 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx;
6648 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1,
6649 "File Entry: 0x%x", i);
6651 /* Include directory index. */
6652 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL);
6654 /* Modification time. */
6655 dw2_asm_output_data_uleb128 (0, NULL);
6657 /* File length in bytes. */
6658 dw2_asm_output_data_uleb128 (0, NULL);
6660 dw2_asm_output_data (1, 0, "End file name table");
6664 /* Output the source line number correspondence information. This
6665 information goes into the .debug_line section. */
6667 static void
6668 output_line_info ()
6670 char l1[20], l2[20], p1[20], p2[20];
6671 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6672 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
6673 register unsigned opc;
6674 register unsigned n_op_args;
6675 register unsigned long lt_index;
6676 register unsigned long current_line;
6677 register long line_offset;
6678 register long line_delta;
6679 register unsigned long current_file;
6680 register unsigned long function;
6682 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0);
6683 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0);
6684 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0);
6685 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0);
6687 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1,
6688 "Length of Source Line Info");
6689 ASM_OUTPUT_LABEL (asm_out_file, l1);
6691 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version");
6693 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length");
6694 ASM_OUTPUT_LABEL (asm_out_file, p1);
6696 dw2_asm_output_data (1, DWARF_LINE_MIN_INSTR_LENGTH,
6697 "Minimum Instruction Length");
6699 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START,
6700 "Default is_stmt_start flag");
6702 dw2_asm_output_data (1, DWARF_LINE_BASE,
6703 "Line Base Value (Special Opcodes)");
6705 dw2_asm_output_data (1, DWARF_LINE_RANGE,
6706 "Line Range Value (Special Opcodes)");
6708 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE,
6709 "Special Opcode Base");
6711 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
6713 switch (opc)
6715 case DW_LNS_advance_pc:
6716 case DW_LNS_advance_line:
6717 case DW_LNS_set_file:
6718 case DW_LNS_set_column:
6719 case DW_LNS_fixed_advance_pc:
6720 n_op_args = 1;
6721 break;
6722 default:
6723 n_op_args = 0;
6724 break;
6727 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args",
6728 opc, n_op_args);
6731 /* Write out the information about the files we use. */
6732 output_file_names ();
6733 ASM_OUTPUT_LABEL (asm_out_file, p2);
6735 /* We used to set the address register to the first location in the text
6736 section here, but that didn't accomplish anything since we already
6737 have a line note for the opening brace of the first function. */
6739 /* Generate the line number to PC correspondence table, encoded as
6740 a series of state machine operations. */
6741 current_file = 1;
6742 current_line = 1;
6743 strcpy (prev_line_label, text_section_label);
6744 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
6746 register dw_line_info_ref line_info = &line_info_table[lt_index];
6748 #if 0
6749 /* Disable this optimization for now; GDB wants to see two line notes
6750 at the beginning of a function so it can find the end of the
6751 prologue. */
6753 /* Don't emit anything for redundant notes. Just updating the
6754 address doesn't accomplish anything, because we already assume
6755 that anything after the last address is this line. */
6756 if (line_info->dw_line_num == current_line
6757 && line_info->dw_file_num == current_file)
6758 continue;
6759 #endif
6761 /* Emit debug info for the address of the current line.
6763 Unfortunately, we have little choice here currently, and must always
6764 use the most general form. Gcc does not know the address delta
6765 itself, so we can't use DW_LNS_advance_pc. Many ports do have length
6766 attributes which will give an upper bound on the address range. We
6767 could perhaps use length attributes to determine when it is safe to
6768 use DW_LNS_fixed_advance_pc. */
6770 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
6771 if (0)
6773 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
6774 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6775 "DW_LNS_fixed_advance_pc");
6776 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6778 else
6780 /* This can handle any delta. This takes
6781 4+DWARF2_ADDR_SIZE bytes. */
6782 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6783 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6784 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6785 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6787 strcpy (prev_line_label, line_label);
6789 /* Emit debug info for the source file of the current line, if
6790 different from the previous line. */
6791 if (line_info->dw_file_num != current_file)
6793 current_file = line_info->dw_file_num;
6794 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6795 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6796 file_table.table[current_file]);
6799 /* Emit debug info for the current line number, choosing the encoding
6800 that uses the least amount of space. */
6801 if (line_info->dw_line_num != current_line)
6803 line_offset = line_info->dw_line_num - current_line;
6804 line_delta = line_offset - DWARF_LINE_BASE;
6805 current_line = line_info->dw_line_num;
6806 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6808 /* This can handle deltas from -10 to 234, using the current
6809 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
6810 takes 1 byte. */
6811 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6812 "line %lu", current_line);
6814 else
6816 /* This can handle any delta. This takes at least 4 bytes,
6817 depending on the value being encoded. */
6818 dw2_asm_output_data (1, DW_LNS_advance_line,
6819 "advance to line %lu", current_line);
6820 dw2_asm_output_data_sleb128 (line_offset, NULL);
6821 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6824 else
6826 /* We still need to start a new row, so output a copy insn. */
6827 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6831 /* Emit debug info for the address of the end of the function. */
6832 if (0)
6834 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6835 "DW_LNS_fixed_advance_pc");
6836 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL);
6838 else
6840 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6841 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6842 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6843 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL);
6846 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6847 dw2_asm_output_data_uleb128 (1, NULL);
6848 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6850 function = 0;
6851 current_file = 1;
6852 current_line = 1;
6853 for (lt_index = 0; lt_index < separate_line_info_table_in_use;)
6855 register dw_separate_line_info_ref line_info
6856 = &separate_line_info_table[lt_index];
6858 #if 0
6859 /* Don't emit anything for redundant notes. */
6860 if (line_info->dw_line_num == current_line
6861 && line_info->dw_file_num == current_file
6862 && line_info->function == function)
6863 goto cont;
6864 #endif
6866 /* Emit debug info for the address of the current line. If this is
6867 a new function, or the first line of a function, then we need
6868 to handle it differently. */
6869 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
6870 lt_index);
6871 if (function != line_info->function)
6873 function = line_info->function;
6875 /* Set the address register to the first line in the function */
6876 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6877 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6878 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6879 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6881 else
6883 /* ??? See the DW_LNS_advance_pc comment above. */
6884 if (0)
6886 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6887 "DW_LNS_fixed_advance_pc");
6888 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6890 else
6892 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6893 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6894 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6895 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6898 strcpy (prev_line_label, line_label);
6900 /* Emit debug info for the source file of the current line, if
6901 different from the previous line. */
6902 if (line_info->dw_file_num != current_file)
6904 current_file = line_info->dw_file_num;
6905 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file");
6906 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")",
6907 file_table.table[current_file]);
6910 /* Emit debug info for the current line number, choosing the encoding
6911 that uses the least amount of space. */
6912 if (line_info->dw_line_num != current_line)
6914 line_offset = line_info->dw_line_num - current_line;
6915 line_delta = line_offset - DWARF_LINE_BASE;
6916 current_line = line_info->dw_line_num;
6917 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
6918 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta,
6919 "line %lu", current_line);
6920 else
6922 dw2_asm_output_data (1, DW_LNS_advance_line,
6923 "advance to line %lu", current_line);
6924 dw2_asm_output_data_sleb128 (line_offset, NULL);
6925 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6928 else
6929 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy");
6931 #if 0
6932 cont:
6933 #endif
6934 ++lt_index;
6936 /* If we're done with a function, end its sequence. */
6937 if (lt_index == separate_line_info_table_in_use
6938 || separate_line_info_table[lt_index].function != function)
6940 current_file = 1;
6941 current_line = 1;
6943 /* Emit debug info for the address of the end of the function. */
6944 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
6945 if (0)
6947 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc,
6948 "DW_LNS_fixed_advance_pc");
6949 dw2_asm_output_delta (2, line_label, prev_line_label, NULL);
6951 else
6953 dw2_asm_output_data (1, 0, "DW_LNE_set_address");
6954 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL);
6955 dw2_asm_output_data (1, DW_LNE_set_address, NULL);
6956 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL);
6959 /* Output the marker for the end of this sequence. */
6960 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence");
6961 dw2_asm_output_data_uleb128 (1, NULL);
6962 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL);
6966 /* Output the marker for the end of the line number info. */
6967 ASM_OUTPUT_LABEL (asm_out_file, l2);
6970 /* Given a pointer to a tree node for some base type, return a pointer to
6971 a DIE that describes the given type.
6973 This routine must only be called for GCC type nodes that correspond to
6974 Dwarf base (fundamental) types. */
6976 static dw_die_ref
6977 base_type_die (type)
6978 register tree type;
6980 register dw_die_ref base_type_result;
6981 register const char *type_name;
6982 register enum dwarf_type encoding;
6983 register tree name = TYPE_NAME (type);
6985 if (TREE_CODE (type) == ERROR_MARK
6986 || TREE_CODE (type) == VOID_TYPE)
6987 return 0;
6989 if (name)
6991 if (TREE_CODE (name) == TYPE_DECL)
6992 name = DECL_NAME (name);
6994 type_name = IDENTIFIER_POINTER (name);
6996 else
6997 type_name = "__unknown__";
6999 switch (TREE_CODE (type))
7001 case INTEGER_TYPE:
7002 /* Carefully distinguish the C character types, without messing
7003 up if the language is not C. Note that we check only for the names
7004 that contain spaces; other names might occur by coincidence in other
7005 languages. */
7006 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
7007 && (type == char_type_node
7008 || ! strcmp (type_name, "signed char")
7009 || ! strcmp (type_name, "unsigned char"))))
7011 if (TREE_UNSIGNED (type))
7012 encoding = DW_ATE_unsigned;
7013 else
7014 encoding = DW_ATE_signed;
7015 break;
7017 /* else fall through. */
7019 case CHAR_TYPE:
7020 /* GNU Pascal/Ada CHAR type. Not used in C. */
7021 if (TREE_UNSIGNED (type))
7022 encoding = DW_ATE_unsigned_char;
7023 else
7024 encoding = DW_ATE_signed_char;
7025 break;
7027 case REAL_TYPE:
7028 encoding = DW_ATE_float;
7029 break;
7031 /* Dwarf2 doesn't know anything about complex ints, so use
7032 a user defined type for it. */
7033 case COMPLEX_TYPE:
7034 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
7035 encoding = DW_ATE_complex_float;
7036 else
7037 encoding = DW_ATE_lo_user;
7038 break;
7040 case BOOLEAN_TYPE:
7041 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
7042 encoding = DW_ATE_boolean;
7043 break;
7045 default:
7046 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
7049 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
7050 if (demangle_name_func)
7051 type_name = (*demangle_name_func) (type_name);
7053 add_AT_string (base_type_result, DW_AT_name, type_name);
7054 add_AT_unsigned (base_type_result, DW_AT_byte_size,
7055 int_size_in_bytes (type));
7056 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
7058 return base_type_result;
7061 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
7062 the Dwarf "root" type for the given input type. The Dwarf "root" type of
7063 a given type is generally the same as the given type, except that if the
7064 given type is a pointer or reference type, then the root type of the given
7065 type is the root type of the "basis" type for the pointer or reference
7066 type. (This definition of the "root" type is recursive.) Also, the root
7067 type of a `const' qualified type or a `volatile' qualified type is the
7068 root type of the given type without the qualifiers. */
7070 static tree
7071 root_type (type)
7072 register tree type;
7074 if (TREE_CODE (type) == ERROR_MARK)
7075 return error_mark_node;
7077 switch (TREE_CODE (type))
7079 case ERROR_MARK:
7080 return error_mark_node;
7082 case POINTER_TYPE:
7083 case REFERENCE_TYPE:
7084 return type_main_variant (root_type (TREE_TYPE (type)));
7086 default:
7087 return type_main_variant (type);
7091 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
7092 given input type is a Dwarf "fundamental" type. Otherwise return null. */
7094 static inline int
7095 is_base_type (type)
7096 register tree type;
7098 switch (TREE_CODE (type))
7100 case ERROR_MARK:
7101 case VOID_TYPE:
7102 case INTEGER_TYPE:
7103 case REAL_TYPE:
7104 case COMPLEX_TYPE:
7105 case BOOLEAN_TYPE:
7106 case CHAR_TYPE:
7107 return 1;
7109 case SET_TYPE:
7110 case ARRAY_TYPE:
7111 case RECORD_TYPE:
7112 case UNION_TYPE:
7113 case QUAL_UNION_TYPE:
7114 case ENUMERAL_TYPE:
7115 case FUNCTION_TYPE:
7116 case METHOD_TYPE:
7117 case POINTER_TYPE:
7118 case REFERENCE_TYPE:
7119 case FILE_TYPE:
7120 case OFFSET_TYPE:
7121 case LANG_TYPE:
7122 case VECTOR_TYPE:
7123 return 0;
7125 default:
7126 abort ();
7129 return 0;
7132 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
7133 entry that chains various modifiers in front of the given type. */
7135 static dw_die_ref
7136 modified_type_die (type, is_const_type, is_volatile_type, context_die)
7137 register tree type;
7138 register int is_const_type;
7139 register int is_volatile_type;
7140 register dw_die_ref context_die;
7142 register enum tree_code code = TREE_CODE (type);
7143 register dw_die_ref mod_type_die = NULL;
7144 register dw_die_ref sub_die = NULL;
7145 register tree item_type = NULL;
7147 if (code != ERROR_MARK)
7149 tree qualified_type;
7151 /* See if we already have the appropriately qualified variant of
7152 this type. */
7153 qualified_type
7154 = get_qualified_type (type,
7155 ((is_const_type ? TYPE_QUAL_CONST : 0)
7156 | (is_volatile_type
7157 ? TYPE_QUAL_VOLATILE : 0)));
7158 /* If we do, then we can just use its DIE, if it exists. */
7159 if (qualified_type)
7161 mod_type_die = lookup_type_die (qualified_type);
7162 if (mod_type_die)
7163 return mod_type_die;
7166 /* Handle C typedef types. */
7167 if (qualified_type && TYPE_NAME (qualified_type)
7168 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL
7169 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type)))
7171 tree type_name = TYPE_NAME (qualified_type);
7172 tree dtype = TREE_TYPE (type_name);
7173 if (qualified_type == dtype)
7175 /* For a named type, use the typedef. */
7176 gen_type_die (qualified_type, context_die);
7177 mod_type_die = lookup_type_die (qualified_type);
7180 else if (is_const_type < TYPE_READONLY (dtype)
7181 || is_volatile_type < TYPE_VOLATILE (dtype))
7182 /* cv-unqualified version of named type. Just use the unnamed
7183 type to which it refers. */
7184 mod_type_die
7185 = modified_type_die (DECL_ORIGINAL_TYPE (type_name),
7186 is_const_type, is_volatile_type,
7187 context_die);
7188 /* Else cv-qualified version of named type; fall through. */
7191 if (mod_type_die)
7192 /* OK. */
7194 else if (is_const_type)
7196 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
7197 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
7199 else if (is_volatile_type)
7201 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
7202 sub_die = modified_type_die (type, 0, 0, context_die);
7204 else if (code == POINTER_TYPE)
7206 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
7207 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7208 #if 0
7209 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7210 #endif
7211 item_type = TREE_TYPE (type);
7213 else if (code == REFERENCE_TYPE)
7215 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
7216 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
7217 #if 0
7218 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
7219 #endif
7220 item_type = TREE_TYPE (type);
7222 else if (is_base_type (type))
7223 mod_type_die = base_type_die (type);
7224 else
7226 gen_type_die (type, context_die);
7228 /* We have to get the type_main_variant here (and pass that to the
7229 `lookup_type_die' routine) because the ..._TYPE node we have
7230 might simply be a *copy* of some original type node (where the
7231 copy was created to help us keep track of typedef names) and
7232 that copy might have a different TYPE_UID from the original
7233 ..._TYPE node. */
7234 mod_type_die = lookup_type_die (type_main_variant (type));
7235 if (mod_type_die == NULL)
7236 abort ();
7239 /* We want to equate the qualified type to the die below. */
7240 if (qualified_type)
7241 type = qualified_type;
7244 equate_type_number_to_die (type, mod_type_die);
7245 if (item_type)
7246 /* We must do this after the equate_type_number_to_die call, in case
7247 this is a recursive type. This ensures that the modified_type_die
7248 recursion will terminate even if the type is recursive. Recursive
7249 types are possible in Ada. */
7250 sub_die = modified_type_die (item_type,
7251 TYPE_READONLY (item_type),
7252 TYPE_VOLATILE (item_type),
7253 context_die);
7255 if (sub_die != NULL)
7256 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
7258 return mod_type_die;
7261 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
7262 an enumerated type. */
7264 static inline int
7265 type_is_enum (type)
7266 register tree type;
7268 return TREE_CODE (type) == ENUMERAL_TYPE;
7271 /* Return the register number described by a given RTL node. */
7273 static unsigned int
7274 reg_number (rtl)
7275 register rtx rtl;
7277 register unsigned regno = REGNO (rtl);
7279 if (regno >= FIRST_PSEUDO_REGISTER)
7281 warning ("internal regno botch: regno = %d\n", regno);
7282 regno = 0;
7285 regno = DBX_REGISTER_NUMBER (regno);
7286 return regno;
7289 /* Return a location descriptor that designates a machine register. */
7291 static dw_loc_descr_ref
7292 reg_loc_descriptor (rtl)
7293 register rtx rtl;
7295 register dw_loc_descr_ref loc_result = NULL;
7296 register unsigned reg = reg_number (rtl);
7298 if (reg <= 31)
7299 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
7300 else
7301 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
7303 return loc_result;
7306 /* Return a location descriptor that designates a constant. */
7308 static dw_loc_descr_ref
7309 int_loc_descriptor (i)
7310 HOST_WIDE_INT i;
7312 enum dwarf_location_atom op;
7314 /* Pick the smallest representation of a constant, rather than just
7315 defaulting to the LEB encoding. */
7316 if (i >= 0)
7318 if (i <= 31)
7319 op = DW_OP_lit0 + i;
7320 else if (i <= 0xff)
7321 op = DW_OP_const1u;
7322 else if (i <= 0xffff)
7323 op = DW_OP_const2u;
7324 else if (HOST_BITS_PER_WIDE_INT == 32
7325 || i <= 0xffffffff)
7326 op = DW_OP_const4u;
7327 else
7328 op = DW_OP_constu;
7330 else
7332 if (i >= -0x80)
7333 op = DW_OP_const1s;
7334 else if (i >= -0x8000)
7335 op = DW_OP_const2s;
7336 else if (HOST_BITS_PER_WIDE_INT == 32
7337 || i >= -0x80000000)
7338 op = DW_OP_const4s;
7339 else
7340 op = DW_OP_consts;
7343 return new_loc_descr (op, i, 0);
7346 /* Return a location descriptor that designates a base+offset location. */
7348 static dw_loc_descr_ref
7349 based_loc_descr (reg, offset)
7350 unsigned reg;
7351 long int offset;
7353 register dw_loc_descr_ref loc_result;
7354 /* For the "frame base", we use the frame pointer or stack pointer
7355 registers, since the RTL for local variables is relative to one of
7356 them. */
7357 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
7358 ? HARD_FRAME_POINTER_REGNUM
7359 : STACK_POINTER_REGNUM);
7361 if (reg == fp_reg)
7362 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
7363 else if (reg <= 31)
7364 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
7365 else
7366 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
7368 return loc_result;
7371 /* Return true if this RTL expression describes a base+offset calculation. */
7373 static inline int
7374 is_based_loc (rtl)
7375 register rtx rtl;
7377 return (GET_CODE (rtl) == PLUS
7378 && ((GET_CODE (XEXP (rtl, 0)) == REG
7379 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
7382 /* The following routine converts the RTL for a variable or parameter
7383 (resident in memory) into an equivalent Dwarf representation of a
7384 mechanism for getting the address of that same variable onto the top of a
7385 hypothetical "address evaluation" stack.
7387 When creating memory location descriptors, we are effectively transforming
7388 the RTL for a memory-resident object into its Dwarf postfix expression
7389 equivalent. This routine recursively descends an RTL tree, turning
7390 it into Dwarf postfix code as it goes.
7392 MODE is the mode of the memory reference, needed to handle some
7393 autoincrement addressing modes. */
7395 static dw_loc_descr_ref
7396 mem_loc_descriptor (rtl, mode)
7397 register rtx rtl;
7398 enum machine_mode mode;
7400 dw_loc_descr_ref mem_loc_result = NULL;
7401 /* Note that for a dynamically sized array, the location we will generate a
7402 description of here will be the lowest numbered location which is
7403 actually within the array. That's *not* necessarily the same as the
7404 zeroth element of the array. */
7406 #ifdef ASM_SIMPLIFY_DWARF_ADDR
7407 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
7408 #endif
7410 switch (GET_CODE (rtl))
7412 case POST_INC:
7413 case POST_DEC:
7414 case POST_MODIFY:
7415 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
7416 just fall into the SUBREG code. */
7418 /* Fall through. */
7420 case SUBREG:
7421 /* The case of a subreg may arise when we have a local (register)
7422 variable or a formal (register) parameter which doesn't quite fill
7423 up an entire register. For now, just assume that it is
7424 legitimate to make the Dwarf info refer to the whole register which
7425 contains the given subreg. */
7426 rtl = SUBREG_REG (rtl);
7428 /* Fall through. */
7430 case REG:
7431 /* Whenever a register number forms a part of the description of the
7432 method for calculating the (dynamic) address of a memory resident
7433 object, DWARF rules require the register number be referred to as
7434 a "base register". This distinction is not based in any way upon
7435 what category of register the hardware believes the given register
7436 belongs to. This is strictly DWARF terminology we're dealing with
7437 here. Note that in cases where the location of a memory-resident
7438 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
7439 OP_CONST (0)) the actual DWARF location descriptor that we generate
7440 may just be OP_BASEREG (basereg). This may look deceptively like
7441 the object in question was allocated to a register (rather than in
7442 memory) so DWARF consumers need to be aware of the subtle
7443 distinction between OP_REG and OP_BASEREG. */
7444 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
7445 break;
7447 case MEM:
7448 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7449 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
7450 break;
7452 case LABEL_REF:
7453 /* Some ports can transform a symbol ref into a label ref, because
7454 the symbol ref is too far away and has to be dumped into a constant
7455 pool. */
7456 case CONST:
7457 case SYMBOL_REF:
7458 /* Alternatively, the symbol in the constant pool might be referenced
7459 by a different symbol. */
7460 if (GET_CODE (rtl) == SYMBOL_REF
7461 && CONSTANT_POOL_ADDRESS_P (rtl))
7463 rtx tmp = get_pool_constant (rtl);
7464 if (GET_CODE (tmp) == SYMBOL_REF)
7465 rtl = tmp;
7468 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
7469 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
7470 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
7471 break;
7473 case PRE_MODIFY:
7474 /* Extract the PLUS expression nested inside and fall into
7475 PLUS code below. */
7476 rtl = XEXP (rtl, 1);
7477 goto plus;
7479 case PRE_INC:
7480 case PRE_DEC:
7481 /* Turn these into a PLUS expression and fall into the PLUS code
7482 below. */
7483 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
7484 GEN_INT (GET_CODE (rtl) == PRE_INC
7485 ? GET_MODE_UNIT_SIZE (mode)
7486 : -GET_MODE_UNIT_SIZE (mode)));
7488 /* Fall through. */
7490 case PLUS:
7491 plus:
7492 if (is_based_loc (rtl))
7493 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
7494 INTVAL (XEXP (rtl, 1)));
7495 else
7497 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
7499 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT
7500 && INTVAL (XEXP (rtl, 1)) >= 0)
7502 add_loc_descr (&mem_loc_result,
7503 new_loc_descr (DW_OP_plus_uconst,
7504 INTVAL (XEXP (rtl, 1)), 0));
7506 else
7508 add_loc_descr (&mem_loc_result,
7509 mem_loc_descriptor (XEXP (rtl, 1), mode));
7510 add_loc_descr (&mem_loc_result,
7511 new_loc_descr (DW_OP_plus, 0, 0));
7514 break;
7516 case MULT:
7517 /* If a pseudo-reg is optimized away, it is possible for it to
7518 be replaced with a MEM containing a multiply. */
7519 add_loc_descr (&mem_loc_result,
7520 mem_loc_descriptor (XEXP (rtl, 0), mode));
7521 add_loc_descr (&mem_loc_result,
7522 mem_loc_descriptor (XEXP (rtl, 1), mode));
7523 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
7524 break;
7526 case CONST_INT:
7527 mem_loc_result = int_loc_descriptor (INTVAL (rtl));
7528 break;
7530 default:
7531 abort ();
7534 return mem_loc_result;
7537 /* Return a descriptor that describes the concatenation of two locations.
7538 This is typically a complex variable. */
7540 static dw_loc_descr_ref
7541 concat_loc_descriptor (x0, x1)
7542 register rtx x0, x1;
7544 dw_loc_descr_ref cc_loc_result = NULL;
7546 if (!is_pseudo_reg (x0)
7547 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
7548 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
7549 add_loc_descr (&cc_loc_result,
7550 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
7552 if (!is_pseudo_reg (x1)
7553 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
7554 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
7555 add_loc_descr (&cc_loc_result,
7556 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
7558 return cc_loc_result;
7561 /* Output a proper Dwarf location descriptor for a variable or parameter
7562 which is either allocated in a register or in a memory location. For a
7563 register, we just generate an OP_REG and the register number. For a
7564 memory location we provide a Dwarf postfix expression describing how to
7565 generate the (dynamic) address of the object onto the address stack. */
7567 static dw_loc_descr_ref
7568 loc_descriptor (rtl)
7569 register rtx rtl;
7571 dw_loc_descr_ref loc_result = NULL;
7572 switch (GET_CODE (rtl))
7574 case SUBREG:
7575 /* The case of a subreg may arise when we have a local (register)
7576 variable or a formal (register) parameter which doesn't quite fill
7577 up an entire register. For now, just assume that it is
7578 legitimate to make the Dwarf info refer to the whole register which
7579 contains the given subreg. */
7580 rtl = SUBREG_REG (rtl);
7582 /* Fall through. */
7584 case REG:
7585 loc_result = reg_loc_descriptor (rtl);
7586 break;
7588 case MEM:
7589 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
7590 break;
7592 case CONCAT:
7593 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
7594 break;
7596 default:
7597 abort ();
7600 return loc_result;
7603 /* Similar, but generate the descriptor from trees instead of rtl.
7604 This comes up particularly with variable length arrays. */
7606 static dw_loc_descr_ref
7607 loc_descriptor_from_tree (loc, addressp)
7608 tree loc;
7609 int addressp;
7611 dw_loc_descr_ref ret = NULL;
7612 int indirect_size = 0;
7613 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc));
7614 enum dwarf_location_atom op;
7616 /* ??? Most of the time we do not take proper care for sign/zero
7617 extending the values properly. Hopefully this won't be a real
7618 problem... */
7620 switch (TREE_CODE (loc))
7622 case ERROR_MARK:
7623 break;
7625 case WITH_RECORD_EXPR:
7626 /* This case involves extracting fields from an object to determine the
7627 position of other fields. We don't try to encode this here. The
7628 only user of this is Ada, which encodes the needed information using
7629 the names of types. */
7630 return ret;
7632 case VAR_DECL:
7633 case PARM_DECL:
7635 rtx rtl = rtl_for_decl_location (loc);
7636 enum machine_mode mode = DECL_MODE (loc);
7638 if (rtl == NULL_RTX)
7639 break;
7640 else if (CONSTANT_P (rtl))
7642 ret = new_loc_descr (DW_OP_addr, 0, 0);
7643 ret->dw_loc_oprnd1.val_class = dw_val_class_addr;
7644 ret->dw_loc_oprnd1.v.val_addr = rtl;
7645 indirect_size = GET_MODE_SIZE (mode);
7647 else
7649 if (GET_CODE (rtl) == MEM)
7651 indirect_size = GET_MODE_SIZE (mode);
7652 rtl = XEXP (rtl, 0);
7654 ret = mem_loc_descriptor (rtl, mode);
7657 break;
7659 case INDIRECT_REF:
7660 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7661 indirect_size = GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (loc)));
7662 break;
7664 case NOP_EXPR:
7665 case CONVERT_EXPR:
7666 case NON_LVALUE_EXPR:
7667 case SAVE_EXPR:
7668 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp);
7670 case COMPONENT_REF:
7671 case BIT_FIELD_REF:
7672 case ARRAY_REF:
7673 case ARRAY_RANGE_REF:
7675 tree obj, offset;
7676 HOST_WIDE_INT bitsize, bitpos, bytepos;
7677 enum machine_mode mode;
7678 int volatilep;
7679 unsigned int alignment;
7681 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode,
7682 &unsignedp, &volatilep, &alignment);
7683 ret = loc_descriptor_from_tree (obj, 1);
7685 if (offset != NULL_TREE)
7687 /* Variable offset. */
7688 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0));
7689 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7692 if (addressp)
7694 /* We cannot address anything not on a unit boundary. */
7695 if (bitpos % BITS_PER_UNIT != 0)
7696 abort ();
7698 else
7700 if (bitpos % BITS_PER_UNIT != 0
7701 || bitsize % BITS_PER_UNIT != 0)
7703 /* ??? We could handle this by loading and shifting etc.
7704 Wait until someone needs it before expending the effort. */
7705 abort ();
7708 indirect_size = bitsize / BITS_PER_UNIT;
7711 bytepos = bitpos / BITS_PER_UNIT;
7712 if (bytepos > 0)
7713 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0));
7714 else if (bytepos < 0)
7716 add_loc_descr (&ret, int_loc_descriptor (bytepos));
7717 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0));
7719 break;
7722 case INTEGER_CST:
7723 if (host_integerp (loc, 0))
7724 ret = int_loc_descriptor (tree_low_cst (loc, 0));
7725 break;
7727 case BIT_AND_EXPR:
7728 op = DW_OP_and;
7729 goto do_binop;
7730 case BIT_XOR_EXPR:
7731 op = DW_OP_xor;
7732 goto do_binop;
7733 case BIT_IOR_EXPR:
7734 op = DW_OP_or;
7735 goto do_binop;
7736 case TRUNC_DIV_EXPR:
7737 op = DW_OP_div;
7738 goto do_binop;
7739 case MINUS_EXPR:
7740 op = DW_OP_minus;
7741 goto do_binop;
7742 case TRUNC_MOD_EXPR:
7743 op = DW_OP_mod;
7744 goto do_binop;
7745 case MULT_EXPR:
7746 op = DW_OP_mul;
7747 goto do_binop;
7748 case LSHIFT_EXPR:
7749 op = DW_OP_shl;
7750 goto do_binop;
7751 case RSHIFT_EXPR:
7752 op = (unsignedp ? DW_OP_shr : DW_OP_shra);
7753 goto do_binop;
7754 case PLUS_EXPR:
7755 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST
7756 && host_integerp (TREE_OPERAND (loc, 1), 0))
7758 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7759 add_loc_descr (&ret,
7760 new_loc_descr (DW_OP_plus_uconst,
7761 tree_low_cst (TREE_OPERAND (loc, 1),
7763 0));
7764 break;
7766 op = DW_OP_plus;
7767 goto do_binop;
7768 case LE_EXPR:
7769 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7770 break;
7771 op = DW_OP_le;
7772 goto do_binop;
7773 case GE_EXPR:
7774 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7775 break;
7776 op = DW_OP_ge;
7777 goto do_binop;
7778 case LT_EXPR:
7779 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7780 break;
7781 op = DW_OP_lt;
7782 goto do_binop;
7783 case GT_EXPR:
7784 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0))))
7785 break;
7786 op = DW_OP_gt;
7787 goto do_binop;
7788 case EQ_EXPR:
7789 op = DW_OP_eq;
7790 goto do_binop;
7791 case NE_EXPR:
7792 op = DW_OP_ne;
7793 goto do_binop;
7795 do_binop:
7796 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7797 add_loc_descr (&ret, loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0));
7798 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7799 break;
7801 case BIT_NOT_EXPR:
7802 op = DW_OP_not;
7803 goto do_unop;
7804 case ABS_EXPR:
7805 op = DW_OP_abs;
7806 goto do_unop;
7807 case NEGATE_EXPR:
7808 op = DW_OP_neg;
7809 goto do_unop;
7811 do_unop:
7812 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7813 add_loc_descr (&ret, new_loc_descr (op, 0, 0));
7814 break;
7816 case MAX_EXPR:
7817 loc = build (COND_EXPR, TREE_TYPE (loc),
7818 build (LT_EXPR, integer_type_node,
7819 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)),
7820 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0));
7821 /* FALLTHRU */
7823 case COND_EXPR:
7825 dw_loc_descr_ref bra_node, jump_node, tmp;
7827 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0);
7828 bra_node = new_loc_descr (DW_OP_bra, 0, 0);
7829 add_loc_descr (&ret, bra_node);
7831 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0);
7832 add_loc_descr (&ret, tmp);
7833 jump_node = new_loc_descr (DW_OP_skip, 0, 0);
7834 add_loc_descr (&ret, jump_node);
7836 tmp = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0);
7837 add_loc_descr (&ret, tmp);
7838 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7839 bra_node->dw_loc_oprnd1.v.val_loc = tmp;
7841 /* ??? Need a node to point the skip at. Use a nop. */
7842 tmp = new_loc_descr (DW_OP_nop, 0, 0);
7843 add_loc_descr (&ret, tmp);
7844 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc;
7845 jump_node->dw_loc_oprnd1.v.val_loc = tmp;
7847 break;
7849 default:
7850 abort ();
7853 /* If we can't fill the request for an address, die. */
7854 if (addressp && indirect_size == 0)
7855 abort ();
7857 /* If we've got an address and don't want one, dereference. */
7858 if (!addressp && indirect_size > 0)
7860 if (indirect_size > DWARF2_ADDR_SIZE)
7861 abort ();
7862 if (indirect_size == DWARF2_ADDR_SIZE)
7863 op = DW_OP_deref;
7864 else
7865 op = DW_OP_deref_size;
7866 add_loc_descr (&ret, new_loc_descr (op, indirect_size, 0));
7869 return ret;
7872 /* Given a value, round it up to the lowest multiple of `boundary'
7873 which is not less than the value itself. */
7875 static inline HOST_WIDE_INT
7876 ceiling (value, boundary)
7877 HOST_WIDE_INT value;
7878 unsigned int boundary;
7880 return (((value + boundary - 1) / boundary) * boundary);
7883 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
7884 pointer to the declared type for the relevant field variable, or return
7885 `integer_type_node' if the given node turns out to be an
7886 ERROR_MARK node. */
7888 static inline tree
7889 field_type (decl)
7890 register tree decl;
7892 register tree type;
7894 if (TREE_CODE (decl) == ERROR_MARK)
7895 return integer_type_node;
7897 type = DECL_BIT_FIELD_TYPE (decl);
7898 if (type == NULL_TREE)
7899 type = TREE_TYPE (decl);
7901 return type;
7904 /* Given a pointer to a tree node, return the alignment in bits for
7905 it, or else return BITS_PER_WORD if the node actually turns out to
7906 be an ERROR_MARK node. */
7908 static inline unsigned
7909 simple_type_align_in_bits (type)
7910 register tree type;
7912 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
7915 static inline unsigned
7916 simple_decl_align_in_bits (decl)
7917 register tree decl;
7919 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
7922 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
7923 node, return the size in bits for the type if it is a constant, or else
7924 return the alignment for the type if the type's size is not constant, or
7925 else return BITS_PER_WORD if the type actually turns out to be an
7926 ERROR_MARK node. */
7928 static inline unsigned HOST_WIDE_INT
7929 simple_type_size_in_bits (type)
7930 register tree type;
7932 tree type_size_tree;
7934 if (TREE_CODE (type) == ERROR_MARK)
7935 return BITS_PER_WORD;
7936 type_size_tree = TYPE_SIZE (type);
7938 if (type_size_tree == NULL_TREE)
7939 return 0;
7940 if (! host_integerp (type_size_tree, 1))
7941 return TYPE_ALIGN (type);
7942 return tree_low_cst (type_size_tree, 1);
7945 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
7946 return the byte offset of the lowest addressed byte of the "containing
7947 object" for the given FIELD_DECL, or return 0 if we are unable to
7948 determine what that offset is, either because the argument turns out to
7949 be a pointer to an ERROR_MARK node, or because the offset is actually
7950 variable. (We can't handle the latter case just yet). */
7952 static HOST_WIDE_INT
7953 field_byte_offset (decl)
7954 register tree decl;
7956 unsigned int type_align_in_bits;
7957 unsigned int decl_align_in_bits;
7958 unsigned HOST_WIDE_INT type_size_in_bits;
7959 HOST_WIDE_INT object_offset_in_bits;
7960 HOST_WIDE_INT object_offset_in_bytes;
7961 tree type;
7962 tree field_size_tree;
7963 HOST_WIDE_INT bitpos_int;
7964 HOST_WIDE_INT deepest_bitpos;
7965 unsigned HOST_WIDE_INT field_size_in_bits;
7967 if (TREE_CODE (decl) == ERROR_MARK)
7968 return 0;
7970 if (TREE_CODE (decl) != FIELD_DECL)
7971 abort ();
7973 type = field_type (decl);
7974 field_size_tree = DECL_SIZE (decl);
7976 /* The size could be unspecified if there was an error, or for
7977 a flexible array member. */
7978 if (! field_size_tree)
7979 field_size_tree = bitsize_zero_node;
7981 /* We cannot yet cope with fields whose positions are variable, so
7982 for now, when we see such things, we simply return 0. Someday, we may
7983 be able to handle such cases, but it will be damn difficult. */
7984 if (! host_integerp (bit_position (decl), 0))
7985 return 0;
7987 bitpos_int = int_bit_position (decl);
7989 /* If we don't know the size of the field, pretend it's a full word. */
7990 if (host_integerp (field_size_tree, 1))
7991 field_size_in_bits = tree_low_cst (field_size_tree, 1);
7992 else
7993 field_size_in_bits = BITS_PER_WORD;
7995 type_size_in_bits = simple_type_size_in_bits (type);
7996 type_align_in_bits = simple_type_align_in_bits (type);
7997 decl_align_in_bits = simple_decl_align_in_bits (decl);
7999 /* Note that the GCC front-end doesn't make any attempt to keep track of
8000 the starting bit offset (relative to the start of the containing
8001 structure type) of the hypothetical "containing object" for a bit-
8002 field. Thus, when computing the byte offset value for the start of the
8003 "containing object" of a bit-field, we must deduce this information on
8004 our own. This can be rather tricky to do in some cases. For example,
8005 handling the following structure type definition when compiling for an
8006 i386/i486 target (which only aligns long long's to 32-bit boundaries)
8007 can be very tricky:
8009 struct S { int field1; long long field2:31; };
8011 Fortunately, there is a simple rule-of-thumb which can be
8012 used in such cases. When compiling for an i386/i486, GCC will allocate
8013 8 bytes for the structure shown above. It decides to do this based upon
8014 one simple rule for bit-field allocation. Quite simply, GCC allocates
8015 each "containing object" for each bit-field at the first (i.e. lowest
8016 addressed) legitimate alignment boundary (based upon the required
8017 minimum alignment for the declared type of the field) which it can
8018 possibly use, subject to the condition that there is still enough
8019 available space remaining in the containing object (when allocated at
8020 the selected point) to fully accommodate all of the bits of the
8021 bit-field itself. This simple rule makes it obvious why GCC allocates
8022 8 bytes for each object of the structure type shown above. When looking
8023 for a place to allocate the "containing object" for `field2', the
8024 compiler simply tries to allocate a 64-bit "containing object" at each
8025 successive 32-bit boundary (starting at zero) until it finds a place to
8026 allocate that 64- bit field such that at least 31 contiguous (and
8027 previously unallocated) bits remain within that selected 64 bit field.
8028 (As it turns out, for the example above, the compiler finds that it is
8029 OK to allocate the "containing object" 64-bit field at bit-offset zero
8030 within the structure type.) Here we attempt to work backwards from the
8031 limited set of facts we're given, and we try to deduce from those facts,
8032 where GCC must have believed that the containing object started (within
8033 the structure type). The value we deduce is then used (by the callers of
8034 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
8035 for fields (both bit-fields and, in the case of DW_AT_location, regular
8036 fields as well). */
8038 /* Figure out the bit-distance from the start of the structure to the
8039 "deepest" bit of the bit-field. */
8040 deepest_bitpos = bitpos_int + field_size_in_bits;
8042 /* This is the tricky part. Use some fancy footwork to deduce where the
8043 lowest addressed bit of the containing object must be. */
8044 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8046 /* Round up to type_align by default. This works best for bitfields. */
8047 object_offset_in_bits += type_align_in_bits - 1;
8048 object_offset_in_bits /= type_align_in_bits;
8049 object_offset_in_bits *= type_align_in_bits;
8051 if (object_offset_in_bits > bitpos_int)
8053 /* Sigh, the decl must be packed. */
8054 object_offset_in_bits = deepest_bitpos - type_size_in_bits;
8056 /* Round up to decl_align instead. */
8057 object_offset_in_bits += decl_align_in_bits - 1;
8058 object_offset_in_bits /= decl_align_in_bits;
8059 object_offset_in_bits *= decl_align_in_bits;
8062 object_offset_in_bytes = object_offset_in_bits / BITS_PER_UNIT;
8064 return object_offset_in_bytes;
8067 /* The following routines define various Dwarf attributes and any data
8068 associated with them. */
8070 /* Add a location description attribute value to a DIE.
8072 This emits location attributes suitable for whole variables and
8073 whole parameters. Note that the location attributes for struct fields are
8074 generated by the routine `data_member_location_attribute' below. */
8076 static void
8077 add_AT_location_description (die, attr_kind, rtl)
8078 dw_die_ref die;
8079 enum dwarf_attribute attr_kind;
8080 register rtx rtl;
8082 /* Handle a special case. If we are about to output a location descriptor
8083 for a variable or parameter which has been optimized out of existence,
8084 don't do that. A variable which has been optimized out
8085 of existence will have a DECL_RTL value which denotes a pseudo-reg.
8086 Currently, in some rare cases, variables can have DECL_RTL values which
8087 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
8088 elsewhere in the compiler. We treat such cases as if the variable(s) in
8089 question had been optimized out of existence. */
8091 if (is_pseudo_reg (rtl)
8092 || (GET_CODE (rtl) == MEM
8093 && is_pseudo_reg (XEXP (rtl, 0)))
8094 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
8095 references the internal argument pointer (a pseudo) in a function
8096 where all references to the internal argument pointer were
8097 eliminated via the optimizers. */
8098 || (GET_CODE (rtl) == MEM
8099 && GET_CODE (XEXP (rtl, 0)) == PLUS
8100 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
8101 || (GET_CODE (rtl) == CONCAT
8102 && is_pseudo_reg (XEXP (rtl, 0))
8103 && is_pseudo_reg (XEXP (rtl, 1))))
8104 return;
8106 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
8109 /* Attach the specialized form of location attribute used for data
8110 members of struct and union types. In the special case of a
8111 FIELD_DECL node which represents a bit-field, the "offset" part
8112 of this special location descriptor must indicate the distance
8113 in bytes from the lowest-addressed byte of the containing struct
8114 or union type to the lowest-addressed byte of the "containing
8115 object" for the bit-field. (See the `field_byte_offset' function
8116 above).. For any given bit-field, the "containing object" is a
8117 hypothetical object (of some integral or enum type) within which
8118 the given bit-field lives. The type of this hypothetical
8119 "containing object" is always the same as the declared type of
8120 the individual bit-field itself (for GCC anyway... the DWARF
8121 spec doesn't actually mandate this). Note that it is the size
8122 (in bytes) of the hypothetical "containing object" which will
8123 be given in the DW_AT_byte_size attribute for this bit-field.
8124 (See the `byte_size_attribute' function below.) It is also used
8125 when calculating the value of the DW_AT_bit_offset attribute.
8126 (See the `bit_offset_attribute' function below). */
8128 static void
8129 add_data_member_location_attribute (die, decl)
8130 register dw_die_ref die;
8131 register tree decl;
8133 register unsigned long offset;
8134 register dw_loc_descr_ref loc_descr;
8135 register enum dwarf_location_atom op;
8137 if (TREE_CODE (decl) == TREE_VEC)
8138 offset = tree_low_cst (BINFO_OFFSET (decl), 0);
8139 else
8140 offset = field_byte_offset (decl);
8142 /* The DWARF2 standard says that we should assume that the structure address
8143 is already on the stack, so we can specify a structure field address
8144 by using DW_OP_plus_uconst. */
8146 #ifdef MIPS_DEBUGGING_INFO
8147 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
8148 correctly. It works only if we leave the offset on the stack. */
8149 op = DW_OP_constu;
8150 #else
8151 op = DW_OP_plus_uconst;
8152 #endif
8154 loc_descr = new_loc_descr (op, offset, 0);
8155 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
8158 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
8159 does not have a "location" either in memory or in a register. These
8160 things can arise in GNU C when a constant is passed as an actual parameter
8161 to an inlined function. They can also arise in C++ where declared
8162 constants do not necessarily get memory "homes". */
8164 static void
8165 add_const_value_attribute (die, rtl)
8166 register dw_die_ref die;
8167 register rtx rtl;
8169 switch (GET_CODE (rtl))
8171 case CONST_INT:
8172 /* Note that a CONST_INT rtx could represent either an integer
8173 or a floating-point constant. A CONST_INT is used whenever
8174 the constant will fit into a single word. In all such
8175 cases, the original mode of the constant value is wiped
8176 out, and the CONST_INT rtx is assigned VOIDmode. */
8178 HOST_WIDE_INT val = INTVAL (rtl);
8180 /* ??? We really should be using HOST_WIDE_INT throughout. */
8181 if (val < 0)
8183 if ((long) val != val)
8184 abort ();
8185 add_AT_int (die, DW_AT_const_value, (long) val);
8187 else
8189 if ((unsigned long) val != (unsigned HOST_WIDE_INT) val)
8190 abort ();
8191 add_AT_int (die, DW_AT_const_value, (unsigned long) val);
8194 break;
8196 case CONST_DOUBLE:
8197 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
8198 floating-point constant. A CONST_DOUBLE is used whenever the
8199 constant requires more than one word in order to be adequately
8200 represented. We output CONST_DOUBLEs as blocks. */
8202 register enum machine_mode mode = GET_MODE (rtl);
8204 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
8206 register unsigned length = GET_MODE_SIZE (mode) / 4;
8207 long *array = (long *) xmalloc (sizeof (long) * length);
8208 REAL_VALUE_TYPE rv;
8210 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
8211 switch (mode)
8213 case SFmode:
8214 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
8215 break;
8217 case DFmode:
8218 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
8219 break;
8221 case XFmode:
8222 case TFmode:
8223 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
8224 break;
8226 default:
8227 abort ();
8230 add_AT_float (die, DW_AT_const_value, length, array);
8232 else
8234 /* ??? We really should be using HOST_WIDE_INT throughout. */
8235 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT)
8236 abort ();
8237 add_AT_long_long (die, DW_AT_const_value,
8238 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
8241 break;
8243 case CONST_STRING:
8244 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
8245 break;
8247 case SYMBOL_REF:
8248 case LABEL_REF:
8249 case CONST:
8250 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
8251 break;
8253 case PLUS:
8254 /* In cases where an inlined instance of an inline function is passed
8255 the address of an `auto' variable (which is local to the caller) we
8256 can get a situation where the DECL_RTL of the artificial local
8257 variable (for the inlining) which acts as a stand-in for the
8258 corresponding formal parameter (of the inline function) will look
8259 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
8260 exactly a compile-time constant expression, but it isn't the address
8261 of the (artificial) local variable either. Rather, it represents the
8262 *value* which the artificial local variable always has during its
8263 lifetime. We currently have no way to represent such quasi-constant
8264 values in Dwarf, so for now we just punt and generate nothing. */
8265 break;
8267 default:
8268 /* No other kinds of rtx should be possible here. */
8269 abort ();
8274 static rtx
8275 rtl_for_decl_location (decl)
8276 tree decl;
8278 register rtx rtl;
8280 /* Here we have to decide where we are going to say the parameter "lives"
8281 (as far as the debugger is concerned). We only have a couple of
8282 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
8284 DECL_RTL normally indicates where the parameter lives during most of the
8285 activation of the function. If optimization is enabled however, this
8286 could be either NULL or else a pseudo-reg. Both of those cases indicate
8287 that the parameter doesn't really live anywhere (as far as the code
8288 generation parts of GCC are concerned) during most of the function's
8289 activation. That will happen (for example) if the parameter is never
8290 referenced within the function.
8292 We could just generate a location descriptor here for all non-NULL
8293 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
8294 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
8295 where DECL_RTL is NULL or is a pseudo-reg.
8297 Note however that we can only get away with using DECL_INCOMING_RTL as
8298 a backup substitute for DECL_RTL in certain limited cases. In cases
8299 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
8300 we can be sure that the parameter was passed using the same type as it is
8301 declared to have within the function, and that its DECL_INCOMING_RTL
8302 points us to a place where a value of that type is passed.
8304 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
8305 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
8306 because in these cases DECL_INCOMING_RTL points us to a value of some
8307 type which is *different* from the type of the parameter itself. Thus,
8308 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
8309 such cases, the debugger would end up (for example) trying to fetch a
8310 `float' from a place which actually contains the first part of a
8311 `double'. That would lead to really incorrect and confusing
8312 output at debug-time.
8314 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
8315 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
8316 are a couple of exceptions however. On little-endian machines we can
8317 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
8318 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
8319 an integral type that is smaller than TREE_TYPE (decl). These cases arise
8320 when (on a little-endian machine) a non-prototyped function has a
8321 parameter declared to be of type `short' or `char'. In such cases,
8322 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
8323 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
8324 passed `int' value. If the debugger then uses that address to fetch
8325 a `short' or a `char' (on a little-endian machine) the result will be
8326 the correct data, so we allow for such exceptional cases below.
8328 Note that our goal here is to describe the place where the given formal
8329 parameter lives during most of the function's activation (i.e. between
8330 the end of the prologue and the start of the epilogue). We'll do that
8331 as best as we can. Note however that if the given formal parameter is
8332 modified sometime during the execution of the function, then a stack
8333 backtrace (at debug-time) will show the function as having been
8334 called with the *new* value rather than the value which was
8335 originally passed in. This happens rarely enough that it is not
8336 a major problem, but it *is* a problem, and I'd like to fix it.
8338 A future version of dwarf2out.c may generate two additional
8339 attributes for any given DW_TAG_formal_parameter DIE which will
8340 describe the "passed type" and the "passed location" for the
8341 given formal parameter in addition to the attributes we now
8342 generate to indicate the "declared type" and the "active
8343 location" for each parameter. This additional set of attributes
8344 could be used by debuggers for stack backtraces. Separately, note
8345 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
8346 NULL also. This happens (for example) for inlined-instances of
8347 inline function formal parameters which are never referenced.
8348 This really shouldn't be happening. All PARM_DECL nodes should
8349 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
8350 doesn't currently generate these values for inlined instances of
8351 inline function parameters, so when we see such cases, we are
8352 just out-of-luck for the time being (until integrate.c
8353 gets fixed). */
8355 /* Use DECL_RTL as the "location" unless we find something better. */
8356 rtl = DECL_RTL_IF_SET (decl);
8358 if (TREE_CODE (decl) == PARM_DECL)
8360 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
8362 tree declared_type = type_main_variant (TREE_TYPE (decl));
8363 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl));
8365 /* This decl represents a formal parameter which was optimized out.
8366 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
8367 all* cases where (rtl == NULL_RTX) just below. */
8368 if (declared_type == passed_type)
8369 rtl = DECL_INCOMING_RTL (decl);
8370 else if (! BYTES_BIG_ENDIAN
8371 && TREE_CODE (declared_type) == INTEGER_TYPE
8372 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
8373 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
8374 rtl = DECL_INCOMING_RTL (decl);
8377 /* If the parm was passed in registers, but lives on the stack, then
8378 make a big endian correction if the mode of the type of the
8379 parameter is not the same as the mode of the rtl. */
8380 /* ??? This is the same series of checks that are made in dbxout.c before
8381 we reach the big endian correction code there. It isn't clear if all
8382 of these checks are necessary here, but keeping them all is the safe
8383 thing to do. */
8384 else if (GET_CODE (rtl) == MEM
8385 && XEXP (rtl, 0) != const0_rtx
8386 && ! CONSTANT_P (XEXP (rtl, 0))
8387 /* Not passed in memory. */
8388 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
8389 /* Not passed by invisible reference. */
8390 && (GET_CODE (XEXP (rtl, 0)) != REG
8391 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
8392 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
8393 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
8394 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
8395 #endif
8397 /* Big endian correction check. */
8398 && BYTES_BIG_ENDIAN
8399 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
8400 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
8401 < UNITS_PER_WORD))
8403 int offset = (UNITS_PER_WORD
8404 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
8405 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
8406 plus_constant (XEXP (rtl, 0), offset));
8410 if (rtl != NULL_RTX)
8412 rtl = eliminate_regs (rtl, 0, NULL_RTX);
8413 #ifdef LEAF_REG_REMAP
8414 if (current_function_uses_only_leaf_regs)
8415 leaf_renumber_regs_insn (rtl);
8416 #endif
8419 return rtl;
8422 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
8423 data attribute for a variable or a parameter. We generate the
8424 DW_AT_const_value attribute only in those cases where the given variable
8425 or parameter does not have a true "location" either in memory or in a
8426 register. This can happen (for example) when a constant is passed as an
8427 actual argument in a call to an inline function. (It's possible that
8428 these things can crop up in other ways also.) Note that one type of
8429 constant value which can be passed into an inlined function is a constant
8430 pointer. This can happen for example if an actual argument in an inlined
8431 function call evaluates to a compile-time constant address. */
8433 static void
8434 add_location_or_const_value_attribute (die, decl)
8435 register dw_die_ref die;
8436 register tree decl;
8438 register rtx rtl;
8440 if (TREE_CODE (decl) == ERROR_MARK)
8441 return;
8443 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
8444 abort ();
8446 rtl = rtl_for_decl_location (decl);
8447 if (rtl == NULL_RTX)
8448 return;
8450 switch (GET_CODE (rtl))
8452 case ADDRESSOF:
8453 /* The address of a variable that was optimized away; don't emit
8454 anything. */
8455 break;
8457 case CONST_INT:
8458 case CONST_DOUBLE:
8459 case CONST_STRING:
8460 case SYMBOL_REF:
8461 case LABEL_REF:
8462 case CONST:
8463 case PLUS:
8464 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
8465 add_const_value_attribute (die, rtl);
8466 break;
8468 case MEM:
8469 case REG:
8470 case SUBREG:
8471 case CONCAT:
8472 add_AT_location_description (die, DW_AT_location, rtl);
8473 break;
8475 default:
8476 abort ();
8480 /* If we don't have a copy of this variable in memory for some reason (such
8481 as a C++ member constant that doesn't have an out-of-line definition),
8482 we should tell the debugger about the constant value. */
8484 static void
8485 tree_add_const_value_attribute (var_die, decl)
8486 dw_die_ref var_die;
8487 tree decl;
8489 tree init = DECL_INITIAL (decl);
8490 tree type = TREE_TYPE (decl);
8492 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init
8493 && initializer_constant_valid_p (init, type) == null_pointer_node)
8494 /* OK */;
8495 else
8496 return;
8498 switch (TREE_CODE (type))
8500 case INTEGER_TYPE:
8501 if (host_integerp (init, 0))
8502 add_AT_unsigned (var_die, DW_AT_const_value,
8503 TREE_INT_CST_LOW (init));
8504 else
8505 add_AT_long_long (var_die, DW_AT_const_value,
8506 TREE_INT_CST_HIGH (init),
8507 TREE_INT_CST_LOW (init));
8508 break;
8510 default:;
8514 /* Generate an DW_AT_name attribute given some string value to be included as
8515 the value of the attribute. */
8517 static inline void
8518 add_name_attribute (die, name_string)
8519 register dw_die_ref die;
8520 register const char *name_string;
8522 if (name_string != NULL && *name_string != 0)
8524 if (demangle_name_func)
8525 name_string = (*demangle_name_func) (name_string);
8527 add_AT_string (die, DW_AT_name, name_string);
8531 /* Given a tree node describing an array bound (either lower or upper) output
8532 a representation for that bound. */
8534 static void
8535 add_bound_info (subrange_die, bound_attr, bound)
8536 register dw_die_ref subrange_die;
8537 register enum dwarf_attribute bound_attr;
8538 register tree bound;
8540 /* If this is an Ada unconstrained array type, then don't emit any debug
8541 info because the array bounds are unknown. They are parameterized when
8542 the type is instantiated. */
8543 if (contains_placeholder_p (bound))
8544 return;
8546 switch (TREE_CODE (bound))
8548 case ERROR_MARK:
8549 return;
8551 /* All fixed-bounds are represented by INTEGER_CST nodes. */
8552 case INTEGER_CST:
8553 if (! host_integerp (bound, 0)
8554 || (bound_attr == DW_AT_lower_bound
8555 && (((is_c_family () || is_java ()) && integer_zerop (bound))
8556 || (is_fortran () && integer_onep (bound)))))
8557 /* use the default */
8559 else
8560 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0));
8561 break;
8563 case CONVERT_EXPR:
8564 case NOP_EXPR:
8565 case NON_LVALUE_EXPR:
8566 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
8567 break;
8569 case SAVE_EXPR:
8570 /* If optimization is turned on, the SAVE_EXPRs that describe how to
8571 access the upper bound values may be bogus. If they refer to a
8572 register, they may only describe how to get at these values at the
8573 points in the generated code right after they have just been
8574 computed. Worse yet, in the typical case, the upper bound values
8575 will not even *be* computed in the optimized code (though the
8576 number of elements will), so these SAVE_EXPRs are entirely
8577 bogus. In order to compensate for this fact, we check here to see
8578 if optimization is enabled, and if so, we don't add an attribute
8579 for the (unknown and unknowable) upper bound. This should not
8580 cause too much trouble for existing (stupid?) debuggers because
8581 they have to deal with empty upper bounds location descriptions
8582 anyway in order to be able to deal with incomplete array types.
8583 Of course an intelligent debugger (GDB?) should be able to
8584 comprehend that a missing upper bound specification in a array
8585 type used for a storage class `auto' local array variable
8586 indicates that the upper bound is both unknown (at compile- time)
8587 and unknowable (at run-time) due to optimization.
8589 We assume that a MEM rtx is safe because gcc wouldn't put the
8590 value there unless it was going to be used repeatedly in the
8591 function, i.e. for cleanups. */
8592 if (SAVE_EXPR_RTL (bound)
8593 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM))
8595 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
8596 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
8597 register rtx loc = SAVE_EXPR_RTL (bound);
8599 /* If the RTL for the SAVE_EXPR is memory, handle the case where
8600 it references an outer function's frame. */
8602 if (GET_CODE (loc) == MEM)
8604 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
8606 if (XEXP (loc, 0) != new_addr)
8607 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
8610 add_AT_flag (decl_die, DW_AT_artificial, 1);
8611 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8612 add_AT_location_description (decl_die, DW_AT_location, loc);
8613 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8616 /* Else leave out the attribute. */
8617 break;
8619 case VAR_DECL:
8620 case PARM_DECL:
8622 dw_die_ref decl_die = lookup_decl_die (bound);
8624 /* ??? Can this happen, or should the variable have been bound
8625 first? Probably it can, since I imagine that we try to create
8626 the types of parameters in the order in which they exist in
8627 the list, and won't have created a forward reference to a
8628 later parameter. */
8629 if (decl_die != NULL)
8630 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8631 break;
8634 default:
8636 /* Otherwise try to create a stack operation procedure to
8637 evaluate the value of the array bound. */
8639 dw_die_ref ctx, decl_die;
8640 dw_loc_descr_ref loc;
8642 loc = loc_descriptor_from_tree (bound, 0);
8643 if (loc == NULL)
8644 break;
8646 ctx = lookup_decl_die (current_function_decl);
8648 decl_die = new_die (DW_TAG_variable, ctx);
8649 add_AT_flag (decl_die, DW_AT_artificial, 1);
8650 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
8651 add_AT_loc (decl_die, DW_AT_location, loc);
8653 add_AT_die_ref (subrange_die, bound_attr, decl_die);
8654 break;
8659 /* Note that the block of subscript information for an array type also
8660 includes information about the element type of type given array type. */
8662 static void
8663 add_subscript_info (type_die, type)
8664 register dw_die_ref type_die;
8665 register tree type;
8667 #ifndef MIPS_DEBUGGING_INFO
8668 register unsigned dimension_number;
8669 #endif
8670 register tree lower, upper;
8671 register dw_die_ref subrange_die;
8673 /* The GNU compilers represent multidimensional array types as sequences of
8674 one dimensional array types whose element types are themselves array
8675 types. Here we squish that down, so that each multidimensional array
8676 type gets only one array_type DIE in the Dwarf debugging info. The draft
8677 Dwarf specification say that we are allowed to do this kind of
8678 compression in C (because there is no difference between an array or
8679 arrays and a multidimensional array in C) but for other source languages
8680 (e.g. Ada) we probably shouldn't do this. */
8682 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
8683 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
8684 We work around this by disabling this feature. See also
8685 gen_array_type_die. */
8686 #ifndef MIPS_DEBUGGING_INFO
8687 for (dimension_number = 0;
8688 TREE_CODE (type) == ARRAY_TYPE;
8689 type = TREE_TYPE (type), dimension_number++)
8691 #endif
8692 register tree domain = TYPE_DOMAIN (type);
8694 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
8695 and (in GNU C only) variable bounds. Handle all three forms
8696 here. */
8697 subrange_die = new_die (DW_TAG_subrange_type, type_die);
8698 if (domain)
8700 /* We have an array type with specified bounds. */
8701 lower = TYPE_MIN_VALUE (domain);
8702 upper = TYPE_MAX_VALUE (domain);
8704 /* define the index type. */
8705 if (TREE_TYPE (domain))
8707 /* ??? This is probably an Ada unnamed subrange type. Ignore the
8708 TREE_TYPE field. We can't emit debug info for this
8709 because it is an unnamed integral type. */
8710 if (TREE_CODE (domain) == INTEGER_TYPE
8711 && TYPE_NAME (domain) == NULL_TREE
8712 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
8713 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
8715 else
8716 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
8717 type_die);
8720 /* ??? If upper is NULL, the array has unspecified length,
8721 but it does have a lower bound. This happens with Fortran
8722 dimension arr(N:*)
8723 Since the debugger is definitely going to need to know N
8724 to produce useful results, go ahead and output the lower
8725 bound solo, and hope the debugger can cope. */
8727 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
8728 if (upper)
8729 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
8731 else
8732 /* We have an array type with an unspecified length. The DWARF-2
8733 spec does not say how to handle this; let's just leave out the
8734 bounds. */
8737 #ifndef MIPS_DEBUGGING_INFO
8739 #endif
8742 static void
8743 add_byte_size_attribute (die, tree_node)
8744 dw_die_ref die;
8745 register tree tree_node;
8747 register unsigned size;
8749 switch (TREE_CODE (tree_node))
8751 case ERROR_MARK:
8752 size = 0;
8753 break;
8754 case ENUMERAL_TYPE:
8755 case RECORD_TYPE:
8756 case UNION_TYPE:
8757 case QUAL_UNION_TYPE:
8758 size = int_size_in_bytes (tree_node);
8759 break;
8760 case FIELD_DECL:
8761 /* For a data member of a struct or union, the DW_AT_byte_size is
8762 generally given as the number of bytes normally allocated for an
8763 object of the *declared* type of the member itself. This is true
8764 even for bit-fields. */
8765 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
8766 break;
8767 default:
8768 abort ();
8771 /* Note that `size' might be -1 when we get to this point. If it is, that
8772 indicates that the byte size of the entity in question is variable. We
8773 have no good way of expressing this fact in Dwarf at the present time,
8774 so just let the -1 pass on through. */
8776 add_AT_unsigned (die, DW_AT_byte_size, size);
8779 /* For a FIELD_DECL node which represents a bit-field, output an attribute
8780 which specifies the distance in bits from the highest order bit of the
8781 "containing object" for the bit-field to the highest order bit of the
8782 bit-field itself.
8784 For any given bit-field, the "containing object" is a hypothetical
8785 object (of some integral or enum type) within which the given bit-field
8786 lives. The type of this hypothetical "containing object" is always the
8787 same as the declared type of the individual bit-field itself. The
8788 determination of the exact location of the "containing object" for a
8789 bit-field is rather complicated. It's handled by the
8790 `field_byte_offset' function (above).
8792 Note that it is the size (in bytes) of the hypothetical "containing object"
8793 which will be given in the DW_AT_byte_size attribute for this bit-field.
8794 (See `byte_size_attribute' above). */
8796 static inline void
8797 add_bit_offset_attribute (die, decl)
8798 register dw_die_ref die;
8799 register tree decl;
8801 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl);
8802 tree type = DECL_BIT_FIELD_TYPE (decl);
8803 HOST_WIDE_INT bitpos_int;
8804 HOST_WIDE_INT highest_order_object_bit_offset;
8805 HOST_WIDE_INT highest_order_field_bit_offset;
8806 HOST_WIDE_INT unsigned bit_offset;
8808 /* Must be a field and a bit field. */
8809 if (!type
8810 || TREE_CODE (decl) != FIELD_DECL)
8811 abort ();
8813 /* We can't yet handle bit-fields whose offsets are variable, so if we
8814 encounter such things, just return without generating any attribute
8815 whatsoever. Likewise for variable or too large size. */
8816 if (! host_integerp (bit_position (decl), 0)
8817 || ! host_integerp (DECL_SIZE (decl), 1))
8818 return;
8820 bitpos_int = int_bit_position (decl);
8822 /* Note that the bit offset is always the distance (in bits) from the
8823 highest-order bit of the "containing object" to the highest-order bit of
8824 the bit-field itself. Since the "high-order end" of any object or field
8825 is different on big-endian and little-endian machines, the computation
8826 below must take account of these differences. */
8827 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
8828 highest_order_field_bit_offset = bitpos_int;
8830 if (! BYTES_BIG_ENDIAN)
8832 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0);
8833 highest_order_object_bit_offset += simple_type_size_in_bits (type);
8836 bit_offset
8837 = (! BYTES_BIG_ENDIAN
8838 ? highest_order_object_bit_offset - highest_order_field_bit_offset
8839 : highest_order_field_bit_offset - highest_order_object_bit_offset);
8841 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
8844 /* For a FIELD_DECL node which represents a bit field, output an attribute
8845 which specifies the length in bits of the given field. */
8847 static inline void
8848 add_bit_size_attribute (die, decl)
8849 register dw_die_ref die;
8850 register tree decl;
8852 /* Must be a field and a bit field. */
8853 if (TREE_CODE (decl) != FIELD_DECL
8854 || ! DECL_BIT_FIELD_TYPE (decl))
8855 abort ();
8857 if (host_integerp (DECL_SIZE (decl), 1))
8858 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1));
8861 /* If the compiled language is ANSI C, then add a 'prototyped'
8862 attribute, if arg types are given for the parameters of a function. */
8864 static inline void
8865 add_prototyped_attribute (die, func_type)
8866 register dw_die_ref die;
8867 register tree func_type;
8869 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
8870 && TYPE_ARG_TYPES (func_type) != NULL)
8871 add_AT_flag (die, DW_AT_prototyped, 1);
8874 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
8875 by looking in either the type declaration or object declaration
8876 equate table. */
8878 static inline void
8879 add_abstract_origin_attribute (die, origin)
8880 register dw_die_ref die;
8881 register tree origin;
8883 dw_die_ref origin_die = NULL;
8885 if (TREE_CODE (origin) != FUNCTION_DECL)
8887 /* We may have gotten separated from the block for the inlined
8888 function, if we're in an exception handler or some such; make
8889 sure that the abstract function has been written out.
8891 Doing this for nested functions is wrong, however; functions are
8892 distinct units, and our context might not even be inline. */
8893 tree fn = origin;
8894 if (TYPE_P (fn))
8895 fn = TYPE_STUB_DECL (fn);
8896 fn = decl_function_context (fn);
8897 if (fn)
8898 dwarf2out_abstract_function (fn);
8901 if (DECL_P (origin))
8902 origin_die = lookup_decl_die (origin);
8903 else if (TYPE_P (origin))
8904 origin_die = lookup_type_die (origin);
8906 if (origin_die == NULL)
8907 abort ();
8909 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
8912 /* We do not currently support the pure_virtual attribute. */
8914 static inline void
8915 add_pure_or_virtual_attribute (die, func_decl)
8916 register dw_die_ref die;
8917 register tree func_decl;
8919 if (DECL_VINDEX (func_decl))
8921 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8923 if (host_integerp (DECL_VINDEX (func_decl), 0))
8924 add_AT_loc (die, DW_AT_vtable_elem_location,
8925 new_loc_descr (DW_OP_constu,
8926 tree_low_cst (DECL_VINDEX (func_decl), 0),
8927 0));
8929 /* GNU extension: Record what type this method came from originally. */
8930 if (debug_info_level > DINFO_LEVEL_TERSE)
8931 add_AT_die_ref (die, DW_AT_containing_type,
8932 lookup_type_die (DECL_CONTEXT (func_decl)));
8936 /* Add source coordinate attributes for the given decl. */
8938 static void
8939 add_src_coords_attributes (die, decl)
8940 register dw_die_ref die;
8941 register tree decl;
8943 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
8945 add_AT_unsigned (die, DW_AT_decl_file, file_index);
8946 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8949 /* Add an DW_AT_name attribute and source coordinate attribute for the
8950 given decl, but only if it actually has a name. */
8952 static void
8953 add_name_and_src_coords_attributes (die, decl)
8954 register dw_die_ref die;
8955 register tree decl;
8957 register tree decl_name;
8959 decl_name = DECL_NAME (decl);
8960 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
8962 add_name_attribute (die, dwarf2_name (decl, 0));
8963 if (! DECL_ARTIFICIAL (decl))
8964 add_src_coords_attributes (die, decl);
8966 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
8967 && TREE_PUBLIC (decl)
8968 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
8969 && !DECL_ABSTRACT (decl))
8970 add_AT_string (die, DW_AT_MIPS_linkage_name,
8971 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
8975 /* Push a new declaration scope. */
8977 static void
8978 push_decl_scope (scope)
8979 tree scope;
8981 /* Make room in the decl_scope_table, if necessary. */
8982 if (decl_scope_table_allocated == decl_scope_depth)
8984 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
8985 decl_scope_table
8986 = (tree *) xrealloc (decl_scope_table,
8987 decl_scope_table_allocated * sizeof (tree));
8990 decl_scope_table[decl_scope_depth] = scope;
8991 decl_scope_depth++;
8994 /* Pop a declaration scope. */
8995 static inline void
8996 pop_decl_scope ()
8998 if (decl_scope_depth <= 0)
8999 abort ();
9000 --decl_scope_depth;
9003 /* Return the DIE for the scope that immediately contains this type.
9004 Non-named types get global scope. Named types nested in other
9005 types get their containing scope if it's open, or global scope
9006 otherwise. All other types (i.e. function-local named types) get
9007 the current active scope. */
9009 static dw_die_ref
9010 scope_die_for (t, context_die)
9011 register tree t;
9012 register dw_die_ref context_die;
9014 register dw_die_ref scope_die = NULL;
9015 register tree containing_scope;
9016 register int i;
9018 /* Non-types always go in the current scope. */
9019 if (! TYPE_P (t))
9020 abort ();
9022 containing_scope = TYPE_CONTEXT (t);
9024 /* Ignore namespaces for the moment. */
9025 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
9026 containing_scope = NULL_TREE;
9028 /* Ignore function type "scopes" from the C frontend. They mean that
9029 a tagged type is local to a parmlist of a function declarator, but
9030 that isn't useful to DWARF. */
9031 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
9032 containing_scope = NULL_TREE;
9034 if (containing_scope == NULL_TREE)
9035 scope_die = comp_unit_die;
9036 else if (TYPE_P (containing_scope))
9038 /* For types, we can just look up the appropriate DIE. But
9039 first we check to see if we're in the middle of emitting it
9040 so we know where the new DIE should go. */
9042 for (i = decl_scope_depth - 1; i >= 0; --i)
9043 if (decl_scope_table[i] == containing_scope)
9044 break;
9046 if (i < 0)
9048 if (debug_info_level > DINFO_LEVEL_TERSE
9049 && !TREE_ASM_WRITTEN (containing_scope))
9050 abort ();
9052 /* If none of the current dies are suitable, we get file scope. */
9053 scope_die = comp_unit_die;
9055 else
9056 scope_die = lookup_type_die (containing_scope);
9058 else
9059 scope_die = context_die;
9061 return scope_die;
9064 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
9066 static inline int local_scope_p PARAMS ((dw_die_ref));
9067 static inline int
9068 local_scope_p (context_die)
9069 dw_die_ref context_die;
9071 for (; context_die; context_die = context_die->die_parent)
9072 if (context_die->die_tag == DW_TAG_inlined_subroutine
9073 || context_die->die_tag == DW_TAG_subprogram)
9074 return 1;
9075 return 0;
9078 /* Returns nonzero iff CONTEXT_DIE is a class. */
9080 static inline int class_scope_p PARAMS ((dw_die_ref));
9081 static inline int
9082 class_scope_p (context_die)
9083 dw_die_ref context_die;
9085 return (context_die
9086 && (context_die->die_tag == DW_TAG_structure_type
9087 || context_die->die_tag == DW_TAG_union_type));
9090 /* Many forms of DIEs require a "type description" attribute. This
9091 routine locates the proper "type descriptor" die for the type given
9092 by 'type', and adds an DW_AT_type attribute below the given die. */
9094 static void
9095 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
9096 register dw_die_ref object_die;
9097 register tree type;
9098 register int decl_const;
9099 register int decl_volatile;
9100 register dw_die_ref context_die;
9102 register enum tree_code code = TREE_CODE (type);
9103 register dw_die_ref type_die = NULL;
9105 /* ??? If this type is an unnamed subrange type of an integral or
9106 floating-point type, use the inner type. This is because we have no
9107 support for unnamed types in base_type_die. This can happen if this is
9108 an Ada subrange type. Correct solution is emit a subrange type die. */
9109 if ((code == INTEGER_TYPE || code == REAL_TYPE)
9110 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
9111 type = TREE_TYPE (type), code = TREE_CODE (type);
9113 if (code == ERROR_MARK)
9114 return;
9116 /* Handle a special case. For functions whose return type is void, we
9117 generate *no* type attribute. (Note that no object may have type
9118 `void', so this only applies to function return types). */
9119 if (code == VOID_TYPE)
9120 return;
9122 type_die = modified_type_die (type,
9123 decl_const || TYPE_READONLY (type),
9124 decl_volatile || TYPE_VOLATILE (type),
9125 context_die);
9126 if (type_die != NULL)
9127 add_AT_die_ref (object_die, DW_AT_type, type_die);
9130 /* Given a tree pointer to a struct, class, union, or enum type node, return
9131 a pointer to the (string) tag name for the given type, or zero if the type
9132 was declared without a tag. */
9134 static const char *
9135 type_tag (type)
9136 register tree type;
9138 register const char *name = 0;
9140 if (TYPE_NAME (type) != 0)
9142 register tree t = 0;
9144 /* Find the IDENTIFIER_NODE for the type name. */
9145 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
9146 t = TYPE_NAME (type);
9148 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
9149 a TYPE_DECL node, regardless of whether or not a `typedef' was
9150 involved. */
9151 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
9152 && ! DECL_IGNORED_P (TYPE_NAME (type)))
9153 t = DECL_NAME (TYPE_NAME (type));
9155 /* Now get the name as a string, or invent one. */
9156 if (t != 0)
9157 name = IDENTIFIER_POINTER (t);
9160 return (name == 0 || *name == '\0') ? 0 : name;
9163 /* Return the type associated with a data member, make a special check
9164 for bit field types. */
9166 static inline tree
9167 member_declared_type (member)
9168 register tree member;
9170 return (DECL_BIT_FIELD_TYPE (member)
9171 ? DECL_BIT_FIELD_TYPE (member)
9172 : TREE_TYPE (member));
9175 /* Get the decl's label, as described by its RTL. This may be different
9176 from the DECL_NAME name used in the source file. */
9178 #if 0
9179 static const char *
9180 decl_start_label (decl)
9181 register tree decl;
9183 rtx x;
9184 const char *fnname;
9185 x = DECL_RTL (decl);
9186 if (GET_CODE (x) != MEM)
9187 abort ();
9189 x = XEXP (x, 0);
9190 if (GET_CODE (x) != SYMBOL_REF)
9191 abort ();
9193 fnname = XSTR (x, 0);
9194 return fnname;
9196 #endif
9198 /* These routines generate the internal representation of the DIE's for
9199 the compilation unit. Debugging information is collected by walking
9200 the declaration trees passed in from dwarf2out_decl(). */
9202 static void
9203 gen_array_type_die (type, context_die)
9204 register tree type;
9205 register dw_die_ref context_die;
9207 register dw_die_ref scope_die = scope_die_for (type, context_die);
9208 register dw_die_ref array_die;
9209 register tree element_type;
9211 /* ??? The SGI dwarf reader fails for array of array of enum types unless
9212 the inner array type comes before the outer array type. Thus we must
9213 call gen_type_die before we call new_die. See below also. */
9214 #ifdef MIPS_DEBUGGING_INFO
9215 gen_type_die (TREE_TYPE (type), context_die);
9216 #endif
9218 array_die = new_die (DW_TAG_array_type, scope_die);
9220 #if 0
9221 /* We default the array ordering. SDB will probably do
9222 the right things even if DW_AT_ordering is not present. It's not even
9223 an issue until we start to get into multidimensional arrays anyway. If
9224 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
9225 then we'll have to put the DW_AT_ordering attribute back in. (But if
9226 and when we find out that we need to put these in, we will only do so
9227 for multidimensional arrays. */
9228 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
9229 #endif
9231 #ifdef MIPS_DEBUGGING_INFO
9232 /* The SGI compilers handle arrays of unknown bound by setting
9233 AT_declaration and not emitting any subrange DIEs. */
9234 if (! TYPE_DOMAIN (type))
9235 add_AT_unsigned (array_die, DW_AT_declaration, 1);
9236 else
9237 #endif
9238 add_subscript_info (array_die, type);
9240 add_name_attribute (array_die, type_tag (type));
9241 equate_type_number_to_die (type, array_die);
9243 /* Add representation of the type of the elements of this array type. */
9244 element_type = TREE_TYPE (type);
9246 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
9247 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
9248 We work around this by disabling this feature. See also
9249 add_subscript_info. */
9250 #ifndef MIPS_DEBUGGING_INFO
9251 while (TREE_CODE (element_type) == ARRAY_TYPE)
9252 element_type = TREE_TYPE (element_type);
9254 gen_type_die (element_type, context_die);
9255 #endif
9257 add_type_attribute (array_die, element_type, 0, 0, context_die);
9260 static void
9261 gen_set_type_die (type, context_die)
9262 register tree type;
9263 register dw_die_ref context_die;
9265 register dw_die_ref type_die
9266 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
9268 equate_type_number_to_die (type, type_die);
9269 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
9272 #if 0
9273 static void
9274 gen_entry_point_die (decl, context_die)
9275 register tree decl;
9276 register dw_die_ref context_die;
9278 register tree origin = decl_ultimate_origin (decl);
9279 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
9280 if (origin != NULL)
9281 add_abstract_origin_attribute (decl_die, origin);
9282 else
9284 add_name_and_src_coords_attributes (decl_die, decl);
9285 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
9286 0, 0, context_die);
9289 if (DECL_ABSTRACT (decl))
9290 equate_decl_number_to_die (decl, decl_die);
9291 else
9292 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
9294 #endif
9296 /* Remember a type in the incomplete_types_list. */
9298 static void
9299 add_incomplete_type (type)
9300 tree type;
9302 if (incomplete_types == incomplete_types_allocated)
9304 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
9305 incomplete_types_list
9306 = (tree *) xrealloc (incomplete_types_list,
9307 sizeof (tree) * incomplete_types_allocated);
9310 incomplete_types_list[incomplete_types++] = type;
9313 /* Walk through the list of incomplete types again, trying once more to
9314 emit full debugging info for them. */
9316 static void
9317 retry_incomplete_types ()
9319 register tree type;
9321 while (incomplete_types)
9323 --incomplete_types;
9324 type = incomplete_types_list[incomplete_types];
9325 gen_type_die (type, comp_unit_die);
9329 /* Generate a DIE to represent an inlined instance of an enumeration type. */
9331 static void
9332 gen_inlined_enumeration_type_die (type, context_die)
9333 register tree type;
9334 register dw_die_ref context_die;
9336 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
9337 context_die);
9338 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9339 be incomplete and such types are not marked. */
9340 add_abstract_origin_attribute (type_die, type);
9343 /* Generate a DIE to represent an inlined instance of a structure type. */
9345 static void
9346 gen_inlined_structure_type_die (type, context_die)
9347 register tree type;
9348 register dw_die_ref context_die;
9350 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
9352 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9353 be incomplete and such types are not marked. */
9354 add_abstract_origin_attribute (type_die, type);
9357 /* Generate a DIE to represent an inlined instance of a union type. */
9359 static void
9360 gen_inlined_union_type_die (type, context_die)
9361 register tree type;
9362 register dw_die_ref context_die;
9364 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
9366 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
9367 be incomplete and such types are not marked. */
9368 add_abstract_origin_attribute (type_die, type);
9371 /* Generate a DIE to represent an enumeration type. Note that these DIEs
9372 include all of the information about the enumeration values also. Each
9373 enumerated type name/value is listed as a child of the enumerated type
9374 DIE. */
9376 static void
9377 gen_enumeration_type_die (type, context_die)
9378 register tree type;
9379 register dw_die_ref context_die;
9381 register dw_die_ref type_die = lookup_type_die (type);
9383 if (type_die == NULL)
9385 type_die = new_die (DW_TAG_enumeration_type,
9386 scope_die_for (type, context_die));
9387 equate_type_number_to_die (type, type_die);
9388 add_name_attribute (type_die, type_tag (type));
9390 else if (! TYPE_SIZE (type))
9391 return;
9392 else
9393 remove_AT (type_die, DW_AT_declaration);
9395 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
9396 given enum type is incomplete, do not generate the DW_AT_byte_size
9397 attribute or the DW_AT_element_list attribute. */
9398 if (TYPE_SIZE (type))
9400 register tree link;
9402 TREE_ASM_WRITTEN (type) = 1;
9403 add_byte_size_attribute (type_die, type);
9404 if (TYPE_STUB_DECL (type) != NULL_TREE)
9405 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
9407 /* If the first reference to this type was as the return type of an
9408 inline function, then it may not have a parent. Fix this now. */
9409 if (type_die->die_parent == NULL)
9410 add_child_die (scope_die_for (type, context_die), type_die);
9412 for (link = TYPE_FIELDS (type);
9413 link != NULL; link = TREE_CHAIN (link))
9415 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
9417 add_name_attribute (enum_die,
9418 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
9420 if (host_integerp (TREE_VALUE (link), 0))
9422 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0)
9423 add_AT_int (enum_die, DW_AT_const_value,
9424 tree_low_cst (TREE_VALUE (link), 0));
9425 else
9426 add_AT_unsigned (enum_die, DW_AT_const_value,
9427 tree_low_cst (TREE_VALUE (link), 0));
9431 else
9432 add_AT_flag (type_die, DW_AT_declaration, 1);
9435 /* Generate a DIE to represent either a real live formal parameter decl or to
9436 represent just the type of some formal parameter position in some function
9437 type.
9439 Note that this routine is a bit unusual because its argument may be a
9440 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
9441 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
9442 node. If it's the former then this function is being called to output a
9443 DIE to represent a formal parameter object (or some inlining thereof). If
9444 it's the latter, then this function is only being called to output a
9445 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
9446 argument type of some subprogram type. */
9448 static dw_die_ref
9449 gen_formal_parameter_die (node, context_die)
9450 register tree node;
9451 register dw_die_ref context_die;
9453 register dw_die_ref parm_die
9454 = new_die (DW_TAG_formal_parameter, context_die);
9455 register tree origin;
9457 switch (TREE_CODE_CLASS (TREE_CODE (node)))
9459 case 'd':
9460 origin = decl_ultimate_origin (node);
9461 if (origin != NULL)
9462 add_abstract_origin_attribute (parm_die, origin);
9463 else
9465 add_name_and_src_coords_attributes (parm_die, node);
9466 add_type_attribute (parm_die, TREE_TYPE (node),
9467 TREE_READONLY (node),
9468 TREE_THIS_VOLATILE (node),
9469 context_die);
9470 if (DECL_ARTIFICIAL (node))
9471 add_AT_flag (parm_die, DW_AT_artificial, 1);
9474 equate_decl_number_to_die (node, parm_die);
9475 if (! DECL_ABSTRACT (node))
9476 add_location_or_const_value_attribute (parm_die, node);
9478 break;
9480 case 't':
9481 /* We were called with some kind of a ..._TYPE node. */
9482 add_type_attribute (parm_die, node, 0, 0, context_die);
9483 break;
9485 default:
9486 abort ();
9489 return parm_die;
9492 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
9493 at the end of an (ANSI prototyped) formal parameters list. */
9495 static void
9496 gen_unspecified_parameters_die (decl_or_type, context_die)
9497 register tree decl_or_type ATTRIBUTE_UNUSED;
9498 register dw_die_ref context_die;
9500 new_die (DW_TAG_unspecified_parameters, context_die);
9503 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
9504 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
9505 parameters as specified in some function type specification (except for
9506 those which appear as part of a function *definition*). */
9508 static void
9509 gen_formal_types_die (function_or_method_type, context_die)
9510 register tree function_or_method_type;
9511 register dw_die_ref context_die;
9513 register tree link;
9514 register tree formal_type = NULL;
9515 register tree first_parm_type;
9516 tree arg;
9518 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL)
9520 arg = DECL_ARGUMENTS (function_or_method_type);
9521 function_or_method_type = TREE_TYPE (function_or_method_type);
9523 else
9524 arg = NULL_TREE;
9526 first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
9528 /* Make our first pass over the list of formal parameter types and output a
9529 DW_TAG_formal_parameter DIE for each one. */
9530 for (link = first_parm_type; link; )
9532 register dw_die_ref parm_die;
9534 formal_type = TREE_VALUE (link);
9535 if (formal_type == void_type_node)
9536 break;
9538 /* Output a (nameless) DIE to represent the formal parameter itself. */
9539 parm_die = gen_formal_parameter_die (formal_type, context_die);
9540 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE
9541 && link == first_parm_type)
9542 || (arg && DECL_ARTIFICIAL (arg)))
9543 add_AT_flag (parm_die, DW_AT_artificial, 1);
9545 link = TREE_CHAIN (link);
9546 if (arg)
9547 arg = TREE_CHAIN (arg);
9550 /* If this function type has an ellipsis, add a
9551 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
9552 if (formal_type != void_type_node)
9553 gen_unspecified_parameters_die (function_or_method_type, context_die);
9555 /* Make our second (and final) pass over the list of formal parameter types
9556 and output DIEs to represent those types (as necessary). */
9557 for (link = TYPE_ARG_TYPES (function_or_method_type);
9558 link;
9559 link = TREE_CHAIN (link))
9561 formal_type = TREE_VALUE (link);
9562 if (formal_type == void_type_node)
9563 break;
9565 gen_type_die (formal_type, context_die);
9569 /* We want to generate the DIE for TYPE so that we can generate the
9570 die for MEMBER, which has been defined; we will need to refer back
9571 to the member declaration nested within TYPE. If we're trying to
9572 generate minimal debug info for TYPE, processing TYPE won't do the
9573 trick; we need to attach the member declaration by hand. */
9575 static void
9576 gen_type_die_for_member (type, member, context_die)
9577 tree type, member;
9578 dw_die_ref context_die;
9580 gen_type_die (type, context_die);
9582 /* If we're trying to avoid duplicate debug info, we may not have
9583 emitted the member decl for this function. Emit it now. */
9584 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
9585 && ! lookup_decl_die (member))
9587 if (decl_ultimate_origin (member))
9588 abort ();
9590 push_decl_scope (type);
9591 if (TREE_CODE (member) == FUNCTION_DECL)
9592 gen_subprogram_die (member, lookup_type_die (type));
9593 else
9594 gen_variable_die (member, lookup_type_die (type));
9595 pop_decl_scope ();
9599 /* Generate the DWARF2 info for the "abstract" instance
9600 of a function which we may later generate inlined and/or
9601 out-of-line instances of. */
9603 void
9604 dwarf2out_abstract_function (decl)
9605 tree decl;
9607 register dw_die_ref old_die;
9608 tree save_fn;
9609 tree context;
9610 int was_abstract = DECL_ABSTRACT (decl);
9612 /* Make sure we have the actual abstract inline, not a clone. */
9613 decl = DECL_ORIGIN (decl);
9615 old_die = lookup_decl_die (decl);
9616 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
9617 /* We've already generated the abstract instance. */
9618 return;
9620 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
9621 we don't get confused by DECL_ABSTRACT. */
9622 context = decl_class_context (decl);
9623 if (context)
9624 gen_type_die_for_member
9625 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die);
9627 /* Pretend we've just finished compiling this function. */
9628 save_fn = current_function_decl;
9629 current_function_decl = decl;
9631 set_decl_abstract_flags (decl, 1);
9632 dwarf2out_decl (decl);
9633 if (! was_abstract)
9634 set_decl_abstract_flags (decl, 0);
9636 current_function_decl = save_fn;
9639 /* Generate a DIE to represent a declared function (either file-scope or
9640 block-local). */
9642 static void
9643 gen_subprogram_die (decl, context_die)
9644 register tree decl;
9645 register dw_die_ref context_die;
9647 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
9648 register tree origin = decl_ultimate_origin (decl);
9649 register dw_die_ref subr_die;
9650 register rtx fp_reg;
9651 register tree fn_arg_types;
9652 register tree outer_scope;
9653 register dw_die_ref old_die = lookup_decl_die (decl);
9654 register int declaration = (current_function_decl != decl
9655 || class_scope_p (context_die));
9657 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
9658 be true, if we started to generate the abstract instance of an inline,
9659 decided to output its containing class, and proceeded to emit the
9660 declaration of the inline from the member list for the class. In that
9661 case, `declaration' takes priority; we'll get back to the abstract
9662 instance when we're done with the class. */
9664 /* The class-scope declaration DIE must be the primary DIE. */
9665 if (origin && declaration && class_scope_p (context_die))
9667 origin = NULL;
9668 if (old_die)
9669 abort ();
9672 if (origin != NULL)
9674 if (declaration && ! local_scope_p (context_die))
9675 abort ();
9677 /* Fixup die_parent for the abstract instance of a nested
9678 inline function. */
9679 if (old_die && old_die->die_parent == NULL)
9680 add_child_die (context_die, old_die);
9682 subr_die = new_die (DW_TAG_subprogram, context_die);
9683 add_abstract_origin_attribute (subr_die, origin);
9685 else if (old_die)
9687 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9689 if (!get_AT_flag (old_die, DW_AT_declaration)
9690 /* We can have a normal definition following an inline one in the
9691 case of redefinition of GNU C extern inlines.
9692 It seems reasonable to use AT_specification in this case. */
9693 && !get_AT_unsigned (old_die, DW_AT_inline))
9695 /* ??? This can happen if there is a bug in the program, for
9696 instance, if it has duplicate function definitions. Ideally,
9697 we should detect this case and ignore it. For now, if we have
9698 already reported an error, any error at all, then assume that
9699 we got here because of a input error, not a dwarf2 bug. */
9700 if (errorcount)
9701 return;
9702 abort ();
9705 /* If the definition comes from the same place as the declaration,
9706 maybe use the old DIE. We always want the DIE for this function
9707 that has the *_pc attributes to be under comp_unit_die so the
9708 debugger can find it. We also need to do this for abstract
9709 instances of inlines, since the spec requires the out-of-line copy
9710 to have the same parent. For local class methods, this doesn't
9711 apply; we just use the old DIE. */
9712 if ((old_die->die_parent == comp_unit_die || context_die == NULL)
9713 && (DECL_ARTIFICIAL (decl)
9714 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
9715 && (get_AT_unsigned (old_die, DW_AT_decl_line)
9716 == (unsigned) DECL_SOURCE_LINE (decl)))))
9718 subr_die = old_die;
9720 /* Clear out the declaration attribute and the parm types. */
9721 remove_AT (subr_die, DW_AT_declaration);
9722 remove_children (subr_die);
9724 else
9726 subr_die = new_die (DW_TAG_subprogram, context_die);
9727 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
9728 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9729 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
9730 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9731 != (unsigned) DECL_SOURCE_LINE (decl))
9732 add_AT_unsigned
9733 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
9736 else
9738 subr_die = new_die (DW_TAG_subprogram, context_die);
9740 if (TREE_PUBLIC (decl))
9741 add_AT_flag (subr_die, DW_AT_external, 1);
9743 add_name_and_src_coords_attributes (subr_die, decl);
9744 if (debug_info_level > DINFO_LEVEL_TERSE)
9746 register tree type = TREE_TYPE (decl);
9748 add_prototyped_attribute (subr_die, type);
9749 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
9752 add_pure_or_virtual_attribute (subr_die, decl);
9753 if (DECL_ARTIFICIAL (decl))
9754 add_AT_flag (subr_die, DW_AT_artificial, 1);
9755 if (TREE_PROTECTED (decl))
9756 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
9757 else if (TREE_PRIVATE (decl))
9758 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
9761 if (declaration)
9763 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9765 add_AT_flag (subr_die, DW_AT_declaration, 1);
9767 /* The first time we see a member function, it is in the context of
9768 the class to which it belongs. We make sure of this by emitting
9769 the class first. The next time is the definition, which is
9770 handled above. The two may come from the same source text. */
9771 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
9772 equate_decl_number_to_die (decl, subr_die);
9775 else if (DECL_ABSTRACT (decl))
9777 if (DECL_INLINE (decl) && !flag_no_inline)
9779 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
9780 inline functions, but not for extern inline functions.
9781 We can't get this completely correct because information
9782 about whether the function was declared inline is not
9783 saved anywhere. */
9784 if (DECL_DEFER_OUTPUT (decl))
9785 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
9786 else
9787 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
9789 else
9790 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
9792 equate_decl_number_to_die (decl, subr_die);
9794 else if (!DECL_EXTERNAL (decl))
9796 if (!(old_die && get_AT_unsigned (old_die, DW_AT_inline)))
9797 equate_decl_number_to_die (decl, subr_die);
9799 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
9800 current_funcdef_number);
9801 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
9802 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
9803 current_funcdef_number);
9804 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
9806 add_pubname (decl, subr_die);
9807 add_arange (decl, subr_die);
9809 #ifdef MIPS_DEBUGGING_INFO
9810 /* Add a reference to the FDE for this routine. */
9811 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
9812 #endif
9814 /* Define the "frame base" location for this routine. We use the
9815 frame pointer or stack pointer registers, since the RTL for local
9816 variables is relative to one of them. */
9817 fp_reg
9818 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
9819 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
9821 #if 0
9822 /* ??? This fails for nested inline functions, because context_display
9823 is not part of the state saved/restored for inline functions. */
9824 if (current_function_needs_context)
9825 add_AT_location_description (subr_die, DW_AT_static_link,
9826 lookup_static_chain (decl));
9827 #endif
9830 /* Now output descriptions of the arguments for this function. This gets
9831 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
9832 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
9833 `...' at the end of the formal parameter list. In order to find out if
9834 there was a trailing ellipsis or not, we must instead look at the type
9835 associated with the FUNCTION_DECL. This will be a node of type
9836 FUNCTION_TYPE. If the chain of type nodes hanging off of this
9837 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
9838 an ellipsis at the end. */
9840 /* In the case where we are describing a mere function declaration, all we
9841 need to do here (and all we *can* do here) is to describe the *types* of
9842 its formal parameters. */
9843 if (debug_info_level <= DINFO_LEVEL_TERSE)
9845 else if (declaration)
9846 gen_formal_types_die (decl, subr_die);
9847 else
9849 /* Generate DIEs to represent all known formal parameters */
9850 register tree arg_decls = DECL_ARGUMENTS (decl);
9851 register tree parm;
9853 /* When generating DIEs, generate the unspecified_parameters DIE
9854 instead if we come across the arg "__builtin_va_alist" */
9855 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
9856 if (TREE_CODE (parm) == PARM_DECL)
9858 if (DECL_NAME (parm)
9859 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
9860 "__builtin_va_alist"))
9861 gen_unspecified_parameters_die (parm, subr_die);
9862 else
9863 gen_decl_die (parm, subr_die);
9866 /* Decide whether we need a unspecified_parameters DIE at the end.
9867 There are 2 more cases to do this for: 1) the ansi ... declaration -
9868 this is detectable when the end of the arg list is not a
9869 void_type_node 2) an unprototyped function declaration (not a
9870 definition). This just means that we have no info about the
9871 parameters at all. */
9872 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
9873 if (fn_arg_types != NULL)
9875 /* this is the prototyped case, check for ... */
9876 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
9877 gen_unspecified_parameters_die (decl, subr_die);
9879 else if (DECL_INITIAL (decl) == NULL_TREE)
9880 gen_unspecified_parameters_die (decl, subr_die);
9883 /* Output Dwarf info for all of the stuff within the body of the function
9884 (if it has one - it may be just a declaration). */
9885 outer_scope = DECL_INITIAL (decl);
9887 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
9888 node created to represent a function. This outermost BLOCK actually
9889 represents the outermost binding contour for the function, i.e. the
9890 contour in which the function's formal parameters and labels get
9891 declared. Curiously, it appears that the front end doesn't actually
9892 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
9893 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
9894 list for the function instead.) The BLOCK_VARS list for the
9895 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
9896 the function however, and we output DWARF info for those in
9897 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
9898 node representing the function's outermost pair of curly braces, and
9899 any blocks used for the base and member initializers of a C++
9900 constructor function. */
9901 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
9903 current_function_has_inlines = 0;
9904 decls_for_scope (outer_scope, subr_die, 0);
9906 #if 0 && defined (MIPS_DEBUGGING_INFO)
9907 if (current_function_has_inlines)
9909 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
9910 if (! comp_unit_has_inlines)
9912 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
9913 comp_unit_has_inlines = 1;
9916 #endif
9920 /* Generate a DIE to represent a declared data object. */
9922 static void
9923 gen_variable_die (decl, context_die)
9924 register tree decl;
9925 register dw_die_ref context_die;
9927 register tree origin = decl_ultimate_origin (decl);
9928 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
9930 dw_die_ref old_die = lookup_decl_die (decl);
9931 int declaration = (DECL_EXTERNAL (decl)
9932 || class_scope_p (context_die));
9934 if (origin != NULL)
9935 add_abstract_origin_attribute (var_die, origin);
9936 /* Loop unrolling can create multiple blocks that refer to the same
9937 static variable, so we must test for the DW_AT_declaration flag. */
9938 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
9939 copy decls and set the DECL_ABSTRACT flag on them instead of
9940 sharing them. */
9941 else if (old_die && TREE_STATIC (decl)
9942 && get_AT_flag (old_die, DW_AT_declaration) == 1)
9944 /* This is a definition of a C++ class level static. */
9945 add_AT_die_ref (var_die, DW_AT_specification, old_die);
9946 if (DECL_NAME (decl))
9948 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
9950 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
9951 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
9953 if (get_AT_unsigned (old_die, DW_AT_decl_line)
9954 != (unsigned) DECL_SOURCE_LINE (decl))
9956 add_AT_unsigned (var_die, DW_AT_decl_line,
9957 DECL_SOURCE_LINE (decl));
9960 else
9962 add_name_and_src_coords_attributes (var_die, decl);
9963 add_type_attribute (var_die, TREE_TYPE (decl),
9964 TREE_READONLY (decl),
9965 TREE_THIS_VOLATILE (decl), context_die);
9967 if (TREE_PUBLIC (decl))
9968 add_AT_flag (var_die, DW_AT_external, 1);
9970 if (DECL_ARTIFICIAL (decl))
9971 add_AT_flag (var_die, DW_AT_artificial, 1);
9973 if (TREE_PROTECTED (decl))
9974 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
9976 else if (TREE_PRIVATE (decl))
9977 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
9980 if (declaration)
9981 add_AT_flag (var_die, DW_AT_declaration, 1);
9983 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
9984 equate_decl_number_to_die (decl, var_die);
9986 if (! declaration && ! DECL_ABSTRACT (decl))
9988 add_location_or_const_value_attribute (var_die, decl);
9989 add_pubname (decl, var_die);
9991 else
9992 tree_add_const_value_attribute (var_die, decl);
9995 /* Generate a DIE to represent a label identifier. */
9997 static void
9998 gen_label_die (decl, context_die)
9999 register tree decl;
10000 register dw_die_ref context_die;
10002 register tree origin = decl_ultimate_origin (decl);
10003 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
10004 register rtx insn;
10005 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10007 if (origin != NULL)
10008 add_abstract_origin_attribute (lbl_die, origin);
10009 else
10010 add_name_and_src_coords_attributes (lbl_die, decl);
10012 if (DECL_ABSTRACT (decl))
10013 equate_decl_number_to_die (decl, lbl_die);
10014 else
10016 insn = DECL_RTL (decl);
10018 /* Deleted labels are programmer specified labels which have been
10019 eliminated because of various optimisations. We still emit them
10020 here so that it is possible to put breakpoints on them. */
10021 if (GET_CODE (insn) == CODE_LABEL
10022 || ((GET_CODE (insn) == NOTE
10023 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
10025 /* When optimization is enabled (via -O) some parts of the compiler
10026 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
10027 represent source-level labels which were explicitly declared by
10028 the user. This really shouldn't be happening though, so catch
10029 it if it ever does happen. */
10030 if (INSN_DELETED_P (insn))
10031 abort ();
10033 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn));
10034 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
10039 /* Generate a DIE for a lexical block. */
10041 static void
10042 gen_lexical_block_die (stmt, context_die, depth)
10043 register tree stmt;
10044 register dw_die_ref context_die;
10045 int depth;
10047 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
10048 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10050 if (! BLOCK_ABSTRACT (stmt))
10052 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10053 BLOCK_NUMBER (stmt));
10054 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
10055 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10056 BLOCK_NUMBER (stmt));
10057 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
10060 decls_for_scope (stmt, stmt_die, depth);
10063 /* Generate a DIE for an inlined subprogram. */
10065 static void
10066 gen_inlined_subroutine_die (stmt, context_die, depth)
10067 register tree stmt;
10068 register dw_die_ref context_die;
10069 int depth;
10071 if (! BLOCK_ABSTRACT (stmt))
10073 register dw_die_ref subr_die
10074 = new_die (DW_TAG_inlined_subroutine, context_die);
10075 register tree decl = block_ultimate_origin (stmt);
10076 char label[MAX_ARTIFICIAL_LABEL_BYTES];
10078 /* Emit info for the abstract instance first, if we haven't yet. */
10079 dwarf2out_abstract_function (decl);
10081 add_abstract_origin_attribute (subr_die, decl);
10082 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
10083 BLOCK_NUMBER (stmt));
10084 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
10085 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL,
10086 BLOCK_NUMBER (stmt));
10087 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
10088 decls_for_scope (stmt, subr_die, depth);
10089 current_function_has_inlines = 1;
10093 /* Generate a DIE for a field in a record, or structure. */
10095 static void
10096 gen_field_die (decl, context_die)
10097 register tree decl;
10098 register dw_die_ref context_die;
10100 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
10102 add_name_and_src_coords_attributes (decl_die, decl);
10103 add_type_attribute (decl_die, member_declared_type (decl),
10104 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
10105 context_die);
10107 /* If this is a bit field... */
10108 if (DECL_BIT_FIELD_TYPE (decl))
10110 add_byte_size_attribute (decl_die, decl);
10111 add_bit_size_attribute (decl_die, decl);
10112 add_bit_offset_attribute (decl_die, decl);
10115 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
10116 add_data_member_location_attribute (decl_die, decl);
10118 if (DECL_ARTIFICIAL (decl))
10119 add_AT_flag (decl_die, DW_AT_artificial, 1);
10121 if (TREE_PROTECTED (decl))
10122 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
10124 else if (TREE_PRIVATE (decl))
10125 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
10128 #if 0
10129 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10130 Use modified_type_die instead.
10131 We keep this code here just in case these types of DIEs may be needed to
10132 represent certain things in other languages (e.g. Pascal) someday. */
10133 static void
10134 gen_pointer_type_die (type, context_die)
10135 register tree type;
10136 register dw_die_ref context_die;
10138 register dw_die_ref ptr_die
10139 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
10141 equate_type_number_to_die (type, ptr_die);
10142 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10143 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10146 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
10147 Use modified_type_die instead.
10148 We keep this code here just in case these types of DIEs may be needed to
10149 represent certain things in other languages (e.g. Pascal) someday. */
10150 static void
10151 gen_reference_type_die (type, context_die)
10152 register tree type;
10153 register dw_die_ref context_die;
10155 register dw_die_ref ref_die
10156 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
10158 equate_type_number_to_die (type, ref_die);
10159 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
10160 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
10162 #endif
10164 /* Generate a DIE for a pointer to a member type. */
10165 static void
10166 gen_ptr_to_mbr_type_die (type, context_die)
10167 register tree type;
10168 register dw_die_ref context_die;
10170 register dw_die_ref ptr_die
10171 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
10173 equate_type_number_to_die (type, ptr_die);
10174 add_AT_die_ref (ptr_die, DW_AT_containing_type,
10175 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
10176 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
10179 /* Generate the DIE for the compilation unit. */
10181 static dw_die_ref
10182 gen_compile_unit_die (filename)
10183 register const char *filename;
10185 register dw_die_ref die;
10186 char producer[250];
10187 const char *wd = getpwd ();
10188 int language;
10190 die = new_die (DW_TAG_compile_unit, NULL);
10191 add_name_attribute (die, filename);
10193 if (wd != NULL && filename[0] != DIR_SEPARATOR)
10194 add_AT_string (die, DW_AT_comp_dir, wd);
10196 sprintf (producer, "%s %s", language_string, version_string);
10198 #ifdef MIPS_DEBUGGING_INFO
10199 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
10200 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
10201 not appear in the producer string, the debugger reaches the conclusion
10202 that the object file is stripped and has no debugging information.
10203 To get the MIPS/SGI debugger to believe that there is debugging
10204 information in the object file, we add a -g to the producer string. */
10205 if (debug_info_level > DINFO_LEVEL_TERSE)
10206 strcat (producer, " -g");
10207 #endif
10209 add_AT_string (die, DW_AT_producer, producer);
10211 if (strcmp (language_string, "GNU C++") == 0)
10212 language = DW_LANG_C_plus_plus;
10213 else if (strcmp (language_string, "GNU Ada") == 0)
10214 language = DW_LANG_Ada83;
10215 else if (strcmp (language_string, "GNU F77") == 0)
10216 language = DW_LANG_Fortran77;
10217 else if (strcmp (language_string, "GNU Pascal") == 0)
10218 language = DW_LANG_Pascal83;
10219 else if (strcmp (language_string, "GNU Java") == 0)
10220 language = DW_LANG_Java;
10221 else if (flag_traditional)
10222 language = DW_LANG_C;
10223 else
10224 language = DW_LANG_C89;
10226 add_AT_unsigned (die, DW_AT_language, language);
10228 return die;
10231 /* Generate a DIE for a string type. */
10233 static void
10234 gen_string_type_die (type, context_die)
10235 register tree type;
10236 register dw_die_ref context_die;
10238 register dw_die_ref type_die
10239 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
10241 equate_type_number_to_die (type, type_die);
10243 /* Fudge the string length attribute for now. */
10245 /* TODO: add string length info.
10246 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
10247 bound_representation (upper_bound, 0, 'u'); */
10250 /* Generate the DIE for a base class. */
10252 static void
10253 gen_inheritance_die (binfo, context_die)
10254 register tree binfo;
10255 register dw_die_ref context_die;
10257 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
10259 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
10260 add_data_member_location_attribute (die, binfo);
10262 if (TREE_VIA_VIRTUAL (binfo))
10263 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
10264 if (TREE_VIA_PUBLIC (binfo))
10265 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
10266 else if (TREE_VIA_PROTECTED (binfo))
10267 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
10270 /* Generate a DIE for a class member. */
10272 static void
10273 gen_member_die (type, context_die)
10274 register tree type;
10275 register dw_die_ref context_die;
10277 register tree member;
10278 dw_die_ref child;
10280 /* If this is not an incomplete type, output descriptions of each of its
10281 members. Note that as we output the DIEs necessary to represent the
10282 members of this record or union type, we will also be trying to output
10283 DIEs to represent the *types* of those members. However the `type'
10284 function (above) will specifically avoid generating type DIEs for member
10285 types *within* the list of member DIEs for this (containing) type execpt
10286 for those types (of members) which are explicitly marked as also being
10287 members of this (containing) type themselves. The g++ front- end can
10288 force any given type to be treated as a member of some other
10289 (containing) type by setting the TYPE_CONTEXT of the given (member) type
10290 to point to the TREE node representing the appropriate (containing)
10291 type. */
10293 /* First output info about the base classes. */
10294 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
10296 register tree bases = TYPE_BINFO_BASETYPES (type);
10297 register int n_bases = TREE_VEC_LENGTH (bases);
10298 register int i;
10300 for (i = 0; i < n_bases; i++)
10301 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
10304 /* Now output info about the data members and type members. */
10305 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
10307 /* If we thought we were generating minimal debug info for TYPE
10308 and then changed our minds, some of the member declarations
10309 may have already been defined. Don't define them again, but
10310 do put them in the right order. */
10312 child = lookup_decl_die (member);
10313 if (child)
10314 splice_child_die (context_die, child);
10315 else
10316 gen_decl_die (member, context_die);
10319 /* Now output info about the function members (if any). */
10320 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
10322 /* Don't include clones in the member list. */
10323 if (DECL_ABSTRACT_ORIGIN (member))
10324 continue;
10326 child = lookup_decl_die (member);
10327 if (child)
10328 splice_child_die (context_die, child);
10329 else
10330 gen_decl_die (member, context_die);
10334 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
10335 is set, we pretend that the type was never defined, so we only get the
10336 member DIEs needed by later specification DIEs. */
10338 static void
10339 gen_struct_or_union_type_die (type, context_die)
10340 register tree type;
10341 register dw_die_ref context_die;
10343 register dw_die_ref type_die = lookup_type_die (type);
10344 register dw_die_ref scope_die = 0;
10345 register int nested = 0;
10346 int complete = (TYPE_SIZE (type)
10347 && (! TYPE_STUB_DECL (type)
10348 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
10350 if (type_die && ! complete)
10351 return;
10353 if (TYPE_CONTEXT (type) != NULL_TREE
10354 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
10355 nested = 1;
10357 scope_die = scope_die_for (type, context_die);
10359 if (! type_die || (nested && scope_die == comp_unit_die))
10360 /* First occurrence of type or toplevel definition of nested class. */
10362 register dw_die_ref old_die = type_die;
10364 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
10365 ? DW_TAG_structure_type : DW_TAG_union_type,
10366 scope_die);
10367 equate_type_number_to_die (type, type_die);
10368 if (old_die)
10369 add_AT_die_ref (type_die, DW_AT_specification, old_die);
10370 else
10371 add_name_attribute (type_die, type_tag (type));
10373 else
10374 remove_AT (type_die, DW_AT_declaration);
10376 /* If this type has been completed, then give it a byte_size attribute and
10377 then give a list of members. */
10378 if (complete)
10380 /* Prevent infinite recursion in cases where the type of some member of
10381 this type is expressed in terms of this type itself. */
10382 TREE_ASM_WRITTEN (type) = 1;
10383 add_byte_size_attribute (type_die, type);
10384 if (TYPE_STUB_DECL (type) != NULL_TREE)
10385 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
10387 /* If the first reference to this type was as the return type of an
10388 inline function, then it may not have a parent. Fix this now. */
10389 if (type_die->die_parent == NULL)
10390 add_child_die (scope_die, type_die);
10392 push_decl_scope (type);
10393 gen_member_die (type, type_die);
10394 pop_decl_scope ();
10396 /* GNU extension: Record what type our vtable lives in. */
10397 if (TYPE_VFIELD (type))
10399 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
10401 gen_type_die (vtype, context_die);
10402 add_AT_die_ref (type_die, DW_AT_containing_type,
10403 lookup_type_die (vtype));
10406 else
10408 add_AT_flag (type_die, DW_AT_declaration, 1);
10410 /* We don't need to do this for function-local types. */
10411 if (! decl_function_context (TYPE_STUB_DECL (type)))
10412 add_incomplete_type (type);
10416 /* Generate a DIE for a subroutine _type_. */
10418 static void
10419 gen_subroutine_type_die (type, context_die)
10420 register tree type;
10421 register dw_die_ref context_die;
10423 register tree return_type = TREE_TYPE (type);
10424 register dw_die_ref subr_die
10425 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
10427 equate_type_number_to_die (type, subr_die);
10428 add_prototyped_attribute (subr_die, type);
10429 add_type_attribute (subr_die, return_type, 0, 0, context_die);
10430 gen_formal_types_die (type, subr_die);
10433 /* Generate a DIE for a type definition */
10435 static void
10436 gen_typedef_die (decl, context_die)
10437 register tree decl;
10438 register dw_die_ref context_die;
10440 register dw_die_ref type_die;
10441 register tree origin;
10443 if (TREE_ASM_WRITTEN (decl))
10444 return;
10445 TREE_ASM_WRITTEN (decl) = 1;
10447 type_die = new_die (DW_TAG_typedef, context_die);
10448 origin = decl_ultimate_origin (decl);
10449 if (origin != NULL)
10450 add_abstract_origin_attribute (type_die, origin);
10451 else
10453 register tree type;
10454 add_name_and_src_coords_attributes (type_die, decl);
10455 if (DECL_ORIGINAL_TYPE (decl))
10457 type = DECL_ORIGINAL_TYPE (decl);
10459 if (type == TREE_TYPE (decl))
10460 abort ();
10461 else
10462 equate_type_number_to_die (TREE_TYPE (decl), type_die);
10464 else
10465 type = TREE_TYPE (decl);
10466 add_type_attribute (type_die, type, TREE_READONLY (decl),
10467 TREE_THIS_VOLATILE (decl), context_die);
10470 if (DECL_ABSTRACT (decl))
10471 equate_decl_number_to_die (decl, type_die);
10474 /* Generate a type description DIE. */
10476 static void
10477 gen_type_die (type, context_die)
10478 register tree type;
10479 register dw_die_ref context_die;
10481 int need_pop;
10483 if (type == NULL_TREE || type == error_mark_node)
10484 return;
10486 /* We are going to output a DIE to represent the unqualified version of
10487 this type (i.e. without any const or volatile qualifiers) so get the
10488 main variant (i.e. the unqualified version) of this type now. */
10489 type = type_main_variant (type);
10491 if (TREE_ASM_WRITTEN (type))
10492 return;
10494 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
10495 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
10497 TREE_ASM_WRITTEN (type) = 1;
10498 gen_decl_die (TYPE_NAME (type), context_die);
10499 return;
10502 switch (TREE_CODE (type))
10504 case ERROR_MARK:
10505 break;
10507 case POINTER_TYPE:
10508 case REFERENCE_TYPE:
10509 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
10510 ensures that the gen_type_die recursion will terminate even if the
10511 type is recursive. Recursive types are possible in Ada. */
10512 /* ??? We could perhaps do this for all types before the switch
10513 statement. */
10514 TREE_ASM_WRITTEN (type) = 1;
10516 /* For these types, all that is required is that we output a DIE (or a
10517 set of DIEs) to represent the "basis" type. */
10518 gen_type_die (TREE_TYPE (type), context_die);
10519 break;
10521 case OFFSET_TYPE:
10522 /* This code is used for C++ pointer-to-data-member types.
10523 Output a description of the relevant class type. */
10524 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
10526 /* Output a description of the type of the object pointed to. */
10527 gen_type_die (TREE_TYPE (type), context_die);
10529 /* Now output a DIE to represent this pointer-to-data-member type
10530 itself. */
10531 gen_ptr_to_mbr_type_die (type, context_die);
10532 break;
10534 case SET_TYPE:
10535 gen_type_die (TYPE_DOMAIN (type), context_die);
10536 gen_set_type_die (type, context_die);
10537 break;
10539 case FILE_TYPE:
10540 gen_type_die (TREE_TYPE (type), context_die);
10541 abort (); /* No way to represent these in Dwarf yet! */
10542 break;
10544 case FUNCTION_TYPE:
10545 /* Force out return type (in case it wasn't forced out already). */
10546 gen_type_die (TREE_TYPE (type), context_die);
10547 gen_subroutine_type_die (type, context_die);
10548 break;
10550 case METHOD_TYPE:
10551 /* Force out return type (in case it wasn't forced out already). */
10552 gen_type_die (TREE_TYPE (type), context_die);
10553 gen_subroutine_type_die (type, context_die);
10554 break;
10556 case ARRAY_TYPE:
10557 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
10559 gen_type_die (TREE_TYPE (type), context_die);
10560 gen_string_type_die (type, context_die);
10562 else
10563 gen_array_type_die (type, context_die);
10564 break;
10566 case VECTOR_TYPE:
10567 gen_type_die (TYPE_DEBUG_REPRESENTATION_TYPE (type), context_die);
10568 break;
10570 case ENUMERAL_TYPE:
10571 case RECORD_TYPE:
10572 case UNION_TYPE:
10573 case QUAL_UNION_TYPE:
10574 /* If this is a nested type whose containing class hasn't been
10575 written out yet, writing it out will cover this one, too.
10576 This does not apply to instantiations of member class templates;
10577 they need to be added to the containing class as they are
10578 generated. FIXME: This hurts the idea of combining type decls
10579 from multiple TUs, since we can't predict what set of template
10580 instantiations we'll get. */
10581 if (TYPE_CONTEXT (type)
10582 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
10583 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
10585 gen_type_die (TYPE_CONTEXT (type), context_die);
10587 if (TREE_ASM_WRITTEN (type))
10588 return;
10590 /* If that failed, attach ourselves to the stub. */
10591 push_decl_scope (TYPE_CONTEXT (type));
10592 context_die = lookup_type_die (TYPE_CONTEXT (type));
10593 need_pop = 1;
10595 else
10596 need_pop = 0;
10598 if (TREE_CODE (type) == ENUMERAL_TYPE)
10599 gen_enumeration_type_die (type, context_die);
10600 else
10601 gen_struct_or_union_type_die (type, context_die);
10603 if (need_pop)
10604 pop_decl_scope ();
10606 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
10607 it up if it is ever completed. gen_*_type_die will set it for us
10608 when appropriate. */
10609 return;
10611 case VOID_TYPE:
10612 case INTEGER_TYPE:
10613 case REAL_TYPE:
10614 case COMPLEX_TYPE:
10615 case BOOLEAN_TYPE:
10616 case CHAR_TYPE:
10617 /* No DIEs needed for fundamental types. */
10618 break;
10620 case LANG_TYPE:
10621 /* No Dwarf representation currently defined. */
10622 break;
10624 default:
10625 abort ();
10628 TREE_ASM_WRITTEN (type) = 1;
10631 /* Generate a DIE for a tagged type instantiation. */
10633 static void
10634 gen_tagged_type_instantiation_die (type, context_die)
10635 register tree type;
10636 register dw_die_ref context_die;
10638 if (type == NULL_TREE || type == error_mark_node)
10639 return;
10641 /* We are going to output a DIE to represent the unqualified version of
10642 this type (i.e. without any const or volatile qualifiers) so make sure
10643 that we have the main variant (i.e. the unqualified version) of this
10644 type now. */
10645 if (type != type_main_variant (type))
10646 abort ();
10648 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
10649 an instance of an unresolved type. */
10651 switch (TREE_CODE (type))
10653 case ERROR_MARK:
10654 break;
10656 case ENUMERAL_TYPE:
10657 gen_inlined_enumeration_type_die (type, context_die);
10658 break;
10660 case RECORD_TYPE:
10661 gen_inlined_structure_type_die (type, context_die);
10662 break;
10664 case UNION_TYPE:
10665 case QUAL_UNION_TYPE:
10666 gen_inlined_union_type_die (type, context_die);
10667 break;
10669 default:
10670 abort ();
10674 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
10675 things which are local to the given block. */
10677 static void
10678 gen_block_die (stmt, context_die, depth)
10679 register tree stmt;
10680 register dw_die_ref context_die;
10681 int depth;
10683 register int must_output_die = 0;
10684 register tree origin;
10685 register tree decl;
10686 register enum tree_code origin_code;
10688 /* Ignore blocks never really used to make RTL. */
10690 if (stmt == NULL_TREE || !TREE_USED (stmt)
10691 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt)))
10692 return;
10694 /* Determine the "ultimate origin" of this block. This block may be an
10695 inlined instance of an inlined instance of inline function, so we have
10696 to trace all of the way back through the origin chain to find out what
10697 sort of node actually served as the original seed for the creation of
10698 the current block. */
10699 origin = block_ultimate_origin (stmt);
10700 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
10702 /* Determine if we need to output any Dwarf DIEs at all to represent this
10703 block. */
10704 if (origin_code == FUNCTION_DECL)
10705 /* The outer scopes for inlinings *must* always be represented. We
10706 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
10707 must_output_die = 1;
10708 else
10710 /* In the case where the current block represents an inlining of the
10711 "body block" of an inline function, we must *NOT* output any DIE for
10712 this block because we have already output a DIE to represent the
10713 whole inlined function scope and the "body block" of any function
10714 doesn't really represent a different scope according to ANSI C
10715 rules. So we check here to make sure that this block does not
10716 represent a "body block inlining" before trying to set the
10717 `must_output_die' flag. */
10718 if (! is_body_block (origin ? origin : stmt))
10720 /* Determine if this block directly contains any "significant"
10721 local declarations which we will need to output DIEs for. */
10722 if (debug_info_level > DINFO_LEVEL_TERSE)
10723 /* We are not in terse mode so *any* local declaration counts
10724 as being a "significant" one. */
10725 must_output_die = (BLOCK_VARS (stmt) != NULL);
10726 else
10727 /* We are in terse mode, so only local (nested) function
10728 definitions count as "significant" local declarations. */
10729 for (decl = BLOCK_VARS (stmt);
10730 decl != NULL; decl = TREE_CHAIN (decl))
10731 if (TREE_CODE (decl) == FUNCTION_DECL
10732 && DECL_INITIAL (decl))
10734 must_output_die = 1;
10735 break;
10740 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
10741 DIE for any block which contains no significant local declarations at
10742 all. Rather, in such cases we just call `decls_for_scope' so that any
10743 needed Dwarf info for any sub-blocks will get properly generated. Note
10744 that in terse mode, our definition of what constitutes a "significant"
10745 local declaration gets restricted to include only inlined function
10746 instances and local (nested) function definitions. */
10747 if (must_output_die)
10749 if (origin_code == FUNCTION_DECL)
10750 gen_inlined_subroutine_die (stmt, context_die, depth);
10751 else
10752 gen_lexical_block_die (stmt, context_die, depth);
10754 else
10755 decls_for_scope (stmt, context_die, depth);
10758 /* Generate all of the decls declared within a given scope and (recursively)
10759 all of its sub-blocks. */
10761 static void
10762 decls_for_scope (stmt, context_die, depth)
10763 register tree stmt;
10764 register dw_die_ref context_die;
10765 int depth;
10767 register tree decl;
10768 register tree subblocks;
10770 /* Ignore blocks never really used to make RTL. */
10771 if (stmt == NULL_TREE || ! TREE_USED (stmt))
10772 return;
10774 /* Output the DIEs to represent all of the data objects and typedefs
10775 declared directly within this block but not within any nested
10776 sub-blocks. Also, nested function and tag DIEs have been
10777 generated with a parent of NULL; fix that up now. */
10778 for (decl = BLOCK_VARS (stmt);
10779 decl != NULL; decl = TREE_CHAIN (decl))
10781 register dw_die_ref die;
10783 if (TREE_CODE (decl) == FUNCTION_DECL)
10784 die = lookup_decl_die (decl);
10785 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
10786 die = lookup_type_die (TREE_TYPE (decl));
10787 else
10788 die = NULL;
10790 if (die != NULL && die->die_parent == NULL)
10791 add_child_die (context_die, die);
10792 else
10793 gen_decl_die (decl, context_die);
10796 /* Output the DIEs to represent all sub-blocks (and the items declared
10797 therein) of this block. */
10798 for (subblocks = BLOCK_SUBBLOCKS (stmt);
10799 subblocks != NULL;
10800 subblocks = BLOCK_CHAIN (subblocks))
10801 gen_block_die (subblocks, context_die, depth + 1);
10804 /* Is this a typedef we can avoid emitting? */
10806 static inline int
10807 is_redundant_typedef (decl)
10808 register tree decl;
10810 if (TYPE_DECL_IS_STUB (decl))
10811 return 1;
10813 if (DECL_ARTIFICIAL (decl)
10814 && DECL_CONTEXT (decl)
10815 && is_tagged_type (DECL_CONTEXT (decl))
10816 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
10817 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
10818 /* Also ignore the artificial member typedef for the class name. */
10819 return 1;
10821 return 0;
10824 /* Generate Dwarf debug information for a decl described by DECL. */
10826 static void
10827 gen_decl_die (decl, context_die)
10828 register tree decl;
10829 register dw_die_ref context_die;
10831 register tree origin;
10833 if (TREE_CODE (decl) == ERROR_MARK)
10834 return;
10836 /* If this ..._DECL node is marked to be ignored, then ignore it. */
10837 if (DECL_IGNORED_P (decl))
10838 return;
10840 switch (TREE_CODE (decl))
10842 case CONST_DECL:
10843 /* The individual enumerators of an enum type get output when we output
10844 the Dwarf representation of the relevant enum type itself. */
10845 break;
10847 case FUNCTION_DECL:
10848 /* Don't output any DIEs to represent mere function declarations,
10849 unless they are class members or explicit block externs. */
10850 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
10851 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
10852 break;
10854 /* If we're emitting a clone, emit info for the abstract instance. */
10855 if (DECL_ORIGIN (decl) != decl)
10856 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl));
10857 /* If we're emitting an out-of-line copy of an inline function,
10858 emit info for the abstract instance and set up to refer to it. */
10859 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl)
10860 && ! class_scope_p (context_die)
10861 /* dwarf2out_abstract_function won't emit a die if this is just
10862 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
10863 that case, because that works only if we have a die. */
10864 && DECL_INITIAL (decl) != NULL_TREE)
10866 dwarf2out_abstract_function (decl);
10867 set_decl_origin_self (decl);
10869 /* Otherwise we're emitting the primary DIE for this decl. */
10870 else if (debug_info_level > DINFO_LEVEL_TERSE)
10872 /* Before we describe the FUNCTION_DECL itself, make sure that we
10873 have described its return type. */
10874 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
10876 /* And its virtual context. */
10877 if (DECL_VINDEX (decl) != NULL_TREE)
10878 gen_type_die (DECL_CONTEXT (decl), context_die);
10880 /* And its containing type. */
10881 origin = decl_class_context (decl);
10882 if (origin != NULL_TREE)
10883 gen_type_die_for_member (origin, decl, context_die);
10886 /* Now output a DIE to represent the function itself. */
10887 gen_subprogram_die (decl, context_die);
10888 break;
10890 case TYPE_DECL:
10891 /* If we are in terse mode, don't generate any DIEs to represent any
10892 actual typedefs. */
10893 if (debug_info_level <= DINFO_LEVEL_TERSE)
10894 break;
10896 /* In the special case of a TYPE_DECL node representing the
10897 declaration of some type tag, if the given TYPE_DECL is marked as
10898 having been instantiated from some other (original) TYPE_DECL node
10899 (e.g. one which was generated within the original definition of an
10900 inline function) we have to generate a special (abbreviated)
10901 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
10902 DIE here. */
10903 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
10905 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
10906 break;
10909 if (is_redundant_typedef (decl))
10910 gen_type_die (TREE_TYPE (decl), context_die);
10911 else
10912 /* Output a DIE to represent the typedef itself. */
10913 gen_typedef_die (decl, context_die);
10914 break;
10916 case LABEL_DECL:
10917 if (debug_info_level >= DINFO_LEVEL_NORMAL)
10918 gen_label_die (decl, context_die);
10919 break;
10921 case VAR_DECL:
10922 /* If we are in terse mode, don't generate any DIEs to represent any
10923 variable declarations or definitions. */
10924 if (debug_info_level <= DINFO_LEVEL_TERSE)
10925 break;
10927 /* Output any DIEs that are needed to specify the type of this data
10928 object. */
10929 gen_type_die (TREE_TYPE (decl), context_die);
10931 /* And its containing type. */
10932 origin = decl_class_context (decl);
10933 if (origin != NULL_TREE)
10934 gen_type_die_for_member (origin, decl, context_die);
10936 /* Now output the DIE to represent the data object itself. This gets
10937 complicated because of the possibility that the VAR_DECL really
10938 represents an inlined instance of a formal parameter for an inline
10939 function. */
10940 origin = decl_ultimate_origin (decl);
10941 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
10942 gen_formal_parameter_die (decl, context_die);
10943 else
10944 gen_variable_die (decl, context_die);
10945 break;
10947 case FIELD_DECL:
10948 /* Ignore the nameless fields that are used to skip bits, but
10949 handle C++ anonymous unions. */
10950 if (DECL_NAME (decl) != NULL_TREE
10951 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
10953 gen_type_die (member_declared_type (decl), context_die);
10954 gen_field_die (decl, context_die);
10956 break;
10958 case PARM_DECL:
10959 gen_type_die (TREE_TYPE (decl), context_die);
10960 gen_formal_parameter_die (decl, context_die);
10961 break;
10963 case NAMESPACE_DECL:
10964 /* Ignore for now. */
10965 break;
10967 default:
10968 abort ();
10972 /* Add Ada "use" clause information for SGI Workshop debugger. */
10974 void
10975 dwarf2out_add_library_unit_info (filename, context_list)
10976 const char *filename;
10977 const char *context_list;
10979 unsigned int file_index;
10981 if (filename != NULL)
10983 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
10984 tree context_list_decl
10985 = build_decl (LABEL_DECL, get_identifier (context_list),
10986 void_type_node);
10988 TREE_PUBLIC (context_list_decl) = TRUE;
10989 add_name_attribute (unit_die, context_list);
10990 file_index = lookup_filename (filename);
10991 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
10992 add_pubname (context_list_decl, unit_die);
10996 /* Write the debugging output for DECL. */
10998 void
10999 dwarf2out_decl (decl)
11000 register tree decl;
11002 register dw_die_ref context_die = comp_unit_die;
11004 if (TREE_CODE (decl) == ERROR_MARK)
11005 return;
11007 /* If this ..._DECL node is marked to be ignored, then ignore it. */
11008 if (DECL_IGNORED_P (decl))
11009 return;
11011 switch (TREE_CODE (decl))
11013 case FUNCTION_DECL:
11014 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
11015 builtin function. Explicit programmer-supplied declarations of
11016 these same functions should NOT be ignored however. */
11017 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
11018 return;
11020 /* What we would really like to do here is to filter out all mere
11021 file-scope declarations of file-scope functions which are never
11022 referenced later within this translation unit (and keep all of ones
11023 that *are* referenced later on) but we aren't clairvoyant, so we have
11024 no idea which functions will be referenced in the future (i.e. later
11025 on within the current translation unit). So here we just ignore all
11026 file-scope function declarations which are not also definitions. If
11027 and when the debugger needs to know something about these functions,
11028 it will have to hunt around and find the DWARF information associated
11029 with the definition of the function. Note that we can't just check
11030 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
11031 definitions and which ones represent mere declarations. We have to
11032 check `DECL_INITIAL' instead. That's because the C front-end
11033 supports some weird semantics for "extern inline" function
11034 definitions. These can get inlined within the current translation
11035 unit (an thus, we need to generate DWARF info for their abstract
11036 instances so that the DWARF info for the concrete inlined instances
11037 can have something to refer to) but the compiler never generates any
11038 out-of-lines instances of such things (despite the fact that they
11039 *are* definitions). The important point is that the C front-end
11040 marks these "extern inline" functions as DECL_EXTERNAL, but we need
11041 to generate DWARF for them anyway. Note that the C++ front-end also
11042 plays some similar games for inline function definitions appearing
11043 within include files which also contain
11044 `#pragma interface' pragmas. */
11045 if (DECL_INITIAL (decl) == NULL_TREE)
11046 return;
11048 /* If we're a nested function, initially use a parent of NULL; if we're
11049 a plain function, this will be fixed up in decls_for_scope. If
11050 we're a method, it will be ignored, since we already have a DIE. */
11051 if (decl_function_context (decl))
11052 context_die = NULL;
11054 break;
11056 case VAR_DECL:
11057 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
11058 declaration and if the declaration was never even referenced from
11059 within this entire compilation unit. We suppress these DIEs in
11060 order to save space in the .debug section (by eliminating entries
11061 which are probably useless). Note that we must not suppress
11062 block-local extern declarations (whether used or not) because that
11063 would screw-up the debugger's name lookup mechanism and cause it to
11064 miss things which really ought to be in scope at a given point. */
11065 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
11066 return;
11068 /* If we are in terse mode, don't generate any DIEs to represent any
11069 variable declarations or definitions. */
11070 if (debug_info_level <= DINFO_LEVEL_TERSE)
11071 return;
11072 break;
11074 case TYPE_DECL:
11075 /* Don't emit stubs for types unless they are needed by other DIEs. */
11076 if (TYPE_DECL_SUPPRESS_DEBUG (decl))
11077 return;
11079 /* Don't bother trying to generate any DIEs to represent any of the
11080 normal built-in types for the language we are compiling. */
11081 if (DECL_SOURCE_LINE (decl) == 0)
11083 /* OK, we need to generate one for `bool' so GDB knows what type
11084 comparisons have. */
11085 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
11086 == DW_LANG_C_plus_plus)
11087 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
11088 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
11090 return;
11093 /* If we are in terse mode, don't generate any DIEs for types. */
11094 if (debug_info_level <= DINFO_LEVEL_TERSE)
11095 return;
11097 /* If we're a function-scope tag, initially use a parent of NULL;
11098 this will be fixed up in decls_for_scope. */
11099 if (decl_function_context (decl))
11100 context_die = NULL;
11102 break;
11104 default:
11105 return;
11108 gen_decl_die (decl, context_die);
11111 /* Output a marker (i.e. a label) for the beginning of the generated code for
11112 a lexical block. */
11114 static void
11115 dwarf2out_begin_block (line, blocknum)
11116 unsigned int line ATTRIBUTE_UNUSED;
11117 unsigned int blocknum;
11119 function_section (current_function_decl);
11120 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
11123 /* Output a marker (i.e. a label) for the end of the generated code for a
11124 lexical block. */
11126 static void
11127 dwarf2out_end_block (line, blocknum)
11128 unsigned int line ATTRIBUTE_UNUSED;
11129 unsigned int blocknum;
11131 function_section (current_function_decl);
11132 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
11135 /* Returns nonzero if it is appropriate not to emit any debugging
11136 information for BLOCK, because it doesn't contain any instructions.
11138 Don't allow this for blocks with nested functions or local classes
11139 as we would end up with orphans, and in the presence of scheduling
11140 we may end up calling them anyway. */
11143 dwarf2out_ignore_block (block)
11144 tree block;
11146 tree decl;
11147 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
11148 if (TREE_CODE (decl) == FUNCTION_DECL
11149 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)))
11150 return 0;
11151 return 1;
11154 /* Lookup a filename (in the list of filenames that we know about here in
11155 dwarf2out.c) and return its "index". The index of each (known) filename is
11156 just a unique number which is associated with only that one filename.
11157 We need such numbers for the sake of generating labels
11158 (in the .debug_sfnames section) and references to those
11159 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
11160 If the filename given as an argument is not found in our current list,
11161 add it to the list and assign it the next available unique index number.
11162 In order to speed up searches, we remember the index of the filename
11163 was looked up last. This handles the majority of all searches. */
11165 static unsigned
11166 lookup_filename (file_name)
11167 const char *file_name;
11169 register unsigned i;
11171 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */
11172 if (strcmp (file_name, "<internal>") == 0
11173 || strcmp (file_name, "<built-in>") == 0)
11174 return 0;
11176 /* Check to see if the file name that was searched on the previous
11177 call matches this file name. If so, return the index. */
11178 if (file_table.last_lookup_index != 0)
11179 if (strcmp (file_name, file_table.table[file_table.last_lookup_index]) == 0)
11180 return file_table.last_lookup_index;
11182 /* Didn't match the previous lookup, search the table */
11183 for (i = 1; i < file_table.in_use; ++i)
11184 if (strcmp (file_name, file_table.table[i]) == 0)
11186 file_table.last_lookup_index = i;
11187 return i;
11190 /* Prepare to add a new table entry by making sure there is enough space in
11191 the table to do so. If not, expand the current table. */
11192 if (i == file_table.allocated)
11194 file_table.allocated = i + FILE_TABLE_INCREMENT;
11195 file_table.table = (char **)
11196 xrealloc (file_table.table, file_table.allocated * sizeof (char *));
11199 /* Add the new entry to the end of the filename table. */
11200 file_table.table[i] = xstrdup (file_name);
11201 file_table.in_use = i + 1;
11202 file_table.last_lookup_index = i;
11204 if (DWARF2_ASM_LINE_DEBUG_INFO)
11205 fprintf (asm_out_file, "\t.file %u \"%s\"\n", i, file_name);
11207 return i;
11210 static void
11211 init_file_table ()
11213 /* Allocate the initial hunk of the file_table. */
11214 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
11215 file_table.allocated = FILE_TABLE_INCREMENT;
11217 /* Skip the first entry - file numbers begin at 1. */
11218 file_table.in_use = 1;
11219 file_table.last_lookup_index = 0;
11222 /* Output a label to mark the beginning of a source code line entry
11223 and record information relating to this source line, in
11224 'line_info_table' for later output of the .debug_line section. */
11226 static void
11227 dwarf2out_source_line (filename, note)
11228 register const char *filename;
11229 rtx note;
11231 unsigned int line = NOTE_LINE_NUMBER (note);
11233 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11235 function_section (current_function_decl);
11237 /* If requested, emit something human-readable. */
11238 if (flag_debug_asm)
11239 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START,
11240 filename, line);
11242 if (DWARF2_ASM_LINE_DEBUG_INFO)
11244 unsigned file_num = lookup_filename (filename);
11246 /* Emit the .loc directive understood by GNU as. */
11247 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
11249 /* Indicate that line number info exists. */
11250 ++line_info_table_in_use;
11252 /* Indicate that multiple line number tables exist. */
11253 if (DECL_SECTION_NAME (current_function_decl))
11254 ++separate_line_info_table_in_use;
11256 else if (DECL_SECTION_NAME (current_function_decl))
11258 register dw_separate_line_info_ref line_info;
11259 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
11260 separate_line_info_table_in_use);
11262 /* expand the line info table if necessary */
11263 if (separate_line_info_table_in_use
11264 == separate_line_info_table_allocated)
11266 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11267 separate_line_info_table
11268 = (dw_separate_line_info_ref)
11269 xrealloc (separate_line_info_table,
11270 separate_line_info_table_allocated
11271 * sizeof (dw_separate_line_info_entry));
11274 /* Add the new entry at the end of the line_info_table. */
11275 line_info
11276 = &separate_line_info_table[separate_line_info_table_in_use++];
11277 line_info->dw_file_num = lookup_filename (filename);
11278 line_info->dw_line_num = line;
11279 line_info->function = current_funcdef_number;
11281 else
11283 register dw_line_info_ref line_info;
11285 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
11286 line_info_table_in_use);
11288 /* Expand the line info table if necessary. */
11289 if (line_info_table_in_use == line_info_table_allocated)
11291 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
11292 line_info_table
11293 = (dw_line_info_ref)
11294 xrealloc (line_info_table,
11295 (line_info_table_allocated
11296 * sizeof (dw_line_info_entry)));
11299 /* Add the new entry at the end of the line_info_table. */
11300 line_info = &line_info_table[line_info_table_in_use++];
11301 line_info->dw_file_num = lookup_filename (filename);
11302 line_info->dw_line_num = line;
11307 /* Record the beginning of a new source file. */
11309 static void
11310 dwarf2out_start_source_file (lineno, filename)
11311 register unsigned int lineno;
11312 register const char *filename;
11314 if (flag_eliminate_dwarf2_dups)
11316 /* Record the beginning of the file for break_out_includes. */
11317 dw_die_ref bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die);
11318 add_AT_string (bincl_die, DW_AT_name, filename);
11320 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11322 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11323 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file");
11324 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", lineno);
11325 dw2_asm_output_data_uleb128 (lookup_filename (filename), "Filename we just started");
11329 /* Record the end of a source file. */
11331 static void
11332 dwarf2out_end_source_file (lineno)
11333 unsigned int lineno ATTRIBUTE_UNUSED;
11335 if (flag_eliminate_dwarf2_dups)
11337 /* Record the end of the file for break_out_includes. */
11338 new_die (DW_TAG_GNU_EINCL, comp_unit_die);
11340 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11342 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11343 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11347 /* Called from debug_define in toplev.c. The `buffer' parameter contains
11348 the tail part of the directive line, i.e. the part which is past the
11349 initial whitespace, #, whitespace, directive-name, whitespace part. */
11351 static void
11352 dwarf2out_define (lineno, buffer)
11353 register unsigned lineno ATTRIBUTE_UNUSED;
11354 register const char *buffer ATTRIBUTE_UNUSED;
11356 static int initialized = 0;
11357 if (!initialized)
11359 dwarf2out_start_source_file (0, primary_filename);
11360 initialized = 1;
11362 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11364 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11365 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro");
11366 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11367 dw2_asm_output_nstring (buffer, -1, "The macro");
11371 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
11372 the tail part of the directive line, i.e. the part which is past the
11373 initial whitespace, #, whitespace, directive-name, whitespace part. */
11375 static void
11376 dwarf2out_undef (lineno, buffer)
11377 register unsigned lineno ATTRIBUTE_UNUSED;
11378 register const char *buffer ATTRIBUTE_UNUSED;
11380 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11382 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11383 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro");
11384 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno);
11385 dw2_asm_output_nstring (buffer, -1, "The macro");
11389 /* Set up for Dwarf output at the start of compilation. */
11391 static void
11392 dwarf2out_init (main_input_filename)
11393 register const char *main_input_filename;
11395 init_file_table ();
11397 /* Remember the name of the primary input file. */
11398 primary_filename = main_input_filename;
11400 /* Add it to the file table first, under the assumption that we'll
11401 be emitting line number data for it first, which avoids having
11402 to add an initial DW_LNS_set_file. */
11403 lookup_filename (main_input_filename);
11405 /* Allocate the initial hunk of the decl_die_table. */
11406 decl_die_table
11407 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
11408 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
11409 decl_die_table_in_use = 0;
11411 /* Allocate the initial hunk of the decl_scope_table. */
11412 decl_scope_table
11413 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
11414 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
11415 decl_scope_depth = 0;
11417 /* Allocate the initial hunk of the abbrev_die_table. */
11418 abbrev_die_table
11419 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
11420 sizeof (dw_die_ref));
11421 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
11422 /* Zero-th entry is allocated, but unused */
11423 abbrev_die_table_in_use = 1;
11425 /* Allocate the initial hunk of the line_info_table. */
11426 line_info_table
11427 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
11428 sizeof (dw_line_info_entry));
11429 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
11430 /* Zero-th entry is allocated, but unused */
11431 line_info_table_in_use = 1;
11433 /* Generate the initial DIE for the .debug section. Note that the (string)
11434 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
11435 will (typically) be a relative pathname and that this pathname should be
11436 taken as being relative to the directory from which the compiler was
11437 invoked when the given (base) source file was compiled. */
11438 comp_unit_die = gen_compile_unit_die (main_input_filename);
11440 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
11441 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
11443 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
11444 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label,
11445 DEBUG_ABBREV_SECTION_LABEL, 0);
11446 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11447 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
11448 else
11449 strcpy (text_section_label, stripattributes (TEXT_SECTION));
11450 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
11451 DEBUG_INFO_SECTION_LABEL, 0);
11452 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
11453 DEBUG_LINE_SECTION_LABEL, 0);
11454 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, DEBUG_LOC_SECTION_LABEL, 0);
11455 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11456 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label);
11457 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11458 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
11459 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
11461 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11462 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
11464 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
11465 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
11466 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11467 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
11468 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11470 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11471 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label,
11472 DEBUG_MACINFO_SECTION_LABEL, 0);
11473 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label);
11477 /* Output stuff that dwarf requires at the end of every file,
11478 and generate the DWARF-2 debugging info. */
11480 static void
11481 dwarf2out_finish (input_filename)
11482 register const char *input_filename ATTRIBUTE_UNUSED;
11484 limbo_die_node *node, *next_node;
11485 dw_die_ref die = 0;
11487 /* Traverse the limbo die list, and add parent/child links. The only
11488 dies without parents that should be here are concrete instances of
11489 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
11490 For concrete instances, we can get the parent die from the abstract
11491 instance. */
11492 for (node = limbo_die_list; node; node = next_node)
11494 next_node = node->next;
11495 die = node->die;
11497 if (die->die_parent == NULL)
11499 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
11500 if (origin)
11501 add_child_die (origin->die_parent, die);
11502 else if (die == comp_unit_die)
11504 else
11505 abort ();
11507 free (node);
11509 limbo_die_list = NULL;
11511 /* Walk through the list of incomplete types again, trying once more to
11512 emit full debugging info for them. */
11513 retry_incomplete_types ();
11515 /* We need to reverse all the dies before break_out_includes, or
11516 we'll see the end of an include file before the beginning. */
11517 reverse_all_dies (comp_unit_die);
11519 /* Generate separate CUs for each of the include files we've seen.
11520 They will go into limbo_die_list. */
11521 if (flag_eliminate_dwarf2_dups)
11522 break_out_includes (comp_unit_die);
11524 /* Traverse the DIE's and add add sibling attributes to those DIE's
11525 that have children. */
11526 add_sibling_attributes (comp_unit_die);
11527 for (node = limbo_die_list; node; node = node->next)
11528 add_sibling_attributes (node->die);
11530 /* Output a terminator label for the .text section. */
11531 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
11532 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
11534 #if 0
11535 /* Output a terminator label for the .data section. */
11536 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
11537 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
11539 /* Output a terminator label for the .bss section. */
11540 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
11541 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
11542 #endif
11544 /* Output the source line correspondence table. We must do this
11545 even if there is no line information. Otherwise, on an empty
11546 translation unit, we will generate a present, but empty,
11547 .debug_info section. IRIX 6.5 `nm' will then complain when
11548 examining the file. */
11549 if (! DWARF2_ASM_LINE_DEBUG_INFO)
11551 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
11552 output_line_info ();
11555 /* We can only use the low/high_pc attributes if all of the code was
11556 in .text. */
11557 if (separate_line_info_table_in_use == 0)
11559 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
11560 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
11563 if (debug_info_level >= DINFO_LEVEL_NORMAL)
11564 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
11565 debug_line_section_label);
11567 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11568 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label);
11570 /* Output all of the compilation units. We put the main one last so that
11571 the offsets are available to output_pubnames. */
11572 for (node = limbo_die_list; node; node = node->next)
11573 output_comp_unit (node->die);
11574 output_comp_unit (comp_unit_die);
11576 /* Output the abbreviation table. */
11577 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ABBREV_SECTION);
11578 output_abbrev_section ();
11580 if (pubname_table_in_use)
11582 /* Output public names table. */
11583 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION);
11584 output_pubnames ();
11587 /* We only put functions in the arange table, so don't write it out if
11588 we don't have any. */
11589 if (fde_table_in_use)
11591 /* Output the address range information. */
11592 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_ARANGES_SECTION);
11593 output_aranges ();
11595 /* Output location list section if necessary */
11596 if (have_location_lists)
11598 /* Output the location lists info. */
11599 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LOC_SECTION);
11600 output_location_lists (die);
11601 have_location_lists = 0;
11604 /* Have to end the primary source file. */
11605 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
11607 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_MACINFO_SECTION);
11608 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file");
11612 #endif /* DWARF2_DEBUGGING_INFO */