OSDN Git Service

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