OSDN Git Service

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