OSDN Git Service

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