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