OSDN Git Service

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