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