OSDN Git Service

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