OSDN Git Service

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