OSDN Git Service

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