OSDN Git Service

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