dbxout.c revision 96280
1/* Output dbx-format symbol table information from GNU compiler.
2   Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3   1999, 2000, 2001 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING.  If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA.  */
21
22/* $FreeBSD: head/contrib/gcc/dbxout.c 96280 2002-05-09 21:24:44Z obrien $ */
23
24
25/* Output dbx-format symbol table data.
26   This consists of many symbol table entries, each of them
27   a .stabs assembler pseudo-op with four operands:
28   a "name" which is really a description of one symbol and its type,
29   a "code", which is a symbol defined in stab.h whose name starts with N_,
30   an unused operand always 0,
31   and a "value" which is an address or an offset.
32   The name is enclosed in doublequote characters.
33
34   Each function, variable, typedef, and structure tag
35   has a symbol table entry to define it.
36   The beginning and end of each level of name scoping within
37   a function are also marked by special symbol table entries.
38
39   The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
40   and a data type number.  The data type number may be followed by
41   "=" and a type definition; normally this will happen the first time
42   the type number is mentioned.  The type definition may refer to
43   other types by number, and those type numbers may be followed
44   by "=" and nested definitions.
45
46   This can make the "name" quite long.
47   When a name is more than 80 characters, we split the .stabs pseudo-op
48   into two .stabs pseudo-ops, both sharing the same "code" and "value".
49   The first one is marked as continued with a double-backslash at the
50   end of its "name".
51
52   The kind-of-symbol letter distinguished function names from global
53   variables from file-scope variables from parameters from auto
54   variables in memory from typedef names from register variables.
55   See `dbxout_symbol'.
56
57   The "code" is mostly redundant with the kind-of-symbol letter
58   that goes in the "name", but not entirely: for symbols located
59   in static storage, the "code" says which segment the address is in,
60   which controls how it is relocated.
61
62   The "value" for a symbol in static storage
63   is the core address of the symbol (actually, the assembler
64   label for the symbol).  For a symbol located in a stack slot
65   it is the stack offset; for one in a register, the register number.
66   For a typedef symbol, it is zero.
67
68   If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
69   output while in the text section.
70
71   For more on data type definitions, see `dbxout_type'.  */
72
73#include "config.h"
74#include "system.h"
75
76#include "tree.h"
77#include "rtl.h"
78#include "flags.h"
79#include "regs.h"
80#include "insn-config.h"
81#include "reload.h"
82#include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions.  */
83#include "dbxout.h"
84#include "toplev.h"
85#include "tm_p.h"
86#include "ggc.h"
87#include "debug.h"
88#include "function.h"
89#include "target.h"
90#include "langhooks.h"
91
92#ifdef XCOFF_DEBUGGING_INFO
93#include "xcoffout.h"
94#endif
95
96#ifndef ASM_STABS_OP
97#define ASM_STABS_OP "\t.stabs\t"
98#endif
99
100#ifndef ASM_STABN_OP
101#define ASM_STABN_OP "\t.stabn\t"
102#endif
103
104#ifndef DBX_TYPE_DECL_STABS_CODE
105#define DBX_TYPE_DECL_STABS_CODE N_LSYM
106#endif
107
108#ifndef DBX_STATIC_CONST_VAR_CODE
109#define DBX_STATIC_CONST_VAR_CODE N_FUN
110#endif
111
112#ifndef DBX_REGPARM_STABS_CODE
113#define DBX_REGPARM_STABS_CODE N_RSYM
114#endif
115
116#ifndef DBX_REGPARM_STABS_LETTER
117#define DBX_REGPARM_STABS_LETTER 'P'
118#endif
119
120/* This is used for parameters passed by invisible reference in a register.  */
121#ifndef GDB_INV_REF_REGPARM_STABS_LETTER
122#define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
123#endif
124
125#ifndef DBX_MEMPARM_STABS_LETTER
126#define DBX_MEMPARM_STABS_LETTER 'p'
127#endif
128
129#ifndef FILE_NAME_JOINER
130#define FILE_NAME_JOINER "/"
131#endif
132
133/* GDB needs to know that the stabs were generated by GCC.  We emit an
134   N_OPT stab at the beginning of the source file to indicate this.
135   The string is historical, and different on a very few targets.  */
136#ifndef STABS_GCC_MARKER
137#define STABS_GCC_MARKER "gcc2_compiled."
138#endif
139
140/* Typical USG systems don't have stab.h, and they also have
141   no use for DBX-format debugging info.  */
142
143#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
144
145/* Nonzero if we have actually used any of the GDB extensions
146   to the debugging format.  The idea is that we use them for the
147   first time only if there's a strong reason, but once we have done that,
148   we use them whenever convenient.  */
149
150static int have_used_extensions = 0;
151
152/* Number for the next N_SOL filename stabs label.  The number 0 is reserved
153   for the N_SO filename stabs label.  */
154
155#if defined (DBX_DEBUGGING_INFO) && !defined (DBX_OUTPUT_SOURCE_FILENAME)
156static int source_label_number = 1;
157#endif
158
159#ifdef DEBUG_SYMS_TEXT
160#define FORCE_TEXT text_section ();
161#else
162#define FORCE_TEXT
163#endif
164
165#include "gstab.h"
166
167#define STAB_CODE_TYPE enum __stab_debug_code
168
169/* 1 if PARM is passed to this function in memory.  */
170
171#define PARM_PASSED_IN_MEMORY(PARM) \
172 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
173
174/* A C expression for the integer offset value of an automatic variable
175   (N_LSYM) having address X (an RTX).  */
176#ifndef DEBUGGER_AUTO_OFFSET
177#define DEBUGGER_AUTO_OFFSET(X) \
178  (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
179#endif
180
181/* A C expression for the integer offset value of an argument (N_PSYM)
182   having address X (an RTX).  The nominal offset is OFFSET.  */
183#ifndef DEBUGGER_ARG_OFFSET
184#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
185#endif
186
187/* Stream for writing to assembler file.  */
188
189static FILE *asmfile;
190
191/* Last source file name mentioned in a NOTE insn.  */
192
193static const char *lastfile;
194
195/* Current working directory.  */
196
197static const char *cwd;
198
199enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
200
201/* Structure recording information about a C data type.
202   The status element says whether we have yet output
203   the definition of the type.  TYPE_XREF says we have
204   output it as a cross-reference only.
205   The file_number and type_number elements are used if DBX_USE_BINCL
206   is defined.  */
207
208struct typeinfo
209{
210  enum typestatus status;
211#ifdef DBX_USE_BINCL
212  int file_number;
213  int type_number;
214#endif
215};
216
217/* Vector recording information about C data types.
218   When we first notice a data type (a tree node),
219   we assign it a number using next_type_number.
220   That is its index in this vector.  */
221
222struct typeinfo *typevec;
223
224/* Number of elements of space allocated in `typevec'.  */
225
226static int typevec_len;
227
228/* In dbx output, each type gets a unique number.
229   This is the number for the next type output.
230   The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
231
232static int next_type_number;
233
234#ifdef DBX_USE_BINCL
235
236/* When using N_BINCL in dbx output, each type number is actually a
237   pair of the file number and the type number within the file.
238   This is a stack of input files.  */
239
240struct dbx_file
241{
242  struct dbx_file *next;
243  int file_number;
244  int next_type_number;
245};
246
247/* This is the top of the stack.  */
248
249static struct dbx_file *current_file;
250
251/* This is the next file number to use.  */
252
253static int next_file_number;
254
255#endif /* DBX_USE_BINCL */
256
257/* These variables are for dbxout_symbol to communicate to
258   dbxout_finish_symbol.
259   current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
260   current_sym_value and current_sym_addr are two ways to address the
261   value to store in the symtab entry.
262   current_sym_addr if nonzero represents the value as an rtx.
263   If that is zero, current_sym_value is used.  This is used
264   when the value is an offset (such as for auto variables,
265   register variables and parms).  */
266
267static STAB_CODE_TYPE current_sym_code;
268static int current_sym_value;
269static rtx current_sym_addr;
270
271/* Number of chars of symbol-description generated so far for the
272   current symbol.  Used by CHARS and CONTIN.  */
273
274static int current_sym_nchars;
275
276/* Report having output N chars of the current symbol-description.  */
277
278#define CHARS(N) (current_sym_nchars += (N))
279
280/* Break the current symbol-description, generating a continuation,
281   if it has become long.  */
282
283#ifndef DBX_CONTIN_LENGTH
284#define DBX_CONTIN_LENGTH 80
285#endif
286
287#if DBX_CONTIN_LENGTH > 0
288#define CONTIN  \
289  do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
290#else
291#define CONTIN do { } while (0)
292#endif
293
294static void dbxout_init			PARAMS ((const char *));
295static void dbxout_finish		PARAMS ((const char *));
296static void dbxout_start_source_file	PARAMS ((unsigned, const char *));
297static void dbxout_end_source_file	PARAMS ((unsigned));
298static void dbxout_typedefs		PARAMS ((tree));
299static void dbxout_type_index		PARAMS ((tree));
300#if DBX_CONTIN_LENGTH > 0
301static void dbxout_continue		PARAMS ((void));
302#endif
303static void dbxout_args			PARAMS ((tree));
304static void dbxout_type_fields		PARAMS ((tree));
305static void dbxout_type_method_1	PARAMS ((tree, const char *));
306static void dbxout_type_methods		PARAMS ((tree));
307static void dbxout_range_type		PARAMS ((tree));
308static void dbxout_type			PARAMS ((tree, int));
309static void print_int_cst_octal		PARAMS ((tree));
310static void print_octal			PARAMS ((unsigned HOST_WIDE_INT, int));
311static void print_wide_int		PARAMS ((HOST_WIDE_INT));
312static void dbxout_type_name		PARAMS ((tree));
313static int dbxout_symbol_location	PARAMS ((tree, tree, const char *, rtx));
314static void dbxout_symbol_name		PARAMS ((tree, const char *, int));
315static void dbxout_prepare_symbol	PARAMS ((tree));
316static void dbxout_finish_symbol	PARAMS ((tree));
317static void dbxout_block		PARAMS ((tree, int, tree));
318static void dbxout_global_decl		PARAMS ((tree));
319
320/* The debug hooks structure.  */
321#if defined (DBX_DEBUGGING_INFO)
322
323static void dbxout_source_line		PARAMS ((unsigned int, const char *));
324static void dbxout_source_file		PARAMS ((FILE *, const char *));
325static void dbxout_function_end		PARAMS ((void));
326static void dbxout_begin_function	PARAMS ((tree));
327static void dbxout_begin_block		PARAMS ((unsigned, unsigned));
328static void dbxout_end_block		PARAMS ((unsigned, unsigned));
329static void dbxout_function_decl	PARAMS ((tree));
330
331struct gcc_debug_hooks dbx_debug_hooks =
332{
333  dbxout_init,
334  dbxout_finish,
335  debug_nothing_int_charstar,
336  debug_nothing_int_charstar,
337  dbxout_start_source_file,
338  dbxout_end_source_file,
339  dbxout_begin_block,
340  dbxout_end_block,
341  debug_true_tree,		/* ignore_block */
342  dbxout_source_line,		/* source_line */
343  dbxout_source_line,		/* begin_prologue: just output line info */
344  debug_nothing_int,		/* end_prologue */
345  debug_nothing_void,		/* end_epilogue */
346#ifdef DBX_FUNCTION_FIRST
347  dbxout_begin_function,
348#else
349  debug_nothing_tree,		/* begin_function */
350#endif
351  debug_nothing_int,		/* end_function */
352  dbxout_function_decl,
353  dbxout_global_decl,		/* global_decl */
354  debug_nothing_tree,		/* deferred_inline_function */
355  debug_nothing_tree,		/* outlining_inline_function */
356  debug_nothing_rtx		/* label */
357};
358#endif /* DBX_DEBUGGING_INFO  */
359
360#if defined (XCOFF_DEBUGGING_INFO)
361struct gcc_debug_hooks xcoff_debug_hooks =
362{
363  dbxout_init,
364  dbxout_finish,
365  debug_nothing_int_charstar,
366  debug_nothing_int_charstar,
367  dbxout_start_source_file,
368  dbxout_end_source_file,
369  xcoffout_begin_block,
370  xcoffout_end_block,
371  debug_true_tree,		/* ignore_block */
372  xcoffout_source_line,
373  xcoffout_begin_prologue,	/* begin_prologue */
374  debug_nothing_int,		/* end_prologue */
375  xcoffout_end_epilogue,
376  debug_nothing_tree,		/* begin_function */
377  xcoffout_end_function,
378  debug_nothing_tree,		/* function_decl */
379  dbxout_global_decl,		/* global_decl */
380  debug_nothing_tree,		/* deferred_inline_function */
381  debug_nothing_tree,		/* outlining_inline_function */
382  debug_nothing_rtx		/* label */
383};
384#endif /* XCOFF_DEBUGGING_INFO  */
385
386#if defined (DBX_DEBUGGING_INFO)
387static void
388dbxout_function_end ()
389{
390  static int scope_labelno = 0;
391  char lscope_label_name[100];
392  /* Convert Ltext into the appropriate format for local labels in case
393     the system doesn't insert underscores in front of user generated
394     labels.  */
395  ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
396  ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Lscope", scope_labelno);
397  scope_labelno++;
398
399  /* By convention, GCC will mark the end of a function with an N_FUN
400     symbol and an empty string.  */
401  fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
402  assemble_name (asmfile, lscope_label_name);
403  putc ('-', asmfile);
404  assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
405  fprintf (asmfile, "\n");
406}
407#endif /* DBX_DEBUGGING_INFO */
408
409/* At the beginning of compilation, start writing the symbol table.
410   Initialize `typevec' and output the standard data types of C.  */
411
412static void
413dbxout_init (input_file_name)
414     const char *input_file_name;
415{
416  char ltext_label_name[100];
417  tree syms = getdecls ();
418
419  asmfile = asm_out_file;
420
421  typevec_len = 100;
422  typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
423
424  /* Convert Ltext into the appropriate format for local labels in case
425     the system doesn't insert underscores in front of user generated
426     labels.  */
427  ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
428
429  /* Put the current working directory in an N_SO symbol.  */
430#ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
431				 but GDB always does.  */
432  if (use_gnu_debug_info_extensions)
433#endif
434    {
435      if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
436	cwd = concat (cwd, FILE_NAME_JOINER, NULL);
437      if (cwd)
438	{
439#ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
440	  DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
441#else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
442	  fprintf (asmfile, "%s", ASM_STABS_OP);
443	  output_quoted_string (asmfile, cwd);
444	  fprintf (asmfile, ",%d,0,0,", N_SO);
445	  assemble_name (asmfile, ltext_label_name);
446	  fputc ('\n', asmfile);
447#endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
448	}
449    }
450
451#ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
452  /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
453     would give us an N_SOL, and we want an N_SO.  */
454  DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
455#else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
456  /* We include outputting `Ltext:' here,
457     because that gives you a way to override it.  */
458  /* Used to put `Ltext:' before the reference, but that loses on sun 4.  */
459  fprintf (asmfile, "%s", ASM_STABS_OP);
460  output_quoted_string (asmfile, input_file_name);
461  fprintf (asmfile, ",%d,0,0,", N_SO);
462  assemble_name (asmfile, ltext_label_name);
463  fputc ('\n', asmfile);
464  text_section ();
465  ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
466#endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
467
468#ifdef DBX_OUTPUT_GCC_MARKER
469  DBX_OUTPUT_GCC_MARKER (asmfile);
470#else
471  /* Emit an N_OPT stab to indicate that this file was compiled by GCC.  */
472  fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
473	   ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
474#endif
475
476  lastfile = input_file_name;
477
478  next_type_number = 1;
479
480#ifdef DBX_USE_BINCL
481  current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
482  current_file->next = NULL;
483  current_file->file_number = 0;
484  current_file->next_type_number = 1;
485  next_file_number = 1;
486#endif
487
488  /* Make sure that types `int' and `char' have numbers 1 and 2.
489     Definitions of other integer types will refer to those numbers.
490     (Actually it should no longer matter what their numbers are.
491     Also, if any types with tags have been defined, dbxout_symbol
492     will output them first, so the numbers won't be 1 and 2.  That
493     happens in C++.  So it's a good thing it should no longer matter).  */
494
495#ifdef DBX_OUTPUT_STANDARD_TYPES
496  DBX_OUTPUT_STANDARD_TYPES (syms);
497#else
498  dbxout_symbol (TYPE_NAME (integer_type_node), 0);
499  dbxout_symbol (TYPE_NAME (char_type_node), 0);
500#endif
501
502  /* Get all permanent types that have typedef names,
503     and output them all, except for those already output.  */
504
505  dbxout_typedefs (syms);
506}
507
508/* Output any typedef names for types described by TYPE_DECLs in SYMS,
509   in the reverse order from that which is found in SYMS.  */
510
511static void
512dbxout_typedefs (syms)
513     tree syms;
514{
515  if (syms)
516    {
517      dbxout_typedefs (TREE_CHAIN (syms));
518      if (TREE_CODE (syms) == TYPE_DECL)
519	{
520	  tree type = TREE_TYPE (syms);
521	  if (TYPE_NAME (type)
522	      && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
523	      && COMPLETE_TYPE_P (type)
524	      && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
525	    dbxout_symbol (TYPE_NAME (type), 0);
526	}
527    }
528}
529
530/* Change to reading from a new source file.  Generate a N_BINCL stab.  */
531
532static void
533dbxout_start_source_file (line, filename)
534     unsigned int line ATTRIBUTE_UNUSED;
535     const char *filename ATTRIBUTE_UNUSED;
536{
537#ifdef DBX_USE_BINCL
538  struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
539
540  n->next = current_file;
541  n->file_number = next_file_number++;
542  n->next_type_number = 1;
543  current_file = n;
544  fprintf (asmfile, "%s", ASM_STABS_OP);
545  output_quoted_string (asmfile, filename);
546  fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
547#endif
548}
549
550/* Revert to reading a previous source file.  Generate a N_EINCL stab.  */
551
552static void
553dbxout_end_source_file (line)
554     unsigned int line ATTRIBUTE_UNUSED;
555{
556#ifdef DBX_USE_BINCL
557  struct dbx_file *next;
558
559  fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
560  next = current_file->next;
561  free (current_file);
562  current_file = next;
563#endif
564}
565
566#if defined (DBX_DEBUGGING_INFO)
567/* Output debugging info to FILE to switch to sourcefile FILENAME.  */
568
569static void
570dbxout_source_file (file, filename)
571     FILE *file;
572     const char *filename;
573{
574  if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
575    {
576#ifdef DBX_OUTPUT_SOURCE_FILENAME
577      DBX_OUTPUT_SOURCE_FILENAME (file, filename);
578#else
579      char ltext_label_name[100];
580
581      ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
582				   source_label_number);
583      fprintf (file, "%s", ASM_STABS_OP);
584      output_quoted_string (file, filename);
585      fprintf (asmfile, ",%d,0,0,", N_SOL);
586      assemble_name (asmfile, ltext_label_name);
587      fputc ('\n', asmfile);
588      if (current_function_decl != NULL_TREE
589	  && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
590	; /* Don't change section amid function.  */
591      else
592	text_section ();
593      ASM_OUTPUT_INTERNAL_LABEL (file, "Ltext", source_label_number);
594      source_label_number++;
595#endif
596      lastfile = filename;
597    }
598}
599
600/* Output a line number symbol entry for source file FILENAME and line
601   number LINENO.  */
602
603static void
604dbxout_source_line (lineno, filename)
605     unsigned int lineno;
606     const char *filename;
607{
608  dbxout_source_file (asmfile, filename);
609
610#ifdef ASM_OUTPUT_SOURCE_LINE
611  ASM_OUTPUT_SOURCE_LINE (asmfile, lineno);
612#else
613  fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
614#endif
615}
616
617/* Describe the beginning of an internal block within a function.  */
618
619static void
620dbxout_begin_block (line, n)
621     unsigned int line ATTRIBUTE_UNUSED;
622     unsigned int n;
623{
624  ASM_OUTPUT_INTERNAL_LABEL (asmfile, "LBB", n);
625}
626
627/* Describe the end line-number of an internal block within a function.  */
628
629static void
630dbxout_end_block (line, n)
631     unsigned int line ATTRIBUTE_UNUSED;
632     unsigned int n;
633{
634  ASM_OUTPUT_INTERNAL_LABEL (asmfile, "LBE", n);
635}
636
637/* Output dbx data for a function definition.
638   This includes a definition of the function name itself (a symbol),
639   definitions of the parameters (locating them in the parameter list)
640   and then output the block that makes up the function's body
641   (including all the auto variables of the function).  */
642
643static void
644dbxout_function_decl (decl)
645     tree decl;
646{
647#ifndef DBX_FUNCTION_FIRST
648  dbxout_begin_function (decl);
649#endif
650  dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
651#ifdef DBX_OUTPUT_FUNCTION_END
652  DBX_OUTPUT_FUNCTION_END (asmfile, decl);
653#endif
654  if (use_gnu_debug_info_extensions
655#if defined(NO_DBX_FUNCTION_END)
656      && ! NO_DBX_FUNCTION_END
657#endif
658      && targetm.have_named_sections)
659    dbxout_function_end ();
660}
661
662#endif /* DBX_DEBUGGING_INFO  */
663
664/* Debug information for a global DECL.  Called from toplev.c after
665   compilation proper has finished.  */
666static void
667dbxout_global_decl (decl)
668     tree decl;
669{
670  if (TREE_CODE (decl) == VAR_DECL
671      && ! DECL_EXTERNAL (decl)
672      && DECL_RTL_SET_P (decl))	/* Not necessary?  */
673    dbxout_symbol (decl, 0);
674}
675
676/* At the end of compilation, finish writing the symbol table.
677   Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
678   to do nothing.  */
679
680static void
681dbxout_finish (filename)
682     const char *filename ATTRIBUTE_UNUSED;
683{
684#ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
685  DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
686#endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
687}
688
689/* Output the index of a type.  */
690
691static void
692dbxout_type_index (type)
693     tree type;
694{
695#ifndef DBX_USE_BINCL
696  fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
697  CHARS (3);
698#else
699  struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
700  fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
701  CHARS (9);
702#endif
703}
704
705#if DBX_CONTIN_LENGTH > 0
706/* Continue a symbol-description that gets too big.
707   End one symbol table entry with a double-backslash
708   and start a new one, eventually producing something like
709   .stabs "start......\\",code,0,value
710   .stabs "...rest",code,0,value   */
711
712static void
713dbxout_continue ()
714{
715#ifdef DBX_CONTIN_CHAR
716  fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
717#else
718  fprintf (asmfile, "\\\\");
719#endif
720  dbxout_finish_symbol (NULL_TREE);
721  fprintf (asmfile, "%s\"", ASM_STABS_OP);
722  current_sym_nchars = 0;
723}
724#endif /* DBX_CONTIN_LENGTH > 0 */
725
726/* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
727   This must be a separate function because anonymous unions require
728   recursive calls.  */
729
730static void
731dbxout_type_fields (type)
732     tree type;
733{
734  tree tem;
735
736  /* Output the name, type, position (in bits), size (in bits) of each
737     field that we can support.  */
738  for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
739    {
740      /* Omit here local type decls until we know how to support them.  */
741      if (TREE_CODE (tem) == TYPE_DECL
742	  /* Omit fields whose position or size are variable or too large to
743	     represent.  */
744	  || (TREE_CODE (tem) == FIELD_DECL
745	      && (! host_integerp (bit_position (tem), 0)
746		  || ! DECL_SIZE (tem)
747		  || ! host_integerp (DECL_SIZE (tem), 1)))
748	  /* Omit here the nameless fields that are used to skip bits.  */
749	   || DECL_IGNORED_P (tem))
750	continue;
751
752      else if (TREE_CODE (tem) != CONST_DECL)
753	{
754	  /* Continue the line if necessary,
755	     but not before the first field.  */
756	  if (tem != TYPE_FIELDS (type))
757	    CONTIN;
758
759	  if (DECL_NAME (tem))
760	    {
761	      fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
762	      CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
763	    }
764	  else
765	    {
766	      fprintf (asmfile, ":");
767	      CHARS (1);
768	    }
769
770	  if (use_gnu_debug_info_extensions
771	      && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
772		  || TREE_CODE (tem) != FIELD_DECL))
773	    {
774	      have_used_extensions = 1;
775	      putc ('/', asmfile);
776	      putc ((TREE_PRIVATE (tem) ? '0'
777		     : TREE_PROTECTED (tem) ? '1' : '2'),
778		    asmfile);
779	      CHARS (2);
780	    }
781
782	  dbxout_type ((TREE_CODE (tem) == FIELD_DECL
783			&& DECL_BIT_FIELD_TYPE (tem))
784		       ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
785
786	  if (TREE_CODE (tem) == VAR_DECL)
787	    {
788	      if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
789		{
790		  tree name = DECL_ASSEMBLER_NAME (tem);
791
792		  have_used_extensions = 1;
793		  fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
794		  CHARS (IDENTIFIER_LENGTH (name) + 2);
795		}
796	      else
797		{
798		  /* If TEM is non-static, GDB won't understand it.  */
799		  fprintf (asmfile, ",0,0;");
800		  CHARS (5);
801		}
802	    }
803	  else
804	    {
805	      putc (',', asmfile);
806	      print_wide_int (int_bit_position (tem));
807	      putc (',', asmfile);
808	      print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
809	      putc (';', asmfile);
810	      CHARS (3);
811	    }
812	}
813    }
814}
815
816/* Subroutine of `dbxout_type_methods'.  Output debug info about the
817   method described DECL.  DEBUG_NAME is an encoding of the method's
818   type signature.  ??? We may be able to do without DEBUG_NAME altogether
819   now.  */
820
821static void
822dbxout_type_method_1 (decl, debug_name)
823     tree decl;
824     const char *debug_name;
825{
826  char c1 = 'A', c2;
827
828  if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
829    c2 = '?';
830  else /* it's a METHOD_TYPE.  */
831    {
832      tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
833      /* A for normal functions.
834	 B for `const' member functions.
835	 C for `volatile' member functions.
836	 D for `const volatile' member functions.  */
837      if (TYPE_READONLY (TREE_TYPE (firstarg)))
838	c1 += 1;
839      if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
840	c1 += 2;
841
842      if (DECL_VINDEX (decl))
843	c2 = '*';
844      else
845	c2 = '.';
846    }
847
848  fprintf (asmfile, ":%s;%c%c%c", debug_name,
849	   TREE_PRIVATE (decl) ? '0'
850	   : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
851  CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
852	 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
853
854  if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
855    {
856      print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
857      putc (';', asmfile);
858      CHARS (1);
859      dbxout_type (DECL_CONTEXT (decl), 0);
860      fprintf (asmfile, ";");
861      CHARS (1);
862    }
863}
864
865/* Subroutine of `dbxout_type'.  Output debug info about the methods defined
866   in TYPE.  */
867
868static void
869dbxout_type_methods (type)
870     tree type;
871{
872  /* C++: put out the method names and their parameter lists */
873  tree methods = TYPE_METHODS (type);
874  tree type_encoding;
875  tree fndecl;
876  tree last;
877  char formatted_type_identifier_length[16];
878  int type_identifier_length;
879
880  if (methods == NULL_TREE)
881    return;
882
883  type_encoding = DECL_NAME (TYPE_NAME (type));
884
885#if 0
886  /* C++: Template classes break some assumptions made by this code about
887     the class names, constructor names, and encodings for assembler
888     label names.  For now, disable output of dbx info for them.  */
889  {
890    const char *ptr = IDENTIFIER_POINTER (type_encoding);
891    /* This should use index.  (mrs) */
892    while (*ptr && *ptr != '<') ptr++;
893    if (*ptr != 0)
894      {
895	static int warned;
896	if (!warned)
897	    warned = 1;
898	return;
899      }
900  }
901#endif
902
903  type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
904
905  sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
906
907  if (TREE_CODE (methods) != TREE_VEC)
908    fndecl = methods;
909  else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
910    fndecl = TREE_VEC_ELT (methods, 0);
911  else
912    fndecl = TREE_VEC_ELT (methods, 1);
913
914  while (fndecl)
915    {
916      int need_prefix = 1;
917
918      /* Group together all the methods for the same operation.
919	 These differ in the types of the arguments.  */
920      for (last = NULL_TREE;
921	   fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
922	   fndecl = TREE_CHAIN (fndecl))
923	/* Output the name of the field (after overloading), as
924	   well as the name of the field before overloading, along
925	   with its parameter list */
926	{
927	  /* This is the "mangled" name of the method.
928	     It encodes the argument types.  */
929	  const char *debug_name;
930
931	  /* Skip methods that aren't FUNCTION_DECLs.  (In C++, these
932	     include TEMPLATE_DECLs.)  The debugger doesn't know what
933	     to do with such entities anyhow.  */
934	  if (TREE_CODE (fndecl) != FUNCTION_DECL)
935	    continue;
936
937	  debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
938
939	  CONTIN;
940
941	  last = fndecl;
942
943	  /* Also ignore abstract methods; those are only interesting to
944	     the DWARF backends.  */
945	  if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
946	    continue;
947
948	  /* Redundantly output the plain name, since that's what gdb
949	     expects.  */
950	  if (need_prefix)
951	    {
952	      tree name = DECL_NAME (fndecl);
953	      fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
954	      CHARS (IDENTIFIER_LENGTH (name) + 2);
955	      need_prefix = 0;
956	    }
957
958	  dbxout_type (TREE_TYPE (fndecl), 0);
959
960	  dbxout_type_method_1 (fndecl, debug_name);
961	}
962      if (!need_prefix)
963	{
964          putc (';', asmfile);
965	  CHARS (1);
966	}
967    }
968}
969
970/* Emit a "range" type specification, which has the form:
971   "r<index type>;<lower bound>;<upper bound>;".
972   TYPE is an INTEGER_TYPE.  */
973
974static void
975dbxout_range_type (type)
976     tree type;
977{
978  fprintf (asmfile, "r");
979  if (TREE_TYPE (type))
980    dbxout_type (TREE_TYPE (type), 0);
981  else if (TREE_CODE (type) != INTEGER_TYPE)
982    dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
983  else
984    {
985      /* Traditionally, we made sure 'int' was type 1, and builtin types
986	 were defined to be sub-ranges of int.  Unfortunately, this
987	 does not allow us to distinguish true sub-ranges from integer
988	 types.  So, instead we define integer (non-sub-range) types as
989	 sub-ranges of themselves.  This matters for Chill.  If this isn't
990	 a subrange type, then we want to define it in terms of itself.
991	 However, in C, this may be an anonymous integer type, and we don't
992	 want to emit debug info referring to it.  Just calling
993	 dbxout_type_index won't work anyways, because the type hasn't been
994	 defined yet.  We make this work for both cases by checked to see
995	 whether this is a defined type, referring to it if it is, and using
996	 'int' otherwise.  */
997      if (TYPE_SYMTAB_ADDRESS (type) != 0)
998	dbxout_type_index (type);
999      else
1000	dbxout_type_index (integer_type_node);
1001    }
1002
1003  if (TYPE_MIN_VALUE (type) != 0
1004      && host_integerp (TYPE_MIN_VALUE (type), 0))
1005    {
1006      putc (';', asmfile);
1007      CHARS (1);
1008      print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1009    }
1010  else
1011    {
1012      fprintf (asmfile, ";0");
1013      CHARS (2);
1014    }
1015
1016  if (TYPE_MAX_VALUE (type) != 0
1017      && host_integerp (TYPE_MAX_VALUE (type), 0))
1018    {
1019      putc (';', asmfile);
1020      CHARS (1);
1021      print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1022      putc (';', asmfile);
1023      CHARS (1);
1024    }
1025  else
1026    {
1027      fprintf (asmfile, ";-1;");
1028      CHARS (4);
1029    }
1030}
1031
1032/* Output a reference to a type.  If the type has not yet been
1033   described in the dbx output, output its definition now.
1034   For a type already defined, just refer to its definition
1035   using the type number.
1036
1037   If FULL is nonzero, and the type has been described only with
1038   a forward-reference, output the definition now.
1039   If FULL is zero in this case, just refer to the forward-reference
1040   using the number previously allocated.  */
1041
1042static void
1043dbxout_type (type, full)
1044     tree type;
1045     int full;
1046{
1047  tree tem;
1048  tree main_variant;
1049  static int anonymous_type_number = 0;
1050
1051  if (TREE_CODE (type) == VECTOR_TYPE)
1052    type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
1053
1054  /* If there was an input error and we don't really have a type,
1055     avoid crashing and write something that is at least valid
1056     by assuming `int'.  */
1057  if (type == error_mark_node)
1058    type = integer_type_node;
1059  else
1060    {
1061      if (TYPE_NAME (type)
1062	  && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1063	  && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1064	full = 0;
1065    }
1066
1067  /* Try to find the "main variant" with the same name.  */
1068  if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1069      && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1070    main_variant = TREE_TYPE (TYPE_NAME (type));
1071  else
1072    main_variant = TYPE_MAIN_VARIANT (type);
1073
1074  /* If we are not using extensions, stabs does not distinguish const and
1075     volatile, so there is no need to make them separate types.  */
1076  if (!use_gnu_debug_info_extensions)
1077    type = main_variant;
1078
1079  if (TYPE_SYMTAB_ADDRESS (type) == 0)
1080    {
1081      /* Type has no dbx number assigned.  Assign next available number.  */
1082      TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1083
1084      /* Make sure type vector is long enough to record about this type.  */
1085
1086      if (next_type_number == typevec_len)
1087	{
1088	  typevec
1089	    = (struct typeinfo *) xrealloc (typevec,
1090					    typevec_len * 2 * sizeof typevec[0]);
1091	  memset ((char *) (typevec + typevec_len), 0,
1092		 typevec_len * sizeof typevec[0]);
1093	  typevec_len *= 2;
1094	}
1095
1096#ifdef DBX_USE_BINCL
1097      typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1098	= current_file->file_number;
1099      typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1100	= current_file->next_type_number++;
1101#endif
1102    }
1103
1104  /* Output the number of this type, to refer to it.  */
1105  dbxout_type_index (type);
1106
1107#ifdef DBX_TYPE_DEFINED
1108  if (DBX_TYPE_DEFINED (type))
1109    return;
1110#endif
1111
1112  /* If this type's definition has been output or is now being output,
1113     that is all.  */
1114
1115  switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1116    {
1117    case TYPE_UNSEEN:
1118      break;
1119    case TYPE_XREF:
1120      /* If we have already had a cross reference,
1121	 and either that's all we want or that's the best we could do,
1122	 don't repeat the cross reference.
1123	 Sun dbx crashes if we do.  */
1124      if (! full || !COMPLETE_TYPE_P (type)
1125	  /* No way in DBX fmt to describe a variable size.  */
1126	  || ! host_integerp (TYPE_SIZE (type), 1))
1127	return;
1128      break;
1129    case TYPE_DEFINED:
1130      return;
1131    }
1132
1133#ifdef DBX_NO_XREFS
1134  /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1135     leave the type-number completely undefined rather than output
1136     a cross-reference.  If we have already used GNU debug info extensions,
1137     then it is OK to output a cross reference.  This is necessary to get
1138     proper C++ debug output.  */
1139  if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1140       || TREE_CODE (type) == QUAL_UNION_TYPE
1141       || TREE_CODE (type) == ENUMERAL_TYPE)
1142      && ! use_gnu_debug_info_extensions)
1143    /* We must use the same test here as we use twice below when deciding
1144       whether to emit a cross-reference.  */
1145    if ((TYPE_NAME (type) != 0
1146	 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1147	       && DECL_IGNORED_P (TYPE_NAME (type)))
1148	 && !full)
1149	|| !COMPLETE_TYPE_P (type)
1150	/* No way in DBX fmt to describe a variable size.  */
1151	|| ! host_integerp (TYPE_SIZE (type), 1))
1152      {
1153	typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1154	return;
1155      }
1156#endif
1157
1158  /* Output a definition now.  */
1159
1160  fprintf (asmfile, "=");
1161  CHARS (1);
1162
1163  /* Mark it as defined, so that if it is self-referent
1164     we will not get into an infinite recursion of definitions.  */
1165
1166  typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1167
1168  /* If this type is a variant of some other, hand off.  Types with
1169     different names are usefully distinguished.  We only distinguish
1170     cv-qualified types if we're using extensions.  */
1171  if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1172    {
1173      putc ('k', asmfile);
1174      CHARS (1);
1175      dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1176      return;
1177    }
1178  else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1179    {
1180      putc ('B', asmfile);
1181      CHARS (1);
1182      dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1183      return;
1184    }
1185  else if (main_variant != TYPE_MAIN_VARIANT (type))
1186    {
1187      /* 'type' is a typedef; output the type it refers to.  */
1188      dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1189      return;
1190    }
1191  /* else continue.  */
1192
1193  switch (TREE_CODE (type))
1194    {
1195    case VOID_TYPE:
1196    case LANG_TYPE:
1197      /* For a void type, just define it as itself; ie, "5=5".
1198	 This makes us consider it defined
1199	 without saying what it is.  The debugger will make it
1200	 a void type when the reference is seen, and nothing will
1201	 ever override that default.  */
1202      dbxout_type_index (type);
1203      break;
1204
1205    case INTEGER_TYPE:
1206      if (type == char_type_node && ! TREE_UNSIGNED (type))
1207	{
1208	  /* Output the type `char' as a subrange of itself!
1209	     I don't understand this definition, just copied it
1210	     from the output of pcc.
1211	     This used to use `r2' explicitly and we used to
1212	     take care to make sure that `char' was type number 2.  */
1213	  fprintf (asmfile, "r");
1214	  CHARS (1);
1215	  dbxout_type_index (type);
1216	  fprintf (asmfile, ";0;127;");
1217	  CHARS (7);
1218	}
1219
1220      /* If this is a subtype of another integer type, always prefer to
1221	 write it as a subtype.  */
1222      else if (TREE_TYPE (type) != 0
1223	       && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1224        {
1225	  /* If the size is non-standard, say what it is if we can use
1226	     GDB extensions.  */
1227
1228	  if (use_gnu_debug_info_extensions
1229	      && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1230	    {
1231	      have_used_extensions = 1;
1232	      fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1233	      CHARS (5);
1234	    }
1235
1236	  dbxout_range_type (type);
1237        }
1238
1239      else
1240  	{
1241	  /* If the size is non-standard, say what it is if we can use
1242	     GDB extensions.  */
1243
1244	  if (use_gnu_debug_info_extensions
1245	      && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1246	    {
1247	      have_used_extensions = 1;
1248	      fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1249	      CHARS (5);
1250	    }
1251
1252	  /* If we can use GDB extensions and the size is wider than a
1253	     long (the size used by GDB to read them) or we may have
1254	     trouble writing the bounds the usual way, write them in
1255	     octal.  Note the test is for the *target's* size of "long",
1256	     not that of the host.  The host test is just to make sure we
1257	     can write it out in case the host wide int is narrower than the
1258	     target "long".  */
1259
1260	  /* For unsigned types, we use octal if they are the same size or
1261	     larger.  This is because we print the bounds as signed decimal,
1262	     and hence they can't span same size unsigned types.  */
1263
1264 	  if (use_gnu_debug_info_extensions
1265	      && TYPE_MIN_VALUE (type) != 0
1266	      && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1267	      && TYPE_MAX_VALUE (type) != 0
1268	      && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1269	      && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1270		  || ((TYPE_PRECISION (type)
1271		       == TYPE_PRECISION (integer_type_node))
1272		      && TREE_UNSIGNED (type))
1273		  || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1274		  || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1275		      && TREE_UNSIGNED (type))))
1276	    {
1277	      fprintf (asmfile, "r");
1278	      CHARS (1);
1279	      dbxout_type_index (type);
1280	      fprintf (asmfile, ";");
1281	      CHARS (1);
1282	      print_int_cst_octal (TYPE_MIN_VALUE (type));
1283	      fprintf (asmfile, ";");
1284	      CHARS (1);
1285	      print_int_cst_octal (TYPE_MAX_VALUE (type));
1286	      fprintf (asmfile, ";");
1287	      CHARS (1);
1288	    }
1289
1290	  else
1291	    /* Output other integer types as subranges of `int'.  */
1292	    dbxout_range_type (type);
1293  	}
1294
1295      break;
1296
1297    case REAL_TYPE:
1298      /* This used to say `r1' and we used to take care
1299	 to make sure that `int' was type number 1.  */
1300      fprintf (asmfile, "r");
1301      CHARS (1);
1302      dbxout_type_index (integer_type_node);
1303      putc (';', asmfile);
1304      CHARS (1);
1305      print_wide_int (int_size_in_bytes (type));
1306      fputs (";0;", asmfile);
1307      CHARS (3);
1308      break;
1309
1310    case CHAR_TYPE:
1311      if (use_gnu_debug_info_extensions)
1312	{
1313	  have_used_extensions = 1;
1314	  fputs ("@s", asmfile);
1315	  CHARS (2);
1316	  print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1317	  fputs (";-20;", asmfile);
1318	  CHARS (4);
1319	}
1320      else
1321	{
1322	  /* Output the type `char' as a subrange of itself.
1323	     That is what pcc seems to do.  */
1324	  fprintf (asmfile, "r");
1325	  CHARS (1);
1326	  dbxout_type_index (char_type_node);
1327	  fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1328	  CHARS (7);
1329	}
1330      break;
1331
1332    case BOOLEAN_TYPE:
1333      if (use_gnu_debug_info_extensions)
1334	{
1335	  have_used_extensions = 1;
1336	  fputs ("@s", asmfile);
1337	  CHARS (2);
1338	  print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1339	  fputs (";-16;", asmfile);
1340	  CHARS (4);
1341	}
1342      else /* Define as enumeral type (False, True) */
1343	{
1344	  fprintf (asmfile, "eFalse:0,True:1,;");
1345	  CHARS (17);
1346	}
1347      break;
1348
1349    case FILE_TYPE:
1350      putc ('d', asmfile);
1351      CHARS (1);
1352      dbxout_type (TREE_TYPE (type), 0);
1353      break;
1354
1355    case COMPLEX_TYPE:
1356      /* Differs from the REAL_TYPE by its new data type number */
1357
1358      if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1359	{
1360	  fprintf (asmfile, "r");
1361	  CHARS (1);
1362	  dbxout_type_index (type);
1363	  putc (';', asmfile);
1364	  CHARS (1);
1365	  print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1366	  fputs (";0;", asmfile);
1367	  CHARS (3);
1368	}
1369      else
1370	{
1371	  /* Output a complex integer type as a structure,
1372	     pending some other way to do it.  */
1373	  putc ('s', asmfile);
1374	  CHARS (1);
1375	  print_wide_int (int_size_in_bytes (type));
1376	  fprintf (asmfile, "real:");
1377	  CHARS (5);
1378
1379	  dbxout_type (TREE_TYPE (type), 0);
1380	  fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1381	  CHARS (7);
1382	  fprintf (asmfile, "imag:");
1383	  CHARS (5);
1384	  dbxout_type (TREE_TYPE (type), 0);
1385	  fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1386		   TYPE_PRECISION (TREE_TYPE (type)));
1387	  CHARS (10);
1388	}
1389      break;
1390
1391    case SET_TYPE:
1392      if (use_gnu_debug_info_extensions)
1393	{
1394	  have_used_extensions = 1;
1395	  fputs ("@s", asmfile);
1396	  CHARS (2);
1397	  print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1398	  putc (';', asmfile);
1399	  CHARS (1);
1400
1401	  /* Check if a bitstring type, which in Chill is
1402	     different from a [power]set.  */
1403	  if (TYPE_STRING_FLAG (type))
1404	    {
1405	      fprintf (asmfile, "@S;");
1406	      CHARS (3);
1407	    }
1408	}
1409      putc ('S', asmfile);
1410      CHARS (1);
1411      dbxout_type (TYPE_DOMAIN (type), 0);
1412      break;
1413
1414    case ARRAY_TYPE:
1415      /* Make arrays of packed bits look like bitstrings for chill.  */
1416      if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1417	{
1418	  have_used_extensions = 1;
1419	  fputs ("@s", asmfile);
1420	  CHARS (2);
1421	  print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1422	  fprintf (asmfile, ";@S;S");
1423	  CHARS (5);
1424	  dbxout_type (TYPE_DOMAIN (type), 0);
1425	  break;
1426	}
1427
1428      /* Output "a" followed by a range type definition
1429	 for the index type of the array
1430	 followed by a reference to the target-type.
1431	 ar1;0;N;M for a C array of type M and size N+1.  */
1432      /* Check if a character string type, which in Chill is
1433	 different from an array of characters.  */
1434      if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1435	{
1436	  have_used_extensions = 1;
1437	  fprintf (asmfile, "@S;");
1438	  CHARS (3);
1439	}
1440      tem = TYPE_DOMAIN (type);
1441      if (tem == NULL)
1442	{
1443	  fprintf (asmfile, "ar");
1444	  CHARS (2);
1445	  dbxout_type_index (integer_type_node);
1446	  fprintf (asmfile, ";0;-1;");
1447	  CHARS (6);
1448	}
1449      else
1450	{
1451	  fprintf (asmfile, "a");
1452	  CHARS (1);
1453	  dbxout_range_type (tem);
1454	}
1455
1456      dbxout_type (TREE_TYPE (type), 0);
1457      break;
1458
1459    case RECORD_TYPE:
1460    case UNION_TYPE:
1461    case QUAL_UNION_TYPE:
1462      {
1463	int i, n_baseclasses = 0;
1464
1465	if (TYPE_BINFO (type) != 0
1466	    && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1467	    && TYPE_BINFO_BASETYPES (type) != 0)
1468	  n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1469
1470	/* Output a structure type.  We must use the same test here as we
1471	   use in the DBX_NO_XREFS case above.  */
1472	if ((TYPE_NAME (type) != 0
1473	     && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1474		   && DECL_IGNORED_P (TYPE_NAME (type)))
1475	     && !full)
1476	    || !COMPLETE_TYPE_P (type)
1477	    /* No way in DBX fmt to describe a variable size.  */
1478	    || ! host_integerp (TYPE_SIZE (type), 1))
1479	  {
1480	    /* If the type is just a cross reference, output one
1481	       and mark the type as partially described.
1482	       If it later becomes defined, we will output
1483	       its real definition.
1484	       If the type has a name, don't nest its definition within
1485	       another type's definition; instead, output an xref
1486	       and let the definition come when the name is defined.  */
1487	    fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1488	    CHARS (2);
1489#if 0 /* This assertion is legitimately false in C++.  */
1490	    /* We shouldn't be outputting a reference to a type before its
1491	       definition unless the type has a tag name.
1492	       A typedef name without a tag name should be impossible.  */
1493	    if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1494	      abort ();
1495#endif
1496	    if (TYPE_NAME (type) != 0)
1497	      dbxout_type_name (type);
1498	    else
1499	      {
1500		fprintf (asmfile, "$$%d", anonymous_type_number++);
1501		CHARS (5);
1502	      }
1503
1504	    fprintf (asmfile, ":");
1505	    CHARS (1);
1506	    typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1507	    break;
1508	  }
1509
1510	/* Identify record or union, and print its size.  */
1511	putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1512	CHARS (1);
1513	print_wide_int (int_size_in_bytes (type));
1514
1515	if (use_gnu_debug_info_extensions)
1516	  {
1517	    if (n_baseclasses)
1518	      {
1519		have_used_extensions = 1;
1520		fprintf (asmfile, "!%d,", n_baseclasses);
1521		CHARS (8);
1522	      }
1523	  }
1524	for (i = 0; i < n_baseclasses; i++)
1525	  {
1526	    tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1527
1528	    if (use_gnu_debug_info_extensions)
1529	      {
1530		have_used_extensions = 1;
1531		putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1532		putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1533		CHARS (2);
1534		if (TREE_VIA_VIRTUAL (child) && strcmp (lang_hooks.name, "GNU C++") == 0)
1535		  /* For a virtual base, print the (negative) offset within
1536		     the vtable where we must look to find the necessary
1537		     adjustment.  */
1538		  print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1539				  * BITS_PER_UNIT);
1540		else
1541		  print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1542				  * BITS_PER_UNIT);
1543		putc (',', asmfile);
1544		CHARS (1);
1545		dbxout_type (BINFO_TYPE (child), 0);
1546		putc (';', asmfile);
1547		CHARS (1);
1548	      }
1549	    else
1550	      {
1551		/* Print out the base class information with fields
1552		   which have the same names at the types they hold.  */
1553		dbxout_type_name (BINFO_TYPE (child));
1554		putc (':', asmfile);
1555		CHARS (1);
1556		dbxout_type (BINFO_TYPE (child), full);
1557		putc (',', asmfile);
1558		CHARS (1);
1559		print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1560				* BITS_PER_UNIT);
1561		putc (',', asmfile);
1562		CHARS (1);
1563		print_wide_int (tree_low_cst (DECL_SIZE
1564					      (TYPE_NAME
1565					       (BINFO_TYPE (child))),
1566					      0)
1567				* BITS_PER_UNIT);
1568		putc (';', asmfile);
1569		CHARS (1);
1570	      }
1571	  }
1572      }
1573
1574      /* Write out the field declarations.  */
1575      dbxout_type_fields (type);
1576      if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1577	{
1578	  have_used_extensions = 1;
1579	  dbxout_type_methods (type);
1580	}
1581
1582      putc (';', asmfile);
1583      CHARS (1);
1584
1585      if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1586	  /* Avoid the ~ if we don't really need it--it confuses dbx.  */
1587	  && TYPE_VFIELD (type))
1588	{
1589	  have_used_extensions = 1;
1590
1591	  /* Tell GDB+ that it may keep reading.  */
1592	  putc ('~', asmfile);
1593	  CHARS (1);
1594
1595	  /* We need to write out info about what field this class
1596	     uses as its "main" vtable pointer field, because if this
1597	     field is inherited from a base class, GDB cannot necessarily
1598	     figure out which field it's using in time.  */
1599	  if (TYPE_VFIELD (type))
1600	    {
1601	      putc ('%', asmfile);
1602	      CHARS (1);
1603	      dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1604	    }
1605
1606	  putc (';', asmfile);
1607	  CHARS (1);
1608	}
1609      break;
1610
1611    case ENUMERAL_TYPE:
1612      /* We must use the same test here as we use in the DBX_NO_XREFS case
1613	 above.  We simplify it a bit since an enum will never have a variable
1614	 size.  */
1615      if ((TYPE_NAME (type) != 0
1616	   && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1617		 && DECL_IGNORED_P (TYPE_NAME (type)))
1618	   && !full)
1619	  || !COMPLETE_TYPE_P (type))
1620	{
1621	  fprintf (asmfile, "xe");
1622	  CHARS (2);
1623	  dbxout_type_name (type);
1624	  typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1625	  putc (':', asmfile);
1626	  CHARS (1);
1627	  return;
1628	}
1629#ifdef DBX_OUTPUT_ENUM
1630      DBX_OUTPUT_ENUM (asmfile, type);
1631#else
1632      if (use_gnu_debug_info_extensions
1633	  && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1634	{
1635	  fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1636	  CHARS (5);
1637	}
1638
1639      putc ('e', asmfile);
1640      CHARS (1);
1641      for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1642	{
1643	  fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1644	  CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1645	  if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1646	    print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1647	  else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1648		   && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1649	    print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1650	  else
1651	    print_int_cst_octal (TREE_VALUE (tem));
1652
1653	  putc (',', asmfile);
1654	  CHARS (1);
1655	  if (TREE_CHAIN (tem) != 0)
1656	    CONTIN;
1657	}
1658
1659      putc (';', asmfile);
1660      CHARS (1);
1661#endif
1662      break;
1663
1664    case POINTER_TYPE:
1665      putc ('*', asmfile);
1666      CHARS (1);
1667      dbxout_type (TREE_TYPE (type), 0);
1668      break;
1669
1670    case METHOD_TYPE:
1671      if (use_gnu_debug_info_extensions)
1672	{
1673	  have_used_extensions = 1;
1674	  putc ('#', asmfile);
1675	  CHARS (1);
1676
1677	  /* Write the argument types out longhand.  */
1678	  dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1679	  putc (',', asmfile);
1680	  CHARS (1);
1681	  dbxout_type (TREE_TYPE (type), 0);
1682	  dbxout_args (TYPE_ARG_TYPES (type));
1683	  putc (';', asmfile);
1684	  CHARS (1);
1685	}
1686      else
1687	/* Treat it as a function type.  */
1688	dbxout_type (TREE_TYPE (type), 0);
1689      break;
1690
1691    case OFFSET_TYPE:
1692      if (use_gnu_debug_info_extensions)
1693	{
1694	  have_used_extensions = 1;
1695	  putc ('@', asmfile);
1696	  CHARS (1);
1697	  dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1698	  putc (',', asmfile);
1699	  CHARS (1);
1700	  dbxout_type (TREE_TYPE (type), 0);
1701	}
1702      else
1703	/* Should print as an int, because it is really just an offset.  */
1704	dbxout_type (integer_type_node, 0);
1705      break;
1706
1707    case REFERENCE_TYPE:
1708      if (use_gnu_debug_info_extensions)
1709	have_used_extensions = 1;
1710      putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1711      CHARS (1);
1712      dbxout_type (TREE_TYPE (type), 0);
1713      break;
1714
1715    case FUNCTION_TYPE:
1716      putc ('f', asmfile);
1717      CHARS (1);
1718      dbxout_type (TREE_TYPE (type), 0);
1719      break;
1720
1721    default:
1722      abort ();
1723    }
1724}
1725
1726/* Print the value of integer constant C, in octal,
1727   handling double precision.  */
1728
1729static void
1730print_int_cst_octal (c)
1731     tree c;
1732{
1733  unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1734  unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1735  int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1736  unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1737
1738  /* GDB wants constants with no extra leading "1" bits, so
1739     we need to remove any sign-extension that might be
1740     present.  */
1741  if (width == HOST_BITS_PER_WIDE_INT * 2)
1742    ;
1743  else if (width > HOST_BITS_PER_WIDE_INT)
1744    high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1745  else if (width == HOST_BITS_PER_WIDE_INT)
1746    high = 0;
1747  else
1748    high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1749
1750  fprintf (asmfile, "0");
1751  CHARS (1);
1752
1753  if (excess == 3)
1754    {
1755      print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1756      print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1757    }
1758  else
1759    {
1760      unsigned HOST_WIDE_INT beg = high >> excess;
1761      unsigned HOST_WIDE_INT middle
1762	= ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1763	   | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1764      unsigned HOST_WIDE_INT end
1765	= low & (((unsigned HOST_WIDE_INT) 1
1766		  << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1767		 - 1);
1768
1769      fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1770      CHARS (2);
1771      print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1772    }
1773}
1774
1775static void
1776print_octal (value, digits)
1777     unsigned HOST_WIDE_INT value;
1778     int digits;
1779{
1780  int i;
1781
1782  for (i = digits - 1; i >= 0; i--)
1783    fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1784
1785  CHARS (digits);
1786}
1787
1788/* Output C in decimal while adjusting the number of digits written.  */
1789
1790static void
1791print_wide_int (c)
1792     HOST_WIDE_INT c;
1793{
1794  int digs = 0;
1795
1796  fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1797
1798  if (c < 0)
1799    digs++, c = -c;
1800
1801  while (c > 0)
1802    c /= 10; digs++;
1803
1804  CHARS (digs);
1805}
1806
1807/* Output the name of type TYPE, with no punctuation.
1808   Such names can be set up either by typedef declarations
1809   or by struct, enum and union tags.  */
1810
1811static void
1812dbxout_type_name (type)
1813     tree type;
1814{
1815  tree t;
1816  if (TYPE_NAME (type) == 0)
1817    abort ();
1818  if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1819    {
1820      t = TYPE_NAME (type);
1821    }
1822  else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1823    {
1824      t = DECL_NAME (TYPE_NAME (type));
1825    }
1826  else
1827    abort ();
1828
1829  fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1830  CHARS (IDENTIFIER_LENGTH (t));
1831}
1832
1833/* Output a .stabs for the symbol defined by DECL,
1834   which must be a ..._DECL node in the normal namespace.
1835   It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1836   LOCAL is nonzero if the scope is less than the entire file.
1837   Return 1 if a stabs might have been emitted.  */
1838
1839int
1840dbxout_symbol (decl, local)
1841     tree decl;
1842     int local ATTRIBUTE_UNUSED;
1843{
1844  tree type = TREE_TYPE (decl);
1845  tree context = NULL_TREE;
1846  int result = 0;
1847
1848  /* Cast avoids warning in old compilers.  */
1849  current_sym_code = (STAB_CODE_TYPE) 0;
1850  current_sym_value = 0;
1851  current_sym_addr = 0;
1852
1853  /* Ignore nameless syms, but don't ignore type tags.  */
1854
1855  if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1856      || DECL_IGNORED_P (decl))
1857    return 0;
1858
1859  dbxout_prepare_symbol (decl);
1860
1861  /* The output will always start with the symbol name,
1862     so always count that in the length-output-so-far.  */
1863
1864  if (DECL_NAME (decl) != 0)
1865    current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1866
1867  switch (TREE_CODE (decl))
1868    {
1869    case CONST_DECL:
1870      /* Enum values are defined by defining the enum type.  */
1871      break;
1872
1873    case FUNCTION_DECL:
1874      if (DECL_RTL (decl) == 0)
1875	return 0;
1876      if (DECL_EXTERNAL (decl))
1877	break;
1878      /* Don't mention a nested function under its parent.  */
1879      context = decl_function_context (decl);
1880      if (context == current_function_decl)
1881	break;
1882      if (GET_CODE (DECL_RTL (decl)) != MEM
1883	  || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1884	break;
1885      FORCE_TEXT;
1886
1887      fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1888	       IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1889	       TREE_PUBLIC (decl) ? 'F' : 'f');
1890      result = 1;
1891
1892      current_sym_code = N_FUN;
1893      current_sym_addr = XEXP (DECL_RTL (decl), 0);
1894
1895      if (TREE_TYPE (type))
1896	dbxout_type (TREE_TYPE (type), 0);
1897      else
1898	dbxout_type (void_type_node, 0);
1899
1900      /* For a nested function, when that function is compiled,
1901	 mention the containing function name
1902	 as well as (since dbx wants it) our own assembler-name.  */
1903      if (context != 0)
1904	fprintf (asmfile, ",%s,%s",
1905		 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1906		 IDENTIFIER_POINTER (DECL_NAME (context)));
1907
1908      dbxout_finish_symbol (decl);
1909      break;
1910
1911    case TYPE_DECL:
1912#if 0
1913      /* This seems all wrong.  Outputting most kinds of types gives no name
1914	 at all.  A true definition gives no name; a cross-ref for a
1915	 structure can give the tag name, but not a type name.
1916	 It seems that no typedef name is defined by outputting a type.  */
1917
1918      /* If this typedef name was defined by outputting the type,
1919	 don't duplicate it.  */
1920      if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
1921	  && TYPE_NAME (TREE_TYPE (decl)) == decl)
1922	return 0;
1923#endif
1924      /* Don't output the same typedef twice.
1925         And don't output what language-specific stuff doesn't want output.  */
1926      if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
1927	return 0;
1928
1929      FORCE_TEXT;
1930      result = 1;
1931      {
1932	int tag_needed = 1;
1933	int did_output = 0;
1934
1935	if (DECL_NAME (decl))
1936	  {
1937	    /* Nonzero means we must output a tag as well as a typedef.  */
1938	    tag_needed = 0;
1939
1940	    /* Handle the case of a C++ structure or union
1941	       where the TYPE_NAME is a TYPE_DECL
1942	       which gives both a typedef name and a tag.  */
1943	    /* dbx requires the tag first and the typedef second.  */
1944	    if ((TREE_CODE (type) == RECORD_TYPE
1945		 || TREE_CODE (type) == UNION_TYPE
1946		 || TREE_CODE (type) == QUAL_UNION_TYPE)
1947		&& TYPE_NAME (type) == decl
1948		&& !(use_gnu_debug_info_extensions && have_used_extensions)
1949		&& !TREE_ASM_WRITTEN (TYPE_NAME (type))
1950		/* Distinguish the implicit typedefs of C++
1951		   from explicit ones that might be found in C.  */
1952                && DECL_ARTIFICIAL (decl)
1953		/* Do not generate a tag for records of variable size,
1954		   since this type can not be properly described in the
1955		   DBX format, and it confuses some tools such as objdump.  */
1956		&& host_integerp (TYPE_SIZE (type), 1))
1957	      {
1958		tree name = TYPE_NAME (type);
1959		if (TREE_CODE (name) == TYPE_DECL)
1960		  name = DECL_NAME (name);
1961
1962		current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1963		current_sym_value = 0;
1964		current_sym_addr = 0;
1965		current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1966
1967		fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1968			 IDENTIFIER_POINTER (name));
1969		dbxout_type (type, 1);
1970		dbxout_finish_symbol (NULL_TREE);
1971	      }
1972
1973	    /* Output typedef name.  */
1974	    fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
1975		     IDENTIFIER_POINTER (DECL_NAME (decl)));
1976
1977	    /* Short cut way to output a tag also.  */
1978	    if ((TREE_CODE (type) == RECORD_TYPE
1979		 || TREE_CODE (type) == UNION_TYPE
1980		 || TREE_CODE (type) == QUAL_UNION_TYPE)
1981		&& TYPE_NAME (type) == decl
1982		/* Distinguish the implicit typedefs of C++
1983		   from explicit ones that might be found in C.  */
1984                && DECL_ARTIFICIAL (decl))
1985	      {
1986		if (use_gnu_debug_info_extensions && have_used_extensions)
1987		  {
1988		    putc ('T', asmfile);
1989		    TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1990		  }
1991#if 0 /* Now we generate the tag for this case up above.  */
1992		else
1993		  tag_needed = 1;
1994#endif
1995	      }
1996
1997	    putc ('t', asmfile);
1998	    current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1999
2000	    dbxout_type (type, 1);
2001	    dbxout_finish_symbol (decl);
2002	    did_output = 1;
2003	  }
2004
2005	/* Don't output a tag if this is an incomplete type.  This prevents
2006	   the sun4 Sun OS 4.x dbx from crashing.  */
2007
2008	if (tag_needed && TYPE_NAME (type) != 0
2009	    && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2010		|| (DECL_NAME (TYPE_NAME (type)) != 0))
2011	    && COMPLETE_TYPE_P (type)
2012	    && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2013	  {
2014	    /* For a TYPE_DECL with no name, but the type has a name,
2015	       output a tag.
2016	       This is what represents `struct foo' with no typedef.  */
2017	    /* In C++, the name of a type is the corresponding typedef.
2018	       In C, it is an IDENTIFIER_NODE.  */
2019	    tree name = TYPE_NAME (type);
2020	    if (TREE_CODE (name) == TYPE_DECL)
2021	      name = DECL_NAME (name);
2022
2023	    current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2024	    current_sym_value = 0;
2025	    current_sym_addr = 0;
2026	    current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2027
2028	    fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2029		     IDENTIFIER_POINTER (name));
2030	    dbxout_type (type, 1);
2031	    dbxout_finish_symbol (NULL_TREE);
2032	    did_output = 1;
2033	  }
2034
2035	/* If an enum type has no name, it cannot be referred to,
2036	   but we must output it anyway, since the enumeration constants
2037	   can be referred to.  */
2038	if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2039	  {
2040	    current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2041	    current_sym_value = 0;
2042	    current_sym_addr = 0;
2043	    current_sym_nchars = 2;
2044
2045	    /* Some debuggers fail when given NULL names, so give this a
2046	       harmless name of ` '.  */
2047	    fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2048	    dbxout_type (type, 1);
2049	    dbxout_finish_symbol (NULL_TREE);
2050	  }
2051
2052	/* Prevent duplicate output of a typedef.  */
2053	TREE_ASM_WRITTEN (decl) = 1;
2054	break;
2055      }
2056
2057    case PARM_DECL:
2058      /* Parm decls go in their own separate chains
2059	 and are output by dbxout_reg_parms and dbxout_parms.  */
2060      abort ();
2061
2062    case RESULT_DECL:
2063      /* Named return value, treat like a VAR_DECL.  */
2064    case VAR_DECL:
2065      if (! DECL_RTL_SET_P (decl))
2066	return 0;
2067      /* Don't mention a variable that is external.
2068	 Let the file that defines it describe it.  */
2069      if (DECL_EXTERNAL (decl))
2070	break;
2071
2072      /* If the variable is really a constant
2073	 and not written in memory, inform the debugger.  */
2074      if (TREE_STATIC (decl) && TREE_READONLY (decl)
2075	  && DECL_INITIAL (decl) != 0
2076	  && host_integerp (DECL_INITIAL (decl), 0)
2077	  && ! TREE_ASM_WRITTEN (decl)
2078	  && (DECL_CONTEXT (decl) == NULL_TREE
2079	      || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2080	{
2081	  if (TREE_PUBLIC (decl) == 0)
2082	    {
2083	      /* The sun4 assembler does not grok this.  */
2084	      const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2085
2086	      if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2087		  || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2088		{
2089		  HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2090#ifdef DBX_OUTPUT_CONSTANT_SYMBOL
2091		  DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
2092#else
2093		  fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
2094
2095		  fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
2096		  fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
2097#endif
2098		  return 1;
2099		}
2100	      else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2101		{
2102		  /* don't know how to do this yet.  */
2103		}
2104	      break;
2105	    }
2106	  /* else it is something we handle like a normal variable.  */
2107	}
2108
2109      SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2110#ifdef LEAF_REG_REMAP
2111      if (current_function_uses_only_leaf_regs)
2112	leaf_renumber_regs_insn (DECL_RTL (decl));
2113#endif
2114
2115      result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2116      break;
2117
2118    default:
2119      break;
2120    }
2121  return result;
2122}
2123
2124/* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2125   Add SUFFIX to its name, if SUFFIX is not 0.
2126   Describe the variable as residing in HOME
2127   (usually HOME is DECL_RTL (DECL), but not always).
2128   Returns 1 if the stab was really emitted.  */
2129
2130static int
2131dbxout_symbol_location (decl, type, suffix, home)
2132     tree decl, type;
2133     const char *suffix;
2134     rtx home;
2135{
2136  int letter = 0;
2137  int regno = -1;
2138
2139  /* Don't mention a variable at all
2140     if it was completely optimized into nothingness.
2141
2142     If the decl was from an inline function, then its rtl
2143     is not identically the rtl that was used in this
2144     particular compilation.  */
2145  if (GET_CODE (home) == SUBREG)
2146    {
2147      rtx value = home;
2148
2149      while (GET_CODE (value) == SUBREG)
2150	value = SUBREG_REG (value);
2151      if (GET_CODE (value) == REG)
2152	{
2153	  if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2154	    return 0;
2155	}
2156      home = alter_subreg (&home);
2157    }
2158  if (GET_CODE (home) == REG)
2159    {
2160      regno = REGNO (home);
2161      if (regno >= FIRST_PSEUDO_REGISTER)
2162	return 0;
2163    }
2164
2165  /* The kind-of-variable letter depends on where
2166     the variable is and on the scope of its name:
2167     G and N_GSYM for static storage and global scope,
2168     S for static storage and file scope,
2169     V for static storage and local scope,
2170     for those two, use N_LCSYM if data is in bss segment,
2171     N_STSYM if in data segment, N_FUN otherwise.
2172     (We used N_FUN originally, then changed to N_STSYM
2173     to please GDB.  However, it seems that confused ld.
2174     Now GDB has been fixed to like N_FUN, says Kingdon.)
2175     no letter at all, and N_LSYM, for auto variable,
2176     r and N_RSYM for register variable.  */
2177
2178  if (GET_CODE (home) == MEM
2179      && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2180    {
2181      if (TREE_PUBLIC (decl))
2182	{
2183	  letter = 'G';
2184	  current_sym_code = N_GSYM;
2185	}
2186      else
2187	{
2188	  current_sym_addr = XEXP (home, 0);
2189
2190	  letter = decl_function_context (decl) ? 'V' : 'S';
2191
2192	  /* This should be the same condition as in assemble_variable, but
2193	     we don't have access to dont_output_data here.  So, instead,
2194	     we rely on the fact that error_mark_node initializers always
2195	     end up in bss for C++ and never end up in bss for C.  */
2196	  if (DECL_INITIAL (decl) == 0
2197	      || (!strcmp (lang_hooks.name, "GNU C++")
2198		  && DECL_INITIAL (decl) == error_mark_node))
2199	    current_sym_code = N_LCSYM;
2200	  else if (DECL_IN_TEXT_SECTION (decl))
2201	    /* This is not quite right, but it's the closest
2202	       of all the codes that Unix defines.  */
2203	    current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2204	  else
2205	    {
2206	      /* Some ports can transform a symbol ref into a label ref,
2207		 because the symbol ref is too far away and has to be
2208		 dumped into a constant pool.  Alternatively, the symbol
2209		 in the constant pool might be referenced by a different
2210		 symbol.  */
2211	      if (GET_CODE (current_sym_addr) == SYMBOL_REF
2212		  && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2213		{
2214		  rtx tmp = get_pool_constant (current_sym_addr);
2215
2216		  if (GET_CODE (tmp) == SYMBOL_REF
2217		      || GET_CODE (tmp) == LABEL_REF)
2218		    current_sym_addr = tmp;
2219		}
2220
2221	      /* Ultrix `as' seems to need this.  */
2222#ifdef DBX_STATIC_STAB_DATA_SECTION
2223	      data_section ();
2224#endif
2225	      current_sym_code = N_STSYM;
2226	    }
2227	}
2228    }
2229  else if (regno >= 0)
2230    {
2231      letter = 'r';
2232      current_sym_code = N_RSYM;
2233      current_sym_value = DBX_REGISTER_NUMBER (regno);
2234    }
2235  else if (GET_CODE (home) == MEM
2236	   && (GET_CODE (XEXP (home, 0)) == MEM
2237	       || (GET_CODE (XEXP (home, 0)) == REG
2238		   && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2239		   && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2240#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2241		   && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2242#endif
2243		   )))
2244    /* If the value is indirect by memory or by a register
2245       that isn't the frame pointer
2246       then it means the object is variable-sized and address through
2247       that register or stack slot.  DBX has no way to represent this
2248       so all we can do is output the variable as a pointer.
2249       If it's not a parameter, ignore it.
2250       (VAR_DECLs like this can be made by integrate.c.)  */
2251    {
2252      if (GET_CODE (XEXP (home, 0)) == REG)
2253	{
2254	  letter = 'r';
2255	  current_sym_code = N_RSYM;
2256	  if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2257	    return 0;
2258	  current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2259	}
2260      else
2261	{
2262	  current_sym_code = N_LSYM;
2263	  /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2264	     We want the value of that CONST_INT.  */
2265	  current_sym_value
2266	    = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2267	}
2268
2269      /* Effectively do build_pointer_type, but don't cache this type,
2270	 since it might be temporary whereas the type it points to
2271	 might have been saved for inlining.  */
2272      /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
2273      type = make_node (POINTER_TYPE);
2274      TREE_TYPE (type) = TREE_TYPE (decl);
2275    }
2276  else if (GET_CODE (home) == MEM
2277	   && GET_CODE (XEXP (home, 0)) == REG)
2278    {
2279      current_sym_code = N_LSYM;
2280      current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2281    }
2282  else if (GET_CODE (home) == MEM
2283	   && GET_CODE (XEXP (home, 0)) == PLUS
2284	   && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2285    {
2286      current_sym_code = N_LSYM;
2287      /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2288	 We want the value of that CONST_INT.  */
2289      current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2290    }
2291  else if (GET_CODE (home) == MEM
2292	   && GET_CODE (XEXP (home, 0)) == CONST)
2293    {
2294      /* Handle an obscure case which can arise when optimizing and
2295	 when there are few available registers.  (This is *always*
2296	 the case for i386/i486 targets).  The RTL looks like
2297	 (MEM (CONST ...)) even though this variable is a local `auto'
2298	 or a local `register' variable.  In effect, what has happened
2299	 is that the reload pass has seen that all assignments and
2300	 references for one such a local variable can be replaced by
2301	 equivalent assignments and references to some static storage
2302	 variable, thereby avoiding the need for a register.  In such
2303	 cases we're forced to lie to debuggers and tell them that
2304	 this variable was itself `static'.  */
2305      current_sym_code = N_LCSYM;
2306      letter = 'V';
2307      current_sym_addr = XEXP (XEXP (home, 0), 0);
2308    }
2309  else if (GET_CODE (home) == CONCAT)
2310    {
2311      tree subtype;
2312
2313      /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2314	 for example), then there is no easy way to figure out
2315	 what SUBTYPE should be.  So, we give up.  */
2316      if (TREE_CODE (type) != COMPLEX_TYPE)
2317	return 0;
2318
2319      subtype = TREE_TYPE (type);
2320
2321      /* If the variable's storage is in two parts,
2322	 output each as a separate stab with a modified name.  */
2323      if (WORDS_BIG_ENDIAN)
2324	dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2325      else
2326	dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2327
2328      /* Cast avoids warning in old compilers.  */
2329      current_sym_code = (STAB_CODE_TYPE) 0;
2330      current_sym_value = 0;
2331      current_sym_addr = 0;
2332      dbxout_prepare_symbol (decl);
2333
2334      if (WORDS_BIG_ENDIAN)
2335	dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2336      else
2337	dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2338      return 1;
2339    }
2340  else
2341    /* Address might be a MEM, when DECL is a variable-sized object.
2342       Or it might be const0_rtx, meaning previous passes
2343       want us to ignore this variable.  */
2344    return 0;
2345
2346  /* Ok, start a symtab entry and output the variable name.  */
2347  FORCE_TEXT;
2348
2349#ifdef DBX_STATIC_BLOCK_START
2350  DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2351#endif
2352
2353  dbxout_symbol_name (decl, suffix, letter);
2354  dbxout_type (type, 0);
2355  dbxout_finish_symbol (decl);
2356
2357#ifdef DBX_STATIC_BLOCK_END
2358  DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2359#endif
2360  return 1;
2361}
2362
2363/* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2364   Then output LETTER to indicate the kind of location the symbol has.  */
2365
2366static void
2367dbxout_symbol_name (decl, suffix, letter)
2368     tree decl;
2369     const char *suffix;
2370     int letter;
2371{
2372  const char *name;
2373
2374  if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2375    /* One slight hitch: if this is a VAR_DECL which is a static
2376       class member, we must put out the mangled name instead of the
2377       DECL_NAME.  Note also that static member (variable) names DO NOT begin
2378       with underscores in .stabs directives.  */
2379    name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2380  else
2381    /* ...but if we're function-local, we don't want to include the junk
2382       added by ASM_FORMAT_PRIVATE_NAME.  */
2383    name = IDENTIFIER_POINTER (DECL_NAME (decl));
2384
2385  if (name == 0)
2386    name = "(anon)";
2387  fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2388	   (suffix ? suffix : ""));
2389
2390  if (letter)
2391    putc (letter, asmfile);
2392}
2393
2394static void
2395dbxout_prepare_symbol (decl)
2396     tree decl ATTRIBUTE_UNUSED;
2397{
2398#ifdef WINNING_GDB
2399  const char *filename = DECL_SOURCE_FILE (decl);
2400
2401  dbxout_source_file (asmfile, filename);
2402#endif
2403}
2404
2405static void
2406dbxout_finish_symbol (sym)
2407     tree sym;
2408{
2409#ifdef DBX_FINISH_SYMBOL
2410  DBX_FINISH_SYMBOL (sym);
2411#else
2412  int line = 0;
2413  if (use_gnu_debug_info_extensions && sym != 0)
2414    line = DECL_SOURCE_LINE (sym);
2415
2416  fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2417  if (current_sym_addr)
2418    output_addr_const (asmfile, current_sym_addr);
2419  else
2420    fprintf (asmfile, "%d", current_sym_value);
2421  putc ('\n', asmfile);
2422#endif
2423}
2424
2425/* Output definitions of all the decls in a chain. Return non-zero if
2426   anything was output */
2427
2428int
2429dbxout_syms (syms)
2430     tree syms;
2431{
2432  int result = 0;
2433  while (syms)
2434    {
2435      result += dbxout_symbol (syms, 1);
2436      syms = TREE_CHAIN (syms);
2437    }
2438  return result;
2439}
2440
2441/* The following two functions output definitions of function parameters.
2442   Each parameter gets a definition locating it in the parameter list.
2443   Each parameter that is a register variable gets a second definition
2444   locating it in the register.
2445
2446   Printing or argument lists in gdb uses the definitions that
2447   locate in the parameter list.  But reference to the variable in
2448   expressions uses preferentially the definition as a register.  */
2449
2450/* Output definitions, referring to storage in the parmlist,
2451   of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
2452
2453void
2454dbxout_parms (parms)
2455     tree parms;
2456{
2457  for (; parms; parms = TREE_CHAIN (parms))
2458    if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2459      {
2460	dbxout_prepare_symbol (parms);
2461
2462	/* Perform any necessary register eliminations on the parameter's rtl,
2463	   so that the debugging output will be accurate.  */
2464	DECL_INCOMING_RTL (parms)
2465	  = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2466	SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2467#ifdef LEAF_REG_REMAP
2468	if (current_function_uses_only_leaf_regs)
2469	  {
2470	    leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2471	    leaf_renumber_regs_insn (DECL_RTL (parms));
2472	  }
2473#endif
2474
2475	if (PARM_PASSED_IN_MEMORY (parms))
2476	  {
2477	    rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2478
2479	    /* ??? Here we assume that the parm address is indexed
2480	       off the frame pointer or arg pointer.
2481	       If that is not true, we produce meaningless results,
2482	       but do not crash.  */
2483	    if (GET_CODE (addr) == PLUS
2484		&& GET_CODE (XEXP (addr, 1)) == CONST_INT)
2485	      current_sym_value = INTVAL (XEXP (addr, 1));
2486	    else
2487	      current_sym_value = 0;
2488
2489	    current_sym_code = N_PSYM;
2490	    current_sym_addr = 0;
2491
2492	    FORCE_TEXT;
2493	    if (DECL_NAME (parms))
2494	      {
2495		current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2496
2497		fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2498			 IDENTIFIER_POINTER (DECL_NAME (parms)),
2499			 DBX_MEMPARM_STABS_LETTER);
2500	      }
2501	    else
2502	      {
2503		current_sym_nchars = 8;
2504		fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2505			 DBX_MEMPARM_STABS_LETTER);
2506	      }
2507
2508	    /* It is quite tempting to use:
2509
2510	           dbxout_type (TREE_TYPE (parms), 0);
2511
2512	       as the next statement, rather than using DECL_ARG_TYPE(), so
2513	       that gcc reports the actual type of the parameter, rather
2514	       than the promoted type.  This certainly makes GDB's life
2515	       easier, at least for some ports.  The change is a bad idea
2516	       however, since GDB expects to be able access the type without
2517	       performing any conversions.  So for example, if we were
2518	       passing a float to an unprototyped function, gcc will store a
2519	       double on the stack, but if we emit a stab saying the type is a
2520	       float, then gdb will only read in a single value, and this will
2521	       produce an erroneous value.  */
2522 	    dbxout_type (DECL_ARG_TYPE (parms), 0);
2523	    current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2524	    dbxout_finish_symbol (parms);
2525	  }
2526	else if (GET_CODE (DECL_RTL (parms)) == REG)
2527	  {
2528	    rtx best_rtl;
2529	    char regparm_letter;
2530	    tree parm_type;
2531	    /* Parm passed in registers and lives in registers or nowhere.  */
2532
2533	    current_sym_code = DBX_REGPARM_STABS_CODE;
2534	    regparm_letter = DBX_REGPARM_STABS_LETTER;
2535	    current_sym_addr = 0;
2536
2537	    /* If parm lives in a register, use that register;
2538	       pretend the parm was passed there.  It would be more consistent
2539	       to describe the register where the parm was passed,
2540	       but in practice that register usually holds something else.
2541
2542	       If we use DECL_RTL, then we must use the declared type of
2543	       the variable, not the type that it arrived in.  */
2544	    if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2545	      {
2546		best_rtl = DECL_RTL (parms);
2547		parm_type = TREE_TYPE (parms);
2548	      }
2549	    /* If the parm lives nowhere, use the register where it was
2550	       passed.  It is also better to use the declared type here.  */
2551	    else
2552	      {
2553		best_rtl = DECL_INCOMING_RTL (parms);
2554		parm_type = TREE_TYPE (parms);
2555	      }
2556	    current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2557
2558	    FORCE_TEXT;
2559	    if (DECL_NAME (parms))
2560	      {
2561		current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2562		fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2563			 IDENTIFIER_POINTER (DECL_NAME (parms)),
2564			 regparm_letter);
2565	      }
2566	    else
2567	      {
2568		current_sym_nchars = 8;
2569		fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2570			 regparm_letter);
2571	      }
2572
2573	    dbxout_type (parm_type, 0);
2574	    dbxout_finish_symbol (parms);
2575	  }
2576	else if (GET_CODE (DECL_RTL (parms)) == MEM
2577		 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2578		 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2579		 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2580#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2581		 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2582#endif
2583		 )
2584	  {
2585	    /* Parm was passed via invisible reference.
2586	       That is, its address was passed in a register.
2587	       Output it as if it lived in that register.
2588	       The debugger will know from the type
2589	       that it was actually passed by invisible reference.  */
2590
2591	    char regparm_letter;
2592	    /* Parm passed in registers and lives in registers or nowhere.  */
2593
2594	    current_sym_code = DBX_REGPARM_STABS_CODE;
2595	    if (use_gnu_debug_info_extensions)
2596	      regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2597	    else
2598	      regparm_letter = DBX_REGPARM_STABS_LETTER;
2599
2600	    /* DECL_RTL looks like (MEM (REG...).  Get the register number.
2601	       If it is an unallocated pseudo-reg, then use the register where
2602	       it was passed instead.  */
2603	    if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2604	      current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2605	    else
2606	      current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2607
2608	    current_sym_addr = 0;
2609
2610	    FORCE_TEXT;
2611	    if (DECL_NAME (parms))
2612	      {
2613		current_sym_nchars
2614		  = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2615
2616		fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2617			 IDENTIFIER_POINTER (DECL_NAME (parms)),
2618			 regparm_letter);
2619	      }
2620	    else
2621	      {
2622		current_sym_nchars = 8;
2623		fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2624			 regparm_letter);
2625	      }
2626
2627	    dbxout_type (TREE_TYPE (parms), 0);
2628	    dbxout_finish_symbol (parms);
2629	  }
2630	else if (GET_CODE (DECL_RTL (parms)) == MEM
2631		 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2632	  {
2633	    /* Parm was passed via invisible reference, with the reference
2634	       living on the stack.  DECL_RTL looks like
2635	       (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2636	       could look like (MEM (MEM (REG))).  */
2637	    const char *const decl_name = (DECL_NAME (parms)
2638				     ? IDENTIFIER_POINTER (DECL_NAME (parms))
2639				     : "(anon)");
2640           if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2641              current_sym_value = 0;
2642	    else
2643	      current_sym_value
2644	        = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2645	    current_sym_addr = 0;
2646
2647	    FORCE_TEXT;
2648	    fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2649
2650	    current_sym_value
2651	      = DEBUGGER_ARG_OFFSET (current_sym_value,
2652				     XEXP (XEXP (DECL_RTL (parms), 0), 0));
2653	    dbxout_type (TREE_TYPE (parms), 0);
2654	    dbxout_finish_symbol (parms);
2655	  }
2656	else if (GET_CODE (DECL_RTL (parms)) == MEM
2657		 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2658		 /* ??? A constant address for a parm can happen
2659		    when the reg it lives in is equiv to a constant in memory.
2660		    Should make this not happen, after 2.4.  */
2661		 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2662	  {
2663	    /* Parm was passed in registers but lives on the stack.  */
2664
2665	    current_sym_code = N_PSYM;
2666	    /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2667	       in which case we want the value of that CONST_INT,
2668	       or (MEM (REG ...)),
2669	       in which case we use a value of zero.  */
2670	    if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2671	      current_sym_value = 0;
2672	    else
2673		current_sym_value
2674		  = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2675
2676	    current_sym_addr = 0;
2677
2678	    /* Make a big endian correction if the mode of the type of the
2679	       parameter is not the same as the mode of the rtl.  */
2680	    if (BYTES_BIG_ENDIAN
2681		&& TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2682		&& GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2683	      {
2684		current_sym_value +=
2685		    GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2686		    - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2687	      }
2688
2689	    FORCE_TEXT;
2690	    if (DECL_NAME (parms))
2691	      {
2692		current_sym_nchars
2693		  = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2694
2695		fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2696			 IDENTIFIER_POINTER (DECL_NAME (parms)),
2697			 DBX_MEMPARM_STABS_LETTER);
2698	      }
2699	    else
2700	      {
2701		current_sym_nchars = 8;
2702		fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2703		DBX_MEMPARM_STABS_LETTER);
2704	      }
2705
2706	    current_sym_value
2707	      = DEBUGGER_ARG_OFFSET (current_sym_value,
2708				     XEXP (DECL_RTL (parms), 0));
2709	    dbxout_type (TREE_TYPE (parms), 0);
2710	    dbxout_finish_symbol (parms);
2711	  }
2712      }
2713}
2714
2715/* Output definitions for the places where parms live during the function,
2716   when different from where they were passed, when the parms were passed
2717   in memory.
2718
2719   It is not useful to do this for parms passed in registers
2720   that live during the function in different registers, because it is
2721   impossible to look in the passed register for the passed value,
2722   so we use the within-the-function register to begin with.
2723
2724   PARMS is a chain of PARM_DECL nodes.  */
2725
2726void
2727dbxout_reg_parms (parms)
2728     tree parms;
2729{
2730  for (; parms; parms = TREE_CHAIN (parms))
2731    if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2732      {
2733	dbxout_prepare_symbol (parms);
2734
2735	/* Report parms that live in registers during the function
2736	   but were passed in memory.  */
2737	if (GET_CODE (DECL_RTL (parms)) == REG
2738	    && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2739	  dbxout_symbol_location (parms, TREE_TYPE (parms),
2740				  0, DECL_RTL (parms));
2741	else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2742	  dbxout_symbol_location (parms, TREE_TYPE (parms),
2743				  0, DECL_RTL (parms));
2744	/* Report parms that live in memory but not where they were passed.  */
2745	else if (GET_CODE (DECL_RTL (parms)) == MEM
2746		 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2747	  dbxout_symbol_location (parms, TREE_TYPE (parms),
2748				  0, DECL_RTL (parms));
2749      }
2750}
2751
2752/* Given a chain of ..._TYPE nodes (as come in a parameter list),
2753   output definitions of those names, in raw form */
2754
2755static void
2756dbxout_args (args)
2757     tree args;
2758{
2759  while (args)
2760    {
2761      putc (',', asmfile);
2762      dbxout_type (TREE_VALUE (args), 0);
2763      CHARS (1);
2764      args = TREE_CHAIN (args);
2765    }
2766}
2767
2768/* Output everything about a symbol block (a BLOCK node
2769   that represents a scope level),
2770   including recursive output of contained blocks.
2771
2772   BLOCK is the BLOCK node.
2773   DEPTH is its depth within containing symbol blocks.
2774   ARGS is usually zero; but for the outermost block of the
2775   body of a function, it is a chain of PARM_DECLs for the function parameters.
2776   We output definitions of all the register parms
2777   as if they were local variables of that block.
2778
2779   If -g1 was used, we count blocks just the same, but output nothing
2780   except for the outermost block.
2781
2782   Actually, BLOCK may be several blocks chained together.
2783   We handle them all in sequence.  */
2784
2785static void
2786dbxout_block (block, depth, args)
2787     tree block;
2788     int depth;
2789     tree args;
2790{
2791  int blocknum = -1;
2792
2793#if DBX_BLOCKS_FUNCTION_RELATIVE
2794  const char *begin_label;
2795  if (current_function_func_begin_label != NULL_TREE)
2796    begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2797  else
2798    begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2799#endif
2800
2801  while (block)
2802    {
2803      /* Ignore blocks never expanded or otherwise marked as real.  */
2804      if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2805	{
2806	  int did_output;
2807
2808#ifdef DBX_LBRAC_FIRST
2809	  did_output = 1;
2810#else
2811	  /* In dbx format, the syms of a block come before the N_LBRAC.
2812	     If nothing is output, we don't need the N_LBRAC, either.  */
2813	  did_output = 0;
2814	  if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2815	    did_output = dbxout_syms (BLOCK_VARS (block));
2816	  if (args)
2817	    dbxout_reg_parms (args);
2818#endif
2819
2820	  /* Now output an N_LBRAC symbol to represent the beginning of
2821	     the block.  Use the block's tree-walk order to generate
2822	     the assembler symbols LBBn and LBEn
2823	     that final will define around the code in this block.  */
2824	  if (depth > 0 && did_output)
2825	    {
2826	      char buf[20];
2827	      blocknum = BLOCK_NUMBER (block);
2828	      ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2829
2830	      if (BLOCK_HANDLER_BLOCK (block))
2831		{
2832		  /* A catch block.  Must precede N_LBRAC.  */
2833		  tree decl = BLOCK_VARS (block);
2834		  while (decl)
2835		    {
2836#ifdef DBX_OUTPUT_CATCH
2837		      DBX_OUTPUT_CATCH (asmfile, decl, buf);
2838#else
2839		      fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2840			       IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2841		      assemble_name (asmfile, buf);
2842		      fprintf (asmfile, "\n");
2843#endif
2844		      decl = TREE_CHAIN (decl);
2845		    }
2846		}
2847
2848#ifdef DBX_OUTPUT_LBRAC
2849	      DBX_OUTPUT_LBRAC (asmfile, buf);
2850#else
2851	      fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2852	      assemble_name (asmfile, buf);
2853#if DBX_BLOCKS_FUNCTION_RELATIVE
2854	      putc ('-', asmfile);
2855	      assemble_name (asmfile, begin_label);
2856#endif
2857	      fprintf (asmfile, "\n");
2858#endif
2859	    }
2860
2861#ifdef DBX_LBRAC_FIRST
2862	  /* On some weird machines, the syms of a block
2863	     come after the N_LBRAC.  */
2864	  if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2865	    dbxout_syms (BLOCK_VARS (block));
2866	  if (args)
2867	    dbxout_reg_parms (args);
2868#endif
2869
2870	  /* Output the subblocks.  */
2871	  dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2872
2873	  /* Refer to the marker for the end of the block.  */
2874	  if (depth > 0 && did_output)
2875	    {
2876	      char buf[20];
2877	      ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2878#ifdef DBX_OUTPUT_RBRAC
2879	      DBX_OUTPUT_RBRAC (asmfile, buf);
2880#else
2881	      fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2882	      assemble_name (asmfile, buf);
2883#if DBX_BLOCKS_FUNCTION_RELATIVE
2884	      putc ('-', asmfile);
2885	      assemble_name (asmfile, begin_label);
2886#endif
2887	      fprintf (asmfile, "\n");
2888#endif
2889	    }
2890	}
2891      block = BLOCK_CHAIN (block);
2892    }
2893}
2894
2895/* Output the information about a function and its arguments and result.
2896   Usually this follows the function's code,
2897   but on some systems, it comes before.  */
2898
2899#if defined (DBX_DEBUGGING_INFO)
2900static void
2901dbxout_begin_function (decl)
2902     tree decl;
2903{
2904  dbxout_symbol (decl, 0);
2905  dbxout_parms (DECL_ARGUMENTS (decl));
2906  if (DECL_NAME (DECL_RESULT (decl)) != 0)
2907    dbxout_symbol (DECL_RESULT (decl), 1);
2908}
2909#endif /* DBX_DEBUGGING_INFO */
2910
2911#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
2912