OSDN Git Service

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