OSDN Git Service

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