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