OSDN Git Service

(dbxout_symbol): For anonymous enum, output type anyway.
[pf3gnuchains/gcc-fork.git] / gcc / dbxout.c
1 /* Output dbx-format symbol table information from GNU compiler.
2    Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20
21 /* Output dbx-format symbol table data.
22    This consists of many symbol table entries, each of them
23    a .stabs assembler pseudo-op with four operands:
24    a "name" which is really a description of one symbol and its type,
25    a "code", which is a symbol defined in stab.h whose name starts with N_,
26    an unused operand always 0,
27    and a "value" which is an address or an offset.
28    The name is enclosed in doublequote characters.
29
30    Each function, variable, typedef, and structure tag
31    has a symbol table entry to define it.
32    The beginning and end of each level of name scoping within
33    a function are also marked by special symbol table entries.
34
35    The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
36    and a data type number.  The data type number may be followed by
37    "=" and a type definition; normally this will happen the first time
38    the type number is mentioned.  The type definition may refer to
39    other types by number, and those type numbers may be followed
40    by "=" and nested definitions.
41
42    This can make the "name" quite long.
43    When a name is more than 80 characters, we split the .stabs pseudo-op
44    into two .stabs pseudo-ops, both sharing the same "code" and "value".
45    The first one is marked as continued with a double-backslash at the
46    end of its "name".
47
48    The kind-of-symbol letter distinguished function names from global
49    variables from file-scope variables from parameters from auto
50    variables in memory from typedef names from register variables.
51    See `dbxout_symbol'.
52
53    The "code" is mostly redundant with the kind-of-symbol letter
54    that goes in the "name", but not entirely: for symbols located
55    in static storage, the "code" says which segment the address is in,
56    which controls how it is relocated.
57
58    The "value" for a symbol in static storage
59    is the core address of the symbol (actually, the assembler
60    label for the symbol).  For a symbol located in a stack slot
61    it is the stack offset; for one in a register, the register number.
62    For a typedef symbol, it is zero.
63
64    If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
65    output while in the text section.
66
67    For more on data type definitions, see `dbxout_type'.  */
68
69 /* Include these first, because they may define MIN and MAX.  */
70 #include <stdio.h>
71 #include <errno.h>
72
73 #include "config.h"
74 #include "tree.h"
75 #include "rtl.h"
76 #include "flags.h"
77 #include "regs.h"
78 #include "insn-config.h"
79 #include "reload.h"
80 #include "defaults.h"
81 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions.  */
82
83 #ifndef errno
84 extern int errno;
85 #endif
86
87 #ifdef XCOFF_DEBUGGING_INFO
88 #include "xcoffout.h"
89 #endif
90
91 #ifndef ASM_STABS_OP
92 #define ASM_STABS_OP ".stabs"
93 #endif
94
95 #ifndef ASM_STABN_OP
96 #define ASM_STABN_OP ".stabn"
97 #endif
98
99 #ifndef DBX_TYPE_DECL_STABS_CODE
100 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
101 #endif
102
103 #ifndef DBX_STATIC_CONST_VAR_CODE
104 #define DBX_STATIC_CONST_VAR_CODE N_FUN
105 #endif
106
107 #ifndef DBX_REGPARM_STABS_CODE
108 #define DBX_REGPARM_STABS_CODE N_RSYM
109 #endif
110
111 #ifndef DBX_REGPARM_STABS_LETTER
112 #define DBX_REGPARM_STABS_LETTER 'P'
113 #endif
114
115 #ifndef DBX_MEMPARM_STABS_LETTER
116 #define DBX_MEMPARM_STABS_LETTER 'p'
117 #endif
118
119 /* Nonzero means if the type has methods, only output debugging
120    information if methods are actually written to the asm file.  */
121
122 static int flag_minimal_debug = 1;
123
124 /* Nonzero if we have actually used any of the GDB extensions
125    to the debugging format.  The idea is that we use them for the
126    first time only if there's a strong reason, but once we have done that,
127    we use them whenever convenient.  */
128
129 static int have_used_extensions = 0;
130
131 char *getpwd ();
132
133 /* Typical USG systems don't have stab.h, and they also have
134    no use for DBX-format debugging info.  */
135
136 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
137
138 #ifdef DEBUG_SYMS_TEXT
139 #define FORCE_TEXT text_section ();
140 #else
141 #define FORCE_TEXT
142 #endif
143
144 #if defined (USG) || defined (NO_STAB_H)
145 #include "gstab.h"  /* If doing DBX on sysV, use our own stab.h.  */
146 #else
147 #include <stab.h>  /* On BSD, use the system's stab.h.  */
148
149 /* This is a GNU extension we need to reference in this file.  */
150 #ifndef N_CATCH
151 #define N_CATCH 0x54
152 #endif
153 #endif /* not USG */
154
155 #ifdef __GNU_STAB__
156 #define STAB_CODE_TYPE enum __stab_debug_code
157 #else
158 #define STAB_CODE_TYPE int
159 #endif
160
161 /* 1 if PARM is passed to this function in memory.  */
162
163 #define PARM_PASSED_IN_MEMORY(PARM) \
164  (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
165
166 /* A C expression for the integer offset value of an automatic variable
167    (N_LSYM) having address X (an RTX).  */
168 #ifndef DEBUGGER_AUTO_OFFSET
169 #define DEBUGGER_AUTO_OFFSET(X) \
170   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
171 #endif
172
173 /* A C expression for the integer offset value of an argument (N_PSYM)
174    having address X (an RTX).  The nominal offset is OFFSET.  */
175 #ifndef DEBUGGER_ARG_OFFSET
176 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
177 #endif
178
179 /* Stream for writing to assembler file.  */
180
181 static FILE *asmfile;
182
183 /* Last source file name mentioned in a NOTE insn.  */
184
185 static char *lastfile;
186
187 /* Current working directory.  */
188
189 static char *cwd;
190
191 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
192
193 /* Vector recording the status of describing C data types.
194    When we first notice a data type (a tree node),
195    we assign it a number using next_type_number.
196    That is its index in this vector.
197    The vector element says whether we have yet output
198    the definition of the type.  TYPE_XREF says we have
199    output it as a cross-reference only.  */
200
201 enum typestatus *typevec;
202
203 /* Number of elements of space allocated in `typevec'.  */
204
205 static int typevec_len;
206
207 /* In dbx output, each type gets a unique number.
208    This is the number for the next type output.
209    The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
210
211 static int next_type_number;
212
213 /* In dbx output, we must assign symbol-blocks id numbers
214    in the order in which their beginnings are encountered.
215    We output debugging info that refers to the beginning and
216    end of the ranges of code in each block
217    with assembler labels LBBn and LBEn, where n is the block number.
218    The labels are generated in final, which assigns numbers to the
219    blocks in the same way.  */
220
221 static int next_block_number;
222
223 /* These variables are for dbxout_symbol to communicate to
224    dbxout_finish_symbol.
225    current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
226    current_sym_value and current_sym_addr are two ways to address the
227    value to store in the symtab entry.
228    current_sym_addr if nonzero represents the value as an rtx.
229    If that is zero, current_sym_value is used.  This is used
230    when the value is an offset (such as for auto variables,
231    register variables and parms).  */
232
233 static STAB_CODE_TYPE current_sym_code;
234 static int current_sym_value;
235 static rtx current_sym_addr;
236
237 /* Number of chars of symbol-description generated so far for the
238    current symbol.  Used by CHARS and CONTIN.  */
239
240 static int current_sym_nchars;
241
242 /* Report having output N chars of the current symbol-description.  */
243
244 #define CHARS(N) (current_sym_nchars += (N))
245
246 /* Break the current symbol-description, generating a continuation,
247    if it has become long.  */
248
249 #ifndef DBX_CONTIN_LENGTH
250 #define DBX_CONTIN_LENGTH 80
251 #endif
252
253 #if DBX_CONTIN_LENGTH > 0
254 #define CONTIN  \
255   do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
256 #else
257 #define CONTIN
258 #endif
259
260 void dbxout_types ();
261 void dbxout_args ();
262 void dbxout_symbol ();
263 static void dbxout_type_name ();
264 static void dbxout_type ();
265 static void dbxout_typedefs ();
266 static void dbxout_prepare_symbol ();
267 static void dbxout_finish_symbol ();
268 static void dbxout_continue ();
269 static void print_int_cst_octal ();
270 static void print_octal ();
271 \f
272 #if 0 /* Not clear we will actually need this.  */
273
274 /* Return the absolutized filename for the given relative
275    filename.  Note that if that filename is already absolute, it may
276    still be returned in a modified form because this routine also
277    eliminates redundant slashes and single dots and eliminates double
278    dots to get a shortest possible filename from the given input
279    filename.  The absolutization of relative filenames is made by
280    assuming that the given filename is to be taken as relative to
281    the first argument (cwd) or to the current directory if cwd is
282    NULL.  */
283
284 static char *
285 abspath (rel_filename)
286      char *rel_filename;
287 {
288   /* Setup the current working directory as needed.  */
289   char *abs_buffer
290     = (char *) alloca (strlen (cwd) + strlen (rel_filename) + 1);
291   char *endp = abs_buffer;
292   char *outp, *inp;
293   char *value;
294
295   /* Copy the filename (possibly preceded by the current working
296      directory name) into the absolutization buffer.  */
297
298   {
299     char *src_p;
300
301     if (rel_filename[0] != '/')
302       {
303         src_p = cwd;
304         while (*endp++ = *src_p++)
305           continue;
306         *(endp-1) = '/';                        /* overwrite null */
307       }
308     src_p = rel_filename;
309     while (*endp++ = *src_p++)
310       continue;
311     if (endp[-1] == '/')
312       *endp = '\0';
313
314   /* Now make a copy of abs_buffer into abs_buffer, shortening the
315      filename (by taking out slashes and dots) as we go.  */
316
317   outp = inp = abs_buffer;
318   *outp++ = *inp++;             /* copy first slash */
319   for (;;)
320     {
321       if (!inp[0])
322         break;
323       else if (inp[0] == '/' && outp[-1] == '/')
324         {
325           inp++;
326           continue;
327         }
328       else if (inp[0] == '.' && outp[-1] == '/')
329         {
330           if (!inp[1])
331                   break;
332           else if (inp[1] == '/')
333             {
334                     inp += 2;
335                     continue;
336             }
337           else if ((inp[1] == '.') && (inp[2] == 0 || inp[2] == '/'))
338             {
339                     inp += (inp[2] == '/') ? 3 : 2;
340                     outp -= 2;
341                     while (outp >= abs_buffer && *outp != '/')
342                 outp--;
343                     if (outp < abs_buffer)
344                 {
345                   /* Catch cases like /.. where we try to backup to a
346                      point above the absolute root of the logical file
347                      system.  */
348
349                   fprintf (stderr, "%s: invalid file name: %s\n",
350                            pname, rel_filename);
351                   exit (1);
352                 }
353                     *++outp = '\0';
354                     continue;
355             }
356         }
357       *outp++ = *inp++;
358     }
359
360   /* On exit, make sure that there is a trailing null, and make sure that
361      the last character of the returned string is *not* a slash.  */
362
363   *outp = '\0';
364   if (outp[-1] == '/')
365     *--outp  = '\0';
366
367   /* Make a copy (in the heap) of the stuff left in the absolutization
368      buffer and return a pointer to the copy.  */
369
370   value = (char *) oballoc (strlen (abs_buffer) + 1);
371   strcpy (value, abs_buffer);
372   return value;
373 }
374 #endif /* 0 */
375 \f
376 /* At the beginning of compilation, start writing the symbol table.
377    Initialize `typevec' and output the standard data types of C.  */
378
379 void
380 dbxout_init (asm_file, input_file_name, syms)
381      FILE *asm_file;
382      char *input_file_name;
383      tree syms;
384 {
385   char ltext_label_name[100];
386
387   asmfile = asm_file;
388
389   typevec_len = 100;
390   typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]);
391   bzero (typevec, typevec_len * sizeof typevec[0]);
392
393   /* Convert Ltext into the appropriate format for local labels in case
394      the system doesn't insert underscores in front of user generated
395      labels.  */
396   ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
397
398   /* Put the current working directory in an N_SO symbol.  */
399 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
400                                  but GDB always does.  */
401   if (use_gnu_debug_info_extensions)
402 #endif
403     {
404       if (cwd || (cwd = getpwd ()))
405         {
406 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
407           DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
408 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
409           fprintf (asmfile, "%s \"%s/\",%d,0,0,%s\n", ASM_STABS_OP,
410                    cwd, N_SO, &ltext_label_name[1]);
411 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
412         }
413     }
414
415 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
416   /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
417      would give us an N_SOL, and we want an N_SO.  */
418   DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
419 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
420   /* We include outputting `Ltext:' here,
421      because that gives you a way to override it.  */
422   /* Used to put `Ltext:' before the reference, but that loses on sun 4.  */
423   fprintf (asmfile, "%s \"%s\",%d,0,0,%s\n", ASM_STABS_OP, input_file_name,
424            N_SO, &ltext_label_name[1]);
425   text_section ();
426   ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
427 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
428
429   /* Possibly output something to inform GDB that this compilation was by
430      GCC.  It's easier for GDB to parse it when after the N_SO's.  This
431      is used in Solaris 2.  */
432 #ifdef ASM_IDENTIFY_GCC_AFTER_SOURCE
433   ASM_IDENTIFY_GCC_AFTER_SOURCE (asmfile);
434 #endif
435
436   lastfile = input_file_name;
437
438   next_type_number = 1;
439   next_block_number = 2;
440
441   /* Make sure that types `int' and `char' have numbers 1 and 2.
442      Definitions of other integer types will refer to those numbers.
443      (Actually it should no longer matter what their numbers are.
444      Also, if any types with tags have been defined, dbxout_symbol
445      will output them first, so the numbers won't be 1 and 2.  That
446      happens in C++.  So it's a good thing it should no longer matter).  */
447
448 #ifdef DBX_OUTPUT_STANDARD_TYPES
449   DBX_OUTPUT_STANDARD_TYPES (syms);
450 #else
451   dbxout_symbol (TYPE_NAME (integer_type_node), 0);
452   dbxout_symbol (TYPE_NAME (char_type_node), 0);
453 #endif
454
455   /* Get all permanent types that have typedef names,
456      and output them all, except for those already output.  */
457
458   dbxout_typedefs (syms);
459 }
460
461 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
462    in the reverse order from that which is found in SYMS.  */
463
464 static void
465 dbxout_typedefs (syms)
466      tree syms;
467 {
468   if (syms)
469     {
470       dbxout_typedefs (TREE_CHAIN (syms));
471       if (TREE_CODE (syms) == TYPE_DECL)
472         {
473           tree type = TREE_TYPE (syms);
474           if (TYPE_NAME (type)
475               && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
476               && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
477             dbxout_symbol (TYPE_NAME (type), 0);
478         }
479     }
480 }
481
482 /* Output debugging info to FILE to switch to sourcefile FILENAME.  */
483
484 void
485 dbxout_source_file (file, filename)
486      FILE *file;
487      char *filename;
488 {
489   char ltext_label_name[100];
490
491   if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
492     {
493 #ifdef DBX_OUTPUT_SOURCE_FILENAME
494       DBX_OUTPUT_SOURCE_FILENAME (file, filename);
495 #else
496       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
497       fprintf (file, "%s \"%s\",%d,0,0,%s\n", ASM_STABS_OP,
498                filename, N_SOL, &ltext_label_name[1]);
499 #endif
500       lastfile = filename;
501     }
502 }
503
504 /* Output a line number symbol entry into output stream FILE, 
505    for source file FILENAME and line number LINENO.  */
506
507 void
508 dbxout_source_line (file, filename, lineno)
509      FILE *file;
510      char *filename;
511      int lineno;
512 {
513   dbxout_source_file (file, filename);
514
515 #ifdef ASM_OUTPUT_SOURCE_LINE
516   ASM_OUTPUT_SOURCE_LINE (file, lineno);
517 #else
518   fprintf (file, "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
519 #endif
520 }
521
522 /* At the end of compilation, finish writing the symbol table.
523    Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
524    to do nothing. */
525
526 void
527 dbxout_finish (file, filename)
528      FILE *file;
529      char *filename;
530 {
531 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
532   DBX_OUTPUT_MAIN_SOURCE_FILE_END (file, filename);
533 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
534 }
535
536 /* Continue a symbol-description that gets too big.
537    End one symbol table entry with a double-backslash
538    and start a new one, eventually producing something like
539    .stabs "start......\\",code,0,value
540    .stabs "...rest",code,0,value   */
541
542 static void
543 dbxout_continue ()
544 {
545 #ifdef DBX_CONTIN_CHAR
546   fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
547 #else
548   fprintf (asmfile, "\\\\");
549 #endif
550   dbxout_finish_symbol (NULL_TREE);
551   fprintf (asmfile, "%s \"", ASM_STABS_OP);
552   current_sym_nchars = 0;
553 }
554 \f
555 /* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
556    This must be a separate function because anonymous unions require
557    recursive calls.  */
558
559 static void
560 dbxout_type_fields (type)
561      tree type;
562 {
563   tree tem;
564   /* Output the name, type, position (in bits), size (in bits) of each
565      field.  */
566   for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
567     {
568       /* For nameless subunions and subrecords, treat their fields as ours.  */
569       if (DECL_NAME (tem) == NULL_TREE
570           && (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
571               || TREE_CODE (TREE_TYPE (tem)) == RECORD_TYPE))
572         dbxout_type_fields (TREE_TYPE (tem));
573       /* Omit here local type decls until we know how to support them.  */
574       else if (TREE_CODE (tem) == TYPE_DECL)
575         continue;
576       /* Omit here the nameless fields that are used to skip bits.  */
577       else if (DECL_NAME (tem) != 0 && TREE_CODE (tem) != CONST_DECL)
578         {
579           /* Continue the line if necessary,
580              but not before the first field.  */
581           if (tem != TYPE_FIELDS (type))
582             CONTIN;
583
584           if (use_gnu_debug_info_extensions
585               && flag_minimal_debug
586               && TREE_CODE (tem) == FIELD_DECL
587               && DECL_VIRTUAL_P (tem)
588               && DECL_ASSEMBLER_NAME (tem))
589             {
590               have_used_extensions = 1;
591               CHARS (3 + IDENTIFIER_LENGTH (DECL_NAME (TYPE_NAME (DECL_FCONTEXT (tem)))));
592               fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)), asmfile);
593               dbxout_type (DECL_FCONTEXT (tem), 0, 0);
594               fprintf (asmfile, ":");
595               dbxout_type (TREE_TYPE (tem), 0, 0);
596               fprintf (asmfile, ",%d;",
597                        TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
598               continue;
599             }
600
601           fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
602           CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
603
604           if (use_gnu_debug_info_extensions
605               && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
606                   || TREE_CODE (tem) != FIELD_DECL))
607             {
608               have_used_extensions = 1;
609               putc ('/', asmfile);
610               putc ((TREE_PRIVATE (tem) ? '0'
611                      : TREE_PROTECTED (tem) ? '1' : '2'),
612                     asmfile);
613               CHARS (2);
614             }
615
616           dbxout_type ((TREE_CODE (tem) == FIELD_DECL
617                         && DECL_BIT_FIELD_TYPE (tem))
618                        ? DECL_BIT_FIELD_TYPE (tem)
619                        : TREE_TYPE (tem), 0, 0);
620
621           if (TREE_CODE (tem) == VAR_DECL)
622             {
623               if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
624                 {
625                   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
626                   have_used_extensions = 1;
627                   fprintf (asmfile, ":%s;", name);
628                   CHARS (strlen (name));
629                 }
630               else
631                 {
632                   /* If TEM is non-static, GDB won't understand it.  */
633                   fprintf (asmfile, ",0,0;");
634                 }
635             }
636           else if (TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
637             {
638               fprintf (asmfile, ",%d,%d;",
639                        TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)),
640                        TREE_INT_CST_LOW (DECL_SIZE (tem)));
641             }
642           else
643             /* This has yet to be implemented.  */
644             abort ();
645           CHARS (23);
646         }
647     }
648 }
649 \f
650 /* Subroutine of `dbxout_type_methods'.  Output debug info about the
651    method described DECL.  DEBUG_NAME is an encoding of the method's
652    type signature.  ??? We may be able to do without DEBUG_NAME altogether
653    now.  */
654
655 static void
656 dbxout_type_method_1 (decl, debug_name)
657      tree decl;
658      char *debug_name;
659 {
660   tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
661   char c1 = 'A', c2;
662
663   if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
664     c2 = '?';
665   else /* it's a METHOD_TYPE.  */
666     {
667       /* A for normal functions.
668          B for `const' member functions.
669          C for `volatile' member functions.
670          D for `const volatile' member functions.  */
671       if (TYPE_READONLY (TREE_TYPE (firstarg)))
672         c1 += 1;
673       if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
674         c1 += 2;
675
676       if (DECL_VINDEX (decl))
677         c2 = '*';
678       else
679         c2 = '.';
680     }
681
682   fprintf (asmfile, ":%s;%c%c%c", debug_name,
683            TREE_PRIVATE (decl) ? '0' : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
684   CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
685          - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
686   if (DECL_VINDEX (decl))
687     {
688       fprintf (asmfile, "%d;",
689                TREE_INT_CST_LOW (DECL_VINDEX (decl)));
690       dbxout_type (DECL_CONTEXT (decl), 0, 0);
691       fprintf (asmfile, ";");
692       CHARS (8);
693     }
694 }
695 \f
696 /* Subroutine of `dbxout_type'.  Output debug info about the methods defined
697    in TYPE.  */
698
699 static void
700 dbxout_type_methods (type)
701      register tree type;
702 {
703   /* C++: put out the method names and their parameter lists */
704   tree methods = TYPE_METHODS (type);
705   tree type_encoding;
706   register tree fndecl;
707   register tree last;
708   char formatted_type_identifier_length[16];
709   register int type_identifier_length;
710
711   if (methods == NULL_TREE)
712     return;
713
714   type_encoding = DECL_NAME (TYPE_NAME (type));
715
716   /* C++: Template classes break some assumptions made by this code about
717      the class names, constructor names, and encodings for assembler
718      label names.  For now, disable output of dbx info for them.  */
719   {
720     char *ptr = IDENTIFIER_POINTER (type_encoding);
721     /* This should use index.  (mrs) */
722     while (*ptr && *ptr != '<') ptr++;
723     if (*ptr != 0)
724       {
725         static int warned;
726         if (!warned)
727           {
728             warned = 1;
729             warning ("dbx info for template class methods not yet supported");
730           }
731         return;
732       }
733   }
734
735   type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
736
737   sprintf(formatted_type_identifier_length, "%d", type_identifier_length);
738
739   if (TREE_CODE (methods) == FUNCTION_DECL)
740     fndecl = methods;
741   else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
742     fndecl = TREE_VEC_ELT (methods, 0);
743   else
744     fndecl = TREE_VEC_ELT (methods, 1);
745
746   while (fndecl)
747     {
748       tree name = DECL_NAME (fndecl);
749       int need_prefix = 1;
750
751       /* Group together all the methods for the same operation.
752          These differ in the types of the arguments.  */
753       for (last = NULL_TREE;
754            fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
755            fndecl = TREE_CHAIN (fndecl))
756         /* Output the name of the field (after overloading), as
757            well as the name of the field before overloading, along
758            with its parameter list */
759         {
760           /* This is the "mangled" name of the method.
761              It encodes the argument types.  */
762           char *debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
763           int destructor = 0;
764
765           CONTIN;
766
767           last = fndecl;
768
769           if (DECL_IGNORED_P (fndecl))
770             continue;
771
772           if (flag_minimal_debug)
773             {
774               /* Detect ordinary methods because their mangled names
775                  start with the operation name.  */
776               if (!strncmp (IDENTIFIER_POINTER (name), debug_name,
777                             IDENTIFIER_LENGTH (name)))
778                 {
779                   debug_name += IDENTIFIER_LENGTH (name);
780                   if (debug_name[0] == '_' && debug_name[1] == '_')
781                     {
782                       char *method_name = debug_name + 2;
783                       char *length_ptr = formatted_type_identifier_length;
784                       /* Get past const and volatile qualifiers.  */
785                       while (*method_name == 'C' || *method_name == 'V')
786                         method_name++;
787                       /* Skip digits for length of type_encoding. */
788                       while (*method_name == *length_ptr && *length_ptr)
789                           length_ptr++, method_name++;
790                       if (! strncmp (method_name,
791                                      IDENTIFIER_POINTER (type_encoding),
792                                      type_identifier_length))
793                         method_name += type_identifier_length;
794                       debug_name = method_name;
795                     }
796                 }
797               /* Detect constructors by their style of name mangling.  */
798               else if (debug_name[0] == '_' && debug_name[1] == '_')
799                 {
800                   char *ctor_name = debug_name + 2;
801                   char *length_ptr = formatted_type_identifier_length;
802                   while (*ctor_name == 'C' || *ctor_name == 'V')
803                     ctor_name++;
804                   /* Skip digits for length of type_encoding. */
805                   while (*ctor_name == *length_ptr && *length_ptr)
806                       length_ptr++, ctor_name++;
807                   if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name,
808                                 type_identifier_length))
809                     debug_name = ctor_name + type_identifier_length;
810                 }
811               /* The other alternative is a destructor.  */
812               else
813                 destructor = 1;
814
815               /* Output the operation name just once, for the first method
816                  that we output.  */
817               if (need_prefix)
818                 {
819                   fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
820                   CHARS (IDENTIFIER_LENGTH (name) + 2);
821                   need_prefix = 0;
822                 }
823             }
824
825           dbxout_type (TREE_TYPE (fndecl), 0, destructor);
826
827           dbxout_type_method_1 (fndecl, debug_name);
828         }
829       if (!need_prefix)
830         {
831           putc (';', asmfile);
832           CHARS (1);
833         }
834     }
835 }
836 \f
837 /* Output a reference to a type.  If the type has not yet been
838    described in the dbx output, output its definition now.
839    For a type already defined, just refer to its definition
840    using the type number.
841
842    If FULL is nonzero, and the type has been described only with
843    a forward-reference, output the definition now.
844    If FULL is zero in this case, just refer to the forward-reference
845    using the number previously allocated.
846
847    If SHOW_ARG_TYPES is nonzero, we output a description of the argument
848    types for a METHOD_TYPE.  */
849
850 static void
851 dbxout_type (type, full, show_arg_types)
852      tree type;
853      int full;
854      int show_arg_types;
855 {
856   register tree tem;
857
858   /* If there was an input error and we don't really have a type,
859      avoid crashing and write something that is at least valid
860      by assuming `int'.  */
861   if (type == error_mark_node)
862     type = integer_type_node;
863   else
864     {
865       type = TYPE_MAIN_VARIANT (type);
866       if (TYPE_NAME (type)
867           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
868           && DECL_IGNORED_P (TYPE_NAME (type)))
869         full = 0;
870     }
871
872   if (TYPE_SYMTAB_ADDRESS (type) == 0)
873     {
874       /* Type has no dbx number assigned.  Assign next available number.  */
875       TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
876
877       /* Make sure type vector is long enough to record about this type.  */
878
879       if (next_type_number == typevec_len)
880         {
881           typevec = (enum typestatus *) xrealloc (typevec, typevec_len * 2 * sizeof typevec[0]);
882           bzero (typevec + typevec_len, typevec_len * sizeof typevec[0]);
883           typevec_len *= 2;
884         }
885     }
886
887   /* Output the number of this type, to refer to it.  */
888   fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
889   CHARS (3);
890
891 #ifdef DBX_TYPE_DEFINED
892   if (DBX_TYPE_DEFINED (type))
893     return;
894 #endif
895
896   /* If this type's definition has been output or is now being output,
897      that is all.  */
898
899   switch (typevec[TYPE_SYMTAB_ADDRESS (type)])
900     {
901     case TYPE_UNSEEN:
902       break;
903     case TYPE_XREF:
904       /* If we have already had a cross reference,
905          and either that's all we want or that's the best we could do,
906          don't repeat the cross reference.
907          Sun dbx crashes if we do.  */
908       if (! full || TYPE_SIZE (type) == 0
909           /* No way in DBX fmt to describe a variable size.  */
910           || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
911         return;
912       break;
913     case TYPE_DEFINED:
914       return;
915     }
916
917 #ifdef DBX_NO_XREFS
918   /* For systems where dbx output does not allow the `=xsNAME:' syntax,
919      leave the type-number completely undefined rather than output
920      a cross-reference.  */
921   if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
922       || TREE_CODE (type) == ENUMERAL_TYPE)
923
924     if ((TYPE_NAME (type) != 0 && !full)
925         || TYPE_SIZE (type) == 0)
926       {
927         typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
928         return;
929       }
930 #endif
931
932   /* Output a definition now.  */
933
934   fprintf (asmfile, "=");
935   CHARS (1);
936
937   /* Mark it as defined, so that if it is self-referent
938      we will not get into an infinite recursion of definitions.  */
939
940   typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
941
942   switch (TREE_CODE (type))
943     {
944     case VOID_TYPE:
945     case LANG_TYPE:
946       /* For a void type, just define it as itself; ie, "5=5".
947          This makes us consider it defined
948          without saying what it is.  The debugger will make it
949          a void type when the reference is seen, and nothing will
950          ever override that default.  */
951       fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
952       CHARS (3);
953       break;
954
955     case INTEGER_TYPE:
956       if (type == char_type_node && ! TREE_UNSIGNED (type))
957         /* Output the type `char' as a subrange of itself!
958            I don't understand this definition, just copied it
959            from the output of pcc.
960            This used to use `r2' explicitly and we used to
961            take care to make sure that `char' was type number 2.  */
962         fprintf (asmfile, "r%d;0;127;", TYPE_SYMTAB_ADDRESS (type));
963 #ifdef WINNING_GDB
964       else if (TYPE_PRECISION (type) > BITS_PER_WORD)
965         {
966           /* This used to say `r1' and we used to take care
967              to make sure that `int' was type number 1.  */
968           fprintf (asmfile, "r%d;", TYPE_SYMTAB_ADDRESS (integer_type_node));
969           print_int_cst_octal (TYPE_MIN_VALUE (type));
970           fprintf (asmfile, ";");
971           print_int_cst_octal (TYPE_MAX_VALUE (type));
972           fprintf (asmfile, ";");
973         }
974 #endif
975       else
976         /* Output other integer types as subranges of `int'.  */
977         /* This used to say `r1' and we used to take care
978            to make sure that `int' was type number 1.  */
979         fprintf (asmfile, "r%d;%d;%d;",
980                  TYPE_SYMTAB_ADDRESS (integer_type_node),
981                  TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)),
982                  TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
983       CHARS (25);
984       break;
985
986     case REAL_TYPE:
987       /* This used to say `r1' and we used to take care
988          to make sure that `int' was type number 1.  */
989       fprintf (asmfile, "r%d;%d;0;", TYPE_SYMTAB_ADDRESS (integer_type_node),
990                TREE_INT_CST_LOW (size_in_bytes (type)));
991       CHARS (16);
992       break;
993
994     case CHAR_TYPE:
995         /* Output the type `char' as a subrange of itself.
996            That is what pcc seems to do.  */
997       fprintf (asmfile, "r%d;0;%d;", TYPE_SYMTAB_ADDRESS (char_type_node),
998                TREE_UNSIGNED (type) ? 255 : 127);
999       CHARS (9);
1000       break;
1001
1002     case BOOLEAN_TYPE:  /* Define as enumeral type (False, True) */
1003       fprintf (asmfile, "eFalse:0,True:1,;");
1004       CHARS (17);
1005       break;
1006
1007     case FILE_TYPE:
1008       putc ('d', asmfile);
1009       CHARS (1);
1010       dbxout_type (TREE_TYPE (type), 0);
1011       break;
1012
1013     case COMPLEX_TYPE:
1014       /* Differs from the REAL_TYPE by its new data type number */
1015
1016       if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1017         {
1018           fprintf (asmfile, "r%d;%d;0;",
1019                    TYPE_SYMTAB_ADDRESS (type),
1020                    TREE_INT_CST_LOW (size_in_bytes (TREE_TYPE (type))));
1021           CHARS (15);           /* The number is propably incorrect here */
1022         } else
1023           abort (); /* What to do with CSImode complex? */
1024       break;
1025
1026     case SET_TYPE:
1027       putc ('S', asmfile);
1028       CHARS (1);
1029       dbxout_type (TREE_TYPE (type), 0);
1030       break;
1031
1032     case ARRAY_TYPE:
1033       /* Output "a" followed by a range type definition
1034          for the index type of the array
1035          followed by a reference to the target-type.
1036          ar1;0;N;M for an array of type M and size N.  */
1037       /* This used to say `r1' and we used to take care
1038          to make sure that `int' was type number 1.  */
1039       fprintf (asmfile, "ar%d;0;%d;", TYPE_SYMTAB_ADDRESS (integer_type_node),
1040
1041                (TYPE_DOMAIN (type)
1042                 ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
1043                 : -1));
1044       CHARS (17);
1045       dbxout_type (TREE_TYPE (type), 0, 0);
1046       break;
1047
1048     case RECORD_TYPE:
1049     case UNION_TYPE:
1050       {
1051         int i, n_baseclasses = 0;
1052
1053         if (TYPE_BINFO (type) != 0 && TYPE_BINFO_BASETYPES (type) != 0)
1054           n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1055
1056         /* Output a structure type.  */
1057         if ((TYPE_NAME (type) != 0
1058 #if 0 /* Tiemann says this creates output tha "confuses GDB".
1059          Too bad the info is so vague.  Hope this doesn't lose.  */
1060              && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1061                    && DECL_IGNORED_P (TYPE_NAME (type)))
1062 #endif
1063              && !full)
1064             || TYPE_SIZE (type) == 0
1065             /* No way in DBX fmt to describe a variable size.  */
1066             || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1067           {
1068             /* If the type is just a cross reference, output one
1069                and mark the type as partially described.
1070                If it later becomes defined, we will output
1071                its real definition.
1072                If the type has a name, don't nest its definition within
1073                another type's definition; instead, output an xref
1074                and let the definition come when the name is defined.  */
1075             fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
1076             CHARS (3);
1077 #if 0 /* This assertion is legitimately false in C++.  */
1078             /* We shouldn't be outputting a reference to a type before its
1079                definition unless the type has a tag name.
1080                A typedef name without a tag name should be impossible.  */
1081             if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1082               abort ();
1083 #endif
1084             dbxout_type_name (type);
1085             fprintf (asmfile, ":");
1086             typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
1087             break;
1088           }
1089         tem = size_in_bytes (type);
1090
1091         /* Identify record or union, and print its size.  */
1092         fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d",
1093                  TREE_INT_CST_LOW (tem));
1094
1095         if (use_gnu_debug_info_extensions)
1096           {
1097             if (n_baseclasses)
1098               {
1099                 have_used_extensions = 1;
1100                 fprintf (asmfile, "!%d,", n_baseclasses);
1101                 CHARS (8);
1102               }
1103           }
1104         for (i = 0; i < n_baseclasses; i++)
1105           {
1106             tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1107             if (use_gnu_debug_info_extensions)
1108               {
1109                 have_used_extensions = 1;
1110                 putc (TREE_VIA_VIRTUAL (child) ? '1'
1111                       : '0',
1112                       asmfile);
1113                 putc (TREE_VIA_PUBLIC (child) ? '2'
1114                       : '0',
1115                       asmfile);
1116                 fprintf (asmfile, "%d,",
1117                          TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT);
1118                 CHARS (15);
1119                 dbxout_type (BINFO_TYPE (child), 0, 0);
1120                 putc (';', asmfile);
1121               }
1122             else
1123               {
1124                 /* Print out the base class information with fields
1125                    which have the same names at the types they hold.  */
1126                 dbxout_type_name (BINFO_TYPE (child));
1127                 putc (':', asmfile);
1128                 dbxout_type (BINFO_TYPE (child), full, 0);
1129                 fprintf (asmfile, ",%d,%d;",
1130                          TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT,
1131                          TREE_INT_CST_LOW (DECL_SIZE (TYPE_NAME (BINFO_TYPE (child)))) * BITS_PER_UNIT);
1132                 CHARS (20);
1133               }
1134           }
1135       }
1136
1137       CHARS (11);
1138
1139       /* Write out the field declarations.  */
1140       dbxout_type_fields (type);
1141       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1142         {
1143           have_used_extensions = 1;
1144           dbxout_type_methods (type);
1145         }
1146       putc (';', asmfile);
1147
1148       if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1149           /* Avoid the ~ if we don't really need it--it confuses dbx.  */
1150           && TYPE_VFIELD (type))
1151         {
1152           have_used_extensions = 1;
1153
1154           /* Tell GDB+ that it may keep reading.  */
1155           putc ('~', asmfile);
1156
1157           /* We need to write out info about what field this class
1158              uses as its "main" vtable pointer field, because if this
1159              field is inherited from a base class, GDB cannot necessarily
1160              figure out which field it's using in time.  */
1161           if (TYPE_VFIELD (type))
1162             {
1163               putc ('%', asmfile);
1164               dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0, 0);
1165             }
1166           putc (';', asmfile);
1167           CHARS (3);
1168         }
1169       break;
1170
1171     case ENUMERAL_TYPE:
1172       if ((TYPE_NAME (type) != 0 && !full
1173            && (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1174                && ! DECL_IGNORED_P (TYPE_NAME (type))))
1175           || TYPE_SIZE (type) == 0)
1176         {
1177           fprintf (asmfile, "xe");
1178           CHARS (3);
1179           dbxout_type_name (type);
1180           typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
1181           fprintf (asmfile, ":");
1182           return;
1183         }
1184 #ifdef DBX_OUTPUT_ENUM
1185       DBX_OUTPUT_ENUM (asmfile, type);
1186 #else
1187       putc ('e', asmfile);
1188       CHARS (1);
1189       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1190         {
1191           fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
1192                    TREE_INT_CST_LOW (TREE_VALUE (tem)));
1193           CHARS (11 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1194           if (TREE_CHAIN (tem) != 0)
1195             CONTIN;
1196         }
1197       putc (';', asmfile);
1198       CHARS (1);
1199 #endif
1200       break;
1201
1202     case POINTER_TYPE:
1203       putc ('*', asmfile);
1204       CHARS (1);
1205       dbxout_type (TREE_TYPE (type), 0, 0);
1206       break;
1207
1208     case METHOD_TYPE:
1209       if (use_gnu_debug_info_extensions)
1210         {
1211           have_used_extensions = 1;
1212           putc ('#', asmfile);
1213           CHARS (1);
1214           if (flag_minimal_debug && !show_arg_types)
1215             {
1216               /* Normally, just output the return type.
1217                  The argument types are encoded in the method name.  */
1218               putc ('#', asmfile);
1219               dbxout_type (TREE_TYPE (type), 0, 0);
1220               putc (';', asmfile);
1221               CHARS (1);
1222             }
1223           else
1224             {
1225               /* When outputting destructors, we need to write
1226                  the argument types out longhand.  */
1227               dbxout_type (TYPE_METHOD_BASETYPE (type), 0, 0);
1228               putc (',', asmfile);
1229               CHARS (1);
1230               dbxout_type (TREE_TYPE (type), 0, 0);
1231               dbxout_args (TYPE_ARG_TYPES (type));
1232               putc (';', asmfile);
1233               CHARS (1);
1234             }
1235         }
1236       else
1237         {
1238           /* Treat it as a function type.  */
1239           dbxout_type (TREE_TYPE (type), 0, 0);
1240         }
1241       break;
1242
1243     case OFFSET_TYPE:
1244       if (use_gnu_debug_info_extensions)
1245         {
1246           have_used_extensions = 1;
1247           putc ('@', asmfile);
1248           CHARS (1);
1249           dbxout_type (TYPE_OFFSET_BASETYPE (type), 0, 0);
1250           putc (',', asmfile);
1251           CHARS (1);
1252           dbxout_type (TREE_TYPE (type), 0, 0);
1253         }
1254       else
1255         {
1256           /* Should print as an int, because it is really
1257              just an offset.  */
1258           dbxout_type (integer_type_node, 0, 0);
1259         }
1260       break;
1261
1262     case REFERENCE_TYPE:
1263       if (use_gnu_debug_info_extensions)
1264         have_used_extensions = 1;
1265       putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1266       CHARS (1);
1267       dbxout_type (TREE_TYPE (type), 0, 0);
1268       break;
1269
1270     case FUNCTION_TYPE:
1271       putc ('f', asmfile);
1272       CHARS (1);
1273       dbxout_type (TREE_TYPE (type), 0, 0);
1274       break;
1275
1276     default:
1277       abort ();
1278     }
1279 }
1280
1281 /* Print the value of integer constant C, in octal,
1282    handling double precision.  */
1283
1284 static void
1285 print_int_cst_octal (c)
1286      tree c;
1287 {
1288   unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1289   unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1290   int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1291
1292   fprintf (asmfile, "0");
1293
1294   if (excess == 3)
1295     {
1296       print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1297       print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1298     }
1299   else
1300     {
1301       unsigned HOST_WIDE_INT beg = high >> excess;
1302       unsigned HOST_WIDE_INT middle
1303         = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1304            | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1305       unsigned HOST_WIDE_INT end
1306         = low & (((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 3 * 3)) - 1);
1307       fprintf (asmfile, "%o%01o", beg, middle);
1308       print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1309     }
1310 }
1311
1312 static void
1313 print_octal (value, digits)
1314      unsigned HOST_WIDE_INT value;
1315      int digits;
1316 {
1317   int i;
1318
1319   for (i = digits - 1; i >= 0; i--)
1320     fprintf (asmfile, "%01o", ((value >> (3 * i)) & 7));
1321 }
1322
1323 /* Output the name of type TYPE, with no punctuation.
1324    Such names can be set up either by typedef declarations
1325    or by struct, enum and union tags.  */
1326
1327 static void
1328 dbxout_type_name (type)
1329      register tree type;
1330 {
1331   tree t;
1332   if (TYPE_NAME (type) == 0)
1333     abort ();
1334   if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1335     {
1336       t = TYPE_NAME (type);
1337     }
1338   else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1339     {
1340       t = DECL_NAME (TYPE_NAME (type));
1341     }
1342   else
1343     abort ();
1344
1345   fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1346   CHARS (IDENTIFIER_LENGTH (t));
1347 }
1348 \f
1349 /* Output a .stabs for the symbol defined by DECL,
1350    which must be a ..._DECL node in the normal namespace.
1351    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1352    LOCAL is nonzero if the scope is less than the entire file.  */
1353
1354 void
1355 dbxout_symbol (decl, local)
1356      tree decl;
1357      int local;
1358 {
1359   int letter = 0;
1360   tree type = TREE_TYPE (decl);
1361   tree context = NULL_TREE;
1362   int regno = -1;
1363
1364   /* Cast avoids warning in old compilers.  */
1365   current_sym_code = (STAB_CODE_TYPE) 0;
1366   current_sym_value = 0;
1367   current_sym_addr = 0;
1368
1369   /* Ignore nameless syms, but don't ignore type tags.  */
1370
1371   if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1372       || DECL_IGNORED_P (decl))
1373     return;
1374
1375   dbxout_prepare_symbol (decl);
1376
1377   /* The output will always start with the symbol name,
1378      so always count that in the length-output-so-far.  */
1379
1380   if (DECL_NAME (decl) != 0)
1381     current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1382
1383   switch (TREE_CODE (decl))
1384     {
1385     case CONST_DECL:
1386       /* Enum values are defined by defining the enum type.  */
1387       break;
1388
1389     case FUNCTION_DECL:
1390       if (DECL_RTL (decl) == 0)
1391         return;
1392       if (DECL_EXTERNAL (decl))
1393         break;
1394       /* Don't mention a nested function under its parent.  */
1395       context = decl_function_context (decl);
1396       if (context == current_function_decl)
1397         break;
1398       if (GET_CODE (DECL_RTL (decl)) != MEM
1399           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1400         break;
1401       FORCE_TEXT;
1402
1403       fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1404                IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1405                TREE_PUBLIC (decl) ? 'F' : 'f');
1406
1407       current_sym_code = N_FUN;
1408       current_sym_addr = XEXP (DECL_RTL (decl), 0);
1409
1410       if (TREE_TYPE (type))
1411         dbxout_type (TREE_TYPE (type), 0, 0);
1412       else
1413         dbxout_type (void_type_node, 0, 0);
1414
1415       /* For a nested function, when that function is compiled,
1416          mention the containing function name
1417          as well as (since dbx wants it) our own assembler-name.  */
1418       if (context != 0)
1419         fprintf (asmfile, ",%s,%s",
1420                  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1421                  IDENTIFIER_POINTER (DECL_NAME (context)));
1422
1423       dbxout_finish_symbol (decl);
1424       break;
1425
1426     case TYPE_DECL:
1427 #if 0
1428       /* This seems all wrong.  Outputting most kinds of types gives no name
1429          at all.  A true definition gives no name; a cross-ref for a
1430          structure can give the tag name, but not a type name.
1431          It seems that no typedef name is defined by outputting a type.  */
1432
1433       /* If this typedef name was defined by outputting the type,
1434          don't duplicate it.  */
1435       if (typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED
1436           && TYPE_NAME (TREE_TYPE (decl)) == decl)
1437         return;
1438 #endif
1439       /* Don't output the same typedef twice.
1440          And don't output what language-specific stuff doesn't want output.  */
1441       if (TREE_ASM_WRITTEN (decl) || DECL_IGNORED_P (decl))
1442         return;
1443
1444       FORCE_TEXT;
1445
1446       {
1447         int tag_needed = 1;
1448         int did_output = 0;
1449
1450         if (DECL_NAME (decl))
1451           {
1452             /* Nonzero means we must output a tag as well as a typedef.  */
1453             tag_needed = 0;
1454
1455             /* Handle the case of a C++ structure or union
1456                where the TYPE_NAME is a TYPE_DECL
1457                which gives both a typedef name and a tag.  */
1458             /* dbx requires the tag first and the typedef second.  */
1459             if ((TREE_CODE (type) == RECORD_TYPE
1460                  || TREE_CODE (type) == UNION_TYPE)
1461                 && TYPE_NAME (type) == decl
1462                 && !(use_gnu_debug_info_extensions && have_used_extensions)
1463                 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
1464                 /* Distinguish the implicit typedefs of C++
1465                    from explicit ones that might be found in C.  */
1466                 && DECL_SOURCE_LINE (decl) == 0)
1467               {
1468                 tree name = TYPE_NAME (type);
1469                 if (TREE_CODE (name) == TYPE_DECL)
1470                   name = DECL_NAME (name);
1471
1472                 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1473                 current_sym_value = 0;
1474                 current_sym_addr = 0;
1475                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1476
1477                 fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP,
1478                          IDENTIFIER_POINTER (name));
1479                 dbxout_type (type, 1, 0);
1480                 dbxout_finish_symbol (NULL_TREE);
1481               }
1482
1483             /* Output typedef name.  */
1484             fprintf (asmfile, "%s \"%s:", ASM_STABS_OP,
1485                      IDENTIFIER_POINTER (DECL_NAME (decl)));
1486
1487             /* Short cut way to output a tag also.  */
1488             if ((TREE_CODE (type) == RECORD_TYPE
1489                  || TREE_CODE (type) == UNION_TYPE)
1490                 && TYPE_NAME (type) == decl)
1491               {
1492                 if (use_gnu_debug_info_extensions && have_used_extensions)
1493                   {
1494                     putc ('T', asmfile);
1495                     TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1496                   }
1497 #if 0 /* Now we generate the tag for this case up above.  */
1498                 else
1499                   tag_needed = 1;
1500 #endif
1501               }
1502
1503             putc ('t', asmfile);
1504             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1505
1506             dbxout_type (type, 1, 0);
1507             dbxout_finish_symbol (decl);
1508             did_output = 1;
1509           }
1510
1511         if (tag_needed && TYPE_NAME (type) != 0
1512             && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1513           {
1514             /* For a TYPE_DECL with no name, but the type has a name,
1515                output a tag.
1516                This is what represents `struct foo' with no typedef.  */
1517             /* In C++, the name of a type is the corresponding typedef.
1518                In C, it is an IDENTIFIER_NODE.  */
1519             tree name = TYPE_NAME (type);
1520             if (TREE_CODE (name) == TYPE_DECL)
1521               name = DECL_NAME (name);
1522
1523             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1524             current_sym_value = 0;
1525             current_sym_addr = 0;
1526             current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1527
1528             fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP,
1529                      IDENTIFIER_POINTER (name));
1530             dbxout_type (type, 1, 0);
1531             dbxout_finish_symbol (NULL_TREE);
1532             did_output = 1;
1533           }
1534
1535         /* If an enum type has no name, it cannot be referred to,
1536            but we must output it anyway, since the enumeration constants
1537            can be referred to.  */
1538         if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
1539           {
1540             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1541             current_sym_value = 0;
1542             current_sym_addr = 0;
1543             current_sym_nchars = 2;
1544
1545             fprintf (asmfile, "%s \":T", ASM_STABS_OP);
1546             dbxout_type (type, 1, 0);
1547             dbxout_finish_symbol (NULL_TREE);
1548           }
1549
1550         /* Prevent duplicate output of a typedef.  */
1551         TREE_ASM_WRITTEN (decl) = 1;
1552         break;
1553       }
1554
1555     case PARM_DECL:
1556       /* Parm decls go in their own separate chains
1557          and are output by dbxout_reg_parms and dbxout_parms.  */
1558       abort ();
1559
1560     case RESULT_DECL:
1561       /* Named return value, treat like a VAR_DECL.  */
1562     case VAR_DECL:
1563       if (DECL_RTL (decl) == 0)
1564         return;
1565       /* Don't mention a variable that is external.
1566          Let the file that defines it describe it.  */
1567       if (DECL_EXTERNAL (decl))
1568         break;
1569
1570       /* If the variable is really a constant
1571          and not written in memory, inform the debugger.  */
1572       if (TREE_STATIC (decl) && TREE_READONLY (decl)
1573           && DECL_INITIAL (decl) != 0
1574           && ! TREE_ASM_WRITTEN (decl)
1575           && (DECL_FIELD_CONTEXT (decl) == NULL_TREE
1576               || TREE_CODE (DECL_FIELD_CONTEXT (decl)) == BLOCK))
1577         {
1578           if (TREE_PUBLIC (decl) == 0)
1579             {
1580               /* The sun4 assembler does not grok this.  */
1581               char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1582               if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
1583                   || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
1584                 {
1585                   HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
1586 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
1587                   DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
1588 #else
1589                   fprintf (asmfile, "%s \"%s:c=i%d\",0x%x,0,0,0\n",
1590                            ASM_STABS_OP, name, ival, N_LSYM);
1591 #endif
1592                   return;
1593                 }
1594               else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
1595                 {
1596                   /* don't know how to do this yet.  */
1597                 }
1598               break;
1599             }
1600           /* else it is something we handle like a normal variable.  */
1601         }
1602
1603       DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, 0);
1604 #ifdef LEAF_REG_REMAP
1605       if (leaf_function)
1606         leaf_renumber_regs_insn (DECL_RTL (decl));
1607 #endif
1608
1609       /* Don't mention a variable at all
1610          if it was completely optimized into nothingness.
1611
1612          If DECL was from an inline function, then it's rtl
1613          is not identically the rtl that was used in this
1614          particular compilation.  */
1615       if (GET_CODE (DECL_RTL (decl)) == REG)
1616         {
1617           regno = REGNO (DECL_RTL (decl));
1618           if (regno >= FIRST_PSEUDO_REGISTER)
1619             return;
1620         }
1621       else if (GET_CODE (DECL_RTL (decl)) == SUBREG)
1622         {
1623           rtx value = DECL_RTL (decl);
1624           int offset = 0;
1625           while (GET_CODE (value) == SUBREG)
1626             {
1627               offset += SUBREG_WORD (value);
1628               value = SUBREG_REG (value);
1629             }
1630           if (GET_CODE (value) == REG)
1631             {
1632               regno = REGNO (value);
1633               if (regno >= FIRST_PSEUDO_REGISTER)
1634                 return;
1635               regno += offset;
1636             }
1637           alter_subreg (DECL_RTL (decl));
1638         }
1639
1640       /* The kind-of-variable letter depends on where
1641          the variable is and on the scope of its name:
1642          G and N_GSYM for static storage and global scope,
1643          S for static storage and file scope,
1644          V for static storage and local scope,
1645             for those two, use N_LCSYM if data is in bss segment,
1646             N_STSYM if in data segment, N_FUN otherwise.
1647             (We used N_FUN originally, then changed to N_STSYM
1648             to please GDB.  However, it seems that confused ld.
1649             Now GDB has been fixed to like N_FUN, says Kingdon.)
1650          no letter at all, and N_LSYM, for auto variable,
1651          r and N_RSYM for register variable.  */
1652
1653       if (GET_CODE (DECL_RTL (decl)) == MEM
1654           && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
1655         {
1656           if (TREE_PUBLIC (decl))
1657             {
1658               letter = 'G';
1659               current_sym_code = N_GSYM;
1660             }
1661           else
1662             {
1663               current_sym_addr = XEXP (DECL_RTL (decl), 0);
1664
1665               letter = decl_function_context (decl) ? 'V' : 'S';
1666
1667               if (!DECL_INITIAL (decl))
1668                 current_sym_code = N_LCSYM;
1669               else if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl))
1670                 /* This is not quite right, but it's the closest
1671                    of all the codes that Unix defines.  */
1672                 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
1673               else
1674                 {
1675 /* Ultrix `as' seems to need this.  */
1676 #ifdef DBX_STATIC_STAB_DATA_SECTION
1677                   data_section ();
1678 #endif
1679                   current_sym_code = N_STSYM;
1680                 }
1681             }
1682         }
1683       else if (regno >= 0)
1684         {
1685           letter = 'r';
1686           current_sym_code = N_RSYM;
1687           current_sym_value = DBX_REGISTER_NUMBER (regno);
1688         }
1689       else if (GET_CODE (DECL_RTL (decl)) == MEM
1690                && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
1691                    || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
1692                        && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
1693         /* If the value is indirect by memory or by a register
1694            that isn't the frame pointer
1695            then it means the object is variable-sized and address through
1696            that register or stack slot.  DBX has no way to represent this
1697            so all we can do is output the variable as a pointer.
1698            If it's not a parameter, ignore it.
1699            (VAR_DECLs like this can be made by integrate.c.)  */
1700         {
1701           if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1702             {
1703               letter = 'r';
1704               current_sym_code = N_RSYM;
1705               current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
1706             }
1707           else
1708             {
1709               current_sym_code = N_LSYM;
1710               /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
1711                  We want the value of that CONST_INT.  */
1712               current_sym_value
1713                 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (DECL_RTL (decl), 0), 0));
1714             }
1715
1716           /* Effectively do build_pointer_type, but don't cache this type,
1717              since it might be temporary whereas the type it points to
1718              might have been saved for inlining.  */
1719           /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
1720           type = make_node (POINTER_TYPE);
1721           TREE_TYPE (type) = TREE_TYPE (decl);
1722         }
1723       else if (GET_CODE (DECL_RTL (decl)) == MEM
1724                && GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1725         {
1726           current_sym_code = N_LSYM;
1727           current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (DECL_RTL (decl), 0));
1728         }
1729       else if (GET_CODE (DECL_RTL (decl)) == MEM
1730                && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
1731                && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
1732         {
1733           current_sym_code = N_LSYM;
1734           /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
1735              We want the value of that CONST_INT.  */
1736           current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (DECL_RTL (decl), 0));
1737         }
1738       else if (GET_CODE (DECL_RTL (decl)) == MEM
1739                && GET_CODE (XEXP (DECL_RTL (decl), 0)) == CONST)
1740         {
1741           /* Handle an obscure case which can arise when optimizing and
1742              when there are few available registers.  (This is *always*
1743              the case for i386/i486 targets).  The DECL_RTL looks like
1744              (MEM (CONST ...)) even though this variable is a local `auto'
1745              or a local `register' variable.  In effect, what has happened
1746              is that the reload pass has seen that all assignments and
1747              references for one such a local variable can be replaced by
1748              equivalent assignments and references to some static storage
1749              variable, thereby avoiding the need for a register.  In such
1750              cases we're forced to lie to debuggers and tell them that
1751              this variable was itself `static'.  */
1752           current_sym_code = N_LCSYM;
1753           letter = 'V';
1754           current_sym_addr = XEXP (XEXP (DECL_RTL (decl), 0), 0);
1755         }
1756       else
1757         /* Address might be a MEM, when DECL is a variable-sized object.
1758            Or it might be const0_rtx, meaning previous passes
1759            want us to ignore this variable.  */
1760         break;
1761
1762       /* Ok, start a symtab entry and output the variable name.  */
1763       FORCE_TEXT;
1764
1765 #ifdef DBX_STATIC_BLOCK_START
1766       DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
1767 #endif
1768
1769       /* One slight hitch: if this is a VAR_DECL which is a static
1770          class member, we must put out the mangled name instead of the
1771          DECL_NAME.  */
1772       {
1773         char *name;
1774         /* Note also that static member (variable) names DO NOT begin
1775            with underscores in .stabs directives.  */
1776         if (DECL_LANG_SPECIFIC (decl))
1777           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1778         else
1779           name = IDENTIFIER_POINTER (DECL_NAME (decl));
1780         fprintf (asmfile, "%s \"%s:", ASM_STABS_OP, name);
1781       }
1782       if (letter) putc (letter, asmfile);
1783       dbxout_type (type, 0, 0);
1784       dbxout_finish_symbol (decl);
1785
1786 #ifdef DBX_STATIC_BLOCK_END
1787       DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
1788 #endif
1789       break;
1790     }
1791 }
1792
1793 static void
1794 dbxout_prepare_symbol (decl)
1795      tree decl;
1796 {
1797 #ifdef WINNING_GDB
1798   char *filename = DECL_SOURCE_FILE (decl);
1799
1800   dbxout_source_file (asmfile, filename);
1801 #endif
1802 }
1803
1804 static void
1805 dbxout_finish_symbol (sym)
1806      tree sym;
1807 {
1808 #ifdef DBX_FINISH_SYMBOL
1809   DBX_FINISH_SYMBOL (sym);
1810 #else
1811   int line = 0;
1812 #ifdef WINNING_GDB
1813   if (sym != 0)
1814     line = DECL_SOURCE_LINE (sym);
1815 #endif
1816
1817   fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
1818   if (current_sym_addr)
1819     output_addr_const (asmfile, current_sym_addr);
1820   else
1821     fprintf (asmfile, "%d", current_sym_value);
1822   putc ('\n', asmfile);
1823 #endif
1824 }
1825
1826 /* Output definitions of all the decls in a chain.  */
1827
1828 void
1829 dbxout_syms (syms)
1830      tree syms;
1831 {
1832   while (syms)
1833     {
1834       dbxout_symbol (syms, 1);
1835       syms = TREE_CHAIN (syms);
1836     }
1837 }
1838 \f
1839 /* The following two functions output definitions of function parameters.
1840    Each parameter gets a definition locating it in the parameter list.
1841    Each parameter that is a register variable gets a second definition
1842    locating it in the register.
1843
1844    Printing or argument lists in gdb uses the definitions that
1845    locate in the parameter list.  But reference to the variable in
1846    expressions uses preferentially the definition as a register.  */
1847
1848 /* Output definitions, referring to storage in the parmlist,
1849    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
1850
1851 void
1852 dbxout_parms (parms)
1853      tree parms;
1854 {
1855   for (; parms; parms = TREE_CHAIN (parms))
1856     if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
1857       {
1858         dbxout_prepare_symbol (parms);
1859
1860         /* Perform any necessary register eliminations on the parameter's rtl,
1861            so that the debugging output will be accurate.  */
1862         DECL_INCOMING_RTL (parms)
1863           = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1864         DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1865 #ifdef LEAF_REG_REMAP
1866         if (leaf_function)
1867           {
1868             leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
1869             leaf_renumber_regs_insn (DECL_RTL (parms));
1870           }
1871 #endif
1872
1873         if (PARM_PASSED_IN_MEMORY (parms))
1874           {
1875             rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1876
1877             /* ??? Here we assume that the parm address is indexed
1878                off the frame pointer or arg pointer.
1879                If that is not true, we produce meaningless results,
1880                but do not crash.  */
1881             if (GET_CODE (addr) == PLUS
1882                 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1883               current_sym_value = INTVAL (XEXP (addr, 1));
1884             else
1885               current_sym_value = 0;
1886
1887             current_sym_code = N_PSYM;
1888             current_sym_addr = 0;
1889
1890             FORCE_TEXT;
1891             if (DECL_NAME (parms))
1892               {
1893                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1894
1895                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1896                          IDENTIFIER_POINTER (DECL_NAME (parms)),
1897                          DBX_MEMPARM_STABS_LETTER);
1898               }
1899             else
1900               {
1901                 current_sym_nchars = 8;
1902                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
1903                          DBX_MEMPARM_STABS_LETTER);
1904               }
1905
1906             if (GET_CODE (DECL_RTL (parms)) == REG
1907                 && REGNO (DECL_RTL (parms)) >= 0
1908                 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1909               dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
1910             else
1911               {
1912                 int original_value = current_sym_value;
1913
1914                 /* This is the case where the parm is passed as an int or double
1915                    and it is converted to a char, short or float and stored back
1916                    in the parmlist.  In this case, describe the parm
1917                    with the variable's declared type, and adjust the address
1918                    if the least significant bytes (which we are using) are not
1919                    the first ones.  */
1920 #if BYTES_BIG_ENDIAN
1921                 if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1922                   current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1923                                         - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1924 #endif
1925
1926                 if (GET_CODE (DECL_RTL (parms)) == MEM
1927                     && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1928                     && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1929                     && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
1930                   dbxout_type (TREE_TYPE (parms), 0, 0);
1931                 else
1932                   {
1933                     current_sym_value = original_value;
1934                     dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
1935                   }
1936               }
1937             current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
1938             dbxout_finish_symbol (parms);
1939           }
1940         else if (GET_CODE (DECL_RTL (parms)) == REG)
1941           {
1942             rtx best_rtl;
1943             char regparm_letter;
1944             /* Parm passed in registers and lives in registers or nowhere.  */
1945
1946             current_sym_code = DBX_REGPARM_STABS_CODE;
1947             regparm_letter = DBX_REGPARM_STABS_LETTER;
1948             current_sym_addr = 0;
1949
1950             /* If parm lives in a register, use that register;
1951                pretend the parm was passed there.  It would be more consistent
1952                to describe the register where the parm was passed,
1953                but in practice that register usually holds something else.  */
1954             if (REGNO (DECL_RTL (parms)) >= 0
1955                 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1956               best_rtl = DECL_RTL (parms);
1957             /* If the parm lives nowhere,
1958                use the register where it was passed.  */
1959             else
1960               best_rtl = DECL_INCOMING_RTL (parms);
1961             current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
1962
1963             FORCE_TEXT;
1964             if (DECL_NAME (parms))
1965               {
1966                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1967                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1968                          IDENTIFIER_POINTER (DECL_NAME (parms)),
1969                          regparm_letter);
1970               }
1971             else
1972               {
1973                 current_sym_nchars = 8;
1974                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
1975                          regparm_letter);
1976               }
1977
1978             dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
1979             dbxout_finish_symbol (parms);
1980           }
1981         else if (GET_CODE (DECL_RTL (parms)) == MEM
1982                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
1983 /*               && rtx_equal_p (XEXP (DECL_RTL (parms), 0),
1984                                  DECL_INCOMING_RTL (parms))) */
1985           {
1986             /* Parm was passed via invisible reference.
1987                That is, its address was passed in a register.
1988                Output it as if it lived in that register.
1989                The debugger will know from the type
1990                that it was actually passed by invisible reference.  */
1991
1992             char regparm_letter;
1993             /* Parm passed in registers and lives in registers or nowhere.  */
1994
1995             current_sym_code = DBX_REGPARM_STABS_CODE;
1996             regparm_letter = DBX_REGPARM_STABS_LETTER;
1997
1998             /* DECL_RTL looks like (MEM (REG...).  Get the register number.  */
1999             current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2000             current_sym_addr = 0;
2001
2002             FORCE_TEXT;
2003             if (DECL_NAME (parms))
2004               {
2005                 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2006
2007                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
2008                          IDENTIFIER_POINTER (DECL_NAME (parms)),
2009                          DBX_REGPARM_STABS_LETTER);
2010               }
2011             else
2012               {
2013                 current_sym_nchars = 8;
2014                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
2015                          DBX_REGPARM_STABS_LETTER);
2016               }
2017
2018             dbxout_type (TREE_TYPE (parms), 0, 0);
2019             dbxout_finish_symbol (parms);
2020           }
2021         else if (GET_CODE (DECL_RTL (parms)) == MEM
2022                  && XEXP (DECL_RTL (parms), 0) != const0_rtx)
2023           {
2024             /* Parm was passed in registers but lives on the stack.  */
2025
2026             current_sym_code = N_PSYM;
2027             /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2028                in which case we want the value of that CONST_INT,
2029                or (MEM (REG ...)) or (MEM (MEM ...)),
2030                in which case we use a value of zero.  */
2031             if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2032                 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2033               current_sym_value = 0;
2034             else
2035               current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2036             current_sym_addr = 0;
2037
2038             FORCE_TEXT;
2039             if (DECL_NAME (parms))
2040               {
2041                 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2042
2043                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
2044                          IDENTIFIER_POINTER (DECL_NAME (parms)),
2045                          DBX_MEMPARM_STABS_LETTER);
2046               }
2047             else
2048               {
2049                 current_sym_nchars = 8;
2050                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
2051                 DBX_MEMPARM_STABS_LETTER);
2052               }
2053
2054             current_sym_value
2055               = DEBUGGER_ARG_OFFSET (current_sym_value,
2056                                      XEXP (DECL_RTL (parms), 0));
2057             dbxout_type (TREE_TYPE (parms), 0, 0);
2058             dbxout_finish_symbol (parms);
2059           }
2060       }
2061 }
2062
2063 /* Output definitions for the places where parms live during the function,
2064    when different from where they were passed, when the parms were passed
2065    in memory.
2066
2067    It is not useful to do this for parms passed in registers
2068    that live during the function in different registers, because it is
2069    impossible to look in the passed register for the passed value,
2070    so we use the within-the-function register to begin with.
2071
2072    PARMS is a chain of PARM_DECL nodes.  */
2073
2074 void
2075 dbxout_reg_parms (parms)
2076      tree parms;
2077 {
2078   for (; parms; parms = TREE_CHAIN (parms))
2079     if (DECL_NAME (parms))
2080       {
2081         dbxout_prepare_symbol (parms);
2082
2083         /* Report parms that live in registers during the function
2084            but were passed in memory.  */
2085         if (GET_CODE (DECL_RTL (parms)) == REG
2086             && REGNO (DECL_RTL (parms)) >= 0
2087             && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
2088             && PARM_PASSED_IN_MEMORY (parms))
2089           {
2090             current_sym_code = N_RSYM;
2091             current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
2092             current_sym_addr = 0;
2093
2094             FORCE_TEXT;
2095             if (DECL_NAME (parms))
2096               {
2097                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2098                 fprintf (asmfile, "%s \"%s:r", ASM_STABS_OP,
2099                          IDENTIFIER_POINTER (DECL_NAME (parms)));
2100               }
2101             else
2102               {
2103                 current_sym_nchars = 8;
2104                 fprintf (asmfile, "%s \"(anon):r", ASM_STABS_OP);
2105               }
2106             dbxout_type (TREE_TYPE (parms), 0, 0);
2107             dbxout_finish_symbol (parms);
2108           }
2109         /* Report parms that live in memory but not where they were passed.  */
2110         else if (GET_CODE (DECL_RTL (parms)) == MEM
2111                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
2112                  && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
2113                  && PARM_PASSED_IN_MEMORY (parms)
2114                  && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2115           {
2116 #if 0 /* ??? It is not clear yet what should replace this.  */
2117             int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
2118             /* A parm declared char is really passed as an int,
2119                so it occupies the least significant bytes.
2120                On a big-endian machine those are not the low-numbered ones.  */
2121 #if BYTES_BIG_ENDIAN
2122             if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
2123               offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
2124                          - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
2125 #endif
2126             if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
2127 #endif
2128             current_sym_code = N_LSYM;
2129             current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (DECL_RTL (parms), 0));
2130             current_sym_addr = 0;
2131             FORCE_TEXT;
2132             if (DECL_NAME (parms))
2133               {
2134                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2135                 fprintf (asmfile, "%s \"%s:", ASM_STABS_OP,
2136                          IDENTIFIER_POINTER (DECL_NAME (parms)));
2137               }
2138             else
2139               {
2140                 current_sym_nchars = 8;
2141                 fprintf (asmfile, "%s \"(anon):", ASM_STABS_OP);
2142               }
2143             dbxout_type (TREE_TYPE (parms), 0, 0);
2144             dbxout_finish_symbol (parms);
2145           }
2146 #if 0
2147         else if (GET_CODE (DECL_RTL (parms)) == MEM
2148                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2149           {
2150             /* Parm was passed via invisible reference.
2151                That is, its address was passed in a register.
2152                Output it as if it lived in that register.
2153                The debugger will know from the type
2154                that it was actually passed by invisible reference.  */
2155
2156             current_sym_code = N_RSYM;
2157
2158             /* DECL_RTL looks like (MEM (REG...).  Get the register number.  */
2159             current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2160             current_sym_addr = 0;
2161
2162             FORCE_TEXT;
2163             if (DECL_NAME (parms))
2164               {
2165                 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2166
2167                 fprintf (asmfile, "%s \"%s:r", ASM_STABS_OP,
2168                          IDENTIFIER_POINTER (DECL_NAME (parms)));
2169               }
2170             else
2171               {
2172                 current_sym_nchars = 8;
2173                 fprintf (asmfile, "%s \"(anon):r", ASM_STABS_OP);
2174               }
2175
2176             dbxout_type (TREE_TYPE (parms), 0, 0);
2177             dbxout_finish_symbol (parms);
2178           }
2179 #endif
2180       }
2181 }
2182 \f
2183 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2184    output definitions of those names, in raw form */
2185
2186 void
2187 dbxout_args (args)
2188      tree args;
2189 {
2190   while (args)
2191     {
2192       putc (',', asmfile);
2193       dbxout_type (TREE_VALUE (args), 0, 0);
2194       CHARS (1);
2195       args = TREE_CHAIN (args);
2196     }
2197 }
2198 \f
2199 /* Given a chain of ..._TYPE nodes,
2200    find those which have typedef names and output those names.
2201    This is to ensure those types get output.  */
2202
2203 void
2204 dbxout_types (types)
2205      register tree types;
2206 {
2207   while (types)
2208     {
2209       if (TYPE_NAME (types)
2210           && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
2211           && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
2212         dbxout_symbol (TYPE_NAME (types), 1);
2213       types = TREE_CHAIN (types);
2214     }
2215 }
2216 \f
2217 /* Output everything about a symbol block (a BLOCK node
2218    that represents a scope level),
2219    including recursive output of contained blocks.
2220
2221    BLOCK is the BLOCK node.
2222    DEPTH is its depth within containing symbol blocks.
2223    ARGS is usually zero; but for the outermost block of the
2224    body of a function, it is a chain of PARM_DECLs for the function parameters.
2225    We output definitions of all the register parms
2226    as if they were local variables of that block.
2227
2228    If -g1 was used, we count blocks just the same, but output nothing
2229    except for the outermost block.
2230
2231    Actually, BLOCK may be several blocks chained together.
2232    We handle them all in sequence.  */
2233
2234 static void
2235 dbxout_block (block, depth, args)
2236      register tree block;
2237      int depth;
2238      tree args;
2239 {
2240   int blocknum;
2241
2242   while (block)
2243     {
2244       /* Ignore blocks never expanded or otherwise marked as real.  */
2245       if (TREE_USED (block))
2246         {
2247 #ifndef DBX_LBRAC_FIRST
2248           /* In dbx format, the syms of a block come before the N_LBRAC.  */
2249           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2250             dbxout_syms (BLOCK_VARS (block));
2251           if (args)
2252             dbxout_reg_parms (args);
2253 #endif
2254
2255           /* Now output an N_LBRAC symbol to represent the beginning of
2256              the block.  Use the block's tree-walk order to generate
2257              the assembler symbols LBBn and LBEn
2258              that final will define around the code in this block.  */
2259           if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE)
2260             {
2261               char buf[20];
2262               blocknum = next_block_number++;
2263               ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2264
2265               if (BLOCK_HANDLER_BLOCK (block))
2266                 {
2267                   /* A catch block.  Must precede N_LBRAC.  */
2268                   tree decl = BLOCK_VARS (block);
2269                   while (decl)
2270                     {
2271 #ifdef DBX_OUTPUT_CATCH
2272                       DBX_OUTPUT_CATCH (asmfile, decl, buf);
2273 #else
2274                       fprintf (asmfile, "%s \"%s:C1\",%d,0,0,", ASM_STABS_OP,
2275                                IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2276                       assemble_name (asmfile, buf);
2277                       fprintf (asmfile, "\n");
2278 #endif
2279                       decl = TREE_CHAIN (decl);
2280                     }
2281                 }
2282
2283 #ifdef DBX_OUTPUT_LBRAC
2284               DBX_OUTPUT_LBRAC (asmfile, buf);
2285 #else
2286               fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC);
2287               assemble_name (asmfile, buf);
2288 #if DBX_BLOCKS_FUNCTION_RELATIVE
2289               fputc ('-', asmfile);
2290               assemble_name (asmfile, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
2291 #endif
2292               fprintf (asmfile, "\n");
2293 #endif
2294             }
2295           else if (depth > 0)
2296             /* Count blocks the same way regardless of debug_info_level.  */
2297             next_block_number++;
2298
2299 #ifdef DBX_LBRAC_FIRST
2300           /* On some weird machines, the syms of a block
2301              come after the N_LBRAC.  */
2302           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2303             dbxout_syms (BLOCK_VARS (block));
2304           if (args)
2305             dbxout_reg_parms (args);
2306 #endif
2307
2308           /* Output the subblocks.  */
2309           dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2310
2311           /* Refer to the marker for the end of the block.  */
2312           if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE)
2313             {
2314               char buf[20];
2315               ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2316 #ifdef DBX_OUTPUT_RBRAC
2317               DBX_OUTPUT_RBRAC (asmfile, buf);
2318 #else
2319               fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC);
2320               assemble_name (asmfile, buf);
2321 #if DBX_BLOCKS_FUNCTION_RELATIVE
2322               fputc ('-', asmfile);
2323               assemble_name (asmfile, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
2324 #endif
2325               fprintf (asmfile, "\n");
2326 #endif
2327             }
2328         }
2329       block = BLOCK_CHAIN (block);
2330     }
2331 }
2332
2333 /* Output the information about a function and its arguments and result.
2334    Usually this follows the function's code,
2335    but on some systems, it comes before.  */
2336
2337 static void
2338 dbxout_really_begin_function (decl)
2339      tree decl;
2340 {
2341   dbxout_symbol (decl, 0);
2342   dbxout_parms (DECL_ARGUMENTS (decl));
2343   if (DECL_NAME (DECL_RESULT (decl)) != 0)
2344     dbxout_symbol (DECL_RESULT (decl), 1);
2345 }
2346
2347 /* Called at beginning of output of function definition.  */
2348
2349 void
2350 dbxout_begin_function (decl)
2351      tree decl;
2352 {
2353 #ifdef DBX_FUNCTION_FIRST
2354   dbxout_really_begin_function (decl);
2355 #endif
2356 }
2357
2358 /* Output dbx data for a function definition.
2359    This includes a definition of the function name itself (a symbol),
2360    definitions of the parameters (locating them in the parameter list)
2361    and then output the block that makes up the function's body
2362    (including all the auto variables of the function).  */
2363
2364 void
2365 dbxout_function (decl)
2366      tree decl;
2367 {
2368 #ifndef DBX_FUNCTION_FIRST
2369   dbxout_really_begin_function (decl);
2370 #endif
2371   dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
2372 #ifdef DBX_OUTPUT_FUNCTION_END
2373   DBX_OUTPUT_FUNCTION_END (asmfile, decl);
2374 #endif
2375 }
2376 #endif /* DBX_DEBUGGING_INFO */