OSDN Git Service

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