* cp-tree.h (DECL_LOCAL_FUCNTION_P): New macro.
[official-gcc.git] / gcc / dwarf2out.c
blobc4ee8ca1058fcac6f03ec439fe1400f66f937b47
1 /* Output Dwarf2 format symbol table information from the GNU C compiler.
2 Copyright (C) 1992, 93, 95-98, 1999 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 /* The first part of this file deals with the DWARF 2 frame unwind
25 information, which is also used by the GCC efficient exception handling
26 mechanism. The second part, controlled only by an #ifdef
27 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
28 information. */
30 #include "config.h"
31 #include "system.h"
32 #include "defaults.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "rtl.h"
36 #include "hard-reg-set.h"
37 #include "regs.h"
38 #include "insn-config.h"
39 #include "reload.h"
40 #include "output.h"
41 #include "expr.h"
42 #include "except.h"
43 #include "dwarf2.h"
44 #include "dwarf2out.h"
45 #include "toplev.h"
46 #include "dyn-string.h"
47 #include "ggc.h"
49 /* We cannot use <assert.h> in GCC source, since that would include
50 GCC's assert.h, which may not be compatible with the host compiler. */
51 #undef assert
52 #ifdef NDEBUG
53 # define assert(e)
54 #else
55 # define assert(e) do { if (! (e)) abort (); } while (0)
56 #endif
58 /* Decide whether we want to emit frame unwind information for the current
59 translation unit. */
61 int
62 dwarf2out_do_frame ()
64 return (write_symbols == DWARF2_DEBUG
65 #ifdef DWARF2_FRAME_INFO
66 || DWARF2_FRAME_INFO
67 #endif
68 #ifdef DWARF2_UNWIND_INFO
69 || flag_unwind_tables
70 || (flag_exceptions && ! exceptions_via_longjmp)
71 #endif
75 #if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO)
77 /* How to start an assembler comment. */
78 #ifndef ASM_COMMENT_START
79 #define ASM_COMMENT_START ";#"
80 #endif
82 typedef struct dw_cfi_struct *dw_cfi_ref;
83 typedef struct dw_fde_struct *dw_fde_ref;
84 typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref;
86 /* Call frames are described using a sequence of Call Frame
87 Information instructions. The register number, offset
88 and address fields are provided as possible operands;
89 their use is selected by the opcode field. */
91 typedef union dw_cfi_oprnd_struct
93 unsigned long dw_cfi_reg_num;
94 long int dw_cfi_offset;
95 char *dw_cfi_addr;
97 dw_cfi_oprnd;
99 typedef struct dw_cfi_struct
101 dw_cfi_ref dw_cfi_next;
102 enum dwarf_call_frame_info dw_cfi_opc;
103 dw_cfi_oprnd dw_cfi_oprnd1;
104 dw_cfi_oprnd dw_cfi_oprnd2;
106 dw_cfi_node;
108 /* All call frame descriptions (FDE's) in the GCC generated DWARF
109 refer to a single Common Information Entry (CIE), defined at
110 the beginning of the .debug_frame section. This used of a single
111 CIE obviates the need to keep track of multiple CIE's
112 in the DWARF generation routines below. */
114 typedef struct dw_fde_struct
116 char *dw_fde_begin;
117 char *dw_fde_current_label;
118 char *dw_fde_end;
119 dw_cfi_ref dw_fde_cfi;
121 dw_fde_node;
123 /* Maximum size (in bytes) of an artificially generated label. */
124 #define MAX_ARTIFICIAL_LABEL_BYTES 30
126 /* Make sure we know the sizes of the various types dwarf can describe. These
127 are only defaults. If the sizes are different for your target, you should
128 override these values by defining the appropriate symbols in your tm.h
129 file. */
131 #ifndef CHAR_TYPE_SIZE
132 #define CHAR_TYPE_SIZE BITS_PER_UNIT
133 #endif
134 #ifndef PTR_SIZE
135 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
136 #endif
138 /* The size in bytes of a DWARF field indicating an offset or length
139 relative to a debug info section, specified to be 4 bytes in the DWARF-2
140 specification. The SGI/MIPS ABI defines it to be the same as PTR_SIZE. */
142 #ifndef DWARF_OFFSET_SIZE
143 #define DWARF_OFFSET_SIZE 4
144 #endif
146 #define DWARF_VERSION 2
148 /* Round SIZE up to the nearest BOUNDARY. */
149 #define DWARF_ROUND(SIZE,BOUNDARY) \
150 (((SIZE) + (BOUNDARY) - 1) & ~((BOUNDARY) - 1))
152 /* Offsets recorded in opcodes are a multiple of this alignment factor. */
153 #ifdef STACK_GROWS_DOWNWARD
154 #define DWARF_CIE_DATA_ALIGNMENT (-UNITS_PER_WORD)
155 #else
156 #define DWARF_CIE_DATA_ALIGNMENT UNITS_PER_WORD
157 #endif
159 /* A pointer to the base of a table that contains frame description
160 information for each routine. */
161 static dw_fde_ref fde_table;
163 /* Number of elements currently allocated for fde_table. */
164 static unsigned fde_table_allocated;
166 /* Number of elements in fde_table currently in use. */
167 static unsigned fde_table_in_use;
169 /* Size (in elements) of increments by which we may expand the
170 fde_table. */
171 #define FDE_TABLE_INCREMENT 256
173 /* A list of call frame insns for the CIE. */
174 static dw_cfi_ref cie_cfi_head;
176 /* The number of the current function definition for which debugging
177 information is being generated. These numbers range from 1 up to the
178 maximum number of function definitions contained within the current
179 compilation unit. These numbers are used to create unique label id's
180 unique to each function definition. */
181 static unsigned current_funcdef_number = 0;
183 /* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram
184 attribute that accelerates the lookup of the FDE associated
185 with the subprogram. This variable holds the table index of the FDE
186 associated with the current function (body) definition. */
187 static unsigned current_funcdef_fde;
189 /* Forward declarations for functions defined in this file. */
191 static char *stripattributes PROTO((const char *));
192 static const char *dwarf_cfi_name PROTO((unsigned));
193 static dw_cfi_ref new_cfi PROTO((void));
194 static void add_cfi PROTO((dw_cfi_ref *, dw_cfi_ref));
195 static unsigned long size_of_uleb128 PROTO((unsigned long));
196 static unsigned long size_of_sleb128 PROTO((long));
197 static void output_uleb128 PROTO((unsigned long));
198 static void output_sleb128 PROTO((long));
199 static void add_fde_cfi PROTO((char *, dw_cfi_ref));
200 static void lookup_cfa_1 PROTO((dw_cfi_ref, unsigned long *,
201 long *));
202 static void lookup_cfa PROTO((unsigned long *, long *));
203 static void reg_save PROTO((char *, unsigned, unsigned,
204 long));
205 static void initial_return_save PROTO((rtx));
206 static void output_cfi PROTO((dw_cfi_ref, dw_fde_ref));
207 static void output_call_frame_info PROTO((int));
208 static unsigned reg_number PROTO((rtx));
209 static void dwarf2out_stack_adjust PROTO((rtx));
210 static void dwarf2out_frame_debug_expr PROTO((rtx, char *));
212 /* Definitions of defaults for assembler-dependent names of various
213 pseudo-ops and section names.
214 Theses may be overridden in the tm.h file (if necessary) for a particular
215 assembler. */
217 #ifdef OBJECT_FORMAT_ELF
218 #ifndef UNALIGNED_SHORT_ASM_OP
219 #define UNALIGNED_SHORT_ASM_OP ".2byte"
220 #endif
221 #ifndef UNALIGNED_INT_ASM_OP
222 #define UNALIGNED_INT_ASM_OP ".4byte"
223 #endif
224 #ifndef UNALIGNED_DOUBLE_INT_ASM_OP
225 #define UNALIGNED_DOUBLE_INT_ASM_OP ".8byte"
226 #endif
227 #endif /* OBJECT_FORMAT_ELF */
229 #ifndef ASM_BYTE_OP
230 #define ASM_BYTE_OP ".byte"
231 #endif
233 /* Data and reference forms for relocatable data. */
234 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
235 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
237 /* Pseudo-op for defining a new section. */
238 #ifndef SECTION_ASM_OP
239 #define SECTION_ASM_OP ".section"
240 #endif
242 /* The default format used by the ASM_OUTPUT_SECTION macro (see below) to
243 print the SECTION_ASM_OP and the section name. The default here works for
244 almost all svr4 assemblers, except for the sparc, where the section name
245 must be enclosed in double quotes. (See sparcv4.h). */
246 #ifndef SECTION_FORMAT
247 #ifdef PUSHSECTION_FORMAT
248 #define SECTION_FORMAT PUSHSECTION_FORMAT
249 #else
250 #define SECTION_FORMAT "\t%s\t%s\n"
251 #endif
252 #endif
254 #ifndef FRAME_SECTION
255 #define FRAME_SECTION ".debug_frame"
256 #endif
258 #ifndef FUNC_BEGIN_LABEL
259 #define FUNC_BEGIN_LABEL "LFB"
260 #endif
261 #ifndef FUNC_END_LABEL
262 #define FUNC_END_LABEL "LFE"
263 #endif
264 #define CIE_AFTER_SIZE_LABEL "LSCIE"
265 #define CIE_END_LABEL "LECIE"
266 #define CIE_LENGTH_LABEL "LLCIE"
267 #define FDE_AFTER_SIZE_LABEL "LSFDE"
268 #define FDE_END_LABEL "LEFDE"
269 #define FDE_LENGTH_LABEL "LLFDE"
271 /* Definitions of defaults for various types of primitive assembly language
272 output operations. These may be overridden from within the tm.h file,
273 but typically, that is unnecessary. */
275 #ifndef ASM_OUTPUT_SECTION
276 #define ASM_OUTPUT_SECTION(FILE, SECTION) \
277 fprintf ((FILE), SECTION_FORMAT, SECTION_ASM_OP, SECTION)
278 #endif
280 #ifndef ASM_OUTPUT_DWARF_DATA1
281 #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
282 fprintf ((FILE), "\t%s\t0x%x", ASM_BYTE_OP, (unsigned) (VALUE))
283 #endif
285 #ifndef ASM_OUTPUT_DWARF_DELTA1
286 #define ASM_OUTPUT_DWARF_DELTA1(FILE,LABEL1,LABEL2) \
287 do { fprintf ((FILE), "\t%s\t", ASM_BYTE_OP); \
288 assemble_name (FILE, LABEL1); \
289 fprintf (FILE, "-"); \
290 assemble_name (FILE, LABEL2); \
291 } while (0)
292 #endif
294 #ifdef UNALIGNED_INT_ASM_OP
296 #ifndef UNALIGNED_OFFSET_ASM_OP
297 #define UNALIGNED_OFFSET_ASM_OP \
298 (DWARF_OFFSET_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
299 #endif
301 #ifndef UNALIGNED_WORD_ASM_OP
302 #define UNALIGNED_WORD_ASM_OP \
303 (PTR_SIZE == 8 ? UNALIGNED_DOUBLE_INT_ASM_OP : UNALIGNED_INT_ASM_OP)
304 #endif
306 #ifndef ASM_OUTPUT_DWARF_DELTA2
307 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
308 do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \
309 assemble_name (FILE, LABEL1); \
310 fprintf (FILE, "-"); \
311 assemble_name (FILE, LABEL2); \
312 } while (0)
313 #endif
315 #ifndef ASM_OUTPUT_DWARF_DELTA4
316 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
317 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
318 assemble_name (FILE, LABEL1); \
319 fprintf (FILE, "-"); \
320 assemble_name (FILE, LABEL2); \
321 } while (0)
322 #endif
324 #ifndef ASM_OUTPUT_DWARF_DELTA
325 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
326 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
327 assemble_name (FILE, LABEL1); \
328 fprintf (FILE, "-"); \
329 assemble_name (FILE, LABEL2); \
330 } while (0)
331 #endif
333 #ifndef ASM_OUTPUT_DWARF_ADDR_DELTA
334 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
335 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
336 assemble_name (FILE, LABEL1); \
337 fprintf (FILE, "-"); \
338 assemble_name (FILE, LABEL2); \
339 } while (0)
340 #endif
342 #ifndef ASM_OUTPUT_DWARF_ADDR
343 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
344 do { fprintf ((FILE), "\t%s\t", UNALIGNED_WORD_ASM_OP); \
345 assemble_name (FILE, LABEL); \
346 } while (0)
347 #endif
349 /* ??? This macro takes an RTX in dwarfout.c and a string in dwarf2out.c.
350 We resolve the conflict by creating a new macro ASM_OUTPUT_DWARF2_ADDR_CONST
351 for ports that want to support both DWARF1 and DWARF2. This needs a better
352 solution. See also the comments in sparc/sp64-elf.h. */
353 #ifdef ASM_OUTPUT_DWARF2_ADDR_CONST
354 #undef ASM_OUTPUT_DWARF_ADDR_CONST
355 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
356 ASM_OUTPUT_DWARF2_ADDR_CONST (FILE, ADDR)
357 #endif
359 #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
360 #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,ADDR) \
361 fprintf ((FILE), "\t%s\t%s", UNALIGNED_WORD_ASM_OP, (ADDR))
362 #endif
364 #ifndef ASM_OUTPUT_DWARF_OFFSET4
365 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
366 do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \
367 assemble_name (FILE, LABEL); \
368 } while (0)
369 #endif
371 #ifndef ASM_OUTPUT_DWARF_OFFSET
372 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
373 do { fprintf ((FILE), "\t%s\t", UNALIGNED_OFFSET_ASM_OP); \
374 assemble_name (FILE, LABEL); \
375 } while (0)
376 #endif
378 #ifndef ASM_OUTPUT_DWARF_DATA2
379 #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
380 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_SHORT_ASM_OP, (unsigned) (VALUE))
381 #endif
383 #ifndef ASM_OUTPUT_DWARF_DATA4
384 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
385 fprintf ((FILE), "\t%s\t0x%x", UNALIGNED_INT_ASM_OP, (unsigned) (VALUE))
386 #endif
388 #ifndef ASM_OUTPUT_DWARF_DATA
389 #define ASM_OUTPUT_DWARF_DATA(FILE,VALUE) \
390 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_OFFSET_ASM_OP, \
391 (unsigned long) (VALUE))
392 #endif
394 #ifndef ASM_OUTPUT_DWARF_ADDR_DATA
395 #define ASM_OUTPUT_DWARF_ADDR_DATA(FILE,VALUE) \
396 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_WORD_ASM_OP, \
397 (unsigned long) (VALUE))
398 #endif
400 #ifndef ASM_OUTPUT_DWARF_DATA8
401 #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \
402 do { \
403 if (WORDS_BIG_ENDIAN) \
405 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (HIGH_VALUE));\
406 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (LOW_VALUE));\
408 else \
410 fprintf ((FILE), "\t%s\t0x%lx\n", UNALIGNED_INT_ASM_OP, (LOW_VALUE)); \
411 fprintf ((FILE), "\t%s\t0x%lx", UNALIGNED_INT_ASM_OP, (HIGH_VALUE)); \
413 } while (0)
414 #endif
416 #else /* UNALIGNED_INT_ASM_OP */
418 /* We don't have unaligned support, let's hope the normal output works for
419 .debug_frame. */
421 #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
422 assemble_integer (gen_rtx_SYMBOL_REF (Pmode, LABEL), PTR_SIZE, 1)
424 #define ASM_OUTPUT_DWARF_OFFSET4(FILE,LABEL) \
425 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
427 #define ASM_OUTPUT_DWARF_OFFSET(FILE,LABEL) \
428 assemble_integer (gen_rtx_SYMBOL_REF (SImode, LABEL), 4, 1)
430 #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \
431 assemble_integer (gen_rtx_MINUS (HImode, \
432 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
433 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
434 2, 1)
436 #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \
437 assemble_integer (gen_rtx_MINUS (SImode, \
438 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
439 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
440 4, 1)
442 #define ASM_OUTPUT_DWARF_ADDR_DELTA(FILE,LABEL1,LABEL2) \
443 assemble_integer (gen_rtx_MINUS (Pmode, \
444 gen_rtx_SYMBOL_REF (Pmode, LABEL1), \
445 gen_rtx_SYMBOL_REF (Pmode, LABEL2)), \
446 PTR_SIZE, 1)
448 #define ASM_OUTPUT_DWARF_DELTA(FILE,LABEL1,LABEL2) \
449 ASM_OUTPUT_DWARF_DELTA4 (FILE,LABEL1,LABEL2)
451 #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
452 assemble_integer (GEN_INT (VALUE), 4, 1)
454 #endif /* UNALIGNED_INT_ASM_OP */
456 #ifdef SET_ASM_OP
457 #ifndef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
458 #define ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL(FILE, SY, HI, LO) \
459 do { \
460 fprintf (FILE, "\t%s\t", SET_ASM_OP); \
461 assemble_name (FILE, SY); \
462 fputc (',', FILE); \
463 assemble_name (FILE, HI); \
464 fputc ('-', FILE); \
465 assemble_name (FILE, LO); \
466 } while (0)
467 #endif
468 #endif /* SET_ASM_OP */
470 /* This is similar to the default ASM_OUTPUT_ASCII, except that no trailing
471 newline is produced. When flag_debug_asm is asserted, we add commentary
472 at the end of the line, so we must avoid output of a newline here. */
473 #ifndef ASM_OUTPUT_DWARF_STRING
474 #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
475 do { \
476 register int slen = strlen(P); \
477 register const char *p = (P); \
478 register int i; \
479 fprintf (FILE, "\t.ascii \""); \
480 for (i = 0; i < slen; i++) \
482 register int c = p[i]; \
483 if (c == '\"' || c == '\\') \
484 putc ('\\', FILE); \
485 if (ISPRINT(c)) \
486 putc (c, FILE); \
487 else \
489 fprintf (FILE, "\\%o", c); \
492 fprintf (FILE, "\\0\""); \
494 while (0)
495 #endif
497 /* The DWARF 2 CFA column which tracks the return address. Normally this
498 is the column for PC, or the first column after all of the hard
499 registers. */
500 #ifndef DWARF_FRAME_RETURN_COLUMN
501 #ifdef PC_REGNUM
502 #define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM)
503 #else
504 #define DWARF_FRAME_RETURN_COLUMN FIRST_PSEUDO_REGISTER
505 #endif
506 #endif
508 /* The mapping from gcc register number to DWARF 2 CFA column number. By
509 default, we just provide columns for all registers. */
510 #ifndef DWARF_FRAME_REGNUM
511 #define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG)
512 #endif
514 /* Hook used by __throw. */
517 expand_builtin_dwarf_fp_regnum ()
519 return GEN_INT (DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM));
522 /* The offset from the incoming value of %sp to the top of the stack frame
523 for the current function. */
524 #ifndef INCOMING_FRAME_SP_OFFSET
525 #define INCOMING_FRAME_SP_OFFSET 0
526 #endif
528 /* Return a pointer to a copy of the section string name S with all
529 attributes stripped off, and an asterisk prepended (for assemble_name). */
531 static inline char *
532 stripattributes (s)
533 const char *s;
535 char *stripped = xmalloc (strlen (s) + 2);
536 char *p = stripped;
538 *p++ = '*';
540 while (*s && *s != ',')
541 *p++ = *s++;
543 *p = '\0';
544 return stripped;
547 /* Return the register number described by a given RTL node. */
549 static unsigned
550 reg_number (rtl)
551 register rtx rtl;
553 register unsigned regno = REGNO (rtl);
555 if (regno >= FIRST_PSEUDO_REGISTER)
557 warning ("internal regno botch: regno = %d\n", regno);
558 regno = 0;
561 regno = DBX_REGISTER_NUMBER (regno);
562 return regno;
565 /* Generate code to initialize the register size table. */
567 void
568 expand_builtin_init_dwarf_reg_sizes (address)
569 tree address;
571 int i;
572 enum machine_mode mode = TYPE_MODE (char_type_node);
573 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0);
574 rtx mem = gen_rtx_MEM (mode, addr);
576 for (i = 0; i < FIRST_PSEUDO_REGISTER; ++i)
578 int offset = i * GET_MODE_SIZE (mode);
579 int size = GET_MODE_SIZE (reg_raw_mode[i]);
581 emit_move_insn (change_address (mem, mode,
582 plus_constant (addr, offset)),
583 GEN_INT (size));
587 /* Convert a DWARF call frame info. operation to its string name */
589 static const char *
590 dwarf_cfi_name (cfi_opc)
591 register unsigned cfi_opc;
593 switch (cfi_opc)
595 case DW_CFA_advance_loc:
596 return "DW_CFA_advance_loc";
597 case DW_CFA_offset:
598 return "DW_CFA_offset";
599 case DW_CFA_restore:
600 return "DW_CFA_restore";
601 case DW_CFA_nop:
602 return "DW_CFA_nop";
603 case DW_CFA_set_loc:
604 return "DW_CFA_set_loc";
605 case DW_CFA_advance_loc1:
606 return "DW_CFA_advance_loc1";
607 case DW_CFA_advance_loc2:
608 return "DW_CFA_advance_loc2";
609 case DW_CFA_advance_loc4:
610 return "DW_CFA_advance_loc4";
611 case DW_CFA_offset_extended:
612 return "DW_CFA_offset_extended";
613 case DW_CFA_restore_extended:
614 return "DW_CFA_restore_extended";
615 case DW_CFA_undefined:
616 return "DW_CFA_undefined";
617 case DW_CFA_same_value:
618 return "DW_CFA_same_value";
619 case DW_CFA_register:
620 return "DW_CFA_register";
621 case DW_CFA_remember_state:
622 return "DW_CFA_remember_state";
623 case DW_CFA_restore_state:
624 return "DW_CFA_restore_state";
625 case DW_CFA_def_cfa:
626 return "DW_CFA_def_cfa";
627 case DW_CFA_def_cfa_register:
628 return "DW_CFA_def_cfa_register";
629 case DW_CFA_def_cfa_offset:
630 return "DW_CFA_def_cfa_offset";
632 /* SGI/MIPS specific */
633 case DW_CFA_MIPS_advance_loc8:
634 return "DW_CFA_MIPS_advance_loc8";
636 /* GNU extensions */
637 case DW_CFA_GNU_window_save:
638 return "DW_CFA_GNU_window_save";
639 case DW_CFA_GNU_args_size:
640 return "DW_CFA_GNU_args_size";
642 default:
643 return "DW_CFA_<unknown>";
647 /* Return a pointer to a newly allocated Call Frame Instruction. */
649 static inline dw_cfi_ref
650 new_cfi ()
652 register dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node));
654 cfi->dw_cfi_next = NULL;
655 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0;
656 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0;
658 return cfi;
661 /* Add a Call Frame Instruction to list of instructions. */
663 static inline void
664 add_cfi (list_head, cfi)
665 register dw_cfi_ref *list_head;
666 register dw_cfi_ref cfi;
668 register dw_cfi_ref *p;
670 /* Find the end of the chain. */
671 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next)
674 *p = cfi;
677 /* Generate a new label for the CFI info to refer to. */
679 char *
680 dwarf2out_cfi_label ()
682 static char label[20];
683 static unsigned long label_num = 0;
685 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++);
686 ASM_OUTPUT_LABEL (asm_out_file, label);
688 return label;
691 /* Add CFI to the current fde at the PC value indicated by LABEL if specified,
692 or to the CIE if LABEL is NULL. */
694 static void
695 add_fde_cfi (label, cfi)
696 register char *label;
697 register dw_cfi_ref cfi;
699 if (label)
701 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
703 if (*label == 0)
704 label = dwarf2out_cfi_label ();
706 if (fde->dw_fde_current_label == NULL
707 || strcmp (label, fde->dw_fde_current_label) != 0)
709 register dw_cfi_ref xcfi;
711 fde->dw_fde_current_label = label = xstrdup (label);
713 /* Set the location counter to the new label. */
714 xcfi = new_cfi ();
715 xcfi->dw_cfi_opc = DW_CFA_advance_loc4;
716 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label;
717 add_cfi (&fde->dw_fde_cfi, xcfi);
720 add_cfi (&fde->dw_fde_cfi, cfi);
723 else
724 add_cfi (&cie_cfi_head, cfi);
727 /* Subroutine of lookup_cfa. */
729 static inline void
730 lookup_cfa_1 (cfi, regp, offsetp)
731 register dw_cfi_ref cfi;
732 register unsigned long *regp;
733 register long *offsetp;
735 switch (cfi->dw_cfi_opc)
737 case DW_CFA_def_cfa_offset:
738 *offsetp = cfi->dw_cfi_oprnd1.dw_cfi_offset;
739 break;
740 case DW_CFA_def_cfa_register:
741 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
742 break;
743 case DW_CFA_def_cfa:
744 *regp = cfi->dw_cfi_oprnd1.dw_cfi_reg_num;
745 *offsetp = cfi->dw_cfi_oprnd2.dw_cfi_offset;
746 break;
747 default:
748 break;
752 /* Find the previous value for the CFA. */
754 static void
755 lookup_cfa (regp, offsetp)
756 register unsigned long *regp;
757 register long *offsetp;
759 register dw_cfi_ref cfi;
761 *regp = (unsigned long) -1;
762 *offsetp = 0;
764 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next)
765 lookup_cfa_1 (cfi, regp, offsetp);
767 if (fde_table_in_use)
769 register dw_fde_ref fde = &fde_table[fde_table_in_use - 1];
770 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next)
771 lookup_cfa_1 (cfi, regp, offsetp);
775 /* The current rule for calculating the DWARF2 canonical frame address. */
776 static unsigned long cfa_reg;
777 static long cfa_offset;
779 /* The register used for saving registers to the stack, and its offset
780 from the CFA. */
781 static unsigned cfa_store_reg;
782 static long cfa_store_offset;
784 /* The running total of the size of arguments pushed onto the stack. */
785 static long args_size;
787 /* The last args_size we actually output. */
788 static long old_args_size;
790 /* Entry point to update the canonical frame address (CFA).
791 LABEL is passed to add_fde_cfi. The value of CFA is now to be
792 calculated from REG+OFFSET. */
794 void
795 dwarf2out_def_cfa (label, reg, offset)
796 register char *label;
797 register unsigned reg;
798 register long offset;
800 register dw_cfi_ref cfi;
801 unsigned long old_reg;
802 long old_offset;
804 cfa_reg = reg;
805 cfa_offset = offset;
806 if (cfa_store_reg == reg)
807 cfa_store_offset = offset;
809 reg = DWARF_FRAME_REGNUM (reg);
810 lookup_cfa (&old_reg, &old_offset);
812 if (reg == old_reg && offset == old_offset)
813 return;
815 cfi = new_cfi ();
817 if (reg == old_reg)
819 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset;
820 cfi->dw_cfi_oprnd1.dw_cfi_offset = offset;
823 #ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */
824 else if (offset == old_offset && old_reg != (unsigned long) -1)
826 cfi->dw_cfi_opc = DW_CFA_def_cfa_register;
827 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
829 #endif
831 else
833 cfi->dw_cfi_opc = DW_CFA_def_cfa;
834 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
835 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
838 add_fde_cfi (label, cfi);
841 /* Add the CFI for saving a register. REG is the CFA column number.
842 LABEL is passed to add_fde_cfi.
843 If SREG is -1, the register is saved at OFFSET from the CFA;
844 otherwise it is saved in SREG. */
846 static void
847 reg_save (label, reg, sreg, offset)
848 register char * label;
849 register unsigned reg;
850 register unsigned sreg;
851 register long offset;
853 register dw_cfi_ref cfi = new_cfi ();
855 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg;
857 /* The following comparison is correct. -1 is used to indicate that
858 the value isn't a register number. */
859 if (sreg == (unsigned int) -1)
861 if (reg & ~0x3f)
862 /* The register number won't fit in 6 bits, so we have to use
863 the long form. */
864 cfi->dw_cfi_opc = DW_CFA_offset_extended;
865 else
866 cfi->dw_cfi_opc = DW_CFA_offset;
868 offset /= DWARF_CIE_DATA_ALIGNMENT;
869 if (offset < 0)
870 abort ();
871 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset;
873 else
875 cfi->dw_cfi_opc = DW_CFA_register;
876 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg;
879 add_fde_cfi (label, cfi);
882 /* Add the CFI for saving a register window. LABEL is passed to reg_save.
883 This CFI tells the unwinder that it needs to restore the window registers
884 from the previous frame's window save area.
886 ??? Perhaps we should note in the CIE where windows are saved (instead of
887 assuming 0(cfa)) and what registers are in the window. */
889 void
890 dwarf2out_window_save (label)
891 register char * label;
893 register dw_cfi_ref cfi = new_cfi ();
894 cfi->dw_cfi_opc = DW_CFA_GNU_window_save;
895 add_fde_cfi (label, cfi);
898 /* Add a CFI to update the running total of the size of arguments
899 pushed onto the stack. */
901 void
902 dwarf2out_args_size (label, size)
903 char *label;
904 long size;
906 register dw_cfi_ref cfi;
908 if (size == old_args_size)
909 return;
910 old_args_size = size;
912 cfi = new_cfi ();
913 cfi->dw_cfi_opc = DW_CFA_GNU_args_size;
914 cfi->dw_cfi_oprnd1.dw_cfi_offset = size;
915 add_fde_cfi (label, cfi);
918 /* Entry point for saving a register to the stack. REG is the GCC register
919 number. LABEL and OFFSET are passed to reg_save. */
921 void
922 dwarf2out_reg_save (label, reg, offset)
923 register char * label;
924 register unsigned reg;
925 register long offset;
927 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset);
930 /* Entry point for saving the return address in the stack.
931 LABEL and OFFSET are passed to reg_save. */
933 void
934 dwarf2out_return_save (label, offset)
935 register char * label;
936 register long offset;
938 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset);
941 /* Entry point for saving the return address in a register.
942 LABEL and SREG are passed to reg_save. */
944 void
945 dwarf2out_return_reg (label, sreg)
946 register char * label;
947 register unsigned sreg;
949 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0);
952 /* Record the initial position of the return address. RTL is
953 INCOMING_RETURN_ADDR_RTX. */
955 static void
956 initial_return_save (rtl)
957 register rtx rtl;
959 unsigned int reg = (unsigned int) -1;
960 long offset = 0;
962 switch (GET_CODE (rtl))
964 case REG:
965 /* RA is in a register. */
966 reg = reg_number (rtl);
967 break;
968 case MEM:
969 /* RA is on the stack. */
970 rtl = XEXP (rtl, 0);
971 switch (GET_CODE (rtl))
973 case REG:
974 if (REGNO (rtl) != STACK_POINTER_REGNUM)
975 abort ();
976 offset = 0;
977 break;
978 case PLUS:
979 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
980 abort ();
981 offset = INTVAL (XEXP (rtl, 1));
982 break;
983 case MINUS:
984 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM)
985 abort ();
986 offset = -INTVAL (XEXP (rtl, 1));
987 break;
988 default:
989 abort ();
991 break;
992 case PLUS:
993 /* The return address is at some offset from any value we can
994 actually load. For instance, on the SPARC it is in %i7+8. Just
995 ignore the offset for now; it doesn't matter for unwinding frames. */
996 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT)
997 abort ();
998 initial_return_save (XEXP (rtl, 0));
999 return;
1000 default:
1001 abort ();
1004 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa_offset);
1007 /* Check INSN to see if it looks like a push or a stack adjustment, and
1008 make a note of it if it does. EH uses this information to find out how
1009 much extra space it needs to pop off the stack. */
1011 static void
1012 dwarf2out_stack_adjust (insn)
1013 rtx insn;
1015 long offset;
1016 char *label;
1018 if (! asynchronous_exceptions && GET_CODE (insn) == CALL_INSN)
1020 /* Extract the size of the args from the CALL rtx itself. */
1022 insn = PATTERN (insn);
1023 if (GET_CODE (insn) == PARALLEL)
1024 insn = XVECEXP (insn, 0, 0);
1025 if (GET_CODE (insn) == SET)
1026 insn = SET_SRC (insn);
1027 assert (GET_CODE (insn) == CALL);
1028 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1)));
1029 return;
1032 /* If only calls can throw, and we have a frame pointer,
1033 save up adjustments until we see the CALL_INSN. */
1034 else if (! asynchronous_exceptions
1035 && cfa_reg != STACK_POINTER_REGNUM)
1036 return;
1038 if (GET_CODE (insn) == BARRIER)
1040 /* When we see a BARRIER, we know to reset args_size to 0. Usually
1041 the compiler will have already emitted a stack adjustment, but
1042 doesn't bother for calls to noreturn functions. */
1043 #ifdef STACK_GROWS_DOWNWARD
1044 offset = -args_size;
1045 #else
1046 offset = args_size;
1047 #endif
1049 else if (GET_CODE (PATTERN (insn)) == SET)
1051 rtx src, dest;
1052 enum rtx_code code;
1054 insn = PATTERN (insn);
1055 src = SET_SRC (insn);
1056 dest = SET_DEST (insn);
1058 if (dest == stack_pointer_rtx)
1060 /* (set (reg sp) (plus (reg sp) (const_int))) */
1061 code = GET_CODE (src);
1062 if (! (code == PLUS || code == MINUS)
1063 || XEXP (src, 0) != stack_pointer_rtx
1064 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1065 return;
1067 offset = INTVAL (XEXP (src, 1));
1069 else if (GET_CODE (dest) == MEM)
1071 /* (set (mem (pre_dec (reg sp))) (foo)) */
1072 src = XEXP (dest, 0);
1073 code = GET_CODE (src);
1075 if (! (code == PRE_DEC || code == PRE_INC)
1076 || XEXP (src, 0) != stack_pointer_rtx)
1077 return;
1079 offset = GET_MODE_SIZE (GET_MODE (dest));
1081 else
1082 return;
1084 if (code == PLUS || code == PRE_INC)
1085 offset = -offset;
1087 else
1088 return;
1090 if (offset == 0)
1091 return;
1093 if (cfa_reg == STACK_POINTER_REGNUM)
1094 cfa_offset += offset;
1096 #ifndef STACK_GROWS_DOWNWARD
1097 offset = -offset;
1098 #endif
1099 args_size += offset;
1100 if (args_size < 0)
1101 args_size = 0;
1103 label = dwarf2out_cfi_label ();
1104 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1105 dwarf2out_args_size (label, args_size);
1108 /* A temporary register used in adjusting SP or setting up the store_reg. */
1109 static unsigned cfa_temp_reg;
1111 /* A temporary value used in adjusting SP or setting up the store_reg. */
1112 static long cfa_temp_value;
1114 /* Record call frame debugging information for an expression, which either
1115 sets SP or FP (adjusting how we calculate the frame address) or saves a
1116 register to the stack. */
1118 static void
1119 dwarf2out_frame_debug_expr (expr, label)
1120 rtx expr;
1121 char *label;
1123 rtx src, dest;
1124 long offset;
1126 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of
1127 the PARALLEL independantly. The first element is always processed if
1128 it is a SET. This is for backward compatability. Other elements
1129 are processed only if they are SETs and the RTX_FRAME_RELATED_P
1130 flag is set in them. */
1132 if (GET_CODE (expr) == PARALLEL)
1134 int par_index;
1135 int limit = XVECLEN (expr, 0);
1137 for (par_index = 0; par_index < limit; par_index++)
1139 rtx x = XVECEXP (expr, 0, par_index);
1141 if (GET_CODE (x) == SET &&
1142 (RTX_FRAME_RELATED_P (x) || par_index == 0))
1143 dwarf2out_frame_debug_expr (x, label);
1145 return;
1148 if (GET_CODE (expr) != SET)
1149 abort ();
1151 src = SET_SRC (expr);
1152 dest = SET_DEST (expr);
1154 switch (GET_CODE (dest))
1156 case REG:
1157 /* Update the CFA rule wrt SP or FP. Make sure src is
1158 relative to the current CFA register. */
1159 switch (GET_CODE (src))
1161 /* Setting FP from SP. */
1162 case REG:
1163 if (cfa_reg != (unsigned) REGNO (src))
1164 abort ();
1165 if (REGNO (dest) != STACK_POINTER_REGNUM
1166 && !(frame_pointer_needed
1167 && REGNO (dest) == HARD_FRAME_POINTER_REGNUM))
1168 abort ();
1169 cfa_reg = REGNO (dest);
1170 break;
1172 case PLUS:
1173 case MINUS:
1174 if (dest == stack_pointer_rtx)
1176 /* Adjusting SP. */
1177 switch (GET_CODE (XEXP (src, 1)))
1179 case CONST_INT:
1180 offset = INTVAL (XEXP (src, 1));
1181 break;
1182 case REG:
1183 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp_reg)
1184 abort ();
1185 offset = cfa_temp_value;
1186 break;
1187 default:
1188 abort ();
1191 if (XEXP (src, 0) == hard_frame_pointer_rtx)
1193 /* Restoring SP from FP in the epilogue. */
1194 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1195 abort ();
1196 cfa_reg = STACK_POINTER_REGNUM;
1198 else if (XEXP (src, 0) != stack_pointer_rtx)
1199 abort ();
1201 if (GET_CODE (src) == PLUS)
1202 offset = -offset;
1203 if (cfa_reg == STACK_POINTER_REGNUM)
1204 cfa_offset += offset;
1205 if (cfa_store_reg == STACK_POINTER_REGNUM)
1206 cfa_store_offset += offset;
1208 else if (dest == hard_frame_pointer_rtx)
1210 /* Either setting the FP from an offset of the SP,
1211 or adjusting the FP */
1212 if (! frame_pointer_needed
1213 || REGNO (dest) != HARD_FRAME_POINTER_REGNUM)
1214 abort ();
1216 if (XEXP (src, 0) == stack_pointer_rtx
1217 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1219 if (cfa_reg != STACK_POINTER_REGNUM)
1220 abort ();
1221 offset = INTVAL (XEXP (src, 1));
1222 if (GET_CODE (src) == PLUS)
1223 offset = -offset;
1224 cfa_offset += offset;
1225 cfa_reg = HARD_FRAME_POINTER_REGNUM;
1227 else if (XEXP (src, 0) == hard_frame_pointer_rtx
1228 && GET_CODE (XEXP (src, 1)) == CONST_INT)
1230 if (cfa_reg != (unsigned) HARD_FRAME_POINTER_REGNUM)
1231 abort ();
1232 offset = INTVAL (XEXP (src, 1));
1233 if (GET_CODE (src) == PLUS)
1234 offset = -offset;
1235 cfa_offset += offset;
1238 else
1239 abort();
1241 else
1243 if (GET_CODE (src) != PLUS
1244 || XEXP (src, 1) != stack_pointer_rtx)
1245 abort ();
1246 if (GET_CODE (XEXP (src, 0)) != REG
1247 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg)
1248 abort ();
1249 if (cfa_reg != STACK_POINTER_REGNUM)
1250 abort ();
1251 cfa_store_reg = REGNO (dest);
1252 cfa_store_offset = cfa_offset - cfa_temp_value;
1254 break;
1256 case CONST_INT:
1257 cfa_temp_reg = REGNO (dest);
1258 cfa_temp_value = INTVAL (src);
1259 break;
1261 case IOR:
1262 if (GET_CODE (XEXP (src, 0)) != REG
1263 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp_reg
1264 || (unsigned) REGNO (dest) != cfa_temp_reg
1265 || GET_CODE (XEXP (src, 1)) != CONST_INT)
1266 abort ();
1267 cfa_temp_value |= INTVAL (XEXP (src, 1));
1268 break;
1270 default:
1271 abort ();
1273 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1274 break;
1276 case MEM:
1277 /* Saving a register to the stack. Make sure dest is relative to the
1278 CFA register. */
1279 if (GET_CODE (src) != REG)
1280 abort ();
1281 switch (GET_CODE (XEXP (dest, 0)))
1283 /* With a push. */
1284 case PRE_INC:
1285 case PRE_DEC:
1286 offset = GET_MODE_SIZE (GET_MODE (dest));
1287 if (GET_CODE (XEXP (dest, 0)) == PRE_INC)
1288 offset = -offset;
1290 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM
1291 || cfa_store_reg != STACK_POINTER_REGNUM)
1292 abort ();
1293 cfa_store_offset += offset;
1294 if (cfa_reg == STACK_POINTER_REGNUM)
1295 cfa_offset = cfa_store_offset;
1297 offset = -cfa_store_offset;
1298 break;
1300 /* With an offset. */
1301 case PLUS:
1302 case MINUS:
1303 offset = INTVAL (XEXP (XEXP (dest, 0), 1));
1304 if (GET_CODE (XEXP (dest, 0)) == MINUS)
1305 offset = -offset;
1307 if (cfa_store_reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0)))
1308 abort ();
1309 offset -= cfa_store_offset;
1310 break;
1312 /* Without an offset. */
1313 case REG:
1314 if (cfa_store_reg != (unsigned) REGNO (XEXP (dest, 0)))
1315 abort();
1316 offset = -cfa_store_offset;
1317 break;
1319 default:
1320 abort ();
1322 dwarf2out_def_cfa (label, cfa_reg, cfa_offset);
1323 dwarf2out_reg_save (label, REGNO (src), offset);
1324 break;
1326 default:
1327 abort ();
1332 /* Record call frame debugging information for INSN, which either
1333 sets SP or FP (adjusting how we calculate the frame address) or saves a
1334 register to the stack. If INSN is NULL_RTX, initialize our state. */
1336 void
1337 dwarf2out_frame_debug (insn)
1338 rtx insn;
1340 char *label;
1341 rtx src;
1343 if (insn == NULL_RTX)
1345 /* Set up state for generating call frame debug info. */
1346 lookup_cfa (&cfa_reg, &cfa_offset);
1347 if (cfa_reg != DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM))
1348 abort ();
1349 cfa_reg = STACK_POINTER_REGNUM;
1350 cfa_store_reg = cfa_reg;
1351 cfa_store_offset = cfa_offset;
1352 cfa_temp_reg = -1;
1353 cfa_temp_value = 0;
1354 return;
1357 if (! RTX_FRAME_RELATED_P (insn))
1359 dwarf2out_stack_adjust (insn);
1360 return;
1363 label = dwarf2out_cfi_label ();
1365 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX);
1366 if (src)
1367 insn = XEXP (src, 0);
1368 else
1369 insn = PATTERN (insn);
1371 dwarf2out_frame_debug_expr (insn, label);
1374 /* Return the size of an unsigned LEB128 quantity. */
1376 static inline unsigned long
1377 size_of_uleb128 (value)
1378 register unsigned long value;
1380 register unsigned long size = 0;
1381 register unsigned byte;
1385 byte = (value & 0x7f);
1386 value >>= 7;
1387 size += 1;
1389 while (value != 0);
1391 return size;
1394 /* Return the size of a signed LEB128 quantity. */
1396 static inline unsigned long
1397 size_of_sleb128 (value)
1398 register long value;
1400 register unsigned long size = 0;
1401 register unsigned byte;
1405 byte = (value & 0x7f);
1406 value >>= 7;
1407 size += 1;
1409 while (!(((value == 0) && ((byte & 0x40) == 0))
1410 || ((value == -1) && ((byte & 0x40) != 0))));
1412 return size;
1415 /* Output an unsigned LEB128 quantity. */
1417 static void
1418 output_uleb128 (value)
1419 register unsigned long value;
1421 unsigned long save_value = value;
1423 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1426 register unsigned byte = (value & 0x7f);
1427 value >>= 7;
1428 if (value != 0)
1429 /* More bytes to follow. */
1430 byte |= 0x80;
1432 fprintf (asm_out_file, "0x%x", byte);
1433 if (value != 0)
1434 fprintf (asm_out_file, ",");
1436 while (value != 0);
1438 if (flag_debug_asm)
1439 fprintf (asm_out_file, "\t%s ULEB128 0x%lx", ASM_COMMENT_START, save_value);
1442 /* Output an signed LEB128 quantity. */
1444 static void
1445 output_sleb128 (value)
1446 register long value;
1448 register int more;
1449 register unsigned byte;
1450 long save_value = value;
1452 fprintf (asm_out_file, "\t%s\t", ASM_BYTE_OP);
1455 byte = (value & 0x7f);
1456 /* arithmetic shift */
1457 value >>= 7;
1458 more = !((((value == 0) && ((byte & 0x40) == 0))
1459 || ((value == -1) && ((byte & 0x40) != 0))));
1460 if (more)
1461 byte |= 0x80;
1463 fprintf (asm_out_file, "0x%x", byte);
1464 if (more)
1465 fprintf (asm_out_file, ",");
1468 while (more);
1469 if (flag_debug_asm)
1470 fprintf (asm_out_file, "\t%s SLEB128 %ld", ASM_COMMENT_START, save_value);
1473 /* Output a Call Frame Information opcode and its operand(s). */
1475 static void
1476 output_cfi (cfi, fde)
1477 register dw_cfi_ref cfi;
1478 register dw_fde_ref fde;
1480 if (cfi->dw_cfi_opc == DW_CFA_advance_loc)
1482 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1483 cfi->dw_cfi_opc
1484 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f));
1485 if (flag_debug_asm)
1486 fprintf (asm_out_file, "\t%s DW_CFA_advance_loc 0x%lx",
1487 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_offset);
1488 fputc ('\n', asm_out_file);
1491 else if (cfi->dw_cfi_opc == DW_CFA_offset)
1493 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1494 cfi->dw_cfi_opc
1495 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1496 if (flag_debug_asm)
1497 fprintf (asm_out_file, "\t%s DW_CFA_offset, column 0x%lx",
1498 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1500 fputc ('\n', asm_out_file);
1501 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1502 fputc ('\n', asm_out_file);
1504 else if (cfi->dw_cfi_opc == DW_CFA_restore)
1506 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
1507 cfi->dw_cfi_opc
1508 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f));
1509 if (flag_debug_asm)
1510 fprintf (asm_out_file, "\t%s DW_CFA_restore, column 0x%lx",
1511 ASM_COMMENT_START, cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1513 fputc ('\n', asm_out_file);
1515 else
1517 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, cfi->dw_cfi_opc);
1518 if (flag_debug_asm)
1519 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
1520 dwarf_cfi_name (cfi->dw_cfi_opc));
1522 fputc ('\n', asm_out_file);
1523 switch (cfi->dw_cfi_opc)
1525 case DW_CFA_set_loc:
1526 ASM_OUTPUT_DWARF_ADDR (asm_out_file, cfi->dw_cfi_oprnd1.dw_cfi_addr);
1527 fputc ('\n', asm_out_file);
1528 break;
1529 case DW_CFA_advance_loc1:
1530 ASM_OUTPUT_DWARF_DELTA1 (asm_out_file,
1531 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1532 fde->dw_fde_current_label);
1533 fputc ('\n', asm_out_file);
1534 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1535 break;
1536 case DW_CFA_advance_loc2:
1537 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file,
1538 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1539 fde->dw_fde_current_label);
1540 fputc ('\n', asm_out_file);
1541 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1542 break;
1543 case DW_CFA_advance_loc4:
1544 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file,
1545 cfi->dw_cfi_oprnd1.dw_cfi_addr,
1546 fde->dw_fde_current_label);
1547 fputc ('\n', asm_out_file);
1548 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr;
1549 break;
1550 #ifdef MIPS_DEBUGGING_INFO
1551 case DW_CFA_MIPS_advance_loc8:
1552 /* TODO: not currently implemented. */
1553 abort ();
1554 break;
1555 #endif
1556 case DW_CFA_offset_extended:
1557 case DW_CFA_def_cfa:
1558 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1559 fputc ('\n', asm_out_file);
1560 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset);
1561 fputc ('\n', asm_out_file);
1562 break;
1563 case DW_CFA_restore_extended:
1564 case DW_CFA_undefined:
1565 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1566 fputc ('\n', asm_out_file);
1567 break;
1568 case DW_CFA_same_value:
1569 case DW_CFA_def_cfa_register:
1570 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1571 fputc ('\n', asm_out_file);
1572 break;
1573 case DW_CFA_register:
1574 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num);
1575 fputc ('\n', asm_out_file);
1576 output_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num);
1577 fputc ('\n', asm_out_file);
1578 break;
1579 case DW_CFA_def_cfa_offset:
1580 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1581 fputc ('\n', asm_out_file);
1582 break;
1583 case DW_CFA_GNU_window_save:
1584 break;
1585 case DW_CFA_GNU_args_size:
1586 output_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset);
1587 fputc ('\n', asm_out_file);
1588 break;
1589 default:
1590 break;
1595 /* Output the call frame information used to used to record information
1596 that relates to calculating the frame pointer, and records the
1597 location of saved registers. */
1599 static void
1600 output_call_frame_info (for_eh)
1601 int for_eh;
1603 register unsigned long i;
1604 register dw_fde_ref fde;
1605 register dw_cfi_ref cfi;
1606 char l1[20], l2[20];
1607 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1608 char ld[20];
1609 #endif
1611 /* Do we want to include a pointer to the exception table? */
1612 int eh_ptr = for_eh && exception_table_p ();
1614 fputc ('\n', asm_out_file);
1616 /* We're going to be generating comments, so turn on app. */
1617 if (flag_debug_asm)
1618 app_enable ();
1620 if (for_eh)
1622 #ifdef EH_FRAME_SECTION
1623 EH_FRAME_SECTION ();
1624 #else
1625 tree label = get_file_function_name ('F');
1627 force_data_section ();
1628 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1629 ASM_GLOBALIZE_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1630 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label));
1631 #endif
1632 assemble_label ("__FRAME_BEGIN__");
1634 else
1635 ASM_OUTPUT_SECTION (asm_out_file, FRAME_SECTION);
1637 /* Output the CIE. */
1638 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh);
1639 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh);
1640 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1641 ASM_GENERATE_INTERNAL_LABEL (ld, CIE_LENGTH_LABEL, for_eh);
1642 if (for_eh)
1643 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1644 else
1645 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1646 #else
1647 if (for_eh)
1648 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1649 else
1650 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1651 #endif
1652 if (flag_debug_asm)
1653 fprintf (asm_out_file, "\t%s Length of Common Information Entry",
1654 ASM_COMMENT_START);
1656 fputc ('\n', asm_out_file);
1657 ASM_OUTPUT_LABEL (asm_out_file, l1);
1659 if (for_eh)
1660 /* Now that the CIE pointer is PC-relative for EH,
1661 use 0 to identify the CIE. */
1662 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1663 else
1664 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1666 if (flag_debug_asm)
1667 fprintf (asm_out_file, "\t%s CIE Identifier Tag", ASM_COMMENT_START);
1669 fputc ('\n', asm_out_file);
1670 if (! for_eh && DWARF_OFFSET_SIZE == 8)
1672 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, DW_CIE_ID);
1673 fputc ('\n', asm_out_file);
1676 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_CIE_VERSION);
1677 if (flag_debug_asm)
1678 fprintf (asm_out_file, "\t%s CIE Version", ASM_COMMENT_START);
1680 fputc ('\n', asm_out_file);
1681 if (eh_ptr)
1683 /* The CIE contains a pointer to the exception region info for the
1684 frame. Make the augmentation string three bytes (including the
1685 trailing null) so the pointer is 4-byte aligned. The Solaris ld
1686 can't handle unaligned relocs. */
1687 if (flag_debug_asm)
1689 ASM_OUTPUT_DWARF_STRING (asm_out_file, "eh");
1690 fprintf (asm_out_file, "\t%s CIE Augmentation", ASM_COMMENT_START);
1692 else
1694 ASM_OUTPUT_ASCII (asm_out_file, "eh", 3);
1696 fputc ('\n', asm_out_file);
1698 ASM_OUTPUT_DWARF_ADDR (asm_out_file, "__EXCEPTION_TABLE__");
1699 if (flag_debug_asm)
1700 fprintf (asm_out_file, "\t%s pointer to exception region info",
1701 ASM_COMMENT_START);
1703 else
1705 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
1706 if (flag_debug_asm)
1707 fprintf (asm_out_file, "\t%s CIE Augmentation (none)",
1708 ASM_COMMENT_START);
1711 fputc ('\n', asm_out_file);
1712 output_uleb128 (1);
1713 if (flag_debug_asm)
1714 fprintf (asm_out_file, " (CIE Code Alignment Factor)");
1716 fputc ('\n', asm_out_file);
1717 output_sleb128 (DWARF_CIE_DATA_ALIGNMENT);
1718 if (flag_debug_asm)
1719 fprintf (asm_out_file, " (CIE Data Alignment Factor)");
1721 fputc ('\n', asm_out_file);
1722 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_FRAME_RETURN_COLUMN);
1723 if (flag_debug_asm)
1724 fprintf (asm_out_file, "\t%s CIE RA Column", ASM_COMMENT_START);
1726 fputc ('\n', asm_out_file);
1728 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next)
1729 output_cfi (cfi, NULL);
1731 /* Pad the CIE out to an address sized boundary. */
1732 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1733 ASM_OUTPUT_LABEL (asm_out_file, l2);
1734 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1735 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1736 if (flag_debug_asm)
1737 fprintf (asm_out_file, "\t%s CIE Length Symbol", ASM_COMMENT_START);
1738 fputc ('\n', asm_out_file);
1739 #endif
1741 /* Loop through all of the FDE's. */
1742 for (i = 0; i < fde_table_in_use; ++i)
1744 fde = &fde_table[i];
1746 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i*2);
1747 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i*2);
1748 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1749 ASM_GENERATE_INTERNAL_LABEL (ld, FDE_LENGTH_LABEL, for_eh + i*2);
1750 if (for_eh)
1751 ASM_OUTPUT_DWARF_OFFSET4 (asm_out_file, ld);
1752 else
1753 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, ld);
1754 #else
1755 if (for_eh)
1756 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l2, l1);
1757 else
1758 ASM_OUTPUT_DWARF_DELTA (asm_out_file, l2, l1);
1759 #endif
1760 if (flag_debug_asm)
1761 fprintf (asm_out_file, "\t%s FDE Length", ASM_COMMENT_START);
1762 fputc ('\n', asm_out_file);
1763 ASM_OUTPUT_LABEL (asm_out_file, l1);
1765 /* ??? This always emits a 4 byte offset when for_eh is true, but it
1766 emits a target dependent sized offset when for_eh is not true.
1767 This inconsistency may confuse gdb. The only case where we need a
1768 non-4 byte offset is for the Irix6 N64 ABI, so we may lose SGI
1769 compatibility if we emit a 4 byte offset. We need a 4 byte offset
1770 though in order to be compatible with the dwarf_fde struct in frame.c.
1771 If the for_eh case is changed, then the struct in frame.c has
1772 to be adjusted appropriately. */
1773 if (for_eh)
1774 ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, l1, "__FRAME_BEGIN__");
1775 else
1776 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, stripattributes (FRAME_SECTION));
1777 if (flag_debug_asm)
1778 fprintf (asm_out_file, "\t%s FDE CIE offset", ASM_COMMENT_START);
1780 fputc ('\n', asm_out_file);
1781 ASM_OUTPUT_DWARF_ADDR (asm_out_file, fde->dw_fde_begin);
1782 if (flag_debug_asm)
1783 fprintf (asm_out_file, "\t%s FDE initial location", ASM_COMMENT_START);
1785 fputc ('\n', asm_out_file);
1786 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file,
1787 fde->dw_fde_end, fde->dw_fde_begin);
1788 if (flag_debug_asm)
1789 fprintf (asm_out_file, "\t%s FDE address range", ASM_COMMENT_START);
1791 fputc ('\n', asm_out_file);
1793 /* Loop through the Call Frame Instructions associated with
1794 this FDE. */
1795 fde->dw_fde_current_label = fde->dw_fde_begin;
1796 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next)
1797 output_cfi (cfi, fde);
1799 /* Pad the FDE out to an address sized boundary. */
1800 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE));
1801 ASM_OUTPUT_LABEL (asm_out_file, l2);
1802 #ifdef ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL
1803 ASM_OUTPUT_DEFINE_LABEL_DIFFERENCE_SYMBOL (asm_out_file, ld, l2, l1);
1804 if (flag_debug_asm)
1805 fprintf (asm_out_file, "\t%s FDE Length Symbol", ASM_COMMENT_START);
1806 fputc ('\n', asm_out_file);
1807 #endif
1809 #ifndef EH_FRAME_SECTION
1810 if (for_eh)
1812 /* Emit terminating zero for table. */
1813 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
1814 fputc ('\n', asm_out_file);
1816 #endif
1817 #ifdef MIPS_DEBUGGING_INFO
1818 /* Work around Irix 6 assembler bug whereby labels at the end of a section
1819 get a value of 0. Putting .align 0 after the label fixes it. */
1820 ASM_OUTPUT_ALIGN (asm_out_file, 0);
1821 #endif
1823 /* Turn off app to make assembly quicker. */
1824 if (flag_debug_asm)
1825 app_disable ();
1828 /* Output a marker (i.e. a label) for the beginning of a function, before
1829 the prologue. */
1831 void
1832 dwarf2out_begin_prologue ()
1834 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1835 register dw_fde_ref fde;
1837 ++current_funcdef_number;
1839 function_section (current_function_decl);
1840 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL,
1841 current_funcdef_number);
1842 ASM_OUTPUT_LABEL (asm_out_file, label);
1844 /* Expand the fde table if necessary. */
1845 if (fde_table_in_use == fde_table_allocated)
1847 fde_table_allocated += FDE_TABLE_INCREMENT;
1848 fde_table
1849 = (dw_fde_ref) xrealloc (fde_table,
1850 fde_table_allocated * sizeof (dw_fde_node));
1853 /* Record the FDE associated with this function. */
1854 current_funcdef_fde = fde_table_in_use;
1856 /* Add the new FDE at the end of the fde_table. */
1857 fde = &fde_table[fde_table_in_use++];
1858 fde->dw_fde_begin = xstrdup (label);
1859 fde->dw_fde_current_label = NULL;
1860 fde->dw_fde_end = NULL;
1861 fde->dw_fde_cfi = NULL;
1863 args_size = old_args_size = 0;
1866 /* Output a marker (i.e. a label) for the absolute end of the generated code
1867 for a function definition. This gets called *after* the epilogue code has
1868 been generated. */
1870 void
1871 dwarf2out_end_epilogue ()
1873 dw_fde_ref fde;
1874 char label[MAX_ARTIFICIAL_LABEL_BYTES];
1876 /* Output a label to mark the endpoint of the code generated for this
1877 function. */
1878 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, current_funcdef_number);
1879 ASM_OUTPUT_LABEL (asm_out_file, label);
1880 fde = &fde_table[fde_table_in_use - 1];
1881 fde->dw_fde_end = xstrdup (label);
1884 void
1885 dwarf2out_frame_init ()
1887 /* Allocate the initial hunk of the fde_table. */
1888 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node));
1889 fde_table_allocated = FDE_TABLE_INCREMENT;
1890 fde_table_in_use = 0;
1892 /* Generate the CFA instructions common to all FDE's. Do it now for the
1893 sake of lookup_cfa. */
1895 #ifdef DWARF2_UNWIND_INFO
1896 /* On entry, the Canonical Frame Address is at SP. */
1897 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET);
1898 initial_return_save (INCOMING_RETURN_ADDR_RTX);
1899 #endif
1902 void
1903 dwarf2out_frame_finish ()
1905 /* Output call frame information. */
1906 #ifdef MIPS_DEBUGGING_INFO
1907 if (write_symbols == DWARF2_DEBUG)
1908 output_call_frame_info (0);
1909 if (flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1910 output_call_frame_info (1);
1911 #else
1912 if (write_symbols == DWARF2_DEBUG
1913 || flag_unwind_tables || (flag_exceptions && ! exceptions_via_longjmp))
1914 output_call_frame_info (1);
1915 #endif
1918 #endif /* .debug_frame support */
1920 /* And now, the support for symbolic debugging information. */
1921 #ifdef DWARF2_DEBUGGING_INFO
1923 /* NOTE: In the comments in this file, many references are made to
1924 "Debugging Information Entries". This term is abbreviated as `DIE'
1925 throughout the remainder of this file. */
1927 /* An internal representation of the DWARF output is built, and then
1928 walked to generate the DWARF debugging info. The walk of the internal
1929 representation is done after the entire program has been compiled.
1930 The types below are used to describe the internal representation. */
1932 /* Each DIE may have a series of attribute/value pairs. Values
1933 can take on several forms. The forms that are used in this
1934 implementation are listed below. */
1936 typedef enum
1938 dw_val_class_addr,
1939 dw_val_class_loc,
1940 dw_val_class_const,
1941 dw_val_class_unsigned_const,
1942 dw_val_class_long_long,
1943 dw_val_class_float,
1944 dw_val_class_flag,
1945 dw_val_class_die_ref,
1946 dw_val_class_fde_ref,
1947 dw_val_class_lbl_id,
1948 dw_val_class_lbl_offset,
1949 dw_val_class_str
1951 dw_val_class;
1953 /* Various DIE's use offsets relative to the beginning of the
1954 .debug_info section to refer to each other. */
1956 typedef long int dw_offset;
1958 /* Define typedefs here to avoid circular dependencies. */
1960 typedef struct die_struct *dw_die_ref;
1961 typedef struct dw_attr_struct *dw_attr_ref;
1962 typedef struct dw_val_struct *dw_val_ref;
1963 typedef struct dw_line_info_struct *dw_line_info_ref;
1964 typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref;
1965 typedef struct dw_loc_descr_struct *dw_loc_descr_ref;
1966 typedef struct pubname_struct *pubname_ref;
1967 typedef dw_die_ref *arange_ref;
1969 /* Describe a double word constant value. */
1971 typedef struct dw_long_long_struct
1973 unsigned long hi;
1974 unsigned long low;
1976 dw_long_long_const;
1978 /* Describe a floating point constant value. */
1980 typedef struct dw_fp_struct
1982 long *array;
1983 unsigned length;
1985 dw_float_const;
1987 /* Each entry in the line_info_table maintains the file and
1988 line number associated with the label generated for that
1989 entry. The label gives the PC value associated with
1990 the line number entry. */
1992 typedef struct dw_line_info_struct
1994 unsigned long dw_file_num;
1995 unsigned long dw_line_num;
1997 dw_line_info_entry;
1999 /* Line information for functions in separate sections; each one gets its
2000 own sequence. */
2001 typedef struct dw_separate_line_info_struct
2003 unsigned long dw_file_num;
2004 unsigned long dw_line_num;
2005 unsigned long function;
2007 dw_separate_line_info_entry;
2009 /* The dw_val_node describes an attribute's value, as it is
2010 represented internally. */
2012 typedef struct dw_val_struct
2014 dw_val_class val_class;
2015 union
2017 char *val_addr;
2018 dw_loc_descr_ref val_loc;
2019 long int val_int;
2020 long unsigned val_unsigned;
2021 dw_long_long_const val_long_long;
2022 dw_float_const val_float;
2023 dw_die_ref val_die_ref;
2024 unsigned val_fde_index;
2025 char *val_str;
2026 char *val_lbl_id;
2027 unsigned char val_flag;
2031 dw_val_node;
2033 /* Locations in memory are described using a sequence of stack machine
2034 operations. */
2036 typedef struct dw_loc_descr_struct
2038 dw_loc_descr_ref dw_loc_next;
2039 enum dwarf_location_atom dw_loc_opc;
2040 dw_val_node dw_loc_oprnd1;
2041 dw_val_node dw_loc_oprnd2;
2043 dw_loc_descr_node;
2045 /* Each DIE attribute has a field specifying the attribute kind,
2046 a link to the next attribute in the chain, and an attribute value.
2047 Attributes are typically linked below the DIE they modify. */
2049 typedef struct dw_attr_struct
2051 enum dwarf_attribute dw_attr;
2052 dw_attr_ref dw_attr_next;
2053 dw_val_node dw_attr_val;
2055 dw_attr_node;
2057 /* The Debugging Information Entry (DIE) structure */
2059 typedef struct die_struct
2061 enum dwarf_tag die_tag;
2062 dw_attr_ref die_attr;
2063 dw_attr_ref die_attr_last;
2064 dw_die_ref die_parent;
2065 dw_die_ref die_child;
2066 dw_die_ref die_child_last;
2067 dw_die_ref die_sib;
2068 dw_offset die_offset;
2069 unsigned long die_abbrev;
2071 die_node;
2073 /* The pubname structure */
2075 typedef struct pubname_struct
2077 dw_die_ref die;
2078 char * name;
2080 pubname_entry;
2082 /* The limbo die list structure. */
2083 typedef struct limbo_die_struct
2085 dw_die_ref die;
2086 struct limbo_die_struct *next;
2088 limbo_die_node;
2090 /* How to start an assembler comment. */
2091 #ifndef ASM_COMMENT_START
2092 #define ASM_COMMENT_START ";#"
2093 #endif
2095 /* Define a macro which returns non-zero for a TYPE_DECL which was
2096 implicitly generated for a tagged type.
2098 Note that unlike the gcc front end (which generates a NULL named
2099 TYPE_DECL node for each complete tagged type, each array type, and
2100 each function type node created) the g++ front end generates a
2101 _named_ TYPE_DECL node for each tagged type node created.
2102 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2103 generate a DW_TAG_typedef DIE for them. */
2105 #define TYPE_DECL_IS_STUB(decl) \
2106 (DECL_NAME (decl) == NULL_TREE \
2107 || (DECL_ARTIFICIAL (decl) \
2108 && is_tagged_type (TREE_TYPE (decl)) \
2109 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2110 /* This is necessary for stub decls that \
2111 appear in nested inline functions. */ \
2112 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2113 && (decl_ultimate_origin (decl) \
2114 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2116 /* Information concerning the compilation unit's programming
2117 language, and compiler version. */
2119 extern int flag_traditional;
2120 extern char *version_string;
2122 /* Fixed size portion of the DWARF compilation unit header. */
2123 #define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3)
2125 /* Fixed size portion of debugging line information prolog. */
2126 #define DWARF_LINE_PROLOG_HEADER_SIZE 5
2128 /* Fixed size portion of public names info. */
2129 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2131 /* Fixed size portion of the address range info. */
2132 #define DWARF_ARANGES_HEADER_SIZE \
2133 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, PTR_SIZE * 2) - DWARF_OFFSET_SIZE)
2135 /* The default is to have gcc emit the line number tables. */
2136 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2137 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2138 #endif
2140 /* Define the architecture-dependent minimum instruction length (in bytes).
2141 In this implementation of DWARF, this field is used for information
2142 purposes only. Since GCC generates assembly language, we have
2143 no a priori knowledge of how many instruction bytes are generated
2144 for each source line, and therefore can use only the DW_LNE_set_address
2145 and DW_LNS_fixed_advance_pc line information commands. */
2147 #ifndef DWARF_LINE_MIN_INSTR_LENGTH
2148 #define DWARF_LINE_MIN_INSTR_LENGTH 4
2149 #endif
2151 /* Minimum line offset in a special line info. opcode.
2152 This value was chosen to give a reasonable range of values. */
2153 #define DWARF_LINE_BASE -10
2155 /* First special line opcde - leave room for the standard opcodes. */
2156 #define DWARF_LINE_OPCODE_BASE 10
2158 /* Range of line offsets in a special line info. opcode. */
2159 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2161 /* Flag that indicates the initial value of the is_stmt_start flag.
2162 In the present implementation, we do not mark any lines as
2163 the beginning of a source statement, because that information
2164 is not made available by the GCC front-end. */
2165 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2167 /* This location is used by calc_die_sizes() to keep track
2168 the offset of each DIE within the .debug_info section. */
2169 static unsigned long next_die_offset;
2171 /* Record the root of the DIE's built for the current compilation unit. */
2172 static dw_die_ref comp_unit_die;
2174 /* A list of DIEs with a NULL parent waiting to be relocated. */
2175 static limbo_die_node *limbo_die_list = 0;
2177 /* Pointer to an array of filenames referenced by this compilation unit. */
2178 static char **file_table;
2180 /* Total number of entries in the table (i.e. array) pointed to by
2181 `file_table'. This is the *total* and includes both used and unused
2182 slots. */
2183 static unsigned file_table_allocated;
2185 /* Number of entries in the file_table which are actually in use. */
2186 static unsigned file_table_in_use;
2188 /* Size (in elements) of increments by which we may expand the filename
2189 table. */
2190 #define FILE_TABLE_INCREMENT 64
2192 /* Local pointer to the name of the main input file. Initialized in
2193 dwarf2out_init. */
2194 static char *primary_filename;
2196 /* For Dwarf output, we must assign lexical-blocks id numbers in the order in
2197 which their beginnings are encountered. We output Dwarf debugging info
2198 that refers to the beginnings and ends of the ranges of code for each
2199 lexical block. The labels themselves are generated in final.c, which
2200 assigns numbers to the blocks in the same way. */
2201 static unsigned next_block_number = 2;
2203 /* A pointer to the base of a table of references to DIE's that describe
2204 declarations. The table is indexed by DECL_UID() which is a unique
2205 number identifying each decl. */
2206 static dw_die_ref *decl_die_table;
2208 /* Number of elements currently allocated for the decl_die_table. */
2209 static unsigned decl_die_table_allocated;
2211 /* Number of elements in decl_die_table currently in use. */
2212 static unsigned decl_die_table_in_use;
2214 /* Size (in elements) of increments by which we may expand the
2215 decl_die_table. */
2216 #define DECL_DIE_TABLE_INCREMENT 256
2218 /* Structure used for the decl_scope table. scope is the current declaration
2219 scope, and previous is the entry that is the parent of this scope. This
2220 is usually but not always the immediately preceeding entry. */
2222 typedef struct decl_scope_struct
2224 tree scope;
2225 int previous;
2227 decl_scope_node;
2229 /* A pointer to the base of a table of references to declaration
2230 scopes. This table is a display which tracks the nesting
2231 of declaration scopes at the current scope and containing
2232 scopes. This table is used to find the proper place to
2233 define type declaration DIE's. */
2234 static decl_scope_node *decl_scope_table;
2236 /* Number of elements currently allocated for the decl_scope_table. */
2237 static int decl_scope_table_allocated;
2239 /* Current level of nesting of declaration scopes. */
2240 static int decl_scope_depth;
2242 /* Size (in elements) of increments by which we may expand the
2243 decl_scope_table. */
2244 #define DECL_SCOPE_TABLE_INCREMENT 64
2246 /* A pointer to the base of a list of references to DIE's that
2247 are uniquely identified by their tag, presence/absence of
2248 children DIE's, and list of attribute/value pairs. */
2249 static dw_die_ref *abbrev_die_table;
2251 /* Number of elements currently allocated for abbrev_die_table. */
2252 static unsigned abbrev_die_table_allocated;
2254 /* Number of elements in type_die_table currently in use. */
2255 static unsigned abbrev_die_table_in_use;
2257 /* Size (in elements) of increments by which we may expand the
2258 abbrev_die_table. */
2259 #define ABBREV_DIE_TABLE_INCREMENT 256
2261 /* A pointer to the base of a table that contains line information
2262 for each source code line in .text in the compilation unit. */
2263 static dw_line_info_ref line_info_table;
2265 /* Number of elements currently allocated for line_info_table. */
2266 static unsigned line_info_table_allocated;
2268 /* Number of elements in separate_line_info_table currently in use. */
2269 static unsigned separate_line_info_table_in_use;
2271 /* A pointer to the base of a table that contains line information
2272 for each source code line outside of .text in the compilation unit. */
2273 static dw_separate_line_info_ref separate_line_info_table;
2275 /* Number of elements currently allocated for separate_line_info_table. */
2276 static unsigned separate_line_info_table_allocated;
2278 /* Number of elements in line_info_table currently in use. */
2279 static unsigned line_info_table_in_use;
2281 /* Size (in elements) of increments by which we may expand the
2282 line_info_table. */
2283 #define LINE_INFO_TABLE_INCREMENT 1024
2285 /* A pointer to the base of a table that contains a list of publicly
2286 accessible names. */
2287 static pubname_ref pubname_table;
2289 /* Number of elements currently allocated for pubname_table. */
2290 static unsigned pubname_table_allocated;
2292 /* Number of elements in pubname_table currently in use. */
2293 static unsigned pubname_table_in_use;
2295 /* Size (in elements) of increments by which we may expand the
2296 pubname_table. */
2297 #define PUBNAME_TABLE_INCREMENT 64
2299 /* A pointer to the base of a table that contains a list of publicly
2300 accessible names. */
2301 static arange_ref arange_table;
2303 /* Number of elements currently allocated for arange_table. */
2304 static unsigned arange_table_allocated;
2306 /* Number of elements in arange_table currently in use. */
2307 static unsigned arange_table_in_use;
2309 /* Size (in elements) of increments by which we may expand the
2310 arange_table. */
2311 #define ARANGE_TABLE_INCREMENT 64
2313 /* A pointer to the base of a list of pending types which we haven't
2314 generated DIEs for yet, but which we will have to come back to
2315 later on. */
2317 static tree *pending_types_list;
2319 /* Number of elements currently allocated for the pending_types_list. */
2320 static unsigned pending_types_allocated;
2322 /* Number of elements of pending_types_list currently in use. */
2323 static unsigned pending_types;
2325 /* Size (in elements) of increments by which we may expand the pending
2326 types list. Actually, a single hunk of space of this size should
2327 be enough for most typical programs. */
2328 #define PENDING_TYPES_INCREMENT 64
2330 /* A pointer to the base of a list of incomplete types which might be
2331 completed at some later time. */
2333 static tree *incomplete_types_list;
2335 /* Number of elements currently allocated for the incomplete_types_list. */
2336 static unsigned incomplete_types_allocated;
2338 /* Number of elements of incomplete_types_list currently in use. */
2339 static unsigned incomplete_types;
2341 /* Size (in elements) of increments by which we may expand the incomplete
2342 types list. Actually, a single hunk of space of this size should
2343 be enough for most typical programs. */
2344 #define INCOMPLETE_TYPES_INCREMENT 64
2346 /* Record whether the function being analyzed contains inlined functions. */
2347 static int current_function_has_inlines;
2348 #if 0 && defined (MIPS_DEBUGGING_INFO)
2349 static int comp_unit_has_inlines;
2350 #endif
2352 /* A pointer to the ..._DECL node which we have most recently been working
2353 on. We keep this around just in case something about it looks screwy and
2354 we want to tell the user what the source coordinates for the actual
2355 declaration are. */
2356 static tree dwarf_last_decl;
2358 /* Forward declarations for functions defined in this file. */
2360 static void addr_const_to_string PROTO((dyn_string_t, rtx));
2361 static char *addr_to_string PROTO((rtx));
2362 static int is_pseudo_reg PROTO((rtx));
2363 static tree type_main_variant PROTO((tree));
2364 static int is_tagged_type PROTO((tree));
2365 static const char *dwarf_tag_name PROTO((unsigned));
2366 static const char *dwarf_attr_name PROTO((unsigned));
2367 static const char *dwarf_form_name PROTO((unsigned));
2368 static const char *dwarf_stack_op_name PROTO((unsigned));
2369 #if 0
2370 static const char *dwarf_type_encoding_name PROTO((unsigned));
2371 #endif
2372 static tree decl_ultimate_origin PROTO((tree));
2373 static tree block_ultimate_origin PROTO((tree));
2374 static tree decl_class_context PROTO((tree));
2375 static void add_dwarf_attr PROTO((dw_die_ref, dw_attr_ref));
2376 static void add_AT_flag PROTO((dw_die_ref,
2377 enum dwarf_attribute,
2378 unsigned));
2379 static void add_AT_int PROTO((dw_die_ref,
2380 enum dwarf_attribute, long));
2381 static void add_AT_unsigned PROTO((dw_die_ref,
2382 enum dwarf_attribute,
2383 unsigned long));
2384 static void add_AT_long_long PROTO((dw_die_ref,
2385 enum dwarf_attribute,
2386 unsigned long, unsigned long));
2387 static void add_AT_float PROTO((dw_die_ref,
2388 enum dwarf_attribute,
2389 unsigned, long *));
2390 static void add_AT_string PROTO((dw_die_ref,
2391 enum dwarf_attribute,
2392 const char *));
2393 static void add_AT_die_ref PROTO((dw_die_ref,
2394 enum dwarf_attribute,
2395 dw_die_ref));
2396 static void add_AT_fde_ref PROTO((dw_die_ref,
2397 enum dwarf_attribute,
2398 unsigned));
2399 static void add_AT_loc PROTO((dw_die_ref,
2400 enum dwarf_attribute,
2401 dw_loc_descr_ref));
2402 static void add_AT_addr PROTO((dw_die_ref,
2403 enum dwarf_attribute, char *));
2404 static void add_AT_lbl_id PROTO((dw_die_ref,
2405 enum dwarf_attribute, char *));
2406 static void add_AT_lbl_offset PROTO((dw_die_ref,
2407 enum dwarf_attribute, char *));
2408 static int is_extern_subr_die PROTO((dw_die_ref));
2409 static dw_attr_ref get_AT PROTO((dw_die_ref,
2410 enum dwarf_attribute));
2411 static char *get_AT_low_pc PROTO((dw_die_ref));
2412 static char *get_AT_hi_pc PROTO((dw_die_ref));
2413 static char *get_AT_string PROTO((dw_die_ref,
2414 enum dwarf_attribute));
2415 static int get_AT_flag PROTO((dw_die_ref,
2416 enum dwarf_attribute));
2417 static unsigned get_AT_unsigned PROTO((dw_die_ref,
2418 enum dwarf_attribute));
2419 static int is_c_family PROTO((void));
2420 static int is_fortran PROTO((void));
2421 static void remove_AT PROTO((dw_die_ref,
2422 enum dwarf_attribute));
2423 static void remove_children PROTO((dw_die_ref));
2424 static void add_child_die PROTO((dw_die_ref, dw_die_ref));
2425 static dw_die_ref new_die PROTO((enum dwarf_tag, dw_die_ref));
2426 static dw_die_ref lookup_type_die PROTO((tree));
2427 static void equate_type_number_to_die PROTO((tree, dw_die_ref));
2428 static dw_die_ref lookup_decl_die PROTO((tree));
2429 static void equate_decl_number_to_die PROTO((tree, dw_die_ref));
2430 static dw_loc_descr_ref new_loc_descr PROTO((enum dwarf_location_atom,
2431 unsigned long, unsigned long));
2432 static void add_loc_descr PROTO((dw_loc_descr_ref *,
2433 dw_loc_descr_ref));
2434 static void print_spaces PROTO((FILE *));
2435 static void print_die PROTO((dw_die_ref, FILE *));
2436 static void print_dwarf_line_table PROTO((FILE *));
2437 static void add_sibling_attributes PROTO((dw_die_ref));
2438 static void build_abbrev_table PROTO((dw_die_ref));
2439 static unsigned long size_of_string PROTO((char *));
2440 static unsigned long size_of_loc_descr PROTO((dw_loc_descr_ref));
2441 static unsigned long size_of_locs PROTO((dw_loc_descr_ref));
2442 static int constant_size PROTO((long unsigned));
2443 static unsigned long size_of_die PROTO((dw_die_ref));
2444 static void calc_die_sizes PROTO((dw_die_ref));
2445 static unsigned long size_of_line_prolog PROTO((void));
2446 static unsigned long size_of_pubnames PROTO((void));
2447 static unsigned long size_of_aranges PROTO((void));
2448 static enum dwarf_form value_format PROTO((dw_val_ref));
2449 static void output_value_format PROTO((dw_val_ref));
2450 static void output_abbrev_section PROTO((void));
2451 static void output_loc_operands PROTO((dw_loc_descr_ref));
2452 static unsigned long sibling_offset PROTO((dw_die_ref));
2453 static void output_die PROTO((dw_die_ref));
2454 static void output_compilation_unit_header PROTO((void));
2455 static const char *dwarf2_name PROTO((tree, int));
2456 static void add_pubname PROTO((tree, dw_die_ref));
2457 static void output_pubnames PROTO((void));
2458 static void add_arange PROTO((tree, dw_die_ref));
2459 static void output_aranges PROTO((void));
2460 static void output_line_info PROTO((void));
2461 static int is_body_block PROTO((tree));
2462 static dw_die_ref base_type_die PROTO((tree));
2463 static tree root_type PROTO((tree));
2464 static int is_base_type PROTO((tree));
2465 static dw_die_ref modified_type_die PROTO((tree, int, int, dw_die_ref));
2466 static int type_is_enum PROTO((tree));
2467 static dw_loc_descr_ref reg_loc_descriptor PROTO((rtx));
2468 static dw_loc_descr_ref based_loc_descr PROTO((unsigned, long));
2469 static int is_based_loc PROTO((rtx));
2470 static dw_loc_descr_ref mem_loc_descriptor PROTO((rtx, enum machine_mode mode));
2471 static dw_loc_descr_ref concat_loc_descriptor PROTO((rtx, rtx));
2472 static dw_loc_descr_ref loc_descriptor PROTO((rtx));
2473 static unsigned ceiling PROTO((unsigned, unsigned));
2474 static tree field_type PROTO((tree));
2475 static unsigned simple_type_align_in_bits PROTO((tree));
2476 static unsigned simple_type_size_in_bits PROTO((tree));
2477 static unsigned field_byte_offset PROTO((tree));
2478 static void add_AT_location_description PROTO((dw_die_ref,
2479 enum dwarf_attribute, rtx));
2480 static void add_data_member_location_attribute PROTO((dw_die_ref, tree));
2481 static void add_const_value_attribute PROTO((dw_die_ref, rtx));
2482 static void add_location_or_const_value_attribute PROTO((dw_die_ref, tree));
2483 static void add_name_attribute PROTO((dw_die_ref, const char *));
2484 static void add_bound_info PROTO((dw_die_ref,
2485 enum dwarf_attribute, tree));
2486 static void add_subscript_info PROTO((dw_die_ref, tree));
2487 static void add_byte_size_attribute PROTO((dw_die_ref, tree));
2488 static void add_bit_offset_attribute PROTO((dw_die_ref, tree));
2489 static void add_bit_size_attribute PROTO((dw_die_ref, tree));
2490 static void add_prototyped_attribute PROTO((dw_die_ref, tree));
2491 static void add_abstract_origin_attribute PROTO((dw_die_ref, tree));
2492 static void add_pure_or_virtual_attribute PROTO((dw_die_ref, tree));
2493 static void add_src_coords_attributes PROTO((dw_die_ref, tree));
2494 static void add_name_and_src_coords_attributes PROTO((dw_die_ref, tree));
2495 static void push_decl_scope PROTO((tree));
2496 static dw_die_ref scope_die_for PROTO((tree, dw_die_ref));
2497 static void pop_decl_scope PROTO((void));
2498 static void add_type_attribute PROTO((dw_die_ref, tree, int, int,
2499 dw_die_ref));
2500 static char *type_tag PROTO((tree));
2501 static tree member_declared_type PROTO((tree));
2502 #if 0
2503 static char *decl_start_label PROTO((tree));
2504 #endif
2505 static void gen_array_type_die PROTO((tree, dw_die_ref));
2506 static void gen_set_type_die PROTO((tree, dw_die_ref));
2507 #if 0
2508 static void gen_entry_point_die PROTO((tree, dw_die_ref));
2509 #endif
2510 static void pend_type PROTO((tree));
2511 static void output_pending_types_for_scope PROTO((dw_die_ref));
2512 static void gen_inlined_enumeration_type_die PROTO((tree, dw_die_ref));
2513 static void gen_inlined_structure_type_die PROTO((tree, dw_die_ref));
2514 static void gen_inlined_union_type_die PROTO((tree, dw_die_ref));
2515 static void gen_enumeration_type_die PROTO((tree, dw_die_ref));
2516 static dw_die_ref gen_formal_parameter_die PROTO((tree, dw_die_ref));
2517 static void gen_unspecified_parameters_die PROTO((tree, dw_die_ref));
2518 static void gen_formal_types_die PROTO((tree, dw_die_ref));
2519 static void gen_subprogram_die PROTO((tree, dw_die_ref));
2520 static void gen_variable_die PROTO((tree, dw_die_ref));
2521 static void gen_label_die PROTO((tree, dw_die_ref));
2522 static void gen_lexical_block_die PROTO((tree, dw_die_ref, int));
2523 static void gen_inlined_subroutine_die PROTO((tree, dw_die_ref, int));
2524 static void gen_field_die PROTO((tree, dw_die_ref));
2525 static void gen_ptr_to_mbr_type_die PROTO((tree, dw_die_ref));
2526 static void gen_compile_unit_die PROTO((char *));
2527 static void gen_string_type_die PROTO((tree, dw_die_ref));
2528 static void gen_inheritance_die PROTO((tree, dw_die_ref));
2529 static void gen_member_die PROTO((tree, dw_die_ref));
2530 static void gen_struct_or_union_type_die PROTO((tree, dw_die_ref));
2531 static void gen_subroutine_type_die PROTO((tree, dw_die_ref));
2532 static void gen_typedef_die PROTO((tree, dw_die_ref));
2533 static void gen_type_die PROTO((tree, dw_die_ref));
2534 static void gen_tagged_type_instantiation_die PROTO((tree, dw_die_ref));
2535 static void gen_block_die PROTO((tree, dw_die_ref, int));
2536 static void decls_for_scope PROTO((tree, dw_die_ref, int));
2537 static int is_redundant_typedef PROTO((tree));
2538 static void gen_decl_die PROTO((tree, dw_die_ref));
2539 static unsigned lookup_filename PROTO((const char *));
2540 static void add_incomplete_type PROTO((tree));
2541 static void retry_incomplete_types PROTO((void));
2543 /* Section names used to hold DWARF debugging information. */
2544 #ifndef DEBUG_INFO_SECTION
2545 #define DEBUG_INFO_SECTION ".debug_info"
2546 #endif
2547 #ifndef ABBREV_SECTION
2548 #define ABBREV_SECTION ".debug_abbrev"
2549 #endif
2550 #ifndef ARANGES_SECTION
2551 #define ARANGES_SECTION ".debug_aranges"
2552 #endif
2553 #ifndef DW_MACINFO_SECTION
2554 #define DW_MACINFO_SECTION ".debug_macinfo"
2555 #endif
2556 #ifndef DEBUG_LINE_SECTION
2557 #define DEBUG_LINE_SECTION ".debug_line"
2558 #endif
2559 #ifndef LOC_SECTION
2560 #define LOC_SECTION ".debug_loc"
2561 #endif
2562 #ifndef PUBNAMES_SECTION
2563 #define PUBNAMES_SECTION ".debug_pubnames"
2564 #endif
2565 #ifndef STR_SECTION
2566 #define STR_SECTION ".debug_str"
2567 #endif
2569 /* Standard ELF section names for compiled code and data. */
2570 #ifndef TEXT_SECTION
2571 #define TEXT_SECTION ".text"
2572 #endif
2573 #ifndef DATA_SECTION
2574 #define DATA_SECTION ".data"
2575 #endif
2576 #ifndef BSS_SECTION
2577 #define BSS_SECTION ".bss"
2578 #endif
2580 /* Labels we insert at beginning sections we can reference instead of
2581 the section names themselves. */
2583 #ifndef TEXT_SECTION_LABEL
2584 #define TEXT_SECTION_LABEL "Ltext"
2585 #endif
2586 #ifndef DEBUG_LINE_SECTION_LABEL
2587 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
2588 #endif
2589 #ifndef DEBUG_INFO_SECTION_LABEL
2590 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
2591 #endif
2592 #ifndef ABBREV_SECTION_LABEL
2593 #define ABBREV_SECTION_LABEL "Ldebug_abbrev"
2594 #endif
2597 /* Definitions of defaults for formats and names of various special
2598 (artificial) labels which may be generated within this file (when the -g
2599 options is used and DWARF_DEBUGGING_INFO is in effect.
2600 If necessary, these may be overridden from within the tm.h file, but
2601 typically, overriding these defaults is unnecessary. */
2603 static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
2604 static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2605 static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2606 static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2607 static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES];
2609 #ifndef TEXT_END_LABEL
2610 #define TEXT_END_LABEL "Letext"
2611 #endif
2612 #ifndef DATA_END_LABEL
2613 #define DATA_END_LABEL "Ledata"
2614 #endif
2615 #ifndef BSS_END_LABEL
2616 #define BSS_END_LABEL "Lebss"
2617 #endif
2618 #ifndef INSN_LABEL_FMT
2619 #define INSN_LABEL_FMT "LI%u_"
2620 #endif
2621 #ifndef BLOCK_BEGIN_LABEL
2622 #define BLOCK_BEGIN_LABEL "LBB"
2623 #endif
2624 #ifndef BLOCK_END_LABEL
2625 #define BLOCK_END_LABEL "LBE"
2626 #endif
2627 #ifndef BODY_BEGIN_LABEL
2628 #define BODY_BEGIN_LABEL "Lbb"
2629 #endif
2630 #ifndef BODY_END_LABEL
2631 #define BODY_END_LABEL "Lbe"
2632 #endif
2633 #ifndef LINE_CODE_LABEL
2634 #define LINE_CODE_LABEL "LM"
2635 #endif
2636 #ifndef SEPARATE_LINE_CODE_LABEL
2637 #define SEPARATE_LINE_CODE_LABEL "LSM"
2638 #endif
2640 /* Convert a reference to the assembler name of a C-level name. This
2641 macro has the same effect as ASM_OUTPUT_LABELREF, but copies to
2642 a string rather than writing to a file. */
2643 #ifndef ASM_NAME_TO_STRING
2644 #define ASM_NAME_TO_STRING(STR, NAME) \
2645 do { \
2646 if ((NAME)[0] == '*') \
2647 dyn_string_append (STR, NAME + 1); \
2648 else \
2650 const char *newstr; \
2651 STRIP_NAME_ENCODING (newstr, NAME); \
2652 dyn_string_append (STR, user_label_prefix); \
2653 dyn_string_append (STR, newstr); \
2656 while (0)
2657 #endif
2659 /* We allow a language front-end to designate a function that is to be
2660 called to "demangle" any name before it it put into a DIE. */
2662 static char *(*demangle_name_func) PROTO((char *));
2664 void
2665 dwarf2out_set_demangle_name_func (func)
2666 char *(*func) PROTO((char *));
2668 demangle_name_func = func;
2671 /* Convert an integer constant expression into assembler syntax. Addition
2672 and subtraction are the only arithmetic that may appear in these
2673 expressions. This is an adaptation of output_addr_const in final.c.
2674 Here, the target of the conversion is a string buffer. We can't use
2675 output_addr_const directly, because it writes to a file. */
2677 static void
2678 addr_const_to_string (str, x)
2679 dyn_string_t str;
2680 rtx x;
2682 char buf1[256];
2684 restart:
2685 switch (GET_CODE (x))
2687 case PC:
2688 if (flag_pic)
2689 dyn_string_append (str, ",");
2690 else
2691 abort ();
2692 break;
2694 case SYMBOL_REF:
2695 ASM_NAME_TO_STRING (str, XSTR (x, 0));
2696 break;
2698 case LABEL_REF:
2699 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (XEXP (x, 0)));
2700 ASM_NAME_TO_STRING (str, buf1);
2701 break;
2703 case CODE_LABEL:
2704 ASM_GENERATE_INTERNAL_LABEL (buf1, "L", CODE_LABEL_NUMBER (x));
2705 ASM_NAME_TO_STRING (str, buf1);
2706 break;
2708 case CONST_INT:
2709 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
2710 dyn_string_append (str, buf1);
2711 break;
2713 case CONST:
2714 /* This used to output parentheses around the expression, but that does
2715 not work on the 386 (either ATT or BSD assembler). */
2716 addr_const_to_string (str, XEXP (x, 0));
2717 break;
2719 case CONST_DOUBLE:
2720 if (GET_MODE (x) == VOIDmode)
2722 /* We can use %d if the number is one word and positive. */
2723 if (CONST_DOUBLE_HIGH (x))
2724 sprintf (buf1, HOST_WIDE_INT_PRINT_DOUBLE_HEX,
2725 CONST_DOUBLE_HIGH (x), CONST_DOUBLE_LOW (x));
2726 else if (CONST_DOUBLE_LOW (x) < 0)
2727 sprintf (buf1, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
2728 else
2729 sprintf (buf1, HOST_WIDE_INT_PRINT_DEC,
2730 CONST_DOUBLE_LOW (x));
2731 dyn_string_append (str, buf1);
2733 else
2734 /* We can't handle floating point constants; PRINT_OPERAND must
2735 handle them. */
2736 output_operand_lossage ("floating constant misused");
2737 break;
2739 case PLUS:
2740 /* Some assemblers need integer constants to appear last (eg masm). */
2741 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2743 addr_const_to_string (str, XEXP (x, 1));
2744 if (INTVAL (XEXP (x, 0)) >= 0)
2745 dyn_string_append (str, "+");
2747 addr_const_to_string (str, XEXP (x, 0));
2749 else
2751 addr_const_to_string (str, XEXP (x, 0));
2752 if (INTVAL (XEXP (x, 1)) >= 0)
2753 dyn_string_append (str, "+");
2755 addr_const_to_string (str, XEXP (x, 1));
2757 break;
2759 case MINUS:
2760 /* Avoid outputting things like x-x or x+5-x, since some assemblers
2761 can't handle that. */
2762 x = simplify_subtraction (x);
2763 if (GET_CODE (x) != MINUS)
2764 goto restart;
2766 addr_const_to_string (str, XEXP (x, 0));
2767 dyn_string_append (str, "-");
2768 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2769 && INTVAL (XEXP (x, 1)) < 0)
2771 dyn_string_append (str, ASM_OPEN_PAREN);
2772 addr_const_to_string (str, XEXP (x, 1));
2773 dyn_string_append (str, ASM_CLOSE_PAREN);
2775 else
2776 addr_const_to_string (str, XEXP (x, 1));
2777 break;
2779 case ZERO_EXTEND:
2780 case SIGN_EXTEND:
2781 addr_const_to_string (str, XEXP (x, 0));
2782 break;
2784 default:
2785 output_operand_lossage ("invalid expression as operand");
2789 /* Convert an address constant to a string, and return a pointer to
2790 a copy of the result, located on the heap. */
2792 static char *
2793 addr_to_string (x)
2794 rtx x;
2796 dyn_string_t ds = dyn_string_new (256);
2797 char *s;
2799 addr_const_to_string (ds, x);
2801 /* Return the dynamically allocated string, but free the
2802 dyn_string_t itself. */
2803 s = ds->s;
2804 free (ds);
2805 return s;
2808 /* Test if rtl node points to a pseudo register. */
2810 static inline int
2811 is_pseudo_reg (rtl)
2812 register rtx rtl;
2814 return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER))
2815 || ((GET_CODE (rtl) == SUBREG)
2816 && (REGNO (XEXP (rtl, 0)) >= FIRST_PSEUDO_REGISTER)));
2819 /* Return a reference to a type, with its const and volatile qualifiers
2820 removed. */
2822 static inline tree
2823 type_main_variant (type)
2824 register tree type;
2826 type = TYPE_MAIN_VARIANT (type);
2828 /* There really should be only one main variant among any group of variants
2829 of a given type (and all of the MAIN_VARIANT values for all members of
2830 the group should point to that one type) but sometimes the C front-end
2831 messes this up for array types, so we work around that bug here. */
2833 if (TREE_CODE (type) == ARRAY_TYPE)
2834 while (type != TYPE_MAIN_VARIANT (type))
2835 type = TYPE_MAIN_VARIANT (type);
2837 return type;
2840 /* Return non-zero if the given type node represents a tagged type. */
2842 static inline int
2843 is_tagged_type (type)
2844 register tree type;
2846 register enum tree_code code = TREE_CODE (type);
2848 return (code == RECORD_TYPE || code == UNION_TYPE
2849 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE);
2852 /* Convert a DIE tag into its string name. */
2854 static const char *
2855 dwarf_tag_name (tag)
2856 register unsigned tag;
2858 switch (tag)
2860 case DW_TAG_padding:
2861 return "DW_TAG_padding";
2862 case DW_TAG_array_type:
2863 return "DW_TAG_array_type";
2864 case DW_TAG_class_type:
2865 return "DW_TAG_class_type";
2866 case DW_TAG_entry_point:
2867 return "DW_TAG_entry_point";
2868 case DW_TAG_enumeration_type:
2869 return "DW_TAG_enumeration_type";
2870 case DW_TAG_formal_parameter:
2871 return "DW_TAG_formal_parameter";
2872 case DW_TAG_imported_declaration:
2873 return "DW_TAG_imported_declaration";
2874 case DW_TAG_label:
2875 return "DW_TAG_label";
2876 case DW_TAG_lexical_block:
2877 return "DW_TAG_lexical_block";
2878 case DW_TAG_member:
2879 return "DW_TAG_member";
2880 case DW_TAG_pointer_type:
2881 return "DW_TAG_pointer_type";
2882 case DW_TAG_reference_type:
2883 return "DW_TAG_reference_type";
2884 case DW_TAG_compile_unit:
2885 return "DW_TAG_compile_unit";
2886 case DW_TAG_string_type:
2887 return "DW_TAG_string_type";
2888 case DW_TAG_structure_type:
2889 return "DW_TAG_structure_type";
2890 case DW_TAG_subroutine_type:
2891 return "DW_TAG_subroutine_type";
2892 case DW_TAG_typedef:
2893 return "DW_TAG_typedef";
2894 case DW_TAG_union_type:
2895 return "DW_TAG_union_type";
2896 case DW_TAG_unspecified_parameters:
2897 return "DW_TAG_unspecified_parameters";
2898 case DW_TAG_variant:
2899 return "DW_TAG_variant";
2900 case DW_TAG_common_block:
2901 return "DW_TAG_common_block";
2902 case DW_TAG_common_inclusion:
2903 return "DW_TAG_common_inclusion";
2904 case DW_TAG_inheritance:
2905 return "DW_TAG_inheritance";
2906 case DW_TAG_inlined_subroutine:
2907 return "DW_TAG_inlined_subroutine";
2908 case DW_TAG_module:
2909 return "DW_TAG_module";
2910 case DW_TAG_ptr_to_member_type:
2911 return "DW_TAG_ptr_to_member_type";
2912 case DW_TAG_set_type:
2913 return "DW_TAG_set_type";
2914 case DW_TAG_subrange_type:
2915 return "DW_TAG_subrange_type";
2916 case DW_TAG_with_stmt:
2917 return "DW_TAG_with_stmt";
2918 case DW_TAG_access_declaration:
2919 return "DW_TAG_access_declaration";
2920 case DW_TAG_base_type:
2921 return "DW_TAG_base_type";
2922 case DW_TAG_catch_block:
2923 return "DW_TAG_catch_block";
2924 case DW_TAG_const_type:
2925 return "DW_TAG_const_type";
2926 case DW_TAG_constant:
2927 return "DW_TAG_constant";
2928 case DW_TAG_enumerator:
2929 return "DW_TAG_enumerator";
2930 case DW_TAG_file_type:
2931 return "DW_TAG_file_type";
2932 case DW_TAG_friend:
2933 return "DW_TAG_friend";
2934 case DW_TAG_namelist:
2935 return "DW_TAG_namelist";
2936 case DW_TAG_namelist_item:
2937 return "DW_TAG_namelist_item";
2938 case DW_TAG_packed_type:
2939 return "DW_TAG_packed_type";
2940 case DW_TAG_subprogram:
2941 return "DW_TAG_subprogram";
2942 case DW_TAG_template_type_param:
2943 return "DW_TAG_template_type_param";
2944 case DW_TAG_template_value_param:
2945 return "DW_TAG_template_value_param";
2946 case DW_TAG_thrown_type:
2947 return "DW_TAG_thrown_type";
2948 case DW_TAG_try_block:
2949 return "DW_TAG_try_block";
2950 case DW_TAG_variant_part:
2951 return "DW_TAG_variant_part";
2952 case DW_TAG_variable:
2953 return "DW_TAG_variable";
2954 case DW_TAG_volatile_type:
2955 return "DW_TAG_volatile_type";
2956 case DW_TAG_MIPS_loop:
2957 return "DW_TAG_MIPS_loop";
2958 case DW_TAG_format_label:
2959 return "DW_TAG_format_label";
2960 case DW_TAG_function_template:
2961 return "DW_TAG_function_template";
2962 case DW_TAG_class_template:
2963 return "DW_TAG_class_template";
2964 default:
2965 return "DW_TAG_<unknown>";
2969 /* Convert a DWARF attribute code into its string name. */
2971 static const char *
2972 dwarf_attr_name (attr)
2973 register unsigned attr;
2975 switch (attr)
2977 case DW_AT_sibling:
2978 return "DW_AT_sibling";
2979 case DW_AT_location:
2980 return "DW_AT_location";
2981 case DW_AT_name:
2982 return "DW_AT_name";
2983 case DW_AT_ordering:
2984 return "DW_AT_ordering";
2985 case DW_AT_subscr_data:
2986 return "DW_AT_subscr_data";
2987 case DW_AT_byte_size:
2988 return "DW_AT_byte_size";
2989 case DW_AT_bit_offset:
2990 return "DW_AT_bit_offset";
2991 case DW_AT_bit_size:
2992 return "DW_AT_bit_size";
2993 case DW_AT_element_list:
2994 return "DW_AT_element_list";
2995 case DW_AT_stmt_list:
2996 return "DW_AT_stmt_list";
2997 case DW_AT_low_pc:
2998 return "DW_AT_low_pc";
2999 case DW_AT_high_pc:
3000 return "DW_AT_high_pc";
3001 case DW_AT_language:
3002 return "DW_AT_language";
3003 case DW_AT_member:
3004 return "DW_AT_member";
3005 case DW_AT_discr:
3006 return "DW_AT_discr";
3007 case DW_AT_discr_value:
3008 return "DW_AT_discr_value";
3009 case DW_AT_visibility:
3010 return "DW_AT_visibility";
3011 case DW_AT_import:
3012 return "DW_AT_import";
3013 case DW_AT_string_length:
3014 return "DW_AT_string_length";
3015 case DW_AT_common_reference:
3016 return "DW_AT_common_reference";
3017 case DW_AT_comp_dir:
3018 return "DW_AT_comp_dir";
3019 case DW_AT_const_value:
3020 return "DW_AT_const_value";
3021 case DW_AT_containing_type:
3022 return "DW_AT_containing_type";
3023 case DW_AT_default_value:
3024 return "DW_AT_default_value";
3025 case DW_AT_inline:
3026 return "DW_AT_inline";
3027 case DW_AT_is_optional:
3028 return "DW_AT_is_optional";
3029 case DW_AT_lower_bound:
3030 return "DW_AT_lower_bound";
3031 case DW_AT_producer:
3032 return "DW_AT_producer";
3033 case DW_AT_prototyped:
3034 return "DW_AT_prototyped";
3035 case DW_AT_return_addr:
3036 return "DW_AT_return_addr";
3037 case DW_AT_start_scope:
3038 return "DW_AT_start_scope";
3039 case DW_AT_stride_size:
3040 return "DW_AT_stride_size";
3041 case DW_AT_upper_bound:
3042 return "DW_AT_upper_bound";
3043 case DW_AT_abstract_origin:
3044 return "DW_AT_abstract_origin";
3045 case DW_AT_accessibility:
3046 return "DW_AT_accessibility";
3047 case DW_AT_address_class:
3048 return "DW_AT_address_class";
3049 case DW_AT_artificial:
3050 return "DW_AT_artificial";
3051 case DW_AT_base_types:
3052 return "DW_AT_base_types";
3053 case DW_AT_calling_convention:
3054 return "DW_AT_calling_convention";
3055 case DW_AT_count:
3056 return "DW_AT_count";
3057 case DW_AT_data_member_location:
3058 return "DW_AT_data_member_location";
3059 case DW_AT_decl_column:
3060 return "DW_AT_decl_column";
3061 case DW_AT_decl_file:
3062 return "DW_AT_decl_file";
3063 case DW_AT_decl_line:
3064 return "DW_AT_decl_line";
3065 case DW_AT_declaration:
3066 return "DW_AT_declaration";
3067 case DW_AT_discr_list:
3068 return "DW_AT_discr_list";
3069 case DW_AT_encoding:
3070 return "DW_AT_encoding";
3071 case DW_AT_external:
3072 return "DW_AT_external";
3073 case DW_AT_frame_base:
3074 return "DW_AT_frame_base";
3075 case DW_AT_friend:
3076 return "DW_AT_friend";
3077 case DW_AT_identifier_case:
3078 return "DW_AT_identifier_case";
3079 case DW_AT_macro_info:
3080 return "DW_AT_macro_info";
3081 case DW_AT_namelist_items:
3082 return "DW_AT_namelist_items";
3083 case DW_AT_priority:
3084 return "DW_AT_priority";
3085 case DW_AT_segment:
3086 return "DW_AT_segment";
3087 case DW_AT_specification:
3088 return "DW_AT_specification";
3089 case DW_AT_static_link:
3090 return "DW_AT_static_link";
3091 case DW_AT_type:
3092 return "DW_AT_type";
3093 case DW_AT_use_location:
3094 return "DW_AT_use_location";
3095 case DW_AT_variable_parameter:
3096 return "DW_AT_variable_parameter";
3097 case DW_AT_virtuality:
3098 return "DW_AT_virtuality";
3099 case DW_AT_vtable_elem_location:
3100 return "DW_AT_vtable_elem_location";
3102 case DW_AT_MIPS_fde:
3103 return "DW_AT_MIPS_fde";
3104 case DW_AT_MIPS_loop_begin:
3105 return "DW_AT_MIPS_loop_begin";
3106 case DW_AT_MIPS_tail_loop_begin:
3107 return "DW_AT_MIPS_tail_loop_begin";
3108 case DW_AT_MIPS_epilog_begin:
3109 return "DW_AT_MIPS_epilog_begin";
3110 case DW_AT_MIPS_loop_unroll_factor:
3111 return "DW_AT_MIPS_loop_unroll_factor";
3112 case DW_AT_MIPS_software_pipeline_depth:
3113 return "DW_AT_MIPS_software_pipeline_depth";
3114 case DW_AT_MIPS_linkage_name:
3115 return "DW_AT_MIPS_linkage_name";
3116 case DW_AT_MIPS_stride:
3117 return "DW_AT_MIPS_stride";
3118 case DW_AT_MIPS_abstract_name:
3119 return "DW_AT_MIPS_abstract_name";
3120 case DW_AT_MIPS_clone_origin:
3121 return "DW_AT_MIPS_clone_origin";
3122 case DW_AT_MIPS_has_inlines:
3123 return "DW_AT_MIPS_has_inlines";
3125 case DW_AT_sf_names:
3126 return "DW_AT_sf_names";
3127 case DW_AT_src_info:
3128 return "DW_AT_src_info";
3129 case DW_AT_mac_info:
3130 return "DW_AT_mac_info";
3131 case DW_AT_src_coords:
3132 return "DW_AT_src_coords";
3133 case DW_AT_body_begin:
3134 return "DW_AT_body_begin";
3135 case DW_AT_body_end:
3136 return "DW_AT_body_end";
3137 default:
3138 return "DW_AT_<unknown>";
3142 /* Convert a DWARF value form code into its string name. */
3144 static const char *
3145 dwarf_form_name (form)
3146 register unsigned form;
3148 switch (form)
3150 case DW_FORM_addr:
3151 return "DW_FORM_addr";
3152 case DW_FORM_block2:
3153 return "DW_FORM_block2";
3154 case DW_FORM_block4:
3155 return "DW_FORM_block4";
3156 case DW_FORM_data2:
3157 return "DW_FORM_data2";
3158 case DW_FORM_data4:
3159 return "DW_FORM_data4";
3160 case DW_FORM_data8:
3161 return "DW_FORM_data8";
3162 case DW_FORM_string:
3163 return "DW_FORM_string";
3164 case DW_FORM_block:
3165 return "DW_FORM_block";
3166 case DW_FORM_block1:
3167 return "DW_FORM_block1";
3168 case DW_FORM_data1:
3169 return "DW_FORM_data1";
3170 case DW_FORM_flag:
3171 return "DW_FORM_flag";
3172 case DW_FORM_sdata:
3173 return "DW_FORM_sdata";
3174 case DW_FORM_strp:
3175 return "DW_FORM_strp";
3176 case DW_FORM_udata:
3177 return "DW_FORM_udata";
3178 case DW_FORM_ref_addr:
3179 return "DW_FORM_ref_addr";
3180 case DW_FORM_ref1:
3181 return "DW_FORM_ref1";
3182 case DW_FORM_ref2:
3183 return "DW_FORM_ref2";
3184 case DW_FORM_ref4:
3185 return "DW_FORM_ref4";
3186 case DW_FORM_ref8:
3187 return "DW_FORM_ref8";
3188 case DW_FORM_ref_udata:
3189 return "DW_FORM_ref_udata";
3190 case DW_FORM_indirect:
3191 return "DW_FORM_indirect";
3192 default:
3193 return "DW_FORM_<unknown>";
3197 /* Convert a DWARF stack opcode into its string name. */
3199 static const char *
3200 dwarf_stack_op_name (op)
3201 register unsigned op;
3203 switch (op)
3205 case DW_OP_addr:
3206 return "DW_OP_addr";
3207 case DW_OP_deref:
3208 return "DW_OP_deref";
3209 case DW_OP_const1u:
3210 return "DW_OP_const1u";
3211 case DW_OP_const1s:
3212 return "DW_OP_const1s";
3213 case DW_OP_const2u:
3214 return "DW_OP_const2u";
3215 case DW_OP_const2s:
3216 return "DW_OP_const2s";
3217 case DW_OP_const4u:
3218 return "DW_OP_const4u";
3219 case DW_OP_const4s:
3220 return "DW_OP_const4s";
3221 case DW_OP_const8u:
3222 return "DW_OP_const8u";
3223 case DW_OP_const8s:
3224 return "DW_OP_const8s";
3225 case DW_OP_constu:
3226 return "DW_OP_constu";
3227 case DW_OP_consts:
3228 return "DW_OP_consts";
3229 case DW_OP_dup:
3230 return "DW_OP_dup";
3231 case DW_OP_drop:
3232 return "DW_OP_drop";
3233 case DW_OP_over:
3234 return "DW_OP_over";
3235 case DW_OP_pick:
3236 return "DW_OP_pick";
3237 case DW_OP_swap:
3238 return "DW_OP_swap";
3239 case DW_OP_rot:
3240 return "DW_OP_rot";
3241 case DW_OP_xderef:
3242 return "DW_OP_xderef";
3243 case DW_OP_abs:
3244 return "DW_OP_abs";
3245 case DW_OP_and:
3246 return "DW_OP_and";
3247 case DW_OP_div:
3248 return "DW_OP_div";
3249 case DW_OP_minus:
3250 return "DW_OP_minus";
3251 case DW_OP_mod:
3252 return "DW_OP_mod";
3253 case DW_OP_mul:
3254 return "DW_OP_mul";
3255 case DW_OP_neg:
3256 return "DW_OP_neg";
3257 case DW_OP_not:
3258 return "DW_OP_not";
3259 case DW_OP_or:
3260 return "DW_OP_or";
3261 case DW_OP_plus:
3262 return "DW_OP_plus";
3263 case DW_OP_plus_uconst:
3264 return "DW_OP_plus_uconst";
3265 case DW_OP_shl:
3266 return "DW_OP_shl";
3267 case DW_OP_shr:
3268 return "DW_OP_shr";
3269 case DW_OP_shra:
3270 return "DW_OP_shra";
3271 case DW_OP_xor:
3272 return "DW_OP_xor";
3273 case DW_OP_bra:
3274 return "DW_OP_bra";
3275 case DW_OP_eq:
3276 return "DW_OP_eq";
3277 case DW_OP_ge:
3278 return "DW_OP_ge";
3279 case DW_OP_gt:
3280 return "DW_OP_gt";
3281 case DW_OP_le:
3282 return "DW_OP_le";
3283 case DW_OP_lt:
3284 return "DW_OP_lt";
3285 case DW_OP_ne:
3286 return "DW_OP_ne";
3287 case DW_OP_skip:
3288 return "DW_OP_skip";
3289 case DW_OP_lit0:
3290 return "DW_OP_lit0";
3291 case DW_OP_lit1:
3292 return "DW_OP_lit1";
3293 case DW_OP_lit2:
3294 return "DW_OP_lit2";
3295 case DW_OP_lit3:
3296 return "DW_OP_lit3";
3297 case DW_OP_lit4:
3298 return "DW_OP_lit4";
3299 case DW_OP_lit5:
3300 return "DW_OP_lit5";
3301 case DW_OP_lit6:
3302 return "DW_OP_lit6";
3303 case DW_OP_lit7:
3304 return "DW_OP_lit7";
3305 case DW_OP_lit8:
3306 return "DW_OP_lit8";
3307 case DW_OP_lit9:
3308 return "DW_OP_lit9";
3309 case DW_OP_lit10:
3310 return "DW_OP_lit10";
3311 case DW_OP_lit11:
3312 return "DW_OP_lit11";
3313 case DW_OP_lit12:
3314 return "DW_OP_lit12";
3315 case DW_OP_lit13:
3316 return "DW_OP_lit13";
3317 case DW_OP_lit14:
3318 return "DW_OP_lit14";
3319 case DW_OP_lit15:
3320 return "DW_OP_lit15";
3321 case DW_OP_lit16:
3322 return "DW_OP_lit16";
3323 case DW_OP_lit17:
3324 return "DW_OP_lit17";
3325 case DW_OP_lit18:
3326 return "DW_OP_lit18";
3327 case DW_OP_lit19:
3328 return "DW_OP_lit19";
3329 case DW_OP_lit20:
3330 return "DW_OP_lit20";
3331 case DW_OP_lit21:
3332 return "DW_OP_lit21";
3333 case DW_OP_lit22:
3334 return "DW_OP_lit22";
3335 case DW_OP_lit23:
3336 return "DW_OP_lit23";
3337 case DW_OP_lit24:
3338 return "DW_OP_lit24";
3339 case DW_OP_lit25:
3340 return "DW_OP_lit25";
3341 case DW_OP_lit26:
3342 return "DW_OP_lit26";
3343 case DW_OP_lit27:
3344 return "DW_OP_lit27";
3345 case DW_OP_lit28:
3346 return "DW_OP_lit28";
3347 case DW_OP_lit29:
3348 return "DW_OP_lit29";
3349 case DW_OP_lit30:
3350 return "DW_OP_lit30";
3351 case DW_OP_lit31:
3352 return "DW_OP_lit31";
3353 case DW_OP_reg0:
3354 return "DW_OP_reg0";
3355 case DW_OP_reg1:
3356 return "DW_OP_reg1";
3357 case DW_OP_reg2:
3358 return "DW_OP_reg2";
3359 case DW_OP_reg3:
3360 return "DW_OP_reg3";
3361 case DW_OP_reg4:
3362 return "DW_OP_reg4";
3363 case DW_OP_reg5:
3364 return "DW_OP_reg5";
3365 case DW_OP_reg6:
3366 return "DW_OP_reg6";
3367 case DW_OP_reg7:
3368 return "DW_OP_reg7";
3369 case DW_OP_reg8:
3370 return "DW_OP_reg8";
3371 case DW_OP_reg9:
3372 return "DW_OP_reg9";
3373 case DW_OP_reg10:
3374 return "DW_OP_reg10";
3375 case DW_OP_reg11:
3376 return "DW_OP_reg11";
3377 case DW_OP_reg12:
3378 return "DW_OP_reg12";
3379 case DW_OP_reg13:
3380 return "DW_OP_reg13";
3381 case DW_OP_reg14:
3382 return "DW_OP_reg14";
3383 case DW_OP_reg15:
3384 return "DW_OP_reg15";
3385 case DW_OP_reg16:
3386 return "DW_OP_reg16";
3387 case DW_OP_reg17:
3388 return "DW_OP_reg17";
3389 case DW_OP_reg18:
3390 return "DW_OP_reg18";
3391 case DW_OP_reg19:
3392 return "DW_OP_reg19";
3393 case DW_OP_reg20:
3394 return "DW_OP_reg20";
3395 case DW_OP_reg21:
3396 return "DW_OP_reg21";
3397 case DW_OP_reg22:
3398 return "DW_OP_reg22";
3399 case DW_OP_reg23:
3400 return "DW_OP_reg23";
3401 case DW_OP_reg24:
3402 return "DW_OP_reg24";
3403 case DW_OP_reg25:
3404 return "DW_OP_reg25";
3405 case DW_OP_reg26:
3406 return "DW_OP_reg26";
3407 case DW_OP_reg27:
3408 return "DW_OP_reg27";
3409 case DW_OP_reg28:
3410 return "DW_OP_reg28";
3411 case DW_OP_reg29:
3412 return "DW_OP_reg29";
3413 case DW_OP_reg30:
3414 return "DW_OP_reg30";
3415 case DW_OP_reg31:
3416 return "DW_OP_reg31";
3417 case DW_OP_breg0:
3418 return "DW_OP_breg0";
3419 case DW_OP_breg1:
3420 return "DW_OP_breg1";
3421 case DW_OP_breg2:
3422 return "DW_OP_breg2";
3423 case DW_OP_breg3:
3424 return "DW_OP_breg3";
3425 case DW_OP_breg4:
3426 return "DW_OP_breg4";
3427 case DW_OP_breg5:
3428 return "DW_OP_breg5";
3429 case DW_OP_breg6:
3430 return "DW_OP_breg6";
3431 case DW_OP_breg7:
3432 return "DW_OP_breg7";
3433 case DW_OP_breg8:
3434 return "DW_OP_breg8";
3435 case DW_OP_breg9:
3436 return "DW_OP_breg9";
3437 case DW_OP_breg10:
3438 return "DW_OP_breg10";
3439 case DW_OP_breg11:
3440 return "DW_OP_breg11";
3441 case DW_OP_breg12:
3442 return "DW_OP_breg12";
3443 case DW_OP_breg13:
3444 return "DW_OP_breg13";
3445 case DW_OP_breg14:
3446 return "DW_OP_breg14";
3447 case DW_OP_breg15:
3448 return "DW_OP_breg15";
3449 case DW_OP_breg16:
3450 return "DW_OP_breg16";
3451 case DW_OP_breg17:
3452 return "DW_OP_breg17";
3453 case DW_OP_breg18:
3454 return "DW_OP_breg18";
3455 case DW_OP_breg19:
3456 return "DW_OP_breg19";
3457 case DW_OP_breg20:
3458 return "DW_OP_breg20";
3459 case DW_OP_breg21:
3460 return "DW_OP_breg21";
3461 case DW_OP_breg22:
3462 return "DW_OP_breg22";
3463 case DW_OP_breg23:
3464 return "DW_OP_breg23";
3465 case DW_OP_breg24:
3466 return "DW_OP_breg24";
3467 case DW_OP_breg25:
3468 return "DW_OP_breg25";
3469 case DW_OP_breg26:
3470 return "DW_OP_breg26";
3471 case DW_OP_breg27:
3472 return "DW_OP_breg27";
3473 case DW_OP_breg28:
3474 return "DW_OP_breg28";
3475 case DW_OP_breg29:
3476 return "DW_OP_breg29";
3477 case DW_OP_breg30:
3478 return "DW_OP_breg30";
3479 case DW_OP_breg31:
3480 return "DW_OP_breg31";
3481 case DW_OP_regx:
3482 return "DW_OP_regx";
3483 case DW_OP_fbreg:
3484 return "DW_OP_fbreg";
3485 case DW_OP_bregx:
3486 return "DW_OP_bregx";
3487 case DW_OP_piece:
3488 return "DW_OP_piece";
3489 case DW_OP_deref_size:
3490 return "DW_OP_deref_size";
3491 case DW_OP_xderef_size:
3492 return "DW_OP_xderef_size";
3493 case DW_OP_nop:
3494 return "DW_OP_nop";
3495 default:
3496 return "OP_<unknown>";
3500 /* Convert a DWARF type code into its string name. */
3502 #if 0
3503 static const char *
3504 dwarf_type_encoding_name (enc)
3505 register unsigned enc;
3507 switch (enc)
3509 case DW_ATE_address:
3510 return "DW_ATE_address";
3511 case DW_ATE_boolean:
3512 return "DW_ATE_boolean";
3513 case DW_ATE_complex_float:
3514 return "DW_ATE_complex_float";
3515 case DW_ATE_float:
3516 return "DW_ATE_float";
3517 case DW_ATE_signed:
3518 return "DW_ATE_signed";
3519 case DW_ATE_signed_char:
3520 return "DW_ATE_signed_char";
3521 case DW_ATE_unsigned:
3522 return "DW_ATE_unsigned";
3523 case DW_ATE_unsigned_char:
3524 return "DW_ATE_unsigned_char";
3525 default:
3526 return "DW_ATE_<unknown>";
3529 #endif
3531 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3532 instance of an inlined instance of a decl which is local to an inline
3533 function, so we have to trace all of the way back through the origin chain
3534 to find out what sort of node actually served as the original seed for the
3535 given block. */
3537 static tree
3538 decl_ultimate_origin (decl)
3539 register tree decl;
3541 #ifdef ENABLE_CHECKING
3542 if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
3543 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3544 most distant ancestor, this should never happen. */
3545 abort ();
3546 #endif
3548 return DECL_ABSTRACT_ORIGIN (decl);
3551 /* Determine the "ultimate origin" of a block. The block may be an inlined
3552 instance of an inlined instance of a block which is local to an inline
3553 function, so we have to trace all of the way back through the origin chain
3554 to find out what sort of node actually served as the original seed for the
3555 given block. */
3557 static tree
3558 block_ultimate_origin (block)
3559 register tree block;
3561 register tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block);
3563 if (immediate_origin == NULL_TREE)
3564 return NULL_TREE;
3565 else
3567 register tree ret_val;
3568 register tree lookahead = immediate_origin;
3572 ret_val = lookahead;
3573 lookahead = (TREE_CODE (ret_val) == BLOCK)
3574 ? BLOCK_ABSTRACT_ORIGIN (ret_val)
3575 : NULL;
3577 while (lookahead != NULL && lookahead != ret_val);
3579 return ret_val;
3583 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3584 of a virtual function may refer to a base class, so we check the 'this'
3585 parameter. */
3587 static tree
3588 decl_class_context (decl)
3589 tree decl;
3591 tree context = NULL_TREE;
3593 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl))
3594 context = DECL_CONTEXT (decl);
3595 else
3596 context = TYPE_MAIN_VARIANT
3597 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
3599 if (context && TREE_CODE_CLASS (TREE_CODE (context)) != 't')
3600 context = NULL_TREE;
3602 return context;
3605 /* Add an attribute/value pair to a DIE */
3607 static inline void
3608 add_dwarf_attr (die, attr)
3609 register dw_die_ref die;
3610 register dw_attr_ref attr;
3612 if (die != NULL && attr != NULL)
3614 if (die->die_attr == NULL)
3616 die->die_attr = attr;
3617 die->die_attr_last = attr;
3619 else
3621 die->die_attr_last->dw_attr_next = attr;
3622 die->die_attr_last = attr;
3627 /* Add a flag value attribute to a DIE. */
3629 static inline void
3630 add_AT_flag (die, attr_kind, flag)
3631 register dw_die_ref die;
3632 register enum dwarf_attribute attr_kind;
3633 register unsigned flag;
3635 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3637 attr->dw_attr_next = NULL;
3638 attr->dw_attr = attr_kind;
3639 attr->dw_attr_val.val_class = dw_val_class_flag;
3640 attr->dw_attr_val.v.val_flag = flag;
3641 add_dwarf_attr (die, attr);
3644 /* Add a signed integer attribute value to a DIE. */
3646 static inline void
3647 add_AT_int (die, attr_kind, int_val)
3648 register dw_die_ref die;
3649 register enum dwarf_attribute attr_kind;
3650 register long int int_val;
3652 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3654 attr->dw_attr_next = NULL;
3655 attr->dw_attr = attr_kind;
3656 attr->dw_attr_val.val_class = dw_val_class_const;
3657 attr->dw_attr_val.v.val_int = int_val;
3658 add_dwarf_attr (die, attr);
3661 /* Add an unsigned integer attribute value to a DIE. */
3663 static inline void
3664 add_AT_unsigned (die, attr_kind, unsigned_val)
3665 register dw_die_ref die;
3666 register enum dwarf_attribute attr_kind;
3667 register unsigned long unsigned_val;
3669 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3671 attr->dw_attr_next = NULL;
3672 attr->dw_attr = attr_kind;
3673 attr->dw_attr_val.val_class = dw_val_class_unsigned_const;
3674 attr->dw_attr_val.v.val_unsigned = unsigned_val;
3675 add_dwarf_attr (die, attr);
3678 /* Add an unsigned double integer attribute value to a DIE. */
3680 static inline void
3681 add_AT_long_long (die, attr_kind, val_hi, val_low)
3682 register dw_die_ref die;
3683 register enum dwarf_attribute attr_kind;
3684 register unsigned long val_hi;
3685 register unsigned long val_low;
3687 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3689 attr->dw_attr_next = NULL;
3690 attr->dw_attr = attr_kind;
3691 attr->dw_attr_val.val_class = dw_val_class_long_long;
3692 attr->dw_attr_val.v.val_long_long.hi = val_hi;
3693 attr->dw_attr_val.v.val_long_long.low = val_low;
3694 add_dwarf_attr (die, attr);
3697 /* Add a floating point attribute value to a DIE and return it. */
3699 static inline void
3700 add_AT_float (die, attr_kind, length, array)
3701 register dw_die_ref die;
3702 register enum dwarf_attribute attr_kind;
3703 register unsigned length;
3704 register long *array;
3706 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3708 attr->dw_attr_next = NULL;
3709 attr->dw_attr = attr_kind;
3710 attr->dw_attr_val.val_class = dw_val_class_float;
3711 attr->dw_attr_val.v.val_float.length = length;
3712 attr->dw_attr_val.v.val_float.array = array;
3713 add_dwarf_attr (die, attr);
3716 /* Add a string attribute value to a DIE. */
3718 static inline void
3719 add_AT_string (die, attr_kind, str)
3720 register dw_die_ref die;
3721 register enum dwarf_attribute attr_kind;
3722 register const char *str;
3724 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3726 attr->dw_attr_next = NULL;
3727 attr->dw_attr = attr_kind;
3728 attr->dw_attr_val.val_class = dw_val_class_str;
3729 attr->dw_attr_val.v.val_str = xstrdup (str);
3730 add_dwarf_attr (die, attr);
3733 /* Add a DIE reference attribute value to a DIE. */
3735 static inline void
3736 add_AT_die_ref (die, attr_kind, targ_die)
3737 register dw_die_ref die;
3738 register enum dwarf_attribute attr_kind;
3739 register dw_die_ref targ_die;
3741 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3743 attr->dw_attr_next = NULL;
3744 attr->dw_attr = attr_kind;
3745 attr->dw_attr_val.val_class = dw_val_class_die_ref;
3746 attr->dw_attr_val.v.val_die_ref = targ_die;
3747 add_dwarf_attr (die, attr);
3750 /* Add an FDE reference attribute value to a DIE. */
3752 static inline void
3753 add_AT_fde_ref (die, attr_kind, targ_fde)
3754 register dw_die_ref die;
3755 register enum dwarf_attribute attr_kind;
3756 register unsigned targ_fde;
3758 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3760 attr->dw_attr_next = NULL;
3761 attr->dw_attr = attr_kind;
3762 attr->dw_attr_val.val_class = dw_val_class_fde_ref;
3763 attr->dw_attr_val.v.val_fde_index = targ_fde;
3764 add_dwarf_attr (die, attr);
3767 /* Add a location description attribute value to a DIE. */
3769 static inline void
3770 add_AT_loc (die, attr_kind, loc)
3771 register dw_die_ref die;
3772 register enum dwarf_attribute attr_kind;
3773 register dw_loc_descr_ref loc;
3775 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3777 attr->dw_attr_next = NULL;
3778 attr->dw_attr = attr_kind;
3779 attr->dw_attr_val.val_class = dw_val_class_loc;
3780 attr->dw_attr_val.v.val_loc = loc;
3781 add_dwarf_attr (die, attr);
3784 /* Add an address constant attribute value to a DIE. */
3786 static inline void
3787 add_AT_addr (die, attr_kind, addr)
3788 register dw_die_ref die;
3789 register enum dwarf_attribute attr_kind;
3790 char *addr;
3792 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3794 attr->dw_attr_next = NULL;
3795 attr->dw_attr = attr_kind;
3796 attr->dw_attr_val.val_class = dw_val_class_addr;
3797 attr->dw_attr_val.v.val_addr = addr;
3798 add_dwarf_attr (die, attr);
3801 /* Add a label identifier attribute value to a DIE. */
3803 static inline void
3804 add_AT_lbl_id (die, attr_kind, lbl_id)
3805 register dw_die_ref die;
3806 register enum dwarf_attribute attr_kind;
3807 register char *lbl_id;
3809 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3811 attr->dw_attr_next = NULL;
3812 attr->dw_attr = attr_kind;
3813 attr->dw_attr_val.val_class = dw_val_class_lbl_id;
3814 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id);
3815 add_dwarf_attr (die, attr);
3818 /* Add a section offset attribute value to a DIE. */
3820 static inline void
3821 add_AT_lbl_offset (die, attr_kind, label)
3822 register dw_die_ref die;
3823 register enum dwarf_attribute attr_kind;
3824 register char *label;
3826 register dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
3828 attr->dw_attr_next = NULL;
3829 attr->dw_attr = attr_kind;
3830 attr->dw_attr_val.val_class = dw_val_class_lbl_offset;
3831 attr->dw_attr_val.v.val_lbl_id = label;
3832 add_dwarf_attr (die, attr);
3836 /* Test if die refers to an external subroutine. */
3838 static inline int
3839 is_extern_subr_die (die)
3840 register dw_die_ref die;
3842 register dw_attr_ref a;
3843 register int is_subr = FALSE;
3844 register int is_extern = FALSE;
3846 if (die != NULL && die->die_tag == DW_TAG_subprogram)
3848 is_subr = TRUE;
3849 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3851 if (a->dw_attr == DW_AT_external
3852 && a->dw_attr_val.val_class == dw_val_class_flag
3853 && a->dw_attr_val.v.val_flag != 0)
3855 is_extern = TRUE;
3856 break;
3861 return is_subr && is_extern;
3864 /* Get the attribute of type attr_kind. */
3866 static inline dw_attr_ref
3867 get_AT (die, attr_kind)
3868 register dw_die_ref die;
3869 register enum dwarf_attribute attr_kind;
3871 register dw_attr_ref a;
3872 register dw_die_ref spec = NULL;
3874 if (die != NULL)
3876 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
3878 if (a->dw_attr == attr_kind)
3879 return a;
3881 if (a->dw_attr == DW_AT_specification
3882 || a->dw_attr == DW_AT_abstract_origin)
3883 spec = a->dw_attr_val.v.val_die_ref;
3886 if (spec)
3887 return get_AT (spec, attr_kind);
3890 return NULL;
3893 /* Return the "low pc" attribute value, typically associated with
3894 a subprogram DIE. Return null if the "low pc" attribute is
3895 either not prsent, or if it cannot be represented as an
3896 assembler label identifier. */
3898 static inline char *
3899 get_AT_low_pc (die)
3900 register dw_die_ref die;
3902 register dw_attr_ref a = get_AT (die, DW_AT_low_pc);
3904 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3905 return a->dw_attr_val.v.val_lbl_id;
3907 return NULL;
3910 /* Return the "high pc" attribute value, typically associated with
3911 a subprogram DIE. Return null if the "high pc" attribute is
3912 either not prsent, or if it cannot be represented as an
3913 assembler label identifier. */
3915 static inline char *
3916 get_AT_hi_pc (die)
3917 register dw_die_ref die;
3919 register dw_attr_ref a = get_AT (die, DW_AT_high_pc);
3921 if (a && a->dw_attr_val.val_class == dw_val_class_lbl_id)
3922 return a->dw_attr_val.v.val_lbl_id;
3924 return NULL;
3927 /* Return the value of the string attribute designated by ATTR_KIND, or
3928 NULL if it is not present. */
3930 static inline char *
3931 get_AT_string (die, attr_kind)
3932 register dw_die_ref die;
3933 register enum dwarf_attribute attr_kind;
3935 register dw_attr_ref a = get_AT (die, attr_kind);
3937 if (a && a->dw_attr_val.val_class == dw_val_class_str)
3938 return a->dw_attr_val.v.val_str;
3940 return NULL;
3943 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
3944 if it is not present. */
3946 static inline int
3947 get_AT_flag (die, attr_kind)
3948 register dw_die_ref die;
3949 register enum dwarf_attribute attr_kind;
3951 register dw_attr_ref a = get_AT (die, attr_kind);
3953 if (a && a->dw_attr_val.val_class == dw_val_class_flag)
3954 return a->dw_attr_val.v.val_flag;
3956 return -1;
3959 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
3960 if it is not present. */
3962 static inline unsigned
3963 get_AT_unsigned (die, attr_kind)
3964 register dw_die_ref die;
3965 register enum dwarf_attribute attr_kind;
3967 register dw_attr_ref a = get_AT (die, attr_kind);
3969 if (a && a->dw_attr_val.val_class == dw_val_class_unsigned_const)
3970 return a->dw_attr_val.v.val_unsigned;
3972 return 0;
3975 static inline int
3976 is_c_family ()
3978 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3980 return (lang == DW_LANG_C || lang == DW_LANG_C89
3981 || lang == DW_LANG_C_plus_plus);
3984 static inline int
3985 is_fortran ()
3987 register unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language);
3989 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90);
3992 /* Remove the specified attribute if present. */
3994 static inline void
3995 remove_AT (die, attr_kind)
3996 register dw_die_ref die;
3997 register enum dwarf_attribute attr_kind;
3999 register dw_attr_ref a;
4000 register dw_attr_ref removed = NULL;
4002 if (die != NULL)
4004 if (die->die_attr->dw_attr == attr_kind)
4006 removed = die->die_attr;
4007 if (die->die_attr_last == die->die_attr)
4008 die->die_attr_last = NULL;
4010 die->die_attr = die->die_attr->dw_attr_next;
4013 else
4014 for (a = die->die_attr; a->dw_attr_next != NULL;
4015 a = a->dw_attr_next)
4016 if (a->dw_attr_next->dw_attr == attr_kind)
4018 removed = a->dw_attr_next;
4019 if (die->die_attr_last == a->dw_attr_next)
4020 die->die_attr_last = a;
4022 a->dw_attr_next = a->dw_attr_next->dw_attr_next;
4023 break;
4026 if (removed != 0)
4027 free (removed);
4031 /* Discard the children of this DIE. */
4033 static inline void
4034 remove_children (die)
4035 register dw_die_ref die;
4037 register dw_die_ref child_die = die->die_child;
4039 die->die_child = NULL;
4040 die->die_child_last = NULL;
4042 while (child_die != NULL)
4044 register dw_die_ref tmp_die = child_die;
4045 register dw_attr_ref a;
4047 child_die = child_die->die_sib;
4049 for (a = tmp_die->die_attr; a != NULL; )
4051 register dw_attr_ref tmp_a = a;
4053 a = a->dw_attr_next;
4054 free (tmp_a);
4057 free (tmp_die);
4061 /* Add a child DIE below its parent. */
4063 static inline void
4064 add_child_die (die, child_die)
4065 register dw_die_ref die;
4066 register dw_die_ref child_die;
4068 if (die != NULL && child_die != NULL)
4070 if (die == child_die)
4071 abort ();
4072 child_die->die_parent = die;
4073 child_die->die_sib = NULL;
4075 if (die->die_child == NULL)
4077 die->die_child = child_die;
4078 die->die_child_last = child_die;
4080 else
4082 die->die_child_last->die_sib = child_die;
4083 die->die_child_last = child_die;
4088 /* Return a pointer to a newly created DIE node. */
4090 static inline dw_die_ref
4091 new_die (tag_value, parent_die)
4092 register enum dwarf_tag tag_value;
4093 register dw_die_ref parent_die;
4095 register dw_die_ref die = (dw_die_ref) xmalloc (sizeof (die_node));
4097 die->die_tag = tag_value;
4098 die->die_abbrev = 0;
4099 die->die_offset = 0;
4100 die->die_child = NULL;
4101 die->die_parent = NULL;
4102 die->die_sib = NULL;
4103 die->die_child_last = NULL;
4104 die->die_attr = NULL;
4105 die->die_attr_last = NULL;
4107 if (parent_die != NULL)
4108 add_child_die (parent_die, die);
4109 else
4111 limbo_die_node *limbo_node;
4113 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node));
4114 limbo_node->die = die;
4115 limbo_node->next = limbo_die_list;
4116 limbo_die_list = limbo_node;
4119 return die;
4122 /* Return the DIE associated with the given type specifier. */
4124 static inline dw_die_ref
4125 lookup_type_die (type)
4126 register tree type;
4128 return (dw_die_ref) TYPE_SYMTAB_POINTER (type);
4131 /* Equate a DIE to a given type specifier. */
4133 static void
4134 equate_type_number_to_die (type, type_die)
4135 register tree type;
4136 register dw_die_ref type_die;
4138 TYPE_SYMTAB_POINTER (type) = (char *) type_die;
4141 /* Return the DIE associated with a given declaration. */
4143 static inline dw_die_ref
4144 lookup_decl_die (decl)
4145 register tree decl;
4147 register unsigned decl_id = DECL_UID (decl);
4149 return (decl_id < decl_die_table_in_use
4150 ? decl_die_table[decl_id] : NULL);
4153 /* Equate a DIE to a particular declaration. */
4155 static void
4156 equate_decl_number_to_die (decl, decl_die)
4157 register tree decl;
4158 register dw_die_ref decl_die;
4160 register unsigned decl_id = DECL_UID (decl);
4161 register unsigned num_allocated;
4163 if (decl_id >= decl_die_table_allocated)
4165 num_allocated
4166 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1)
4167 / DECL_DIE_TABLE_INCREMENT)
4168 * DECL_DIE_TABLE_INCREMENT;
4170 decl_die_table
4171 = (dw_die_ref *) xrealloc (decl_die_table,
4172 sizeof (dw_die_ref) * num_allocated);
4174 bzero ((char *) &decl_die_table[decl_die_table_allocated],
4175 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref));
4176 decl_die_table_allocated = num_allocated;
4179 if (decl_id >= decl_die_table_in_use)
4180 decl_die_table_in_use = (decl_id + 1);
4182 decl_die_table[decl_id] = decl_die;
4185 /* Return a pointer to a newly allocated location description. Location
4186 descriptions are simple expression terms that can be strung
4187 together to form more complicated location (address) descriptions. */
4189 static inline dw_loc_descr_ref
4190 new_loc_descr (op, oprnd1, oprnd2)
4191 register enum dwarf_location_atom op;
4192 register unsigned long oprnd1;
4193 register unsigned long oprnd2;
4195 register dw_loc_descr_ref descr
4196 = (dw_loc_descr_ref) xmalloc (sizeof (dw_loc_descr_node));
4198 descr->dw_loc_next = NULL;
4199 descr->dw_loc_opc = op;
4200 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const;
4201 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1;
4202 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const;
4203 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2;
4205 return descr;
4208 /* Add a location description term to a location description expression. */
4210 static inline void
4211 add_loc_descr (list_head, descr)
4212 register dw_loc_descr_ref *list_head;
4213 register dw_loc_descr_ref descr;
4215 register dw_loc_descr_ref *d;
4217 /* Find the end of the chain. */
4218 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next)
4221 *d = descr;
4224 /* Keep track of the number of spaces used to indent the
4225 output of the debugging routines that print the structure of
4226 the DIE internal representation. */
4227 static int print_indent;
4229 /* Indent the line the number of spaces given by print_indent. */
4231 static inline void
4232 print_spaces (outfile)
4233 FILE *outfile;
4235 fprintf (outfile, "%*s", print_indent, "");
4238 /* Print the information associated with a given DIE, and its children.
4239 This routine is a debugging aid only. */
4241 static void
4242 print_die (die, outfile)
4243 dw_die_ref die;
4244 FILE *outfile;
4246 register dw_attr_ref a;
4247 register dw_die_ref c;
4249 print_spaces (outfile);
4250 fprintf (outfile, "DIE %4lu: %s\n",
4251 die->die_offset, dwarf_tag_name (die->die_tag));
4252 print_spaces (outfile);
4253 fprintf (outfile, " abbrev id: %lu", die->die_abbrev);
4254 fprintf (outfile, " offset: %lu\n", die->die_offset);
4256 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4258 print_spaces (outfile);
4259 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr));
4261 switch (a->dw_attr_val.val_class)
4263 case dw_val_class_addr:
4264 fprintf (outfile, "address");
4265 break;
4266 case dw_val_class_loc:
4267 fprintf (outfile, "location descriptor");
4268 break;
4269 case dw_val_class_const:
4270 fprintf (outfile, "%ld", a->dw_attr_val.v.val_int);
4271 break;
4272 case dw_val_class_unsigned_const:
4273 fprintf (outfile, "%lu", a->dw_attr_val.v.val_unsigned);
4274 break;
4275 case dw_val_class_long_long:
4276 fprintf (outfile, "constant (%lu,%lu)",
4277 a->dw_attr_val.v.val_long_long.hi,
4278 a->dw_attr_val.v.val_long_long.low);
4279 break;
4280 case dw_val_class_float:
4281 fprintf (outfile, "floating-point constant");
4282 break;
4283 case dw_val_class_flag:
4284 fprintf (outfile, "%u", a->dw_attr_val.v.val_flag);
4285 break;
4286 case dw_val_class_die_ref:
4287 if (a->dw_attr_val.v.val_die_ref != NULL)
4288 fprintf (outfile, "die -> %lu",
4289 a->dw_attr_val.v.val_die_ref->die_offset);
4290 else
4291 fprintf (outfile, "die -> <null>");
4292 break;
4293 case dw_val_class_lbl_id:
4294 case dw_val_class_lbl_offset:
4295 fprintf (outfile, "label: %s", a->dw_attr_val.v.val_lbl_id);
4296 break;
4297 case dw_val_class_str:
4298 if (a->dw_attr_val.v.val_str != NULL)
4299 fprintf (outfile, "\"%s\"", a->dw_attr_val.v.val_str);
4300 else
4301 fprintf (outfile, "<null>");
4302 break;
4303 default:
4304 break;
4307 fprintf (outfile, "\n");
4310 if (die->die_child != NULL)
4312 print_indent += 4;
4313 for (c = die->die_child; c != NULL; c = c->die_sib)
4314 print_die (c, outfile);
4316 print_indent -= 4;
4320 /* Print the contents of the source code line number correspondence table.
4321 This routine is a debugging aid only. */
4323 static void
4324 print_dwarf_line_table (outfile)
4325 FILE *outfile;
4327 register unsigned i;
4328 register dw_line_info_ref line_info;
4330 fprintf (outfile, "\n\nDWARF source line information\n");
4331 for (i = 1; i < line_info_table_in_use; ++i)
4333 line_info = &line_info_table[i];
4334 fprintf (outfile, "%5d: ", i);
4335 fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
4336 fprintf (outfile, "%6ld", line_info->dw_line_num);
4337 fprintf (outfile, "\n");
4340 fprintf (outfile, "\n\n");
4343 /* Print the information collected for a given DIE. */
4345 void
4346 debug_dwarf_die (die)
4347 dw_die_ref die;
4349 print_die (die, stderr);
4352 /* Print all DWARF information collected for the compilation unit.
4353 This routine is a debugging aid only. */
4355 void
4356 debug_dwarf ()
4358 print_indent = 0;
4359 print_die (comp_unit_die, stderr);
4360 if (! DWARF2_ASM_LINE_DEBUG_INFO)
4361 print_dwarf_line_table (stderr);
4364 /* Traverse the DIE, and add a sibling attribute if it may have the
4365 effect of speeding up access to siblings. To save some space,
4366 avoid generating sibling attributes for DIE's without children. */
4368 static void
4369 add_sibling_attributes(die)
4370 register dw_die_ref die;
4372 register dw_die_ref c;
4373 register dw_attr_ref attr;
4374 if (die != comp_unit_die && die->die_child != NULL)
4376 attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node));
4377 attr->dw_attr_next = NULL;
4378 attr->dw_attr = DW_AT_sibling;
4379 attr->dw_attr_val.val_class = dw_val_class_die_ref;
4380 attr->dw_attr_val.v.val_die_ref = die->die_sib;
4382 /* Add the sibling link to the front of the attribute list. */
4383 attr->dw_attr_next = die->die_attr;
4384 if (die->die_attr == NULL)
4385 die->die_attr_last = attr;
4387 die->die_attr = attr;
4390 for (c = die->die_child; c != NULL; c = c->die_sib)
4391 add_sibling_attributes (c);
4394 /* The format of each DIE (and its attribute value pairs)
4395 is encoded in an abbreviation table. This routine builds the
4396 abbreviation table and assigns a unique abbreviation id for
4397 each abbreviation entry. The children of each die are visited
4398 recursively. */
4400 static void
4401 build_abbrev_table (die)
4402 register dw_die_ref die;
4404 register unsigned long abbrev_id;
4405 register unsigned long n_alloc;
4406 register dw_die_ref c;
4407 register dw_attr_ref d_attr, a_attr;
4408 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4410 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4412 if (abbrev->die_tag == die->die_tag)
4414 if ((abbrev->die_child != NULL) == (die->die_child != NULL))
4416 a_attr = abbrev->die_attr;
4417 d_attr = die->die_attr;
4419 while (a_attr != NULL && d_attr != NULL)
4421 if ((a_attr->dw_attr != d_attr->dw_attr)
4422 || (value_format (&a_attr->dw_attr_val)
4423 != value_format (&d_attr->dw_attr_val)))
4424 break;
4426 a_attr = a_attr->dw_attr_next;
4427 d_attr = d_attr->dw_attr_next;
4430 if (a_attr == NULL && d_attr == NULL)
4431 break;
4436 if (abbrev_id >= abbrev_die_table_in_use)
4438 if (abbrev_die_table_in_use >= abbrev_die_table_allocated)
4440 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT;
4441 abbrev_die_table
4442 = (dw_die_ref *) xrealloc (abbrev_die_table,
4443 sizeof (dw_die_ref) * n_alloc);
4445 bzero ((char *) &abbrev_die_table[abbrev_die_table_allocated],
4446 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref));
4447 abbrev_die_table_allocated = n_alloc;
4450 ++abbrev_die_table_in_use;
4451 abbrev_die_table[abbrev_id] = die;
4454 die->die_abbrev = abbrev_id;
4455 for (c = die->die_child; c != NULL; c = c->die_sib)
4456 build_abbrev_table (c);
4459 /* Return the size of a string, including the null byte.
4461 This used to treat backslashes as escapes, and hence they were not included
4462 in the count. However, that conflicts with what ASM_OUTPUT_ASCII does,
4463 which treats a backslash as a backslash, escaping it if necessary, and hence
4464 we must include them in the count. */
4466 static unsigned long
4467 size_of_string (str)
4468 register char *str;
4470 return strlen (str) + 1;
4473 /* Return the size of a location descriptor. */
4475 static unsigned long
4476 size_of_loc_descr (loc)
4477 register dw_loc_descr_ref loc;
4479 register unsigned long size = 1;
4481 switch (loc->dw_loc_opc)
4483 case DW_OP_addr:
4484 size += PTR_SIZE;
4485 break;
4486 case DW_OP_const1u:
4487 case DW_OP_const1s:
4488 size += 1;
4489 break;
4490 case DW_OP_const2u:
4491 case DW_OP_const2s:
4492 size += 2;
4493 break;
4494 case DW_OP_const4u:
4495 case DW_OP_const4s:
4496 size += 4;
4497 break;
4498 case DW_OP_const8u:
4499 case DW_OP_const8s:
4500 size += 8;
4501 break;
4502 case DW_OP_constu:
4503 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4504 break;
4505 case DW_OP_consts:
4506 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4507 break;
4508 case DW_OP_pick:
4509 size += 1;
4510 break;
4511 case DW_OP_plus_uconst:
4512 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4513 break;
4514 case DW_OP_skip:
4515 case DW_OP_bra:
4516 size += 2;
4517 break;
4518 case DW_OP_breg0:
4519 case DW_OP_breg1:
4520 case DW_OP_breg2:
4521 case DW_OP_breg3:
4522 case DW_OP_breg4:
4523 case DW_OP_breg5:
4524 case DW_OP_breg6:
4525 case DW_OP_breg7:
4526 case DW_OP_breg8:
4527 case DW_OP_breg9:
4528 case DW_OP_breg10:
4529 case DW_OP_breg11:
4530 case DW_OP_breg12:
4531 case DW_OP_breg13:
4532 case DW_OP_breg14:
4533 case DW_OP_breg15:
4534 case DW_OP_breg16:
4535 case DW_OP_breg17:
4536 case DW_OP_breg18:
4537 case DW_OP_breg19:
4538 case DW_OP_breg20:
4539 case DW_OP_breg21:
4540 case DW_OP_breg22:
4541 case DW_OP_breg23:
4542 case DW_OP_breg24:
4543 case DW_OP_breg25:
4544 case DW_OP_breg26:
4545 case DW_OP_breg27:
4546 case DW_OP_breg28:
4547 case DW_OP_breg29:
4548 case DW_OP_breg30:
4549 case DW_OP_breg31:
4550 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4551 break;
4552 case DW_OP_regx:
4553 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4554 break;
4555 case DW_OP_fbreg:
4556 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int);
4557 break;
4558 case DW_OP_bregx:
4559 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4560 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int);
4561 break;
4562 case DW_OP_piece:
4563 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned);
4564 break;
4565 case DW_OP_deref_size:
4566 case DW_OP_xderef_size:
4567 size += 1;
4568 break;
4569 default:
4570 break;
4573 return size;
4576 /* Return the size of a series of location descriptors. */
4578 static unsigned long
4579 size_of_locs (loc)
4580 register dw_loc_descr_ref loc;
4582 register unsigned long size = 0;
4584 for (; loc != NULL; loc = loc->dw_loc_next)
4585 size += size_of_loc_descr (loc);
4587 return size;
4590 /* Return the power-of-two number of bytes necessary to represent VALUE. */
4592 static int
4593 constant_size (value)
4594 long unsigned value;
4596 int log;
4598 if (value == 0)
4599 log = 0;
4600 else
4601 log = floor_log2 (value);
4603 log = log / 8;
4604 log = 1 << (floor_log2 (log) + 1);
4606 return log;
4609 /* Return the size of a DIE, as it is represented in the
4610 .debug_info section. */
4612 static unsigned long
4613 size_of_die (die)
4614 register dw_die_ref die;
4616 register unsigned long size = 0;
4617 register dw_attr_ref a;
4619 size += size_of_uleb128 (die->die_abbrev);
4620 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
4622 switch (a->dw_attr_val.val_class)
4624 case dw_val_class_addr:
4625 size += PTR_SIZE;
4626 break;
4627 case dw_val_class_loc:
4629 register unsigned long lsize
4630 = size_of_locs (a->dw_attr_val.v.val_loc);
4632 /* Block length. */
4633 size += constant_size (lsize);
4634 size += lsize;
4636 break;
4637 case dw_val_class_const:
4638 size += 4;
4639 break;
4640 case dw_val_class_unsigned_const:
4641 size += constant_size (a->dw_attr_val.v.val_unsigned);
4642 break;
4643 case dw_val_class_long_long:
4644 size += 1 + 8; /* block */
4645 break;
4646 case dw_val_class_float:
4647 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */
4648 break;
4649 case dw_val_class_flag:
4650 size += 1;
4651 break;
4652 case dw_val_class_die_ref:
4653 size += DWARF_OFFSET_SIZE;
4654 break;
4655 case dw_val_class_fde_ref:
4656 size += DWARF_OFFSET_SIZE;
4657 break;
4658 case dw_val_class_lbl_id:
4659 size += PTR_SIZE;
4660 break;
4661 case dw_val_class_lbl_offset:
4662 size += DWARF_OFFSET_SIZE;
4663 break;
4664 case dw_val_class_str:
4665 size += size_of_string (a->dw_attr_val.v.val_str);
4666 break;
4667 default:
4668 abort ();
4672 return size;
4675 /* Size the debugging information associated with a given DIE.
4676 Visits the DIE's children recursively. Updates the global
4677 variable next_die_offset, on each time through. Uses the
4678 current value of next_die_offset to update the die_offset
4679 field in each DIE. */
4681 static void
4682 calc_die_sizes (die)
4683 dw_die_ref die;
4685 register dw_die_ref c;
4686 die->die_offset = next_die_offset;
4687 next_die_offset += size_of_die (die);
4689 for (c = die->die_child; c != NULL; c = c->die_sib)
4690 calc_die_sizes (c);
4692 if (die->die_child != NULL)
4693 /* Count the null byte used to terminate sibling lists. */
4694 next_die_offset += 1;
4697 /* Return the size of the line information prolog generated for the
4698 compilation unit. */
4700 static unsigned long
4701 size_of_line_prolog ()
4703 register unsigned long size;
4704 register unsigned long ft_index;
4706 size = DWARF_LINE_PROLOG_HEADER_SIZE;
4708 /* Count the size of the table giving number of args for each
4709 standard opcode. */
4710 size += DWARF_LINE_OPCODE_BASE - 1;
4712 /* Include directory table is empty (at present). Count only the
4713 null byte used to terminate the table. */
4714 size += 1;
4716 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
4718 /* File name entry. */
4719 size += size_of_string (file_table[ft_index]);
4721 /* Include directory index. */
4722 size += size_of_uleb128 (0);
4724 /* Modification time. */
4725 size += size_of_uleb128 (0);
4727 /* File length in bytes. */
4728 size += size_of_uleb128 (0);
4731 /* Count the file table terminator. */
4732 size += 1;
4733 return size;
4736 /* Return the size of the .debug_pubnames table generated for the
4737 compilation unit. */
4739 static unsigned long
4740 size_of_pubnames ()
4742 register unsigned long size;
4743 register unsigned i;
4745 size = DWARF_PUBNAMES_HEADER_SIZE;
4746 for (i = 0; i < pubname_table_in_use; ++i)
4748 register pubname_ref p = &pubname_table[i];
4749 size += DWARF_OFFSET_SIZE + size_of_string (p->name);
4752 size += DWARF_OFFSET_SIZE;
4753 return size;
4756 /* Return the size of the information in the .debug_aranges section. */
4758 static unsigned long
4759 size_of_aranges ()
4761 register unsigned long size;
4763 size = DWARF_ARANGES_HEADER_SIZE;
4765 /* Count the address/length pair for this compilation unit. */
4766 size += 2 * PTR_SIZE;
4767 size += 2 * PTR_SIZE * arange_table_in_use;
4769 /* Count the two zero words used to terminated the address range table. */
4770 size += 2 * PTR_SIZE;
4771 return size;
4774 /* Select the encoding of an attribute value. */
4776 static enum dwarf_form
4777 value_format (v)
4778 dw_val_ref v;
4780 switch (v->val_class)
4782 case dw_val_class_addr:
4783 return DW_FORM_addr;
4784 case dw_val_class_loc:
4785 switch (constant_size (size_of_locs (v->v.val_loc)))
4787 case 1:
4788 return DW_FORM_block1;
4789 case 2:
4790 return DW_FORM_block2;
4791 default:
4792 abort ();
4794 case dw_val_class_const:
4795 return DW_FORM_data4;
4796 case dw_val_class_unsigned_const:
4797 switch (constant_size (v->v.val_unsigned))
4799 case 1:
4800 return DW_FORM_data1;
4801 case 2:
4802 return DW_FORM_data2;
4803 case 4:
4804 return DW_FORM_data4;
4805 case 8:
4806 return DW_FORM_data8;
4807 default:
4808 abort ();
4810 case dw_val_class_long_long:
4811 return DW_FORM_block1;
4812 case dw_val_class_float:
4813 return DW_FORM_block1;
4814 case dw_val_class_flag:
4815 return DW_FORM_flag;
4816 case dw_val_class_die_ref:
4817 return DW_FORM_ref;
4818 case dw_val_class_fde_ref:
4819 return DW_FORM_data;
4820 case dw_val_class_lbl_id:
4821 return DW_FORM_addr;
4822 case dw_val_class_lbl_offset:
4823 return DW_FORM_data;
4824 case dw_val_class_str:
4825 return DW_FORM_string;
4826 default:
4827 abort ();
4831 /* Output the encoding of an attribute value. */
4833 static void
4834 output_value_format (v)
4835 dw_val_ref v;
4837 enum dwarf_form form = value_format (v);
4839 output_uleb128 (form);
4840 if (flag_debug_asm)
4841 fprintf (asm_out_file, " (%s)", dwarf_form_name (form));
4843 fputc ('\n', asm_out_file);
4846 /* Output the .debug_abbrev section which defines the DIE abbreviation
4847 table. */
4849 static void
4850 output_abbrev_section ()
4852 unsigned long abbrev_id;
4854 dw_attr_ref a_attr;
4855 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id)
4857 register dw_die_ref abbrev = abbrev_die_table[abbrev_id];
4859 output_uleb128 (abbrev_id);
4860 if (flag_debug_asm)
4861 fprintf (asm_out_file, " (abbrev code)");
4863 fputc ('\n', asm_out_file);
4864 output_uleb128 (abbrev->die_tag);
4865 if (flag_debug_asm)
4866 fprintf (asm_out_file, " (TAG: %s)",
4867 dwarf_tag_name (abbrev->die_tag));
4869 fputc ('\n', asm_out_file);
4870 fprintf (asm_out_file, "\t%s\t0x%x", ASM_BYTE_OP,
4871 abbrev->die_child != NULL ? DW_children_yes : DW_children_no);
4873 if (flag_debug_asm)
4874 fprintf (asm_out_file, "\t%s %s",
4875 ASM_COMMENT_START,
4876 (abbrev->die_child != NULL
4877 ? "DW_children_yes" : "DW_children_no"));
4879 fputc ('\n', asm_out_file);
4881 for (a_attr = abbrev->die_attr; a_attr != NULL;
4882 a_attr = a_attr->dw_attr_next)
4884 output_uleb128 (a_attr->dw_attr);
4885 if (flag_debug_asm)
4886 fprintf (asm_out_file, " (%s)",
4887 dwarf_attr_name (a_attr->dw_attr));
4889 fputc ('\n', asm_out_file);
4890 output_value_format (&a_attr->dw_attr_val);
4893 fprintf (asm_out_file, "\t%s\t0,0\n", ASM_BYTE_OP);
4896 /* Terminate the table. */
4897 fprintf (asm_out_file, "\t%s\t0\n", ASM_BYTE_OP);
4900 /* Output location description stack opcode's operands (if any). */
4902 static void
4903 output_loc_operands (loc)
4904 register dw_loc_descr_ref loc;
4906 register dw_val_ref val1 = &loc->dw_loc_oprnd1;
4907 register dw_val_ref val2 = &loc->dw_loc_oprnd2;
4909 switch (loc->dw_loc_opc)
4911 case DW_OP_addr:
4912 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, val1->v.val_addr);
4913 fputc ('\n', asm_out_file);
4914 break;
4915 case DW_OP_const1u:
4916 case DW_OP_const1s:
4917 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
4918 fputc ('\n', asm_out_file);
4919 break;
4920 case DW_OP_const2u:
4921 case DW_OP_const2s:
4922 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4923 fputc ('\n', asm_out_file);
4924 break;
4925 case DW_OP_const4u:
4926 case DW_OP_const4s:
4927 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, val1->v.val_int);
4928 fputc ('\n', asm_out_file);
4929 break;
4930 case DW_OP_const8u:
4931 case DW_OP_const8s:
4932 abort ();
4933 fputc ('\n', asm_out_file);
4934 break;
4935 case DW_OP_constu:
4936 output_uleb128 (val1->v.val_unsigned);
4937 fputc ('\n', asm_out_file);
4938 break;
4939 case DW_OP_consts:
4940 output_sleb128 (val1->v.val_int);
4941 fputc ('\n', asm_out_file);
4942 break;
4943 case DW_OP_pick:
4944 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_int);
4945 fputc ('\n', asm_out_file);
4946 break;
4947 case DW_OP_plus_uconst:
4948 output_uleb128 (val1->v.val_unsigned);
4949 fputc ('\n', asm_out_file);
4950 break;
4951 case DW_OP_skip:
4952 case DW_OP_bra:
4953 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, val1->v.val_int);
4954 fputc ('\n', asm_out_file);
4955 break;
4956 case DW_OP_breg0:
4957 case DW_OP_breg1:
4958 case DW_OP_breg2:
4959 case DW_OP_breg3:
4960 case DW_OP_breg4:
4961 case DW_OP_breg5:
4962 case DW_OP_breg6:
4963 case DW_OP_breg7:
4964 case DW_OP_breg8:
4965 case DW_OP_breg9:
4966 case DW_OP_breg10:
4967 case DW_OP_breg11:
4968 case DW_OP_breg12:
4969 case DW_OP_breg13:
4970 case DW_OP_breg14:
4971 case DW_OP_breg15:
4972 case DW_OP_breg16:
4973 case DW_OP_breg17:
4974 case DW_OP_breg18:
4975 case DW_OP_breg19:
4976 case DW_OP_breg20:
4977 case DW_OP_breg21:
4978 case DW_OP_breg22:
4979 case DW_OP_breg23:
4980 case DW_OP_breg24:
4981 case DW_OP_breg25:
4982 case DW_OP_breg26:
4983 case DW_OP_breg27:
4984 case DW_OP_breg28:
4985 case DW_OP_breg29:
4986 case DW_OP_breg30:
4987 case DW_OP_breg31:
4988 output_sleb128 (val1->v.val_int);
4989 fputc ('\n', asm_out_file);
4990 break;
4991 case DW_OP_regx:
4992 output_uleb128 (val1->v.val_unsigned);
4993 fputc ('\n', asm_out_file);
4994 break;
4995 case DW_OP_fbreg:
4996 output_sleb128 (val1->v.val_int);
4997 fputc ('\n', asm_out_file);
4998 break;
4999 case DW_OP_bregx:
5000 output_uleb128 (val1->v.val_unsigned);
5001 fputc ('\n', asm_out_file);
5002 output_sleb128 (val2->v.val_int);
5003 fputc ('\n', asm_out_file);
5004 break;
5005 case DW_OP_piece:
5006 output_uleb128 (val1->v.val_unsigned);
5007 fputc ('\n', asm_out_file);
5008 break;
5009 case DW_OP_deref_size:
5010 case DW_OP_xderef_size:
5011 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, val1->v.val_flag);
5012 fputc ('\n', asm_out_file);
5013 break;
5014 default:
5015 break;
5019 /* Compute the offset of a sibling. */
5021 static unsigned long
5022 sibling_offset (die)
5023 dw_die_ref die;
5025 unsigned long offset;
5027 if (die->die_child_last == NULL)
5028 offset = die->die_offset + size_of_die (die);
5029 else
5030 offset = sibling_offset (die->die_child_last) + 1;
5032 return offset;
5035 /* Output the DIE and its attributes. Called recursively to generate
5036 the definitions of each child DIE. */
5038 static void
5039 output_die (die)
5040 register dw_die_ref die;
5042 register dw_attr_ref a;
5043 register dw_die_ref c;
5044 register unsigned long ref_offset;
5045 register unsigned long size;
5046 register dw_loc_descr_ref loc;
5048 output_uleb128 (die->die_abbrev);
5049 if (flag_debug_asm)
5050 fprintf (asm_out_file, " (DIE (0x%lx) %s)",
5051 die->die_offset, dwarf_tag_name (die->die_tag));
5053 fputc ('\n', asm_out_file);
5055 for (a = die->die_attr; a != NULL; a = a->dw_attr_next)
5057 switch (a->dw_attr_val.val_class)
5059 case dw_val_class_addr:
5060 ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file,
5061 a->dw_attr_val.v.val_addr);
5062 break;
5064 case dw_val_class_loc:
5065 size = size_of_locs (a->dw_attr_val.v.val_loc);
5067 /* Output the block length for this list of location operations. */
5068 switch (constant_size (size))
5070 case 1:
5071 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, size);
5072 break;
5073 case 2:
5074 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, size);
5075 break;
5076 default:
5077 abort ();
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 (loc = a->dw_attr_val.v.val_loc; loc != NULL;
5086 loc = loc->dw_loc_next)
5088 /* Output the opcode. */
5089 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, loc->dw_loc_opc);
5090 if (flag_debug_asm)
5091 fprintf (asm_out_file, "\t%s %s", ASM_COMMENT_START,
5092 dwarf_stack_op_name (loc->dw_loc_opc));
5094 fputc ('\n', asm_out_file);
5096 /* Output the operand(s) (if any). */
5097 output_loc_operands (loc);
5099 break;
5101 case dw_val_class_const:
5102 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, a->dw_attr_val.v.val_int);
5103 break;
5105 case dw_val_class_unsigned_const:
5106 switch (constant_size (a->dw_attr_val.v.val_unsigned))
5108 case 1:
5109 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5110 a->dw_attr_val.v.val_unsigned);
5111 break;
5112 case 2:
5113 ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
5114 a->dw_attr_val.v.val_unsigned);
5115 break;
5116 case 4:
5117 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5118 a->dw_attr_val.v.val_unsigned);
5119 break;
5120 case 8:
5121 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5122 a->dw_attr_val.v.val_long_long.hi,
5123 a->dw_attr_val.v.val_long_long.low);
5124 break;
5125 default:
5126 abort ();
5128 break;
5130 case dw_val_class_long_long:
5131 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 8);
5132 if (flag_debug_asm)
5133 fprintf (asm_out_file, "\t%s %s",
5134 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5136 fputc ('\n', asm_out_file);
5137 ASM_OUTPUT_DWARF_DATA8 (asm_out_file,
5138 a->dw_attr_val.v.val_long_long.hi,
5139 a->dw_attr_val.v.val_long_long.low);
5141 if (flag_debug_asm)
5142 fprintf (asm_out_file,
5143 "\t%s long long constant", ASM_COMMENT_START);
5145 fputc ('\n', asm_out_file);
5146 break;
5148 case dw_val_class_float:
5150 register unsigned int i;
5151 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5152 a->dw_attr_val.v.val_float.length * 4);
5153 if (flag_debug_asm)
5154 fprintf (asm_out_file, "\t%s %s",
5155 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5157 fputc ('\n', asm_out_file);
5158 for (i = 0; i < a->dw_attr_val.v.val_float.length; ++i)
5160 ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
5161 a->dw_attr_val.v.val_float.array[i]);
5162 if (flag_debug_asm)
5163 fprintf (asm_out_file, "\t%s fp constant word %u",
5164 ASM_COMMENT_START, i);
5166 fputc ('\n', asm_out_file);
5168 break;
5171 case dw_val_class_flag:
5172 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, a->dw_attr_val.v.val_flag);
5173 break;
5175 case dw_val_class_die_ref:
5176 if (a->dw_attr_val.v.val_die_ref != NULL)
5177 ref_offset = a->dw_attr_val.v.val_die_ref->die_offset;
5178 else if (a->dw_attr == DW_AT_sibling)
5179 ref_offset = sibling_offset(die);
5180 else
5181 abort ();
5183 ASM_OUTPUT_DWARF_DATA (asm_out_file, ref_offset);
5184 break;
5186 case dw_val_class_fde_ref:
5188 char l1[20];
5189 ASM_GENERATE_INTERNAL_LABEL
5190 (l1, FDE_AFTER_SIZE_LABEL, a->dw_attr_val.v.val_fde_index * 2);
5191 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, l1);
5192 fprintf (asm_out_file, " - %d", DWARF_OFFSET_SIZE);
5194 break;
5196 case dw_val_class_lbl_id:
5197 ASM_OUTPUT_DWARF_ADDR (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5198 break;
5200 case dw_val_class_lbl_offset:
5201 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, a->dw_attr_val.v.val_lbl_id);
5202 break;
5204 case dw_val_class_str:
5205 if (flag_debug_asm)
5206 ASM_OUTPUT_DWARF_STRING (asm_out_file, a->dw_attr_val.v.val_str);
5207 else
5208 ASM_OUTPUT_ASCII (asm_out_file,
5209 a->dw_attr_val.v.val_str,
5210 (int) strlen (a->dw_attr_val.v.val_str) + 1);
5211 break;
5213 default:
5214 abort ();
5217 if (a->dw_attr_val.val_class != dw_val_class_loc
5218 && a->dw_attr_val.val_class != dw_val_class_long_long
5219 && a->dw_attr_val.val_class != dw_val_class_float)
5221 if (flag_debug_asm)
5222 fprintf (asm_out_file, "\t%s %s",
5223 ASM_COMMENT_START, dwarf_attr_name (a->dw_attr));
5225 fputc ('\n', asm_out_file);
5229 for (c = die->die_child; c != NULL; c = c->die_sib)
5230 output_die (c);
5232 if (die->die_child != NULL)
5234 /* Add null byte to terminate sibling list. */
5235 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5236 if (flag_debug_asm)
5237 fprintf (asm_out_file, "\t%s end of children of DIE 0x%lx",
5238 ASM_COMMENT_START, die->die_offset);
5240 fputc ('\n', asm_out_file);
5244 /* Output the compilation unit that appears at the beginning of the
5245 .debug_info section, and precedes the DIE descriptions. */
5247 static void
5248 output_compilation_unit_header ()
5250 ASM_OUTPUT_DWARF_DATA (asm_out_file, next_die_offset - DWARF_OFFSET_SIZE);
5251 if (flag_debug_asm)
5252 fprintf (asm_out_file, "\t%s Length of Compilation Unit Info.",
5253 ASM_COMMENT_START);
5255 fputc ('\n', asm_out_file);
5256 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5257 if (flag_debug_asm)
5258 fprintf (asm_out_file, "\t%s DWARF version number", ASM_COMMENT_START);
5260 fputc ('\n', asm_out_file);
5261 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, abbrev_section_label);
5262 if (flag_debug_asm)
5263 fprintf (asm_out_file, "\t%s Offset Into Abbrev. Section",
5264 ASM_COMMENT_START);
5266 fputc ('\n', asm_out_file);
5267 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5268 if (flag_debug_asm)
5269 fprintf (asm_out_file, "\t%s Pointer Size (in bytes)", ASM_COMMENT_START);
5271 fputc ('\n', asm_out_file);
5274 /* The DWARF2 pubname for a nested thingy looks like "A::f". The output
5275 of decl_printable_name for C++ looks like "A::f(int)". Let's drop the
5276 argument list, and maybe the scope. */
5278 static const char *
5279 dwarf2_name (decl, scope)
5280 tree decl;
5281 int scope;
5283 return (*decl_printable_name) (decl, scope ? 1 : 0);
5286 /* Add a new entry to .debug_pubnames if appropriate. */
5288 static void
5289 add_pubname (decl, die)
5290 tree decl;
5291 dw_die_ref die;
5293 pubname_ref p;
5295 if (! TREE_PUBLIC (decl))
5296 return;
5298 if (pubname_table_in_use == pubname_table_allocated)
5300 pubname_table_allocated += PUBNAME_TABLE_INCREMENT;
5301 pubname_table = (pubname_ref) xrealloc
5302 (pubname_table, pubname_table_allocated * sizeof (pubname_entry));
5305 p = &pubname_table[pubname_table_in_use++];
5306 p->die = die;
5308 p->name = xstrdup (dwarf2_name (decl, 1));
5311 /* Output the public names table used to speed up access to externally
5312 visible names. For now, only generate entries for externally
5313 visible procedures. */
5315 static void
5316 output_pubnames ()
5318 register unsigned i;
5319 register unsigned long pubnames_length = size_of_pubnames ();
5321 ASM_OUTPUT_DWARF_DATA (asm_out_file, pubnames_length);
5323 if (flag_debug_asm)
5324 fprintf (asm_out_file, "\t%s Length of Public Names Info.",
5325 ASM_COMMENT_START);
5327 fputc ('\n', asm_out_file);
5328 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_DATA (asm_out_file, next_die_offset);
5341 if (flag_debug_asm)
5342 fprintf (asm_out_file, "\t%s Compilation Unit Length", ASM_COMMENT_START);
5344 fputc ('\n', asm_out_file);
5345 for (i = 0; i < pubname_table_in_use; ++i)
5347 register pubname_ref pub = &pubname_table[i];
5349 ASM_OUTPUT_DWARF_DATA (asm_out_file, pub->die->die_offset);
5350 if (flag_debug_asm)
5351 fprintf (asm_out_file, "\t%s DIE offset", ASM_COMMENT_START);
5353 fputc ('\n', asm_out_file);
5355 if (flag_debug_asm)
5357 ASM_OUTPUT_DWARF_STRING (asm_out_file, pub->name);
5358 fprintf (asm_out_file, "%s external name", ASM_COMMENT_START);
5360 else
5362 ASM_OUTPUT_ASCII (asm_out_file, pub->name,
5363 (int) strlen (pub->name) + 1);
5366 fputc ('\n', asm_out_file);
5369 ASM_OUTPUT_DWARF_DATA (asm_out_file, 0);
5370 fputc ('\n', asm_out_file);
5373 /* Add a new entry to .debug_aranges if appropriate. */
5375 static void
5376 add_arange (decl, die)
5377 tree decl;
5378 dw_die_ref die;
5380 if (! DECL_SECTION_NAME (decl))
5381 return;
5383 if (arange_table_in_use == arange_table_allocated)
5385 arange_table_allocated += ARANGE_TABLE_INCREMENT;
5386 arange_table
5387 = (arange_ref) xrealloc (arange_table,
5388 arange_table_allocated * sizeof (dw_die_ref));
5391 arange_table[arange_table_in_use++] = die;
5394 /* Output the information that goes into the .debug_aranges table.
5395 Namely, define the beginning and ending address range of the
5396 text section generated for this compilation unit. */
5398 static void
5399 output_aranges ()
5401 register unsigned i;
5402 register unsigned long aranges_length = size_of_aranges ();
5404 ASM_OUTPUT_DWARF_DATA (asm_out_file, aranges_length);
5405 if (flag_debug_asm)
5406 fprintf (asm_out_file, "\t%s Length of Address Ranges Info.",
5407 ASM_COMMENT_START);
5409 fputc ('\n', asm_out_file);
5410 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5411 if (flag_debug_asm)
5412 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5414 fputc ('\n', asm_out_file);
5415 ASM_OUTPUT_DWARF_OFFSET (asm_out_file, debug_info_section_label);
5416 if (flag_debug_asm)
5417 fprintf (asm_out_file, "\t%s Offset of Compilation Unit Info.",
5418 ASM_COMMENT_START);
5420 fputc ('\n', asm_out_file);
5421 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, PTR_SIZE);
5422 if (flag_debug_asm)
5423 fprintf (asm_out_file, "\t%s Size of Address", ASM_COMMENT_START);
5425 fputc ('\n', asm_out_file);
5426 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5427 if (flag_debug_asm)
5428 fprintf (asm_out_file, "\t%s Size of Segment Descriptor",
5429 ASM_COMMENT_START);
5431 fputc ('\n', asm_out_file);
5432 /* We need to align to twice the pointer size here.
5433 If DWARF_OFFSET_SIZE == 4, then we have emitted 12 bytes, and need 4
5434 bytes of padding to align for either 4 or 8 byte pointers. */
5435 ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
5436 /* If DWARF_OFFSET_SIZE == 8, then we have emitted 20 bytes, and need 12
5437 bytes of padding to align for 8 byte pointers. We have already emitted
5438 4 bytes of padding, so emit 8 more here. */
5439 if (DWARF_OFFSET_SIZE == 8)
5440 fprintf (asm_out_file, ",0,0");
5442 if (flag_debug_asm)
5443 fprintf (asm_out_file, "\t%s Pad to %d byte boundary",
5444 ASM_COMMENT_START, 2 * PTR_SIZE);
5446 fputc ('\n', asm_out_file);
5447 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_section_label);
5448 if (flag_debug_asm)
5449 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5451 fputc ('\n', asm_out_file);
5452 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, text_end_label,
5453 text_section_label);
5454 if (flag_debug_asm)
5455 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5457 fputc ('\n', asm_out_file);
5458 for (i = 0; i < arange_table_in_use; ++i)
5460 dw_die_ref die = arange_table[i];
5462 if (die->die_tag == DW_TAG_subprogram)
5463 ASM_OUTPUT_DWARF_ADDR (asm_out_file, get_AT_low_pc (die));
5464 else
5466 /* A static variable; extract the symbol from DW_AT_location.
5467 Note that this code isn't currently hit, as we only emit
5468 aranges for functions (jason 9/23/99). */
5470 dw_attr_ref a = get_AT (die, DW_AT_location);
5471 dw_loc_descr_ref loc;
5472 if (! a || a->dw_attr_val.val_class != dw_val_class_loc)
5473 abort ();
5475 loc = a->dw_attr_val.v.val_loc;
5476 if (loc->dw_loc_opc != DW_OP_addr)
5477 abort ();
5479 ASM_OUTPUT_DWARF_ADDR (asm_out_file, loc->dw_loc_oprnd1.v.val_addr);
5482 if (flag_debug_asm)
5483 fprintf (asm_out_file, "\t%s Address", ASM_COMMENT_START);
5485 fputc ('\n', asm_out_file);
5486 if (die->die_tag == DW_TAG_subprogram)
5487 ASM_OUTPUT_DWARF_ADDR_DELTA (asm_out_file, get_AT_hi_pc (die),
5488 get_AT_low_pc (die));
5489 else
5490 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file,
5491 get_AT_unsigned (die, DW_AT_byte_size));
5493 if (flag_debug_asm)
5494 fprintf (asm_out_file, "%s Length", ASM_COMMENT_START);
5496 fputc ('\n', asm_out_file);
5499 /* Output the terminator words. */
5500 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5501 fputc ('\n', asm_out_file);
5502 ASM_OUTPUT_DWARF_ADDR_DATA (asm_out_file, 0);
5503 fputc ('\n', asm_out_file);
5506 /* Output the source line number correspondence information. This
5507 information goes into the .debug_line section. */
5509 static void
5510 output_line_info ()
5512 char line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5513 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES];
5514 register unsigned opc;
5515 register unsigned n_op_args;
5516 register unsigned long ft_index;
5517 register unsigned long lt_index;
5518 register unsigned long current_line;
5519 register long line_offset;
5520 register long line_delta;
5521 register unsigned long current_file;
5522 register unsigned long function;
5524 ASM_OUTPUT_DWARF_DELTA (asm_out_file, ".LTEND", ".LTSTART");
5525 if (flag_debug_asm)
5526 fprintf (asm_out_file, "\t%s Length of Source Line Info.",
5527 ASM_COMMENT_START);
5529 fputc ('\n', asm_out_file);
5530 ASM_OUTPUT_LABEL (asm_out_file, ".LTSTART");
5531 ASM_OUTPUT_DWARF_DATA2 (asm_out_file, DWARF_VERSION);
5532 if (flag_debug_asm)
5533 fprintf (asm_out_file, "\t%s DWARF Version", ASM_COMMENT_START);
5535 fputc ('\n', asm_out_file);
5536 ASM_OUTPUT_DWARF_DATA (asm_out_file, size_of_line_prolog ());
5537 if (flag_debug_asm)
5538 fprintf (asm_out_file, "\t%s Prolog Length", ASM_COMMENT_START);
5540 fputc ('\n', asm_out_file);
5541 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_MIN_INSTR_LENGTH);
5542 if (flag_debug_asm)
5543 fprintf (asm_out_file, "\t%s Minimum Instruction Length",
5544 ASM_COMMENT_START);
5546 fputc ('\n', asm_out_file);
5547 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DWARF_LINE_DEFAULT_IS_STMT_START);
5548 if (flag_debug_asm)
5549 fprintf (asm_out_file, "\t%s Default is_stmt_start flag",
5550 ASM_COMMENT_START);
5552 fputc ('\n', asm_out_file);
5553 fprintf (asm_out_file, "\t%s\t%d", ASM_BYTE_OP, DWARF_LINE_BASE);
5554 if (flag_debug_asm)
5555 fprintf (asm_out_file, "\t%s Line Base Value (Special Opcodes)",
5556 ASM_COMMENT_START);
5558 fputc ('\n', asm_out_file);
5559 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_RANGE);
5560 if (flag_debug_asm)
5561 fprintf (asm_out_file, "\t%s Line Range Value (Special Opcodes)",
5562 ASM_COMMENT_START);
5564 fputc ('\n', asm_out_file);
5565 fprintf (asm_out_file, "\t%s\t%u", ASM_BYTE_OP, DWARF_LINE_OPCODE_BASE);
5566 if (flag_debug_asm)
5567 fprintf (asm_out_file, "\t%s Special Opcode Base", ASM_COMMENT_START);
5569 fputc ('\n', asm_out_file);
5570 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; ++opc)
5572 switch (opc)
5574 case DW_LNS_advance_pc:
5575 case DW_LNS_advance_line:
5576 case DW_LNS_set_file:
5577 case DW_LNS_set_column:
5578 case DW_LNS_fixed_advance_pc:
5579 n_op_args = 1;
5580 break;
5581 default:
5582 n_op_args = 0;
5583 break;
5585 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, n_op_args);
5586 if (flag_debug_asm)
5587 fprintf (asm_out_file, "\t%s opcode: 0x%x has %d args",
5588 ASM_COMMENT_START, opc, n_op_args);
5589 fputc ('\n', asm_out_file);
5592 if (flag_debug_asm)
5593 fprintf (asm_out_file, "%s Include Directory Table\n", ASM_COMMENT_START);
5595 /* Include directory table is empty, at present */
5596 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5597 fputc ('\n', asm_out_file);
5598 if (flag_debug_asm)
5599 fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
5601 for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
5603 if (flag_debug_asm)
5605 ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
5606 fprintf (asm_out_file, "%s File Entry: 0x%lx",
5607 ASM_COMMENT_START, ft_index);
5609 else
5611 ASM_OUTPUT_ASCII (asm_out_file,
5612 file_table[ft_index],
5613 (int) strlen (file_table[ft_index]) + 1);
5616 fputc ('\n', asm_out_file);
5618 /* Include directory index */
5619 output_uleb128 (0);
5620 fputc ('\n', asm_out_file);
5622 /* Modification time */
5623 output_uleb128 (0);
5624 fputc ('\n', asm_out_file);
5626 /* File length in bytes */
5627 output_uleb128 (0);
5628 fputc ('\n', asm_out_file);
5631 /* Terminate the file name table */
5632 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5633 fputc ('\n', asm_out_file);
5635 /* We used to set the address register to the first location in the text
5636 section here, but that didn't accomplish anything since we already
5637 have a line note for the opening brace of the first function. */
5639 /* Generate the line number to PC correspondence table, encoded as
5640 a series of state machine operations. */
5641 current_file = 1;
5642 current_line = 1;
5643 strcpy (prev_line_label, text_section_label);
5644 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index)
5646 register dw_line_info_ref line_info = &line_info_table[lt_index];
5648 /* Don't emit anything for redundant notes. Just updating the
5649 address doesn't accomplish anything, because we already assume
5650 that anything after the last address is this line. */
5651 if (line_info->dw_line_num == current_line
5652 && line_info->dw_file_num == current_file)
5653 continue;
5655 /* Emit debug info for the address of the current line, choosing
5656 the encoding that uses the least amount of space. */
5657 /* ??? Unfortunately, we have little choice here currently, and must
5658 always use the most general form. Gcc does not know the address
5659 delta itself, so we can't use DW_LNS_advance_pc. There are no known
5660 dwarf2 aware assemblers at this time, so we can't use any special
5661 pseudo ops that would allow the assembler to optimally encode this for
5662 us. Many ports do have length attributes which will give an upper
5663 bound on the address range. We could perhaps use length attributes
5664 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
5665 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index);
5666 if (0)
5668 /* This can handle deltas up to 0xffff. This takes 3 bytes. */
5669 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5670 if (flag_debug_asm)
5671 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5672 ASM_COMMENT_START);
5674 fputc ('\n', asm_out_file);
5675 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label, prev_line_label);
5676 fputc ('\n', asm_out_file);
5678 else
5680 /* This can handle any delta. This takes 4+PTR_SIZE bytes. */
5681 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5682 if (flag_debug_asm)
5683 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5684 ASM_COMMENT_START);
5685 fputc ('\n', asm_out_file);
5686 output_uleb128 (1 + PTR_SIZE);
5687 fputc ('\n', asm_out_file);
5688 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5689 fputc ('\n', asm_out_file);
5690 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5691 fputc ('\n', asm_out_file);
5693 strcpy (prev_line_label, line_label);
5695 /* Emit debug info for the source file of the current line, if
5696 different from the previous line. */
5697 if (line_info->dw_file_num != current_file)
5699 current_file = line_info->dw_file_num;
5700 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5701 if (flag_debug_asm)
5702 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5704 fputc ('\n', asm_out_file);
5705 output_uleb128 (current_file);
5706 if (flag_debug_asm)
5707 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5709 fputc ('\n', asm_out_file);
5712 /* Emit debug info for the current line number, choosing the encoding
5713 that uses the least amount of space. */
5714 if (line_info->dw_line_num != current_line)
5716 line_offset = line_info->dw_line_num - current_line;
5717 line_delta = line_offset - DWARF_LINE_BASE;
5718 current_line = line_info->dw_line_num;
5719 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5721 /* This can handle deltas from -10 to 234, using the current
5722 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This
5723 takes 1 byte. */
5724 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5725 DWARF_LINE_OPCODE_BASE + line_delta);
5726 if (flag_debug_asm)
5727 fprintf (asm_out_file,
5728 "\t%s line %ld", ASM_COMMENT_START, current_line);
5730 fputc ('\n', asm_out_file);
5732 else
5734 /* This can handle any delta. This takes at least 4 bytes,
5735 depending on the value being encoded. */
5736 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5737 if (flag_debug_asm)
5738 fprintf (asm_out_file, "\t%s advance to line %ld",
5739 ASM_COMMENT_START, current_line);
5741 fputc ('\n', asm_out_file);
5742 output_sleb128 (line_offset);
5743 fputc ('\n', asm_out_file);
5744 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5745 if (flag_debug_asm)
5746 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5747 fputc ('\n', asm_out_file);
5750 else
5752 /* We still need to start a new row, so output a copy insn. */
5753 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5754 if (flag_debug_asm)
5755 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5756 fputc ('\n', asm_out_file);
5760 /* Emit debug info for the address of the end of the function. */
5761 if (0)
5763 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5764 if (flag_debug_asm)
5765 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5766 ASM_COMMENT_START);
5768 fputc ('\n', asm_out_file);
5769 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, text_end_label, prev_line_label);
5770 fputc ('\n', asm_out_file);
5772 else
5774 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5775 if (flag_debug_asm)
5776 fprintf (asm_out_file, "\t%s DW_LNE_set_address", ASM_COMMENT_START);
5777 fputc ('\n', asm_out_file);
5778 output_uleb128 (1 + PTR_SIZE);
5779 fputc ('\n', asm_out_file);
5780 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5781 fputc ('\n', asm_out_file);
5782 ASM_OUTPUT_DWARF_ADDR (asm_out_file, text_end_label);
5783 fputc ('\n', asm_out_file);
5786 /* Output the marker for the end of the line number info. */
5787 ASM_OUTPUT_LABEL (asm_out_file, ".LTEND");
5788 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5789 if (flag_debug_asm)
5790 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence", ASM_COMMENT_START);
5792 fputc ('\n', asm_out_file);
5793 output_uleb128 (1);
5794 fputc ('\n', asm_out_file);
5795 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5796 fputc ('\n', asm_out_file);
5798 function = 0;
5799 current_file = 1;
5800 current_line = 1;
5801 for (lt_index = 0; lt_index < separate_line_info_table_in_use; )
5803 register dw_separate_line_info_ref line_info
5804 = &separate_line_info_table[lt_index];
5806 /* Don't emit anything for redundant notes. */
5807 if (line_info->dw_line_num == current_line
5808 && line_info->dw_file_num == current_file
5809 && line_info->function == function)
5810 goto cont;
5812 /* Emit debug info for the address of the current line. If this is
5813 a new function, or the first line of a function, then we need
5814 to handle it differently. */
5815 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL,
5816 lt_index);
5817 if (function != line_info->function)
5819 function = line_info->function;
5821 /* Set the address register to the first line in the function */
5822 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5823 if (flag_debug_asm)
5824 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5825 ASM_COMMENT_START);
5827 fputc ('\n', asm_out_file);
5828 output_uleb128 (1 + PTR_SIZE);
5829 fputc ('\n', asm_out_file);
5830 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5831 fputc ('\n', asm_out_file);
5832 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5833 fputc ('\n', asm_out_file);
5835 else
5837 /* ??? See the DW_LNS_advance_pc comment above. */
5838 if (0)
5840 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5841 if (flag_debug_asm)
5842 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5843 ASM_COMMENT_START);
5845 fputc ('\n', asm_out_file);
5846 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5847 prev_line_label);
5848 fputc ('\n', asm_out_file);
5850 else
5852 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5853 if (flag_debug_asm)
5854 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5855 ASM_COMMENT_START);
5856 fputc ('\n', asm_out_file);
5857 output_uleb128 (1 + PTR_SIZE);
5858 fputc ('\n', asm_out_file);
5859 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5860 fputc ('\n', asm_out_file);
5861 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5862 fputc ('\n', asm_out_file);
5865 strcpy (prev_line_label, line_label);
5867 /* Emit debug info for the source file of the current line, if
5868 different from the previous line. */
5869 if (line_info->dw_file_num != current_file)
5871 current_file = line_info->dw_file_num;
5872 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_set_file);
5873 if (flag_debug_asm)
5874 fprintf (asm_out_file, "\t%s DW_LNS_set_file", ASM_COMMENT_START);
5876 fputc ('\n', asm_out_file);
5877 output_uleb128 (current_file);
5878 if (flag_debug_asm)
5879 fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
5881 fputc ('\n', asm_out_file);
5884 /* Emit debug info for the current line number, choosing the encoding
5885 that uses the least amount of space. */
5886 if (line_info->dw_line_num != current_line)
5888 line_offset = line_info->dw_line_num - current_line;
5889 line_delta = line_offset - DWARF_LINE_BASE;
5890 current_line = line_info->dw_line_num;
5891 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1))
5893 ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
5894 DWARF_LINE_OPCODE_BASE + line_delta);
5895 if (flag_debug_asm)
5896 fprintf (asm_out_file,
5897 "\t%s line %ld", ASM_COMMENT_START, current_line);
5899 fputc ('\n', asm_out_file);
5901 else
5903 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_advance_line);
5904 if (flag_debug_asm)
5905 fprintf (asm_out_file, "\t%s advance to line %ld",
5906 ASM_COMMENT_START, current_line);
5908 fputc ('\n', asm_out_file);
5909 output_sleb128 (line_offset);
5910 fputc ('\n', asm_out_file);
5911 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5912 if (flag_debug_asm)
5913 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5914 fputc ('\n', asm_out_file);
5917 else
5919 /* We still need to start a new row, so output a copy insn. */
5920 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_copy);
5921 if (flag_debug_asm)
5922 fprintf (asm_out_file, "\t%s DW_LNS_copy", ASM_COMMENT_START);
5923 fputc ('\n', asm_out_file);
5926 cont:
5927 ++lt_index;
5929 /* If we're done with a function, end its sequence. */
5930 if (lt_index == separate_line_info_table_in_use
5931 || separate_line_info_table[lt_index].function != function)
5933 current_file = 1;
5934 current_line = 1;
5936 /* Emit debug info for the address of the end of the function. */
5937 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function);
5938 if (0)
5940 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNS_fixed_advance_pc);
5941 if (flag_debug_asm)
5942 fprintf (asm_out_file, "\t%s DW_LNS_fixed_advance_pc",
5943 ASM_COMMENT_START);
5945 fputc ('\n', asm_out_file);
5946 ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, line_label,
5947 prev_line_label);
5948 fputc ('\n', asm_out_file);
5950 else
5952 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5953 if (flag_debug_asm)
5954 fprintf (asm_out_file, "\t%s DW_LNE_set_address",
5955 ASM_COMMENT_START);
5956 fputc ('\n', asm_out_file);
5957 output_uleb128 (1 + PTR_SIZE);
5958 fputc ('\n', asm_out_file);
5959 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_set_address);
5960 fputc ('\n', asm_out_file);
5961 ASM_OUTPUT_DWARF_ADDR (asm_out_file, line_label);
5962 fputc ('\n', asm_out_file);
5965 /* Output the marker for the end of this sequence. */
5966 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 0);
5967 if (flag_debug_asm)
5968 fprintf (asm_out_file, "\t%s DW_LNE_end_sequence",
5969 ASM_COMMENT_START);
5971 fputc ('\n', asm_out_file);
5972 output_uleb128 (1);
5973 fputc ('\n', asm_out_file);
5974 ASM_OUTPUT_DWARF_DATA1 (asm_out_file, DW_LNE_end_sequence);
5975 fputc ('\n', asm_out_file);
5980 /* Given a pointer to a BLOCK node return non-zero if (and only if) the node
5981 in question represents the outermost pair of curly braces (i.e. the "body
5982 block") of a function or method.
5984 For any BLOCK node representing a "body block" of a function or method, the
5985 BLOCK_SUPERCONTEXT of the node will point to another BLOCK node which
5986 represents the outermost (function) scope for the function or method (i.e.
5987 the one which includes the formal parameters). The BLOCK_SUPERCONTEXT of
5988 *that* node in turn will point to the relevant FUNCTION_DECL node. */
5990 static inline int
5991 is_body_block (stmt)
5992 register tree stmt;
5994 if (TREE_CODE (stmt) == BLOCK)
5996 register tree parent = BLOCK_SUPERCONTEXT (stmt);
5998 if (TREE_CODE (parent) == BLOCK)
6000 register tree grandparent = BLOCK_SUPERCONTEXT (parent);
6002 if (TREE_CODE (grandparent) == FUNCTION_DECL)
6003 return 1;
6007 return 0;
6010 /* Given a pointer to a tree node for some base type, return a pointer to
6011 a DIE that describes the given type.
6013 This routine must only be called for GCC type nodes that correspond to
6014 Dwarf base (fundamental) types. */
6016 static dw_die_ref
6017 base_type_die (type)
6018 register tree type;
6020 register dw_die_ref base_type_result;
6021 register const char *type_name;
6022 register enum dwarf_type encoding;
6023 register tree name = TYPE_NAME (type);
6025 if (TREE_CODE (type) == ERROR_MARK
6026 || TREE_CODE (type) == VOID_TYPE)
6027 return 0;
6029 if (name)
6031 if (TREE_CODE (name) == TYPE_DECL)
6032 name = DECL_NAME (name);
6034 type_name = IDENTIFIER_POINTER (name);
6036 else
6037 type_name = "__unknown__";
6039 switch (TREE_CODE (type))
6041 case INTEGER_TYPE:
6042 /* Carefully distinguish the C character types, without messing
6043 up if the language is not C. Note that we check only for the names
6044 that contain spaces; other names might occur by coincidence in other
6045 languages. */
6046 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE
6047 && (type == char_type_node
6048 || ! strcmp (type_name, "signed char")
6049 || ! strcmp (type_name, "unsigned char"))))
6051 if (TREE_UNSIGNED (type))
6052 encoding = DW_ATE_unsigned;
6053 else
6054 encoding = DW_ATE_signed;
6055 break;
6057 /* else fall through */
6059 case CHAR_TYPE:
6060 /* GNU Pascal/Ada CHAR type. Not used in C. */
6061 if (TREE_UNSIGNED (type))
6062 encoding = DW_ATE_unsigned_char;
6063 else
6064 encoding = DW_ATE_signed_char;
6065 break;
6067 case REAL_TYPE:
6068 encoding = DW_ATE_float;
6069 break;
6071 /* Dwarf2 doesn't know anything about complex ints, so use
6072 a user defined type for it. */
6073 case COMPLEX_TYPE:
6074 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6075 encoding = DW_ATE_complex_float;
6076 else
6077 encoding = DW_ATE_lo_user;
6078 break;
6080 case BOOLEAN_TYPE:
6081 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
6082 encoding = DW_ATE_boolean;
6083 break;
6085 default:
6086 abort (); /* No other TREE_CODEs are Dwarf fundamental types. */
6089 base_type_result = new_die (DW_TAG_base_type, comp_unit_die);
6090 if (demangle_name_func)
6091 type_name = (*demangle_name_func) (type_name);
6093 add_AT_string (base_type_result, DW_AT_name, type_name);
6094 add_AT_unsigned (base_type_result, DW_AT_byte_size,
6095 int_size_in_bytes (type));
6096 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding);
6098 return base_type_result;
6101 /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
6102 the Dwarf "root" type for the given input type. The Dwarf "root" type of
6103 a given type is generally the same as the given type, except that if the
6104 given type is a pointer or reference type, then the root type of the given
6105 type is the root type of the "basis" type for the pointer or reference
6106 type. (This definition of the "root" type is recursive.) Also, the root
6107 type of a `const' qualified type or a `volatile' qualified type is the
6108 root type of the given type without the qualifiers. */
6110 static tree
6111 root_type (type)
6112 register tree type;
6114 if (TREE_CODE (type) == ERROR_MARK)
6115 return error_mark_node;
6117 switch (TREE_CODE (type))
6119 case ERROR_MARK:
6120 return error_mark_node;
6122 case POINTER_TYPE:
6123 case REFERENCE_TYPE:
6124 return type_main_variant (root_type (TREE_TYPE (type)));
6126 default:
6127 return type_main_variant (type);
6131 /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
6132 given input type is a Dwarf "fundamental" type. Otherwise return null. */
6134 static inline int
6135 is_base_type (type)
6136 register tree type;
6138 switch (TREE_CODE (type))
6140 case ERROR_MARK:
6141 case VOID_TYPE:
6142 case INTEGER_TYPE:
6143 case REAL_TYPE:
6144 case COMPLEX_TYPE:
6145 case BOOLEAN_TYPE:
6146 case CHAR_TYPE:
6147 return 1;
6149 case SET_TYPE:
6150 case ARRAY_TYPE:
6151 case RECORD_TYPE:
6152 case UNION_TYPE:
6153 case QUAL_UNION_TYPE:
6154 case ENUMERAL_TYPE:
6155 case FUNCTION_TYPE:
6156 case METHOD_TYPE:
6157 case POINTER_TYPE:
6158 case REFERENCE_TYPE:
6159 case FILE_TYPE:
6160 case OFFSET_TYPE:
6161 case LANG_TYPE:
6162 return 0;
6164 default:
6165 abort ();
6168 return 0;
6171 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
6172 entry that chains various modifiers in front of the given type. */
6174 static dw_die_ref
6175 modified_type_die (type, is_const_type, is_volatile_type, context_die)
6176 register tree type;
6177 register int is_const_type;
6178 register int is_volatile_type;
6179 register dw_die_ref context_die;
6181 register enum tree_code code = TREE_CODE (type);
6182 register dw_die_ref mod_type_die = NULL;
6183 register dw_die_ref sub_die = NULL;
6184 register tree item_type = NULL;
6186 if (code != ERROR_MARK)
6188 type = build_type_variant (type, is_const_type, is_volatile_type);
6190 mod_type_die = lookup_type_die (type);
6191 if (mod_type_die)
6192 return mod_type_die;
6194 /* Handle C typedef types. */
6195 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
6196 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
6198 tree dtype = TREE_TYPE (TYPE_NAME (type));
6199 if (type == dtype)
6201 /* For a named type, use the typedef. */
6202 gen_type_die (type, context_die);
6203 mod_type_die = lookup_type_die (type);
6206 else if (is_const_type < TYPE_READONLY (dtype)
6207 || is_volatile_type < TYPE_VOLATILE (dtype))
6208 /* cv-unqualified version of named type. Just use the unnamed
6209 type to which it refers. */
6210 mod_type_die
6211 = modified_type_die (DECL_ORIGINAL_TYPE (TYPE_NAME (type)),
6212 is_const_type, is_volatile_type,
6213 context_die);
6214 /* Else cv-qualified version of named type; fall through. */
6217 if (mod_type_die)
6218 /* OK */;
6219 else if (is_const_type)
6221 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die);
6222 sub_die = modified_type_die (type, 0, is_volatile_type, context_die);
6224 else if (is_volatile_type)
6226 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die);
6227 sub_die = modified_type_die (type, 0, 0, context_die);
6229 else if (code == POINTER_TYPE)
6231 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die);
6232 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6233 #if 0
6234 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6235 #endif
6236 item_type = TREE_TYPE (type);
6238 else if (code == REFERENCE_TYPE)
6240 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die);
6241 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
6242 #if 0
6243 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0);
6244 #endif
6245 item_type = TREE_TYPE (type);
6247 else if (is_base_type (type))
6248 mod_type_die = base_type_die (type);
6249 else
6251 gen_type_die (type, context_die);
6253 /* We have to get the type_main_variant here (and pass that to the
6254 `lookup_type_die' routine) because the ..._TYPE node we have
6255 might simply be a *copy* of some original type node (where the
6256 copy was created to help us keep track of typedef names) and
6257 that copy might have a different TYPE_UID from the original
6258 ..._TYPE node. */
6259 mod_type_die = lookup_type_die (type_main_variant (type));
6260 if (mod_type_die == NULL)
6261 abort ();
6265 equate_type_number_to_die (type, mod_type_die);
6266 if (item_type)
6267 /* We must do this after the equate_type_number_to_die call, in case
6268 this is a recursive type. This ensures that the modified_type_die
6269 recursion will terminate even if the type is recursive. Recursive
6270 types are possible in Ada. */
6271 sub_die = modified_type_die (item_type,
6272 TYPE_READONLY (item_type),
6273 TYPE_VOLATILE (item_type),
6274 context_die);
6276 if (sub_die != NULL)
6277 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die);
6279 return mod_type_die;
6282 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
6283 an enumerated type. */
6285 static inline int
6286 type_is_enum (type)
6287 register tree type;
6289 return TREE_CODE (type) == ENUMERAL_TYPE;
6292 /* Return a location descriptor that designates a machine register. */
6294 static dw_loc_descr_ref
6295 reg_loc_descriptor (rtl)
6296 register rtx rtl;
6298 register dw_loc_descr_ref loc_result = NULL;
6299 register unsigned reg = reg_number (rtl);
6301 if (reg <= 31)
6302 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0);
6303 else
6304 loc_result = new_loc_descr (DW_OP_regx, reg, 0);
6306 return loc_result;
6309 /* Return a location descriptor that designates a base+offset location. */
6311 static dw_loc_descr_ref
6312 based_loc_descr (reg, offset)
6313 unsigned reg;
6314 long int offset;
6316 register dw_loc_descr_ref loc_result;
6317 /* For the "frame base", we use the frame pointer or stack pointer
6318 registers, since the RTL for local variables is relative to one of
6319 them. */
6320 register unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed
6321 ? HARD_FRAME_POINTER_REGNUM
6322 : STACK_POINTER_REGNUM);
6324 if (reg == fp_reg)
6325 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0);
6326 else if (reg <= 31)
6327 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0);
6328 else
6329 loc_result = new_loc_descr (DW_OP_bregx, reg, offset);
6331 return loc_result;
6334 /* Return true if this RTL expression describes a base+offset calculation. */
6336 static inline int
6337 is_based_loc (rtl)
6338 register rtx rtl;
6340 return (GET_CODE (rtl) == PLUS
6341 && ((GET_CODE (XEXP (rtl, 0)) == REG
6342 && GET_CODE (XEXP (rtl, 1)) == CONST_INT)));
6345 /* The following routine converts the RTL for a variable or parameter
6346 (resident in memory) into an equivalent Dwarf representation of a
6347 mechanism for getting the address of that same variable onto the top of a
6348 hypothetical "address evaluation" stack.
6350 When creating memory location descriptors, we are effectively transforming
6351 the RTL for a memory-resident object into its Dwarf postfix expression
6352 equivalent. This routine recursively descends an RTL tree, turning
6353 it into Dwarf postfix code as it goes.
6355 MODE is the mode of the memory reference, needed to handle some
6356 autoincrement addressing modes. */
6358 static dw_loc_descr_ref
6359 mem_loc_descriptor (rtl, mode)
6360 register rtx rtl;
6361 enum machine_mode mode;
6363 dw_loc_descr_ref mem_loc_result = NULL;
6364 /* Note that for a dynamically sized array, the location we will generate a
6365 description of here will be the lowest numbered location which is
6366 actually within the array. That's *not* necessarily the same as the
6367 zeroth element of the array. */
6369 switch (GET_CODE (rtl))
6371 case POST_INC:
6372 case POST_DEC:
6373 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we
6374 just fall into the SUBREG code. */
6376 /* ... fall through ... */
6378 case SUBREG:
6379 /* The case of a subreg may arise when we have a local (register)
6380 variable or a formal (register) parameter which doesn't quite fill
6381 up an entire register. For now, just assume that it is
6382 legitimate to make the Dwarf info refer to the whole register which
6383 contains the given subreg. */
6384 rtl = XEXP (rtl, 0);
6386 /* ... fall through ... */
6388 case REG:
6389 /* Whenever a register number forms a part of the description of the
6390 method for calculating the (dynamic) address of a memory resident
6391 object, DWARF rules require the register number be referred to as
6392 a "base register". This distinction is not based in any way upon
6393 what category of register the hardware believes the given register
6394 belongs to. This is strictly DWARF terminology we're dealing with
6395 here. Note that in cases where the location of a memory-resident
6396 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
6397 OP_CONST (0)) the actual DWARF location descriptor that we generate
6398 may just be OP_BASEREG (basereg). This may look deceptively like
6399 the object in question was allocated to a register (rather than in
6400 memory) so DWARF consumers need to be aware of the subtle
6401 distinction between OP_REG and OP_BASEREG. */
6402 mem_loc_result = based_loc_descr (reg_number (rtl), 0);
6403 break;
6405 case MEM:
6406 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode);
6407 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0));
6408 break;
6410 case LABEL_REF:
6411 /* Some ports can transform a symbol ref into a label ref, because
6412 the symbol ref is too far away and has to be dumped into a constant
6413 pool. */
6414 case CONST:
6415 case SYMBOL_REF:
6416 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0);
6417 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr;
6418 mem_loc_result->dw_loc_oprnd1.v.val_addr = addr_to_string (rtl);
6419 break;
6421 case PRE_INC:
6422 case PRE_DEC:
6423 /* Turn these into a PLUS expression and fall into the PLUS code
6424 below. */
6425 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0),
6426 GEN_INT (GET_CODE (rtl) == PRE_INC
6427 ? GET_MODE_UNIT_SIZE (mode)
6428 : - GET_MODE_UNIT_SIZE (mode)));
6430 /* ... fall through ... */
6432 case PLUS:
6433 if (is_based_loc (rtl))
6434 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)),
6435 INTVAL (XEXP (rtl, 1)));
6436 else
6438 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0),
6439 mode));
6440 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1),
6441 mode));
6442 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_plus, 0, 0));
6444 break;
6446 case MULT:
6447 /* If a pseudo-reg is optimized away, it is possible for it to
6448 be replaced with a MEM containing a multiply. */
6449 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 0), mode));
6450 add_loc_descr (&mem_loc_result, mem_loc_descriptor (XEXP (rtl, 1), mode));
6451 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0));
6452 break;
6454 case CONST_INT:
6455 mem_loc_result = new_loc_descr (DW_OP_constu, INTVAL (rtl), 0);
6456 break;
6458 default:
6459 abort ();
6462 return mem_loc_result;
6465 /* Return a descriptor that describes the concatenation of two locations.
6466 This is typically a complex variable. */
6468 static dw_loc_descr_ref
6469 concat_loc_descriptor (x0, x1)
6470 register rtx x0, x1;
6472 dw_loc_descr_ref cc_loc_result = NULL;
6474 if (!is_pseudo_reg (x0)
6475 && (GET_CODE (x0) != MEM || !is_pseudo_reg (XEXP (x0, 0))))
6476 add_loc_descr (&cc_loc_result, loc_descriptor (x0));
6477 add_loc_descr (&cc_loc_result,
6478 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x0)), 0));
6480 if (!is_pseudo_reg (x1)
6481 && (GET_CODE (x1) != MEM || !is_pseudo_reg (XEXP (x1, 0))))
6482 add_loc_descr (&cc_loc_result, loc_descriptor (x1));
6483 add_loc_descr (&cc_loc_result,
6484 new_loc_descr (DW_OP_piece, GET_MODE_SIZE (GET_MODE (x1)), 0));
6486 return cc_loc_result;
6489 /* Output a proper Dwarf location descriptor for a variable or parameter
6490 which is either allocated in a register or in a memory location. For a
6491 register, we just generate an OP_REG and the register number. For a
6492 memory location we provide a Dwarf postfix expression describing how to
6493 generate the (dynamic) address of the object onto the address stack. */
6495 static dw_loc_descr_ref
6496 loc_descriptor (rtl)
6497 register rtx rtl;
6499 dw_loc_descr_ref loc_result = NULL;
6500 switch (GET_CODE (rtl))
6502 case SUBREG:
6503 /* The case of a subreg may arise when we have a local (register)
6504 variable or a formal (register) parameter which doesn't quite fill
6505 up an entire register. For now, just assume that it is
6506 legitimate to make the Dwarf info refer to the whole register which
6507 contains the given subreg. */
6508 rtl = XEXP (rtl, 0);
6510 /* ... fall through ... */
6512 case REG:
6513 loc_result = reg_loc_descriptor (rtl);
6514 break;
6516 case MEM:
6517 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl));
6518 break;
6520 case CONCAT:
6521 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1));
6522 break;
6524 default:
6525 abort ();
6528 return loc_result;
6531 /* Given an unsigned value, round it up to the lowest multiple of `boundary'
6532 which is not less than the value itself. */
6534 static inline unsigned
6535 ceiling (value, boundary)
6536 register unsigned value;
6537 register unsigned boundary;
6539 return (((value + boundary - 1) / boundary) * boundary);
6542 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
6543 pointer to the declared type for the relevant field variable, or return
6544 `integer_type_node' if the given node turns out to be an
6545 ERROR_MARK node. */
6547 static inline tree
6548 field_type (decl)
6549 register tree decl;
6551 register tree type;
6553 if (TREE_CODE (decl) == ERROR_MARK)
6554 return integer_type_node;
6556 type = DECL_BIT_FIELD_TYPE (decl);
6557 if (type == NULL_TREE)
6558 type = TREE_TYPE (decl);
6560 return type;
6563 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6564 node, return the alignment in bits for the type, or else return
6565 BITS_PER_WORD if the node actually turns out to be an
6566 ERROR_MARK node. */
6568 static inline unsigned
6569 simple_type_align_in_bits (type)
6570 register tree type;
6572 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD;
6575 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
6576 node, return the size in bits for the type if it is a constant, or else
6577 return the alignment for the type if the type's size is not constant, or
6578 else return BITS_PER_WORD if the type actually turns out to be an
6579 ERROR_MARK node. */
6581 static inline unsigned
6582 simple_type_size_in_bits (type)
6583 register tree type;
6585 if (TREE_CODE (type) == ERROR_MARK)
6586 return BITS_PER_WORD;
6587 else
6589 register tree type_size_tree = TYPE_SIZE (type);
6591 if (TREE_CODE (type_size_tree) != INTEGER_CST)
6592 return TYPE_ALIGN (type);
6594 return (unsigned) TREE_INT_CST_LOW (type_size_tree);
6598 /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and
6599 return the byte offset of the lowest addressed byte of the "containing
6600 object" for the given FIELD_DECL, or return 0 if we are unable to
6601 determine what that offset is, either because the argument turns out to
6602 be a pointer to an ERROR_MARK node, or because the offset is actually
6603 variable. (We can't handle the latter case just yet). */
6605 static unsigned
6606 field_byte_offset (decl)
6607 register tree decl;
6609 register unsigned type_align_in_bytes;
6610 register unsigned type_align_in_bits;
6611 register unsigned type_size_in_bits;
6612 register unsigned object_offset_in_align_units;
6613 register unsigned object_offset_in_bits;
6614 register unsigned object_offset_in_bytes;
6615 register tree type;
6616 register tree bitpos_tree;
6617 register tree field_size_tree;
6618 register unsigned bitpos_int;
6619 register unsigned deepest_bitpos;
6620 register unsigned field_size_in_bits;
6622 if (TREE_CODE (decl) == ERROR_MARK)
6623 return 0;
6625 if (TREE_CODE (decl) != FIELD_DECL)
6626 abort ();
6628 type = field_type (decl);
6630 bitpos_tree = DECL_FIELD_BITPOS (decl);
6631 field_size_tree = DECL_SIZE (decl);
6633 /* We cannot yet cope with fields whose positions are variable, so
6634 for now, when we see such things, we simply return 0. Someday, we may
6635 be able to handle such cases, but it will be damn difficult. */
6636 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
6637 return 0;
6639 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
6641 /* If we don't know the size of the field, pretend it's a full word. */
6642 if (TREE_CODE (field_size_tree) == INTEGER_CST)
6643 field_size_in_bits = (unsigned) TREE_INT_CST_LOW (field_size_tree);
6644 else
6645 field_size_in_bits = BITS_PER_WORD;
6647 type_size_in_bits = simple_type_size_in_bits (type);
6648 type_align_in_bits = simple_type_align_in_bits (type);
6649 type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT;
6651 /* Note that the GCC front-end doesn't make any attempt to keep track of
6652 the starting bit offset (relative to the start of the containing
6653 structure type) of the hypothetical "containing object" for a bit-
6654 field. Thus, when computing the byte offset value for the start of the
6655 "containing object" of a bit-field, we must deduce this information on
6656 our own. This can be rather tricky to do in some cases. For example,
6657 handling the following structure type definition when compiling for an
6658 i386/i486 target (which only aligns long long's to 32-bit boundaries)
6659 can be very tricky:
6661 struct S { int field1; long long field2:31; };
6663 Fortunately, there is a simple rule-of-thumb which can be
6664 used in such cases. When compiling for an i386/i486, GCC will allocate
6665 8 bytes for the structure shown above. It decides to do this based upon
6666 one simple rule for bit-field allocation. Quite simply, GCC allocates
6667 each "containing object" for each bit-field at the first (i.e. lowest
6668 addressed) legitimate alignment boundary (based upon the required
6669 minimum alignment for the declared type of the field) which it can
6670 possibly use, subject to the condition that there is still enough
6671 available space remaining in the containing object (when allocated at
6672 the selected point) to fully accommodate all of the bits of the
6673 bit-field itself. This simple rule makes it obvious why GCC allocates
6674 8 bytes for each object of the structure type shown above. When looking
6675 for a place to allocate the "containing object" for `field2', the
6676 compiler simply tries to allocate a 64-bit "containing object" at each
6677 successive 32-bit boundary (starting at zero) until it finds a place to
6678 allocate that 64- bit field such that at least 31 contiguous (and
6679 previously unallocated) bits remain within that selected 64 bit field.
6680 (As it turns out, for the example above, the compiler finds that it is
6681 OK to allocate the "containing object" 64-bit field at bit-offset zero
6682 within the structure type.) Here we attempt to work backwards from the
6683 limited set of facts we're given, and we try to deduce from those facts,
6684 where GCC must have believed that the containing object started (within
6685 the structure type). The value we deduce is then used (by the callers of
6686 this routine) to generate DW_AT_location and DW_AT_bit_offset attributes
6687 for fields (both bit-fields and, in the case of DW_AT_location, regular
6688 fields as well). */
6690 /* Figure out the bit-distance from the start of the structure to the
6691 "deepest" bit of the bit-field. */
6692 deepest_bitpos = bitpos_int + field_size_in_bits;
6694 /* This is the tricky part. Use some fancy footwork to deduce where the
6695 lowest addressed bit of the containing object must be. */
6696 object_offset_in_bits
6697 = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits;
6699 /* Compute the offset of the containing object in "alignment units". */
6700 object_offset_in_align_units = object_offset_in_bits / type_align_in_bits;
6702 /* Compute the offset of the containing object in bytes. */
6703 object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes;
6705 return object_offset_in_bytes;
6708 /* The following routines define various Dwarf attributes and any data
6709 associated with them. */
6711 /* Add a location description attribute value to a DIE.
6713 This emits location attributes suitable for whole variables and
6714 whole parameters. Note that the location attributes for struct fields are
6715 generated by the routine `data_member_location_attribute' below. */
6717 static void
6718 add_AT_location_description (die, attr_kind, rtl)
6719 dw_die_ref die;
6720 enum dwarf_attribute attr_kind;
6721 register rtx rtl;
6723 /* Handle a special case. If we are about to output a location descriptor
6724 for a variable or parameter which has been optimized out of existence,
6725 don't do that. A variable which has been optimized out
6726 of existence will have a DECL_RTL value which denotes a pseudo-reg.
6727 Currently, in some rare cases, variables can have DECL_RTL values which
6728 look like (MEM (REG pseudo-reg#)). These cases are due to bugs
6729 elsewhere in the compiler. We treat such cases as if the variable(s) in
6730 question had been optimized out of existence. */
6732 if (is_pseudo_reg (rtl)
6733 || (GET_CODE (rtl) == MEM
6734 && is_pseudo_reg (XEXP (rtl, 0)))
6735 /* This can happen for a PARM_DECL with a DECL_INCOMING_RTL which
6736 references the internal argument pointer (a pseudo) in a function
6737 where all references to the internal argument pointer were
6738 eliminated via the optimizers. */
6739 || (GET_CODE (rtl) == MEM
6740 && GET_CODE (XEXP (rtl, 0)) == PLUS
6741 && is_pseudo_reg (XEXP (XEXP (rtl, 0), 0)))
6742 || (GET_CODE (rtl) == CONCAT
6743 && is_pseudo_reg (XEXP (rtl, 0))
6744 && is_pseudo_reg (XEXP (rtl, 1))))
6745 return;
6747 add_AT_loc (die, attr_kind, loc_descriptor (rtl));
6750 /* Attach the specialized form of location attribute used for data
6751 members of struct and union types. In the special case of a
6752 FIELD_DECL node which represents a bit-field, the "offset" part
6753 of this special location descriptor must indicate the distance
6754 in bytes from the lowest-addressed byte of the containing struct
6755 or union type to the lowest-addressed byte of the "containing
6756 object" for the bit-field. (See the `field_byte_offset' function
6757 above).. For any given bit-field, the "containing object" is a
6758 hypothetical object (of some integral or enum type) within which
6759 the given bit-field lives. The type of this hypothetical
6760 "containing object" is always the same as the declared type of
6761 the individual bit-field itself (for GCC anyway... the DWARF
6762 spec doesn't actually mandate this). Note that it is the size
6763 (in bytes) of the hypothetical "containing object" which will
6764 be given in the DW_AT_byte_size attribute for this bit-field.
6765 (See the `byte_size_attribute' function below.) It is also used
6766 when calculating the value of the DW_AT_bit_offset attribute.
6767 (See the `bit_offset_attribute' function below). */
6769 static void
6770 add_data_member_location_attribute (die, decl)
6771 register dw_die_ref die;
6772 register tree decl;
6774 register unsigned long offset;
6775 register dw_loc_descr_ref loc_descr;
6776 register enum dwarf_location_atom op;
6778 if (TREE_CODE (decl) == TREE_VEC)
6779 offset = TREE_INT_CST_LOW (BINFO_OFFSET (decl));
6780 else
6781 offset = field_byte_offset (decl);
6783 /* The DWARF2 standard says that we should assume that the structure address
6784 is already on the stack, so we can specify a structure field address
6785 by using DW_OP_plus_uconst. */
6787 #ifdef MIPS_DEBUGGING_INFO
6788 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst operator
6789 correctly. It works only if we leave the offset on the stack. */
6790 op = DW_OP_constu;
6791 #else
6792 op = DW_OP_plus_uconst;
6793 #endif
6795 loc_descr = new_loc_descr (op, offset, 0);
6796 add_AT_loc (die, DW_AT_data_member_location, loc_descr);
6799 /* Attach an DW_AT_const_value attribute for a variable or a parameter which
6800 does not have a "location" either in memory or in a register. These
6801 things can arise in GNU C when a constant is passed as an actual parameter
6802 to an inlined function. They can also arise in C++ where declared
6803 constants do not necessarily get memory "homes". */
6805 static void
6806 add_const_value_attribute (die, rtl)
6807 register dw_die_ref die;
6808 register rtx rtl;
6810 switch (GET_CODE (rtl))
6812 case CONST_INT:
6813 /* Note that a CONST_INT rtx could represent either an integer or a
6814 floating-point constant. A CONST_INT is used whenever the constant
6815 will fit into a single word. In all such cases, the original mode
6816 of the constant value is wiped out, and the CONST_INT rtx is
6817 assigned VOIDmode. */
6818 add_AT_unsigned (die, DW_AT_const_value, (unsigned) INTVAL (rtl));
6819 break;
6821 case CONST_DOUBLE:
6822 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
6823 floating-point constant. A CONST_DOUBLE is used whenever the
6824 constant requires more than one word in order to be adequately
6825 represented. We output CONST_DOUBLEs as blocks. */
6827 register enum machine_mode mode = GET_MODE (rtl);
6829 if (GET_MODE_CLASS (mode) == MODE_FLOAT)
6831 register unsigned length = GET_MODE_SIZE (mode) / sizeof (long);
6832 long array[4];
6833 REAL_VALUE_TYPE rv;
6835 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl);
6836 switch (mode)
6838 case SFmode:
6839 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]);
6840 break;
6842 case DFmode:
6843 REAL_VALUE_TO_TARGET_DOUBLE (rv, array);
6844 break;
6846 case XFmode:
6847 case TFmode:
6848 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array);
6849 break;
6851 default:
6852 abort ();
6855 add_AT_float (die, DW_AT_const_value, length, array);
6857 else
6858 add_AT_long_long (die, DW_AT_const_value,
6859 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl));
6861 break;
6863 case CONST_STRING:
6864 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0));
6865 break;
6867 case SYMBOL_REF:
6868 case LABEL_REF:
6869 case CONST:
6870 add_AT_addr (die, DW_AT_const_value, addr_to_string (rtl));
6871 break;
6873 case PLUS:
6874 /* In cases where an inlined instance of an inline function is passed
6875 the address of an `auto' variable (which is local to the caller) we
6876 can get a situation where the DECL_RTL of the artificial local
6877 variable (for the inlining) which acts as a stand-in for the
6878 corresponding formal parameter (of the inline function) will look
6879 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
6880 exactly a compile-time constant expression, but it isn't the address
6881 of the (artificial) local variable either. Rather, it represents the
6882 *value* which the artificial local variable always has during its
6883 lifetime. We currently have no way to represent such quasi-constant
6884 values in Dwarf, so for now we just punt and generate nothing. */
6885 break;
6887 default:
6888 /* No other kinds of rtx should be possible here. */
6889 abort ();
6894 /* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value
6895 data attribute for a variable or a parameter. We generate the
6896 DW_AT_const_value attribute only in those cases where the given variable
6897 or parameter does not have a true "location" either in memory or in a
6898 register. This can happen (for example) when a constant is passed as an
6899 actual argument in a call to an inline function. (It's possible that
6900 these things can crop up in other ways also.) Note that one type of
6901 constant value which can be passed into an inlined function is a constant
6902 pointer. This can happen for example if an actual argument in an inlined
6903 function call evaluates to a compile-time constant address. */
6905 static void
6906 add_location_or_const_value_attribute (die, decl)
6907 register dw_die_ref die;
6908 register tree decl;
6910 register rtx rtl;
6911 register tree declared_type;
6912 register tree passed_type;
6914 if (TREE_CODE (decl) == ERROR_MARK)
6915 return;
6917 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL)
6918 abort ();
6920 /* Here we have to decide where we are going to say the parameter "lives"
6921 (as far as the debugger is concerned). We only have a couple of
6922 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
6924 DECL_RTL normally indicates where the parameter lives during most of the
6925 activation of the function. If optimization is enabled however, this
6926 could be either NULL or else a pseudo-reg. Both of those cases indicate
6927 that the parameter doesn't really live anywhere (as far as the code
6928 generation parts of GCC are concerned) during most of the function's
6929 activation. That will happen (for example) if the parameter is never
6930 referenced within the function.
6932 We could just generate a location descriptor here for all non-NULL
6933 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
6934 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
6935 where DECL_RTL is NULL or is a pseudo-reg.
6937 Note however that we can only get away with using DECL_INCOMING_RTL as
6938 a backup substitute for DECL_RTL in certain limited cases. In cases
6939 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
6940 we can be sure that the parameter was passed using the same type as it is
6941 declared to have within the function, and that its DECL_INCOMING_RTL
6942 points us to a place where a value of that type is passed.
6944 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
6945 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
6946 because in these cases DECL_INCOMING_RTL points us to a value of some
6947 type which is *different* from the type of the parameter itself. Thus,
6948 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
6949 such cases, the debugger would end up (for example) trying to fetch a
6950 `float' from a place which actually contains the first part of a
6951 `double'. That would lead to really incorrect and confusing
6952 output at debug-time.
6954 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
6955 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
6956 are a couple of exceptions however. On little-endian machines we can
6957 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
6958 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
6959 an integral type that is smaller than TREE_TYPE (decl). These cases arise
6960 when (on a little-endian machine) a non-prototyped function has a
6961 parameter declared to be of type `short' or `char'. In such cases,
6962 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
6963 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
6964 passed `int' value. If the debugger then uses that address to fetch
6965 a `short' or a `char' (on a little-endian machine) the result will be
6966 the correct data, so we allow for such exceptional cases below.
6968 Note that our goal here is to describe the place where the given formal
6969 parameter lives during most of the function's activation (i.e. between
6970 the end of the prologue and the start of the epilogue). We'll do that
6971 as best as we can. Note however that if the given formal parameter is
6972 modified sometime during the execution of the function, then a stack
6973 backtrace (at debug-time) will show the function as having been
6974 called with the *new* value rather than the value which was
6975 originally passed in. This happens rarely enough that it is not
6976 a major problem, but it *is* a problem, and I'd like to fix it.
6978 A future version of dwarf2out.c may generate two additional
6979 attributes for any given DW_TAG_formal_parameter DIE which will
6980 describe the "passed type" and the "passed location" for the
6981 given formal parameter in addition to the attributes we now
6982 generate to indicate the "declared type" and the "active
6983 location" for each parameter. This additional set of attributes
6984 could be used by debuggers for stack backtraces. Separately, note
6985 that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be
6986 NULL also. This happens (for example) for inlined-instances of
6987 inline function formal parameters which are never referenced.
6988 This really shouldn't be happening. All PARM_DECL nodes should
6989 get valid non-NULL DECL_INCOMING_RTL values, but integrate.c
6990 doesn't currently generate these values for inlined instances of
6991 inline function parameters, so when we see such cases, we are
6992 just out-of-luck for the time being (until integrate.c
6993 gets fixed). */
6995 /* Use DECL_RTL as the "location" unless we find something better. */
6996 rtl = DECL_RTL (decl);
6998 if (TREE_CODE (decl) == PARM_DECL)
7000 if (rtl == NULL_RTX || is_pseudo_reg (rtl))
7002 declared_type = type_main_variant (TREE_TYPE (decl));
7003 passed_type = type_main_variant (DECL_ARG_TYPE (decl));
7005 /* This decl represents a formal parameter which was optimized out.
7006 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
7007 all* cases where (rtl == NULL_RTX) just below. */
7008 if (declared_type == passed_type)
7009 rtl = DECL_INCOMING_RTL (decl);
7010 else if (! BYTES_BIG_ENDIAN
7011 && TREE_CODE (declared_type) == INTEGER_TYPE
7012 && (GET_MODE_SIZE (TYPE_MODE (declared_type))
7013 <= GET_MODE_SIZE (TYPE_MODE (passed_type))))
7014 rtl = DECL_INCOMING_RTL (decl);
7017 /* If the parm was passed in registers, but lives on the stack, then
7018 make a big endian correction if the mode of the type of the
7019 parameter is not the same as the mode of the rtl. */
7020 /* ??? This is the same series of checks that are made in dbxout.c before
7021 we reach the big endian correction code there. It isn't clear if all
7022 of these checks are necessary here, but keeping them all is the safe
7023 thing to do. */
7024 else if (GET_CODE (rtl) == MEM
7025 && XEXP (rtl, 0) != const0_rtx
7026 && ! CONSTANT_P (XEXP (rtl, 0))
7027 /* Not passed in memory. */
7028 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM
7029 /* Not passed by invisible reference. */
7030 && (GET_CODE (XEXP (rtl, 0)) != REG
7031 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM
7032 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM
7033 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
7034 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM
7035 #endif
7037 /* Big endian correction check. */
7038 && BYTES_BIG_ENDIAN
7039 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl)
7040 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))
7041 < UNITS_PER_WORD))
7043 int offset = (UNITS_PER_WORD
7044 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))));
7045 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)),
7046 plus_constant (XEXP (rtl, 0), offset));
7050 if (rtl == NULL_RTX)
7051 return;
7053 rtl = eliminate_regs (rtl, 0, NULL_RTX);
7054 #ifdef LEAF_REG_REMAP
7055 if (current_function_uses_only_leaf_regs)
7056 leaf_renumber_regs_insn (rtl);
7057 #endif
7059 switch (GET_CODE (rtl))
7061 case ADDRESSOF:
7062 /* The address of a variable that was optimized away; don't emit
7063 anything. */
7064 break;
7066 case CONST_INT:
7067 case CONST_DOUBLE:
7068 case CONST_STRING:
7069 case SYMBOL_REF:
7070 case LABEL_REF:
7071 case CONST:
7072 case PLUS:
7073 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */
7074 add_const_value_attribute (die, rtl);
7075 break;
7077 case MEM:
7078 case REG:
7079 case SUBREG:
7080 case CONCAT:
7081 add_AT_location_description (die, DW_AT_location, rtl);
7082 break;
7084 default:
7085 abort ();
7089 /* Generate an DW_AT_name attribute given some string value to be included as
7090 the value of the attribute. */
7092 static inline void
7093 add_name_attribute (die, name_string)
7094 register dw_die_ref die;
7095 register const char *name_string;
7097 if (name_string != NULL && *name_string != 0)
7099 if (demangle_name_func)
7100 name_string = (*demangle_name_func) (name_string);
7102 add_AT_string (die, DW_AT_name, name_string);
7106 /* Given a tree node describing an array bound (either lower or upper) output
7107 a representation for that bound. */
7109 static void
7110 add_bound_info (subrange_die, bound_attr, bound)
7111 register dw_die_ref subrange_die;
7112 register enum dwarf_attribute bound_attr;
7113 register tree bound;
7115 register unsigned bound_value = 0;
7117 /* If this is an Ada unconstrained array type, then don't emit any debug
7118 info because the array bounds are unknown. They are parameterized when
7119 the type is instantiated. */
7120 if (contains_placeholder_p (bound))
7121 return;
7123 switch (TREE_CODE (bound))
7125 case ERROR_MARK:
7126 return;
7128 /* All fixed-bounds are represented by INTEGER_CST nodes. */
7129 case INTEGER_CST:
7130 bound_value = TREE_INT_CST_LOW (bound);
7131 if (bound_attr == DW_AT_lower_bound
7132 && ((is_c_family () && bound_value == 0)
7133 || (is_fortran () && bound_value == 1)))
7134 /* use the default */;
7135 else
7136 add_AT_unsigned (subrange_die, bound_attr, bound_value);
7137 break;
7139 case CONVERT_EXPR:
7140 case NOP_EXPR:
7141 case NON_LVALUE_EXPR:
7142 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0));
7143 break;
7145 case SAVE_EXPR:
7146 /* If optimization is turned on, the SAVE_EXPRs that describe how to
7147 access the upper bound values may be bogus. If they refer to a
7148 register, they may only describe how to get at these values at the
7149 points in the generated code right after they have just been
7150 computed. Worse yet, in the typical case, the upper bound values
7151 will not even *be* computed in the optimized code (though the
7152 number of elements will), so these SAVE_EXPRs are entirely
7153 bogus. In order to compensate for this fact, we check here to see
7154 if optimization is enabled, and if so, we don't add an attribute
7155 for the (unknown and unknowable) upper bound. This should not
7156 cause too much trouble for existing (stupid?) debuggers because
7157 they have to deal with empty upper bounds location descriptions
7158 anyway in order to be able to deal with incomplete array types.
7159 Of course an intelligent debugger (GDB?) should be able to
7160 comprehend that a missing upper bound specification in a array
7161 type used for a storage class `auto' local array variable
7162 indicates that the upper bound is both unknown (at compile- time)
7163 and unknowable (at run-time) due to optimization.
7165 We assume that a MEM rtx is safe because gcc wouldn't put the
7166 value there unless it was going to be used repeatedly in the
7167 function, i.e. for cleanups. */
7168 if (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)
7170 register dw_die_ref ctx = lookup_decl_die (current_function_decl);
7171 register dw_die_ref decl_die = new_die (DW_TAG_variable, ctx);
7172 register rtx loc = SAVE_EXPR_RTL (bound);
7174 /* If the RTL for the SAVE_EXPR is memory, handle the case where
7175 it references an outer function's frame. */
7177 if (GET_CODE (loc) == MEM)
7179 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound);
7181 if (XEXP (loc, 0) != new_addr)
7182 loc = gen_rtx_MEM (GET_MODE (loc), new_addr);
7185 add_AT_flag (decl_die, DW_AT_artificial, 1);
7186 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx);
7187 add_AT_location_description (decl_die, DW_AT_location, loc);
7188 add_AT_die_ref (subrange_die, bound_attr, decl_die);
7191 /* Else leave out the attribute. */
7192 break;
7194 case MAX_EXPR:
7195 case VAR_DECL:
7196 case COMPONENT_REF:
7197 /* ??? These types of bounds can be created by the Ada front end,
7198 and it isn't clear how to emit debug info for them. */
7199 break;
7201 default:
7202 abort ();
7206 /* Note that the block of subscript information for an array type also
7207 includes information about the element type of type given array type. */
7209 static void
7210 add_subscript_info (type_die, type)
7211 register dw_die_ref type_die;
7212 register tree type;
7214 #ifndef MIPS_DEBUGGING_INFO
7215 register unsigned dimension_number;
7216 #endif
7217 register tree lower, upper;
7218 register dw_die_ref subrange_die;
7220 /* The GNU compilers represent multidimensional array types as sequences of
7221 one dimensional array types whose element types are themselves array
7222 types. Here we squish that down, so that each multidimensional array
7223 type gets only one array_type DIE in the Dwarf debugging info. The draft
7224 Dwarf specification say that we are allowed to do this kind of
7225 compression in C (because there is no difference between an array or
7226 arrays and a multidimensional array in C) but for other source languages
7227 (e.g. Ada) we probably shouldn't do this. */
7229 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7230 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7231 We work around this by disabling this feature. See also
7232 gen_array_type_die. */
7233 #ifndef MIPS_DEBUGGING_INFO
7234 for (dimension_number = 0;
7235 TREE_CODE (type) == ARRAY_TYPE;
7236 type = TREE_TYPE (type), dimension_number++)
7238 #endif
7239 register tree domain = TYPE_DOMAIN (type);
7241 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
7242 and (in GNU C only) variable bounds. Handle all three forms
7243 here. */
7244 subrange_die = new_die (DW_TAG_subrange_type, type_die);
7245 if (domain)
7247 /* We have an array type with specified bounds. */
7248 lower = TYPE_MIN_VALUE (domain);
7249 upper = TYPE_MAX_VALUE (domain);
7251 /* define the index type. */
7252 if (TREE_TYPE (domain))
7254 /* ??? This is probably an Ada unnamed subrange type. Ignore the
7255 TREE_TYPE field. We can't emit debug info for this
7256 because it is an unnamed integral type. */
7257 if (TREE_CODE (domain) == INTEGER_TYPE
7258 && TYPE_NAME (domain) == NULL_TREE
7259 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE
7260 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE)
7262 else
7263 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0,
7264 type_die);
7267 /* ??? If upper is NULL, the array has unspecified length,
7268 but it does have a lower bound. This happens with Fortran
7269 dimension arr(N:*)
7270 Since the debugger is definitely going to need to know N
7271 to produce useful results, go ahead and output the lower
7272 bound solo, and hope the debugger can cope. */
7274 add_bound_info (subrange_die, DW_AT_lower_bound, lower);
7275 if (upper)
7276 add_bound_info (subrange_die, DW_AT_upper_bound, upper);
7278 else
7279 /* We have an array type with an unspecified length. The DWARF-2
7280 spec does not say how to handle this; let's just leave out the
7281 bounds. */
7285 #ifndef MIPS_DEBUGGING_INFO
7287 #endif
7290 static void
7291 add_byte_size_attribute (die, tree_node)
7292 dw_die_ref die;
7293 register tree tree_node;
7295 register unsigned size;
7297 switch (TREE_CODE (tree_node))
7299 case ERROR_MARK:
7300 size = 0;
7301 break;
7302 case ENUMERAL_TYPE:
7303 case RECORD_TYPE:
7304 case UNION_TYPE:
7305 case QUAL_UNION_TYPE:
7306 size = int_size_in_bytes (tree_node);
7307 break;
7308 case FIELD_DECL:
7309 /* For a data member of a struct or union, the DW_AT_byte_size is
7310 generally given as the number of bytes normally allocated for an
7311 object of the *declared* type of the member itself. This is true
7312 even for bit-fields. */
7313 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT;
7314 break;
7315 default:
7316 abort ();
7319 /* Note that `size' might be -1 when we get to this point. If it is, that
7320 indicates that the byte size of the entity in question is variable. We
7321 have no good way of expressing this fact in Dwarf at the present time,
7322 so just let the -1 pass on through. */
7324 add_AT_unsigned (die, DW_AT_byte_size, size);
7327 /* For a FIELD_DECL node which represents a bit-field, output an attribute
7328 which specifies the distance in bits from the highest order bit of the
7329 "containing object" for the bit-field to the highest order bit of the
7330 bit-field itself.
7332 For any given bit-field, the "containing object" is a hypothetical
7333 object (of some integral or enum type) within which the given bit-field
7334 lives. The type of this hypothetical "containing object" is always the
7335 same as the declared type of the individual bit-field itself. The
7336 determination of the exact location of the "containing object" for a
7337 bit-field is rather complicated. It's handled by the
7338 `field_byte_offset' function (above).
7340 Note that it is the size (in bytes) of the hypothetical "containing object"
7341 which will be given in the DW_AT_byte_size attribute for this bit-field.
7342 (See `byte_size_attribute' above). */
7344 static inline void
7345 add_bit_offset_attribute (die, decl)
7346 register dw_die_ref die;
7347 register tree decl;
7349 register unsigned object_offset_in_bytes = field_byte_offset (decl);
7350 register tree type = DECL_BIT_FIELD_TYPE (decl);
7351 register tree bitpos_tree = DECL_FIELD_BITPOS (decl);
7352 register unsigned bitpos_int;
7353 register unsigned highest_order_object_bit_offset;
7354 register unsigned highest_order_field_bit_offset;
7355 register unsigned bit_offset;
7357 /* Must be a field and a bit field. */
7358 if (!type
7359 || TREE_CODE (decl) != FIELD_DECL)
7360 abort ();
7362 /* We can't yet handle bit-fields whose offsets are variable, so if we
7363 encounter such things, just return without generating any attribute
7364 whatsoever. */
7365 if (TREE_CODE (bitpos_tree) != INTEGER_CST)
7366 return;
7368 bitpos_int = (unsigned) TREE_INT_CST_LOW (bitpos_tree);
7370 /* Note that the bit offset is always the distance (in bits) from the
7371 highest-order bit of the "containing object" to the highest-order bit of
7372 the bit-field itself. Since the "high-order end" of any object or field
7373 is different on big-endian and little-endian machines, the computation
7374 below must take account of these differences. */
7375 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT;
7376 highest_order_field_bit_offset = bitpos_int;
7378 if (! BYTES_BIG_ENDIAN)
7380 highest_order_field_bit_offset
7381 += (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl));
7383 highest_order_object_bit_offset += simple_type_size_in_bits (type);
7386 bit_offset
7387 = (! BYTES_BIG_ENDIAN
7388 ? highest_order_object_bit_offset - highest_order_field_bit_offset
7389 : highest_order_field_bit_offset - highest_order_object_bit_offset);
7391 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset);
7394 /* For a FIELD_DECL node which represents a bit field, output an attribute
7395 which specifies the length in bits of the given field. */
7397 static inline void
7398 add_bit_size_attribute (die, decl)
7399 register dw_die_ref die;
7400 register tree decl;
7402 /* Must be a field and a bit field. */
7403 if (TREE_CODE (decl) != FIELD_DECL
7404 || ! DECL_BIT_FIELD_TYPE (decl))
7405 abort ();
7406 add_AT_unsigned (die, DW_AT_bit_size,
7407 (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl)));
7410 /* If the compiled language is ANSI C, then add a 'prototyped'
7411 attribute, if arg types are given for the parameters of a function. */
7413 static inline void
7414 add_prototyped_attribute (die, func_type)
7415 register dw_die_ref die;
7416 register tree func_type;
7418 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89
7419 && TYPE_ARG_TYPES (func_type) != NULL)
7420 add_AT_flag (die, DW_AT_prototyped, 1);
7424 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
7425 by looking in either the type declaration or object declaration
7426 equate table. */
7428 static inline void
7429 add_abstract_origin_attribute (die, origin)
7430 register dw_die_ref die;
7431 register tree origin;
7433 dw_die_ref origin_die = NULL;
7435 if (TREE_CODE_CLASS (TREE_CODE (origin)) == 'd')
7436 origin_die = lookup_decl_die (origin);
7437 else if (TREE_CODE_CLASS (TREE_CODE (origin)) == 't')
7438 origin_die = lookup_type_die (origin);
7440 if (origin_die == NULL)
7441 abort ();
7443 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die);
7446 /* We do not currently support the pure_virtual attribute. */
7448 static inline void
7449 add_pure_or_virtual_attribute (die, func_decl)
7450 register dw_die_ref die;
7451 register tree func_decl;
7453 if (DECL_VINDEX (func_decl))
7455 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
7456 add_AT_loc (die, DW_AT_vtable_elem_location,
7457 new_loc_descr (DW_OP_constu,
7458 TREE_INT_CST_LOW (DECL_VINDEX (func_decl)),
7459 0));
7461 /* GNU extension: Record what type this method came from originally. */
7462 if (debug_info_level > DINFO_LEVEL_TERSE)
7463 add_AT_die_ref (die, DW_AT_containing_type,
7464 lookup_type_die (DECL_CONTEXT (func_decl)));
7468 /* Add source coordinate attributes for the given decl. */
7470 static void
7471 add_src_coords_attributes (die, decl)
7472 register dw_die_ref die;
7473 register tree decl;
7475 register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
7477 add_AT_unsigned (die, DW_AT_decl_file, file_index);
7478 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
7481 /* Add an DW_AT_name attribute and source coordinate attribute for the
7482 given decl, but only if it actually has a name. */
7484 static void
7485 add_name_and_src_coords_attributes (die, decl)
7486 register dw_die_ref die;
7487 register tree decl;
7489 register tree decl_name;
7491 decl_name = DECL_NAME (decl);
7492 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL)
7494 add_name_attribute (die, dwarf2_name (decl, 0));
7495 add_src_coords_attributes (die, decl);
7497 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL)
7498 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
7499 add_AT_string (die, DW_AT_MIPS_linkage_name,
7500 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
7504 /* Push a new declaration scope. */
7506 static void
7507 push_decl_scope (scope)
7508 tree scope;
7510 tree containing_scope;
7511 int i;
7513 /* Make room in the decl_scope_table, if necessary. */
7514 if (decl_scope_table_allocated == decl_scope_depth)
7516 decl_scope_table_allocated += DECL_SCOPE_TABLE_INCREMENT;
7517 decl_scope_table
7518 = (decl_scope_node *) xrealloc (decl_scope_table,
7519 (decl_scope_table_allocated
7520 * sizeof (decl_scope_node)));
7523 decl_scope_table[decl_scope_depth].scope = scope;
7525 /* Sometimes, while recursively emitting subtypes within a class type,
7526 we end up recuring on a subtype at a higher level then the current
7527 subtype. In such a case, we need to search the decl_scope_table to
7528 find the parent of this subtype. */
7530 if (AGGREGATE_TYPE_P (scope))
7531 containing_scope = TYPE_CONTEXT (scope);
7532 else
7533 containing_scope = NULL_TREE;
7535 /* The normal case. */
7536 if (decl_scope_depth == 0
7537 || containing_scope == NULL_TREE
7538 /* Ignore namespaces for the moment. */
7539 || TREE_CODE (containing_scope) == NAMESPACE_DECL
7540 || containing_scope == decl_scope_table[decl_scope_depth - 1].scope)
7541 decl_scope_table[decl_scope_depth].previous = decl_scope_depth - 1;
7542 else
7544 /* We need to search for the containing_scope. */
7545 for (i = 0; i < decl_scope_depth; i++)
7546 if (decl_scope_table[i].scope == containing_scope)
7547 break;
7549 if (i == decl_scope_depth)
7550 abort ();
7551 else
7552 decl_scope_table[decl_scope_depth].previous = i;
7555 decl_scope_depth++;
7558 /* Return the DIE for the scope that immediately contains this declaration. */
7560 static dw_die_ref
7561 scope_die_for (t, context_die)
7562 register tree t;
7563 register dw_die_ref context_die;
7565 register dw_die_ref scope_die = NULL;
7566 register tree containing_scope;
7567 register int i;
7569 /* Walk back up the declaration tree looking for a place to define
7570 this type. */
7571 if (TREE_CODE_CLASS (TREE_CODE (t)) == 't')
7572 containing_scope = TYPE_CONTEXT (t);
7573 else if (TREE_CODE (t) == FUNCTION_DECL && DECL_VINDEX (t))
7574 containing_scope = decl_class_context (t);
7575 else
7576 containing_scope = DECL_CONTEXT (t);
7578 /* Ignore namespaces for the moment. */
7579 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL)
7580 containing_scope = NULL_TREE;
7582 /* Ignore function type "scopes" from the C frontend. They mean that
7583 a tagged type is local to a parmlist of a function declarator, but
7584 that isn't useful to DWARF. */
7585 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE)
7586 containing_scope = NULL_TREE;
7588 /* Function-local tags and functions get stuck in limbo until they are
7589 fixed up by decls_for_scope. */
7590 if (context_die == NULL && containing_scope != NULL_TREE
7591 && (TREE_CODE (t) == FUNCTION_DECL || is_tagged_type (t)))
7592 return NULL;
7594 if (containing_scope == NULL_TREE)
7595 scope_die = comp_unit_die;
7596 else
7598 for (i = decl_scope_depth - 1, scope_die = context_die;
7599 i >= 0 && decl_scope_table[i].scope != containing_scope;
7600 (scope_die = scope_die->die_parent,
7601 i = decl_scope_table[i].previous))
7604 /* ??? Integrate_decl_tree does not handle BLOCK_TYPE_TAGS, nor
7605 does it try to handle types defined by TYPE_DECLs. Such types
7606 thus have an incorrect TYPE_CONTEXT, which points to the block
7607 they were originally defined in, instead of the current block
7608 created by function inlining. We try to detect that here and
7609 work around it. */
7611 if (i < 0 && scope_die == comp_unit_die
7612 && TREE_CODE (containing_scope) == BLOCK
7613 && is_tagged_type (t)
7614 && (block_ultimate_origin (decl_scope_table[decl_scope_depth - 1].scope)
7615 == containing_scope))
7617 scope_die = context_die;
7618 /* Since the checks below are no longer applicable. */
7619 i = 0;
7622 if (i < 0)
7624 if (TREE_CODE_CLASS (TREE_CODE (containing_scope)) != 't')
7625 abort ();
7626 if (debug_info_level > DINFO_LEVEL_TERSE
7627 && !TREE_ASM_WRITTEN (containing_scope))
7628 abort ();
7630 /* If none of the current dies are suitable, we get file scope. */
7631 scope_die = comp_unit_die;
7635 return scope_die;
7638 /* Pop a declaration scope. */
7639 static inline void
7640 pop_decl_scope ()
7642 if (decl_scope_depth <= 0)
7643 abort ();
7644 --decl_scope_depth;
7647 /* Many forms of DIEs require a "type description" attribute. This
7648 routine locates the proper "type descriptor" die for the type given
7649 by 'type', and adds an DW_AT_type attribute below the given die. */
7651 static void
7652 add_type_attribute (object_die, type, decl_const, decl_volatile, context_die)
7653 register dw_die_ref object_die;
7654 register tree type;
7655 register int decl_const;
7656 register int decl_volatile;
7657 register dw_die_ref context_die;
7659 register enum tree_code code = TREE_CODE (type);
7660 register dw_die_ref type_die = NULL;
7662 /* ??? If this type is an unnamed subrange type of an integral or
7663 floating-point type, use the inner type. This is because we have no
7664 support for unnamed types in base_type_die. This can happen if this is
7665 an Ada subrange type. Correct solution is emit a subrange type die. */
7666 if ((code == INTEGER_TYPE || code == REAL_TYPE)
7667 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0)
7668 type = TREE_TYPE (type), code = TREE_CODE (type);
7670 if (code == ERROR_MARK)
7671 return;
7673 /* Handle a special case. For functions whose return type is void, we
7674 generate *no* type attribute. (Note that no object may have type
7675 `void', so this only applies to function return types). */
7676 if (code == VOID_TYPE)
7677 return;
7679 type_die = modified_type_die (type,
7680 decl_const || TYPE_READONLY (type),
7681 decl_volatile || TYPE_VOLATILE (type),
7682 context_die);
7683 if (type_die != NULL)
7684 add_AT_die_ref (object_die, DW_AT_type, type_die);
7687 /* Given a tree pointer to a struct, class, union, or enum type node, return
7688 a pointer to the (string) tag name for the given type, or zero if the type
7689 was declared without a tag. */
7691 static char *
7692 type_tag (type)
7693 register tree type;
7695 register char *name = 0;
7697 if (TYPE_NAME (type) != 0)
7699 register tree t = 0;
7701 /* Find the IDENTIFIER_NODE for the type name. */
7702 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
7703 t = TYPE_NAME (type);
7705 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
7706 a TYPE_DECL node, regardless of whether or not a `typedef' was
7707 involved. */
7708 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
7709 && ! DECL_IGNORED_P (TYPE_NAME (type)))
7710 t = DECL_NAME (TYPE_NAME (type));
7712 /* Now get the name as a string, or invent one. */
7713 if (t != 0)
7714 name = IDENTIFIER_POINTER (t);
7717 return (name == 0 || *name == '\0') ? 0 : name;
7720 /* Return the type associated with a data member, make a special check
7721 for bit field types. */
7723 static inline tree
7724 member_declared_type (member)
7725 register tree member;
7727 return (DECL_BIT_FIELD_TYPE (member)
7728 ? DECL_BIT_FIELD_TYPE (member)
7729 : TREE_TYPE (member));
7732 /* Get the decl's label, as described by its RTL. This may be different
7733 from the DECL_NAME name used in the source file. */
7735 #if 0
7736 static char *
7737 decl_start_label (decl)
7738 register tree decl;
7740 rtx x;
7741 char *fnname;
7742 x = DECL_RTL (decl);
7743 if (GET_CODE (x) != MEM)
7744 abort ();
7746 x = XEXP (x, 0);
7747 if (GET_CODE (x) != SYMBOL_REF)
7748 abort ();
7750 fnname = XSTR (x, 0);
7751 return fnname;
7753 #endif
7755 /* These routines generate the internal representation of the DIE's for
7756 the compilation unit. Debugging information is collected by walking
7757 the declaration trees passed in from dwarf2out_decl(). */
7759 static void
7760 gen_array_type_die (type, context_die)
7761 register tree type;
7762 register dw_die_ref context_die;
7764 register dw_die_ref scope_die = scope_die_for (type, context_die);
7765 register dw_die_ref array_die;
7766 register tree element_type;
7768 /* ??? The SGI dwarf reader fails for array of array of enum types unless
7769 the inner array type comes before the outer array type. Thus we must
7770 call gen_type_die before we call new_die. See below also. */
7771 #ifdef MIPS_DEBUGGING_INFO
7772 gen_type_die (TREE_TYPE (type), context_die);
7773 #endif
7775 array_die = new_die (DW_TAG_array_type, scope_die);
7777 #if 0
7778 /* We default the array ordering. SDB will probably do
7779 the right things even if DW_AT_ordering is not present. It's not even
7780 an issue until we start to get into multidimensional arrays anyway. If
7781 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
7782 then we'll have to put the DW_AT_ordering attribute back in. (But if
7783 and when we find out that we need to put these in, we will only do so
7784 for multidimensional arrays. */
7785 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major);
7786 #endif
7788 #ifdef MIPS_DEBUGGING_INFO
7789 /* The SGI compilers handle arrays of unknown bound by setting
7790 AT_declaration and not emitting any subrange DIEs. */
7791 if (! TYPE_DOMAIN (type))
7792 add_AT_unsigned (array_die, DW_AT_declaration, 1);
7793 else
7794 #endif
7795 add_subscript_info (array_die, type);
7797 add_name_attribute (array_die, type_tag (type));
7798 equate_type_number_to_die (type, array_die);
7800 /* Add representation of the type of the elements of this array type. */
7801 element_type = TREE_TYPE (type);
7803 /* ??? The SGI dwarf reader fails for multidimensional arrays with a
7804 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10].
7805 We work around this by disabling this feature. See also
7806 add_subscript_info. */
7807 #ifndef MIPS_DEBUGGING_INFO
7808 while (TREE_CODE (element_type) == ARRAY_TYPE)
7809 element_type = TREE_TYPE (element_type);
7811 gen_type_die (element_type, context_die);
7812 #endif
7814 add_type_attribute (array_die, element_type, 0, 0, context_die);
7817 static void
7818 gen_set_type_die (type, context_die)
7819 register tree type;
7820 register dw_die_ref context_die;
7822 register dw_die_ref type_die
7823 = new_die (DW_TAG_set_type, scope_die_for (type, context_die));
7825 equate_type_number_to_die (type, type_die);
7826 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die);
7829 #if 0
7830 static void
7831 gen_entry_point_die (decl, context_die)
7832 register tree decl;
7833 register dw_die_ref context_die;
7835 register tree origin = decl_ultimate_origin (decl);
7836 register dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die);
7837 if (origin != NULL)
7838 add_abstract_origin_attribute (decl_die, origin);
7839 else
7841 add_name_and_src_coords_attributes (decl_die, decl);
7842 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)),
7843 0, 0, context_die);
7846 if (DECL_ABSTRACT (decl))
7847 equate_decl_number_to_die (decl, decl_die);
7848 else
7849 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl));
7851 #endif
7853 /* Remember a type in the pending_types_list. */
7855 static void
7856 pend_type (type)
7857 register tree type;
7859 if (pending_types == pending_types_allocated)
7861 pending_types_allocated += PENDING_TYPES_INCREMENT;
7862 pending_types_list
7863 = (tree *) xrealloc (pending_types_list,
7864 sizeof (tree) * pending_types_allocated);
7867 pending_types_list[pending_types++] = type;
7870 /* Output any pending types (from the pending_types list) which we can output
7871 now (taking into account the scope that we are working on now).
7873 For each type output, remove the given type from the pending_types_list
7874 *before* we try to output it. */
7876 static void
7877 output_pending_types_for_scope (context_die)
7878 register dw_die_ref context_die;
7880 register tree type;
7882 while (pending_types)
7884 --pending_types;
7885 type = pending_types_list[pending_types];
7886 gen_type_die (type, context_die);
7887 if (!TREE_ASM_WRITTEN (type))
7888 abort ();
7892 /* Remember a type in the incomplete_types_list. */
7894 static void
7895 add_incomplete_type (type)
7896 tree type;
7898 if (incomplete_types == incomplete_types_allocated)
7900 incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT;
7901 incomplete_types_list
7902 = (tree *) xrealloc (incomplete_types_list,
7903 sizeof (tree) * incomplete_types_allocated);
7906 incomplete_types_list[incomplete_types++] = type;
7909 /* Walk through the list of incomplete types again, trying once more to
7910 emit full debugging info for them. */
7912 static void
7913 retry_incomplete_types ()
7915 register tree type;
7917 while (incomplete_types)
7919 --incomplete_types;
7920 type = incomplete_types_list[incomplete_types];
7921 gen_type_die (type, comp_unit_die);
7925 /* Generate a DIE to represent an inlined instance of an enumeration type. */
7927 static void
7928 gen_inlined_enumeration_type_die (type, context_die)
7929 register tree type;
7930 register dw_die_ref context_die;
7932 register dw_die_ref type_die = new_die (DW_TAG_enumeration_type,
7933 scope_die_for (type, context_die));
7934 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7935 be incomplete and such types are not marked. */
7936 add_abstract_origin_attribute (type_die, type);
7939 /* Generate a DIE to represent an inlined instance of a structure type. */
7941 static void
7942 gen_inlined_structure_type_die (type, context_die)
7943 register tree type;
7944 register dw_die_ref context_die;
7946 register dw_die_ref type_die = new_die (DW_TAG_structure_type,
7947 scope_die_for (type, context_die));
7948 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7949 be incomplete and such types are not marked. */
7950 add_abstract_origin_attribute (type_die, type);
7953 /* Generate a DIE to represent an inlined instance of a union type. */
7955 static void
7956 gen_inlined_union_type_die (type, context_die)
7957 register tree type;
7958 register dw_die_ref context_die;
7960 register dw_die_ref type_die = new_die (DW_TAG_union_type,
7961 scope_die_for (type, context_die));
7962 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may
7963 be incomplete and such types are not marked. */
7964 add_abstract_origin_attribute (type_die, type);
7967 /* Generate a DIE to represent an enumeration type. Note that these DIEs
7968 include all of the information about the enumeration values also. Each
7969 enumerated type name/value is listed as a child of the enumerated type
7970 DIE. */
7972 static void
7973 gen_enumeration_type_die (type, context_die)
7974 register tree type;
7975 register dw_die_ref context_die;
7977 register dw_die_ref type_die = lookup_type_die (type);
7979 if (type_die == NULL)
7981 type_die = new_die (DW_TAG_enumeration_type,
7982 scope_die_for (type, context_die));
7983 equate_type_number_to_die (type, type_die);
7984 add_name_attribute (type_die, type_tag (type));
7986 else if (! TYPE_SIZE (type))
7987 return;
7988 else
7989 remove_AT (type_die, DW_AT_declaration);
7991 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
7992 given enum type is incomplete, do not generate the DW_AT_byte_size
7993 attribute or the DW_AT_element_list attribute. */
7994 if (TYPE_SIZE (type))
7996 register tree link;
7998 TREE_ASM_WRITTEN (type) = 1;
7999 add_byte_size_attribute (type_die, type);
8000 if (TYPE_STUB_DECL (type) != NULL_TREE)
8001 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8003 /* If the first reference to this type was as the return type of an
8004 inline function, then it may not have a parent. Fix this now. */
8005 if (type_die->die_parent == NULL)
8006 add_child_die (scope_die_for (type, context_die), type_die);
8008 for (link = TYPE_FIELDS (type);
8009 link != NULL; link = TREE_CHAIN (link))
8011 register dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die);
8013 add_name_attribute (enum_die,
8014 IDENTIFIER_POINTER (TREE_PURPOSE (link)));
8015 add_AT_unsigned (enum_die, DW_AT_const_value,
8016 (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link)));
8019 else
8020 add_AT_flag (type_die, DW_AT_declaration, 1);
8024 /* Generate a DIE to represent either a real live formal parameter decl or to
8025 represent just the type of some formal parameter position in some function
8026 type.
8028 Note that this routine is a bit unusual because its argument may be a
8029 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
8030 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
8031 node. If it's the former then this function is being called to output a
8032 DIE to represent a formal parameter object (or some inlining thereof). If
8033 it's the latter, then this function is only being called to output a
8034 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
8035 argument type of some subprogram type. */
8037 static dw_die_ref
8038 gen_formal_parameter_die (node, context_die)
8039 register tree node;
8040 register dw_die_ref context_die;
8042 register dw_die_ref parm_die
8043 = new_die (DW_TAG_formal_parameter, context_die);
8044 register tree origin;
8046 switch (TREE_CODE_CLASS (TREE_CODE (node)))
8048 case 'd':
8049 origin = decl_ultimate_origin (node);
8050 if (origin != NULL)
8051 add_abstract_origin_attribute (parm_die, origin);
8052 else
8054 add_name_and_src_coords_attributes (parm_die, node);
8055 add_type_attribute (parm_die, TREE_TYPE (node),
8056 TREE_READONLY (node),
8057 TREE_THIS_VOLATILE (node),
8058 context_die);
8059 if (DECL_ARTIFICIAL (node))
8060 add_AT_flag (parm_die, DW_AT_artificial, 1);
8063 equate_decl_number_to_die (node, parm_die);
8064 if (! DECL_ABSTRACT (node))
8065 add_location_or_const_value_attribute (parm_die, node);
8067 break;
8069 case 't':
8070 /* We were called with some kind of a ..._TYPE node. */
8071 add_type_attribute (parm_die, node, 0, 0, context_die);
8072 break;
8074 default:
8075 abort ();
8078 return parm_die;
8081 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
8082 at the end of an (ANSI prototyped) formal parameters list. */
8084 static void
8085 gen_unspecified_parameters_die (decl_or_type, context_die)
8086 register tree decl_or_type ATTRIBUTE_UNUSED;
8087 register dw_die_ref context_die;
8089 new_die (DW_TAG_unspecified_parameters, context_die);
8092 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
8093 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
8094 parameters as specified in some function type specification (except for
8095 those which appear as part of a function *definition*).
8097 Note we must be careful here to output all of the parameter DIEs before*
8098 we output any DIEs needed to represent the types of the formal parameters.
8099 This keeps svr4 SDB happy because it (incorrectly) thinks that the first
8100 non-parameter DIE it sees ends the formal parameter list. */
8102 static void
8103 gen_formal_types_die (function_or_method_type, context_die)
8104 register tree function_or_method_type;
8105 register dw_die_ref context_die;
8107 register tree link;
8108 register tree formal_type = NULL;
8109 register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type);
8111 #if 0
8112 /* In the case where we are generating a formal types list for a C++
8113 non-static member function type, skip over the first thing on the
8114 TYPE_ARG_TYPES list because it only represents the type of the hidden
8115 `this pointer'. The debugger should be able to figure out (without
8116 being explicitly told) that this non-static member function type takes a
8117 `this pointer' and should be able to figure what the type of that hidden
8118 parameter is from the DW_AT_member attribute of the parent
8119 DW_TAG_subroutine_type DIE. */
8120 if (TREE_CODE (function_or_method_type) == METHOD_TYPE)
8121 first_parm_type = TREE_CHAIN (first_parm_type);
8122 #endif
8124 /* Make our first pass over the list of formal parameter types and output a
8125 DW_TAG_formal_parameter DIE for each one. */
8126 for (link = first_parm_type; link; link = TREE_CHAIN (link))
8128 register dw_die_ref parm_die;
8130 formal_type = TREE_VALUE (link);
8131 if (formal_type == void_type_node)
8132 break;
8134 /* Output a (nameless) DIE to represent the formal parameter itself. */
8135 parm_die = gen_formal_parameter_die (formal_type, context_die);
8136 if (TREE_CODE (function_or_method_type) == METHOD_TYPE
8137 && link == first_parm_type)
8138 add_AT_flag (parm_die, DW_AT_artificial, 1);
8141 /* If this function type has an ellipsis, add a
8142 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
8143 if (formal_type != void_type_node)
8144 gen_unspecified_parameters_die (function_or_method_type, context_die);
8146 /* Make our second (and final) pass over the list of formal parameter types
8147 and output DIEs to represent those types (as necessary). */
8148 for (link = TYPE_ARG_TYPES (function_or_method_type);
8149 link;
8150 link = TREE_CHAIN (link))
8152 formal_type = TREE_VALUE (link);
8153 if (formal_type == void_type_node)
8154 break;
8156 gen_type_die (formal_type, context_die);
8160 /* Generate a DIE to represent a declared function (either file-scope or
8161 block-local). */
8163 static void
8164 gen_subprogram_die (decl, context_die)
8165 register tree decl;
8166 register dw_die_ref context_die;
8168 char label_id[MAX_ARTIFICIAL_LABEL_BYTES];
8169 register tree origin = decl_ultimate_origin (decl);
8170 register dw_die_ref subr_die;
8171 register rtx fp_reg;
8172 register tree fn_arg_types;
8173 register tree outer_scope;
8174 register dw_die_ref old_die = lookup_decl_die (decl);
8175 register int declaration
8176 = (current_function_decl != decl
8177 || (context_die
8178 && (context_die->die_tag == DW_TAG_structure_type
8179 || context_die->die_tag == DW_TAG_union_type)));
8181 if (origin != NULL)
8183 subr_die = new_die (DW_TAG_subprogram, context_die);
8184 add_abstract_origin_attribute (subr_die, origin);
8186 else if (old_die && DECL_ABSTRACT (decl)
8187 && get_AT_unsigned (old_die, DW_AT_inline))
8189 /* This must be a redefinition of an extern inline function.
8190 We can just reuse the old die here. */
8191 subr_die = old_die;
8193 /* Clear out the inlined attribute and parm types. */
8194 remove_AT (subr_die, DW_AT_inline);
8195 remove_children (subr_die);
8197 else if (old_die)
8199 register unsigned file_index
8200 = lookup_filename (DECL_SOURCE_FILE (decl));
8202 if (get_AT_flag (old_die, DW_AT_declaration) != 1)
8204 /* ??? This can happen if there is a bug in the program, for
8205 instance, if it has duplicate function definitions. Ideally,
8206 we should detect this case and ignore it. For now, if we have
8207 already reported an error, any error at all, then assume that
8208 we got here because of a input error, not a dwarf2 bug. */
8209 if (errorcount)
8210 return;
8211 abort ();
8214 /* If the definition comes from the same place as the declaration,
8215 maybe use the old DIE. We always want the DIE for this function
8216 that has the *_pc attributes to be under comp_unit_die so the
8217 debugger can find it. For inlines, that is the concrete instance,
8218 so we can use the old DIE here. For non-inline methods, we want a
8219 specification DIE at toplevel, so we need a new DIE. For local
8220 class methods, this does not apply. */
8221 if ((DECL_ABSTRACT (decl) || old_die->die_parent == comp_unit_die
8222 || context_die == NULL)
8223 && get_AT_unsigned (old_die, DW_AT_decl_file) == file_index
8224 && (get_AT_unsigned (old_die, DW_AT_decl_line)
8225 == (unsigned)DECL_SOURCE_LINE (decl)))
8227 subr_die = old_die;
8229 /* Clear out the declaration attribute and the parm types. */
8230 remove_AT (subr_die, DW_AT_declaration);
8231 remove_children (subr_die);
8233 else
8235 subr_die = new_die (DW_TAG_subprogram, context_die);
8236 add_AT_die_ref (subr_die, DW_AT_specification, old_die);
8237 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8238 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index);
8239 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8240 != (unsigned)DECL_SOURCE_LINE (decl))
8241 add_AT_unsigned
8242 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
8245 else
8247 register dw_die_ref scope_die;
8249 if (DECL_CONTEXT (decl))
8250 scope_die = scope_die_for (decl, context_die);
8251 else
8252 /* Don't put block extern declarations under comp_unit_die. */
8253 scope_die = context_die;
8255 subr_die = new_die (DW_TAG_subprogram, scope_die);
8257 if (TREE_PUBLIC (decl))
8258 add_AT_flag (subr_die, DW_AT_external, 1);
8260 add_name_and_src_coords_attributes (subr_die, decl);
8261 if (debug_info_level > DINFO_LEVEL_TERSE)
8263 register tree type = TREE_TYPE (decl);
8265 add_prototyped_attribute (subr_die, type);
8266 add_type_attribute (subr_die, TREE_TYPE (type), 0, 0, context_die);
8269 add_pure_or_virtual_attribute (subr_die, decl);
8270 if (DECL_ARTIFICIAL (decl))
8271 add_AT_flag (subr_die, DW_AT_artificial, 1);
8272 if (TREE_PROTECTED (decl))
8273 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected);
8274 else if (TREE_PRIVATE (decl))
8275 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private);
8278 if (declaration)
8280 add_AT_flag (subr_die, DW_AT_declaration, 1);
8282 /* The first time we see a member function, it is in the context of
8283 the class to which it belongs. We make sure of this by emitting
8284 the class first. The next time is the definition, which is
8285 handled above. The two may come from the same source text. */
8286 if (DECL_CONTEXT (decl))
8287 equate_decl_number_to_die (decl, subr_die);
8289 else if (DECL_ABSTRACT (decl))
8291 /* ??? Checking DECL_DEFER_OUTPUT is correct for static inline functions,
8292 but not for extern inline functions. We can't get this completely
8293 correct because information about whether the function was declared
8294 inline is not saved anywhere. */
8295 if (DECL_DEFER_OUTPUT (decl))
8297 if (DECL_INLINE (decl) && !flag_no_inline)
8298 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined);
8299 else
8300 add_AT_unsigned (subr_die, DW_AT_inline,
8301 DW_INL_declared_not_inlined);
8303 else if (DECL_INLINE (decl) && !flag_no_inline)
8304 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined);
8305 else
8306 abort ();
8308 equate_decl_number_to_die (decl, subr_die);
8310 else if (!DECL_EXTERNAL (decl))
8312 if (origin == NULL_TREE)
8313 equate_decl_number_to_die (decl, subr_die);
8315 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL,
8316 current_funcdef_number);
8317 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id);
8318 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL,
8319 current_funcdef_number);
8320 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id);
8322 add_pubname (decl, subr_die);
8323 add_arange (decl, subr_die);
8325 #ifdef MIPS_DEBUGGING_INFO
8326 /* Add a reference to the FDE for this routine. */
8327 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde);
8328 #endif
8330 /* Define the "frame base" location for this routine. We use the
8331 frame pointer or stack pointer registers, since the RTL for local
8332 variables is relative to one of them. */
8333 fp_reg
8334 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx;
8335 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg));
8337 #if 0
8338 /* ??? This fails for nested inline functions, because context_display
8339 is not part of the state saved/restored for inline functions. */
8340 if (current_function_needs_context)
8341 add_AT_location_description (subr_die, DW_AT_static_link,
8342 lookup_static_chain (decl));
8343 #endif
8346 /* Now output descriptions of the arguments for this function. This gets
8347 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
8348 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
8349 `...' at the end of the formal parameter list. In order to find out if
8350 there was a trailing ellipsis or not, we must instead look at the type
8351 associated with the FUNCTION_DECL. This will be a node of type
8352 FUNCTION_TYPE. If the chain of type nodes hanging off of this
8353 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
8354 an ellipsis at the end. */
8355 push_decl_scope (decl);
8357 /* In the case where we are describing a mere function declaration, all we
8358 need to do here (and all we *can* do here) is to describe the *types* of
8359 its formal parameters. */
8360 if (debug_info_level <= DINFO_LEVEL_TERSE)
8362 else if (declaration)
8363 gen_formal_types_die (TREE_TYPE (decl), subr_die);
8364 else
8366 /* Generate DIEs to represent all known formal parameters */
8367 register tree arg_decls = DECL_ARGUMENTS (decl);
8368 register tree parm;
8370 /* When generating DIEs, generate the unspecified_parameters DIE
8371 instead if we come across the arg "__builtin_va_alist" */
8372 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
8373 if (TREE_CODE (parm) == PARM_DECL)
8375 if (DECL_NAME (parm)
8376 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
8377 "__builtin_va_alist"))
8378 gen_unspecified_parameters_die (parm, subr_die);
8379 else
8380 gen_decl_die (parm, subr_die);
8383 /* Decide whether we need a unspecified_parameters DIE at the end.
8384 There are 2 more cases to do this for: 1) the ansi ... declaration -
8385 this is detectable when the end of the arg list is not a
8386 void_type_node 2) an unprototyped function declaration (not a
8387 definition). This just means that we have no info about the
8388 parameters at all. */
8389 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
8390 if (fn_arg_types != NULL)
8392 /* this is the prototyped case, check for ... */
8393 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
8394 gen_unspecified_parameters_die (decl, subr_die);
8396 else if (DECL_INITIAL (decl) == NULL_TREE)
8397 gen_unspecified_parameters_die (decl, subr_die);
8400 /* Output Dwarf info for all of the stuff within the body of the function
8401 (if it has one - it may be just a declaration). */
8402 outer_scope = DECL_INITIAL (decl);
8404 /* Note that here, `outer_scope' is a pointer to the outermost BLOCK
8405 node created to represent a function. This outermost BLOCK actually
8406 represents the outermost binding contour for the function, i.e. the
8407 contour in which the function's formal parameters and labels get
8408 declared. Curiously, it appears that the front end doesn't actually
8409 put the PARM_DECL nodes for the current function onto the BLOCK_VARS
8410 list for this outer scope. (They are strung off of the DECL_ARGUMENTS
8411 list for the function instead.) The BLOCK_VARS list for the
8412 `outer_scope' does provide us with a list of the LABEL_DECL nodes for
8413 the function however, and we output DWARF info for those in
8414 decls_for_scope. Just within the `outer_scope' there will be a BLOCK
8415 node representing the function's outermost pair of curly braces, and
8416 any blocks used for the base and member initializers of a C++
8417 constructor function. */
8418 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK)
8420 current_function_has_inlines = 0;
8421 decls_for_scope (outer_scope, subr_die, 0);
8423 #if 0 && defined (MIPS_DEBUGGING_INFO)
8424 if (current_function_has_inlines)
8426 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1);
8427 if (! comp_unit_has_inlines)
8429 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1);
8430 comp_unit_has_inlines = 1;
8433 #endif
8436 pop_decl_scope ();
8439 /* Generate a DIE to represent a declared data object. */
8441 static void
8442 gen_variable_die (decl, context_die)
8443 register tree decl;
8444 register dw_die_ref context_die;
8446 register tree origin = decl_ultimate_origin (decl);
8447 register dw_die_ref var_die = new_die (DW_TAG_variable, context_die);
8449 dw_die_ref old_die = lookup_decl_die (decl);
8450 int declaration
8451 = (DECL_EXTERNAL (decl)
8452 || current_function_decl != decl_function_context (decl)
8453 || context_die->die_tag == DW_TAG_structure_type
8454 || context_die->die_tag == DW_TAG_union_type);
8456 if (origin != NULL)
8457 add_abstract_origin_attribute (var_die, origin);
8458 /* Loop unrolling can create multiple blocks that refer to the same
8459 static variable, so we must test for the DW_AT_declaration flag. */
8460 /* ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
8461 copy decls and set the DECL_ABSTRACT flag on them instead of
8462 sharing them. */
8463 else if (old_die && TREE_STATIC (decl)
8464 && get_AT_flag (old_die, DW_AT_declaration) == 1)
8466 /* This is a definition of a C++ class level static. */
8467 add_AT_die_ref (var_die, DW_AT_specification, old_die);
8468 if (DECL_NAME (decl))
8470 register unsigned file_index
8471 = lookup_filename (DECL_SOURCE_FILE (decl));
8473 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
8474 add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
8476 if (get_AT_unsigned (old_die, DW_AT_decl_line)
8477 != (unsigned)DECL_SOURCE_LINE (decl))
8479 add_AT_unsigned (var_die, DW_AT_decl_line,
8480 DECL_SOURCE_LINE (decl));
8483 else
8485 add_name_and_src_coords_attributes (var_die, decl);
8486 add_type_attribute (var_die, TREE_TYPE (decl),
8487 TREE_READONLY (decl),
8488 TREE_THIS_VOLATILE (decl), context_die);
8490 if (TREE_PUBLIC (decl))
8491 add_AT_flag (var_die, DW_AT_external, 1);
8493 if (DECL_ARTIFICIAL (decl))
8494 add_AT_flag (var_die, DW_AT_artificial, 1);
8496 if (TREE_PROTECTED (decl))
8497 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected);
8499 else if (TREE_PRIVATE (decl))
8500 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private);
8503 if (declaration)
8504 add_AT_flag (var_die, DW_AT_declaration, 1);
8506 if ((declaration && decl_class_context (decl)) || DECL_ABSTRACT (decl))
8507 equate_decl_number_to_die (decl, var_die);
8509 if (! declaration && ! DECL_ABSTRACT (decl))
8511 equate_decl_number_to_die (decl, var_die);
8512 add_location_or_const_value_attribute (var_die, decl);
8513 add_pubname (decl, var_die);
8517 /* Generate a DIE to represent a label identifier. */
8519 static void
8520 gen_label_die (decl, context_die)
8521 register tree decl;
8522 register dw_die_ref context_die;
8524 register tree origin = decl_ultimate_origin (decl);
8525 register dw_die_ref lbl_die = new_die (DW_TAG_label, context_die);
8526 register rtx insn;
8527 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8528 char label2[MAX_ARTIFICIAL_LABEL_BYTES];
8530 if (origin != NULL)
8531 add_abstract_origin_attribute (lbl_die, origin);
8532 else
8533 add_name_and_src_coords_attributes (lbl_die, decl);
8535 if (DECL_ABSTRACT (decl))
8536 equate_decl_number_to_die (decl, lbl_die);
8537 else
8539 insn = DECL_RTL (decl);
8541 /* Deleted labels are programmer specified labels which have been
8542 eliminated because of various optimisations. We still emit them
8543 here so that it is possible to put breakpoints on them. */
8544 if (GET_CODE (insn) == CODE_LABEL
8545 || ((GET_CODE (insn) == NOTE
8546 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL)))
8548 /* When optimization is enabled (via -O) some parts of the compiler
8549 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
8550 represent source-level labels which were explicitly declared by
8551 the user. This really shouldn't be happening though, so catch
8552 it if it ever does happen. */
8553 if (INSN_DELETED_P (insn))
8554 abort ();
8556 sprintf (label2, INSN_LABEL_FMT, current_funcdef_number);
8557 ASM_GENERATE_INTERNAL_LABEL (label, label2,
8558 (unsigned) INSN_UID (insn));
8559 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label);
8564 /* Generate a DIE for a lexical block. */
8566 static void
8567 gen_lexical_block_die (stmt, context_die, depth)
8568 register tree stmt;
8569 register dw_die_ref context_die;
8570 int depth;
8572 register dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die);
8573 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8575 if (! BLOCK_ABSTRACT (stmt))
8577 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8578 next_block_number);
8579 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label);
8580 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8581 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label);
8584 push_decl_scope (stmt);
8585 decls_for_scope (stmt, stmt_die, depth);
8586 pop_decl_scope ();
8589 /* Generate a DIE for an inlined subprogram. */
8591 static void
8592 gen_inlined_subroutine_die (stmt, context_die, depth)
8593 register tree stmt;
8594 register dw_die_ref context_die;
8595 int depth;
8597 if (! BLOCK_ABSTRACT (stmt))
8599 register dw_die_ref subr_die
8600 = new_die (DW_TAG_inlined_subroutine, context_die);
8601 register tree decl = block_ultimate_origin (stmt);
8602 char label[MAX_ARTIFICIAL_LABEL_BYTES];
8604 add_abstract_origin_attribute (subr_die, decl);
8605 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL,
8606 next_block_number);
8607 add_AT_lbl_id (subr_die, DW_AT_low_pc, label);
8608 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, next_block_number);
8609 add_AT_lbl_id (subr_die, DW_AT_high_pc, label);
8610 push_decl_scope (decl);
8611 decls_for_scope (stmt, subr_die, depth);
8612 pop_decl_scope ();
8613 current_function_has_inlines = 1;
8617 /* Generate a DIE for a field in a record, or structure. */
8619 static void
8620 gen_field_die (decl, context_die)
8621 register tree decl;
8622 register dw_die_ref context_die;
8624 register dw_die_ref decl_die = new_die (DW_TAG_member, context_die);
8626 add_name_and_src_coords_attributes (decl_die, decl);
8627 add_type_attribute (decl_die, member_declared_type (decl),
8628 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl),
8629 context_die);
8631 /* If this is a bit field... */
8632 if (DECL_BIT_FIELD_TYPE (decl))
8634 add_byte_size_attribute (decl_die, decl);
8635 add_bit_size_attribute (decl_die, decl);
8636 add_bit_offset_attribute (decl_die, decl);
8639 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE)
8640 add_data_member_location_attribute (decl_die, decl);
8642 if (DECL_ARTIFICIAL (decl))
8643 add_AT_flag (decl_die, DW_AT_artificial, 1);
8645 if (TREE_PROTECTED (decl))
8646 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected);
8648 else if (TREE_PRIVATE (decl))
8649 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private);
8652 #if 0
8653 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8654 Use modified_type_die instead.
8655 We keep this code here just in case these types of DIEs may be needed to
8656 represent certain things in other languages (e.g. Pascal) someday. */
8657 static void
8658 gen_pointer_type_die (type, context_die)
8659 register tree type;
8660 register dw_die_ref context_die;
8662 register dw_die_ref ptr_die
8663 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die));
8665 equate_type_number_to_die (type, ptr_die);
8666 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8667 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8670 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
8671 Use modified_type_die instead.
8672 We keep this code here just in case these types of DIEs may be needed to
8673 represent certain things in other languages (e.g. Pascal) someday. */
8674 static void
8675 gen_reference_type_die (type, context_die)
8676 register tree type;
8677 register dw_die_ref context_die;
8679 register dw_die_ref ref_die
8680 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die));
8682 equate_type_number_to_die (type, ref_die);
8683 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die);
8684 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE);
8686 #endif
8688 /* Generate a DIE for a pointer to a member type. */
8689 static void
8690 gen_ptr_to_mbr_type_die (type, context_die)
8691 register tree type;
8692 register dw_die_ref context_die;
8694 register dw_die_ref ptr_die
8695 = new_die (DW_TAG_ptr_to_member_type, scope_die_for (type, context_die));
8697 equate_type_number_to_die (type, ptr_die);
8698 add_AT_die_ref (ptr_die, DW_AT_containing_type,
8699 lookup_type_die (TYPE_OFFSET_BASETYPE (type)));
8700 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die);
8703 /* Generate the DIE for the compilation unit. */
8705 static void
8706 gen_compile_unit_die (main_input_filename)
8707 register char *main_input_filename;
8709 char producer[250];
8710 char *wd = getpwd ();
8712 comp_unit_die = new_die (DW_TAG_compile_unit, NULL);
8713 add_name_attribute (comp_unit_die, main_input_filename);
8715 if (wd != NULL)
8716 add_AT_string (comp_unit_die, DW_AT_comp_dir, wd);
8718 sprintf (producer, "%s %s", language_string, version_string);
8720 #ifdef MIPS_DEBUGGING_INFO
8721 /* The MIPS/SGI compilers place the 'cc' command line options in the producer
8722 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do
8723 not appear in the producer string, the debugger reaches the conclusion
8724 that the object file is stripped and has no debugging information.
8725 To get the MIPS/SGI debugger to believe that there is debugging
8726 information in the object file, we add a -g to the producer string. */
8727 if (debug_info_level > DINFO_LEVEL_TERSE)
8728 strcat (producer, " -g");
8729 #endif
8731 add_AT_string (comp_unit_die, DW_AT_producer, producer);
8733 if (strcmp (language_string, "GNU C++") == 0)
8734 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C_plus_plus);
8736 else if (strcmp (language_string, "GNU Ada") == 0)
8737 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Ada83);
8739 else if (strcmp (language_string, "GNU F77") == 0)
8740 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Fortran77);
8742 else if (strcmp (language_string, "GNU Pascal") == 0)
8743 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_Pascal83);
8745 else if (flag_traditional)
8746 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C);
8748 else
8749 add_AT_unsigned (comp_unit_die, DW_AT_language, DW_LANG_C89);
8751 #if 0 /* unimplemented */
8752 if (debug_info_level >= DINFO_LEVEL_VERBOSE)
8753 add_AT_unsigned (comp_unit_die, DW_AT_macro_info, 0);
8754 #endif
8757 /* Generate a DIE for a string type. */
8759 static void
8760 gen_string_type_die (type, context_die)
8761 register tree type;
8762 register dw_die_ref context_die;
8764 register dw_die_ref type_die
8765 = new_die (DW_TAG_string_type, scope_die_for (type, context_die));
8767 equate_type_number_to_die (type, type_die);
8769 /* Fudge the string length attribute for now. */
8771 /* TODO: add string length info.
8772 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
8773 bound_representation (upper_bound, 0, 'u'); */
8776 /* Generate the DIE for a base class. */
8778 static void
8779 gen_inheritance_die (binfo, context_die)
8780 register tree binfo;
8781 register dw_die_ref context_die;
8783 dw_die_ref die = new_die (DW_TAG_inheritance, context_die);
8785 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die);
8786 add_data_member_location_attribute (die, binfo);
8788 if (TREE_VIA_VIRTUAL (binfo))
8789 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual);
8790 if (TREE_VIA_PUBLIC (binfo))
8791 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public);
8792 else if (TREE_VIA_PROTECTED (binfo))
8793 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected);
8796 /* Generate a DIE for a class member. */
8798 static void
8799 gen_member_die (type, context_die)
8800 register tree type;
8801 register dw_die_ref context_die;
8803 register tree member;
8805 /* If this is not an incomplete type, output descriptions of each of its
8806 members. Note that as we output the DIEs necessary to represent the
8807 members of this record or union type, we will also be trying to output
8808 DIEs to represent the *types* of those members. However the `type'
8809 function (above) will specifically avoid generating type DIEs for member
8810 types *within* the list of member DIEs for this (containing) type execpt
8811 for those types (of members) which are explicitly marked as also being
8812 members of this (containing) type themselves. The g++ front- end can
8813 force any given type to be treated as a member of some other
8814 (containing) type by setting the TYPE_CONTEXT of the given (member) type
8815 to point to the TREE node representing the appropriate (containing)
8816 type. */
8818 /* First output info about the base classes. */
8819 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type))
8821 register tree bases = TYPE_BINFO_BASETYPES (type);
8822 register int n_bases = TREE_VEC_LENGTH (bases);
8823 register int i;
8825 for (i = 0; i < n_bases; i++)
8826 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die);
8829 /* Now output info about the data members and type members. */
8830 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member))
8831 gen_decl_die (member, context_die);
8833 /* Now output info about the function members (if any). */
8834 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member))
8835 gen_decl_die (member, context_die);
8838 /* Generate a DIE for a structure or union type. */
8840 static void
8841 gen_struct_or_union_type_die (type, context_die)
8842 register tree type;
8843 register dw_die_ref context_die;
8845 register dw_die_ref type_die = lookup_type_die (type);
8846 register dw_die_ref scope_die = 0;
8847 register int nested = 0;
8849 if (type_die && ! TYPE_SIZE (type))
8850 return;
8852 if (TYPE_CONTEXT (type) != NULL_TREE
8853 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)))
8854 nested = 1;
8856 scope_die = scope_die_for (type, context_die);
8858 if (! type_die || (nested && scope_die == comp_unit_die))
8859 /* First occurrence of type or toplevel definition of nested class. */
8861 register dw_die_ref old_die = type_die;
8863 type_die = new_die (TREE_CODE (type) == RECORD_TYPE
8864 ? DW_TAG_structure_type : DW_TAG_union_type,
8865 scope_die);
8866 equate_type_number_to_die (type, type_die);
8867 add_name_attribute (type_die, type_tag (type));
8868 if (old_die)
8869 add_AT_die_ref (type_die, DW_AT_specification, old_die);
8871 else
8872 remove_AT (type_die, DW_AT_declaration);
8874 /* If we're not in the right context to be defining this type, defer to
8875 avoid tricky recursion. */
8876 if (TYPE_SIZE (type) && decl_scope_depth > 0 && scope_die == comp_unit_die)
8878 add_AT_flag (type_die, DW_AT_declaration, 1);
8879 pend_type (type);
8881 /* If this type has been completed, then give it a byte_size attribute and
8882 then give a list of members. */
8883 else if (TYPE_SIZE (type))
8885 /* Prevent infinite recursion in cases where the type of some member of
8886 this type is expressed in terms of this type itself. */
8887 TREE_ASM_WRITTEN (type) = 1;
8888 add_byte_size_attribute (type_die, type);
8889 if (TYPE_STUB_DECL (type) != NULL_TREE)
8890 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type));
8892 /* If the first reference to this type was as the return type of an
8893 inline function, then it may not have a parent. Fix this now. */
8894 if (type_die->die_parent == NULL)
8895 add_child_die (scope_die, type_die);
8897 push_decl_scope (type);
8898 gen_member_die (type, type_die);
8899 pop_decl_scope ();
8901 /* GNU extension: Record what type our vtable lives in. */
8902 if (TYPE_VFIELD (type))
8904 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type));
8906 gen_type_die (vtype, context_die);
8907 add_AT_die_ref (type_die, DW_AT_containing_type,
8908 lookup_type_die (vtype));
8911 else
8913 add_AT_flag (type_die, DW_AT_declaration, 1);
8915 /* We can't do this for function-local types, and we don't need to. */
8916 if (TREE_PERMANENT (type))
8917 add_incomplete_type (type);
8921 /* Generate a DIE for a subroutine _type_. */
8923 static void
8924 gen_subroutine_type_die (type, context_die)
8925 register tree type;
8926 register dw_die_ref context_die;
8928 register tree return_type = TREE_TYPE (type);
8929 register dw_die_ref subr_die
8930 = new_die (DW_TAG_subroutine_type, scope_die_for (type, context_die));
8932 equate_type_number_to_die (type, subr_die);
8933 add_prototyped_attribute (subr_die, type);
8934 add_type_attribute (subr_die, return_type, 0, 0, context_die);
8935 gen_formal_types_die (type, subr_die);
8938 /* Generate a DIE for a type definition */
8940 static void
8941 gen_typedef_die (decl, context_die)
8942 register tree decl;
8943 register dw_die_ref context_die;
8945 register dw_die_ref type_die;
8946 register tree origin;
8948 if (TREE_ASM_WRITTEN (decl))
8949 return;
8950 TREE_ASM_WRITTEN (decl) = 1;
8952 type_die = new_die (DW_TAG_typedef, scope_die_for (decl, context_die));
8953 origin = decl_ultimate_origin (decl);
8954 if (origin != NULL)
8955 add_abstract_origin_attribute (type_die, origin);
8956 else
8958 register tree type;
8959 add_name_and_src_coords_attributes (type_die, decl);
8960 if (DECL_ORIGINAL_TYPE (decl))
8962 type = DECL_ORIGINAL_TYPE (decl);
8963 equate_type_number_to_die (TREE_TYPE (decl), type_die);
8965 else
8966 type = TREE_TYPE (decl);
8967 add_type_attribute (type_die, type, TREE_READONLY (decl),
8968 TREE_THIS_VOLATILE (decl), context_die);
8971 if (DECL_ABSTRACT (decl))
8972 equate_decl_number_to_die (decl, type_die);
8975 /* Generate a type description DIE. */
8977 static void
8978 gen_type_die (type, context_die)
8979 register tree type;
8980 register dw_die_ref context_die;
8982 if (type == NULL_TREE || type == error_mark_node)
8983 return;
8985 /* We are going to output a DIE to represent the unqualified version of
8986 this type (i.e. without any const or volatile qualifiers) so get the
8987 main variant (i.e. the unqualified version) of this type now. */
8988 type = type_main_variant (type);
8990 if (TREE_ASM_WRITTEN (type))
8991 return;
8993 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
8994 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
8996 TREE_ASM_WRITTEN (type) = 1;
8997 gen_decl_die (TYPE_NAME (type), context_die);
8998 return;
9001 switch (TREE_CODE (type))
9003 case ERROR_MARK:
9004 break;
9006 case POINTER_TYPE:
9007 case REFERENCE_TYPE:
9008 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
9009 ensures that the gen_type_die recursion will terminate even if the
9010 type is recursive. Recursive types are possible in Ada. */
9011 /* ??? We could perhaps do this for all types before the switch
9012 statement. */
9013 TREE_ASM_WRITTEN (type) = 1;
9015 /* For these types, all that is required is that we output a DIE (or a
9016 set of DIEs) to represent the "basis" type. */
9017 gen_type_die (TREE_TYPE (type), context_die);
9018 break;
9020 case OFFSET_TYPE:
9021 /* This code is used for C++ pointer-to-data-member types.
9022 Output a description of the relevant class type. */
9023 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die);
9025 /* Output a description of the type of the object pointed to. */
9026 gen_type_die (TREE_TYPE (type), context_die);
9028 /* Now output a DIE to represent this pointer-to-data-member type
9029 itself. */
9030 gen_ptr_to_mbr_type_die (type, context_die);
9031 break;
9033 case SET_TYPE:
9034 gen_type_die (TYPE_DOMAIN (type), context_die);
9035 gen_set_type_die (type, context_die);
9036 break;
9038 case FILE_TYPE:
9039 gen_type_die (TREE_TYPE (type), context_die);
9040 abort (); /* No way to represent these in Dwarf yet! */
9041 break;
9043 case FUNCTION_TYPE:
9044 /* Force out return type (in case it wasn't forced out already). */
9045 gen_type_die (TREE_TYPE (type), context_die);
9046 gen_subroutine_type_die (type, context_die);
9047 break;
9049 case METHOD_TYPE:
9050 /* Force out return type (in case it wasn't forced out already). */
9051 gen_type_die (TREE_TYPE (type), context_die);
9052 gen_subroutine_type_die (type, context_die);
9053 break;
9055 case ARRAY_TYPE:
9056 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE)
9058 gen_type_die (TREE_TYPE (type), context_die);
9059 gen_string_type_die (type, context_die);
9061 else
9062 gen_array_type_die (type, context_die);
9063 break;
9065 case ENUMERAL_TYPE:
9066 case RECORD_TYPE:
9067 case UNION_TYPE:
9068 case QUAL_UNION_TYPE:
9069 /* If this is a nested type whose containing class hasn't been
9070 written out yet, writing it out will cover this one, too. */
9071 if (TYPE_CONTEXT (type)
9072 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9073 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9075 gen_type_die (TYPE_CONTEXT (type), context_die);
9077 if (TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9078 return;
9080 /* If that failed, attach ourselves to the stub. */
9081 push_decl_scope (TYPE_CONTEXT (type));
9082 context_die = lookup_type_die (TYPE_CONTEXT (type));
9085 if (TREE_CODE (type) == ENUMERAL_TYPE)
9086 gen_enumeration_type_die (type, context_die);
9087 else
9088 gen_struct_or_union_type_die (type, context_die);
9090 if (TYPE_CONTEXT (type)
9091 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))
9092 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))
9093 pop_decl_scope ();
9095 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
9096 it up if it is ever completed. gen_*_type_die will set it for us
9097 when appropriate. */
9098 return;
9100 case VOID_TYPE:
9101 case INTEGER_TYPE:
9102 case REAL_TYPE:
9103 case COMPLEX_TYPE:
9104 case BOOLEAN_TYPE:
9105 case CHAR_TYPE:
9106 /* No DIEs needed for fundamental types. */
9107 break;
9109 case LANG_TYPE:
9110 /* No Dwarf representation currently defined. */
9111 break;
9113 default:
9114 abort ();
9117 TREE_ASM_WRITTEN (type) = 1;
9120 /* Generate a DIE for a tagged type instantiation. */
9122 static void
9123 gen_tagged_type_instantiation_die (type, context_die)
9124 register tree type;
9125 register dw_die_ref context_die;
9127 if (type == NULL_TREE || type == error_mark_node)
9128 return;
9130 /* We are going to output a DIE to represent the unqualified version of
9131 this type (i.e. without any const or volatile qualifiers) so make sure
9132 that we have the main variant (i.e. the unqualified version) of this
9133 type now. */
9134 if (type != type_main_variant (type))
9135 abort ();
9137 /* Do not check TREE_ASM_WRITTEN(type) as it may not be set if this is
9138 an instance of an unresolved type. */
9140 switch (TREE_CODE (type))
9142 case ERROR_MARK:
9143 break;
9145 case ENUMERAL_TYPE:
9146 gen_inlined_enumeration_type_die (type, context_die);
9147 break;
9149 case RECORD_TYPE:
9150 gen_inlined_structure_type_die (type, context_die);
9151 break;
9153 case UNION_TYPE:
9154 case QUAL_UNION_TYPE:
9155 gen_inlined_union_type_die (type, context_die);
9156 break;
9158 default:
9159 abort ();
9163 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
9164 things which are local to the given block. */
9166 static void
9167 gen_block_die (stmt, context_die, depth)
9168 register tree stmt;
9169 register dw_die_ref context_die;
9170 int depth;
9172 register int must_output_die = 0;
9173 register tree origin;
9174 register tree decl;
9175 register enum tree_code origin_code;
9177 /* Ignore blocks never really used to make RTL. */
9179 if (stmt == NULL_TREE || !TREE_USED (stmt))
9180 return;
9182 /* Determine the "ultimate origin" of this block. This block may be an
9183 inlined instance of an inlined instance of inline function, so we have
9184 to trace all of the way back through the origin chain to find out what
9185 sort of node actually served as the original seed for the creation of
9186 the current block. */
9187 origin = block_ultimate_origin (stmt);
9188 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK;
9190 /* Determine if we need to output any Dwarf DIEs at all to represent this
9191 block. */
9192 if (origin_code == FUNCTION_DECL)
9193 /* The outer scopes for inlinings *must* always be represented. We
9194 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
9195 must_output_die = 1;
9196 else
9198 /* In the case where the current block represents an inlining of the
9199 "body block" of an inline function, we must *NOT* output any DIE for
9200 this block because we have already output a DIE to represent the
9201 whole inlined function scope and the "body block" of any function
9202 doesn't really represent a different scope according to ANSI C
9203 rules. So we check here to make sure that this block does not
9204 represent a "body block inlining" before trying to set the
9205 `must_output_die' flag. */
9206 if (! is_body_block (origin ? origin : stmt))
9208 /* Determine if this block directly contains any "significant"
9209 local declarations which we will need to output DIEs for. */
9210 if (debug_info_level > DINFO_LEVEL_TERSE)
9211 /* We are not in terse mode so *any* local declaration counts
9212 as being a "significant" one. */
9213 must_output_die = (BLOCK_VARS (stmt) != NULL);
9214 else
9215 /* We are in terse mode, so only local (nested) function
9216 definitions count as "significant" local declarations. */
9217 for (decl = BLOCK_VARS (stmt);
9218 decl != NULL; decl = TREE_CHAIN (decl))
9219 if (TREE_CODE (decl) == FUNCTION_DECL
9220 && DECL_INITIAL (decl))
9222 must_output_die = 1;
9223 break;
9228 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
9229 DIE for any block which contains no significant local declarations at
9230 all. Rather, in such cases we just call `decls_for_scope' so that any
9231 needed Dwarf info for any sub-blocks will get properly generated. Note
9232 that in terse mode, our definition of what constitutes a "significant"
9233 local declaration gets restricted to include only inlined function
9234 instances and local (nested) function definitions. */
9235 if (must_output_die)
9237 if (origin_code == FUNCTION_DECL)
9238 gen_inlined_subroutine_die (stmt, context_die, depth);
9239 else
9240 gen_lexical_block_die (stmt, context_die, depth);
9242 else
9243 decls_for_scope (stmt, context_die, depth);
9246 /* Generate all of the decls declared within a given scope and (recursively)
9247 all of its sub-blocks. */
9249 static void
9250 decls_for_scope (stmt, context_die, depth)
9251 register tree stmt;
9252 register dw_die_ref context_die;
9253 int depth;
9255 register tree decl;
9256 register tree subblocks;
9258 /* Ignore blocks never really used to make RTL. */
9259 if (stmt == NULL_TREE || ! TREE_USED (stmt))
9260 return;
9262 if (!BLOCK_ABSTRACT (stmt) && depth > 0)
9263 next_block_number++;
9265 /* Output the DIEs to represent all of the data objects and typedefs
9266 declared directly within this block but not within any nested
9267 sub-blocks. Also, nested function and tag DIEs have been
9268 generated with a parent of NULL; fix that up now. */
9269 for (decl = BLOCK_VARS (stmt);
9270 decl != NULL; decl = TREE_CHAIN (decl))
9272 register dw_die_ref die;
9274 if (TREE_CODE (decl) == FUNCTION_DECL)
9275 die = lookup_decl_die (decl);
9276 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))
9277 die = lookup_type_die (TREE_TYPE (decl));
9278 else
9279 die = NULL;
9281 if (die != NULL && die->die_parent == NULL)
9282 add_child_die (context_die, die);
9283 else
9284 gen_decl_die (decl, context_die);
9287 /* Output the DIEs to represent all sub-blocks (and the items declared
9288 therein) of this block. */
9289 for (subblocks = BLOCK_SUBBLOCKS (stmt);
9290 subblocks != NULL;
9291 subblocks = BLOCK_CHAIN (subblocks))
9292 gen_block_die (subblocks, context_die, depth + 1);
9295 /* Is this a typedef we can avoid emitting? */
9297 static inline int
9298 is_redundant_typedef (decl)
9299 register tree decl;
9301 if (TYPE_DECL_IS_STUB (decl))
9302 return 1;
9304 if (DECL_ARTIFICIAL (decl)
9305 && DECL_CONTEXT (decl)
9306 && is_tagged_type (DECL_CONTEXT (decl))
9307 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL
9308 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl))))
9309 /* Also ignore the artificial member typedef for the class name. */
9310 return 1;
9312 return 0;
9315 /* Generate Dwarf debug information for a decl described by DECL. */
9317 static void
9318 gen_decl_die (decl, context_die)
9319 register tree decl;
9320 register dw_die_ref context_die;
9322 register tree origin;
9324 /* Make a note of the decl node we are going to be working on. We may need
9325 to give the user the source coordinates of where it appeared in case we
9326 notice (later on) that something about it looks screwy. */
9327 dwarf_last_decl = decl;
9329 if (TREE_CODE (decl) == ERROR_MARK)
9330 return;
9332 /* If this ..._DECL node is marked to be ignored, then ignore it. But don't
9333 ignore a function definition, since that would screw up our count of
9334 blocks, and that in turn will completely screw up the labels we will
9335 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9336 subsequent blocks). */
9337 if (DECL_IGNORED_P (decl) && TREE_CODE (decl) != FUNCTION_DECL)
9338 return;
9340 switch (TREE_CODE (decl))
9342 case CONST_DECL:
9343 /* The individual enumerators of an enum type get output when we output
9344 the Dwarf representation of the relevant enum type itself. */
9345 break;
9347 case FUNCTION_DECL:
9348 /* Don't output any DIEs to represent mere function declarations,
9349 unless they are class members or explicit block externs. */
9350 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE
9351 && (current_function_decl == NULL_TREE || ! DECL_ARTIFICIAL (decl)))
9352 break;
9354 if (debug_info_level > DINFO_LEVEL_TERSE)
9356 /* Before we describe the FUNCTION_DECL itself, make sure that we
9357 have described its return type. */
9358 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die);
9360 /* And its containing type. */
9361 origin = decl_class_context (decl);
9362 if (origin != NULL_TREE)
9363 gen_type_die (origin, context_die);
9365 /* And its virtual context. */
9366 if (DECL_VINDEX (decl) != NULL_TREE)
9367 gen_type_die (DECL_CONTEXT (decl), context_die);
9370 /* Now output a DIE to represent the function itself. */
9371 gen_subprogram_die (decl, context_die);
9372 break;
9374 case TYPE_DECL:
9375 /* If we are in terse mode, don't generate any DIEs to represent any
9376 actual typedefs. */
9377 if (debug_info_level <= DINFO_LEVEL_TERSE)
9378 break;
9380 /* In the special case of a TYPE_DECL node representing the
9381 declaration of some type tag, if the given TYPE_DECL is marked as
9382 having been instantiated from some other (original) TYPE_DECL node
9383 (e.g. one which was generated within the original definition of an
9384 inline function) we have to generate a special (abbreviated)
9385 DW_TAG_structure_type, DW_TAG_union_type, or DW_TAG_enumeration_type
9386 DIE here. */
9387 if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE)
9389 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die);
9390 break;
9393 if (is_redundant_typedef (decl))
9394 gen_type_die (TREE_TYPE (decl), context_die);
9395 else
9396 /* Output a DIE to represent the typedef itself. */
9397 gen_typedef_die (decl, context_die);
9398 break;
9400 case LABEL_DECL:
9401 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9402 gen_label_die (decl, context_die);
9403 break;
9405 case VAR_DECL:
9406 /* If we are in terse mode, don't generate any DIEs to represent any
9407 variable declarations or definitions. */
9408 if (debug_info_level <= DINFO_LEVEL_TERSE)
9409 break;
9411 /* Output any DIEs that are needed to specify the type of this data
9412 object. */
9413 gen_type_die (TREE_TYPE (decl), context_die);
9415 /* And its containing type. */
9416 origin = decl_class_context (decl);
9417 if (origin != NULL_TREE)
9418 gen_type_die (origin, context_die);
9420 /* Now output the DIE to represent the data object itself. This gets
9421 complicated because of the possibility that the VAR_DECL really
9422 represents an inlined instance of a formal parameter for an inline
9423 function. */
9424 origin = decl_ultimate_origin (decl);
9425 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL)
9426 gen_formal_parameter_die (decl, context_die);
9427 else
9428 gen_variable_die (decl, context_die);
9429 break;
9431 case FIELD_DECL:
9432 /* Ignore the nameless fields that are used to skip bits, but
9433 handle C++ anonymous unions. */
9434 if (DECL_NAME (decl) != NULL_TREE
9435 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE)
9437 gen_type_die (member_declared_type (decl), context_die);
9438 gen_field_die (decl, context_die);
9440 break;
9442 case PARM_DECL:
9443 gen_type_die (TREE_TYPE (decl), context_die);
9444 gen_formal_parameter_die (decl, context_die);
9445 break;
9447 default:
9448 abort ();
9452 /* Add Ada "use" clause information for SGI Workshop debugger. */
9454 void
9455 dwarf2out_add_library_unit_info (filename, context_list)
9456 char *filename;
9457 char *context_list;
9459 unsigned int file_index;
9461 if (filename != NULL)
9463 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die);
9464 tree context_list_decl
9465 = build_decl (LABEL_DECL, get_identifier (context_list),
9466 void_type_node);
9468 TREE_PUBLIC (context_list_decl) = TRUE;
9469 add_name_attribute (unit_die, context_list);
9470 file_index = lookup_filename (filename);
9471 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
9472 add_pubname (context_list_decl, unit_die);
9476 /* Write the debugging output for DECL. */
9478 void
9479 dwarf2out_decl (decl)
9480 register tree decl;
9482 register dw_die_ref context_die = comp_unit_die;
9484 if (TREE_CODE (decl) == ERROR_MARK)
9485 return;
9487 /* If this ..._DECL node is marked to be ignored, then ignore it. We gotta
9488 hope that the node in question doesn't represent a function definition.
9489 If it does, then totally ignoring it is bound to screw up our count of
9490 blocks, and that in turn will completely screw up the labels we will
9491 reference in subsequent DW_AT_low_pc and DW_AT_high_pc attributes (for
9492 subsequent blocks). (It's too bad that BLOCK nodes don't carry their
9493 own sequence numbers with them!) */
9494 if (DECL_IGNORED_P (decl))
9496 if (TREE_CODE (decl) == FUNCTION_DECL
9497 && DECL_INITIAL (decl) != NULL)
9498 abort ();
9500 return;
9503 switch (TREE_CODE (decl))
9505 case FUNCTION_DECL:
9506 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a
9507 builtin function. Explicit programmer-supplied declarations of
9508 these same functions should NOT be ignored however. */
9509 if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl))
9510 return;
9512 /* What we would really like to do here is to filter out all mere
9513 file-scope declarations of file-scope functions which are never
9514 referenced later within this translation unit (and keep all of ones
9515 that *are* referenced later on) but we aren't clairvoyant, so we have
9516 no idea which functions will be referenced in the future (i.e. later
9517 on within the current translation unit). So here we just ignore all
9518 file-scope function declarations which are not also definitions. If
9519 and when the debugger needs to know something about these functions,
9520 it will have to hunt around and find the DWARF information associated
9521 with the definition of the function. Note that we can't just check
9522 `DECL_EXTERNAL' to find out which FUNCTION_DECL nodes represent
9523 definitions and which ones represent mere declarations. We have to
9524 check `DECL_INITIAL' instead. That's because the C front-end
9525 supports some weird semantics for "extern inline" function
9526 definitions. These can get inlined within the current translation
9527 unit (an thus, we need to generate DWARF info for their abstract
9528 instances so that the DWARF info for the concrete inlined instances
9529 can have something to refer to) but the compiler never generates any
9530 out-of-lines instances of such things (despite the fact that they
9531 *are* definitions). The important point is that the C front-end
9532 marks these "extern inline" functions as DECL_EXTERNAL, but we need
9533 to generate DWARF for them anyway. Note that the C++ front-end also
9534 plays some similar games for inline function definitions appearing
9535 within include files which also contain
9536 `#pragma interface' pragmas. */
9537 if (DECL_INITIAL (decl) == NULL_TREE)
9538 return;
9540 /* If we're a nested function, initially use a parent of NULL; if we're
9541 a plain function, this will be fixed up in decls_for_scope. If
9542 we're a method, it will be ignored, since we already have a DIE. */
9543 if (decl_function_context (decl))
9544 context_die = NULL;
9546 break;
9548 case VAR_DECL:
9549 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
9550 declaration and if the declaration was never even referenced from
9551 within this entire compilation unit. We suppress these DIEs in
9552 order to save space in the .debug section (by eliminating entries
9553 which are probably useless). Note that we must not suppress
9554 block-local extern declarations (whether used or not) because that
9555 would screw-up the debugger's name lookup mechanism and cause it to
9556 miss things which really ought to be in scope at a given point. */
9557 if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
9558 return;
9560 /* If we are in terse mode, don't generate any DIEs to represent any
9561 variable declarations or definitions. */
9562 if (debug_info_level <= DINFO_LEVEL_TERSE)
9563 return;
9564 break;
9566 case TYPE_DECL:
9567 /* Don't bother trying to generate any DIEs to represent any of the
9568 normal built-in types for the language we are compiling. */
9569 if (DECL_SOURCE_LINE (decl) == 0)
9571 /* OK, we need to generate one for `bool' so GDB knows what type
9572 comparisons have. */
9573 if ((get_AT_unsigned (comp_unit_die, DW_AT_language)
9574 == DW_LANG_C_plus_plus)
9575 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE)
9576 modified_type_die (TREE_TYPE (decl), 0, 0, NULL);
9578 return;
9581 /* If we are in terse mode, don't generate any DIEs for types. */
9582 if (debug_info_level <= DINFO_LEVEL_TERSE)
9583 return;
9585 /* If we're a function-scope tag, initially use a parent of NULL;
9586 this will be fixed up in decls_for_scope. */
9587 if (decl_function_context (decl))
9588 context_die = NULL;
9590 break;
9592 default:
9593 return;
9596 gen_decl_die (decl, context_die);
9597 output_pending_types_for_scope (comp_unit_die);
9600 /* Output a marker (i.e. a label) for the beginning of the generated code for
9601 a lexical block. */
9603 void
9604 dwarf2out_begin_block (blocknum)
9605 register unsigned blocknum;
9607 function_section (current_function_decl);
9608 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum);
9611 /* Output a marker (i.e. a label) for the end of the generated code for a
9612 lexical block. */
9614 void
9615 dwarf2out_end_block (blocknum)
9616 register unsigned blocknum;
9618 function_section (current_function_decl);
9619 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum);
9622 /* Output a marker (i.e. a label) at a point in the assembly code which
9623 corresponds to a given source level label. */
9625 void
9626 dwarf2out_label (insn)
9627 register rtx insn;
9629 char label[MAX_ARTIFICIAL_LABEL_BYTES];
9631 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9633 function_section (current_function_decl);
9634 sprintf (label, INSN_LABEL_FMT, current_funcdef_number);
9635 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, label,
9636 (unsigned) INSN_UID (insn));
9640 /* Lookup a filename (in the list of filenames that we know about here in
9641 dwarf2out.c) and return its "index". The index of each (known) filename is
9642 just a unique number which is associated with only that one filename.
9643 We need such numbers for the sake of generating labels
9644 (in the .debug_sfnames section) and references to those
9645 files numbers (in the .debug_srcinfo and.debug_macinfo sections).
9646 If the filename given as an argument is not found in our current list,
9647 add it to the list and assign it the next available unique index number.
9648 In order to speed up searches, we remember the index of the filename
9649 was looked up last. This handles the majority of all searches. */
9651 static unsigned
9652 lookup_filename (file_name)
9653 const char *file_name;
9655 static unsigned last_file_lookup_index = 0;
9656 register unsigned i;
9658 /* Check to see if the file name that was searched on the previous call
9659 matches this file name. If so, return the index. */
9660 if (last_file_lookup_index != 0)
9661 if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
9662 return last_file_lookup_index;
9664 /* Didn't match the previous lookup, search the table */
9665 for (i = 1; i < file_table_in_use; ++i)
9666 if (strcmp (file_name, file_table[i]) == 0)
9668 last_file_lookup_index = i;
9669 return i;
9672 /* Prepare to add a new table entry by making sure there is enough space in
9673 the table to do so. If not, expand the current table. */
9674 if (file_table_in_use == file_table_allocated)
9676 file_table_allocated += FILE_TABLE_INCREMENT;
9677 file_table
9678 = (char **) xrealloc (file_table,
9679 file_table_allocated * sizeof (char *));
9682 /* Add the new entry to the end of the filename table. */
9683 file_table[file_table_in_use] = xstrdup (file_name);
9684 last_file_lookup_index = file_table_in_use++;
9686 return last_file_lookup_index;
9689 /* Output a label to mark the beginning of a source code line entry
9690 and record information relating to this source line, in
9691 'line_info_table' for later output of the .debug_line section. */
9693 void
9694 dwarf2out_line (filename, line)
9695 register const char *filename;
9696 register unsigned line;
9698 if (debug_info_level >= DINFO_LEVEL_NORMAL)
9700 function_section (current_function_decl);
9702 if (DWARF2_ASM_LINE_DEBUG_INFO)
9704 static const char *lastfile;
9706 /* Emit the .file and .loc directives understood by GNU as. */
9707 if (lastfile == 0 || strcmp (filename, lastfile))
9709 if (lastfile == 0)
9710 ggc_add_string_root ((char **) &lastfile, 1);
9712 fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
9713 lastfile = filename;
9716 fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
9718 /* Indicate that line number info exists. */
9719 ++line_info_table_in_use;
9721 /* Indicate that multiple line number tables exist. */
9722 if (DECL_SECTION_NAME (current_function_decl))
9723 ++separate_line_info_table_in_use;
9725 else if (DECL_SECTION_NAME (current_function_decl))
9727 register dw_separate_line_info_ref line_info;
9728 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL,
9729 separate_line_info_table_in_use);
9730 if (flag_debug_asm)
9731 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9732 fputc ('\n', asm_out_file);
9734 /* expand the line info table if necessary */
9735 if (separate_line_info_table_in_use
9736 == separate_line_info_table_allocated)
9738 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9739 separate_line_info_table
9740 = (dw_separate_line_info_ref)
9741 xrealloc (separate_line_info_table,
9742 separate_line_info_table_allocated
9743 * sizeof (dw_separate_line_info_entry));
9746 /* Add the new entry at the end of the line_info_table. */
9747 line_info
9748 = &separate_line_info_table[separate_line_info_table_in_use++];
9749 line_info->dw_file_num = lookup_filename (filename);
9750 line_info->dw_line_num = line;
9751 line_info->function = current_funcdef_number;
9753 else
9755 register dw_line_info_ref line_info;
9757 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL,
9758 line_info_table_in_use);
9759 if (flag_debug_asm)
9760 fprintf (asm_out_file, "\t%s line %d", ASM_COMMENT_START, line);
9761 fputc ('\n', asm_out_file);
9763 /* Expand the line info table if necessary. */
9764 if (line_info_table_in_use == line_info_table_allocated)
9766 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT;
9767 line_info_table
9768 = (dw_line_info_ref)
9769 xrealloc (line_info_table,
9770 (line_info_table_allocated
9771 * sizeof (dw_line_info_entry)));
9774 /* Add the new entry at the end of the line_info_table. */
9775 line_info = &line_info_table[line_info_table_in_use++];
9776 line_info->dw_file_num = lookup_filename (filename);
9777 line_info->dw_line_num = line;
9782 /* Record the beginning of a new source file, for later output
9783 of the .debug_macinfo section. At present, unimplemented. */
9785 void
9786 dwarf2out_start_source_file (filename)
9787 register const char *filename ATTRIBUTE_UNUSED;
9791 /* Record the end of a source file, for later output
9792 of the .debug_macinfo section. At present, unimplemented. */
9794 void
9795 dwarf2out_end_source_file ()
9799 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9800 the tail part of the directive line, i.e. the part which is past the
9801 initial whitespace, #, whitespace, directive-name, whitespace part. */
9803 void
9804 dwarf2out_define (lineno, buffer)
9805 register unsigned lineno ATTRIBUTE_UNUSED;
9806 register const char *buffer ATTRIBUTE_UNUSED;
9808 static int initialized = 0;
9809 if (!initialized)
9811 dwarf2out_start_source_file (primary_filename);
9812 initialized = 1;
9816 /* Called from check_newline in c-parse.y. The `buffer' parameter contains
9817 the tail part of the directive line, i.e. the part which is past the
9818 initial whitespace, #, whitespace, directive-name, whitespace part. */
9820 void
9821 dwarf2out_undef (lineno, buffer)
9822 register unsigned lineno ATTRIBUTE_UNUSED;
9823 register const char *buffer ATTRIBUTE_UNUSED;
9827 /* Set up for Dwarf output at the start of compilation. */
9829 void
9830 dwarf2out_init (asm_out_file, main_input_filename)
9831 register FILE *asm_out_file;
9832 register char *main_input_filename;
9834 /* Remember the name of the primary input file. */
9835 primary_filename = main_input_filename;
9837 /* Allocate the initial hunk of the file_table. */
9838 file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
9839 file_table_allocated = FILE_TABLE_INCREMENT;
9841 /* Skip the first entry - file numbers begin at 1. */
9842 file_table_in_use = 1;
9844 /* Allocate the initial hunk of the decl_die_table. */
9845 decl_die_table
9846 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref));
9847 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT;
9848 decl_die_table_in_use = 0;
9850 /* Allocate the initial hunk of the decl_scope_table. */
9851 decl_scope_table
9852 = (decl_scope_node *) xcalloc (DECL_SCOPE_TABLE_INCREMENT,
9853 sizeof (decl_scope_node));
9854 decl_scope_table_allocated = DECL_SCOPE_TABLE_INCREMENT;
9855 decl_scope_depth = 0;
9857 /* Allocate the initial hunk of the abbrev_die_table. */
9858 abbrev_die_table
9859 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT,
9860 sizeof (dw_die_ref));
9861 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT;
9862 /* Zero-th entry is allocated, but unused */
9863 abbrev_die_table_in_use = 1;
9865 /* Allocate the initial hunk of the line_info_table. */
9866 line_info_table
9867 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT,
9868 sizeof (dw_line_info_entry));
9869 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT;
9870 /* Zero-th entry is allocated, but unused */
9871 line_info_table_in_use = 1;
9873 /* Generate the initial DIE for the .debug section. Note that the (string)
9874 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE
9875 will (typically) be a relative pathname and that this pathname should be
9876 taken as being relative to the directory from which the compiler was
9877 invoked when the given (base) source file was compiled. */
9878 gen_compile_unit_die (main_input_filename);
9880 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0);
9881 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, ABBREV_SECTION_LABEL, 0);
9882 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9883 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0);
9884 else
9885 strcpy (text_section_label, stripattributes (TEXT_SECTION));
9886 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label,
9887 DEBUG_INFO_SECTION_LABEL, 0);
9888 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label,
9889 DEBUG_LINE_SECTION_LABEL, 0);
9891 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9892 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label);
9893 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9894 if (DWARF2_GENERATE_TEXT_SECTION_LABEL)
9895 ASM_OUTPUT_LABEL (asm_out_file, text_section_label);
9896 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9897 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label);
9898 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9899 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label);
9902 /* Output stuff that dwarf requires at the end of every file,
9903 and generate the DWARF-2 debugging info. */
9905 void
9906 dwarf2out_finish ()
9908 limbo_die_node *node, *next_node;
9909 dw_die_ref die;
9910 dw_attr_ref a;
9912 /* Traverse the limbo die list, and add parent/child links. The only
9913 dies without parents that should be here are concrete instances of
9914 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
9915 For concrete instances, we can get the parent die from the abstract
9916 instance. */
9917 for (node = limbo_die_list; node; node = next_node)
9919 next_node = node->next;
9920 die = node->die;
9922 if (die->die_parent == NULL)
9924 a = get_AT (die, DW_AT_abstract_origin);
9925 if (a)
9926 add_child_die (a->dw_attr_val.v.val_die_ref->die_parent, die);
9927 else if (die == comp_unit_die)
9929 else
9930 abort ();
9932 free (node);
9935 /* Walk through the list of incomplete types again, trying once more to
9936 emit full debugging info for them. */
9937 retry_incomplete_types ();
9939 /* Traverse the DIE tree and add sibling attributes to those DIE's
9940 that have children. */
9941 add_sibling_attributes (comp_unit_die);
9943 /* Output a terminator label for the .text section. */
9944 fputc ('\n', asm_out_file);
9945 ASM_OUTPUT_SECTION (asm_out_file, TEXT_SECTION);
9946 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0);
9948 #if 0
9949 /* Output a terminator label for the .data section. */
9950 fputc ('\n', asm_out_file);
9951 ASM_OUTPUT_SECTION (asm_out_file, DATA_SECTION);
9952 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, DATA_END_LABEL, 0);
9954 /* Output a terminator label for the .bss section. */
9955 fputc ('\n', asm_out_file);
9956 ASM_OUTPUT_SECTION (asm_out_file, BSS_SECTION);
9957 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, BSS_END_LABEL, 0);
9958 #endif
9960 /* Output the source line correspondence table. */
9961 if (line_info_table_in_use > 1 || separate_line_info_table_in_use)
9963 if (! DWARF2_ASM_LINE_DEBUG_INFO)
9965 fputc ('\n', asm_out_file);
9966 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_LINE_SECTION);
9967 output_line_info ();
9970 /* We can only use the low/high_pc attributes if all of the code
9971 was in .text. */
9972 if (separate_line_info_table_in_use == 0)
9974 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label);
9975 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label);
9978 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list,
9979 debug_line_section_label);
9982 /* Output the abbreviation table. */
9983 fputc ('\n', asm_out_file);
9984 ASM_OUTPUT_SECTION (asm_out_file, ABBREV_SECTION);
9985 build_abbrev_table (comp_unit_die);
9986 output_abbrev_section ();
9988 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9989 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE;
9990 calc_die_sizes (comp_unit_die);
9992 /* Output debugging information. */
9993 fputc ('\n', asm_out_file);
9994 ASM_OUTPUT_SECTION (asm_out_file, DEBUG_INFO_SECTION);
9995 output_compilation_unit_header ();
9996 output_die (comp_unit_die);
9998 if (pubname_table_in_use)
10000 /* Output public names table. */
10001 fputc ('\n', asm_out_file);
10002 ASM_OUTPUT_SECTION (asm_out_file, PUBNAMES_SECTION);
10003 output_pubnames ();
10006 /* We only put functions in the arange table, so don't write it out if
10007 we don't have any. */
10008 if (fde_table_in_use)
10010 /* Output the address range information. */
10011 fputc ('\n', asm_out_file);
10012 ASM_OUTPUT_SECTION (asm_out_file, ARANGES_SECTION);
10013 output_aranges ();
10016 #endif /* DWARF2_DEBUGGING_INFO */