OSDN Git Service

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