OSDN Git Service

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