oops - omitted from previous delta fixing UNIQUE_SECTION
[official-gcc.git] / gcc / dwarf2out.c
blob2ca007a4b057c2d63ead10c217bb2607e16527c4
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 93, 95-99, 2000 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* TODO: Implement .debug_str handling, and share entries somehow.
25 Eliminate duplicates by putting common info in a separate section
26 to be collected by the linker and referring to it with
27 DW_FORM_ref_addr.
28 Emit .debug_line header even when there are no functions, since
29 the file numbers are used by .debug_info. Alternately, leave
30 out locations for types and decls.
31 Avoid talking about ctors and op= for PODs.
32 Factor out common prologue sequences into multiple CIEs. */
34 /* The first part of this file deals with the DWARF 2 frame unwind
35 information, which is also used by the GCC efficient exception handling
36 mechanism. The second part, controlled only by an #ifdef
37 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
38 information. */
40 #include "config.h"
41 #include "system.h"
42 #include "defaults.h"
43 #include "tree.h"
44 #include "flags.h"
45 #include "rtl.h"
46 #include "hard-reg-set.h"
47 #include "regs.h"
48 #include "insn-config.h"
49 #include "reload.h"
50 #include "output.h"
51 #include "expr.h"
52 #include "except.h"
53 #include "dwarf2.h"
54 #include "dwarf2out.h"
55 #include "toplev.h"
56 #include "varray.h"
57 #include "ggc.h"
58 #include "tm_p.h"
60 /* We cannot use <assert.h> in GCC source, since that would include
61 GCC's assert.h, which may not be compatible with the host compiler. */
62 #undef assert
63 #ifdef NDEBUG
64 # define assert(e)
65 #else
66 # define assert(e) do { if (! (e)) abort (); } while (0)
67 #endif
69 /* Decide whether we want to emit frame unwind information for the current
70 translation unit. */
72 int
73 dwarf2out_do_frame ()
75 return (write_symbols == DWARF2_DEBUG
76 #ifdef DWARF2_FRAME_INFO
77 || DWARF2_FRAME_INFO
78 #endif
79 #ifdef DWARF2_UNWIND_INFO
80 || flag_unwind_tables
81 || (flag_exceptions && ! exceptions_via_longjmp)
82 #endif
86 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
88 /* How to start an assembler comment. */
89 #ifndef ASM_COMMENT_START
90 #define ASM_COMMENT_START ";#"
91 #endif
93 typedef struct dw_cfi_struct *dw_cfi_ref;
94 typedef struct dw_fde_struct *dw_fde_ref;
95 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
97 /* Call frames are described using a sequence of Call Frame
98 Information instructions. The register number, offset
99 and address fields are provided as possible operands;
100 their use is selected by the opcode field. */
102 typedef union dw_cfi_oprnd_struct
104 unsigned long dw_cfi_reg_num;
105 long int dw_cfi_offset;
106 char *dw_cfi_addr;
108 dw_cfi_oprnd;
110 typedef struct dw_cfi_struct
112 dw_cfi_ref dw_cfi_next;
113 enum dwarf_call_frame_info dw_cfi_opc;
114 dw_cfi_oprnd dw_cfi_oprnd1;
115 dw_cfi_oprnd dw_cfi_oprnd2;
117 dw_cfi_node;
119 /* All call frame descriptions (FDE's) in the GCC generated DWARF
120 refer to a single Common Information Entry (CIE), defined at
121 the beginning of the .debug_frame section. This used of a single
122 CIE obviates the need to keep track of multiple CIE's
123 in the DWARF generation routines below. */
125 typedef struct dw_fde_struct
127 char *dw_fde_begin;
128 char *dw_fde_current_label;
129 char *dw_fde_end;
130 dw_cfi_ref dw_fde_cfi;
132 dw_fde_node;
134 /* Maximum size (in bytes) of an artificially generated label. */
135 #define MAX_ARTIFICIAL_LABEL_BYTES 30
137 /* Make sure we know the sizes of the various types dwarf can describe. These
138 are only defaults. If the sizes are different for your target, you should
139 override these values by defining the appropriate symbols in your tm.h
140 file. */
142 #ifndef CHAR_TYPE_SIZE
143 #define CHAR_TYPE_SIZE BITS_PER_UNIT
144 #endif
145 #ifndef PTR_SIZE
146 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
147 #endif
149 /* The size in bytes of a DWARF field indicating an offset or length
150 relative to a debug info section, specified to be 4 bytes in the DWARF-2
151 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
153 #ifndef DWARF_OFFSET_SIZE
154 #define DWARF_OFFSET_SIZE 4
155 #endif
157 #define DWARF_VERSION 2
159 /* Round SIZE up to the nearest BOUNDARY. */
160 #define DWARF_ROUND(SIZE,BOUNDARY) \
161 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
163 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
164 #ifdef STACK_GROWS_DOWNWARD
165 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
166 #else
167 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
168 #endif
170 /* A pointer to the base of a table that contains frame description
171 information for each routine. */
172 static dw_fde_ref fde_table;
174 /* Number of elements currently allocated for fde_table. */
175 static unsigned fde_table_allocated;
177 /* Number of elements in fde_table currently in use. */
178 static unsigned fde_table_in_use;
180 /* Size (in elements) of increments by which we may expand the
181 fde_table. */
182 #define FDE_TABLE_INCREMENT 256
184 /* A list of call frame insns for the CIE. */
185 static dw_cfi_ref cie_cfi_head;
187 /* The number of the current function definition for which debugging
188 information is being generated. These numbers range from 1 up to the
189 maximum number of function definitions contained within the current
190 compilation unit. These numbers are used to create unique label id's
191 unique to each function definition. */
192 static unsigned current_funcdef_number = 0;
194 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
195 attribute that accelerates the lookup of the FDE associated
196 with the subprogram. This variable holds the table index of the FDE
197 associated with the current function (body) definition. */
198 static unsigned current_funcdef_fde;
200 /* Forward declarations for functions defined in this file. */
202 static char *stripattributes PARAMS ((const char *));
203 static const char *dwarf_cfi_name PARAMS ((unsigned));
204 static dw_cfi_ref new_cfi PARAMS ((void));
205 static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref));
206 static unsigned long size_of_uleb128 PARAMS ((unsigned long));
207 static unsigned long size_of_sleb128 PARAMS ((long));
208 static void output_uleb128 PARAMS ((unsigned long));
209 static void output_sleb128 PARAMS ((long));
210 static void add_fde_cfi PARAMS ((char *, dw_cfi_ref));
211 static void lookup_cfa_1 PARAMS ((dw_cfi_ref, unsigned long *,
212 long *));
213 static void lookup_cfa PARAMS ((unsigned long *, long *));
214 static void reg_save PARAMS ((char *, unsigned, unsigned,
215 long));
216 static void initial_return_save PARAMS ((rtx));
217 static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref));
218 static void output_call_frame_info PARAMS ((int));
219 static unsigned reg_number PARAMS ((rtx));
220 static void dwarf2out_stack_adjust PARAMS ((rtx));
221 static void dwarf2out_frame_debug_expr PARAMS ((rtx, char *));
223 /* Definitions of defaults for assembler-dependent names of various
224 pseudo-ops and section names.
225 Theses may be overridden in the tm.h file (if necessary) for a particular
226 assembler. */
228 #ifdef OBJECT_FORMAT_ELF
229 #ifndef UNALIGNED_SHORT_ASM_OP
230 #define UNALIGNED_SHORT_ASM_OP ".2byte"
231 #endif
232 #ifndef UNALIGNED_INT_ASM_OP
233 #define UNALIGNED_INT_ASM_OP ".4byte"
234 #endif
235 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
236 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
237 #endif
238 #endif /* OBJECT_FORMAT_ELF */
240 #ifndef ASM_BYTE_OP
241 #define ASM_BYTE_OP ".byte"
242 #endif
244 /* Data and reference forms for relocatable data. */
245 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
246 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
248 /* Pseudo-op for defining a new section. */
249 #ifndef SECTION_ASM_OP
250 #define SECTION_ASM_OP ".section"
251 #endif
253 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
254 print the SECTION_ASM_OP and the section name. The default here works for
255 almost all svr4 assemblers, except for the sparc, where the section name
256 must be enclosed in double quotes. (See sparcv4.h). */
257 #ifndef SECTION_FORMAT
258 #ifdef PUSHSECTION_FORMAT
259 #define SECTION_FORMAT PUSHSECTION_FORMAT
260 #else
261 #define SECTION_FORMAT "\t%s\t%s\n"
262 #endif
263 #endif
265 #ifndef FRAME_SECTION
266 #define FRAME_SECTION ".debug_frame"
267 #endif
269 #ifndef FUNC_BEGIN_LABEL
270 #define FUNC_BEGIN_LABEL "LFB"
271 #endif
272 #ifndef FUNC_END_LABEL
273 #define FUNC_END_LABEL "LFE"
274 #endif
275 #define CIE_AFTER_SIZE_LABEL "LSCIE"
276 #define CIE_END_LABEL "LECIE"
277 #define CIE_LENGTH_LABEL "LLCIE"
278 #define FDE_AFTER_SIZE_LABEL "LSFDE"
279 #define FDE_END_LABEL "LEFDE"
280 #define FDE_LENGTH_LABEL "LLFDE"
282 /* Definitions of defaults for various types of primitive assembly language
283 output operations. These may be overridden from within the tm.h file,
284 but typically, that is unnecessary. */
286 #ifndef ASM_OUTPUT_SECTION
287 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
288 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
289 #endif
291 #ifndef ASM_OUTPUT_DWARF_DATA1
292 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
293 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
294 #endif
296 #ifndef ASM_OUTPUT_DWARF_DELTA1
297 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
298 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
299 assemble_name (FILE, LABEL1); \
300 fprintf (FILE, "-"); \
301 assemble_name (FILE, LABEL2); \
302 } while (0)
303 #endif
305 #ifdef UNALIGNED_INT_ASM_OP
307 #ifndef UNALIGNED_OFFSET_ASM_OP
308 #define UNALIGNED_OFFSET_ASM_OP \
309 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
310 #endif
312 #ifndef UNALIGNED_WORD_ASM_OP
313 #define UNALIGNED_WORD_ASM_OP \
314 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
315 #endif
317 #ifndef ASM_OUTPUT_DWARF_DELTA2
318 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
319 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
320 assemble_name (FILE, LABEL1); \
321 fprintf (FILE, "-"); \
322 assemble_name (FILE, LABEL2); \
323 } while (0)
324 #endif
326 #ifndef ASM_OUTPUT_DWARF_DELTA4
327 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
328 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
329 assemble_name (FILE, LABEL1); \
330 fprintf (FILE, "-"); \
331 assemble_name (FILE, LABEL2); \
332 } while (0)
333 #endif
335 #ifndef ASM_OUTPUT_DWARF_DELTA
336 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
337 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
338 assemble_name (FILE, LABEL1); \
339 fprintf (FILE, "-"); \
340 assemble_name (FILE, LABEL2); \
341 } while (0)
342 #endif
344 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
345 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
346 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
347 assemble_name (FILE, LABEL1); \
348 fprintf (FILE, "-"); \
349 assemble_name (FILE, LABEL2); \
350 } while (0)
351 #endif
353 #ifndef ASM_OUTPUT_DWARF_ADDR
354 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
355 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
356 assemble_name (FILE, LABEL); \
357 } while (0)
358 #endif
360 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
361 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
362 do { \
363 fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
364 output_addr_const ((FILE), (RTX)); \
365 fputc ('\n', (FILE)); \
366 } while (0)
367 #endif
369 #ifndef ASM_OUTPUT_DWARF_OFFSET4
370 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
371 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
372 assemble_name (FILE, LABEL); \
373 } while (0)
374 #endif
376 #ifndef ASM_OUTPUT_DWARF_OFFSET
377 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
378 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
379 assemble_name (FILE, LABEL); \
380 } while (0)
381 #endif
383 #ifndef ASM_OUTPUT_DWARF_DATA2
384 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
385 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
386 #endif
388 #ifndef ASM_OUTPUT_DWARF_DATA4
389 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
390 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
391 #endif
393 #ifndef ASM_OUTPUT_DWARF_DATA
394 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
395 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
396 (unsigned long) (VALUE))
397 #endif
399 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
400 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
401 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
402 (unsigned long) (VALUE))
403 #endif
405 #ifndef ASM_OUTPUT_DWARF_DATA8
406 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
407 do { \
408 if (WORDS_BIG_ENDIAN) \
410 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
411 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
413 else \
415 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
416 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
418 } while (0)
419 #endif
421 #else /* UNALIGNED_INT_ASM_OP */
423 /* We don't have unaligned support, let's hope the normal output works for
424 .debug_frame. */
426 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
427 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
429 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
430 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
432 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
433 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
435 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
436 assemble_integer (gen_rtx_MINUS (HImode, \
437 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
438 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
439 2, 1)
441 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
442 assemble_integer (gen_rtx_MINUS (SImode, \
443 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
444 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
445 4, 1)
447 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
448 assemble_integer (gen_rtx_MINUS (Pmode, \
449 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
450 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
451 PTR_SIZE, 1)
453 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
454 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
456 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
457 assemble_integer (GEN_INT (VALUE), 4, 1)
459 #endif /* UNALIGNED_INT_ASM_OP */
461 #ifdef SET_ASM_OP
462 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
463 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
464 do { \
465 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
466 assemble_name (FILE, SY); \
467 fputc (',', FILE); \
468 assemble_name (FILE, HI); \
469 fputc ('-', FILE); \
470 assemble_name (FILE, LO); \
471 } while (0)
472 #endif
473 #endif /* SET_ASM_OP */
475 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
476 newline is produced. When flag_debug_asm is asserted, we add commentary
477 at the end of the line, so we must avoid output of a newline here. */
478 #ifndef ASM_OUTPUT_DWARF_STRING
479 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
480 do { \
481 register int slen = strlen(P); \
482 register const char *p = (P); \
483 register int i; \
484 fprintf (FILE, "\t.ascii \""); \
485 for (i = 0; i < slen; i++) \
487 register int c = p[i]; \
488 if (c == '\"' || c == '\\') \
489 putc ('\\', FILE); \
490 if (ISPRINT(c)) \
491 putc (c, FILE); \
492 else \
494 fprintf (FILE, "\\%o", c); \
497 fprintf (FILE, "\\0\""); \
499 while (0)
500 #endif
502 /* The DWARF 2 CFA column which tracks the return address. Normally this
503 is the column for PC, or the first column after all of the hard
504 registers. */
505 #ifndef DWARF_FRAME_RETURN_COLUMN
506 #ifdef PC_REGNUM
507 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
508 #else
509 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS
510 #endif
511 #endif
513 /* The mapping from gcc register number to DWARF 2 CFA column number. By
514 default, we just provide columns for all registers. */
515 #ifndef DWARF_FRAME_REGNUM
516 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
517 #endif
519 /* Hook used by __throw. */
522 expand_builtin_dwarf_fp_regnum ()
524 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
527 /* The offset from the incoming value of %sp to the top of the stack frame
528 for the current function. */
529 #ifndef INCOMING_FRAME_SP_OFFSET
530 #define INCOMING_FRAME_SP_OFFSET 0
531 #endif
533 /* Return a pointer to a copy of the section string name S with all
534 attributes stripped off, and an asterisk prepended (for assemble_name). */
536 static inline char *
537 stripattributes (s)
538 const char *s;
540 char *stripped = xmalloc (strlen (s) + 2);
541 char *p = stripped;
543 *p++ = '*';
545 while (*s && *s != ',')
546 *p++ = *s++;
548 *p = '\0';
549 return stripped;
552 /* Return the register number described by a given RTL node. */
554 static unsigned
555 reg_number (rtl)
556 register rtx rtl;
558 register unsigned regno = REGNO (rtl);
560 if (regno >= DWARF_FRAME_REGISTERS)
562 warning ("internal regno botch: regno = %d\n", regno);
563 regno = 0;
566 regno = DBX_REGISTER_NUMBER (regno);
567 return regno;
570 /* Generate code to initialize the register size table. */
572 void
573 expand_builtin_init_dwarf_reg_sizes (address)
574 tree address;
576 int i;
577 enum machine_mode mode = TYPE_MODE (char_type_node);
578 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
579 rtx mem = gen_rtx_MEM (mode, addr);
581 for (i = 0; i < DWARF_FRAME_REGISTERS; ++i)
583 int offset = i * GET_MODE_SIZE (mode);
584 int size = GET_MODE_SIZE (reg_raw_mode[i]);
586 emit_move_insn (change_address (mem, mode,
587 plus_constant (addr, offset)),
588 GEN_INT (size));
592 /* Convert a DWARF call frame info. operation to its string name */
594 static const char *
595 dwarf_cfi_name (cfi_opc)
596 register unsigned cfi_opc;
598 switch (cfi_opc)
600 case DW_CFA_advance_loc:
601 return "DW_CFA_advance_loc";
602 case DW_CFA_offset:
603 return "DW_CFA_offset";
604 case DW_CFA_restore:
605 return "DW_CFA_restore";
606 case DW_CFA_nop:
607 return "DW_CFA_nop";
608 case DW_CFA_set_loc:
609 return "DW_CFA_set_loc";
610 case DW_CFA_advance_loc1:
611 return "DW_CFA_advance_loc1";
612 case DW_CFA_advance_loc2:
613 return "DW_CFA_advance_loc2";
614 case DW_CFA_advance_loc4:
615 return "DW_CFA_advance_loc4";
616 case DW_CFA_offset_extended:
617 return "DW_CFA_offset_extended";
618 case DW_CFA_restore_extended:
619 return "DW_CFA_restore_extended";
620 case DW_CFA_undefined:
621 return "DW_CFA_undefined";
622 case DW_CFA_same_value:
623 return "DW_CFA_same_value";
624 case DW_CFA_register:
625 return "DW_CFA_register";
626 case DW_CFA_remember_state:
627 return "DW_CFA_remember_state";
628 case DW_CFA_restore_state:
629 return "DW_CFA_restore_state";
630 case DW_CFA_def_cfa:
631 return "DW_CFA_def_cfa";
632 case DW_CFA_def_cfa_register:
633 return "DW_CFA_def_cfa_register";
634 case DW_CFA_def_cfa_offset:
635 return "DW_CFA_def_cfa_offset";
637 /* SGI/MIPS specific */
638 case DW_CFA_MIPS_advance_loc8:
639 return "DW_CFA_MIPS_advance_loc8";
641 /* GNU extensions */
642 case DW_CFA_GNU_window_save:
643 return "DW_CFA_GNU_window_save";
644 case DW_CFA_GNU_args_size:
645 return "DW_CFA_GNU_args_size";
647 default:
648 return "DW_CFA_<unknown>";
652 /* Return a pointer to a newly allocated Call Frame Instruction. */
654 static inline dw_cfi_ref
655 new_cfi ()
657 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
659 cfi->dw_cfi_next = NULL;
660 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
661 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
663 return cfi;
666 /* Add a Call Frame Instruction to list of instructions. */
668 static inline void
669 add_cfi (list_head, cfi)
670 register dw_cfi_ref *list_head;
671 register dw_cfi_ref cfi;
673 register dw_cfi_ref *p;
675 /* Find the end of the chain. */
676 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
679 *p = cfi;
682 /* Generate a new label for the CFI info to refer to. */
684 char *
685 dwarf2out_cfi_label ()
687 static char label[20];
688 static unsigned long label_num = 0;
690 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
691 ASM_OUTPUT_LABEL (asm_out_file, label);
693 return label;
696 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
697 or to the CIE if LABEL is NULL. */
699 static void
700 add_fde_cfi (label, cfi)
701 register char *label;
702 register dw_cfi_ref cfi;
704 if (label)
706 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
708 if (*label == 0)
709 label = dwarf2out_cfi_label ();
711 if (fde->dw_fde_current_label == NULL
712 || strcmp (label, fde->dw_fde_current_label) != 0)
714 register dw_cfi_ref xcfi;
716 fde->dw_fde_current_label = label = xstrdup (label);
718 /* Set the location counter to the new label. */
719 xcfi = new_cfi ();
720 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
721 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
722 add_cfi (&fde->dw_fde_cfi, xcfi);
725 add_cfi (&fde->dw_fde_cfi, cfi);
728 else
729 add_cfi (&cie_cfi_head, cfi);
732 /* Subroutine of lookup_cfa. */
734 static inline void
735 lookup_cfa_1 (cfi, regp, offsetp)
736 register dw_cfi_ref cfi;
737 register unsigned long *regp;
738 register long *offsetp;
740 switch (cfi->dw_cfi_opc)
742 case DW_CFA_def_cfa_offset:
743 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
744 break;
745 case DW_CFA_def_cfa_register:
746 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
747 break;
748 case DW_CFA_def_cfa:
749 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
750 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
751 break;
752 default:
753 break;
757 /* Find the previous value for the CFA. */
759 static void
760 lookup_cfa (regp, offsetp)
761 register unsigned long *regp;
762 register long *offsetp;
764 register dw_cfi_ref cfi;
766 *regp = (unsigned long) -1;
767 *offsetp = 0;
769 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
770 lookup_cfa_1 (cfi, regp, offsetp);
772 if (fde_table_in_use)
774 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
775 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
776 lookup_cfa_1 (cfi, regp, offsetp);
780 /* The current rule for calculating the DWARF2 canonical frame address. */
781 static unsigned long cfa_reg;
782 static long cfa_offset;
784 /* The register used for saving registers to the stack, and its offset
785 from the CFA. */
786 static unsigned cfa_store_reg;
787 static long cfa_store_offset;
789 /* The running total of the size of arguments pushed onto the stack. */
790 static long args_size;
792 /* The last args_size we actually output. */
793 static long old_args_size;
795 /* Entry point to update the canonical frame address (CFA).
796 LABEL is passed to add_fde_cfi. The value of CFA is now to be
797 calculated from REG+OFFSET. */
799 void
800 dwarf2out_def_cfa (label, reg, offset)
801 register char *label;
802 register unsigned reg;
803 register long offset;
805 register dw_cfi_ref cfi;
806 unsigned long old_reg;
807 long old_offset;
809 cfa_reg = reg;
810 cfa_offset = offset;
811 if (cfa_store_reg == reg)
812 cfa_store_offset = offset;
814 reg = DWARF_FRAME_REGNUM (reg);
815 lookup_cfa (&old_reg, &old_offset);
817 if (reg == old_reg && offset == old_offset)
818 return;
820 cfi = new_cfi ();
822 if (reg == old_reg)
824 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
825 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
828 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
829 else if (offset == old_offset && old_reg != (unsigned long) -1)
831 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
832 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
834 #endif
836 else
838 cfi->dw_cfi_opc = DW_CFA_def_cfa;
839 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
840 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
843 add_fde_cfi (label, cfi);
846 /* Add the CFI for saving a register. REG is the CFA column number.
847 LABEL is passed to add_fde_cfi.
848 If SREG is -1, the register is saved at OFFSET from the CFA;
849 otherwise it is saved in SREG. */
851 static void
852 reg_save (label, reg, sreg, offset)
853 register char * label;
854 register unsigned reg;
855 register unsigned sreg;
856 register long offset;
858 register dw_cfi_ref cfi = new_cfi ();
860 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
862 /* The following comparison is correct. -1 is used to indicate that
863 the value isn't a register number. */
864 if (sreg == (unsigned int) -1)
866 if (reg & ~0x3f)
867 /* The register number won't fit in 6 bits, so we have to use
868 the long form. */
869 cfi->dw_cfi_opc = DW_CFA_offset_extended;
870 else
871 cfi->dw_cfi_opc = DW_CFA_offset;
873 offset /= DWARF_CIE_DATA_ALIGNMENT;
874 if (offset < 0)
875 abort ();
876 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
878 else
880 cfi->dw_cfi_opc = DW_CFA_register;
881 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
884 add_fde_cfi (label, cfi);
887 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
888 This CFI tells the unwinder that it needs to restore the window registers
889 from the previous frame's window save area.
891 ??? Perhaps we should note in the CIE where windows are saved (instead of
892 assuming 0(cfa)) and what registers are in the window. */
894 void
895 dwarf2out_window_save (label)
896 register char * label;
898 register dw_cfi_ref cfi = new_cfi ();
899 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
900 add_fde_cfi (label, cfi);
903 /* Add a CFI to update the running total of the size of arguments
904 pushed onto the stack. */
906 void
907 dwarf2out_args_size (label, size)
908 char *label;
909 long size;
911 register dw_cfi_ref cfi;
913 if (size == old_args_size)
914 return;
915 old_args_size = size;
917 cfi = new_cfi ();
918 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
919 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
920 add_fde_cfi (label, cfi);
923 /* Entry point for saving a register to the stack. REG is the GCC register
924 number. LABEL and OFFSET are passed to reg_save. */
926 void
927 dwarf2out_reg_save (label, reg, offset)
928 register char * label;
929 register unsigned reg;
930 register long offset;
932 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
935 /* Entry point for saving the return address in the stack.
936 LABEL and OFFSET are passed to reg_save. */
938 void
939 dwarf2out_return_save (label, offset)
940 register char * label;
941 register long offset;
943 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
946 /* Entry point for saving the return address in a register.
947 LABEL and SREG are passed to reg_save. */
949 void
950 dwarf2out_return_reg (label, sreg)
951 register char * label;
952 register unsigned sreg;
954 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
957 /* Record the initial position of the return address. RTL is
958 INCOMING_RETURN_ADDR_RTX. */
960 static void
961 initial_return_save (rtl)
962 register rtx rtl;
964 unsigned int reg = (unsigned int) -1;
965 long offset = 0;
967 switch (GET_CODE (rtl))
969 case REG:
970 /* RA is in a register. */
971 reg = reg_number (rtl);
972 break;
973 case MEM:
974 /* RA is on the stack. */
975 rtl = XEXP (rtl, 0);
976 switch (GET_CODE (rtl))
978 case REG:
979 if (REGNO (rtl) != STACK_POINTER_REGNUM)
980 abort ();
981 offset = 0;
982 break;
983 case PLUS:
984 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
985 abort ();
986 offset = INTVAL (XEXP (rtl, 1));
987 break;
988 case MINUS:
989 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
990 abort ();
991 offset = -INTVAL (XEXP (rtl, 1));
992 break;
993 default:
994 abort ();
996 break;
997 case PLUS:
998 /* The return address is at some offset from any value we can
999 actually load. For instance, on the SPARC it is in %i7+8. Just
1000 ignore the offset for now; it doesn't matter for unwinding frames. */
1001 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
1002 abort ();
1003 initial_return_save (XEXP (rtl, 0));
1004 return;
1005 default:
1006 abort ();
1009 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1012 /* Check INSN to see if it looks like a push or a stack adjustment, and
1013 make a note of it if it does. EH uses this information to find out how
1014 much extra space it needs to pop off the stack. */
1016 static void
1017 dwarf2out_stack_adjust (insn)
1018 rtx insn;
1020 long offset;
1021 char *label;
1023 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1025 /* Extract the size of the args from the CALL rtx itself. */
1027 insn = PATTERN (insn);
1028 if (GET_CODE (insn) == PARALLEL)
1029 insn = XVECEXP (insn, 0, 0);
1030 if (GET_CODE (insn) == SET)
1031 insn = SET_SRC (insn);
1032 assert (GET_CODE (insn) == CALL);
1033 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1034 return;
1037 /* If only calls can throw, and we have a frame pointer,
1038 save up adjustments until we see the CALL_INSN. */
1039 else if (! asynchronous_exceptions
1040 && cfa_reg != STACK_POINTER_REGNUM)
1041 return;
1043 if (GET_CODE (insn) == BARRIER)
1045 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1046 the compiler will have already emitted a stack adjustment, but
1047 doesn't bother for calls to noreturn functions. */
1048 #ifdef STACK_GROWS_DOWNWARD
1049 offset = -args_size;
1050 #else
1051 offset = args_size;
1052 #endif
1054 else if (GET_CODE (PATTERN (insn)) == SET)
1056 rtx src, dest;
1057 enum rtx_code code;
1059 insn = PATTERN (insn);
1060 src = SET_SRC (insn);
1061 dest = SET_DEST (insn);
1063 if (dest == stack_pointer_rtx)
1065 /* (set (reg sp) (plus (reg sp) (const_int))) */
1066 code = GET_CODE (src);
1067 if (! (code == PLUS || code == MINUS)
1068 || XEXP (src, 0) != stack_pointer_rtx
1069 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1070 return;
1072 offset = INTVAL (XEXP (src, 1));
1074 else if (GET_CODE (dest) == MEM)
1076 /* (set (mem (pre_dec (reg sp))) (foo)) */
1077 src = XEXP (dest, 0);
1078 code = GET_CODE (src);
1080 if (! (code == PRE_DEC || code == PRE_INC)
1081 || XEXP (src, 0) != stack_pointer_rtx)
1082 return;
1084 offset = GET_MODE_SIZE (GET_MODE (dest));
1086 else
1087 return;
1089 if (code == PLUS || code == PRE_INC)
1090 offset = -offset;
1092 else
1093 return;
1095 if (offset == 0)
1096 return;
1098 if (cfa_reg == STACK_POINTER_REGNUM)
1099 cfa_offset += offset;
1101 #ifndef STACK_GROWS_DOWNWARD
1102 offset = -offset;
1103 #endif
1104 args_size += offset;
1105 if (args_size < 0)
1106 args_size = 0;
1108 label = dwarf2out_cfi_label ();
1109 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1110 dwarf2out_args_size (label, args_size);
1113 /* A temporary register used in adjusting SP or setting up the store_reg. */
1114 static unsigned cfa_temp_reg;
1116 /* A temporary value used in adjusting SP or setting up the store_reg. */
1117 static long cfa_temp_value;
1119 /* Record call frame debugging information for an expression, which either
1120 sets SP or FP (adjusting how we calculate the frame address) or saves a
1121 register to the stack. */
1123 static void
1124 dwarf2out_frame_debug_expr (expr, label)
1125 rtx expr;
1126 char *label;
1128 rtx src, dest;
1129 long offset;
1131 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1132 the PARALLEL independantly. The first element is always processed if
1133 it is a SET. This is for backward compatability. Other elements
1134 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1135 flag is set in them. */
1137 if (GET_CODE (expr) == PARALLEL)
1139 int par_index;
1140 int limit = XVECLEN (expr, 0);
1142 for (par_index = 0; par_index < limit; par_index++)
1144 rtx x = XVECEXP (expr, 0, par_index);
1146 if (GET_CODE (x) == SET &&
1147 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1148 dwarf2out_frame_debug_expr (x, label);
1150 return;
1153 if (GET_CODE (expr) != SET)
1154 abort ();
1156 src = SET_SRC (expr);
1157 dest = SET_DEST (expr);
1159 switch (GET_CODE (dest))
1161 case REG:
1162 /* Update the CFA rule wrt SP or FP. Make sure src is
1163 relative to the current CFA register. */
1164 switch (GET_CODE (src))
1166 /* Setting FP from SP. */
1167 case REG:
1168 if (cfa_reg != (unsigned) REGNO (src))
1169 abort ();
1170 if (REGNO (dest) != STACK_POINTER_REGNUM
1171 && !(frame_pointer_needed
1172 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1173 abort ();
1174 cfa_reg = REGNO (dest);
1175 break;
1177 case PLUS:
1178 case MINUS:
1179 if (dest == stack_pointer_rtx)
1181 /* Adjusting SP. */
1182 switch (GET_CODE (XEXP (src, 1)))
1184 case CONST_INT:
1185 offset = INTVAL (XEXP (src, 1));
1186 break;
1187 case REG:
1188 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1189 abort ();
1190 offset = cfa_temp_value;
1191 break;
1192 default:
1193 abort ();
1196 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1198 /* Restoring SP from FP in the epilogue. */
1199 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1200 abort ();
1201 cfa_reg = STACK_POINTER_REGNUM;
1203 else if (XEXP (src, 0) != stack_pointer_rtx)
1204 abort ();
1206 if (GET_CODE (src) == PLUS)
1207 offset = -offset;
1208 if (cfa_reg == STACK_POINTER_REGNUM)
1209 cfa_offset += offset;
1210 if (cfa_store_reg == STACK_POINTER_REGNUM)
1211 cfa_store_offset += offset;
1213 else if (dest == hard_frame_pointer_rtx)
1215 /* Either setting the FP from an offset of the SP,
1216 or adjusting the FP */
1217 if (! frame_pointer_needed
1218 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1219 abort ();
1221 if (XEXP (src, 0) == stack_pointer_rtx
1222 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1224 if (cfa_reg != STACK_POINTER_REGNUM)
1225 abort ();
1226 offset = INTVAL (XEXP (src, 1));
1227 if (GET_CODE (src) == PLUS)
1228 offset = -offset;
1229 cfa_offset += offset;
1230 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1232 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1233 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1235 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1236 abort ();
1237 offset = INTVAL (XEXP (src, 1));
1238 if (GET_CODE (src) == PLUS)
1239 offset = -offset;
1240 cfa_offset += offset;
1243 else
1244 abort();
1246 else
1248 if (GET_CODE (src) != PLUS
1249 || XEXP (src, 1) != stack_pointer_rtx)
1250 abort ();
1251 if (GET_CODE (XEXP (src, 0)) != REG
1252 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1253 abort ();
1254 if (cfa_reg != STACK_POINTER_REGNUM)
1255 abort ();
1256 cfa_store_reg = REGNO (dest);
1257 cfa_store_offset = cfa_offset - cfa_temp_value;
1259 break;
1261 case CONST_INT:
1262 cfa_temp_reg = REGNO (dest);
1263 cfa_temp_value = INTVAL (src);
1264 break;
1266 case IOR:
1267 if (GET_CODE (XEXP (src, 0)) != REG
1268 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1269 || (unsigned) REGNO (dest) != cfa_temp_reg
1270 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1271 abort ();
1272 cfa_temp_value |= INTVAL (XEXP (src, 1));
1273 break;
1275 default:
1276 abort ();
1278 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1279 break;
1281 case MEM:
1282 /* Saving a register to the stack. Make sure dest is relative to the
1283 CFA register. */
1284 if (GET_CODE (src) != REG)
1285 abort ();
1286 switch (GET_CODE (XEXP (dest, 0)))
1288 /* With a push. */
1289 case PRE_INC:
1290 case PRE_DEC:
1291 offset = GET_MODE_SIZE (GET_MODE (dest));
1292 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1293 offset = -offset;
1295 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1296 || cfa_store_reg != STACK_POINTER_REGNUM)
1297 abort ();
1298 cfa_store_offset += offset;
1299 if (cfa_reg == STACK_POINTER_REGNUM)
1300 cfa_offset = cfa_store_offset;
1302 offset = -cfa_store_offset;
1303 break;
1305 /* With an offset. */
1306 case PLUS:
1307 case MINUS:
1308 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1309 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1310 offset = -offset;
1312 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1313 abort ();
1314 offset -= cfa_store_offset;
1315 break;
1317 /* Without an offset. */
1318 case REG:
1319 if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
1320 abort();
1321 offset = -cfa_store_offset;
1322 break;
1324 default:
1325 abort ();
1327 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1328 dwarf2out_reg_save (label, REGNO (src), offset);
1329 break;
1331 default:
1332 abort ();
1337 /* Record call frame debugging information for INSN, which either
1338 sets SP or FP (adjusting how we calculate the frame address) or saves a
1339 register to the stack. If INSN is NULL_RTX, initialize our state. */
1341 void
1342 dwarf2out_frame_debug (insn)
1343 rtx insn;
1345 char *label;
1346 rtx src;
1348 if (insn == NULL_RTX)
1350 /* Set up state for generating call frame debug info. */
1351 lookup_cfa (&cfa_reg, &cfa_offset);
1352 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1353 abort ();
1354 cfa_reg = STACK_POINTER_REGNUM;
1355 cfa_store_reg = cfa_reg;
1356 cfa_store_offset = cfa_offset;
1357 cfa_temp_reg = -1;
1358 cfa_temp_value = 0;
1359 return;
1362 if (! RTX_FRAME_RELATED_P (insn))
1364 dwarf2out_stack_adjust (insn);
1365 return;
1368 label = dwarf2out_cfi_label ();
1370 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1371 if (src)
1372 insn = XEXP (src, 0);
1373 else
1374 insn = PATTERN (insn);
1376 dwarf2out_frame_debug_expr (insn, label);
1379 /* Return the size of an unsigned LEB128 quantity. */
1381 static inline unsigned long
1382 size_of_uleb128 (value)
1383 register unsigned long value;
1385 register unsigned long size = 0;
1386 register unsigned byte;
1390 byte = (value & 0x7f);
1391 value >>= 7;
1392 size += 1;
1394 while (value != 0);
1396 return size;
1399 /* Return the size of a signed LEB128 quantity. */
1401 static inline unsigned long
1402 size_of_sleb128 (value)
1403 register long value;
1405 register unsigned long size = 0;
1406 register unsigned byte;
1410 byte = (value & 0x7f);
1411 value >>= 7;
1412 size += 1;
1414 while (!(((value == 0) && ((byte & 0x40) == 0))
1415 || ((value == -1) && ((byte & 0x40) != 0))));
1417 return size;
1420 /* Output an unsigned LEB128 quantity. */
1422 static void
1423 output_uleb128 (value)
1424 register unsigned long value;
1426 unsigned long save_value = value;
1428 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1431 register unsigned byte = (value & 0x7f);
1432 value >>= 7;
1433 if (value != 0)
1434 /* More bytes to follow. */
1435 byte |= 0x80;
1437 fprintf (asm_out_file, "0x%x", byte);
1438 if (value != 0)
1439 fprintf (asm_out_file, ",");
1441 while (value != 0);
1443 if (flag_debug_asm)
1444 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1447 /* Output an signed LEB128 quantity. */
1449 static void
1450 output_sleb128 (value)
1451 register long value;
1453 register int more;
1454 register unsigned byte;
1455 long save_value = value;
1457 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1460 byte = (value & 0x7f);
1461 /* arithmetic shift */
1462 value >>= 7;
1463 more = !((((value == 0) && ((byte & 0x40) == 0))
1464 || ((value == -1) && ((byte & 0x40) != 0))));
1465 if (more)
1466 byte |= 0x80;
1468 fprintf (asm_out_file, "0x%x", byte);
1469 if (more)
1470 fprintf (asm_out_file, ",");
1473 while (more);
1474 if (flag_debug_asm)
1475 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1478 /* Output a Call Frame Information opcode and its operand(s). */
1480 static void
1481 output_cfi (cfi, fde)
1482 register dw_cfi_ref cfi;
1483 register dw_fde_ref fde;
1485 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1487 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1488 cfi->dw_cfi_opc
1489 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1490 if (flag_debug_asm)
1491 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1492 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1493 fputc ('\n', asm_out_file);
1496 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1498 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1499 cfi->dw_cfi_opc
1500 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1501 if (flag_debug_asm)
1502 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1503 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1505 fputc ('\n', asm_out_file);
1506 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1507 fputc ('\n', asm_out_file);
1509 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1511 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1512 cfi->dw_cfi_opc
1513 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1514 if (flag_debug_asm)
1515 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1516 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1518 fputc ('\n', asm_out_file);
1520 else
1522 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1523 if (flag_debug_asm)
1524 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1525 dwarf_cfi_name (cfi->dw_cfi_opc));
1527 fputc ('\n', asm_out_file);
1528 switch (cfi->dw_cfi_opc)
1530 case DW_CFA_set_loc:
1531 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1532 fputc ('\n', asm_out_file);
1533 break;
1534 case DW_CFA_advance_loc1:
1535 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1536 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1537 fde->dw_fde_current_label);
1538 fputc ('\n', asm_out_file);
1539 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1540 break;
1541 case DW_CFA_advance_loc2:
1542 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1543 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1544 fde->dw_fde_current_label);
1545 fputc ('\n', asm_out_file);
1546 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1547 break;
1548 case DW_CFA_advance_loc4:
1549 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1550 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1551 fde->dw_fde_current_label);
1552 fputc ('\n', asm_out_file);
1553 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1554 break;
1555 #ifdef MIPS_DEBUGGING_INFO
1556 case DW_CFA_MIPS_advance_loc8:
1557 /* TODO: not currently implemented. */
1558 abort ();
1559 break;
1560 #endif
1561 case DW_CFA_offset_extended:
1562 case DW_CFA_def_cfa:
1563 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1564 fputc ('\n', asm_out_file);
1565 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1566 fputc ('\n', asm_out_file);
1567 break;
1568 case DW_CFA_restore_extended:
1569 case DW_CFA_undefined:
1570 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1571 fputc ('\n', asm_out_file);
1572 break;
1573 case DW_CFA_same_value:
1574 case DW_CFA_def_cfa_register:
1575 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1576 fputc ('\n', asm_out_file);
1577 break;
1578 case DW_CFA_register:
1579 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1580 fputc ('\n', asm_out_file);
1581 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1582 fputc ('\n', asm_out_file);
1583 break;
1584 case DW_CFA_def_cfa_offset:
1585 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1586 fputc ('\n', asm_out_file);
1587 break;
1588 case DW_CFA_GNU_window_save:
1589 break;
1590 case DW_CFA_GNU_args_size:
1591 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1592 fputc ('\n', asm_out_file);
1593 break;
1594 default:
1595 break;
1600 /* Output the call frame information used to used to record information
1601 that relates to calculating the frame pointer, and records the
1602 location of saved registers. */
1604 static void
1605 output_call_frame_info (for_eh)
1606 int for_eh;
1608 register unsigned long i;
1609 register dw_fde_ref fde;
1610 register dw_cfi_ref cfi;
1611 char l1[20], l2[20];
1612 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1613 char ld[20];
1614 #endif
1616 /* Do we want to include a pointer to the exception table? */
1617 int eh_ptr = for_eh && exception_table_p ();
1619 fputc ('\n', asm_out_file);
1621 /* We're going to be generating comments, so turn on app. */
1622 if (flag_debug_asm)
1623 app_enable ();
1625 if (for_eh)
1627 #ifdef EH_FRAME_SECTION
1628 EH_FRAME_SECTION ();
1629 #else
1630 tree label = get_file_function_name ('F');
1632 force_data_section ();
1633 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1634 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1635 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1636 #endif
1637 assemble_label ("__FRAME_BEGIN__");
1639 else
1640 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1642 /* Output the CIE. */
1643 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1644 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1645 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1646 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1647 if (for_eh)
1648 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1649 else
1650 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1651 #else
1652 if (for_eh)
1653 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1654 else
1655 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1656 #endif
1657 if (flag_debug_asm)
1658 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1659 ASM_COMMENT_START);
1661 fputc ('\n', asm_out_file);
1662 ASM_OUTPUT_LABEL (asm_out_file, l1);
1664 if (for_eh)
1665 /* Now that the CIE pointer is PC-relative for EH,
1666 use 0 to identify the CIE. */
1667 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1668 else
1669 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1671 if (flag_debug_asm)
1672 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1674 fputc ('\n', asm_out_file);
1675 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1677 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1678 fputc ('\n', asm_out_file);
1681 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1682 if (flag_debug_asm)
1683 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1685 fputc ('\n', asm_out_file);
1686 if (eh_ptr)
1688 /* The CIE contains a pointer to the exception region info for the
1689 frame. Make the augmentation string three bytes (including the
1690 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1691 can't handle unaligned relocs. */
1692 if (flag_debug_asm)
1694 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1695 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1697 else
1699 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1701 fputc ('\n', asm_out_file);
1703 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1704 if (flag_debug_asm)
1705 fprintf (asm_out_file, "\t%s pointer to exception region info",
1706 ASM_COMMENT_START);
1708 else
1710 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1711 if (flag_debug_asm)
1712 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1713 ASM_COMMENT_START);
1716 fputc ('\n', asm_out_file);
1717 output_uleb128 (1);
1718 if (flag_debug_asm)
1719 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1721 fputc ('\n', asm_out_file);
1722 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1723 if (flag_debug_asm)
1724 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1726 fputc ('\n', asm_out_file);
1727 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1728 if (flag_debug_asm)
1729 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1731 fputc ('\n', asm_out_file);
1733 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1734 output_cfi (cfi, NULL);
1736 /* Pad the CIE out to an address sized boundary. */
1737 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1738 ASM_OUTPUT_LABEL (asm_out_file, l2);
1739 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1740 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1741 if (flag_debug_asm)
1742 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1743 fputc ('\n', asm_out_file);
1744 #endif
1746 /* Loop through all of the FDE's. */
1747 for (i = 0; i < fde_table_in_use; ++i)
1749 fde = &fde_table[i];
1751 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1752 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1753 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1754 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1755 if (for_eh)
1756 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1757 else
1758 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1759 #else
1760 if (for_eh)
1761 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1762 else
1763 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1764 #endif
1765 if (flag_debug_asm)
1766 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1767 fputc ('\n', asm_out_file);
1768 ASM_OUTPUT_LABEL (asm_out_file, l1);
1770 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1771 emits a target dependent sized offset when for_eh is not true.
1772 This inconsistency may confuse gdb. The only case where we need a
1773 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1774 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1775 though in order to be compatible with the dwarf_fde struct in frame.c.
1776 If the for_eh case is changed, then the struct in frame.c has
1777 to be adjusted appropriately. */
1778 if (for_eh)
1779 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1780 else
1781 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1782 if (flag_debug_asm)
1783 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1785 fputc ('\n', asm_out_file);
1786 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1787 if (flag_debug_asm)
1788 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1790 fputc ('\n', asm_out_file);
1791 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1792 fde->dw_fde_end, fde->dw_fde_begin);
1793 if (flag_debug_asm)
1794 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1796 fputc ('\n', asm_out_file);
1798 /* Loop through the Call Frame Instructions associated with
1799 this FDE. */
1800 fde->dw_fde_current_label = fde->dw_fde_begin;
1801 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1802 output_cfi (cfi, fde);
1804 /* Pad the FDE out to an address sized boundary. */
1805 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1806 ASM_OUTPUT_LABEL (asm_out_file, l2);
1807 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1808 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1809 if (flag_debug_asm)
1810 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1811 fputc ('\n', asm_out_file);
1812 #endif
1814 #ifndef EH_FRAME_SECTION
1815 if (for_eh)
1817 /* Emit terminating zero for table. */
1818 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1819 fputc ('\n', asm_out_file);
1821 #endif
1822 #ifdef MIPS_DEBUGGING_INFO
1823 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1824 get a value of 0. Putting .align 0 after the label fixes it. */
1825 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1826 #endif
1828 /* Turn off app to make assembly quicker. */
1829 if (flag_debug_asm)
1830 app_disable ();
1833 /* Output a marker (i.e. a label) for the beginning of a function, before
1834 the prologue. */
1836 void
1837 dwarf2out_begin_prologue ()
1839 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1840 register dw_fde_ref fde;
1842 ++current_funcdef_number;
1844 function_section (current_function_decl);
1845 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1846 current_funcdef_number);
1847 ASM_OUTPUT_LABEL (asm_out_file, label);
1849 /* Expand the fde table if necessary. */
1850 if (fde_table_in_use == fde_table_allocated)
1852 fde_table_allocated += FDE_TABLE_INCREMENT;
1853 fde_table
1854 = (dw_fde_ref) xrealloc (fde_table,
1855 fde_table_allocated * sizeof (dw_fde_node));
1858 /* Record the FDE associated with this function. */
1859 current_funcdef_fde = fde_table_in_use;
1861 /* Add the new FDE at the end of the fde_table. */
1862 fde = &fde_table[fde_table_in_use++];
1863 fde->dw_fde_begin = xstrdup (label);
1864 fde->dw_fde_current_label = NULL;
1865 fde->dw_fde_end = NULL;
1866 fde->dw_fde_cfi = NULL;
1868 args_size = old_args_size = 0;
1871 /* Output a marker (i.e. a label) for the absolute end of the generated code
1872 for a function definition. This gets called *after* the epilogue code has
1873 been generated. */
1875 void
1876 dwarf2out_end_epilogue ()
1878 dw_fde_ref fde;
1879 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1881 /* Output a label to mark the endpoint of the code generated for this
1882 function. */
1883 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1884 ASM_OUTPUT_LABEL (asm_out_file, label);
1885 fde = &fde_table[fde_table_in_use - 1];
1886 fde->dw_fde_end = xstrdup (label);
1889 void
1890 dwarf2out_frame_init ()
1892 /* Allocate the initial hunk of the fde_table. */
1893 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1894 fde_table_allocated = FDE_TABLE_INCREMENT;
1895 fde_table_in_use = 0;
1897 /* Generate the CFA instructions common to all FDE's. Do it now for the
1898 sake of lookup_cfa. */
1900 #ifdef DWARF2_UNWIND_INFO
1901 /* On entry, the Canonical Frame Address is at SP. */
1902 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1903 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1904 #endif
1907 void
1908 dwarf2out_frame_finish ()
1910 /* Output call frame information. */
1911 #ifdef MIPS_DEBUGGING_INFO
1912 if (write_symbols == DWARF2_DEBUG)
1913 output_call_frame_info (0);
1914 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1915 output_call_frame_info (1);
1916 #else
1917 if (write_symbols == DWARF2_DEBUG
1918 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1919 output_call_frame_info (1);
1920 #endif
1923 #endif /* .debug_frame support */
1925 /* And now, the support for symbolic debugging information. */
1926 #ifdef DWARF2_DEBUGGING_INFO
1928 /* NOTE: In the comments in this file, many references are made to
1929 "Debugging Information Entries". This term is abbreviated as `DIE'
1930 throughout the remainder of this file. */
1932 /* An internal representation of the DWARF output is built, and then
1933 walked to generate the DWARF debugging info. The walk of the internal
1934 representation is done after the entire program has been compiled.
1935 The types below are used to describe the internal representation. */
1937 /* Each DIE may have a series of attribute/value pairs. Values
1938 can take on several forms. The forms that are used in this
1939 implementation are listed below. */
1941 typedef enum
1943 dw_val_class_addr,
1944 dw_val_class_loc,
1945 dw_val_class_const,
1946 dw_val_class_unsigned_const,
1947 dw_val_class_long_long,
1948 dw_val_class_float,
1949 dw_val_class_flag,
1950 dw_val_class_die_ref,
1951 dw_val_class_fde_ref,
1952 dw_val_class_lbl_id,
1953 dw_val_class_lbl_offset,
1954 dw_val_class_str
1956 dw_val_class;
1958 /* Various DIE's use offsets relative to the beginning of the
1959 .debug_info section to refer to each other. */
1961 typedef long int dw_offset;
1963 /* Define typedefs here to avoid circular dependencies. */
1965 typedef struct die_struct *dw_die_ref;
1966 typedef struct dw_attr_struct *dw_attr_ref;
1967 typedef struct dw_val_struct *dw_val_ref;
1968 typedef struct dw_line_info_struct *dw_line_info_ref;
1969 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1970 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1971 typedef struct pubname_struct *pubname_ref;
1972 typedef dw_die_ref *arange_ref;
1974 /* Describe a double word constant value. */
1976 typedef struct dw_long_long_struct
1978 unsigned long hi;
1979 unsigned long low;
1981 dw_long_long_const;
1983 /* Describe a floating point constant value. */
1985 typedef struct dw_fp_struct
1987 long *array;
1988 unsigned length;
1990 dw_float_const;
1992 /* Each entry in the line_info_table maintains the file and
1993 line number associated with the label generated for that
1994 entry. The label gives the PC value associated with
1995 the line number entry. */
1997 typedef struct dw_line_info_struct
1999 unsigned long dw_file_num;
2000 unsigned long dw_line_num;
2002 dw_line_info_entry;
2004 /* Line information for functions in separate sections; each one gets its
2005 own sequence. */
2006 typedef struct dw_separate_line_info_struct
2008 unsigned long dw_file_num;
2009 unsigned long dw_line_num;
2010 unsigned long function;
2012 dw_separate_line_info_entry;
2014 /* The dw_val_node describes an attribute's value, as it is
2015 represented internally. */
2017 typedef struct dw_val_struct
2019 dw_val_class val_class;
2020 union
2022 rtx val_addr;
2023 dw_loc_descr_ref val_loc;
2024 long int val_int;
2025 long unsigned val_unsigned;
2026 dw_long_long_const val_long_long;
2027 dw_float_const val_float;
2028 dw_die_ref val_die_ref;
2029 unsigned val_fde_index;
2030 char *val_str;
2031 char *val_lbl_id;
2032 unsigned char val_flag;
2036 dw_val_node;
2038 /* Locations in memory are described using a sequence of stack machine
2039 operations. */
2041 typedef struct dw_loc_descr_struct
2043 dw_loc_descr_ref dw_loc_next;
2044 enum dwarf_location_atom dw_loc_opc;
2045 dw_val_node dw_loc_oprnd1;
2046 dw_val_node dw_loc_oprnd2;
2048 dw_loc_descr_node;
2050 /* Each DIE attribute has a field specifying the attribute kind,
2051 a link to the next attribute in the chain, and an attribute value.
2052 Attributes are typically linked below the DIE they modify. */
2054 typedef struct dw_attr_struct
2056 enum dwarf_attribute dw_attr;
2057 dw_attr_ref dw_attr_next;
2058 dw_val_node dw_attr_val;
2060 dw_attr_node;
2062 /* The Debugging Information Entry (DIE) structure */
2064 typedef struct die_struct
2066 enum dwarf_tag die_tag;
2067 dw_attr_ref die_attr;
2068 dw_die_ref die_parent;
2069 dw_die_ref die_child;
2070 dw_die_ref die_sib;
2071 dw_offset die_offset;
2072 unsigned long die_abbrev;
2074 die_node;
2076 /* The pubname structure */
2078 typedef struct pubname_struct
2080 dw_die_ref die;
2081 char * name;
2083 pubname_entry;
2085 /* The limbo die list structure. */
2086 typedef struct limbo_die_struct
2088 dw_die_ref die;
2089 struct limbo_die_struct *next;
2091 limbo_die_node;
2093 /* How to start an assembler comment. */
2094 #ifndef ASM_COMMENT_START
2095 #define ASM_COMMENT_START ";#"
2096 #endif
2098 /* Define a macro which returns non-zero for a TYPE_DECL which was
2099 implicitly generated for a tagged type.
2101 Note that unlike the gcc front end (which generates a NULL named
2102 TYPE_DECL node for each complete tagged type, each array type, and
2103 each function type node created) the g++ front end generates a
2104 _named_ TYPE_DECL node for each tagged type node created.
2105 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2106 generate a DW_TAG_typedef DIE for them. */
2108 #define TYPE_DECL_IS_STUB(decl) \
2109 (DECL_NAME (decl) == NULL_TREE \
2110 || (DECL_ARTIFICIAL (decl) \
2111 && is_tagged_type (TREE_TYPE (decl)) \
2112 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2113 /* This is necessary for stub decls that \
2114 appear in nested inline functions. */ \
2115 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2116 && (decl_ultimate_origin (decl) \
2117 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2119 /* Information concerning the compilation unit's programming
2120 language, and compiler version. */
2122 extern int flag_traditional;
2123 extern char *version_string;
2125 /* Fixed size portion of the DWARF compilation unit header. */
2126 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2128 /* Fixed size portion of debugging line information prolog. */
2129 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2131 /* Fixed size portion of public names info. */
2132 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2134 /* Fixed size portion of the address range info. */
2135 #define DWARF_ARANGES_HEADER_SIZE \
2136 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2138 /* The default is to have gcc emit the line number tables. */
2139 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2140 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2141 #endif
2143 /* Define the architecture-dependent minimum instruction length (in bytes).
2144 In this implementation of DWARF, this field is used for information
2145 purposes only. Since GCC generates assembly language, we have
2146 no a priori knowledge of how many instruction bytes are generated
2147 for each source line, and therefore can use only the DW_LNE_set_address
2148 and DW_LNS_fixed_advance_pc line information commands. */
2150 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2151 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2152 #endif
2154 /* Minimum line offset in a special line info. opcode.
2155 This value was chosen to give a reasonable range of values. */
2156 #define DWARF_LINE_BASE -10
2158 /* First special line opcde - leave room for the standard opcodes. */
2159 #define DWARF_LINE_OPCODE_BASE 10
2161 /* Range of line offsets in a special line info. opcode. */
2162 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2164 /* Flag that indicates the initial value of the is_stmt_start flag.
2165 In the present implementation, we do not mark any lines as
2166 the beginning of a source statement, because that information
2167 is not made available by the GCC front-end. */
2168 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2170 /* This location is used by calc_die_sizes() to keep track
2171 the offset of each DIE within the .debug_info section. */
2172 static unsigned long next_die_offset;
2174 /* Record the root of the DIE's built for the current compilation unit. */
2175 static dw_die_ref comp_unit_die;
2177 /* A list of DIEs with a NULL parent waiting to be relocated. */
2178 static limbo_die_node *limbo_die_list = 0;
2180 /* Pointer to an array of filenames referenced by this compilation unit. */
2181 static char **file_table;
2183 /* Total number of entries in the table (i.e. array) pointed to by
2184 `file_table'. This is the *total* and includes both used and unused
2185 slots. */
2186 static unsigned file_table_allocated;
2188 /* Number of entries in the file_table which are actually in use. */
2189 static unsigned file_table_in_use;
2191 /* Size (in elements) of increments by which we may expand the filename
2192 table. */
2193 #define FILE_TABLE_INCREMENT 64
2195 /* Local pointer to the name of the main input file. Initialized in
2196 dwarf2out_init. */
2197 static char *primary_filename;
2199 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2200 which their beginnings are encountered. We output Dwarf debugging info
2201 that refers to the beginnings and ends of the ranges of code for each
2202 lexical block. The labels themselves are generated in final.c, which
2203 assigns numbers to the blocks in the same way. */
2204 static unsigned next_block_number = 2;
2206 /* A pointer to the base of a table of references to DIE's that describe
2207 declarations. The table is indexed by DECL_UID() which is a unique
2208 number identifying each decl. */
2209 static dw_die_ref *decl_die_table;
2211 /* Number of elements currently allocated for the decl_die_table. */
2212 static unsigned decl_die_table_allocated;
2214 /* Number of elements in decl_die_table currently in use. */
2215 static unsigned decl_die_table_in_use;
2217 /* Size (in elements) of increments by which we may expand the
2218 decl_die_table. */
2219 #define DECL_DIE_TABLE_INCREMENT 256
2221 /* A pointer to the base of a table of references to declaration
2222 scopes. This table is a display which tracks the nesting
2223 of declaration scopes at the current scope and containing
2224 scopes. This table is used to find the proper place to
2225 define type declaration DIE's. */
2226 static tree *decl_scope_table;
2228 /* Number of elements currently allocated for the decl_scope_table. */
2229 static int decl_scope_table_allocated;
2231 /* Current level of nesting of declaration scopes. */
2232 static int decl_scope_depth;
2234 /* Size (in elements) of increments by which we may expand the
2235 decl_scope_table. */
2236 #define DECL_SCOPE_TABLE_INCREMENT 64
2238 /* A pointer to the base of a list of references to DIE's that
2239 are uniquely identified by their tag, presence/absence of
2240 children DIE's, and list of attribute/value pairs. */
2241 static dw_die_ref *abbrev_die_table;
2243 /* Number of elements currently allocated for abbrev_die_table. */
2244 static unsigned abbrev_die_table_allocated;
2246 /* Number of elements in type_die_table currently in use. */
2247 static unsigned abbrev_die_table_in_use;
2249 /* Size (in elements) of increments by which we may expand the
2250 abbrev_die_table. */
2251 #define ABBREV_DIE_TABLE_INCREMENT 256
2253 /* A pointer to the base of a table that contains line information
2254 for each source code line in .text in the compilation unit. */
2255 static dw_line_info_ref line_info_table;
2257 /* Number of elements currently allocated for line_info_table. */
2258 static unsigned line_info_table_allocated;
2260 /* Number of elements in separate_line_info_table currently in use. */
2261 static unsigned separate_line_info_table_in_use;
2263 /* A pointer to the base of a table that contains line information
2264 for each source code line outside of .text in the compilation unit. */
2265 static dw_separate_line_info_ref separate_line_info_table;
2267 /* Number of elements currently allocated for separate_line_info_table. */
2268 static unsigned separate_line_info_table_allocated;
2270 /* Number of elements in line_info_table currently in use. */
2271 static unsigned line_info_table_in_use;
2273 /* Size (in elements) of increments by which we may expand the
2274 line_info_table. */
2275 #define LINE_INFO_TABLE_INCREMENT 1024
2277 /* A pointer to the base of a table that contains a list of publicly
2278 accessible names. */
2279 static pubname_ref pubname_table;
2281 /* Number of elements currently allocated for pubname_table. */
2282 static unsigned pubname_table_allocated;
2284 /* Number of elements in pubname_table currently in use. */
2285 static unsigned pubname_table_in_use;
2287 /* Size (in elements) of increments by which we may expand the
2288 pubname_table. */
2289 #define PUBNAME_TABLE_INCREMENT 64
2291 /* A pointer to the base of a table that contains a list of publicly
2292 accessible names. */
2293 static arange_ref arange_table;
2295 /* Number of elements currently allocated for arange_table. */
2296 static unsigned arange_table_allocated;
2298 /* Number of elements in arange_table currently in use. */
2299 static unsigned arange_table_in_use;
2301 /* Size (in elements) of increments by which we may expand the
2302 arange_table. */
2303 #define ARANGE_TABLE_INCREMENT 64
2305 /* A pointer to the base of a list of incomplete types which might be
2306 completed at some later time. */
2308 static tree *incomplete_types_list;
2310 /* Number of elements currently allocated for the incomplete_types_list. */
2311 static unsigned incomplete_types_allocated;
2313 /* Number of elements of incomplete_types_list currently in use. */
2314 static unsigned incomplete_types;
2316 /* Size (in elements) of increments by which we may expand the incomplete
2317 types list. Actually, a single hunk of space of this size should
2318 be enough for most typical programs. */
2319 #define INCOMPLETE_TYPES_INCREMENT 64
2321 /* Record whether the function being analyzed contains inlined functions. */
2322 static int current_function_has_inlines;
2323 #if 0 && defined (MIPS_DEBUGGING_INFO)
2324 static int comp_unit_has_inlines;
2325 #endif
2327 /* Array of RTXes referenced by the debugging information, which therefore
2328 must be kept around forever. We do this rather than perform GC on
2329 the dwarf info because almost all of the dwarf info lives forever, and
2330 it's easier to support non-GC frontends this way. */
2331 static varray_type used_rtx_varray;
2333 /* Forward declarations for functions defined in this file. */
2335 static int is_pseudo_reg PARAMS ((rtx));
2336 static tree type_main_variant PARAMS ((tree));
2337 static int is_tagged_type PARAMS ((tree));
2338 static const char *dwarf_tag_name PARAMS ((unsigned));
2339 static const char *dwarf_attr_name PARAMS ((unsigned));
2340 static const char *dwarf_form_name PARAMS ((unsigned));
2341 static const char *dwarf_stack_op_name PARAMS ((unsigned));
2342 #if 0
2343 static const char *dwarf_type_encoding_name PARAMS ((unsigned));
2344 #endif
2345 static tree decl_ultimate_origin PARAMS ((tree));
2346 static tree block_ultimate_origin PARAMS ((tree));
2347 static tree decl_class_context PARAMS ((tree));
2348 static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref));
2349 static void add_AT_flag PARAMS ((dw_die_ref,
2350 enum dwarf_attribute,
2351 unsigned));
2352 static void add_AT_int PARAMS ((dw_die_ref,
2353 enum dwarf_attribute, long));
2354 static void add_AT_unsigned PARAMS ((dw_die_ref,
2355 enum dwarf_attribute,
2356 unsigned long));
2357 static void add_AT_long_long PARAMS ((dw_die_ref,
2358 enum dwarf_attribute,
2359 unsigned long,
2360 unsigned long));
2361 static void add_AT_float PARAMS ((dw_die_ref,
2362 enum dwarf_attribute,
2363 unsigned, long *));
2364 static void add_AT_string PARAMS ((dw_die_ref,
2365 enum dwarf_attribute,
2366 const char *));
2367 static void add_AT_die_ref PARAMS ((dw_die_ref,
2368 enum dwarf_attribute,
2369 dw_die_ref));
2370 static void add_AT_fde_ref PARAMS ((dw_die_ref,
2371 enum dwarf_attribute,
2372 unsigned));
2373 static void add_AT_loc PARAMS ((dw_die_ref,
2374 enum dwarf_attribute,
2375 dw_loc_descr_ref));
2376 static void add_AT_addr PARAMS ((dw_die_ref,
2377 enum dwarf_attribute,
2378 rtx));
2379 static void add_AT_lbl_id PARAMS ((dw_die_ref,
2380 enum dwarf_attribute,
2381 char *));
2382 static void add_AT_lbl_offset PARAMS ((dw_die_ref,
2383 enum dwarf_attribute,
2384 char *));
2385 static dw_attr_ref get_AT PARAMS ((dw_die_ref,
2386 enum dwarf_attribute));
2387 static const char *get_AT_low_pc PARAMS ((dw_die_ref));
2388 static const char *get_AT_hi_pc PARAMS ((dw_die_ref));
2389 static const char *get_AT_string PARAMS ((dw_die_ref,
2390 enum dwarf_attribute));
2391 static int get_AT_flag PARAMS ((dw_die_ref,
2392 enum dwarf_attribute));
2393 static unsigned get_AT_unsigned PARAMS ((dw_die_ref,
2394 enum dwarf_attribute));
2395 static int is_c_family PARAMS ((void));
2396 static int is_fortran PARAMS ((void));
2397 static void remove_AT PARAMS ((dw_die_ref,
2398 enum dwarf_attribute));
2399 static void remove_children PARAMS ((dw_die_ref));
2400 static void add_child_die PARAMS ((dw_die_ref, dw_die_ref));
2401 static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref));
2402 static dw_die_ref lookup_type_die PARAMS ((tree));
2403 static void equate_type_number_to_die PARAMS ((tree, dw_die_ref));
2404 static dw_die_ref lookup_decl_die PARAMS ((tree));
2405 static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref));
2406 static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom,
2407 unsigned long,
2408 unsigned long));
2409 static void add_loc_descr PARAMS ((dw_loc_descr_ref *,
2410 dw_loc_descr_ref));
2411 static void print_spaces PARAMS ((FILE *));
2412 static void print_die PARAMS ((dw_die_ref, FILE *));
2413 static void print_dwarf_line_table PARAMS ((FILE *));
2414 static void add_sibling_attributes PARAMS ((dw_die_ref));
2415 static void build_abbrev_table PARAMS ((dw_die_ref));
2416 static unsigned long size_of_string PARAMS ((const char *));
2417 static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref));
2418 static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref));
2419 static int constant_size PARAMS ((long unsigned));
2420 static unsigned long size_of_die PARAMS ((dw_die_ref));
2421 static void calc_die_sizes PARAMS ((dw_die_ref));
2422 static unsigned long size_of_line_prolog PARAMS ((void));
2423 static unsigned long size_of_pubnames PARAMS ((void));
2424 static unsigned long size_of_aranges PARAMS ((void));
2425 static enum dwarf_form value_format PARAMS ((dw_attr_ref));
2426 static void output_value_format PARAMS ((dw_attr_ref));
2427 static void output_abbrev_section PARAMS ((void));
2428 static void output_loc_operands PARAMS ((dw_loc_descr_ref));
2429 static void output_die PARAMS ((dw_die_ref));
2430 static void output_compilation_unit_header PARAMS ((void));
2431 static const char *dwarf2_name PARAMS ((tree, int));
2432 static void add_pubname PARAMS ((tree, dw_die_ref));
2433 static void output_pubnames PARAMS ((void));
2434 static void add_arange PARAMS ((tree, dw_die_ref));
2435 static void output_aranges PARAMS ((void));
2436 static void output_line_info PARAMS ((void));
2437 static int is_body_block PARAMS ((tree));
2438 static dw_die_ref base_type_die PARAMS ((tree));
2439 static tree root_type PARAMS ((tree));
2440 static int is_base_type PARAMS ((tree));
2441 static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref));
2442 static int type_is_enum PARAMS ((tree));
2443 static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx));
2444 static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long));
2445 static int is_based_loc PARAMS ((rtx));
2446 static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode));
2447 static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx));
2448 static dw_loc_descr_ref loc_descriptor PARAMS ((rtx));
2449 static unsigned ceiling PARAMS ((unsigned, unsigned));
2450 static tree field_type PARAMS ((tree));
2451 static unsigned simple_type_align_in_bits PARAMS ((tree));
2452 static unsigned simple_type_size_in_bits PARAMS ((tree));
2453 static unsigned field_byte_offset PARAMS ((tree));
2454 static void add_AT_location_description PARAMS ((dw_die_ref,
2455 enum dwarf_attribute, rtx));
2456 static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree));
2457 static void add_const_value_attribute PARAMS ((dw_die_ref, rtx));
2458 static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree));
2459 static void add_name_attribute PARAMS ((dw_die_ref, const char *));
2460 static void add_bound_info PARAMS ((dw_die_ref,
2461 enum dwarf_attribute, tree));
2462 static void add_subscript_info PARAMS ((dw_die_ref, tree));
2463 static void add_byte_size_attribute PARAMS ((dw_die_ref, tree));
2464 static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree));
2465 static void add_bit_size_attribute PARAMS ((dw_die_ref, tree));
2466 static void add_prototyped_attribute PARAMS ((dw_die_ref, tree));
2467 static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree));
2468 static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree));
2469 static void add_src_coords_attributes PARAMS ((dw_die_ref, tree));
2470 static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree));
2471 static void push_decl_scope PARAMS ((tree));
2472 static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref));
2473 static void pop_decl_scope PARAMS ((void));
2474 static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int,
2475 dw_die_ref));
2476 static char *type_tag PARAMS ((tree));
2477 static tree member_declared_type PARAMS ((tree));
2478 #if 0
2479 static char *decl_start_label PARAMS ((tree));
2480 #endif
2481 static void gen_array_type_die PARAMS ((tree, dw_die_ref));
2482 static void gen_set_type_die PARAMS ((tree, dw_die_ref));
2483 #if 0
2484 static void gen_entry_point_die PARAMS ((tree, dw_die_ref));
2485 #endif
2486 static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref));
2487 static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref));
2488 static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref));
2489 static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref));
2490 static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref));
2491 static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref));
2492 static void gen_formal_types_die PARAMS ((tree, dw_die_ref));
2493 static void gen_subprogram_die PARAMS ((tree, dw_die_ref));
2494 static void gen_variable_die PARAMS ((tree, dw_die_ref));
2495 static void gen_label_die PARAMS ((tree, dw_die_ref));
2496 static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int));
2497 static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int));
2498 static void gen_field_die PARAMS ((tree, dw_die_ref));
2499 static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref));
2500 static dw_die_ref gen_compile_unit_die PARAMS ((const char *));
2501 static void gen_string_type_die PARAMS ((tree, dw_die_ref));
2502 static void gen_inheritance_die PARAMS ((tree, dw_die_ref));
2503 static void gen_member_die PARAMS ((tree, dw_die_ref));
2504 static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref));
2505 static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref));
2506 static void gen_typedef_die PARAMS ((tree, dw_die_ref));
2507 static void gen_type_die PARAMS ((tree, dw_die_ref));
2508 static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref));
2509 static void gen_block_die PARAMS ((tree, dw_die_ref, int));
2510 static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
2511 static int is_redundant_typedef PARAMS ((tree));
2512 static void gen_decl_die PARAMS ((tree, dw_die_ref));
2513 static unsigned lookup_filename PARAMS ((const char *));
2514 static void add_incomplete_type PARAMS ((tree));
2515 static void retry_incomplete_types PARAMS ((void));
2516 static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
2517 static void gen_abstract_function PARAMS ((tree));
2519 /* Section names used to hold DWARF debugging information. */
2520 #ifndef DEBUG_INFO_SECTION
2521 #define DEBUG_INFO_SECTION ".debug_info"
2522 #endif
2523 #ifndef ABBREV_SECTION
2524 #define ABBREV_SECTION ".debug_abbrev"
2525 #endif
2526 #ifndef ARANGES_SECTION
2527 #define ARANGES_SECTION ".debug_aranges"
2528 #endif
2529 #ifndef DW_MACINFO_SECTION
2530 #define DW_MACINFO_SECTION ".debug_macinfo"
2531 #endif
2532 #ifndef DEBUG_LINE_SECTION
2533 #define DEBUG_LINE_SECTION ".debug_line"
2534 #endif
2535 #ifndef LOC_SECTION
2536 #define LOC_SECTION ".debug_loc"
2537 #endif
2538 #ifndef PUBNAMES_SECTION
2539 #define PUBNAMES_SECTION ".debug_pubnames"
2540 #endif
2541 #ifndef STR_SECTION
2542 #define STR_SECTION ".debug_str"
2543 #endif
2545 /* Standard ELF section names for compiled code and data. */
2546 #ifndef TEXT_SECTION
2547 #define TEXT_SECTION ".text"
2548 #endif
2549 #ifndef DATA_SECTION
2550 #define DATA_SECTION ".data"
2551 #endif
2552 #ifndef BSS_SECTION
2553 #define BSS_SECTION ".bss"
2554 #endif
2556 /* Labels we insert at beginning sections we can reference instead of
2557 the section names themselves. */
2559 #ifndef TEXT_SECTION_LABEL
2560 #define TEXT_SECTION_LABEL "Ltext"
2561 #endif
2562 #ifndef DEBUG_LINE_SECTION_LABEL
2563 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2564 #endif
2565 #ifndef DEBUG_INFO_SECTION_LABEL
2566 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2567 #endif
2568 #ifndef ABBREV_SECTION_LABEL
2569 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2570 #endif
2573 /* Definitions of defaults for formats and names of various special
2574 (artificial) labels which may be generated within this file (when the -g
2575 options is used and DWARF_DEBUGGING_INFO is in effect.
2576 If necessary, these may be overridden from within the tm.h file, but
2577 typically, overriding these defaults is unnecessary. */
2579 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2580 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2581 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2582 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2583 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2585 #ifndef TEXT_END_LABEL
2586 #define TEXT_END_LABEL "Letext"
2587 #endif
2588 #ifndef DATA_END_LABEL
2589 #define DATA_END_LABEL "Ledata"
2590 #endif
2591 #ifndef BSS_END_LABEL
2592 #define BSS_END_LABEL "Lebss"
2593 #endif
2594 #ifndef INSN_LABEL_FMT
2595 #define INSN_LABEL_FMT "LI%u_"
2596 #endif
2597 #ifndef BLOCK_BEGIN_LABEL
2598 #define BLOCK_BEGIN_LABEL "LBB"
2599 #endif
2600 #ifndef BLOCK_END_LABEL
2601 #define BLOCK_END_LABEL "LBE"
2602 #endif
2603 #ifndef BODY_BEGIN_LABEL
2604 #define BODY_BEGIN_LABEL "Lbb"
2605 #endif
2606 #ifndef BODY_END_LABEL
2607 #define BODY_END_LABEL "Lbe"
2608 #endif
2609 #ifndef LINE_CODE_LABEL
2610 #define LINE_CODE_LABEL "LM"
2611 #endif
2612 #ifndef SEPARATE_LINE_CODE_LABEL
2613 #define SEPARATE_LINE_CODE_LABEL "LSM"
2614 #endif
2616 /* We allow a language front-end to designate a function that is to be
2617 called to "demangle" any name before it it put into a DIE. */
2619 static const char *(*demangle_name_func) PARAMS ((const char *));
2621 void
2622 dwarf2out_set_demangle_name_func (func)
2623 const char *(*func) PARAMS ((const char *));
2625 demangle_name_func = func;
2628 /* Return an rtx like ORIG which lives forever. If we're doing GC,
2629 that means adding it to used_rtx_varray. If not, that means making
2630 a copy on the permanent_obstack. */
2632 static rtx
2633 save_rtx (orig)
2634 register rtx orig;
2636 if (ggc_p)
2637 VARRAY_PUSH_RTX (used_rtx_varray, orig);
2638 else
2640 push_obstacks_nochange ();
2641 end_temporary_allocation ();
2642 orig = copy_rtx (orig);
2643 pop_obstacks ();
2646 return orig;
2649 /* Test if rtl node points to a pseudo register. */
2651 static inline int
2652 is_pseudo_reg (rtl)
2653 register rtx rtl;
2655 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2656 || ((GET_CODE (rtl) == SUBREG)
2657 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2660 /* Return a reference to a type, with its const and volatile qualifiers
2661 removed. */
2663 static inline tree
2664 type_main_variant (type)
2665 register tree type;
2667 type = TYPE_MAIN_VARIANT (type);
2669 /* There really should be only one main variant among any group of variants
2670 of a given type (and all of the MAIN_VARIANT values for all members of
2671 the group should point to that one type) but sometimes the C front-end
2672 messes this up for array types, so we work around that bug here. */
2674 if (TREE_CODE (type) == ARRAY_TYPE)
2675 while (type != TYPE_MAIN_VARIANT (type))
2676 type = TYPE_MAIN_VARIANT (type);
2678 return type;
2681 /* Return non-zero if the given type node represents a tagged type. */
2683 static inline int
2684 is_tagged_type (type)
2685 register tree type;
2687 register enum tree_code code = TREE_CODE (type);
2689 return (code == RECORD_TYPE || code == UNION_TYPE
2690 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2693 /* Convert a DIE tag into its string name. */
2695 static const char *
2696 dwarf_tag_name (tag)
2697 register unsigned tag;
2699 switch (tag)
2701 case DW_TAG_padding:
2702 return "DW_TAG_padding";
2703 case DW_TAG_array_type:
2704 return "DW_TAG_array_type";
2705 case DW_TAG_class_type:
2706 return "DW_TAG_class_type";
2707 case DW_TAG_entry_point:
2708 return "DW_TAG_entry_point";
2709 case DW_TAG_enumeration_type:
2710 return "DW_TAG_enumeration_type";
2711 case DW_TAG_formal_parameter:
2712 return "DW_TAG_formal_parameter";
2713 case DW_TAG_imported_declaration:
2714 return "DW_TAG_imported_declaration";
2715 case DW_TAG_label:
2716 return "DW_TAG_label";
2717 case DW_TAG_lexical_block:
2718 return "DW_TAG_lexical_block";
2719 case DW_TAG_member:
2720 return "DW_TAG_member";
2721 case DW_TAG_pointer_type:
2722 return "DW_TAG_pointer_type";
2723 case DW_TAG_reference_type:
2724 return "DW_TAG_reference_type";
2725 case DW_TAG_compile_unit:
2726 return "DW_TAG_compile_unit";
2727 case DW_TAG_string_type:
2728 return "DW_TAG_string_type";
2729 case DW_TAG_structure_type:
2730 return "DW_TAG_structure_type";
2731 case DW_TAG_subroutine_type:
2732 return "DW_TAG_subroutine_type";
2733 case DW_TAG_typedef:
2734 return "DW_TAG_typedef";
2735 case DW_TAG_union_type:
2736 return "DW_TAG_union_type";
2737 case DW_TAG_unspecified_parameters:
2738 return "DW_TAG_unspecified_parameters";
2739 case DW_TAG_variant:
2740 return "DW_TAG_variant";
2741 case DW_TAG_common_block:
2742 return "DW_TAG_common_block";
2743 case DW_TAG_common_inclusion:
2744 return "DW_TAG_common_inclusion";
2745 case DW_TAG_inheritance:
2746 return "DW_TAG_inheritance";
2747 case DW_TAG_inlined_subroutine:
2748 return "DW_TAG_inlined_subroutine";
2749 case DW_TAG_module:
2750 return "DW_TAG_module";
2751 case DW_TAG_ptr_to_member_type:
2752 return "DW_TAG_ptr_to_member_type";
2753 case DW_TAG_set_type:
2754 return "DW_TAG_set_type";
2755 case DW_TAG_subrange_type:
2756 return "DW_TAG_subrange_type";
2757 case DW_TAG_with_stmt:
2758 return "DW_TAG_with_stmt";
2759 case DW_TAG_access_declaration:
2760 return "DW_TAG_access_declaration";
2761 case DW_TAG_base_type:
2762 return "DW_TAG_base_type";
2763 case DW_TAG_catch_block:
2764 return "DW_TAG_catch_block";
2765 case DW_TAG_const_type:
2766 return "DW_TAG_const_type";
2767 case DW_TAG_constant:
2768 return "DW_TAG_constant";
2769 case DW_TAG_enumerator:
2770 return "DW_TAG_enumerator";
2771 case DW_TAG_file_type:
2772 return "DW_TAG_file_type";
2773 case DW_TAG_friend:
2774 return "DW_TAG_friend";
2775 case DW_TAG_namelist:
2776 return "DW_TAG_namelist";
2777 case DW_TAG_namelist_item:
2778 return "DW_TAG_namelist_item";
2779 case DW_TAG_packed_type:
2780 return "DW_TAG_packed_type";
2781 case DW_TAG_subprogram:
2782 return "DW_TAG_subprogram";
2783 case DW_TAG_template_type_param:
2784 return "DW_TAG_template_type_param";
2785 case DW_TAG_template_value_param:
2786 return "DW_TAG_template_value_param";
2787 case DW_TAG_thrown_type:
2788 return "DW_TAG_thrown_type";
2789 case DW_TAG_try_block:
2790 return "DW_TAG_try_block";
2791 case DW_TAG_variant_part:
2792 return "DW_TAG_variant_part";
2793 case DW_TAG_variable:
2794 return "DW_TAG_variable";
2795 case DW_TAG_volatile_type:
2796 return "DW_TAG_volatile_type";
2797 case DW_TAG_MIPS_loop:
2798 return "DW_TAG_MIPS_loop";
2799 case DW_TAG_format_label:
2800 return "DW_TAG_format_label";
2801 case DW_TAG_function_template:
2802 return "DW_TAG_function_template";
2803 case DW_TAG_class_template:
2804 return "DW_TAG_class_template";
2805 default:
2806 return "DW_TAG_<unknown>";
2810 /* Convert a DWARF attribute code into its string name. */
2812 static const char *
2813 dwarf_attr_name (attr)
2814 register unsigned attr;
2816 switch (attr)
2818 case DW_AT_sibling:
2819 return "DW_AT_sibling";
2820 case DW_AT_location:
2821 return "DW_AT_location";
2822 case DW_AT_name:
2823 return "DW_AT_name";
2824 case DW_AT_ordering:
2825 return "DW_AT_ordering";
2826 case DW_AT_subscr_data:
2827 return "DW_AT_subscr_data";
2828 case DW_AT_byte_size:
2829 return "DW_AT_byte_size";
2830 case DW_AT_bit_offset:
2831 return "DW_AT_bit_offset";
2832 case DW_AT_bit_size:
2833 return "DW_AT_bit_size";
2834 case DW_AT_element_list:
2835 return "DW_AT_element_list";
2836 case DW_AT_stmt_list:
2837 return "DW_AT_stmt_list";
2838 case DW_AT_low_pc:
2839 return "DW_AT_low_pc";
2840 case DW_AT_high_pc:
2841 return "DW_AT_high_pc";
2842 case DW_AT_language:
2843 return "DW_AT_language";
2844 case DW_AT_member:
2845 return "DW_AT_member";
2846 case DW_AT_discr:
2847 return "DW_AT_discr";
2848 case DW_AT_discr_value:
2849 return "DW_AT_discr_value";
2850 case DW_AT_visibility:
2851 return "DW_AT_visibility";
2852 case DW_AT_import:
2853 return "DW_AT_import";
2854 case DW_AT_string_length:
2855 return "DW_AT_string_length";
2856 case DW_AT_common_reference:
2857 return "DW_AT_common_reference";
2858 case DW_AT_comp_dir:
2859 return "DW_AT_comp_dir";
2860 case DW_AT_const_value:
2861 return "DW_AT_const_value";
2862 case DW_AT_containing_type:
2863 return "DW_AT_containing_type";
2864 case DW_AT_default_value:
2865 return "DW_AT_default_value";
2866 case DW_AT_inline:
2867 return "DW_AT_inline";
2868 case DW_AT_is_optional:
2869 return "DW_AT_is_optional";
2870 case DW_AT_lower_bound:
2871 return "DW_AT_lower_bound";
2872 case DW_AT_producer:
2873 return "DW_AT_producer";
2874 case DW_AT_prototyped:
2875 return "DW_AT_prototyped";
2876 case DW_AT_return_addr:
2877 return "DW_AT_return_addr";
2878 case DW_AT_start_scope:
2879 return "DW_AT_start_scope";
2880 case DW_AT_stride_size:
2881 return "DW_AT_stride_size";
2882 case DW_AT_upper_bound:
2883 return "DW_AT_upper_bound";
2884 case DW_AT_abstract_origin:
2885 return "DW_AT_abstract_origin";
2886 case DW_AT_accessibility:
2887 return "DW_AT_accessibility";
2888 case DW_AT_address_class:
2889 return "DW_AT_address_class";
2890 case DW_AT_artificial:
2891 return "DW_AT_artificial";
2892 case DW_AT_base_types:
2893 return "DW_AT_base_types";
2894 case DW_AT_calling_convention:
2895 return "DW_AT_calling_convention";
2896 case DW_AT_count:
2897 return "DW_AT_count";
2898 case DW_AT_data_member_location:
2899 return "DW_AT_data_member_location";
2900 case DW_AT_decl_column:
2901 return "DW_AT_decl_column";
2902 case DW_AT_decl_file:
2903 return "DW_AT_decl_file";
2904 case DW_AT_decl_line:
2905 return "DW_AT_decl_line";
2906 case DW_AT_declaration:
2907 return "DW_AT_declaration";
2908 case DW_AT_discr_list:
2909 return "DW_AT_discr_list";
2910 case DW_AT_encoding:
2911 return "DW_AT_encoding";
2912 case DW_AT_external:
2913 return "DW_AT_external";
2914 case DW_AT_frame_base:
2915 return "DW_AT_frame_base";
2916 case DW_AT_friend:
2917 return "DW_AT_friend";
2918 case DW_AT_identifier_case:
2919 return "DW_AT_identifier_case";
2920 case DW_AT_macro_info:
2921 return "DW_AT_macro_info";
2922 case DW_AT_namelist_items:
2923 return "DW_AT_namelist_items";
2924 case DW_AT_priority:
2925 return "DW_AT_priority";
2926 case DW_AT_segment:
2927 return "DW_AT_segment";
2928 case DW_AT_specification:
2929 return "DW_AT_specification";
2930 case DW_AT_static_link:
2931 return "DW_AT_static_link";
2932 case DW_AT_type:
2933 return "DW_AT_type";
2934 case DW_AT_use_location:
2935 return "DW_AT_use_location";
2936 case DW_AT_variable_parameter:
2937 return "DW_AT_variable_parameter";
2938 case DW_AT_virtuality:
2939 return "DW_AT_virtuality";
2940 case DW_AT_vtable_elem_location:
2941 return "DW_AT_vtable_elem_location";
2943 case DW_AT_MIPS_fde:
2944 return "DW_AT_MIPS_fde";
2945 case DW_AT_MIPS_loop_begin:
2946 return "DW_AT_MIPS_loop_begin";
2947 case DW_AT_MIPS_tail_loop_begin:
2948 return "DW_AT_MIPS_tail_loop_begin";
2949 case DW_AT_MIPS_epilog_begin:
2950 return "DW_AT_MIPS_epilog_begin";
2951 case DW_AT_MIPS_loop_unroll_factor:
2952 return "DW_AT_MIPS_loop_unroll_factor";
2953 case DW_AT_MIPS_software_pipeline_depth:
2954 return "DW_AT_MIPS_software_pipeline_depth";
2955 case DW_AT_MIPS_linkage_name:
2956 return "DW_AT_MIPS_linkage_name";
2957 case DW_AT_MIPS_stride:
2958 return "DW_AT_MIPS_stride";
2959 case DW_AT_MIPS_abstract_name:
2960 return "DW_AT_MIPS_abstract_name";
2961 case DW_AT_MIPS_clone_origin:
2962 return "DW_AT_MIPS_clone_origin";
2963 case DW_AT_MIPS_has_inlines:
2964 return "DW_AT_MIPS_has_inlines";
2966 case DW_AT_sf_names:
2967 return "DW_AT_sf_names";
2968 case DW_AT_src_info:
2969 return "DW_AT_src_info";
2970 case DW_AT_mac_info:
2971 return "DW_AT_mac_info";
2972 case DW_AT_src_coords:
2973 return "DW_AT_src_coords";
2974 case DW_AT_body_begin:
2975 return "DW_AT_body_begin";
2976 case DW_AT_body_end:
2977 return "DW_AT_body_end";
2978 default:
2979 return "DW_AT_<unknown>";
2983 /* Convert a DWARF value form code into its string name. */
2985 static const char *
2986 dwarf_form_name (form)
2987 register unsigned form;
2989 switch (form)
2991 case DW_FORM_addr:
2992 return "DW_FORM_addr";
2993 case DW_FORM_block2:
2994 return "DW_FORM_block2";
2995 case DW_FORM_block4:
2996 return "DW_FORM_block4";
2997 case DW_FORM_data2:
2998 return "DW_FORM_data2";
2999 case DW_FORM_data4:
3000 return "DW_FORM_data4";
3001 case DW_FORM_data8:
3002 return "DW_FORM_data8";
3003 case DW_FORM_string:
3004 return "DW_FORM_string";
3005 case DW_FORM_block:
3006 return "DW_FORM_block";
3007 case DW_FORM_block1:
3008 return "DW_FORM_block1";
3009 case DW_FORM_data1:
3010 return "DW_FORM_data1";
3011 case DW_FORM_flag:
3012 return "DW_FORM_flag";
3013 case DW_FORM_sdata:
3014 return "DW_FORM_sdata";
3015 case DW_FORM_strp:
3016 return "DW_FORM_strp";
3017 case DW_FORM_udata:
3018 return "DW_FORM_udata";
3019 case DW_FORM_ref_addr:
3020 return "DW_FORM_ref_addr";
3021 case DW_FORM_ref1:
3022 return "DW_FORM_ref1";
3023 case DW_FORM_ref2:
3024 return "DW_FORM_ref2";
3025 case DW_FORM_ref4:
3026 return "DW_FORM_ref4";
3027 case DW_FORM_ref8:
3028 return "DW_FORM_ref8";
3029 case DW_FORM_ref_udata:
3030 return "DW_FORM_ref_udata";
3031 case DW_FORM_indirect:
3032 return "DW_FORM_indirect";
3033 default:
3034 return "DW_FORM_<unknown>";
3038 /* Convert a DWARF stack opcode into its string name. */
3040 static const char *
3041 dwarf_stack_op_name (op)
3042 register unsigned op;
3044 switch (op)
3046 case DW_OP_addr:
3047 return "DW_OP_addr";
3048 case DW_OP_deref:
3049 return "DW_OP_deref";
3050 case DW_OP_const1u:
3051 return "DW_OP_const1u";
3052 case DW_OP_const1s:
3053 return "DW_OP_const1s";
3054 case DW_OP_const2u:
3055 return "DW_OP_const2u";
3056 case DW_OP_const2s:
3057 return "DW_OP_const2s";
3058 case DW_OP_const4u:
3059 return "DW_OP_const4u";
3060 case DW_OP_const4s:
3061 return "DW_OP_const4s";
3062 case DW_OP_const8u:
3063 return "DW_OP_const8u";
3064 case DW_OP_const8s:
3065 return "DW_OP_const8s";
3066 case DW_OP_constu:
3067 return "DW_OP_constu";
3068 case DW_OP_consts:
3069 return "DW_OP_consts";
3070 case DW_OP_dup:
3071 return "DW_OP_dup";
3072 case DW_OP_drop:
3073 return "DW_OP_drop";
3074 case DW_OP_over:
3075 return "DW_OP_over";
3076 case DW_OP_pick:
3077 return "DW_OP_pick";
3078 case DW_OP_swap:
3079 return "DW_OP_swap";
3080 case DW_OP_rot:
3081 return "DW_OP_rot";
3082 case DW_OP_xderef:
3083 return "DW_OP_xderef";
3084 case DW_OP_abs:
3085 return "DW_OP_abs";
3086 case DW_OP_and:
3087 return "DW_OP_and";
3088 case DW_OP_div:
3089 return "DW_OP_div";
3090 case DW_OP_minus:
3091 return "DW_OP_minus";
3092 case DW_OP_mod:
3093 return "DW_OP_mod";
3094 case DW_OP_mul:
3095 return "DW_OP_mul";
3096 case DW_OP_neg:
3097 return "DW_OP_neg";
3098 case DW_OP_not:
3099 return "DW_OP_not";
3100 case DW_OP_or:
3101 return "DW_OP_or";
3102 case DW_OP_plus:
3103 return "DW_OP_plus";
3104 case DW_OP_plus_uconst:
3105 return "DW_OP_plus_uconst";
3106 case DW_OP_shl:
3107 return "DW_OP_shl";
3108 case DW_OP_shr:
3109 return "DW_OP_shr";
3110 case DW_OP_shra:
3111 return "DW_OP_shra";
3112 case DW_OP_xor:
3113 return "DW_OP_xor";
3114 case DW_OP_bra:
3115 return "DW_OP_bra";
3116 case DW_OP_eq:
3117 return "DW_OP_eq";
3118 case DW_OP_ge:
3119 return "DW_OP_ge";
3120 case DW_OP_gt:
3121 return "DW_OP_gt";
3122 case DW_OP_le:
3123 return "DW_OP_le";
3124 case DW_OP_lt:
3125 return "DW_OP_lt";
3126 case DW_OP_ne:
3127 return "DW_OP_ne";
3128 case DW_OP_skip:
3129 return "DW_OP_skip";
3130 case DW_OP_lit0:
3131 return "DW_OP_lit0";
3132 case DW_OP_lit1:
3133 return "DW_OP_lit1";
3134 case DW_OP_lit2:
3135 return "DW_OP_lit2";
3136 case DW_OP_lit3:
3137 return "DW_OP_lit3";
3138 case DW_OP_lit4:
3139 return "DW_OP_lit4";
3140 case DW_OP_lit5:
3141 return "DW_OP_lit5";
3142 case DW_OP_lit6:
3143 return "DW_OP_lit6";
3144 case DW_OP_lit7:
3145 return "DW_OP_lit7";
3146 case DW_OP_lit8:
3147 return "DW_OP_lit8";
3148 case DW_OP_lit9:
3149 return "DW_OP_lit9";
3150 case DW_OP_lit10:
3151 return "DW_OP_lit10";
3152 case DW_OP_lit11:
3153 return "DW_OP_lit11";
3154 case DW_OP_lit12:
3155 return "DW_OP_lit12";
3156 case DW_OP_lit13:
3157 return "DW_OP_lit13";
3158 case DW_OP_lit14:
3159 return "DW_OP_lit14";
3160 case DW_OP_lit15:
3161 return "DW_OP_lit15";
3162 case DW_OP_lit16:
3163 return "DW_OP_lit16";
3164 case DW_OP_lit17:
3165 return "DW_OP_lit17";
3166 case DW_OP_lit18:
3167 return "DW_OP_lit18";
3168 case DW_OP_lit19:
3169 return "DW_OP_lit19";
3170 case DW_OP_lit20:
3171 return "DW_OP_lit20";
3172 case DW_OP_lit21:
3173 return "DW_OP_lit21";
3174 case DW_OP_lit22:
3175 return "DW_OP_lit22";
3176 case DW_OP_lit23:
3177 return "DW_OP_lit23";
3178 case DW_OP_lit24:
3179 return "DW_OP_lit24";
3180 case DW_OP_lit25:
3181 return "DW_OP_lit25";
3182 case DW_OP_lit26:
3183 return "DW_OP_lit26";
3184 case DW_OP_lit27:
3185 return "DW_OP_lit27";
3186 case DW_OP_lit28:
3187 return "DW_OP_lit28";
3188 case DW_OP_lit29:
3189 return "DW_OP_lit29";
3190 case DW_OP_lit30:
3191 return "DW_OP_lit30";
3192 case DW_OP_lit31:
3193 return "DW_OP_lit31";
3194 case DW_OP_reg0:
3195 return "DW_OP_reg0";
3196 case DW_OP_reg1:
3197 return "DW_OP_reg1";
3198 case DW_OP_reg2:
3199 return "DW_OP_reg2";
3200 case DW_OP_reg3:
3201 return "DW_OP_reg3";
3202 case DW_OP_reg4:
3203 return "DW_OP_reg4";
3204 case DW_OP_reg5:
3205 return "DW_OP_reg5";
3206 case DW_OP_reg6:
3207 return "DW_OP_reg6";
3208 case DW_OP_reg7:
3209 return "DW_OP_reg7";
3210 case DW_OP_reg8:
3211 return "DW_OP_reg8";
3212 case DW_OP_reg9:
3213 return "DW_OP_reg9";
3214 case DW_OP_reg10:
3215 return "DW_OP_reg10";
3216 case DW_OP_reg11:
3217 return "DW_OP_reg11";
3218 case DW_OP_reg12:
3219 return "DW_OP_reg12";
3220 case DW_OP_reg13:
3221 return "DW_OP_reg13";
3222 case DW_OP_reg14:
3223 return "DW_OP_reg14";
3224 case DW_OP_reg15:
3225 return "DW_OP_reg15";
3226 case DW_OP_reg16:
3227 return "DW_OP_reg16";
3228 case DW_OP_reg17:
3229 return "DW_OP_reg17";
3230 case DW_OP_reg18:
3231 return "DW_OP_reg18";
3232 case DW_OP_reg19:
3233 return "DW_OP_reg19";
3234 case DW_OP_reg20:
3235 return "DW_OP_reg20";
3236 case DW_OP_reg21:
3237 return "DW_OP_reg21";
3238 case DW_OP_reg22:
3239 return "DW_OP_reg22";
3240 case DW_OP_reg23:
3241 return "DW_OP_reg23";
3242 case DW_OP_reg24:
3243 return "DW_OP_reg24";
3244 case DW_OP_reg25:
3245 return "DW_OP_reg25";
3246 case DW_OP_reg26:
3247 return "DW_OP_reg26";
3248 case DW_OP_reg27:
3249 return "DW_OP_reg27";
3250 case DW_OP_reg28:
3251 return "DW_OP_reg28";
3252 case DW_OP_reg29:
3253 return "DW_OP_reg29";
3254 case DW_OP_reg30:
3255 return "DW_OP_reg30";
3256 case DW_OP_reg31:
3257 return "DW_OP_reg31";
3258 case DW_OP_breg0:
3259 return "DW_OP_breg0";
3260 case DW_OP_breg1:
3261 return "DW_OP_breg1";
3262 case DW_OP_breg2:
3263 return "DW_OP_breg2";
3264 case DW_OP_breg3:
3265 return "DW_OP_breg3";
3266 case DW_OP_breg4:
3267 return "DW_OP_breg4";
3268 case DW_OP_breg5:
3269 return "DW_OP_breg5";
3270 case DW_OP_breg6:
3271 return "DW_OP_breg6";
3272 case DW_OP_breg7:
3273 return "DW_OP_breg7";
3274 case DW_OP_breg8:
3275 return "DW_OP_breg8";
3276 case DW_OP_breg9:
3277 return "DW_OP_breg9";
3278 case DW_OP_breg10:
3279 return "DW_OP_breg10";
3280 case DW_OP_breg11:
3281 return "DW_OP_breg11";
3282 case DW_OP_breg12:
3283 return "DW_OP_breg12";
3284 case DW_OP_breg13:
3285 return "DW_OP_breg13";
3286 case DW_OP_breg14:
3287 return "DW_OP_breg14";
3288 case DW_OP_breg15:
3289 return "DW_OP_breg15";
3290 case DW_OP_breg16:
3291 return "DW_OP_breg16";
3292 case DW_OP_breg17:
3293 return "DW_OP_breg17";
3294 case DW_OP_breg18:
3295 return "DW_OP_breg18";
3296 case DW_OP_breg19:
3297 return "DW_OP_breg19";
3298 case DW_OP_breg20:
3299 return "DW_OP_breg20";
3300 case DW_OP_breg21:
3301 return "DW_OP_breg21";
3302 case DW_OP_breg22:
3303 return "DW_OP_breg22";
3304 case DW_OP_breg23:
3305 return "DW_OP_breg23";
3306 case DW_OP_breg24:
3307 return "DW_OP_breg24";
3308 case DW_OP_breg25:
3309 return "DW_OP_breg25";
3310 case DW_OP_breg26:
3311 return "DW_OP_breg26";
3312 case DW_OP_breg27:
3313 return "DW_OP_breg27";
3314 case DW_OP_breg28:
3315 return "DW_OP_breg28";
3316 case DW_OP_breg29:
3317 return "DW_OP_breg29";
3318 case DW_OP_breg30:
3319 return "DW_OP_breg30";
3320 case DW_OP_breg31:
3321 return "DW_OP_breg31";
3322 case DW_OP_regx:
3323 return "DW_OP_regx";
3324 case DW_OP_fbreg:
3325 return "DW_OP_fbreg";
3326 case DW_OP_bregx:
3327 return "DW_OP_bregx";
3328 case DW_OP_piece:
3329 return "DW_OP_piece";
3330 case DW_OP_deref_size:
3331 return "DW_OP_deref_size";
3332 case DW_OP_xderef_size:
3333 return "DW_OP_xderef_size";
3334 case DW_OP_nop:
3335 return "DW_OP_nop";
3336 default:
3337 return "OP_<unknown>";
3341 /* Convert a DWARF type code into its string name. */
3343 #if 0
3344 static const char *
3345 dwarf_type_encoding_name (enc)
3346 register unsigned enc;
3348 switch (enc)
3350 case DW_ATE_address:
3351 return "DW_ATE_address";
3352 case DW_ATE_boolean:
3353 return "DW_ATE_boolean";
3354 case DW_ATE_complex_float:
3355 return "DW_ATE_complex_float";
3356 case DW_ATE_float:
3357 return "DW_ATE_float";
3358 case DW_ATE_signed:
3359 return "DW_ATE_signed";
3360 case DW_ATE_signed_char:
3361 return "DW_ATE_signed_char";
3362 case DW_ATE_unsigned:
3363 return "DW_ATE_unsigned";
3364 case DW_ATE_unsigned_char:
3365 return "DW_ATE_unsigned_char";
3366 default:
3367 return "DW_ATE_<unknown>";
3370 #endif
3372 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3373 instance of an inlined instance of a decl which is local to an inline
3374 function, so we have to trace all of the way back through the origin chain
3375 to find out what sort of node actually served as the original seed for the
3376 given block. */
3378 static tree
3379 decl_ultimate_origin (decl)
3380 register tree decl;
3382 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3383 nodes in the function to point to themselves; ignore that if
3384 we're trying to output the abstract instance of this function. */
3385 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl)
3386 return NULL_TREE;
3388 #ifdef ENABLE_CHECKING
3389 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3390 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3391 most distant ancestor, this should never happen. */
3392 abort ();
3393 #endif
3395 return DECL_ABSTRACT_ORIGIN (decl);
3398 /* Determine the "ultimate origin" of a block. The block may be an inlined
3399 instance of an inlined instance of a block which is local to an inline
3400 function, so we have to trace all of the way back through the origin chain
3401 to find out what sort of node actually served as the original seed for the
3402 given block. */
3404 static tree
3405 block_ultimate_origin (block)
3406 register tree block;
3408 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3410 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the
3411 nodes in the function to point to themselves; ignore that if
3412 we're trying to output the abstract instance of this function. */
3413 if (BLOCK_ABSTRACT (block) && immediate_origin == block)
3414 return NULL_TREE;
3416 if (immediate_origin == NULL_TREE)
3417 return NULL_TREE;
3418 else
3420 register tree ret_val;
3421 register tree lookahead = immediate_origin;
3425 ret_val = lookahead;
3426 lookahead = (TREE_CODE (ret_val) == BLOCK)
3427 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3428 : NULL;
3430 while (lookahead != NULL && lookahead != ret_val);
3432 return ret_val;
3436 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3437 of a virtual function may refer to a base class, so we check the 'this'
3438 parameter. */
3440 static tree
3441 decl_class_context (decl)
3442 tree decl;
3444 tree context = NULL_TREE;
3446 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3447 context = DECL_CONTEXT (decl);
3448 else
3449 context = TYPE_MAIN_VARIANT
3450 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3452 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3453 context = NULL_TREE;
3455 return context;
3458 /* Add an attribute/value pair to a DIE. We build the lists up in reverse
3459 addition order, and correct that in add_sibling_attributes. */
3461 static inline void
3462 add_dwarf_attr (die, attr)
3463 register dw_die_ref die;
3464 register dw_attr_ref attr;
3466 if (die != NULL && attr != NULL)
3468 attr->dw_attr_next = die->die_attr;
3469 die->die_attr = attr;
3473 static inline dw_val_class
3474 AT_class (a)
3475 dw_attr_ref a;
3477 return a->dw_attr_val.val_class;
3480 /* Add a flag value attribute to a DIE. */
3482 static inline void
3483 add_AT_flag (die, attr_kind, flag)
3484 register dw_die_ref die;
3485 register enum dwarf_attribute attr_kind;
3486 register unsigned flag;
3488 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3490 attr->dw_attr_next = NULL;
3491 attr->dw_attr = attr_kind;
3492 attr->dw_attr_val.val_class = dw_val_class_flag;
3493 attr->dw_attr_val.v.val_flag = flag;
3494 add_dwarf_attr (die, attr);
3497 static inline unsigned
3498 AT_flag (a)
3499 register dw_attr_ref a;
3501 if (a && AT_class (a) == dw_val_class_flag)
3502 return a->dw_attr_val.v.val_flag;
3504 return 0;
3507 /* Add a signed integer attribute value to a DIE. */
3509 static inline void
3510 add_AT_int (die, attr_kind, int_val)
3511 register dw_die_ref die;
3512 register enum dwarf_attribute attr_kind;
3513 register long int int_val;
3515 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3517 attr->dw_attr_next = NULL;
3518 attr->dw_attr = attr_kind;
3519 attr->dw_attr_val.val_class = dw_val_class_const;
3520 attr->dw_attr_val.v.val_int = int_val;
3521 add_dwarf_attr (die, attr);
3524 static inline long int
3525 AT_int (a)
3526 register dw_attr_ref a;
3528 if (a && AT_class (a) == dw_val_class_const)
3529 return a->dw_attr_val.v.val_int;
3531 return 0;
3534 /* Add an unsigned integer attribute value to a DIE. */
3536 static inline void
3537 add_AT_unsigned (die, attr_kind, unsigned_val)
3538 register dw_die_ref die;
3539 register enum dwarf_attribute attr_kind;
3540 register unsigned long unsigned_val;
3542 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3544 attr->dw_attr_next = NULL;
3545 attr->dw_attr = attr_kind;
3546 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3547 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3548 add_dwarf_attr (die, attr);
3551 static inline unsigned long
3552 AT_unsigned (a)
3553 register dw_attr_ref a;
3555 if (a && AT_class (a) == dw_val_class_unsigned_const)
3556 return a->dw_attr_val.v.val_unsigned;
3558 return 0;
3561 /* Add an unsigned double integer attribute value to a DIE. */
3563 static inline void
3564 add_AT_long_long (die, attr_kind, val_hi, val_low)
3565 register dw_die_ref die;
3566 register enum dwarf_attribute attr_kind;
3567 register unsigned long val_hi;
3568 register unsigned long val_low;
3570 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3572 attr->dw_attr_next = NULL;
3573 attr->dw_attr = attr_kind;
3574 attr->dw_attr_val.val_class = dw_val_class_long_long;
3575 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3576 attr->dw_attr_val.v.val_long_long.low = val_low;
3577 add_dwarf_attr (die, attr);
3580 /* Add a floating point attribute value to a DIE and return it. */
3582 static inline void
3583 add_AT_float (die, attr_kind, length, array)
3584 register dw_die_ref die;
3585 register enum dwarf_attribute attr_kind;
3586 register unsigned length;
3587 register long *array;
3589 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3591 attr->dw_attr_next = NULL;
3592 attr->dw_attr = attr_kind;
3593 attr->dw_attr_val.val_class = dw_val_class_float;
3594 attr->dw_attr_val.v.val_float.length = length;
3595 attr->dw_attr_val.v.val_float.array = array;
3596 add_dwarf_attr (die, attr);
3599 /* Add a string attribute value to a DIE. */
3601 static inline void
3602 add_AT_string (die, attr_kind, str)
3603 register dw_die_ref die;
3604 register enum dwarf_attribute attr_kind;
3605 register const char *str;
3607 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3609 attr->dw_attr_next = NULL;
3610 attr->dw_attr = attr_kind;
3611 attr->dw_attr_val.val_class = dw_val_class_str;
3612 attr->dw_attr_val.v.val_str = xstrdup (str);
3613 add_dwarf_attr (die, attr);
3616 static inline const char *
3617 AT_string (a)
3618 register dw_attr_ref a;
3620 if (a && AT_class (a) == dw_val_class_str)
3621 return a->dw_attr_val.v.val_str;
3623 return NULL;
3626 /* Add a DIE reference attribute value to a DIE. */
3628 static inline void
3629 add_AT_die_ref (die, attr_kind, targ_die)
3630 register dw_die_ref die;
3631 register enum dwarf_attribute attr_kind;
3632 register dw_die_ref targ_die;
3634 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3636 attr->dw_attr_next = NULL;
3637 attr->dw_attr = attr_kind;
3638 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3639 attr->dw_attr_val.v.val_die_ref = targ_die;
3640 add_dwarf_attr (die, attr);
3643 static inline dw_die_ref
3644 AT_ref (a)
3645 register dw_attr_ref a;
3647 if (a && AT_class (a) == dw_val_class_die_ref)
3648 return a->dw_attr_val.v.val_die_ref;
3650 return NULL;
3653 /* Add an FDE reference attribute value to a DIE. */
3655 static inline void
3656 add_AT_fde_ref (die, attr_kind, targ_fde)
3657 register dw_die_ref die;
3658 register enum dwarf_attribute attr_kind;
3659 register unsigned targ_fde;
3661 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3663 attr->dw_attr_next = NULL;
3664 attr->dw_attr = attr_kind;
3665 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3666 attr->dw_attr_val.v.val_fde_index = targ_fde;
3667 add_dwarf_attr (die, attr);
3670 /* Add a location description attribute value to a DIE. */
3672 static inline void
3673 add_AT_loc (die, attr_kind, loc)
3674 register dw_die_ref die;
3675 register enum dwarf_attribute attr_kind;
3676 register dw_loc_descr_ref loc;
3678 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3680 attr->dw_attr_next = NULL;
3681 attr->dw_attr = attr_kind;
3682 attr->dw_attr_val.val_class = dw_val_class_loc;
3683 attr->dw_attr_val.v.val_loc = loc;
3684 add_dwarf_attr (die, attr);
3687 static inline dw_loc_descr_ref
3688 AT_loc (a)
3689 register dw_attr_ref a;
3691 if (a && AT_class (a) == dw_val_class_loc)
3692 return a->dw_attr_val.v.val_loc;
3694 return NULL;
3697 /* Add an address constant attribute value to a DIE. */
3699 static inline void
3700 add_AT_addr (die, attr_kind, addr)
3701 register dw_die_ref die;
3702 register enum dwarf_attribute attr_kind;
3703 rtx addr;
3705 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3707 attr->dw_attr_next = NULL;
3708 attr->dw_attr = attr_kind;
3709 attr->dw_attr_val.val_class = dw_val_class_addr;
3710 attr->dw_attr_val.v.val_addr = addr;
3711 add_dwarf_attr (die, attr);
3714 static inline rtx
3715 AT_addr (a)
3716 register dw_attr_ref a;
3718 if (a && AT_class (a) == dw_val_class_addr)
3719 return a->dw_attr_val.v.val_addr;
3721 return NULL;
3724 /* Add a label identifier attribute value to a DIE. */
3726 static inline void
3727 add_AT_lbl_id (die, attr_kind, lbl_id)
3728 register dw_die_ref die;
3729 register enum dwarf_attribute attr_kind;
3730 register char *lbl_id;
3732 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3734 attr->dw_attr_next = NULL;
3735 attr->dw_attr = attr_kind;
3736 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3737 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3738 add_dwarf_attr (die, attr);
3741 /* Add a section offset attribute value to a DIE. */
3743 static inline void
3744 add_AT_lbl_offset (die, attr_kind, label)
3745 register dw_die_ref die;
3746 register enum dwarf_attribute attr_kind;
3747 register char *label;
3749 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3751 attr->dw_attr_next = NULL;
3752 attr->dw_attr = attr_kind;
3753 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3754 attr->dw_attr_val.v.val_lbl_id = xstrdup (label);
3755 add_dwarf_attr (die, attr);
3759 static inline const char *
3760 AT_lbl (a)
3761 register dw_attr_ref a;
3763 if (a && (AT_class (a) == dw_val_class_lbl_id
3764 || AT_class (a) == dw_val_class_lbl_offset))
3765 return a->dw_attr_val.v.val_lbl_id;
3767 return NULL;
3770 /* Get the attribute of type attr_kind. */
3772 static inline dw_attr_ref
3773 get_AT (die, attr_kind)
3774 register dw_die_ref die;
3775 register enum dwarf_attribute attr_kind;
3777 register dw_attr_ref a;
3778 register dw_die_ref spec = NULL;
3780 if (die != NULL)
3782 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3784 if (a->dw_attr == attr_kind)
3785 return a;
3787 if (a->dw_attr == DW_AT_specification
3788 || a->dw_attr == DW_AT_abstract_origin)
3789 spec = AT_ref (a);
3792 if (spec)
3793 return get_AT (spec, attr_kind);
3796 return NULL;
3799 /* Return the "low pc" attribute value, typically associated with
3800 a subprogram DIE. Return null if the "low pc" attribute is
3801 either not prsent, or if it cannot be represented as an
3802 assembler label identifier. */
3804 static inline const char *
3805 get_AT_low_pc (die)
3806 register dw_die_ref die;
3808 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3809 return AT_lbl (a);
3812 /* Return the "high pc" attribute value, typically associated with
3813 a subprogram DIE. Return null if the "high pc" attribute is
3814 either not prsent, or if it cannot be represented as an
3815 assembler label identifier. */
3817 static inline const char *
3818 get_AT_hi_pc (die)
3819 register dw_die_ref die;
3821 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3822 return AT_lbl (a);
3825 /* Return the value of the string attribute designated by ATTR_KIND, or
3826 NULL if it is not present. */
3828 static inline const char *
3829 get_AT_string (die, attr_kind)
3830 register dw_die_ref die;
3831 register enum dwarf_attribute attr_kind;
3833 register dw_attr_ref a = get_AT (die, attr_kind);
3834 return AT_string (a);
3837 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3838 if it is not present. */
3840 static inline int
3841 get_AT_flag (die, attr_kind)
3842 register dw_die_ref die;
3843 register enum dwarf_attribute attr_kind;
3845 register dw_attr_ref a = get_AT (die, attr_kind);
3846 return AT_flag (a);
3849 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3850 if it is not present. */
3852 static inline unsigned
3853 get_AT_unsigned (die, attr_kind)
3854 register dw_die_ref die;
3855 register enum dwarf_attribute attr_kind;
3857 register dw_attr_ref a = get_AT (die, attr_kind);
3858 return AT_unsigned (a);
3861 static inline dw_die_ref
3862 get_AT_ref (die, attr_kind)
3863 dw_die_ref die;
3864 register enum dwarf_attribute attr_kind;
3866 register dw_attr_ref a = get_AT (die, attr_kind);
3867 return AT_ref (a);
3870 static inline int
3871 is_c_family ()
3873 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3875 return (lang == DW_LANG_C || lang == DW_LANG_C89
3876 || lang == DW_LANG_C_plus_plus);
3879 static inline int
3880 is_fortran ()
3882 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3884 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3887 /* Free up the memory used by A. */
3889 static inline void
3890 free_AT (a)
3891 dw_attr_ref a;
3893 switch (AT_class (a))
3895 case dw_val_class_str:
3896 case dw_val_class_lbl_id:
3897 case dw_val_class_lbl_offset:
3898 free (a->dw_attr_val.v.val_str);
3899 break;
3901 default:
3902 break;
3905 free (a);
3908 /* Remove the specified attribute if present. */
3910 static void
3911 remove_AT (die, attr_kind)
3912 register dw_die_ref die;
3913 register enum dwarf_attribute attr_kind;
3915 register dw_attr_ref *p;
3916 register dw_attr_ref removed = NULL;
3918 if (die != NULL)
3920 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next))
3921 if ((*p)->dw_attr == attr_kind)
3923 removed = *p;
3924 *p = (*p)->dw_attr_next;
3925 break;
3928 if (removed != 0)
3929 free_AT (removed);
3933 /* Free up the memory used by DIE. */
3935 static inline void
3936 free_die (die)
3937 dw_die_ref die;
3939 remove_children (die);
3940 free (die);
3943 /* Discard the children of this DIE. */
3945 static void
3946 remove_children (die)
3947 register dw_die_ref die;
3949 register dw_die_ref child_die = die->die_child;
3951 die->die_child = NULL;
3953 while (child_die != NULL)
3955 register dw_die_ref tmp_die = child_die;
3956 register dw_attr_ref a;
3958 child_die = child_die->die_sib;
3960 for (a = tmp_die->die_attr; a != NULL; )
3962 register dw_attr_ref tmp_a = a;
3964 a = a->dw_attr_next;
3965 free_AT (tmp_a);
3968 free_die (tmp_die);
3972 /* Add a child DIE below its parent. We build the lists up in reverse
3973 addition order, and correct that in add_sibling_attributes. */
3975 static inline void
3976 add_child_die (die, child_die)
3977 register dw_die_ref die;
3978 register dw_die_ref child_die;
3980 if (die != NULL && child_die != NULL)
3982 if (die == child_die)
3983 abort ();
3984 child_die->die_parent = die;
3985 child_die->die_sib = die->die_child;
3986 die->die_child = child_die;
3990 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
3991 is the specification, to the front of PARENT's list of children. */
3993 static void
3994 splice_child_die (parent, child)
3995 dw_die_ref parent, child;
3997 dw_die_ref *p;
3999 /* We want the declaration DIE from inside the class, not the
4000 specification DIE at toplevel. */
4001 if (child->die_parent != parent)
4003 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification);
4004 if (tmp)
4005 child = tmp;
4008 if (child->die_parent != parent
4009 && child->die_parent != get_AT_ref (parent, DW_AT_specification))
4010 abort ();
4012 for (p = &(parent->die_child); *p; p = &((*p)->die_sib))
4013 if (*p == child)
4015 *p = child->die_sib;
4016 break;
4019 child->die_sib = parent->die_child;
4020 parent->die_child = child;
4023 /* Return a pointer to a newly created DIE node. */
4025 static inline dw_die_ref
4026 new_die (tag_value, parent_die)
4027 register enum dwarf_tag tag_value;
4028 register dw_die_ref parent_die;
4030 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4032 die->die_tag = tag_value;
4033 die->die_abbrev = 0;
4034 die->die_offset = 0;
4035 die->die_child = NULL;
4036 die->die_parent = NULL;
4037 die->die_sib = NULL;
4038 die->die_attr = NULL;
4040 if (parent_die != NULL)
4041 add_child_die (parent_die, die);
4042 else
4044 limbo_die_node *limbo_node;
4046 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4047 limbo_node->die = die;
4048 limbo_node->next = limbo_die_list;
4049 limbo_die_list = limbo_node;
4052 return die;
4055 /* Return the DIE associated with the given type specifier. */
4057 static inline dw_die_ref
4058 lookup_type_die (type)
4059 register tree type;
4061 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4064 /* Equate a DIE to a given type specifier. */
4066 static inline void
4067 equate_type_number_to_die (type, type_die)
4068 register tree type;
4069 register dw_die_ref type_die;
4071 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4074 /* Return the DIE associated with a given declaration. */
4076 static inline dw_die_ref
4077 lookup_decl_die (decl)
4078 register tree decl;
4080 register unsigned decl_id = DECL_UID (decl);
4082 return (decl_id < decl_die_table_in_use
4083 ? decl_die_table[decl_id] : NULL);
4086 /* Equate a DIE to a particular declaration. */
4088 static void
4089 equate_decl_number_to_die (decl, decl_die)
4090 register tree decl;
4091 register dw_die_ref decl_die;
4093 register unsigned decl_id = DECL_UID (decl);
4094 register unsigned num_allocated;
4096 if (decl_id >= decl_die_table_allocated)
4098 num_allocated
4099 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4100 / DECL_DIE_TABLE_INCREMENT)
4101 * DECL_DIE_TABLE_INCREMENT;
4103 decl_die_table
4104 = (dw_die_ref *) xrealloc (decl_die_table,
4105 sizeof (dw_die_ref) * num_allocated);
4107 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4108 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4109 decl_die_table_allocated = num_allocated;
4112 if (decl_id >= decl_die_table_in_use)
4113 decl_die_table_in_use = (decl_id + 1);
4115 decl_die_table[decl_id] = decl_die;
4118 /* Return a pointer to a newly allocated location description. Location
4119 descriptions are simple expression terms that can be strung
4120 together to form more complicated location (address) descriptions. */
4122 static inline dw_loc_descr_ref
4123 new_loc_descr (op, oprnd1, oprnd2)
4124 register enum dwarf_location_atom op;
4125 register unsigned long oprnd1;
4126 register unsigned long oprnd2;
4128 register dw_loc_descr_ref descr
4129 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4131 descr->dw_loc_next = NULL;
4132 descr->dw_loc_opc = op;
4133 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4134 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4135 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4136 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4138 return descr;
4141 /* Add a location description term to a location description expression. */
4143 static inline void
4144 add_loc_descr (list_head, descr)
4145 register dw_loc_descr_ref *list_head;
4146 register dw_loc_descr_ref descr;
4148 register dw_loc_descr_ref *d;
4150 /* Find the end of the chain. */
4151 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4154 *d = descr;
4157 /* Keep track of the number of spaces used to indent the
4158 output of the debugging routines that print the structure of
4159 the DIE internal representation. */
4160 static int print_indent;
4162 /* Indent the line the number of spaces given by print_indent. */
4164 static inline void
4165 print_spaces (outfile)
4166 FILE *outfile;
4168 fprintf (outfile, "%*s", print_indent, "");
4171 /* Print the information associated with a given DIE, and its children.
4172 This routine is a debugging aid only. */
4174 static void
4175 print_die (die, outfile)
4176 dw_die_ref die;
4177 FILE *outfile;
4179 register dw_attr_ref a;
4180 register dw_die_ref c;
4182 print_spaces (outfile);
4183 fprintf (outfile, "DIE %4lu: %s\n",
4184 die->die_offset, dwarf_tag_name (die->die_tag));
4185 print_spaces (outfile);
4186 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4187 fprintf (outfile, " offset: %lu\n", die->die_offset);
4189 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4191 print_spaces (outfile);
4192 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4194 switch (AT_class (a))
4196 case dw_val_class_addr:
4197 fprintf (outfile, "address");
4198 break;
4199 case dw_val_class_loc:
4200 fprintf (outfile, "location descriptor");
4201 break;
4202 case dw_val_class_const:
4203 fprintf (outfile, "%ld", AT_int (a));
4204 break;
4205 case dw_val_class_unsigned_const:
4206 fprintf (outfile, "%lu", AT_unsigned (a));
4207 break;
4208 case dw_val_class_long_long:
4209 fprintf (outfile, "constant (%lu,%lu)",
4210 a->dw_attr_val.v.val_long_long.hi,
4211 a->dw_attr_val.v.val_long_long.low);
4212 break;
4213 case dw_val_class_float:
4214 fprintf (outfile, "floating-point constant");
4215 break;
4216 case dw_val_class_flag:
4217 fprintf (outfile, "%u", AT_flag (a));
4218 break;
4219 case dw_val_class_die_ref:
4220 if (AT_ref (a) != NULL)
4221 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
4222 else
4223 fprintf (outfile, "die -> <null>");
4224 break;
4225 case dw_val_class_lbl_id:
4226 case dw_val_class_lbl_offset:
4227 fprintf (outfile, "label: %s", AT_lbl (a));
4228 break;
4229 case dw_val_class_str:
4230 if (AT_string (a) != NULL)
4231 fprintf (outfile, "\"%s\"", AT_string (a));
4232 else
4233 fprintf (outfile, "<null>");
4234 break;
4235 default:
4236 break;
4239 fprintf (outfile, "\n");
4242 if (die->die_child != NULL)
4244 print_indent += 4;
4245 for (c = die->die_child; c != NULL; c = c->die_sib)
4246 print_die (c, outfile);
4248 print_indent -= 4;
4252 /* Print the contents of the source code line number correspondence table.
4253 This routine is a debugging aid only. */
4255 static void
4256 print_dwarf_line_table (outfile)
4257 FILE *outfile;
4259 register unsigned i;
4260 register dw_line_info_ref line_info;
4262 fprintf (outfile, "\n\nDWARF source line information\n");
4263 for (i = 1; i < line_info_table_in_use; ++i)
4265 line_info = &line_info_table[i];
4266 fprintf (outfile, "%5d: ", i);
4267 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4268 fprintf (outfile, "%6ld", line_info->dw_line_num);
4269 fprintf (outfile, "\n");
4272 fprintf (outfile, "\n\n");
4275 /* Print the information collected for a given DIE. */
4277 void
4278 debug_dwarf_die (die)
4279 dw_die_ref die;
4281 print_die (die, stderr);
4284 /* Print all DWARF information collected for the compilation unit.
4285 This routine is a debugging aid only. */
4287 void
4288 debug_dwarf ()
4290 print_indent = 0;
4291 print_die (comp_unit_die, stderr);
4292 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4293 print_dwarf_line_table (stderr);
4296 /* We build up the lists of children and attributes by pushing new ones
4297 onto the beginning of the list. Reverse the lists for DIE so that
4298 they are in order of addition. */
4300 static void
4301 reverse_die_lists (die)
4302 register dw_die_ref die;
4304 register dw_die_ref c, cp, cn;
4305 register dw_attr_ref a, ap, an;
4307 for (a = die->die_attr, ap = 0; a; a = an)
4309 an = a->dw_attr_next;
4310 a->dw_attr_next = ap;
4311 ap = a;
4313 die->die_attr = ap;
4315 for (c = die->die_child, cp = 0; c; c = cn)
4317 cn = c->die_sib;
4318 c->die_sib = cp;
4319 cp = c;
4321 die->die_child = cp;
4324 /* Traverse the DIE, reverse its lists of attributes and children, and
4325 add a sibling attribute if it may have the effect of speeding up
4326 access to siblings. To save some space, avoid generating sibling
4327 attributes for DIE's without children. */
4329 static void
4330 add_sibling_attributes (die)
4331 register dw_die_ref die;
4333 register dw_die_ref c;
4335 reverse_die_lists (die);
4337 if (die != comp_unit_die && die->die_sib && die->die_child != NULL)
4338 /* Add the sibling link to the front of the attribute list. */
4339 add_AT_die_ref (die, DW_AT_sibling, die->die_sib);
4341 for (c = die->die_child; c != NULL; c = c->die_sib)
4342 add_sibling_attributes (c);
4345 /* The format of each DIE (and its attribute value pairs)
4346 is encoded in an abbreviation table. This routine builds the
4347 abbreviation table and assigns a unique abbreviation id for
4348 each abbreviation entry. The children of each die are visited
4349 recursively. */
4351 static void
4352 build_abbrev_table (die)
4353 register dw_die_ref die;
4355 register unsigned long abbrev_id;
4356 register unsigned long n_alloc;
4357 register dw_die_ref c;
4358 register dw_attr_ref d_attr, a_attr;
4359 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4361 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4363 if (abbrev->die_tag == die->die_tag)
4365 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4367 a_attr = abbrev->die_attr;
4368 d_attr = die->die_attr;
4370 while (a_attr != NULL && d_attr != NULL)
4372 if ((a_attr->dw_attr != d_attr->dw_attr)
4373 || (value_format (a_attr) != value_format (d_attr)))
4374 break;
4376 a_attr = a_attr->dw_attr_next;
4377 d_attr = d_attr->dw_attr_next;
4380 if (a_attr == NULL && d_attr == NULL)
4381 break;
4386 if (abbrev_id >= abbrev_die_table_in_use)
4388 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4390 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4391 abbrev_die_table
4392 = (dw_die_ref *) xrealloc (abbrev_die_table,
4393 sizeof (dw_die_ref) * n_alloc);
4395 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4396 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4397 abbrev_die_table_allocated = n_alloc;
4400 ++abbrev_die_table_in_use;
4401 abbrev_die_table[abbrev_id] = die;
4404 die->die_abbrev = abbrev_id;
4405 for (c = die->die_child; c != NULL; c = c->die_sib)
4406 build_abbrev_table (c);
4409 /* Return the size of a string, including the null byte.
4411 This used to treat backslashes as escapes, and hence they were not included
4412 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4413 which treats a backslash as a backslash, escaping it if necessary, and hence
4414 we must include them in the count. */
4416 static unsigned long
4417 size_of_string (str)
4418 register const char *str;
4420 return strlen (str) + 1;
4423 /* Return the size of a location descriptor. */
4425 static unsigned long
4426 size_of_loc_descr (loc)
4427 register dw_loc_descr_ref loc;
4429 register unsigned long size = 1;
4431 switch (loc->dw_loc_opc)
4433 case DW_OP_addr:
4434 size += PTR_SIZE;
4435 break;
4436 case DW_OP_const1u:
4437 case DW_OP_const1s:
4438 size += 1;
4439 break;
4440 case DW_OP_const2u:
4441 case DW_OP_const2s:
4442 size += 2;
4443 break;
4444 case DW_OP_const4u:
4445 case DW_OP_const4s:
4446 size += 4;
4447 break;
4448 case DW_OP_const8u:
4449 case DW_OP_const8s:
4450 size += 8;
4451 break;
4452 case DW_OP_constu:
4453 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4454 break;
4455 case DW_OP_consts:
4456 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4457 break;
4458 case DW_OP_pick:
4459 size += 1;
4460 break;
4461 case DW_OP_plus_uconst:
4462 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4463 break;
4464 case DW_OP_skip:
4465 case DW_OP_bra:
4466 size += 2;
4467 break;
4468 case DW_OP_breg0:
4469 case DW_OP_breg1:
4470 case DW_OP_breg2:
4471 case DW_OP_breg3:
4472 case DW_OP_breg4:
4473 case DW_OP_breg5:
4474 case DW_OP_breg6:
4475 case DW_OP_breg7:
4476 case DW_OP_breg8:
4477 case DW_OP_breg9:
4478 case DW_OP_breg10:
4479 case DW_OP_breg11:
4480 case DW_OP_breg12:
4481 case DW_OP_breg13:
4482 case DW_OP_breg14:
4483 case DW_OP_breg15:
4484 case DW_OP_breg16:
4485 case DW_OP_breg17:
4486 case DW_OP_breg18:
4487 case DW_OP_breg19:
4488 case DW_OP_breg20:
4489 case DW_OP_breg21:
4490 case DW_OP_breg22:
4491 case DW_OP_breg23:
4492 case DW_OP_breg24:
4493 case DW_OP_breg25:
4494 case DW_OP_breg26:
4495 case DW_OP_breg27:
4496 case DW_OP_breg28:
4497 case DW_OP_breg29:
4498 case DW_OP_breg30:
4499 case DW_OP_breg31:
4500 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4501 break;
4502 case DW_OP_regx:
4503 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4504 break;
4505 case DW_OP_fbreg:
4506 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4507 break;
4508 case DW_OP_bregx:
4509 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4510 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4511 break;
4512 case DW_OP_piece:
4513 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4514 break;
4515 case DW_OP_deref_size:
4516 case DW_OP_xderef_size:
4517 size += 1;
4518 break;
4519 default:
4520 break;
4523 return size;
4526 /* Return the size of a series of location descriptors. */
4528 static unsigned long
4529 size_of_locs (loc)
4530 register dw_loc_descr_ref loc;
4532 register unsigned long size = 0;
4534 for (; loc != NULL; loc = loc->dw_loc_next)
4535 size += size_of_loc_descr (loc);
4537 return size;
4540 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4542 static int
4543 constant_size (value)
4544 long unsigned value;
4546 int log;
4548 if (value == 0)
4549 log = 0;
4550 else
4551 log = floor_log2 (value);
4553 log = log / 8;
4554 log = 1 << (floor_log2 (log) + 1);
4556 return log;
4559 /* Return the size of a DIE, as it is represented in the
4560 .debug_info section. */
4562 static unsigned long
4563 size_of_die (die)
4564 register dw_die_ref die;
4566 register unsigned long size = 0;
4567 register dw_attr_ref a;
4569 size += size_of_uleb128 (die->die_abbrev);
4570 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4572 switch (AT_class (a))
4574 case dw_val_class_addr:
4575 size += PTR_SIZE;
4576 break;
4577 case dw_val_class_loc:
4579 register unsigned long lsize = size_of_locs (AT_loc (a));
4581 /* Block length. */
4582 size += constant_size (lsize);
4583 size += lsize;
4585 break;
4586 case dw_val_class_const:
4587 size += 4;
4588 break;
4589 case dw_val_class_unsigned_const:
4590 size += constant_size (AT_unsigned (a));
4591 break;
4592 case dw_val_class_long_long:
4593 size += 1 + 8; /* block */
4594 break;
4595 case dw_val_class_float:
4596 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4597 break;
4598 case dw_val_class_flag:
4599 size += 1;
4600 break;
4601 case dw_val_class_die_ref:
4602 size += DWARF_OFFSET_SIZE;
4603 break;
4604 case dw_val_class_fde_ref:
4605 size += DWARF_OFFSET_SIZE;
4606 break;
4607 case dw_val_class_lbl_id:
4608 size += PTR_SIZE;
4609 break;
4610 case dw_val_class_lbl_offset:
4611 size += DWARF_OFFSET_SIZE;
4612 break;
4613 case dw_val_class_str:
4614 size += size_of_string (AT_string (a));
4615 break;
4616 default:
4617 abort ();
4621 return size;
4624 /* Size the debugging information associated with a given DIE.
4625 Visits the DIE's children recursively. Updates the global
4626 variable next_die_offset, on each time through. Uses the
4627 current value of next_die_offset to update the die_offset
4628 field in each DIE. */
4630 static void
4631 calc_die_sizes (die)
4632 dw_die_ref die;
4634 register dw_die_ref c;
4635 die->die_offset = next_die_offset;
4636 next_die_offset += size_of_die (die);
4638 for (c = die->die_child; c != NULL; c = c->die_sib)
4639 calc_die_sizes (c);
4641 if (die->die_child != NULL)
4642 /* Count the null byte used to terminate sibling lists. */
4643 next_die_offset += 1;
4646 /* Return the size of the line information prolog generated for the
4647 compilation unit. */
4649 static unsigned long
4650 size_of_line_prolog ()
4652 register unsigned long size;
4653 register unsigned long ft_index;
4655 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4657 /* Count the size of the table giving number of args for each
4658 standard opcode. */
4659 size += DWARF_LINE_OPCODE_BASE - 1;
4661 /* Include directory table is empty (at present). Count only the
4662 null byte used to terminate the table. */
4663 size += 1;
4665 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4667 /* File name entry. */
4668 size += size_of_string (file_table[ft_index]);
4670 /* Include directory index. */
4671 size += size_of_uleb128 (0);
4673 /* Modification time. */
4674 size += size_of_uleb128 (0);
4676 /* File length in bytes. */
4677 size += size_of_uleb128 (0);
4680 /* Count the file table terminator. */
4681 size += 1;
4682 return size;
4685 /* Return the size of the .debug_pubnames table generated for the
4686 compilation unit. */
4688 static unsigned long
4689 size_of_pubnames ()
4691 register unsigned long size;
4692 register unsigned i;
4694 size = DWARF_PUBNAMES_HEADER_SIZE;
4695 for (i = 0; i < pubname_table_in_use; ++i)
4697 register pubname_ref p = &pubname_table[i];
4698 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4701 size += DWARF_OFFSET_SIZE;
4702 return size;
4705 /* Return the size of the information in the .debug_aranges section. */
4707 static unsigned long
4708 size_of_aranges ()
4710 register unsigned long size;
4712 size = DWARF_ARANGES_HEADER_SIZE;
4714 /* Count the address/length pair for this compilation unit. */
4715 size += 2 * PTR_SIZE;
4716 size += 2 * PTR_SIZE * arange_table_in_use;
4718 /* Count the two zero words used to terminated the address range table. */
4719 size += 2 * PTR_SIZE;
4720 return size;
4723 /* Select the encoding of an attribute value. */
4725 static enum dwarf_form
4726 value_format (a)
4727 dw_attr_ref a;
4729 switch (a->dw_attr_val.val_class)
4731 case dw_val_class_addr:
4732 return DW_FORM_addr;
4733 case dw_val_class_loc:
4734 switch (constant_size (size_of_locs (AT_loc (a))))
4736 case 1:
4737 return DW_FORM_block1;
4738 case 2:
4739 return DW_FORM_block2;
4740 default:
4741 abort ();
4743 case dw_val_class_const:
4744 return DW_FORM_data4;
4745 case dw_val_class_unsigned_const:
4746 switch (constant_size (AT_unsigned (a)))
4748 case 1:
4749 return DW_FORM_data1;
4750 case 2:
4751 return DW_FORM_data2;
4752 case 4:
4753 return DW_FORM_data4;
4754 case 8:
4755 return DW_FORM_data8;
4756 default:
4757 abort ();
4759 case dw_val_class_long_long:
4760 return DW_FORM_block1;
4761 case dw_val_class_float:
4762 return DW_FORM_block1;
4763 case dw_val_class_flag:
4764 return DW_FORM_flag;
4765 case dw_val_class_die_ref:
4766 return DW_FORM_ref;
4767 case dw_val_class_fde_ref:
4768 return DW_FORM_data;
4769 case dw_val_class_lbl_id:
4770 return DW_FORM_addr;
4771 case dw_val_class_lbl_offset:
4772 return DW_FORM_data;
4773 case dw_val_class_str:
4774 return DW_FORM_string;
4775 default:
4776 abort ();
4780 /* Output the encoding of an attribute value. */
4782 static void
4783 output_value_format (a)
4784 dw_attr_ref a;
4786 enum dwarf_form form = value_format (a);
4788 output_uleb128 (form);
4789 if (flag_debug_asm)
4790 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4792 fputc ('\n', asm_out_file);
4795 /* Output the .debug_abbrev section which defines the DIE abbreviation
4796 table. */
4798 static void
4799 output_abbrev_section ()
4801 unsigned long abbrev_id;
4803 dw_attr_ref a_attr;
4804 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4806 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4808 output_uleb128 (abbrev_id);
4809 if (flag_debug_asm)
4810 fprintf (asm_out_file, " (abbrev code)");
4812 fputc ('\n', asm_out_file);
4813 output_uleb128 (abbrev->die_tag);
4814 if (flag_debug_asm)
4815 fprintf (asm_out_file, " (TAG: %s)",
4816 dwarf_tag_name (abbrev->die_tag));
4818 fputc ('\n', asm_out_file);
4819 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4820 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4822 if (flag_debug_asm)
4823 fprintf (asm_out_file, "\t%s %s",
4824 ASM_COMMENT_START,
4825 (abbrev->die_child != NULL
4826 ? "DW_children_yes" : "DW_children_no"));
4828 fputc ('\n', asm_out_file);
4830 for (a_attr = abbrev->die_attr; a_attr != NULL;
4831 a_attr = a_attr->dw_attr_next)
4833 output_uleb128 (a_attr->dw_attr);
4834 if (flag_debug_asm)
4835 fprintf (asm_out_file, " (%s)",
4836 dwarf_attr_name (a_attr->dw_attr));
4838 fputc ('\n', asm_out_file);
4839 output_value_format (a_attr);
4842 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4845 /* Terminate the table. */
4846 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4849 /* Output location description stack opcode's operands (if any). */
4851 static void
4852 output_loc_operands (loc)
4853 register dw_loc_descr_ref loc;
4855 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4856 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4858 switch (loc->dw_loc_opc)
4860 case DW_OP_addr:
4861 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4862 fputc ('\n', asm_out_file);
4863 break;
4864 case DW_OP_const1u:
4865 case DW_OP_const1s:
4866 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4867 fputc ('\n', asm_out_file);
4868 break;
4869 case DW_OP_const2u:
4870 case DW_OP_const2s:
4871 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4872 fputc ('\n', asm_out_file);
4873 break;
4874 case DW_OP_const4u:
4875 case DW_OP_const4s:
4876 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4877 fputc ('\n', asm_out_file);
4878 break;
4879 case DW_OP_const8u:
4880 case DW_OP_const8s:
4881 abort ();
4882 fputc ('\n', asm_out_file);
4883 break;
4884 case DW_OP_constu:
4885 output_uleb128 (val1->v.val_unsigned);
4886 fputc ('\n', asm_out_file);
4887 break;
4888 case DW_OP_consts:
4889 output_sleb128 (val1->v.val_int);
4890 fputc ('\n', asm_out_file);
4891 break;
4892 case DW_OP_pick:
4893 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4894 fputc ('\n', asm_out_file);
4895 break;
4896 case DW_OP_plus_uconst:
4897 output_uleb128 (val1->v.val_unsigned);
4898 fputc ('\n', asm_out_file);
4899 break;
4900 case DW_OP_skip:
4901 case DW_OP_bra:
4902 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4903 fputc ('\n', asm_out_file);
4904 break;
4905 case DW_OP_breg0:
4906 case DW_OP_breg1:
4907 case DW_OP_breg2:
4908 case DW_OP_breg3:
4909 case DW_OP_breg4:
4910 case DW_OP_breg5:
4911 case DW_OP_breg6:
4912 case DW_OP_breg7:
4913 case DW_OP_breg8:
4914 case DW_OP_breg9:
4915 case DW_OP_breg10:
4916 case DW_OP_breg11:
4917 case DW_OP_breg12:
4918 case DW_OP_breg13:
4919 case DW_OP_breg14:
4920 case DW_OP_breg15:
4921 case DW_OP_breg16:
4922 case DW_OP_breg17:
4923 case DW_OP_breg18:
4924 case DW_OP_breg19:
4925 case DW_OP_breg20:
4926 case DW_OP_breg21:
4927 case DW_OP_breg22:
4928 case DW_OP_breg23:
4929 case DW_OP_breg24:
4930 case DW_OP_breg25:
4931 case DW_OP_breg26:
4932 case DW_OP_breg27:
4933 case DW_OP_breg28:
4934 case DW_OP_breg29:
4935 case DW_OP_breg30:
4936 case DW_OP_breg31:
4937 output_sleb128 (val1->v.val_int);
4938 fputc ('\n', asm_out_file);
4939 break;
4940 case DW_OP_regx:
4941 output_uleb128 (val1->v.val_unsigned);
4942 fputc ('\n', asm_out_file);
4943 break;
4944 case DW_OP_fbreg:
4945 output_sleb128 (val1->v.val_int);
4946 fputc ('\n', asm_out_file);
4947 break;
4948 case DW_OP_bregx:
4949 output_uleb128 (val1->v.val_unsigned);
4950 fputc ('\n', asm_out_file);
4951 output_sleb128 (val2->v.val_int);
4952 fputc ('\n', asm_out_file);
4953 break;
4954 case DW_OP_piece:
4955 output_uleb128 (val1->v.val_unsigned);
4956 fputc ('\n', asm_out_file);
4957 break;
4958 case DW_OP_deref_size:
4959 case DW_OP_xderef_size:
4960 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4961 fputc ('\n', asm_out_file);
4962 break;
4963 default:
4964 break;
4968 /* Output the DIE and its attributes. Called recursively to generate
4969 the definitions of each child DIE. */
4971 static void
4972 output_die (die)
4973 register dw_die_ref die;
4975 register dw_attr_ref a;
4976 register dw_die_ref c;
4977 register unsigned long size;
4978 register dw_loc_descr_ref loc;
4980 output_uleb128 (die->die_abbrev);
4981 if (flag_debug_asm)
4982 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
4983 die->die_offset, dwarf_tag_name (die->die_tag));
4985 fputc ('\n', asm_out_file);
4987 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4989 switch (AT_class (a))
4991 case dw_val_class_addr:
4992 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, AT_addr (a));
4993 break;
4995 case dw_val_class_loc:
4996 size = size_of_locs (AT_loc (a));
4998 /* Output the block length for this list of location operations. */
4999 switch (constant_size (size))
5001 case 1:
5002 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5003 break;
5004 case 2:
5005 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5006 break;
5007 default:
5008 abort ();
5011 if (flag_debug_asm)
5012 fprintf (asm_out_file, "\t%s %s",
5013 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5015 fputc ('\n', asm_out_file);
5016 for (loc = AT_loc (a); loc != NULL; loc = loc->dw_loc_next)
5018 /* Output the opcode. */
5019 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5020 if (flag_debug_asm)
5021 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5022 dwarf_stack_op_name (loc->dw_loc_opc));
5024 fputc ('\n', asm_out_file);
5026 /* Output the operand(s) (if any). */
5027 output_loc_operands (loc);
5029 break;
5031 case dw_val_class_const:
5032 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_int (a));
5033 break;
5035 case dw_val_class_unsigned_const:
5036 switch (constant_size (AT_unsigned (a)))
5038 case 1:
5039 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_unsigned (a));
5040 break;
5041 case 2:
5042 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, AT_unsigned (a));
5043 break;
5044 case 4:
5045 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, AT_unsigned (a));
5046 break;
5047 case 8:
5048 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5049 a->dw_attr_val.v.val_long_long.hi,
5050 a->dw_attr_val.v.val_long_long.low);
5051 break;
5052 default:
5053 abort ();
5055 break;
5057 case dw_val_class_long_long:
5058 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5059 if (flag_debug_asm)
5060 fprintf (asm_out_file, "\t%s %s",
5061 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5063 fputc ('\n', asm_out_file);
5064 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5065 a->dw_attr_val.v.val_long_long.hi,
5066 a->dw_attr_val.v.val_long_long.low);
5068 if (flag_debug_asm)
5069 fprintf (asm_out_file,
5070 "\t%s long long constant", ASM_COMMENT_START);
5072 fputc ('\n', asm_out_file);
5073 break;
5075 case dw_val_class_float:
5077 register unsigned int i;
5078 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5079 a->dw_attr_val.v.val_float.length * 4);
5080 if (flag_debug_asm)
5081 fprintf (asm_out_file, "\t%s %s",
5082 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5084 fputc ('\n', asm_out_file);
5085 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5087 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5088 a->dw_attr_val.v.val_float.array[i]);
5089 if (flag_debug_asm)
5090 fprintf (asm_out_file, "\t%s fp constant word %u",
5091 ASM_COMMENT_START, i);
5093 fputc ('\n', asm_out_file);
5095 break;
5098 case dw_val_class_flag:
5099 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, AT_flag (a));
5100 break;
5102 case dw_val_class_die_ref:
5103 ASM_OUTPUT_DWARF_DATA (asm_out_file, AT_ref (a)->die_offset);
5104 break;
5106 case dw_val_class_fde_ref:
5108 char l1[20];
5109 ASM_GENERATE_INTERNAL_LABEL
5110 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5111 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5112 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5114 break;
5116 case dw_val_class_lbl_id:
5117 ASM_OUTPUT_DWARF_ADDR (asm_out_file, AT_lbl (a));
5118 break;
5120 case dw_val_class_lbl_offset:
5121 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, AT_lbl (a));
5122 break;
5124 case dw_val_class_str:
5125 if (flag_debug_asm)
5126 ASM_OUTPUT_DWARF_STRING (asm_out_file, AT_string (a));
5127 else
5128 ASM_OUTPUT_ASCII (asm_out_file, AT_string (a),
5129 (int) strlen (AT_string (a)) + 1);
5130 break;
5132 default:
5133 abort ();
5136 if (AT_class (a) != dw_val_class_loc
5137 && AT_class (a) != dw_val_class_long_long
5138 && AT_class (a) != dw_val_class_float)
5140 if (flag_debug_asm)
5141 fprintf (asm_out_file, "\t%s %s",
5142 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5144 fputc ('\n', asm_out_file);
5148 for (c = die->die_child; c != NULL; c = c->die_sib)
5149 output_die (c);
5151 if (die->die_child != NULL)
5153 /* Add null byte to terminate sibling list. */
5154 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5155 if (flag_debug_asm)
5156 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5157 ASM_COMMENT_START, die->die_offset);
5159 fputc ('\n', asm_out_file);
5163 /* Output the compilation unit that appears at the beginning of the
5164 .debug_info section, and precedes the DIE descriptions. */
5166 static void
5167 output_compilation_unit_header ()
5169 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5170 if (flag_debug_asm)
5171 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5172 ASM_COMMENT_START);
5174 fputc ('\n', asm_out_file);
5175 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5176 if (flag_debug_asm)
5177 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5179 fputc ('\n', asm_out_file);
5180 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5181 if (flag_debug_asm)
5182 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5183 ASM_COMMENT_START);
5185 fputc ('\n', asm_out_file);
5186 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5187 if (flag_debug_asm)
5188 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5190 fputc ('\n', asm_out_file);
5193 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5194 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5195 argument list, and maybe the scope. */
5197 static const char *
5198 dwarf2_name (decl, scope)
5199 tree decl;
5200 int scope;
5202 return (*decl_printable_name) (decl, scope ? 1 : 0);
5205 /* Add a new entry to .debug_pubnames if appropriate. */
5207 static void
5208 add_pubname (decl, die)
5209 tree decl;
5210 dw_die_ref die;
5212 pubname_ref p;
5214 if (! TREE_PUBLIC (decl))
5215 return;
5217 if (pubname_table_in_use == pubname_table_allocated)
5219 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5220 pubname_table = (pubname_ref) xrealloc
5221 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5224 p = &pubname_table[pubname_table_in_use++];
5225 p->die = die;
5227 p->name = xstrdup (dwarf2_name (decl, 1));
5230 /* Output the public names table used to speed up access to externally
5231 visible names. For now, only generate entries for externally
5232 visible procedures. */
5234 static void
5235 output_pubnames ()
5237 register unsigned i;
5238 register unsigned long pubnames_length = size_of_pubnames ();
5240 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5242 if (flag_debug_asm)
5243 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5244 ASM_COMMENT_START);
5246 fputc ('\n', asm_out_file);
5247 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5249 if (flag_debug_asm)
5250 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5252 fputc ('\n', asm_out_file);
5253 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5254 if (flag_debug_asm)
5255 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5256 ASM_COMMENT_START);
5258 fputc ('\n', asm_out_file);
5259 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset);
5260 if (flag_debug_asm)
5261 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5263 fputc ('\n', asm_out_file);
5264 for (i = 0; i < pubname_table_in_use; ++i)
5266 register pubname_ref pub = &pubname_table[i];
5268 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5269 if (flag_debug_asm)
5270 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5272 fputc ('\n', asm_out_file);
5274 if (flag_debug_asm)
5276 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5277 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5279 else
5281 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5282 (int) strlen (pub->name) + 1);
5285 fputc ('\n', asm_out_file);
5288 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5289 fputc ('\n', asm_out_file);
5292 /* Add a new entry to .debug_aranges if appropriate. */
5294 static void
5295 add_arange (decl, die)
5296 tree decl;
5297 dw_die_ref die;
5299 if (! DECL_SECTION_NAME (decl))
5300 return;
5302 if (arange_table_in_use == arange_table_allocated)
5304 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5305 arange_table
5306 = (arange_ref) xrealloc (arange_table,
5307 arange_table_allocated * sizeof (dw_die_ref));
5310 arange_table[arange_table_in_use++] = die;
5313 /* Output the information that goes into the .debug_aranges table.
5314 Namely, define the beginning and ending address range of the
5315 text section generated for this compilation unit. */
5317 static void
5318 output_aranges ()
5320 register unsigned i;
5321 register unsigned long aranges_length = size_of_aranges ();
5323 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5324 if (flag_debug_asm)
5325 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5326 ASM_COMMENT_START);
5328 fputc ('\n', asm_out_file);
5329 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5330 if (flag_debug_asm)
5331 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5333 fputc ('\n', asm_out_file);
5334 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5335 if (flag_debug_asm)
5336 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5337 ASM_COMMENT_START);
5339 fputc ('\n', asm_out_file);
5340 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5341 if (flag_debug_asm)
5342 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5344 fputc ('\n', asm_out_file);
5345 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5346 if (flag_debug_asm)
5347 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5348 ASM_COMMENT_START);
5350 fputc ('\n', asm_out_file);
5351 /* We need to align to twice the pointer size here.
5352 If DWARF_OFFSET_SIZE == 4, then we have emitted 12 bytes, and need 4
5353 bytes of padding to align for either 4 or 8 byte pointers. */
5354 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5355 /* If DWARF_OFFSET_SIZE == 8, then we have emitted 20 bytes, and need 12
5356 bytes of padding to align for 8 byte pointers. We have already emitted
5357 4 bytes of padding, so emit 8 more here. */
5358 if (DWARF_OFFSET_SIZE == 8)
5359 fprintf (asm_out_file, ",0,0");
5361 if (flag_debug_asm)
5362 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5363 ASM_COMMENT_START, 2 * PTR_SIZE);
5365 fputc ('\n', asm_out_file);
5366 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5367 if (flag_debug_asm)
5368 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5370 fputc ('\n', asm_out_file);
5371 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5372 text_section_label);
5373 if (flag_debug_asm)
5374 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5376 fputc ('\n', asm_out_file);
5377 for (i = 0; i < arange_table_in_use; ++i)
5379 dw_die_ref die = arange_table[i];
5381 if (die->die_tag == DW_TAG_subprogram)
5382 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5383 else
5385 /* A static variable; extract the symbol from DW_AT_location.
5386 Note that this code isn't currently hit, as we only emit
5387 aranges for functions (jason 9/23/99). */
5389 dw_attr_ref a = get_AT (die, DW_AT_location);
5390 dw_loc_descr_ref loc;
5391 if (! a || AT_class (a) != dw_val_class_loc)
5392 abort ();
5394 loc = AT_loc (a);
5395 if (loc->dw_loc_opc != DW_OP_addr)
5396 abort ();
5398 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5399 loc->dw_loc_oprnd1.v.val_addr);
5402 if (flag_debug_asm)
5403 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5405 fputc ('\n', asm_out_file);
5406 if (die->die_tag == DW_TAG_subprogram)
5407 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5408 get_AT_low_pc (die));
5409 else
5410 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5411 get_AT_unsigned (die, DW_AT_byte_size));
5413 if (flag_debug_asm)
5414 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5416 fputc ('\n', asm_out_file);
5419 /* Output the terminator words. */
5420 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5421 fputc ('\n', asm_out_file);
5422 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5423 fputc ('\n', asm_out_file);
5426 /* Output the source line number correspondence information. This
5427 information goes into the .debug_line section. */
5429 static void
5430 output_line_info ()
5432 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5433 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5434 register unsigned opc;
5435 register unsigned n_op_args;
5436 register unsigned long ft_index;
5437 register unsigned long lt_index;
5438 register unsigned long current_line;
5439 register long line_offset;
5440 register long line_delta;
5441 register unsigned long current_file;
5442 register unsigned long function;
5444 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5445 if (flag_debug_asm)
5446 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5447 ASM_COMMENT_START);
5449 fputc ('\n', asm_out_file);
5450 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5451 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5452 if (flag_debug_asm)
5453 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5455 fputc ('\n', asm_out_file);
5456 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5457 if (flag_debug_asm)
5458 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5460 fputc ('\n', asm_out_file);
5461 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5462 if (flag_debug_asm)
5463 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5464 ASM_COMMENT_START);
5466 fputc ('\n', asm_out_file);
5467 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5468 if (flag_debug_asm)
5469 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5470 ASM_COMMENT_START);
5472 fputc ('\n', asm_out_file);
5473 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5474 if (flag_debug_asm)
5475 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5476 ASM_COMMENT_START);
5478 fputc ('\n', asm_out_file);
5479 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5480 if (flag_debug_asm)
5481 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5482 ASM_COMMENT_START);
5484 fputc ('\n', asm_out_file);
5485 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5486 if (flag_debug_asm)
5487 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5489 fputc ('\n', asm_out_file);
5490 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5492 switch (opc)
5494 case DW_LNS_advance_pc:
5495 case DW_LNS_advance_line:
5496 case DW_LNS_set_file:
5497 case DW_LNS_set_column:
5498 case DW_LNS_fixed_advance_pc:
5499 n_op_args = 1;
5500 break;
5501 default:
5502 n_op_args = 0;
5503 break;
5505 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5506 if (flag_debug_asm)
5507 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5508 ASM_COMMENT_START, opc, n_op_args);
5509 fputc ('\n', asm_out_file);
5512 if (flag_debug_asm)
5513 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5515 /* Include directory table is empty, at present */
5516 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5517 fputc ('\n', asm_out_file);
5518 if (flag_debug_asm)
5519 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5521 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5523 if (flag_debug_asm)
5525 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5526 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5527 ASM_COMMENT_START, ft_index);
5529 else
5531 ASM_OUTPUT_ASCII (asm_out_file,
5532 file_table[ft_index],
5533 (int) strlen (file_table[ft_index]) + 1);
5536 fputc ('\n', asm_out_file);
5538 /* Include directory index */
5539 output_uleb128 (0);
5540 fputc ('\n', asm_out_file);
5542 /* Modification time */
5543 output_uleb128 (0);
5544 fputc ('\n', asm_out_file);
5546 /* File length in bytes */
5547 output_uleb128 (0);
5548 fputc ('\n', asm_out_file);
5551 /* Terminate the file name table */
5552 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5553 fputc ('\n', asm_out_file);
5555 /* We used to set the address register to the first location in the text
5556 section here, but that didn't accomplish anything since we already
5557 have a line note for the opening brace of the first function. */
5559 /* Generate the line number to PC correspondence table, encoded as
5560 a series of state machine operations. */
5561 current_file = 1;
5562 current_line = 1;
5563 strcpy (prev_line_label, text_section_label);
5564 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5566 register dw_line_info_ref line_info = &line_info_table[lt_index];
5568 #if 0
5569 /* Disable this optimization for now; GDB wants to see two line notes
5570 at the beginning of a function so it can find the end of the
5571 prologue. */
5573 /* Don't emit anything for redundant notes. Just updating the
5574 address doesn't accomplish anything, because we already assume
5575 that anything after the last address is this line. */
5576 if (line_info->dw_line_num == current_line
5577 && line_info->dw_file_num == current_file)
5578 continue;
5579 #endif
5581 /* Emit debug info for the address of the current line, choosing
5582 the encoding that uses the least amount of space. */
5583 /* ??? Unfortunately, we have little choice here currently, and must
5584 always use the most general form. Gcc does not know the address
5585 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5586 dwarf2 aware assemblers at this time, so we can't use any special
5587 pseudo ops that would allow the assembler to optimally encode this for
5588 us. Many ports do have length attributes which will give an upper
5589 bound on the address range. We could perhaps use length attributes
5590 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5591 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5592 if (0)
5594 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5595 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5596 if (flag_debug_asm)
5597 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5598 ASM_COMMENT_START);
5600 fputc ('\n', asm_out_file);
5601 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5602 fputc ('\n', asm_out_file);
5604 else
5606 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5607 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5608 if (flag_debug_asm)
5609 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5610 ASM_COMMENT_START);
5611 fputc ('\n', asm_out_file);
5612 output_uleb128 (1 + PTR_SIZE);
5613 fputc ('\n', asm_out_file);
5614 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5615 fputc ('\n', asm_out_file);
5616 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5617 fputc ('\n', asm_out_file);
5619 strcpy (prev_line_label, line_label);
5621 /* Emit debug info for the source file of the current line, if
5622 different from the previous line. */
5623 if (line_info->dw_file_num != current_file)
5625 current_file = line_info->dw_file_num;
5626 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5627 if (flag_debug_asm)
5628 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5630 fputc ('\n', asm_out_file);
5631 output_uleb128 (current_file);
5632 if (flag_debug_asm)
5633 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5635 fputc ('\n', asm_out_file);
5638 /* Emit debug info for the current line number, choosing the encoding
5639 that uses the least amount of space. */
5640 if (line_info->dw_line_num != current_line)
5642 line_offset = line_info->dw_line_num - current_line;
5643 line_delta = line_offset - DWARF_LINE_BASE;
5644 current_line = line_info->dw_line_num;
5645 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5647 /* This can handle deltas from -10 to 234, using the current
5648 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5649 takes 1 byte. */
5650 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5651 DWARF_LINE_OPCODE_BASE + line_delta);
5652 if (flag_debug_asm)
5653 fprintf (asm_out_file,
5654 "\t%s line %ld", ASM_COMMENT_START, current_line);
5656 fputc ('\n', asm_out_file);
5658 else
5660 /* This can handle any delta. This takes at least 4 bytes,
5661 depending on the value being encoded. */
5662 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5663 if (flag_debug_asm)
5664 fprintf (asm_out_file, "\t%s advance to line %ld",
5665 ASM_COMMENT_START, current_line);
5667 fputc ('\n', asm_out_file);
5668 output_sleb128 (line_offset);
5669 fputc ('\n', asm_out_file);
5670 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5671 if (flag_debug_asm)
5672 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5673 fputc ('\n', asm_out_file);
5676 else
5678 /* We still need to start a new row, so output a copy insn. */
5679 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5680 if (flag_debug_asm)
5681 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5682 fputc ('\n', asm_out_file);
5686 /* Emit debug info for the address of the end of the function. */
5687 if (0)
5689 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5690 if (flag_debug_asm)
5691 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5692 ASM_COMMENT_START);
5694 fputc ('\n', asm_out_file);
5695 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5696 fputc ('\n', asm_out_file);
5698 else
5700 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5701 if (flag_debug_asm)
5702 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5703 fputc ('\n', asm_out_file);
5704 output_uleb128 (1 + PTR_SIZE);
5705 fputc ('\n', asm_out_file);
5706 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5707 fputc ('\n', asm_out_file);
5708 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5709 fputc ('\n', asm_out_file);
5712 /* Output the marker for the end of the line number info. */
5713 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5714 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5715 if (flag_debug_asm)
5716 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5718 fputc ('\n', asm_out_file);
5719 output_uleb128 (1);
5720 fputc ('\n', asm_out_file);
5721 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5722 fputc ('\n', asm_out_file);
5724 function = 0;
5725 current_file = 1;
5726 current_line = 1;
5727 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5729 register dw_separate_line_info_ref line_info
5730 = &separate_line_info_table[lt_index];
5732 #if 0
5733 /* Don't emit anything for redundant notes. */
5734 if (line_info->dw_line_num == current_line
5735 && line_info->dw_file_num == current_file
5736 && line_info->function == function)
5737 goto cont;
5738 #endif
5740 /* Emit debug info for the address of the current line. If this is
5741 a new function, or the first line of a function, then we need
5742 to handle it differently. */
5743 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5744 lt_index);
5745 if (function != line_info->function)
5747 function = line_info->function;
5749 /* Set the address register to the first line in the function */
5750 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5751 if (flag_debug_asm)
5752 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5753 ASM_COMMENT_START);
5755 fputc ('\n', asm_out_file);
5756 output_uleb128 (1 + PTR_SIZE);
5757 fputc ('\n', asm_out_file);
5758 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5759 fputc ('\n', asm_out_file);
5760 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5761 fputc ('\n', asm_out_file);
5763 else
5765 /* ??? See the DW_LNS_advance_pc comment above. */
5766 if (0)
5768 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5769 if (flag_debug_asm)
5770 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5771 ASM_COMMENT_START);
5773 fputc ('\n', asm_out_file);
5774 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5775 prev_line_label);
5776 fputc ('\n', asm_out_file);
5778 else
5780 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5781 if (flag_debug_asm)
5782 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5783 ASM_COMMENT_START);
5784 fputc ('\n', asm_out_file);
5785 output_uleb128 (1 + PTR_SIZE);
5786 fputc ('\n', asm_out_file);
5787 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5788 fputc ('\n', asm_out_file);
5789 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5790 fputc ('\n', asm_out_file);
5793 strcpy (prev_line_label, line_label);
5795 /* Emit debug info for the source file of the current line, if
5796 different from the previous line. */
5797 if (line_info->dw_file_num != current_file)
5799 current_file = line_info->dw_file_num;
5800 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5801 if (flag_debug_asm)
5802 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5804 fputc ('\n', asm_out_file);
5805 output_uleb128 (current_file);
5806 if (flag_debug_asm)
5807 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5809 fputc ('\n', asm_out_file);
5812 /* Emit debug info for the current line number, choosing the encoding
5813 that uses the least amount of space. */
5814 if (line_info->dw_line_num != current_line)
5816 line_offset = line_info->dw_line_num - current_line;
5817 line_delta = line_offset - DWARF_LINE_BASE;
5818 current_line = line_info->dw_line_num;
5819 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5821 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5822 DWARF_LINE_OPCODE_BASE + line_delta);
5823 if (flag_debug_asm)
5824 fprintf (asm_out_file,
5825 "\t%s line %ld", ASM_COMMENT_START, current_line);
5827 fputc ('\n', asm_out_file);
5829 else
5831 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5832 if (flag_debug_asm)
5833 fprintf (asm_out_file, "\t%s advance to line %ld",
5834 ASM_COMMENT_START, current_line);
5836 fputc ('\n', asm_out_file);
5837 output_sleb128 (line_offset);
5838 fputc ('\n', asm_out_file);
5839 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5840 if (flag_debug_asm)
5841 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5842 fputc ('\n', asm_out_file);
5845 else
5847 /* We still need to start a new row, so output a copy insn. */
5848 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5849 if (flag_debug_asm)
5850 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5851 fputc ('\n', asm_out_file);
5854 #if 0
5855 cont:
5856 #endif
5857 ++lt_index;
5859 /* If we're done with a function, end its sequence. */
5860 if (lt_index == separate_line_info_table_in_use
5861 || separate_line_info_table[lt_index].function != function)
5863 current_file = 1;
5864 current_line = 1;
5866 /* Emit debug info for the address of the end of the function. */
5867 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5868 if (0)
5870 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5871 if (flag_debug_asm)
5872 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5873 ASM_COMMENT_START);
5875 fputc ('\n', asm_out_file);
5876 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5877 prev_line_label);
5878 fputc ('\n', asm_out_file);
5880 else
5882 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5883 if (flag_debug_asm)
5884 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5885 ASM_COMMENT_START);
5886 fputc ('\n', asm_out_file);
5887 output_uleb128 (1 + PTR_SIZE);
5888 fputc ('\n', asm_out_file);
5889 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5890 fputc ('\n', asm_out_file);
5891 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5892 fputc ('\n', asm_out_file);
5895 /* Output the marker for the end of this sequence. */
5896 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5897 if (flag_debug_asm)
5898 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5899 ASM_COMMENT_START);
5901 fputc ('\n', asm_out_file);
5902 output_uleb128 (1);
5903 fputc ('\n', asm_out_file);
5904 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5905 fputc ('\n', asm_out_file);
5910 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5911 in question represents the outermost pair of curly braces (i.e. the "body
5912 block") of a function or method.
5914 For any BLOCK node representing a "body block" of a function or method, the
5915 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5916 represents the outermost (function) scope for the function or method (i.e.
5917 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5918 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5920 static inline int
5921 is_body_block (stmt)
5922 register tree stmt;
5924 if (TREE_CODE (stmt) == BLOCK)
5926 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5928 if (TREE_CODE (parent) == BLOCK)
5930 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
5932 if (TREE_CODE (grandparent) == FUNCTION_DECL)
5933 return 1;
5937 return 0;
5940 /* Given a pointer to a tree node for some base type, return a pointer to
5941 a DIE that describes the given type.
5943 This routine must only be called for GCC type nodes that correspond to
5944 Dwarf base (fundamental) types. */
5946 static dw_die_ref
5947 base_type_die (type)
5948 register tree type;
5950 register dw_die_ref base_type_result;
5951 register const char *type_name;
5952 register enum dwarf_type encoding;
5953 register tree name = TYPE_NAME (type);
5955 if (TREE_CODE (type) == ERROR_MARK
5956 || TREE_CODE (type) == VOID_TYPE)
5957 return 0;
5959 if (name)
5961 if (TREE_CODE (name) == TYPE_DECL)
5962 name = DECL_NAME (name);
5964 type_name = IDENTIFIER_POINTER (name);
5966 else
5967 type_name = "__unknown__";
5969 switch (TREE_CODE (type))
5971 case INTEGER_TYPE:
5972 /* Carefully distinguish the C character types, without messing
5973 up if the language is not C. Note that we check only for the names
5974 that contain spaces; other names might occur by coincidence in other
5975 languages. */
5976 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
5977 && (type == char_type_node
5978 || ! strcmp (type_name, "signed char")
5979 || ! strcmp (type_name, "unsigned char"))))
5981 if (TREE_UNSIGNED (type))
5982 encoding = DW_ATE_unsigned;
5983 else
5984 encoding = DW_ATE_signed;
5985 break;
5987 /* else fall through */
5989 case CHAR_TYPE:
5990 /* GNU Pascal/Ada CHAR type. Not used in C. */
5991 if (TREE_UNSIGNED (type))
5992 encoding = DW_ATE_unsigned_char;
5993 else
5994 encoding = DW_ATE_signed_char;
5995 break;
5997 case REAL_TYPE:
5998 encoding = DW_ATE_float;
5999 break;
6001 /* Dwarf2 doesn't know anything about complex ints, so use
6002 a user defined type for it. */
6003 case COMPLEX_TYPE:
6004 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6005 encoding = DW_ATE_complex_float;
6006 else
6007 encoding = DW_ATE_lo_user;
6008 break;
6010 case BOOLEAN_TYPE:
6011 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6012 encoding = DW_ATE_boolean;
6013 break;
6015 default:
6016 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6019 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6020 if (demangle_name_func)
6021 type_name = (*demangle_name_func) (type_name);
6023 add_AT_string (base_type_result, DW_AT_name, type_name);
6024 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6025 int_size_in_bytes (type));
6026 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6028 return base_type_result;
6031 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6032 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6033 a given type is generally the same as the given type, except that if the
6034 given type is a pointer or reference type, then the root type of the given
6035 type is the root type of the "basis" type for the pointer or reference
6036 type. (This definition of the "root" type is recursive.) Also, the root
6037 type of a `const' qualified type or a `volatile' qualified type is the
6038 root type of the given type without the qualifiers. */
6040 static tree
6041 root_type (type)
6042 register tree type;
6044 if (TREE_CODE (type) == ERROR_MARK)
6045 return error_mark_node;
6047 switch (TREE_CODE (type))
6049 case ERROR_MARK:
6050 return error_mark_node;
6052 case POINTER_TYPE:
6053 case REFERENCE_TYPE:
6054 return type_main_variant (root_type (TREE_TYPE (type)));
6056 default:
6057 return type_main_variant (type);
6061 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6062 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6064 static inline int
6065 is_base_type (type)
6066 register tree type;
6068 switch (TREE_CODE (type))
6070 case ERROR_MARK:
6071 case VOID_TYPE:
6072 case INTEGER_TYPE:
6073 case REAL_TYPE:
6074 case COMPLEX_TYPE:
6075 case BOOLEAN_TYPE:
6076 case CHAR_TYPE:
6077 return 1;
6079 case SET_TYPE:
6080 case ARRAY_TYPE:
6081 case RECORD_TYPE:
6082 case UNION_TYPE:
6083 case QUAL_UNION_TYPE:
6084 case ENUMERAL_TYPE:
6085 case FUNCTION_TYPE:
6086 case METHOD_TYPE:
6087 case POINTER_TYPE:
6088 case REFERENCE_TYPE:
6089 case FILE_TYPE:
6090 case OFFSET_TYPE:
6091 case LANG_TYPE:
6092 return 0;
6094 default:
6095 abort ();
6098 return 0;
6101 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6102 entry that chains various modifiers in front of the given type. */
6104 static dw_die_ref
6105 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6106 register tree type;
6107 register int is_const_type;
6108 register int is_volatile_type;
6109 register dw_die_ref context_die;
6111 register enum tree_code code = TREE_CODE (type);
6112 register dw_die_ref mod_type_die = NULL;
6113 register dw_die_ref sub_die = NULL;
6114 register tree item_type = NULL;
6116 if (code != ERROR_MARK)
6118 type = build_type_variant (type, is_const_type, is_volatile_type);
6120 mod_type_die = lookup_type_die (type);
6121 if (mod_type_die)
6122 return mod_type_die;
6124 /* Handle C typedef types. */
6125 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6126 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6128 tree dtype = TREE_TYPE (TYPE_NAME (type));
6129 if (type == dtype)
6131 /* For a named type, use the typedef. */
6132 gen_type_die (type, context_die);
6133 mod_type_die = lookup_type_die (type);
6136 else if (is_const_type < TYPE_READONLY (dtype)
6137 || is_volatile_type < TYPE_VOLATILE (dtype))
6138 /* cv-unqualified version of named type. Just use the unnamed
6139 type to which it refers. */
6140 mod_type_die
6141 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6142 is_const_type, is_volatile_type,
6143 context_die);
6144 /* Else cv-qualified version of named type; fall through. */
6147 if (mod_type_die)
6148 /* OK */;
6149 else if (is_const_type)
6151 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6152 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6154 else if (is_volatile_type)
6156 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6157 sub_die = modified_type_die (type, 0, 0, context_die);
6159 else if (code == POINTER_TYPE)
6161 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6162 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6163 #if 0
6164 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6165 #endif
6166 item_type = TREE_TYPE (type);
6168 else if (code == REFERENCE_TYPE)
6170 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6171 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6172 #if 0
6173 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6174 #endif
6175 item_type = TREE_TYPE (type);
6177 else if (is_base_type (type))
6178 mod_type_die = base_type_die (type);
6179 else
6181 gen_type_die (type, context_die);
6183 /* We have to get the type_main_variant here (and pass that to the
6184 `lookup_type_die' routine) because the ..._TYPE node we have
6185 might simply be a *copy* of some original type node (where the
6186 copy was created to help us keep track of typedef names) and
6187 that copy might have a different TYPE_UID from the original
6188 ..._TYPE node. */
6189 mod_type_die = lookup_type_die (type_main_variant (type));
6190 if (mod_type_die == NULL)
6191 abort ();
6195 equate_type_number_to_die (type, mod_type_die);
6196 if (item_type)
6197 /* We must do this after the equate_type_number_to_die call, in case
6198 this is a recursive type. This ensures that the modified_type_die
6199 recursion will terminate even if the type is recursive. Recursive
6200 types are possible in Ada. */
6201 sub_die = modified_type_die (item_type,
6202 TYPE_READONLY (item_type),
6203 TYPE_VOLATILE (item_type),
6204 context_die);
6206 if (sub_die != NULL)
6207 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6209 return mod_type_die;
6212 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6213 an enumerated type. */
6215 static inline int
6216 type_is_enum (type)
6217 register tree type;
6219 return TREE_CODE (type) == ENUMERAL_TYPE;
6222 /* Return a location descriptor that designates a machine register. */
6224 static dw_loc_descr_ref
6225 reg_loc_descriptor (rtl)
6226 register rtx rtl;
6228 register dw_loc_descr_ref loc_result = NULL;
6229 register unsigned reg = reg_number (rtl);
6231 if (reg <= 31)
6232 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6233 else
6234 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6236 return loc_result;
6239 /* Return a location descriptor that designates a base+offset location. */
6241 static dw_loc_descr_ref
6242 based_loc_descr (reg, offset)
6243 unsigned reg;
6244 long int offset;
6246 register dw_loc_descr_ref loc_result;
6247 /* For the "frame base", we use the frame pointer or stack pointer
6248 registers, since the RTL for local variables is relative to one of
6249 them. */
6250 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6251 ? HARD_FRAME_POINTER_REGNUM
6252 : STACK_POINTER_REGNUM);
6254 if (reg == fp_reg)
6255 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6256 else if (reg <= 31)
6257 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6258 else
6259 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6261 return loc_result;
6264 /* Return true if this RTL expression describes a base+offset calculation. */
6266 static inline int
6267 is_based_loc (rtl)
6268 register rtx rtl;
6270 return (GET_CODE (rtl) == PLUS
6271 && ((GET_CODE (XEXP (rtl, 0)) == REG
6272 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6275 /* The following routine converts the RTL for a variable or parameter
6276 (resident in memory) into an equivalent Dwarf representation of a
6277 mechanism for getting the address of that same variable onto the top of a
6278 hypothetical "address evaluation" stack.
6280 When creating memory location descriptors, we are effectively transforming
6281 the RTL for a memory-resident object into its Dwarf postfix expression
6282 equivalent. This routine recursively descends an RTL tree, turning
6283 it into Dwarf postfix code as it goes.
6285 MODE is the mode of the memory reference, needed to handle some
6286 autoincrement addressing modes. */
6288 static dw_loc_descr_ref
6289 mem_loc_descriptor (rtl, mode)
6290 register rtx rtl;
6291 enum machine_mode mode;
6293 dw_loc_descr_ref mem_loc_result = NULL;
6294 /* Note that for a dynamically sized array, the location we will generate a
6295 description of here will be the lowest numbered location which is
6296 actually within the array. That's *not* necessarily the same as the
6297 zeroth element of the array. */
6299 #ifdef ASM_SIMPLIFY_DWARF_ADDR
6300 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl);
6301 #endif
6303 switch (GET_CODE (rtl))
6305 case POST_INC:
6306 case POST_DEC:
6307 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6308 just fall into the SUBREG code. */
6310 /* ... fall through ... */
6312 case SUBREG:
6313 /* The case of a subreg may arise when we have a local (register)
6314 variable or a formal (register) parameter which doesn't quite fill
6315 up an entire register. For now, just assume that it is
6316 legitimate to make the Dwarf info refer to the whole register which
6317 contains the given subreg. */
6318 rtl = XEXP (rtl, 0);
6320 /* ... fall through ... */
6322 case REG:
6323 /* Whenever a register number forms a part of the description of the
6324 method for calculating the (dynamic) address of a memory resident
6325 object, DWARF rules require the register number be referred to as
6326 a "base register". This distinction is not based in any way upon
6327 what category of register the hardware believes the given register
6328 belongs to. This is strictly DWARF terminology we're dealing with
6329 here. Note that in cases where the location of a memory-resident
6330 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6331 OP_CONST (0)) the actual DWARF location descriptor that we generate
6332 may just be OP_BASEREG (basereg). This may look deceptively like
6333 the object in question was allocated to a register (rather than in
6334 memory) so DWARF consumers need to be aware of the subtle
6335 distinction between OP_REG and OP_BASEREG. */
6336 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6337 break;
6339 case MEM:
6340 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6341 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6342 break;
6344 case LABEL_REF:
6345 /* Some ports can transform a symbol ref into a label ref, because
6346 the symbol ref is too far away and has to be dumped into a constant
6347 pool. */
6348 case CONST:
6349 case SYMBOL_REF:
6350 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6351 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6352 mem_loc_result->dw_loc_oprnd1.v.val_addr = save_rtx (rtl);
6353 break;
6355 case PRE_INC:
6356 case PRE_DEC:
6357 /* Turn these into a PLUS expression and fall into the PLUS code
6358 below. */
6359 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6360 GEN_INT (GET_CODE (rtl) == PRE_INC
6361 ? GET_MODE_UNIT_SIZE (mode)
6362 : - GET_MODE_UNIT_SIZE (mode)));
6364 /* ... fall through ... */
6366 case PLUS:
6367 if (is_based_loc (rtl))
6368 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6369 INTVAL (XEXP (rtl, 1)));
6370 else
6372 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6373 mode));
6374 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6375 mode));
6376 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6378 break;
6380 case MULT:
6381 /* If a pseudo-reg is optimized away, it is possible for it to
6382 be replaced with a MEM containing a multiply. */
6383 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6384 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6385 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6386 break;
6388 case CONST_INT:
6389 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6390 break;
6392 default:
6393 abort ();
6396 return mem_loc_result;
6399 /* Return a descriptor that describes the concatenation of two locations.
6400 This is typically a complex variable. */
6402 static dw_loc_descr_ref
6403 concat_loc_descriptor (x0, x1)
6404 register rtx x0, x1;
6406 dw_loc_descr_ref cc_loc_result = NULL;
6408 if (!is_pseudo_reg (x0)
6409 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6410 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6411 add_loc_descr (&cc_loc_result,
6412 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6414 if (!is_pseudo_reg (x1)
6415 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6416 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6417 add_loc_descr (&cc_loc_result,
6418 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6420 return cc_loc_result;
6423 /* Output a proper Dwarf location descriptor for a variable or parameter
6424 which is either allocated in a register or in a memory location. For a
6425 register, we just generate an OP_REG and the register number. For a
6426 memory location we provide a Dwarf postfix expression describing how to
6427 generate the (dynamic) address of the object onto the address stack. */
6429 static dw_loc_descr_ref
6430 loc_descriptor (rtl)
6431 register rtx rtl;
6433 dw_loc_descr_ref loc_result = NULL;
6434 switch (GET_CODE (rtl))
6436 case SUBREG:
6437 /* The case of a subreg may arise when we have a local (register)
6438 variable or a formal (register) parameter which doesn't quite fill
6439 up an entire register. For now, just assume that it is
6440 legitimate to make the Dwarf info refer to the whole register which
6441 contains the given subreg. */
6442 rtl = XEXP (rtl, 0);
6444 /* ... fall through ... */
6446 case REG:
6447 loc_result = reg_loc_descriptor (rtl);
6448 break;
6450 case MEM:
6451 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6452 break;
6454 case CONCAT:
6455 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6456 break;
6458 default:
6459 abort ();
6462 return loc_result;
6465 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6466 which is not less than the value itself. */
6468 static inline unsigned
6469 ceiling (value, boundary)
6470 register unsigned value;
6471 register unsigned boundary;
6473 return (((value + boundary - 1) / boundary) * boundary);
6476 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6477 pointer to the declared type for the relevant field variable, or return
6478 `integer_type_node' if the given node turns out to be an
6479 ERROR_MARK node. */
6481 static inline tree
6482 field_type (decl)
6483 register tree decl;
6485 register tree type;
6487 if (TREE_CODE (decl) == ERROR_MARK)
6488 return integer_type_node;
6490 type = DECL_BIT_FIELD_TYPE (decl);
6491 if (type == NULL_TREE)
6492 type = TREE_TYPE (decl);
6494 return type;
6497 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6498 node, return the alignment in bits for the type, or else return
6499 BITS_PER_WORD if the node actually turns out to be an
6500 ERROR_MARK node. */
6502 static inline unsigned
6503 simple_type_align_in_bits (type)
6504 register tree type;
6506 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6509 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6510 node, return the size in bits for the type if it is a constant, or else
6511 return the alignment for the type if the type's size is not constant, or
6512 else return BITS_PER_WORD if the type actually turns out to be an
6513 ERROR_MARK node. */
6515 static inline unsigned
6516 simple_type_size_in_bits (type)
6517 register tree type;
6519 if (TREE_CODE (type) == ERROR_MARK)
6520 return BITS_PER_WORD;
6521 else
6523 register tree type_size_tree = TYPE_SIZE (type);
6525 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6526 return TYPE_ALIGN (type);
6528 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6532 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6533 return the byte offset of the lowest addressed byte of the "containing
6534 object" for the given FIELD_DECL, or return 0 if we are unable to
6535 determine what that offset is, either because the argument turns out to
6536 be a pointer to an ERROR_MARK node, or because the offset is actually
6537 variable. (We can't handle the latter case just yet). */
6539 static unsigned
6540 field_byte_offset (decl)
6541 register tree decl;
6543 register unsigned type_align_in_bytes;
6544 register unsigned type_align_in_bits;
6545 register unsigned type_size_in_bits;
6546 register unsigned object_offset_in_align_units;
6547 register unsigned object_offset_in_bits;
6548 register unsigned object_offset_in_bytes;
6549 register tree type;
6550 register tree bitpos_tree;
6551 register tree field_size_tree;
6552 register unsigned bitpos_int;
6553 register unsigned deepest_bitpos;
6554 register unsigned field_size_in_bits;
6556 if (TREE_CODE (decl) == ERROR_MARK)
6557 return 0;
6559 if (TREE_CODE (decl) != FIELD_DECL)
6560 abort ();
6562 type = field_type (decl);
6564 bitpos_tree = DECL_FIELD_BITPOS (decl);
6565 field_size_tree = DECL_SIZE (decl);
6567 /* If there was an error, the size could be zero. */
6568 if (! field_size_tree)
6570 if (errorcount)
6571 return 0;
6572 abort ();
6575 /* We cannot yet cope with fields whose positions are variable, so
6576 for now, when we see such things, we simply return 0. Someday, we may
6577 be able to handle such cases, but it will be damn difficult. */
6578 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6579 return 0;
6581 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6583 /* If we don't know the size of the field, pretend it's a full word. */
6584 if (TREE_CODE (field_size_tree) == INTEGER_CST)
6585 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6586 else
6587 field_size_in_bits = BITS_PER_WORD;
6589 type_size_in_bits = simple_type_size_in_bits (type);
6590 type_align_in_bits = simple_type_align_in_bits (type);
6591 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6593 /* Note that the GCC front-end doesn't make any attempt to keep track of
6594 the starting bit offset (relative to the start of the containing
6595 structure type) of the hypothetical "containing object" for a bit-
6596 field. Thus, when computing the byte offset value for the start of the
6597 "containing object" of a bit-field, we must deduce this information on
6598 our own. This can be rather tricky to do in some cases. For example,
6599 handling the following structure type definition when compiling for an
6600 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6601 can be very tricky:
6603 struct S { int field1; long long field2:31; };
6605 Fortunately, there is a simple rule-of-thumb which can be
6606 used in such cases. When compiling for an i386/i486, GCC will allocate
6607 8 bytes for the structure shown above. It decides to do this based upon
6608 one simple rule for bit-field allocation. Quite simply, GCC allocates
6609 each "containing object" for each bit-field at the first (i.e. lowest
6610 addressed) legitimate alignment boundary (based upon the required
6611 minimum alignment for the declared type of the field) which it can
6612 possibly use, subject to the condition that there is still enough
6613 available space remaining in the containing object (when allocated at
6614 the selected point) to fully accommodate all of the bits of the
6615 bit-field itself. This simple rule makes it obvious why GCC allocates
6616 8 bytes for each object of the structure type shown above. When looking
6617 for a place to allocate the "containing object" for `field2', the
6618 compiler simply tries to allocate a 64-bit "containing object" at each
6619 successive 32-bit boundary (starting at zero) until it finds a place to
6620 allocate that 64- bit field such that at least 31 contiguous (and
6621 previously unallocated) bits remain within that selected 64 bit field.
6622 (As it turns out, for the example above, the compiler finds that it is
6623 OK to allocate the "containing object" 64-bit field at bit-offset zero
6624 within the structure type.) Here we attempt to work backwards from the
6625 limited set of facts we're given, and we try to deduce from those facts,
6626 where GCC must have believed that the containing object started (within
6627 the structure type). The value we deduce is then used (by the callers of
6628 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6629 for fields (both bit-fields and, in the case of DW_AT_location, regular
6630 fields as well). */
6632 /* Figure out the bit-distance from the start of the structure to the
6633 "deepest" bit of the bit-field. */
6634 deepest_bitpos = bitpos_int + field_size_in_bits;
6636 /* This is the tricky part. Use some fancy footwork to deduce where the
6637 lowest addressed bit of the containing object must be. */
6638 object_offset_in_bits
6639 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6641 /* Compute the offset of the containing object in "alignment units". */
6642 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6644 /* Compute the offset of the containing object in bytes. */
6645 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6647 return object_offset_in_bytes;
6650 /* The following routines define various Dwarf attributes and any data
6651 associated with them. */
6653 /* Add a location description attribute value to a DIE.
6655 This emits location attributes suitable for whole variables and
6656 whole parameters. Note that the location attributes for struct fields are
6657 generated by the routine `data_member_location_attribute' below. */
6659 static void
6660 add_AT_location_description (die, attr_kind, rtl)
6661 dw_die_ref die;
6662 enum dwarf_attribute attr_kind;
6663 register rtx rtl;
6665 /* Handle a special case. If we are about to output a location descriptor
6666 for a variable or parameter which has been optimized out of existence,
6667 don't do that. A variable which has been optimized out
6668 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6669 Currently, in some rare cases, variables can have DECL_RTL values which
6670 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6671 elsewhere in the compiler. We treat such cases as if the variable(s) in
6672 question had been optimized out of existence. */
6674 if (is_pseudo_reg (rtl)
6675 || (GET_CODE (rtl) == MEM
6676 && is_pseudo_reg (XEXP (rtl, 0)))
6677 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6678 references the internal argument pointer (a pseudo) in a function
6679 where all references to the internal argument pointer were
6680 eliminated via the optimizers. */
6681 || (GET_CODE (rtl) == MEM
6682 && GET_CODE (XEXP (rtl, 0)) == PLUS
6683 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6684 || (GET_CODE (rtl) == CONCAT
6685 && is_pseudo_reg (XEXP (rtl, 0))
6686 && is_pseudo_reg (XEXP (rtl, 1))))
6687 return;
6689 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6692 /* Attach the specialized form of location attribute used for data
6693 members of struct and union types. In the special case of a
6694 FIELD_DECL node which represents a bit-field, the "offset" part
6695 of this special location descriptor must indicate the distance
6696 in bytes from the lowest-addressed byte of the containing struct
6697 or union type to the lowest-addressed byte of the "containing
6698 object" for the bit-field. (See the `field_byte_offset' function
6699 above).. For any given bit-field, the "containing object" is a
6700 hypothetical object (of some integral or enum type) within which
6701 the given bit-field lives. The type of this hypothetical
6702 "containing object" is always the same as the declared type of
6703 the individual bit-field itself (for GCC anyway... the DWARF
6704 spec doesn't actually mandate this). Note that it is the size
6705 (in bytes) of the hypothetical "containing object" which will
6706 be given in the DW_AT_byte_size attribute for this bit-field.
6707 (See the `byte_size_attribute' function below.) It is also used
6708 when calculating the value of the DW_AT_bit_offset attribute.
6709 (See the `bit_offset_attribute' function below). */
6711 static void
6712 add_data_member_location_attribute (die, decl)
6713 register dw_die_ref die;
6714 register tree decl;
6716 register unsigned long offset;
6717 register dw_loc_descr_ref loc_descr;
6718 register enum dwarf_location_atom op;
6720 if (TREE_CODE (decl) == TREE_VEC)
6721 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6722 else
6723 offset = field_byte_offset (decl);
6725 /* The DWARF2 standard says that we should assume that the structure address
6726 is already on the stack, so we can specify a structure field address
6727 by using DW_OP_plus_uconst. */
6729 #ifdef MIPS_DEBUGGING_INFO
6730 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6731 correctly. It works only if we leave the offset on the stack. */
6732 op = DW_OP_constu;
6733 #else
6734 op = DW_OP_plus_uconst;
6735 #endif
6737 loc_descr = new_loc_descr (op, offset, 0);
6738 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6741 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6742 does not have a "location" either in memory or in a register. These
6743 things can arise in GNU C when a constant is passed as an actual parameter
6744 to an inlined function. They can also arise in C++ where declared
6745 constants do not necessarily get memory "homes". */
6747 static void
6748 add_const_value_attribute (die, rtl)
6749 register dw_die_ref die;
6750 register rtx rtl;
6752 switch (GET_CODE (rtl))
6754 case CONST_INT:
6755 /* Note that a CONST_INT rtx could represent either an integer or a
6756 floating-point constant. A CONST_INT is used whenever the constant
6757 will fit into a single word. In all such cases, the original mode
6758 of the constant value is wiped out, and the CONST_INT rtx is
6759 assigned VOIDmode. */
6760 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6761 break;
6763 case CONST_DOUBLE:
6764 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6765 floating-point constant. A CONST_DOUBLE is used whenever the
6766 constant requires more than one word in order to be adequately
6767 represented. We output CONST_DOUBLEs as blocks. */
6769 register enum machine_mode mode = GET_MODE (rtl);
6771 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6773 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6774 long array[4];
6775 REAL_VALUE_TYPE rv;
6777 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6778 switch (mode)
6780 case SFmode:
6781 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6782 break;
6784 case DFmode:
6785 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6786 break;
6788 case XFmode:
6789 case TFmode:
6790 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6791 break;
6793 default:
6794 abort ();
6797 add_AT_float (die, DW_AT_const_value, length, array);
6799 else
6800 add_AT_long_long (die, DW_AT_const_value,
6801 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6803 break;
6805 case CONST_STRING:
6806 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6807 break;
6809 case SYMBOL_REF:
6810 case LABEL_REF:
6811 case CONST:
6812 add_AT_addr (die, DW_AT_const_value, save_rtx (rtl));
6813 break;
6815 case PLUS:
6816 /* In cases where an inlined instance of an inline function is passed
6817 the address of an `auto' variable (which is local to the caller) we
6818 can get a situation where the DECL_RTL of the artificial local
6819 variable (for the inlining) which acts as a stand-in for the
6820 corresponding formal parameter (of the inline function) will look
6821 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6822 exactly a compile-time constant expression, but it isn't the address
6823 of the (artificial) local variable either. Rather, it represents the
6824 *value* which the artificial local variable always has during its
6825 lifetime. We currently have no way to represent such quasi-constant
6826 values in Dwarf, so for now we just punt and generate nothing. */
6827 break;
6829 default:
6830 /* No other kinds of rtx should be possible here. */
6831 abort ();
6836 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6837 data attribute for a variable or a parameter. We generate the
6838 DW_AT_const_value attribute only in those cases where the given variable
6839 or parameter does not have a true "location" either in memory or in a
6840 register. This can happen (for example) when a constant is passed as an
6841 actual argument in a call to an inline function. (It's possible that
6842 these things can crop up in other ways also.) Note that one type of
6843 constant value which can be passed into an inlined function is a constant
6844 pointer. This can happen for example if an actual argument in an inlined
6845 function call evaluates to a compile-time constant address. */
6847 static void
6848 add_location_or_const_value_attribute (die, decl)
6849 register dw_die_ref die;
6850 register tree decl;
6852 register rtx rtl;
6853 register tree declared_type;
6854 register tree passed_type;
6856 if (TREE_CODE (decl) == ERROR_MARK)
6857 return;
6859 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6860 abort ();
6862 /* Here we have to decide where we are going to say the parameter "lives"
6863 (as far as the debugger is concerned). We only have a couple of
6864 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6866 DECL_RTL normally indicates where the parameter lives during most of the
6867 activation of the function. If optimization is enabled however, this
6868 could be either NULL or else a pseudo-reg. Both of those cases indicate
6869 that the parameter doesn't really live anywhere (as far as the code
6870 generation parts of GCC are concerned) during most of the function's
6871 activation. That will happen (for example) if the parameter is never
6872 referenced within the function.
6874 We could just generate a location descriptor here for all non-NULL
6875 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6876 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6877 where DECL_RTL is NULL or is a pseudo-reg.
6879 Note however that we can only get away with using DECL_INCOMING_RTL as
6880 a backup substitute for DECL_RTL in certain limited cases. In cases
6881 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6882 we can be sure that the parameter was passed using the same type as it is
6883 declared to have within the function, and that its DECL_INCOMING_RTL
6884 points us to a place where a value of that type is passed.
6886 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6887 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6888 because in these cases DECL_INCOMING_RTL points us to a value of some
6889 type which is *different* from the type of the parameter itself. Thus,
6890 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6891 such cases, the debugger would end up (for example) trying to fetch a
6892 `float' from a place which actually contains the first part of a
6893 `double'. That would lead to really incorrect and confusing
6894 output at debug-time.
6896 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6897 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6898 are a couple of exceptions however. On little-endian machines we can
6899 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6900 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6901 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6902 when (on a little-endian machine) a non-prototyped function has a
6903 parameter declared to be of type `short' or `char'. In such cases,
6904 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6905 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6906 passed `int' value. If the debugger then uses that address to fetch
6907 a `short' or a `char' (on a little-endian machine) the result will be
6908 the correct data, so we allow for such exceptional cases below.
6910 Note that our goal here is to describe the place where the given formal
6911 parameter lives during most of the function's activation (i.e. between
6912 the end of the prologue and the start of the epilogue). We'll do that
6913 as best as we can. Note however that if the given formal parameter is
6914 modified sometime during the execution of the function, then a stack
6915 backtrace (at debug-time) will show the function as having been
6916 called with the *new* value rather than the value which was
6917 originally passed in. This happens rarely enough that it is not
6918 a major problem, but it *is* a problem, and I'd like to fix it.
6920 A future version of dwarf2out.c may generate two additional
6921 attributes for any given DW_TAG_formal_parameter DIE which will
6922 describe the "passed type" and the "passed location" for the
6923 given formal parameter in addition to the attributes we now
6924 generate to indicate the "declared type" and the "active
6925 location" for each parameter. This additional set of attributes
6926 could be used by debuggers for stack backtraces. Separately, note
6927 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6928 NULL also. This happens (for example) for inlined-instances of
6929 inline function formal parameters which are never referenced.
6930 This really shouldn't be happening. All PARM_DECL nodes should
6931 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6932 doesn't currently generate these values for inlined instances of
6933 inline function parameters, so when we see such cases, we are
6934 just out-of-luck for the time being (until integrate.c
6935 gets fixed). */
6937 /* Use DECL_RTL as the "location" unless we find something better. */
6938 rtl = DECL_RTL (decl);
6940 if (TREE_CODE (decl) == PARM_DECL)
6942 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
6944 declared_type = type_main_variant (TREE_TYPE (decl));
6945 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
6947 /* This decl represents a formal parameter which was optimized out.
6948 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
6949 all* cases where (rtl == NULL_RTX) just below. */
6950 if (declared_type == passed_type)
6951 rtl = DECL_INCOMING_RTL (decl);
6952 else if (! BYTES_BIG_ENDIAN
6953 && TREE_CODE (declared_type) == INTEGER_TYPE
6954 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
6955 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
6956 rtl = DECL_INCOMING_RTL (decl);
6959 /* If the parm was passed in registers, but lives on the stack, then
6960 make a big endian correction if the mode of the type of the
6961 parameter is not the same as the mode of the rtl. */
6962 /* ??? This is the same series of checks that are made in dbxout.c before
6963 we reach the big endian correction code there. It isn't clear if all
6964 of these checks are necessary here, but keeping them all is the safe
6965 thing to do. */
6966 else if (GET_CODE (rtl) == MEM
6967 && XEXP (rtl, 0) != const0_rtx
6968 && ! CONSTANT_P (XEXP (rtl, 0))
6969 /* Not passed in memory. */
6970 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
6971 /* Not passed by invisible reference. */
6972 && (GET_CODE (XEXP (rtl, 0)) != REG
6973 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
6974 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
6975 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
6976 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
6977 #endif
6979 /* Big endian correction check. */
6980 && BYTES_BIG_ENDIAN
6981 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
6982 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
6983 < UNITS_PER_WORD))
6985 int offset = (UNITS_PER_WORD
6986 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
6987 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
6988 plus_constant (XEXP (rtl, 0), offset));
6992 if (rtl == NULL_RTX)
6993 return;
6995 rtl = eliminate_regs (rtl, 0, NULL_RTX);
6996 #ifdef LEAF_REG_REMAP
6997 if (current_function_uses_only_leaf_regs)
6998 leaf_renumber_regs_insn (rtl);
6999 #endif
7001 switch (GET_CODE (rtl))
7003 case ADDRESSOF:
7004 /* The address of a variable that was optimized away; don't emit
7005 anything. */
7006 break;
7008 case CONST_INT:
7009 case CONST_DOUBLE:
7010 case CONST_STRING:
7011 case SYMBOL_REF:
7012 case LABEL_REF:
7013 case CONST:
7014 case PLUS:
7015 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7016 add_const_value_attribute (die, rtl);
7017 break;
7019 case MEM:
7020 case REG:
7021 case SUBREG:
7022 case CONCAT:
7023 add_AT_location_description (die, DW_AT_location, rtl);
7024 break;
7026 default:
7027 abort ();
7031 /* Generate an DW_AT_name attribute given some string value to be included as
7032 the value of the attribute. */
7034 static inline void
7035 add_name_attribute (die, name_string)
7036 register dw_die_ref die;
7037 register const char *name_string;
7039 if (name_string != NULL && *name_string != 0)
7041 if (demangle_name_func)
7042 name_string = (*demangle_name_func) (name_string);
7044 add_AT_string (die, DW_AT_name, name_string);
7048 /* Given a tree node describing an array bound (either lower or upper) output
7049 a representation for that bound. */
7051 static void
7052 add_bound_info (subrange_die, bound_attr, bound)
7053 register dw_die_ref subrange_die;
7054 register enum dwarf_attribute bound_attr;
7055 register tree bound;
7057 register unsigned bound_value = 0;
7059 /* If this is an Ada unconstrained array type, then don't emit any debug
7060 info because the array bounds are unknown. They are parameterized when
7061 the type is instantiated. */
7062 if (contains_placeholder_p (bound))
7063 return;
7065 switch (TREE_CODE (bound))
7067 case ERROR_MARK:
7068 return;
7070 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7071 case INTEGER_CST:
7072 bound_value = TREE_INT_CST_LOW (bound);
7073 if (bound_attr == DW_AT_lower_bound
7074 && ((is_c_family () && bound_value == 0)
7075 || (is_fortran () && bound_value == 1)))
7076 /* use the default */;
7077 else
7078 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7079 break;
7081 case CONVERT_EXPR:
7082 case NOP_EXPR:
7083 case NON_LVALUE_EXPR:
7084 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7085 break;
7087 case SAVE_EXPR:
7088 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7089 access the upper bound values may be bogus. If they refer to a
7090 register, they may only describe how to get at these values at the
7091 points in the generated code right after they have just been
7092 computed. Worse yet, in the typical case, the upper bound values
7093 will not even *be* computed in the optimized code (though the
7094 number of elements will), so these SAVE_EXPRs are entirely
7095 bogus. In order to compensate for this fact, we check here to see
7096 if optimization is enabled, and if so, we don't add an attribute
7097 for the (unknown and unknowable) upper bound. This should not
7098 cause too much trouble for existing (stupid?) debuggers because
7099 they have to deal with empty upper bounds location descriptions
7100 anyway in order to be able to deal with incomplete array types.
7101 Of course an intelligent debugger (GDB?) should be able to
7102 comprehend that a missing upper bound specification in a array
7103 type used for a storage class `auto' local array variable
7104 indicates that the upper bound is both unknown (at compile- time)
7105 and unknowable (at run-time) due to optimization.
7107 We assume that a MEM rtx is safe because gcc wouldn't put the
7108 value there unless it was going to be used repeatedly in the
7109 function, i.e. for cleanups. */
7110 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7112 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7113 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7114 register rtx loc = SAVE_EXPR_RTL (bound);
7116 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7117 it references an outer function's frame. */
7119 if (GET_CODE (loc) == MEM)
7121 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7123 if (XEXP (loc, 0) != new_addr)
7124 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7127 add_AT_flag (decl_die, DW_AT_artificial, 1);
7128 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7129 add_AT_location_description (decl_die, DW_AT_location, loc);
7130 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7133 /* Else leave out the attribute. */
7134 break;
7136 case MAX_EXPR:
7137 case VAR_DECL:
7138 case COMPONENT_REF:
7139 /* ??? These types of bounds can be created by the Ada front end,
7140 and it isn't clear how to emit debug info for them. */
7141 break;
7143 default:
7144 abort ();
7148 /* Note that the block of subscript information for an array type also
7149 includes information about the element type of type given array type. */
7151 static void
7152 add_subscript_info (type_die, type)
7153 register dw_die_ref type_die;
7154 register tree type;
7156 #ifndef MIPS_DEBUGGING_INFO
7157 register unsigned dimension_number;
7158 #endif
7159 register tree lower, upper;
7160 register dw_die_ref subrange_die;
7162 /* The GNU compilers represent multidimensional array types as sequences of
7163 one dimensional array types whose element types are themselves array
7164 types. Here we squish that down, so that each multidimensional array
7165 type gets only one array_type DIE in the Dwarf debugging info. The draft
7166 Dwarf specification say that we are allowed to do this kind of
7167 compression in C (because there is no difference between an array or
7168 arrays and a multidimensional array in C) but for other source languages
7169 (e.g. Ada) we probably shouldn't do this. */
7171 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7172 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7173 We work around this by disabling this feature. See also
7174 gen_array_type_die. */
7175 #ifndef MIPS_DEBUGGING_INFO
7176 for (dimension_number = 0;
7177 TREE_CODE (type) == ARRAY_TYPE;
7178 type = TREE_TYPE (type), dimension_number++)
7180 #endif
7181 register tree domain = TYPE_DOMAIN (type);
7183 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7184 and (in GNU C only) variable bounds. Handle all three forms
7185 here. */
7186 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7187 if (domain)
7189 /* We have an array type with specified bounds. */
7190 lower = TYPE_MIN_VALUE (domain);
7191 upper = TYPE_MAX_VALUE (domain);
7193 /* define the index type. */
7194 if (TREE_TYPE (domain))
7196 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7197 TREE_TYPE field. We can't emit debug info for this
7198 because it is an unnamed integral type. */
7199 if (TREE_CODE (domain) == INTEGER_TYPE
7200 && TYPE_NAME (domain) == NULL_TREE
7201 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7202 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7204 else
7205 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7206 type_die);
7209 /* ??? If upper is NULL, the array has unspecified length,
7210 but it does have a lower bound. This happens with Fortran
7211 dimension arr(N:*)
7212 Since the debugger is definitely going to need to know N
7213 to produce useful results, go ahead and output the lower
7214 bound solo, and hope the debugger can cope. */
7216 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7217 if (upper)
7218 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7220 else
7221 /* We have an array type with an unspecified length. The DWARF-2
7222 spec does not say how to handle this; let's just leave out the
7223 bounds. */
7227 #ifndef MIPS_DEBUGGING_INFO
7229 #endif
7232 static void
7233 add_byte_size_attribute (die, tree_node)
7234 dw_die_ref die;
7235 register tree tree_node;
7237 register unsigned size;
7239 switch (TREE_CODE (tree_node))
7241 case ERROR_MARK:
7242 size = 0;
7243 break;
7244 case ENUMERAL_TYPE:
7245 case RECORD_TYPE:
7246 case UNION_TYPE:
7247 case QUAL_UNION_TYPE:
7248 size = int_size_in_bytes (tree_node);
7249 break;
7250 case FIELD_DECL:
7251 /* For a data member of a struct or union, the DW_AT_byte_size is
7252 generally given as the number of bytes normally allocated for an
7253 object of the *declared* type of the member itself. This is true
7254 even for bit-fields. */
7255 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7256 break;
7257 default:
7258 abort ();
7261 /* Note that `size' might be -1 when we get to this point. If it is, that
7262 indicates that the byte size of the entity in question is variable. We
7263 have no good way of expressing this fact in Dwarf at the present time,
7264 so just let the -1 pass on through. */
7266 add_AT_unsigned (die, DW_AT_byte_size, size);
7269 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7270 which specifies the distance in bits from the highest order bit of the
7271 "containing object" for the bit-field to the highest order bit of the
7272 bit-field itself.
7274 For any given bit-field, the "containing object" is a hypothetical
7275 object (of some integral or enum type) within which the given bit-field
7276 lives. The type of this hypothetical "containing object" is always the
7277 same as the declared type of the individual bit-field itself. The
7278 determination of the exact location of the "containing object" for a
7279 bit-field is rather complicated. It's handled by the
7280 `field_byte_offset' function (above).
7282 Note that it is the size (in bytes) of the hypothetical "containing object"
7283 which will be given in the DW_AT_byte_size attribute for this bit-field.
7284 (See `byte_size_attribute' above). */
7286 static inline void
7287 add_bit_offset_attribute (die, decl)
7288 register dw_die_ref die;
7289 register tree decl;
7291 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7292 register tree type = DECL_BIT_FIELD_TYPE (decl);
7293 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7294 register unsigned bitpos_int;
7295 register unsigned highest_order_object_bit_offset;
7296 register unsigned highest_order_field_bit_offset;
7297 register unsigned bit_offset;
7299 /* Must be a field and a bit field. */
7300 if (!type
7301 || TREE_CODE (decl) != FIELD_DECL)
7302 abort ();
7304 /* We can't yet handle bit-fields whose offsets are variable, so if we
7305 encounter such things, just return without generating any attribute
7306 whatsoever. */
7307 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7308 return;
7310 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7312 /* Note that the bit offset is always the distance (in bits) from the
7313 highest-order bit of the "containing object" to the highest-order bit of
7314 the bit-field itself. Since the "high-order end" of any object or field
7315 is different on big-endian and little-endian machines, the computation
7316 below must take account of these differences. */
7317 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7318 highest_order_field_bit_offset = bitpos_int;
7320 if (! BYTES_BIG_ENDIAN)
7322 highest_order_field_bit_offset
7323 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7325 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7328 bit_offset
7329 = (! BYTES_BIG_ENDIAN
7330 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7331 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7333 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7336 /* For a FIELD_DECL node which represents a bit field, output an attribute
7337 which specifies the length in bits of the given field. */
7339 static inline void
7340 add_bit_size_attribute (die, decl)
7341 register dw_die_ref die;
7342 register tree decl;
7344 /* Must be a field and a bit field. */
7345 if (TREE_CODE (decl) != FIELD_DECL
7346 || ! DECL_BIT_FIELD_TYPE (decl))
7347 abort ();
7348 add_AT_unsigned (die, DW_AT_bit_size,
7349 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7352 /* If the compiled language is ANSI C, then add a 'prototyped'
7353 attribute, if arg types are given for the parameters of a function. */
7355 static inline void
7356 add_prototyped_attribute (die, func_type)
7357 register dw_die_ref die;
7358 register tree func_type;
7360 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7361 && TYPE_ARG_TYPES (func_type) != NULL)
7362 add_AT_flag (die, DW_AT_prototyped, 1);
7366 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7367 by looking in either the type declaration or object declaration
7368 equate table. */
7370 static inline void
7371 add_abstract_origin_attribute (die, origin)
7372 register dw_die_ref die;
7373 register tree origin;
7375 dw_die_ref origin_die = NULL;
7377 /* We may have gotten separated from the block for the inlined
7378 function, if we're in an exception handler or some such; make
7379 sure that the abstract function has been written out. */
7380 tree fn = decl_function_context (origin);
7381 if (fn)
7382 gen_abstract_function (fn);
7384 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7385 origin_die = lookup_decl_die (origin);
7386 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7387 origin_die = lookup_type_die (origin);
7389 if (origin_die == NULL)
7390 abort ();
7392 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7395 /* We do not currently support the pure_virtual attribute. */
7397 static inline void
7398 add_pure_or_virtual_attribute (die, func_decl)
7399 register dw_die_ref die;
7400 register tree func_decl;
7402 if (DECL_VINDEX (func_decl))
7404 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7405 add_AT_loc (die, DW_AT_vtable_elem_location,
7406 new_loc_descr (DW_OP_constu,
7407 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7408 0));
7410 /* GNU extension: Record what type this method came from originally. */
7411 if (debug_info_level > DINFO_LEVEL_TERSE)
7412 add_AT_die_ref (die, DW_AT_containing_type,
7413 lookup_type_die (DECL_CONTEXT (func_decl)));
7417 /* Add source coordinate attributes for the given decl. */
7419 static void
7420 add_src_coords_attributes (die, decl)
7421 register dw_die_ref die;
7422 register tree decl;
7424 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7426 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7427 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7430 /* Add an DW_AT_name attribute and source coordinate attribute for the
7431 given decl, but only if it actually has a name. */
7433 static void
7434 add_name_and_src_coords_attributes (die, decl)
7435 register dw_die_ref die;
7436 register tree decl;
7438 register tree decl_name;
7440 decl_name = DECL_NAME (decl);
7441 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7443 add_name_attribute (die, dwarf2_name (decl, 0));
7444 if (! DECL_ARTIFICIAL (decl))
7445 add_src_coords_attributes (die, decl);
7447 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7448 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7449 add_AT_string (die, DW_AT_MIPS_linkage_name,
7450 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7454 /* Push a new declaration scope. */
7456 static void
7457 push_decl_scope (scope)
7458 tree scope;
7460 /* Make room in the decl_scope_table, if necessary. */
7461 if (decl_scope_table_allocated == decl_scope_depth)
7463 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7464 decl_scope_table
7465 = (tree *) xrealloc (decl_scope_table,
7466 decl_scope_table_allocated * sizeof (tree));
7469 decl_scope_table[decl_scope_depth] = scope;
7470 decl_scope_depth++;
7473 /* Pop a declaration scope. */
7474 static inline void
7475 pop_decl_scope ()
7477 if (decl_scope_depth <= 0)
7478 abort ();
7479 --decl_scope_depth;
7482 /* Return the DIE for the scope that immediately contains this type.
7483 Non-named types get global scope. Named types nested in other
7484 types get their containing scope if it's open, or global scope
7485 otherwise. All other types (i.e. function-local named types) get
7486 the current active scope. */
7488 static dw_die_ref
7489 scope_die_for (t, context_die)
7490 register tree t;
7491 register dw_die_ref context_die;
7493 register dw_die_ref scope_die = NULL;
7494 register tree containing_scope;
7495 register int i;
7497 /* Non-types always go in the current scope. */
7498 if (! TYPE_P (t))
7499 abort ();
7501 containing_scope = TYPE_CONTEXT (t);
7503 /* Ignore namespaces for the moment. */
7504 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7505 containing_scope = NULL_TREE;
7507 /* Ignore function type "scopes" from the C frontend. They mean that
7508 a tagged type is local to a parmlist of a function declarator, but
7509 that isn't useful to DWARF. */
7510 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7511 containing_scope = NULL_TREE;
7513 if (containing_scope == NULL_TREE)
7514 scope_die = comp_unit_die;
7515 else if (TYPE_P (containing_scope))
7517 /* For types, we can just look up the appropriate DIE. But
7518 first we check to see if we're in the middle of emitting it
7519 so we know where the new DIE should go. */
7521 for (i = decl_scope_depth - 1; i >= 0; --i)
7522 if (decl_scope_table[i] == containing_scope)
7523 break;
7525 if (i < 0)
7527 if (debug_info_level > DINFO_LEVEL_TERSE
7528 && !TREE_ASM_WRITTEN (containing_scope))
7529 abort ();
7531 /* If none of the current dies are suitable, we get file scope. */
7532 scope_die = comp_unit_die;
7534 else
7535 scope_die = lookup_type_die (containing_scope);
7537 else
7538 scope_die = context_die;
7540 return scope_die;
7543 /* Returns nonzero iff CONTEXT_DIE is internal to a function. */
7545 static inline int
7546 local_scope_p (context_die)
7547 dw_die_ref context_die;
7549 for (; context_die; context_die = context_die->die_parent)
7550 if (context_die->die_tag == DW_TAG_inlined_subroutine
7551 || context_die->die_tag == DW_TAG_subprogram)
7552 return 1;
7553 return 0;
7556 /* Returns nonzero iff CONTEXT_DIE is a class. */
7558 static inline int
7559 class_scope_p (context_die)
7560 dw_die_ref context_die;
7562 return (context_die
7563 && (context_die->die_tag == DW_TAG_structure_type
7564 || context_die->die_tag == DW_TAG_union_type));
7567 /* Many forms of DIEs require a "type description" attribute. This
7568 routine locates the proper "type descriptor" die for the type given
7569 by 'type', and adds an DW_AT_type attribute below the given die. */
7571 static void
7572 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7573 register dw_die_ref object_die;
7574 register tree type;
7575 register int decl_const;
7576 register int decl_volatile;
7577 register dw_die_ref context_die;
7579 register enum tree_code code = TREE_CODE (type);
7580 register dw_die_ref type_die = NULL;
7582 /* ??? If this type is an unnamed subrange type of an integral or
7583 floating-point type, use the inner type. This is because we have no
7584 support for unnamed types in base_type_die. This can happen if this is
7585 an Ada subrange type. Correct solution is emit a subrange type die. */
7586 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7587 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7588 type = TREE_TYPE (type), code = TREE_CODE (type);
7590 if (code == ERROR_MARK)
7591 return;
7593 /* Handle a special case. For functions whose return type is void, we
7594 generate *no* type attribute. (Note that no object may have type
7595 `void', so this only applies to function return types). */
7596 if (code == VOID_TYPE)
7597 return;
7599 type_die = modified_type_die (type,
7600 decl_const || TYPE_READONLY (type),
7601 decl_volatile || TYPE_VOLATILE (type),
7602 context_die);
7603 if (type_die != NULL)
7604 add_AT_die_ref (object_die, DW_AT_type, type_die);
7607 /* Given a tree pointer to a struct, class, union, or enum type node, return
7608 a pointer to the (string) tag name for the given type, or zero if the type
7609 was declared without a tag. */
7611 static char *
7612 type_tag (type)
7613 register tree type;
7615 register char *name = 0;
7617 if (TYPE_NAME (type) != 0)
7619 register tree t = 0;
7621 /* Find the IDENTIFIER_NODE for the type name. */
7622 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7623 t = TYPE_NAME (type);
7625 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7626 a TYPE_DECL node, regardless of whether or not a `typedef' was
7627 involved. */
7628 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7629 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7630 t = DECL_NAME (TYPE_NAME (type));
7632 /* Now get the name as a string, or invent one. */
7633 if (t != 0)
7634 name = IDENTIFIER_POINTER (t);
7637 return (name == 0 || *name == '\0') ? 0 : name;
7640 /* Return the type associated with a data member, make a special check
7641 for bit field types. */
7643 static inline tree
7644 member_declared_type (member)
7645 register tree member;
7647 return (DECL_BIT_FIELD_TYPE (member)
7648 ? DECL_BIT_FIELD_TYPE (member)
7649 : TREE_TYPE (member));
7652 /* Get the decl's label, as described by its RTL. This may be different
7653 from the DECL_NAME name used in the source file. */
7655 #if 0
7656 static char *
7657 decl_start_label (decl)
7658 register tree decl;
7660 rtx x;
7661 char *fnname;
7662 x = DECL_RTL (decl);
7663 if (GET_CODE (x) != MEM)
7664 abort ();
7666 x = XEXP (x, 0);
7667 if (GET_CODE (x) != SYMBOL_REF)
7668 abort ();
7670 fnname = XSTR (x, 0);
7671 return fnname;
7673 #endif
7675 /* These routines generate the internal representation of the DIE's for
7676 the compilation unit. Debugging information is collected by walking
7677 the declaration trees passed in from dwarf2out_decl(). */
7679 static void
7680 gen_array_type_die (type, context_die)
7681 register tree type;
7682 register dw_die_ref context_die;
7684 register dw_die_ref scope_die = scope_die_for (type, context_die);
7685 register dw_die_ref array_die;
7686 register tree element_type;
7688 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7689 the inner array type comes before the outer array type. Thus we must
7690 call gen_type_die before we call new_die. See below also. */
7691 #ifdef MIPS_DEBUGGING_INFO
7692 gen_type_die (TREE_TYPE (type), context_die);
7693 #endif
7695 array_die = new_die (DW_TAG_array_type, scope_die);
7697 #if 0
7698 /* We default the array ordering. SDB will probably do
7699 the right things even if DW_AT_ordering is not present. It's not even
7700 an issue until we start to get into multidimensional arrays anyway. If
7701 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7702 then we'll have to put the DW_AT_ordering attribute back in. (But if
7703 and when we find out that we need to put these in, we will only do so
7704 for multidimensional arrays. */
7705 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7706 #endif
7708 #ifdef MIPS_DEBUGGING_INFO
7709 /* The SGI compilers handle arrays of unknown bound by setting
7710 AT_declaration and not emitting any subrange DIEs. */
7711 if (! TYPE_DOMAIN (type))
7712 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7713 else
7714 #endif
7715 add_subscript_info (array_die, type);
7717 add_name_attribute (array_die, type_tag (type));
7718 equate_type_number_to_die (type, array_die);
7720 /* Add representation of the type of the elements of this array type. */
7721 element_type = TREE_TYPE (type);
7723 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7724 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7725 We work around this by disabling this feature. See also
7726 add_subscript_info. */
7727 #ifndef MIPS_DEBUGGING_INFO
7728 while (TREE_CODE (element_type) == ARRAY_TYPE)
7729 element_type = TREE_TYPE (element_type);
7731 gen_type_die (element_type, context_die);
7732 #endif
7734 add_type_attribute (array_die, element_type, 0, 0, context_die);
7737 static void
7738 gen_set_type_die (type, context_die)
7739 register tree type;
7740 register dw_die_ref context_die;
7742 register dw_die_ref type_die
7743 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7745 equate_type_number_to_die (type, type_die);
7746 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7749 #if 0
7750 static void
7751 gen_entry_point_die (decl, context_die)
7752 register tree decl;
7753 register dw_die_ref context_die;
7755 register tree origin = decl_ultimate_origin (decl);
7756 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7757 if (origin != NULL)
7758 add_abstract_origin_attribute (decl_die, origin);
7759 else
7761 add_name_and_src_coords_attributes (decl_die, decl);
7762 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7763 0, 0, context_die);
7766 if (DECL_ABSTRACT (decl))
7767 equate_decl_number_to_die (decl, decl_die);
7768 else
7769 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7771 #endif
7773 /* Remember a type in the incomplete_types_list. */
7775 static void
7776 add_incomplete_type (type)
7777 tree type;
7779 if (incomplete_types == incomplete_types_allocated)
7781 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7782 incomplete_types_list
7783 = (tree *) xrealloc (incomplete_types_list,
7784 sizeof (tree) * incomplete_types_allocated);
7787 incomplete_types_list[incomplete_types++] = type;
7790 /* Walk through the list of incomplete types again, trying once more to
7791 emit full debugging info for them. */
7793 static void
7794 retry_incomplete_types ()
7796 register tree type;
7798 while (incomplete_types)
7800 --incomplete_types;
7801 type = incomplete_types_list[incomplete_types];
7802 gen_type_die (type, comp_unit_die);
7806 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7808 static void
7809 gen_inlined_enumeration_type_die (type, context_die)
7810 register tree type;
7811 register dw_die_ref context_die;
7813 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7814 context_die);
7815 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7816 be incomplete and such types are not marked. */
7817 add_abstract_origin_attribute (type_die, type);
7820 /* Generate a DIE to represent an inlined instance of a structure type. */
7822 static void
7823 gen_inlined_structure_type_die (type, context_die)
7824 register tree type;
7825 register dw_die_ref context_die;
7827 register dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die);
7829 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7830 be incomplete and such types are not marked. */
7831 add_abstract_origin_attribute (type_die, type);
7834 /* Generate a DIE to represent an inlined instance of a union type. */
7836 static void
7837 gen_inlined_union_type_die (type, context_die)
7838 register tree type;
7839 register dw_die_ref context_die;
7841 register dw_die_ref type_die = new_die (DW_TAG_union_type, context_die);
7843 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7844 be incomplete and such types are not marked. */
7845 add_abstract_origin_attribute (type_die, type);
7848 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7849 include all of the information about the enumeration values also. Each
7850 enumerated type name/value is listed as a child of the enumerated type
7851 DIE. */
7853 static void
7854 gen_enumeration_type_die (type, context_die)
7855 register tree type;
7856 register dw_die_ref context_die;
7858 register dw_die_ref type_die = lookup_type_die (type);
7860 if (type_die == NULL)
7862 type_die = new_die (DW_TAG_enumeration_type,
7863 scope_die_for (type, context_die));
7864 equate_type_number_to_die (type, type_die);
7865 add_name_attribute (type_die, type_tag (type));
7867 else if (! TYPE_SIZE (type))
7868 return;
7869 else
7870 remove_AT (type_die, DW_AT_declaration);
7872 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7873 given enum type is incomplete, do not generate the DW_AT_byte_size
7874 attribute or the DW_AT_element_list attribute. */
7875 if (TYPE_SIZE (type))
7877 register tree link;
7879 TREE_ASM_WRITTEN (type) = 1;
7880 add_byte_size_attribute (type_die, type);
7881 if (TYPE_STUB_DECL (type) != NULL_TREE)
7882 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
7884 /* If the first reference to this type was as the return type of an
7885 inline function, then it may not have a parent. Fix this now. */
7886 if (type_die->die_parent == NULL)
7887 add_child_die (scope_die_for (type, context_die), type_die);
7889 for (link = TYPE_FIELDS (type);
7890 link != NULL; link = TREE_CHAIN (link))
7892 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
7894 add_name_attribute (enum_die,
7895 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
7896 add_AT_unsigned (enum_die, DW_AT_const_value,
7897 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
7900 else
7901 add_AT_flag (type_die, DW_AT_declaration, 1);
7905 /* Generate a DIE to represent either a real live formal parameter decl or to
7906 represent just the type of some formal parameter position in some function
7907 type.
7909 Note that this routine is a bit unusual because its argument may be a
7910 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
7911 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
7912 node. If it's the former then this function is being called to output a
7913 DIE to represent a formal parameter object (or some inlining thereof). If
7914 it's the latter, then this function is only being called to output a
7915 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
7916 argument type of some subprogram type. */
7918 static dw_die_ref
7919 gen_formal_parameter_die (node, context_die)
7920 register tree node;
7921 register dw_die_ref context_die;
7923 register dw_die_ref parm_die
7924 = new_die (DW_TAG_formal_parameter, context_die);
7925 register tree origin;
7927 switch (TREE_CODE_CLASS (TREE_CODE (node)))
7929 case 'd':
7930 origin = decl_ultimate_origin (node);
7931 if (origin != NULL)
7932 add_abstract_origin_attribute (parm_die, origin);
7933 else
7935 add_name_and_src_coords_attributes (parm_die, node);
7936 add_type_attribute (parm_die, TREE_TYPE (node),
7937 TREE_READONLY (node),
7938 TREE_THIS_VOLATILE (node),
7939 context_die);
7940 if (DECL_ARTIFICIAL (node))
7941 add_AT_flag (parm_die, DW_AT_artificial, 1);
7944 equate_decl_number_to_die (node, parm_die);
7945 if (! DECL_ABSTRACT (node))
7946 add_location_or_const_value_attribute (parm_die, node);
7948 break;
7950 case 't':
7951 /* We were called with some kind of a ..._TYPE node. */
7952 add_type_attribute (parm_die, node, 0, 0, context_die);
7953 break;
7955 default:
7956 abort ();
7959 return parm_die;
7962 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
7963 at the end of an (ANSI prototyped) formal parameters list. */
7965 static void
7966 gen_unspecified_parameters_die (decl_or_type, context_die)
7967 register tree decl_or_type ATTRIBUTE_UNUSED;
7968 register dw_die_ref context_die;
7970 new_die (DW_TAG_unspecified_parameters, context_die);
7973 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
7974 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
7975 parameters as specified in some function type specification (except for
7976 those which appear as part of a function *definition*).
7978 Note we must be careful here to output all of the parameter DIEs before*
7979 we output any DIEs needed to represent the types of the formal parameters.
7980 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
7981 non-parameter DIE it sees ends the formal parameter list. */
7983 static void
7984 gen_formal_types_die (function_or_method_type, context_die)
7985 register tree function_or_method_type;
7986 register dw_die_ref context_die;
7988 register tree link;
7989 register tree formal_type = NULL;
7990 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
7992 #if 0
7993 /* In the case where we are generating a formal types list for a C++
7994 non-static member function type, skip over the first thing on the
7995 TYPE_ARG_TYPES list because it only represents the type of the hidden
7996 `this pointer'. The debugger should be able to figure out (without
7997 being explicitly told) that this non-static member function type takes a
7998 `this pointer' and should be able to figure what the type of that hidden
7999 parameter is from the DW_AT_member attribute of the parent
8000 DW_TAG_subroutine_type DIE. */
8001 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8002 first_parm_type = TREE_CHAIN (first_parm_type);
8003 #endif
8005 /* Make our first pass over the list of formal parameter types and output a
8006 DW_TAG_formal_parameter DIE for each one. */
8007 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8009 register dw_die_ref parm_die;
8011 formal_type = TREE_VALUE (link);
8012 if (formal_type == void_type_node)
8013 break;
8015 /* Output a (nameless) DIE to represent the formal parameter itself. */
8016 parm_die = gen_formal_parameter_die (formal_type, context_die);
8017 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8018 && link == first_parm_type)
8019 add_AT_flag (parm_die, DW_AT_artificial, 1);
8022 /* If this function type has an ellipsis, add a
8023 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8024 if (formal_type != void_type_node)
8025 gen_unspecified_parameters_die (function_or_method_type, context_die);
8027 /* Make our second (and final) pass over the list of formal parameter types
8028 and output DIEs to represent those types (as necessary). */
8029 for (link = TYPE_ARG_TYPES (function_or_method_type);
8030 link;
8031 link = TREE_CHAIN (link))
8033 formal_type = TREE_VALUE (link);
8034 if (formal_type == void_type_node)
8035 break;
8037 gen_type_die (formal_type, context_die);
8041 /* We want to generate the DIE for TYPE so that we can generate the
8042 die for MEMBER, which has been defined; we will need to refer back
8043 to the member declaration nested within TYPE. If we're trying to
8044 generate minimal debug info for TYPE, processing TYPE won't do the
8045 trick; we need to attach the member declaration by hand. */
8047 static void
8048 gen_type_die_for_member (type, member, context_die)
8049 tree type, member;
8050 dw_die_ref context_die;
8052 gen_type_die (type, context_die);
8054 /* If we're trying to avoid duplicate debug info, we may not have
8055 emitted the member decl for this function. Emit it now. */
8056 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))
8057 && ! lookup_decl_die (member))
8059 if (decl_ultimate_origin (member))
8060 abort ();
8062 push_decl_scope (type);
8063 if (TREE_CODE (member) == FUNCTION_DECL)
8064 gen_subprogram_die (member, lookup_type_die (type));
8065 else
8066 gen_variable_die (member, lookup_type_die (type));
8067 pop_decl_scope ();
8071 /* Generate the DWARF2 info for the "abstract" instance
8072 of a function which we may later generate inlined and/or
8073 out-of-line instances of. */
8075 static void
8076 gen_abstract_function (decl)
8077 tree decl;
8079 register dw_die_ref old_die = lookup_decl_die (decl);
8080 tree save_fn;
8082 if (old_die && get_AT_unsigned (old_die, DW_AT_inline))
8083 /* We've already generated the abstract instance. */
8084 return;
8086 save_fn = current_function_decl;
8087 current_function_decl = decl;
8089 set_decl_abstract_flags (decl, 1);
8090 dwarf2out_decl (decl);
8091 set_decl_abstract_flags (decl, 0);
8093 current_function_decl = save_fn;
8096 /* Generate a DIE to represent a declared function (either file-scope or
8097 block-local). */
8099 static void
8100 gen_subprogram_die (decl, context_die)
8101 register tree decl;
8102 register dw_die_ref context_die;
8104 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8105 register tree origin = decl_ultimate_origin (decl);
8106 register dw_die_ref subr_die;
8107 register rtx fp_reg;
8108 register tree fn_arg_types;
8109 register tree outer_scope;
8110 register dw_die_ref old_die = lookup_decl_die (decl);
8111 register int declaration = (current_function_decl != decl
8112 || class_scope_p (context_die));
8114 /* Note that it is possible to have both DECL_ABSTRACT and `declaration'
8115 be true, if we started to generate the abstract instance of an inline,
8116 decided to output its containing class, and proceeded to emit the
8117 declaration of the inline from the member list for the class. In that
8118 case, `declaration' takes priority; we'll get back to the abstract
8119 instance when we're done with the class. */
8121 if (origin != NULL)
8123 if (declaration && ! local_scope_p (context_die))
8124 abort ();
8126 subr_die = new_die (DW_TAG_subprogram, context_die);
8127 add_abstract_origin_attribute (subr_die, origin);
8129 else if (old_die && DECL_ABSTRACT (decl)
8130 && get_AT_unsigned (old_die, DW_AT_inline))
8132 /* This must be a redefinition of an extern inline function.
8133 We can just reuse the old die here. */
8134 subr_die = old_die;
8136 /* Clear out the inlined attribute and parm types. */
8137 remove_AT (subr_die, DW_AT_inline);
8138 remove_children (subr_die);
8140 else if (old_die)
8142 register unsigned file_index
8143 = lookup_filename (DECL_SOURCE_FILE (decl));
8145 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8147 /* ??? This can happen if there is a bug in the program, for
8148 instance, if it has duplicate function definitions. Ideally,
8149 we should detect this case and ignore it. For now, if we have
8150 already reported an error, any error at all, then assume that
8151 we got here because of a input error, not a dwarf2 bug. */
8152 if (errorcount)
8153 return;
8154 abort ();
8157 /* If the definition comes from the same place as the declaration,
8158 maybe use the old DIE. We always want the DIE for this function
8159 that has the *_pc attributes to be under comp_unit_die so the
8160 debugger can find it. For inlines, that is the concrete instance,
8161 so we can use the old DIE here. For non-inline methods, we want a
8162 specification DIE at toplevel, so we need a new DIE. For local
8163 class methods, this doesn't apply; we just use the old DIE. */
8164 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8165 || context_die == NULL)
8166 && (DECL_ARTIFICIAL (decl)
8167 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8168 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8169 == (unsigned)DECL_SOURCE_LINE (decl)))))
8171 subr_die = old_die;
8173 /* Clear out the declaration attribute and the parm types. */
8174 remove_AT (subr_die, DW_AT_declaration);
8175 remove_children (subr_die);
8177 else
8179 subr_die = new_die (DW_TAG_subprogram, context_die);
8180 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8181 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8182 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8183 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8184 != (unsigned)DECL_SOURCE_LINE (decl))
8185 add_AT_unsigned
8186 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8189 else
8191 subr_die = new_die (DW_TAG_subprogram, context_die);
8193 if (TREE_PUBLIC (decl))
8194 add_AT_flag (subr_die, DW_AT_external, 1);
8196 add_name_and_src_coords_attributes (subr_die, decl);
8197 if (debug_info_level > DINFO_LEVEL_TERSE)
8199 register tree type = TREE_TYPE (decl);
8201 add_prototyped_attribute (subr_die, type);
8202 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8205 add_pure_or_virtual_attribute (subr_die, decl);
8206 if (DECL_ARTIFICIAL (decl))
8207 add_AT_flag (subr_die, DW_AT_artificial, 1);
8208 if (TREE_PROTECTED (decl))
8209 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8210 else if (TREE_PRIVATE (decl))
8211 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8214 if (declaration)
8216 if (! origin)
8217 add_AT_flag (subr_die, DW_AT_declaration, 1);
8219 /* The first time we see a member function, it is in the context of
8220 the class to which it belongs. We make sure of this by emitting
8221 the class first. The next time is the definition, which is
8222 handled above. The two may come from the same source text. */
8223 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl))
8224 equate_decl_number_to_die (decl, subr_die);
8226 else if (DECL_ABSTRACT (decl))
8228 if (DECL_INLINE (decl) && !flag_no_inline)
8230 /* ??? Checking DECL_DEFER_OUTPUT is correct for static
8231 inline functions, but not for extern inline functions.
8232 We can't get this completely correct because information
8233 about whether the function was declared inline is not
8234 saved anywhere. */
8235 if (DECL_DEFER_OUTPUT (decl))
8236 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8237 else
8238 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8240 else
8241 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined);
8243 equate_decl_number_to_die (decl, subr_die);
8245 else if (!DECL_EXTERNAL (decl))
8247 if (origin == NULL_TREE)
8248 equate_decl_number_to_die (decl, subr_die);
8250 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8251 current_funcdef_number);
8252 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8253 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8254 current_funcdef_number);
8255 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8257 add_pubname (decl, subr_die);
8258 add_arange (decl, subr_die);
8260 #ifdef MIPS_DEBUGGING_INFO
8261 /* Add a reference to the FDE for this routine. */
8262 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8263 #endif
8265 /* Define the "frame base" location for this routine. We use the
8266 frame pointer or stack pointer registers, since the RTL for local
8267 variables is relative to one of them. */
8268 fp_reg
8269 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8270 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8272 #if 0
8273 /* ??? This fails for nested inline functions, because context_display
8274 is not part of the state saved/restored for inline functions. */
8275 if (current_function_needs_context)
8276 add_AT_location_description (subr_die, DW_AT_static_link,
8277 lookup_static_chain (decl));
8278 #endif
8281 /* Now output descriptions of the arguments for this function. This gets
8282 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8283 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8284 `...' at the end of the formal parameter list. In order to find out if
8285 there was a trailing ellipsis or not, we must instead look at the type
8286 associated with the FUNCTION_DECL. This will be a node of type
8287 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8288 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8289 an ellipsis at the end. */
8291 /* In the case where we are describing a mere function declaration, all we
8292 need to do here (and all we *can* do here) is to describe the *types* of
8293 its formal parameters. */
8294 if (debug_info_level <= DINFO_LEVEL_TERSE)
8296 else if (declaration)
8297 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8298 else
8300 /* Generate DIEs to represent all known formal parameters */
8301 register tree arg_decls = DECL_ARGUMENTS (decl);
8302 register tree parm;
8304 /* When generating DIEs, generate the unspecified_parameters DIE
8305 instead if we come across the arg "__builtin_va_alist" */
8306 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8307 if (TREE_CODE (parm) == PARM_DECL)
8309 if (DECL_NAME (parm)
8310 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8311 "__builtin_va_alist"))
8312 gen_unspecified_parameters_die (parm, subr_die);
8313 else
8314 gen_decl_die (parm, subr_die);
8317 /* Decide whether we need a unspecified_parameters DIE at the end.
8318 There are 2 more cases to do this for: 1) the ansi ... declaration -
8319 this is detectable when the end of the arg list is not a
8320 void_type_node 2) an unprototyped function declaration (not a
8321 definition). This just means that we have no info about the
8322 parameters at all. */
8323 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8324 if (fn_arg_types != NULL)
8326 /* this is the prototyped case, check for ... */
8327 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8328 gen_unspecified_parameters_die (decl, subr_die);
8330 else if (DECL_INITIAL (decl) == NULL_TREE)
8331 gen_unspecified_parameters_die (decl, subr_die);
8334 /* Output Dwarf info for all of the stuff within the body of the function
8335 (if it has one - it may be just a declaration). */
8336 outer_scope = DECL_INITIAL (decl);
8338 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8339 node created to represent a function. This outermost BLOCK actually
8340 represents the outermost binding contour for the function, i.e. the
8341 contour in which the function's formal parameters and labels get
8342 declared. Curiously, it appears that the front end doesn't actually
8343 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8344 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8345 list for the function instead.) The BLOCK_VARS list for the
8346 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8347 the function however, and we output DWARF info for those in
8348 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8349 node representing the function's outermost pair of curly braces, and
8350 any blocks used for the base and member initializers of a C++
8351 constructor function. */
8352 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8354 current_function_has_inlines = 0;
8355 decls_for_scope (outer_scope, subr_die, 0);
8357 #if 0 && defined (MIPS_DEBUGGING_INFO)
8358 if (current_function_has_inlines)
8360 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8361 if (! comp_unit_has_inlines)
8363 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8364 comp_unit_has_inlines = 1;
8367 #endif
8371 /* Generate a DIE to represent a declared data object. */
8373 static void
8374 gen_variable_die (decl, context_die)
8375 register tree decl;
8376 register dw_die_ref context_die;
8378 register tree origin = decl_ultimate_origin (decl);
8379 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8381 dw_die_ref old_die = lookup_decl_die (decl);
8382 int declaration = (DECL_EXTERNAL (decl)
8383 || class_scope_p (context_die));
8385 if (origin != NULL)
8386 add_abstract_origin_attribute (var_die, origin);
8387 /* Loop unrolling can create multiple blocks that refer to the same
8388 static variable, so we must test for the DW_AT_declaration flag. */
8389 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8390 copy decls and set the DECL_ABSTRACT flag on them instead of
8391 sharing them. */
8392 else if (old_die && TREE_STATIC (decl)
8393 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8395 /* This is a definition of a C++ class level static. */
8396 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8397 if (DECL_NAME (decl))
8399 register unsigned file_index
8400 = lookup_filename (DECL_SOURCE_FILE (decl));
8402 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8403 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8405 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8406 != (unsigned)DECL_SOURCE_LINE (decl))
8408 add_AT_unsigned (var_die, DW_AT_decl_line,
8409 DECL_SOURCE_LINE (decl));
8412 else
8414 add_name_and_src_coords_attributes (var_die, decl);
8415 add_type_attribute (var_die, TREE_TYPE (decl),
8416 TREE_READONLY (decl),
8417 TREE_THIS_VOLATILE (decl), context_die);
8419 if (TREE_PUBLIC (decl))
8420 add_AT_flag (var_die, DW_AT_external, 1);
8422 if (DECL_ARTIFICIAL (decl))
8423 add_AT_flag (var_die, DW_AT_artificial, 1);
8425 if (TREE_PROTECTED (decl))
8426 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8428 else if (TREE_PRIVATE (decl))
8429 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8432 if (declaration)
8433 add_AT_flag (var_die, DW_AT_declaration, 1);
8435 if (class_scope_p (context_die) || DECL_ABSTRACT (decl))
8436 equate_decl_number_to_die (decl, var_die);
8438 if (! declaration && ! DECL_ABSTRACT (decl))
8440 add_location_or_const_value_attribute (var_die, decl);
8441 add_pubname (decl, var_die);
8445 /* Generate a DIE to represent a label identifier. */
8447 static void
8448 gen_label_die (decl, context_die)
8449 register tree decl;
8450 register dw_die_ref context_die;
8452 register tree origin = decl_ultimate_origin (decl);
8453 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8454 register rtx insn;
8455 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8456 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8458 if (origin != NULL)
8459 add_abstract_origin_attribute (lbl_die, origin);
8460 else
8461 add_name_and_src_coords_attributes (lbl_die, decl);
8463 if (DECL_ABSTRACT (decl))
8464 equate_decl_number_to_die (decl, lbl_die);
8465 else
8467 insn = DECL_RTL (decl);
8469 /* Deleted labels are programmer specified labels which have been
8470 eliminated because of various optimisations. We still emit them
8471 here so that it is possible to put breakpoints on them. */
8472 if (GET_CODE (insn) == CODE_LABEL
8473 || ((GET_CODE (insn) == NOTE
8474 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8476 /* When optimization is enabled (via -O) some parts of the compiler
8477 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8478 represent source-level labels which were explicitly declared by
8479 the user. This really shouldn't be happening though, so catch
8480 it if it ever does happen. */
8481 if (INSN_DELETED_P (insn))
8482 abort ();
8484 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8485 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8486 (unsigned) INSN_UID (insn));
8487 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8492 /* Generate a DIE for a lexical block. */
8494 static void
8495 gen_lexical_block_die (stmt, context_die, depth)
8496 register tree stmt;
8497 register dw_die_ref context_die;
8498 int depth;
8500 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8501 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8503 if (! BLOCK_ABSTRACT (stmt))
8505 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8506 next_block_number);
8507 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8508 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8509 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8512 decls_for_scope (stmt, stmt_die, depth);
8515 /* Generate a DIE for an inlined subprogram. */
8517 static void
8518 gen_inlined_subroutine_die (stmt, context_die, depth)
8519 register tree stmt;
8520 register dw_die_ref context_die;
8521 int depth;
8523 if (! BLOCK_ABSTRACT (stmt))
8525 register dw_die_ref subr_die
8526 = new_die (DW_TAG_inlined_subroutine, context_die);
8527 register tree decl = block_ultimate_origin (stmt);
8528 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8530 /* Emit info for the abstract instance first, if we haven't yet. */
8531 gen_abstract_function (decl);
8533 add_abstract_origin_attribute (subr_die, decl);
8534 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8535 next_block_number);
8536 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8537 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8538 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8539 decls_for_scope (stmt, subr_die, depth);
8540 current_function_has_inlines = 1;
8544 /* Generate a DIE for a field in a record, or structure. */
8546 static void
8547 gen_field_die (decl, context_die)
8548 register tree decl;
8549 register dw_die_ref context_die;
8551 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8553 add_name_and_src_coords_attributes (decl_die, decl);
8554 add_type_attribute (decl_die, member_declared_type (decl),
8555 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8556 context_die);
8558 /* If this is a bit field... */
8559 if (DECL_BIT_FIELD_TYPE (decl))
8561 add_byte_size_attribute (decl_die, decl);
8562 add_bit_size_attribute (decl_die, decl);
8563 add_bit_offset_attribute (decl_die, decl);
8566 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8567 add_data_member_location_attribute (decl_die, decl);
8569 if (DECL_ARTIFICIAL (decl))
8570 add_AT_flag (decl_die, DW_AT_artificial, 1);
8572 if (TREE_PROTECTED (decl))
8573 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8575 else if (TREE_PRIVATE (decl))
8576 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8579 #if 0
8580 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8581 Use modified_type_die instead.
8582 We keep this code here just in case these types of DIEs may be needed to
8583 represent certain things in other languages (e.g. Pascal) someday. */
8584 static void
8585 gen_pointer_type_die (type, context_die)
8586 register tree type;
8587 register dw_die_ref context_die;
8589 register dw_die_ref ptr_die
8590 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8592 equate_type_number_to_die (type, ptr_die);
8593 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8594 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8597 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8598 Use modified_type_die instead.
8599 We keep this code here just in case these types of DIEs may be needed to
8600 represent certain things in other languages (e.g. Pascal) someday. */
8601 static void
8602 gen_reference_type_die (type, context_die)
8603 register tree type;
8604 register dw_die_ref context_die;
8606 register dw_die_ref ref_die
8607 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8609 equate_type_number_to_die (type, ref_die);
8610 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8611 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8613 #endif
8615 /* Generate a DIE for a pointer to a member type. */
8616 static void
8617 gen_ptr_to_mbr_type_die (type, context_die)
8618 register tree type;
8619 register dw_die_ref context_die;
8621 register dw_die_ref ptr_die
8622 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8624 equate_type_number_to_die (type, ptr_die);
8625 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8626 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8627 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8630 /* Generate the DIE for the compilation unit. */
8632 static dw_die_ref
8633 gen_compile_unit_die (filename)
8634 register const char *filename;
8636 register dw_die_ref die;
8637 char producer[250];
8638 char *wd = getpwd ();
8639 int language;
8641 die = new_die (DW_TAG_compile_unit, NULL);
8642 add_name_attribute (die, filename);
8644 if (wd != NULL && filename[0] != DIR_SEPARATOR)
8645 add_AT_string (die, DW_AT_comp_dir, wd);
8647 sprintf (producer, "%s %s", language_string, version_string);
8649 #ifdef MIPS_DEBUGGING_INFO
8650 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8651 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8652 not appear in the producer string, the debugger reaches the conclusion
8653 that the object file is stripped and has no debugging information.
8654 To get the MIPS/SGI debugger to believe that there is debugging
8655 information in the object file, we add a -g to the producer string. */
8656 if (debug_info_level > DINFO_LEVEL_TERSE)
8657 strcat (producer, " -g");
8658 #endif
8660 add_AT_string (die, DW_AT_producer, producer);
8662 if (strcmp (language_string, "GNU C++") == 0)
8663 language = DW_LANG_C_plus_plus;
8664 else if (strcmp (language_string, "GNU Ada") == 0)
8665 language = DW_LANG_Ada83;
8666 else if (strcmp (language_string, "GNU F77") == 0)
8667 language = DW_LANG_Fortran77;
8668 else if (strcmp (language_string, "GNU Pascal") == 0)
8669 language = DW_LANG_Pascal83;
8670 else if (flag_traditional)
8671 language = DW_LANG_C;
8672 else
8673 language = DW_LANG_C89;
8675 add_AT_unsigned (die, DW_AT_language, language);
8677 return die;
8680 /* Generate a DIE for a string type. */
8682 static void
8683 gen_string_type_die (type, context_die)
8684 register tree type;
8685 register dw_die_ref context_die;
8687 register dw_die_ref type_die
8688 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8690 equate_type_number_to_die (type, type_die);
8692 /* Fudge the string length attribute for now. */
8694 /* TODO: add string length info.
8695 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8696 bound_representation (upper_bound, 0, 'u'); */
8699 /* Generate the DIE for a base class. */
8701 static void
8702 gen_inheritance_die (binfo, context_die)
8703 register tree binfo;
8704 register dw_die_ref context_die;
8706 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8708 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8709 add_data_member_location_attribute (die, binfo);
8711 if (TREE_VIA_VIRTUAL (binfo))
8712 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8713 if (TREE_VIA_PUBLIC (binfo))
8714 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8715 else if (TREE_VIA_PROTECTED (binfo))
8716 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8719 /* Generate a DIE for a class member. */
8721 static void
8722 gen_member_die (type, context_die)
8723 register tree type;
8724 register dw_die_ref context_die;
8726 register tree member;
8727 dw_die_ref child;
8729 /* If this is not an incomplete type, output descriptions of each of its
8730 members. Note that as we output the DIEs necessary to represent the
8731 members of this record or union type, we will also be trying to output
8732 DIEs to represent the *types* of those members. However the `type'
8733 function (above) will specifically avoid generating type DIEs for member
8734 types *within* the list of member DIEs for this (containing) type execpt
8735 for those types (of members) which are explicitly marked as also being
8736 members of this (containing) type themselves. The g++ front- end can
8737 force any given type to be treated as a member of some other
8738 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8739 to point to the TREE node representing the appropriate (containing)
8740 type. */
8742 /* First output info about the base classes. */
8743 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8745 register tree bases = TYPE_BINFO_BASETYPES (type);
8746 register int n_bases = TREE_VEC_LENGTH (bases);
8747 register int i;
8749 for (i = 0; i < n_bases; i++)
8750 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8753 /* Now output info about the data members and type members. */
8754 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8756 /* If we thought we were generating minimal debug info for TYPE
8757 and then changed our minds, some of the member declarations
8758 may have already been defined. Don't define them again, but
8759 do put them in the right order. */
8761 child = lookup_decl_die (member);
8762 if (child)
8763 splice_child_die (context_die, child);
8764 else
8765 gen_decl_die (member, context_die);
8768 /* Now output info about the function members (if any). */
8769 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8771 child = lookup_decl_die (member);
8772 if (child)
8773 splice_child_die (context_die, child);
8774 else
8775 gen_decl_die (member, context_die);
8779 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
8780 is set, we pretend that the type was never defined, so we only get the
8781 member DIEs needed by later specification DIEs. */
8783 static void
8784 gen_struct_or_union_type_die (type, context_die)
8785 register tree type;
8786 register dw_die_ref context_die;
8788 register dw_die_ref type_die = lookup_type_die (type);
8789 register dw_die_ref scope_die = 0;
8790 register int nested = 0;
8791 int complete = (TYPE_SIZE (type)
8792 && (! TYPE_STUB_DECL (type)
8793 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type))));
8795 if (type_die && ! complete)
8796 return;
8798 if (TYPE_CONTEXT (type) != NULL_TREE
8799 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8800 nested = 1;
8802 scope_die = scope_die_for (type, context_die);
8804 if (! type_die || (nested && scope_die == comp_unit_die))
8805 /* First occurrence of type or toplevel definition of nested class. */
8807 register dw_die_ref old_die = type_die;
8809 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8810 ? DW_TAG_structure_type : DW_TAG_union_type,
8811 scope_die);
8812 equate_type_number_to_die (type, type_die);
8813 add_name_attribute (type_die, type_tag (type));
8814 if (old_die)
8815 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8817 else
8818 remove_AT (type_die, DW_AT_declaration);
8820 /* If this type has been completed, then give it a byte_size attribute and
8821 then give a list of members. */
8822 if (complete)
8824 /* Prevent infinite recursion in cases where the type of some member of
8825 this type is expressed in terms of this type itself. */
8826 TREE_ASM_WRITTEN (type) = 1;
8827 add_byte_size_attribute (type_die, type);
8828 if (TYPE_STUB_DECL (type) != NULL_TREE)
8829 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8831 /* If the first reference to this type was as the return type of an
8832 inline function, then it may not have a parent. Fix this now. */
8833 if (type_die->die_parent == NULL)
8834 add_child_die (scope_die, type_die);
8836 push_decl_scope (type);
8837 gen_member_die (type, type_die);
8838 pop_decl_scope ();
8840 /* GNU extension: Record what type our vtable lives in. */
8841 if (TYPE_VFIELD (type))
8843 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8845 gen_type_die (vtype, context_die);
8846 add_AT_die_ref (type_die, DW_AT_containing_type,
8847 lookup_type_die (vtype));
8850 else
8852 add_AT_flag (type_die, DW_AT_declaration, 1);
8854 /* We don't need to do this for function-local types. */
8855 if (context_die)
8856 add_incomplete_type (type);
8860 /* Generate a DIE for a subroutine _type_. */
8862 static void
8863 gen_subroutine_type_die (type, context_die)
8864 register tree type;
8865 register dw_die_ref context_die;
8867 register tree return_type = TREE_TYPE (type);
8868 register dw_die_ref subr_die
8869 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8871 equate_type_number_to_die (type, subr_die);
8872 add_prototyped_attribute (subr_die, type);
8873 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8874 gen_formal_types_die (type, subr_die);
8877 /* Generate a DIE for a type definition */
8879 static void
8880 gen_typedef_die (decl, context_die)
8881 register tree decl;
8882 register dw_die_ref context_die;
8884 register dw_die_ref type_die;
8885 register tree origin;
8887 if (TREE_ASM_WRITTEN (decl))
8888 return;
8889 TREE_ASM_WRITTEN (decl) = 1;
8891 type_die = new_die (DW_TAG_typedef, context_die);
8892 origin = decl_ultimate_origin (decl);
8893 if (origin != NULL)
8894 add_abstract_origin_attribute (type_die, origin);
8895 else
8897 register tree type;
8898 add_name_and_src_coords_attributes (type_die, decl);
8899 if (DECL_ORIGINAL_TYPE (decl))
8901 type = DECL_ORIGINAL_TYPE (decl);
8902 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8904 else
8905 type = TREE_TYPE (decl);
8906 add_type_attribute (type_die, type, TREE_READONLY (decl),
8907 TREE_THIS_VOLATILE (decl), context_die);
8910 if (DECL_ABSTRACT (decl))
8911 equate_decl_number_to_die (decl, type_die);
8914 /* Generate a type description DIE. */
8916 static void
8917 gen_type_die (type, context_die)
8918 register tree type;
8919 register dw_die_ref context_die;
8921 int need_pop;
8923 if (type == NULL_TREE || type == error_mark_node)
8924 return;
8926 /* We are going to output a DIE to represent the unqualified version of
8927 this type (i.e. without any const or volatile qualifiers) so get the
8928 main variant (i.e. the unqualified version) of this type now. */
8929 type = type_main_variant (type);
8931 if (TREE_ASM_WRITTEN (type))
8932 return;
8934 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8935 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8937 TREE_ASM_WRITTEN (type) = 1;
8938 gen_decl_die (TYPE_NAME (type), context_die);
8939 return;
8942 switch (TREE_CODE (type))
8944 case ERROR_MARK:
8945 break;
8947 case POINTER_TYPE:
8948 case REFERENCE_TYPE:
8949 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
8950 ensures that the gen_type_die recursion will terminate even if the
8951 type is recursive. Recursive types are possible in Ada. */
8952 /* ??? We could perhaps do this for all types before the switch
8953 statement. */
8954 TREE_ASM_WRITTEN (type) = 1;
8956 /* For these types, all that is required is that we output a DIE (or a
8957 set of DIEs) to represent the "basis" type. */
8958 gen_type_die (TREE_TYPE (type), context_die);
8959 break;
8961 case OFFSET_TYPE:
8962 /* This code is used for C++ pointer-to-data-member types.
8963 Output a description of the relevant class type. */
8964 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
8966 /* Output a description of the type of the object pointed to. */
8967 gen_type_die (TREE_TYPE (type), context_die);
8969 /* Now output a DIE to represent this pointer-to-data-member type
8970 itself. */
8971 gen_ptr_to_mbr_type_die (type, context_die);
8972 break;
8974 case SET_TYPE:
8975 gen_type_die (TYPE_DOMAIN (type), context_die);
8976 gen_set_type_die (type, context_die);
8977 break;
8979 case FILE_TYPE:
8980 gen_type_die (TREE_TYPE (type), context_die);
8981 abort (); /* No way to represent these in Dwarf yet! */
8982 break;
8984 case FUNCTION_TYPE:
8985 /* Force out return type (in case it wasn't forced out already). */
8986 gen_type_die (TREE_TYPE (type), context_die);
8987 gen_subroutine_type_die (type, context_die);
8988 break;
8990 case METHOD_TYPE:
8991 /* Force out return type (in case it wasn't forced out already). */
8992 gen_type_die (TREE_TYPE (type), context_die);
8993 gen_subroutine_type_die (type, context_die);
8994 break;
8996 case ARRAY_TYPE:
8997 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
8999 gen_type_die (TREE_TYPE (type), context_die);
9000 gen_string_type_die (type, context_die);
9002 else
9003 gen_array_type_die (type, context_die);
9004 break;
9006 case ENUMERAL_TYPE:
9007 case RECORD_TYPE:
9008 case UNION_TYPE:
9009 case QUAL_UNION_TYPE:
9010 /* If this is a nested type whose containing class hasn't been
9011 written out yet, writing it out will cover this one, too.
9012 This does not apply to instantiations of member class templates;
9013 they need to be added to the containing class as they are
9014 generated. FIXME: This hurts the idea of combining type decls
9015 from multiple TUs, since we can't predict what set of template
9016 instantiations we'll get. */
9017 if (TYPE_CONTEXT (type)
9018 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9019 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9021 gen_type_die (TYPE_CONTEXT (type), context_die);
9023 if (TREE_ASM_WRITTEN (type))
9024 return;
9026 /* If that failed, attach ourselves to the stub. */
9027 push_decl_scope (TYPE_CONTEXT (type));
9028 context_die = lookup_type_die (TYPE_CONTEXT (type));
9029 need_pop = 1;
9031 else
9032 need_pop = 0;
9034 if (TREE_CODE (type) == ENUMERAL_TYPE)
9035 gen_enumeration_type_die (type, context_die);
9036 else
9037 gen_struct_or_union_type_die (type, context_die);
9039 if (need_pop)
9040 pop_decl_scope ();
9042 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9043 it up if it is ever completed. gen_*_type_die will set it for us
9044 when appropriate. */
9045 return;
9047 case VOID_TYPE:
9048 case INTEGER_TYPE:
9049 case REAL_TYPE:
9050 case COMPLEX_TYPE:
9051 case BOOLEAN_TYPE:
9052 case CHAR_TYPE:
9053 /* No DIEs needed for fundamental types. */
9054 break;
9056 case LANG_TYPE:
9057 /* No Dwarf representation currently defined. */
9058 break;
9060 default:
9061 abort ();
9064 TREE_ASM_WRITTEN (type) = 1;
9067 /* Generate a DIE for a tagged type instantiation. */
9069 static void
9070 gen_tagged_type_instantiation_die (type, context_die)
9071 register tree type;
9072 register dw_die_ref context_die;
9074 if (type == NULL_TREE || type == error_mark_node)
9075 return;
9077 /* We are going to output a DIE to represent the unqualified version of
9078 this type (i.e. without any const or volatile qualifiers) so make sure
9079 that we have the main variant (i.e. the unqualified version) of this
9080 type now. */
9081 if (type != type_main_variant (type))
9082 abort ();
9084 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is
9085 an instance of an unresolved type. */
9087 switch (TREE_CODE (type))
9089 case ERROR_MARK:
9090 break;
9092 case ENUMERAL_TYPE:
9093 gen_inlined_enumeration_type_die (type, context_die);
9094 break;
9096 case RECORD_TYPE:
9097 gen_inlined_structure_type_die (type, context_die);
9098 break;
9100 case UNION_TYPE:
9101 case QUAL_UNION_TYPE:
9102 gen_inlined_union_type_die (type, context_die);
9103 break;
9105 default:
9106 abort ();
9110 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9111 things which are local to the given block. */
9113 static void
9114 gen_block_die (stmt, context_die, depth)
9115 register tree stmt;
9116 register dw_die_ref context_die;
9117 int depth;
9119 register int must_output_die = 0;
9120 register tree origin;
9121 register tree decl;
9122 register enum tree_code origin_code;
9124 /* Ignore blocks never really used to make RTL. */
9126 if (stmt == NULL_TREE || !TREE_USED (stmt))
9127 return;
9129 /* Determine the "ultimate origin" of this block. This block may be an
9130 inlined instance of an inlined instance of inline function, so we have
9131 to trace all of the way back through the origin chain to find out what
9132 sort of node actually served as the original seed for the creation of
9133 the current block. */
9134 origin = block_ultimate_origin (stmt);
9135 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9137 /* Determine if we need to output any Dwarf DIEs at all to represent this
9138 block. */
9139 if (origin_code == FUNCTION_DECL)
9140 /* The outer scopes for inlinings *must* always be represented. We
9141 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9142 must_output_die = 1;
9143 else
9145 /* In the case where the current block represents an inlining of the
9146 "body block" of an inline function, we must *NOT* output any DIE for
9147 this block because we have already output a DIE to represent the
9148 whole inlined function scope and the "body block" of any function
9149 doesn't really represent a different scope according to ANSI C
9150 rules. So we check here to make sure that this block does not
9151 represent a "body block inlining" before trying to set the
9152 `must_output_die' flag. */
9153 if (! is_body_block (origin ? origin : stmt))
9155 /* Determine if this block directly contains any "significant"
9156 local declarations which we will need to output DIEs for. */
9157 if (debug_info_level > DINFO_LEVEL_TERSE)
9158 /* We are not in terse mode so *any* local declaration counts
9159 as being a "significant" one. */
9160 must_output_die = (BLOCK_VARS (stmt) != NULL);
9161 else
9162 /* We are in terse mode, so only local (nested) function
9163 definitions count as "significant" local declarations. */
9164 for (decl = BLOCK_VARS (stmt);
9165 decl != NULL; decl = TREE_CHAIN (decl))
9166 if (TREE_CODE (decl) == FUNCTION_DECL
9167 && DECL_INITIAL (decl))
9169 must_output_die = 1;
9170 break;
9175 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9176 DIE for any block which contains no significant local declarations at
9177 all. Rather, in such cases we just call `decls_for_scope' so that any
9178 needed Dwarf info for any sub-blocks will get properly generated. Note
9179 that in terse mode, our definition of what constitutes a "significant"
9180 local declaration gets restricted to include only inlined function
9181 instances and local (nested) function definitions. */
9182 if (must_output_die)
9184 if (origin_code == FUNCTION_DECL)
9185 gen_inlined_subroutine_die (stmt, context_die, depth);
9186 else
9187 gen_lexical_block_die (stmt, context_die, depth);
9189 else
9190 decls_for_scope (stmt, context_die, depth);
9193 /* Generate all of the decls declared within a given scope and (recursively)
9194 all of its sub-blocks. */
9196 static void
9197 decls_for_scope (stmt, context_die, depth)
9198 register tree stmt;
9199 register dw_die_ref context_die;
9200 int depth;
9202 register tree decl;
9203 register tree subblocks;
9205 /* Ignore blocks never really used to make RTL. */
9206 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9207 return;
9209 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
9210 next_block_number++;
9212 /* Output the DIEs to represent all of the data objects and typedefs
9213 declared directly within this block but not within any nested
9214 sub-blocks. Also, nested function and tag DIEs have been
9215 generated with a parent of NULL; fix that up now. */
9216 for (decl = BLOCK_VARS (stmt);
9217 decl != NULL; decl = TREE_CHAIN (decl))
9219 register dw_die_ref die;
9221 if (TREE_CODE (decl) == FUNCTION_DECL)
9222 die = lookup_decl_die (decl);
9223 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9224 die = lookup_type_die (TREE_TYPE (decl));
9225 else
9226 die = NULL;
9228 if (die != NULL && die->die_parent == NULL)
9229 add_child_die (context_die, die);
9230 else
9231 gen_decl_die (decl, context_die);
9234 /* Output the DIEs to represent all sub-blocks (and the items declared
9235 therein) of this block. */
9236 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9237 subblocks != NULL;
9238 subblocks = BLOCK_CHAIN (subblocks))
9239 gen_block_die (subblocks, context_die, depth + 1);
9242 /* Is this a typedef we can avoid emitting? */
9244 static inline int
9245 is_redundant_typedef (decl)
9246 register tree decl;
9248 if (TYPE_DECL_IS_STUB (decl))
9249 return 1;
9251 if (DECL_ARTIFICIAL (decl)
9252 && DECL_CONTEXT (decl)
9253 && is_tagged_type (DECL_CONTEXT (decl))
9254 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9255 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9256 /* Also ignore the artificial member typedef for the class name. */
9257 return 1;
9259 return 0;
9262 /* Generate Dwarf debug information for a decl described by DECL. */
9264 static void
9265 gen_decl_die (decl, context_die)
9266 register tree decl;
9267 register dw_die_ref context_die;
9269 register tree origin;
9271 if (TREE_CODE (decl) == ERROR_MARK)
9272 return;
9274 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9275 ignore a function definition, since that would screw up our count of
9276 blocks, and that in turn will completely screw up the labels we will
9277 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9278 subsequent blocks). */
9279 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9280 return;
9282 switch (TREE_CODE (decl))
9284 case CONST_DECL:
9285 /* The individual enumerators of an enum type get output when we output
9286 the Dwarf representation of the relevant enum type itself. */
9287 break;
9289 case FUNCTION_DECL:
9290 /* Don't output any DIEs to represent mere function declarations,
9291 unless they are class members or explicit block externs. */
9292 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9293 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl)))
9294 break;
9296 /* Emit info for the abstract instance first, if we haven't yet. */
9297 origin = decl_ultimate_origin (decl);
9298 if (origin)
9299 gen_abstract_function (origin);
9301 if (debug_info_level > DINFO_LEVEL_TERSE)
9303 /* Before we describe the FUNCTION_DECL itself, make sure that we
9304 have described its return type. */
9305 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9307 /* And its virtual context. */
9308 if (DECL_VINDEX (decl) != NULL_TREE)
9309 gen_type_die (DECL_CONTEXT (decl), context_die);
9311 /* And its containing type. */
9312 origin = decl_class_context (decl);
9313 if (origin != NULL_TREE)
9314 gen_type_die_for_member (origin, decl, context_die);
9317 /* Now output a DIE to represent the function itself. */
9318 gen_subprogram_die (decl, context_die);
9319 break;
9321 case TYPE_DECL:
9322 /* If we are in terse mode, don't generate any DIEs to represent any
9323 actual typedefs. */
9324 if (debug_info_level <= DINFO_LEVEL_TERSE)
9325 break;
9327 /* In the special case of a TYPE_DECL node representing the
9328 declaration of some type tag, if the given TYPE_DECL is marked as
9329 having been instantiated from some other (original) TYPE_DECL node
9330 (e.g. one which was generated within the original definition of an
9331 inline function) we have to generate a special (abbreviated)
9332 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9333 DIE here. */
9334 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE)
9336 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9337 break;
9340 if (is_redundant_typedef (decl))
9341 gen_type_die (TREE_TYPE (decl), context_die);
9342 else
9343 /* Output a DIE to represent the typedef itself. */
9344 gen_typedef_die (decl, context_die);
9345 break;
9347 case LABEL_DECL:
9348 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9349 gen_label_die (decl, context_die);
9350 break;
9352 case VAR_DECL:
9353 /* If we are in terse mode, don't generate any DIEs to represent any
9354 variable declarations or definitions. */
9355 if (debug_info_level <= DINFO_LEVEL_TERSE)
9356 break;
9358 /* Output any DIEs that are needed to specify the type of this data
9359 object. */
9360 gen_type_die (TREE_TYPE (decl), context_die);
9362 /* And its containing type. */
9363 origin = decl_class_context (decl);
9364 if (origin != NULL_TREE)
9365 gen_type_die_for_member (origin, decl, context_die);
9367 /* Now output the DIE to represent the data object itself. This gets
9368 complicated because of the possibility that the VAR_DECL really
9369 represents an inlined instance of a formal parameter for an inline
9370 function. */
9371 origin = decl_ultimate_origin (decl);
9372 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9373 gen_formal_parameter_die (decl, context_die);
9374 else
9375 gen_variable_die (decl, context_die);
9376 break;
9378 case FIELD_DECL:
9379 /* Ignore the nameless fields that are used to skip bits, but
9380 handle C++ anonymous unions. */
9381 if (DECL_NAME (decl) != NULL_TREE
9382 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9384 gen_type_die (member_declared_type (decl), context_die);
9385 gen_field_die (decl, context_die);
9387 break;
9389 case PARM_DECL:
9390 gen_type_die (TREE_TYPE (decl), context_die);
9391 gen_formal_parameter_die (decl, context_die);
9392 break;
9394 case NAMESPACE_DECL:
9395 /* Ignore for now. */
9396 break;
9398 default:
9399 abort ();
9403 /* Add Ada "use" clause information for SGI Workshop debugger. */
9405 void
9406 dwarf2out_add_library_unit_info (filename, context_list)
9407 char *filename;
9408 char *context_list;
9410 unsigned int file_index;
9412 if (filename != NULL)
9414 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9415 tree context_list_decl
9416 = build_decl (LABEL_DECL, get_identifier (context_list),
9417 void_type_node);
9419 TREE_PUBLIC (context_list_decl) = TRUE;
9420 add_name_attribute (unit_die, context_list);
9421 file_index = lookup_filename (filename);
9422 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9423 add_pubname (context_list_decl, unit_die);
9427 /* Write the debugging output for DECL. */
9429 void
9430 dwarf2out_decl (decl)
9431 register tree decl;
9433 register dw_die_ref context_die = comp_unit_die;
9435 if (TREE_CODE (decl) == ERROR_MARK)
9436 return;
9438 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9439 hope that the node in question doesn't represent a function definition.
9440 If it does, then totally ignoring it is bound to screw up our count of
9441 blocks, and that in turn will completely screw up the labels we will
9442 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9443 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9444 own sequence numbers with them!) */
9445 if (DECL_IGNORED_P (decl))
9447 if (TREE_CODE (decl) == FUNCTION_DECL
9448 && DECL_INITIAL (decl) != NULL)
9449 abort ();
9451 return;
9454 switch (TREE_CODE (decl))
9456 case FUNCTION_DECL:
9457 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9458 builtin function. Explicit programmer-supplied declarations of
9459 these same functions should NOT be ignored however. */
9460 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl))
9461 return;
9463 /* What we would really like to do here is to filter out all mere
9464 file-scope declarations of file-scope functions which are never
9465 referenced later within this translation unit (and keep all of ones
9466 that *are* referenced later on) but we aren't clairvoyant, so we have
9467 no idea which functions will be referenced in the future (i.e. later
9468 on within the current translation unit). So here we just ignore all
9469 file-scope function declarations which are not also definitions. If
9470 and when the debugger needs to know something about these functions,
9471 it will have to hunt around and find the DWARF information associated
9472 with the definition of the function. Note that we can't just check
9473 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9474 definitions and which ones represent mere declarations. We have to
9475 check `DECL_INITIAL' instead. That's because the C front-end
9476 supports some weird semantics for "extern inline" function
9477 definitions. These can get inlined within the current translation
9478 unit (an thus, we need to generate DWARF info for their abstract
9479 instances so that the DWARF info for the concrete inlined instances
9480 can have something to refer to) but the compiler never generates any
9481 out-of-lines instances of such things (despite the fact that they
9482 *are* definitions). The important point is that the C front-end
9483 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9484 to generate DWARF for them anyway. Note that the C++ front-end also
9485 plays some similar games for inline function definitions appearing
9486 within include files which also contain
9487 `#pragma interface' pragmas. */
9488 if (DECL_INITIAL (decl) == NULL_TREE)
9489 return;
9491 /* If we're a nested function, initially use a parent of NULL; if we're
9492 a plain function, this will be fixed up in decls_for_scope. If
9493 we're a method, it will be ignored, since we already have a DIE. */
9494 if (decl_function_context (decl))
9495 context_die = NULL;
9497 break;
9499 case VAR_DECL:
9500 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9501 declaration and if the declaration was never even referenced from
9502 within this entire compilation unit. We suppress these DIEs in
9503 order to save space in the .debug section (by eliminating entries
9504 which are probably useless). Note that we must not suppress
9505 block-local extern declarations (whether used or not) because that
9506 would screw-up the debugger's name lookup mechanism and cause it to
9507 miss things which really ought to be in scope at a given point. */
9508 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9509 return;
9511 /* If we are in terse mode, don't generate any DIEs to represent any
9512 variable declarations or definitions. */
9513 if (debug_info_level <= DINFO_LEVEL_TERSE)
9514 return;
9515 break;
9517 case TYPE_DECL:
9518 /* Don't bother trying to generate any DIEs to represent any of the
9519 normal built-in types for the language we are compiling. */
9520 if (DECL_SOURCE_LINE (decl) == 0)
9522 /* OK, we need to generate one for `bool' so GDB knows what type
9523 comparisons have. */
9524 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9525 == DW_LANG_C_plus_plus)
9526 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9527 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9529 return;
9532 /* If we are in terse mode, don't generate any DIEs for types. */
9533 if (debug_info_level <= DINFO_LEVEL_TERSE)
9534 return;
9536 /* If we're a function-scope tag, initially use a parent of NULL;
9537 this will be fixed up in decls_for_scope. */
9538 if (decl_function_context (decl))
9539 context_die = NULL;
9541 break;
9543 default:
9544 return;
9547 gen_decl_die (decl, context_die);
9550 /* Output a marker (i.e. a label) for the beginning of the generated code for
9551 a lexical block. */
9553 void
9554 dwarf2out_begin_block (blocknum)
9555 register unsigned blocknum;
9557 function_section (current_function_decl);
9558 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9561 /* Output a marker (i.e. a label) for the end of the generated code for a
9562 lexical block. */
9564 void
9565 dwarf2out_end_block (blocknum)
9566 register unsigned blocknum;
9568 function_section (current_function_decl);
9569 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9572 /* Output a marker (i.e. a label) at a point in the assembly code which
9573 corresponds to a given source level label. */
9575 void
9576 dwarf2out_label (insn)
9577 register rtx insn;
9579 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9581 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9583 function_section (current_function_decl);
9584 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9585 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9586 (unsigned) INSN_UID (insn));
9590 /* Lookup a filename (in the list of filenames that we know about here in
9591 dwarf2out.c) and return its "index". The index of each (known) filename is
9592 just a unique number which is associated with only that one filename.
9593 We need such numbers for the sake of generating labels
9594 (in the .debug_sfnames section) and references to those
9595 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9596 If the filename given as an argument is not found in our current list,
9597 add it to the list and assign it the next available unique index number.
9598 In order to speed up searches, we remember the index of the filename
9599 was looked up last. This handles the majority of all searches. */
9601 static unsigned
9602 lookup_filename (file_name)
9603 const char *file_name;
9605 static unsigned last_file_lookup_index = 0;
9606 register unsigned i;
9608 /* Check to see if the file name that was searched on the previous call
9609 matches this file name. If so, return the index. */
9610 if (last_file_lookup_index != 0)
9611 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9612 return last_file_lookup_index;
9614 /* Didn't match the previous lookup, search the table */
9615 for (i = 1; i < file_table_in_use; ++i)
9616 if (strcmp (file_name, file_table[i]) == 0)
9618 last_file_lookup_index = i;
9619 return i;
9622 /* Prepare to add a new table entry by making sure there is enough space in
9623 the table to do so. If not, expand the current table. */
9624 if (file_table_in_use == file_table_allocated)
9626 file_table_allocated += FILE_TABLE_INCREMENT;
9627 file_table
9628 = (char **) xrealloc (file_table,
9629 file_table_allocated * sizeof (char *));
9632 /* Add the new entry to the end of the filename table. */
9633 file_table[file_table_in_use] = xstrdup (file_name);
9634 last_file_lookup_index = file_table_in_use++;
9636 return last_file_lookup_index;
9639 /* Output a label to mark the beginning of a source code line entry
9640 and record information relating to this source line, in
9641 'line_info_table' for later output of the .debug_line section. */
9643 void
9644 dwarf2out_line (filename, line)
9645 register const char *filename;
9646 register unsigned line;
9648 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9650 function_section (current_function_decl);
9652 if (DWARF2_ASM_LINE_DEBUG_INFO)
9654 static const char *lastfile;
9656 /* Emit the .file and .loc directives understood by GNU as. */
9657 if (lastfile == 0 || strcmp (filename, lastfile))
9659 if (lastfile == 0)
9660 ggc_add_string_root ((char **) &lastfile, 1);
9662 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9663 lastfile = filename;
9666 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9668 /* Indicate that line number info exists. */
9669 ++line_info_table_in_use;
9671 /* Indicate that multiple line number tables exist. */
9672 if (DECL_SECTION_NAME (current_function_decl))
9673 ++separate_line_info_table_in_use;
9675 else if (DECL_SECTION_NAME (current_function_decl))
9677 register dw_separate_line_info_ref line_info;
9678 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9679 separate_line_info_table_in_use);
9680 if (flag_debug_asm)
9681 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9682 fputc ('\n', asm_out_file);
9684 /* expand the line info table if necessary */
9685 if (separate_line_info_table_in_use
9686 == separate_line_info_table_allocated)
9688 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9689 separate_line_info_table
9690 = (dw_separate_line_info_ref)
9691 xrealloc (separate_line_info_table,
9692 separate_line_info_table_allocated
9693 * sizeof (dw_separate_line_info_entry));
9696 /* Add the new entry at the end of the line_info_table. */
9697 line_info
9698 = &separate_line_info_table[separate_line_info_table_in_use++];
9699 line_info->dw_file_num = lookup_filename (filename);
9700 line_info->dw_line_num = line;
9701 line_info->function = current_funcdef_number;
9703 else
9705 register dw_line_info_ref line_info;
9707 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9708 line_info_table_in_use);
9709 if (flag_debug_asm)
9710 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9711 fputc ('\n', asm_out_file);
9713 /* Expand the line info table if necessary. */
9714 if (line_info_table_in_use == line_info_table_allocated)
9716 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9717 line_info_table
9718 = (dw_line_info_ref)
9719 xrealloc (line_info_table,
9720 (line_info_table_allocated
9721 * sizeof (dw_line_info_entry)));
9724 /* Add the new entry at the end of the line_info_table. */
9725 line_info = &line_info_table[line_info_table_in_use++];
9726 line_info->dw_file_num = lookup_filename (filename);
9727 line_info->dw_line_num = line;
9732 /* Record the beginning of a new source file, for later output
9733 of the .debug_macinfo section. At present, unimplemented. */
9735 void
9736 dwarf2out_start_source_file (filename)
9737 register const char *filename ATTRIBUTE_UNUSED;
9741 /* Record the end of a source file, for later output
9742 of the .debug_macinfo section. At present, unimplemented. */
9744 void
9745 dwarf2out_end_source_file ()
9749 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9750 the tail part of the directive line, i.e. the part which is past the
9751 initial whitespace, #, whitespace, directive-name, whitespace part. */
9753 void
9754 dwarf2out_define (lineno, buffer)
9755 register unsigned lineno ATTRIBUTE_UNUSED;
9756 register const char *buffer ATTRIBUTE_UNUSED;
9758 static int initialized = 0;
9759 if (!initialized)
9761 dwarf2out_start_source_file (primary_filename);
9762 initialized = 1;
9766 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9767 the tail part of the directive line, i.e. the part which is past the
9768 initial whitespace, #, whitespace, directive-name, whitespace part. */
9770 void
9771 dwarf2out_undef (lineno, buffer)
9772 register unsigned lineno ATTRIBUTE_UNUSED;
9773 register const char *buffer ATTRIBUTE_UNUSED;
9777 /* Set up for Dwarf output at the start of compilation. */
9779 void
9780 dwarf2out_init (asm_out_file, main_input_filename)
9781 register FILE *asm_out_file;
9782 register char *main_input_filename;
9784 /* Remember the name of the primary input file. */
9785 primary_filename = main_input_filename;
9787 /* Allocate the initial hunk of the file_table. */
9788 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9789 file_table_allocated = FILE_TABLE_INCREMENT;
9791 /* Skip the first entry - file numbers begin at 1. */
9792 file_table_in_use = 1;
9794 /* Allocate the initial hunk of the decl_die_table. */
9795 decl_die_table
9796 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9797 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9798 decl_die_table_in_use = 0;
9800 /* Allocate the initial hunk of the decl_scope_table. */
9801 decl_scope_table
9802 = (tree *) xcalloc (DECL_SCOPE_TABLE_INCREMENT, sizeof (tree));
9803 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9804 decl_scope_depth = 0;
9806 /* Allocate the initial hunk of the abbrev_die_table. */
9807 abbrev_die_table
9808 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9809 sizeof (dw_die_ref));
9810 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9811 /* Zero-th entry is allocated, but unused */
9812 abbrev_die_table_in_use = 1;
9814 /* Allocate the initial hunk of the line_info_table. */
9815 line_info_table
9816 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9817 sizeof (dw_line_info_entry));
9818 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9819 /* Zero-th entry is allocated, but unused */
9820 line_info_table_in_use = 1;
9822 /* Generate the initial DIE for the .debug section. Note that the (string)
9823 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9824 will (typically) be a relative pathname and that this pathname should be
9825 taken as being relative to the directory from which the compiler was
9826 invoked when the given (base) source file was compiled. */
9827 comp_unit_die = gen_compile_unit_die (main_input_filename);
9829 if (ggc_p)
9831 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray");
9832 ggc_add_rtx_varray_root (&used_rtx_varray, 1);
9835 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9836 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9837 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9838 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9839 else
9840 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9841 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9842 DEBUG_INFO_SECTION_LABEL, 0);
9843 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9844 DEBUG_LINE_SECTION_LABEL, 0);
9846 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9847 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9848 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9850 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9851 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9853 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9854 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9855 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9856 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9859 /* Output stuff that dwarf requires at the end of every file,
9860 and generate the DWARF-2 debugging info. */
9862 void
9863 dwarf2out_finish ()
9865 limbo_die_node *node, *next_node;
9866 dw_die_ref die;
9868 /* Traverse the limbo die list, and add parent/child links. The only
9869 dies without parents that should be here are concrete instances of
9870 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9871 For concrete instances, we can get the parent die from the abstract
9872 instance. */
9873 for (node = limbo_die_list; node; node = next_node)
9875 next_node = node->next;
9876 die = node->die;
9878 if (die->die_parent == NULL)
9880 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin);
9881 if (origin)
9882 add_child_die (origin->die_parent, die);
9883 else if (die == comp_unit_die)
9885 else
9886 abort ();
9888 free (node);
9890 limbo_die_list = NULL;
9892 /* Walk through the list of incomplete types again, trying once more to
9893 emit full debugging info for them. */
9894 retry_incomplete_types ();
9896 /* Traverse the DIE's, reverse their lists of attributes and children,
9897 and add add sibling attributes to those DIE's that have children. */
9898 add_sibling_attributes (comp_unit_die);
9900 /* Output a terminator label for the .text section. */
9901 fputc ('\n', asm_out_file);
9902 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9903 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9905 #if 0
9906 /* Output a terminator label for the .data section. */
9907 fputc ('\n', asm_out_file);
9908 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9909 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9911 /* Output a terminator label for the .bss section. */
9912 fputc ('\n', asm_out_file);
9913 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9914 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9915 #endif
9917 /* Output the source line correspondence table. */
9918 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9920 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9922 fputc ('\n', asm_out_file);
9923 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9924 output_line_info ();
9927 /* We can only use the low/high_pc attributes if all of the code
9928 was in .text. */
9929 if (separate_line_info_table_in_use == 0)
9931 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9932 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9935 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9936 debug_line_section_label);
9939 #if 0 /* unimplemented */
9940 if (debug_info_level >= DINFO_LEVEL_VERBOSE && primary)
9941 add_AT_unsigned (die, DW_AT_macro_info, 0);
9942 #endif
9944 /* Output the abbreviation table. */
9945 fputc ('\n', asm_out_file);
9946 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9947 build_abbrev_table (comp_unit_die);
9948 output_abbrev_section ();
9950 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9951 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9952 calc_die_sizes (comp_unit_die);
9954 /* Output debugging information. */
9955 fputc ('\n', asm_out_file);
9956 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9957 output_compilation_unit_header ();
9958 output_die (comp_unit_die);
9960 if (pubname_table_in_use)
9962 /* Output public names table. */
9963 fputc ('\n', asm_out_file);
9964 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
9965 output_pubnames ();
9968 /* We only put functions in the arange table, so don't write it out if
9969 we don't have any. */
9970 if (fde_table_in_use)
9972 /* Output the address range information. */
9973 fputc ('\n', asm_out_file);
9974 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
9975 output_aranges ();
9978 #endif /* DWARF2_DEBUGGING_INFO */