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